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 _ALTERNATE_LOCK_SCREEN_SETTINGS_PATH
= (
11 '/data/data/com.android.providers.settings/databases/settings.db')
12 PASSWORD_QUALITY_UNSPECIFIED
= '0'
15 def ConfigureContentSettings(device
, desired_settings
):
16 """Configures device content setings from a list.
18 Many settings are documented at:
19 http://developer.android.com/reference/android/provider/Settings.Global.html
20 http://developer.android.com/reference/android/provider/Settings.Secure.html
21 http://developer.android.com/reference/android/provider/Settings.System.html
23 Many others are undocumented.
26 device: A DeviceUtils instance for the device to configure.
27 desired_settings: A list of (table, [(key: value), ...]) for all
28 settings to configure.
30 if device
.build_type
== 'userdebug':
31 for table
, key_value
in desired_settings
:
32 settings
= content_settings
.ContentSettings(table
, device
)
33 for key
, value
in 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
)
40 def SetLockScreenSettings(device
):
41 """Sets lock screen settings on the device.
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
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
54 device: A DeviceUtils instance for the device to configure.
57 Exception if the setting was not properly set.
59 if device
.build_type
!= 'userdebug':
60 logging
.warning('Unable to disable lockscreen on user builds.')
63 def get_lock_settings(table
):
64 return [(table
, 'lockscreen.disabled', '1'),
65 (table
, 'lockscreen.password_type', PASSWORD_QUALITY_UNSPECIFIED
),
66 (table
, 'lockscreen.password_type_alternate',
67 PASSWORD_QUALITY_UNSPECIFIED
)]
69 if device
.FileExists(_LOCK_SCREEN_SETTINGS_PATH
):
70 db
= _LOCK_SCREEN_SETTINGS_PATH
71 locksettings
= get_lock_settings('locksettings')
72 columns
= ['name', 'user', 'value']
73 generate_values
= lambda k
, v
: [k
, '0', v
]
74 elif device
.FileExists(_ALTERNATE_LOCK_SCREEN_SETTINGS_PATH
):
75 db
= _ALTERNATE_LOCK_SCREEN_SETTINGS_PATH
76 locksettings
= get_lock_settings('secure') + get_lock_settings('system')
77 columns
= ['name', 'value']
78 generate_values
= lambda k
, v
: [k
, v
]
80 logging
.warning('Unable to find database file to set lock screen settings.')
83 for table
, key
, value
in locksettings
:
84 # Set the lockscreen setting for default user '0'
85 values
= generate_values(key
, value
)
87 cmd
= """begin transaction;
88 delete from '%(table)s' where %(primary_key)s='%(primary_value)s';
89 insert into '%(table)s' (%(columns)s) values (%(values)s);
90 commit transaction;""" % {
92 'primary_key': columns
[0],
93 'primary_value': values
[0],
94 'columns': ', '.join(columns
),
95 'values': ', '.join(["'%s'" % value
for value
in values
])
97 output_msg
= device
.RunShellCommand('sqlite3 %s "%s"' % (db
, cmd
),
100 logging
.info(' '.join(output_msg
))
103 ENABLE_LOCATION_SETTINGS
= [
104 # Note that setting these in this order is required in order for all of
105 # them to take and stick through a reboot.
106 ('com.google.settings/partner', [
107 ('use_location_for_services', 1),
109 ('settings/secure', [
110 # Ensure Geolocation is enabled and allowed for tests.
111 ('location_providers_allowed', 'gps,network'),
113 ('com.google.settings/partner', [
114 ('network_location_opt_in', 1),
118 DISABLE_LOCATION_SETTINGS
= [
119 ('com.google.settings/partner', [
120 ('use_location_for_services', 0),
122 ('settings/secure', [
123 # Ensure Geolocation is disabled.
124 ('location_providers_allowed', ''),
128 ENABLE_MOCK_LOCATION_SETTINGS
= [
129 ('settings/secure', [
130 ('mock_location', 1),
134 DISABLE_MOCK_LOCATION_SETTINGS
= [
135 ('settings/secure', [
136 ('mock_location', 0),
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.
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),