Пример #1
0
def screenshot():
    path = PATH("%s/screenshot" % os.getcwd())
    androiddebug.shell("screencap -p /data/local/tmp/tmp.png").wait()
    if not os.path.isdir(path):
        os.makedirs(path)

    androiddebug.adb("pull /data/local/tmp/tmp.png %s" %
                     PATH("%s/%s.png" %
                          (path, androiddebug.timestamp()))).wait()
    androiddebug.shell("rm /data/local/tmp/tmp.png")
Пример #2
0
def record():
    androiddebug.shell("screenrecord /data/local/tmp/video.mp4")
    input_key = raw_input("Please press the Enter key to stop recording:\n")
    if input_key == "":
        androiddebug.adb("kill-server")

    print "Get Video file..."
    androiddebug.adb("start-server")
    time.sleep(1.5)

    path = PATH("%s/video" %os.getcwd())
    if not os.path.isdir(path):
        os.makedirs(path)

    androiddebug.adb("pull /data/local/tmp/video.mp4 %s" % PATH("%s/%s.mp4" % (path, androiddebug.timestamp()))).wait()
Пример #3
0
def get_match_apk(package_name, path):
    list = []
    for packages in androiddebug.shell("pm list packages -f %s" %package_name).stdout.readlines():
        if packages.split(":")[0] == "package":
            list.append(packages.split(":")[-1].split("=")[0])

    androiddebug.adb("pull %s %s" % (list[0], path)).wait()
Пример #4
0
 def get_total_cpu_time():
     time = androiddebug.shell(
         "cat /proc/stat|gawk '{print $2,$3,$4,$5,$6,$7,$8,$9,$10,$11}'"
     ).stdout.readline().split()
     total_time = 0
     for i in time:
         total_time += int(i)
     return total_time
Пример #5
0
 def get_process_cpu_time(self):
     time = androiddebug.shell(
         "cat /proc/%s/stat|gawk '{print $14,$15,$16,$17}'" %
         self.get_pid()).stdout.readline().split()
     pro_time = 0
     for i in time:
         pro_time += int(i)
     return pro_time
def get_permission_list(package_name):

    permission_list = []
    result_list = androiddebug.shell("dumpsys package %s | %s android.permission" % (package_name, androiddebug.find_util)).stdout.readlines()

    for permission in result_list:
        permission_list.append(permission.strip())

    return permission_list
def get_crash_log(time_list):
    log_file = PATH("%s/crash_log/%s.txt" %
                    (os.getcwd(), androiddebug.timestamp()))
    f = open(log_file, "w")
    for time in time_list:
        cash_log = androiddebug.shell("dumpsys dropbox --print %s" %
                                      time).stdout.read()
        f.write(cash_log)
    f.close()
Пример #8
0
 def get_frame_data(self):
     """
     获取帧数据及时间戳
     :return:字典
     """
     result = androiddebug.shell(
         "su -c 'service call SurfaceFlinger 1013'").stdout.readline()
     cur_surface = int(result.split("(")[1].split()[0], 16)
     return {"surface": cur_surface, "timestamp": time.time()}
Пример #9
0
    def run(self):
        user = androiddebug.shell(
            "su -c 'ls'").stdout.readline()  # 检查手机是否可以ROOT用户执行命令

        if "not found" in user:  # 非ROOT手机执行该方式
            serial_number = androiddebug.get_serialno()
            command = android_commands.AndroidCommands(serial_number)
            collector = surface_stats_collector.SurfaceStatsCollector(command)
            collector.DisableWarningAboutEmptyData()
            collector.Start()
            while True:
                if androiddebug.stop != True:
                    break
                tm = androiddebug.timestamp()
                results = collector.SampleResults()
                fpsdata = []
                if not results:
                    pass
                else:
                    for i in results:

                        if i.name == "avg_surface_fps":
                            if i.value == None:
                                fpsdata.insert(0, tm)
                                fpsdata.append(0)

                            else:
                                fpsdata.insert(0, tm)
                                fpsdata.append(i.value)
                self.ls.append(fpsdata)
            collector.Stop()

        else:  # ROOT手机执行该方式
            value1 = self.get_frame_data()
            self.time_before = value1["timestamp"]
            self.surface_before = value1["surface"]
            while True:
                if androiddebug.stop != True:
                    break
                y = []
                time.sleep(1)
                value2 = self.get_frame_data()
                self.time_after = value2["timestamp"]
                self.surface_after = value2["surface"]
                time_difference = int(
                    round((self.time_after - self.time_before), 2))
                frame_count = (self.surface_after - self.surface_before)
                tm = androiddebug.timestamp()
                fps = int(frame_count / time_difference)
                y.append(fps)
                self.time_before = self.time_after
                self.surface_before = self.surface_after
                y.insert(0, tm)
                self.ls.append(y)
def get_crash_time_list():
    time_list = []
    result_list = androiddebug.shell(
        "dumpsys dropbox | %s data_app_crash" %
        androiddebug.find_util).stdout.readlines()
    for time in result_list:
        temp_list = time.split(" ")
        temp_time = []
        temp_time.append(temp_list[0])
        temp_time.append(temp_list[1])
        time_list.append(" ".join(temp_time))

    return time_list
Пример #11
0
def top():
    cpu = []
    mem = []

    top_info = androiddebug.shell(
        "top -n %s | %s %s$" %
        (str(times), androiddebug.find_util, pkg_name)).stdout.readlines()
    #  PID PR CPU% S #THR VSS RSS PCY UID Name
    for info in top_info:
        #temp_list = del_space(info)
        temp_list = info.split()
        cpu.append(temp_list[2])
        mem.append(temp_list[6])

    return (cpu, mem)
Пример #12
0
 def run(self):
     while True:
         if androiddebug.stop != True:
             break
         sleep(1)
         y = []
         tm = androiddebug.timestamp()
         result = androiddebug.shell(
             "cat /sys/class/thermal/thermal_zone0/temp").stdout.readline()
         if "No such file or directory" in result:
             result = 0
         y.append(tm)
         y.append("".join(list(result)[0:2]) + "." +
                  "".join(list(result)[2:]))
         self.ls.append(y)
 def run(self):
     while True:
         if androiddebug.stop != True:
             break
         sleep(1)
         y = []
         dictionaries = {}
         tm = androiddebug.timestamp()
         # 这个温度单位是:
         result = androiddebug.shell("dumpsys battery").stdout.readlines()
         for i in result[1:]:
             new = i.split(":")
             dictionaries[new[0].strip()] = new[1].strip()
         y.append(tm)
         y.append("".join(list(dictionaries["temperature"])[0:2]) + "." +
                  "".join(list(dictionaries["temperature"])[2:]))
         self.ls.append(y)
Пример #14
0
# 需要Android4.4及4.4以上版本,运行脚本后可录制设备上的操作,默认使用手机分辨率,时间3min。手动按Enter结束录制。
# 录制结果存放于当前目录下的video目录下

PATH = lambda p: os.path.abspath(p)

def record():
    androiddebug.shell("screenrecord /data/local/tmp/video.mp4")
    input_key = raw_input("Please press the Enter key to stop recording:\n")
    if input_key == "":
        androiddebug.adb("kill-server")

    print "Get Video file..."
    androiddebug.adb("start-server")
    time.sleep(1.5)

    path = PATH("%s/video" %os.getcwd())
    if not os.path.isdir(path):
        os.makedirs(path)

    androiddebug.adb("pull /data/local/tmp/video.mp4 %s" % PATH("%s/%s.mp4" % (path, androiddebug.timestamp()))).wait()

if __name__ == "__main__":
    sdk = string.atoi(androiddebug.shell("getprop ro.build.version.sdk").stdout.read())
    if sdk < 19:
        print ">>> sdk version is %s, less than 19!"
        sys.exit(0)
    else:
        record()
        print "Completed"
Пример #15
0
def get_apk_list():
    apps = []
    for apk in androiddebug.shell("pm list packages -f -3").stdout.readlines():
        apps.append(apk.split(":")[-1].split("=")[0])
    return apps
Пример #16
0
 def get_sdkVersion(self):
     print "SDK版本:", androiddebug.shell(
         "cat /system/build.prop | findstr ro.build.version.sdk"
     ).stdout.readline().split("=")[1]
Пример #17
0
 def get_DisplayDeviceInfo(self):
     result = androiddebug.shell(
         "dumpsys display | findstr DisplayDeviceInfo").stdout.readline(
         ).split(",")[1].strip()
     print "分辨率:", result
Пример #18
0
 def get_memInfo(self):
     result = androiddebug.shell('cat /proc/meminfo|findstr "MemTotal"'
                                 ).stdout.readline().split(":")[1].strip()
     MemTotal = "{val}MB".format(val=int(result.split()[0]) / 1024)
     print "总内存:%s" % MemTotal
Пример #19
0
 def get_cpuModel(self):
     print "CPU型号:", androiddebug.shell("cat /proc/cpuinfo|findstr Hardware"
                                        ).stdout.readline().strip().split(
                                            ":")[1]