-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreinstall_apps.py
More file actions
57 lines (51 loc) · 2.47 KB
/
reinstall_apps.py
File metadata and controls
57 lines (51 loc) · 2.47 KB
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
54
55
56
57
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from android_scripts_python.library import main_functions
from android_scripts_python.library.device_operations import display_selected_device, is_adb_device, is_at_home_device
from android_scripts_python.library.machine_file_operations import build_machine_files_list
from android_scripts_python.library.configure_machine import myAppDir
from android_scripts_python.library.apk_operations import apk_operations
from android_scripts_python.library.text_formatting import pbold, format_message
def uninstall_all_apks(device_serial):
# Uninstall all user-installed APKs
output = main_functions.adb_shell(device_serial, "shell", "pm", "list", "packages", "-3")
pkgs = [line.split(":")[-1].strip() for line in output.splitlines() if line.strip()]
for pkg in pkgs:
format_message(f"Uninstalling {pkg} ...", "W")
main_functions.adb_shell(device_serial, "shell", "uninstall", pkg)
def install_all_apks_from_folder(device_serial, folder):
files = build_machine_files_list(folder, ".apk")
if not files:
format_message(f"There are no APK files in the directory: {folder}\n", "E")
return
for apk_path in files:
apk_name = os.path.basename(apk_path)
yn = input(f"Do you want to install [y/n] - {apk_name}: ")
if yn.lower() == 'y':
print(f"\nInstalling {apk_name} ...")
output = main_functions.adb_shell(device_serial, "wait-for-device", "install", "-r", "-d", apk_path)
print(output)
print("...Done\n")
def main():
main_functions.get_device_choice()
display_selected_device(main_functions.deviceSerial)
if not is_adb_device(main_functions.deviceSerial):
format_message(" Device is not in adb mode", "E")
return
if is_at_home_device(main_functions.deviceSerial):
format_message(" Installing Apps is not allowed in @Home device ...\n", "E")
return
if len(sys.argv) < 2:
pbold("\n Enter the Folder name (Case-sensitive) : ")
build = input().strip()
else:
build = sys.argv[1]
folder_path = os.path.join(myAppDir, build)
if not os.path.isdir(folder_path):
format_message(f"Subfolder '{build}' does not exist in {myAppDir}\n", "E")
return
uninstall_all_apks(main_functions.deviceSerial)
install_all_apks_from_folder(main_functions.deviceSerial, folder_path)
if __name__ == "__main__":
main()