From 9ce57c087581d8d2637936d19ad403e2b6e4a83f Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Thu, 16 Feb 2017 13:11:02 +0000 Subject: [PATCH] AndroidTarget: add support to reboot a device via ADB This adds a couple of commodity ADB commands to reboot in bootloader mode and to restart ADB in root mode. Signed-off-by: Patrick Bellasi --- devlib/target.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/devlib/target.py b/devlib/target.py index 92d8367..9d274a2 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -62,10 +62,11 @@ class Target(object): return self.conn is not None @property - @memoized def connected_as_root(self): - result = self.execute('id') - return 'uid=0(' in result + if self._connected_as_root is None: + result = self.execute('id') + self._connected_as_root = 'uid=0(' in result + return self._connected_as_root @property @memoized @@ -151,6 +152,7 @@ class Target(object): shell_prompt=DEFAULT_SHELL_PROMPT, conn_cls=None, ): + self._connected_as_root = None self.connection_settings = connection_settings or {} # Set self.platform: either it's given directly (by platform argument) # or it's given in the connection_settings argument @@ -1035,6 +1037,19 @@ class AndroidTarget(Target): def clear_logcat(self): adb_command(self.adb_name, 'logcat -c', timeout=30) + def adb_reboot_bootloader(self, timeout=30): + adb_command(self.adb_name, 'reboot-bootloader', timeout) + + def adb_root(self, enable=True): + if enable: + if self._connected_as_root: + return + adb_command(self.adb_name, 'root', timeout=30) + self._connected_as_root = True + return + adb_command(self.adb_name, 'unroot', timeout=30) + self._connected_as_root = False + def is_screen_on(self): output = self.execute('dumpsys power') match = ANDROID_SCREEN_STATE_REGEX.search(output)