-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpackage_info.py
49 lines (38 loc) · 1.41 KB
/
package_info.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
from py_adb.adb import ADB
class PackageInfo:
@staticmethod
def get_list_packages(dev_id: str) -> list:
"""
Return a list of installed packages on the device
"""
command = "adb -s {dev_id} shell pm list packages".format(dev_id=dev_id)
raw_packages = ADB.get_terminal_output(command)
return [x.strip() for x in raw_packages]
@staticmethod
def is_package_exist(dev_id, package) -> bool:
"""
Method check is package installed on the device
"""
check = "package:{pack}".format(pack=package)
for pack in PackageInfo.get_list_packages(dev_id):
print(pack)
if check == pack.lower():
return True
return False
@staticmethod
def get_package_version(dev_id: str, package: str) -> list:
"""
Return a package version
:dev_id: device id
:package: package name
"""
command = "adb -s {dev_id} shell dumpsys package {package} | grep versionName".format(
dev_id=dev_id, package=package)
raw_out = ADB.get_terminal_output(command)
versions = []
for ver in raw_out:
versions.append(ver.strip().split("=")[1])
return versions
# if __name__ == "__main__":
# dev_id = ADB.get_connected_devices()[0]
# x = PackageInfo.get_packages_version(dev_id, AndroidKPackage.YOUTUBE)