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

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

Issue 360183002: Set lockscreen settings in the locksettings db. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Used --auto-bots arg to git cl upload. 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 | Annotate | Revision Log
« no previous file with comments | « build/android/provision_devices.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 from pylib.device import device_errors
9
10 _LOCK_SCREEN_SETTINGS_PATH = '/data/system/locksettings.db'
11 PASSWORD_QUALITY_UNSPECIFIED = 0
8 12
9 13
10 def ConfigureContentSettingsDict(device, desired_settings): 14 def ConfigureContentSettingsDict(device, desired_settings):
11 """Configures device content setings from a dictionary. 15 """Configures device content setings from a dictionary.
12 16
13 Many settings are documented at: 17 Many settings are documented at:
14 http://developer.android.com/reference/android/provider/Settings.Global.html 18 http://developer.android.com/reference/android/provider/Settings.Global.html
15 http://developer.android.com/reference/android/provider/Settings.Secure.html 19 http://developer.android.com/reference/android/provider/Settings.Secure.html
16 http://developer.android.com/reference/android/provider/Settings.System.html 20 http://developer.android.com/reference/android/provider/Settings.System.html
17 21
(...skipping 23 matching lines...) Expand all
41 if device.old_interface.GetBuildType() == 'userdebug': 45 if device.old_interface.GetBuildType() == 'userdebug':
42 for table, key_value in sorted(desired_settings.iteritems()): 46 for table, key_value in sorted(desired_settings.iteritems()):
43 settings = content_settings.ContentSettings(table, device) 47 settings = content_settings.ContentSettings(table, device)
44 for key, value in key_value.iteritems(): 48 for key, value in key_value.iteritems():
45 settings[key] = value 49 settings[key] = value
46 logging.info('\n%s %s', table, (80 - len(table)) * '-') 50 logging.info('\n%s %s', table, (80 - len(table)) * '-')
47 for key, value in sorted(settings.iteritems()): 51 for key, value in sorted(settings.iteritems()):
48 logging.info('\t%s: %s', key, value) 52 logging.info('\t%s: %s', key, value)
49 53
50 54
55 def SetLockScreenSettings(device):
56 """Sets lock screen settings on the device.
57
58 On certain device/Android configurations we need to disable the lock screen in
59 a different database. Additionally, the password type must be set to
60 DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED.
61 Lock screen settings are stored in sqlite on the device in:
62 /data/system/locksettings.db
63
64 IMPORTANT: The first column is used as a primary key so that all rows with the
65 same value for that column are removed from the table prior to inserting the
66 new values.
67
68 Args:
69 device: A DeviceUtils instance for the device to configure.
70
71 Raises:
72 Exception if the setting was not properly set.
73 """
74 if (not device.old_interface.FileExistsOnDevice(_LOCK_SCREEN_SETTINGS_PATH) or
75 device.old_interface.GetBuildType() != 'userdebug'):
76 return
77
78 db = _LOCK_SCREEN_SETTINGS_PATH
79 locksettings = [('locksettings', 'lockscreen.disabled', '1'),
80 ('locksettings', 'lockscreen.password_type',
81 str(PASSWORD_QUALITY_UNSPECIFIED)),
82 ('locksettings', 'lockscreen.password_type_alternate',
83 str(PASSWORD_QUALITY_UNSPECIFIED))]
84 for locksetting in locksettings:
jbudorick 2014/07/01 15:10:55 nit: These four lines could be collapsed into:
navabi 2014/07/01 22:44:43 Done.
85 table = locksetting[0]
86 key = locksetting[1]
87 value = locksetting[2]
88 # Set the lockscreen setting for default user '0'
89 columns = ['name', 'user', 'value']
90 values = [key, '0', value]
91 print 'db: %s' % db
jbudorick 2014/07/01 15:10:55 What's up with the prints? Are these left over fro
navabi 2014/07/01 22:44:43 Done. Yes. They are. Good catch.
92 print 'table: %s' % table
93 print 'columns: %s' % columns
94 print 'values: %s' % values
95 assert len(columns), 'must have at least one column'
jbudorick 2014/07/01 15:10:55 These asserts seems somewhat excessive given that
navabi 2014/07/01 22:44:43 Removed the asserts. These were copied over from a
96 assert len(columns) == len(values), 'need same number of columns and values'
97 assert '"' not in table, 'table cannot contain double quotes'
98 assert '"' not in ''.join(columns), 'columns cannot contain double quotes'
99 assert '"' not in ''.join(values), 'values cannot contain double quotes'
100 def escape(s):
jbudorick 2014/07/01 15:10:55 What's up with this? None of the items in |columns
navabi 2014/07/01 22:44:43 Removed this as well. See previous comment.
101 return s.replace("'", "''")
102
103 cmd = """begin transaction;
104 delete from '%(table)s' where %(primary_key)s='%(primary_value)s';
105 insert into '%(table)s' (%(columns)s) values (%(values)s);
106 commit transaction;""" % {
107 'table': table,
108 'primary_key': escape(columns[0]),
109 'primary_value': escape(values[0]),
110 'columns': ', '.join([escape(column) for column in columns]),
111 'values': ', '.join(["'%s'" % escape(value) for value in values])
112 }
113 try:
114 output_msg = device.RunShellCommand('\'sqlite3 %s "%s"\'' % (db, cmd))
jbudorick 2014/07/01 15:10:55 RunShellCommand should quote the command for you,
navabi 2014/07/01 22:44:43 I don't think it adds the single quotes correctly.
jbudorick 2014/07/02 01:01:29 In that case, this is fine with me. I'll have to l
115 except device_errors.CommandFailedError:
116 raise Exception('Failed to set system setting.\n%s' % ''.join(output_msg))
jbudorick 2014/07/01 15:10:55 If RunShellCommand raises an error, output_msg isn
navabi 2014/07/01 22:44:43 Done.
117
118
51 ENABLE_LOCATION_SETTING = { 119 ENABLE_LOCATION_SETTING = {
52 'settings/secure': { 120 'settings/secure': {
53 # Ensure Geolocation is enabled and allowed for tests. 121 # Ensure Geolocation is enabled and allowed for tests.
54 'location_providers_allowed': 'gps,network', 122 'location_providers_allowed': 'gps,network',
55 } 123 }
56 } 124 }
57 125
58 DISABLE_LOCATION_SETTING = { 126 DISABLE_LOCATION_SETTING = {
59 'settings/secure': { 127 'settings/secure': {
60 # Ensure Geolocation is disabled. 128 # Ensure Geolocation is disabled.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 }, 185 },
118 } 186 }
119 187
120 188
121 NETWORK_DISABLED_SETTINGS = { 189 NETWORK_DISABLED_SETTINGS = {
122 'settings/global': { 190 'settings/global': {
123 'airplane_mode_on': 1, 191 'airplane_mode_on': 1,
124 'wifi_on': 0, 192 'wifi_on': 0,
125 }, 193 },
126 } 194 }
OLDNEW
« no previous file with comments | « build/android/provision_devices.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698