Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 | |
| 6 class SystemProperties(dict): | |
| 7 | |
| 8 """A dict interface to interact with device system properties. | |
| 9 | |
| 10 System properties are key/value pairs as exposed by adb shell getprop/setprop. | |
| 11 | |
| 12 This implementation minimizes interaction with the physical device. It is | |
| 13 valid for the lifetime of a boot. | |
| 14 """ | |
| 15 | |
| 16 def __init__(self, android_commands): | |
| 17 super(SystemProperties, self).__init__() | |
| 18 self._adb = android_commands | |
| 19 self._cached_static_properties = {} | |
| 20 | |
| 21 def __getitem__(self, key): | |
| 22 if self._IsStatic(key): | |
| 23 if key not in self._cached_static_properties: | |
| 24 self._cached_static_properties[key] = self._GetProperty(key) | |
| 25 return self._cached_static_properties[key] | |
| 26 return self._GetProperty(key) | |
| 27 | |
| 28 def __setitem__(self, key, value): | |
| 29 status = self._adb.SendShellCommand( | |
| 30 'setprop %s "%s"; echo $?' % (key, value), retry_count=3).strip() | |
|
frankf
2013/12/03 01:27:28
I tried on KRT16M and setprop returns 0 even if do
| |
| 31 if status != '0': | |
| 32 raise RuntimeError( | |
| 33 'Failed to setprop %s to %s. Exit status=%s' % (key, value, status)) | |
| 34 | |
| 35 def _IsStatic(self, key): | |
| 36 # TODO(tonyg): This list is conservative and could be expanded as needed. | |
| 37 return (key.startswith('ro.boot.') or | |
| 38 key.startswith('ro.build.') or | |
| 39 key.startswith('ro.product.')) | |
| 40 | |
| 41 def _GetProperty(self, key): | |
| 42 return self._adb.SendShellCommand('getprop %s' % key, retry_count=3).strip() | |
| OLD | NEW |