-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfix_ing.py
53 lines (38 loc) · 1.56 KB
/
fix_ing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
import re
import logging
import subprocess
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
ing_package = "pl.ing.mojeing"
google_installer = "com.android.vending"
def shell(*args) -> str:
prefix = ["adb", "shell"]
return subprocess.check_output(prefix + list(args)).decode()
def pm(*args) -> str:
return shell("pm", *args)
def adb_devices() -> None:
logging.info("Initializing connection with device via ADB")
logging.info("You may need to accept connection on a dialog in your phone.")
subprocess.check_call("adb devices".split())
def get_size(file_path) -> str:
return str(int(shell("stat", "-c", "%s", file_path)))
def main() -> None:
adb_devices()
out = pm("path", ing_package)
apks = [x.split(":")[1] for x in out.splitlines()]
logger.info(f"Found APKs {apks=}")
copied_paths = [f"/data/local/tmp/ing_{i}.apk" for i in range(len(apks))]
for name, apk in zip(copied_paths, apks):
shell("cp", apk, name)
logger.info("Copied split apk files to /data/local/tmp/")
pm('uninstall', ing_package)
logger.info("Uninstalled old version.")
out = pm("install-create", "-S", str(len(apks)), "-i", google_installer)
installation_id = re.findall(r"\[(\d+)\]", out)[0]
logger.info(f"Current {installation_id=}.")
for i, name in enumerate(copied_paths):
pm("install-write", "-S", get_size(name), str(installation_id), str(i), name)
logger.info("Finished, status = " + pm('install-commit', str(installation_id)))
if __name__ == '__main__':
main()