Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / build / android / pylib / content_settings.py
blob8594140856d8765f0014cb80a81bb7e53e2425e2
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
3 # found in the LICENSE file.
5 from pylib import constants
8 class ContentSettings(dict):
10 """A dict interface to interact with device content settings.
12 System properties are key/value pairs as exposed by adb shell content.
13 """
15 def __init__(self, table, device):
16 super(ContentSettings, self).__init__()
17 self._table = table
18 self._device = device
20 @staticmethod
21 def _GetTypeBinding(value):
22 if isinstance(value, bool):
23 return 'b'
24 if isinstance(value, float):
25 return 'f'
26 if isinstance(value, int):
27 return 'i'
28 if isinstance(value, long):
29 return 'l'
30 if isinstance(value, str):
31 return 's'
32 raise ValueError('Unsupported type %s' % type(value))
34 def iteritems(self):
35 # Example row:
36 # 'Row: 0 _id=13, name=logging_id2, value=-1fccbaa546705b05'
37 for row in self._device.RunShellCommand(
38 'content query --uri content://%s' % self._table, as_root=True):
39 fields = row.split(', ')
40 key = None
41 value = None
42 for field in fields:
43 k, _, v = field.partition('=')
44 if k == 'name':
45 key = v
46 elif k == 'value':
47 value = v
48 if not key:
49 continue
50 if not value:
51 value = ''
52 yield key, value
54 def __getitem__(self, key):
55 return self._device.RunShellCommand(
56 'content query --uri content://%s --where "name=\'%s\'" '
57 '--projection value' % (self._table, key), as_root=True).strip()
59 def __setitem__(self, key, value):
60 if key in self:
61 self._device.RunShellCommand(
62 'content update --uri content://%s '
63 '--bind value:%s:%s --where "name=\'%s\'"' % (
64 self._table,
65 self._GetTypeBinding(value), value, key),
66 as_root=True)
67 else:
68 self._device.RunShellCommand(
69 'content insert --uri content://%s '
70 '--bind name:%s:%s --bind value:%s:%s' % (
71 self._table,
72 self._GetTypeBinding(key), key,
73 self._GetTypeBinding(value), value),
74 as_root=True)
76 def __delitem__(self, key):
77 self._device.RunShellCommand(
78 'content delete --uri content://%s '
79 '--bind name:%s:%s' % (
80 self._table,
81 self._GetTypeBinding(key), key),
82 as_root=True)