def downloadPkgList(self, pkgs): ''' 功能:批量下载APK ''' logging.info('======Download======') try: os.mkdir(self._dirapps) except: pass try: os.mkdir(self._dirappstmp) except: pass islinux = platform.system() == 'Linux' arm64 = True cmd = self._adb + ' shell "getprop ro.product.cpu.abi"' ret = execShell(cmd) if 'd' in ret.keys() and 'arm64' not in ret.get('d'): arm64 = False #android9出现cdex if self._androidver >= '9': cdextool = 'cdex_converter64' if not arm64: cdextool = 'cdex_converter32' cmd = self._adb + ' shell "ls /data/local/tmp/' + cdextool + ' "' ret = execShell(cmd) if 'No such file' in str(ret): if not os.path.isfile(self._dirinter + cdextool): logging.info('从android9+ 手机下载app,需要compact-dex-converter') logging.error( '先下载{} 链接: https://pan.baidu.com/s/1VMKyJ3n4ubiXeqICNatzYw 提取码: q8fk 保存到inter目录下' .format(cdextool)) else: cmd = self._adb + ' push ' + self._dirinter + cdextool + ' /data/local/tmp/' ret = execShell(cmd) if 'd' in ret.keys(): logging.info('push compact-dex-converter success') cmd = self._adb + ' shell "su -c \' chmod +x /data/local/tmp/' + cdextool + ' \' " ' ret = execShell(cmd) #android7.0出现vdex,在手机上执行转换 if self._androidver >= '7': vdextool = 'vdexExtractor64' if not arm64: vdextool = 'vdexExtractor32' cmd = self._adb + ' shell "ls /data/local/tmp/' + vdextool + ' "' ret = execShell(cmd) if 'No such file' in str(ret): if not os.path.isfile(self._dirinter + vdextool): logging.info('从android7+ 手机下载app,需要vdexExtractor') logging.error( '先下载{} 链接: https://pan.baidu.com/s/1VMKyJ3n4ubiXeqICNatzYw 提取码: q8fk 保存到inter目录下' .format(vdextool)) else: cmd = self._adb + ' push ' + self._dirinter + vdextool + ' /data/local/tmp/' ret = execShell(cmd) if 'd' in ret.keys(): logging.info('push vdexExtractor success') cmd = self._adb + ' shell "su -c \' chmod +x /data/local/tmp/' + vdextool + ' \' " ' ret = execShell(cmd) #android6未处理odex,需要framework/baksmali for p in pkgs: logging.info('==' + p) sp = self._dirapps + p needDownload = False needPullfromDevice = False #存在APK时,判断是否有dex、是否过期 if os.path.isfile(sp + '.apk'): if self.isDexExist(sp + '.apk'): ver = self.getVersionApk(p) over = self.getVersionOnline(p) dver = self.getVersionDevice(p) if not ver: logging.error('get apk version error') else: #线上存在 if over: tover = over.split(':') if len(tover) == 2: # 检查是否半年未更新,未维护APP直接跳过 lastupdate = datetime.datetime.now( ) - datetime.timedelta(days=180) lastupdate = lastupdate.strftime("%Y-%m-%d") if lastupdate > tover[1]: logging.info('!!outdated') if ver < tover[0]: os.remove(sp + '.apk') #设备是否存在最新版 if dver and dver >= tover[0]: needPullfromDevice = True else: needDownload = True logging.info('old version - online') else: if dver: #切换手机时,版本可高可低 if ver != dver: os.remove(sp + '.apk') needPullfromDevice = True logging.info('version not same - device') else: #app已经不存在 logging.error('app package name changed') else: needPullfromDevice = True os.remove(sp + '.apk') else: if p in self._devicepkg: needPullfromDevice = True else: needDownload = True if needPullfromDevice: cmd = self._adb + ' shell "pm path ' + p + '"' ret = execShell(cmd) # 可能返回多个APK if 'd' in ret.keys() and ret.get('d'): apkpath = ret.get('d').split('\n')[0].split(':')[1] logging.info('Pull from device') cmd = self._adb + ' pull ' + apkpath + ' ' + sp ret = execShell(cmd) if 'd' in ret.keys(): shutil.move(sp, sp + '.apk') if not self.isDexExist( sp + '.apk') and self._androidver >= '7': self.assembleAPP(apkpath, sp, vdextool, cdextool) else: logging.error('pull error' + ret.get('e') + apkpath) else: logging.error('device has no ' + p) if needDownload: #下载 url = packageinfo_get_getpkg(p, False) if url: logging.info('Downloading ') if self.downloadFile(url, sp + '.tmp'): ret = shutil.move(sp + '.tmp', sp + '.apk') else: logging.info('Downlod error ') else: logging.info('!!pkgname not exists') logging.info('====Download done====')
def getPkgListInternet(pkg): return packageinfo_get_getpkg(pkg, True)
def getVersionOnline(self, pkg): return packageinfo_get_getpkg(pkg, True, True)