OLD | NEW |
| (Empty) |
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. | |
4 | |
5 import logging | |
6 | |
7 from pylib import constants | |
8 from pylib import content_settings | |
9 from pylib.device import device_errors | |
10 | |
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' | |
15 | |
16 | |
17 def ConfigureContentSettings(device, desired_settings): | |
18 """Configures device content setings from a list. | |
19 | |
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 | |
24 | |
25 Many others are undocumented. | |
26 | |
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) | |
40 | |
41 | |
42 def SetLockScreenSettings(device): | |
43 """Sets lock screen settings on the device. | |
44 | |
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 | |
50 | |
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. | |
54 | |
55 Args: | |
56 device: A DeviceUtils instance for the device to configure. | |
57 | |
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 | |
64 | |
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)] | |
70 | |
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 | |
84 | |
85 for table, key, value in locksettings: | |
86 # Set the lockscreen setting for default user '0' | |
87 values = generate_values(key, value) | |
88 | |
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]) | |
98 } | |
99 output_msg = device.RunShellCommand('sqlite3 %s "%s"' % (db, cmd), | |
100 as_root=True) | |
101 if output_msg: | |
102 logging.info(' '.join(output_msg)) | |
103 | |
104 | |
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), | |
110 ]), | |
111 ('settings/secure', [ | |
112 # Ensure Geolocation is enabled and allowed for tests. | |
113 ('location_providers_allowed', 'gps,network'), | |
114 ]), | |
115 ('com.google.settings/partner', [ | |
116 ('network_location_opt_in', 1), | |
117 ]) | |
118 ] | |
119 | |
120 DISABLE_LOCATION_SETTINGS = [ | |
121 ('com.google.settings/partner', [ | |
122 ('use_location_for_services', 0), | |
123 ]), | |
124 ('settings/secure', [ | |
125 # Ensure Geolocation is disabled. | |
126 ('location_providers_allowed', ''), | |
127 ]), | |
128 ] | |
129 | |
130 ENABLE_MOCK_LOCATION_SETTINGS = [ | |
131 ('settings/secure', [ | |
132 ('mock_location', 1), | |
133 ]), | |
134 ] | |
135 | |
136 DISABLE_MOCK_LOCATION_SETTINGS = [ | |
137 ('settings/secure', [ | |
138 ('mock_location', 0), | |
139 ]), | |
140 ] | |
141 | |
142 DETERMINISTIC_DEVICE_SETTINGS = [ | |
143 ('settings/global', [ | |
144 ('assisted_gps_enabled', 0), | |
145 | |
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), | |
151 | |
152 ('development_settings_enabled', 1), | |
153 | |
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), | |
159 | |
160 ('stay_on_while_plugged_in', 3), | |
161 | |
162 ('verifier_verify_adb_installs', 0), | |
163 ]), | |
164 ('settings/secure', [ | |
165 ('allowed_geolocation_origins', | |
166 'http://www.google.co.uk http://www.google.com'), | |
167 | |
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), | |
173 | |
174 ('lockscreen.disabled', 1), | |
175 | |
176 ('screensaver_enabled', 0), | |
177 ]), | |
178 ('settings/system', [ | |
179 # Don't want devices to accidentally rotate the screen as that could | |
180 # affect performance measurements. | |
181 ('accelerometer_rotation', 0), | |
182 | |
183 ('lockscreen.disabled', 1), | |
184 | |
185 # Turn down brightness and disable auto-adjust so that devices run cooler. | |
186 ('screen_brightness', 5), | |
187 ('screen_brightness_mode', 0), | |
188 | |
189 ('user_rotation', 0), | |
190 ]), | |
191 ] | |
192 | |
193 NETWORK_DISABLED_SETTINGS = [ | |
194 ('settings/global', [ | |
195 ('airplane_mode_on', 1), | |
196 ('wifi_on', 0), | |
197 ]), | |
198 ] | |
OLD | NEW |