Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1742)

Unified Diff: build/android/pylib/system_properties.py

Issue 99713002: Factor out a system_properties interface for interacting with getprop/setprop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use shlex.split() Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/android_commands.py ('k') | build/android/pylib/utils/test_environment.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/system_properties.py
diff --git a/build/android/pylib/system_properties.py b/build/android/pylib/system_properties.py
new file mode 100644
index 0000000000000000000000000000000000000000..c4f29fcf66edb67d56691bf67d947ff996ff7882
--- /dev/null
+++ b/build/android/pylib/system_properties.py
@@ -0,0 +1,39 @@
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+class SystemProperties(dict):
+
+ """A dict interface to interact with device system properties.
+
+ System properties are key/value pairs as exposed by adb shell getprop/setprop.
+
+ This implementation minimizes interaction with the physical device. It is
+ valid for the lifetime of a boot.
+ """
+
+ def __init__(self, android_commands):
+ super(SystemProperties, self).__init__()
+ self._adb = android_commands
+ self._cached_static_properties = {}
+
+ def __getitem__(self, key):
+ if self._IsStatic(key):
+ if key not in self._cached_static_properties:
+ self._cached_static_properties[key] = self._GetProperty(key)
+ return self._cached_static_properties[key]
+ return self._GetProperty(key)
+
+ def __setitem__(self, key, value):
+ # TODO(tonyg): This can fail with no root. Verify that it succeeds.
frankf 2013/12/03 18:44:07 In a future patch you can add an optional paramete
+ self._adb.SendShellCommand('setprop %s "%s"' % (key, value), retry_count=3)
+
+ def _IsStatic(self, key):
+ # TODO(tonyg): This list is conservative and could be expanded as needed.
+ return (key.startswith('ro.boot.') or
+ key.startswith('ro.build.') or
+ key.startswith('ro.product.'))
+
+ def _GetProperty(self, key):
+ return self._adb.SendShellCommand('getprop %s' % key, retry_count=3).strip()
« no previous file with comments | « build/android/pylib/android_commands.py ('k') | build/android/pylib/utils/test_environment.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698