Commit 83bfe6ce authored by Botond Ballo's avatar Botond Ballo
Browse files

Bug 1590857 - Don't prompt to install Android app if the user is running 'mach install'. r=gbrown

Differential Revision: https://phabricator.services.mozilla.com/D54381

--HG--
extra : moz-landing-system : lando
parent 6b83eba3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -236,8 +236,8 @@ class MachCommands(MachCommandBase):
        # adb which uses an unstructured logger in its constructor.
        reftest.log_manager.enable_unstructured()
        if conditions.is_android(self):
            from mozrunner.devices.android_device import verify_android_device
            install = not kwargs.get('no_install')
            from mozrunner.devices.android_device import (verify_android_device, InstallIntent)
            install = InstallIntent.NO if kwargs.get('no_install') else InstallIntent.PROMPT
            verify_android_device(self, install=install, xre=True, network=True,
                                  app=kwargs["app"], device_serial=kwargs["deviceSerial"])
            return reftest.run_android_test(**kwargs)
+10 −5
Original line number Diff line number Diff line
@@ -498,10 +498,12 @@ class GTestCommands(MachCommandBase):
                print("--jobs is not supported on Android and will be ignored")
            if debug or debugger or debugger_args:
                print("--debug options are not supported on Android and will be ignored")
            from mozrunner.devices.android_device import InstallIntent
            return self.android_gtest(cwd, shuffle, gtest_filter,
                                      package, adb_path, device_serial,
                                      remote_test_root, libxul_path,
                                      enable_webrender, not no_install)
                                      enable_webrender,
                                      InstallIntent.NO if no_install else InstallIntent.PROMPT)

        if package or adb_path or device_serial or remote_test_root or libxul_path or no_install:
            print("One or more Android-only options will be ignored")
@@ -699,8 +701,8 @@ class Install(MachCommandBase):
             description='Install the package on the machine (or device in the case of Android).')
    def install(self, **kwargs):
        if conditions.is_android(self):
            from mozrunner.devices.android_device import verify_android_device
            ret = verify_android_device(self, install=True, **kwargs) == 0
            from mozrunner.devices.android_device import (verify_android_device, InstallIntent)
            ret = verify_android_device(self, install=InstallIntent.YES, **kwargs) == 0
        else:
            ret = self._run_make(directory=".", target='install', ensure_exit_code=False)

@@ -826,7 +828,9 @@ class RunProgram(MachCommandBase):

    def _run_android(self, app='org.mozilla.geckoview_example', intent=None, env=[], profile=None,
                     url=None, no_install=None, no_wait=None, fail_if_running=None, restart=None):
        from mozrunner.devices.android_device import verify_android_device, _get_device
        from mozrunner.devices.android_device import (verify_android_device,
                                                      _get_device,
                                                      InstallIntent)
        from six.moves import shlex_quote

        if app == 'org.mozilla.geckoview_example':
@@ -839,7 +843,8 @@ class RunProgram(MachCommandBase):
            raise RuntimeError('Application not recognized: {}'.format(app))

        # `verify_android_device` respects `DEVICE_SERIAL` if it is set and sets it otherwise.
        verify_android_device(self, app=app, install=not no_install)
        verify_android_device(self, app=app,
                              install=InstallIntent.NO if no_install else InstallIntent.PROMPT)
        device_serial = os.environ.get('DEVICE_SERIAL')
        if not device_serial:
            print('No ADB devices connected.')
+2 −2
Original line number Diff line number Diff line
@@ -431,8 +431,8 @@ class MachCommands(MachCommandBase):
        utility_path = self.bindir

        if conditions.is_android(self):
            from mozrunner.devices.android_device import verify_android_device
            verify_android_device(self, install=False)
            from mozrunner.devices.android_device import (verify_android_device, InstallIntent)
            verify_android_device(self, install=InstallIntent.NO)
            return self.run_android_test(tests, symbols_path, manifest_path, log)

        return self.run_desktop_test(tests, symbols_path, manifest_path,
+11 −8
Original line number Diff line number Diff line
@@ -214,9 +214,9 @@ def setup_argument_parser():
        # emulator if appropriate) before running tests. This check must
        # be done in this admittedly awkward place because
        # MochitestArgumentParser initialization fails if no device is found.
        from mozrunner.devices.android_device import verify_android_device
        from mozrunner.devices.android_device import (verify_android_device, InstallIntent)
        # verify device and xre
        verify_android_device(build_obj, install=False, xre=True)
        verify_android_device(build_obj, install=InstallIntent.NO, xre=True)

    global parser
    parser = MochitestArgumentParser()
@@ -247,8 +247,8 @@ def setup_junit_argument_parser():

        import runjunit

        from mozrunner.devices.android_device import verify_android_device
        verify_android_device(build_obj, install=False, xre=True, network=True)
        from mozrunner.devices.android_device import (verify_android_device, InstallIntent)
        verify_android_device(build_obj, install=InstallIntent.NO, xre=True, network=True)

    global parser
    parser = runjunit.JunitArgumentParser()
@@ -418,12 +418,12 @@ class MachCommands(MachCommandBase):
            return 1

        if buildapp == 'android':
            from mozrunner.devices.android_device import verify_android_device
            from mozrunner.devices.android_device import (verify_android_device, InstallIntent)
            app = kwargs.get('app')
            if not app:
                app = "org.mozilla.geckoview.test"
            device_serial = kwargs.get('deviceSerial')
            install = not kwargs.get('no_install')
            install = InstallIntent.NO if kwargs.get('no_install') else InstallIntent.PROMPT

            # verify installation
            verify_android_device(self, install=install, xre=False, network=True,
@@ -475,11 +475,14 @@ class GeckoviewJunitCommands(MachCommandBase):
        self._ensure_state_subdir_exists('.')

        from mozrunner.devices.android_device import (get_adb_path,
                                                      verify_android_device)
                                                      verify_android_device,
                                                      InstallIntent)
        # verify installation
        app = kwargs.get('app')
        device_serial = kwargs.get('deviceSerial')
        verify_android_device(self, install=not no_install, xre=False, app=app,
        verify_android_device(self,
                              install=InstallIntent.NO if no_install else InstallIntent.PROMPT,
                              xre=False, app=app,
                              device_serial=device_serial)

        if not kwargs.get('adbPath'):
+20 −11
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ import sys
import telnetlib
import time
from distutils.spawn import find_executable
from enum import Enum

import psutil
from mozdevice import ADBHost, ADBDevice
@@ -34,6 +35,12 @@ verbose_logging = False
devices = {}


class InstallIntent(Enum):
    YES = 1
    NO = 2
    PROMPT = 3


class AvdInfo(object):
    """
       Simple class to contain an AVD description.
@@ -161,7 +168,7 @@ def _maybe_update_host_utils(build_obj):
                _install_host_utils(build_obj)


def verify_android_device(build_obj, install=False, xre=False, debugger=False,
def verify_android_device(build_obj, install=InstallIntent.NO, xre=False, debugger=False,
                          network=False, verbose=False, app=None, device_serial=None):
    """
       Determine if any Android device is connected via adb.
@@ -208,7 +215,7 @@ def verify_android_device(build_obj, install=False, xre=False, debugger=False,
                os.environ["DEVICE_SERIAL"] = d['device_serial']
                break

    if device_verified and install:
    if device_verified and install != InstallIntent.NO:
        # Determine if test app is installed on the device; if not,
        # prompt to install. This feature allows a test command to
        # launch an emulator, install the test app, and proceed with testing
@@ -227,22 +234,26 @@ def verify_android_device(build_obj, install=False, xre=False, debugger=False,
        response = ''
        action = 'Re-install'
        installed = device.is_app_installed(app)

        def should_install(appname):
            if install == InstallIntent.YES:
                return True
            else:  # InstallIntent.PROMPT
                response = input("%s %s? (Y/n) " % (action, appname)).strip()
                return response.lower().startswith('y') or response == ''

        if not installed:
            _log_info("It looks like %s is not installed on this device." % app)
            action = 'Install'
        if 'fennec' in app or 'firefox' in app:
            response = response = input(
                "%s Firefox? (Y/n) " % action).strip()
            if response.lower().startswith('y') or response == '':
            if should_install("Firefox"):
                if installed:
                    device.uninstall_app(app)
                _log_info("Installing Firefox...")
                build_obj._run_make(directory=".", target='install',
                                    ensure_exit_code=False)
        elif app == 'org.mozilla.geckoview.test':
            response = response = input(
                "%s geckoview AndroidTest? (Y/n) " % action).strip()
            if response.lower().startswith('y') or response == '':
            if should_install("geckoview AndroidTest"):
                if installed:
                    device.uninstall_app(app)
                _log_info("Installing geckoview AndroidTest...")
@@ -251,9 +262,7 @@ def verify_android_device(build_obj, install=False, xre=False, debugger=False,
                                                          args=[sub],
                                                          context=build_obj._mach_context)
        elif app == 'org.mozilla.geckoview_example':
            response = response = input(
                "%s geckoview_example? (Y/n) " % action).strip()
            if response.lower().startswith('y') or response == '':
            if should_install("geckoview_example"):
                if installed:
                    device.uninstall_app(app)
                _log_info("Installing geckoview_example...")
Loading