Bug 1021756 - Allow to run adbd as root. r=wlach

This allows a device that starts adbd as non-root to restart adbd
every time that is needed to ensure the ability of running
privileged tasks on the device.
This commit is contained in:
Armen Zambrano Gasparnian 2014-08-05 11:58:30 -04:00
Родитель 32cfea205c
Коммит 1cd86432c2
2 изменённых файлов: 68 добавлений и 2 удалений

Просмотреть файл

@ -0,0 +1,46 @@
"""
This test is to test devices that adbd does not get started as root.
Specifically devices that have ro.secure == 1 and ro.debuggable == 1
Running this test case requires various reboots which makes it a
very slow test case to run.
"""
import unittest
import sys
from mozdevice import DeviceManagerADB
class TestFileOperations(unittest.TestCase):
def setUp(self):
dm = DeviceManagerADB()
dm.reboot(wait=True)
def test_run_adb_as_root_parameter(self):
dm = DeviceManagerADB()
self.assertTrue(dm.processInfo("adbd")[2] != "root")
dm = DeviceManagerADB(runAdbAsRoot=True)
self.assertTrue(dm.processInfo("adbd")[2] == "root")
def test_after_reboot_adb_runs_as_root(self):
dm = DeviceManagerADB(runAdbAsRoot=True)
self.assertTrue(dm.processInfo("adbd")[2] == "root")
dm.reboot(wait=True)
self.assertTrue(dm.processInfo("adbd")[2] == "root")
def tearDown(self):
dm = DeviceManagerADB()
dm.reboot()
if __name__ == "__main__":
dm = DeviceManagerADB()
if not dm.devices():
print "There are no connected adb devices"
sys.exit(1)
else:
if not (int(dm._runCmd(["shell", "getprop", "ro.secure"]).output[0]) and \
int(dm._runCmd(["shell", "getprop", "ro.debuggable"]).output[0])):
print "This test case is meant for devices with devices that start " \
"adbd as non-root and allows for adbd to be restarted as root."
sys.exit(1)
unittest.main()

Просмотреть файл

@ -34,7 +34,7 @@ class DeviceManagerADB(DeviceManager):
def __init__(self, host=None, port=5555, retryLimit=5, packageName='fennec',
adbPath='adb', deviceSerial=None, deviceRoot=None,
logLevel=mozlog.ERROR, autoconnect=True, **kwargs):
logLevel=mozlog.ERROR, autoconnect=True, runAdbAsRoot=False, **kwargs):
DeviceManager.__init__(self, logLevel=logLevel,
deviceRoot=deviceRoot)
self.host = host
@ -48,6 +48,10 @@ class DeviceManagerADB(DeviceManager):
# where multiple devices are being managed by the same adb instance.
self._deviceSerial = deviceSerial
# Some devices do no start adb as root, if allowed you can use
# this to reboot adbd on the device as root automatically
self._runAdbAsRoot = runAdbAsRoot
if packageName == 'fennec':
if os.getenv('USER'):
self._packageName = 'org.mozilla.fennec_' + os.getenv('USER')
@ -472,7 +476,10 @@ class DeviceManagerADB(DeviceManager):
def reboot(self, wait = False, **kwargs):
self._checkCmd(["reboot"])
if wait:
self._checkCmd(["wait-for-device", "shell", "ls", "/sbin"])
self._checkCmd(["wait-for-device"])
if self._runAdbAsRoot:
self._adb_root()
self._checkCmd(["shell", "ls", "/sbin"])
def updateApp(self, appBundlePath, **kwargs):
return self._runCmd(["install", "-r", appBundlePath]).output
@ -641,6 +648,9 @@ class DeviceManagerADB(DeviceManager):
if data.find('uid=0(root)') >= 0:
self._haveSu = True
if self._runAdbAsRoot:
self._adb_root()
def _isUnzipAvailable(self):
data = self._runCmd(["shell", "unzip"]).output
for line in data:
@ -665,3 +675,13 @@ class DeviceManagerADB(DeviceManager):
self._useZip = True
else:
raise DMError("zip not available")
def _adb_root(self):
""" Some devices require us to reboot adbd as root.
This function takes care of it.
"""
if self.processInfo("adbd")[2] != "root":
self._checkCmd(["root"])
self._checkCmd(["wait-for-device"])
if self.processInfo("adbd")[2] != "root":
raise DMError("We tried rebooting adbd as root, however, it failed.")