OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import logging | 5 import logging |
6 | 6 |
7 from pylib import constants | 7 from pylib import constants |
8 from pylib import content_settings | 8 from pylib import content_settings |
| 9 from pylib.device import device_errors |
9 | 10 |
10 _LOCK_SCREEN_SETTINGS_PATH = '/data/system/locksettings.db' | 11 _LOCK_SCREEN_SETTINGS_PATH = '/data/system/locksettings.db' |
11 _ALTERNATE_LOCK_SCREEN_SETTINGS_PATH = ( | 12 _ALTERNATE_LOCK_SCREEN_SETTINGS_PATH = ( |
12 '/data/data/com.android.providers.settings/databases/settings.db') | 13 '/data/data/com.android.providers.settings/databases/settings.db') |
13 PASSWORD_QUALITY_UNSPECIFIED = '0' | 14 PASSWORD_QUALITY_UNSPECIFIED = '0' |
14 | 15 |
15 | 16 |
16 def ConfigureContentSettings(device, desired_settings): | 17 def ConfigureContentSettings(device, desired_settings): |
17 """Configures device content setings from a list. | 18 """Configures device content setings from a list. |
18 | 19 |
19 Many settings are documented at: | 20 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.Global.html |
21 http://developer.android.com/reference/android/provider/Settings.Secure.html | 22 http://developer.android.com/reference/android/provider/Settings.Secure.html |
22 http://developer.android.com/reference/android/provider/Settings.System.html | 23 http://developer.android.com/reference/android/provider/Settings.System.html |
23 | 24 |
24 Many others are undocumented. | 25 Many others are undocumented. |
25 | 26 |
26 Args: | 27 Args: |
27 device: A DeviceUtils instance for the device to configure. | 28 device: A DeviceUtils instance for the device to configure. |
28 desired_settings: A list of (table, [(key: value), ...]) for all | 29 desired_settings: A list of (table, [(key: value), ...]) for all |
29 settings to configure. | 30 settings to configure. |
30 """ | 31 """ |
31 try: | 32 try: |
32 sdk_version = int(device.GetProp('ro.build.version.sdk')) | 33 sdk_version = device.build_version_sdk |
33 except ValueError: | 34 except device_errors.CommandFailedError as exc: |
34 logging.error('Skipping content settings configuration, unknown sdk %s', | 35 logging.error('Skipping content settings configuration: %s', str(exc)) |
35 device.GetProp('ro.build.version.sdk')) | |
36 return | 36 return |
37 | 37 |
38 if sdk_version < constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN: | 38 if sdk_version < constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN: |
39 logging.error('Skipping content settings configuration due to outdated sdk') | 39 logging.error('Skipping content settings configuration due to outdated sdk') |
40 return | 40 return |
41 | 41 |
42 if device.GetProp('ro.build.type') == 'userdebug': | 42 if device.build_type == 'userdebug': |
43 for table, key_value in desired_settings: | 43 for table, key_value in desired_settings: |
44 settings = content_settings.ContentSettings(table, device) | 44 settings = content_settings.ContentSettings(table, device) |
45 for key, value in key_value: | 45 for key, value in key_value: |
46 settings[key] = value | 46 settings[key] = value |
47 logging.info('\n%s %s', table, (80 - len(table)) * '-') | 47 logging.info('\n%s %s', table, (80 - len(table)) * '-') |
48 for key, value in sorted(settings.iteritems()): | 48 for key, value in sorted(settings.iteritems()): |
49 logging.info('\t%s: %s', key, value) | 49 logging.info('\t%s: %s', key, value) |
50 | 50 |
51 | 51 |
52 def SetLockScreenSettings(device): | 52 def SetLockScreenSettings(device): |
53 """Sets lock screen settings on the device. | 53 """Sets lock screen settings on the device. |
54 | 54 |
55 On certain device/Android configurations we need to disable the lock screen in | 55 On certain device/Android configurations we need to disable the lock screen in |
56 a different database. Additionally, the password type must be set to | 56 a different database. Additionally, the password type must be set to |
57 DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED. | 57 DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED. |
58 Lock screen settings are stored in sqlite on the device in: | 58 Lock screen settings are stored in sqlite on the device in: |
59 /data/system/locksettings.db | 59 /data/system/locksettings.db |
60 | 60 |
61 IMPORTANT: The first column is used as a primary key so that all rows with the | 61 IMPORTANT: The first column is used as a primary key so that all rows with the |
62 same value for that column are removed from the table prior to inserting the | 62 same value for that column are removed from the table prior to inserting the |
63 new values. | 63 new values. |
64 | 64 |
65 Args: | 65 Args: |
66 device: A DeviceUtils instance for the device to configure. | 66 device: A DeviceUtils instance for the device to configure. |
67 | 67 |
68 Raises: | 68 Raises: |
69 Exception if the setting was not properly set. | 69 Exception if the setting was not properly set. |
70 """ | 70 """ |
71 if device.GetProp('ro.build.type') != 'userdebug': | 71 if device.build_type != 'userdebug': |
72 logging.warning('Unable to disable lockscreen on user builds.') | 72 logging.warning('Unable to disable lockscreen on user builds.') |
73 return | 73 return |
74 | 74 |
75 def get_lock_settings(table): | 75 def get_lock_settings(table): |
76 return [(table, 'lockscreen.disabled', '1'), | 76 return [(table, 'lockscreen.disabled', '1'), |
77 (table, 'lockscreen.password_type', PASSWORD_QUALITY_UNSPECIFIED), | 77 (table, 'lockscreen.password_type', PASSWORD_QUALITY_UNSPECIFIED), |
78 (table, 'lockscreen.password_type_alternate', | 78 (table, 'lockscreen.password_type_alternate', |
79 PASSWORD_QUALITY_UNSPECIFIED)] | 79 PASSWORD_QUALITY_UNSPECIFIED)] |
80 | 80 |
81 if device.FileExists(_LOCK_SCREEN_SETTINGS_PATH): | 81 if device.FileExists(_LOCK_SCREEN_SETTINGS_PATH): |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 ('user_rotation', 0), | 187 ('user_rotation', 0), |
188 ]), | 188 ]), |
189 ] | 189 ] |
190 | 190 |
191 NETWORK_DISABLED_SETTINGS = [ | 191 NETWORK_DISABLED_SETTINGS = [ |
192 ('settings/global', [ | 192 ('settings/global', [ |
193 ('airplane_mode_on', 1), | 193 ('airplane_mode_on', 1), |
194 ('wifi_on', 0), | 194 ('wifi_on', 0), |
195 ]), | 195 ]), |
196 ] | 196 ] |
OLD | NEW |