Bug 1310937 - Autophone - mozdevice - sync Bug 1241267 - Autophone - adb_android.py - use install -g on Marshmallow to grant permissions at install time, r=gbrown.
authorBob Clary <bclary@bclary.com>
Wed, 19 Oct 2016 06:06:54 -0700
changeset 318636 5b6b91ca5d506ba30ecf1a5d800e53be76c76fdd
parent 318635 815de87b6dbaad501c84fa221630e9597f0caaf6
child 318637 5c9959b4e6aa08c5aa572657153def956b336122
push id20725
push userphilringnalda@gmail.com
push dateThu, 20 Oct 2016 01:36:01 +0000
treeherderfx-team@998ad5a74da8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs1310937, 1241267
milestone52.0a1
Bug 1310937 - Autophone - mozdevice - sync Bug 1241267 - Autophone - adb_android.py - use install -g on Marshmallow to grant permissions at install time, r=gbrown.
testing/mozbase/mozdevice/mozdevice/adb_android.py
--- a/testing/mozbase/mozdevice/mozdevice/adb_android.py
+++ b/testing/mozbase/mozdevice/mozdevice/adb_android.py
@@ -88,16 +88,19 @@ class ADBAndroid(ADBDevice):
         try:
             self.selinux = True
             if self.shell_output('getenforce', timeout=timeout) != 'Permissive':
                 self._logger.info('Setting SELinux Permissive Mode')
                 self.shell_output("setenforce Permissive", timeout=timeout, root=True)
         except ADBError:
             self.selinux = False
 
+        self.version = int(self.shell_output("getprop ro.build.version.sdk",
+                                             timeout=timeout))
+
     def reboot(self, timeout=None):
         """Reboots the device.
 
         :param timeout: optional integer specifying the maximum time in
             seconds for any spawned adb process to complete before
             throwing an ADBTimeoutError.
             This timeout is per adb call. The total time spent
             may exceed this value. If it is not specified, the value
@@ -260,17 +263,21 @@ class ADBAndroid(ADBDevice):
             throwing an ADBTimeoutError.
             This timeout is per adb call. The total time spent
             may exceed this value. If it is not specified, the value
             set in the ADB constructor is used.
         :type timeout: integer or None
         :raises: * ADBTimeoutError
                  * ADBError
         """
-        data = self.command_output(["install", apk_path], timeout=timeout)
+        cmd = ["install"]
+        if self.version >= version_codes.M:
+            cmd.append("-g")
+        cmd.append(apk_path)
+        data = self.command_output(cmd, timeout=timeout)
         if data.find('Success') == -1:
             raise ADBError("install failed for %s. Got: %s" %
                            (apk_path, data))
 
     def is_app_installed(self, app_name, timeout=None):
         """Returns True if an app is installed on the device.
 
         :param str app_name: The name of the app to be checked.
@@ -413,19 +420,17 @@ class ADBAndroid(ADBDevice):
             may exceed this value. If it is not specified, the value
             set in the ADB constructor is used.
         :type timeout: integer or None
         :param bool root: Flag specifying if the command should be
             executed as root.
         :raises: * ADBTimeoutError
                  * ADBError
         """
-        version = self.shell_output("getprop ro.build.version.sdk",
-                                    timeout=timeout, root=root)
-        if int(version) >= version_codes.HONEYCOMB:
+        if self.version >= version_codes.HONEYCOMB:
             self.shell_output("am force-stop %s" % app_name,
                               timeout=timeout, root=root)
         else:
             num_tries = 0
             max_tries = 5
             while self.process_exist(app_name, timeout=timeout):
                 if num_tries > max_tries:
                     raise ADBError("Couldn't successfully kill %s after %s "
@@ -475,12 +480,15 @@ class ADBAndroid(ADBDevice):
             throwing an ADBTimeoutError.
             This timeout is per adb call. The total time spent
             may exceed this value. If it is not specified, the value
             set in the ADB constructor is used.
         :type timeout: integer or None
         :raises: * ADBTimeoutError
                  * ADBError
         """
-        output = self.command_output(["install", "-r", apk_path],
-                                     timeout=timeout)
+        cmd = ["install", "-r"]
+        if self.version >= version_codes.M:
+            cmd.append("-g")
+        cmd.append(apk_path)
+        output = self.command_output(cmd, timeout=timeout)
         self.reboot(timeout=timeout)
         return output