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