OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 a variety of device interactions based on adb. | 5 """Provides a variety of device interactions based on adb. |
6 | 6 |
7 Eventually, this will be based on adb_wrapper. | 7 Eventually, this will be based on adb_wrapper. |
8 """ | 8 """ |
9 # pylint: disable=unused-argument | 9 # pylint: disable=unused-argument |
10 | 10 |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 apks = [] | 379 apks = [] |
380 for line in output: | 380 for line in output: |
381 if not line.startswith('package:'): | 381 if not line.startswith('package:'): |
382 raise device_errors.CommandFailedError( | 382 raise device_errors.CommandFailedError( |
383 'pm path returned: %r' % '\n'.join(output), str(self)) | 383 'pm path returned: %r' % '\n'.join(output), str(self)) |
384 apks.append(line[len('package:'):]) | 384 apks.append(line[len('package:'):]) |
385 self._cache['package_apk_paths'][package] = list(apks) | 385 self._cache['package_apk_paths'][package] = list(apks) |
386 return apks | 386 return apks |
387 | 387 |
388 @decorators.WithTimeoutAndRetriesFromInstance() | 388 @decorators.WithTimeoutAndRetriesFromInstance() |
389 def GetApplicationVersion(self, package, timeout=None, retries=None): | |
390 """Get the version name of a package installed on the device. | |
391 | |
392 Args: | |
393 package: Name of the package. | |
394 | |
395 Returns: | |
396 A string with the version name or None if the package is not found | |
397 on the device. | |
398 """ | |
399 output = self.RunShellCommand( | |
400 ['dumpsys', 'package', package], check_return=True) | |
401 if not output: | |
402 return None | |
jbudorick
2015/08/26 13:01:18
Should this be an exception, too?
perezju
2015/08/26 13:21:12
This usually means that the app is not installed o
jbudorick
2015/08/26 13:22:51
Seems reasonable.
| |
403 for line in output: | |
404 line = line.strip() | |
405 if line.startswith('versionName='): | |
406 return line[len('versionName='):] | |
407 raise device_errors.CommandFailedError( | |
408 'Version name for %s not found on dumpsys output' % package, str(self)) | |
409 | |
410 @decorators.WithTimeoutAndRetriesFromInstance() | |
389 def GetApplicationDataDirectory(self, package, timeout=None, retries=None): | 411 def GetApplicationDataDirectory(self, package, timeout=None, retries=None): |
390 """Get the data directory on the device for the given package. | 412 """Get the data directory on the device for the given package. |
391 | 413 |
392 Args: | 414 Args: |
393 package: Name of the package. | 415 package: Name of the package. |
394 | 416 |
395 Returns: | 417 Returns: |
396 The package's data directory, or None if the package doesn't exist on the | 418 The package's data directory, or None if the package doesn't exist on the |
397 device. | 419 device. |
398 """ | 420 """ |
(...skipping 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1882 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() | 1904 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() |
1883 if not blacklisted(adb)] | 1905 if not blacklisted(adb)] |
1884 | 1906 |
1885 @decorators.WithTimeoutAndRetriesFromInstance() | 1907 @decorators.WithTimeoutAndRetriesFromInstance() |
1886 def RestartAdbd(self, timeout=None, retries=None): | 1908 def RestartAdbd(self, timeout=None, retries=None): |
1887 logging.info('Restarting adbd on device.') | 1909 logging.info('Restarting adbd on device.') |
1888 with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: | 1910 with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: |
1889 self.WriteFile(script.name, _RESTART_ADBD_SCRIPT) | 1911 self.WriteFile(script.name, _RESTART_ADBD_SCRIPT) |
1890 self.RunShellCommand(['source', script.name], as_root=True) | 1912 self.RunShellCommand(['source', script.name], as_root=True) |
1891 self.adb.WaitForDevice() | 1913 self.adb.WaitForDevice() |
OLD | NEW |