1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

android: Don't error if ADB is already running as root

With recent versions of adb, adb root can fail if the
daemon is already running as root.

Check the raised error message for this case and avoid
raising an error in this scenario.
This commit is contained in:
Marc Bonnici 2022-06-21 16:47:26 +01:00
parent 1196e336a5
commit a585426924

View File

@ -385,9 +385,18 @@ class AdbConnection(ConnectionBase):
def adb_root(self, enable=True):
cmd = 'root' if enable else 'unroot'
output = adb_command(self.device, cmd, timeout=30, adb_server=self.adb_server)
if 'cannot run as root in production builds' in output:
raise TargetStableError(output)
try:
output = adb_command(self.device, cmd, timeout=30, adb_server=self.adb_server)
except subprocess.CalledProcessError as e:
# Ignore if we're already root
if 'adbd is already running as root' in e.output:
pass
else:
raise
else:
# Check separately as this does not cause a error exit code.
if 'cannot run as root in production builds' in output:
raise TargetStableError(output)
AdbConnection._connected_as_root[self.device] = enable
def wait_for_device(self, timeout=30):