blob: 58385267d1a6fba6e0778cfca975ba90543c95e6 [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;
Wink Savillea639b312012-07-10 12:37:54 -070042import android.telephony.TelephonyManager;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070043import android.text.TextUtils;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070044import android.util.Log;
Suchi Amalapurapu40e47252010-04-07 16:15:50 -070045
Gilles Debunnefa53d302011-07-08 10:40:51 -070046import com.android.internal.content.PackageHelper;
Gilles Debunnefa53d302011-07-08 10:40:51 -070047import com.android.internal.telephony.Phone;
Wink Savillea639b312012-07-10 12:37:54 -070048import com.android.internal.telephony.PhoneConstants;
Gilles Debunnefa53d302011-07-08 10:40:51 -070049import com.android.internal.telephony.RILConstants;
50import com.android.internal.util.XmlUtils;
51import com.android.internal.widget.LockPatternUtils;
52import com.android.internal.widget.LockPatternView;
53
54import org.xmlpull.v1.XmlPullParser;
55import org.xmlpull.v1.XmlPullParserException;
56
Christopher Tate06efb532012-08-24 15:29:27 -070057import java.io.File;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070058import java.io.IOException;
Dianne Hackborn24117ce2010-07-12 15:54:38 -070059import java.util.HashSet;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070060import java.util.List;
61
62/**
63 * Database helper class for {@link SettingsProvider}.
64 * Mostly just has a bit {@link #onCreate} to initialize the database.
65 */
James Wylder074da8f2009-02-25 08:38:31 -060066public class DatabaseHelper extends SQLiteOpenHelper {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070067 private static final String TAG = "SettingsProvider";
68 private static final String DATABASE_NAME = "settings.db";
Jim Millerf1860552009-09-09 17:46:35 -070069
70 // Please, please please. If you update the database version, check to make sure the
71 // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
72 // is properly propagated through your change. Not doing so will result in a loss of user
73 // settings.
Mike Clerond1ed3ce2013-02-01 18:36:41 +000074 private static final int DATABASE_VERSION = 97;
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -070075
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070076 private Context mContext;
Christopher Tate06efb532012-08-24 15:29:27 -070077 private int mUserHandle;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070078
Dianne Hackborn24117ce2010-07-12 15:54:38 -070079 private static final HashSet<String> mValidTables = new HashSet<String>();
80
Christopher Tate06efb532012-08-24 15:29:27 -070081 private static final String TABLE_SYSTEM = "system";
82 private static final String TABLE_SECURE = "secure";
83 private static final String TABLE_GLOBAL = "global";
84
Dianne Hackborn24117ce2010-07-12 15:54:38 -070085 static {
Christopher Tate06efb532012-08-24 15:29:27 -070086 mValidTables.add(TABLE_SYSTEM);
87 mValidTables.add(TABLE_SECURE);
88 mValidTables.add(TABLE_GLOBAL);
Dianne Hackborn24117ce2010-07-12 15:54:38 -070089 mValidTables.add("bluetooth_devices");
90 mValidTables.add("bookmarks");
91
92 // These are old.
93 mValidTables.add("favorites");
94 mValidTables.add("gservices");
95 mValidTables.add("old_favorites");
96 }
97
Christopher Tate06efb532012-08-24 15:29:27 -070098 static String dbNameForUser(final int userHandle) {
99 // The owner gets the unadorned db name;
100 if (userHandle == UserHandle.USER_OWNER) {
101 return DATABASE_NAME;
102 } else {
103 // Place the database in the user-specific data tree so that it's
104 // cleaned up automatically when the user is deleted.
105 File databaseFile = new File(
106 Environment.getUserSystemDirectory(userHandle), DATABASE_NAME);
107 return databaseFile.getPath();
108 }
109 }
110
111 public DatabaseHelper(Context context, int userHandle) {
112 super(context, dbNameForUser(userHandle), null, DATABASE_VERSION);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700113 mContext = context;
Christopher Tate06efb532012-08-24 15:29:27 -0700114 mUserHandle = userHandle;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700115 }
116
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700117 public static boolean isValidTable(String name) {
118 return mValidTables.contains(name);
119 }
120
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800121 private void createSecureTable(SQLiteDatabase db) {
122 db.execSQL("CREATE TABLE secure (" +
123 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
124 "name TEXT UNIQUE ON CONFLICT REPLACE," +
125 "value TEXT" +
126 ");");
127 db.execSQL("CREATE INDEX secureIndex1 ON secure (name);");
128 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700129
Christopher Tate06efb532012-08-24 15:29:27 -0700130 private void createGlobalTable(SQLiteDatabase db) {
131 db.execSQL("CREATE TABLE global (" +
132 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
133 "name TEXT UNIQUE ON CONFLICT REPLACE," +
134 "value TEXT" +
135 ");");
136 db.execSQL("CREATE INDEX globalIndex1 ON global (name);");
137 }
138
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700139 @Override
140 public void onCreate(SQLiteDatabase db) {
141 db.execSQL("CREATE TABLE system (" +
142 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
143 "name TEXT UNIQUE ON CONFLICT REPLACE," +
144 "value TEXT" +
145 ");");
146 db.execSQL("CREATE INDEX systemIndex1 ON system (name);");
147
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800148 createSecureTable(db);
149
Christopher Tate06efb532012-08-24 15:29:27 -0700150 // Only create the global table for the singleton 'owner' user
151 if (mUserHandle == UserHandle.USER_OWNER) {
152 createGlobalTable(db);
153 }
154
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700155 db.execSQL("CREATE TABLE bluetooth_devices (" +
156 "_id INTEGER PRIMARY KEY," +
157 "name TEXT," +
158 "addr TEXT," +
159 "channel INTEGER," +
160 "type INTEGER" +
161 ");");
162
163 db.execSQL("CREATE TABLE bookmarks (" +
164 "_id INTEGER PRIMARY KEY," +
165 "title TEXT," +
166 "folder TEXT," +
167 "intent TEXT," +
168 "shortcut INTEGER," +
169 "ordering INTEGER" +
170 ");");
171
172 db.execSQL("CREATE INDEX bookmarksIndex1 ON bookmarks (folder);");
173 db.execSQL("CREATE INDEX bookmarksIndex2 ON bookmarks (shortcut);");
174
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700175 // Populate bookmarks table with initial bookmarks
Dianne Hackborn13579ed2012-11-28 18:05:36 -0800176 boolean onlyCore = false;
177 try {
178 onlyCore = IPackageManager.Stub.asInterface(ServiceManager.getService(
179 "package")).isOnlyCoreApps();
180 } catch (RemoteException e) {
181 }
182 if (!onlyCore) {
183 loadBookmarks(db);
184 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700185
186 // Load initial volume levels into DB
187 loadVolumeLevels(db);
188
189 // Load inital settings values
190 loadSettings(db);
191 }
192
193 @Override
194 public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700195 Log.w(TAG, "Upgrading settings database from version " + oldVersion + " to "
196 + currentVersion);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700197
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700198 int upgradeVersion = oldVersion;
199
200 // Pattern for upgrade blocks:
201 //
202 // if (upgradeVersion == [the DATABASE_VERSION you set] - 1) {
203 // .. your upgrade logic..
204 // upgradeVersion = [the DATABASE_VERSION you set]
205 // }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700206
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700207 if (upgradeVersion == 20) {
208 /*
209 * Version 21 is part of the volume control refresh. There is no
210 * longer a UI-visible for setting notification vibrate on/off (in
211 * our design), but the functionality still exists. Force the
212 * notification vibrate to on.
213 */
214 loadVibrateSetting(db, true);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700215
216 upgradeVersion = 21;
217 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700218
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700219 if (upgradeVersion < 22) {
220 upgradeVersion = 22;
221 // Upgrade the lock gesture storage location and format
222 upgradeLockPatternLocation(db);
223 }
224
225 if (upgradeVersion < 23) {
226 db.execSQL("UPDATE favorites SET iconResource=0 WHERE iconType=0");
227 upgradeVersion = 23;
228 }
229
230 if (upgradeVersion == 23) {
231 db.beginTransaction();
232 try {
233 db.execSQL("ALTER TABLE favorites ADD spanX INTEGER");
234 db.execSQL("ALTER TABLE favorites ADD spanY INTEGER");
235 // Shortcuts, applications, folders
236 db.execSQL("UPDATE favorites SET spanX=1, spanY=1 WHERE itemType<=0");
237 // Photo frames, clocks
Wink Saville04e71b32009-04-02 11:00:54 -0700238 db.execSQL(
239 "UPDATE favorites SET spanX=2, spanY=2 WHERE itemType=1000 or itemType=1002");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700240 // Search boxes
241 db.execSQL("UPDATE favorites SET spanX=4, spanY=1 WHERE itemType=1001");
242 db.setTransactionSuccessful();
243 } finally {
244 db.endTransaction();
245 }
246 upgradeVersion = 24;
247 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700248
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700249 if (upgradeVersion == 24) {
250 db.beginTransaction();
251 try {
252 // The value of the constants for preferring wifi or preferring mobile have been
253 // swapped, so reload the default.
254 db.execSQL("DELETE FROM system WHERE name='network_preference'");
255 db.execSQL("INSERT INTO system ('name', 'value') values ('network_preference', '" +
256 ConnectivityManager.DEFAULT_NETWORK_PREFERENCE + "')");
257 db.setTransactionSuccessful();
258 } finally {
259 db.endTransaction();
260 }
261 upgradeVersion = 25;
262 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800263
264 if (upgradeVersion == 25) {
265 db.beginTransaction();
266 try {
267 db.execSQL("ALTER TABLE favorites ADD uri TEXT");
268 db.execSQL("ALTER TABLE favorites ADD displayMode INTEGER");
269 db.setTransactionSuccessful();
270 } finally {
271 db.endTransaction();
272 }
273 upgradeVersion = 26;
274 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700275
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800276 if (upgradeVersion == 26) {
277 // This introduces the new secure settings table.
278 db.beginTransaction();
279 try {
280 createSecureTable(db);
281 db.setTransactionSuccessful();
282 } finally {
283 db.endTransaction();
284 }
285 upgradeVersion = 27;
286 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700287
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800288 if (upgradeVersion == 27) {
Amith Yamasani156c4352010-03-05 17:10:03 -0800289 String[] settingsToMove = {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800290 Settings.Secure.ADB_ENABLED,
291 Settings.Secure.ANDROID_ID,
292 Settings.Secure.BLUETOOTH_ON,
293 Settings.Secure.DATA_ROAMING,
294 Settings.Secure.DEVICE_PROVISIONED,
295 Settings.Secure.HTTP_PROXY,
296 Settings.Secure.INSTALL_NON_MARKET_APPS,
297 Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
298 Settings.Secure.LOGGING_ID,
299 Settings.Secure.NETWORK_PREFERENCE,
300 Settings.Secure.PARENTAL_CONTROL_ENABLED,
301 Settings.Secure.PARENTAL_CONTROL_LAST_UPDATE,
302 Settings.Secure.PARENTAL_CONTROL_REDIRECT_URL,
303 Settings.Secure.SETTINGS_CLASSNAME,
304 Settings.Secure.USB_MASS_STORAGE_ENABLED,
305 Settings.Secure.USE_GOOGLE_MAIL,
306 Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
307 Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,
308 Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT,
309 Settings.Secure.WIFI_ON,
310 Settings.Secure.WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE,
311 Settings.Secure.WIFI_WATCHDOG_AP_COUNT,
312 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS,
313 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED,
314 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS,
315 Settings.Secure.WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT,
316 Settings.Secure.WIFI_WATCHDOG_MAX_AP_CHECKS,
317 Settings.Secure.WIFI_WATCHDOG_ON,
318 Settings.Secure.WIFI_WATCHDOG_PING_COUNT,
319 Settings.Secure.WIFI_WATCHDOG_PING_DELAY_MS,
320 Settings.Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS,
321 };
Christopher Tate92198742012-09-07 12:00:13 -0700322 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800323 upgradeVersion = 28;
324 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700325
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800326 if (upgradeVersion == 28 || upgradeVersion == 29) {
327 // Note: The upgrade to 28 was flawed since it didn't delete the old
328 // setting first before inserting. Combining 28 and 29 with the
329 // fixed version.
330
331 // This upgrade adds the STREAM_NOTIFICATION type to the list of
332 // types affected by ringer modes (silent, vibrate, etc.)
333 db.beginTransaction();
334 try {
335 db.execSQL("DELETE FROM system WHERE name='"
336 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
337 int newValue = (1 << AudioManager.STREAM_RING)
338 | (1 << AudioManager.STREAM_NOTIFICATION)
339 | (1 << AudioManager.STREAM_SYSTEM);
340 db.execSQL("INSERT INTO system ('name', 'value') values ('"
341 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
342 + String.valueOf(newValue) + "')");
343 db.setTransactionSuccessful();
344 } finally {
345 db.endTransaction();
346 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700347
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800348 upgradeVersion = 30;
349 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700350
The Android Open Source Project9266c552009-01-15 16:12:10 -0800351 if (upgradeVersion == 30) {
352 /*
353 * Upgrade 31 clears the title for all quick launch shortcuts so the
354 * activities' titles will be resolved at display time. Also, the
355 * folder is changed to '@quicklaunch'.
356 */
357 db.beginTransaction();
358 try {
359 db.execSQL("UPDATE bookmarks SET folder = '@quicklaunch'");
360 db.execSQL("UPDATE bookmarks SET title = ''");
361 db.setTransactionSuccessful();
362 } finally {
363 db.endTransaction();
364 }
365 upgradeVersion = 31;
366 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 if (upgradeVersion == 31) {
369 /*
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700370 * Animations are now managed in preferences, and may be
371 * enabled or disabled based on product resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 */
373 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700374 SQLiteStatement stmt = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 try {
376 db.execSQL("DELETE FROM system WHERE name='"
377 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
378 db.execSQL("DELETE FROM system WHERE name='"
379 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700380 stmt = db.compileStatement("INSERT INTO system(name,value)"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 + " VALUES(?,?);");
382 loadDefaultAnimationSettings(stmt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 db.setTransactionSuccessful();
384 } finally {
385 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700386 if (stmt != null) stmt.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 }
388 upgradeVersion = 32;
389 }
390
391 if (upgradeVersion == 32) {
392 // The Wi-Fi watchdog SSID list is now seeded with the value of
393 // the property ro.com.android.wifi-watchlist
394 String wifiWatchList = SystemProperties.get("ro.com.android.wifi-watchlist");
395 if (!TextUtils.isEmpty(wifiWatchList)) {
396 db.beginTransaction();
397 try {
398 db.execSQL("INSERT OR IGNORE INTO secure(name,value) values('" +
399 Settings.Secure.WIFI_WATCHDOG_WATCH_LIST + "','" +
400 wifiWatchList + "');");
401 db.setTransactionSuccessful();
402 } finally {
403 db.endTransaction();
404 }
405 }
406 upgradeVersion = 33;
407 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700408
The Android Open Source Project4df24232009-03-05 14:34:35 -0800409 if (upgradeVersion == 33) {
410 // Set the default zoom controls to: tap-twice to bring up +/-
411 db.beginTransaction();
412 try {
413 db.execSQL("INSERT INTO system(name,value) values('zoom','2');");
414 db.setTransactionSuccessful();
415 } finally {
416 db.endTransaction();
417 }
418 upgradeVersion = 34;
419 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420
Mike Lockwoodbcab8df2009-06-25 16:39:09 -0400421 if (upgradeVersion == 34) {
422 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700423 SQLiteStatement stmt = null;
Mike Lockwoodbcab8df2009-06-25 16:39:09 -0400424 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700425 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
Dianne Hackborncf098292009-07-01 19:55:20 -0700426 + " VALUES(?,?);");
427 loadSecure35Settings(stmt);
Dianne Hackborncf098292009-07-01 19:55:20 -0700428 db.setTransactionSuccessful();
429 } finally {
430 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700431 if (stmt != null) stmt.close();
Dianne Hackborncf098292009-07-01 19:55:20 -0700432 }
Jim Millerf1860552009-09-09 17:46:35 -0700433 upgradeVersion = 35;
Mike Lockwood02901eb2009-08-25 15:11:17 -0700434 }
435 // due to a botched merge from donut to eclair, the initialization of ASSISTED_GPS_ENABLED
436 // was accidentally done out of order here.
437 // to fix this, ASSISTED_GPS_ENABLED is now initialized while upgrading from 38 to 39,
438 // and we intentionally do nothing from 35 to 36 now.
439 if (upgradeVersion == 35) {
The Android Open Source Project575d1af2009-07-03 08:55:59 -0700440 upgradeVersion = 36;
Dianne Hackborncf098292009-07-01 19:55:20 -0700441 }
Mike Lockwood02901eb2009-08-25 15:11:17 -0700442
Eric Laurenta553c252009-07-17 12:17:14 -0700443 if (upgradeVersion == 36) {
444 // This upgrade adds the STREAM_SYSTEM_ENFORCED type to the list of
445 // types affected by ringer modes (silent, vibrate, etc.)
446 db.beginTransaction();
447 try {
448 db.execSQL("DELETE FROM system WHERE name='"
449 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
450 int newValue = (1 << AudioManager.STREAM_RING)
451 | (1 << AudioManager.STREAM_NOTIFICATION)
452 | (1 << AudioManager.STREAM_SYSTEM)
453 | (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
454 db.execSQL("INSERT INTO system ('name', 'value') values ('"
455 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
456 + String.valueOf(newValue) + "')");
457 db.setTransactionSuccessful();
458 } finally {
459 db.endTransaction();
460 }
Jim Miller48805752009-08-04 18:59:20 -0700461 upgradeVersion = 37;
Eric Laurenta553c252009-07-17 12:17:14 -0700462 }
463
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700464 if (upgradeVersion == 37) {
465 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700466 SQLiteStatement stmt = null;
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700467 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700468 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700469 + " VALUES(?,?);");
470 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
471 R.string.airplane_mode_toggleable_radios);
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700472 db.setTransactionSuccessful();
473 } finally {
474 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700475 if (stmt != null) stmt.close();
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700476 }
477 upgradeVersion = 38;
478 }
479
Mike Lockwood02901eb2009-08-25 15:11:17 -0700480 if (upgradeVersion == 38) {
481 db.beginTransaction();
482 try {
483 String value =
484 mContext.getResources().getBoolean(R.bool.assisted_gps_enabled) ? "1" : "0";
485 db.execSQL("INSERT OR IGNORE INTO secure(name,value) values('" +
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -0700486 Settings.Global.ASSISTED_GPS_ENABLED + "','" + value + "');");
Mike Lockwood02901eb2009-08-25 15:11:17 -0700487 db.setTransactionSuccessful();
488 } finally {
489 db.endTransaction();
490 }
491
492 upgradeVersion = 39;
493 }
494
Dan Murphy951764b2009-08-27 14:59:03 -0500495 if (upgradeVersion == 39) {
Amith Yamasanif50c5112011-01-07 11:32:30 -0800496 upgradeAutoBrightness(db);
Dan Murphy951764b2009-08-27 14:59:03 -0500497 upgradeVersion = 40;
498 }
499
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700500 if (upgradeVersion == 40) {
501 /*
502 * All animations are now turned on by default!
503 */
504 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700505 SQLiteStatement stmt = null;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700506 try {
507 db.execSQL("DELETE FROM system WHERE name='"
508 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
509 db.execSQL("DELETE FROM system WHERE name='"
510 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700511 stmt = db.compileStatement("INSERT INTO system(name,value)"
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700512 + " VALUES(?,?);");
513 loadDefaultAnimationSettings(stmt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700514 db.setTransactionSuccessful();
515 } finally {
516 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700517 if (stmt != null) stmt.close();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700518 }
519 upgradeVersion = 41;
520 }
521
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700522 if (upgradeVersion == 41) {
523 /*
524 * Initialize newly public haptic feedback setting
525 */
526 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700527 SQLiteStatement stmt = null;
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700528 try {
529 db.execSQL("DELETE FROM system WHERE name='"
530 + Settings.System.HAPTIC_FEEDBACK_ENABLED + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700531 stmt = db.compileStatement("INSERT INTO system(name,value)"
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700532 + " VALUES(?,?);");
533 loadDefaultHapticSettings(stmt);
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700534 db.setTransactionSuccessful();
535 } finally {
536 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700537 if (stmt != null) stmt.close();
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700538 }
539 upgradeVersion = 42;
540 }
541
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800542 if (upgradeVersion == 42) {
543 /*
544 * Initialize new notification pulse setting
545 */
546 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700547 SQLiteStatement stmt = null;
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800548 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700549 stmt = db.compileStatement("INSERT INTO system(name,value)"
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800550 + " VALUES(?,?);");
551 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
552 R.bool.def_notification_pulse);
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800553 db.setTransactionSuccessful();
554 } finally {
555 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700556 if (stmt != null) stmt.close();
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800557 }
558 upgradeVersion = 43;
559 }
560
Eric Laurent484d2882009-12-08 09:05:45 -0800561 if (upgradeVersion == 43) {
562 /*
563 * This upgrade stores bluetooth volume separately from voice volume
564 */
565 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700566 SQLiteStatement stmt = null;
Eric Laurent484d2882009-12-08 09:05:45 -0800567 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700568 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
Eric Laurent484d2882009-12-08 09:05:45 -0800569 + " VALUES(?,?);");
570 loadSetting(stmt, Settings.System.VOLUME_BLUETOOTH_SCO,
571 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_BLUETOOTH_SCO]);
Eric Laurent484d2882009-12-08 09:05:45 -0800572 db.setTransactionSuccessful();
573 } finally {
574 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700575 if (stmt != null) stmt.close();
Eric Laurent484d2882009-12-08 09:05:45 -0800576 }
577 upgradeVersion = 44;
578 }
579
Doug Zongkeraed8f8e2010-01-07 18:07:50 -0800580 if (upgradeVersion == 44) {
581 /*
582 * Gservices was moved into vendor/google.
583 */
584 db.execSQL("DROP TABLE IF EXISTS gservices");
585 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1");
586 upgradeVersion = 45;
587 }
San Mehat87734d32010-01-08 12:53:06 -0800588
589 if (upgradeVersion == 45) {
590 /*
591 * New settings for MountService
592 */
593 db.beginTransaction();
594 try {
595 db.execSQL("INSERT INTO secure(name,value) values('" +
596 Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND + "','1');");
597 db.execSQL("INSERT INTO secure(name,value) values('" +
598 Settings.Secure.MOUNT_UMS_AUTOSTART + "','0');");
599 db.execSQL("INSERT INTO secure(name,value) values('" +
600 Settings.Secure.MOUNT_UMS_PROMPT + "','1');");
601 db.execSQL("INSERT INTO secure(name,value) values('" +
602 Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED + "','1');");
603 db.setTransactionSuccessful();
604 } finally {
605 db.endTransaction();
606 }
607 upgradeVersion = 46;
608 }
609
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800610 if (upgradeVersion == 46) {
611 /*
612 * The password mode constants have changed; reset back to no
613 * password.
614 */
615 db.beginTransaction();
616 try {
617 db.execSQL("DELETE FROM system WHERE name='lockscreen.password_type';");
618 db.setTransactionSuccessful();
619 } finally {
620 db.endTransaction();
621 }
622 upgradeVersion = 47;
623 }
624
Jim Miller61766772010-02-12 14:56:49 -0800625
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800626 if (upgradeVersion == 47) {
627 /*
628 * The password mode constants have changed again; reset back to no
629 * password.
630 */
631 db.beginTransaction();
632 try {
633 db.execSQL("DELETE FROM system WHERE name='lockscreen.password_type';");
634 db.setTransactionSuccessful();
635 } finally {
636 db.endTransaction();
637 }
638 upgradeVersion = 48;
639 }
Jim Miller61766772010-02-12 14:56:49 -0800640
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800641 if (upgradeVersion == 48) {
642 /*
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800643 * Default recognition service no longer initialized here,
644 * moved to RecognitionManagerService.
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800645 */
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800646 upgradeVersion = 49;
647 }
Jim Miller31f90b62010-01-20 13:35:20 -0800648
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500649 if (upgradeVersion == 49) {
650 /*
651 * New settings for new user interface noises.
652 */
653 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700654 SQLiteStatement stmt = null;
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500655 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700656 stmt = db.compileStatement("INSERT INTO system(name,value)"
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500657 + " VALUES(?,?);");
658 loadUISoundEffectsSettings(stmt);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500659 db.setTransactionSuccessful();
660 } finally {
661 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700662 if (stmt != null) stmt.close();
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500663 }
664
665 upgradeVersion = 50;
666 }
667
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800668 if (upgradeVersion == 50) {
669 /*
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700670 * Install location no longer initiated here.
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800671 */
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800672 upgradeVersion = 51;
673 }
674
Amith Yamasani156c4352010-03-05 17:10:03 -0800675 if (upgradeVersion == 51) {
676 /* Move the lockscreen related settings to Secure, including some private ones. */
677 String[] settingsToMove = {
678 Secure.LOCK_PATTERN_ENABLED,
679 Secure.LOCK_PATTERN_VISIBLE,
680 Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED,
681 "lockscreen.password_type",
682 "lockscreen.lockoutattemptdeadline",
683 "lockscreen.patterneverchosen",
684 "lock_pattern_autolock",
685 "lockscreen.lockedoutpermanently",
686 "lockscreen.password_salt"
687 };
Christopher Tate92198742012-09-07 12:00:13 -0700688 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
Amith Yamasani156c4352010-03-05 17:10:03 -0800689 upgradeVersion = 52;
690 }
691
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500692 if (upgradeVersion == 52) {
693 // new vibration/silent mode settings
694 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700695 SQLiteStatement stmt = null;
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500696 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700697 stmt = db.compileStatement("INSERT INTO system(name,value)"
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500698 + " VALUES(?,?);");
699 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
700 R.bool.def_vibrate_in_silent);
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500701 db.setTransactionSuccessful();
702 } finally {
703 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700704 if (stmt != null) stmt.close();
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500705 }
706
707 upgradeVersion = 53;
708 }
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -0700709
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800710 if (upgradeVersion == 53) {
711 /*
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700712 * New settings for set install location UI no longer initiated here.
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800713 */
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800714 upgradeVersion = 54;
715 }
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500716
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -0700717 if (upgradeVersion == 54) {
718 /*
719 * Update the screen timeout value if set to never
720 */
721 db.beginTransaction();
722 try {
723 upgradeScreenTimeoutFromNever(db);
724 db.setTransactionSuccessful();
725 } finally {
726 db.endTransaction();
727 }
728
729 upgradeVersion = 55;
730 }
731
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700732 if (upgradeVersion == 55) {
733 /* Move the install location settings. */
734 String[] settingsToMove = {
Jeff Sharkey625239a2012-09-26 22:03:49 -0700735 Global.SET_INSTALL_LOCATION,
736 Global.DEFAULT_INSTALL_LOCATION
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700737 };
Christopher Tate92198742012-09-07 12:00:13 -0700738 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700739 db.beginTransaction();
740 SQLiteStatement stmt = null;
741 try {
742 stmt = db.compileStatement("INSERT INTO system(name,value)"
743 + " VALUES(?,?);");
Jeff Sharkey625239a2012-09-26 22:03:49 -0700744 loadSetting(stmt, Global.SET_INSTALL_LOCATION, 0);
745 loadSetting(stmt, Global.DEFAULT_INSTALL_LOCATION,
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700746 PackageHelper.APP_INSTALL_AUTO);
747 db.setTransactionSuccessful();
748 } finally {
749 db.endTransaction();
750 if (stmt != null) stmt.close();
751 }
752 upgradeVersion = 56;
753 }
Jake Hamby66592842010-08-24 19:55:20 -0700754
755 if (upgradeVersion == 56) {
756 /*
757 * Add Bluetooth to list of toggleable radios in airplane mode
758 */
759 db.beginTransaction();
760 SQLiteStatement stmt = null;
761 try {
762 db.execSQL("DELETE FROM system WHERE name='"
763 + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS + "'");
764 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
765 + " VALUES(?,?);");
766 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
767 R.string.airplane_mode_toggleable_radios);
768 db.setTransactionSuccessful();
769 } finally {
770 db.endTransaction();
771 if (stmt != null) stmt.close();
772 }
773 upgradeVersion = 57;
774 }
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700775
Amith Yamasani5cd15002011-11-16 11:19:48 -0800776 /************* The following are Honeycomb changes ************/
777
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700778 if (upgradeVersion == 57) {
779 /*
780 * New settings to:
781 * 1. Enable injection of accessibility scripts in WebViews.
782 * 2. Define the key bindings for traversing web content in WebViews.
783 */
784 db.beginTransaction();
785 SQLiteStatement stmt = null;
786 try {
787 stmt = db.compileStatement("INSERT INTO secure(name,value)"
788 + " VALUES(?,?);");
789 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION,
790 R.bool.def_accessibility_script_injection);
791 stmt.close();
792 stmt = db.compileStatement("INSERT INTO secure(name,value)"
793 + " VALUES(?,?);");
794 loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS,
795 R.string.def_accessibility_web_content_key_bindings);
796 db.setTransactionSuccessful();
797 } finally {
798 db.endTransaction();
799 if (stmt != null) stmt.close();
800 }
801 upgradeVersion = 58;
802 }
803
Amith Yamasaniad450be2010-09-16 16:47:00 -0700804 if (upgradeVersion == 58) {
805 /* Add default for new Auto Time Zone */
Amith Yamasani5cd15002011-11-16 11:19:48 -0800806 int autoTimeValue = getIntValueFromSystem(db, Settings.System.AUTO_TIME, 0);
Amith Yamasaniad450be2010-09-16 16:47:00 -0700807 db.beginTransaction();
808 SQLiteStatement stmt = null;
809 try {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800810 stmt = db.compileStatement("INSERT INTO system(name,value)" + " VALUES(?,?);");
811 loadSetting(stmt, Settings.System.AUTO_TIME_ZONE,
812 autoTimeValue); // Sync timezone to NITZ if auto_time was enabled
Amith Yamasaniad450be2010-09-16 16:47:00 -0700813 db.setTransactionSuccessful();
814 } finally {
815 db.endTransaction();
816 if (stmt != null) stmt.close();
817 }
818 upgradeVersion = 59;
819 }
820
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400821 if (upgradeVersion == 59) {
822 // Persistence for the rotation lock feature.
823 db.beginTransaction();
824 SQLiteStatement stmt = null;
825 try {
826 stmt = db.compileStatement("INSERT INTO system(name,value)"
827 + " VALUES(?,?);");
828 loadBooleanSetting(stmt, Settings.System.USER_ROTATION,
829 R.integer.def_user_rotation); // should be zero degrees
830 db.setTransactionSuccessful();
831 } finally {
832 db.endTransaction();
833 if (stmt != null) stmt.close();
834 }
835 upgradeVersion = 60;
836 }
837
Amith Yamasani00389312010-11-05 11:22:21 -0700838 if (upgradeVersion == 60) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800839 // Don't do this for upgrades from Gingerbread
840 // Were only required for intra-Honeycomb upgrades for testing
841 // upgradeScreenTimeout(db);
Amith Yamasani00389312010-11-05 11:22:21 -0700842 upgradeVersion = 61;
843 }
844
Amith Yamasani79373f62010-11-18 16:32:48 -0800845 if (upgradeVersion == 61) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800846 // Don't do this for upgrades from Gingerbread
847 // Were only required for intra-Honeycomb upgrades for testing
848 // upgradeScreenTimeout(db);
Amith Yamasani79373f62010-11-18 16:32:48 -0800849 upgradeVersion = 62;
850 }
851
Amith Yamasanif50c5112011-01-07 11:32:30 -0800852 // Change the default for screen auto-brightness mode
853 if (upgradeVersion == 62) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800854 // Don't do this for upgrades from Gingerbread
855 // Were only required for intra-Honeycomb upgrades for testing
856 // upgradeAutoBrightness(db);
Amith Yamasanif50c5112011-01-07 11:32:30 -0800857 upgradeVersion = 63;
858 }
859
Eric Laurent25101b02011-02-02 09:33:30 -0800860 if (upgradeVersion == 63) {
861 // This upgrade adds the STREAM_MUSIC type to the list of
862 // types affected by ringer modes (silent, vibrate, etc.)
863 db.beginTransaction();
864 try {
865 db.execSQL("DELETE FROM system WHERE name='"
866 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
867 int newValue = (1 << AudioManager.STREAM_RING)
868 | (1 << AudioManager.STREAM_NOTIFICATION)
869 | (1 << AudioManager.STREAM_SYSTEM)
870 | (1 << AudioManager.STREAM_SYSTEM_ENFORCED)
871 | (1 << AudioManager.STREAM_MUSIC);
872 db.execSQL("INSERT INTO system ('name', 'value') values ('"
873 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
874 + String.valueOf(newValue) + "')");
875 db.setTransactionSuccessful();
876 } finally {
877 db.endTransaction();
878 }
879 upgradeVersion = 64;
880 }
881
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800882 if (upgradeVersion == 64) {
883 // New setting to configure the long press timeout.
884 db.beginTransaction();
885 SQLiteStatement stmt = null;
886 try {
887 stmt = db.compileStatement("INSERT INTO secure(name,value)"
888 + " VALUES(?,?);");
889 loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT,
890 R.integer.def_long_press_timeout_millis);
891 stmt.close();
892 db.setTransactionSuccessful();
893 } finally {
894 db.endTransaction();
895 if (stmt != null) stmt.close();
896 }
897 upgradeVersion = 65;
898 }
899
Amith Yamasani5cd15002011-11-16 11:19:48 -0800900 /************* The following are Ice Cream Sandwich changes ************/
901
Gilles Debunnefa53d302011-07-08 10:40:51 -0700902 if (upgradeVersion == 65) {
903 /*
904 * Animations are removed from Settings. Turned on by default
905 */
906 db.beginTransaction();
907 SQLiteStatement stmt = null;
908 try {
909 db.execSQL("DELETE FROM system WHERE name='"
910 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
911 db.execSQL("DELETE FROM system WHERE name='"
912 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
913 stmt = db.compileStatement("INSERT INTO system(name,value)"
914 + " VALUES(?,?);");
915 loadDefaultAnimationSettings(stmt);
916 db.setTransactionSuccessful();
917 } finally {
918 db.endTransaction();
919 if (stmt != null) stmt.close();
920 }
921 upgradeVersion = 66;
922 }
923
Eric Laurentc1d41662011-07-19 11:21:13 -0700924 if (upgradeVersion == 66) {
Amith Yamasani42722bf2011-07-22 10:34:27 -0700925 // This upgrade makes sure that MODE_RINGER_STREAMS_AFFECTED is set
926 // according to device voice capability
927 db.beginTransaction();
928 try {
929 int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
930 (1 << AudioManager.STREAM_NOTIFICATION) |
931 (1 << AudioManager.STREAM_SYSTEM) |
932 (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
933 if (!mContext.getResources().getBoolean(
934 com.android.internal.R.bool.config_voice_capable)) {
935 ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
936 }
937 db.execSQL("DELETE FROM system WHERE name='"
938 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
939 db.execSQL("INSERT INTO system ('name', 'value') values ('"
940 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
941 + String.valueOf(ringerModeAffectedStreams) + "')");
942 db.setTransactionSuccessful();
943 } finally {
944 db.endTransaction();
945 }
946 upgradeVersion = 67;
947 }
Eric Laurentc1d41662011-07-19 11:21:13 -0700948
Svetoslav Ganova28a16d2011-07-28 11:24:21 -0700949 if (upgradeVersion == 67) {
950 // New setting to enable touch exploration.
951 db.beginTransaction();
952 SQLiteStatement stmt = null;
953 try {
954 stmt = db.compileStatement("INSERT INTO secure(name,value)"
955 + " VALUES(?,?);");
956 loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED,
957 R.bool.def_touch_exploration_enabled);
958 stmt.close();
959 db.setTransactionSuccessful();
960 } finally {
961 db.endTransaction();
962 if (stmt != null) stmt.close();
963 }
964 upgradeVersion = 68;
965 }
966
Amith Yamasani42722bf2011-07-22 10:34:27 -0700967 if (upgradeVersion == 68) {
968 // Enable all system sounds by default
969 db.beginTransaction();
Amith Yamasani42722bf2011-07-22 10:34:27 -0700970 try {
Amith Yamasani42722bf2011-07-22 10:34:27 -0700971 db.execSQL("DELETE FROM system WHERE name='"
972 + Settings.System.NOTIFICATIONS_USE_RING_VOLUME + "'");
Amith Yamasani42722bf2011-07-22 10:34:27 -0700973 db.setTransactionSuccessful();
974 } finally {
975 db.endTransaction();
Amith Yamasani42722bf2011-07-22 10:34:27 -0700976 }
977 upgradeVersion = 69;
978 }
Svetoslav Ganova28a16d2011-07-28 11:24:21 -0700979
Nick Pelly8d32a012011-08-09 07:03:49 -0700980 if (upgradeVersion == 69) {
981 // Add RADIO_NFC to AIRPLANE_MODE_RADIO and AIRPLANE_MODE_TOGGLEABLE_RADIOS
982 String airplaneRadios = mContext.getResources().getString(
983 R.string.def_airplane_mode_radios);
984 String toggleableRadios = mContext.getResources().getString(
985 R.string.airplane_mode_toggleable_radios);
986 db.beginTransaction();
987 try {
988 db.execSQL("UPDATE system SET value='" + airplaneRadios + "' " +
989 "WHERE name='" + Settings.System.AIRPLANE_MODE_RADIOS + "'");
990 db.execSQL("UPDATE system SET value='" + toggleableRadios + "' " +
991 "WHERE name='" + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS + "'");
992 db.setTransactionSuccessful();
993 } finally {
994 db.endTransaction();
995 }
996 upgradeVersion = 70;
997 }
998
Jeff Brown6651a632011-11-28 12:59:11 -0800999 if (upgradeVersion == 70) {
1000 // Update all built-in bookmarks. Some of the package names have changed.
1001 loadBookmarks(db);
1002 upgradeVersion = 71;
1003 }
1004
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08001005 if (upgradeVersion == 71) {
1006 // New setting to specify whether to speak passwords in accessibility mode.
1007 db.beginTransaction();
1008 SQLiteStatement stmt = null;
1009 try {
1010 stmt = db.compileStatement("INSERT INTO secure(name,value)"
1011 + " VALUES(?,?);");
1012 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD,
1013 R.bool.def_accessibility_speak_password);
Amith Yamasani6243edd2011-12-05 19:58:48 -08001014 db.setTransactionSuccessful();
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08001015 } finally {
1016 db.endTransaction();
1017 if (stmt != null) stmt.close();
1018 }
1019 upgradeVersion = 72;
1020 }
1021
Amith Yamasani6243edd2011-12-05 19:58:48 -08001022 if (upgradeVersion == 72) {
1023 // update vibration settings
1024 db.beginTransaction();
1025 SQLiteStatement stmt = null;
1026 try {
1027 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1028 + " VALUES(?,?);");
1029 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
1030 R.bool.def_vibrate_in_silent);
1031 db.setTransactionSuccessful();
1032 } finally {
1033 db.endTransaction();
1034 if (stmt != null) stmt.close();
1035 }
1036 upgradeVersion = 73;
1037 }
1038
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001039 if (upgradeVersion == 73) {
Amith Yamasani398c83c2011-12-13 10:38:47 -08001040 upgradeVibrateSettingFromNone(db);
1041 upgradeVersion = 74;
1042 }
1043
1044 if (upgradeVersion == 74) {
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001045 // URL from which WebView loads a JavaScript based screen-reader.
1046 db.beginTransaction();
1047 SQLiteStatement stmt = null;
1048 try {
1049 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
1050 loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_SCREEN_READER_URL,
1051 R.string.def_accessibility_screen_reader_url);
1052 db.setTransactionSuccessful();
1053 } finally {
1054 db.endTransaction();
1055 if (stmt != null) stmt.close();
1056 }
Amith Yamasani398c83c2011-12-13 10:38:47 -08001057 upgradeVersion = 75;
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001058 }
Mike Lockwood7bef7392011-10-20 16:51:53 -04001059 if (upgradeVersion == 75) {
1060 db.beginTransaction();
1061 SQLiteStatement stmt = null;
1062 Cursor c = null;
1063 try {
Christopher Tate06efb532012-08-24 15:29:27 -07001064 c = db.query(TABLE_SECURE, new String[] {"_id", "value"},
Mike Lockwood7bef7392011-10-20 16:51:53 -04001065 "name='lockscreen.disabled'",
1066 null, null, null, null);
1067 // only set default if it has not yet been set
1068 if (c == null || c.getCount() == 0) {
1069 stmt = db.compileStatement("INSERT INTO system(name,value)"
1070 + " VALUES(?,?);");
1071 loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED,
1072 R.bool.def_lockscreen_disabled);
1073 }
1074 db.setTransactionSuccessful();
1075 } finally {
1076 db.endTransaction();
1077 if (c != null) c.close();
1078 if (stmt != null) stmt.close();
1079 }
1080 upgradeVersion = 76;
1081 }
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001082
Eric Laurentbffc3d12012-05-07 17:43:49 -07001083 /************* The following are Jelly Bean changes ************/
1084
1085 if (upgradeVersion == 76) {
1086 // Removed VIBRATE_IN_SILENT setting
1087 db.beginTransaction();
1088 try {
1089 db.execSQL("DELETE FROM system WHERE name='"
1090 + Settings.System.VIBRATE_IN_SILENT + "'");
1091 db.setTransactionSuccessful();
1092 } finally {
1093 db.endTransaction();
1094 }
1095
1096 upgradeVersion = 77;
1097 }
1098
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001099 if (upgradeVersion == 77) {
1100 // Introduce "vibrate when ringing" setting
1101 loadVibrateWhenRingingSetting(db);
1102
1103 upgradeVersion = 78;
1104 }
Eric Laurentbffc3d12012-05-07 17:43:49 -07001105
alanv3a67eb32012-06-22 10:47:28 -07001106 if (upgradeVersion == 78) {
1107 // The JavaScript based screen-reader URL changes in JellyBean.
1108 db.beginTransaction();
1109 SQLiteStatement stmt = null;
1110 try {
1111 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1112 + " VALUES(?,?);");
1113 loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_SCREEN_READER_URL,
1114 R.string.def_accessibility_screen_reader_url);
1115 db.setTransactionSuccessful();
1116 } finally {
1117 db.endTransaction();
1118 if (stmt != null) stmt.close();
1119 }
1120 upgradeVersion = 79;
1121 }
1122
Svetoslav Ganov86317012012-08-15 22:13:00 -07001123 if (upgradeVersion == 79) {
1124 // Before touch exploration was a global setting controlled by the user
1125 // via the UI. However, if the enabled accessibility services do not
1126 // handle touch exploration mode, enabling it makes no sense. Therefore,
1127 // now the services request touch exploration mode and the user is
1128 // presented with a dialog to allow that and if she does we store that
1129 // in the database. As a result of this change a user that has enabled
1130 // accessibility, touch exploration, and some accessibility services
1131 // may lose touch exploration state, thus rendering the device useless
1132 // unless sighted help is provided, since the enabled service(s) are
1133 // not in the list of services to which the user granted a permission
1134 // to put the device in touch explore mode. Here we are allowing all
1135 // enabled accessibility services to toggle touch exploration provided
1136 // accessibility and touch exploration are enabled and no services can
1137 // toggle touch exploration. Note that the user has already manually
1138 // enabled the services and touch exploration which means the she has
1139 // given consent to have these services work in touch exploration mode.
Christopher Tate06efb532012-08-24 15:29:27 -07001140 final boolean accessibilityEnabled = getIntValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001141 Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;
Christopher Tate06efb532012-08-24 15:29:27 -07001142 final boolean touchExplorationEnabled = getIntValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001143 Settings.Secure.TOUCH_EXPLORATION_ENABLED, 0) == 1;
1144 if (accessibilityEnabled && touchExplorationEnabled) {
Christopher Tate06efb532012-08-24 15:29:27 -07001145 String enabledServices = getStringValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001146 Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "");
Christopher Tate06efb532012-08-24 15:29:27 -07001147 String touchExplorationGrantedServices = getStringValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001148 Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, "");
1149 if (TextUtils.isEmpty(touchExplorationGrantedServices)
1150 && !TextUtils.isEmpty(enabledServices)) {
1151 SQLiteStatement stmt = null;
1152 try {
1153 db.beginTransaction();
1154 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1155 + " VALUES(?,?);");
1156 loadSetting(stmt,
1157 Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES,
1158 enabledServices);
1159 db.setTransactionSuccessful();
1160 } finally {
1161 db.endTransaction();
1162 if (stmt != null) stmt.close();
1163 }
1164 }
1165 }
1166 upgradeVersion = 80;
1167 }
1168
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001169 // vvv Jelly Bean MR1 changes begin here vvv
1170
Svetoslav Ganovca34bcf2012-08-16 12:22:23 -07001171 if (upgradeVersion == 80) {
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001172 // update screensaver settings
1173 db.beginTransaction();
1174 SQLiteStatement stmt = null;
1175 try {
1176 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1177 + " VALUES(?,?);");
1178 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED,
John Spurlocked108f32012-10-18 16:49:24 -04001179 com.android.internal.R.bool.config_dreamsEnabledByDefault);
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001180 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
John Spurlocked108f32012-10-18 16:49:24 -04001181 com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04001182 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
John Spurlocked108f32012-10-18 16:49:24 -04001183 com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04001184 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_COMPONENTS,
John Spurlocked108f32012-10-18 16:49:24 -04001185 com.android.internal.R.string.config_dreamsDefaultComponent);
1186 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT,
1187 com.android.internal.R.string.config_dreamsDefaultComponent);
Christopher Tate06efb532012-08-24 15:29:27 -07001188
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001189 db.setTransactionSuccessful();
1190 } finally {
1191 db.endTransaction();
1192 if (stmt != null) stmt.close();
1193 }
Svetoslav Ganovca34bcf2012-08-16 12:22:23 -07001194 upgradeVersion = 81;
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001195 }
1196
rich cannings16e119e2012-09-06 12:04:37 -07001197 if (upgradeVersion == 81) {
1198 // Add package verification setting
1199 db.beginTransaction();
1200 SQLiteStatement stmt = null;
1201 try {
1202 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1203 + " VALUES(?,?);");
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001204 loadBooleanSetting(stmt, Settings.Global.PACKAGE_VERIFIER_ENABLE,
rich cannings16e119e2012-09-06 12:04:37 -07001205 R.bool.def_package_verifier_enable);
1206 db.setTransactionSuccessful();
1207 } finally {
1208 db.endTransaction();
1209 if (stmt != null) stmt.close();
1210 }
1211 upgradeVersion = 82;
1212 }
1213
Christopher Tate06efb532012-08-24 15:29:27 -07001214 if (upgradeVersion == 82) {
1215 // Move to per-user settings dbs
Christopher Tate59c5bee2012-09-13 14:38:33 -07001216 if (mUserHandle == UserHandle.USER_OWNER) {
Christopher Tate06efb532012-08-24 15:29:27 -07001217
Christopher Tate59c5bee2012-09-13 14:38:33 -07001218 db.beginTransaction();
1219 SQLiteStatement stmt = null;
1220 try {
1221 // Migrate now-global settings. Note that this happens before
1222 // new users can be created.
1223 createGlobalTable(db);
1224 String[] settingsToMove = hashsetToStringArray(SettingsProvider.sSystemGlobalKeys);
1225 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, false);
1226 settingsToMove = hashsetToStringArray(SettingsProvider.sSecureGlobalKeys);
1227 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, false);
1228
1229 db.setTransactionSuccessful();
1230 } finally {
1231 db.endTransaction();
1232 if (stmt != null) stmt.close();
1233 }
Christopher Tate06efb532012-08-24 15:29:27 -07001234 }
1235 upgradeVersion = 83;
1236 }
1237
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001238 if (upgradeVersion == 83) {
1239 // 1. Setting whether screen magnification is enabled.
1240 // 2. Setting for screen magnification scale.
1241 // 3. Setting for screen magnification auto update.
1242 db.beginTransaction();
1243 SQLiteStatement stmt = null;
1244 try {
1245 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
1246 loadBooleanSetting(stmt,
1247 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
1248 R.bool.def_accessibility_display_magnification_enabled);
1249 stmt.close();
1250 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
1251 loadFractionSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
1252 R.fraction.def_accessibility_display_magnification_scale, 1);
1253 stmt.close();
1254 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
1255 loadBooleanSetting(stmt,
1256 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_AUTO_UPDATE,
1257 R.bool.def_accessibility_display_magnification_auto_update);
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001258
1259 db.setTransactionSuccessful();
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001260 } finally {
1261 db.endTransaction();
1262 if (stmt != null) stmt.close();
1263 }
1264 upgradeVersion = 84;
1265 }
1266
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001267 if (upgradeVersion == 84) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001268 if (mUserHandle == UserHandle.USER_OWNER) {
1269 db.beginTransaction();
1270 SQLiteStatement stmt = null;
1271 try {
1272 // Patch up the slightly-wrong key migration from 82 -> 83 for those
1273 // devices that missed it, ignoring if the move is redundant
1274 String[] settingsToMove = {
1275 Settings.Secure.ADB_ENABLED,
1276 Settings.Secure.BLUETOOTH_ON,
1277 Settings.Secure.DATA_ROAMING,
1278 Settings.Secure.DEVICE_PROVISIONED,
1279 Settings.Secure.INSTALL_NON_MARKET_APPS,
1280 Settings.Secure.USB_MASS_STORAGE_ENABLED
1281 };
1282 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1283 db.setTransactionSuccessful();
1284 } finally {
1285 db.endTransaction();
1286 if (stmt != null) stmt.close();
1287 }
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001288 }
1289 upgradeVersion = 85;
1290 }
1291
Christopher Tate92198742012-09-07 12:00:13 -07001292 if (upgradeVersion == 85) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001293 if (mUserHandle == UserHandle.USER_OWNER) {
1294 db.beginTransaction();
1295 try {
1296 // Fix up the migration, ignoring already-migrated elements, to snap up to
1297 // date with new changes to the set of global versus system/secure settings
1298 String[] settingsToMove = { Settings.System.STAY_ON_WHILE_PLUGGED_IN };
1299 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
Christopher Tate92198742012-09-07 12:00:13 -07001300
Christopher Tate59c5bee2012-09-13 14:38:33 -07001301 db.setTransactionSuccessful();
1302 } finally {
1303 db.endTransaction();
1304 }
Christopher Tate92198742012-09-07 12:00:13 -07001305 }
1306 upgradeVersion = 86;
1307 }
1308
rich cannings4d8fc792012-09-07 14:43:43 -07001309 if (upgradeVersion == 86) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001310 if (mUserHandle == UserHandle.USER_OWNER) {
1311 db.beginTransaction();
1312 try {
1313 String[] settingsToMove = {
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001314 Settings.Global.PACKAGE_VERIFIER_ENABLE,
1315 Settings.Global.PACKAGE_VERIFIER_TIMEOUT,
1316 Settings.Global.PACKAGE_VERIFIER_DEFAULT_RESPONSE
Christopher Tate59c5bee2012-09-13 14:38:33 -07001317 };
1318 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
rich cannings4d8fc792012-09-07 14:43:43 -07001319
Christopher Tate59c5bee2012-09-13 14:38:33 -07001320 db.setTransactionSuccessful();
1321 } finally {
1322 db.endTransaction();
1323 }
rich cannings4d8fc792012-09-07 14:43:43 -07001324 }
1325 upgradeVersion = 87;
1326 }
1327
Christopher Tatec868b642012-09-12 17:41:04 -07001328 if (upgradeVersion == 87) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001329 if (mUserHandle == UserHandle.USER_OWNER) {
1330 db.beginTransaction();
1331 try {
1332 String[] settingsToMove = {
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001333 Settings.Global.DATA_STALL_ALARM_NON_AGGRESSIVE_DELAY_IN_MS,
1334 Settings.Global.DATA_STALL_ALARM_AGGRESSIVE_DELAY_IN_MS,
1335 Settings.Global.GPRS_REGISTER_CHECK_PERIOD_MS
Christopher Tate59c5bee2012-09-13 14:38:33 -07001336 };
1337 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
Christopher Tatec868b642012-09-12 17:41:04 -07001338
Christopher Tate59c5bee2012-09-13 14:38:33 -07001339 db.setTransactionSuccessful();
1340 } finally {
1341 db.endTransaction();
1342 }
Christopher Tatec868b642012-09-12 17:41:04 -07001343 }
1344 upgradeVersion = 88;
1345 }
1346
Jeff Sharkey625239a2012-09-26 22:03:49 -07001347 if (upgradeVersion == 88) {
1348 if (mUserHandle == UserHandle.USER_OWNER) {
1349 db.beginTransaction();
1350 try {
1351 String[] settingsToMove = {
1352 Settings.Global.BATTERY_DISCHARGE_DURATION_THRESHOLD,
1353 Settings.Global.BATTERY_DISCHARGE_THRESHOLD,
1354 Settings.Global.SEND_ACTION_APP_ERROR,
1355 Settings.Global.DROPBOX_AGE_SECONDS,
1356 Settings.Global.DROPBOX_MAX_FILES,
1357 Settings.Global.DROPBOX_QUOTA_KB,
1358 Settings.Global.DROPBOX_QUOTA_PERCENT,
1359 Settings.Global.DROPBOX_RESERVE_PERCENT,
1360 Settings.Global.DROPBOX_TAG_PREFIX,
1361 Settings.Global.ERROR_LOGCAT_PREFIX,
1362 Settings.Global.SYS_FREE_STORAGE_LOG_INTERVAL,
1363 Settings.Global.DISK_FREE_CHANGE_REPORTING_THRESHOLD,
1364 Settings.Global.SYS_STORAGE_THRESHOLD_PERCENTAGE,
1365 Settings.Global.SYS_STORAGE_THRESHOLD_MAX_BYTES,
1366 Settings.Global.SYS_STORAGE_FULL_THRESHOLD_BYTES,
1367 Settings.Global.SYNC_MAX_RETRY_DELAY_IN_SECONDS,
1368 Settings.Global.CONNECTIVITY_CHANGE_DELAY,
1369 Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED,
1370 Settings.Global.CAPTIVE_PORTAL_SERVER,
1371 Settings.Global.NSD_ON,
1372 Settings.Global.SET_INSTALL_LOCATION,
1373 Settings.Global.DEFAULT_INSTALL_LOCATION,
1374 Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY,
1375 Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY,
1376 Settings.Global.READ_EXTERNAL_STORAGE_ENFORCED_DEFAULT,
1377 Settings.Global.HTTP_PROXY,
1378 Settings.Global.GLOBAL_HTTP_PROXY_HOST,
1379 Settings.Global.GLOBAL_HTTP_PROXY_PORT,
1380 Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST,
1381 Settings.Global.SET_GLOBAL_HTTP_PROXY,
1382 Settings.Global.DEFAULT_DNS_SERVER,
1383 };
1384 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1385 db.setTransactionSuccessful();
1386 } finally {
1387 db.endTransaction();
1388 }
1389 }
1390 upgradeVersion = 89;
1391 }
1392
Jeff Sharkey0ac10282012-10-01 12:50:22 -07001393 if (upgradeVersion == 89) {
1394 if (mUserHandle == UserHandle.USER_OWNER) {
1395 db.beginTransaction();
1396 try {
1397 String[] prefixesToMove = {
1398 Settings.Global.BLUETOOTH_HEADSET_PRIORITY_PREFIX,
1399 Settings.Global.BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX,
1400 Settings.Global.BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX,
1401 };
1402
1403 movePrefixedSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, prefixesToMove);
1404
1405 db.setTransactionSuccessful();
1406 } finally {
1407 db.endTransaction();
1408 }
1409 }
1410 upgradeVersion = 90;
1411 }
1412
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001413 if (upgradeVersion == 90) {
1414 if (mUserHandle == UserHandle.USER_OWNER) {
1415 db.beginTransaction();
1416 try {
1417 String[] systemToGlobal = {
1418 Settings.Global.WINDOW_ANIMATION_SCALE,
1419 Settings.Global.TRANSITION_ANIMATION_SCALE,
1420 Settings.Global.ANIMATOR_DURATION_SCALE,
1421 Settings.Global.FANCY_IME_ANIMATIONS,
1422 Settings.Global.COMPATIBILITY_MODE,
1423 Settings.Global.EMERGENCY_TONE,
1424 Settings.Global.CALL_AUTO_RETRY,
1425 Settings.Global.DEBUG_APP,
1426 Settings.Global.WAIT_FOR_DEBUGGER,
1427 Settings.Global.SHOW_PROCESSES,
1428 Settings.Global.ALWAYS_FINISH_ACTIVITIES,
1429 };
1430 String[] secureToGlobal = {
1431 Settings.Global.PREFERRED_NETWORK_MODE,
1432 Settings.Global.PREFERRED_CDMA_SUBSCRIPTION,
1433 };
1434
1435 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, systemToGlobal, true);
1436 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, secureToGlobal, true);
1437
1438 db.setTransactionSuccessful();
1439 } finally {
1440 db.endTransaction();
1441 }
1442 }
1443 upgradeVersion = 91;
1444 }
1445
Eric Laurent55b02222012-10-03 11:56:23 -07001446 if (upgradeVersion == 91) {
1447 if (mUserHandle == UserHandle.USER_OWNER) {
1448 db.beginTransaction();
1449 try {
1450 // Move ringer mode from system to global settings
Amith Yamasani531c2372012-10-08 14:43:20 -07001451 String[] settingsToMove = { Settings.Global.MODE_RINGER };
Eric Laurent55b02222012-10-03 11:56:23 -07001452 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
1453
1454 db.setTransactionSuccessful();
1455 } finally {
1456 db.endTransaction();
1457 }
1458 }
1459 upgradeVersion = 92;
1460 }
1461
John Spurlock7f1c2482012-10-05 11:15:28 -04001462 if (upgradeVersion == 92) {
1463 SQLiteStatement stmt = null;
1464 try {
1465 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1466 + " VALUES(?,?);");
1467 if (mUserHandle == UserHandle.USER_OWNER) {
1468 // consider existing primary users to have made it through user setup
1469 // if the globally-scoped device-provisioned bit is set
1470 // (indicating they already made it through setup as primary)
1471 int deviceProvisioned = getIntValueFromTable(db, TABLE_GLOBAL,
1472 Settings.Global.DEVICE_PROVISIONED, 0);
1473 loadSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
1474 deviceProvisioned);
1475 } else {
1476 // otherwise use the default
1477 loadBooleanSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
1478 R.bool.def_user_setup_complete);
1479 }
1480 } finally {
1481 if (stmt != null) stmt.close();
1482 }
1483 upgradeVersion = 93;
1484 }
1485
Amith Yamasani531c2372012-10-08 14:43:20 -07001486 if (upgradeVersion == 93) {
1487 // Redo this step, since somehow it didn't work the first time for some users
1488 if (mUserHandle == UserHandle.USER_OWNER) {
1489 db.beginTransaction();
Amith Yamasani531c2372012-10-08 14:43:20 -07001490 try {
1491 // Migrate now-global settings
1492 String[] settingsToMove = hashsetToStringArray(SettingsProvider.sSystemGlobalKeys);
1493 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
1494 settingsToMove = hashsetToStringArray(SettingsProvider.sSecureGlobalKeys);
1495 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1496
1497 db.setTransactionSuccessful();
1498 } finally {
1499 db.endTransaction();
Amith Yamasani531c2372012-10-08 14:43:20 -07001500 }
1501 }
1502 upgradeVersion = 94;
1503 }
1504
Jeff Brown84e27562012-12-07 13:56:34 -08001505 if (upgradeVersion == 94) {
1506 // Add wireless charging started sound setting
Amith Yamasani2d43fab2012-12-12 09:52:26 -08001507 if (mUserHandle == UserHandle.USER_OWNER) {
1508 db.beginTransaction();
1509 SQLiteStatement stmt = null;
1510 try {
1511 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1512 + " VALUES(?,?);");
1513 loadStringSetting(stmt, Settings.Global.WIRELESS_CHARGING_STARTED_SOUND,
1514 R.string.def_wireless_charging_started_sound);
1515 db.setTransactionSuccessful();
1516 } finally {
1517 db.endTransaction();
1518 if (stmt != null) stmt.close();
1519 }
Jeff Brown84e27562012-12-07 13:56:34 -08001520 }
1521 upgradeVersion = 95;
1522 }
1523
Christopher Tate58f41ec2013-01-11 15:40:36 -08001524 if (upgradeVersion == 95) {
1525 if (mUserHandle == UserHandle.USER_OWNER) {
1526 db.beginTransaction();
1527 try {
1528 String[] settingsToMove = { Settings.Global.BUGREPORT_IN_POWER_MENU };
1529 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1530 db.setTransactionSuccessful();
1531 } finally {
1532 db.endTransaction();
1533 }
1534 }
1535 upgradeVersion = 96;
1536 }
1537
Mike Clerond1ed3ce2013-02-01 18:36:41 +00001538 if (upgradeVersion == 96) {
Svetoslav Ganov447d9462013-02-01 19:46:20 +00001539 // NOP bump due to a reverted change that some people got on upgrade.
Mike Clerond1ed3ce2013-02-01 18:36:41 +00001540 upgradeVersion = 97;
1541 }
1542
Daniel Sandler1c7fa482010-03-10 09:45:01 -05001543 // *** Remember to update DATABASE_VERSION above!
1544
1545 if (upgradeVersion != currentVersion) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001546 Log.w(TAG, "Got stuck trying to upgrade from version " + upgradeVersion
1547 + ", must wipe the settings provider");
Christopher Tate06efb532012-08-24 15:29:27 -07001548 db.execSQL("DROP TABLE IF EXISTS global");
1549 db.execSQL("DROP TABLE IF EXISTS globalIndex1");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001550 db.execSQL("DROP TABLE IF EXISTS system");
1551 db.execSQL("DROP INDEX IF EXISTS systemIndex1");
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001552 db.execSQL("DROP TABLE IF EXISTS secure");
1553 db.execSQL("DROP INDEX IF EXISTS secureIndex1");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001554 db.execSQL("DROP TABLE IF EXISTS gservices");
1555 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1");
1556 db.execSQL("DROP TABLE IF EXISTS bluetooth_devices");
1557 db.execSQL("DROP TABLE IF EXISTS bookmarks");
1558 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex1");
1559 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex2");
1560 db.execSQL("DROP TABLE IF EXISTS favorites");
1561 onCreate(db);
Jim Miller61766772010-02-12 14:56:49 -08001562
1563 // Added for diagnosing settings.db wipes after the fact
1564 String wipeReason = oldVersion + "/" + upgradeVersion + "/" + currentVersion;
1565 db.execSQL("INSERT INTO secure(name,value) values('" +
1566 "wiped_db_reason" + "','" + wipeReason + "');");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001567 }
1568 }
1569
Christopher Tatea96798e42012-09-06 19:07:19 -07001570 private String[] hashsetToStringArray(HashSet<String> set) {
1571 String[] array = new String[set.size()];
1572 return set.toArray(array);
1573 }
1574
Christopher Tate06efb532012-08-24 15:29:27 -07001575 private void moveSettingsToNewTable(SQLiteDatabase db,
1576 String sourceTable, String destTable,
Christopher Tate92198742012-09-07 12:00:13 -07001577 String[] settingsToMove, boolean doIgnore) {
Christopher Tate06efb532012-08-24 15:29:27 -07001578 // Copy settings values from the source table to the dest, and remove from the source
Amith Yamasani156c4352010-03-05 17:10:03 -08001579 SQLiteStatement insertStmt = null;
1580 SQLiteStatement deleteStmt = null;
1581
1582 db.beginTransaction();
1583 try {
Christopher Tate92198742012-09-07 12:00:13 -07001584 insertStmt = db.compileStatement("INSERT "
1585 + (doIgnore ? " OR IGNORE " : "")
1586 + " INTO " + destTable + " (name,value) SELECT name,value FROM "
Christopher Tate06efb532012-08-24 15:29:27 -07001587 + sourceTable + " WHERE name=?");
1588 deleteStmt = db.compileStatement("DELETE FROM " + sourceTable + " WHERE name=?");
Amith Yamasani156c4352010-03-05 17:10:03 -08001589
1590 for (String setting : settingsToMove) {
1591 insertStmt.bindString(1, setting);
1592 insertStmt.execute();
1593
1594 deleteStmt.bindString(1, setting);
1595 deleteStmt.execute();
1596 }
1597 db.setTransactionSuccessful();
1598 } finally {
1599 db.endTransaction();
1600 if (insertStmt != null) {
1601 insertStmt.close();
1602 }
1603 if (deleteStmt != null) {
1604 deleteStmt.close();
1605 }
1606 }
1607 }
1608
Jeff Sharkey0ac10282012-10-01 12:50:22 -07001609 /**
1610 * Move any settings with the given prefixes from the source table to the
1611 * destination table.
1612 */
1613 private void movePrefixedSettingsToNewTable(
1614 SQLiteDatabase db, String sourceTable, String destTable, String[] prefixesToMove) {
1615 SQLiteStatement insertStmt = null;
1616 SQLiteStatement deleteStmt = null;
1617
1618 db.beginTransaction();
1619 try {
1620 insertStmt = db.compileStatement("INSERT INTO " + destTable
1621 + " (name,value) SELECT name,value FROM " + sourceTable
1622 + " WHERE substr(name,0,?)=?");
1623 deleteStmt = db.compileStatement(
1624 "DELETE FROM " + sourceTable + " WHERE substr(name,0,?)=?");
1625
1626 for (String prefix : prefixesToMove) {
1627 insertStmt.bindLong(1, prefix.length() + 1);
1628 insertStmt.bindString(2, prefix);
1629 insertStmt.execute();
1630
1631 deleteStmt.bindLong(1, prefix.length() + 1);
1632 deleteStmt.bindString(2, prefix);
1633 deleteStmt.execute();
1634 }
1635 db.setTransactionSuccessful();
1636 } finally {
1637 db.endTransaction();
1638 if (insertStmt != null) {
1639 insertStmt.close();
1640 }
1641 if (deleteStmt != null) {
1642 deleteStmt.close();
1643 }
1644 }
1645 }
1646
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001647 private void upgradeLockPatternLocation(SQLiteDatabase db) {
Christopher Tate06efb532012-08-24 15:29:27 -07001648 Cursor c = db.query(TABLE_SYSTEM, new String[] {"_id", "value"}, "name='lock_pattern'",
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001649 null, null, null, null);
1650 if (c.getCount() > 0) {
1651 c.moveToFirst();
1652 String lockPattern = c.getString(1);
1653 if (!TextUtils.isEmpty(lockPattern)) {
1654 // Convert lock pattern
1655 try {
Jim Miller31f90b62010-01-20 13:35:20 -08001656 LockPatternUtils lpu = new LockPatternUtils(mContext);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07001657 List<LockPatternView.Cell> cellPattern =
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001658 LockPatternUtils.stringToPattern(lockPattern);
1659 lpu.saveLockPattern(cellPattern);
1660 } catch (IllegalArgumentException e) {
1661 // Don't want corrupted lock pattern to hang the reboot process
1662 }
1663 }
1664 c.close();
Christopher Tate06efb532012-08-24 15:29:27 -07001665 db.delete(TABLE_SYSTEM, "name='lock_pattern'", null);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001666 } else {
1667 c.close();
1668 }
1669 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001670
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07001671 private void upgradeScreenTimeoutFromNever(SQLiteDatabase db) {
1672 // See if the timeout is -1 (for "Never").
Christopher Tate06efb532012-08-24 15:29:27 -07001673 Cursor c = db.query(TABLE_SYSTEM, new String[] { "_id", "value" }, "name=? AND value=?",
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07001674 new String[] { Settings.System.SCREEN_OFF_TIMEOUT, "-1" },
1675 null, null, null);
1676
1677 SQLiteStatement stmt = null;
1678 if (c.getCount() > 0) {
1679 c.close();
1680 try {
1681 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1682 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001683
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07001684 // Set the timeout to 30 minutes in milliseconds
Amith Yamasanicd66caf2010-04-12 15:49:12 -07001685 loadSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
1686 Integer.toString(30 * 60 * 1000));
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07001687 } finally {
1688 if (stmt != null) stmt.close();
1689 }
1690 } else {
1691 c.close();
1692 }
1693 }
1694
Amith Yamasani398c83c2011-12-13 10:38:47 -08001695 private void upgradeVibrateSettingFromNone(SQLiteDatabase db) {
1696 int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON, 0);
1697 // If the ringer vibrate value is invalid, set it to the default
1698 if ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_OFF) {
1699 vibrateSetting = AudioService.getValueForVibrateSetting(0,
1700 AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
1701 }
1702 // Apply the same setting to the notification vibrate value
1703 vibrateSetting = AudioService.getValueForVibrateSetting(vibrateSetting,
1704 AudioManager.VIBRATE_TYPE_NOTIFICATION, vibrateSetting);
1705
1706 SQLiteStatement stmt = null;
1707 try {
1708 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1709 + " VALUES(?,?);");
1710 loadSetting(stmt, Settings.System.VIBRATE_ON, vibrateSetting);
1711 } finally {
1712 if (stmt != null)
1713 stmt.close();
1714 }
1715 }
1716
Amith Yamasani79373f62010-11-18 16:32:48 -08001717 private void upgradeScreenTimeout(SQLiteDatabase db) {
1718 // Change screen timeout to current default
1719 db.beginTransaction();
1720 SQLiteStatement stmt = null;
1721 try {
1722 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1723 + " VALUES(?,?);");
1724 loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
1725 R.integer.def_screen_off_timeout);
1726 db.setTransactionSuccessful();
1727 } finally {
1728 db.endTransaction();
1729 if (stmt != null)
1730 stmt.close();
1731 }
1732 }
1733
Amith Yamasanif50c5112011-01-07 11:32:30 -08001734 private void upgradeAutoBrightness(SQLiteDatabase db) {
1735 db.beginTransaction();
1736 try {
1737 String value =
1738 mContext.getResources().getBoolean(
1739 R.bool.def_screen_brightness_automatic_mode) ? "1" : "0";
1740 db.execSQL("INSERT OR REPLACE INTO system(name,value) values('" +
1741 Settings.System.SCREEN_BRIGHTNESS_MODE + "','" + value + "');");
1742 db.setTransactionSuccessful();
1743 } finally {
1744 db.endTransaction();
1745 }
1746 }
1747
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001748 /**
1749 * Loads the default set of bookmarked shortcuts from an xml file.
1750 *
1751 * @param db The database to write the values into
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001752 */
Jeff Brown6651a632011-11-28 12:59:11 -08001753 private void loadBookmarks(SQLiteDatabase db) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001754 ContentValues values = new ContentValues();
1755
1756 PackageManager packageManager = mContext.getPackageManager();
Romain Guyf02811f2010-03-09 16:33:51 -08001757 try {
1758 XmlResourceParser parser = mContext.getResources().getXml(R.xml.bookmarks);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001759 XmlUtils.beginDocument(parser, "bookmarks");
1760
Romain Guyf02811f2010-03-09 16:33:51 -08001761 final int depth = parser.getDepth();
1762 int type;
1763
1764 while (((type = parser.next()) != XmlPullParser.END_TAG ||
1765 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
1766
1767 if (type != XmlPullParser.START_TAG) {
1768 continue;
1769 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001770
1771 String name = parser.getName();
1772 if (!"bookmark".equals(name)) {
1773 break;
1774 }
1775
1776 String pkg = parser.getAttributeValue(null, "package");
1777 String cls = parser.getAttributeValue(null, "class");
1778 String shortcutStr = parser.getAttributeValue(null, "shortcut");
Jeff Brown6651a632011-11-28 12:59:11 -08001779 String category = parser.getAttributeValue(null, "category");
Romain Guyf02811f2010-03-09 16:33:51 -08001780
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -07001781 int shortcutValue = shortcutStr.charAt(0);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001782 if (TextUtils.isEmpty(shortcutStr)) {
1783 Log.w(TAG, "Unable to get shortcut for: " + pkg + "/" + cls);
Jeff Brown6651a632011-11-28 12:59:11 -08001784 continue;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001785 }
Romain Guyf02811f2010-03-09 16:33:51 -08001786
Jeff Brown6651a632011-11-28 12:59:11 -08001787 final Intent intent;
1788 final String title;
1789 if (pkg != null && cls != null) {
1790 ActivityInfo info = null;
1791 ComponentName cn = new ComponentName(pkg, cls);
Romain Guyf02811f2010-03-09 16:33:51 -08001792 try {
1793 info = packageManager.getActivityInfo(cn, 0);
Jeff Brown6651a632011-11-28 12:59:11 -08001794 } catch (PackageManager.NameNotFoundException e) {
1795 String[] packages = packageManager.canonicalToCurrentPackageNames(
1796 new String[] { pkg });
1797 cn = new ComponentName(packages[0], cls);
1798 try {
1799 info = packageManager.getActivityInfo(cn, 0);
1800 } catch (PackageManager.NameNotFoundException e1) {
1801 Log.w(TAG, "Unable to add bookmark: " + pkg + "/" + cls, e);
1802 continue;
1803 }
Romain Guyf02811f2010-03-09 16:33:51 -08001804 }
Jeff Brown6651a632011-11-28 12:59:11 -08001805
1806 intent = new Intent(Intent.ACTION_MAIN, null);
1807 intent.addCategory(Intent.CATEGORY_LAUNCHER);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001808 intent.setComponent(cn);
Jeff Brown6651a632011-11-28 12:59:11 -08001809 title = info.loadLabel(packageManager).toString();
1810 } else if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08001811 intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08001812 title = "";
1813 } else {
1814 Log.w(TAG, "Unable to add bookmark for shortcut " + shortcutStr
1815 + ": missing package/class or category attributes");
1816 continue;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001817 }
Jeff Brown6651a632011-11-28 12:59:11 -08001818
1819 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1820 values.put(Settings.Bookmarks.INTENT, intent.toUri(0));
1821 values.put(Settings.Bookmarks.TITLE, title);
1822 values.put(Settings.Bookmarks.SHORTCUT, shortcutValue);
1823 db.delete("bookmarks", "shortcut = ?",
1824 new String[] { Integer.toString(shortcutValue) });
1825 db.insert("bookmarks", null, values);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001826 }
1827 } catch (XmlPullParserException e) {
1828 Log.w(TAG, "Got execption parsing bookmarks.", e);
1829 } catch (IOException e) {
1830 Log.w(TAG, "Got execption parsing bookmarks.", e);
1831 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001832 }
1833
1834 /**
1835 * Loads the default volume levels. It is actually inserting the index of
1836 * the volume array for each of the volume controls.
1837 *
1838 * @param db the database to insert the volume levels into
1839 */
1840 private void loadVolumeLevels(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07001841 SQLiteStatement stmt = null;
1842 try {
1843 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
1844 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001845
Vasu Nori89206fdb2010-03-22 10:37:03 -07001846 loadSetting(stmt, Settings.System.VOLUME_MUSIC,
1847 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_MUSIC]);
1848 loadSetting(stmt, Settings.System.VOLUME_RING,
1849 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_RING]);
1850 loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
1851 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_SYSTEM]);
1852 loadSetting(
1853 stmt,
1854 Settings.System.VOLUME_VOICE,
1855 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_VOICE_CALL]);
1856 loadSetting(stmt, Settings.System.VOLUME_ALARM,
1857 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_ALARM]);
1858 loadSetting(
1859 stmt,
1860 Settings.System.VOLUME_NOTIFICATION,
1861 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_NOTIFICATION]);
1862 loadSetting(
1863 stmt,
1864 Settings.System.VOLUME_BLUETOOTH_SCO,
1865 AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_BLUETOOTH_SCO]);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001866
Eric Laurentc1d41662011-07-19 11:21:13 -07001867 // By default:
1868 // - ringtones, notification, system and music streams are affected by ringer mode
1869 // on non voice capable devices (tablets)
1870 // - ringtones, notification and system streams are affected by ringer mode
1871 // on voice capable devices (phones)
1872 int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
1873 (1 << AudioManager.STREAM_NOTIFICATION) |
1874 (1 << AudioManager.STREAM_SYSTEM) |
1875 (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
1876 if (!mContext.getResources().getBoolean(
1877 com.android.internal.R.bool.config_voice_capable)) {
1878 ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
1879 }
Vasu Nori89206fdb2010-03-22 10:37:03 -07001880 loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
Eric Laurentc1d41662011-07-19 11:21:13 -07001881 ringerModeAffectedStreams);
1882
Vasu Nori89206fdb2010-03-22 10:37:03 -07001883 loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
1884 ((1 << AudioManager.STREAM_MUSIC) |
1885 (1 << AudioManager.STREAM_RING) |
1886 (1 << AudioManager.STREAM_NOTIFICATION) |
1887 (1 << AudioManager.STREAM_SYSTEM)));
1888 } finally {
1889 if (stmt != null) stmt.close();
1890 }
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001891
1892 loadVibrateWhenRingingSetting(db);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001893 }
1894
1895 private void loadVibrateSetting(SQLiteDatabase db, boolean deleteOld) {
1896 if (deleteOld) {
1897 db.execSQL("DELETE FROM system WHERE name='" + Settings.System.VIBRATE_ON + "'");
1898 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07001899
Vasu Nori89206fdb2010-03-22 10:37:03 -07001900 SQLiteStatement stmt = null;
1901 try {
1902 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
1903 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001904
Amith Yamasani5cd15002011-11-16 11:19:48 -08001905 // Vibrate on by default for ringer, on for notification
Vasu Nori89206fdb2010-03-22 10:37:03 -07001906 int vibrate = 0;
1907 vibrate = AudioService.getValueForVibrateSetting(vibrate,
Amith Yamasani5cd15002011-11-16 11:19:48 -08001908 AudioManager.VIBRATE_TYPE_NOTIFICATION,
1909 AudioManager.VIBRATE_SETTING_ONLY_SILENT);
Joe Onorato89320202010-06-24 17:49:44 -07001910 vibrate |= AudioService.getValueForVibrateSetting(vibrate,
Amith Yamasani5cd15002011-11-16 11:19:48 -08001911 AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
Vasu Nori89206fdb2010-03-22 10:37:03 -07001912 loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate);
1913 } finally {
1914 if (stmt != null) stmt.close();
1915 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001916 }
1917
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001918 private void loadVibrateWhenRingingSetting(SQLiteDatabase db) {
1919 // The default should be off. VIBRATE_SETTING_ONLY_SILENT should also be ignored here.
1920 // Phone app should separately check whether AudioManager#getRingerMode() returns
1921 // RINGER_MODE_VIBRATE, with which the device should vibrate anyway.
1922 int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON,
1923 AudioManager.VIBRATE_SETTING_OFF);
1924 boolean vibrateWhenRinging = ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_ON);
1925
1926 SQLiteStatement stmt = null;
1927 try {
1928 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
1929 + " VALUES(?,?);");
1930 loadSetting(stmt, Settings.System.VIBRATE_WHEN_RINGING, vibrateWhenRinging ? 1 : 0);
1931 } finally {
1932 if (stmt != null) stmt.close();
1933 }
1934 }
1935
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001936 private void loadSettings(SQLiteDatabase db) {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001937 loadSystemSettings(db);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07001938 loadSecureSettings(db);
Christopher Tate06efb532012-08-24 15:29:27 -07001939 // The global table only exists for the 'owner' user
1940 if (mUserHandle == UserHandle.USER_OWNER) {
1941 loadGlobalSettings(db);
1942 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001943 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07001944
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001945 private void loadSystemSettings(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07001946 SQLiteStatement stmt = null;
1947 try {
1948 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
1949 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001950
Vasu Nori89206fdb2010-03-22 10:37:03 -07001951 loadBooleanSetting(stmt, Settings.System.DIM_SCREEN,
1952 R.bool.def_dim_screen);
Vasu Nori89206fdb2010-03-22 10:37:03 -07001953 loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
1954 R.integer.def_screen_off_timeout);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001955
Vasu Nori89206fdb2010-03-22 10:37:03 -07001956 // Set default cdma DTMF type
1957 loadSetting(stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001958
Vasu Nori89206fdb2010-03-22 10:37:03 -07001959 // Set default hearing aid
1960 loadSetting(stmt, Settings.System.HEARING_AID, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001961
Vasu Nori89206fdb2010-03-22 10:37:03 -07001962 // Set default tty mode
1963 loadSetting(stmt, Settings.System.TTY_MODE, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001964
Vasu Nori89206fdb2010-03-22 10:37:03 -07001965 loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS,
1966 R.integer.def_screen_brightness);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001967
Vasu Nori89206fdb2010-03-22 10:37:03 -07001968 loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE,
1969 R.bool.def_screen_brightness_automatic_mode);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001970
Vasu Nori89206fdb2010-03-22 10:37:03 -07001971 loadDefaultAnimationSettings(stmt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001972
Vasu Nori89206fdb2010-03-22 10:37:03 -07001973 loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION,
1974 R.bool.def_accelerometer_rotation);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001975
Vasu Nori89206fdb2010-03-22 10:37:03 -07001976 loadDefaultHapticSettings(stmt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001977
Vasu Nori89206fdb2010-03-22 10:37:03 -07001978 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
1979 R.bool.def_notification_pulse);
Amith Yamasani42722bf2011-07-22 10:34:27 -07001980
Vasu Nori89206fdb2010-03-22 10:37:03 -07001981 loadUISoundEffectsSettings(stmt);
Amith Yamasani42722bf2011-07-22 10:34:27 -07001982
Jeff Brown1a84fd12011-06-02 01:26:32 -07001983 loadIntegerSetting(stmt, Settings.System.POINTER_SPEED,
1984 R.integer.def_pointer_speed);
Vasu Nori89206fdb2010-03-22 10:37:03 -07001985 } finally {
1986 if (stmt != null) stmt.close();
1987 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08001988 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07001989
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05001990 private void loadUISoundEffectsSettings(SQLiteStatement stmt) {
Amith Yamasani42722bf2011-07-22 10:34:27 -07001991 loadBooleanSetting(stmt, Settings.System.DTMF_TONE_WHEN_DIALING,
1992 R.bool.def_dtmf_tones_enabled);
1993 loadBooleanSetting(stmt, Settings.System.SOUND_EFFECTS_ENABLED,
1994 R.bool.def_sound_effects_enabled);
1995 loadBooleanSetting(stmt, Settings.System.HAPTIC_FEEDBACK_ENABLED,
1996 R.bool.def_haptic_feedback);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05001997
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05001998 loadIntegerSetting(stmt, Settings.System.LOCKSCREEN_SOUNDS_ENABLED,
1999 R.integer.def_lockscreen_sounds_enabled);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002000 }
2001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002002 private void loadDefaultAnimationSettings(SQLiteStatement stmt) {
2003 loadFractionSetting(stmt, Settings.System.WINDOW_ANIMATION_SCALE,
2004 R.fraction.def_window_animation_scale, 1);
2005 loadFractionSetting(stmt, Settings.System.TRANSITION_ANIMATION_SCALE,
2006 R.fraction.def_window_transition_scale, 1);
2007 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002008
Dianne Hackborn075a18d2009-09-26 12:43:19 -07002009 private void loadDefaultHapticSettings(SQLiteStatement stmt) {
2010 loadBooleanSetting(stmt, Settings.System.HAPTIC_FEEDBACK_ENABLED,
2011 R.bool.def_haptic_feedback);
2012 }
2013
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002014 private void loadSecureSettings(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07002015 SQLiteStatement stmt = null;
2016 try {
2017 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
2018 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002019
Vasu Nori89206fdb2010-03-22 10:37:03 -07002020 loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
2021 R.string.def_location_providers_allowed);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002022
Vasu Nori89206fdb2010-03-22 10:37:03 -07002023 String wifiWatchList = SystemProperties.get("ro.com.android.wifi-watchlist");
2024 if (!TextUtils.isEmpty(wifiWatchList)) {
2025 loadSetting(stmt, Settings.Secure.WIFI_WATCHDOG_WATCH_LIST, wifiWatchList);
2026 }
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002027
Vasu Nori89206fdb2010-03-22 10:37:03 -07002028 // Don't do this. The SystemServer will initialize ADB_ENABLED from a
2029 // persistent system property instead.
2030 //loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002031
Vasu Nori89206fdb2010-03-22 10:37:03 -07002032 // Allow mock locations default, based on build
2033 loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION,
2034 "1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002035
Vasu Nori89206fdb2010-03-22 10:37:03 -07002036 loadSecure35Settings(stmt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002037
Vasu Nori89206fdb2010-03-22 10:37:03 -07002038 loadBooleanSetting(stmt, Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND,
2039 R.bool.def_mount_play_notification_snd);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002040
Vasu Nori89206fdb2010-03-22 10:37:03 -07002041 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_AUTOSTART,
2042 R.bool.def_mount_ums_autostart);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002043
Vasu Nori89206fdb2010-03-22 10:37:03 -07002044 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_PROMPT,
2045 R.bool.def_mount_ums_prompt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002046
Vasu Nori89206fdb2010-03-22 10:37:03 -07002047 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED,
2048 R.bool.def_mount_ums_notify_enabled);
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -07002049
2050 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION,
2051 R.bool.def_accessibility_script_injection);
2052
2053 loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS,
2054 R.string.def_accessibility_web_content_key_bindings);
Paul Westbrookd99d0dc2011-02-01 14:26:16 -08002055
Svetoslav Ganov54d068e2011-03-02 12:58:40 -08002056 loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT,
2057 R.integer.def_long_press_timeout_millis);
Svetoslav Ganova28a16d2011-07-28 11:24:21 -07002058
2059 loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED,
2060 R.bool.def_touch_exploration_enabled);
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08002061
2062 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD,
2063 R.bool.def_accessibility_speak_password);
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08002064
2065 loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_SCREEN_READER_URL,
2066 R.string.def_accessibility_screen_reader_url);
Mike Lockwood86aeb062011-10-21 13:29:58 -04002067
Amith Yamasanid1645f82012-06-12 11:53:26 -07002068 if (SystemProperties.getBoolean("ro.lockscreen.disable.default", false) == true) {
2069 loadSetting(stmt, Settings.System.LOCKSCREEN_DISABLED, "1");
2070 } else {
2071 loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED,
2072 R.bool.def_lockscreen_disabled);
2073 }
Mike Lockwood23955272011-10-21 11:22:48 -04002074
John Spurlock634471e2012-08-09 10:41:37 -04002075 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED,
John Spurlocked108f32012-10-18 16:49:24 -04002076 com.android.internal.R.bool.config_dreamsEnabledByDefault);
John Spurlock634471e2012-08-09 10:41:37 -04002077 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
John Spurlocked108f32012-10-18 16:49:24 -04002078 com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04002079 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
John Spurlocked108f32012-10-18 16:49:24 -04002080 com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04002081 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_COMPONENTS,
John Spurlocked108f32012-10-18 16:49:24 -04002082 com.android.internal.R.string.config_dreamsDefaultComponent);
John Spurlock1a868b72012-08-22 09:56:51 -04002083 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT,
John Spurlocked108f32012-10-18 16:49:24 -04002084 com.android.internal.R.string.config_dreamsDefaultComponent);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07002085
2086 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
2087 R.bool.def_accessibility_display_magnification_enabled);
2088
2089 loadFractionSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
2090 R.fraction.def_accessibility_display_magnification_scale, 1);
2091
2092 loadBooleanSetting(stmt,
2093 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_AUTO_UPDATE,
2094 R.bool.def_accessibility_display_magnification_auto_update);
John Spurlock7f1c2482012-10-05 11:15:28 -04002095
2096 loadBooleanSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
2097 R.bool.def_user_setup_complete);
Vasu Nori89206fdb2010-03-22 10:37:03 -07002098 } finally {
2099 if (stmt != null) stmt.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002100 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002101 }
2102
Dianne Hackborncf098292009-07-01 19:55:20 -07002103 private void loadSecure35Settings(SQLiteStatement stmt) {
2104 loadBooleanSetting(stmt, Settings.Secure.BACKUP_ENABLED,
2105 R.bool.def_backup_enabled);
Jim Miller31f90b62010-01-20 13:35:20 -08002106
Dianne Hackborncf098292009-07-01 19:55:20 -07002107 loadStringSetting(stmt, Settings.Secure.BACKUP_TRANSPORT,
2108 R.string.def_backup_transport);
2109 }
Jim Miller61766772010-02-12 14:56:49 -08002110
Christopher Tate06efb532012-08-24 15:29:27 -07002111 private void loadGlobalSettings(SQLiteDatabase db) {
2112 SQLiteStatement stmt = null;
2113 try {
2114 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
2115 + " VALUES(?,?);");
2116
2117 // --- Previously in 'system'
2118 loadBooleanSetting(stmt, Settings.Global.AIRPLANE_MODE_ON,
2119 R.bool.def_airplane_mode_on);
2120
2121 loadStringSetting(stmt, Settings.Global.AIRPLANE_MODE_RADIOS,
2122 R.string.def_airplane_mode_radios);
2123
2124 loadStringSetting(stmt, Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
2125 R.string.airplane_mode_toggleable_radios);
2126
2127 loadBooleanSetting(stmt, Settings.Global.ASSISTED_GPS_ENABLED,
2128 R.bool.assisted_gps_enabled);
2129
2130 loadBooleanSetting(stmt, Settings.Global.AUTO_TIME,
2131 R.bool.def_auto_time); // Sync time to NITZ
2132
2133 loadBooleanSetting(stmt, Settings.Global.AUTO_TIME_ZONE,
2134 R.bool.def_auto_time_zone); // Sync timezone to NITZ
2135
2136 loadSetting(stmt, Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
2137 ("1".equals(SystemProperties.get("ro.kernel.qemu")) ||
2138 mContext.getResources().getBoolean(R.bool.def_stay_on_while_plugged_in))
2139 ? 1 : 0);
2140
2141 loadIntegerSetting(stmt, Settings.Global.WIFI_SLEEP_POLICY,
2142 R.integer.def_wifi_sleep_policy);
2143
Eric Laurent55b02222012-10-03 11:56:23 -07002144 loadSetting(stmt, Settings.Global.MODE_RINGER,
2145 AudioManager.RINGER_MODE_NORMAL);
2146
Christopher Tate06efb532012-08-24 15:29:27 -07002147 // --- Previously in 'secure'
Christopher Tate6f5a9a92012-09-14 17:24:28 -07002148 loadBooleanSetting(stmt, Settings.Global.PACKAGE_VERIFIER_ENABLE,
2149 R.bool.def_package_verifier_enable);
2150
2151 loadBooleanSetting(stmt, Settings.Global.WIFI_ON,
2152 R.bool.def_wifi_on);
2153
2154 loadBooleanSetting(stmt, Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
2155 R.bool.def_networks_available_notification_on);
2156
Christopher Tate06efb532012-08-24 15:29:27 -07002157 loadBooleanSetting(stmt, Settings.Global.BLUETOOTH_ON,
2158 R.bool.def_bluetooth_on);
2159
2160 // Enable or disable Cell Broadcast SMS
2161 loadSetting(stmt, Settings.Global.CDMA_CELL_BROADCAST_SMS,
2162 RILConstants.CDMA_CELL_BROADCAST_SMS_DISABLED);
2163
2164 // Data roaming default, based on build
2165 loadSetting(stmt, Settings.Global.DATA_ROAMING,
2166 "true".equalsIgnoreCase(
2167 SystemProperties.get("ro.com.android.dataroaming",
2168 "false")) ? 1 : 0);
2169
2170 loadBooleanSetting(stmt, Settings.Global.DEVICE_PROVISIONED,
2171 R.bool.def_device_provisioned);
2172
2173 final int maxBytes = mContext.getResources().getInteger(
2174 R.integer.def_download_manager_max_bytes_over_mobile);
2175 if (maxBytes > 0) {
2176 loadSetting(stmt, Settings.Global.DOWNLOAD_MAX_BYTES_OVER_MOBILE,
2177 Integer.toString(maxBytes));
2178 }
2179
2180 final int recommendedMaxBytes = mContext.getResources().getInteger(
2181 R.integer.def_download_manager_recommended_max_bytes_over_mobile);
2182 if (recommendedMaxBytes > 0) {
2183 loadSetting(stmt, Settings.Global.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE,
2184 Integer.toString(recommendedMaxBytes));
2185 }
2186
2187 // Mobile Data default, based on build
2188 loadSetting(stmt, Settings.Global.MOBILE_DATA,
2189 "true".equalsIgnoreCase(
2190 SystemProperties.get("ro.com.android.mobiledata",
2191 "true")) ? 1 : 0);
2192
2193 loadBooleanSetting(stmt, Settings.Global.NETSTATS_ENABLED,
2194 R.bool.def_netstats_enabled);
2195
2196 loadBooleanSetting(stmt, Settings.Global.INSTALL_NON_MARKET_APPS,
2197 R.bool.def_install_non_market_apps);
2198
Christopher Tate06efb532012-08-24 15:29:27 -07002199 loadBooleanSetting(stmt, Settings.Global.USB_MASS_STORAGE_ENABLED,
2200 R.bool.def_usb_mass_storage_enabled);
2201
2202 loadIntegerSetting(stmt, Settings.Global.WIFI_MAX_DHCP_RETRY_COUNT,
2203 R.integer.def_max_dhcp_retries);
2204
Jeff Brown89d55462012-09-19 11:33:42 -07002205 loadBooleanSetting(stmt, Settings.Global.WIFI_DISPLAY_ON,
2206 R.bool.def_wifi_display_on);
2207
Jim Millerb14288d2012-09-30 18:25:05 -07002208 loadStringSetting(stmt, Settings.Global.LOCK_SOUND,
2209 R.string.def_lock_sound);
Jim Millerb14288d2012-09-30 18:25:05 -07002210 loadStringSetting(stmt, Settings.Global.UNLOCK_SOUND,
2211 R.string.def_unlock_sound);
Amith Yamasani531c2372012-10-08 14:43:20 -07002212 loadIntegerSetting(stmt, Settings.Global.POWER_SOUNDS_ENABLED,
2213 R.integer.def_power_sounds_enabled);
2214 loadStringSetting(stmt, Settings.Global.LOW_BATTERY_SOUND,
2215 R.string.def_low_battery_sound);
2216 loadIntegerSetting(stmt, Settings.Global.DOCK_SOUNDS_ENABLED,
2217 R.integer.def_dock_sounds_enabled);
2218 loadStringSetting(stmt, Settings.Global.DESK_DOCK_SOUND,
2219 R.string.def_desk_dock_sound);
2220 loadStringSetting(stmt, Settings.Global.DESK_UNDOCK_SOUND,
2221 R.string.def_desk_undock_sound);
2222 loadStringSetting(stmt, Settings.Global.CAR_DOCK_SOUND,
2223 R.string.def_car_dock_sound);
2224 loadStringSetting(stmt, Settings.Global.CAR_UNDOCK_SOUND,
2225 R.string.def_car_undock_sound);
Jeff Brown84e27562012-12-07 13:56:34 -08002226 loadStringSetting(stmt, Settings.Global.WIRELESS_CHARGING_STARTED_SOUND,
2227 R.string.def_wireless_charging_started_sound);
Jim Millerb14288d2012-09-30 18:25:05 -07002228
Dmytro Dubovyk729f6682012-12-18 18:07:50 +02002229 loadIntegerSetting(stmt, Settings.Global.DOCK_AUDIO_MEDIA_ENABLED,
2230 R.integer.def_dock_audio_media_enabled);
2231
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07002232 loadSetting(stmt, Settings.Global.SET_INSTALL_LOCATION, 0);
2233 loadSetting(stmt, Settings.Global.DEFAULT_INSTALL_LOCATION,
2234 PackageHelper.APP_INSTALL_AUTO);
2235
2236 // Set default cdma emergency tone
2237 loadSetting(stmt, Settings.Global.EMERGENCY_TONE, 0);
2238
2239 // Set default cdma call auto retry
2240 loadSetting(stmt, Settings.Global.CALL_AUTO_RETRY, 0);
2241
2242 // Set the preferred network mode to 0 = Global, CDMA default
2243 int type;
2244 if (TelephonyManager.getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) {
2245 type = Phone.NT_MODE_GLOBAL;
2246 } else {
2247 type = SystemProperties.getInt("ro.telephony.default_network",
2248 RILConstants.PREFERRED_NETWORK_MODE);
2249 }
2250 loadSetting(stmt, Settings.Global.PREFERRED_NETWORK_MODE, type);
2251
Christopher Tate06efb532012-08-24 15:29:27 -07002252 // --- New global settings start here
2253 } finally {
2254 if (stmt != null) stmt.close();
2255 }
2256 }
2257
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002258 private void loadSetting(SQLiteStatement stmt, String key, Object value) {
2259 stmt.bindString(1, key);
2260 stmt.bindString(2, value.toString());
2261 stmt.execute();
2262 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 private void loadStringSetting(SQLiteStatement stmt, String key, int resid) {
2265 loadSetting(stmt, key, mContext.getResources().getString(resid));
2266 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268 private void loadBooleanSetting(SQLiteStatement stmt, String key, int resid) {
2269 loadSetting(stmt, key,
2270 mContext.getResources().getBoolean(resid) ? "1" : "0");
2271 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 private void loadIntegerSetting(SQLiteStatement stmt, String key, int resid) {
2274 loadSetting(stmt, key,
2275 Integer.toString(mContext.getResources().getInteger(resid)));
2276 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002278 private void loadFractionSetting(SQLiteStatement stmt, String key, int resid, int base) {
2279 loadSetting(stmt, key,
2280 Float.toString(mContext.getResources().getFraction(resid, base, base)));
2281 }
Amith Yamasani5cd15002011-11-16 11:19:48 -08002282
2283 private int getIntValueFromSystem(SQLiteDatabase db, String name, int defaultValue) {
Christopher Tate06efb532012-08-24 15:29:27 -07002284 return getIntValueFromTable(db, TABLE_SYSTEM, name, defaultValue);
Svetoslav Ganov86317012012-08-15 22:13:00 -07002285 }
2286
2287 private int getIntValueFromTable(SQLiteDatabase db, String table, String name,
2288 int defaultValue) {
2289 String value = getStringValueFromTable(db, table, name, null);
2290 return (value != null) ? Integer.parseInt(value) : defaultValue;
2291 }
2292
2293 private String getStringValueFromTable(SQLiteDatabase db, String table, String name,
2294 String defaultValue) {
Amith Yamasani5cd15002011-11-16 11:19:48 -08002295 Cursor c = null;
2296 try {
Svetoslav Ganov86317012012-08-15 22:13:00 -07002297 c = db.query(table, new String[] { Settings.System.VALUE }, "name='" + name + "'",
Amith Yamasani5cd15002011-11-16 11:19:48 -08002298 null, null, null, null);
2299 if (c != null && c.moveToFirst()) {
2300 String val = c.getString(0);
Svetoslav Ganov86317012012-08-15 22:13:00 -07002301 return val == null ? defaultValue : val;
Amith Yamasani5cd15002011-11-16 11:19:48 -08002302 }
2303 } finally {
2304 if (c != null) c.close();
2305 }
Svetoslav Ganov86317012012-08-15 22:13:00 -07002306 return defaultValue;
Amith Yamasani5cd15002011-11-16 11:19:48 -08002307 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002308}