Skip to content

Conversation

@mhaoli
Copy link
Collaborator

@mhaoli mhaoli commented Aug 8, 2025

API AndroidDevice#take_screenshot fails when debug tag contains bracket characters.

The root cause is that adb shell do not automatically handle special characters like brackets. So this PR adds double quotations to args of adb.shell calls.

Bracket characters do not affect most Mobly provided APIs, e.g. calling adb.pull with bracket characters works well.

Tested locally.


This change is Reviewable

@mhaoli mhaoli added this to the Mobly Release 1.13.1 milestone Aug 8, 2025
@mhaoli mhaoli self-assigned this Aug 8, 2025
@mhaoli mhaoli added the bug label Aug 8, 2025
@mhaoli mhaoli requested a review from xpconanfan August 8, 2025 15:57
@xpconanfan
Copy link
Collaborator

xpconanfan commented Aug 11, 2025 via email

@mhaoli
Copy link
Collaborator Author

mhaoli commented Aug 12, 2025

Debug tag shouldn't contain slashes in the first place, no? Why does a debug tag need to contain "/"? It'll cause all kinds of problems in other places

On Mon, Aug 11, 2025, 03:17 Minghao Li @.> wrote: @.* commented on this pull request. ------------------------------ In tests/mobly/controllers/android_device_test.py <#986 (comment)>: > @@ -1301,6 +1348,64 @@ def custom_shell_for_screenshot(params, timeout=None): ], ) + @mock.patch( + 'mobly.controllers.android_device_lib.adb.AdbProxy', + return_value=mock_android_device.MockAdbProxy('1'), + ) + @mock.patch( + 'mobly.controllers.android_device_lib.fastboot.FastbootProxy', + return_value=mock_android_device.MockFastbootProxy('1'), + ) + @mock.patch('mobly.utils.create_dir') + @mock.patch('mobly.logger.get_log_file_timestamp') + def test_AndroidDevice_take_screenshot_all_displays_add_double_quotations( Modified, PTAL, thanks. The use case is that current implementation fails when debug_tag contains "(" / ")" character. — Reply to this email directly, view it on GitHub <#986 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARDNZKC2HACWMUHKAFTVTL3NBUSBAVCNFSM6AAAAACDOHYBCOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTCMBVGEZDANBQGQ . You are receiving this because your review was requested.Message ID: @.***>

Sorry my previous reply looks confusing in email.

The problem is not due to slashes, but brackets. E.g., my test sets debug tag to <serial>(Requester) and then take_screenshot fails.

Also, this does not cause failure for most mobly provided APIs, I only noticed failure in take_screenshot. This is because commands like adb pull supports handling brackets, but abd shell does not.

@xpconanfan
Copy link
Collaborator

Ok, a test should cover this actual case instead?
And the title of the PR should reflect the end goal, not the approach

@mhaoli mhaoli changed the title Add double quotations to adb.shell calls Fix AndroidDevice#take_screenshot failure when debug tag contains bracket characters Aug 12, 2025
@mhaoli
Copy link
Collaborator Author

mhaoli commented Aug 12, 2025

Do you mean add an integration test case in internal codebase?

@mhaoli mhaoli changed the title Fix AndroidDevice#take_screenshot failure when debug tag contains bracket characters Fix AndroidDevice#take_screenshot failure caused by bracket characters Aug 12, 2025
@mhaoli
Copy link
Collaborator Author

mhaoli commented Aug 12, 2025

Now we have unit tests for this CUJ. I'm creating the CL for a integration test case internally.
Updated PR title and description.

Copy link
Collaborator

@xpconanfan xpconanfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If path validation is common across the code base, should we utilize https://pypi.org/project/pathvalidate/ ?

return [ad.serial for ad in get_mock_ads(5)]


def _assert_valid_path_in_adb_shell_cmd(path: str):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything specific to "adb shell" in this function.
Also this seems like an overkill, with many questionable checks...

Might be more straightforward to perform the actual check needed in the test case instead.

)
elif 'which' in params:
return b''
elif isinstance(params, list) and params and params[0] == 'rm':
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is too much logic
I don't think anybody else could understand and maintain these effectively.

consider doing the proper validation in each test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants