| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Finds android browsers that can be controlled by telemetry.""" | 5 """Finds android browsers that can be controlled by telemetry.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 | 9 |
| 10 from telemetry.core import browser | 10 from telemetry.core import browser |
| 11 from telemetry.core import exceptions | 11 from telemetry.core import exceptions |
| 12 from telemetry.core import platform | 12 from telemetry.core import platform |
| 13 from telemetry.core.platform import android_device | 13 from telemetry.core.platform import android_device |
| 14 from telemetry.core import possible_browser | 14 from telemetry.core import possible_browser |
| 15 from telemetry.core import util | 15 from telemetry.core import util |
| 16 from telemetry import decorators | 16 from telemetry import decorators |
| 17 from telemetry.internal.backends import adb_commands | |
| 18 from telemetry.internal.backends import android_browser_backend_settings | 17 from telemetry.internal.backends import android_browser_backend_settings |
| 19 from telemetry.internal.backends.chrome import android_browser_backend | 18 from telemetry.internal.backends.chrome import android_browser_backend |
| 20 | 19 |
| 20 util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android') |
| 21 from pylib.utils import apk_helper # pylint: disable=import-error |
| 22 |
| 21 | 23 |
| 22 CHROME_PACKAGE_NAMES = { | 24 CHROME_PACKAGE_NAMES = { |
| 23 'android-content-shell': | 25 'android-content-shell': |
| 24 ['org.chromium.content_shell_apk', | 26 ['org.chromium.content_shell_apk', |
| 25 android_browser_backend_settings.ContentShellBackendSettings, | 27 android_browser_backend_settings.ContentShellBackendSettings, |
| 26 'ContentShell.apk'], | 28 'ContentShell.apk'], |
| 27 'android-chrome-shell': | 29 'android-chrome-shell': |
| 28 ['org.chromium.chrome.shell', | 30 ['org.chromium.chrome.shell', |
| 29 android_browser_backend_settings.ChromeShellBackendSettings, | 31 android_browser_backend_settings.ChromeShellBackendSettings, |
| 30 'ChromeShell.apk'], | 32 'ChromeShell.apk'], |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 """Testable version of FindAllAvailableBrowsers.""" | 165 """Testable version of FindAllAvailableBrowsers.""" |
| 164 if not android_platform: | 166 if not android_platform: |
| 165 return [] | 167 return [] |
| 166 possible_browsers = [] | 168 possible_browsers = [] |
| 167 | 169 |
| 168 # Add the exact APK if given. | 170 # Add the exact APK if given. |
| 169 if (finder_options.browser_executable and | 171 if (finder_options.browser_executable and |
| 170 CanPossiblyHandlePath(finder_options.browser_executable)): | 172 CanPossiblyHandlePath(finder_options.browser_executable)): |
| 171 normalized_path = os.path.expanduser(finder_options.browser_executable) | 173 normalized_path = os.path.expanduser(finder_options.browser_executable) |
| 172 | 174 |
| 173 exact_package = adb_commands.GetPackageName(normalized_path) | 175 exact_package = apk_helper.GetPackageName(normalized_path) |
| 174 if not exact_package: | 176 if not exact_package: |
| 175 raise exceptions.PackageDetectionError( | 177 raise exceptions.PackageDetectionError( |
| 176 'Unable to find package for %s specified by --browser-executable' % | 178 'Unable to find package for %s specified by --browser-executable' % |
| 177 normalized_path) | 179 normalized_path) |
| 178 | 180 |
| 179 package_info = next((info for info in CHROME_PACKAGE_NAMES.itervalues() | 181 package_info = next((info for info in CHROME_PACKAGE_NAMES.itervalues() |
| 180 if info[0] == exact_package), None) | 182 if info[0] == exact_package), None) |
| 181 if package_info: | 183 if package_info: |
| 182 [package, backend_settings, _] = package_info | 184 [package, backend_settings, _] = package_info |
| 183 possible_browsers.append( | 185 possible_browsers.append( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 207 def FindAllAvailableBrowsers(finder_options, device): | 209 def FindAllAvailableBrowsers(finder_options, device): |
| 208 """Finds all the possible browsers on one device. | 210 """Finds all the possible browsers on one device. |
| 209 | 211 |
| 210 The device is either the only device on the host platform, | 212 The device is either the only device on the host platform, |
| 211 or |finder_options| specifies a particular device. | 213 or |finder_options| specifies a particular device. |
| 212 """ | 214 """ |
| 213 if not isinstance(device, android_device.AndroidDevice): | 215 if not isinstance(device, android_device.AndroidDevice): |
| 214 return [] | 216 return [] |
| 215 android_platform = platform.GetPlatformForDevice(device, finder_options) | 217 android_platform = platform.GetPlatformForDevice(device, finder_options) |
| 216 return _FindAllPossibleBrowsers(finder_options, android_platform) | 218 return _FindAllPossibleBrowsers(finder_options, android_platform) |
| OLD | NEW |