text stringlengths 1 93.6k |
|---|
device._write(SESSION_ID, info)
|
run = device._commit(SESSION_ID)
|
device._del(info)
|
if run.returncode:
|
return info, False
|
return info, True
|
def install_multiple(device: Device, install: List[str]) -> Tuple[List[str], bool]:
|
"""install-multiple"""
|
run = device.adb(install)[0]
|
if run.returncode:
|
if install[1] == '-rtd':
|
install[1] = '-r'
|
log.info("正在修改安装参数重新安装,请等待...")
|
return install_multiple(device, install)
|
elif install[1] == 'r':
|
install[1] = ''
|
log.info("正在修改安装参数重新安装,请等待...")
|
return install_multiple(device, install)
|
elif install[1] == '':
|
print_err(tostr(run.stderr))
|
try:
|
log.info("使用备用方案")
|
run = install_base(device, install[2:])[1]
|
if not run.returncode:
|
return install, True
|
except Exception:
|
log.exception('Failed in install_multiple->install_base.')
|
return install, False
|
def install_xapk(device: Device, file: str, del_path: List[str], root: str) -> Tuple[List[Union[str, List[str]]], bool]:
|
"""安装xapk文件"""
|
os.chdir(file)
|
log.info("开始安装...")
|
if not os.path.isfile("manifest.json"):
|
sys.exit(f"安装失败:路径中没有`manifest.json`。{file!r}不是`xapk`安装包的解压路径!")
|
manifest = read_json("manifest.json")
|
if not manifest.get("expansions"):
|
split_apks = manifest["split_apks"]
|
if device.sdk < int(manifest["min_sdk_version"]):
|
sys.exit(info_msg['sdktoolow'])
|
elif device.sdk > int(manifest["target_sdk_version"]):
|
log.info("警告:安卓版本过高!可能存在兼容性问题!")
|
install = ["install-multiple", "-rtd"]
|
config, install = build_xapk_config(device, split_apks, install)
|
checkVersion(device, manifest["package_name"], manifest["version_code"], config.get('abi'))
|
config, install = config_abi(config, install, device.abilist)
|
config, install = config_drawable(config, install)
|
config, install = config_language(config, install)
|
return install_multiple(device, install)
|
else:
|
install = install_apk(device, manifest["package_name"]+".apk", del_path, root)[0]
|
expansions = manifest["expansions"]
|
for i in expansions:
|
if i["install_location"] == "EXTERNAL_STORAGE":
|
push: List[str] = ["push", i["file"], "/storage/emulated/0/"+i["install_path"]]
|
if device.adb(push)[0].returncode:
|
return [install, push], False
|
return [install, push], True
|
else:
|
sys.exit(1)
|
# device: Device, file: str, del_path: List[str], root: str[, abc: str] -> Tuple[List[Union[str, List[str]]], bool]
|
installSuffix = [".aab", ".apk", ".apkm", ".apks", ".xapk"]
|
installSelector = {".aab": install_aab, ".apk": install_apk, ".apkm": install_apkm, ".apks": install_apks,
|
".xapk": install_xapk}
|
def main(root: str, one: str) -> bool:
|
os.chdir(root)
|
name_suffix = os.path.split(one)[1]
|
name_suffix = name_suffix.rsplit(".", 1)
|
new_path = md5(name_suffix[0]) # md5 用处:避免莫名其妙的文件名导致意料之外的问题
|
if len(name_suffix) > 1:
|
new_path += f".{name_suffix[1]}"
|
del_path = [os.path.join(root, new_path)]
|
copy = [one, del_path[0]]
|
copy_files(copy)
|
try:
|
ADB = check_sth('adb')
|
devices = check(ADB)
|
if len(devices) == 0:
|
sys.exit("安装失败:手机未连接电脑!")
|
suffix = os.path.splitext(os.path.split(copy[1])[1])[1]
|
for device in devices:
|
device = Device(device)
|
device.ADB = ADB
|
if copy[1].endswith(".xapk"):
|
del_path.append(unpack(copy[1]))
|
os.chdir(del_path[-1])
|
elif suffix in installSuffix:
|
return installSelector[suffix](device, copy[1], del_path, root)[1]
|
elif os.path.isfile(copy[1]):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.