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 from pylib import constants | 5 from pylib import constants |
6 | 6 |
7 | 7 |
8 class ContentSettings(dict): | 8 class ContentSettings(dict): |
9 | 9 |
10 """A dict interface to interact with device content settings. | 10 """A dict interface to interact with device content settings. |
11 | 11 |
12 System properties are key/value pairs as exposed by adb shell content. | 12 System properties are key/value pairs as exposed by adb shell content. |
13 """ | 13 """ |
14 | 14 |
15 def __init__(self, table, device): | 15 def __init__(self, table, device): |
16 super(ContentSettings, self).__init__() | 16 super(ContentSettings, self).__init__() |
17 sdk_version_string = device.GetProp('ro.build.version.sdk') | 17 assert (device.build_version_sdk |
18 try: | 18 >= constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN), ( |
19 sdk_version = int(sdk_version_string) | 19 'ContentSettings supported only on SDK 16 and later') |
20 assert sdk_version >= constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN, ( | |
21 'ContentSettings supported only on SDK 16 and later') | |
22 except ValueError: | |
23 assert False, ('Unknown SDK version %s' % sdk_version_string) | |
24 self._table = table | 20 self._table = table |
25 self._device = device | 21 self._device = device |
26 | 22 |
27 @staticmethod | 23 @staticmethod |
28 def _GetTypeBinding(value): | 24 def _GetTypeBinding(value): |
29 if isinstance(value, bool): | 25 if isinstance(value, bool): |
30 return 'b' | 26 return 'b' |
31 if isinstance(value, float): | 27 if isinstance(value, float): |
32 return 'f' | 28 return 'f' |
33 if isinstance(value, int): | 29 if isinstance(value, int): |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 self._GetTypeBinding(value), value), | 76 self._GetTypeBinding(value), value), |
81 as_root=True) | 77 as_root=True) |
82 | 78 |
83 def __delitem__(self, key): | 79 def __delitem__(self, key): |
84 self._device.RunShellCommand( | 80 self._device.RunShellCommand( |
85 'content delete --uri content://%s ' | 81 'content delete --uri content://%s ' |
86 '--bind name:%s:%s' % ( | 82 '--bind name:%s:%s' % ( |
87 self._table, | 83 self._table, |
88 self._GetTypeBinding(key), key), | 84 self._GetTypeBinding(key), key), |
89 as_root=True) | 85 as_root=True) |
OLD | NEW |