调试手机adb小工具

简单的版本一:

"""gui tool"""

from tkinter import *
import datetime
import sys
import re
import time
import os
import subprocess

# enable print with color
if 1:
   if os.name == "nt":
      os.system("")


def getdevlist1():
    # print(11)
    devlist = []
    # connectfile = os.popen('type serialno_list.txt')
    connectfile = os.popen('adb devices')
    list1 = connectfile.readlines()
    # print("list1 = ", list1)
    # print(len(list1))
    # print(1,len(list1)-1)
    list2 = list1[1:len(list1) - 1]
    # print("list2 =",list2)
    for i in range(len(list2)):
        # print(list1[i].find('\tdevice') )
        # print(list1[i].find('\tdevice') != -1)
        # if list1[i].find('\tdevice') != -1:
        # temp = list1[i].split('\t')
        temp = list2[i].split()
        # print(22,temp,temp[0],temp[1])
        devlist.append(temp[0])
    # print(11,devlist)
    return devlist


def wait_one_device():
    ret = getdevlist1()
    # print(ret)
    counter = 0
    print("adb devices -l")
    os.system("adb devices -l")
    while (len(ret) != 1):
        # print("please keep \033[32m ss \033[0m device !")
        counter += 1
        print("\r current %d devices, please keep only 1 device, waiting %d Seconds" % (len(ret), counter), end=""),
        time.sleep(1)
        # os.system("ping -n 1 127.0.0.1 >nul")
        ret = getdevlist1()
    print("")


class Application(Frame):
    """yi ge lei"""

    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.createWidget()

    def do_cmd(self, *args):
        print(datetime.datetime.now().strftime('%Y_%m_%d %H:%M:%S'))
        wait_one_device()
        for i in args:
            print(i)
            os.system(i)
        print("\n\n")

    def createWidget(self):
        Button(self, text="亮/灭屏", width=10,
               command=lambda: self.do_cmd("adb shell input keyevent 26")).grid(row=0, column=0, padx=15, pady=10)

        Button(self, text="重启", width=10, command=lambda: self.do_cmd('adb reboot')).grid(row=0, column=1, padx=15,
                                                                                            pady=10)
        Button(self, text="截屏", width=10, command=lambda: self.do_cmd(
            "adb shell screencap -p /sdcard/screen.png",
            "adb pull /sdcard/screen.png C:\\Users\\dj0011744\\Desktop",
        )).grid(row=0, column=2, padx=15, pady=10)

        Button(self, text="录屏15s", width=10, command=lambda: self.do_cmd(
            "adb shell screenrecord  --time-limit 15 /sdcard/record.mp4",
            "adb pull /sdcard/record.mp4 C:\\Users\\dj0011744\\Desktop",
        )).grid(row=0, column=3, padx=15, pady=10)

        Button(self, text="过滤drm", width=10,
               command=lambda: os.system('start cmd /k adb shell "dmesg -w | grep drm"')).grid(row=1, column=0,
                                                                                                    padx=15, pady=10)

        Button(self, text="revised on", width=10,
               command=lambda: self.do_cmd(
                   'adb shell   ls  /sys/devices/platform/soc/ae00000.qcom,mdss_mdp/of_node/qcom,mdss_dsi_260_a20_12p3_dphy_cmd_ver_000')).grid(
            row=1, column=1, padx=15, pady=10)

        Button(self, text="启动单项老化", width=10,
               command=lambda: self.do_cmd("adb shell setprop persist.sys.rt.para true")).grid(row=1, column=2, padx=15,
                                                                                               pady=10)

        Button(self, text="停止老化", width=10, command=lambda: self.do_cmd(
            "adb remount",
            "adb shell rm -fr data/data/com.hihonor.runningtestii/shared_prefs",
            "adb reboot"
        )).grid(row=1, column=3, padx=15, pady=10)

        Button(self, text="刷dtbo.img", width=10, command=lambda: self.do_cmd(
            "adb  reboot  bootloader",
            "ping 127.0.0.1  -n 20",
            "fastboot devices",
            "fastboot flash dtbo dtbo.img",
            "fastboot reboot",
            "ping 127.0.0.1  -n 40",
            "adb wait-for-device",
            "adb shell   ls  /sys/devices/platform/soc/ae00000.qcom,mdss_mdp/of_node/qcom,mdss_dsi_260_a20_12p3_dphy_cmd_ver_000",
        )).grid(row=2, column=0, padx=15, pady=10)


        cmds = '''
        启动单项MMI:
        adb shell am start com.hihonor.mmitest/.MmiSingleItemMenu

        切帧率
        adb shell service call SurfaceFlinger 1035 i32 2

        打开屏幕显示刷新率
        adb shell service call SurfaceFlinger 1034 i32 1

        读寄存器
        adb remount
        adb shell "mount -t debugfs none /sys/kernel/debug"
        adb shell "echo set_debug_level:4 > /sys/kernel/debug/lcd-dbg/lcd_kit_dbg"
        adb shell "echo read_reg:dsi:0 cmd:0x0A read_count:1 > /sys/kernel/debug/lcd-dbg/lcd_kit_dbg"
        adb shell "echo read_reg:dsi:1 cmd:0x0A read_count:1 > /sys/kernel/debug/lcd-dbg/lcd_kit_dbg"
        adb shell "cat /sys/kernel/debug/lcd-dbg/lcd_kit_dbg"
        adb   shell   cat   /sys/class/graphics/fb0/panel_sncode

        常亮屏:
        adb shell settings put system screen_off_timeout 60000000

        触发死机进dump:
        adb shell "echo c > /proc/sysrq-trigger"

        查看修改时间
        adb shell   ls  /sys/devices/platform/soc/ae00000.qcom,mdss_mdp/of_node/qcom,mdss_dsi_260_a20_12p3_dphy_cmd_ver_000

        查看/修改亮度
        adb shell cat /sys/class/backlight/panel0-backlight/brightness
        adb shell "echo 800 > /sys/class/backlight/panel0-backlight/brightness"

        pull ko
        adb pull vendor_dlkm/lib/modules/msm_drm.ko  .

        过滤drm
        adb shell "dmesg -w | grep drm"

        拉 reliability log
        adb pull /data/vendor/log/reliability/dumplog  .

        查看屏幕批次命令
        adb shell cat sys/class/graphics/fb0/lcd_model

        查看初始化代码
        adb shell od  -t x1   /sys/devices/platform/soc/ae00000.qcom,mdss_mdp/of_node/qcom,mdss_dsi_260_a20_12p3_dphy_cmd_ver_000/qcom,mdss-dsi-display-timings/timing@0/qcom,mdss-dsi-on-command

        adb shell od  -t x1   /sys/devices/platform/soc/ae00000.qcom,mdss_mdp/of_node/qcom,mdss_dsi_260_a20_12p3_dphy_cmd_ver_000/qcom,mdss-dsi-display-timings/timing@0/qcom,mdss-dsi-off-command

        adb shell cat /sys/class/graphics/fb0/lcd_check_reg
        '''
        Button(self, text="查看其它命令", width=10, command=lambda: print(cmds + "\n\n")).grid(row=2, column=1, padx=15,
                                                                                               pady=10)


if __name__ == "__main__":
    root = Tk()
    root.geometry("500x300+0+0")
    root.title("小工具v0")
    app = Application(master=root)

    root.mainloop()
 

"""gui for a.py"""
from tkinter import *
import os


class Application(Frame):
    """yi ge lei"""

    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.python_path = "a.py"
        self.pack()
        self.createWidget()

    def createWidget(self):
        Button(self, text="查看porch", width=10,
               command=lambda: os.system("start cmd /c python " + self.python_path + " 1")).grid(row=0, column=0,
               #command=lambda: os.system("start cmd /c python b.py")).grid(row=0, column=0,
                                                                                                 padx=15, pady=10)
        Button(self, text="下版本", width=10,
               command=lambda: os.system("start cmd /c python " + self.python_path + " 2")).grid(row=0, column=1,
                                                                                                 padx=15, pady=10)
        Button(self, text="安装fps2d", width=10,
               command=lambda: os.system("start cmd /c python " + self.python_path + " 3")).grid(row=0, column=2,
                                                                                                 padx=15, pady=10)
        Button(self, text="开机向导", width=10,
               command=lambda: os.system("start cmd /c python " + self.python_path + " 4")).grid(row=0, column=3,
                                                                                                 padx=15, pady=10)
        Button(self, text="显示帧率", width=10,
               command=lambda: os.system("start cmd /c python " + self.python_path + " 5")).grid(row=1, column=0,
                                                                                                 padx=15, pady=10)
        Button(self, text="重启", width=10,
               command=lambda: os.system("start cmd /c python " + self.python_path + " 6")).grid(row=1, column=1,
                                                                                                 padx=15, pady=10)
        Button(self, text="查看亮度", width=10,
               command=lambda: os.system("start cmd /c python " + self.python_path + " 7")).grid(row=1, column=2,
                                                                                                 padx=15, pady=10)
        Button(self, text="过滤drm", width=10,
               command=lambda: os.system("start cmd /c python " + self.python_path + " 8")).grid(row=1, column=3,
                                                                                                 padx=15, pady=10)
        Button(self, text="拉 log", width=10,
               command=lambda: os.system("start cmd /c python " + self.python_path + " 9")).grid(row=2, column=0,
                                                                                                 padx=15, pady=10)

        Button(self, text="SecureEmode", width=10,
               command=lambda: os.system("start cmd /c python " + self.python_path + " 3 3")).grid(row=2, column=1,
                                                                                                   padx=15, pady=10)


if __name__ == "__main__":
    root = Tk()
    root.geometry("500x300+0+0")
    root.title("小工具v1.0")
    app = Application(master=root)

    root.mainloop()
 

import re
import time
import os
import subprocess
#enable print with color
if 1:
    import os
    if os.name == "nt":
        os.system("")
        print("os.name=",os.name)
    print("\033[1;32m Welcome! \033[0m")


def cat2():
    task_list=[
               'adb shell cat /proc/driver/lcd_id',
               'adb shell cat /proc/cmdline',
               'adb shell cat /proc/version',                                 
               'adb shell "ls  /sys/lcd_sys/reg_debug/"',                  
               'adb shell "cat /sys/class/display/panel0/hporch"',     
               'adb shell "cat /sys/class/display/panel0/vporch"',        
               'adb shell "cat /sys/class/display/panel0/pixel_clock"',    
               'adb shell "cat /sys/class/display/dphy0/freq"',            
               ]                                 
    cmdtask = subprocess.run(' {}'.format('adb shell cat /proc/cmdline'), shell=True, capture_output=True,universal_newlines=True)
    ret=re.search(r"lcd_name\S+",cmdtask.stdout)
    #print("ret=",ret)
    if ret!=None:
        print("\033[33m lcd name \033[0m =",ret.group())

    for i in task_list:
        cmdtask = subprocess.run(' {}'.format(i), shell=True, capture_output=True,universal_newlines=True)
        print("\033[33m {} \033[0m =".format(i),cmdtask.stdout)


def menu():
    print("------------------------------------------------------------------------")
    print("|   0.  exit                                                           |")
    print("|   1.  cat /sys/class/display/panel0/hporch  ( only one device )      |")
    print("|   2.  adb reboot autodloader                ( only one device )      |")
    print("|   3.  adb -s xxx reboot autodloader         ( at least one device )  |")
    print("|   4.  adb -s xxx install androidFPS2D.apk   ( at least one device )  |")
    print("|   5.  perform DIY command by subprocess     ( at least one device )  |")
    print("|   6.  perform DIY command in cmd window     ( at least one device )  |")
    print("|   7.  adb pull /data/ylog C:/Users/10335101/Desktop                  |")
    print("|   8.  adb devices                                                    |")
    print("|   9.  help and print manual                                          |")
    print("------------------------------------------------------------------------")


def getdevlist1():
    devlist = []
    #connectfile = os.popen('type serialno_list.txt')
    connectfile = os.popen('adb devices')
    list1 = connectfile.readlines()
    #print(list1)
    #print(len(list1))
    #print(1,len(list1)-1)
    list2=list(list1[1:len(list1)-1])
    #print(list2)
    for i in range(len(list2)):
        #print(list1[i].find('\tdevice') )
        #print(list1[i].find('\tdevice') != -1)
        #if list1[i].find('\tdevice') != -1:
            #temp = list1[i].split('\t')
        temp = list2[i].split()
        #print(22,temp,temp[0],temp[1])
        devlist.append(temp[0])
    #print(11,devlist)
    return devlist


def all_devices_do(cmd1,mode):
    no_list=getdevlist1()
    counter=0
    while(len(no_list)<=0):
        counter+=1
        #print("please keep \033[32m ss \033[0m device !")
        print("\rcurrent \033[31m %d \033[0m devices,please at least 1 device ! waiting...\033[32m %d \033[0m Seconds" % (len(no_list),counter),end=" ")
        time.sleep(1)
        #os.system("ping -n 1 127.0.0.1 >nul")
        no_list=getdevlist1()
    print("")
    c=0
    for  i in no_list:
        print(c,".  ",i)
        c+=1
    c=0
    for i in no_list:
        print("---the \033[33m %d \033[0m device---" % c)
        if mode=="sub":
            #os.system("ls %s" % (i))
            cmd2=cmd1.replace("xxx",i)
            #os.popen(cmd2)
            cmdtask=subprocess.run(' {}'.format( cmd2), shell=True, capture_output=True,universal_newlines=True)
            #os.popen("adb -s %s reboot autodloader" % i)
            #print("adb -s %s reboot autodloader" % i)
            print("\033[33m {} \033[0m =".format(cmd2),cmdtask.stdout)
            ret=re.search(r"lcd_name\S+",cmdtask.stdout)
            #print("ret=",ret)
            if ret!=None:
                print("\033[33m ",ret.group(),"\033[0m ")
            #print("---the %d  device---" % c)
        else:
            cmd2=cmd1.replace("xxx",i)
            s=f'start cmd /k "{cmd2}"'
            print(s)
            os.system(s)
        print("---the \033[33m %d \033[0m device---" % c)
        c+=1


def help():
    print("1.cat something by adb command ,limit only for one device, dynamic detect device number, if not one device, it will wait for you plug at least one device,or extract surplus devices")
    print("2.adb reboot autodloader for only one device, dynamic detect device number, if not one device, it will wait for you plug at least one device,or extract surplus devices")
    print("3.adb reboot autodloader for at least one device")
    print("4.install apk for at least one device")
    print("5.perform your own command for at least one device , use xxx stand for serial number")
    print("6.perform your own command for at least one device , use xxx stand for serial number . perform in cmd window, which always keep open")
    print("7.adb pull /data/ylog C:/Users/10335101/Desktop")
    print("8.adb devices ")
    print("9.help and print manual")


def main():
    while True:
        #print("\n\n")
        menu()
        select=input("please select function: ")
        if select=="0":
            print("\n")
            exit()
        elif select=="1":
            ret=getdevlist1()
            #print(ret)
            counter=0
            while(len(ret)!=1):
                #print("please keep \033[32m ss \033[0m device !")
                counter+=1
                print("\rcurrent \033[31m %d \033[0m devices,please keep 1 device ! waiting...\033[32m %d \033[0m Seconds" % (len(ret),counter),end=" ")
                time.sleep(1)
                #os.system("ping -n 1 127.0.0.1 >nul")
                ret=getdevlist1()
            #cat()
            print("")
            cat2()
            os.system("pause")
            print("\n\n")
            #os.system("cls")
        elif select=="2":
            ret=getdevlist1()
            #print(ret)
            counter=0
            while(len(ret)!=1):
                #print("please keep \033[32m ss \033[0m device !")
                counter+=1
                print("\rcurrent \033[31m %d \033[0m devices,please keep 1 device ! waiting...\033[32m %d \033[0m Seconds" % (len(ret),counter),end=" ")
                time.sleep(1)
                ret=getdevlist1()
            print("")
            #os.system("adb reboot autodloader")
            # popen geng kuai
            os.popen("adb reboot autodloader")
            print("adb reboot autodloader")
            os.system("pause")
            print("\n\n")
        elif select=="3":
            all_devices_do("adb -s xxx reboot autodloader","sub")
            os.system("pause")
            print("\n\n")
        elif select=="4":
            app_list=["D:\\MYFILE\\OLD\\DevCheckPro_4.42.apk",
                     "D:\\MYFILE\\androidFPS2D.apk",
                     "D:\\MYFILE\\OLD\\AIDA64_138.apk",
                     "D:\\MYFILE\\OLD\\SecureEmode-S-signed.apk"]
            for i in range(len(app_list)):
                #print(i,app_list[i],len(app_list))
                s=f"adb -s xxx install {app_list[i]}"
                #print(s)
                all_devices_do(s,"sub")
                if i<len(app_list)-1:
                    wait_time=6
                    for i in range(wait_time):
                        #print("\rwaiting ...\033[33m {}\033[0m Seconds left  ".format(wait_time-i),end='')
                        print("\rThe next app will be installed after \033[33m {}\033[0m Seconds!".format(wait_time-i),end='')
                        time.sleep(1)
                    print("")
            os.system("pause")
            print("\n\n")
        elif select=="5":
            print("please input your command , use xxx stand for serial_no \n Usage1: adb -s xxx install D:\MYFILE\\androidFPS2D.apk  \n Usage2: adb  -s xxx reboot autodloader \n Usage3: adb -s xxx shell cat /proc/cmdline")
            cmd3=input("command : ")
            all_devices_do(cmd3,"sub")
            os.system("pause")
            print("\n\n")
        elif select=="6":
            print("please input your command , use xxx stand for serial_no \n Usage: fota_test.py xxx")
            cmd3=input("command : ")
            all_devices_do(cmd3,"cmd")
            os.system("pause")
            print("\n\n")
        elif select=="7":
            ret=getdevlist1()
            #print(ret)
            counter=0
            while(len(ret)!=1):
                #print("please keep \033[32m ss \033[0m device !")
                counter+=1
                print("\rcurrent \033[31m %d \033[0m devices,please keep 1 device ! waiting...\033[32m %d \033[0m Seconds" % (len(ret),counter),end=" ")
                time.sleep(1)
                #os.system("ping -n 1 127.0.0.1 >nul")
                ret=getdevlist1()
            print("")
            os.system("adb pull /data/ylog C:/Users/10335101/Desktop")
            os.system("pause")
        elif select=="8":
            with os.popen("adb devices","r") as p:
                ret=p.read()
            print(ret)
            os.system("pause")
            print("\n\n")
        elif select=="9":
            help()
            os.system("pause")
            print("\n\n")
        else:
            print("input error!")
            print("\n\n")
            #os.system("cls")
        #print("\n\n")
    
if __name__=="__main__":
    main()


    '''
    def cat():
    os.startfile("cat.bat")
    counter=0
    print("")
    for i in range(20):
        print("\rwaiting ...\033[33m %d \033[0m Seconds" % i,end=" ")
        #print("\rwaiting ...%d Seconds" % i,end=" ")
        time.sleep(1)
        #os.system("ping -n 1 127.0.0.1 >nul")
    print("")
    f1=open("porch.txt","r")
    print(f1.read())
    f1.close()
    def acquire_serialno_list():
    with os.popen("adb devices","r") as p:
        r=p.read()
        f1=open("serialno_list.txt","w")
        print(r,file=f1)
        f1.close()
    def all_devices_do_in_cmd_window(cmd1):
    ret=acquire_serialno_list()
    counter=0
    while(len(ret)<=0):
        #print("please keep \033[32m ss \033[0m device !")
        counter+=1
        print("\rcurrent \033[31m %d \033[0m devices,please at least 1 device ! waiting...\033[32m %d \033[0m Seconds" % (len(ret),counter),end=" ")
        #print("\rcurrent %d devices,please at least 1 device ! waiting...%d Seconds" % (len(ret),counter),end=" ")
        time.sleep(1)
        #os.system("ping -n 1 127.0.0.1 >nul")
        ret=acquire_serialno_list()
    print("")
    no_list=[]
    for i in ret:
        #print("mei hang shu ju: ",i)
        sp=i.split()
        #print("mei hang chai fen hou: ",sp)
        #print("no= ",sp[0])   
        no_list.append(sp[0])
    #print("no_list = ",no_list)
    #print("there are %d devices !" % len(ret))
    print("there are %d devices ! the serialno are:" % len(no_list))
    #print("there are \033[32m  %d \033[0m devices, the serialno are:" % len(no_list))
    c=0
    for  i in no_list:
        print(c,".  ",i)
        c+=1
    c=0
    f1=open("a.bat","w")
    for i in no_list:
        print("---the \033[33m %d \033[0m device---" % c)
        # zhe li gai xi tong ming ling 
        #os.system("ls %s" % (i))
        cmd2=cmd1.replace("xxx",i)
        #os.popen(cmd2)
        #subprocess.run(' {}'.format( cmd2), shell=True, capture_output=True,universal_newlines=True)
        s1 = 'start cmd /k "{}"'.format(cmd2) 
        #print('start cmd /k "{}"'.format(cmd2))
        print(s1)
        print(s1,file=f1)
        #ret=subprocess.run(' {}'.format( cmd2), shell=True, capture_output=True,universal_newlines=True)
        #print(cmd2)

        #os.popen("adb -s %s reboot autodloader" % i)
        #print("adb -s %s reboot autodloader" % i)
        #print("---the %d  device---" % c)
        print("---the \033[33m %d \033[0m device---" % c)
        c+=1
    f1.close()
    os.startfile("a.bat")


    f1=open("serialno_list.txt","r")
    #print(f1.read())
    #print(f1.readlines())
    ret=f1.readlines()
    #print(ret)
    #print(type(ret))
    #print(len(ret))
    #print(ret[1:])
    len1=len(ret)-2
    #print(len1)
    #print(ret[1:len1])
    ret2=ret[1:len1]
    f1.close()
    return ret2
    #os.startfile("C:\\Users\\10335101\\tt\\cat.bat")
    #print("Welcome to use this system !" )
    #all_devices_do("adb -s xxx install D:\\MYFILE\\OLD\\DevCheckPro_4.42.apk")
    #time.sleep(6) 
    #all_devices_do("adb -s xxx install D:\\MYFILE\\androidFPS2D.apk")
    #time.sleep(6) 
    #all_devices_do("adb -s xxx install D:\\MYFILE\\OLD\\AIDA64_138.apk")
    #time.sleep(6) 
    #all_devices_do("adb -s xxx install D:\\MYFILE\\OLD\\SecureEmode-S-signed.apk")
    '''
 

import subprocess


def workingTime30min():  #设置亮屏时间
    order1 = "adb shell settings put system screen_off_timeout 1800000"
    pi1 = subprocess.Popen(order1, shell=True, stdout=subprocess.PIPE)

def workingTime15s():  #设置亮屏时间
    order1 = "adb shell settings put system screen_off_timeout 15000"
    pi1 = subprocess.Popen(order1, shell=True, stdout=subprocess.PIPE)

def powerkey():     #按下power键
    order1 = "adb shell input keyevent POWER"
    pi1 = subprocess.Popen(order1, shell=True, stdout=subprocess.PIPE)
    # print(11111)

def shutdown():     #关机
    order1 = "adb shell reboot -p"
    pi1 = subprocess.Popen(order1, shell=True, stdout=subprocess.PIPE)

def reboot():       #重启
    # os.system("adb shell reboot")
    order1 = "adb shell reboot"
    pi1 = subprocess.Popen(order1, shell=True, stdout=subprocess.PIPE)


def closelocus():   #关闭触摸轨迹
    # os.system("adb shell settings put system pointer_location 1")
    order1 = "adb shell settings put system pointer_location 0"
    pi1 = subprocess.Popen(order1, shell=True, stdout=subprocess.PIPE)
    # os.system("adb shell settings put system show_touches 1")
    order2 = "adb shell settings put system show_touches 0"
    pi2 = subprocess.Popen(order2, shell=True, stdout=subprocess.PIPE)

def openlocus():    #开启触摸轨迹
    # os.system("adb shell settings put system pointer_location 0")
    order1 = "adb shell settings put system pointer_location 1"
    pi1 = subprocess.Popen(order1, shell=True, stdout=subprocess.PIPE)
    # os.system("adb shell settings put system show_touches 0")
    order2 = "adb shell settings put system show_touches 1"
    pi2 = subprocess.Popen(order2, shell=True, stdout=subprocess.PIPE)


def unlock():       # 滑动解锁
    # os.system("adb shell input keyevent 82")
    order1 = "adb shell input keyevent 82"
    pi1 = subprocess.Popen(order1, shell=True, stdout=subprocess.PIPE)


def TurnOffTouch():  # 关闭TP功能
    # os.system(""" adb shell "echo 1 >/proc/touchscreen/suspend" """)
    order1 = """ adb shell "echo 1 >/proc/touchscreen/suspend" """
    pi1 = subprocess.Popen(order1, shell=True, stdout=subprocess.PIPE)

def GetEnforce():
    order1 = "adb root"
    pi1 = subprocess.Popen(order1, shell=True, stdout=subprocess.PIPE)

    order2 = "adb remount"
    pi2 = subprocess.Popen(order2, shell=True, stdout=subprocess.PIPE)

    order3 = """ adb shell "setenforce 0" """
    pi3 = subprocess.Popen(order3, shell=True, stdout=subprocess.PIPE)

    order3 = """ adb shell "chmod 777 /proc/gcore_app" """
    pi3 = subprocess.Popen(order3, shell=True, stdout=subprocess.PIPE)


def GetTPLog():
    order1 = """ adb shell cat /dev/kmsg | grep "CB value download the" """
    pi1 = subprocess.Popen(order1, shell=True, stdout=subprocess.PIPE)

def test():     #测试
    # self.mess = os.popen("adb shell cat proc/version").read()
    print("13t763217867890765678")
    # print("skdjfhsdbkj")


 

import time
from tkinter import *
from tkinter import ttk
import function
#import thread
import _thread

class AdbLabor():

    def __init__(self):
        # super(AdbLabor, self).__init__()
        # self.message = None
        self.width =1000
        self.height = 600
        self.win = Tk(className="adb操作")
        self.canvas = Canvas(self.win, width=1000, height=600)
        self.canvas.pack()

        # Add a line in canvas widget


        g_screenwidth = self.win.winfo_screenwidth()
        g_screenheight = self.win.winfo_screenheight()
        alignstr = '%dx%d+%d+%d' % (self.width, self.height, (g_screenwidth - self.width) / 2, (g_screenheight - self.height) / 2)

        self.win.resizable(height=False, width=False)
        # self.win.geometry("1500x800")
        self.win.geometry(alignstr)
        #self.messageText()
        self.keyboot()
        self.key_boot()
        # self.win.bind('<Configure>', self.WindowResize)
        self.win.mainloop()
        #print("__init__")
        #print(type(self.FunctionKey(1)))

    def keyboot(self):
        self.bttn_click = 0
        self.pwr_click = 0
        self.tp_click = 0
        self.timeeee = 0
        # x_variable = StringVar()  # #创建变量,便于取值
        y_variable = StringVar()  # #创建变量,便于取值
        self.times = ttk.Combobox(self.win, width=10, textvariable=y_variable)  # #创建下拉菜单
        #self.times.place(x=10, y=80)
        self.times["value"] = ("2秒", "5秒", "10秒", "20秒")  # #给下拉菜单设定值


        self.lable1 = Label(text="按键相关",font=('微软雅黑',12),width=12,height=3)
        self.lable1.place(x=(self.width/4-190),y=-20)

        self.lable2 = Label(text="显示相关", font=('微软雅黑', 12), width=12, height=3)
        self.lable2.place(x=(self.width/2-190), y=-20)

        self.lable3 = Label(text="TP 相关", font=('微软雅黑', 12), width=12, height=3)
        self.lable3.place(x=(self.width/4-190), y=self.height/3-20)

        self.canvas.create_line(self.width / 4, 0, self.width / 4, self.height, fill='black', width=2)
        self.canvas.create_line(self.width / 2, 0, self.width / 2, self.height, fill='black', width=2)
        self.canvas.create_line(0, self.height / 3, self.width, self.height / 3, fill='black', width=2)
        self.canvas.create_line(0, self.height / 3 * 2, self.width / 2, self.height / 3 * 2, fill='black', width=2)

        self.button1 = Button(text="按下power", width=12, height=1, command=lambda: self.FunctionKey(1))
        self.button1.place(x=20, y=30)

        self.button2 = Button(text="滑动解锁", width=12, height=1, command=lambda: self.FunctionKey(2))
        self.button2.place(x=135, y=30)

        self.button3 = Button(text="关机", width=12, height=1, command=lambda: self.FunctionKey(3))
        self.button3.place(x=20, y=80)

        self.button5 = Button(text="重启", width=12, height=1, command=lambda: self.FunctionKey(4))
        self.button5.place(x=135, y=80)
        #"""
        self.button4 = Button(text="触摸轨迹", width=12, height=1, command=lambda: self.FunctionKey(4))
        self.button4.place(x=480, y=5)

        self.button6 = Button(text="压测休眠唤醒", width=12, height=1, command=lambda: self.FunctionKey(6))
        self.button6.place(x=240, y=55)

        self.button7 = Button(text="关闭TP功能", width=12, height=1, command=lambda: self.FunctionKey(7))
        self.button7.place(x=360, y=55)

        self.button8 = Button(text="强制解锁手机", width=12, height=1, command=lambda: self.FunctionKey(8))
        self.button8.place(x=480, y=55)

        self.button9 = Button(text="设置亮屏30min", width=12, height=1, command=lambda: self.FunctionKey(9))
        self.button9.place(x=120, y=105)

        self.button9 = Button(text="设置亮屏15s", width=12, height=1, command=lambda: self.FunctionKey(10))
        self.button9.place(x=240, y=105)

        self.button9 = Button(text="查看TP log", width=12, height=1, command=lambda: self.FunctionKey(11))
        self.button9.place(x=360, y=105)

        self.button100 = Button(text="测试", width=12, height=1, command=self.ShowLog)
        self.button100.place(x=480, y=505)
        """

    """
    def WindowResize(self,event):
        save_width = self.width
        save_height = self.height


        new_width = self.win.winfo_width()
        new_height = self.win.winfo_height()

        if new_width == 1 and new_height == 1:
            return
        if save_width != new_width or save_height != new_height:
            # frame1.config(width=new_width - 40, height=new_height - 60)
            #self.button1.place(x=20, y=40)
            self.canvas.create_line(new_width / 4, 0, new_width / 4, new_height, fill='red', width=2)
            self.canvas.create_line(new_width / 2, 0, new_width / 2, new_height, fill='red', width=2)
            #pass
        save_width = new_width
        save_height = new_height
    #"""
    def key_boot(self):
        #time1 = time.time()
        self.bttn_click = 0
        self.pwr_click = 0
        self.tp_click = 0
        self.timeeee = 0
        # x_variable = StringVar()  # #创建变量,便于取值
        y_variable = StringVar()  # #创建变量,便于取值
        # ttk.Label(self.win, text="       次  数 ").place(x=10, y=5)
        # self.time = ttk.Combobox(self.win, width=10, textvariable=x_variable)  # #创建下拉菜单
        # self.time.place(x=10, y=30)
        # self.time["value"] = ("100", "500","1000", "一直干")  # #给下拉菜单设定值
        #ttk.Label(self.win, text="     间隔时间 ").place(x=10, y=55)
        self.times = ttk.Combobox(self.win, width=10, textvariable=y_variable)  # #创建下拉菜单
        #self.times.place(x=10, y=80)
        self.times["value"] = ("2秒", "5秒", "10秒", "20秒")  # #给下拉菜单设定值

        self.button1 = Button(text="按下power",width=12,height = 1,command=lambda:self.FunctionKey(1))
        #self.button1.place(x=120, y=5)

        self.button2 = Button(text="关机", width=12, height=1, command=lambda:self.FunctionKey(2))
        #self.button2.place(x=240, y=5)

        self.button3 = Button(text="重启", width=12, height=1, command=lambda:self.FunctionKey(3))
        #self.button3.place(x=360, y=5)

        self.button4 = Button(text="触摸轨迹", width=12, height=1, command=lambda :self.FunctionKey(4))
        #self.button4.place(x=480, y=5)

        self.button5 = Button(text="滑动解锁", width=12, height=1, command=lambda:self.FunctionKey(5))
        #self.button5.place(x=120, y=55)

        self.button6 = Button(text="压测休眠唤醒", width=12, height=1, command=lambda:self.FunctionKey(6))
        self.button6.place(x=240, y=55)

        self.button7 = Button(text="关闭TP功能", width=12, height=1, command=lambda: self.FunctionKey(7))
        #self.button7.place(x=360, y=55)

        self.button8 = Button(text="强制解锁手机", width=12, height=1, command=lambda: self.FunctionKey(8))
        #self.button8.place(x=480, y=55)

        self.button9 = Button(text="设置亮屏30min", width=12, height=1, command=lambda: self.FunctionKey(9))
        #self.button9.place(x=120, y=105)

        self.button9 = Button(text="设置亮屏15s", width=12, height=1, command=lambda: self.FunctionKey(10))
        #self.button9.place(x=240, y=105)

        self.button9 = Button(text="查看TP log", width=12, height=1, command=lambda: self.FunctionKey(11))
        #self.button9.place(x=360, y=105)

        self.button100 = Button(text="测试", width=12, height=1, command=self.ShowLog)
        #self.button100.place(x=480, y=505)

        #time2 = time.time()
        #print("运行完成,耗时:%dS" % (time2 - time1))
        print("key_boot")


    def OpeationTime(self):
        if self.times.get() == "2秒":
            return 2
        elif self.times.get() == "5秒":
            return 5
        elif self.times.get() == "10秒":
            return 10
        else:
            return 2


    def FunctionKey(self,button_id):

        if button_id == 1:      #按下power键
            function.powerkey()
            #self.messageText(1)

        elif button_id == 3:    #关机键
            function.shutdown()

        elif button_id == 4:    #重启
            function.reboot()

        elif button_id == 10:  # 触摸轨迹
            if self.bttn_click % 2 == 1:
                function.closelocus()
            else:
                function.openlocus()
            self.bttn_click += 1

        elif button_id == 2:    #滑动解锁
            function.unlock()

        elif button_id == 6:  #休眠压测
            self.pwr_click += 1
            #self.thread(self.Timeee)
            thread.thread(self.Timeee)
            if self.timeeee == 0:  #设置不同点击次数输出不同标识
                return ("开始压测休眠唤醒")
            else:
                return ("休眠唤醒次数:%d" % (self.timeeee / 2))


        elif button_id == 7:    #关闭TP功能
            function.TurnOffTouch()

        elif button_id == 8:    #强制解锁
            function.GetEnforce()

        elif button_id == 9:    #强制解锁
            function.workingTime30min()

        elif button_id == 10:    #强制解锁
            function.workingTime15s()

        elif button_id == 11:    #查看TP
            function.GetTPLog()

        elif button_id == 100:
            function.test()


    def Timeee(self):
        while 1:
            function.powerkey()
            time.sleep(self.OpeationTime())
            self.timeeee = self.timeeee + 1  # 记录压测次数
            if self.pwr_click % 2 == 0 :    #点击奇数次,启动压测;偶数次,结束压测
                break


    def ShowLog(self):
        print(123)

    def messageText(self,button_id):
        self.message = Text(self.win, wrap='word', height=100, width=60)
        self.message.pack(side=RIGHT)
        self.message.tag_configure('stderr', foreground='#b22222')
        # self.showmessage = self.FunctionKey()
        self.message.update()
        return self.message.insert(END, chars=(self.FunctionKey(button_id)))
        # print("messageText")
        # )

AdbLabor()
 

  • 11
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值