Skip to content

Verify adb root took effect and add skip_root option - #1066

Open
xpconanfan wants to merge 1 commit into
masterfrom
root_on_init
Open

xpconanfan wants to merge 1 commit into
masterfrom
root_on_init

Conversation

@xpconanfan

@xpconanfan xpconanfan commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

adb root exits 0 even when adbd refuses to restart as root (e.g. "adbd cannot run as root in production builds"; the exact message varies across OEMs), so Mobly's automatic adb root on debuggable builds could fail without any indication. Separately, there was no way to opt out of automatic rooting, which matters for tests that must behave identically on user and userdebug builds (e.g. CTS).

This PR:

  • AndroidDevice.root_adb() now verifies the outcome via is_adb_root (id -u == 0) after adb root, logs a warning if it did not take effect, and returns a bool. No new exception path, so devices that report ro.debuggable=1 but refuse root keep working as before, just no longer silently.
  • Adds a skip_root option (constructor kwarg + skip_root controller config key, mirroring skip_logcat) that disables automatic adb root at creation time and after handle_reboot. Explicit root_adb() calls are unaffected.

Automatic rooting still happens in __init__, so code that constructs AndroidDevice(serial) directly keeps its current behavior.

Fixes b/419425573 (internal).

Comment thread mobly/controllers/android_device.py Outdated

def _root_adb_on_init(self):
"""Runs `adb root` on rootable builds according to `root_on_init`."""
if self.root_on_init == ROOT_ON_INIT_NEVER or not self.is_rootable:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

there should be a debug/verbose log here so we know what happened

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added debug logs when skipping automatic adb root (both when root_on_init is "never" and when the build is not rootable), and moved _root_adb_on_init() out of AndroidDevice.__init__ into get_instances / get_instances_with_configs (with root_on_init as a validated settable property loaded via load_config).

@xpconanfan
xpconanfan force-pushed the root_on_init branch 2 times, most recently from 449781a to 99233bf Compare October 12, 2026 20:48
@xpconanfan xpconanfan changed the title Fix silent adb root failures and add root_on_init option Verify adb root took effect and add skip_root option Oct 23, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant