Пример #1
0
def _FindAllPossibleBrowsers(finder_options, android_platform):
    """Testable version of FindAllAvailableBrowsers."""
    if not android_platform:
        return []
    possible_browsers = []

    # Add the exact APK if given.
    if _CanPossiblyHandlePath(finder_options.browser_executable):
        if not os.path.exists(finder_options.browser_executable):
            raise exceptions.PathMissingError(
                'Unable to find exact apk specified by --browser-executable=%s'
                % finder_options.browser_executable)

        package_name = apk_helper.GetPackageName(
            finder_options.browser_executable)
        try:
            backend_settings = next(backend_settings
                                    for target_package, backend_settings in
                                    CHROME_PACKAGE_NAMES.itervalues()
                                    if package_name == target_package)
        except StopIteration:
            raise exceptions.UnknownPackageError(
                '%s specified by --browser-executable has an unknown package: %s'
                % (finder_options.browser_executable, package_name))

        possible_browsers.append(
            PossibleAndroidBrowser('exact', finder_options, android_platform,
                                   backend_settings(package_name),
                                   finder_options.browser_executable))

    # 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 = package_info
        p_browser = PossibleAndroidBrowser(name, finder_options,
                                           android_platform,
                                           backend_settings(package))
        if p_browser.IsAvailable():
            possible_browsers.append(p_browser)
    return possible_browsers
Пример #2
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)
Пример #3
0
def _FindAllPossibleBrowsers(finder_options, android_platform):
    """Testable version of FindAllAvailableBrowsers."""
    if not android_platform:
        return []
    possible_browsers = []

    # Add the exact APK if given.
    if _CanPossiblyHandlePath(finder_options.browser_executable):
        if not os.path.exists(finder_options.browser_executable):
            raise exceptions.PathMissingError(
                'Unable to find exact apk specified by --browser-executable=%s'
                % finder_options.browser_executable)

        package_name = apk_helper.GetPackageName(
            finder_options.browser_executable)
        try:
            backend_settings = next(b for b in ANDROID_BACKEND_SETTINGS
                                    if b.package == package_name)
        except StopIteration:
            raise exceptions.UnknownPackageError(
                '%s specified by --browser-executable has an unknown package: %s'
                % (finder_options.browser_executable, package_name))

        possible_browsers.append(
            PossibleAndroidBrowser('exact', finder_options, android_platform,
                                   backend_settings,
                                   finder_options.browser_executable))

    # 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 backend settings?
        possible_browsers.append(
            PossibleAndroidBrowser(
                'reference', finder_options, android_platform,
                android_browser_backend_settings.ANDROID_CHROME,
                reference_build))

    # Add any other known available browsers.
    for settings in ANDROID_BACKEND_SETTINGS:
        p_browser = PossibleAndroidBrowser(settings.browser_type,
                                           finder_options, android_platform,
                                           settings)
        if p_browser.IsAvailable():
            possible_browsers.append(p_browser)
    return possible_browsers
def _GetReferenceAndroidBrowser(android_platform, finder_options):
    # 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):
        return PossibleAndroidBrowser(
            'reference', finder_options, android_platform,
            android_browser_backend_settings.ANDROID_CHROME, reference_build)
Пример #5
0
def _FetchReferenceApk(android_platform, is_bundle=False):
  """Fetch the apk for reference browser type from gcloud.

  Local path to the apk will be returned upon success.
  Otherwise, None will be returned.
  """
  os_version = dependency_util.GetChromeApkOsVersion(
      android_platform.GetOSVersionName())
  if is_bundle:
    os_version += '_bundle'
  arch = android_platform.GetArchName()
  try:
    reference_build = binary_manager.FetchPath(
        'chrome_stable', 'android', arch, os_version)
    if reference_build and os.path.exists(reference_build):
      return reference_build
  except binary_manager.NoPathFoundError:
    logging.warning('Cannot find path for reference apk for device %s',
                    android_platform.GetDeviceId())
  except binary_manager.CloudStorageError:
    logging.warning('Failed to download reference apk for device %s',
                    android_platform.GetDeviceId())
  return None
Пример #6
0
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)
        normalized_path = os.path.expanduser(finder_options.browser_executable)
        exact_package = apk_helper.GetPackageName(normalized_path)
        package_info = next(
            (info for info in CHROME_PACKAGE_NAMES.itervalues()
             if info[0] == exact_package or info[2] == apk_name), None)

        # It is okay if the APK name or package doesn't match any of known chrome
        # browser APKs, since it may be of a different browser.
        if package_info:
            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, apk_name = package_info
        if apk_name and not finder_options.chrome_root:
            continue
        b = PossibleAndroidBrowser(name, finder_options, android_platform,
                                   backend_settings(package), apk_name)
        if b.platform.CanLaunchApplication(package) or b.HaveLocalAPK():
            possible_browsers.append(b)
    return possible_browsers