Skip to content

Commit 8f3f527

Browse files
authored
chore: add more types (#300)
1 parent b42cad0 commit 8f3f527

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

adbe/adb_enhanced.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def func_wrapper(package_name, *args, **kwargs):
100100
return func_wrapper
101101

102102

103-
def _package_exists(package_name):
103+
def _package_exists(package_name: str) -> bool:
104104
cmd = f"pm path {package_name}"
105105
return_code, response, _ = execute_adb_shell_command2(cmd)
106106
return return_code == 0 and response is not None and len(response.strip()) != 0
@@ -142,7 +142,7 @@ def handle_gfx(value) -> None:
142142

143143
# Source: https://github.com/dhelleberg/android-scripts/blob/master/src/devtools.groovy
144144
# https://plus.google.com/+AladinQ/posts/dpidzto1b8B
145-
def handle_overdraw(value) -> None:
145+
def handle_overdraw(value: str) -> None:
146146
version = get_device_android_api_version()
147147

148148
if version < 19:
@@ -221,7 +221,7 @@ def handle_layout(*, turn_on: bool) -> None:
221221

222222

223223
# Source: https://stackoverflow.com/questions/10506591/turning-airplane-mode-on-via-adb
224-
def handle_airplane(*, turn_on: bool):
224+
def handle_airplane(*, turn_on: bool) -> str | None:
225225
state = 1 if turn_on else 0
226226
return_code, su_path, _ = execute_adb_shell_command2("which su")
227227
if not return_code and su_path and len(su_path):
@@ -411,7 +411,7 @@ def handle_get_jank(app_name: str) -> None:
411411
force_stop(app_name)
412412

413413

414-
def _is_app_running(app_name: str):
414+
def _is_app_running(app_name: str) -> bool:
415415
return_code, result, _ = execute_adb_shell_command2("ps -o NAME")
416416
if return_code != 0 or not result:
417417
return False
@@ -496,7 +496,7 @@ def print_top_activity() -> None:
496496
print_message(f"Activity name: {activity_name}")
497497

498498

499-
def _get_top_activity_data():
499+
def _get_top_activity_data() -> tuple[None, None] | tuple:
500500
cmd = "dumpsys window windows"
501501
return_code, output, _ = execute_adb_shell_command2(cmd)
502502
if return_code != 0 and not output:
@@ -555,7 +555,7 @@ def clear_disk_data(app_name: str) -> None:
555555
print_error_and_exit(f'Failed to clear data of "{app_name}"')
556556

557557

558-
def get_mobile_data_state():
558+
def get_mobile_data_state() -> str:
559559
# Using "adb shell dumpsys telephony.registry | ag mDataConnectionState"
560560
cmd = "dumpsys telephony.registry"
561561
return_code, stdout, _ = execute_adb_shell_command2(cmd)
@@ -678,7 +678,7 @@ def signal_handler(_sig, _frame) -> None:
678678
screen_record_file_path_on_device = _start_recording()
679679

680680

681-
def get_mobile_data_saver_state():
681+
def get_mobile_data_saver_state() -> str:
682682
cmd = "cmd netpolicy get restrict-background"
683683
return_code, stdout, _ = execute_adb_shell_command2(cmd)
684684
if return_code != 0:
@@ -699,7 +699,7 @@ def handle_mobile_data_saver(*, turn_on: bool) -> None:
699699
print_error_and_exit("Failed to modify data saver mode setting")
700700

701701

702-
def get_dont_keep_activities_in_background_state():
702+
def get_dont_keep_activities_in_background_state() -> str:
703703
cmd = "get global always_finish_activities"
704704
return_code, stdout, _ = execute_adb_shell_settings_command2(cmd)
705705
if return_code != 0:
@@ -751,7 +751,7 @@ def toggle_animations(*, turn_on: bool) -> None:
751751
execute_adb_shell_settings_command(cmd3)
752752

753753

754-
def get_show_taps_state():
754+
def get_show_taps_state() -> str:
755755
cmd = "get system show_touches"
756756
return_code, stdout, _ = execute_adb_shell_settings_command2(cmd)
757757
if return_code != 0:
@@ -775,7 +775,7 @@ def toggle_show_taps(*, turn_on: bool) -> None:
775775
execute_adb_shell_settings_command(cmd)
776776

777777

778-
def get_stay_awake_while_charging_state():
778+
def get_stay_awake_while_charging_state() -> str:
779779
cmd = "get global stay_on_while_plugged_in"
780780
return_code, stdout, _ = execute_adb_shell_settings_command2(cmd)
781781
if return_code != 0:
@@ -847,7 +847,7 @@ def list_permissions(*, dangerous_only_permissions: bool) -> None:
847847

848848

849849
# Creates a tmp file on Android device
850-
def _create_tmp_file(filename_prefix=None, filename_suffix=None):
850+
def _create_tmp_file(filename_prefix=None, filename_suffix=None) -> str | None:
851851
if filename_prefix is None:
852852
filename_prefix = "file"
853853
if filename_suffix is None:
@@ -882,7 +882,7 @@ def _create_tmp_file(filename_prefix=None, filename_suffix=None):
882882

883883

884884
# Returns true if the file_path exists on the device, false if it does not exists or is inaccessible.
885-
def _file_exists(file_path):
885+
def _file_exists(file_path) -> bool:
886886
exists_cmd = f'"ls {file_path} 1>/dev/null 2>/dev/null && echo exists"'
887887
stdout = execute_file_related_adb_shell_command(exists_cmd, file_path)
888888
return stdout is not None and stdout.find("exists") != -1
@@ -968,7 +968,7 @@ def _get_hardcoded_permissions_for_group(permission_group: str) -> list[str]:
968968

969969

970970
# Pass the full-qualified permission group name to this method.
971-
def get_permissions_in_permission_group(permission_group):
971+
def get_permissions_in_permission_group(permission_group) -> list[str] | list | None:
972972
# List permissions by group
973973
cmd = "pm list permissions -g"
974974
return_code, stdout, stderr = execute_adb_shell_command2(cmd)
@@ -1026,7 +1026,7 @@ def grant_or_revoke_runtime_permissions(package_name, action_grant, permissions)
10261026
print_error_and_exit(f"None of these permissions were granted to {package_name}: {permissions}")
10271027

10281028

1029-
def _get_all_packages(pm_cmd):
1029+
def _get_all_packages(pm_cmd) -> list:
10301030
return_code, result, _ = execute_adb_shell_command2(pm_cmd)
10311031
if return_code != 0:
10321032
print_error_and_exit(f'Command "{pm_cmd}" failed, something is wrong')
@@ -1044,7 +1044,7 @@ def _get_all_packages(pm_cmd):
10441044
# For now, we can live with this discrepancy but in the longer run we want to fix those
10451045
# other functions as well
10461046
# https://stackoverflow.com/questions/63416599/adb-shell-pm-list-packages-missing-some-packages
1047-
def get_list_all_apps():
1047+
def get_list_all_apps() -> tuple | tuple[None, str, bytes | str]:
10481048
"""This function return a list of installed applications, error message and command
10491049
execution error
10501050
:returns: tuple(all_apps, err_msg, error)
@@ -1083,7 +1083,7 @@ def print_list_all_apps() -> None:
10831083
print_message("\n".join(all_apps))
10841084

10851085

1086-
def get_list_system_apps():
1086+
def get_list_system_apps() -> list:
10871087
"""This function return a list of installed system applications
10881088
:returns: system_apps_packages
10891089
WHERE
@@ -1106,7 +1106,7 @@ def list_system_apps() -> None:
11061106
print("\n".join(packages))
11071107

11081108

1109-
def get_list_non_system_apps():
1109+
def get_list_non_system_apps() -> list:
11101110
"""Return a list of installed third party applications.
11111111
:returns: third_party_pkgs
11121112
WHERE
@@ -1128,7 +1128,7 @@ def print_list_non_system_apps() -> None:
11281128
print("\n".join(get_list_non_system_apps()))
11291129

11301130

1131-
def get_list_debug_apps():
1131+
def get_list_debug_apps() -> list:
11321132
"""Return a list of installed debug applications.
11331133
:returns: debug_packages
11341134
WHERE
@@ -1174,7 +1174,7 @@ def _is_debug_package(app_name: str) -> tuple[str | None, bool]:
11741174
return _package_contains_flag(app_name, _REGEX_DEBUGGABLE)
11751175

11761176

1177-
def list_allow_backup_apps():
1177+
def list_allow_backup_apps() -> list:
11781178
"""Return list of applications that can be backed up (flag backup set to true)
11791179
:returns: list[str] packages that have backup flag set to true
11801180
:Example:
@@ -1208,7 +1208,7 @@ def print_allow_backup_apps() -> None:
12081208
print("\n".join(list_allow_backup_apps()))
12091209

12101210

1211-
def _is_allow_backup_package(app_name: str):
1211+
def _is_allow_backup_package(app_name: str) -> tuple[str | None, bool]:
12121212
return _package_contains_flag(app_name, _REGEX_BACKUP_ALLOWED)
12131213

12141214

@@ -1239,7 +1239,7 @@ def _package_contains_flag(app_name: str, flag_regex: str) -> tuple[str | None,
12391239

12401240
# Source: https://developer.android.com/preview/features/power#buckets
12411241
@ensure_package_exists
1242-
def get_standby_bucket(package_name) -> None:
1242+
def get_standby_bucket(package_name: str) -> None:
12431243
_error_if_min_version_less_than(28)
12441244
cmd = f"am get-standby-bucket {package_name}"
12451245
result = execute_adb_shell_command(cmd)

adbe/adb_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def execute_adb_command2(
109109
return None
110110

111111

112-
def execute_adb_shell_command(adb_cmd: str, piped_into_cmd: bool | None = None, ignore_stderr: bool = False,
112+
def execute_adb_shell_command(adb_cmd: str, piped_into_cmd: str | None = None, ignore_stderr: bool = False,
113113
device_serial: str | None = None) -> str:
114114
_, stdout, _ = execute_adb_command2(
115115
f"shell {adb_cmd}", piped_into_cmd, ignore_stderr, device_serial=device_serial)

0 commit comments

Comments
 (0)