Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement setting and clearing debug app #234

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
ashishb marked this conversation as resolved.
Show resolved Hide resolved
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
11 changes: 11 additions & 0 deletions tests/adbe_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,16 @@ def test_location():
check("location off")


def test_debug_app():
_assert_success('debug-app set %s' % _TEST_APP_ID)
_assert_success('debug-app set %s -w' % _TEST_APP_ID)
_assert_success('debug-app set %s -p' % _TEST_APP_ID)
_assert_success('debug-app set %s -p -w' % _TEST_APP_ID)
_assert_fail('debug-app set %s' % _TEST_NON_EXISTANT_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 +564,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
Loading