Bug 1521996 - Part 3: Make `mach run` for Android bring Fennec forward by default. r=gbrown
authorNick Alexander <nalexander@mozilla.com>
Fri, 17 May 2019 22:21:20 +0000
changeset 474401 c0df3469a4cb5982613aca1cfef71af8ba38b843
parent 474400 376efab28772a451060d9832e84c918b46aef8f4
child 474402 4cc7642d8e0f98492aab3209e3c547d1b270c430
push id113152
push userdluca@mozilla.com
push dateSat, 18 May 2019 10:33:03 +0000
treeherdermozilla-inbound@9b2f851979cb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs1521996
milestone68.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 1521996 - Part 3: Make `mach run` for Android bring Fennec forward by default. r=gbrown `mach run` as it is doesn't really parallel `mach run` on Desktop; this makes it a little closer more fully featured. The underlying functionality is all there in layers of mozharness; let's make it easier to get to. Differential Revision: https://phabricator.services.mozilla.com/D18292
mobile/android/mach_commands.py
testing/mozbase/mozrunner/mozrunner/devices/android_device.py
--- a/mobile/android/mach_commands.py
+++ b/mobile/android/mach_commands.py
@@ -606,21 +606,39 @@ class MachCommands(MachCommandBase):
         if ret == 0:
             self.notify('Install complete')
         return ret
 
     @Command('run-android', category='post-build',
              conditional_name='run',
              conditions=[conditions.is_android],
              description='Run Fennec on an Android device or an emulator.')
-    def run(self):
+    @CommandArgument('--url', help='URL to open',
+                     default=None)
+    @CommandArgument('--no-install', help='Do not try to install application on device before ' +
+                     'running (default: False)',
+                     action='store_true',
+                     default=False)
+    @CommandArgument('--no-wait', help='Do not wait for application to start before returning ' +
+                     '(default: False)',
+                     action='store_true',
+                     default=False)
+    @CommandArgument('--fail-if-running', help='Fail if application is already running ' +
+                     '(default: False)',
+                     action='store_true',
+                     default=False)
+    def run(self, url=None, no_install=None, no_wait=None, fail_if_running=None):
         from mozrunner.devices.android_device import verify_android_device, run_firefox_for_android
 
-        verify_android_device(self, install=True)
-        return run_firefox_for_android(self, [])
+        verify_android_device(self, install=not no_install)
+        return run_firefox_for_android(self,
+                                       [],
+                                       url=url,
+                                       wait=not no_wait,
+                                       fail_if_running=fail_if_running)
 
 
 def _get_maven_archive_abs_and_relative_paths(maven_folder):
     for subdir, _, files in os.walk(maven_folder):
         for file in files:
             full_path = os.path.join(subdir, file)
             relative_path = os.path.relpath(full_path, maven_folder)
 
--- a/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
+++ b/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
@@ -327,40 +327,43 @@ def verify_android_device(build_obj, ins
 
     return device_verified
 
 
 def get_adb_path(build_obj):
     return _find_sdk_exe(build_obj.substs, 'adb', False)
 
 
-def run_firefox_for_android(build_obj, params):
+def run_firefox_for_android(build_obj, params, **kwargs):
     """
        Launch Firefox for Android on the connected device.
        Optional 'params' allow parameters to be passed to Firefox.
     """
     device = _get_device(build_obj.substs)
     try:
         #
         # Construct an adb command similar to:
         #
         # $ adb shell am start -a android.activity.MAIN \
         #   -n org.mozilla.fennec_$USER \
         #   -d <url param> \
         #   --es args "<params>"
         #
         app = build_obj.substs['ANDROID_PACKAGE_NAME']
-        url = None
+
+        msg = "URL specified as '{}'; dropping URL-like parameter '{}'"
         if params:
             for p in params:
                 if urlparse.urlparse(p).scheme != "":
-                    url = p
                     params.remove(p)
-                    break
-        device.launch_fennec(app, extra_args=params, url=url)
+                    if kwargs.get('url'):
+                        _log_warning(msg.format(kwargs['url'], p))
+                    else:
+                        kwargs['url'] = p
+        device.launch_fennec(app, extra_args=params, **kwargs)
     except Exception:
         _log_warning("unable to launch Firefox for Android")
         return 1
     return 0
 
 
 def grant_runtime_permissions(build_obj, app, device_serial=None):
     """