Adding Peter Thatcher to the owners file.
[chromium-blink-merge.git] / build / android / pylib / device_settings.py
blob73ffa72966da777e22d15ed495221269ec576aeb
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 import logging
7 from pylib import constants
8 from pylib import content_settings
9 from pylib.device import device_errors
11 _LOCK_SCREEN_SETTINGS_PATH = '/data/system/locksettings.db'
12 _ALTERNATE_LOCK_SCREEN_SETTINGS_PATH = (
13 '/data/data/com.android.providers.settings/databases/settings.db')
14 PASSWORD_QUALITY_UNSPECIFIED = '0'
17 def ConfigureContentSettings(device, desired_settings):
18 """Configures device content setings from a list.
20 Many settings are documented at:
21 http://developer.android.com/reference/android/provider/Settings.Global.html
22 http://developer.android.com/reference/android/provider/Settings.Secure.html
23 http://developer.android.com/reference/android/provider/Settings.System.html
25 Many others are undocumented.
27 Args:
28 device: A DeviceUtils instance for the device to configure.
29 desired_settings: A list of (table, [(key: value), ...]) for all
30 settings to configure.
31 """
32 try:
33 sdk_version = device.build_version_sdk
34 except device_errors.CommandFailedError as exc:
35 logging.error('Skipping content settings configuration: %s', str(exc))
36 return
38 if sdk_version < constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN:
39 logging.error('Skipping content settings configuration due to outdated sdk')
40 return
42 if device.build_type == 'userdebug':
43 for table, key_value in desired_settings:
44 settings = content_settings.ContentSettings(table, device)
45 for key, value in key_value:
46 settings[key] = value
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
63 new values.
65 Args:
66 device: A DeviceUtils instance for the device to configure.
68 Raises:
69 Exception if the setting was not properly set.
70 """
71 if device.build_type != 'userdebug':
72 logging.warning('Unable to disable lockscreen on user builds.')
73 return
75 def get_lock_settings(table):
76 return [(table, 'lockscreen.disabled', '1'),
77 (table, 'lockscreen.password_type', PASSWORD_QUALITY_UNSPECIFIED),
78 (table, 'lockscreen.password_type_alternate',
79 PASSWORD_QUALITY_UNSPECIFIED)]
81 if device.FileExists(_LOCK_SCREEN_SETTINGS_PATH):
82 db = _LOCK_SCREEN_SETTINGS_PATH
83 locksettings = get_lock_settings('locksettings')
84 columns = ['name', 'user', 'value']
85 generate_values = lambda k, v: [k, '0', v]
86 elif device.FileExists(_ALTERNATE_LOCK_SCREEN_SETTINGS_PATH):
87 db = _ALTERNATE_LOCK_SCREEN_SETTINGS_PATH
88 locksettings = get_lock_settings('secure') + get_lock_settings('system')
89 columns = ['name', 'value']
90 generate_values = lambda k, v: [k, v]
91 else:
92 logging.warning('Unable to find database file to set lock screen settings.')
93 return
95 for table, key, value in locksettings:
96 # Set the lockscreen setting for default user '0'
97 values = generate_values(key, value)
99 cmd = """begin transaction;
100 delete from '%(table)s' where %(primary_key)s='%(primary_value)s';
101 insert into '%(table)s' (%(columns)s) values (%(values)s);
102 commit transaction;""" % {
103 'table': table,
104 'primary_key': columns[0],
105 'primary_value': values[0],
106 'columns': ', '.join(columns),
107 'values': ', '.join(["'%s'" % value for value in values])
109 output_msg = device.RunShellCommand('sqlite3 %s "%s"' % (db, cmd),
110 as_root=True)
111 if output_msg:
112 logging.info(' '.join(output_msg))
115 ENABLE_LOCATION_SETTINGS = [
116 # Note that setting these in this order is required in order for all of
117 # them to take and stick through a reboot.
118 ('com.google.settings/partner', [
119 ('use_location_for_services', 1),
121 ('settings/secure', [
122 # Ensure Geolocation is enabled and allowed for tests.
123 ('location_providers_allowed', 'gps,network'),
125 ('com.google.settings/partner', [
126 ('network_location_opt_in', 1),
130 DISABLE_LOCATION_SETTINGS = [
131 ('com.google.settings/partner', [
132 ('use_location_for_services', 0),
134 ('settings/secure', [
135 # Ensure Geolocation is disabled.
136 ('location_providers_allowed', ''),
140 DETERMINISTIC_DEVICE_SETTINGS = [
141 ('settings/global', [
142 ('assisted_gps_enabled', 0),
144 # Disable "auto time" and "auto time zone" to avoid network-provided time
145 # to overwrite the device's datetime and timezone synchronized from host
146 # when running tests later. See b/6569849.
147 ('auto_time', 0),
148 ('auto_time_zone', 0),
150 ('development_settings_enabled', 1),
152 # Flag for allowing ActivityManagerService to send ACTION_APP_ERROR intents
153 # on application crashes and ANRs. If this is disabled, the crash/ANR dialog
154 # will never display the "Report" button.
155 # Type: int ( 0 = disallow, 1 = allow )
156 ('send_action_app_error', 0),
158 ('stay_on_while_plugged_in', 3),
160 ('verifier_verify_adb_installs', 0),
162 ('settings/secure', [
163 ('allowed_geolocation_origins',
164 'http://www.google.co.uk http://www.google.com'),
166 # Ensure that we never get random dialogs like "Unfortunately the process
167 # android.process.acore has stopped", which steal the focus, and make our
168 # automation fail (because the dialog steals the focus then mistakenly
169 # receives the injected user input events).
170 ('anr_show_background', 0),
172 ('lockscreen.disabled', 1),
174 ('screensaver_enabled', 0),
176 ('settings/system', [
177 # Don't want devices to accidentally rotate the screen as that could
178 # affect performance measurements.
179 ('accelerometer_rotation', 0),
181 ('lockscreen.disabled', 1),
183 # Turn down brightness and disable auto-adjust so that devices run cooler.
184 ('screen_brightness', 5),
185 ('screen_brightness_mode', 0),
187 ('user_rotation', 0),
191 NETWORK_DISABLED_SETTINGS = [
192 ('settings/global', [
193 ('airplane_mode_on', 1),
194 ('wifi_on', 0),