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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 'content query --uri content://%s' % self._table): | 44 'content query --uri content://%s' % self._table): |
45 fields = row.split(', ') | 45 fields = row.split(', ') |
46 key = None | 46 key = None |
47 value = None | 47 value = None |
48 for field in fields: | 48 for field in fields: |
49 k, _, v = field.partition('=') | 49 k, _, v = field.partition('=') |
50 if k == 'name': | 50 if k == 'name': |
51 key = v | 51 key = v |
52 elif k == 'value': | 52 elif k == 'value': |
53 value = v | 53 value = v |
54 print 'asserting %s, %s' % (key, value) | |
navabi
2014/04/29 07:53:28
remove this debugging print.
| |
54 assert key, value | 55 assert key, value |
55 yield key, value | 56 yield key, value |
56 | 57 |
57 def __getitem__(self, key): | 58 def __getitem__(self, key): |
58 return self._device.old_interface.RunShellCommandWithSU( | 59 return self._device.old_interface.RunShellCommandWithSU( |
59 'content query --uri content://%s --where "name=\'%s\'" ' | 60 'content query --uri content://%s --where "name=\'%s\'" ' |
60 '--projection value' % (self._table, key)).strip() | 61 '--projection value' % (self._table, key)).strip() |
61 | 62 |
62 def __setitem__(self, key, value): | 63 def __setitem__(self, key, value): |
63 if key in self: | 64 if key in self: |
64 self._device.old_interface.RunShellCommandWithSU( | 65 self._device.old_interface.RunShellCommandWithSU( |
65 'content update --uri content://%s ' | 66 'content update --uri content://%s ' |
66 '--bind value:%s:%s --where "name=\'%s\'"' % ( | 67 '--bind value:%s:%s --where "name=\'%s\'"' % ( |
67 self._table, | 68 self._table, |
68 self._GetTypeBinding(value), value, key)) | 69 self._GetTypeBinding(value), value, key)) |
69 else: | 70 else: |
70 self._device.old_interface.RunShellCommandWithSU( | 71 self._device.old_interface.RunShellCommandWithSU( |
71 'content insert --uri content://%s ' | 72 'content insert --uri content://%s ' |
72 '--bind name:%s:%s --bind value:%s:%s' % ( | 73 '--bind name:%s:%s --bind value:%s:%s' % ( |
73 self._table, | 74 self._table, |
74 self._GetTypeBinding(key), key, | 75 self._GetTypeBinding(key), key, |
75 self._GetTypeBinding(value), value)) | 76 self._GetTypeBinding(value), value)) |
76 | 77 |
77 def __delitem__(self, key): | 78 def __delitem__(self, key): |
78 self._device.old_interface.RunShellCommandWithSU( | 79 self._device.old_interface.RunShellCommandWithSU( |
79 'content delete --uri content://%s ' | 80 'content delete --uri content://%s ' |
80 '--bind name:%s:%s' % ( | 81 '--bind name:%s:%s' % ( |
81 self._table, | 82 self._table, |
82 self._GetTypeBinding(key), key)) | 83 self._GetTypeBinding(key), key)) |
OLD | NEW |