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.
15 def __init__(self
, table
, device
):
16 super(ContentSettings
, self
).__init
__()
21 def _GetTypeBinding(value
):
22 if isinstance(value
, bool):
24 if isinstance(value
, float):
26 if isinstance(value
, int):
28 if isinstance(value
, long):
30 if isinstance(value
, str):
32 raise ValueError('Unsupported type %s' % type(value
))
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(', ')
43 k
, _
, v
= field
.partition('=')
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
):
61 self
._device
.RunShellCommand(
62 'content update --uri content://%s '
63 '--bind value:%s:%s --where "name=\'%s\'"' % (
65 self
._GetTypeBinding
(value
), value
, key
),
68 self
._device
.RunShellCommand(
69 'content insert --uri content://%s '
70 '--bind name:%s:%s --bind value:%s:%s' % (
72 self
._GetTypeBinding
(key
), key
,
73 self
._GetTypeBinding
(value
), value
),
76 def __delitem__(self
, key
):
77 self
._device
.RunShellCommand(
78 'content delete --uri content://%s '
79 '--bind name:%s:%s' % (
81 self
._GetTypeBinding
(key
), key
),