Chromium Code Reviews| 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 content_settings | 7 from pylib import content_settings |
| 8 | 8 |
| 9 _LOCK_SCREEN_SETTINGS_PATH = '/data/system/locksettings.db' | 9 _LOCK_SCREEN_SETTINGS_PATH = '/data/system/locksettings.db' |
| 10 PASSWORD_QUALITY_UNSPECIFIED = '0' | 10 PASSWORD_QUALITY_UNSPECIFIED = '0' |
| 11 | 11 |
| 12 | 12 |
| 13 def ConfigureContentSettingsDict(device, desired_settings): | 13 def ConfigureContentSettings(device, desired_settings): |
| 14 """Configures device content setings from a dictionary. | 14 """Configures device content setings from a list. |
| 15 | 15 |
| 16 Many settings are documented at: | 16 Many settings are documented at: |
| 17 http://developer.android.com/reference/android/provider/Settings.Global.html | 17 http://developer.android.com/reference/android/provider/Settings.Global.html |
| 18 http://developer.android.com/reference/android/provider/Settings.Secure.html | 18 http://developer.android.com/reference/android/provider/Settings.Secure.html |
| 19 http://developer.android.com/reference/android/provider/Settings.System.html | 19 http://developer.android.com/reference/android/provider/Settings.System.html |
| 20 | 20 |
| 21 Many others are undocumented. | 21 Many others are undocumented. |
| 22 | 22 |
| 23 Args: | 23 Args: |
| 24 device: A DeviceUtils instance for the device to configure. | 24 device: A DeviceUtils instance for the device to configure. |
| 25 desired_settings: A dict of {table: {key: value}} for all | 25 desired_settings: A list of (table, [(key: value), ...]) for all |
| 26 settings to configure. | 26 settings to configure. |
| 27 """ | 27 """ |
| 28 try: | 28 try: |
| 29 sdk_version = int(device.GetProp('ro.build.version.sdk')) | 29 sdk_version = int(device.GetProp('ro.build.version.sdk')) |
| 30 except ValueError: | 30 except ValueError: |
| 31 logging.error('Skipping content settings configuration, unknown sdk %s', | 31 logging.error('Skipping content settings configuration, unknown sdk %s', |
| 32 device.GetProp('ro.build.version.sdk')) | 32 device.GetProp('ro.build.version.sdk')) |
| 33 return | 33 return |
| 34 | 34 |
| 35 if sdk_version < 16: | 35 if sdk_version < 16: |
| 36 logging.error('Skipping content settings configuration due to outdated sdk') | 36 logging.error('Skipping content settings configuration due to outdated sdk') |
| 37 return | 37 return |
| 38 | 38 |
| 39 device.SetProp('persist.sys.usb.config', 'adb') | 39 device.SetProp('persist.sys.usb.config', 'adb') |
| 40 device.old_interface.WaitForDevicePm() | 40 device.old_interface.WaitForDevicePm() |
|
jbudorick
2014/08/18 19:00:33
I removed the change I had here to how DeviceUtils
| |
| 41 | 41 |
| 42 if device.GetProp('ro.build.type') == 'userdebug': | 42 if device.GetProp('ro.build.type') == 'userdebug': |
| 43 for table, key_value in sorted(desired_settings.iteritems()): | 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.iteritems(): | 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 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 'primary_key': columns[0], | 91 'primary_key': columns[0], |
| 92 'primary_value': values[0], | 92 'primary_value': values[0], |
| 93 'columns': ', '.join(columns), | 93 'columns': ', '.join(columns), |
| 94 'values': ', '.join(["'%s'" % value for value in values]) | 94 'values': ', '.join(["'%s'" % value for value in values]) |
| 95 } | 95 } |
| 96 output_msg = device.RunShellCommand('sqlite3 %s "%s"' % (db, cmd)) | 96 output_msg = device.RunShellCommand('sqlite3 %s "%s"' % (db, cmd)) |
| 97 if output_msg: | 97 if output_msg: |
| 98 print ' '.join(output_msg) | 98 print ' '.join(output_msg) |
| 99 | 99 |
| 100 | 100 |
| 101 ENABLE_LOCATION_SETTING = { | 101 ENABLE_LOCATION_SETTINGS = [ |
| 102 'settings/secure': { | 102 # Note that setting these in this order is required in order for all of |
| 103 # them to take and stick through a reboot. | |
| 104 ('com.google.settings/partner', [ | |
| 105 ('use_location_for_services', 1), | |
| 106 ]), | |
| 107 ('settings/secure', [ | |
| 103 # Ensure Geolocation is enabled and allowed for tests. | 108 # Ensure Geolocation is enabled and allowed for tests. |
| 104 'location_providers_allowed': 'gps,network', | 109 ('location_providers_allowed', 'gps,network'), |
| 105 } | 110 ]), |
| 106 } | 111 ('com.google.settings/partner', [ |
| 112 ('network_location_opt_in', 1), | |
| 113 ]) | |
| 114 ] | |
| 107 | 115 |
| 108 DISABLE_LOCATION_SETTING = { | 116 DISABLE_LOCATION_SETTINGS = [ |
| 109 'settings/secure': { | 117 ('com.google.settings/partner', [ |
| 118 ('use_location_for_services', 0), | |
| 119 ]), | |
| 120 ('settings/secure', [ | |
| 110 # Ensure Geolocation is disabled. | 121 # Ensure Geolocation is disabled. |
| 111 'location_providers_allowed': '', | 122 ('location_providers_allowed', ''), |
| 112 } | 123 ]), |
| 113 } | 124 ] |
| 114 | 125 |
| 115 DETERMINISTIC_DEVICE_SETTINGS = { | 126 DETERMINISTIC_DEVICE_SETTINGS = [ |
| 116 'com.google.settings/partner': { | 127 ('settings/global', [ |
| 117 'network_location_opt_in': 0, | 128 ('assisted_gps_enabled', 0), |
| 118 'use_location_for_services': 1, | |
| 119 }, | |
| 120 'settings/global': { | |
| 121 'assisted_gps_enabled': 0, | |
| 122 | 129 |
| 123 # Disable "auto time" and "auto time zone" to avoid network-provided time | 130 # Disable "auto time" and "auto time zone" to avoid network-provided time |
| 124 # to overwrite the device's datetime and timezone synchronized from host | 131 # to overwrite the device's datetime and timezone synchronized from host |
| 125 # when running tests later. See b/6569849. | 132 # when running tests later. See b/6569849. |
| 126 'auto_time': 0, | 133 ('auto_time', 0), |
| 127 'auto_time_zone': 0, | 134 ('auto_time_zone', 0), |
| 128 | 135 |
| 129 'development_settings_enabled': 1, | 136 ('development_settings_enabled', 1), |
| 130 | 137 |
| 131 # Flag for allowing ActivityManagerService to send ACTION_APP_ERROR intents | 138 # Flag for allowing ActivityManagerService to send ACTION_APP_ERROR intents |
| 132 # on application crashes and ANRs. If this is disabled, the crash/ANR dialog | 139 # on application crashes and ANRs. If this is disabled, the crash/ANR dialog |
| 133 # will never display the "Report" button. | 140 # will never display the "Report" button. |
| 134 # Type: int ( 0 = disallow, 1 = allow ) | 141 # Type: int ( 0 = disallow, 1 = allow ) |
| 135 'send_action_app_error': 0, | 142 ('send_action_app_error', 0), |
| 136 | 143 |
| 137 'stay_on_while_plugged_in': 3, | 144 ('stay_on_while_plugged_in', 3), |
| 138 | 145 |
| 139 'verifier_verify_adb_installs' : 0, | 146 ('verifier_verify_adb_installs', 0), |
| 140 }, | 147 ]), |
| 141 'settings/secure': { | 148 ('settings/secure', [ |
| 142 'allowed_geolocation_origins': | 149 ('allowed_geolocation_origins', |
| 143 'http://www.google.co.uk http://www.google.com', | 150 'http://www.google.co.uk http://www.google.com'), |
| 144 | 151 |
| 145 # Ensure that we never get random dialogs like "Unfortunately the process | 152 # Ensure that we never get random dialogs like "Unfortunately the process |
| 146 # android.process.acore has stopped", which steal the focus, and make our | 153 # android.process.acore has stopped", which steal the focus, and make our |
| 147 # automation fail (because the dialog steals the focus then mistakenly | 154 # automation fail (because the dialog steals the focus then mistakenly |
| 148 # receives the injected user input events). | 155 # receives the injected user input events). |
| 149 'anr_show_background': 0, | 156 ('anr_show_background', 0), |
| 150 | 157 |
| 151 'lockscreen.disabled': 1, | 158 ('lockscreen.disabled', 1), |
| 152 | 159 |
| 153 'screensaver_enabled': 0, | 160 ('screensaver_enabled', 0), |
| 154 }, | 161 ]), |
| 155 'settings/system': { | 162 ('settings/system', [ |
| 156 # Don't want devices to accidentally rotate the screen as that could | 163 # Don't want devices to accidentally rotate the screen as that could |
| 157 # affect performance measurements. | 164 # affect performance measurements. |
| 158 'accelerometer_rotation': 0, | 165 ('accelerometer_rotation', 0), |
| 159 | 166 |
| 160 'lockscreen.disabled': 1, | 167 ('lockscreen.disabled', 1), |
| 161 | 168 |
| 162 # Turn down brightness and disable auto-adjust so that devices run cooler. | 169 # Turn down brightness and disable auto-adjust so that devices run cooler. |
| 163 'screen_brightness': 5, | 170 ('screen_brightness', 5), |
| 164 'screen_brightness_mode': 0, | 171 ('screen_brightness_mode', 0), |
| 165 | 172 |
| 166 'user_rotation': 0, | 173 ('user_rotation', 0), |
| 167 }, | 174 ]), |
| 168 } | 175 ] |
| 169 | 176 |
| 170 | 177 NETWORK_DISABLED_SETTINGS = [ |
| 171 NETWORK_DISABLED_SETTINGS = { | 178 ('settings/global', [ |
| 172 'settings/global': { | 179 ('airplane_mode_on', 1), |
| 173 'airplane_mode_on': 1, | 180 ('wifi_on', 0), |
| 174 'wifi_on': 0, | 181 ]), |
| 175 }, | 182 ] |
| 176 } | |
| OLD | NEW |