ignore if adb root fails and prints more logging info for diagnosis
Change-Id: I7fa2776db5c2c43e2d872e9004e2e18b67e428ef
diff --git a/utils/python/controllers/adb.py b/utils/python/controllers/adb.py
index 00f952a..252a3ad 100644
--- a/utils/python/controllers/adb.py
+++ b/utils/python/controllers/adb.py
@@ -16,6 +16,7 @@
from builtins import str
+import logging
import random
import socket
import subprocess
@@ -118,13 +119,13 @@
indicator of cmd execution status.
Args:
- cmds: A string that is the adb command to execute.
+ cmd: string, the adb command to execute.
Returns:
- The output of the adb command run if exit code is 0.
+ The output of the adb command run if the exit code is 0.
Raises:
- AdbError is raised if the adb command exit code is not 0.
+ AdbError if the adb command exit code is not 0.
"""
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
@@ -133,10 +134,11 @@
# TODO(angli): Fix this when global logger is done.
if self.log:
self.log.debug("{}\n{}".format(cmd, total_output))
- if ret == 0:
- return out
- else:
+ if ret != 0:
+ logging.error("adb '%s' failed error code %s", cmd, ret)
+ logging.error("total_output: %s", total_output)
raise AdbError(total_output)
+ return out
def _exec_adb_cmd(self, name, arg_str):
return self._exec_cmd(' '.join((self.adb_str, name, arg_str)))
diff --git a/utils/python/controllers/android_device.py b/utils/python/controllers/android_device.py
index 607400a..7269a95 100644
--- a/utils/python/controllers/android_device.py
+++ b/utils/python/controllers/android_device.py
@@ -333,20 +333,19 @@
@property
def isBootloaderMode(self):
- """True if the device is in bootloader mode.
- """
+ """True if the device is in bootloader mode."""
return self.serial in list_fastboot_devices()
@property
def isAdbRoot(self):
- """True if adb is running as root for this device.
- """
- return "root" in self.adb.shell("id -u").decode("utf-8")
+ """True if adb is running as root for this device."""
+ id_str = self.adb.shell("id -u").decode("utf-8")
+ self.log.info(id_str)
+ return "root" in id_str
@property
def model(self):
- """The Android code name for the device.
- """
+ """The Android code name for the device."""
# If device is in bootloader mode, get mode name from fastboot.
if self.isBootloaderMode:
out = self.fastboot.getvar("product").strip()
@@ -393,10 +392,13 @@
setattr(self, k, v)
def rootAdb(self):
- """Change adb to root mode for this device.
- """
+ """Changes adb to root mode for this device."""
if not self.isAdbRoot:
- self.adb.root()
+ try:
+ self.adb.root()
+ except adb.AdbError as e:
+ # adb root is not always possible in the lab
+ logging.exception(e)
self.adb.wait_for_device()
self.adb.remount()
self.adb.wait_for_device()