Exemplo n.º 1
0
def install_application_if_needed(apk_path, force_update):
    """Install application package if it does not exist on device
  or if force_update is set."""
    # Make sure that apk exists and has non-zero size. Otherwise, it means we
    # are using a system package that we just want to fuzz, but not care about
    # installation.
    if (not apk_path or not os.path.exists(apk_path)
            or not os.path.getsize(apk_path)):
        return

    # If we don't have a package name, we can't uninstall the app. This is needed
    # for installation workflow.
    package_name = adb.get_package_name()
    if not package_name:
        return

    # Add |REINSTALL_APP_BEFORE_EACH_TASK| to force update decision.
    reinstall_app_before_each_task = environment.get_value(
        'REINSTALL_APP_BEFORE_EACH_TASK', False)
    force_update = force_update or reinstall_app_before_each_task

    # Install application if it is not found in the device's
    # package list or force_update flag has been set.
    if force_update or not adb.is_package_installed(package_name):
        # Update system webview when fuzzing webview shell apk.
        if package_name == 'org.chromium.webview_shell':
            update_system_web_view()

        adb.uninstall_package(package_name)
        adb.install_package(apk_path)

        if not adb.is_package_installed(package_name):
            logs.log_error('Package %s was not installed successfully.' %
                           package_name)
            return

        logs.log('Package %s is successfully installed using apk %s.' %
                 (package_name, apk_path))

    adb.reset_application_state()
Exemplo n.º 2
0
 def test_apk_path_in_arg(self):
   """Test apk path passed as argument."""
   self.assertEqual(
       adb.get_package_name(self.test_apk_path), self.test_apk_pkg_name)
Exemplo n.º 3
0
 def test_apk_path_in_app_path_env(self):
   """Test apk path set in |APP_PATH| env variable."""
   environment.set_value('APP_PATH', self.test_apk_path)
   self.assertEqual(adb.get_package_name(), self.test_apk_pkg_name)
Exemplo n.º 4
0
 def test_pkg_name_in_env(self):
   """Test package name already set in |PKG_NAME| env."""
   environment.set_value('PKG_NAME', 'a.b.c')
   self.assertEqual(adb.get_package_name(), 'a.b.c')