From e9eb030bbd9486d7785bd97d617e6f62ee908a85 Mon Sep 17 00:00:00 2001 From: Denis Buzmakov Date: Mon, 8 Apr 2024 22:49:28 +0200 Subject: [PATCH] Implement setting and clearing debug app (#234) * Implement setting and clearing debug app * Try to remove unnecessary tests * Leave only simple set and clear test --------- Co-authored-by: Ashish Bhatia --- adbe/adb_enhanced.py | 16 ++++++++++++++++ adbe/main.py | 5 +++++ tests/adbe_tests.py | 6 ++++++ 3 files changed, 27 insertions(+) diff --git a/adbe/adb_enhanced.py b/adbe/adb_enhanced.py index ccbf4e3..8d61a09 100755 --- a/adbe/adb_enhanced.py +++ b/adbe/adb_enhanced.py @@ -2090,6 +2090,22 @@ def toggle_location(turn_on): execute_adb_shell_settings_command(cmd) +@ensure_package_exists +def set_debug_app(app_name, wait_for_debugger, persistent): + cmd = 'am set-debug-app' + if wait_for_debugger: + cmd += ' -w' + if persistent: + cmd += ' --persistent' + cmd += ' %s' % app_name + execute_adb_shell_command2(cmd) + + +def clear_debug_app(): + cmd = 'am clear-debug-app' + execute_adb_shell_command2(cmd) + + # This permissions group seems to have been removed in API 29 and beyond. # https://github.com/ashishb/adb-enhanced/runs/1799363523?check_suite_focus=true def is_permission_group_unavailable_after_api_29(permission_group): diff --git a/adbe/main.py b/adbe/main.py index 26db28b..d833980 100755 --- a/adbe/main.py +++ b/adbe/main.py @@ -39,6 +39,7 @@ adbe [options] cat adbe [options] clear-data adbe [options] dark mode (on | off) + adbe [options] debug-app (set [-w] [-p] | clear) adbe [options] devices adbe [options] (enable | disable) wireless debugging adbe [options] dont-keep-activities (on | off) @@ -297,6 +298,10 @@ def _get_actions(args: typing.Dict[str, typing.Any]) -> typing.Dict[typing.Tuple ('top-activity',): adb_enhanced.print_top_activity, ('screenshot', ): lambda: adb_enhanced.dump_screenshot(args['']), ('screenrecord',): lambda: adb_enhanced.dump_screenrecord(args['']), + + # Debug app + ('debug-app', 'set'): lambda: adb_enhanced.set_debug_app(args[''], args['-w'], args['-p']), + ('debug-app', 'clear'): lambda: adb_enhanced.clear_debug_app, } diff --git a/tests/adbe_tests.py b/tests/adbe_tests.py index eec4259..72593b2 100644 --- a/tests/adbe_tests.py +++ b/tests/adbe_tests.py @@ -465,6 +465,11 @@ def test_location(): check("location off") +def test_debug_app(): + _assert_success('debug-app set %s' % _TEST_APP_ID) + _assert_success('debug-app clear') + + def _assert_fail(sub_cmd): exit_code, stdout_data, stderr_data = _execute(sub_cmd) assert exit_code == 1, 'Command "%s" failed with stdout: "%s" and stderr: "%s"' %(sub_cmd, stdout_data, stderr_data) @@ -554,6 +559,7 @@ def main(): test_screen_toggle() test_notifications() test_location() + test_debug_app() # TODO: Add a test for screen record after figuring out how to perform ^C while it is running.