| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 import logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import random | 7 import random |
| 8 import re | 8 import re |
| 9 import sys | 9 import sys |
| 10 | 10 |
| 11 from telemetry.core import exceptions | 11 from telemetry.core import exceptions |
| 12 from telemetry.core import util | 12 from telemetry.core import util |
| 13 from telemetry.internal.backends.mandoline import android | 13 from telemetry.internal.backends.mandoline import android |
| 14 from telemetry.internal.backends.mandoline import config | 14 from telemetry.internal.backends.mandoline import config |
| 15 from telemetry.internal.backends.mandoline import mandoline_browser_backend | 15 from telemetry.internal.backends.mandoline import mandoline_browser_backend |
| 16 from telemetry.internal.platform import android_platform_backend as \ | 16 from telemetry.internal.platform import android_platform_backend as \ |
| 17 android_platform_backend_module | 17 android_platform_backend_module |
| 18 | 18 |
| 19 try: | 19 try: |
| 20 from pylib import constants | 20 from devil.android.sdk import keyevent |
| 21 except ImportError: | 21 except ImportError: |
| 22 pass | 22 pass |
| 23 | 23 |
| 24 class AndroidMandolineBackend( | 24 class AndroidMandolineBackend( |
| 25 mandoline_browser_backend.MandolineBrowserBackend): | 25 mandoline_browser_backend.MandolineBrowserBackend): |
| 26 """The backend for controlling a mandoline browser instance running on | 26 """The backend for controlling a mandoline browser instance running on |
| 27 Android.""" | 27 Android.""" |
| 28 | 28 |
| 29 def __init__(self, android_platform_backend, browser_options, target_arch, | 29 def __init__(self, android_platform_backend, browser_options, target_arch, |
| 30 browser_type, build_path, package, chrome_root): | 30 browser_type, build_path, package, chrome_root): |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 apk_name='Mandoline.apk') | 84 apk_name='Mandoline.apk') |
| 85 shell = android.AndroidShell(mandoline_config, self._chrome_root) | 85 shell = android.AndroidShell(mandoline_config, self._chrome_root) |
| 86 shell.InitShell(self.device) | 86 shell.InitShell(self.device) |
| 87 | 87 |
| 88 output = sys.stdout | 88 output = sys.stdout |
| 89 if not self.browser_options.show_stdout: | 89 if not self.browser_options.show_stdout: |
| 90 output = open(os.devnull, 'w') | 90 output = open(os.devnull, 'w') |
| 91 logging_process = shell.ShowLogs(output) | 91 logging_process = shell.ShowLogs(output) |
| 92 | 92 |
| 93 # Unlock device screen. | 93 # Unlock device screen. |
| 94 self.device.SendKeyEvent(constants.keyevent.KEYCODE_MENU) | 94 self.device.SendKeyEvent(keyevent.KEYCODE_MENU) |
| 95 shell.StartActivity(self.activity, args, output, logging_process.terminate) | 95 shell.StartActivity(self.activity, args, output, logging_process.terminate) |
| 96 | 96 |
| 97 try: | 97 try: |
| 98 self._WaitForBrowserToComeUp() | 98 self._WaitForBrowserToComeUp() |
| 99 self._InitDevtoolsClientBackend(self._port) | 99 self._InitDevtoolsClientBackend(self._port) |
| 100 except exceptions.BrowserGoneException: | 100 except exceptions.BrowserGoneException: |
| 101 logging.critical('Failed to connect to browser.') | 101 logging.critical('Failed to connect to browser.') |
| 102 self.Close() | 102 self.Close() |
| 103 raise | 103 raise |
| 104 except: | 104 except: |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 # The range of ephemeral ports on Android. | 187 # The range of ephemeral ports on Android. |
| 188 dynamic_port_begin = 32768 | 188 dynamic_port_begin = 32768 |
| 189 dynamic_port_end = 61000 | 189 dynamic_port_end = 61000 |
| 190 assert len(used_ports) < dynamic_port_end - dynamic_port_begin + 1 | 190 assert len(used_ports) < dynamic_port_end - dynamic_port_begin + 1 |
| 191 | 191 |
| 192 available_port = random.randint(dynamic_port_begin, dynamic_port_end) | 192 available_port = random.randint(dynamic_port_begin, dynamic_port_end) |
| 193 while available_port in used_ports: | 193 while available_port in used_ports: |
| 194 available_port = random.randint(dynamic_port_begin, dynamic_port_end) | 194 available_port = random.randint(dynamic_port_begin, dynamic_port_end) |
| 195 | 195 |
| 196 return available_port | 196 return available_port |
| OLD | NEW |