Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / build / android / pylib / device_settings.py
blobbeabcff1f3ac3ab077a828a41b48feb32346d4c7
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 if device.build_type == 'userdebug':
33 for table, key_value in desired_settings:
34 settings = content_settings.ContentSettings(table, device)
35 for key, value in key_value:
36 settings[key] = value
37 logging.info('\n%s %s', table, (80 - len(table)) * '-')
38 for key, value in sorted(settings.iteritems()):
39 logging.info('\t%s: %s', key, value)
42 def SetLockScreenSettings(device):
43 """Sets lock screen settings on the device.
45 On certain device/Android configurations we need to disable the lock screen in
46 a different database. Additionally, the password type must be set to
47 DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED.
48 Lock screen settings are stored in sqlite on the device in:
49 /data/system/locksettings.db
51 IMPORTANT: The first column is used as a primary key so that all rows with the
52 same value for that column are removed from the table prior to inserting the
53 new values.
55 Args:
56 device: A DeviceUtils instance for the device to configure.
58 Raises:
59 Exception if the setting was not properly set.
60 """
61 if device.build_type != 'userdebug':
62 logging.warning('Unable to disable lockscreen on user builds.')
63 return
65 def get_lock_settings(table):
66 return [(table, 'lockscreen.disabled', '1'),
67 (table, 'lockscreen.password_type', PASSWORD_QUALITY_UNSPECIFIED),
68 (table, 'lockscreen.password_type_alternate',
69 PASSWORD_QUALITY_UNSPECIFIED)]
71 if device.FileExists(_LOCK_SCREEN_SETTINGS_PATH):
72 db = _LOCK_SCREEN_SETTINGS_PATH
73 locksettings = get_lock_settings('locksettings')
74 columns = ['name', 'user', 'value']
75 generate_values = lambda k, v: [k, '0', v]
76 elif device.FileExists(_ALTERNATE_LOCK_SCREEN_SETTINGS_PATH):
77 db = _ALTERNATE_LOCK_SCREEN_SETTINGS_PATH
78 locksettings = get_lock_settings('secure') + get_lock_settings('system')
79 columns = ['name', 'value']
80 generate_values = lambda k, v: [k, v]
81 else:
82 logging.warning('Unable to find database file to set lock screen settings.')
83 return
85 for table, key, value in locksettings:
86 # Set the lockscreen setting for default user '0'
87 values = generate_values(key, value)
89 cmd = """begin transaction;
90 delete from '%(table)s' where %(primary_key)s='%(primary_value)s';
91 insert into '%(table)s' (%(columns)s) values (%(values)s);
92 commit transaction;""" % {
93 'table': table,
94 'primary_key': columns[0],
95 'primary_value': values[0],
96 'columns': ', '.join(columns),
97 'values': ', '.join(["'%s'" % value for value in values])
99 output_msg = device.RunShellCommand('sqlite3 %s "%s"' % (db, cmd),
100 as_root=True)
101 if output_msg:
102 logging.info(' '.join(output_msg))
105 ENABLE_LOCATION_SETTINGS = [
106 # Note that setting these in this order is required in order for all of
107 # them to take and stick through a reboot.
108 ('com.google.settings/partner', [
109 ('use_location_for_services', 1),
111 ('settings/secure', [
112 # Ensure Geolocation is enabled and allowed for tests.
113 ('location_providers_allowed', 'gps,network'),
115 ('com.google.settings/partner', [
116 ('network_location_opt_in', 1),
120 DISABLE_LOCATION_SETTINGS = [
121 ('com.google.settings/partner', [
122 ('use_location_for_services', 0),
124 ('settings/secure', [
125 # Ensure Geolocation is disabled.
126 ('location_providers_allowed', ''),
130 ENABLE_MOCK_LOCATION_SETTINGS = [
131 ('settings/secure', [
132 ('mock_location', 1),
136 DISABLE_MOCK_LOCATION_SETTINGS = [
137 ('settings/secure', [
138 ('mock_location', 0),
142 DETERMINISTIC_DEVICE_SETTINGS = [
143 ('settings/global', [
144 ('assisted_gps_enabled', 0),
146 # Disable "auto time" and "auto time zone" to avoid network-provided time
147 # to overwrite the device's datetime and timezone synchronized from host
148 # when running tests later. See b/6569849.
149 ('auto_time', 0),
150 ('auto_time_zone', 0),
152 ('development_settings_enabled', 1),
154 # Flag for allowing ActivityManagerService to send ACTION_APP_ERROR intents
155 # on application crashes and ANRs. If this is disabled, the crash/ANR dialog
156 # will never display the "Report" button.
157 # Type: int ( 0 = disallow, 1 = allow )
158 ('send_action_app_error', 0),
160 ('stay_on_while_plugged_in', 3),
162 ('verifier_verify_adb_installs', 0),
164 ('settings/secure', [
165 ('allowed_geolocation_origins',
166 'http://www.google.co.uk http://www.google.com'),
168 # Ensure that we never get random dialogs like "Unfortunately the process
169 # android.process.acore has stopped", which steal the focus, and make our
170 # automation fail (because the dialog steals the focus then mistakenly
171 # receives the injected user input events).
172 ('anr_show_background', 0),
174 ('lockscreen.disabled', 1),
176 ('screensaver_enabled', 0),
178 ('settings/system', [
179 # Don't want devices to accidentally rotate the screen as that could
180 # affect performance measurements.
181 ('accelerometer_rotation', 0),
183 ('lockscreen.disabled', 1),
185 # Turn down brightness and disable auto-adjust so that devices run cooler.
186 ('screen_brightness', 5),
187 ('screen_brightness_mode', 0),
189 ('user_rotation', 0),
193 NETWORK_DISABLED_SETTINGS = [
194 ('settings/global', [
195 ('airplane_mode_on', 1),
196 ('wifi_on', 0),