Use `ro.debuggable` to decide if a device is rootable. (#471)
* Use `ro.debuggable` to decide if a device is rootable.
diff --git a/mobly/controllers/android_device.py b/mobly/controllers/android_device.py
index 504f671..4d89af8 100644
--- a/mobly/controllers/android_device.py
+++ b/mobly/controllers/android_device.py
@@ -436,8 +436,9 @@
self._log_path = os.path.join(self._log_path_base,
'AndroidDevice%s' % self._serial)
self._debug_tag = self._serial
- self.log = AndroidDeviceLoggerAdapter(logging.getLogger(),
- {'tag': self.debug_tag})
+ self.log = AndroidDeviceLoggerAdapter(logging.getLogger(), {
+ 'tag': self.debug_tag
+ })
self.sl4a = None
self.ed = None
self._adb_logcat_process = None
@@ -783,15 +784,7 @@
@property
def is_rootable(self):
- """If the build type is 'user', the device is not rootable.
-
- Other possible build types are 'userdebug' and 'eng', both are rootable.
- We are checking the last four chars of the clean stdout because the
- stdout of the adb command could be polluted with other info like adb
- server startup message.
- """
- build_type_output = self.adb.getprop('ro.build.type').lower()
- return build_type_output[-4:] != 'user'
+ return self.adb.getprop('ro.debuggable') == '1'
@property
def model(self):
diff --git a/tests/mobly/controllers/android_device_test.py b/tests/mobly/controllers/android_device_test.py
index e12e511..eb5129a 100755
--- a/tests/mobly/controllers/android_device_test.py
+++ b/tests/mobly/controllers/android_device_test.py
@@ -706,7 +706,8 @@
self, MockFastboot, MockAdbProxy):
mock_serial = '1'
mock_adb_proxy = MockAdbProxy.return_value
- mock_adb_proxy.getprop.return_value = 'userdebug'
+ # Set getprop to return '1' to indicate the device is rootable.
+ mock_adb_proxy.getprop.return_value = '1'
mock_adb_proxy.has_shell_command.side_effect = lambda command: {
'logpersist.start': True,
'logpersist.stop': True, }[command]