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 | 4 |
5 """Provides an interface to communicate with the device via the adb command. | 5 """Provides an interface to communicate with the device via the adb command. |
6 | 6 |
7 Assumes adb binary is currently on system path. | 7 Assumes adb binary is currently on system path. |
8 """ | 8 """ |
9 | 9 |
10 import collections | 10 import collections |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\tdevice$', re.MULTILINE) | 107 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\tdevice$', re.MULTILINE) |
108 devices = re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH, | 108 devices = re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH, |
109 'devices'])) | 109 'devices'])) |
110 preferred_device = os.environ.get('ANDROID_SERIAL') | 110 preferred_device = os.environ.get('ANDROID_SERIAL') |
111 if preferred_device in devices: | 111 if preferred_device in devices: |
112 devices.remove(preferred_device) | 112 devices.remove(preferred_device) |
113 devices.insert(0, preferred_device) | 113 devices.insert(0, preferred_device) |
114 return devices | 114 return devices |
115 | 115 |
116 | 116 |
| 117 def GetAttachedOfflineDevices(): |
| 118 """Returns a list of attached, offline android devices. |
| 119 |
| 120 Returns: List of devices with status 'offline'. |
| 121 """ |
| 122 re_device = re.compile('^([a-zA-Z0-9_:.-]+)\toffline$', re.MULTILINE) |
| 123 return re_device.findall(cmd_helper.GetCmdOutput([constants.ADB_PATH, |
| 124 'devices'])) |
| 125 |
| 126 |
117 def IsDeviceAttached(device): | 127 def IsDeviceAttached(device): |
| 128 """Return true if the device is attached and online.""" |
118 return device in GetAttachedDevices() | 129 return device in GetAttachedDevices() |
119 | 130 |
120 | 131 |
121 def _GetFilesFromRecursiveLsOutput(path, ls_output, re_file, utc_offset=None): | 132 def _GetFilesFromRecursiveLsOutput(path, ls_output, re_file, utc_offset=None): |
122 """Gets a list of files from `ls` command output. | 133 """Gets a list of files from `ls` command output. |
123 | 134 |
124 Python's os.walk isn't used because it doesn't work over adb shell. | 135 Python's os.walk isn't used because it doesn't work over adb shell. |
125 | 136 |
126 Args: | 137 Args: |
127 path: The path to list. | 138 path: The path to list. |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 self._adb.SendCommand('reboot') | 335 self._adb.SendCommand('reboot') |
325 timeout = 300 | 336 timeout = 300 |
326 else: | 337 else: |
327 self.RestartShell() | 338 self.RestartShell() |
328 timeout = 120 | 339 timeout = 120 |
329 # To run tests we need at least the package manager and the sd card (or | 340 # To run tests we need at least the package manager and the sd card (or |
330 # other external storage) to be ready. | 341 # other external storage) to be ready. |
331 self.WaitForDevicePm() | 342 self.WaitForDevicePm() |
332 self.WaitForSdCardReady(timeout) | 343 self.WaitForSdCardReady(timeout) |
333 | 344 |
| 345 def Shutdown(self): |
| 346 """Shuts down the device.""" |
| 347 self._adb.SendCommand('reboot -p') |
| 348 |
334 def Uninstall(self, package): | 349 def Uninstall(self, package): |
335 """Uninstalls the specified package from the device. | 350 """Uninstalls the specified package from the device. |
336 | 351 |
337 Args: | 352 Args: |
338 package: Name of the package to remove. | 353 package: Name of the package to remove. |
339 | 354 |
340 Returns: | 355 Returns: |
341 A status string returned by adb uninstall | 356 A status string returned by adb uninstall |
342 """ | 357 """ |
343 uninstall_command = 'uninstall %s' % package | 358 uninstall_command = 'uninstall %s' % package |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 build_id = self.RunShellCommand('getprop ro.build.id')[0] | 928 build_id = self.RunShellCommand('getprop ro.build.id')[0] |
914 assert build_id | 929 assert build_id |
915 return build_id | 930 return build_id |
916 | 931 |
917 def GetBuildType(self): | 932 def GetBuildType(self): |
918 """Returns the build type of the system (e.g. eng).""" | 933 """Returns the build type of the system (e.g. eng).""" |
919 build_type = self.RunShellCommand('getprop ro.build.type')[0] | 934 build_type = self.RunShellCommand('getprop ro.build.type')[0] |
920 assert build_type | 935 assert build_type |
921 return build_type | 936 return build_type |
922 | 937 |
| 938 def GetBuildProduct(self): |
| 939 """Returns the build product of the device (e.g. maguro).""" |
| 940 build_product = self.RunShellCommand('getprop ro.build.product')[0] |
| 941 assert build_product |
| 942 return build_product |
| 943 |
| 944 def GetProductName(self): |
| 945 """Returns the product name of the device (e.g. takju).""" |
| 946 name = self.RunShellCommand('getprop ro.product.name')[0] |
| 947 assert name |
| 948 return name |
| 949 |
| 950 def GetBuildFingerprint(self): |
| 951 """Returns the build fingerprint of the device.""" |
| 952 build_fingerprint = self.RunShellCommand('getprop ro.build.fingerprint')[0] |
| 953 assert build_fingerprint |
| 954 return build_fingerprint |
| 955 |
923 def GetDescription(self): | 956 def GetDescription(self): |
924 """Returns the description of the system. | 957 """Returns the description of the system. |
925 | 958 |
926 For example, "yakju-userdebug 4.1 JRN54F 364167 dev-keys". | 959 For example, "yakju-userdebug 4.1 JRN54F 364167 dev-keys". |
927 """ | 960 """ |
928 description = self.RunShellCommand('getprop ro.build.description')[0] | 961 description = self.RunShellCommand('getprop ro.build.description')[0] |
929 assert description | 962 assert description |
930 return description | 963 return description |
931 | 964 |
932 def GetProductModel(self): | 965 def GetProductModel(self): |
933 """Returns the name of the product model (e.g. "Galaxy Nexus") """ | 966 """Returns the name of the product model (e.g. "Galaxy Nexus") """ |
934 model = self.RunShellCommand('getprop ro.product.model')[0] | 967 model = self.RunShellCommand('getprop ro.product.model')[0] |
935 assert model | 968 assert model |
936 return model | 969 return model |
937 | 970 |
| 971 def GetWifiIP(self): |
| 972 """Returns the wifi IP on the device.""" |
| 973 wifi_ip = self.RunShellCommand('getprop dhcp.wlan0.ipaddress')[0] |
| 974 assert wifi_ip |
| 975 return wifi_ip |
| 976 |
| 977 def GetSubscriberInfo(self): |
| 978 """Returns the device subscriber info (e.g. GSM and device ID) as string.""" |
| 979 iphone_sub = self.RunShellCommand('dumpsys iphonesubinfo') |
| 980 assert iphone_sub |
| 981 return '\n'.join(iphone_sub) |
| 982 |
| 983 def GetBatteryInfo(self): |
| 984 """Returns the device battery info (e.g. status, level, etc) as string.""" |
| 985 battery = self.RunShellCommand('dumpsys battery') |
| 986 assert battery |
| 987 return '\n'.join(battery) |
| 988 |
938 def StartMonitoringLogcat(self, clear=True, logfile=None, filters=None): | 989 def StartMonitoringLogcat(self, clear=True, logfile=None, filters=None): |
939 """Starts monitoring the output of logcat, for use with WaitForLogMatch. | 990 """Starts monitoring the output of logcat, for use with WaitForLogMatch. |
940 | 991 |
941 Args: | 992 Args: |
942 clear: If True the existing logcat output will be cleared, to avoiding | 993 clear: If True the existing logcat output will be cleared, to avoiding |
943 matching historical output lurking in the log. | 994 matching historical output lurking in the log. |
944 filters: A list of logcat filters to be used. | 995 filters: A list of logcat filters to be used. |
945 """ | 996 """ |
946 if clear: | 997 if clear: |
947 self.RunShellCommand('logcat -c') | 998 self.RunShellCommand('logcat -c') |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 """ | 1419 """ |
1369 def __init__(self, output): | 1420 def __init__(self, output): |
1370 self._output = output | 1421 self._output = output |
1371 | 1422 |
1372 def write(self, data): | 1423 def write(self, data): |
1373 data = data.replace('\r\r\n', '\n') | 1424 data = data.replace('\r\r\n', '\n') |
1374 self._output.write(data) | 1425 self._output.write(data) |
1375 | 1426 |
1376 def flush(self): | 1427 def flush(self): |
1377 self._output.flush() | 1428 self._output.flush() |
OLD | NEW |