From 72e4443b7dba3eacf91b9b8c7e185bfbb10d4a1c Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Tue, 27 Aug 2019 14:12:07 +0100 Subject: [PATCH] AdbConnection: Enable `adb_as_root` as a connection parameter To allow for connecting to an `AndroidTarget` as root before the target has been initialised, allow for passing `adb_as_root` as a connection parameter to the `AdbConnection`. This will restart `adbd` as root before attempting to connect to the target and will restart as unrooted once all connections to that target have been closed. --- devlib/utils/android.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/devlib/utils/android.py b/devlib/utils/android.py index 3a341be..f10e370 100755 --- a/devlib/utils/android.py +++ b/devlib/utils/android.py @@ -260,12 +260,16 @@ class AdbConnection(object): # pylint: disable=unused-argument - def __init__(self, device=None, timeout=None, platform=None, adb_server=None): + def __init__(self, device=None, timeout=None, platform=None, adb_server=None, + adb_as_root=False): self.timeout = timeout if timeout is not None else self.default_timeout if device is None: device = adb_get_device(timeout=timeout, adb_server=adb_server) self.device = device self.adb_server = adb_server + self.adb_as_root = adb_as_root + if self.adb_as_root: + self.adb_root(enable=True) adb_connect(self.device) AdbConnection.active_connections[self.device] += 1 self._setup_ls() @@ -312,6 +316,8 @@ class AdbConnection(object): def close(self): AdbConnection.active_connections[self.device] -= 1 if AdbConnection.active_connections[self.device] <= 0: + if self.adb_as_root: + adb_root(self.device, enable=False) adb_disconnect(self.device) del AdbConnection.active_connections[self.device]