Skip to content

Commit

Permalink
Implement setting and clearing debug app (#234)
Browse files Browse the repository at this point in the history
* Implement setting and clearing debug app

* Try to remove unnecessary tests

* Leave only simple set and clear test

---------

Co-authored-by: Ashish Bhatia <ashishb@ashishb.net>
  • Loading branch information
bacecek and ashishb committed Apr 8, 2024
1 parent 9ff6024 commit e9eb030
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions adbe/adb_enhanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions adbe/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
adbe [options] cat <file_path>
adbe [options] clear-data <app_name>
adbe [options] dark mode (on | off)
adbe [options] debug-app (set [-w] [-p] <app_name> | clear)
adbe [options] devices
adbe [options] (enable | disable) wireless debugging
adbe [options] dont-keep-activities (on | off)
Expand Down Expand Up @@ -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['<filename.png>']),
('screenrecord',): lambda: adb_enhanced.dump_screenrecord(args['<filename.mp4>']),

# Debug app
('debug-app', 'set'): lambda: adb_enhanced.set_debug_app(args['<app_name>'], args['-w'], args['-p']),
('debug-app', 'clear'): lambda: adb_enhanced.clear_debug_app,
}


Expand Down
6 changes: 6 additions & 0 deletions tests/adbe_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.


Expand Down

0 comments on commit e9eb030

Please sign in to comment.