blob: 06d00be8aee8dd30a36552a880d942c17602f7ac [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;
John Spurlock61560172015-02-06 19:46:04 -050031import android.media.AudioSystem;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070032import android.media.AudioManager;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070033import android.net.ConnectivityManager;
Jerome Poichet147b4d72014-05-12 18:13:27 -070034import android.os.Build;
Christopher Tate06efb532012-08-24 15:29:27 -070035import android.os.Environment;
Dianne Hackborn13579ed2012-11-28 18:05:36 -080036import android.os.RemoteException;
37import android.os.ServiceManager;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070038import android.os.SystemProperties;
Christopher Tate06efb532012-08-24 15:29:27 -070039import android.os.UserHandle;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070040import android.provider.Settings;
Jeff Sharkey625239a2012-09-26 22:03:49 -070041import android.provider.Settings.Global;
Amith Yamasani156c4352010-03-05 17:10:03 -080042import android.provider.Settings.Secure;
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
Libin.Tang@motorola.com0499bb52014-10-10 14:55:57 -050046import com.android.ims.ImsConfig;
Gilles Debunnefa53d302011-07-08 10:40:51 -070047import com.android.internal.content.PackageHelper;
Grace Chen6ad1c5e2017-06-13 16:07:45 -070048import com.android.internal.telephony.Phone;
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;
Svetoslav683914b2015-01-15 14:22:26 -080061import java.util.Set;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070062
63/**
Jeff Brown503cffc2015-03-26 18:08:51 -070064 * Legacy settings database helper class for {@link SettingsProvider}.
65 *
66 * IMPORTANT: Do not add any more upgrade steps here as the global,
67 * secure, and system settings are no longer stored in a database
68 * but are kept in memory and persisted to XML.
69 *
70 * See: SettingsProvider.UpgradeController#onUpgradeLocked
71 *
72 * @deprecated The implementation is frozen. Do not add any new code to this class!
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070073 */
Jeff Brown503cffc2015-03-26 18:08:51 -070074@Deprecated
75class DatabaseHelper extends SQLiteOpenHelper {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070076 private static final String TAG = "SettingsProvider";
77 private static final String DATABASE_NAME = "settings.db";
Jim Millerf1860552009-09-09 17:46:35 -070078
79 // Please, please please. If you update the database version, check to make sure the
80 // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
81 // is properly propagated through your change. Not doing so will result in a loss of user
82 // settings.
John Spurlock8c51d0b2014-11-07 15:14:21 -050083 private static final int DATABASE_VERSION = 118;
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -070084
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070085 private Context mContext;
Christopher Tate06efb532012-08-24 15:29:27 -070086 private int mUserHandle;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070087
Dianne Hackborn24117ce2010-07-12 15:54:38 -070088 private static final HashSet<String> mValidTables = new HashSet<String>();
89
Svetoslav683914b2015-01-15 14:22:26 -080090 private static final String DATABASE_JOURNAL_SUFFIX = "-journal";
91 private static final String DATABASE_BACKUP_SUFFIX = "-backup";
92
Christopher Tate06efb532012-08-24 15:29:27 -070093 private static final String TABLE_SYSTEM = "system";
94 private static final String TABLE_SECURE = "secure";
95 private static final String TABLE_GLOBAL = "global";
96
Dianne Hackborn24117ce2010-07-12 15:54:38 -070097 static {
Christopher Tate06efb532012-08-24 15:29:27 -070098 mValidTables.add(TABLE_SYSTEM);
99 mValidTables.add(TABLE_SECURE);
100 mValidTables.add(TABLE_GLOBAL);
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700101
102 // These are old.
Svetoslav683914b2015-01-15 14:22:26 -0800103 mValidTables.add("bluetooth_devices");
104 mValidTables.add("bookmarks");
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700105 mValidTables.add("favorites");
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700106 mValidTables.add("old_favorites");
Svetoslav683914b2015-01-15 14:22:26 -0800107 mValidTables.add("android_metadata");
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700108 }
109
Christopher Tate06efb532012-08-24 15:29:27 -0700110 static String dbNameForUser(final int userHandle) {
111 // The owner gets the unadorned db name;
Xiaohui Chen43765b72015-08-31 10:57:33 -0700112 if (userHandle == UserHandle.USER_SYSTEM) {
Christopher Tate06efb532012-08-24 15:29:27 -0700113 return DATABASE_NAME;
114 } else {
115 // Place the database in the user-specific data tree so that it's
116 // cleaned up automatically when the user is deleted.
117 File databaseFile = new File(
118 Environment.getUserSystemDirectory(userHandle), DATABASE_NAME);
Fyodor Kupolov497b5fa2015-12-17 10:47:33 -0800119 // If databaseFile doesn't exist, database can be kept in memory. It's safe because the
120 // database will be migrated and disposed of immediately after onCreate finishes
121 if (!databaseFile.exists()) {
122 Log.i(TAG, "No previous database file exists - running in in-memory mode");
123 return null;
124 }
Christopher Tate06efb532012-08-24 15:29:27 -0700125 return databaseFile.getPath();
126 }
127 }
128
129 public DatabaseHelper(Context context, int userHandle) {
130 super(context, dbNameForUser(userHandle), null, DATABASE_VERSION);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700131 mContext = context;
Christopher Tate06efb532012-08-24 15:29:27 -0700132 mUserHandle = userHandle;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700133 }
134
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700135 public static boolean isValidTable(String name) {
136 return mValidTables.contains(name);
137 }
138
Fyodor Kupolov497b5fa2015-12-17 10:47:33 -0800139 private boolean isInMemory() {
140 return getDatabaseName() == null;
141 }
142
Svetoslav683914b2015-01-15 14:22:26 -0800143 public void dropDatabase() {
144 close();
Fyodor Kupolov497b5fa2015-12-17 10:47:33 -0800145 // No need to remove files if db is in memory
146 if (isInMemory()) {
147 return;
148 }
Svetoslav683914b2015-01-15 14:22:26 -0800149 File databaseFile = mContext.getDatabasePath(getDatabaseName());
150 if (databaseFile.exists()) {
151 databaseFile.delete();
152 }
153 File databaseJournalFile = mContext.getDatabasePath(getDatabaseName()
154 + DATABASE_JOURNAL_SUFFIX);
155 if (databaseJournalFile.exists()) {
156 databaseJournalFile.delete();
157 }
158 }
159
160 public void backupDatabase() {
161 close();
Fyodor Kupolov497b5fa2015-12-17 10:47:33 -0800162 // No need to backup files if db is in memory
163 if (isInMemory()) {
164 return;
165 }
Svetoslav683914b2015-01-15 14:22:26 -0800166 File databaseFile = mContext.getDatabasePath(getDatabaseName());
167 if (!databaseFile.exists()) {
168 return;
169 }
170 File backupFile = mContext.getDatabasePath(getDatabaseName()
171 + DATABASE_BACKUP_SUFFIX);
172 if (backupFile.exists()) {
173 return;
174 }
175 databaseFile.renameTo(backupFile);
176 }
177
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800178 private void createSecureTable(SQLiteDatabase db) {
179 db.execSQL("CREATE TABLE secure (" +
180 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
181 "name TEXT UNIQUE ON CONFLICT REPLACE," +
182 "value TEXT" +
183 ");");
184 db.execSQL("CREATE INDEX secureIndex1 ON secure (name);");
185 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700186
Christopher Tate06efb532012-08-24 15:29:27 -0700187 private void createGlobalTable(SQLiteDatabase db) {
188 db.execSQL("CREATE TABLE global (" +
189 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
190 "name TEXT UNIQUE ON CONFLICT REPLACE," +
191 "value TEXT" +
192 ");");
193 db.execSQL("CREATE INDEX globalIndex1 ON global (name);");
194 }
195
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700196 @Override
197 public void onCreate(SQLiteDatabase db) {
198 db.execSQL("CREATE TABLE system (" +
199 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
200 "name TEXT UNIQUE ON CONFLICT REPLACE," +
201 "value TEXT" +
202 ");");
203 db.execSQL("CREATE INDEX systemIndex1 ON system (name);");
204
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800205 createSecureTable(db);
206
Xiaohui Chen43765b72015-08-31 10:57:33 -0700207 // Only create the global table for the singleton 'owner/system' user
208 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate06efb532012-08-24 15:29:27 -0700209 createGlobalTable(db);
210 }
211
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700212 db.execSQL("CREATE TABLE bluetooth_devices (" +
213 "_id INTEGER PRIMARY KEY," +
214 "name TEXT," +
215 "addr TEXT," +
216 "channel INTEGER," +
217 "type INTEGER" +
218 ");");
219
220 db.execSQL("CREATE TABLE bookmarks (" +
221 "_id INTEGER PRIMARY KEY," +
222 "title TEXT," +
223 "folder TEXT," +
224 "intent TEXT," +
225 "shortcut INTEGER," +
226 "ordering INTEGER" +
227 ");");
228
229 db.execSQL("CREATE INDEX bookmarksIndex1 ON bookmarks (folder);");
230 db.execSQL("CREATE INDEX bookmarksIndex2 ON bookmarks (shortcut);");
231
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700232 // Populate bookmarks table with initial bookmarks
Dianne Hackborn13579ed2012-11-28 18:05:36 -0800233 boolean onlyCore = false;
234 try {
235 onlyCore = IPackageManager.Stub.asInterface(ServiceManager.getService(
236 "package")).isOnlyCoreApps();
237 } catch (RemoteException e) {
238 }
239 if (!onlyCore) {
240 loadBookmarks(db);
241 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700242
243 // Load initial volume levels into DB
244 loadVolumeLevels(db);
245
246 // Load inital settings values
247 loadSettings(db);
248 }
249
250 @Override
251 public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700252 Log.w(TAG, "Upgrading settings database from version " + oldVersion + " to "
253 + currentVersion);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700254
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700255 int upgradeVersion = oldVersion;
256
257 // Pattern for upgrade blocks:
258 //
259 // if (upgradeVersion == [the DATABASE_VERSION you set] - 1) {
260 // .. your upgrade logic..
261 // upgradeVersion = [the DATABASE_VERSION you set]
262 // }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700263
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700264 if (upgradeVersion == 20) {
265 /*
266 * Version 21 is part of the volume control refresh. There is no
267 * longer a UI-visible for setting notification vibrate on/off (in
268 * our design), but the functionality still exists. Force the
269 * notification vibrate to on.
270 */
271 loadVibrateSetting(db, true);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700272
273 upgradeVersion = 21;
274 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700275
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700276 if (upgradeVersion < 22) {
277 upgradeVersion = 22;
278 // Upgrade the lock gesture storage location and format
279 upgradeLockPatternLocation(db);
280 }
281
282 if (upgradeVersion < 23) {
283 db.execSQL("UPDATE favorites SET iconResource=0 WHERE iconType=0");
284 upgradeVersion = 23;
285 }
286
287 if (upgradeVersion == 23) {
288 db.beginTransaction();
289 try {
290 db.execSQL("ALTER TABLE favorites ADD spanX INTEGER");
291 db.execSQL("ALTER TABLE favorites ADD spanY INTEGER");
292 // Shortcuts, applications, folders
293 db.execSQL("UPDATE favorites SET spanX=1, spanY=1 WHERE itemType<=0");
294 // Photo frames, clocks
Wink Saville04e71b32009-04-02 11:00:54 -0700295 db.execSQL(
296 "UPDATE favorites SET spanX=2, spanY=2 WHERE itemType=1000 or itemType=1002");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700297 // Search boxes
298 db.execSQL("UPDATE favorites SET spanX=4, spanY=1 WHERE itemType=1001");
299 db.setTransactionSuccessful();
300 } finally {
301 db.endTransaction();
302 }
303 upgradeVersion = 24;
304 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700305
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700306 if (upgradeVersion == 24) {
307 db.beginTransaction();
308 try {
309 // The value of the constants for preferring wifi or preferring mobile have been
310 // swapped, so reload the default.
311 db.execSQL("DELETE FROM system WHERE name='network_preference'");
312 db.execSQL("INSERT INTO system ('name', 'value') values ('network_preference', '" +
313 ConnectivityManager.DEFAULT_NETWORK_PREFERENCE + "')");
314 db.setTransactionSuccessful();
315 } finally {
316 db.endTransaction();
317 }
318 upgradeVersion = 25;
319 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800320
321 if (upgradeVersion == 25) {
322 db.beginTransaction();
323 try {
324 db.execSQL("ALTER TABLE favorites ADD uri TEXT");
325 db.execSQL("ALTER TABLE favorites ADD displayMode INTEGER");
326 db.setTransactionSuccessful();
327 } finally {
328 db.endTransaction();
329 }
330 upgradeVersion = 26;
331 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700332
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800333 if (upgradeVersion == 26) {
334 // This introduces the new secure settings table.
335 db.beginTransaction();
336 try {
337 createSecureTable(db);
338 db.setTransactionSuccessful();
339 } finally {
340 db.endTransaction();
341 }
342 upgradeVersion = 27;
343 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700344
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800345 if (upgradeVersion == 27) {
Amith Yamasani156c4352010-03-05 17:10:03 -0800346 String[] settingsToMove = {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800347 Settings.Secure.ADB_ENABLED,
348 Settings.Secure.ANDROID_ID,
349 Settings.Secure.BLUETOOTH_ON,
350 Settings.Secure.DATA_ROAMING,
351 Settings.Secure.DEVICE_PROVISIONED,
352 Settings.Secure.HTTP_PROXY,
353 Settings.Secure.INSTALL_NON_MARKET_APPS,
354 Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
355 Settings.Secure.LOGGING_ID,
356 Settings.Secure.NETWORK_PREFERENCE,
357 Settings.Secure.PARENTAL_CONTROL_ENABLED,
358 Settings.Secure.PARENTAL_CONTROL_LAST_UPDATE,
359 Settings.Secure.PARENTAL_CONTROL_REDIRECT_URL,
360 Settings.Secure.SETTINGS_CLASSNAME,
361 Settings.Secure.USB_MASS_STORAGE_ENABLED,
362 Settings.Secure.USE_GOOGLE_MAIL,
363 Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
364 Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,
365 Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT,
366 Settings.Secure.WIFI_ON,
367 Settings.Secure.WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE,
368 Settings.Secure.WIFI_WATCHDOG_AP_COUNT,
369 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS,
370 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED,
371 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS,
372 Settings.Secure.WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT,
373 Settings.Secure.WIFI_WATCHDOG_MAX_AP_CHECKS,
374 Settings.Secure.WIFI_WATCHDOG_ON,
375 Settings.Secure.WIFI_WATCHDOG_PING_COUNT,
376 Settings.Secure.WIFI_WATCHDOG_PING_DELAY_MS,
377 Settings.Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS,
378 };
Christopher Tate92198742012-09-07 12:00:13 -0700379 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800380 upgradeVersion = 28;
381 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700382
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800383 if (upgradeVersion == 28 || upgradeVersion == 29) {
384 // Note: The upgrade to 28 was flawed since it didn't delete the old
385 // setting first before inserting. Combining 28 and 29 with the
386 // fixed version.
387
388 // This upgrade adds the STREAM_NOTIFICATION type to the list of
389 // types affected by ringer modes (silent, vibrate, etc.)
390 db.beginTransaction();
391 try {
392 db.execSQL("DELETE FROM system WHERE name='"
393 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
394 int newValue = (1 << AudioManager.STREAM_RING)
395 | (1 << AudioManager.STREAM_NOTIFICATION)
396 | (1 << AudioManager.STREAM_SYSTEM);
397 db.execSQL("INSERT INTO system ('name', 'value') values ('"
398 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
399 + String.valueOf(newValue) + "')");
400 db.setTransactionSuccessful();
401 } finally {
402 db.endTransaction();
403 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700404
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800405 upgradeVersion = 30;
406 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700407
The Android Open Source Project9266c552009-01-15 16:12:10 -0800408 if (upgradeVersion == 30) {
409 /*
410 * Upgrade 31 clears the title for all quick launch shortcuts so the
411 * activities' titles will be resolved at display time. Also, the
412 * folder is changed to '@quicklaunch'.
413 */
414 db.beginTransaction();
415 try {
416 db.execSQL("UPDATE bookmarks SET folder = '@quicklaunch'");
417 db.execSQL("UPDATE bookmarks SET title = ''");
418 db.setTransactionSuccessful();
419 } finally {
420 db.endTransaction();
421 }
422 upgradeVersion = 31;
423 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 if (upgradeVersion == 31) {
426 /*
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700427 * Animations are now managed in preferences, and may be
428 * enabled or disabled based on product resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 */
430 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700431 SQLiteStatement stmt = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 try {
433 db.execSQL("DELETE FROM system WHERE name='"
434 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
435 db.execSQL("DELETE FROM system WHERE name='"
436 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700437 stmt = db.compileStatement("INSERT INTO system(name,value)"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 + " VALUES(?,?);");
439 loadDefaultAnimationSettings(stmt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 db.setTransactionSuccessful();
441 } finally {
442 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700443 if (stmt != null) stmt.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 }
445 upgradeVersion = 32;
446 }
447
448 if (upgradeVersion == 32) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 upgradeVersion = 33;
450 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700451
The Android Open Source Project4df24232009-03-05 14:34:35 -0800452 if (upgradeVersion == 33) {
453 // Set the default zoom controls to: tap-twice to bring up +/-
454 db.beginTransaction();
455 try {
456 db.execSQL("INSERT INTO system(name,value) values('zoom','2');");
457 db.setTransactionSuccessful();
458 } finally {
459 db.endTransaction();
460 }
461 upgradeVersion = 34;
462 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463
Mike Lockwoodbcab8df2009-06-25 16:39:09 -0400464 if (upgradeVersion == 34) {
465 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700466 SQLiteStatement stmt = null;
Mike Lockwoodbcab8df2009-06-25 16:39:09 -0400467 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700468 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
Dianne Hackborncf098292009-07-01 19:55:20 -0700469 + " VALUES(?,?);");
470 loadSecure35Settings(stmt);
Dianne Hackborncf098292009-07-01 19:55:20 -0700471 db.setTransactionSuccessful();
472 } finally {
473 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700474 if (stmt != null) stmt.close();
Dianne Hackborncf098292009-07-01 19:55:20 -0700475 }
Jim Millerf1860552009-09-09 17:46:35 -0700476 upgradeVersion = 35;
Mike Lockwood02901eb2009-08-25 15:11:17 -0700477 }
478 // due to a botched merge from donut to eclair, the initialization of ASSISTED_GPS_ENABLED
479 // was accidentally done out of order here.
480 // to fix this, ASSISTED_GPS_ENABLED is now initialized while upgrading from 38 to 39,
481 // and we intentionally do nothing from 35 to 36 now.
482 if (upgradeVersion == 35) {
The Android Open Source Project575d1af2009-07-03 08:55:59 -0700483 upgradeVersion = 36;
Dianne Hackborncf098292009-07-01 19:55:20 -0700484 }
Mike Lockwood02901eb2009-08-25 15:11:17 -0700485
Eric Laurenta553c252009-07-17 12:17:14 -0700486 if (upgradeVersion == 36) {
487 // This upgrade adds the STREAM_SYSTEM_ENFORCED type to the list of
488 // types affected by ringer modes (silent, vibrate, etc.)
489 db.beginTransaction();
490 try {
491 db.execSQL("DELETE FROM system WHERE name='"
492 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
493 int newValue = (1 << AudioManager.STREAM_RING)
494 | (1 << AudioManager.STREAM_NOTIFICATION)
495 | (1 << AudioManager.STREAM_SYSTEM)
496 | (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
497 db.execSQL("INSERT INTO system ('name', 'value') values ('"
498 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
499 + String.valueOf(newValue) + "')");
500 db.setTransactionSuccessful();
501 } finally {
502 db.endTransaction();
503 }
Jim Miller48805752009-08-04 18:59:20 -0700504 upgradeVersion = 37;
Eric Laurenta553c252009-07-17 12:17:14 -0700505 }
506
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700507 if (upgradeVersion == 37) {
508 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700509 SQLiteStatement stmt = null;
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700510 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700511 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700512 + " VALUES(?,?);");
513 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
514 R.string.airplane_mode_toggleable_radios);
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700515 db.setTransactionSuccessful();
516 } finally {
517 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700518 if (stmt != null) stmt.close();
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700519 }
520 upgradeVersion = 38;
521 }
522
Mike Lockwood02901eb2009-08-25 15:11:17 -0700523 if (upgradeVersion == 38) {
524 db.beginTransaction();
525 try {
526 String value =
527 mContext.getResources().getBoolean(R.bool.assisted_gps_enabled) ? "1" : "0";
528 db.execSQL("INSERT OR IGNORE INTO secure(name,value) values('" +
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -0700529 Settings.Global.ASSISTED_GPS_ENABLED + "','" + value + "');");
Mike Lockwood02901eb2009-08-25 15:11:17 -0700530 db.setTransactionSuccessful();
531 } finally {
532 db.endTransaction();
533 }
534
535 upgradeVersion = 39;
536 }
537
Dan Murphy951764b2009-08-27 14:59:03 -0500538 if (upgradeVersion == 39) {
Amith Yamasanif50c5112011-01-07 11:32:30 -0800539 upgradeAutoBrightness(db);
Dan Murphy951764b2009-08-27 14:59:03 -0500540 upgradeVersion = 40;
541 }
542
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700543 if (upgradeVersion == 40) {
544 /*
545 * All animations are now turned on by default!
546 */
547 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700548 SQLiteStatement stmt = null;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700549 try {
550 db.execSQL("DELETE FROM system WHERE name='"
551 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
552 db.execSQL("DELETE FROM system WHERE name='"
553 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700554 stmt = db.compileStatement("INSERT INTO system(name,value)"
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700555 + " VALUES(?,?);");
556 loadDefaultAnimationSettings(stmt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700557 db.setTransactionSuccessful();
558 } finally {
559 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700560 if (stmt != null) stmt.close();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700561 }
562 upgradeVersion = 41;
563 }
564
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700565 if (upgradeVersion == 41) {
566 /*
567 * Initialize newly public haptic feedback setting
568 */
569 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700570 SQLiteStatement stmt = null;
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700571 try {
572 db.execSQL("DELETE FROM system WHERE name='"
573 + Settings.System.HAPTIC_FEEDBACK_ENABLED + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700574 stmt = db.compileStatement("INSERT INTO system(name,value)"
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700575 + " VALUES(?,?);");
576 loadDefaultHapticSettings(stmt);
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700577 db.setTransactionSuccessful();
578 } finally {
579 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700580 if (stmt != null) stmt.close();
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700581 }
582 upgradeVersion = 42;
583 }
584
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800585 if (upgradeVersion == 42) {
586 /*
587 * Initialize new notification pulse setting
588 */
589 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700590 SQLiteStatement stmt = null;
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800591 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700592 stmt = db.compileStatement("INSERT INTO system(name,value)"
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800593 + " VALUES(?,?);");
594 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
595 R.bool.def_notification_pulse);
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800596 db.setTransactionSuccessful();
597 } finally {
598 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700599 if (stmt != null) stmt.close();
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800600 }
601 upgradeVersion = 43;
602 }
603
Eric Laurent484d2882009-12-08 09:05:45 -0800604 if (upgradeVersion == 43) {
605 /*
606 * This upgrade stores bluetooth volume separately from voice volume
607 */
608 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700609 SQLiteStatement stmt = null;
Eric Laurent484d2882009-12-08 09:05:45 -0800610 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700611 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
Eric Laurent484d2882009-12-08 09:05:45 -0800612 + " VALUES(?,?);");
613 loadSetting(stmt, Settings.System.VOLUME_BLUETOOTH_SCO,
John Spurlock61560172015-02-06 19:46:04 -0500614 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
Eric Laurent484d2882009-12-08 09:05:45 -0800615 db.setTransactionSuccessful();
616 } finally {
617 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700618 if (stmt != null) stmt.close();
Eric Laurent484d2882009-12-08 09:05:45 -0800619 }
620 upgradeVersion = 44;
621 }
622
Doug Zongkeraed8f8e2010-01-07 18:07:50 -0800623 if (upgradeVersion == 44) {
624 /*
625 * Gservices was moved into vendor/google.
626 */
627 db.execSQL("DROP TABLE IF EXISTS gservices");
628 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1");
629 upgradeVersion = 45;
630 }
San Mehat87734d32010-01-08 12:53:06 -0800631
632 if (upgradeVersion == 45) {
633 /*
Sudheer Shanka2250d562016-11-07 15:41:02 -0800634 * New settings for StorageManagerService
San Mehat87734d32010-01-08 12:53:06 -0800635 */
636 db.beginTransaction();
637 try {
638 db.execSQL("INSERT INTO secure(name,value) values('" +
639 Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND + "','1');");
640 db.execSQL("INSERT INTO secure(name,value) values('" +
641 Settings.Secure.MOUNT_UMS_AUTOSTART + "','0');");
642 db.execSQL("INSERT INTO secure(name,value) values('" +
643 Settings.Secure.MOUNT_UMS_PROMPT + "','1');");
644 db.execSQL("INSERT INTO secure(name,value) values('" +
645 Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED + "','1');");
646 db.setTransactionSuccessful();
647 } finally {
648 db.endTransaction();
649 }
650 upgradeVersion = 46;
651 }
652
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800653 if (upgradeVersion == 46) {
654 /*
655 * The password mode constants have changed; reset back to no
656 * password.
657 */
658 db.beginTransaction();
659 try {
660 db.execSQL("DELETE FROM system WHERE name='lockscreen.password_type';");
661 db.setTransactionSuccessful();
662 } finally {
663 db.endTransaction();
664 }
665 upgradeVersion = 47;
666 }
667
Jim Miller61766772010-02-12 14:56:49 -0800668
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800669 if (upgradeVersion == 47) {
670 /*
671 * The password mode constants have changed again; reset back to no
672 * password.
673 */
674 db.beginTransaction();
675 try {
676 db.execSQL("DELETE FROM system WHERE name='lockscreen.password_type';");
677 db.setTransactionSuccessful();
678 } finally {
679 db.endTransaction();
680 }
681 upgradeVersion = 48;
682 }
Jim Miller61766772010-02-12 14:56:49 -0800683
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800684 if (upgradeVersion == 48) {
685 /*
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800686 * Default recognition service no longer initialized here,
687 * moved to RecognitionManagerService.
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800688 */
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800689 upgradeVersion = 49;
690 }
Jim Miller31f90b62010-01-20 13:35:20 -0800691
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500692 if (upgradeVersion == 49) {
693 /*
694 * New settings for new user interface noises.
695 */
696 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700697 SQLiteStatement stmt = null;
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500698 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700699 stmt = db.compileStatement("INSERT INTO system(name,value)"
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500700 + " VALUES(?,?);");
701 loadUISoundEffectsSettings(stmt);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500702 db.setTransactionSuccessful();
703 } finally {
704 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700705 if (stmt != null) stmt.close();
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500706 }
707
708 upgradeVersion = 50;
709 }
710
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800711 if (upgradeVersion == 50) {
712 /*
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700713 * Install location no longer initiated here.
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800714 */
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800715 upgradeVersion = 51;
716 }
717
Amith Yamasani156c4352010-03-05 17:10:03 -0800718 if (upgradeVersion == 51) {
719 /* Move the lockscreen related settings to Secure, including some private ones. */
720 String[] settingsToMove = {
721 Secure.LOCK_PATTERN_ENABLED,
722 Secure.LOCK_PATTERN_VISIBLE,
723 Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED,
724 "lockscreen.password_type",
725 "lockscreen.lockoutattemptdeadline",
726 "lockscreen.patterneverchosen",
727 "lock_pattern_autolock",
728 "lockscreen.lockedoutpermanently",
729 "lockscreen.password_salt"
730 };
Christopher Tate92198742012-09-07 12:00:13 -0700731 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
Amith Yamasani156c4352010-03-05 17:10:03 -0800732 upgradeVersion = 52;
733 }
734
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500735 if (upgradeVersion == 52) {
736 // new vibration/silent mode settings
737 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700738 SQLiteStatement stmt = null;
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500739 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700740 stmt = db.compileStatement("INSERT INTO system(name,value)"
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500741 + " VALUES(?,?);");
742 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
743 R.bool.def_vibrate_in_silent);
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500744 db.setTransactionSuccessful();
745 } finally {
746 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700747 if (stmt != null) stmt.close();
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500748 }
749
750 upgradeVersion = 53;
751 }
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -0700752
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800753 if (upgradeVersion == 53) {
754 /*
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700755 * New settings for set install location UI no longer initiated here.
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800756 */
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800757 upgradeVersion = 54;
758 }
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500759
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -0700760 if (upgradeVersion == 54) {
761 /*
762 * Update the screen timeout value if set to never
763 */
764 db.beginTransaction();
765 try {
766 upgradeScreenTimeoutFromNever(db);
767 db.setTransactionSuccessful();
768 } finally {
769 db.endTransaction();
770 }
771
772 upgradeVersion = 55;
773 }
774
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700775 if (upgradeVersion == 55) {
776 /* Move the install location settings. */
777 String[] settingsToMove = {
Jeff Sharkey625239a2012-09-26 22:03:49 -0700778 Global.SET_INSTALL_LOCATION,
779 Global.DEFAULT_INSTALL_LOCATION
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700780 };
Christopher Tate92198742012-09-07 12:00:13 -0700781 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700782 db.beginTransaction();
783 SQLiteStatement stmt = null;
784 try {
785 stmt = db.compileStatement("INSERT INTO system(name,value)"
786 + " VALUES(?,?);");
Jeff Sharkey625239a2012-09-26 22:03:49 -0700787 loadSetting(stmt, Global.SET_INSTALL_LOCATION, 0);
788 loadSetting(stmt, Global.DEFAULT_INSTALL_LOCATION,
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700789 PackageHelper.APP_INSTALL_AUTO);
790 db.setTransactionSuccessful();
791 } finally {
792 db.endTransaction();
793 if (stmt != null) stmt.close();
794 }
795 upgradeVersion = 56;
796 }
Jake Hamby66592842010-08-24 19:55:20 -0700797
798 if (upgradeVersion == 56) {
799 /*
800 * Add Bluetooth to list of toggleable radios in airplane mode
801 */
802 db.beginTransaction();
803 SQLiteStatement stmt = null;
804 try {
805 db.execSQL("DELETE FROM system WHERE name='"
806 + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS + "'");
807 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
808 + " VALUES(?,?);");
809 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
810 R.string.airplane_mode_toggleable_radios);
811 db.setTransactionSuccessful();
812 } finally {
813 db.endTransaction();
814 if (stmt != null) stmt.close();
815 }
816 upgradeVersion = 57;
817 }
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700818
Amith Yamasani5cd15002011-11-16 11:19:48 -0800819 /************* The following are Honeycomb changes ************/
820
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700821 if (upgradeVersion == 57) {
822 /*
Phil Weaver09d4ff82017-03-31 11:22:17 -0700823 * No longer initializing deleted setting ACCESSIBILITY_SCRIPT_INJECTION.
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700824 */
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700825 upgradeVersion = 58;
826 }
827
Amith Yamasaniad450be2010-09-16 16:47:00 -0700828 if (upgradeVersion == 58) {
829 /* Add default for new Auto Time Zone */
Amith Yamasani5cd15002011-11-16 11:19:48 -0800830 int autoTimeValue = getIntValueFromSystem(db, Settings.System.AUTO_TIME, 0);
Amith Yamasaniad450be2010-09-16 16:47:00 -0700831 db.beginTransaction();
832 SQLiteStatement stmt = null;
833 try {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800834 stmt = db.compileStatement("INSERT INTO system(name,value)" + " VALUES(?,?);");
835 loadSetting(stmt, Settings.System.AUTO_TIME_ZONE,
836 autoTimeValue); // Sync timezone to NITZ if auto_time was enabled
Amith Yamasaniad450be2010-09-16 16:47:00 -0700837 db.setTransactionSuccessful();
838 } finally {
839 db.endTransaction();
840 if (stmt != null) stmt.close();
841 }
842 upgradeVersion = 59;
843 }
844
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400845 if (upgradeVersion == 59) {
846 // Persistence for the rotation lock feature.
847 db.beginTransaction();
848 SQLiteStatement stmt = null;
849 try {
850 stmt = db.compileStatement("INSERT INTO system(name,value)"
851 + " VALUES(?,?);");
852 loadBooleanSetting(stmt, Settings.System.USER_ROTATION,
853 R.integer.def_user_rotation); // should be zero degrees
854 db.setTransactionSuccessful();
855 } finally {
856 db.endTransaction();
857 if (stmt != null) stmt.close();
858 }
859 upgradeVersion = 60;
860 }
861
Amith Yamasani00389312010-11-05 11:22:21 -0700862 if (upgradeVersion == 60) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800863 // Don't do this for upgrades from Gingerbread
864 // Were only required for intra-Honeycomb upgrades for testing
865 // upgradeScreenTimeout(db);
Amith Yamasani00389312010-11-05 11:22:21 -0700866 upgradeVersion = 61;
867 }
868
Amith Yamasani79373f62010-11-18 16:32:48 -0800869 if (upgradeVersion == 61) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800870 // Don't do this for upgrades from Gingerbread
871 // Were only required for intra-Honeycomb upgrades for testing
872 // upgradeScreenTimeout(db);
Amith Yamasani79373f62010-11-18 16:32:48 -0800873 upgradeVersion = 62;
874 }
875
Amith Yamasanif50c5112011-01-07 11:32:30 -0800876 // Change the default for screen auto-brightness mode
877 if (upgradeVersion == 62) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800878 // Don't do this for upgrades from Gingerbread
879 // Were only required for intra-Honeycomb upgrades for testing
880 // upgradeAutoBrightness(db);
Amith Yamasanif50c5112011-01-07 11:32:30 -0800881 upgradeVersion = 63;
882 }
883
Eric Laurent25101b02011-02-02 09:33:30 -0800884 if (upgradeVersion == 63) {
885 // This upgrade adds the STREAM_MUSIC type to the list of
886 // types affected by ringer modes (silent, vibrate, etc.)
887 db.beginTransaction();
888 try {
889 db.execSQL("DELETE FROM system WHERE name='"
890 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
891 int newValue = (1 << AudioManager.STREAM_RING)
892 | (1 << AudioManager.STREAM_NOTIFICATION)
893 | (1 << AudioManager.STREAM_SYSTEM)
894 | (1 << AudioManager.STREAM_SYSTEM_ENFORCED)
895 | (1 << AudioManager.STREAM_MUSIC);
896 db.execSQL("INSERT INTO system ('name', 'value') values ('"
897 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
898 + String.valueOf(newValue) + "')");
899 db.setTransactionSuccessful();
900 } finally {
901 db.endTransaction();
902 }
903 upgradeVersion = 64;
904 }
905
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800906 if (upgradeVersion == 64) {
907 // New setting to configure the long press timeout.
908 db.beginTransaction();
909 SQLiteStatement stmt = null;
910 try {
911 stmt = db.compileStatement("INSERT INTO secure(name,value)"
912 + " VALUES(?,?);");
913 loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT,
914 R.integer.def_long_press_timeout_millis);
915 stmt.close();
916 db.setTransactionSuccessful();
917 } finally {
918 db.endTransaction();
919 if (stmt != null) stmt.close();
920 }
921 upgradeVersion = 65;
922 }
923
Amith Yamasani5cd15002011-11-16 11:19:48 -0800924 /************* The following are Ice Cream Sandwich changes ************/
925
Gilles Debunnefa53d302011-07-08 10:40:51 -0700926 if (upgradeVersion == 65) {
927 /*
928 * Animations are removed from Settings. Turned on by default
929 */
930 db.beginTransaction();
931 SQLiteStatement stmt = null;
932 try {
933 db.execSQL("DELETE FROM system WHERE name='"
934 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
935 db.execSQL("DELETE FROM system WHERE name='"
936 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
937 stmt = db.compileStatement("INSERT INTO system(name,value)"
938 + " VALUES(?,?);");
939 loadDefaultAnimationSettings(stmt);
940 db.setTransactionSuccessful();
941 } finally {
942 db.endTransaction();
943 if (stmt != null) stmt.close();
944 }
945 upgradeVersion = 66;
946 }
947
Eric Laurentc1d41662011-07-19 11:21:13 -0700948 if (upgradeVersion == 66) {
Amith Yamasani42722bf2011-07-22 10:34:27 -0700949 // This upgrade makes sure that MODE_RINGER_STREAMS_AFFECTED is set
950 // according to device voice capability
951 db.beginTransaction();
952 try {
953 int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
954 (1 << AudioManager.STREAM_NOTIFICATION) |
955 (1 << AudioManager.STREAM_SYSTEM) |
956 (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
957 if (!mContext.getResources().getBoolean(
958 com.android.internal.R.bool.config_voice_capable)) {
959 ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
960 }
961 db.execSQL("DELETE FROM system WHERE name='"
962 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
963 db.execSQL("INSERT INTO system ('name', 'value') values ('"
964 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
965 + String.valueOf(ringerModeAffectedStreams) + "')");
966 db.setTransactionSuccessful();
967 } finally {
968 db.endTransaction();
969 }
970 upgradeVersion = 67;
971 }
Eric Laurentc1d41662011-07-19 11:21:13 -0700972
Svetoslav Ganova28a16d2011-07-28 11:24:21 -0700973 if (upgradeVersion == 67) {
974 // New setting to enable touch exploration.
975 db.beginTransaction();
976 SQLiteStatement stmt = null;
977 try {
978 stmt = db.compileStatement("INSERT INTO secure(name,value)"
979 + " VALUES(?,?);");
980 loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED,
981 R.bool.def_touch_exploration_enabled);
982 stmt.close();
983 db.setTransactionSuccessful();
984 } finally {
985 db.endTransaction();
986 if (stmt != null) stmt.close();
987 }
988 upgradeVersion = 68;
989 }
990
Amith Yamasani42722bf2011-07-22 10:34:27 -0700991 if (upgradeVersion == 68) {
992 // Enable all system sounds by default
993 db.beginTransaction();
Amith Yamasani42722bf2011-07-22 10:34:27 -0700994 try {
Amith Yamasani42722bf2011-07-22 10:34:27 -0700995 db.execSQL("DELETE FROM system WHERE name='"
996 + Settings.System.NOTIFICATIONS_USE_RING_VOLUME + "'");
Amith Yamasani42722bf2011-07-22 10:34:27 -0700997 db.setTransactionSuccessful();
998 } finally {
999 db.endTransaction();
Amith Yamasani42722bf2011-07-22 10:34:27 -07001000 }
1001 upgradeVersion = 69;
1002 }
Svetoslav Ganova28a16d2011-07-28 11:24:21 -07001003
Nick Pelly8d32a012011-08-09 07:03:49 -07001004 if (upgradeVersion == 69) {
1005 // Add RADIO_NFC to AIRPLANE_MODE_RADIO and AIRPLANE_MODE_TOGGLEABLE_RADIOS
1006 String airplaneRadios = mContext.getResources().getString(
1007 R.string.def_airplane_mode_radios);
1008 String toggleableRadios = mContext.getResources().getString(
1009 R.string.airplane_mode_toggleable_radios);
1010 db.beginTransaction();
1011 try {
1012 db.execSQL("UPDATE system SET value='" + airplaneRadios + "' " +
1013 "WHERE name='" + Settings.System.AIRPLANE_MODE_RADIOS + "'");
1014 db.execSQL("UPDATE system SET value='" + toggleableRadios + "' " +
1015 "WHERE name='" + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS + "'");
1016 db.setTransactionSuccessful();
1017 } finally {
1018 db.endTransaction();
1019 }
1020 upgradeVersion = 70;
1021 }
1022
Jeff Brown6651a632011-11-28 12:59:11 -08001023 if (upgradeVersion == 70) {
1024 // Update all built-in bookmarks. Some of the package names have changed.
1025 loadBookmarks(db);
1026 upgradeVersion = 71;
1027 }
1028
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08001029 if (upgradeVersion == 71) {
1030 // New setting to specify whether to speak passwords in accessibility mode.
1031 db.beginTransaction();
1032 SQLiteStatement stmt = null;
1033 try {
1034 stmt = db.compileStatement("INSERT INTO secure(name,value)"
1035 + " VALUES(?,?);");
1036 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD,
1037 R.bool.def_accessibility_speak_password);
Amith Yamasani6243edd2011-12-05 19:58:48 -08001038 db.setTransactionSuccessful();
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08001039 } finally {
1040 db.endTransaction();
1041 if (stmt != null) stmt.close();
1042 }
1043 upgradeVersion = 72;
1044 }
1045
Amith Yamasani6243edd2011-12-05 19:58:48 -08001046 if (upgradeVersion == 72) {
1047 // update vibration settings
1048 db.beginTransaction();
1049 SQLiteStatement stmt = null;
1050 try {
1051 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1052 + " VALUES(?,?);");
1053 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
1054 R.bool.def_vibrate_in_silent);
1055 db.setTransactionSuccessful();
1056 } finally {
1057 db.endTransaction();
1058 if (stmt != null) stmt.close();
1059 }
1060 upgradeVersion = 73;
1061 }
1062
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001063 if (upgradeVersion == 73) {
Amith Yamasani398c83c2011-12-13 10:38:47 -08001064 upgradeVibrateSettingFromNone(db);
1065 upgradeVersion = 74;
1066 }
1067
1068 if (upgradeVersion == 74) {
Phil Weaver09d4ff82017-03-31 11:22:17 -07001069 // No longer using URL from which WebView loads a JavaScript based screen-reader.
Amith Yamasani398c83c2011-12-13 10:38:47 -08001070 upgradeVersion = 75;
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001071 }
Mike Lockwood7bef7392011-10-20 16:51:53 -04001072 if (upgradeVersion == 75) {
1073 db.beginTransaction();
1074 SQLiteStatement stmt = null;
1075 Cursor c = null;
1076 try {
Christopher Tate06efb532012-08-24 15:29:27 -07001077 c = db.query(TABLE_SECURE, new String[] {"_id", "value"},
Mike Lockwood7bef7392011-10-20 16:51:53 -04001078 "name='lockscreen.disabled'",
1079 null, null, null, null);
1080 // only set default if it has not yet been set
1081 if (c == null || c.getCount() == 0) {
1082 stmt = db.compileStatement("INSERT INTO system(name,value)"
1083 + " VALUES(?,?);");
1084 loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED,
1085 R.bool.def_lockscreen_disabled);
1086 }
1087 db.setTransactionSuccessful();
1088 } finally {
1089 db.endTransaction();
1090 if (c != null) c.close();
1091 if (stmt != null) stmt.close();
1092 }
1093 upgradeVersion = 76;
1094 }
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001095
Eric Laurentbffc3d12012-05-07 17:43:49 -07001096 /************* The following are Jelly Bean changes ************/
1097
1098 if (upgradeVersion == 76) {
1099 // Removed VIBRATE_IN_SILENT setting
1100 db.beginTransaction();
1101 try {
1102 db.execSQL("DELETE FROM system WHERE name='"
1103 + Settings.System.VIBRATE_IN_SILENT + "'");
1104 db.setTransactionSuccessful();
1105 } finally {
1106 db.endTransaction();
1107 }
1108
1109 upgradeVersion = 77;
1110 }
1111
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001112 if (upgradeVersion == 77) {
1113 // Introduce "vibrate when ringing" setting
1114 loadVibrateWhenRingingSetting(db);
1115
1116 upgradeVersion = 78;
1117 }
Eric Laurentbffc3d12012-05-07 17:43:49 -07001118
alanv3a67eb32012-06-22 10:47:28 -07001119 if (upgradeVersion == 78) {
Phil Weaver09d4ff82017-03-31 11:22:17 -07001120 // ACCESSIBILITY_SCREEN_READER_URL has been removed
alanv3a67eb32012-06-22 10:47:28 -07001121 upgradeVersion = 79;
1122 }
1123
Svetoslav Ganov86317012012-08-15 22:13:00 -07001124 if (upgradeVersion == 79) {
1125 // Before touch exploration was a global setting controlled by the user
1126 // via the UI. However, if the enabled accessibility services do not
1127 // handle touch exploration mode, enabling it makes no sense. Therefore,
1128 // now the services request touch exploration mode and the user is
1129 // presented with a dialog to allow that and if she does we store that
1130 // in the database. As a result of this change a user that has enabled
1131 // accessibility, touch exploration, and some accessibility services
1132 // may lose touch exploration state, thus rendering the device useless
1133 // unless sighted help is provided, since the enabled service(s) are
1134 // not in the list of services to which the user granted a permission
1135 // to put the device in touch explore mode. Here we are allowing all
1136 // enabled accessibility services to toggle touch exploration provided
1137 // accessibility and touch exploration are enabled and no services can
1138 // toggle touch exploration. Note that the user has already manually
1139 // enabled the services and touch exploration which means the she has
1140 // given consent to have these services work in touch exploration mode.
Christopher Tate06efb532012-08-24 15:29:27 -07001141 final boolean accessibilityEnabled = getIntValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001142 Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;
Christopher Tate06efb532012-08-24 15:29:27 -07001143 final boolean touchExplorationEnabled = getIntValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001144 Settings.Secure.TOUCH_EXPLORATION_ENABLED, 0) == 1;
1145 if (accessibilityEnabled && touchExplorationEnabled) {
Christopher Tate06efb532012-08-24 15:29:27 -07001146 String enabledServices = getStringValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001147 Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "");
Christopher Tate06efb532012-08-24 15:29:27 -07001148 String touchExplorationGrantedServices = getStringValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001149 Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, "");
1150 if (TextUtils.isEmpty(touchExplorationGrantedServices)
1151 && !TextUtils.isEmpty(enabledServices)) {
1152 SQLiteStatement stmt = null;
1153 try {
1154 db.beginTransaction();
1155 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1156 + " VALUES(?,?);");
1157 loadSetting(stmt,
1158 Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES,
1159 enabledServices);
1160 db.setTransactionSuccessful();
1161 } finally {
1162 db.endTransaction();
1163 if (stmt != null) stmt.close();
1164 }
1165 }
1166 }
1167 upgradeVersion = 80;
1168 }
1169
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001170 // vvv Jelly Bean MR1 changes begin here vvv
1171
Svetoslav Ganovca34bcf2012-08-16 12:22:23 -07001172 if (upgradeVersion == 80) {
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001173 // update screensaver settings
1174 db.beginTransaction();
1175 SQLiteStatement stmt = null;
1176 try {
1177 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1178 + " VALUES(?,?);");
1179 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED,
John Spurlocked108f32012-10-18 16:49:24 -04001180 com.android.internal.R.bool.config_dreamsEnabledByDefault);
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001181 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
John Spurlocked108f32012-10-18 16:49:24 -04001182 com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04001183 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
John Spurlocked108f32012-10-18 16:49:24 -04001184 com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04001185 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_COMPONENTS,
John Spurlocked108f32012-10-18 16:49:24 -04001186 com.android.internal.R.string.config_dreamsDefaultComponent);
1187 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT,
1188 com.android.internal.R.string.config_dreamsDefaultComponent);
Christopher Tate06efb532012-08-24 15:29:27 -07001189
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001190 db.setTransactionSuccessful();
1191 } finally {
1192 db.endTransaction();
1193 if (stmt != null) stmt.close();
1194 }
Svetoslav Ganovca34bcf2012-08-16 12:22:23 -07001195 upgradeVersion = 81;
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001196 }
1197
rich cannings16e119e2012-09-06 12:04:37 -07001198 if (upgradeVersion == 81) {
1199 // Add package verification setting
1200 db.beginTransaction();
1201 SQLiteStatement stmt = null;
1202 try {
1203 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1204 + " VALUES(?,?);");
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001205 loadBooleanSetting(stmt, Settings.Global.PACKAGE_VERIFIER_ENABLE,
rich cannings16e119e2012-09-06 12:04:37 -07001206 R.bool.def_package_verifier_enable);
1207 db.setTransactionSuccessful();
1208 } finally {
1209 db.endTransaction();
1210 if (stmt != null) stmt.close();
1211 }
1212 upgradeVersion = 82;
1213 }
1214
Christopher Tate06efb532012-08-24 15:29:27 -07001215 if (upgradeVersion == 82) {
1216 // Move to per-user settings dbs
Xiaohui Chen43765b72015-08-31 10:57:33 -07001217 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate06efb532012-08-24 15:29:27 -07001218
Christopher Tate59c5bee2012-09-13 14:38:33 -07001219 db.beginTransaction();
1220 SQLiteStatement stmt = null;
1221 try {
1222 // Migrate now-global settings. Note that this happens before
1223 // new users can be created.
1224 createGlobalTable(db);
Svetoslav683914b2015-01-15 14:22:26 -08001225 String[] settingsToMove = setToStringArray(
1226 SettingsProvider.sSystemMovedToGlobalSettings);
Christopher Tate59c5bee2012-09-13 14:38:33 -07001227 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, false);
Svetoslav683914b2015-01-15 14:22:26 -08001228 settingsToMove = setToStringArray(
1229 SettingsProvider.sSecureMovedToGlobalSettings);
Christopher Tate59c5bee2012-09-13 14:38:33 -07001230 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, false);
1231
1232 db.setTransactionSuccessful();
1233 } finally {
1234 db.endTransaction();
1235 if (stmt != null) stmt.close();
1236 }
Christopher Tate06efb532012-08-24 15:29:27 -07001237 }
1238 upgradeVersion = 83;
1239 }
1240
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001241 if (upgradeVersion == 83) {
1242 // 1. Setting whether screen magnification is enabled.
1243 // 2. Setting for screen magnification scale.
1244 // 3. Setting for screen magnification auto update.
1245 db.beginTransaction();
1246 SQLiteStatement stmt = null;
1247 try {
1248 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
1249 loadBooleanSetting(stmt,
1250 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
1251 R.bool.def_accessibility_display_magnification_enabled);
1252 stmt.close();
1253 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
1254 loadFractionSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
1255 R.fraction.def_accessibility_display_magnification_scale, 1);
1256 stmt.close();
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001257
1258 db.setTransactionSuccessful();
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001259 } finally {
1260 db.endTransaction();
1261 if (stmt != null) stmt.close();
1262 }
1263 upgradeVersion = 84;
1264 }
1265
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001266 if (upgradeVersion == 84) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001267 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001268 db.beginTransaction();
1269 SQLiteStatement stmt = null;
1270 try {
1271 // Patch up the slightly-wrong key migration from 82 -> 83 for those
1272 // devices that missed it, ignoring if the move is redundant
1273 String[] settingsToMove = {
1274 Settings.Secure.ADB_ENABLED,
1275 Settings.Secure.BLUETOOTH_ON,
1276 Settings.Secure.DATA_ROAMING,
1277 Settings.Secure.DEVICE_PROVISIONED,
1278 Settings.Secure.INSTALL_NON_MARKET_APPS,
1279 Settings.Secure.USB_MASS_STORAGE_ENABLED
1280 };
1281 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1282 db.setTransactionSuccessful();
1283 } finally {
1284 db.endTransaction();
1285 if (stmt != null) stmt.close();
1286 }
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001287 }
1288 upgradeVersion = 85;
1289 }
1290
Christopher Tate92198742012-09-07 12:00:13 -07001291 if (upgradeVersion == 85) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001292 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001293 db.beginTransaction();
1294 try {
1295 // Fix up the migration, ignoring already-migrated elements, to snap up to
1296 // date with new changes to the set of global versus system/secure settings
1297 String[] settingsToMove = { Settings.System.STAY_ON_WHILE_PLUGGED_IN };
1298 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
Christopher Tate92198742012-09-07 12:00:13 -07001299
Christopher Tate59c5bee2012-09-13 14:38:33 -07001300 db.setTransactionSuccessful();
1301 } finally {
1302 db.endTransaction();
1303 }
Christopher Tate92198742012-09-07 12:00:13 -07001304 }
1305 upgradeVersion = 86;
1306 }
1307
rich cannings4d8fc792012-09-07 14:43:43 -07001308 if (upgradeVersion == 86) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001309 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001310 db.beginTransaction();
1311 try {
1312 String[] settingsToMove = {
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001313 Settings.Global.PACKAGE_VERIFIER_ENABLE,
1314 Settings.Global.PACKAGE_VERIFIER_TIMEOUT,
1315 Settings.Global.PACKAGE_VERIFIER_DEFAULT_RESPONSE
Christopher Tate59c5bee2012-09-13 14:38:33 -07001316 };
1317 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
rich cannings4d8fc792012-09-07 14:43:43 -07001318
Christopher Tate59c5bee2012-09-13 14:38:33 -07001319 db.setTransactionSuccessful();
1320 } finally {
1321 db.endTransaction();
1322 }
rich cannings4d8fc792012-09-07 14:43:43 -07001323 }
1324 upgradeVersion = 87;
1325 }
1326
Christopher Tatec868b642012-09-12 17:41:04 -07001327 if (upgradeVersion == 87) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001328 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001329 db.beginTransaction();
1330 try {
1331 String[] settingsToMove = {
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001332 Settings.Global.DATA_STALL_ALARM_NON_AGGRESSIVE_DELAY_IN_MS,
1333 Settings.Global.DATA_STALL_ALARM_AGGRESSIVE_DELAY_IN_MS,
1334 Settings.Global.GPRS_REGISTER_CHECK_PERIOD_MS
Christopher Tate59c5bee2012-09-13 14:38:33 -07001335 };
1336 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
Christopher Tatec868b642012-09-12 17:41:04 -07001337
Christopher Tate59c5bee2012-09-13 14:38:33 -07001338 db.setTransactionSuccessful();
1339 } finally {
1340 db.endTransaction();
1341 }
Christopher Tatec868b642012-09-12 17:41:04 -07001342 }
1343 upgradeVersion = 88;
1344 }
1345
Jeff Sharkey625239a2012-09-26 22:03:49 -07001346 if (upgradeVersion == 88) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001347 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jeff Sharkey625239a2012-09-26 22:03:49 -07001348 db.beginTransaction();
1349 try {
1350 String[] settingsToMove = {
1351 Settings.Global.BATTERY_DISCHARGE_DURATION_THRESHOLD,
1352 Settings.Global.BATTERY_DISCHARGE_THRESHOLD,
1353 Settings.Global.SEND_ACTION_APP_ERROR,
1354 Settings.Global.DROPBOX_AGE_SECONDS,
1355 Settings.Global.DROPBOX_MAX_FILES,
1356 Settings.Global.DROPBOX_QUOTA_KB,
1357 Settings.Global.DROPBOX_QUOTA_PERCENT,
1358 Settings.Global.DROPBOX_RESERVE_PERCENT,
1359 Settings.Global.DROPBOX_TAG_PREFIX,
1360 Settings.Global.ERROR_LOGCAT_PREFIX,
1361 Settings.Global.SYS_FREE_STORAGE_LOG_INTERVAL,
1362 Settings.Global.DISK_FREE_CHANGE_REPORTING_THRESHOLD,
1363 Settings.Global.SYS_STORAGE_THRESHOLD_PERCENTAGE,
1364 Settings.Global.SYS_STORAGE_THRESHOLD_MAX_BYTES,
1365 Settings.Global.SYS_STORAGE_FULL_THRESHOLD_BYTES,
1366 Settings.Global.SYNC_MAX_RETRY_DELAY_IN_SECONDS,
1367 Settings.Global.CONNECTIVITY_CHANGE_DELAY,
1368 Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED,
1369 Settings.Global.CAPTIVE_PORTAL_SERVER,
1370 Settings.Global.NSD_ON,
1371 Settings.Global.SET_INSTALL_LOCATION,
1372 Settings.Global.DEFAULT_INSTALL_LOCATION,
1373 Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY,
1374 Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY,
1375 Settings.Global.READ_EXTERNAL_STORAGE_ENFORCED_DEFAULT,
1376 Settings.Global.HTTP_PROXY,
1377 Settings.Global.GLOBAL_HTTP_PROXY_HOST,
1378 Settings.Global.GLOBAL_HTTP_PROXY_PORT,
1379 Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST,
1380 Settings.Global.SET_GLOBAL_HTTP_PROXY,
1381 Settings.Global.DEFAULT_DNS_SERVER,
1382 };
1383 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1384 db.setTransactionSuccessful();
1385 } finally {
1386 db.endTransaction();
1387 }
1388 }
1389 upgradeVersion = 89;
1390 }
1391
Jeff Sharkey0ac10282012-10-01 12:50:22 -07001392 if (upgradeVersion == 89) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001393 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jeff Sharkey0ac10282012-10-01 12:50:22 -07001394 db.beginTransaction();
1395 try {
1396 String[] prefixesToMove = {
1397 Settings.Global.BLUETOOTH_HEADSET_PRIORITY_PREFIX,
1398 Settings.Global.BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX,
1399 Settings.Global.BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX,
1400 };
1401
1402 movePrefixedSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, prefixesToMove);
1403
1404 db.setTransactionSuccessful();
1405 } finally {
1406 db.endTransaction();
1407 }
1408 }
1409 upgradeVersion = 90;
1410 }
1411
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001412 if (upgradeVersion == 90) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001413 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001414 db.beginTransaction();
1415 try {
1416 String[] systemToGlobal = {
1417 Settings.Global.WINDOW_ANIMATION_SCALE,
1418 Settings.Global.TRANSITION_ANIMATION_SCALE,
1419 Settings.Global.ANIMATOR_DURATION_SCALE,
1420 Settings.Global.FANCY_IME_ANIMATIONS,
1421 Settings.Global.COMPATIBILITY_MODE,
1422 Settings.Global.EMERGENCY_TONE,
1423 Settings.Global.CALL_AUTO_RETRY,
1424 Settings.Global.DEBUG_APP,
1425 Settings.Global.WAIT_FOR_DEBUGGER,
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001426 Settings.Global.ALWAYS_FINISH_ACTIVITIES,
1427 };
1428 String[] secureToGlobal = {
1429 Settings.Global.PREFERRED_NETWORK_MODE,
Naveen Kallab4d485c2013-07-03 16:39:27 -07001430 Settings.Global.CDMA_SUBSCRIPTION_MODE,
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001431 };
1432
1433 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, systemToGlobal, true);
1434 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, secureToGlobal, true);
1435
1436 db.setTransactionSuccessful();
1437 } finally {
1438 db.endTransaction();
1439 }
1440 }
1441 upgradeVersion = 91;
1442 }
1443
Eric Laurent55b02222012-10-03 11:56:23 -07001444 if (upgradeVersion == 91) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001445 if (mUserHandle == UserHandle.USER_SYSTEM) {
Eric Laurent55b02222012-10-03 11:56:23 -07001446 db.beginTransaction();
1447 try {
1448 // Move ringer mode from system to global settings
Amith Yamasani531c2372012-10-08 14:43:20 -07001449 String[] settingsToMove = { Settings.Global.MODE_RINGER };
Eric Laurent55b02222012-10-03 11:56:23 -07001450 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
1451
1452 db.setTransactionSuccessful();
1453 } finally {
1454 db.endTransaction();
1455 }
1456 }
1457 upgradeVersion = 92;
1458 }
1459
John Spurlock7f1c2482012-10-05 11:15:28 -04001460 if (upgradeVersion == 92) {
1461 SQLiteStatement stmt = null;
1462 try {
1463 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1464 + " VALUES(?,?);");
Xiaohui Chen43765b72015-08-31 10:57:33 -07001465 if (mUserHandle == UserHandle.USER_SYSTEM) {
John Spurlock7f1c2482012-10-05 11:15:28 -04001466 // consider existing primary users to have made it through user setup
1467 // if the globally-scoped device-provisioned bit is set
1468 // (indicating they already made it through setup as primary)
1469 int deviceProvisioned = getIntValueFromTable(db, TABLE_GLOBAL,
1470 Settings.Global.DEVICE_PROVISIONED, 0);
1471 loadSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
1472 deviceProvisioned);
1473 } else {
1474 // otherwise use the default
1475 loadBooleanSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
1476 R.bool.def_user_setup_complete);
1477 }
1478 } finally {
1479 if (stmt != null) stmt.close();
1480 }
1481 upgradeVersion = 93;
1482 }
1483
Amith Yamasani531c2372012-10-08 14:43:20 -07001484 if (upgradeVersion == 93) {
1485 // Redo this step, since somehow it didn't work the first time for some users
Xiaohui Chen43765b72015-08-31 10:57:33 -07001486 if (mUserHandle == UserHandle.USER_SYSTEM) {
Amith Yamasani531c2372012-10-08 14:43:20 -07001487 db.beginTransaction();
Amith Yamasani531c2372012-10-08 14:43:20 -07001488 try {
1489 // Migrate now-global settings
Svetoslav683914b2015-01-15 14:22:26 -08001490 String[] settingsToMove = setToStringArray(
1491 SettingsProvider.sSystemMovedToGlobalSettings);
Amith Yamasani531c2372012-10-08 14:43:20 -07001492 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
Svetoslav683914b2015-01-15 14:22:26 -08001493 settingsToMove = setToStringArray(
1494 SettingsProvider.sSecureMovedToGlobalSettings);
Amith Yamasani531c2372012-10-08 14:43:20 -07001495 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
Xiaohui Chen43765b72015-08-31 10:57:33 -07001507 if (mUserHandle == UserHandle.USER_SYSTEM) {
Amith Yamasani2d43fab2012-12-12 09:52:26 -08001508 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) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001525 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate58f41ec2013-01-11 15:40:36 -08001526 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 Sandlerdea64622013-09-23 16:05:57 -04001543 if (upgradeVersion == 97) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001544 if (mUserHandle == UserHandle.USER_SYSTEM) {
Daniel Sandlerdea64622013-09-23 16:05:57 -04001545 db.beginTransaction();
1546 SQLiteStatement stmt = null;
1547 try {
1548 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1549 + " VALUES(?,?);");
1550 loadIntegerSetting(stmt, Settings.Global.LOW_BATTERY_SOUND_TIMEOUT,
1551 R.integer.def_low_battery_sound_timeout);
1552 db.setTransactionSuccessful();
1553 } finally {
1554 db.endTransaction();
1555 if (stmt != null) stmt.close();
1556 }
1557 }
1558 upgradeVersion = 98;
1559 }
1560
Dan Sandler82a6c5c2014-02-20 14:43:20 -05001561 if (upgradeVersion == 98) {
Dan Sandler52e5701e2014-07-22 23:14:54 -04001562 // no-op; LOCK_SCREEN_SHOW_NOTIFICATIONS now handled in version 106
Dan Sandler82a6c5c2014-02-20 14:43:20 -05001563 upgradeVersion = 99;
1564 }
1565
Chris Wren1cdd7dd2014-02-28 17:49:20 -05001566 if (upgradeVersion == 99) {
Dan Sandler52e5701e2014-07-22 23:14:54 -04001567 // no-op; HEADS_UP_NOTIFICATIONS_ENABLED now handled in version 100
1568 upgradeVersion = 100;
1569 }
1570
1571 if (upgradeVersion == 100) {
1572 // note: LOCK_SCREEN_SHOW_NOTIFICATIONS now handled in version 106
Xiaohui Chen43765b72015-08-31 10:57:33 -07001573 if (mUserHandle == UserHandle.USER_SYSTEM) {
Chris Wren1cdd7dd2014-02-28 17:49:20 -05001574 db.beginTransaction();
1575 SQLiteStatement stmt = null;
1576 try {
1577 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1578 + " VALUES(?,?);");
1579 loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED,
1580 R.integer.def_heads_up_enabled);
1581 db.setTransactionSuccessful();
1582 } finally {
1583 db.endTransaction();
1584 if (stmt != null) stmt.close();
1585 }
1586 }
Chris Wren5242cf32014-03-19 16:16:48 -04001587 upgradeVersion = 101;
1588 }
Chris Wren1cdd7dd2014-02-28 17:49:20 -05001589
Jerome Poichet147b4d72014-05-12 18:13:27 -07001590 if (upgradeVersion == 101) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001591 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jerome Poichet147b4d72014-05-12 18:13:27 -07001592 db.beginTransaction();
1593 SQLiteStatement stmt = null;
1594 try {
1595 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
1596 + " VALUES(?,?);");
1597 loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName());
1598 db.setTransactionSuccessful();
1599 } finally {
1600 db.endTransaction();
1601 if (stmt != null) stmt.close();
1602 }
1603 }
1604 upgradeVersion = 102;
1605 }
1606
Christopher Tateaa036a22014-05-19 16:33:27 -07001607 if (upgradeVersion == 102) {
1608 db.beginTransaction();
1609 SQLiteStatement stmt = null;
1610 try {
1611 // The INSTALL_NON_MARKET_APPS setting is becoming per-user rather
1612 // than device-global.
Xiaohui Chen43765b72015-08-31 10:57:33 -07001613 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tateaa036a22014-05-19 16:33:27 -07001614 // In the owner user, the global table exists so we can migrate the
1615 // entry from there to the secure table, preserving its value.
1616 String[] globalToSecure = {
1617 Settings.Secure.INSTALL_NON_MARKET_APPS
1618 };
1619 moveSettingsToNewTable(db, TABLE_GLOBAL, TABLE_SECURE, globalToSecure, true);
1620 } else {
1621 // Secondary users' dbs don't have the global table, so institute the
1622 // default.
1623 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1624 + " VALUES(?,?);");
1625 loadBooleanSetting(stmt, Settings.Secure.INSTALL_NON_MARKET_APPS,
1626 R.bool.def_install_non_market_apps);
1627 }
1628 db.setTransactionSuccessful();
1629 } finally {
1630 db.endTransaction();
1631 if (stmt != null) stmt.close();
1632 }
1633 upgradeVersion = 103;
1634 }
Jeff Browna20dda42014-05-27 20:57:24 -07001635
1636 if (upgradeVersion == 103) {
1637 db.beginTransaction();
1638 SQLiteStatement stmt = null;
1639 try {
1640 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1641 + " VALUES(?,?);");
1642 loadBooleanSetting(stmt, Settings.Secure.WAKE_GESTURE_ENABLED,
1643 R.bool.def_wake_gesture_enabled);
1644 db.setTransactionSuccessful();
1645 } finally {
1646 db.endTransaction();
1647 if (stmt != null) stmt.close();
1648 }
1649 upgradeVersion = 104;
1650 }
1651
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001652 if (upgradeVersion < 105) {
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07001653 // No-op: GUEST_USER_ENABLED setting was removed
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001654 upgradeVersion = 105;
1655 }
1656
Dan Sandler52e5701e2014-07-22 23:14:54 -04001657 if (upgradeVersion < 106) {
1658 // LOCK_SCREEN_SHOW_NOTIFICATIONS is now per-user.
1659 db.beginTransaction();
1660 SQLiteStatement stmt = null;
1661 try {
1662 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1663 + " VALUES(?,?);");
Chris Wrencd8f4f72014-08-27 18:48:13 -04001664 loadIntegerSetting(stmt, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
1665 R.integer.def_lock_screen_show_notifications);
Xiaohui Chen43765b72015-08-31 10:57:33 -07001666 if (mUserHandle == UserHandle.USER_SYSTEM) {
Dan Sandler52e5701e2014-07-22 23:14:54 -04001667 final int oldShow = getIntValueFromTable(db,
1668 TABLE_GLOBAL, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, -1);
1669 if (oldShow >= 0) {
1670 // overwrite the default with whatever you had
1671 loadSetting(stmt, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, oldShow);
1672 final SQLiteStatement deleteStmt
1673 = db.compileStatement("DELETE FROM global WHERE name=?");
1674 deleteStmt.bindString(1, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS);
1675 deleteStmt.execute();
1676 }
1677 }
1678 db.setTransactionSuccessful();
1679 } finally {
1680 db.endTransaction();
1681 if (stmt != null) stmt.close();
1682 }
1683 upgradeVersion = 106;
1684 }
Adrian Roos49e057d2014-08-13 17:14:51 +02001685
1686 if (upgradeVersion < 107) {
1687 // Add trusted sound setting
Xiaohui Chen43765b72015-08-31 10:57:33 -07001688 if (mUserHandle == UserHandle.USER_SYSTEM) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001689 db.beginTransaction();
1690 SQLiteStatement stmt = null;
1691 try {
1692 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1693 + " VALUES(?,?);");
1694 loadStringSetting(stmt, Settings.Global.TRUSTED_SOUND,
1695 R.string.def_trusted_sound);
1696 db.setTransactionSuccessful();
1697 } finally {
1698 db.endTransaction();
1699 if (stmt != null) stmt.close();
1700 }
1701 }
1702 upgradeVersion = 107;
1703 }
1704
Jeff Brown49cb6132014-08-20 14:32:38 -07001705 if (upgradeVersion < 108) {
1706 // Reset the auto-brightness setting to default since the behavior
1707 // of the feature is now quite different and is being presented to
1708 // the user in a new way as "adaptive brightness".
1709 db.beginTransaction();
1710 SQLiteStatement stmt = null;
1711 try {
1712 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1713 + " VALUES(?,?);");
1714 loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE,
1715 R.bool.def_screen_brightness_automatic_mode);
1716 db.setTransactionSuccessful();
1717 } finally {
1718 db.endTransaction();
1719 if (stmt != null) stmt.close();
1720 }
1721 upgradeVersion = 108;
1722 }
1723
Chris Wrencd8f4f72014-08-27 18:48:13 -04001724 if (upgradeVersion < 109) {
1725 db.beginTransaction();
1726 SQLiteStatement stmt = null;
1727 try {
1728 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1729 + " VALUES(?,?);");
1730 loadBooleanSetting(stmt, Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
1731 R.bool.def_lock_screen_allow_private_notifications);
1732 db.setTransactionSuccessful();
1733 } finally {
1734 db.endTransaction();
1735 if (stmt != null) stmt.close();
1736 }
1737 upgradeVersion = 109;
1738 }
1739
Tyler Gunn2c830a22014-09-02 08:39:35 -07001740 if (upgradeVersion < 110) {
1741 // The SIP_CALL_OPTIONS value SIP_ASK_EACH_TIME is being deprecated.
1742 // If the SIP_CALL_OPTIONS setting is set to SIP_ASK_EACH_TIME, default to
1743 // SIP_ADDRESS_ONLY.
1744 db.beginTransaction();
1745 SQLiteStatement stmt = null;
1746 try {
1747 stmt = db.compileStatement("UPDATE system SET value = ? " +
1748 "WHERE name = ? AND value = ?;");
1749 stmt.bindString(1, Settings.System.SIP_ADDRESS_ONLY);
1750 stmt.bindString(2, Settings.System.SIP_CALL_OPTIONS);
1751 stmt.bindString(3, Settings.System.SIP_ASK_ME_EACH_TIME);
1752 stmt.execute();
1753 db.setTransactionSuccessful();
1754 } finally {
1755 db.endTransaction();
1756 if (stmt != null) stmt.close();
1757 }
1758 upgradeVersion = 110;
1759 }
1760
John Spurlock7d424b62014-09-09 17:05:54 -04001761 if (upgradeVersion < 111) {
1762 // reset ringer mode, so it doesn't force zen mode to follow
Xiaohui Chen43765b72015-08-31 10:57:33 -07001763 if (mUserHandle == UserHandle.USER_SYSTEM) {
John Spurlock7d424b62014-09-09 17:05:54 -04001764 db.beginTransaction();
1765 SQLiteStatement stmt = null;
1766 try {
1767 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1768 + " VALUES(?,?);");
1769 loadSetting(stmt, Settings.Global.MODE_RINGER, AudioManager.RINGER_MODE_NORMAL);
1770 db.setTransactionSuccessful();
1771 } finally {
1772 db.endTransaction();
1773 if (stmt != null) stmt.close();
1774 }
1775 }
1776 upgradeVersion = 111;
1777 }
1778
Jerome Poichet550021e2014-09-11 10:38:12 -07001779 if (upgradeVersion < 112) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001780 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jerome Poichet550021e2014-09-11 10:38:12 -07001781 // When device name was added, we went with Manufacturer + Model, device name should
1782 // actually be Model only.
1783 // Update device name to Model if it wasn't modified by user.
1784 db.beginTransaction();
1785 SQLiteStatement stmt = null;
1786 try {
1787 stmt = db.compileStatement("UPDATE global SET value = ? "
1788 + " WHERE name = ? AND value = ?");
1789 stmt.bindString(1, getDefaultDeviceName()); // new default device name
1790 stmt.bindString(2, Settings.Global.DEVICE_NAME);
1791 stmt.bindString(3, getOldDefaultDeviceName()); // old default device name
1792 stmt.execute();
1793 db.setTransactionSuccessful();
1794 } finally {
1795 db.endTransaction();
1796 if (stmt != null) stmt.close();
1797 }
1798 }
1799 upgradeVersion = 112;
1800 }
1801
Jeff Brown05af6ad2014-09-30 20:54:30 -07001802 if (upgradeVersion < 113) {
1803 db.beginTransaction();
1804 SQLiteStatement stmt = null;
1805 try {
1806 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1807 + " VALUES(?,?);");
1808 loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT,
1809 R.integer.def_sleep_timeout);
1810 db.setTransactionSuccessful();
1811 } finally {
1812 db.endTransaction();
1813 if (stmt != null) stmt.close();
1814 }
1815 upgradeVersion = 113;
1816 }
1817
Bryce Leefb1cf362014-10-22 16:56:08 -07001818 // We skipped 114 to handle a merge conflict with the introduction of theater mode.
1819
1820 if (upgradeVersion < 115) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001821 if (mUserHandle == UserHandle.USER_SYSTEM) {
Bryce Leefb1cf362014-10-22 16:56:08 -07001822 db.beginTransaction();
1823 SQLiteStatement stmt = null;
1824 try {
1825 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
1826 + " VALUES(?,?);");
1827 loadBooleanSetting(stmt, Global.THEATER_MODE_ON,
1828 R.bool.def_theater_mode_on);
1829 db.setTransactionSuccessful();
1830 } finally {
1831 db.endTransaction();
1832 if (stmt != null) stmt.close();
1833 }
Bryce Lee584a4452014-10-21 15:55:55 -07001834 }
Bryce Leefb1cf362014-10-22 16:56:08 -07001835 upgradeVersion = 115;
1836 }
1837
1838 if (upgradeVersion < 116) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001839 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate04e68272014-10-22 10:36:42 -07001840 db.beginTransaction();
1841 SQLiteStatement stmt = null;
1842 try {
1843 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
1844 + " VALUES(?,?);");
Svetoslav683914b2015-01-15 14:22:26 -08001845 loadSetting(stmt, Settings.Global.ENHANCED_4G_MODE_ENABLED,
1846 ImsConfig.FeatureValueConstants.ON);
Christopher Tate04e68272014-10-22 10:36:42 -07001847 db.setTransactionSuccessful();
1848 } finally {
1849 db.endTransaction();
1850 if (stmt != null) stmt.close();
1851 }
Libin.Tang@motorola.com0499bb52014-10-10 14:55:57 -05001852 }
Bryce Leefb1cf362014-10-22 16:56:08 -07001853 upgradeVersion = 116;
Libin.Tang@motorola.com0499bb52014-10-10 14:55:57 -05001854 }
Bryce Lee584a4452014-10-21 15:55:55 -07001855
Jason Monk94cfd9d2014-10-31 13:18:21 -04001856 if (upgradeVersion < 117) {
1857 db.beginTransaction();
1858 try {
1859 String[] systemToSecure = {
1860 Settings.Secure.LOCK_TO_APP_EXIT_LOCKED
1861 };
1862 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, systemToSecure, true);
1863 db.setTransactionSuccessful();
1864 } finally {
1865 db.endTransaction();
1866 }
1867 upgradeVersion = 117;
1868 }
1869
John Spurlock8c51d0b2014-11-07 15:14:21 -05001870 if (upgradeVersion < 118) {
1871 // Reset rotation-lock-for-accessibility on upgrade, since it now hides the display
1872 // setting.
1873 db.beginTransaction();
1874 SQLiteStatement stmt = null;
1875 try {
1876 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1877 + " VALUES(?,?);");
1878 loadSetting(stmt, Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0);
1879 db.setTransactionSuccessful();
1880 } finally {
1881 db.endTransaction();
1882 if (stmt != null) stmt.close();
1883 }
1884 upgradeVersion = 118;
1885 }
Svetoslav683914b2015-01-15 14:22:26 -08001886
Jeff Brown503cffc2015-03-26 18:08:51 -07001887 /*
Svetoslav683914b2015-01-15 14:22:26 -08001888 * IMPORTANT: Do not add any more upgrade steps here as the global,
1889 * secure, and system settings are no longer stored in a database
Jeff Brown503cffc2015-03-26 18:08:51 -07001890 * but are kept in memory and persisted to XML.
Svetoslav683914b2015-01-15 14:22:26 -08001891 *
Jeff Brown503cffc2015-03-26 18:08:51 -07001892 * See: SettingsProvider.UpgradeController#onUpgradeLocked
Svetoslav683914b2015-01-15 14:22:26 -08001893 */
1894
Daniel Sandler1c7fa482010-03-10 09:45:01 -05001895 if (upgradeVersion != currentVersion) {
Svetoslav683914b2015-01-15 14:22:26 -08001896 recreateDatabase(db, oldVersion, upgradeVersion, currentVersion);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001897 }
1898 }
1899
Svetoslav683914b2015-01-15 14:22:26 -08001900 public void recreateDatabase(SQLiteDatabase db, int oldVersion,
1901 int upgradeVersion, int currentVersion) {
1902 db.execSQL("DROP TABLE IF EXISTS global");
1903 db.execSQL("DROP TABLE IF EXISTS globalIndex1");
1904 db.execSQL("DROP TABLE IF EXISTS system");
1905 db.execSQL("DROP INDEX IF EXISTS systemIndex1");
1906 db.execSQL("DROP TABLE IF EXISTS secure");
1907 db.execSQL("DROP INDEX IF EXISTS secureIndex1");
1908 db.execSQL("DROP TABLE IF EXISTS gservices");
1909 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1");
1910 db.execSQL("DROP TABLE IF EXISTS bluetooth_devices");
1911 db.execSQL("DROP TABLE IF EXISTS bookmarks");
1912 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex1");
1913 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex2");
1914 db.execSQL("DROP TABLE IF EXISTS favorites");
1915
1916 onCreate(db);
1917
1918 // Added for diagnosing settings.db wipes after the fact
1919 String wipeReason = oldVersion + "/" + upgradeVersion + "/" + currentVersion;
1920 db.execSQL("INSERT INTO secure(name,value) values('" +
1921 "wiped_db_reason" + "','" + wipeReason + "');");
1922 }
1923
1924 private String[] setToStringArray(Set<String> set) {
Christopher Tatea96798e42012-09-06 19:07:19 -07001925 String[] array = new String[set.size()];
1926 return set.toArray(array);
1927 }
1928
Christopher Tate06efb532012-08-24 15:29:27 -07001929 private void moveSettingsToNewTable(SQLiteDatabase db,
1930 String sourceTable, String destTable,
Christopher Tate92198742012-09-07 12:00:13 -07001931 String[] settingsToMove, boolean doIgnore) {
Christopher Tate06efb532012-08-24 15:29:27 -07001932 // Copy settings values from the source table to the dest, and remove from the source
Amith Yamasani156c4352010-03-05 17:10:03 -08001933 SQLiteStatement insertStmt = null;
1934 SQLiteStatement deleteStmt = null;
1935
1936 db.beginTransaction();
1937 try {
Christopher Tate92198742012-09-07 12:00:13 -07001938 insertStmt = db.compileStatement("INSERT "
1939 + (doIgnore ? " OR IGNORE " : "")
1940 + " INTO " + destTable + " (name,value) SELECT name,value FROM "
Christopher Tate06efb532012-08-24 15:29:27 -07001941 + sourceTable + " WHERE name=?");
1942 deleteStmt = db.compileStatement("DELETE FROM " + sourceTable + " WHERE name=?");
Amith Yamasani156c4352010-03-05 17:10:03 -08001943
1944 for (String setting : settingsToMove) {
1945 insertStmt.bindString(1, setting);
1946 insertStmt.execute();
1947
1948 deleteStmt.bindString(1, setting);
1949 deleteStmt.execute();
1950 }
1951 db.setTransactionSuccessful();
1952 } finally {
1953 db.endTransaction();
1954 if (insertStmt != null) {
1955 insertStmt.close();
1956 }
1957 if (deleteStmt != null) {
1958 deleteStmt.close();
1959 }
1960 }
1961 }
1962
Jeff Sharkey0ac10282012-10-01 12:50:22 -07001963 /**
1964 * Move any settings with the given prefixes from the source table to the
1965 * destination table.
1966 */
1967 private void movePrefixedSettingsToNewTable(
1968 SQLiteDatabase db, String sourceTable, String destTable, String[] prefixesToMove) {
1969 SQLiteStatement insertStmt = null;
1970 SQLiteStatement deleteStmt = null;
1971
1972 db.beginTransaction();
1973 try {
1974 insertStmt = db.compileStatement("INSERT INTO " + destTable
1975 + " (name,value) SELECT name,value FROM " + sourceTable
1976 + " WHERE substr(name,0,?)=?");
1977 deleteStmt = db.compileStatement(
1978 "DELETE FROM " + sourceTable + " WHERE substr(name,0,?)=?");
1979
1980 for (String prefix : prefixesToMove) {
1981 insertStmt.bindLong(1, prefix.length() + 1);
1982 insertStmt.bindString(2, prefix);
1983 insertStmt.execute();
1984
1985 deleteStmt.bindLong(1, prefix.length() + 1);
1986 deleteStmt.bindString(2, prefix);
1987 deleteStmt.execute();
1988 }
1989 db.setTransactionSuccessful();
1990 } finally {
1991 db.endTransaction();
1992 if (insertStmt != null) {
1993 insertStmt.close();
1994 }
1995 if (deleteStmt != null) {
1996 deleteStmt.close();
1997 }
1998 }
1999 }
2000
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002001 private void upgradeLockPatternLocation(SQLiteDatabase db) {
Christopher Tate06efb532012-08-24 15:29:27 -07002002 Cursor c = db.query(TABLE_SYSTEM, new String[] {"_id", "value"}, "name='lock_pattern'",
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002003 null, null, null, null);
2004 if (c.getCount() > 0) {
2005 c.moveToFirst();
2006 String lockPattern = c.getString(1);
2007 if (!TextUtils.isEmpty(lockPattern)) {
2008 // Convert lock pattern
2009 try {
Jim Miller31f90b62010-01-20 13:35:20 -08002010 LockPatternUtils lpu = new LockPatternUtils(mContext);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002011 List<LockPatternView.Cell> cellPattern =
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002012 LockPatternUtils.stringToPattern(lockPattern);
Xiaohui Chen43765b72015-08-31 10:57:33 -07002013 lpu.saveLockPattern(cellPattern, null, UserHandle.USER_SYSTEM);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002014 } catch (IllegalArgumentException e) {
2015 // Don't want corrupted lock pattern to hang the reboot process
2016 }
2017 }
2018 c.close();
Christopher Tate06efb532012-08-24 15:29:27 -07002019 db.delete(TABLE_SYSTEM, "name='lock_pattern'", null);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002020 } else {
2021 c.close();
2022 }
2023 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002024
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07002025 private void upgradeScreenTimeoutFromNever(SQLiteDatabase db) {
2026 // See if the timeout is -1 (for "Never").
Christopher Tate06efb532012-08-24 15:29:27 -07002027 Cursor c = db.query(TABLE_SYSTEM, new String[] { "_id", "value" }, "name=? AND value=?",
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07002028 new String[] { Settings.System.SCREEN_OFF_TIMEOUT, "-1" },
2029 null, null, null);
2030
2031 SQLiteStatement stmt = null;
2032 if (c.getCount() > 0) {
2033 c.close();
2034 try {
2035 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
2036 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002037
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07002038 // Set the timeout to 30 minutes in milliseconds
Amith Yamasanicd66caf2010-04-12 15:49:12 -07002039 loadSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
2040 Integer.toString(30 * 60 * 1000));
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07002041 } finally {
2042 if (stmt != null) stmt.close();
2043 }
2044 } else {
2045 c.close();
2046 }
2047 }
2048
Amith Yamasani398c83c2011-12-13 10:38:47 -08002049 private void upgradeVibrateSettingFromNone(SQLiteDatabase db) {
2050 int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON, 0);
2051 // If the ringer vibrate value is invalid, set it to the default
2052 if ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_OFF) {
John Spurlock61560172015-02-06 19:46:04 -05002053 vibrateSetting = AudioSystem.getValueForVibrateSetting(0,
Amith Yamasani398c83c2011-12-13 10:38:47 -08002054 AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
2055 }
2056 // Apply the same setting to the notification vibrate value
John Spurlock61560172015-02-06 19:46:04 -05002057 vibrateSetting = AudioSystem.getValueForVibrateSetting(vibrateSetting,
Amith Yamasani398c83c2011-12-13 10:38:47 -08002058 AudioManager.VIBRATE_TYPE_NOTIFICATION, vibrateSetting);
2059
2060 SQLiteStatement stmt = null;
2061 try {
2062 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
2063 + " VALUES(?,?);");
2064 loadSetting(stmt, Settings.System.VIBRATE_ON, vibrateSetting);
2065 } finally {
2066 if (stmt != null)
2067 stmt.close();
2068 }
2069 }
2070
Amith Yamasani79373f62010-11-18 16:32:48 -08002071 private void upgradeScreenTimeout(SQLiteDatabase db) {
2072 // Change screen timeout to current default
2073 db.beginTransaction();
2074 SQLiteStatement stmt = null;
2075 try {
2076 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
2077 + " VALUES(?,?);");
2078 loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
2079 R.integer.def_screen_off_timeout);
2080 db.setTransactionSuccessful();
2081 } finally {
2082 db.endTransaction();
2083 if (stmt != null)
2084 stmt.close();
2085 }
2086 }
2087
Amith Yamasanif50c5112011-01-07 11:32:30 -08002088 private void upgradeAutoBrightness(SQLiteDatabase db) {
2089 db.beginTransaction();
2090 try {
2091 String value =
2092 mContext.getResources().getBoolean(
2093 R.bool.def_screen_brightness_automatic_mode) ? "1" : "0";
2094 db.execSQL("INSERT OR REPLACE INTO system(name,value) values('" +
2095 Settings.System.SCREEN_BRIGHTNESS_MODE + "','" + value + "');");
2096 db.setTransactionSuccessful();
2097 } finally {
2098 db.endTransaction();
2099 }
2100 }
2101
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002102 /**
2103 * Loads the default set of bookmarked shortcuts from an xml file.
2104 *
2105 * @param db The database to write the values into
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002106 */
Jeff Brown6651a632011-11-28 12:59:11 -08002107 private void loadBookmarks(SQLiteDatabase db) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002108 ContentValues values = new ContentValues();
2109
2110 PackageManager packageManager = mContext.getPackageManager();
Romain Guyf02811f2010-03-09 16:33:51 -08002111 try {
2112 XmlResourceParser parser = mContext.getResources().getXml(R.xml.bookmarks);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002113 XmlUtils.beginDocument(parser, "bookmarks");
2114
Romain Guyf02811f2010-03-09 16:33:51 -08002115 final int depth = parser.getDepth();
2116 int type;
2117
2118 while (((type = parser.next()) != XmlPullParser.END_TAG ||
2119 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
2120
2121 if (type != XmlPullParser.START_TAG) {
2122 continue;
2123 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002124
2125 String name = parser.getName();
2126 if (!"bookmark".equals(name)) {
2127 break;
2128 }
2129
2130 String pkg = parser.getAttributeValue(null, "package");
2131 String cls = parser.getAttributeValue(null, "class");
2132 String shortcutStr = parser.getAttributeValue(null, "shortcut");
Jeff Brown6651a632011-11-28 12:59:11 -08002133 String category = parser.getAttributeValue(null, "category");
Romain Guyf02811f2010-03-09 16:33:51 -08002134
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -07002135 int shortcutValue = shortcutStr.charAt(0);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002136 if (TextUtils.isEmpty(shortcutStr)) {
2137 Log.w(TAG, "Unable to get shortcut for: " + pkg + "/" + cls);
Jeff Brown6651a632011-11-28 12:59:11 -08002138 continue;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002139 }
Romain Guyf02811f2010-03-09 16:33:51 -08002140
Jeff Brown6651a632011-11-28 12:59:11 -08002141 final Intent intent;
2142 final String title;
2143 if (pkg != null && cls != null) {
2144 ActivityInfo info = null;
2145 ComponentName cn = new ComponentName(pkg, cls);
Romain Guyf02811f2010-03-09 16:33:51 -08002146 try {
2147 info = packageManager.getActivityInfo(cn, 0);
Jeff Brown6651a632011-11-28 12:59:11 -08002148 } catch (PackageManager.NameNotFoundException e) {
2149 String[] packages = packageManager.canonicalToCurrentPackageNames(
2150 new String[] { pkg });
2151 cn = new ComponentName(packages[0], cls);
2152 try {
2153 info = packageManager.getActivityInfo(cn, 0);
2154 } catch (PackageManager.NameNotFoundException e1) {
2155 Log.w(TAG, "Unable to add bookmark: " + pkg + "/" + cls, e);
2156 continue;
2157 }
Romain Guyf02811f2010-03-09 16:33:51 -08002158 }
Jeff Brown6651a632011-11-28 12:59:11 -08002159
2160 intent = new Intent(Intent.ACTION_MAIN, null);
2161 intent.addCategory(Intent.CATEGORY_LAUNCHER);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002162 intent.setComponent(cn);
Jeff Brown6651a632011-11-28 12:59:11 -08002163 title = info.loadLabel(packageManager).toString();
2164 } else if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002165 intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002166 title = "";
2167 } else {
2168 Log.w(TAG, "Unable to add bookmark for shortcut " + shortcutStr
2169 + ": missing package/class or category attributes");
2170 continue;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002171 }
Jeff Brown6651a632011-11-28 12:59:11 -08002172
2173 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2174 values.put(Settings.Bookmarks.INTENT, intent.toUri(0));
2175 values.put(Settings.Bookmarks.TITLE, title);
2176 values.put(Settings.Bookmarks.SHORTCUT, shortcutValue);
2177 db.delete("bookmarks", "shortcut = ?",
2178 new String[] { Integer.toString(shortcutValue) });
2179 db.insert("bookmarks", null, values);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002180 }
2181 } catch (XmlPullParserException e) {
2182 Log.w(TAG, "Got execption parsing bookmarks.", e);
2183 } catch (IOException e) {
2184 Log.w(TAG, "Got execption parsing bookmarks.", e);
2185 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002186 }
2187
2188 /**
2189 * Loads the default volume levels. It is actually inserting the index of
2190 * the volume array for each of the volume controls.
2191 *
2192 * @param db the database to insert the volume levels into
2193 */
2194 private void loadVolumeLevels(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07002195 SQLiteStatement stmt = null;
2196 try {
2197 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
2198 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002199
Vasu Nori89206fdb2010-03-22 10:37:03 -07002200 loadSetting(stmt, Settings.System.VOLUME_MUSIC,
John Spurlock61560172015-02-06 19:46:04 -05002201 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_MUSIC));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002202 loadSetting(stmt, Settings.System.VOLUME_RING,
John Spurlock61560172015-02-06 19:46:04 -05002203 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_RING));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002204 loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
John Spurlock61560172015-02-06 19:46:04 -05002205 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_SYSTEM));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002206 loadSetting(
2207 stmt,
2208 Settings.System.VOLUME_VOICE,
John Spurlock61560172015-02-06 19:46:04 -05002209 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_VOICE_CALL));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002210 loadSetting(stmt, Settings.System.VOLUME_ALARM,
John Spurlock61560172015-02-06 19:46:04 -05002211 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_ALARM));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002212 loadSetting(
2213 stmt,
2214 Settings.System.VOLUME_NOTIFICATION,
John Spurlock61560172015-02-06 19:46:04 -05002215 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_NOTIFICATION));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002216 loadSetting(
2217 stmt,
2218 Settings.System.VOLUME_BLUETOOTH_SCO,
John Spurlock61560172015-02-06 19:46:04 -05002219 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002220
Eric Laurentc1d41662011-07-19 11:21:13 -07002221 // By default:
2222 // - ringtones, notification, system and music streams are affected by ringer mode
2223 // on non voice capable devices (tablets)
2224 // - ringtones, notification and system streams are affected by ringer mode
2225 // on voice capable devices (phones)
2226 int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
2227 (1 << AudioManager.STREAM_NOTIFICATION) |
2228 (1 << AudioManager.STREAM_SYSTEM) |
2229 (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
2230 if (!mContext.getResources().getBoolean(
2231 com.android.internal.R.bool.config_voice_capable)) {
2232 ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
2233 }
Vasu Nori89206fdb2010-03-22 10:37:03 -07002234 loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
Eric Laurentc1d41662011-07-19 11:21:13 -07002235 ringerModeAffectedStreams);
2236
Vasu Nori89206fdb2010-03-22 10:37:03 -07002237 loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
John Spurlock61560172015-02-06 19:46:04 -05002238 AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED);
Vasu Nori89206fdb2010-03-22 10:37:03 -07002239 } finally {
2240 if (stmt != null) stmt.close();
2241 }
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002242
2243 loadVibrateWhenRingingSetting(db);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002244 }
2245
2246 private void loadVibrateSetting(SQLiteDatabase db, boolean deleteOld) {
2247 if (deleteOld) {
2248 db.execSQL("DELETE FROM system WHERE name='" + Settings.System.VIBRATE_ON + "'");
2249 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002250
Vasu Nori89206fdb2010-03-22 10:37:03 -07002251 SQLiteStatement stmt = null;
2252 try {
2253 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
2254 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002255
Amith Yamasani5cd15002011-11-16 11:19:48 -08002256 // Vibrate on by default for ringer, on for notification
Vasu Nori89206fdb2010-03-22 10:37:03 -07002257 int vibrate = 0;
John Spurlock61560172015-02-06 19:46:04 -05002258 vibrate = AudioSystem.getValueForVibrateSetting(vibrate,
Amith Yamasani5cd15002011-11-16 11:19:48 -08002259 AudioManager.VIBRATE_TYPE_NOTIFICATION,
2260 AudioManager.VIBRATE_SETTING_ONLY_SILENT);
John Spurlock61560172015-02-06 19:46:04 -05002261 vibrate |= AudioSystem.getValueForVibrateSetting(vibrate,
Amith Yamasani5cd15002011-11-16 11:19:48 -08002262 AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
Vasu Nori89206fdb2010-03-22 10:37:03 -07002263 loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate);
2264 } finally {
2265 if (stmt != null) stmt.close();
2266 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002267 }
2268
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002269 private void loadVibrateWhenRingingSetting(SQLiteDatabase db) {
2270 // The default should be off. VIBRATE_SETTING_ONLY_SILENT should also be ignored here.
2271 // Phone app should separately check whether AudioManager#getRingerMode() returns
2272 // RINGER_MODE_VIBRATE, with which the device should vibrate anyway.
2273 int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON,
2274 AudioManager.VIBRATE_SETTING_OFF);
2275 boolean vibrateWhenRinging = ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_ON);
2276
2277 SQLiteStatement stmt = null;
2278 try {
2279 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
2280 + " VALUES(?,?);");
2281 loadSetting(stmt, Settings.System.VIBRATE_WHEN_RINGING, vibrateWhenRinging ? 1 : 0);
2282 } finally {
2283 if (stmt != null) stmt.close();
2284 }
2285 }
2286
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002287 private void loadSettings(SQLiteDatabase db) {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002288 loadSystemSettings(db);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002289 loadSecureSettings(db);
Xiaohui Chen43765b72015-08-31 10:57:33 -07002290 // The global table only exists for the 'owner/system' user
2291 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate06efb532012-08-24 15:29:27 -07002292 loadGlobalSettings(db);
2293 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002294 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002295
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002296 private void loadSystemSettings(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07002297 SQLiteStatement stmt = null;
2298 try {
2299 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
2300 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002301
Vasu Nori89206fdb2010-03-22 10:37:03 -07002302 loadBooleanSetting(stmt, Settings.System.DIM_SCREEN,
2303 R.bool.def_dim_screen);
Vasu Nori89206fdb2010-03-22 10:37:03 -07002304 loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
2305 R.integer.def_screen_off_timeout);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002306
Vasu Nori89206fdb2010-03-22 10:37:03 -07002307 // Set default cdma DTMF type
2308 loadSetting(stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002309
Vasu Nori89206fdb2010-03-22 10:37:03 -07002310 // Set default hearing aid
2311 loadSetting(stmt, Settings.System.HEARING_AID, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002312
Vasu Nori89206fdb2010-03-22 10:37:03 -07002313 // Set default tty mode
2314 loadSetting(stmt, Settings.System.TTY_MODE, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002315
Vasu Nori89206fdb2010-03-22 10:37:03 -07002316 loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS,
2317 R.integer.def_screen_brightness);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002318
Vasu Nori89206fdb2010-03-22 10:37:03 -07002319 loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE,
2320 R.bool.def_screen_brightness_automatic_mode);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002321
Vasu Nori89206fdb2010-03-22 10:37:03 -07002322 loadDefaultAnimationSettings(stmt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002323
Vasu Nori89206fdb2010-03-22 10:37:03 -07002324 loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION,
2325 R.bool.def_accelerometer_rotation);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002326
Vasu Nori89206fdb2010-03-22 10:37:03 -07002327 loadDefaultHapticSettings(stmt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002328
Vasu Nori89206fdb2010-03-22 10:37:03 -07002329 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
2330 R.bool.def_notification_pulse);
Amith Yamasani42722bf2011-07-22 10:34:27 -07002331
Vasu Nori89206fdb2010-03-22 10:37:03 -07002332 loadUISoundEffectsSettings(stmt);
Amith Yamasani42722bf2011-07-22 10:34:27 -07002333
Jeff Brown1a84fd12011-06-02 01:26:32 -07002334 loadIntegerSetting(stmt, Settings.System.POINTER_SPEED,
2335 R.integer.def_pointer_speed);
Jeff Brown503cffc2015-03-26 18:08:51 -07002336
2337 /*
2338 * IMPORTANT: Do not add any more upgrade steps here as the global,
2339 * secure, and system settings are no longer stored in a database
2340 * but are kept in memory and persisted to XML.
2341 *
2342 * See: SettingsProvider.UpgradeController#onUpgradeLocked
2343 */
Vasu Nori89206fdb2010-03-22 10:37:03 -07002344 } finally {
2345 if (stmt != null) stmt.close();
2346 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002347 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002348
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002349 private void loadUISoundEffectsSettings(SQLiteStatement stmt) {
Amith Yamasani42722bf2011-07-22 10:34:27 -07002350 loadBooleanSetting(stmt, Settings.System.DTMF_TONE_WHEN_DIALING,
2351 R.bool.def_dtmf_tones_enabled);
2352 loadBooleanSetting(stmt, Settings.System.SOUND_EFFECTS_ENABLED,
2353 R.bool.def_sound_effects_enabled);
2354 loadBooleanSetting(stmt, Settings.System.HAPTIC_FEEDBACK_ENABLED,
2355 R.bool.def_haptic_feedback);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002356
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002357 loadIntegerSetting(stmt, Settings.System.LOCKSCREEN_SOUNDS_ENABLED,
2358 R.integer.def_lockscreen_sounds_enabled);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002359 }
2360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002361 private void loadDefaultAnimationSettings(SQLiteStatement stmt) {
2362 loadFractionSetting(stmt, Settings.System.WINDOW_ANIMATION_SCALE,
2363 R.fraction.def_window_animation_scale, 1);
2364 loadFractionSetting(stmt, Settings.System.TRANSITION_ANIMATION_SCALE,
2365 R.fraction.def_window_transition_scale, 1);
2366 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002367
Dianne Hackborn075a18d2009-09-26 12:43:19 -07002368 private void loadDefaultHapticSettings(SQLiteStatement stmt) {
2369 loadBooleanSetting(stmt, Settings.System.HAPTIC_FEEDBACK_ENABLED,
2370 R.bool.def_haptic_feedback);
2371 }
2372
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002373 private void loadSecureSettings(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07002374 SQLiteStatement stmt = null;
2375 try {
2376 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
2377 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002378
Vasu Nori89206fdb2010-03-22 10:37:03 -07002379 loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
2380 R.string.def_location_providers_allowed);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002381
Vasu Nori89206fdb2010-03-22 10:37:03 -07002382 // Don't do this. The SystemServer will initialize ADB_ENABLED from a
2383 // persistent system property instead.
2384 //loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002385
Vasu Nori89206fdb2010-03-22 10:37:03 -07002386 // Allow mock locations default, based on build
2387 loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION,
2388 "1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002389
Vasu Nori89206fdb2010-03-22 10:37:03 -07002390 loadSecure35Settings(stmt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002391
Vasu Nori89206fdb2010-03-22 10:37:03 -07002392 loadBooleanSetting(stmt, Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND,
2393 R.bool.def_mount_play_notification_snd);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002394
Vasu Nori89206fdb2010-03-22 10:37:03 -07002395 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_AUTOSTART,
2396 R.bool.def_mount_ums_autostart);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002397
Vasu Nori89206fdb2010-03-22 10:37:03 -07002398 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_PROMPT,
2399 R.bool.def_mount_ums_prompt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002400
Vasu Nori89206fdb2010-03-22 10:37:03 -07002401 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED,
2402 R.bool.def_mount_ums_notify_enabled);
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -07002403
Svetoslav Ganov54d068e2011-03-02 12:58:40 -08002404 loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT,
2405 R.integer.def_long_press_timeout_millis);
Svetoslav Ganova28a16d2011-07-28 11:24:21 -07002406
2407 loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED,
2408 R.bool.def_touch_exploration_enabled);
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08002409
2410 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD,
2411 R.bool.def_accessibility_speak_password);
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08002412
Amith Yamasanid1645f82012-06-12 11:53:26 -07002413 if (SystemProperties.getBoolean("ro.lockscreen.disable.default", false) == true) {
2414 loadSetting(stmt, Settings.System.LOCKSCREEN_DISABLED, "1");
2415 } else {
2416 loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED,
2417 R.bool.def_lockscreen_disabled);
2418 }
Mike Lockwood23955272011-10-21 11:22:48 -04002419
John Spurlock634471e2012-08-09 10:41:37 -04002420 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED,
John Spurlocked108f32012-10-18 16:49:24 -04002421 com.android.internal.R.bool.config_dreamsEnabledByDefault);
John Spurlock634471e2012-08-09 10:41:37 -04002422 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
John Spurlocked108f32012-10-18 16:49:24 -04002423 com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04002424 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
John Spurlocked108f32012-10-18 16:49:24 -04002425 com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04002426 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_COMPONENTS,
John Spurlocked108f32012-10-18 16:49:24 -04002427 com.android.internal.R.string.config_dreamsDefaultComponent);
John Spurlock1a868b72012-08-22 09:56:51 -04002428 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT,
John Spurlocked108f32012-10-18 16:49:24 -04002429 com.android.internal.R.string.config_dreamsDefaultComponent);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07002430
2431 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
2432 R.bool.def_accessibility_display_magnification_enabled);
2433
2434 loadFractionSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
2435 R.fraction.def_accessibility_display_magnification_scale, 1);
2436
John Spurlock7f1c2482012-10-05 11:15:28 -04002437 loadBooleanSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
2438 R.bool.def_user_setup_complete);
Mike Lockwoodc02c4a72014-01-07 14:46:22 -08002439
2440 loadStringSetting(stmt, Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS,
2441 R.string.def_immersive_mode_confirmations);
2442
Christopher Tateaa036a22014-05-19 16:33:27 -07002443 loadBooleanSetting(stmt, Settings.Secure.INSTALL_NON_MARKET_APPS,
2444 R.bool.def_install_non_market_apps);
2445
Jeff Browna20dda42014-05-27 20:57:24 -07002446 loadBooleanSetting(stmt, Settings.Secure.WAKE_GESTURE_ENABLED,
2447 R.bool.def_wake_gesture_enabled);
2448
Dan Sandler52e5701e2014-07-22 23:14:54 -04002449 loadIntegerSetting(stmt, Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
2450 R.integer.def_lock_screen_show_notifications);
2451
Chris Wrencd8f4f72014-08-27 18:48:13 -04002452 loadBooleanSetting(stmt, Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
2453 R.bool.def_lock_screen_allow_private_notifications);
2454
Jeff Brown05af6ad2014-09-30 20:54:30 -07002455 loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT,
2456 R.integer.def_sleep_timeout);
Jeff Brown503cffc2015-03-26 18:08:51 -07002457
2458 /*
2459 * IMPORTANT: Do not add any more upgrade steps here as the global,
2460 * secure, and system settings are no longer stored in a database
2461 * but are kept in memory and persisted to XML.
2462 *
2463 * See: SettingsProvider.UpgradeController#onUpgradeLocked
2464 */
Vasu Nori89206fdb2010-03-22 10:37:03 -07002465 } finally {
2466 if (stmt != null) stmt.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002467 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002468 }
2469
Dianne Hackborncf098292009-07-01 19:55:20 -07002470 private void loadSecure35Settings(SQLiteStatement stmt) {
2471 loadBooleanSetting(stmt, Settings.Secure.BACKUP_ENABLED,
2472 R.bool.def_backup_enabled);
Jim Miller31f90b62010-01-20 13:35:20 -08002473
Dianne Hackborncf098292009-07-01 19:55:20 -07002474 loadStringSetting(stmt, Settings.Secure.BACKUP_TRANSPORT,
2475 R.string.def_backup_transport);
2476 }
Jim Miller61766772010-02-12 14:56:49 -08002477
Christopher Tate06efb532012-08-24 15:29:27 -07002478 private void loadGlobalSettings(SQLiteDatabase db) {
2479 SQLiteStatement stmt = null;
2480 try {
2481 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
2482 + " VALUES(?,?);");
2483
2484 // --- Previously in 'system'
2485 loadBooleanSetting(stmt, Settings.Global.AIRPLANE_MODE_ON,
2486 R.bool.def_airplane_mode_on);
2487
Bryce Lee584a4452014-10-21 15:55:55 -07002488 loadBooleanSetting(stmt, Settings.Global.THEATER_MODE_ON,
2489 R.bool.def_theater_mode_on);
2490
Christopher Tate06efb532012-08-24 15:29:27 -07002491 loadStringSetting(stmt, Settings.Global.AIRPLANE_MODE_RADIOS,
2492 R.string.def_airplane_mode_radios);
2493
2494 loadStringSetting(stmt, Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
2495 R.string.airplane_mode_toggleable_radios);
2496
2497 loadBooleanSetting(stmt, Settings.Global.ASSISTED_GPS_ENABLED,
2498 R.bool.assisted_gps_enabled);
2499
2500 loadBooleanSetting(stmt, Settings.Global.AUTO_TIME,
2501 R.bool.def_auto_time); // Sync time to NITZ
2502
2503 loadBooleanSetting(stmt, Settings.Global.AUTO_TIME_ZONE,
2504 R.bool.def_auto_time_zone); // Sync timezone to NITZ
2505
2506 loadSetting(stmt, Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
2507 ("1".equals(SystemProperties.get("ro.kernel.qemu")) ||
2508 mContext.getResources().getBoolean(R.bool.def_stay_on_while_plugged_in))
2509 ? 1 : 0);
2510
2511 loadIntegerSetting(stmt, Settings.Global.WIFI_SLEEP_POLICY,
2512 R.integer.def_wifi_sleep_policy);
2513
Eric Laurent55b02222012-10-03 11:56:23 -07002514 loadSetting(stmt, Settings.Global.MODE_RINGER,
2515 AudioManager.RINGER_MODE_NORMAL);
2516
Christopher Tate06efb532012-08-24 15:29:27 -07002517 // --- Previously in 'secure'
Christopher Tate6f5a9a92012-09-14 17:24:28 -07002518 loadBooleanSetting(stmt, Settings.Global.PACKAGE_VERIFIER_ENABLE,
2519 R.bool.def_package_verifier_enable);
2520
2521 loadBooleanSetting(stmt, Settings.Global.WIFI_ON,
2522 R.bool.def_wifi_on);
2523
2524 loadBooleanSetting(stmt, Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
2525 R.bool.def_networks_available_notification_on);
2526
Christopher Tate06efb532012-08-24 15:29:27 -07002527 loadBooleanSetting(stmt, Settings.Global.BLUETOOTH_ON,
2528 R.bool.def_bluetooth_on);
2529
2530 // Enable or disable Cell Broadcast SMS
2531 loadSetting(stmt, Settings.Global.CDMA_CELL_BROADCAST_SMS,
2532 RILConstants.CDMA_CELL_BROADCAST_SMS_DISABLED);
2533
2534 // Data roaming default, based on build
2535 loadSetting(stmt, Settings.Global.DATA_ROAMING,
2536 "true".equalsIgnoreCase(
2537 SystemProperties.get("ro.com.android.dataroaming",
2538 "false")) ? 1 : 0);
2539
2540 loadBooleanSetting(stmt, Settings.Global.DEVICE_PROVISIONED,
2541 R.bool.def_device_provisioned);
2542
2543 final int maxBytes = mContext.getResources().getInteger(
2544 R.integer.def_download_manager_max_bytes_over_mobile);
2545 if (maxBytes > 0) {
2546 loadSetting(stmt, Settings.Global.DOWNLOAD_MAX_BYTES_OVER_MOBILE,
2547 Integer.toString(maxBytes));
2548 }
2549
2550 final int recommendedMaxBytes = mContext.getResources().getInteger(
2551 R.integer.def_download_manager_recommended_max_bytes_over_mobile);
2552 if (recommendedMaxBytes > 0) {
2553 loadSetting(stmt, Settings.Global.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE,
2554 Integer.toString(recommendedMaxBytes));
2555 }
2556
2557 // Mobile Data default, based on build
2558 loadSetting(stmt, Settings.Global.MOBILE_DATA,
2559 "true".equalsIgnoreCase(
2560 SystemProperties.get("ro.com.android.mobiledata",
2561 "true")) ? 1 : 0);
2562
2563 loadBooleanSetting(stmt, Settings.Global.NETSTATS_ENABLED,
2564 R.bool.def_netstats_enabled);
2565
Christopher Tate06efb532012-08-24 15:29:27 -07002566 loadBooleanSetting(stmt, Settings.Global.USB_MASS_STORAGE_ENABLED,
2567 R.bool.def_usb_mass_storage_enabled);
2568
2569 loadIntegerSetting(stmt, Settings.Global.WIFI_MAX_DHCP_RETRY_COUNT,
2570 R.integer.def_max_dhcp_retries);
2571
Jeff Brown89d55462012-09-19 11:33:42 -07002572 loadBooleanSetting(stmt, Settings.Global.WIFI_DISPLAY_ON,
2573 R.bool.def_wifi_display_on);
2574
Jim Millerb14288d2012-09-30 18:25:05 -07002575 loadStringSetting(stmt, Settings.Global.LOCK_SOUND,
2576 R.string.def_lock_sound);
Jim Millerb14288d2012-09-30 18:25:05 -07002577 loadStringSetting(stmt, Settings.Global.UNLOCK_SOUND,
2578 R.string.def_unlock_sound);
Adrian Roos49e057d2014-08-13 17:14:51 +02002579 loadStringSetting(stmt, Settings.Global.TRUSTED_SOUND,
2580 R.string.def_trusted_sound);
Amith Yamasani531c2372012-10-08 14:43:20 -07002581 loadIntegerSetting(stmt, Settings.Global.POWER_SOUNDS_ENABLED,
2582 R.integer.def_power_sounds_enabled);
2583 loadStringSetting(stmt, Settings.Global.LOW_BATTERY_SOUND,
2584 R.string.def_low_battery_sound);
2585 loadIntegerSetting(stmt, Settings.Global.DOCK_SOUNDS_ENABLED,
2586 R.integer.def_dock_sounds_enabled);
Vinod Krishnancf11cea2016-10-20 22:57:02 -07002587 loadIntegerSetting(stmt, Settings.Global.DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY,
2588 R.integer.def_dock_sounds_enabled_when_accessibility);
Amith Yamasani531c2372012-10-08 14:43:20 -07002589 loadStringSetting(stmt, Settings.Global.DESK_DOCK_SOUND,
2590 R.string.def_desk_dock_sound);
2591 loadStringSetting(stmt, Settings.Global.DESK_UNDOCK_SOUND,
2592 R.string.def_desk_undock_sound);
2593 loadStringSetting(stmt, Settings.Global.CAR_DOCK_SOUND,
2594 R.string.def_car_dock_sound);
2595 loadStringSetting(stmt, Settings.Global.CAR_UNDOCK_SOUND,
2596 R.string.def_car_undock_sound);
Jeff Brown84e27562012-12-07 13:56:34 -08002597 loadStringSetting(stmt, Settings.Global.WIRELESS_CHARGING_STARTED_SOUND,
2598 R.string.def_wireless_charging_started_sound);
Jim Millerb14288d2012-09-30 18:25:05 -07002599
Dmytro Dubovyk729f6682012-12-18 18:07:50 +02002600 loadIntegerSetting(stmt, Settings.Global.DOCK_AUDIO_MEDIA_ENABLED,
2601 R.integer.def_dock_audio_media_enabled);
2602
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07002603 loadSetting(stmt, Settings.Global.SET_INSTALL_LOCATION, 0);
2604 loadSetting(stmt, Settings.Global.DEFAULT_INSTALL_LOCATION,
2605 PackageHelper.APP_INSTALL_AUTO);
2606
2607 // Set default cdma emergency tone
2608 loadSetting(stmt, Settings.Global.EMERGENCY_TONE, 0);
2609
2610 // Set default cdma call auto retry
2611 loadSetting(stmt, Settings.Global.CALL_AUTO_RETRY, 0);
2612
Naveen Kalla97ecc9e2012-07-13 20:10:22 -07002613 // Set the preferred network mode to target desired value or Default
2614 // value defined in RILConstants
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07002615 int type;
Amit Mahajan4fea0922014-11-18 12:56:28 -08002616 type = RILConstants.PREFERRED_NETWORK_MODE;
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07002617 loadSetting(stmt, Settings.Global.PREFERRED_NETWORK_MODE, type);
2618
Naveen Kallab4d485c2013-07-03 16:39:27 -07002619 // Set the preferred cdma subscription source to target desired value or default
Grace Chen6ad1c5e2017-06-13 16:07:45 -07002620 // value defined in Phone
Naveen Kallab4d485c2013-07-03 16:39:27 -07002621 type = SystemProperties.getInt("ro.telephony.default_cdma_sub",
Grace Chen6ad1c5e2017-06-13 16:07:45 -07002622 Phone.PREFERRED_CDMA_SUBSCRIPTION);
Naveen Kallab4d485c2013-07-03 16:39:27 -07002623 loadSetting(stmt, Settings.Global.CDMA_SUBSCRIPTION_MODE, type);
2624
Daniel Sandlerdea64622013-09-23 16:05:57 -04002625 loadIntegerSetting(stmt, Settings.Global.LOW_BATTERY_SOUND_TIMEOUT,
2626 R.integer.def_low_battery_sound_timeout);
2627
Oskar Grönqvist2c4254e2013-12-11 14:14:33 +01002628 loadIntegerSetting(stmt, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE,
2629 R.integer.def_wifi_scan_always_available);
2630
Chris Wren5242cf32014-03-19 16:16:48 -04002631 loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED,
2632 R.integer.def_heads_up_enabled);
2633
Jerome Poichet147b4d72014-05-12 18:13:27 -07002634 loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName());
2635
Svetoslav683914b2015-01-15 14:22:26 -08002636 loadSetting(stmt, Settings.Global.ENHANCED_4G_MODE_ENABLED,
2637 ImsConfig.FeatureValueConstants.ON);
Jeff Brown503cffc2015-03-26 18:08:51 -07002638
2639 /*
2640 * IMPORTANT: Do not add any more upgrade steps here as the global,
2641 * secure, and system settings are no longer stored in a database
2642 * but are kept in memory and persisted to XML.
2643 *
2644 * See: SettingsProvider.UpgradeController#onUpgradeLocked
2645 */
Christopher Tate06efb532012-08-24 15:29:27 -07002646 } finally {
2647 if (stmt != null) stmt.close();
2648 }
2649 }
2650
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002651 private void loadSetting(SQLiteStatement stmt, String key, Object value) {
2652 stmt.bindString(1, key);
2653 stmt.bindString(2, value.toString());
2654 stmt.execute();
2655 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 private void loadStringSetting(SQLiteStatement stmt, String key, int resid) {
2658 loadSetting(stmt, key, mContext.getResources().getString(resid));
2659 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002661 private void loadBooleanSetting(SQLiteStatement stmt, String key, int resid) {
2662 loadSetting(stmt, key,
2663 mContext.getResources().getBoolean(resid) ? "1" : "0");
2664 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666 private void loadIntegerSetting(SQLiteStatement stmt, String key, int resid) {
2667 loadSetting(stmt, key,
2668 Integer.toString(mContext.getResources().getInteger(resid)));
2669 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002671 private void loadFractionSetting(SQLiteStatement stmt, String key, int resid, int base) {
2672 loadSetting(stmt, key,
2673 Float.toString(mContext.getResources().getFraction(resid, base, base)));
2674 }
Amith Yamasani5cd15002011-11-16 11:19:48 -08002675
2676 private int getIntValueFromSystem(SQLiteDatabase db, String name, int defaultValue) {
Christopher Tate06efb532012-08-24 15:29:27 -07002677 return getIntValueFromTable(db, TABLE_SYSTEM, name, defaultValue);
Svetoslav Ganov86317012012-08-15 22:13:00 -07002678 }
2679
2680 private int getIntValueFromTable(SQLiteDatabase db, String table, String name,
2681 int defaultValue) {
2682 String value = getStringValueFromTable(db, table, name, null);
2683 return (value != null) ? Integer.parseInt(value) : defaultValue;
2684 }
2685
2686 private String getStringValueFromTable(SQLiteDatabase db, String table, String name,
2687 String defaultValue) {
Amith Yamasani5cd15002011-11-16 11:19:48 -08002688 Cursor c = null;
2689 try {
Svetoslav Ganov86317012012-08-15 22:13:00 -07002690 c = db.query(table, new String[] { Settings.System.VALUE }, "name='" + name + "'",
Amith Yamasani5cd15002011-11-16 11:19:48 -08002691 null, null, null, null);
2692 if (c != null && c.moveToFirst()) {
2693 String val = c.getString(0);
Svetoslav Ganov86317012012-08-15 22:13:00 -07002694 return val == null ? defaultValue : val;
Amith Yamasani5cd15002011-11-16 11:19:48 -08002695 }
2696 } finally {
2697 if (c != null) c.close();
2698 }
Svetoslav Ganov86317012012-08-15 22:13:00 -07002699 return defaultValue;
Amith Yamasani5cd15002011-11-16 11:19:48 -08002700 }
Jerome Poichet147b4d72014-05-12 18:13:27 -07002701
Jerome Poichet550021e2014-09-11 10:38:12 -07002702 private String getOldDefaultDeviceName() {
Jeff Sharkeyad59c432014-09-12 15:56:30 -07002703 return mContext.getResources().getString(R.string.def_device_name,
Jerome Poichet550021e2014-09-11 10:38:12 -07002704 Build.MANUFACTURER, Build.MODEL);
2705 }
2706
Jerome Poichet147b4d72014-05-12 18:13:27 -07002707 private String getDefaultDeviceName() {
Jeff Sharkeyad59c432014-09-12 15:56:30 -07002708 return mContext.getResources().getString(R.string.def_device_name_simple, Build.MODEL);
Jerome Poichet147b4d72014-05-12 18:13:27 -07002709 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002710}