def press_android(key, com, long_press=MODE_ONCE) -> bool: logging.debug('tv serial {} send key: {}'.format(com, key.cn_name)) if isinstance(key, Key): code = str(key.code) elif isinstance(key, str): code = key elif isinstance(key, int) and int(key) > 0: code = str(key) else: return False cmd = 'input keyevent --longpress ' + code if long_press else 'input keyevent ' + code shellcmd.send_cmd(com, cmd) return True
def send_cmd(self, cmd, wait=0, is_clear_cache=True, timeout=None): self.lock.acquire() ret = shellcmd.send_cmd(com=self.com, cmd=cmd, wait=wait, is_clear_cache=is_clear_cache, timeout=timeout) self.lock.release() return ret
def push_file_by_base64(com: str, pc_file: str, tv_file: str): """ example: push_file_by_base64(com='com28', pc_file=r'F:\WORK_FILE\eclipse_work\kktestsocket\bin\kktestsocket.jar', tv_file=r'/data/local/tmp/kktestsocket.jar') """ with open(pc_file, 'rb') as f: b = f.read() base_string = base64.b64encode(b).decode() base_tv_file = tv_file + '.base' now = 0 step = 2000 write_label = '>' for i in range(len(base_string) // step): shellcmd.send_cmd( com, 'echo "' + base_string[now:now + step] + '" ' + write_label + ' ' + base_tv_file) now = now + step write_label = '>>' shellcmd.send_cmd( com, 'echo "' + base_string[now:now + step] + '" ' + write_label + ' ' + base_tv_file) shellcmd.send_cmd( com, 'cat ' + base_tv_file + ' | busybox base64 -d > ' + tv_file)
def aria_test(com, count, wait_time, usb): i = 0 usb_aria_root = usb + '/aria_log' send_cmd(com, 'if [ ! -d "' + usb_root + '" ];then mkdir /data/aria_log;fi') while i < count: print('当前执行次数为: {}'.format(i)) cur_date_stamp = str(int(time.time())) log_file = usb_aria_root + '/第' + str( i) + '次_' + cur_date_stamp + '.log' send_cmd( com, 'am start com.konka.kkmultiscreen/com.konka.throwingscreen.WelcomeActivity' ) pid = send_cmd_get_result( com, 'logcat -v time |grep `ps -A|grep com.konka.kkmultis' 'creen|busybox awk -F" " \'{print $2}\'` > ' + log_file + ' &') time.sleep(wait_time) send_cmd(com, 'busybox killall logcat') error_1 = send_cmd_get_result( com, 'cat ' + log_file + '|grep "java.lang.ClassCastException: android.os.BinderProxy cannot be cast to com.konka.kkmultiscreen.DataService"' ) error_2 = send_cmd_get_result( com, 'cat ' + log_file + '|grep "java.lang.RuntimeException: Unable to start' ' service com.konka.kkmultiscreen.tecentscreen.TencentService"') if error_1 or error_2: print('error_1: ', error_1) print('error_2: ', error_2) print('第{}次启动过程发现指定异常'.format(i)) # else: # send_cmd(com, 'rm -rf ' + log_file) send_cmd(com, 'am force-stop com.konka.kkmultiscreen') # send_cmd(com, 'logcat -c') time.sleep(5) i += 1
def init_env(com): if int(send_cmd_get_result(com, 'ps -A|grep "S sh"|wc -l')) < 3: send_cmd(com, '\rsu\r') send_cmd(com, 'echo 0 > /proc/sys/kernel/printk') send_cmd(com, 'start logd;logcat -G 2M')
# send_cmd(com, 'rm -rf ' + log_file) send_cmd(com, 'am force-stop com.konka.kkmultiscreen') # send_cmd(com, 'logcat -c') time.sleep(5) i += 1 if __name__ == '__main__': while True: tv_com = input('请输入电视串口:') if tv_com: if tv_com.upper() not in KKSerialFactory.get_all_serial(): print('请输入正确的串口!!!') continue try: send_cmd(tv_com, '') except SerialException as e: print('串口被占用,请先排查坏境后,新重输入') continue out_duration_count = input('请输入启动易投屏的次数:') if out_duration_count: try: out_duration_count = int(out_duration_count) except Exception as e: print('Exception: ' + str(e)) print('请输入合法的数值,请勿在输入次数时输入非数字的按键') continue wait_time = input('请输入启动应用后的等待时长:') if wait_time: try: wait_time = int(wait_time)
def test(com, count=1000, wait=90): res, mes = check_tv_com(com) send_cmd( com, 'file="/data/misc/konka/audio_log.txt";if [ ! -f "$file" ];then touch "$file"; fi' ) send_cmd(com, 'chmod 777 /data/misc/konka/audio_log.txt') if not res: print(mes) # 设置音量 i = 0 while i < count: volume = str(random.randrange(101)) send_cmd(com, '\rsu\r') print('第{}次测试,开始设置音量为{}'.format(i, volume)) if 'set volume to index=' + volume not in send_cmd_get_result( com, 'media volume --stream 3 --set ' + volume): print('设置音量失败,请联系对应管理人员') send_email(['*****@*****.**', '*****@*****.**'], 'AC断电音量检测脚本执行提示邮件', '设置音量失败,请检查权限') break if 'volume is ' + volume in send_cmd_get_result( com, 'media volume --stream 3 --get'): print('音量设置成功,开始AC断电') send_cmd( com, 'echo "第{}次测试,开始设置音量为{}" >> /data/misc/konka/audio_log.txt'.format( i, volume)) time.sleep(0.5) send_cmd( com, 'echo "重启前的audio_stream 日志:" >> /data/misc/konka/audio_log.txt') print('audio 信息是:') print(send_cmd_get_result(com, 'dumpsys audio | grep stream')) time.sleep(0.5) send_cmd( com, 'dumpsys audio | grep stream >> /data/misc/konka/audio_log.txt') time.sleep(1) ac_off() time.sleep(2) ac_on() time.sleep(wait) res, mes = check_tv_com(com) if not res: print(mes) print('异常处理中,断电重启') ac_on() time.sleep(wait) res, mes = check_tv_com(com) if not res: print(mes) print('连续2次串口不可以用,脚本中断') send_email(['*****@*****.**', '*****@*****.**'], 'AC断电音量检测脚本执行提示邮件', 'AC断电后串口不可用,连续2次,请检查') break send_cmd( com, 'echo "重启后的audio_stream 日志:" >> /data/misc/konka/audio_log.txt') send_cmd( com, 'dumpsys audio | grep stream >> /data/misc/konka/audio_log.txt') send_cmd(com, 'echo " " >> /data/misc/konka/audio_log.txt') if 'volume is ' + volume in send_cmd_get_result( com, 'media volume --stream 3 --get '): print('音量检查成功') print('audio 信息是:') time.sleep(0.5) print(send_cmd_get_result(com, 'dumpsys audio | grep stream')) else: print('音量检查失败') print('audio 信息是:') time.sleep(0.5) print(send_cmd(com, 'dumpsys audio | grep stream')) time.sleep(0.5) send_email(['*****@*****.**', '*****@*****.**'], 'AC断电音量检测脚本执行提示邮件', 'AC断电后音量检查失败,请现场确认') break i += 1 if i == count: print('执行完成!!!') return True else: print('执行异常!!!') return False
def _send_cmd(com, cmd, timeout=60): if isinstance(com, str): res = shellcmd.send_cmd(com, cmd, timeout=timeout) else: res = com.tv.send_cmd(cmd, timeout=timeout) return res
from time import sleep from serial import SerialException from utils.kkserial import KKSerialFactory from utils.shellcmd import send_cmd_get_result, send_cmd if __name__ == '__main__': while True: com = input('请输入电视串口:') if com: if com.upper() not in KKSerialFactory.get_all_serial(): print('请输入正确的串口!!!') continue try: send_cmd(com, '') except SerialException as e: print('串口串口被占用,请先排查坏境后,重新输入') continue out_duration_count = input('请输入重启的次数:') if out_duration_count: try: out_duration_count = int(out_duration_count) except Exception as e: print('Exception: ' + str(e)) print('请输入合法的数值,请勿在输入次数时输入非数字的按键') continue in_duration_count = input('请输入单次开机脚本的执行次数:') if in_duration_count: try: in_duration_count = int(in_duration_count)