blob: f316d889879fb7cf34759317cb251733d4f07d69 [file] [log] [blame]
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.providers.settings;
18
19import android.content.ComponentName;
20import android.content.ContentValues;
21import android.content.Context;
22import android.content.Intent;
23import android.content.pm.ActivityInfo;
Dianne Hackborn13579ed2012-11-28 18:05:36 -080024import android.content.pm.IPackageManager;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070025import android.content.pm.PackageManager;
Romain Guyf02811f2010-03-09 16:33:51 -080026import android.content.res.XmlResourceParser;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070027import android.database.Cursor;
28import android.database.sqlite.SQLiteDatabase;
29import android.database.sqlite.SQLiteOpenHelper;
30import android.database.sqlite.SQLiteStatement;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070031import android.media.AudioManager;
32import android.media.AudioService;
33import android.net.ConnectivityManager;
Christopher Tate06efb532012-08-24 15:29:27 -070034import android.os.Environment;
Dianne Hackborn13579ed2012-11-28 18:05:36 -080035import android.os.RemoteException;
36import android.os.ServiceManager;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070037import android.os.SystemProperties;
Christopher Tate06efb532012-08-24 15:29:27 -070038import android.os.UserHandle;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070039import android.provider.Settings;
Jeff Sharkey625239a2012-09-26 22:03:49 -070040import android.provider.Settings.Global;
Amith Yamasani156c4352010-03-05 17:10:03 -080041import android.provider.Settings.Secure;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070042import android.text.TextUtils;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070043import android.util.Log;
Suchi Amalapurapu40e47252010-04-07 16:15:50 -070044
Gilles Debunnefa53d302011-07-08 10:40:51 -070045import com.android.internal.content.PackageHelper;
Gilles Debunnefa53d302011-07-08 10:40:51 -070046import com.android.internal.telephony.RILConstants;
Naveen Kallab4d485c2013-07-03 16:39:27 -070047import com.android.internal.telephony.cdma.CdmaSubscriptionSourceManager;
Gilles Debunnefa53d302011-07-08 10:40:51 -070048import com.android.internal.util.XmlUtils;
49import com.android.internal.widget.LockPatternUtils;
50import com.android.internal.widget.LockPatternView;
51
52import org.xmlpull.v1.XmlPullParser;
53import org.xmlpull.v1.XmlPullParserException;
54
Christopher Tate06efb532012-08-24 15:29:27 -070055import java.io.File;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070056import java.io.IOException;
Dianne Hackborn24117ce2010-07-12 15:54:38 -070057import java.util.HashSet;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070058import java.util.List;
59
60/**
61 * Database helper class for {@link SettingsProvider}.
62 * Mostly just has a bit {@link #onCreate} to initialize the database.
63 */
James Wylder074da8f2009-02-25 08:38:31 -060064public class DatabaseHelper extends SQLiteOpenHelper {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070065 private static final String TAG = "SettingsProvider";
66 private static final String DATABASE_NAME = "settings.db";
Jim Millerf1860552009-09-09 17:46:35 -070067
68 // Please, please please. If you update the database version, check to make sure the
69 // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
70 // is properly propagated through your change. Not doing so will result in a loss of user
71 // settings.
Daniel Sandlerdea64622013-09-23 16:05:57 -040072 private static final int DATABASE_VERSION = 98;
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -070073
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070074 private Context mContext;
Christopher Tate06efb532012-08-24 15:29:27 -070075 private int mUserHandle;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070076
Dianne Hackborn24117ce2010-07-12 15:54:38 -070077 private static final HashSet<String> mValidTables = new HashSet<String>();
78
Christopher Tate06efb532012-08-24 15:29:27 -070079 private static final String TABLE_SYSTEM = "system";
80 private static final String TABLE_SECURE = "secure";
81 private static final String TABLE_GLOBAL = "global";
82
Dianne Hackborn24117ce2010-07-12 15:54:38 -070083 static {
Christopher Tate06efb532012-08-24 15:29:27 -070084 mValidTables.add(TABLE_SYSTEM);
85 mValidTables.add(TABLE_SECURE);
86 mValidTables.add(TABLE_GLOBAL);
Dianne Hackborn24117ce2010-07-12 15:54:38 -070087 mValidTables.add("bluetooth_devices");
88 mValidTables.add("bookmarks");
89
90 // These are old.
91 mValidTables.add("favorites");
92 mValidTables.add("gservices");
93 mValidTables.add("old_favorites");
94 }
95
Christopher Tate06efb532012-08-24 15:29:27 -070096 static String dbNameForUser(final int userHandle) {
97 // The owner gets the unadorned db name;
98 if (userHandle == UserHandle.USER_OWNER) {
99 return DATABASE_NAME;
100 } else {
101 // Place the database in the user-specific data tree so that it's
102 // cleaned up automatically when the user is deleted.
103 File databaseFile = new File(
104 Environment.getUserSystemDirectory(userHandle), DATABASE_NAME);
105 return databaseFile.getPath();
106 }
107 }
108
109 public DatabaseHelper(Context context, int userHandle) {
110 super(context, dbNameForUser(userHandle), null, DATABASE_VERSION);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700111 mContext = context;
Christopher Tate06efb532012-08-24 15:29:27 -0700112 mUserHandle = userHandle;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700113 }
114
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700115 public static boolean isValidTable(String name) {
116 return mValidTables.contains(name);
117 }
118
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800119 private void createSecureTable(SQLiteDatabase db) {
120 db.execSQL("CREATE TABLE secure (" +
121 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
122 "name TEXT UNIQUE ON CONFLICT REPLACE," +
123 "value TEXT" +
124 ");");
125 db.execSQL("CREATE INDEX secureIndex1 ON secure (name);");
126 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700127
Christopher Tate06efb532012-08-24 15:29:27 -0700128 private void createGlobalTable(SQLiteDatabase db) {
129 db.execSQL("CREATE TABLE global (" +
130 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
131 "name TEXT UNIQUE ON CONFLICT REPLACE," +
132 "value TEXT" +
133 ");");
134 db.execSQL("CREATE INDEX globalIndex1 ON global (name);");
135 }
136
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700137 @Override
138 public void onCreate(SQLiteDatabase db) {
139 db.execSQL("CREATE TABLE system (" +
140 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
141 "name TEXT UNIQUE ON CONFLICT REPLACE," +
142 "value TEXT" +
143 ");");
144 db.execSQL("CREATE INDEX systemIndex1 ON system (name);");
145
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800146 createSecureTable(db);
147
Christopher Tate06efb532012-08-24 15:29:27 -0700148 // Only create the global table for the singleton 'owner' user
149 if (mUserHandle == UserHandle.USER_OWNER) {
150 createGlobalTable(db);
151 }
152
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700153 db.execSQL("CREATE TABLE bluetooth_devices (" +
154 "_id INTEGER PRIMARY KEY," +
155 "name TEXT," +
156 "addr TEXT," +
157 "channel INTEGER," +
158 "type INTEGER" +
159 ");");
160
161 db.execSQL("CREATE TABLE bookmarks (" +
162 "_id INTEGER PRIMARY KEY," +
163 "title TEXT," +
164 "folder TEXT," +
165 "intent TEXT," +
166 "shortcut INTEGER," +
167 "ordering INTEGER" +
168 ");");
169
170 db.execSQL("CREATE INDEX bookmarksIndex1 ON bookmarks (folder);");
171 db.execSQL("CREATE INDEX bookmarksIndex2 ON bookmarks (shortcut);");
172
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700173 // Populate bookmarks table with initial bookmarks
Dianne Hackborn13579ed2012-11-28 18:05:36 -0800174 boolean onlyCore = false;
175 try {
176 onlyCore = IPackageManager.Stub.asInterface(ServiceManager.getService(
177 "package")).isOnlyCoreApps();
178 } catch (RemoteException e) {
179 }
180 if (!onlyCore) {
181 loadBookmarks(db);
182 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700183
184 // Load initial volume levels into DB
185 loadVolumeLevels(db);
186
187 // Load inital settings values
188 loadSettings(db);
189 }
190
191 @Override
192 public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700193 Log.w(TAG, "Upgrading settings database from version " + oldVersion + " to "
194 + currentVersion);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700195
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700196 int upgradeVersion = oldVersion;
197
198 // Pattern for upgrade blocks:
199 //
200 // if (upgradeVersion == [the DATABASE_VERSION you set] - 1) {
201 // .. your upgrade logic..
202 // upgradeVersion = [the DATABASE_VERSION you set]
203 // }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700204
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700205 if (upgradeVersion == 20) {
206 /*
207 * Version 21 is part of the volume control refresh. There is no
208 * longer a UI-visible for setting notification vibrate on/off (in
209 * our design), but the functionality still exists. Force the
210 * notification vibrate to on.
211 */
212 loadVibrateSetting(db, true);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700213
214 upgradeVersion = 21;
215 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700216
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700217 if (upgradeVersion < 22) {
218 upgradeVersion = 22;
219 // Upgrade the lock gesture storage location and format
220 upgradeLockPatternLocation(db);
221 }
222
223 if (upgradeVersion < 23) {
224 db.execSQL("UPDATE favorites SET iconResource=0 WHERE iconType=0");
225 upgradeVersion = 23;
226 }
227
228 if (upgradeVersion == 23) {
229 db.beginTransaction();
230 try {
231 db.execSQL("ALTER TABLE favorites ADD spanX INTEGER");
232 db.execSQL("ALTER TABLE favorites ADD spanY INTEGER");
233 // Shortcuts, applications, folders
234 db.execSQL("UPDATE favorites SET spanX=1, spanY=1 WHERE itemType<=0");
235 // Photo frames, clocks
Wink Saville04e71b32009-04-02 11:00:54 -0700236 db.execSQL(
237 "UPDATE favorites SET spanX=2, spanY=2 WHERE itemType=1000 or itemType=1002");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700238 // Search boxes
239 db.execSQL("UPDATE favorites SET spanX=4, spanY=1 WHERE itemType=1001");
240 db.setTransactionSuccessful();
241 } finally {
242 db.endTransaction();
243 }
244 upgradeVersion = 24;
245 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700246
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700247 if (upgradeVersion == 24) {
248 db.beginTransaction();
249 try {
250 // The value of the constants for preferring wifi or preferring mobile have been
251 // swapped, so reload the default.
252 db.execSQL("DELETE FROM system WHERE name='network_preference'");
253 db.execSQL("INSERT INTO system ('name', 'value') values ('network_preference', '" +
254 ConnectivityManager.DEFAULT_NETWORK_PREFERENCE + "')");
255 db.setTransactionSuccessful();
256 } finally {
257 db.endTransaction();
258 }
259 upgradeVersion = 25;
260 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800261
262 if (upgradeVersion == 25) {
263 db.beginTransaction();
264 try {
265 db.execSQL("ALTER TABLE favorites ADD uri TEXT");
266 db.execSQL("ALTER TABLE favorites ADD displayMode INTEGER");
267 db.setTransactionSuccessful();
268 } finally {
269 db.endTransaction();
270 }
271 upgradeVersion = 26;
272 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700273
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800274 if (upgradeVersion == 26) {
275 // This introduces the new secure settings table.
276 db.beginTransaction();
277 try {
278 createSecureTable(db);
279 db.setTransactionSuccessful();
280 } finally {
281 db.endTransaction();
282 }
283 upgradeVersion = 27;
284 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700285
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800286 if (upgradeVersion == 27) {
Amith Yamasani156c4352010-03-05 17:10:03 -0800287 String[] settingsToMove = {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800288 Settings.Secure.ADB_ENABLED,
289 Settings.Secure.ANDROID_ID,
290 Settings.Secure.BLUETOOTH_ON,
291 Settings.Secure.DATA_ROAMING,
292 Settings.Secure.DEVICE_PROVISIONED,
293 Settings.Secure.HTTP_PROXY,
294 Settings.Secure.INSTALL_NON_MARKET_APPS,
295 Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
296 Settings.Secure.LOGGING_ID,
297 Settings.Secure.NETWORK_PREFERENCE,
298 Settings.Secure.PARENTAL_CONTROL_ENABLED,
299 Settings.Secure.PARENTAL_CONTROL_LAST_UPDATE,
300 Settings.Secure.PARENTAL_CONTROL_REDIRECT_URL,
301 Settings.Secure.SETTINGS_CLASSNAME,
302 Settings.Secure.USB_MASS_STORAGE_ENABLED,
303 Settings.Secure.USE_GOOGLE_MAIL,
304 Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
305 Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,
306 Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT,
307 Settings.Secure.WIFI_ON,
308 Settings.Secure.WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE,
309 Settings.Secure.WIFI_WATCHDOG_AP_COUNT,
310 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS,
311 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED,
312 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS,
313 Settings.Secure.WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT,
314 Settings.Secure.WIFI_WATCHDOG_MAX_AP_CHECKS,
315 Settings.Secure.WIFI_WATCHDOG_ON,
316 Settings.Secure.WIFI_WATCHDOG_PING_COUNT,
317 Settings.Secure.WIFI_WATCHDOG_PING_DELAY_MS,
318 Settings.Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS,
319 };
Christopher Tate92198742012-09-07 12:00:13 -0700320 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800321 upgradeVersion = 28;
322 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700323
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800324 if (upgradeVersion == 28 || upgradeVersion == 29) {
325 // Note: The upgrade to 28 was flawed since it didn't delete the old
326 // setting first before inserting. Combining 28 and 29 with the
327 // fixed version.
328
329 // This upgrade adds the STREAM_NOTIFICATION type to the list of
330 // types affected by ringer modes (silent, vibrate, etc.)
331 db.beginTransaction();
332 try {
333 db.execSQL("DELETE FROM system WHERE name='"
334 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
335 int newValue = (1 << AudioManager.STREAM_RING)
336 | (1 << AudioManager.STREAM_NOTIFICATION)
337 | (1 << AudioManager.STREAM_SYSTEM);
338 db.execSQL("INSERT INTO system ('name', 'value') values ('"
339 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
340 + String.valueOf(newValue) + "')");
341 db.setTransactionSuccessful();
342 } finally {
343 db.endTransaction();
344 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700345
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800346 upgradeVersion = 30;
347 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700348
The Android Open Source Project9266c552009-01-15 16:12:10 -0800349 if (upgradeVersion == 30) {
350 /*
351 * Upgrade 31 clears the title for all quick launch shortcuts so the
352 * activities' titles will be resolved at display time. Also, the
353 * folder is changed to '@quicklaunch'.
354 */
355 db.beginTransaction();
356 try {
357 db.execSQL("UPDATE bookmarks SET folder = '@quicklaunch'");
358 db.execSQL("UPDATE bookmarks SET title = ''");
359 db.setTransactionSuccessful();
360 } finally {
361 db.endTransaction();
362 }
363 upgradeVersion = 31;
364 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 if (upgradeVersion == 31) {
367 /*
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700368 * Animations are now managed in preferences, and may be
369 * enabled or disabled based on product resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 */
371 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700372 SQLiteStatement stmt = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 try {
374 db.execSQL("DELETE FROM system WHERE name='"
375 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
376 db.execSQL("DELETE FROM system WHERE name='"
377 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700378 stmt = db.compileStatement("INSERT INTO system(name,value)"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 + " VALUES(?,?);");
380 loadDefaultAnimationSettings(stmt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 db.setTransactionSuccessful();
382 } finally {
383 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700384 if (stmt != null) stmt.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 }
386 upgradeVersion = 32;
387 }
388
389 if (upgradeVersion == 32) {
390 // The Wi-Fi watchdog SSID list is now seeded with the value of
391 // the property ro.com.android.wifi-watchlist
392 String wifiWatchList = SystemProperties.get("ro.com.android.wifi-watchlist");
393 if (!TextUtils.isEmpty(wifiWatchList)) {
394 db.beginTransaction();
395 try {
396 db.execSQL("INSERT OR IGNORE INTO secure(name,value) values('" +
397 Settings.Secure.WIFI_WATCHDOG_WATCH_LIST + "','" +
398 wifiWatchList + "');");
399 db.setTransactionSuccessful();
400 } finally {
401 db.endTransaction();
402 }
403 }
404 upgradeVersion = 33;
405 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700406
The Android Open Source Project4df24232009-03-05 14:34:35 -0800407 if (upgradeVersion == 33) {
408 // Set the default zoom controls to: tap-twice to bring up +/-
409 db.beginTransaction();
410 try {
411 db.execSQL("INSERT INTO system(name,value) values('zoom','2');");
412 db.setTransactionSuccessful();
413 } finally {
414 db.endTransaction();
415 }
416 upgradeVersion = 34;
417 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418
Mike Lockwoodbcab8df2009-06-25 16:39:09 -0400419 if (upgradeVersion == 34) {
420 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700421 SQLiteStatement stmt = null;
Mike Lockwoodbcab8df2009-06-25 16:39:09 -0400422 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700423 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
Dianne Hackborncf098292009-07-01 19:55:20 -0700424 + " VALUES(?,?);");
425 loadSecure35Settings(stmt);
Dianne Hackborncf098292009-07-01 19:55:20 -0700426 db.setTransactionSuccessful();
427 } finally {
428 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700429 if (stmt != null) stmt.close();
Dianne Hackborncf098292009-07-01 19:55:20 -0700430 }
Jim Millerf1860552009-09-09 17:46:35 -0700431 upgradeVersion = 35;
Mike Lockwood02901eb2009-08-25 15:11:17 -0700432 }
433 // due to a botched merge from donut to eclair, the initialization of ASSISTED_GPS_ENABLED
434 // was accidentally done out of order here.
435 // to fix this, ASSISTED_GPS_ENABLED is now initialized while upgrading from 38 to 39,
436 // and we intentionally do nothing from 35 to 36 now.
437 if (upgradeVersion == 35) {
The Android Open Source Project575d1af2009-07-03 08:55:59 -0700438 upgradeVersion = 36;
Dianne Hackborncf098292009-07-01 19:55:20 -0700439 }
Mike Lockwood02901eb2009-08-25 15:11:17 -0700440
Eric Laurenta553c252009-07-17 12:17:14 -0700441 if (upgradeVersion == 36) {
442 // This upgrade adds the STREAM_SYSTEM_ENFORCED type to the list of
443 // types affected by ringer modes (silent, vibrate, etc.)
444 db.beginTransaction();
445 try {
446 db.execSQL("DELETE FROM system WHERE name='"
447 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
448 int newValue = (1 << AudioManager.STREAM_RING)
449 | (1 << AudioManager.STREAM_NOTIFICATION)
450 | (1 << AudioManager.STREAM_SYSTEM)
451 | (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
452 db.execSQL("INSERT INTO system ('name', 'value') values ('"
453 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
454 + String.valueOf(newValue) + "')");
455 db.setTransactionSuccessful();
456 } finally {
457 db.endTransaction();
458 }
Jim Miller48805752009-08-04 18:59:20 -0700459 upgradeVersion = 37;
Eric Laurenta553c252009-07-17 12:17:14 -0700460 }
461
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700462 if (upgradeVersion == 37) {
463 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700464 SQLiteStatement stmt = null;
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700465 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700466 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700467 + " VALUES(?,?);");
468 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
469 R.string.airplane_mode_toggleable_radios);
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700470 db.setTransactionSuccessful();
471 } finally {
472 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700473 if (stmt != null) stmt.close();
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700474 }
475 upgradeVersion = 38;
476 }
477
Mike Lockwood02901eb2009-08-25 15:11:17 -0700478 if (upgradeVersion == 38) {
479 db.beginTransaction();
480 try {
481 String value =
482 mContext.getResources().getBoolean(R.bool.assisted_gps_enabled) ? "1" : "0";
483 db.execSQL("INSERT OR IGNORE INTO secure(name,value) values('" +
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -0700484 Settings.Global.ASSISTED_GPS_ENABLED + "','" + value + "');");
Mike Lockwood02901eb2009-08-25 15:11:17 -0700485 db.setTransactionSuccessful();
486 } finally {
487 db.endTransaction();
488 }
489
490 upgradeVersion = 39;
491 }
492
Dan Murphy951764b2009-08-27 14:59:03 -0500493 if (upgradeVersion == 39) {
Amith Yamasanif50c5112011-01-07 11:32:30 -0800494 upgradeAutoBrightness(db);
Dan Murphy951764b2009-08-27 14:59:03 -0500495 upgradeVersion = 40;
496 }
497
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700498 if (upgradeVersion == 40) {
499 /*
500 * All animations are now turned on by default!
501 */
502 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700503 SQLiteStatement stmt = null;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700504 try {
505 db.execSQL("DELETE FROM system WHERE name='"
506 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
507 db.execSQL("DELETE FROM system WHERE name='"
508 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700509 stmt = db.compileStatement("INSERT INTO system(name,value)"
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700510 + " VALUES(?,?);");
511 loadDefaultAnimationSettings(stmt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700512 db.setTransactionSuccessful();
513 } finally {
514 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700515 if (stmt != null) stmt.close();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700516 }
517 upgradeVersion = 41;
518 }
519
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700520 if (upgradeVersion == 41) {
521 /*
522 * Initialize newly public haptic feedback setting
523 */
524 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700525 SQLiteStatement stmt = null;
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700526 try {
527 db.execSQL("DELETE FROM system WHERE name='"
528 + Settings.System.HAPTIC_FEEDBACK_ENABLED + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700529 stmt = db.compileStatement("INSERT INTO system(name,value)"
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700530 + " VALUES(?,?);");
531 loadDefaultHapticSettings(stmt);
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700532 db.setTransactionSuccessful();
533 } finally {
534 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700535 if (stmt != null) stmt.close();
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700536 }
537 upgradeVersion = 42;
538 }
539
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800540 if (upgradeVersion == 42) {
541 /*
542 * Initialize new notification pulse setting
543 */
544 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700545 SQLiteStatement stmt = null;
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800546 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700547 stmt = db.compileStatement("INSERT INTO system(name,value)"
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800548 + " VALUES(?,?);");
549 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
550 R.bool.def_notification_pulse);
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800551 db.setTransactionSuccessful();
552 } finally {
553 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700554 if (stmt != null) stmt.close();
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800555 }
556 upgradeVersion = 43;
557 }
558
Eric Laurent484d2882009-12-08 09:05:45 -0800559 if (upgradeVersion == 43) {
560 /*
561 * This upgrade stores bluetooth volume separately from voice volume
562 */
563 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700564 SQLiteStatement stmt = null;
Eric Laurent484d2882009-12-08 09:05:45 -0800565 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700566 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
Eric Laurent484d2882009-12-08 09:05:45 -0800567 + " VALUES(?,?);");
568 loadSetting(stmt, Settings.System.VOLUME_BLUETOOTH_SCO,
569 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_BLUETOOTH_SCO]);
Eric Laurent484d2882009-12-08 09:05:45 -0800570 db.setTransactionSuccessful();
571 } finally {
572 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700573 if (stmt != null) stmt.close();
Eric Laurent484d2882009-12-08 09:05:45 -0800574 }
575 upgradeVersion = 44;
576 }
577
Doug Zongkeraed8f8e2010-01-07 18:07:50 -0800578 if (upgradeVersion == 44) {
579 /*
580 * Gservices was moved into vendor/google.
581 */
582 db.execSQL("DROP TABLE IF EXISTS gservices");
583 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1");
584 upgradeVersion = 45;
585 }
San Mehat87734d32010-01-08 12:53:06 -0800586
587 if (upgradeVersion == 45) {
588 /*
589 * New settings for MountService
590 */
591 db.beginTransaction();
592 try {
593 db.execSQL("INSERT INTO secure(name,value) values('" +
594 Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND + "','1');");
595 db.execSQL("INSERT INTO secure(name,value) values('" +
596 Settings.Secure.MOUNT_UMS_AUTOSTART + "','0');");
597 db.execSQL("INSERT INTO secure(name,value) values('" +
598 Settings.Secure.MOUNT_UMS_PROMPT + "','1');");
599 db.execSQL("INSERT INTO secure(name,value) values('" +
600 Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED + "','1');");
601 db.setTransactionSuccessful();
602 } finally {
603 db.endTransaction();
604 }
605 upgradeVersion = 46;
606 }
607
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800608 if (upgradeVersion == 46) {
609 /*
610 * The password mode constants have changed; reset back to no
611 * password.
612 */
613 db.beginTransaction();
614 try {
615 db.execSQL("DELETE FROM system WHERE name='lockscreen.password_type';");
616 db.setTransactionSuccessful();
617 } finally {
618 db.endTransaction();
619 }
620 upgradeVersion = 47;
621 }
622
Jim Miller61766772010-02-12 14:56:49 -0800623
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800624 if (upgradeVersion == 47) {
625 /*
626 * The password mode constants have changed again; reset back to no
627 * password.
628 */
629 db.beginTransaction();
630 try {
631 db.execSQL("DELETE FROM system WHERE name='lockscreen.password_type';");
632 db.setTransactionSuccessful();
633 } finally {
634 db.endTransaction();
635 }
636 upgradeVersion = 48;
637 }
Jim Miller61766772010-02-12 14:56:49 -0800638
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800639 if (upgradeVersion == 48) {
640 /*
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800641 * Default recognition service no longer initialized here,
642 * moved to RecognitionManagerService.
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800643 */
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800644 upgradeVersion = 49;
645 }
Jim Miller31f90b62010-01-20 13:35:20 -0800646
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500647 if (upgradeVersion == 49) {
648 /*
649 * New settings for new user interface noises.
650 */
651 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700652 SQLiteStatement stmt = null;
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500653 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700654 stmt = db.compileStatement("INSERT INTO system(name,value)"
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500655 + " VALUES(?,?);");
656 loadUISoundEffectsSettings(stmt);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500657 db.setTransactionSuccessful();
658 } finally {
659 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700660 if (stmt != null) stmt.close();
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500661 }
662
663 upgradeVersion = 50;
664 }
665
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800666 if (upgradeVersion == 50) {
667 /*
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700668 * Install location no longer initiated here.
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800669 */
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800670 upgradeVersion = 51;
671 }
672
Amith Yamasani156c4352010-03-05 17:10:03 -0800673 if (upgradeVersion == 51) {
674 /* Move the lockscreen related settings to Secure, including some private ones. */
675 String[] settingsToMove = {
676 Secure.LOCK_PATTERN_ENABLED,
677 Secure.LOCK_PATTERN_VISIBLE,
678 Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED,
679 "lockscreen.password_type",
680 "lockscreen.lockoutattemptdeadline",
681 "lockscreen.patterneverchosen",
682 "lock_pattern_autolock",
683 "lockscreen.lockedoutpermanently",
684 "lockscreen.password_salt"
685 };
Christopher Tate92198742012-09-07 12:00:13 -0700686 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
Amith Yamasani156c4352010-03-05 17:10:03 -0800687 upgradeVersion = 52;
688 }
689
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500690 if (upgradeVersion == 52) {
691 // new vibration/silent mode settings
692 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700693 SQLiteStatement stmt = null;
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500694 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700695 stmt = db.compileStatement("INSERT INTO system(name,value)"
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500696 + " VALUES(?,?);");
697 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
698 R.bool.def_vibrate_in_silent);
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500699 db.setTransactionSuccessful();
700 } finally {
701 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700702 if (stmt != null) stmt.close();
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500703 }
704
705 upgradeVersion = 53;
706 }
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -0700707
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800708 if (upgradeVersion == 53) {
709 /*
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700710 * New settings for set install location UI no longer initiated here.
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800711 */
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800712 upgradeVersion = 54;
713 }
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500714
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -0700715 if (upgradeVersion == 54) {
716 /*
717 * Update the screen timeout value if set to never
718 */
719 db.beginTransaction();
720 try {
721 upgradeScreenTimeoutFromNever(db);
722 db.setTransactionSuccessful();
723 } finally {
724 db.endTransaction();
725 }
726
727 upgradeVersion = 55;
728 }
729
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700730 if (upgradeVersion == 55) {
731 /* Move the install location settings. */
732 String[] settingsToMove = {
Jeff Sharkey625239a2012-09-26 22:03:49 -0700733 Global.SET_INSTALL_LOCATION,
734 Global.DEFAULT_INSTALL_LOCATION
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700735 };
Christopher Tate92198742012-09-07 12:00:13 -0700736 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700737 db.beginTransaction();
738 SQLiteStatement stmt = null;
739 try {
740 stmt = db.compileStatement("INSERT INTO system(name,value)"
741 + " VALUES(?,?);");
Jeff Sharkey625239a2012-09-26 22:03:49 -0700742 loadSetting(stmt, Global.SET_INSTALL_LOCATION, 0);
743 loadSetting(stmt, Global.DEFAULT_INSTALL_LOCATION,
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700744 PackageHelper.APP_INSTALL_AUTO);
745 db.setTransactionSuccessful();
746 } finally {
747 db.endTransaction();
748 if (stmt != null) stmt.close();
749 }
750 upgradeVersion = 56;
751 }
Jake Hamby66592842010-08-24 19:55:20 -0700752
753 if (upgradeVersion == 56) {
754 /*
755 * Add Bluetooth to list of toggleable radios in airplane mode
756 */
757 db.beginTransaction();
758 SQLiteStatement stmt = null;
759 try {
760 db.execSQL("DELETE FROM system WHERE name='"
761 + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS + "'");
762 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
763 + " VALUES(?,?);");
764 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
765 R.string.airplane_mode_toggleable_radios);
766 db.setTransactionSuccessful();
767 } finally {
768 db.endTransaction();
769 if (stmt != null) stmt.close();
770 }
771 upgradeVersion = 57;
772 }
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700773
Amith Yamasani5cd15002011-11-16 11:19:48 -0800774 /************* The following are Honeycomb changes ************/
775
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700776 if (upgradeVersion == 57) {
777 /*
778 * New settings to:
779 * 1. Enable injection of accessibility scripts in WebViews.
780 * 2. Define the key bindings for traversing web content in WebViews.
781 */
782 db.beginTransaction();
783 SQLiteStatement stmt = null;
784 try {
785 stmt = db.compileStatement("INSERT INTO secure(name,value)"
786 + " VALUES(?,?);");
787 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION,
788 R.bool.def_accessibility_script_injection);
789 stmt.close();
790 stmt = db.compileStatement("INSERT INTO secure(name,value)"
791 + " VALUES(?,?);");
792 loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS,
793 R.string.def_accessibility_web_content_key_bindings);
794 db.setTransactionSuccessful();
795 } finally {
796 db.endTransaction();
797 if (stmt != null) stmt.close();
798 }
799 upgradeVersion = 58;
800 }
801
Amith Yamasaniad450be2010-09-16 16:47:00 -0700802 if (upgradeVersion == 58) {
803 /* Add default for new Auto Time Zone */
Amith Yamasani5cd15002011-11-16 11:19:48 -0800804 int autoTimeValue = getIntValueFromSystem(db, Settings.System.AUTO_TIME, 0);
Amith Yamasaniad450be2010-09-16 16:47:00 -0700805 db.beginTransaction();
806 SQLiteStatement stmt = null;
807 try {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800808 stmt = db.compileStatement("INSERT INTO system(name,value)" + " VALUES(?,?);");
809 loadSetting(stmt, Settings.System.AUTO_TIME_ZONE,
810 autoTimeValue); // Sync timezone to NITZ if auto_time was enabled
Amith Yamasaniad450be2010-09-16 16:47:00 -0700811 db.setTransactionSuccessful();
812 } finally {
813 db.endTransaction();
814 if (stmt != null) stmt.close();
815 }
816 upgradeVersion = 59;
817 }
818
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400819 if (upgradeVersion == 59) {
820 // Persistence for the rotation lock feature.
821 db.beginTransaction();
822 SQLiteStatement stmt = null;
823 try {
824 stmt = db.compileStatement("INSERT INTO system(name,value)"
825 + " VALUES(?,?);");
826 loadBooleanSetting(stmt, Settings.System.USER_ROTATION,
827 R.integer.def_user_rotation); // should be zero degrees
828 db.setTransactionSuccessful();
829 } finally {
830 db.endTransaction();
831 if (stmt != null) stmt.close();
832 }
833 upgradeVersion = 60;
834 }
835
Amith Yamasani00389312010-11-05 11:22:21 -0700836 if (upgradeVersion == 60) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800837 // Don't do this for upgrades from Gingerbread
838 // Were only required for intra-Honeycomb upgrades for testing
839 // upgradeScreenTimeout(db);
Amith Yamasani00389312010-11-05 11:22:21 -0700840 upgradeVersion = 61;
841 }
842
Amith Yamasani79373f62010-11-18 16:32:48 -0800843 if (upgradeVersion == 61) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800844 // Don't do this for upgrades from Gingerbread
845 // Were only required for intra-Honeycomb upgrades for testing
846 // upgradeScreenTimeout(db);
Amith Yamasani79373f62010-11-18 16:32:48 -0800847 upgradeVersion = 62;
848 }
849
Amith Yamasanif50c5112011-01-07 11:32:30 -0800850 // Change the default for screen auto-brightness mode
851 if (upgradeVersion == 62) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800852 // Don't do this for upgrades from Gingerbread
853 // Were only required for intra-Honeycomb upgrades for testing
854 // upgradeAutoBrightness(db);
Amith Yamasanif50c5112011-01-07 11:32:30 -0800855 upgradeVersion = 63;
856 }
857
Eric Laurent25101b02011-02-02 09:33:30 -0800858 if (upgradeVersion == 63) {
859 // This upgrade adds the STREAM_MUSIC type to the list of
860 // types affected by ringer modes (silent, vibrate, etc.)
861 db.beginTransaction();
862 try {
863 db.execSQL("DELETE FROM system WHERE name='"
864 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
865 int newValue = (1 << AudioManager.STREAM_RING)
866 | (1 << AudioManager.STREAM_NOTIFICATION)
867 | (1 << AudioManager.STREAM_SYSTEM)
868 | (1 << AudioManager.STREAM_SYSTEM_ENFORCED)
869 | (1 << AudioManager.STREAM_MUSIC);
870 db.execSQL("INSERT INTO system ('name', 'value') values ('"
871 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
872 + String.valueOf(newValue) + "')");
873 db.setTransactionSuccessful();
874 } finally {
875 db.endTransaction();
876 }
877 upgradeVersion = 64;
878 }
879
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800880 if (upgradeVersion == 64) {
881 // New setting to configure the long press timeout.
882 db.beginTransaction();
883 SQLiteStatement stmt = null;
884 try {
885 stmt = db.compileStatement("INSERT INTO secure(name,value)"
886 + " VALUES(?,?);");
887 loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT,
888 R.integer.def_long_press_timeout_millis);
889 stmt.close();
890 db.setTransactionSuccessful();
891 } finally {
892 db.endTransaction();
893 if (stmt != null) stmt.close();
894 }
895 upgradeVersion = 65;
896 }
897
Amith Yamasani5cd15002011-11-16 11:19:48 -0800898 /************* The following are Ice Cream Sandwich changes ************/
899
Gilles Debunnefa53d302011-07-08 10:40:51 -0700900 if (upgradeVersion == 65) {
901 /*
902 * Animations are removed from Settings. Turned on by default
903 */
904 db.beginTransaction();
905 SQLiteStatement stmt = null;
906 try {
907 db.execSQL("DELETE FROM system WHERE name='"
908 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
909 db.execSQL("DELETE FROM system WHERE name='"
910 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
911 stmt = db.compileStatement("INSERT INTO system(name,value)"
912 + " VALUES(?,?);");
913 loadDefaultAnimationSettings(stmt);
914 db.setTransactionSuccessful();
915 } finally {
916 db.endTransaction();
917 if (stmt != null) stmt.close();
918 }
919 upgradeVersion = 66;
920 }
921
Eric Laurentc1d41662011-07-19 11:21:13 -0700922 if (upgradeVersion == 66) {
Amith Yamasani42722bf2011-07-22 10:34:27 -0700923 // This upgrade makes sure that MODE_RINGER_STREAMS_AFFECTED is set
924 // according to device voice capability
925 db.beginTransaction();
926 try {
927 int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
928 (1 << AudioManager.STREAM_NOTIFICATION) |
929 (1 << AudioManager.STREAM_SYSTEM) |
930 (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
931 if (!mContext.getResources().getBoolean(
932 com.android.internal.R.bool.config_voice_capable)) {
933 ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
934 }
935 db.execSQL("DELETE FROM system WHERE name='"
936 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
937 db.execSQL("INSERT INTO system ('name', 'value') values ('"
938 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
939 + String.valueOf(ringerModeAffectedStreams) + "')");
940 db.setTransactionSuccessful();
941 } finally {
942 db.endTransaction();
943 }
944 upgradeVersion = 67;
945 }
Eric Laurentc1d41662011-07-19 11:21:13 -0700946
Svetoslav Ganova28a16d2011-07-28 11:24:21 -0700947 if (upgradeVersion == 67) {
948 // New setting to enable touch exploration.
949 db.beginTransaction();
950 SQLiteStatement stmt = null;
951 try {
952 stmt = db.compileStatement("INSERT INTO secure(name,value)"
953 + " VALUES(?,?);");
954 loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED,
955 R.bool.def_touch_exploration_enabled);
956 stmt.close();
957 db.setTransactionSuccessful();
958 } finally {
959 db.endTransaction();
960 if (stmt != null) stmt.close();
961 }
962 upgradeVersion = 68;
963 }
964
Amith Yamasani42722bf2011-07-22 10:34:27 -0700965 if (upgradeVersion == 68) {
966 // Enable all system sounds by default
967 db.beginTransaction();
Amith Yamasani42722bf2011-07-22 10:34:27 -0700968 try {
Amith Yamasani42722bf2011-07-22 10:34:27 -0700969 db.execSQL("DELETE FROM system WHERE name='"
970 + Settings.System.NOTIFICATIONS_USE_RING_VOLUME + "'");
Amith Yamasani42722bf2011-07-22 10:34:27 -0700971 db.setTransactionSuccessful();
972 } finally {
973 db.endTransaction();
Amith Yamasani42722bf2011-07-22 10:34:27 -0700974 }
975 upgradeVersion = 69;
976 }
Svetoslav Ganova28a16d2011-07-28 11:24:21 -0700977
Nick Pelly8d32a012011-08-09 07:03:49 -0700978 if (upgradeVersion == 69) {
979 // Add RADIO_NFC to AIRPLANE_MODE_RADIO and AIRPLANE_MODE_TOGGLEABLE_RADIOS
980 String airplaneRadios = mContext.getResources().getString(
981 R.string.def_airplane_mode_radios);
982 String toggleableRadios = mContext.getResources().getString(
983 R.string.airplane_mode_toggleable_radios);
984 db.beginTransaction();
985 try {
986 db.execSQL("UPDATE system SET value='" + airplaneRadios + "' " +
987 "WHERE name='" + Settings.System.AIRPLANE_MODE_RADIOS + "'");
988 db.execSQL("UPDATE system SET value='" + toggleableRadios + "' " +
989 "WHERE name='" + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS + "'");
990 db.setTransactionSuccessful();
991 } finally {
992 db.endTransaction();
993 }
994 upgradeVersion = 70;
995 }
996
Jeff Brown6651a632011-11-28 12:59:11 -0800997 if (upgradeVersion == 70) {
998 // Update all built-in bookmarks. Some of the package names have changed.
999 loadBookmarks(db);
1000 upgradeVersion = 71;
1001 }
1002
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08001003 if (upgradeVersion == 71) {
1004 // New setting to specify whether to speak passwords in accessibility mode.
1005 db.beginTransaction();
1006 SQLiteStatement stmt = null;
1007 try {
1008 stmt = db.compileStatement("INSERT INTO secure(name,value)"
1009 + " VALUES(?,?);");
1010 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD,
1011 R.bool.def_accessibility_speak_password);
Amith Yamasani6243edd2011-12-05 19:58:48 -08001012 db.setTransactionSuccessful();
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08001013 } finally {
1014 db.endTransaction();
1015 if (stmt != null) stmt.close();
1016 }
1017 upgradeVersion = 72;
1018 }
1019
Amith Yamasani6243edd2011-12-05 19:58:48 -08001020 if (upgradeVersion == 72) {
1021 // update vibration settings
1022 db.beginTransaction();
1023 SQLiteStatement stmt = null;
1024 try {
1025 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1026 + " VALUES(?,?);");
1027 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
1028 R.bool.def_vibrate_in_silent);
1029 db.setTransactionSuccessful();
1030 } finally {
1031 db.endTransaction();
1032 if (stmt != null) stmt.close();
1033 }
1034 upgradeVersion = 73;
1035 }
1036
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001037 if (upgradeVersion == 73) {
Amith Yamasani398c83c2011-12-13 10:38:47 -08001038 upgradeVibrateSettingFromNone(db);
1039 upgradeVersion = 74;
1040 }
1041
1042 if (upgradeVersion == 74) {
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001043 // URL from which WebView loads a JavaScript based screen-reader.
1044 db.beginTransaction();
1045 SQLiteStatement stmt = null;
1046 try {
1047 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
1048 loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_SCREEN_READER_URL,
1049 R.string.def_accessibility_screen_reader_url);
1050 db.setTransactionSuccessful();
1051 } finally {
1052 db.endTransaction();
1053 if (stmt != null) stmt.close();
1054 }
Amith Yamasani398c83c2011-12-13 10:38:47 -08001055 upgradeVersion = 75;
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001056 }
Mike Lockwood7bef7392011-10-20 16:51:53 -04001057 if (upgradeVersion == 75) {
1058 db.beginTransaction();
1059 SQLiteStatement stmt = null;
1060 Cursor c = null;
1061 try {
Christopher Tate06efb532012-08-24 15:29:27 -07001062 c = db.query(TABLE_SECURE, new String[] {"_id", "value"},
Mike Lockwood7bef7392011-10-20 16:51:53 -04001063 "name='lockscreen.disabled'",
1064 null, null, null, null);
1065 // only set default if it has not yet been set
1066 if (c == null || c.getCount() == 0) {
1067 stmt = db.compileStatement("INSERT INTO system(name,value)"
1068 + " VALUES(?,?);");
1069 loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED,
1070 R.bool.def_lockscreen_disabled);
1071 }
1072 db.setTransactionSuccessful();
1073 } finally {
1074 db.endTransaction();
1075 if (c != null) c.close();
1076 if (stmt != null) stmt.close();
1077 }
1078 upgradeVersion = 76;
1079 }
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001080
Eric Laurentbffc3d12012-05-07 17:43:49 -07001081 /************* The following are Jelly Bean changes ************/
1082
1083 if (upgradeVersion == 76) {
1084 // Removed VIBRATE_IN_SILENT setting
1085 db.beginTransaction();
1086 try {
1087 db.execSQL("DELETE FROM system WHERE name='"
1088 + Settings.System.VIBRATE_IN_SILENT + "'");
1089 db.setTransactionSuccessful();
1090 } finally {
1091 db.endTransaction();
1092 }
1093
1094 upgradeVersion = 77;
1095 }
1096
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001097 if (upgradeVersion == 77) {
1098 // Introduce "vibrate when ringing" setting
1099 loadVibrateWhenRingingSetting(db);
1100
1101 upgradeVersion = 78;
1102 }
Eric Laurentbffc3d12012-05-07 17:43:49 -07001103
alanv3a67eb32012-06-22 10:47:28 -07001104 if (upgradeVersion == 78) {
1105 // The JavaScript based screen-reader URL changes in JellyBean.
1106 db.beginTransaction();
1107 SQLiteStatement stmt = null;
1108 try {
1109 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1110 + " VALUES(?,?);");
1111 loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_SCREEN_READER_URL,
1112 R.string.def_accessibility_screen_reader_url);
1113 db.setTransactionSuccessful();
1114 } finally {
1115 db.endTransaction();
1116 if (stmt != null) stmt.close();
1117 }
1118 upgradeVersion = 79;
1119 }
1120
Svetoslav Ganov86317012012-08-15 22:13:00 -07001121 if (upgradeVersion == 79) {
1122 // Before touch exploration was a global setting controlled by the user
1123 // via the UI. However, if the enabled accessibility services do not
1124 // handle touch exploration mode, enabling it makes no sense. Therefore,
1125 // now the services request touch exploration mode and the user is
1126 // presented with a dialog to allow that and if she does we store that
1127 // in the database. As a result of this change a user that has enabled
1128 // accessibility, touch exploration, and some accessibility services
1129 // may lose touch exploration state, thus rendering the device useless
1130 // unless sighted help is provided, since the enabled service(s) are
1131 // not in the list of services to which the user granted a permission
1132 // to put the device in touch explore mode. Here we are allowing all
1133 // enabled accessibility services to toggle touch exploration provided
1134 // accessibility and touch exploration are enabled and no services can
1135 // toggle touch exploration. Note that the user has already manually
1136 // enabled the services and touch exploration which means the she has
1137 // given consent to have these services work in touch exploration mode.
Christopher Tate06efb532012-08-24 15:29:27 -07001138 final boolean accessibilityEnabled = getIntValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001139 Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;
Christopher Tate06efb532012-08-24 15:29:27 -07001140 final boolean touchExplorationEnabled = getIntValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001141 Settings.Secure.TOUCH_EXPLORATION_ENABLED, 0) == 1;
1142 if (accessibilityEnabled && touchExplorationEnabled) {
Christopher Tate06efb532012-08-24 15:29:27 -07001143 String enabledServices = getStringValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001144 Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "");
Christopher Tate06efb532012-08-24 15:29:27 -07001145 String touchExplorationGrantedServices = getStringValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001146 Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, "");
1147 if (TextUtils.isEmpty(touchExplorationGrantedServices)
1148 && !TextUtils.isEmpty(enabledServices)) {
1149 SQLiteStatement stmt = null;
1150 try {
1151 db.beginTransaction();
1152 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1153 + " VALUES(?,?);");
1154 loadSetting(stmt,
1155 Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES,
1156 enabledServices);
1157 db.setTransactionSuccessful();
1158 } finally {
1159 db.endTransaction();
1160 if (stmt != null) stmt.close();
1161 }
1162 }
1163 }
1164 upgradeVersion = 80;
1165 }
1166
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001167 // vvv Jelly Bean MR1 changes begin here vvv
1168
Svetoslav Ganovca34bcf2012-08-16 12:22:23 -07001169 if (upgradeVersion == 80) {
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001170 // update screensaver settings
1171 db.beginTransaction();
1172 SQLiteStatement stmt = null;
1173 try {
1174 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1175 + " VALUES(?,?);");
1176 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED,
John Spurlocked108f32012-10-18 16:49:24 -04001177 com.android.internal.R.bool.config_dreamsEnabledByDefault);
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001178 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
John Spurlocked108f32012-10-18 16:49:24 -04001179 com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04001180 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
John Spurlocked108f32012-10-18 16:49:24 -04001181 com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04001182 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_COMPONENTS,
John Spurlocked108f32012-10-18 16:49:24 -04001183 com.android.internal.R.string.config_dreamsDefaultComponent);
1184 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT,
1185 com.android.internal.R.string.config_dreamsDefaultComponent);
Christopher Tate06efb532012-08-24 15:29:27 -07001186
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001187 db.setTransactionSuccessful();
1188 } finally {
1189 db.endTransaction();
1190 if (stmt != null) stmt.close();
1191 }
Svetoslav Ganovca34bcf2012-08-16 12:22:23 -07001192 upgradeVersion = 81;
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001193 }
1194
rich cannings16e119e2012-09-06 12:04:37 -07001195 if (upgradeVersion == 81) {
1196 // Add package verification setting
1197 db.beginTransaction();
1198 SQLiteStatement stmt = null;
1199 try {
1200 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1201 + " VALUES(?,?);");
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001202 loadBooleanSetting(stmt, Settings.Global.PACKAGE_VERIFIER_ENABLE,
rich cannings16e119e2012-09-06 12:04:37 -07001203 R.bool.def_package_verifier_enable);
1204 db.setTransactionSuccessful();
1205 } finally {
1206 db.endTransaction();
1207 if (stmt != null) stmt.close();
1208 }
1209 upgradeVersion = 82;
1210 }
1211
Christopher Tate06efb532012-08-24 15:29:27 -07001212 if (upgradeVersion == 82) {
1213 // Move to per-user settings dbs
Christopher Tate59c5bee2012-09-13 14:38:33 -07001214 if (mUserHandle == UserHandle.USER_OWNER) {
Christopher Tate06efb532012-08-24 15:29:27 -07001215
Christopher Tate59c5bee2012-09-13 14:38:33 -07001216 db.beginTransaction();
1217 SQLiteStatement stmt = null;
1218 try {
1219 // Migrate now-global settings. Note that this happens before
1220 // new users can be created.
1221 createGlobalTable(db);
1222 String[] settingsToMove = hashsetToStringArray(SettingsProvider.sSystemGlobalKeys);
1223 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, false);
1224 settingsToMove = hashsetToStringArray(SettingsProvider.sSecureGlobalKeys);
1225 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, false);
1226
1227 db.setTransactionSuccessful();
1228 } finally {
1229 db.endTransaction();
1230 if (stmt != null) stmt.close();
1231 }
Christopher Tate06efb532012-08-24 15:29:27 -07001232 }
1233 upgradeVersion = 83;
1234 }
1235
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001236 if (upgradeVersion == 83) {
1237 // 1. Setting whether screen magnification is enabled.
1238 // 2. Setting for screen magnification scale.
1239 // 3. Setting for screen magnification auto update.
1240 db.beginTransaction();
1241 SQLiteStatement stmt = null;
1242 try {
1243 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
1244 loadBooleanSetting(stmt,
1245 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
1246 R.bool.def_accessibility_display_magnification_enabled);
1247 stmt.close();
1248 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
1249 loadFractionSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
1250 R.fraction.def_accessibility_display_magnification_scale, 1);
1251 stmt.close();
1252 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
1253 loadBooleanSetting(stmt,
1254 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_AUTO_UPDATE,
1255 R.bool.def_accessibility_display_magnification_auto_update);
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001256
1257 db.setTransactionSuccessful();
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001258 } finally {
1259 db.endTransaction();
1260 if (stmt != null) stmt.close();
1261 }
1262 upgradeVersion = 84;
1263 }
1264
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001265 if (upgradeVersion == 84) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001266 if (mUserHandle == UserHandle.USER_OWNER) {
1267 db.beginTransaction();
1268 SQLiteStatement stmt = null;
1269 try {
1270 // Patch up the slightly-wrong key migration from 82 -> 83 for those
1271 // devices that missed it, ignoring if the move is redundant
1272 String[] settingsToMove = {
1273 Settings.Secure.ADB_ENABLED,
1274 Settings.Secure.BLUETOOTH_ON,
1275 Settings.Secure.DATA_ROAMING,
1276 Settings.Secure.DEVICE_PROVISIONED,
1277 Settings.Secure.INSTALL_NON_MARKET_APPS,
1278 Settings.Secure.USB_MASS_STORAGE_ENABLED
1279 };
1280 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1281 db.setTransactionSuccessful();
1282 } finally {
1283 db.endTransaction();
1284 if (stmt != null) stmt.close();
1285 }
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001286 }
1287 upgradeVersion = 85;
1288 }
1289
Christopher Tate92198742012-09-07 12:00:13 -07001290 if (upgradeVersion == 85) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001291 if (mUserHandle == UserHandle.USER_OWNER) {
1292 db.beginTransaction();
1293 try {
1294 // Fix up the migration, ignoring already-migrated elements, to snap up to
1295 // date with new changes to the set of global versus system/secure settings
1296 String[] settingsToMove = { Settings.System.STAY_ON_WHILE_PLUGGED_IN };
1297 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
Christopher Tate92198742012-09-07 12:00:13 -07001298
Christopher Tate59c5bee2012-09-13 14:38:33 -07001299 db.setTransactionSuccessful();
1300 } finally {
1301 db.endTransaction();
1302 }
Christopher Tate92198742012-09-07 12:00:13 -07001303 }
1304 upgradeVersion = 86;
1305 }
1306
rich cannings4d8fc792012-09-07 14:43:43 -07001307 if (upgradeVersion == 86) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001308 if (mUserHandle == UserHandle.USER_OWNER) {
1309 db.beginTransaction();
1310 try {
1311 String[] settingsToMove = {
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001312 Settings.Global.PACKAGE_VERIFIER_ENABLE,
1313 Settings.Global.PACKAGE_VERIFIER_TIMEOUT,
1314 Settings.Global.PACKAGE_VERIFIER_DEFAULT_RESPONSE
Christopher Tate59c5bee2012-09-13 14:38:33 -07001315 };
1316 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
rich cannings4d8fc792012-09-07 14:43:43 -07001317
Christopher Tate59c5bee2012-09-13 14:38:33 -07001318 db.setTransactionSuccessful();
1319 } finally {
1320 db.endTransaction();
1321 }
rich cannings4d8fc792012-09-07 14:43:43 -07001322 }
1323 upgradeVersion = 87;
1324 }
1325
Christopher Tatec868b642012-09-12 17:41:04 -07001326 if (upgradeVersion == 87) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001327 if (mUserHandle == UserHandle.USER_OWNER) {
1328 db.beginTransaction();
1329 try {
1330 String[] settingsToMove = {
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001331 Settings.Global.DATA_STALL_ALARM_NON_AGGRESSIVE_DELAY_IN_MS,
1332 Settings.Global.DATA_STALL_ALARM_AGGRESSIVE_DELAY_IN_MS,
1333 Settings.Global.GPRS_REGISTER_CHECK_PERIOD_MS
Christopher Tate59c5bee2012-09-13 14:38:33 -07001334 };
1335 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
Christopher Tatec868b642012-09-12 17:41:04 -07001336
Christopher Tate59c5bee2012-09-13 14:38:33 -07001337 db.setTransactionSuccessful();
1338 } finally {
1339 db.endTransaction();
1340 }
Christopher Tatec868b642012-09-12 17:41:04 -07001341 }
1342 upgradeVersion = 88;
1343 }
1344
Jeff Sharkey625239a2012-09-26 22:03:49 -07001345 if (upgradeVersion == 88) {
1346 if (mUserHandle == UserHandle.USER_OWNER) {
1347 db.beginTransaction();
1348 try {
1349 String[] settingsToMove = {
1350 Settings.Global.BATTERY_DISCHARGE_DURATION_THRESHOLD,
1351 Settings.Global.BATTERY_DISCHARGE_THRESHOLD,
1352 Settings.Global.SEND_ACTION_APP_ERROR,
1353 Settings.Global.DROPBOX_AGE_SECONDS,
1354 Settings.Global.DROPBOX_MAX_FILES,
1355 Settings.Global.DROPBOX_QUOTA_KB,
1356 Settings.Global.DROPBOX_QUOTA_PERCENT,
1357 Settings.Global.DROPBOX_RESERVE_PERCENT,
1358 Settings.Global.DROPBOX_TAG_PREFIX,
1359 Settings.Global.ERROR_LOGCAT_PREFIX,
1360 Settings.Global.SYS_FREE_STORAGE_LOG_INTERVAL,
1361 Settings.Global.DISK_FREE_CHANGE_REPORTING_THRESHOLD,
1362 Settings.Global.SYS_STORAGE_THRESHOLD_PERCENTAGE,
1363 Settings.Global.SYS_STORAGE_THRESHOLD_MAX_BYTES,
1364 Settings.Global.SYS_STORAGE_FULL_THRESHOLD_BYTES,
1365 Settings.Global.SYNC_MAX_RETRY_DELAY_IN_SECONDS,
1366 Settings.Global.CONNECTIVITY_CHANGE_DELAY,
1367 Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED,
1368 Settings.Global.CAPTIVE_PORTAL_SERVER,
1369 Settings.Global.NSD_ON,
1370 Settings.Global.SET_INSTALL_LOCATION,
1371 Settings.Global.DEFAULT_INSTALL_LOCATION,
1372 Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY,
1373 Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY,
1374 Settings.Global.READ_EXTERNAL_STORAGE_ENFORCED_DEFAULT,
1375 Settings.Global.HTTP_PROXY,
1376 Settings.Global.GLOBAL_HTTP_PROXY_HOST,
1377 Settings.Global.GLOBAL_HTTP_PROXY_PORT,
1378 Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST,
1379 Settings.Global.SET_GLOBAL_HTTP_PROXY,
1380 Settings.Global.DEFAULT_DNS_SERVER,
1381 };
1382 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1383 db.setTransactionSuccessful();
1384 } finally {
1385 db.endTransaction();
1386 }
1387 }
1388 upgradeVersion = 89;
1389 }
1390
Jeff Sharkey0ac10282012-10-01 12:50:22 -07001391 if (upgradeVersion == 89) {
1392 if (mUserHandle == UserHandle.USER_OWNER) {
1393 db.beginTransaction();
1394 try {
1395 String[] prefixesToMove = {
1396 Settings.Global.BLUETOOTH_HEADSET_PRIORITY_PREFIX,
1397 Settings.Global.BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX,
1398 Settings.Global.BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX,
1399 };
1400
1401 movePrefixedSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, prefixesToMove);
1402
1403 db.setTransactionSuccessful();
1404 } finally {
1405 db.endTransaction();
1406 }
1407 }
1408 upgradeVersion = 90;
1409 }
1410
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001411 if (upgradeVersion == 90) {
1412 if (mUserHandle == UserHandle.USER_OWNER) {
1413 db.beginTransaction();
1414 try {
1415 String[] systemToGlobal = {
1416 Settings.Global.WINDOW_ANIMATION_SCALE,
1417 Settings.Global.TRANSITION_ANIMATION_SCALE,
1418 Settings.Global.ANIMATOR_DURATION_SCALE,
1419 Settings.Global.FANCY_IME_ANIMATIONS,
1420 Settings.Global.COMPATIBILITY_MODE,
1421 Settings.Global.EMERGENCY_TONE,
1422 Settings.Global.CALL_AUTO_RETRY,
1423 Settings.Global.DEBUG_APP,
1424 Settings.Global.WAIT_FOR_DEBUGGER,
1425 Settings.Global.SHOW_PROCESSES,
1426 Settings.Global.ALWAYS_FINISH_ACTIVITIES,
1427 };
1428 String[] secureToGlobal = {
1429 Settings.Global.PREFERRED_NETWORK_MODE,
Naveen Kallab4d485c2013-07-03 16:39:27 -07001430 Settings.Global.CDMA_SUBSCRIPTION_MODE,
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001431 };
1432
1433 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, systemToGlobal, true);
1434 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, secureToGlobal, true);
1435
1436 db.setTransactionSuccessful();
1437 } finally {
1438 db.endTransaction();
1439 }
1440 }
1441 upgradeVersion = 91;
1442 }
1443
Eric Laurent55b02222012-10-03 11:56:23 -07001444 if (upgradeVersion == 91) {
1445 if (mUserHandle == UserHandle.USER_OWNER) {
1446 db.beginTransaction();
1447 try {
1448 // Move ringer mode from system to global settings
Amith Yamasani531c2372012-10-08 14:43:20 -07001449 String[] settingsToMove = { Settings.Global.MODE_RINGER };
Eric Laurent55b02222012-10-03 11:56:23 -07001450 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
1451
1452 db.setTransactionSuccessful();
1453 } finally {
1454 db.endTransaction();
1455 }
1456 }
1457 upgradeVersion = 92;
1458 }
1459
John Spurlock7f1c2482012-10-05 11:15:28 -04001460 if (upgradeVersion == 92) {
1461 SQLiteStatement stmt = null;
1462 try {
1463 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1464 + " VALUES(?,?);");
1465 if (mUserHandle == UserHandle.USER_OWNER) {
1466 // consider existing primary users to have made it through user setup
1467 // if the globally-scoped device-provisioned bit is set
1468 // (indicating they already made it through setup as primary)
1469 int deviceProvisioned = getIntValueFromTable(db, TABLE_GLOBAL,
1470 Settings.Global.DEVICE_PROVISIONED, 0);
1471 loadSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
1472 deviceProvisioned);
1473 } else {
1474 // otherwise use the default
1475 loadBooleanSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
1476 R.bool.def_user_setup_complete);
1477 }
1478 } finally {
1479 if (stmt != null) stmt.close();
1480 }
1481 upgradeVersion = 93;
1482 }
1483
Amith Yamasani531c2372012-10-08 14:43:20 -07001484 if (upgradeVersion == 93) {
1485 // Redo this step, since somehow it didn't work the first time for some users
1486 if (mUserHandle == UserHandle.USER_OWNER) {
1487 db.beginTransaction();
Amith Yamasani531c2372012-10-08 14:43:20 -07001488 try {
1489 // Migrate now-global settings
1490 String[] settingsToMove = hashsetToStringArray(SettingsProvider.sSystemGlobalKeys);
1491 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
1492 settingsToMove = hashsetToStringArray(SettingsProvider.sSecureGlobalKeys);
1493 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1494
1495 db.setTransactionSuccessful();
1496 } finally {
1497 db.endTransaction();
Amith Yamasani531c2372012-10-08 14:43:20 -07001498 }
1499 }
1500 upgradeVersion = 94;
1501 }
1502
Jeff Brown84e27562012-12-07 13:56:34 -08001503 if (upgradeVersion == 94) {
1504 // Add wireless charging started sound setting
Amith Yamasani2d43fab2012-12-12 09:52:26 -08001505 if (mUserHandle == UserHandle.USER_OWNER) {
1506 db.beginTransaction();
1507 SQLiteStatement stmt = null;
1508 try {
1509 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1510 + " VALUES(?,?);");
1511 loadStringSetting(stmt, Settings.Global.WIRELESS_CHARGING_STARTED_SOUND,
1512 R.string.def_wireless_charging_started_sound);
1513 db.setTransactionSuccessful();
1514 } finally {
1515 db.endTransaction();
1516 if (stmt != null) stmt.close();
1517 }
Jeff Brown84e27562012-12-07 13:56:34 -08001518 }
1519 upgradeVersion = 95;
1520 }
1521
Christopher Tate58f41ec2013-01-11 15:40:36 -08001522 if (upgradeVersion == 95) {
1523 if (mUserHandle == UserHandle.USER_OWNER) {
1524 db.beginTransaction();
1525 try {
1526 String[] settingsToMove = { Settings.Global.BUGREPORT_IN_POWER_MENU };
1527 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1528 db.setTransactionSuccessful();
1529 } finally {
1530 db.endTransaction();
1531 }
1532 }
1533 upgradeVersion = 96;
1534 }
1535
Mike Clerond1ed3ce2013-02-01 18:36:41 +00001536 if (upgradeVersion == 96) {
Svetoslav Ganov447d9462013-02-01 19:46:20 +00001537 // NOP bump due to a reverted change that some people got on upgrade.
Mike Clerond1ed3ce2013-02-01 18:36:41 +00001538 upgradeVersion = 97;
1539 }
1540
Daniel Sandlerdea64622013-09-23 16:05:57 -04001541 if (upgradeVersion == 97) {
1542 if (mUserHandle == UserHandle.USER_OWNER) {
1543 db.beginTransaction();
1544 SQLiteStatement stmt = null;
1545 try {
1546 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1547 + " VALUES(?,?);");
1548 loadIntegerSetting(stmt, Settings.Global.LOW_BATTERY_SOUND_TIMEOUT,
1549 R.integer.def_low_battery_sound_timeout);
1550 db.setTransactionSuccessful();
1551 } finally {
1552 db.endTransaction();
1553 if (stmt != null) stmt.close();
1554 }
1555 }
1556 upgradeVersion = 98;
1557 }
1558
Daniel Sandler1c7fa482010-03-10 09:45:01 -05001559 // *** Remember to update DATABASE_VERSION above!
1560
1561 if (upgradeVersion != currentVersion) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001562 Log.w(TAG, "Got stuck trying to upgrade from version " + upgradeVersion
1563 + ", must wipe the settings provider");
Christopher Tate06efb532012-08-24 15:29:27 -07001564 db.execSQL("DROP TABLE IF EXISTS global");
1565 db.execSQL("DROP TABLE IF EXISTS globalIndex1");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001566 db.execSQL("DROP TABLE IF EXISTS system");
1567 db.execSQL("DROP INDEX IF EXISTS systemIndex1");
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001568 db.execSQL("DROP TABLE IF EXISTS secure");
1569 db.execSQL("DROP INDEX IF EXISTS secureIndex1");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001570 db.execSQL("DROP TABLE IF EXISTS gservices");
1571 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1");
1572 db.execSQL("DROP TABLE IF EXISTS bluetooth_devices");
1573 db.execSQL("DROP TABLE IF EXISTS bookmarks");
1574 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex1");
1575 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex2");
1576 db.execSQL("DROP TABLE IF EXISTS favorites");
1577 onCreate(db);
Jim Miller61766772010-02-12 14:56:49 -08001578
1579 // Added for diagnosing settings.db wipes after the fact
1580 String wipeReason = oldVersion + "/" + upgradeVersion + "/" + currentVersion;
1581 db.execSQL("INSERT INTO secure(name,value) values('" +
1582 "wiped_db_reason" + "','" + wipeReason + "');");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001583 }
1584 }
1585
Christopher Tatea96798e42012-09-06 19:07:19 -07001586 private String[] hashsetToStringArray(HashSet<String> set) {
1587 String[] array = new String[set.size()];
1588 return set.toArray(array);
1589 }
1590
Christopher Tate06efb532012-08-24 15:29:27 -07001591 private void moveSettingsToNewTable(SQLiteDatabase db,
1592 String sourceTable, String destTable,
Christopher Tate92198742012-09-07 12:00:13 -07001593 String[] settingsToMove, boolean doIgnore) {
Christopher Tate06efb532012-08-24 15:29:27 -07001594 // Copy settings values from the source table to the dest, and remove from the source
Amith Yamasani156c4352010-03-05 17:10:03 -08001595 SQLiteStatement insertStmt = null;
1596 SQLiteStatement deleteStmt = null;
1597
1598 db.beginTransaction();
1599 try {
Christopher Tate92198742012-09-07 12:00:13 -07001600 insertStmt = db.compileStatement("INSERT "
1601 + (doIgnore ? " OR IGNORE " : "")
1602 + " INTO " + destTable + " (name,value) SELECT name,value FROM "
Christopher Tate06efb532012-08-24 15:29:27 -07001603 + sourceTable + " WHERE name=?");
1604 deleteStmt = db.compileStatement("DELETE FROM " + sourceTable + " WHERE name=?");
Amith Yamasani156c4352010-03-05 17:10:03 -08001605
1606 for (String setting : settingsToMove) {
1607 insertStmt.bindString(1, setting);
1608 insertStmt.execute();
1609
1610 deleteStmt.bindString(1, setting);
1611 deleteStmt.execute();
1612 }
1613 db.setTransactionSuccessful();
1614 } finally {
1615 db.endTransaction();
1616 if (insertStmt != null) {
1617 insertStmt.close();
1618 }
1619 if (deleteStmt != null) {
1620 deleteStmt.close();
1621 }
1622 }
1623 }
1624
Jeff Sharkey0ac10282012-10-01 12:50:22 -07001625 /**
1626 * Move any settings with the given prefixes from the source table to the
1627 * destination table.
1628 */
1629 private void movePrefixedSettingsToNewTable(
1630 SQLiteDatabase db, String sourceTable, String destTable, String[] prefixesToMove) {
1631 SQLiteStatement insertStmt = null;
1632 SQLiteStatement deleteStmt = null;
1633
1634 db.beginTransaction();
1635 try {
1636 insertStmt = db.compileStatement("INSERT INTO " + destTable
1637 + " (name,value) SELECT name,value FROM " + sourceTable
1638 + " WHERE substr(name,0,?)=?");
1639 deleteStmt = db.compileStatement(
1640 "DELETE FROM " + sourceTable + " WHERE substr(name,0,?)=?");
1641
1642 for (String prefix : prefixesToMove) {
1643 insertStmt.bindLong(1, prefix.length() + 1);
1644 insertStmt.bindString(2, prefix);
1645 insertStmt.execute();
1646
1647 deleteStmt.bindLong(1, prefix.length() + 1);
1648 deleteStmt.bindString(2, prefix);
1649 deleteStmt.execute();
1650 }
1651 db.setTransactionSuccessful();
1652 } finally {
1653 db.endTransaction();
1654 if (insertStmt != null) {
1655 insertStmt.close();
1656 }
1657 if (deleteStmt != null) {
1658 deleteStmt.close();
1659 }
1660 }
1661 }
1662
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001663 private void upgradeLockPatternLocation(SQLiteDatabase db) {
Christopher Tate06efb532012-08-24 15:29:27 -07001664 Cursor c = db.query(TABLE_SYSTEM, new String[] {"_id", "value"}, "name='lock_pattern'",
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001665 null, null, null, null);
1666 if (c.getCount() > 0) {
1667 c.moveToFirst();
1668 String lockPattern = c.getString(1);
1669 if (!TextUtils.isEmpty(lockPattern)) {
1670 // Convert lock pattern
1671 try {
Jim Miller31f90b62010-01-20 13:35:20 -08001672 LockPatternUtils lpu = new LockPatternUtils(mContext);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07001673 List<LockPatternView.Cell> cellPattern =
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001674 LockPatternUtils.stringToPattern(lockPattern);
1675 lpu.saveLockPattern(cellPattern);
1676 } catch (IllegalArgumentException e) {
1677 // Don't want corrupted lock pattern to hang the reboot process
1678 }
1679 }
1680 c.close();
Christopher Tate06efb532012-08-24 15:29:27 -07001681 db.delete(TABLE_SYSTEM, "name='lock_pattern'", null);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001682 } else {
1683 c.close();
1684 }
1685 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001686
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07001687 private void upgradeScreenTimeoutFromNever(SQLiteDatabase db) {
1688 // See if the timeout is -1 (for "Never").
Christopher Tate06efb532012-08-24 15:29:27 -07001689 Cursor c = db.query(TABLE_SYSTEM, new String[] { "_id", "value" }, "name=? AND value=?",
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07001690 new String[] { Settings.System.SCREEN_OFF_TIMEOUT, "-1" },
1691 null, null, null);
1692
1693 SQLiteStatement stmt = null;
1694 if (c.getCount() > 0) {
1695 c.close();
1696 try {
1697 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1698 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001699
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07001700 // Set the timeout to 30 minutes in milliseconds
Amith Yamasanicd66caf2010-04-12 15:49:12 -07001701 loadSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
1702 Integer.toString(30 * 60 * 1000));
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07001703 } finally {
1704 if (stmt != null) stmt.close();
1705 }
1706 } else {
1707 c.close();
1708 }
1709 }
1710
Amith Yamasani398c83c2011-12-13 10:38:47 -08001711 private void upgradeVibrateSettingFromNone(SQLiteDatabase db) {
1712 int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON, 0);
1713 // If the ringer vibrate value is invalid, set it to the default
1714 if ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_OFF) {
1715 vibrateSetting = AudioService.getValueForVibrateSetting(0,
1716 AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
1717 }
1718 // Apply the same setting to the notification vibrate value
1719 vibrateSetting = AudioService.getValueForVibrateSetting(vibrateSetting,
1720 AudioManager.VIBRATE_TYPE_NOTIFICATION, vibrateSetting);
1721
1722 SQLiteStatement stmt = null;
1723 try {
1724 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1725 + " VALUES(?,?);");
1726 loadSetting(stmt, Settings.System.VIBRATE_ON, vibrateSetting);
1727 } finally {
1728 if (stmt != null)
1729 stmt.close();
1730 }
1731 }
1732
Amith Yamasani79373f62010-11-18 16:32:48 -08001733 private void upgradeScreenTimeout(SQLiteDatabase db) {
1734 // Change screen timeout to current default
1735 db.beginTransaction();
1736 SQLiteStatement stmt = null;
1737 try {
1738 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1739 + " VALUES(?,?);");
1740 loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
1741 R.integer.def_screen_off_timeout);
1742 db.setTransactionSuccessful();
1743 } finally {
1744 db.endTransaction();
1745 if (stmt != null)
1746 stmt.close();
1747 }
1748 }
1749
Amith Yamasanif50c5112011-01-07 11:32:30 -08001750 private void upgradeAutoBrightness(SQLiteDatabase db) {
1751 db.beginTransaction();
1752 try {
1753 String value =
1754 mContext.getResources().getBoolean(
1755 R.bool.def_screen_brightness_automatic_mode) ? "1" : "0";
1756 db.execSQL("INSERT OR REPLACE INTO system(name,value) values('" +
1757 Settings.System.SCREEN_BRIGHTNESS_MODE + "','" + value + "');");
1758 db.setTransactionSuccessful();
1759 } finally {
1760 db.endTransaction();
1761 }
1762 }
1763
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001764 /**
1765 * Loads the default set of bookmarked shortcuts from an xml file.
1766 *
1767 * @param db The database to write the values into
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001768 */
Jeff Brown6651a632011-11-28 12:59:11 -08001769 private void loadBookmarks(SQLiteDatabase db) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001770 ContentValues values = new ContentValues();
1771
1772 PackageManager packageManager = mContext.getPackageManager();
Romain Guyf02811f2010-03-09 16:33:51 -08001773 try {
1774 XmlResourceParser parser = mContext.getResources().getXml(R.xml.bookmarks);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001775 XmlUtils.beginDocument(parser, "bookmarks");
1776
Romain Guyf02811f2010-03-09 16:33:51 -08001777 final int depth = parser.getDepth();
1778 int type;
1779
1780 while (((type = parser.next()) != XmlPullParser.END_TAG ||
1781 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
1782
1783 if (type != XmlPullParser.START_TAG) {
1784 continue;
1785 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001786
1787 String name = parser.getName();
1788 if (!"bookmark".equals(name)) {
1789 break;
1790 }
1791
1792 String pkg = parser.getAttributeValue(null, "package");
1793 String cls = parser.getAttributeValue(null, "class");
1794 String shortcutStr = parser.getAttributeValue(null, "shortcut");
Jeff Brown6651a632011-11-28 12:59:11 -08001795 String category = parser.getAttributeValue(null, "category");
Romain Guyf02811f2010-03-09 16:33:51 -08001796
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -07001797 int shortcutValue = shortcutStr.charAt(0);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001798 if (TextUtils.isEmpty(shortcutStr)) {
1799 Log.w(TAG, "Unable to get shortcut for: " + pkg + "/" + cls);
Jeff Brown6651a632011-11-28 12:59:11 -08001800 continue;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001801 }
Romain Guyf02811f2010-03-09 16:33:51 -08001802
Jeff Brown6651a632011-11-28 12:59:11 -08001803 final Intent intent;
1804 final String title;
1805 if (pkg != null && cls != null) {
1806 ActivityInfo info = null;
1807 ComponentName cn = new ComponentName(pkg, cls);
Romain Guyf02811f2010-03-09 16:33:51 -08001808 try {
1809 info = packageManager.getActivityInfo(cn, 0);
Jeff Brown6651a632011-11-28 12:59:11 -08001810 } catch (PackageManager.NameNotFoundException e) {
1811 String[] packages = packageManager.canonicalToCurrentPackageNames(
1812 new String[] { pkg });
1813 cn = new ComponentName(packages[0], cls);
1814 try {
1815 info = packageManager.getActivityInfo(cn, 0);
1816 } catch (PackageManager.NameNotFoundException e1) {
1817 Log.w(TAG, "Unable to add bookmark: " + pkg + "/" + cls, e);
1818 continue;
1819 }
Romain Guyf02811f2010-03-09 16:33:51 -08001820 }
Jeff Brown6651a632011-11-28 12:59:11 -08001821
1822 intent = new Intent(Intent.ACTION_MAIN, null);
1823 intent.addCategory(Intent.CATEGORY_LAUNCHER);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001824 intent.setComponent(cn);
Jeff Brown6651a632011-11-28 12:59:11 -08001825 title = info.loadLabel(packageManager).toString();
1826 } else if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08001827 intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08001828 title = "";
1829 } else {
1830 Log.w(TAG, "Unable to add bookmark for shortcut " + shortcutStr
1831 + ": missing package/class or category attributes");
1832 continue;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001833 }
Jeff Brown6651a632011-11-28 12:59:11 -08001834
1835 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1836 values.put(Settings.Bookmarks.INTENT, intent.toUri(0));
1837 values.put(Settings.Bookmarks.TITLE, title);
1838 values.put(Settings.Bookmarks.SHORTCUT, shortcutValue);
1839 db.delete("bookmarks", "shortcut = ?",
1840 new String[] { Integer.toString(shortcutValue) });
1841 db.insert("bookmarks", null, values);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001842 }
1843 } catch (XmlPullParserException e) {
1844 Log.w(TAG, "Got execption parsing bookmarks.", e);
1845 } catch (IOException e) {
1846 Log.w(TAG, "Got execption parsing bookmarks.", e);
1847 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001848 }
1849
1850 /**
1851 * Loads the default volume levels. It is actually inserting the index of
1852 * the volume array for each of the volume controls.
1853 *
1854 * @param db the database to insert the volume levels into
1855 */
1856 private void loadVolumeLevels(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07001857 SQLiteStatement stmt = null;
1858 try {
1859 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
1860 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001861
Vasu Nori89206fdb2010-03-22 10:37:03 -07001862 loadSetting(stmt, Settings.System.VOLUME_MUSIC,
1863 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_MUSIC]);
1864 loadSetting(stmt, Settings.System.VOLUME_RING,
1865 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_RING]);
1866 loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
1867 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_SYSTEM]);
1868 loadSetting(
1869 stmt,
1870 Settings.System.VOLUME_VOICE,
1871 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_VOICE_CALL]);
1872 loadSetting(stmt, Settings.System.VOLUME_ALARM,
1873 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_ALARM]);
1874 loadSetting(
1875 stmt,
1876 Settings.System.VOLUME_NOTIFICATION,
1877 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_NOTIFICATION]);
1878 loadSetting(
1879 stmt,
1880 Settings.System.VOLUME_BLUETOOTH_SCO,
1881 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_BLUETOOTH_SCO]);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001882
Eric Laurentc1d41662011-07-19 11:21:13 -07001883 // By default:
1884 // - ringtones, notification, system and music streams are affected by ringer mode
1885 // on non voice capable devices (tablets)
1886 // - ringtones, notification and system streams are affected by ringer mode
1887 // on voice capable devices (phones)
1888 int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
1889 (1 << AudioManager.STREAM_NOTIFICATION) |
1890 (1 << AudioManager.STREAM_SYSTEM) |
1891 (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
1892 if (!mContext.getResources().getBoolean(
1893 com.android.internal.R.bool.config_voice_capable)) {
1894 ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
1895 }
Vasu Nori89206fdb2010-03-22 10:37:03 -07001896 loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
Eric Laurentc1d41662011-07-19 11:21:13 -07001897 ringerModeAffectedStreams);
1898
Vasu Nori89206fdb2010-03-22 10:37:03 -07001899 loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
1900 ((1 << AudioManager.STREAM_MUSIC) |
1901 (1 << AudioManager.STREAM_RING) |
1902 (1 << AudioManager.STREAM_NOTIFICATION) |
1903 (1 << AudioManager.STREAM_SYSTEM)));
1904 } finally {
1905 if (stmt != null) stmt.close();
1906 }
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001907
1908 loadVibrateWhenRingingSetting(db);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001909 }
1910
1911 private void loadVibrateSetting(SQLiteDatabase db, boolean deleteOld) {
1912 if (deleteOld) {
1913 db.execSQL("DELETE FROM system WHERE name='" + Settings.System.VIBRATE_ON + "'");
1914 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07001915
Vasu Nori89206fdb2010-03-22 10:37:03 -07001916 SQLiteStatement stmt = null;
1917 try {
1918 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
1919 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001920
Amith Yamasani5cd15002011-11-16 11:19:48 -08001921 // Vibrate on by default for ringer, on for notification
Vasu Nori89206fdb2010-03-22 10:37:03 -07001922 int vibrate = 0;
1923 vibrate = AudioService.getValueForVibrateSetting(vibrate,
Amith Yamasani5cd15002011-11-16 11:19:48 -08001924 AudioManager.VIBRATE_TYPE_NOTIFICATION,
1925 AudioManager.VIBRATE_SETTING_ONLY_SILENT);
Joe Onorato89320202010-06-24 17:49:44 -07001926 vibrate |= AudioService.getValueForVibrateSetting(vibrate,
Amith Yamasani5cd15002011-11-16 11:19:48 -08001927 AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
Vasu Nori89206fdb2010-03-22 10:37:03 -07001928 loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate);
1929 } finally {
1930 if (stmt != null) stmt.close();
1931 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001932 }
1933
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001934 private void loadVibrateWhenRingingSetting(SQLiteDatabase db) {
1935 // The default should be off. VIBRATE_SETTING_ONLY_SILENT should also be ignored here.
1936 // Phone app should separately check whether AudioManager#getRingerMode() returns
1937 // RINGER_MODE_VIBRATE, with which the device should vibrate anyway.
1938 int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON,
1939 AudioManager.VIBRATE_SETTING_OFF);
1940 boolean vibrateWhenRinging = ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_ON);
1941
1942 SQLiteStatement stmt = null;
1943 try {
1944 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
1945 + " VALUES(?,?);");
1946 loadSetting(stmt, Settings.System.VIBRATE_WHEN_RINGING, vibrateWhenRinging ? 1 : 0);
1947 } finally {
1948 if (stmt != null) stmt.close();
1949 }
1950 }
1951
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001952 private void loadSettings(SQLiteDatabase db) {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001953 loadSystemSettings(db);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07001954 loadSecureSettings(db);
Christopher Tate06efb532012-08-24 15:29:27 -07001955 // The global table only exists for the 'owner' user
1956 if (mUserHandle == UserHandle.USER_OWNER) {
1957 loadGlobalSettings(db);
1958 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001959 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07001960
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001961 private void loadSystemSettings(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07001962 SQLiteStatement stmt = null;
1963 try {
1964 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
1965 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001966
Vasu Nori89206fdb2010-03-22 10:37:03 -07001967 loadBooleanSetting(stmt, Settings.System.DIM_SCREEN,
1968 R.bool.def_dim_screen);
Vasu Nori89206fdb2010-03-22 10:37:03 -07001969 loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
1970 R.integer.def_screen_off_timeout);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001971
Vasu Nori89206fdb2010-03-22 10:37:03 -07001972 // Set default cdma DTMF type
1973 loadSetting(stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001974
Vasu Nori89206fdb2010-03-22 10:37:03 -07001975 // Set default hearing aid
1976 loadSetting(stmt, Settings.System.HEARING_AID, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001977
Vasu Nori89206fdb2010-03-22 10:37:03 -07001978 // Set default tty mode
1979 loadSetting(stmt, Settings.System.TTY_MODE, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001980
Vasu Nori89206fdb2010-03-22 10:37:03 -07001981 loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS,
1982 R.integer.def_screen_brightness);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001983
Vasu Nori89206fdb2010-03-22 10:37:03 -07001984 loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE,
1985 R.bool.def_screen_brightness_automatic_mode);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001986
Vasu Nori89206fdb2010-03-22 10:37:03 -07001987 loadDefaultAnimationSettings(stmt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001988
Vasu Nori89206fdb2010-03-22 10:37:03 -07001989 loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION,
1990 R.bool.def_accelerometer_rotation);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001991
Vasu Nori89206fdb2010-03-22 10:37:03 -07001992 loadDefaultHapticSettings(stmt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001993
Vasu Nori89206fdb2010-03-22 10:37:03 -07001994 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
1995 R.bool.def_notification_pulse);
Amith Yamasani42722bf2011-07-22 10:34:27 -07001996
Vasu Nori89206fdb2010-03-22 10:37:03 -07001997 loadUISoundEffectsSettings(stmt);
Amith Yamasani42722bf2011-07-22 10:34:27 -07001998
Jeff Brown1a84fd12011-06-02 01:26:32 -07001999 loadIntegerSetting(stmt, Settings.System.POINTER_SPEED,
2000 R.integer.def_pointer_speed);
Vasu Nori89206fdb2010-03-22 10:37:03 -07002001 } finally {
2002 if (stmt != null) stmt.close();
2003 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002004 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002005
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002006 private void loadUISoundEffectsSettings(SQLiteStatement stmt) {
Amith Yamasani42722bf2011-07-22 10:34:27 -07002007 loadBooleanSetting(stmt, Settings.System.DTMF_TONE_WHEN_DIALING,
2008 R.bool.def_dtmf_tones_enabled);
2009 loadBooleanSetting(stmt, Settings.System.SOUND_EFFECTS_ENABLED,
2010 R.bool.def_sound_effects_enabled);
2011 loadBooleanSetting(stmt, Settings.System.HAPTIC_FEEDBACK_ENABLED,
2012 R.bool.def_haptic_feedback);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002013
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002014 loadIntegerSetting(stmt, Settings.System.LOCKSCREEN_SOUNDS_ENABLED,
2015 R.integer.def_lockscreen_sounds_enabled);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002016 }
2017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 private void loadDefaultAnimationSettings(SQLiteStatement stmt) {
2019 loadFractionSetting(stmt, Settings.System.WINDOW_ANIMATION_SCALE,
2020 R.fraction.def_window_animation_scale, 1);
2021 loadFractionSetting(stmt, Settings.System.TRANSITION_ANIMATION_SCALE,
2022 R.fraction.def_window_transition_scale, 1);
2023 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002024
Dianne Hackborn075a18d2009-09-26 12:43:19 -07002025 private void loadDefaultHapticSettings(SQLiteStatement stmt) {
2026 loadBooleanSetting(stmt, Settings.System.HAPTIC_FEEDBACK_ENABLED,
2027 R.bool.def_haptic_feedback);
2028 }
2029
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002030 private void loadSecureSettings(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07002031 SQLiteStatement stmt = null;
2032 try {
2033 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
2034 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002035
Vasu Nori89206fdb2010-03-22 10:37:03 -07002036 loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
2037 R.string.def_location_providers_allowed);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002038
Vasu Nori89206fdb2010-03-22 10:37:03 -07002039 String wifiWatchList = SystemProperties.get("ro.com.android.wifi-watchlist");
2040 if (!TextUtils.isEmpty(wifiWatchList)) {
2041 loadSetting(stmt, Settings.Secure.WIFI_WATCHDOG_WATCH_LIST, wifiWatchList);
2042 }
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002043
Vasu Nori89206fdb2010-03-22 10:37:03 -07002044 // Don't do this. The SystemServer will initialize ADB_ENABLED from a
2045 // persistent system property instead.
2046 //loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002047
Vasu Nori89206fdb2010-03-22 10:37:03 -07002048 // Allow mock locations default, based on build
2049 loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION,
2050 "1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002051
Vasu Nori89206fdb2010-03-22 10:37:03 -07002052 loadSecure35Settings(stmt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002053
Vasu Nori89206fdb2010-03-22 10:37:03 -07002054 loadBooleanSetting(stmt, Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND,
2055 R.bool.def_mount_play_notification_snd);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002056
Vasu Nori89206fdb2010-03-22 10:37:03 -07002057 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_AUTOSTART,
2058 R.bool.def_mount_ums_autostart);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002059
Vasu Nori89206fdb2010-03-22 10:37:03 -07002060 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_PROMPT,
2061 R.bool.def_mount_ums_prompt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002062
Vasu Nori89206fdb2010-03-22 10:37:03 -07002063 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED,
2064 R.bool.def_mount_ums_notify_enabled);
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -07002065
2066 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION,
2067 R.bool.def_accessibility_script_injection);
2068
2069 loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS,
2070 R.string.def_accessibility_web_content_key_bindings);
Paul Westbrookd99d0dc2011-02-01 14:26:16 -08002071
Svetoslav Ganov54d068e2011-03-02 12:58:40 -08002072 loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT,
2073 R.integer.def_long_press_timeout_millis);
Svetoslav Ganova28a16d2011-07-28 11:24:21 -07002074
2075 loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED,
2076 R.bool.def_touch_exploration_enabled);
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08002077
2078 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD,
2079 R.bool.def_accessibility_speak_password);
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08002080
2081 loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_SCREEN_READER_URL,
2082 R.string.def_accessibility_screen_reader_url);
Mike Lockwood86aeb062011-10-21 13:29:58 -04002083
Amith Yamasanid1645f82012-06-12 11:53:26 -07002084 if (SystemProperties.getBoolean("ro.lockscreen.disable.default", false) == true) {
2085 loadSetting(stmt, Settings.System.LOCKSCREEN_DISABLED, "1");
2086 } else {
2087 loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED,
2088 R.bool.def_lockscreen_disabled);
2089 }
Mike Lockwood23955272011-10-21 11:22:48 -04002090
John Spurlock634471e2012-08-09 10:41:37 -04002091 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED,
John Spurlocked108f32012-10-18 16:49:24 -04002092 com.android.internal.R.bool.config_dreamsEnabledByDefault);
John Spurlock634471e2012-08-09 10:41:37 -04002093 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
John Spurlocked108f32012-10-18 16:49:24 -04002094 com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04002095 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
John Spurlocked108f32012-10-18 16:49:24 -04002096 com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04002097 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_COMPONENTS,
John Spurlocked108f32012-10-18 16:49:24 -04002098 com.android.internal.R.string.config_dreamsDefaultComponent);
John Spurlock1a868b72012-08-22 09:56:51 -04002099 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT,
John Spurlocked108f32012-10-18 16:49:24 -04002100 com.android.internal.R.string.config_dreamsDefaultComponent);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07002101
2102 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
2103 R.bool.def_accessibility_display_magnification_enabled);
2104
2105 loadFractionSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
2106 R.fraction.def_accessibility_display_magnification_scale, 1);
2107
2108 loadBooleanSetting(stmt,
2109 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_AUTO_UPDATE,
2110 R.bool.def_accessibility_display_magnification_auto_update);
John Spurlock7f1c2482012-10-05 11:15:28 -04002111
2112 loadBooleanSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
2113 R.bool.def_user_setup_complete);
Mike Lockwoodc02c4a72014-01-07 14:46:22 -08002114
2115 loadStringSetting(stmt, Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS,
2116 R.string.def_immersive_mode_confirmations);
2117
Vasu Nori89206fdb2010-03-22 10:37:03 -07002118 } finally {
2119 if (stmt != null) stmt.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002121 }
2122
Dianne Hackborncf098292009-07-01 19:55:20 -07002123 private void loadSecure35Settings(SQLiteStatement stmt) {
2124 loadBooleanSetting(stmt, Settings.Secure.BACKUP_ENABLED,
2125 R.bool.def_backup_enabled);
Jim Miller31f90b62010-01-20 13:35:20 -08002126
Dianne Hackborncf098292009-07-01 19:55:20 -07002127 loadStringSetting(stmt, Settings.Secure.BACKUP_TRANSPORT,
2128 R.string.def_backup_transport);
2129 }
Jim Miller61766772010-02-12 14:56:49 -08002130
Christopher Tate06efb532012-08-24 15:29:27 -07002131 private void loadGlobalSettings(SQLiteDatabase db) {
2132 SQLiteStatement stmt = null;
2133 try {
2134 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
2135 + " VALUES(?,?);");
2136
2137 // --- Previously in 'system'
2138 loadBooleanSetting(stmt, Settings.Global.AIRPLANE_MODE_ON,
2139 R.bool.def_airplane_mode_on);
2140
2141 loadStringSetting(stmt, Settings.Global.AIRPLANE_MODE_RADIOS,
2142 R.string.def_airplane_mode_radios);
2143
2144 loadStringSetting(stmt, Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
2145 R.string.airplane_mode_toggleable_radios);
2146
2147 loadBooleanSetting(stmt, Settings.Global.ASSISTED_GPS_ENABLED,
2148 R.bool.assisted_gps_enabled);
2149
2150 loadBooleanSetting(stmt, Settings.Global.AUTO_TIME,
2151 R.bool.def_auto_time); // Sync time to NITZ
2152
2153 loadBooleanSetting(stmt, Settings.Global.AUTO_TIME_ZONE,
2154 R.bool.def_auto_time_zone); // Sync timezone to NITZ
2155
2156 loadSetting(stmt, Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
2157 ("1".equals(SystemProperties.get("ro.kernel.qemu")) ||
2158 mContext.getResources().getBoolean(R.bool.def_stay_on_while_plugged_in))
2159 ? 1 : 0);
2160
2161 loadIntegerSetting(stmt, Settings.Global.WIFI_SLEEP_POLICY,
2162 R.integer.def_wifi_sleep_policy);
2163
Eric Laurent55b02222012-10-03 11:56:23 -07002164 loadSetting(stmt, Settings.Global.MODE_RINGER,
2165 AudioManager.RINGER_MODE_NORMAL);
2166
Christopher Tate06efb532012-08-24 15:29:27 -07002167 // --- Previously in 'secure'
Christopher Tate6f5a9a92012-09-14 17:24:28 -07002168 loadBooleanSetting(stmt, Settings.Global.PACKAGE_VERIFIER_ENABLE,
2169 R.bool.def_package_verifier_enable);
2170
2171 loadBooleanSetting(stmt, Settings.Global.WIFI_ON,
2172 R.bool.def_wifi_on);
2173
2174 loadBooleanSetting(stmt, Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
2175 R.bool.def_networks_available_notification_on);
2176
Christopher Tate06efb532012-08-24 15:29:27 -07002177 loadBooleanSetting(stmt, Settings.Global.BLUETOOTH_ON,
2178 R.bool.def_bluetooth_on);
2179
2180 // Enable or disable Cell Broadcast SMS
2181 loadSetting(stmt, Settings.Global.CDMA_CELL_BROADCAST_SMS,
2182 RILConstants.CDMA_CELL_BROADCAST_SMS_DISABLED);
2183
2184 // Data roaming default, based on build
2185 loadSetting(stmt, Settings.Global.DATA_ROAMING,
2186 "true".equalsIgnoreCase(
2187 SystemProperties.get("ro.com.android.dataroaming",
2188 "false")) ? 1 : 0);
2189
2190 loadBooleanSetting(stmt, Settings.Global.DEVICE_PROVISIONED,
2191 R.bool.def_device_provisioned);
2192
2193 final int maxBytes = mContext.getResources().getInteger(
2194 R.integer.def_download_manager_max_bytes_over_mobile);
2195 if (maxBytes > 0) {
2196 loadSetting(stmt, Settings.Global.DOWNLOAD_MAX_BYTES_OVER_MOBILE,
2197 Integer.toString(maxBytes));
2198 }
2199
2200 final int recommendedMaxBytes = mContext.getResources().getInteger(
2201 R.integer.def_download_manager_recommended_max_bytes_over_mobile);
2202 if (recommendedMaxBytes > 0) {
2203 loadSetting(stmt, Settings.Global.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE,
2204 Integer.toString(recommendedMaxBytes));
2205 }
2206
2207 // Mobile Data default, based on build
2208 loadSetting(stmt, Settings.Global.MOBILE_DATA,
2209 "true".equalsIgnoreCase(
2210 SystemProperties.get("ro.com.android.mobiledata",
2211 "true")) ? 1 : 0);
2212
2213 loadBooleanSetting(stmt, Settings.Global.NETSTATS_ENABLED,
2214 R.bool.def_netstats_enabled);
2215
2216 loadBooleanSetting(stmt, Settings.Global.INSTALL_NON_MARKET_APPS,
2217 R.bool.def_install_non_market_apps);
2218
Christopher Tate06efb532012-08-24 15:29:27 -07002219 loadBooleanSetting(stmt, Settings.Global.USB_MASS_STORAGE_ENABLED,
2220 R.bool.def_usb_mass_storage_enabled);
2221
2222 loadIntegerSetting(stmt, Settings.Global.WIFI_MAX_DHCP_RETRY_COUNT,
2223 R.integer.def_max_dhcp_retries);
2224
Jeff Brown89d55462012-09-19 11:33:42 -07002225 loadBooleanSetting(stmt, Settings.Global.WIFI_DISPLAY_ON,
2226 R.bool.def_wifi_display_on);
2227
Jim Millerb14288d2012-09-30 18:25:05 -07002228 loadStringSetting(stmt, Settings.Global.LOCK_SOUND,
2229 R.string.def_lock_sound);
Jim Millerb14288d2012-09-30 18:25:05 -07002230 loadStringSetting(stmt, Settings.Global.UNLOCK_SOUND,
2231 R.string.def_unlock_sound);
Amith Yamasani531c2372012-10-08 14:43:20 -07002232 loadIntegerSetting(stmt, Settings.Global.POWER_SOUNDS_ENABLED,
2233 R.integer.def_power_sounds_enabled);
2234 loadStringSetting(stmt, Settings.Global.LOW_BATTERY_SOUND,
2235 R.string.def_low_battery_sound);
2236 loadIntegerSetting(stmt, Settings.Global.DOCK_SOUNDS_ENABLED,
2237 R.integer.def_dock_sounds_enabled);
2238 loadStringSetting(stmt, Settings.Global.DESK_DOCK_SOUND,
2239 R.string.def_desk_dock_sound);
2240 loadStringSetting(stmt, Settings.Global.DESK_UNDOCK_SOUND,
2241 R.string.def_desk_undock_sound);
2242 loadStringSetting(stmt, Settings.Global.CAR_DOCK_SOUND,
2243 R.string.def_car_dock_sound);
2244 loadStringSetting(stmt, Settings.Global.CAR_UNDOCK_SOUND,
2245 R.string.def_car_undock_sound);
Jeff Brown84e27562012-12-07 13:56:34 -08002246 loadStringSetting(stmt, Settings.Global.WIRELESS_CHARGING_STARTED_SOUND,
2247 R.string.def_wireless_charging_started_sound);
Jim Millerb14288d2012-09-30 18:25:05 -07002248
Dmytro Dubovyk729f6682012-12-18 18:07:50 +02002249 loadIntegerSetting(stmt, Settings.Global.DOCK_AUDIO_MEDIA_ENABLED,
2250 R.integer.def_dock_audio_media_enabled);
2251
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07002252 loadSetting(stmt, Settings.Global.SET_INSTALL_LOCATION, 0);
2253 loadSetting(stmt, Settings.Global.DEFAULT_INSTALL_LOCATION,
2254 PackageHelper.APP_INSTALL_AUTO);
2255
2256 // Set default cdma emergency tone
2257 loadSetting(stmt, Settings.Global.EMERGENCY_TONE, 0);
2258
2259 // Set default cdma call auto retry
2260 loadSetting(stmt, Settings.Global.CALL_AUTO_RETRY, 0);
2261
Naveen Kalla97ecc9e2012-07-13 20:10:22 -07002262 // Set the preferred network mode to target desired value or Default
2263 // value defined in RILConstants
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07002264 int type;
Naveen Kalla97ecc9e2012-07-13 20:10:22 -07002265 type = SystemProperties.getInt("ro.telephony.default_network",
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07002266 RILConstants.PREFERRED_NETWORK_MODE);
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07002267 loadSetting(stmt, Settings.Global.PREFERRED_NETWORK_MODE, type);
2268
Naveen Kallab4d485c2013-07-03 16:39:27 -07002269 // Set the preferred cdma subscription source to target desired value or default
2270 // value defined in CdmaSubscriptionSourceManager
2271 type = SystemProperties.getInt("ro.telephony.default_cdma_sub",
2272 CdmaSubscriptionSourceManager.PREFERRED_CDMA_SUBSCRIPTION);
2273 loadSetting(stmt, Settings.Global.CDMA_SUBSCRIPTION_MODE, type);
2274
Daniel Sandlerdea64622013-09-23 16:05:57 -04002275 loadIntegerSetting(stmt, Settings.Global.LOW_BATTERY_SOUND_TIMEOUT,
2276 R.integer.def_low_battery_sound_timeout);
2277
Oskar Grönqvist2c4254e2013-12-11 14:14:33 +01002278 loadIntegerSetting(stmt, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE,
2279 R.integer.def_wifi_scan_always_available);
2280
Christopher Tate06efb532012-08-24 15:29:27 -07002281 // --- New global settings start here
2282 } finally {
2283 if (stmt != null) stmt.close();
2284 }
2285 }
2286
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002287 private void loadSetting(SQLiteStatement stmt, String key, Object value) {
2288 stmt.bindString(1, key);
2289 stmt.bindString(2, value.toString());
2290 stmt.execute();
2291 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 private void loadStringSetting(SQLiteStatement stmt, String key, int resid) {
2294 loadSetting(stmt, key, mContext.getResources().getString(resid));
2295 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002297 private void loadBooleanSetting(SQLiteStatement stmt, String key, int resid) {
2298 loadSetting(stmt, key,
2299 mContext.getResources().getBoolean(resid) ? "1" : "0");
2300 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002302 private void loadIntegerSetting(SQLiteStatement stmt, String key, int resid) {
2303 loadSetting(stmt, key,
2304 Integer.toString(mContext.getResources().getInteger(resid)));
2305 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002307 private void loadFractionSetting(SQLiteStatement stmt, String key, int resid, int base) {
2308 loadSetting(stmt, key,
2309 Float.toString(mContext.getResources().getFraction(resid, base, base)));
2310 }
Amith Yamasani5cd15002011-11-16 11:19:48 -08002311
2312 private int getIntValueFromSystem(SQLiteDatabase db, String name, int defaultValue) {
Christopher Tate06efb532012-08-24 15:29:27 -07002313 return getIntValueFromTable(db, TABLE_SYSTEM, name, defaultValue);
Svetoslav Ganov86317012012-08-15 22:13:00 -07002314 }
2315
2316 private int getIntValueFromTable(SQLiteDatabase db, String table, String name,
2317 int defaultValue) {
2318 String value = getStringValueFromTable(db, table, name, null);
2319 return (value != null) ? Integer.parseInt(value) : defaultValue;
2320 }
2321
2322 private String getStringValueFromTable(SQLiteDatabase db, String table, String name,
2323 String defaultValue) {
Amith Yamasani5cd15002011-11-16 11:19:48 -08002324 Cursor c = null;
2325 try {
Svetoslav Ganov86317012012-08-15 22:13:00 -07002326 c = db.query(table, new String[] { Settings.System.VALUE }, "name='" + name + "'",
Amith Yamasani5cd15002011-11-16 11:19:48 -08002327 null, null, null, null);
2328 if (c != null && c.moveToFirst()) {
2329 String val = c.getString(0);
Svetoslav Ganov86317012012-08-15 22:13:00 -07002330 return val == null ? defaultValue : val;
Amith Yamasani5cd15002011-11-16 11:19:48 -08002331 }
2332 } finally {
2333 if (c != null) c.close();
2334 }
Svetoslav Ganov86317012012-08-15 22:13:00 -07002335 return defaultValue;
Amith Yamasani5cd15002011-11-16 11:19:48 -08002336 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002337}