mirror of
https://github.com/ARM-software/devlib.git
synced 2025-02-25 22:17:51 +00:00
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 <patrick.bellasi@arm.com>
This commit is contained in:
parent
da588ea091
commit
9ce57c0875
@ -62,10 +62,11 @@ class Target(object):
|
|||||||
return self.conn is not None
|
return self.conn is not None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@memoized
|
|
||||||
def connected_as_root(self):
|
def connected_as_root(self):
|
||||||
result = self.execute('id')
|
if self._connected_as_root is None:
|
||||||
return 'uid=0(' in result
|
result = self.execute('id')
|
||||||
|
self._connected_as_root = 'uid=0(' in result
|
||||||
|
return self._connected_as_root
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@memoized
|
@memoized
|
||||||
@ -151,6 +152,7 @@ class Target(object):
|
|||||||
shell_prompt=DEFAULT_SHELL_PROMPT,
|
shell_prompt=DEFAULT_SHELL_PROMPT,
|
||||||
conn_cls=None,
|
conn_cls=None,
|
||||||
):
|
):
|
||||||
|
self._connected_as_root = None
|
||||||
self.connection_settings = connection_settings or {}
|
self.connection_settings = connection_settings or {}
|
||||||
# Set self.platform: either it's given directly (by platform argument)
|
# Set self.platform: either it's given directly (by platform argument)
|
||||||
# or it's given in the connection_settings argument
|
# or it's given in the connection_settings argument
|
||||||
@ -1035,6 +1037,19 @@ class AndroidTarget(Target):
|
|||||||
def clear_logcat(self):
|
def clear_logcat(self):
|
||||||
adb_command(self.adb_name, 'logcat -c', timeout=30)
|
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):
|
def is_screen_on(self):
|
||||||
output = self.execute('dumpsys power')
|
output = self.execute('dumpsys power')
|
||||||
match = ANDROID_SCREEN_STATE_REGEX.search(output)
|
match = ANDROID_SCREEN_STATE_REGEX.search(output)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user