Bug 747268 - devicemanagerADB: improve listFiles error handling and check for root. r=jmaher, a=test-only
authorGeoff Brown <gbrown@mozilla.com>
Fri, 20 Apr 2012 17:15:59 -0400
changeset 95365 d7d1e8e3b435a1e3681b18b80d08c3cb3d1877b9
parent 95364 230435e1426324b472d3d1a8aed32845b788178b
child 95366 bce6cabacc8802c9086c20dc8c015b25c50bad4b
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher, test-only
bugs747268
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 747268 - devicemanagerADB: improve listFiles error handling and check for root. r=jmaher, a=test-only
build/mobile/devicemanagerADB.py
--- a/build/mobile/devicemanagerADB.py
+++ b/build/mobile/devicemanagerADB.py
@@ -48,30 +48,33 @@ class DeviceManagerADB(DeviceManager):
 
     # Can we use run-as? (currently not required)
     try:
       self.verifyRunAs()
     except DMError:
       pass
 
     # Can we run things as root? (currently not required)
+    useRunAsTmp = self.useRunAs
+    self.useRunAs = False
     try:
       self.verifyRoot()
     except DMError, e:
       try:
         self.checkCmd(["root"])
         # The root command does not fail even if ADB cannot get
         # root rights (e.g. due to production builds), so we have
         # to check again ourselves that we have root now.
         self.verifyRoot()
       except DMError:
-        if self.useRunAs:
+        if useRunAsTmp:
           print "restarting as root failed, but run-as available"
         else:
           print "restarting as root failed"
+    self.useRunAs = useRunAsTmp
 
     # can we use zip to speed up some file operations? (currently not
     # required)
     try:
       self.verifyZip()
     except DMError:
       pass
 
@@ -309,16 +312,20 @@ class DeviceManagerADB(DeviceManager):
       data[:] = [item.rstrip('\r\n') for item in data]
       if (len(data) == 1):
           if (data[0] == rootdir):
               return []
           if (data[0].find("No such file or directory") != -1):
               return []
           if (data[0].find("Not a directory") != -1):
               return []
+          if (data[0].find("Permission denied") != -1):
+              return []
+          if (data[0].find("opendir failed") != -1):
+              return []
       return data
 
   # external function
   # returns:
   #  success: array of process tuples
   #  failure: []
   def getProcessList(self):
     p = self.runCmd(["shell", "ps"])
@@ -772,20 +779,19 @@ class DeviceManagerADB(DeviceManager):
     try:
       self.checkCmd(["shell", "echo"])
     except subprocess.CalledProcessError:
       raise DMError("unable to connect to device: is it plugged in?")
 
   def verifyRoot(self):
     # a test to see if we have root privs
     files = self.listFiles("/data/data")
-    if (len(files) == 1):
-      if (files[0].find("Permission denied") != -1):
-        print "NOT running as root"
-        raise DMError("not running as root")
+    if (len(files) == 0):
+      print "NOT running as root"
+      raise DMError("not running as root")
 
     self.haveRoot = True
 
   def isCpAvailable(self):
     # Some Android systems may not have a cp command installed,
     # or it may not be executable by the user.
     data = self.runCmd(["shell", "cp"]).stdout.read()
     if (re.search('Usage', data)):