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.
6 class ContentSettings(dict):
8 """A dict interface to interact with device content settings.
10 System properties are key/value pairs as exposed by adb shell content.
13 def __init__(self
, table
, device
):
14 super(ContentSettings
, self
).__init
__()
19 def _GetTypeBinding(value
):
20 if isinstance(value
, bool):
22 if isinstance(value
, float):
24 if isinstance(value
, int):
26 if isinstance(value
, long):
28 if isinstance(value
, str):
30 raise ValueError('Unsupported type %s' % type(value
))
34 # 'Row: 0 _id=13, name=logging_id2, value=-1fccbaa546705b05'
35 for row
in self
._device
.RunShellCommand(
36 'content query --uri content://%s' % self
._table
, as_root
=True):
37 fields
= row
.split(', ')
41 k
, _
, v
= field
.partition('=')
52 def __getitem__(self
, key
):
53 return self
._device
.RunShellCommand(
54 'content query --uri content://%s --where "name=\'%s\'" '
55 '--projection value' % (self
._table
, key
), as_root
=True).strip()
57 def __setitem__(self
, key
, value
):
59 self
._device
.RunShellCommand(
60 'content update --uri content://%s '
61 '--bind value:%s:%s --where "name=\'%s\'"' % (
63 self
._GetTypeBinding
(value
), value
, key
),
66 self
._device
.RunShellCommand(
67 'content insert --uri content://%s '
68 '--bind name:%s:%s --bind value:%s:%s' % (
70 self
._GetTypeBinding
(key
), key
,
71 self
._GetTypeBinding
(value
), value
),
74 def __delitem__(self
, key
):
75 self
._device
.RunShellCommand(
76 'content delete --uri content://%s '
77 '--bind name:%s:%s' % (
79 self
._GetTypeBinding
(key
), key
),