Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / build / android / pylib / device_settings.py
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 content_settings
8
9 _LOCK_SCREEN_SETTINGS_PATH = '/data/system/locksettings.db'
10 PASSWORD_QUALITY_UNSPECIFIED = '0'
11
12
13 def ConfigureContentSettingsDict(device, desired_settings):
14   """Configures device content setings from a dictionary.
15
16   Many settings are documented at:
17     http://developer.android.com/reference/android/provider/Settings.Global.html
18     http://developer.android.com/reference/android/provider/Settings.Secure.html
19     http://developer.android.com/reference/android/provider/Settings.System.html
20
21   Many others are undocumented.
22
23   Args:
24     device: A DeviceUtils instance for the device to configure.
25     desired_settings: A dict of {table: {key: value}} for all
26         settings to configure.
27   """
28   try:
29     sdk_version = int(device.GetProp('ro.build.version.sdk'))
30   except ValueError:
31     logging.error('Skipping content settings configuration, unknown sdk %s',
32                   device.GetProp('ro.build.version.sdk'))
33     return
34
35   if sdk_version < 16:
36     logging.error('Skipping content settings configuration due to outdated sdk')
37     return
38
39   device.SetProp('persist.sys.usb.config', 'adb')
40   device.old_interface.WaitForDevicePm()
41
42   if device.GetProp('ro.build.type') == 'userdebug':
43     for table, key_value in sorted(desired_settings.iteritems()):
44       settings = content_settings.ContentSettings(table, device)
45       for key, value in key_value.iteritems():
46         settings[key] = value
47       logging.info('\n%s %s', table, (80 - len(table)) * '-')
48       for key, value in sorted(settings.iteritems()):
49         logging.info('\t%s: %s', key, value)
50
51
52 def SetLockScreenSettings(device):
53   """Sets lock screen settings on the device.
54
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
57   DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED.
58   Lock screen settings are stored in sqlite on the device in:
59       /data/system/locksettings.db
60
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
63   new values.
64
65   Args:
66     device: A DeviceUtils instance for the device to configure.
67
68   Raises:
69     Exception if the setting was not properly set.
70   """
71   if (not device.old_interface.FileExistsOnDevice(_LOCK_SCREEN_SETTINGS_PATH) or
72       device.GetProp('ro.build.type') != 'userdebug'):
73     return
74
75   db = _LOCK_SCREEN_SETTINGS_PATH
76   locksettings = [('locksettings', 'lockscreen.disabled', '1'),
77                   ('locksettings', 'lockscreen.password_type',
78                    PASSWORD_QUALITY_UNSPECIFIED),
79                   ('locksettings', 'lockscreen.password_type_alternate',
80                    PASSWORD_QUALITY_UNSPECIFIED)]
81   for table, key, value in locksettings:
82     # Set the lockscreen setting for default user '0'
83     columns = ['name', 'user', 'value']
84     values = [key, '0', value]
85
86     cmd = """begin transaction;
87 delete from '%(table)s' where %(primary_key)s='%(primary_value)s';
88 insert into '%(table)s' (%(columns)s) values (%(values)s);
89 commit transaction;""" % {
90       'table': table,
91       'primary_key': columns[0],
92       'primary_value': values[0],
93       'columns': ', '.join(columns),
94       'values': ', '.join(["'%s'" % value for value in values])
95     }
96     output_msg = device.RunShellCommand('\'sqlite3 %s "%s"\'' % (db, cmd))
97     if output_msg:
98       print ' '.join(output_msg)
99
100
101 ENABLE_LOCATION_SETTING = {
102   'settings/secure': {
103     # Ensure Geolocation is enabled and allowed for tests.
104     'location_providers_allowed': 'gps,network',
105   }
106 }
107
108 DISABLE_LOCATION_SETTING = {
109   'settings/secure': {
110     # Ensure Geolocation is disabled.
111     'location_providers_allowed': '',
112   }
113 }
114
115 DETERMINISTIC_DEVICE_SETTINGS = {
116   'com.google.settings/partner': {
117     'network_location_opt_in': 0,
118     'use_location_for_services': 1,
119   },
120   'settings/global': {
121     'assisted_gps_enabled': 0,
122
123     # Disable "auto time" and "auto time zone" to avoid network-provided time
124     # to overwrite the device's datetime and timezone synchronized from host
125     # when running tests later. See b/6569849.
126     'auto_time': 0,
127     'auto_time_zone': 0,
128
129     'development_settings_enabled': 1,
130
131     # Flag for allowing ActivityManagerService to send ACTION_APP_ERROR intents
132     # on application crashes and ANRs. If this is disabled, the crash/ANR dialog
133     # will never display the "Report" button.
134     # Type: int ( 0 = disallow, 1 = allow )
135     'send_action_app_error': 0,
136
137     'stay_on_while_plugged_in': 3,
138
139     'verifier_verify_adb_installs' : 0,
140   },
141   'settings/secure': {
142     'allowed_geolocation_origins':
143         'http://www.google.co.uk http://www.google.com',
144
145     # Ensure that we never get random dialogs like "Unfortunately the process
146     # android.process.acore has stopped", which steal the focus, and make our
147     # automation fail (because the dialog steals the focus then mistakenly
148     # receives the injected user input events).
149     'anr_show_background': 0,
150
151     'lockscreen.disabled': 1,
152
153     'screensaver_enabled': 0,
154   },
155   'settings/system': {
156     # Don't want devices to accidentally rotate the screen as that could
157     # affect performance measurements.
158     'accelerometer_rotation': 0,
159
160     'lockscreen.disabled': 1,
161
162     # Turn down brightness and disable auto-adjust so that devices run cooler.
163     'screen_brightness': 5,
164     'screen_brightness_mode': 0,
165
166     'user_rotation': 0,
167   },
168 }
169
170
171 NETWORK_DISABLED_SETTINGS = {
172   'settings/global': {
173     'airplane_mode_on': 1,
174     'wifi_on': 0,
175   },
176 }