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. |
11 """ | 11 """ |
12 | 12 |
13 def __init__(self, table, adb): | 13 def __init__(self, table, adb): |
14 super(ContentSettings, self).__init__() | 14 super(ContentSettings, self).__init__() |
15 try: | 15 try: |
16 sdk_version = int(adb.system_properties['ro.build.version.sdk']) | 16 sdk_version = int(adb.system_properties['ro.build.version.sdk']) |
17 assert sdk_version >= 16, ( | 17 assert sdk_version >= 16, ( |
18 'ContentSettings supported only on SDK 16 and later') | 18 'ContentSettings supported only on SDK 16 and later') |
19 except ValueError: | 19 except ValueError: |
20 assert False, ('Unknown SDK version %s' % | 20 assert False, ('Unknown SDK version %s' % |
21 adb.system_properties['ro.build.version.sdk']) | 21 adb.system_properties['ro.build.version.sdk']) |
22 self._table = table | 22 self._table = table |
23 self._adb = adb | 23 self._adb = adb |
24 | 24 |
25 def _GetTypeBinding(self, value): | 25 @staticmethod |
| 26 def _GetTypeBinding(value): |
26 if isinstance(value, bool): | 27 if isinstance(value, bool): |
27 return 'b' | 28 return 'b' |
28 if isinstance(value, float): | 29 if isinstance(value, float): |
29 return 'f' | 30 return 'f' |
30 if isinstance(value, int): | 31 if isinstance(value, int): |
31 return 'i' | 32 return 'i' |
32 if isinstance(value, long): | 33 if isinstance(value, long): |
33 return 'l' | 34 return 'l' |
34 if isinstance(value, str): | 35 if isinstance(value, str): |
35 return 's' | 36 return 's' |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 self._table, | 72 self._table, |
72 self._GetTypeBinding(key), key, | 73 self._GetTypeBinding(key), key, |
73 self._GetTypeBinding(value), value)) | 74 self._GetTypeBinding(value), value)) |
74 | 75 |
75 def __delitem__(self, key): | 76 def __delitem__(self, key): |
76 self._adb.RunShellCommandWithSU( | 77 self._adb.RunShellCommandWithSU( |
77 'content delete --uri content://%s ' | 78 'content delete --uri content://%s ' |
78 '--bind name:%s:%s' % ( | 79 '--bind name:%s:%s' % ( |
79 self._table, | 80 self._table, |
80 self._GetTypeBinding(key), key)) | 81 self._GetTypeBinding(key), key)) |
OLD | NEW |