Chromium Code Reviews| 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 """ A simple device interface for build steps. | 5 """ A simple device interface for build steps. |
| 6 | 6 |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import logging | 9 import logging |
| 10 import os | 10 import os |
| 11 import re | 11 import re |
| 12 import sys | 12 import sys |
| 13 | 13 |
| 14 from util import build_utils | 14 from util import build_utils |
| 15 | 15 |
| 16 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..', '..') | 16 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..', '..') |
| 17 sys.path.append(BUILD_ANDROID_DIR) | 17 sys.path.append(BUILD_ANDROID_DIR) |
| 18 | 18 |
| 19 from pylib import android_commands | 19 from pylib import android_commands |
| 20 from pylib.device import device_errors | |
| 20 from pylib.device import device_utils | 21 from pylib.device import device_utils |
| 21 | 22 |
| 22 GetAttachedDevices = android_commands.GetAttachedDevices | 23 GetAttachedDevices = android_commands.GetAttachedDevices |
| 23 | 24 |
| 24 | 25 |
| 25 class BuildDevice(object): | 26 class BuildDevice(object): |
| 26 def __init__(self, configuration): | 27 def __init__(self, configuration): |
| 27 self.id = configuration['id'] | 28 self.id = configuration['id'] |
| 28 self.description = configuration['description'] | 29 self.description = configuration['description'] |
| 29 self.install_metadata = configuration['install_metadata'] | 30 self.install_metadata = configuration['install_metadata'] |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 50 # org.chromium.chrome.shell-1.apk | 51 # org.chromium.chrome.shell-1.apk |
| 51 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?.apk$' % apk_package, s) | 52 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?.apk$' % apk_package, s) |
| 52 matches = filter(apk_matcher, self.install_metadata) | 53 matches = filter(apk_matcher, self.install_metadata) |
| 53 return matches[0] if matches else None | 54 return matches[0] if matches else None |
| 54 | 55 |
| 55 | 56 |
| 56 def GetConfigurationForDevice(device_id): | 57 def GetConfigurationForDevice(device_id): |
| 57 device = device_utils.DeviceUtils(device_id) | 58 device = device_utils.DeviceUtils(device_id) |
| 58 configuration = None | 59 configuration = None |
| 59 has_root = False | 60 has_root = False |
| 60 is_online = device.old_interface.IsOnline() | 61 is_online = device.IsOnline() |
| 61 if is_online: | 62 if is_online: |
| 62 cmd = 'ls -l /data/app; getprop ro.build.description' | 63 cmd = 'ls -l /data/app; getprop ro.build.description' |
| 63 cmd_output = device.old_interface.RunShellCommand(cmd) | 64 cmd_output = device.old_interface.RunShellCommand(cmd) |
| 64 has_root = not 'Permission denied' in cmd_output[0] | 65 has_root = not 'Permission denied' in cmd_output[0] |
| 65 if not has_root: | 66 if not has_root: |
| 66 # Disable warning log messages from EnableAdbRoot() | 67 # Disable warning log messages from EnableRoot() |
| 67 logging.getLogger().disabled = True | 68 class LoggingDisabled(object): |
| 68 has_root = device.old_interface.EnableAdbRoot() | 69 def __enter__(self): |
| 69 logging.getLogger().disabled = False | 70 logging.getLogger().enabled = True |
|
craigdh
2014/05/14 20:33:08
I believe you meant disabled = True here
jbudorick
2014/05/14 21:02:01
Done.
| |
| 71 def __exit__(self, _a, _b, _c): | |
| 72 logging.getLogger().disabled = False | |
| 73 | |
| 74 with LoggingDisabled(): | |
| 75 try: | |
| 76 device.EnableRoot() | |
| 77 has_root = True | |
| 78 except device_errors.CommandFailedError: | |
| 79 has_root = False | |
| 70 cmd_output = device.old_interface.RunShellCommand(cmd) | 80 cmd_output = device.old_interface.RunShellCommand(cmd) |
| 71 | 81 |
| 72 configuration = { | 82 configuration = { |
| 73 'id': device_id, | 83 'id': device_id, |
| 74 'description': cmd_output[-1], | 84 'description': cmd_output[-1], |
| 75 'install_metadata': cmd_output[:-1], | 85 'install_metadata': cmd_output[:-1], |
| 76 } | 86 } |
| 77 return configuration, is_online, has_root | 87 return configuration, is_online, has_root |
| 78 | 88 |
| 79 | 89 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 90 assert len(configurations) == 1 | 100 assert len(configurations) == 1 |
| 91 return BuildDevice(configurations[0]) | 101 return BuildDevice(configurations[0]) |
| 92 | 102 |
| 93 | 103 |
| 94 def GetBuildDeviceFromPath(path): | 104 def GetBuildDeviceFromPath(path): |
| 95 configurations = ReadConfigurations(path) | 105 configurations = ReadConfigurations(path) |
| 96 if len(configurations) > 0: | 106 if len(configurations) > 0: |
| 97 return GetBuildDevice(ReadConfigurations(path)) | 107 return GetBuildDevice(ReadConfigurations(path)) |
| 98 return None | 108 return None |
| 99 | 109 |
| OLD | NEW |