Esempio n. 1
0
def _FetchReferenceBrowserBinary(platform):
    os_name = platform.GetOSName()
    arch_name = platform.GetArchName()
    manager = binary_manager.BinaryManager([CHROME_BINARY_CONFIG])
    if os_name == 'android':
        os_version = dependency_util.GetChromeApkOsVersion(
            platform.GetOSVersionName())
        manager.FetchPath('chrome_stable', os_name, arch_name, os_version)
    else:
        manager.FetchPath('reference_build', os_name, arch_name)
def _FindAllPossibleBrowsers(finder_options, android_platform):
    """Testable version of FindAllAvailableBrowsers."""
    if not android_platform:
        return []
    possible_browsers = []

    # Add the exact APK if given.
    if (finder_options.browser_executable
            and CanPossiblyHandlePath(finder_options.browser_executable)):
        apk_name = os.path.basename(finder_options.browser_executable)
        package_info = next((info
                             for info in CHROME_PACKAGE_NAMES.itervalues()
                             if info[2] == apk_name), None)

        # It is okay if the APK name doesn't match any of known chrome browser APKs,
        # since it may be of a different browser.
        if package_info:
            normalized_path = os.path.expanduser(
                finder_options.browser_executable)
            exact_package = apk_helper.GetPackageName(normalized_path)
            if not exact_package:
                raise exceptions.PackageDetectionError(
                    'Unable to find package for %s specified by --browser-executable'
                    % normalized_path)

            [package, backend_settings, _] = package_info
            if package == exact_package:
                possible_browsers.append(
                    PossibleAndroidBrowser('exact', finder_options,
                                           android_platform,
                                           backend_settings(package),
                                           normalized_path))
            else:
                raise exceptions.UnknownPackageError(
                    '%s specified by --browser-executable has an unknown package: %s'
                    % (normalized_path, exact_package))

    # Add the reference build if found.
    os_version = dependency_util.GetChromeApkOsVersion(
        android_platform.GetOSVersionName())
    arch = android_platform.GetArchName()
    try:
        reference_build = binary_manager.FetchPath('chrome_stable', arch,
                                                   'android', os_version)
    except (binary_manager.NoPathFoundError, binary_manager.CloudStorageError):
        reference_build = None

    if reference_build and os.path.exists(reference_build):
        # TODO(aiolos): how do we stably map the android chrome_stable apk to the
        # correct package name?
        package, backend_settings, _ = CHROME_PACKAGE_NAMES['android-chrome']
        possible_browsers.append(
            PossibleAndroidBrowser('reference',
                                   finder_options, android_platform,
                                   backend_settings(package), reference_build))

    # Add any known local versions.
    for name, package_info in CHROME_PACKAGE_NAMES.iteritems():
        package, backend_settings, local_apk = package_info
        b = PossibleAndroidBrowser(name, finder_options, android_platform,
                                   backend_settings(package), local_apk)
        if b.platform.CanLaunchApplication(package) or b.HaveLocalAPK():
            possible_browsers.append(b)
    return possible_browsers