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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/provision_devices.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/device_settings.py
diff --git a/build/android/pylib/device_settings.py b/build/android/pylib/device_settings.py
index deb673b971dd9e8f9f736e197074a8f656b6f434..13aa29ceea91bfde1221c0512510edfecdf03de1 100644
--- a/build/android/pylib/device_settings.py
+++ b/build/android/pylib/device_settings.py
@@ -5,6 +5,10 @@
import logging
from pylib import content_settings
+from pylib.device import device_errors
+
+_LOCK_SCREEN_SETTINGS_PATH = '/data/system/locksettings.db'
+PASSWORD_QUALITY_UNSPECIFIED = 0
def ConfigureContentSettingsDict(device, desired_settings):
@@ -48,6 +52,70 @@ def ConfigureContentSettingsDict(device, desired_settings):
logging.info('\t%s: %s', key, value)
+def SetLockScreenSettings(device):
+ """Sets lock screen settings on the device.
+
+ On certain device/Android configurations we need to disable the lock screen in
+ a different database. Additionally, the password type must be set to
+ DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED.
+ Lock screen settings are stored in sqlite on the device in:
+ /data/system/locksettings.db
+
+ IMPORTANT: The first column is used as a primary key so that all rows with the
+ same value for that column are removed from the table prior to inserting the
+ new values.
+
+ Args:
+ device: A DeviceUtils instance for the device to configure.
+
+ Raises:
+ Exception if the setting was not properly set.
+ """
+ if (not device.old_interface.FileExistsOnDevice(_LOCK_SCREEN_SETTINGS_PATH) or
+ device.old_interface.GetBuildType() != 'userdebug'):
+ return
+
+ db = _LOCK_SCREEN_SETTINGS_PATH
+ locksettings = [('locksettings', 'lockscreen.disabled', '1'),
+ ('locksettings', 'lockscreen.password_type',
+ str(PASSWORD_QUALITY_UNSPECIFIED)),
+ ('locksettings', 'lockscreen.password_type_alternate',
+ str(PASSWORD_QUALITY_UNSPECIFIED))]
+ 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.
+ table = locksetting[0]
+ key = locksetting[1]
+ value = locksetting[2]
+ # Set the lockscreen setting for default user '0'
+ columns = ['name', 'user', 'value']
+ values = [key, '0', value]
+ 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.
+ print 'table: %s' % table
+ print 'columns: %s' % columns
+ print 'values: %s' % values
+ 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
+ assert len(columns) == len(values), 'need same number of columns and values'
+ assert '"' not in table, 'table cannot contain double quotes'
+ assert '"' not in ''.join(columns), 'columns cannot contain double quotes'
+ assert '"' not in ''.join(values), 'values cannot contain double quotes'
+ 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.
+ return s.replace("'", "''")
+
+ cmd = """begin transaction;
+delete from '%(table)s' where %(primary_key)s='%(primary_value)s';
+insert into '%(table)s' (%(columns)s) values (%(values)s);
+commit transaction;""" % {
+ 'table': table,
+ 'primary_key': escape(columns[0]),
+ 'primary_value': escape(values[0]),
+ 'columns': ', '.join([escape(column) for column in columns]),
+ 'values': ', '.join(["'%s'" % escape(value) for value in values])
+ }
+ try:
+ 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
+ except device_errors.CommandFailedError:
+ 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.
+
+
ENABLE_LOCATION_SETTING = {
'settings/secure': {
# Ensure Geolocation is enabled and allowed for tests.
« 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