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.
7 from pylib import content_settings
9 _LOCK_SCREEN_SETTINGS_PATH = '/data/system/locksettings.db'
10 PASSWORD_QUALITY_UNSPECIFIED = '0'
13 def ConfigureContentSettingsDict(device, desired_settings):
14 """Configures device content setings from a dictionary.
16 Many settings are documented at:
17 http://developer.android.com/reference/android/provider/Settings.Global.html
18 http://developer.android.com/reference/android/provider/Settings.Secure.html
19 http://developer.android.com/reference/android/provider/Settings.System.html
21 Many others are undocumented.
24 device: A DeviceUtils instance for the device to configure.
25 desired_settings: A dict of {table: {key: value}} for all
26 settings to configure.
29 sdk_version = int(device.GetProp('ro.build.version.sdk'))
31 logging.error('Skipping content settings configuration, unknown sdk %s',
32 device.GetProp('ro.build.version.sdk'))
36 logging.error('Skipping content settings configuration due to outdated sdk')
39 device.SetProp('persist.sys.usb.config', 'adb')
40 device.old_interface.WaitForDevicePm()
42 if device.GetProp('ro.build.type') == 'userdebug':
43 for table, key_value in sorted(desired_settings.iteritems()):
44 settings = content_settings.ContentSettings(table, device)
45 for key, value in key_value.iteritems():
47 logging.info('\n%s %s', table, (80 - len(table)) * '-')
48 for key, value in sorted(settings.iteritems()):
49 logging.info('\t%s: %s', key, value)
52 def SetLockScreenSettings(device):
53 """Sets lock screen settings on the device.
55 On certain device/Android configurations we need to disable the lock screen in
56 a different database. Additionally, the password type must be set to
57 DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED.
58 Lock screen settings are stored in sqlite on the device in:
59 /data/system/locksettings.db
61 IMPORTANT: The first column is used as a primary key so that all rows with the
62 same value for that column are removed from the table prior to inserting the
66 device: A DeviceUtils instance for the device to configure.
69 Exception if the setting was not properly set.
71 if (not device.old_interface.FileExistsOnDevice(_LOCK_SCREEN_SETTINGS_PATH) or
72 device.GetProp('ro.build.type') != 'userdebug'):
75 db = _LOCK_SCREEN_SETTINGS_PATH
76 locksettings = [('locksettings', 'lockscreen.disabled', '1'),
77 ('locksettings', 'lockscreen.password_type',
78 PASSWORD_QUALITY_UNSPECIFIED),
79 ('locksettings', 'lockscreen.password_type_alternate',
80 PASSWORD_QUALITY_UNSPECIFIED)]
81 for table, key, value in locksettings:
82 # Set the lockscreen setting for default user '0'
83 columns = ['name', 'user', 'value']
84 values = [key, '0', value]
86 cmd = """begin transaction;
87 delete from '%(table)s' where %(primary_key)s='%(primary_value)s';
88 insert into '%(table)s' (%(columns)s) values (%(values)s);
89 commit transaction;""" % {
91 'primary_key': columns[0],
92 'primary_value': values[0],
93 'columns': ', '.join(columns),
94 'values': ', '.join(["'%s'" % value for value in values])
96 output_msg = device.RunShellCommand('\'sqlite3 %s "%s"\'' % (db, cmd))
98 print ' '.join(output_msg)
101 ENABLE_LOCATION_SETTING = {
103 # Ensure Geolocation is enabled and allowed for tests.
104 'location_providers_allowed': 'gps,network',
108 DISABLE_LOCATION_SETTING = {
110 # Ensure Geolocation is disabled.
111 'location_providers_allowed': '',
115 DETERMINISTIC_DEVICE_SETTINGS = {
116 'com.google.settings/partner': {
117 'network_location_opt_in': 0,
118 'use_location_for_services': 1,
121 'assisted_gps_enabled': 0,
123 # Disable "auto time" and "auto time zone" to avoid network-provided time
124 # to overwrite the device's datetime and timezone synchronized from host
125 # when running tests later. See b/6569849.
129 'development_settings_enabled': 1,
131 # Flag for allowing ActivityManagerService to send ACTION_APP_ERROR intents
132 # on application crashes and ANRs. If this is disabled, the crash/ANR dialog
133 # will never display the "Report" button.
134 # Type: int ( 0 = disallow, 1 = allow )
135 'send_action_app_error': 0,
137 'stay_on_while_plugged_in': 3,
139 'verifier_verify_adb_installs' : 0,
142 'allowed_geolocation_origins':
143 'http://www.google.co.uk http://www.google.com',
145 # Ensure that we never get random dialogs like "Unfortunately the process
146 # android.process.acore has stopped", which steal the focus, and make our
147 # automation fail (because the dialog steals the focus then mistakenly
148 # receives the injected user input events).
149 'anr_show_background': 0,
151 'lockscreen.disabled': 1,
153 'screensaver_enabled': 0,
156 # Don't want devices to accidentally rotate the screen as that could
157 # affect performance measurements.
158 'accelerometer_rotation': 0,
160 'lockscreen.disabled': 1,
162 # Turn down brightness and disable auto-adjust so that devices run cooler.
163 'screen_brightness': 5,
164 'screen_brightness_mode': 0,
171 NETWORK_DISABLED_SETTINGS = {
173 'airplane_mode_on': 1,