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 | 5 |
6 class ContentSettings(dict): | 6 class ContentSettings(dict): |
7 | 7 |
8 """A dict interface to interact with device content settings. | 8 """A dict interface to interact with device content settings. |
9 | 9 |
10 System properties are key/value pairs as exposed by adb shell content. | 10 System properties are key/value pairs as exposed by adb shell content. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 'content query --uri content://%s' % self._table, as_root=True): | 43 'content query --uri content://%s' % self._table, as_root=True): |
44 fields = row.split(', ') | 44 fields = row.split(', ') |
45 key = None | 45 key = None |
46 value = None | 46 value = None |
47 for field in fields: | 47 for field in fields: |
48 k, _, v = field.partition('=') | 48 k, _, v = field.partition('=') |
49 if k == 'name': | 49 if k == 'name': |
50 key = v | 50 key = v |
51 elif k == 'value': | 51 elif k == 'value': |
52 value = v | 52 value = v |
53 assert key, value | 53 if not key: |
| 54 continue |
| 55 if not value: |
| 56 value = '' |
54 yield key, value | 57 yield key, value |
55 | 58 |
56 def __getitem__(self, key): | 59 def __getitem__(self, key): |
57 return self._device.RunShellCommand( | 60 return self._device.RunShellCommand( |
58 'content query --uri content://%s --where "name=\'%s\'" ' | 61 'content query --uri content://%s --where "name=\'%s\'" ' |
59 '--projection value' % (self._table, key), as_root=True).strip() | 62 '--projection value' % (self._table, key), as_root=True).strip() |
60 | 63 |
61 def __setitem__(self, key, value): | 64 def __setitem__(self, key, value): |
62 if key in self: | 65 if key in self: |
63 self._device.RunShellCommand( | 66 self._device.RunShellCommand( |
(...skipping 11 matching lines...) Expand all Loading... |
75 self._GetTypeBinding(value), value), | 78 self._GetTypeBinding(value), value), |
76 as_root=True) | 79 as_root=True) |
77 | 80 |
78 def __delitem__(self, key): | 81 def __delitem__(self, key): |
79 self._device.RunShellCommand( | 82 self._device.RunShellCommand( |
80 'content delete --uri content://%s ' | 83 'content delete --uri content://%s ' |
81 '--bind name:%s:%s' % ( | 84 '--bind name:%s:%s' % ( |
82 self._table, | 85 self._table, |
83 self._GetTypeBinding(key), key), | 86 self._GetTypeBinding(key), key), |
84 as_root=True) | 87 as_root=True) |
OLD | NEW |