Bug 1241907 - Grant runtime permissions before running browser tests; r=jmaher

This commit is contained in:
Geoff Brown 2016-02-01 15:52:34 -07:00
parent 2e6b117ca3
commit 695fcf875c
4 changed files with 28 additions and 7 deletions

View File

@ -246,6 +246,9 @@ class ReftestRunner(MozbuildObject):
kwargs["ignoreWindowSize"] = True
kwargs["printDeviceInfo"] = False
from mozrunner.devices.android_device import grant_runtime_permissions
grant_runtime_permissions(self, kwargs['app'])
# A symlink and some path manipulations are required so that test
# manifests can be found both locally and remotely (via a url)
# using the same relative path.

View File

@ -11,8 +11,6 @@ package:
@$(MAKE) -C mobile/android/installer
ifeq ($(OS_TARGET),Android)
sdk_level=$(shell $(ADB) shell getprop ro.build.version.sdk)
permissions-required=$(shell if [ $(sdk_level) -gt 22 ] ; then echo yes ; else echo no ; fi)
ifneq ($(MOZ_ANDROID_INSTALL_TARGET),)
ANDROID_SERIAL = $(MOZ_ANDROID_INSTALL_TARGET)
endif
@ -36,12 +34,7 @@ endif
endif
install::
ifeq ($(permissions-required),yes)
$(ADB) install -r -g $(DIST)/$(PKG_PATH)$(PKG_BASENAME).apk
else
$(ADB) install -r $(DIST)/$(PKG_PATH)$(PKG_BASENAME).apk
endif
else
@echo 'Mobile can't be installed directly.'
@exit 1

View File

@ -537,6 +537,8 @@ class MachCommands(MachCommandBase):
if buildapp in ('b2g',):
run_mochitest = mochitest.run_b2g_test
elif buildapp == 'android':
from mozrunner.devices.android_device import grant_runtime_permissions
grant_runtime_permissions(self, kwargs['app'])
run_mochitest = mochitest.run_android_test
else:
run_mochitest = mochitest.run_desktop_test
@ -608,6 +610,9 @@ class RobocopCommands(MachCommandBase):
sorted(list(test_paths)))))
return 1
from mozrunner.devices.android_device import grant_runtime_permissions
grant_runtime_permissions(self, kwargs['app'])
mochitest = self._spawn(MochitestRunner)
return mochitest.run_robocop_test(self._mach_context, tests, 'robocop', **kwargs)

View File

@ -260,6 +260,26 @@ def run_firefox_for_android(build_obj, params):
return 1
return 0
def grant_runtime_permissions(build_obj, app):
"""
Grant required runtime permissions to the specified app (typically org.mozilla.fennec_$USER).
"""
adb_path = _find_sdk_exe(build_obj.substs, 'adb', False)
if not adb_path:
adb_path = 'adb'
dm = DeviceManagerADB(autoconnect=False, adbPath=adb_path, retryLimit=1)
dm.default_timeout = 10
try:
sdk_level = dm.shellCheckOutput(['getprop', 'ro.build.version.sdk'])
if sdk_level and int(sdk_level) >= 23:
_log_info("Granting important runtime permissions to %s" % app)
dm.shellCheckOutput(['pm', 'grant', app, 'android.permission.WRITE_EXTERNAL_STORAGE'])
dm.shellCheckOutput(['pm', 'grant', app, 'android.permission.ACCESS_FINE_LOCATION'])
dm.shellCheckOutput(['pm', 'grant', app, 'android.permission.CAMERA'])
dm.shellCheckOutput(['pm', 'grant', app, 'android.permission.WRITE_CONTACTS'])
except DMError:
_log_warning("Unable to grant runtime permissions to %s" % app)
class AndroidEmulator(object):
"""