| 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 | 9 |
| 10 _LOCK_SCREEN_SETTINGS_PATH = '/data/system/locksettings.db' | 10 _LOCK_SCREEN_SETTINGS_PATH = '/data/system/locksettings.db' |
| 11 _ALTERNATE_LOCK_SCREEN_SETTINGS_PATH = ( |
| 12 '/data/data/com.android.providers.settings/databases/settings.db') |
| 11 PASSWORD_QUALITY_UNSPECIFIED = '0' | 13 PASSWORD_QUALITY_UNSPECIFIED = '0' |
| 12 | 14 |
| 13 | 15 |
| 14 def ConfigureContentSettings(device, desired_settings): | 16 def ConfigureContentSettings(device, desired_settings): |
| 15 """Configures device content setings from a list. | 17 """Configures device content setings from a list. |
| 16 | 18 |
| 17 Many settings are documented at: | 19 Many settings are documented at: |
| 18 http://developer.android.com/reference/android/provider/Settings.Global.html | 20 http://developer.android.com/reference/android/provider/Settings.Global.html |
| 19 http://developer.android.com/reference/android/provider/Settings.Secure.html | 21 http://developer.android.com/reference/android/provider/Settings.Secure.html |
| 20 http://developer.android.com/reference/android/provider/Settings.System.html | 22 http://developer.android.com/reference/android/provider/Settings.System.html |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 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 |
| 60 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 |
| 61 new values. | 63 new values. |
| 62 | 64 |
| 63 Args: | 65 Args: |
| 64 device: A DeviceUtils instance for the device to configure. | 66 device: A DeviceUtils instance for the device to configure. |
| 65 | 67 |
| 66 Raises: | 68 Raises: |
| 67 Exception if the setting was not properly set. | 69 Exception if the setting was not properly set. |
| 68 """ | 70 """ |
| 69 if (not device.old_interface.FileExistsOnDevice(_LOCK_SCREEN_SETTINGS_PATH) or | 71 if device.GetProp('ro.build.type') != 'userdebug': |
| 70 device.GetProp('ro.build.type') != 'userdebug'): | 72 logging.warning('Unable to disable lockscreen on user builds.') |
| 71 return | 73 return |
| 72 | 74 |
| 73 db = _LOCK_SCREEN_SETTINGS_PATH | 75 def get_lock_settings(table): |
| 74 locksettings = [('locksettings', 'lockscreen.disabled', '1'), | 76 return [(table, 'lockscreen.disabled', '1'), |
| 75 ('locksettings', 'lockscreen.password_type', | 77 (table, 'lockscreen.password_type', PASSWORD_QUALITY_UNSPECIFIED), |
| 76 PASSWORD_QUALITY_UNSPECIFIED), | 78 (table, 'lockscreen.password_type_alternate', |
| 77 ('locksettings', 'lockscreen.password_type_alternate', | 79 PASSWORD_QUALITY_UNSPECIFIED)] |
| 78 PASSWORD_QUALITY_UNSPECIFIED)] | 80 |
| 81 if device.FileExists(_LOCK_SCREEN_SETTINGS_PATH): |
| 82 db = _LOCK_SCREEN_SETTINGS_PATH |
| 83 locksettings = get_lock_settings('locksettings') |
| 84 elif device.FileExists(_ALTERNATE_LOCK_SCREEN_SETTINGS_PATH): |
| 85 db = _ALTERNATE_LOCK_SCREEN_SETTINGS_PATH |
| 86 locksettings = get_lock_settings('secure') + get_lock_settings('system') |
| 87 else: |
| 88 logging.warning('Unable to find database file to set lock screen settings.') |
| 89 return |
| 90 |
| 79 for table, key, value in locksettings: | 91 for table, key, value in locksettings: |
| 80 # Set the lockscreen setting for default user '0' | 92 # Set the lockscreen setting for default user '0' |
| 81 columns = ['name', 'user', 'value'] | 93 columns = ['name', 'user', 'value'] |
| 82 values = [key, '0', value] | 94 values = [key, '0', value] |
| 83 | 95 |
| 84 cmd = """begin transaction; | 96 cmd = """begin transaction; |
| 85 delete from '%(table)s' where %(primary_key)s='%(primary_value)s'; | 97 delete from '%(table)s' where %(primary_key)s='%(primary_value)s'; |
| 86 insert into '%(table)s' (%(columns)s) values (%(values)s); | 98 insert into '%(table)s' (%(columns)s) values (%(values)s); |
| 87 commit transaction;""" % { | 99 commit transaction;""" % { |
| 88 'table': table, | 100 'table': table, |
| 89 'primary_key': columns[0], | 101 'primary_key': columns[0], |
| 90 'primary_value': values[0], | 102 'primary_value': values[0], |
| 91 'columns': ', '.join(columns), | 103 'columns': ', '.join(columns), |
| 92 'values': ', '.join(["'%s'" % value for value in values]) | 104 'values': ', '.join(["'%s'" % value for value in values]) |
| 93 } | 105 } |
| 94 output_msg = device.RunShellCommand('sqlite3 %s "%s"' % (db, cmd)) | 106 output_msg = device.RunShellCommand('sqlite3 %s "%s"' % (db, cmd), |
| 107 as_root=True) |
| 95 if output_msg: | 108 if output_msg: |
| 96 print ' '.join(output_msg) | 109 logging.info(' '.join(output_msg)) |
| 97 | 110 |
| 98 | 111 |
| 99 ENABLE_LOCATION_SETTINGS = [ | 112 ENABLE_LOCATION_SETTINGS = [ |
| 100 # Note that setting these in this order is required in order for all of | 113 # Note that setting these in this order is required in order for all of |
| 101 # them to take and stick through a reboot. | 114 # them to take and stick through a reboot. |
| 102 ('com.google.settings/partner', [ | 115 ('com.google.settings/partner', [ |
| 103 ('use_location_for_services', 1), | 116 ('use_location_for_services', 1), |
| 104 ]), | 117 ]), |
| 105 ('settings/secure', [ | 118 ('settings/secure', [ |
| 106 # Ensure Geolocation is enabled and allowed for tests. | 119 # Ensure Geolocation is enabled and allowed for tests. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 ('user_rotation', 0), | 184 ('user_rotation', 0), |
| 172 ]), | 185 ]), |
| 173 ] | 186 ] |
| 174 | 187 |
| 175 NETWORK_DISABLED_SETTINGS = [ | 188 NETWORK_DISABLED_SETTINGS = [ |
| 176 ('settings/global', [ | 189 ('settings/global', [ |
| 177 ('airplane_mode_on', 1), | 190 ('airplane_mode_on', 1), |
| 178 ('wifi_on', 0), | 191 ('wifi_on', 0), |
| 179 ]), | 192 ]), |
| 180 ] | 193 ] |
| OLD | NEW |