OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Finds android browsers that can be controlled by chrome_remote_control.""" | 4 """Finds android browsers that can be controlled by chrome_remote_control.""" |
5 | 5 |
6 import os as real_os | 6 import os |
7 import subprocess as real_subprocess | |
8 import logging | 7 import logging |
9 import re | 8 import re |
| 9 import subprocess |
10 | 10 |
| 11 from chrome_remote_control import adb_commands |
11 from chrome_remote_control import android_browser_backend | 12 from chrome_remote_control import android_browser_backend |
12 import chrome_remote_control.adb_commands as real_adb_commands | |
13 from chrome_remote_control import browser | 13 from chrome_remote_control import browser |
14 from chrome_remote_control import possible_browser | 14 from chrome_remote_control import possible_browser |
15 | 15 |
16 ALL_BROWSER_TYPES = ','.join([ | 16 ALL_BROWSER_TYPES = ','.join([ |
17 'android-content-shell', | 17 'android-content-shell', |
18 'android-chrome', | 18 'android-chrome', |
19 'android-jb-system-chrome', | 19 'android-jb-system-chrome', |
20 ]) | 20 ]) |
21 | 21 |
22 CHROME_PACKAGE = 'com.google.android.apps.chrome' | 22 CHROME_PACKAGE = 'com.google.android.apps.chrome' |
(...skipping 24 matching lines...) Expand all Loading... |
47 self._args = args | 47 self._args = args |
48 | 48 |
49 def __repr__(self): | 49 def __repr__(self): |
50 return 'PossibleAndroidBrowser(browser_type=%s)' % self.browser_type | 50 return 'PossibleAndroidBrowser(browser_type=%s)' % self.browser_type |
51 | 51 |
52 def Create(self): | 52 def Create(self): |
53 backend = android_browser_backend.AndroidBrowserBackend( | 53 backend = android_browser_backend.AndroidBrowserBackend( |
54 self._options, *self._args) | 54 self._options, *self._args) |
55 return browser.Browser(backend) | 55 return browser.Browser(backend) |
56 | 56 |
57 def FindAllAvailableBrowsers(options, | 57 def FindAllAvailableBrowsers(options): |
58 subprocess=real_subprocess, | |
59 adb_commands=real_adb_commands): | |
60 """Finds all the desktop browsers available on this machine.""" | 58 """Finds all the desktop browsers available on this machine.""" |
61 if not adb_commands.IsAndroidSupported(): | 59 if not adb_commands.IsAndroidSupported(): |
62 return [] | 60 return [] |
63 | 61 |
64 # See if adb even works. | 62 # See if adb even works. |
65 try: | 63 try: |
66 with open(real_os.devnull, 'w') as devnull: | 64 with open(os.devnull, 'w') as devnull: |
67 proc = subprocess.Popen(['adb', 'devices'], | 65 proc = subprocess.Popen(['adb', 'devices'], |
68 stdout=subprocess.PIPE, | 66 stdout=subprocess.PIPE, |
69 stderr=subprocess.PIPE, | 67 stderr=subprocess.PIPE, |
70 stdin=devnull) | 68 stdin=devnull) |
71 stdout, _ = proc.communicate() | 69 stdout, _ = proc.communicate() |
72 if re.search(re.escape('????????????\tno permissions'), stdout) != None: | 70 if re.search(re.escape('????????????\tno permissions'), stdout) != None: |
73 logging.warning( | 71 logging.warning( |
74 ('adb devices reported a permissions error. Consider ' | 72 ('adb devices reported a permissions error. Consider ' |
75 'restarting adb as root:')) | 73 'restarting adb as root:')) |
76 logging.warning(' adb kill-server') | 74 logging.warning(' adb kill-server') |
(...skipping 13 matching lines...) Expand all Loading... |
90 logging.info('No android devices found.') | 88 logging.info('No android devices found.') |
91 return [] | 89 return [] |
92 | 90 |
93 if len(devices) > 1: | 91 if len(devices) > 1: |
94 logging.warn('Multiple devices attached. ' + | 92 logging.warn('Multiple devices attached. ' + |
95 'Please specify a device explicitly.') | 93 'Please specify a device explicitly.') |
96 return [] | 94 return [] |
97 | 95 |
98 device = devices[0] | 96 device = devices[0] |
99 | 97 |
100 adb = adb_commands.ADBCommands(device=device) | 98 adb = adb_commands.AdbCommands(device=device) |
101 | 99 |
102 # See if adb is root | 100 # See if adb is root |
103 if not adb.IsRootEnabled(): | 101 if not adb.IsRootEnabled(): |
104 logging.warn('ADB is not root. Please make it root by doing:') | 102 logging.warn('ADB is not root. Please make it root by doing:') |
105 logging.warn(' adb root') | 103 logging.warn(' adb root') |
106 return [] | 104 return [] |
107 | 105 |
108 packages = adb.RunShellCommand('pm list packages') | 106 packages = adb.RunShellCommand('pm list packages') |
109 possible_browsers = [] | 107 possible_browsers = [] |
110 if 'package:' + CONTENT_SHELL_PACKAGE in packages: | 108 if 'package:' + CONTENT_SHELL_PACKAGE in packages: |
(...skipping 29 matching lines...) Expand all Loading... |
140 logging.warn('chrome_remote_control detected an android device. However,') | 138 logging.warn('chrome_remote_control detected an android device. However,') |
141 logging.warn('Chrome\'s port-forwarder app is not installed on the device.') | 139 logging.warn('Chrome\'s port-forwarder app is not installed on the device.') |
142 logging.warn('To build:') | 140 logging.warn('To build:') |
143 logging.warn(' make -j16 out/$BUILDTYPE/forwarder') | 141 logging.warn(' make -j16 out/$BUILDTYPE/forwarder') |
144 logging.warn('And then install it:') | 142 logging.warn('And then install it:') |
145 logging.warn(' %s', adb_commands.HowToInstallForwarder()) | 143 logging.warn(' %s', adb_commands.HowToInstallForwarder()) |
146 logging.warn('') | 144 logging.warn('') |
147 logging.warn('') | 145 logging.warn('') |
148 return [] | 146 return [] |
149 return possible_browsers | 147 return possible_browsers |
OLD | NEW |