Add Apps.AppListSearchQueryLength UMA histogram.
[chromium-blink-merge.git] / build / android / pylib / device_settings.py
blob97e966322ce08aed2ff36c47646beeecaeefb5b3
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 DETERMINISTIC_DEVICE_SETTINGS = [
131 ('settings/global', [
132 ('assisted_gps_enabled', 0),
134 # Disable "auto time" and "auto time zone" to avoid network-provided time
135 # to overwrite the device's datetime and timezone synchronized from host
136 # when running tests later. See b/6569849.
137 ('auto_time', 0),
138 ('auto_time_zone', 0),
140 ('development_settings_enabled', 1),
142 # Flag for allowing ActivityManagerService to send ACTION_APP_ERROR intents
143 # on application crashes and ANRs. If this is disabled, the crash/ANR dialog
144 # will never display the "Report" button.
145 # Type: int ( 0 = disallow, 1 = allow )
146 ('send_action_app_error', 0),
148 ('stay_on_while_plugged_in', 3),
150 ('verifier_verify_adb_installs', 0),
152 ('settings/secure', [
153 ('allowed_geolocation_origins',
154 'http://www.google.co.uk http://www.google.com'),
156 # Ensure that we never get random dialogs like "Unfortunately the process
157 # android.process.acore has stopped", which steal the focus, and make our
158 # automation fail (because the dialog steals the focus then mistakenly
159 # receives the injected user input events).
160 ('anr_show_background', 0),
162 ('lockscreen.disabled', 1),
164 ('screensaver_enabled', 0),
166 ('settings/system', [
167 # Don't want devices to accidentally rotate the screen as that could
168 # affect performance measurements.
169 ('accelerometer_rotation', 0),
171 ('lockscreen.disabled', 1),
173 # Turn down brightness and disable auto-adjust so that devices run cooler.
174 ('screen_brightness', 5),
175 ('screen_brightness_mode', 0),
177 ('user_rotation', 0),
181 NETWORK_DISABLED_SETTINGS = [
182 ('settings/global', [
183 ('airplane_mode_on', 1),
184 ('wifi_on', 0),