Ejemplo n.º 1
0
def runAppThenGetPid():
    cmdUtils.doStrAsCmdAndGetPipeline("adb wait-for-device", _pwd)
    # 自动获取包名
    _packageName = getPackageName()
    # 获取运行中的 package 对应的 pid
    _pid = getRuntimePid(_packageName)
    # 取到了,打印出要执行的 shell
    if _pid is None:
        print("没有处于运行状态,尝试启动 app")
        runPackage(_packageName)  # 运行 app
        _pid = getRuntimePid(_packageName)  # 再次获取 运行 pid
    else:
        print("处于运行状态中")
    return _pid
Ejemplo n.º 2
0
def getThridPackageList():
    '''
    列出第三方安装包,显示如下格式(展示一小部分)
    package:com.tencent.mobileqq
    package:com.xxx.west.west01
    package:com.xxx.west.west02
    package:com.baidu.BaiduMap
    '''
    _packageStrList = cmdUtils.doStrAsCmdAndGetPipeline(
        "adb shell pm list packages -3", _pwd)
    for _i in range(len(_packageStrList)):
        _packageStrList[_i] = _packageStrList[_i].split("package:")[1]
    return _packageStrList
Ejemplo n.º 3
0
 def doLogMemoryInfo(self, packageName_: str, logFolderPath_: str, intervalSecond_: int = 10):
     _pid = adbUtils.getRuntimePid(packageName_)
     _memCmd = adbUtils.getMemInfoCmdByPid(_pid)
     _count = 0
     while True:
         _count += 1
         _lines = cmdUtils.doStrAsCmdAndGetPipeline(_memCmd, "/Users/jiasy/Downloads/")
         fileUtils.writeFileWithStr(
             os.path.join(logFolderPath_, str(_count).rjust(4, "0") + ".txt"),
             "\n".join(_lines)
         )
         self.doScreenCap(logFolderPath_, _count)  # 再截个同名的屏
         time.sleep(intervalSecond_)
Ejemplo n.º 4
0
def getMainActivity(packageName_: str):
    _cmdResult = cmdUtils.doStrAsCmdAndGetPipeline(
        "adb shell monkey -c android.intent.category.LAUNCHER -v -v -v  0",
        _pwd)
    for _i in range(len(_cmdResult)):
        _resultLine = _cmdResult[_i]

        _activityAndPackageResult = re.search(
            r'.* Using main activity (.+) \(.*from package (.+)\)',
            _resultLine)

        if _activityAndPackageResult:
            if _activityAndPackageResult.group(2) == packageName_:
                return _activityAndPackageResult.group(1)
    return None
Ejemplo n.º 5
0
def getRuntimePid(packageName_):
    # 获取包的运行信息,确保其处于运行中
    _processStrList = cmdUtils.doStrAsCmdAndGetPipeline(
        "adb shell ps | grep " + packageName_, _pwd)
    if not _processStrList:
        print(packageName_ + " 不在运行中")
        return None
    '''
    过滤出来的内容有两行,第一行为推送的包名
    u0_a484      29763   662 5167588  72208 0                   0 S com.xxx.west.west02:push_xx
    u0_a484      30766   662 11566688 509036 0                  0 S com.xxx.west.west02
    '''
    _pid = None
    # 获取 pid
    for _i in range(len(_processStrList)):
        _processInfoStr = _processStrList[_i]
        _processInfoStr = ' '.join(_processInfoStr.split())
        if not (":push" in _processInfoStr):
            _pid = _processInfoStr.split(' ')[1]
    return _pid
Ejemplo n.º 6
0
def doScreencap(screenCapName_="screenCap"):
    _screenPath = os.path.join("", "sdcard/DCIM", screenCapName_ + ".png")
    cmdUtils.doStrAsCmdAndGetPipeline(
        "adb shell screencap -p {0}".format(_screenPath), _pwd)
    return _screenPath
Ejemplo n.º 7
0
def pullFromSD(sdPath_: str, localFolderPath_: str):
    _localFilePath = os.path.join(localFolderPath_, os.path.basename(sdPath_))
    if os.path.exists(_localFilePath):
        print("覆盖文件 : " + _localFilePath)
    cmdUtils.doStrAsCmdAndGetPipeline(
        "adb pull {0} {1}".format(sdPath_, localFolderPath_), _pwd)
Ejemplo n.º 8
0
def pushToSD(localPath_: str, sdFolderPath_: str):
    cmdUtils.doStrAsCmdAndGetPipeline(
        "adb push {0} {1}".format(localPath_, sdFolderPath_), _pwd)
Ejemplo n.º 9
0
 def doScreenCap(self, logFolderPath_: str, count_: int):
     # 截屏,并保存到本地
     cmdUtils.doStrAsCmdAndGetPipeline(
         "adb exec-out screencap -p > " + os.path.join(logFolderPath_, str(count_).rjust(3, "0") + ".png"),
         "/Users/jiasy/Downloads/"
     )