Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: build/android/pylib/device_settings.py

Issue 371813005: [Android] Switch to DeviceUtils versions of Ls, SetJavaAsserts, GetProp, and SetProp. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 import logging 5 import logging
6 6
7 from pylib import content_settings 7 from pylib import content_settings
8 8
9 _LOCK_SCREEN_SETTINGS_PATH = '/data/system/locksettings.db' 9 _LOCK_SCREEN_SETTINGS_PATH = '/data/system/locksettings.db'
10 PASSWORD_QUALITY_UNSPECIFIED = '0' 10 PASSWORD_QUALITY_UNSPECIFIED = '0'
11 11
12 12
13 def ConfigureContentSettingsDict(device, desired_settings): 13 def ConfigureContentSettingsDict(device, desired_settings):
14 """Configures device content setings from a dictionary. 14 """Configures device content setings from a dictionary.
15 15
16 Many settings are documented at: 16 Many settings are documented at:
17 http://developer.android.com/reference/android/provider/Settings.Global.html 17 http://developer.android.com/reference/android/provider/Settings.Global.html
18 http://developer.android.com/reference/android/provider/Settings.Secure.html 18 http://developer.android.com/reference/android/provider/Settings.Secure.html
19 http://developer.android.com/reference/android/provider/Settings.System.html 19 http://developer.android.com/reference/android/provider/Settings.System.html
20 20
21 Many others are undocumented. 21 Many others are undocumented.
22 22
23 Args: 23 Args:
24 device: A DeviceUtils instance for the device to configure. 24 device: A DeviceUtils instance for the device to configure.
25 desired_settings: A dict of {table: {key: value}} for all 25 desired_settings: A dict of {table: {key: value}} for all
26 settings to configure. 26 settings to configure.
27 """ 27 """
28 try: 28 try:
29 sdk_version = int(device.old_interface.system_properties[ 29 sdk_version = int(device.GetProp('ro.build.version.sdk'))
30 'ro.build.version.sdk'])
31 except ValueError: 30 except ValueError:
32 logging.error('Skipping content settings configuration, unknown sdk %s', 31 logging.error('Skipping content settings configuration, unknown sdk %s',
33 device.old_interface.system_properties[ 32 device.GetProp('ro.build.version.sdk'))
34 'ro.build.version.sdk'])
35 return 33 return
36 34
37 if sdk_version < 16: 35 if sdk_version < 16:
38 logging.error('Skipping content settings configuration due to outdated sdk') 36 logging.error('Skipping content settings configuration due to outdated sdk')
39 return 37 return
40 38
41 device.old_interface.system_properties['persist.sys.usb.config'] = 'adb' 39 device.SetProp('persist.sys.usb.config', 'adb')
42 device.old_interface.WaitForDevicePm() 40 device.old_interface.WaitForDevicePm()
43 41
44 if device.old_interface.GetBuildType() == 'userdebug': 42 if device.GetProp('ro.build.type') == 'userdebug':
45 for table, key_value in sorted(desired_settings.iteritems()): 43 for table, key_value in sorted(desired_settings.iteritems()):
46 settings = content_settings.ContentSettings(table, device) 44 settings = content_settings.ContentSettings(table, device)
47 for key, value in key_value.iteritems(): 45 for key, value in key_value.iteritems():
48 settings[key] = value 46 settings[key] = value
49 logging.info('\n%s %s', table, (80 - len(table)) * '-') 47 logging.info('\n%s %s', table, (80 - len(table)) * '-')
50 for key, value in sorted(settings.iteritems()): 48 for key, value in sorted(settings.iteritems()):
51 logging.info('\t%s: %s', key, value) 49 logging.info('\t%s: %s', key, value)
52 50
53 51
54 def SetLockScreenSettings(device): 52 def SetLockScreenSettings(device):
55 """Sets lock screen settings on the device. 53 """Sets lock screen settings on the device.
56 54
57 On certain device/Android configurations we need to disable the lock screen in 55 On certain device/Android configurations we need to disable the lock screen in
58 a different database. Additionally, the password type must be set to 56 a different database. Additionally, the password type must be set to
59 DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED. 57 DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED.
60 Lock screen settings are stored in sqlite on the device in: 58 Lock screen settings are stored in sqlite on the device in:
61 /data/system/locksettings.db 59 /data/system/locksettings.db
62 60
63 IMPORTANT: The first column is used as a primary key so that all rows with the 61 IMPORTANT: The first column is used as a primary key so that all rows with the
64 same value for that column are removed from the table prior to inserting the 62 same value for that column are removed from the table prior to inserting the
65 new values. 63 new values.
66 64
67 Args: 65 Args:
68 device: A DeviceUtils instance for the device to configure. 66 device: A DeviceUtils instance for the device to configure.
69 67
70 Raises: 68 Raises:
71 Exception if the setting was not properly set. 69 Exception if the setting was not properly set.
72 """ 70 """
73 if (not device.old_interface.FileExistsOnDevice(_LOCK_SCREEN_SETTINGS_PATH) or 71 if (not device.old_interface.FileExistsOnDevice(_LOCK_SCREEN_SETTINGS_PATH) or
74 device.old_interface.GetBuildType() != 'userdebug'): 72 device.GetProp('ro.build.type') != 'userdebug'):
75 return 73 return
76 74
77 db = _LOCK_SCREEN_SETTINGS_PATH 75 db = _LOCK_SCREEN_SETTINGS_PATH
78 locksettings = [('locksettings', 'lockscreen.disabled', '1'), 76 locksettings = [('locksettings', 'lockscreen.disabled', '1'),
79 ('locksettings', 'lockscreen.password_type', 77 ('locksettings', 'lockscreen.password_type',
80 PASSWORD_QUALITY_UNSPECIFIED), 78 PASSWORD_QUALITY_UNSPECIFIED),
81 ('locksettings', 'lockscreen.password_type_alternate', 79 ('locksettings', 'lockscreen.password_type_alternate',
82 PASSWORD_QUALITY_UNSPECIFIED)] 80 PASSWORD_QUALITY_UNSPECIFIED)]
83 for table, key, value in locksettings: 81 for table, key, value in locksettings:
84 # Set the lockscreen setting for default user '0' 82 # Set the lockscreen setting for default user '0'
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 }, 167 },
170 } 168 }
171 169
172 170
173 NETWORK_DISABLED_SETTINGS = { 171 NETWORK_DISABLED_SETTINGS = {
174 'settings/global': { 172 'settings/global': {
175 'airplane_mode_on': 1, 173 'airplane_mode_on': 1,
176 'wifi_on': 0, 174 'wifi_on': 0,
177 }, 175 },
178 } 176 }
OLDNEW
« no previous file with comments | « build/android/pylib/device/device_utils_test.py ('k') | build/android/pylib/instrumentation/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698