Beispiel #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()
Beispiel #2
0
def update_system_web_view():
    """Updates the system webview on the device."""
    app_directory = environment.get_value('APP_DIR')
    system_webview_apk = os.path.join(app_directory, SYSTEM_WEBVIEW_APK_NAME)
    if not os.path.exists(system_webview_apk):
        logs.log_error('System Webview apk not found.')
        return
    adb.set_property('persist.sys.webview.vmsize', SYSTEM_WEBVIEW_VMSIZE_BYTES)

    adb.run_as_root()
    if any([adb.directory_exists(d) for d in SYSTEM_WEBVIEW_DIRS]):
        adb.remount()
        adb.stop_shell()
        adb.run_adb_shell_command(['rm', '-rf', ' '.join(SYSTEM_WEBVIEW_DIRS)])
        reboot()

    adb.uninstall_package(SYSTEM_WEBVIEW_PACKAGE)
    adb.install_package(system_webview_apk)

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