blob: ab4ad1b900b54797d89f5df9dd70390ecb7ad5da [file] [log] [blame]
Ben Murdoch342c50c2016-05-18 11:27:45 +01001# 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.
4
5import logging
6
7from pylib import content_settings
8
9_LOCK_SCREEN_SETTINGS_PATH = '/data/system/locksettings.db'
10_ALTERNATE_LOCK_SCREEN_SETTINGS_PATH = (
11 '/data/data/com.android.providers.settings/databases/settings.db')
12PASSWORD_QUALITY_UNSPECIFIED = '0'
13_COMPATIBLE_BUILD_TYPES = ['userdebug', 'eng']
14
15
16def ConfigureContentSettings(device, desired_settings):
17 """Configures device content setings from a list.
18
19 Many settings are documented at:
20 http://developer.android.com/reference/android/provider/Settings.Global.html
21 http://developer.android.com/reference/android/provider/Settings.Secure.html
22 http://developer.android.com/reference/android/provider/Settings.System.html
23
24 Many others are undocumented.
25
26 Args:
27 device: A DeviceUtils instance for the device to configure.
28 desired_settings: A list of (table, [(key: value), ...]) for all
29 settings to configure.
30 """
31 for table, key_value in desired_settings:
32 settings = content_settings.ContentSettings(table, device)
33 for key, value in key_value:
34 settings[key] = value
35 logging.info('\n%s %s', table, (80 - len(table)) * '-')
36 for key, value in sorted(settings.iteritems()):
37 logging.info('\t%s: %s', key, value)
38
39
40def SetLockScreenSettings(device):
41 """Sets lock screen settings on the device.
42
43 On certain device/Android configurations we need to disable the lock screen in
44 a different database. Additionally, the password type must be set to
45 DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED.
46 Lock screen settings are stored in sqlite on the device in:
47 /data/system/locksettings.db
48
49 IMPORTANT: The first column is used as a primary key so that all rows with the
50 same value for that column are removed from the table prior to inserting the
51 new values.
52
53 Args:
54 device: A DeviceUtils instance for the device to configure.
55
56 Raises:
57 Exception if the setting was not properly set.
58 """
59 if device.build_type not in _COMPATIBLE_BUILD_TYPES:
60 logging.warning('Unable to disable lockscreen on %s builds.',
61 device.build_type)
62 return
63
64 def get_lock_settings(table):
65 return [(table, 'lockscreen.disabled', '1'),
66 (table, 'lockscreen.password_type', PASSWORD_QUALITY_UNSPECIFIED),
67 (table, 'lockscreen.password_type_alternate',
68 PASSWORD_QUALITY_UNSPECIFIED)]
69
70 if device.FileExists(_LOCK_SCREEN_SETTINGS_PATH):
71 db = _LOCK_SCREEN_SETTINGS_PATH
72 locksettings = get_lock_settings('locksettings')
73 columns = ['name', 'user', 'value']
74 generate_values = lambda k, v: [k, '0', v]
75 elif device.FileExists(_ALTERNATE_LOCK_SCREEN_SETTINGS_PATH):
76 db = _ALTERNATE_LOCK_SCREEN_SETTINGS_PATH
77 locksettings = get_lock_settings('secure') + get_lock_settings('system')
78 columns = ['name', 'value']
79 generate_values = lambda k, v: [k, v]
80 else:
81 logging.warning('Unable to find database file to set lock screen settings.')
82 return
83
84 for table, key, value in locksettings:
85 # Set the lockscreen setting for default user '0'
86 values = generate_values(key, value)
87
88 cmd = """begin transaction;
89delete from '%(table)s' where %(primary_key)s='%(primary_value)s';
90insert into '%(table)s' (%(columns)s) values (%(values)s);
91commit transaction;""" % {
92 'table': table,
93 'primary_key': columns[0],
94 'primary_value': values[0],
95 'columns': ', '.join(columns),
96 'values': ', '.join(["'%s'" % value for value in values])
97 }
98 output_msg = device.RunShellCommand('sqlite3 %s "%s"' % (db, cmd),
99 as_root=True)
100 if output_msg:
101 logging.info(' '.join(output_msg))
102
103
104ENABLE_LOCATION_SETTINGS = [
105 # Note that setting these in this order is required in order for all of
106 # them to take and stick through a reboot.
107 ('com.google.settings/partner', [
108 ('use_location_for_services', 1),
109 ]),
110 ('settings/secure', [
111 # Ensure Geolocation is enabled and allowed for tests.
112 ('location_providers_allowed', 'gps,network'),
113 ]),
114 ('com.google.settings/partner', [
115 ('network_location_opt_in', 1),
116 ])
117]
118
119DISABLE_LOCATION_SETTINGS = [
120 ('com.google.settings/partner', [
121 ('use_location_for_services', 0),
122 ]),
123 ('settings/secure', [
124 # Ensure Geolocation is disabled.
125 ('location_providers_allowed', ''),
126 ]),
127]
128
129ENABLE_MOCK_LOCATION_SETTINGS = [
130 ('settings/secure', [
131 ('mock_location', 1),
132 ]),
133]
134
135DISABLE_MOCK_LOCATION_SETTINGS = [
136 ('settings/secure', [
137 ('mock_location', 0),
138 ]),
139]
140
141DETERMINISTIC_DEVICE_SETTINGS = [
142 ('settings/global', [
143 ('assisted_gps_enabled', 0),
144
145 # Disable "auto time" and "auto time zone" to avoid network-provided time
146 # to overwrite the device's datetime and timezone synchronized from host
147 # when running tests later. See b/6569849.
148 ('auto_time', 0),
149 ('auto_time_zone', 0),
150
151 ('development_settings_enabled', 1),
152
153 # Flag for allowing ActivityManagerService to send ACTION_APP_ERROR intents
154 # on application crashes and ANRs. If this is disabled, the crash/ANR dialog
155 # will never display the "Report" button.
156 # Type: int ( 0 = disallow, 1 = allow )
157 ('send_action_app_error', 0),
158
159 ('stay_on_while_plugged_in', 3),
160
161 ('verifier_verify_adb_installs', 0),
162 ]),
163 ('settings/secure', [
164 ('allowed_geolocation_origins',
165 'http://www.google.co.uk http://www.google.com'),
166
167 # Ensure that we never get random dialogs like "Unfortunately the process
168 # android.process.acore has stopped", which steal the focus, and make our
169 # automation fail (because the dialog steals the focus then mistakenly
170 # receives the injected user input events).
171 ('anr_show_background', 0),
172
173 ('lockscreen.disabled', 1),
174
175 ('screensaver_enabled', 0),
176
177 ('skip_first_use_hints', 1),
178 ]),
179 ('settings/system', [
180 # Don't want devices to accidentally rotate the screen as that could
181 # affect performance measurements.
182 ('accelerometer_rotation', 0),
183
184 ('lockscreen.disabled', 1),
185
186 # Turn down brightness and disable auto-adjust so that devices run cooler.
187 ('screen_brightness', 5),
188 ('screen_brightness_mode', 0),
189
190 ('user_rotation', 0),
191 ]),
192]
193
194NETWORK_DISABLED_SETTINGS = [
195 ('settings/global', [
196 ('airplane_mode_on', 1),
197 ('wifi_on', 0),
198 ]),
199]