blob: ef90dc981870099fdbfc83f805a176471acb2d53 [file] [log] [blame]
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.providers.settings;
18
19import android.content.ComponentName;
20import android.content.ContentValues;
21import android.content.Context;
22import android.content.Intent;
23import android.content.pm.ActivityInfo;
Dianne Hackborn13579ed2012-11-28 18:05:36 -080024import android.content.pm.IPackageManager;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070025import android.content.pm.PackageManager;
Romain Guyf02811f2010-03-09 16:33:51 -080026import android.content.res.XmlResourceParser;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070027import android.database.Cursor;
28import android.database.sqlite.SQLiteDatabase;
29import android.database.sqlite.SQLiteOpenHelper;
30import android.database.sqlite.SQLiteStatement;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070031import android.media.AudioManager;
Beverlyf9af4082019-01-09 15:31:18 -050032import android.media.AudioSystem;
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;
Sandeep Gutta2a7c0d32016-03-16 21:37:25 +053043import android.telephony.TelephonyManager;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070044import android.text.TextUtils;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070045import android.util.Log;
Suchi Amalapurapu40e47252010-04-07 16:15:50 -070046
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_BACKUP_SUFFIX = "-backup";
91
Christopher Tate06efb532012-08-24 15:29:27 -070092 private static final String TABLE_SYSTEM = "system";
93 private static final String TABLE_SECURE = "secure";
94 private static final String TABLE_GLOBAL = "global";
95
Dianne Hackborn24117ce2010-07-12 15:54:38 -070096 static {
Christopher Tate06efb532012-08-24 15:29:27 -070097 mValidTables.add(TABLE_SYSTEM);
98 mValidTables.add(TABLE_SECURE);
99 mValidTables.add(TABLE_GLOBAL);
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700100
101 // These are old.
Svetoslav683914b2015-01-15 14:22:26 -0800102 mValidTables.add("bluetooth_devices");
103 mValidTables.add("bookmarks");
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700104 mValidTables.add("favorites");
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700105 mValidTables.add("old_favorites");
Svetoslav683914b2015-01-15 14:22:26 -0800106 mValidTables.add("android_metadata");
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700107 }
108
Christopher Tate06efb532012-08-24 15:29:27 -0700109 static String dbNameForUser(final int userHandle) {
110 // The owner gets the unadorned db name;
Xiaohui Chen43765b72015-08-31 10:57:33 -0700111 if (userHandle == UserHandle.USER_SYSTEM) {
Christopher Tate06efb532012-08-24 15:29:27 -0700112 return DATABASE_NAME;
113 } else {
114 // Place the database in the user-specific data tree so that it's
115 // cleaned up automatically when the user is deleted.
116 File databaseFile = new File(
117 Environment.getUserSystemDirectory(userHandle), DATABASE_NAME);
Fyodor Kupolov497b5fa2015-12-17 10:47:33 -0800118 // If databaseFile doesn't exist, database can be kept in memory. It's safe because the
119 // database will be migrated and disposed of immediately after onCreate finishes
120 if (!databaseFile.exists()) {
121 Log.i(TAG, "No previous database file exists - running in in-memory mode");
122 return null;
123 }
Christopher Tate06efb532012-08-24 15:29:27 -0700124 return databaseFile.getPath();
125 }
126 }
127
128 public DatabaseHelper(Context context, int userHandle) {
129 super(context, dbNameForUser(userHandle), null, DATABASE_VERSION);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700130 mContext = context;
Christopher Tate06efb532012-08-24 15:29:27 -0700131 mUserHandle = userHandle;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700132 }
133
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700134 public static boolean isValidTable(String name) {
135 return mValidTables.contains(name);
136 }
137
Fyodor Kupolov497b5fa2015-12-17 10:47:33 -0800138 private boolean isInMemory() {
139 return getDatabaseName() == null;
140 }
141
Svetoslav683914b2015-01-15 14:22:26 -0800142 public void dropDatabase() {
143 close();
Fyodor Kupolov497b5fa2015-12-17 10:47:33 -0800144 // No need to remove files if db is in memory
145 if (isInMemory()) {
146 return;
147 }
Svetoslav683914b2015-01-15 14:22:26 -0800148 File databaseFile = mContext.getDatabasePath(getDatabaseName());
149 if (databaseFile.exists()) {
Fyodor Kupolov15e7c622018-01-25 18:14:53 -0800150 SQLiteDatabase.deleteDatabase(databaseFile);
Svetoslav683914b2015-01-15 14:22:26 -0800151 }
152 }
153
154 public void backupDatabase() {
155 close();
Fyodor Kupolov497b5fa2015-12-17 10:47:33 -0800156 // No need to backup files if db is in memory
157 if (isInMemory()) {
158 return;
159 }
Svetoslav683914b2015-01-15 14:22:26 -0800160 File databaseFile = mContext.getDatabasePath(getDatabaseName());
161 if (!databaseFile.exists()) {
162 return;
163 }
164 File backupFile = mContext.getDatabasePath(getDatabaseName()
165 + DATABASE_BACKUP_SUFFIX);
166 if (backupFile.exists()) {
167 return;
168 }
169 databaseFile.renameTo(backupFile);
170 }
171
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800172 private void createSecureTable(SQLiteDatabase db) {
173 db.execSQL("CREATE TABLE secure (" +
174 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
175 "name TEXT UNIQUE ON CONFLICT REPLACE," +
176 "value TEXT" +
177 ");");
178 db.execSQL("CREATE INDEX secureIndex1 ON secure (name);");
179 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700180
Christopher Tate06efb532012-08-24 15:29:27 -0700181 private void createGlobalTable(SQLiteDatabase db) {
182 db.execSQL("CREATE TABLE global (" +
183 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
184 "name TEXT UNIQUE ON CONFLICT REPLACE," +
185 "value TEXT" +
186 ");");
187 db.execSQL("CREATE INDEX globalIndex1 ON global (name);");
188 }
189
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700190 @Override
191 public void onCreate(SQLiteDatabase db) {
192 db.execSQL("CREATE TABLE system (" +
193 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
194 "name TEXT UNIQUE ON CONFLICT REPLACE," +
195 "value TEXT" +
196 ");");
197 db.execSQL("CREATE INDEX systemIndex1 ON system (name);");
198
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800199 createSecureTable(db);
200
Xiaohui Chen43765b72015-08-31 10:57:33 -0700201 // Only create the global table for the singleton 'owner/system' user
202 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate06efb532012-08-24 15:29:27 -0700203 createGlobalTable(db);
204 }
205
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700206 db.execSQL("CREATE TABLE bluetooth_devices (" +
207 "_id INTEGER PRIMARY KEY," +
208 "name TEXT," +
209 "addr TEXT," +
210 "channel INTEGER," +
211 "type INTEGER" +
212 ");");
213
214 db.execSQL("CREATE TABLE bookmarks (" +
215 "_id INTEGER PRIMARY KEY," +
216 "title TEXT," +
217 "folder TEXT," +
218 "intent TEXT," +
219 "shortcut INTEGER," +
220 "ordering INTEGER" +
221 ");");
222
223 db.execSQL("CREATE INDEX bookmarksIndex1 ON bookmarks (folder);");
224 db.execSQL("CREATE INDEX bookmarksIndex2 ON bookmarks (shortcut);");
225
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700226 // Populate bookmarks table with initial bookmarks
Dianne Hackborn13579ed2012-11-28 18:05:36 -0800227 boolean onlyCore = false;
228 try {
229 onlyCore = IPackageManager.Stub.asInterface(ServiceManager.getService(
230 "package")).isOnlyCoreApps();
231 } catch (RemoteException e) {
232 }
233 if (!onlyCore) {
234 loadBookmarks(db);
235 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700236
237 // Load initial volume levels into DB
238 loadVolumeLevels(db);
239
240 // Load inital settings values
241 loadSettings(db);
242 }
243
244 @Override
245 public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700246 Log.w(TAG, "Upgrading settings database from version " + oldVersion + " to "
247 + currentVersion);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700248
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700249 int upgradeVersion = oldVersion;
250
251 // Pattern for upgrade blocks:
252 //
253 // if (upgradeVersion == [the DATABASE_VERSION you set] - 1) {
254 // .. your upgrade logic..
255 // upgradeVersion = [the DATABASE_VERSION you set]
256 // }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700257
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700258 if (upgradeVersion == 20) {
259 /*
260 * Version 21 is part of the volume control refresh. There is no
261 * longer a UI-visible for setting notification vibrate on/off (in
262 * our design), but the functionality still exists. Force the
263 * notification vibrate to on.
264 */
265 loadVibrateSetting(db, true);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700266
267 upgradeVersion = 21;
268 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700269
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700270 if (upgradeVersion < 22) {
271 upgradeVersion = 22;
272 // Upgrade the lock gesture storage location and format
273 upgradeLockPatternLocation(db);
274 }
275
276 if (upgradeVersion < 23) {
277 db.execSQL("UPDATE favorites SET iconResource=0 WHERE iconType=0");
278 upgradeVersion = 23;
279 }
280
281 if (upgradeVersion == 23) {
282 db.beginTransaction();
283 try {
284 db.execSQL("ALTER TABLE favorites ADD spanX INTEGER");
285 db.execSQL("ALTER TABLE favorites ADD spanY INTEGER");
286 // Shortcuts, applications, folders
287 db.execSQL("UPDATE favorites SET spanX=1, spanY=1 WHERE itemType<=0");
288 // Photo frames, clocks
Wink Saville04e71b32009-04-02 11:00:54 -0700289 db.execSQL(
290 "UPDATE favorites SET spanX=2, spanY=2 WHERE itemType=1000 or itemType=1002");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700291 // Search boxes
292 db.execSQL("UPDATE favorites SET spanX=4, spanY=1 WHERE itemType=1001");
293 db.setTransactionSuccessful();
294 } finally {
295 db.endTransaction();
296 }
297 upgradeVersion = 24;
298 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700299
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700300 if (upgradeVersion == 24) {
301 db.beginTransaction();
302 try {
303 // The value of the constants for preferring wifi or preferring mobile have been
304 // swapped, so reload the default.
305 db.execSQL("DELETE FROM system WHERE name='network_preference'");
306 db.execSQL("INSERT INTO system ('name', 'value') values ('network_preference', '" +
307 ConnectivityManager.DEFAULT_NETWORK_PREFERENCE + "')");
308 db.setTransactionSuccessful();
309 } finally {
310 db.endTransaction();
311 }
312 upgradeVersion = 25;
313 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800314
315 if (upgradeVersion == 25) {
316 db.beginTransaction();
317 try {
318 db.execSQL("ALTER TABLE favorites ADD uri TEXT");
319 db.execSQL("ALTER TABLE favorites ADD displayMode INTEGER");
320 db.setTransactionSuccessful();
321 } finally {
322 db.endTransaction();
323 }
324 upgradeVersion = 26;
325 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700326
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800327 if (upgradeVersion == 26) {
328 // This introduces the new secure settings table.
329 db.beginTransaction();
330 try {
331 createSecureTable(db);
332 db.setTransactionSuccessful();
333 } finally {
334 db.endTransaction();
335 }
336 upgradeVersion = 27;
337 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700338
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800339 if (upgradeVersion == 27) {
Amith Yamasani156c4352010-03-05 17:10:03 -0800340 String[] settingsToMove = {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800341 Settings.Secure.ADB_ENABLED,
342 Settings.Secure.ANDROID_ID,
343 Settings.Secure.BLUETOOTH_ON,
344 Settings.Secure.DATA_ROAMING,
345 Settings.Secure.DEVICE_PROVISIONED,
346 Settings.Secure.HTTP_PROXY,
347 Settings.Secure.INSTALL_NON_MARKET_APPS,
348 Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
349 Settings.Secure.LOGGING_ID,
350 Settings.Secure.NETWORK_PREFERENCE,
351 Settings.Secure.PARENTAL_CONTROL_ENABLED,
352 Settings.Secure.PARENTAL_CONTROL_LAST_UPDATE,
353 Settings.Secure.PARENTAL_CONTROL_REDIRECT_URL,
354 Settings.Secure.SETTINGS_CLASSNAME,
355 Settings.Secure.USB_MASS_STORAGE_ENABLED,
356 Settings.Secure.USE_GOOGLE_MAIL,
357 Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
358 Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,
359 Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT,
360 Settings.Secure.WIFI_ON,
361 Settings.Secure.WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE,
362 Settings.Secure.WIFI_WATCHDOG_AP_COUNT,
363 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS,
364 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED,
365 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS,
366 Settings.Secure.WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT,
367 Settings.Secure.WIFI_WATCHDOG_MAX_AP_CHECKS,
368 Settings.Secure.WIFI_WATCHDOG_ON,
369 Settings.Secure.WIFI_WATCHDOG_PING_COUNT,
370 Settings.Secure.WIFI_WATCHDOG_PING_DELAY_MS,
371 Settings.Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS,
372 };
Christopher Tate92198742012-09-07 12:00:13 -0700373 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800374 upgradeVersion = 28;
375 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700376
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800377 if (upgradeVersion == 28 || upgradeVersion == 29) {
378 // Note: The upgrade to 28 was flawed since it didn't delete the old
379 // setting first before inserting. Combining 28 and 29 with the
380 // fixed version.
381
382 // This upgrade adds the STREAM_NOTIFICATION type to the list of
383 // types affected by ringer modes (silent, vibrate, etc.)
384 db.beginTransaction();
385 try {
386 db.execSQL("DELETE FROM system WHERE name='"
387 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
388 int newValue = (1 << AudioManager.STREAM_RING)
389 | (1 << AudioManager.STREAM_NOTIFICATION)
390 | (1 << AudioManager.STREAM_SYSTEM);
391 db.execSQL("INSERT INTO system ('name', 'value') values ('"
392 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
393 + String.valueOf(newValue) + "')");
394 db.setTransactionSuccessful();
395 } finally {
396 db.endTransaction();
397 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700398
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800399 upgradeVersion = 30;
400 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700401
The Android Open Source Project9266c552009-01-15 16:12:10 -0800402 if (upgradeVersion == 30) {
403 /*
404 * Upgrade 31 clears the title for all quick launch shortcuts so the
405 * activities' titles will be resolved at display time. Also, the
406 * folder is changed to '@quicklaunch'.
407 */
408 db.beginTransaction();
409 try {
410 db.execSQL("UPDATE bookmarks SET folder = '@quicklaunch'");
411 db.execSQL("UPDATE bookmarks SET title = ''");
412 db.setTransactionSuccessful();
413 } finally {
414 db.endTransaction();
415 }
416 upgradeVersion = 31;
417 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 if (upgradeVersion == 31) {
420 /*
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700421 * Animations are now managed in preferences, and may be
422 * enabled or disabled based on product resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 */
424 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700425 SQLiteStatement stmt = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 try {
427 db.execSQL("DELETE FROM system WHERE name='"
428 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
429 db.execSQL("DELETE FROM system WHERE name='"
430 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700431 stmt = db.compileStatement("INSERT INTO system(name,value)"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 + " VALUES(?,?);");
433 loadDefaultAnimationSettings(stmt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 db.setTransactionSuccessful();
435 } finally {
436 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700437 if (stmt != null) stmt.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 }
439 upgradeVersion = 32;
440 }
441
442 if (upgradeVersion == 32) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 upgradeVersion = 33;
444 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700445
The Android Open Source Project4df24232009-03-05 14:34:35 -0800446 if (upgradeVersion == 33) {
447 // Set the default zoom controls to: tap-twice to bring up +/-
448 db.beginTransaction();
449 try {
450 db.execSQL("INSERT INTO system(name,value) values('zoom','2');");
451 db.setTransactionSuccessful();
452 } finally {
453 db.endTransaction();
454 }
455 upgradeVersion = 34;
456 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457
Mike Lockwoodbcab8df2009-06-25 16:39:09 -0400458 if (upgradeVersion == 34) {
459 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700460 SQLiteStatement stmt = null;
Mike Lockwoodbcab8df2009-06-25 16:39:09 -0400461 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700462 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
Dianne Hackborncf098292009-07-01 19:55:20 -0700463 + " VALUES(?,?);");
464 loadSecure35Settings(stmt);
Dianne Hackborncf098292009-07-01 19:55:20 -0700465 db.setTransactionSuccessful();
466 } finally {
467 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700468 if (stmt != null) stmt.close();
Dianne Hackborncf098292009-07-01 19:55:20 -0700469 }
Jim Millerf1860552009-09-09 17:46:35 -0700470 upgradeVersion = 35;
Mike Lockwood02901eb2009-08-25 15:11:17 -0700471 }
472 // due to a botched merge from donut to eclair, the initialization of ASSISTED_GPS_ENABLED
473 // was accidentally done out of order here.
474 // to fix this, ASSISTED_GPS_ENABLED is now initialized while upgrading from 38 to 39,
475 // and we intentionally do nothing from 35 to 36 now.
476 if (upgradeVersion == 35) {
The Android Open Source Project575d1af2009-07-03 08:55:59 -0700477 upgradeVersion = 36;
Dianne Hackborncf098292009-07-01 19:55:20 -0700478 }
Mike Lockwood02901eb2009-08-25 15:11:17 -0700479
Eric Laurenta553c252009-07-17 12:17:14 -0700480 if (upgradeVersion == 36) {
481 // This upgrade adds the STREAM_SYSTEM_ENFORCED type to the list of
482 // types affected by ringer modes (silent, vibrate, etc.)
483 db.beginTransaction();
484 try {
485 db.execSQL("DELETE FROM system WHERE name='"
486 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
487 int newValue = (1 << AudioManager.STREAM_RING)
488 | (1 << AudioManager.STREAM_NOTIFICATION)
489 | (1 << AudioManager.STREAM_SYSTEM)
490 | (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
491 db.execSQL("INSERT INTO system ('name', 'value') values ('"
492 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
493 + String.valueOf(newValue) + "')");
494 db.setTransactionSuccessful();
495 } finally {
496 db.endTransaction();
497 }
Jim Miller48805752009-08-04 18:59:20 -0700498 upgradeVersion = 37;
Eric Laurenta553c252009-07-17 12:17:14 -0700499 }
500
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700501 if (upgradeVersion == 37) {
502 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700503 SQLiteStatement stmt = null;
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700504 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700505 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700506 + " VALUES(?,?);");
507 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
508 R.string.airplane_mode_toggleable_radios);
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700509 db.setTransactionSuccessful();
510 } finally {
511 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700512 if (stmt != null) stmt.close();
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700513 }
514 upgradeVersion = 38;
515 }
516
Mike Lockwood02901eb2009-08-25 15:11:17 -0700517 if (upgradeVersion == 38) {
518 db.beginTransaction();
519 try {
520 String value =
521 mContext.getResources().getBoolean(R.bool.assisted_gps_enabled) ? "1" : "0";
522 db.execSQL("INSERT OR IGNORE INTO secure(name,value) values('" +
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -0700523 Settings.Global.ASSISTED_GPS_ENABLED + "','" + value + "');");
Mike Lockwood02901eb2009-08-25 15:11:17 -0700524 db.setTransactionSuccessful();
525 } finally {
526 db.endTransaction();
527 }
528
529 upgradeVersion = 39;
530 }
531
Dan Murphy951764b2009-08-27 14:59:03 -0500532 if (upgradeVersion == 39) {
Amith Yamasanif50c5112011-01-07 11:32:30 -0800533 upgradeAutoBrightness(db);
Dan Murphy951764b2009-08-27 14:59:03 -0500534 upgradeVersion = 40;
535 }
536
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700537 if (upgradeVersion == 40) {
538 /*
539 * All animations are now turned on by default!
540 */
541 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700542 SQLiteStatement stmt = null;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700543 try {
544 db.execSQL("DELETE FROM system WHERE name='"
545 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
546 db.execSQL("DELETE FROM system WHERE name='"
547 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700548 stmt = db.compileStatement("INSERT INTO system(name,value)"
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700549 + " VALUES(?,?);");
550 loadDefaultAnimationSettings(stmt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700551 db.setTransactionSuccessful();
552 } finally {
553 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700554 if (stmt != null) stmt.close();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700555 }
556 upgradeVersion = 41;
557 }
558
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700559 if (upgradeVersion == 41) {
560 /*
561 * Initialize newly public haptic feedback setting
562 */
563 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700564 SQLiteStatement stmt = null;
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700565 try {
566 db.execSQL("DELETE FROM system WHERE name='"
567 + Settings.System.HAPTIC_FEEDBACK_ENABLED + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700568 stmt = db.compileStatement("INSERT INTO system(name,value)"
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700569 + " VALUES(?,?);");
570 loadDefaultHapticSettings(stmt);
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700571 db.setTransactionSuccessful();
572 } finally {
573 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700574 if (stmt != null) stmt.close();
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700575 }
576 upgradeVersion = 42;
577 }
578
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800579 if (upgradeVersion == 42) {
580 /*
581 * Initialize new notification pulse setting
582 */
583 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700584 SQLiteStatement stmt = null;
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800585 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700586 stmt = db.compileStatement("INSERT INTO system(name,value)"
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800587 + " VALUES(?,?);");
588 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
589 R.bool.def_notification_pulse);
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800590 db.setTransactionSuccessful();
591 } finally {
592 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700593 if (stmt != null) stmt.close();
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800594 }
595 upgradeVersion = 43;
596 }
597
Eric Laurent484d2882009-12-08 09:05:45 -0800598 if (upgradeVersion == 43) {
599 /*
600 * This upgrade stores bluetooth volume separately from voice volume
601 */
602 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700603 SQLiteStatement stmt = null;
Eric Laurent484d2882009-12-08 09:05:45 -0800604 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700605 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
Eric Laurent484d2882009-12-08 09:05:45 -0800606 + " VALUES(?,?);");
607 loadSetting(stmt, Settings.System.VOLUME_BLUETOOTH_SCO,
John Spurlock61560172015-02-06 19:46:04 -0500608 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
Eric Laurent484d2882009-12-08 09:05:45 -0800609 db.setTransactionSuccessful();
610 } finally {
611 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700612 if (stmt != null) stmt.close();
Eric Laurent484d2882009-12-08 09:05:45 -0800613 }
614 upgradeVersion = 44;
615 }
616
Doug Zongkeraed8f8e2010-01-07 18:07:50 -0800617 if (upgradeVersion == 44) {
618 /*
619 * Gservices was moved into vendor/google.
620 */
621 db.execSQL("DROP TABLE IF EXISTS gservices");
622 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1");
623 upgradeVersion = 45;
624 }
San Mehat87734d32010-01-08 12:53:06 -0800625
626 if (upgradeVersion == 45) {
627 /*
Sudheer Shanka2250d562016-11-07 15:41:02 -0800628 * New settings for StorageManagerService
San Mehat87734d32010-01-08 12:53:06 -0800629 */
630 db.beginTransaction();
631 try {
632 db.execSQL("INSERT INTO secure(name,value) values('" +
633 Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND + "','1');");
634 db.execSQL("INSERT INTO secure(name,value) values('" +
635 Settings.Secure.MOUNT_UMS_AUTOSTART + "','0');");
636 db.execSQL("INSERT INTO secure(name,value) values('" +
637 Settings.Secure.MOUNT_UMS_PROMPT + "','1');");
638 db.execSQL("INSERT INTO secure(name,value) values('" +
639 Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED + "','1');");
640 db.setTransactionSuccessful();
641 } finally {
642 db.endTransaction();
643 }
644 upgradeVersion = 46;
645 }
646
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800647 if (upgradeVersion == 46) {
648 /*
649 * The password mode constants have changed; reset back to no
650 * password.
651 */
652 db.beginTransaction();
653 try {
654 db.execSQL("DELETE FROM system WHERE name='lockscreen.password_type';");
655 db.setTransactionSuccessful();
656 } finally {
657 db.endTransaction();
658 }
659 upgradeVersion = 47;
660 }
661
Jim Miller61766772010-02-12 14:56:49 -0800662
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800663 if (upgradeVersion == 47) {
664 /*
665 * The password mode constants have changed again; reset back to no
666 * password.
667 */
668 db.beginTransaction();
669 try {
670 db.execSQL("DELETE FROM system WHERE name='lockscreen.password_type';");
671 db.setTransactionSuccessful();
672 } finally {
673 db.endTransaction();
674 }
675 upgradeVersion = 48;
676 }
Jim Miller61766772010-02-12 14:56:49 -0800677
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800678 if (upgradeVersion == 48) {
679 /*
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800680 * Default recognition service no longer initialized here,
681 * moved to RecognitionManagerService.
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800682 */
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800683 upgradeVersion = 49;
684 }
Jim Miller31f90b62010-01-20 13:35:20 -0800685
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500686 if (upgradeVersion == 49) {
687 /*
688 * New settings for new user interface noises.
689 */
690 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700691 SQLiteStatement stmt = null;
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500692 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700693 stmt = db.compileStatement("INSERT INTO system(name,value)"
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500694 + " VALUES(?,?);");
695 loadUISoundEffectsSettings(stmt);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500696 db.setTransactionSuccessful();
697 } finally {
698 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700699 if (stmt != null) stmt.close();
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500700 }
701
702 upgradeVersion = 50;
703 }
704
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800705 if (upgradeVersion == 50) {
706 /*
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700707 * Install location no longer initiated here.
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800708 */
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800709 upgradeVersion = 51;
710 }
711
Amith Yamasani156c4352010-03-05 17:10:03 -0800712 if (upgradeVersion == 51) {
713 /* Move the lockscreen related settings to Secure, including some private ones. */
714 String[] settingsToMove = {
715 Secure.LOCK_PATTERN_ENABLED,
716 Secure.LOCK_PATTERN_VISIBLE,
717 Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED,
718 "lockscreen.password_type",
719 "lockscreen.lockoutattemptdeadline",
720 "lockscreen.patterneverchosen",
721 "lock_pattern_autolock",
722 "lockscreen.lockedoutpermanently",
723 "lockscreen.password_salt"
724 };
Christopher Tate92198742012-09-07 12:00:13 -0700725 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
Amith Yamasani156c4352010-03-05 17:10:03 -0800726 upgradeVersion = 52;
727 }
728
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500729 if (upgradeVersion == 52) {
730 // new vibration/silent mode settings
731 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700732 SQLiteStatement stmt = null;
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500733 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700734 stmt = db.compileStatement("INSERT INTO system(name,value)"
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500735 + " VALUES(?,?);");
736 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
737 R.bool.def_vibrate_in_silent);
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500738 db.setTransactionSuccessful();
739 } finally {
740 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700741 if (stmt != null) stmt.close();
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500742 }
743
744 upgradeVersion = 53;
745 }
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -0700746
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800747 if (upgradeVersion == 53) {
748 /*
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700749 * New settings for set install location UI no longer initiated here.
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800750 */
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800751 upgradeVersion = 54;
752 }
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500753
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -0700754 if (upgradeVersion == 54) {
755 /*
756 * Update the screen timeout value if set to never
757 */
758 db.beginTransaction();
759 try {
760 upgradeScreenTimeoutFromNever(db);
761 db.setTransactionSuccessful();
762 } finally {
763 db.endTransaction();
764 }
765
766 upgradeVersion = 55;
767 }
768
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700769 if (upgradeVersion == 55) {
770 /* Move the install location settings. */
771 String[] settingsToMove = {
Jeff Sharkey625239a2012-09-26 22:03:49 -0700772 Global.SET_INSTALL_LOCATION,
773 Global.DEFAULT_INSTALL_LOCATION
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700774 };
Christopher Tate92198742012-09-07 12:00:13 -0700775 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700776 db.beginTransaction();
777 SQLiteStatement stmt = null;
778 try {
779 stmt = db.compileStatement("INSERT INTO system(name,value)"
780 + " VALUES(?,?);");
Jeff Sharkey625239a2012-09-26 22:03:49 -0700781 loadSetting(stmt, Global.SET_INSTALL_LOCATION, 0);
782 loadSetting(stmt, Global.DEFAULT_INSTALL_LOCATION,
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700783 PackageHelper.APP_INSTALL_AUTO);
784 db.setTransactionSuccessful();
785 } finally {
786 db.endTransaction();
787 if (stmt != null) stmt.close();
788 }
789 upgradeVersion = 56;
790 }
Jake Hamby66592842010-08-24 19:55:20 -0700791
792 if (upgradeVersion == 56) {
793 /*
794 * Add Bluetooth to list of toggleable radios in airplane mode
795 */
796 db.beginTransaction();
797 SQLiteStatement stmt = null;
798 try {
799 db.execSQL("DELETE FROM system WHERE name='"
800 + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS + "'");
801 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
802 + " VALUES(?,?);");
803 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
804 R.string.airplane_mode_toggleable_radios);
805 db.setTransactionSuccessful();
806 } finally {
807 db.endTransaction();
808 if (stmt != null) stmt.close();
809 }
810 upgradeVersion = 57;
811 }
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700812
Amith Yamasani5cd15002011-11-16 11:19:48 -0800813 /************* The following are Honeycomb changes ************/
814
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700815 if (upgradeVersion == 57) {
816 /*
Phil Weaver09d4ff82017-03-31 11:22:17 -0700817 * No longer initializing deleted setting ACCESSIBILITY_SCRIPT_INJECTION.
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700818 */
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700819 upgradeVersion = 58;
820 }
821
Amith Yamasaniad450be2010-09-16 16:47:00 -0700822 if (upgradeVersion == 58) {
823 /* Add default for new Auto Time Zone */
Amith Yamasani5cd15002011-11-16 11:19:48 -0800824 int autoTimeValue = getIntValueFromSystem(db, Settings.System.AUTO_TIME, 0);
Amith Yamasaniad450be2010-09-16 16:47:00 -0700825 db.beginTransaction();
826 SQLiteStatement stmt = null;
827 try {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800828 stmt = db.compileStatement("INSERT INTO system(name,value)" + " VALUES(?,?);");
829 loadSetting(stmt, Settings.System.AUTO_TIME_ZONE,
830 autoTimeValue); // Sync timezone to NITZ if auto_time was enabled
Amith Yamasaniad450be2010-09-16 16:47:00 -0700831 db.setTransactionSuccessful();
832 } finally {
833 db.endTransaction();
834 if (stmt != null) stmt.close();
835 }
836 upgradeVersion = 59;
837 }
838
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400839 if (upgradeVersion == 59) {
840 // Persistence for the rotation lock feature.
841 db.beginTransaction();
842 SQLiteStatement stmt = null;
843 try {
844 stmt = db.compileStatement("INSERT INTO system(name,value)"
845 + " VALUES(?,?);");
846 loadBooleanSetting(stmt, Settings.System.USER_ROTATION,
847 R.integer.def_user_rotation); // should be zero degrees
848 db.setTransactionSuccessful();
849 } finally {
850 db.endTransaction();
851 if (stmt != null) stmt.close();
852 }
853 upgradeVersion = 60;
854 }
855
Amith Yamasani00389312010-11-05 11:22:21 -0700856 if (upgradeVersion == 60) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800857 // Don't do this for upgrades from Gingerbread
858 // Were only required for intra-Honeycomb upgrades for testing
859 // upgradeScreenTimeout(db);
Amith Yamasani00389312010-11-05 11:22:21 -0700860 upgradeVersion = 61;
861 }
862
Amith Yamasani79373f62010-11-18 16:32:48 -0800863 if (upgradeVersion == 61) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800864 // Don't do this for upgrades from Gingerbread
865 // Were only required for intra-Honeycomb upgrades for testing
866 // upgradeScreenTimeout(db);
Amith Yamasani79373f62010-11-18 16:32:48 -0800867 upgradeVersion = 62;
868 }
869
Amith Yamasanif50c5112011-01-07 11:32:30 -0800870 // Change the default for screen auto-brightness mode
871 if (upgradeVersion == 62) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800872 // Don't do this for upgrades from Gingerbread
873 // Were only required for intra-Honeycomb upgrades for testing
874 // upgradeAutoBrightness(db);
Amith Yamasanif50c5112011-01-07 11:32:30 -0800875 upgradeVersion = 63;
876 }
877
Eric Laurent25101b02011-02-02 09:33:30 -0800878 if (upgradeVersion == 63) {
879 // This upgrade adds the STREAM_MUSIC type to the list of
880 // types affected by ringer modes (silent, vibrate, etc.)
881 db.beginTransaction();
882 try {
883 db.execSQL("DELETE FROM system WHERE name='"
884 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
885 int newValue = (1 << AudioManager.STREAM_RING)
886 | (1 << AudioManager.STREAM_NOTIFICATION)
887 | (1 << AudioManager.STREAM_SYSTEM)
888 | (1 << AudioManager.STREAM_SYSTEM_ENFORCED)
889 | (1 << AudioManager.STREAM_MUSIC);
890 db.execSQL("INSERT INTO system ('name', 'value') values ('"
891 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
892 + String.valueOf(newValue) + "')");
893 db.setTransactionSuccessful();
894 } finally {
895 db.endTransaction();
896 }
897 upgradeVersion = 64;
898 }
899
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800900 if (upgradeVersion == 64) {
901 // New setting to configure the long press timeout.
902 db.beginTransaction();
903 SQLiteStatement stmt = null;
904 try {
905 stmt = db.compileStatement("INSERT INTO secure(name,value)"
906 + " VALUES(?,?);");
907 loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT,
908 R.integer.def_long_press_timeout_millis);
909 stmt.close();
910 db.setTransactionSuccessful();
911 } finally {
912 db.endTransaction();
913 if (stmt != null) stmt.close();
914 }
915 upgradeVersion = 65;
916 }
917
Amith Yamasani5cd15002011-11-16 11:19:48 -0800918 /************* The following are Ice Cream Sandwich changes ************/
919
Gilles Debunnefa53d302011-07-08 10:40:51 -0700920 if (upgradeVersion == 65) {
921 /*
922 * Animations are removed from Settings. Turned on by default
923 */
924 db.beginTransaction();
925 SQLiteStatement stmt = null;
926 try {
927 db.execSQL("DELETE FROM system WHERE name='"
928 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
929 db.execSQL("DELETE FROM system WHERE name='"
930 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
931 stmt = db.compileStatement("INSERT INTO system(name,value)"
932 + " VALUES(?,?);");
933 loadDefaultAnimationSettings(stmt);
934 db.setTransactionSuccessful();
935 } finally {
936 db.endTransaction();
937 if (stmt != null) stmt.close();
938 }
939 upgradeVersion = 66;
940 }
941
Eric Laurentc1d41662011-07-19 11:21:13 -0700942 if (upgradeVersion == 66) {
Amith Yamasani42722bf2011-07-22 10:34:27 -0700943 // This upgrade makes sure that MODE_RINGER_STREAMS_AFFECTED is set
944 // according to device voice capability
945 db.beginTransaction();
946 try {
947 int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
948 (1 << AudioManager.STREAM_NOTIFICATION) |
949 (1 << AudioManager.STREAM_SYSTEM) |
950 (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
951 if (!mContext.getResources().getBoolean(
952 com.android.internal.R.bool.config_voice_capable)) {
953 ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
954 }
955 db.execSQL("DELETE FROM system WHERE name='"
956 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
957 db.execSQL("INSERT INTO system ('name', 'value') values ('"
958 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
959 + String.valueOf(ringerModeAffectedStreams) + "')");
960 db.setTransactionSuccessful();
961 } finally {
962 db.endTransaction();
963 }
964 upgradeVersion = 67;
965 }
Eric Laurentc1d41662011-07-19 11:21:13 -0700966
Svetoslav Ganova28a16d2011-07-28 11:24:21 -0700967 if (upgradeVersion == 67) {
968 // New setting to enable touch exploration.
969 db.beginTransaction();
970 SQLiteStatement stmt = null;
971 try {
972 stmt = db.compileStatement("INSERT INTO secure(name,value)"
973 + " VALUES(?,?);");
974 loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED,
975 R.bool.def_touch_exploration_enabled);
976 stmt.close();
977 db.setTransactionSuccessful();
978 } finally {
979 db.endTransaction();
980 if (stmt != null) stmt.close();
981 }
982 upgradeVersion = 68;
983 }
984
Amith Yamasani42722bf2011-07-22 10:34:27 -0700985 if (upgradeVersion == 68) {
986 // Enable all system sounds by default
987 db.beginTransaction();
Amith Yamasani42722bf2011-07-22 10:34:27 -0700988 try {
Amith Yamasani42722bf2011-07-22 10:34:27 -0700989 db.execSQL("DELETE FROM system WHERE name='"
990 + Settings.System.NOTIFICATIONS_USE_RING_VOLUME + "'");
Amith Yamasani42722bf2011-07-22 10:34:27 -0700991 db.setTransactionSuccessful();
992 } finally {
993 db.endTransaction();
Amith Yamasani42722bf2011-07-22 10:34:27 -0700994 }
995 upgradeVersion = 69;
996 }
Svetoslav Ganova28a16d2011-07-28 11:24:21 -0700997
Nick Pelly8d32a012011-08-09 07:03:49 -0700998 if (upgradeVersion == 69) {
999 // Add RADIO_NFC to AIRPLANE_MODE_RADIO and AIRPLANE_MODE_TOGGLEABLE_RADIOS
1000 String airplaneRadios = mContext.getResources().getString(
1001 R.string.def_airplane_mode_radios);
1002 String toggleableRadios = mContext.getResources().getString(
1003 R.string.airplane_mode_toggleable_radios);
1004 db.beginTransaction();
1005 try {
1006 db.execSQL("UPDATE system SET value='" + airplaneRadios + "' " +
1007 "WHERE name='" + Settings.System.AIRPLANE_MODE_RADIOS + "'");
1008 db.execSQL("UPDATE system SET value='" + toggleableRadios + "' " +
1009 "WHERE name='" + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS + "'");
1010 db.setTransactionSuccessful();
1011 } finally {
1012 db.endTransaction();
1013 }
1014 upgradeVersion = 70;
1015 }
1016
Jeff Brown6651a632011-11-28 12:59:11 -08001017 if (upgradeVersion == 70) {
1018 // Update all built-in bookmarks. Some of the package names have changed.
1019 loadBookmarks(db);
1020 upgradeVersion = 71;
1021 }
1022
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08001023 if (upgradeVersion == 71) {
1024 // New setting to specify whether to speak passwords in accessibility mode.
1025 db.beginTransaction();
1026 SQLiteStatement stmt = null;
1027 try {
1028 stmt = db.compileStatement("INSERT INTO secure(name,value)"
1029 + " VALUES(?,?);");
1030 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD,
1031 R.bool.def_accessibility_speak_password);
Amith Yamasani6243edd2011-12-05 19:58:48 -08001032 db.setTransactionSuccessful();
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08001033 } finally {
1034 db.endTransaction();
1035 if (stmt != null) stmt.close();
1036 }
1037 upgradeVersion = 72;
1038 }
1039
Amith Yamasani6243edd2011-12-05 19:58:48 -08001040 if (upgradeVersion == 72) {
1041 // update vibration settings
1042 db.beginTransaction();
1043 SQLiteStatement stmt = null;
1044 try {
1045 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1046 + " VALUES(?,?);");
1047 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
1048 R.bool.def_vibrate_in_silent);
1049 db.setTransactionSuccessful();
1050 } finally {
1051 db.endTransaction();
1052 if (stmt != null) stmt.close();
1053 }
1054 upgradeVersion = 73;
1055 }
1056
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001057 if (upgradeVersion == 73) {
Amith Yamasani398c83c2011-12-13 10:38:47 -08001058 upgradeVibrateSettingFromNone(db);
1059 upgradeVersion = 74;
1060 }
1061
1062 if (upgradeVersion == 74) {
Phil Weaver09d4ff82017-03-31 11:22:17 -07001063 // No longer using URL from which WebView loads a JavaScript based screen-reader.
Amith Yamasani398c83c2011-12-13 10:38:47 -08001064 upgradeVersion = 75;
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001065 }
Mike Lockwood7bef7392011-10-20 16:51:53 -04001066 if (upgradeVersion == 75) {
1067 db.beginTransaction();
1068 SQLiteStatement stmt = null;
1069 Cursor c = null;
1070 try {
Christopher Tate06efb532012-08-24 15:29:27 -07001071 c = db.query(TABLE_SECURE, new String[] {"_id", "value"},
Mike Lockwood7bef7392011-10-20 16:51:53 -04001072 "name='lockscreen.disabled'",
1073 null, null, null, null);
1074 // only set default if it has not yet been set
1075 if (c == null || c.getCount() == 0) {
1076 stmt = db.compileStatement("INSERT INTO system(name,value)"
1077 + " VALUES(?,?);");
1078 loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED,
1079 R.bool.def_lockscreen_disabled);
1080 }
1081 db.setTransactionSuccessful();
1082 } finally {
1083 db.endTransaction();
1084 if (c != null) c.close();
1085 if (stmt != null) stmt.close();
1086 }
1087 upgradeVersion = 76;
1088 }
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001089
Eric Laurentbffc3d12012-05-07 17:43:49 -07001090 /************* The following are Jelly Bean changes ************/
1091
1092 if (upgradeVersion == 76) {
1093 // Removed VIBRATE_IN_SILENT setting
1094 db.beginTransaction();
1095 try {
1096 db.execSQL("DELETE FROM system WHERE name='"
1097 + Settings.System.VIBRATE_IN_SILENT + "'");
1098 db.setTransactionSuccessful();
1099 } finally {
1100 db.endTransaction();
1101 }
1102
1103 upgradeVersion = 77;
1104 }
1105
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001106 if (upgradeVersion == 77) {
Beverlyf9af4082019-01-09 15:31:18 -05001107 // "vibrate when ringing" setting moved to SettingsProvider version 168
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001108 upgradeVersion = 78;
1109 }
Eric Laurentbffc3d12012-05-07 17:43:49 -07001110
alanv3a67eb32012-06-22 10:47:28 -07001111 if (upgradeVersion == 78) {
Phil Weaver09d4ff82017-03-31 11:22:17 -07001112 // ACCESSIBILITY_SCREEN_READER_URL has been removed
alanv3a67eb32012-06-22 10:47:28 -07001113 upgradeVersion = 79;
1114 }
1115
Svetoslav Ganov86317012012-08-15 22:13:00 -07001116 if (upgradeVersion == 79) {
1117 // Before touch exploration was a global setting controlled by the user
1118 // via the UI. However, if the enabled accessibility services do not
1119 // handle touch exploration mode, enabling it makes no sense. Therefore,
1120 // now the services request touch exploration mode and the user is
1121 // presented with a dialog to allow that and if she does we store that
1122 // in the database. As a result of this change a user that has enabled
1123 // accessibility, touch exploration, and some accessibility services
1124 // may lose touch exploration state, thus rendering the device useless
1125 // unless sighted help is provided, since the enabled service(s) are
1126 // not in the list of services to which the user granted a permission
1127 // to put the device in touch explore mode. Here we are allowing all
1128 // enabled accessibility services to toggle touch exploration provided
1129 // accessibility and touch exploration are enabled and no services can
1130 // toggle touch exploration. Note that the user has already manually
1131 // enabled the services and touch exploration which means the she has
1132 // given consent to have these services work in touch exploration mode.
Christopher Tate06efb532012-08-24 15:29:27 -07001133 final boolean accessibilityEnabled = getIntValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001134 Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;
Christopher Tate06efb532012-08-24 15:29:27 -07001135 final boolean touchExplorationEnabled = getIntValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001136 Settings.Secure.TOUCH_EXPLORATION_ENABLED, 0) == 1;
1137 if (accessibilityEnabled && touchExplorationEnabled) {
Christopher Tate06efb532012-08-24 15:29:27 -07001138 String enabledServices = getStringValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001139 Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "");
Christopher Tate06efb532012-08-24 15:29:27 -07001140 String touchExplorationGrantedServices = getStringValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001141 Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, "");
1142 if (TextUtils.isEmpty(touchExplorationGrantedServices)
1143 && !TextUtils.isEmpty(enabledServices)) {
1144 SQLiteStatement stmt = null;
1145 try {
1146 db.beginTransaction();
1147 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1148 + " VALUES(?,?);");
1149 loadSetting(stmt,
1150 Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES,
1151 enabledServices);
1152 db.setTransactionSuccessful();
1153 } finally {
1154 db.endTransaction();
1155 if (stmt != null) stmt.close();
1156 }
1157 }
1158 }
1159 upgradeVersion = 80;
1160 }
1161
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001162 // vvv Jelly Bean MR1 changes begin here vvv
1163
Svetoslav Ganovca34bcf2012-08-16 12:22:23 -07001164 if (upgradeVersion == 80) {
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001165 // update screensaver settings
1166 db.beginTransaction();
1167 SQLiteStatement stmt = null;
1168 try {
1169 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1170 + " VALUES(?,?);");
1171 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED,
John Spurlocked108f32012-10-18 16:49:24 -04001172 com.android.internal.R.bool.config_dreamsEnabledByDefault);
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001173 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
John Spurlocked108f32012-10-18 16:49:24 -04001174 com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04001175 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
John Spurlocked108f32012-10-18 16:49:24 -04001176 com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04001177 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_COMPONENTS,
John Spurlocked108f32012-10-18 16:49:24 -04001178 com.android.internal.R.string.config_dreamsDefaultComponent);
1179 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT,
1180 com.android.internal.R.string.config_dreamsDefaultComponent);
Christopher Tate06efb532012-08-24 15:29:27 -07001181
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001182 db.setTransactionSuccessful();
1183 } finally {
1184 db.endTransaction();
1185 if (stmt != null) stmt.close();
1186 }
Svetoslav Ganovca34bcf2012-08-16 12:22:23 -07001187 upgradeVersion = 81;
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001188 }
1189
rich cannings16e119e2012-09-06 12:04:37 -07001190 if (upgradeVersion == 81) {
1191 // Add package verification setting
1192 db.beginTransaction();
1193 SQLiteStatement stmt = null;
1194 try {
1195 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1196 + " VALUES(?,?);");
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001197 loadBooleanSetting(stmt, Settings.Global.PACKAGE_VERIFIER_ENABLE,
rich cannings16e119e2012-09-06 12:04:37 -07001198 R.bool.def_package_verifier_enable);
1199 db.setTransactionSuccessful();
1200 } finally {
1201 db.endTransaction();
1202 if (stmt != null) stmt.close();
1203 }
1204 upgradeVersion = 82;
1205 }
1206
Christopher Tate06efb532012-08-24 15:29:27 -07001207 if (upgradeVersion == 82) {
1208 // Move to per-user settings dbs
Xiaohui Chen43765b72015-08-31 10:57:33 -07001209 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate06efb532012-08-24 15:29:27 -07001210
Christopher Tate59c5bee2012-09-13 14:38:33 -07001211 db.beginTransaction();
1212 SQLiteStatement stmt = null;
1213 try {
1214 // Migrate now-global settings. Note that this happens before
1215 // new users can be created.
1216 createGlobalTable(db);
Svetoslav683914b2015-01-15 14:22:26 -08001217 String[] settingsToMove = setToStringArray(
1218 SettingsProvider.sSystemMovedToGlobalSettings);
Christopher Tate59c5bee2012-09-13 14:38:33 -07001219 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, false);
Svetoslav683914b2015-01-15 14:22:26 -08001220 settingsToMove = setToStringArray(
1221 SettingsProvider.sSecureMovedToGlobalSettings);
Christopher Tate59c5bee2012-09-13 14:38:33 -07001222 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, false);
1223
1224 db.setTransactionSuccessful();
1225 } finally {
1226 db.endTransaction();
1227 if (stmt != null) stmt.close();
1228 }
Christopher Tate06efb532012-08-24 15:29:27 -07001229 }
1230 upgradeVersion = 83;
1231 }
1232
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001233 if (upgradeVersion == 83) {
1234 // 1. Setting whether screen magnification is enabled.
1235 // 2. Setting for screen magnification scale.
1236 // 3. Setting for screen magnification auto update.
1237 db.beginTransaction();
1238 SQLiteStatement stmt = null;
1239 try {
1240 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
1241 loadBooleanSetting(stmt,
1242 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
1243 R.bool.def_accessibility_display_magnification_enabled);
1244 stmt.close();
1245 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
1246 loadFractionSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
1247 R.fraction.def_accessibility_display_magnification_scale, 1);
1248 stmt.close();
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001249
1250 db.setTransactionSuccessful();
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001251 } finally {
1252 db.endTransaction();
1253 if (stmt != null) stmt.close();
1254 }
1255 upgradeVersion = 84;
1256 }
1257
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001258 if (upgradeVersion == 84) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001259 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001260 db.beginTransaction();
1261 SQLiteStatement stmt = null;
1262 try {
1263 // Patch up the slightly-wrong key migration from 82 -> 83 for those
1264 // devices that missed it, ignoring if the move is redundant
1265 String[] settingsToMove = {
1266 Settings.Secure.ADB_ENABLED,
1267 Settings.Secure.BLUETOOTH_ON,
1268 Settings.Secure.DATA_ROAMING,
1269 Settings.Secure.DEVICE_PROVISIONED,
1270 Settings.Secure.INSTALL_NON_MARKET_APPS,
1271 Settings.Secure.USB_MASS_STORAGE_ENABLED
1272 };
1273 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1274 db.setTransactionSuccessful();
1275 } finally {
1276 db.endTransaction();
1277 if (stmt != null) stmt.close();
1278 }
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001279 }
1280 upgradeVersion = 85;
1281 }
1282
Christopher Tate92198742012-09-07 12:00:13 -07001283 if (upgradeVersion == 85) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001284 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001285 db.beginTransaction();
1286 try {
1287 // Fix up the migration, ignoring already-migrated elements, to snap up to
1288 // date with new changes to the set of global versus system/secure settings
1289 String[] settingsToMove = { Settings.System.STAY_ON_WHILE_PLUGGED_IN };
1290 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
Christopher Tate92198742012-09-07 12:00:13 -07001291
Christopher Tate59c5bee2012-09-13 14:38:33 -07001292 db.setTransactionSuccessful();
1293 } finally {
1294 db.endTransaction();
1295 }
Christopher Tate92198742012-09-07 12:00:13 -07001296 }
1297 upgradeVersion = 86;
1298 }
1299
rich cannings4d8fc792012-09-07 14:43:43 -07001300 if (upgradeVersion == 86) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001301 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001302 db.beginTransaction();
1303 try {
1304 String[] settingsToMove = {
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001305 Settings.Global.PACKAGE_VERIFIER_ENABLE,
1306 Settings.Global.PACKAGE_VERIFIER_TIMEOUT,
1307 Settings.Global.PACKAGE_VERIFIER_DEFAULT_RESPONSE
Christopher Tate59c5bee2012-09-13 14:38:33 -07001308 };
1309 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
rich cannings4d8fc792012-09-07 14:43:43 -07001310
Christopher Tate59c5bee2012-09-13 14:38:33 -07001311 db.setTransactionSuccessful();
1312 } finally {
1313 db.endTransaction();
1314 }
rich cannings4d8fc792012-09-07 14:43:43 -07001315 }
1316 upgradeVersion = 87;
1317 }
1318
Christopher Tatec868b642012-09-12 17:41:04 -07001319 if (upgradeVersion == 87) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001320 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001321 db.beginTransaction();
1322 try {
1323 String[] settingsToMove = {
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001324 Settings.Global.DATA_STALL_ALARM_NON_AGGRESSIVE_DELAY_IN_MS,
1325 Settings.Global.DATA_STALL_ALARM_AGGRESSIVE_DELAY_IN_MS,
1326 Settings.Global.GPRS_REGISTER_CHECK_PERIOD_MS
Christopher Tate59c5bee2012-09-13 14:38:33 -07001327 };
1328 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
Christopher Tatec868b642012-09-12 17:41:04 -07001329
Christopher Tate59c5bee2012-09-13 14:38:33 -07001330 db.setTransactionSuccessful();
1331 } finally {
1332 db.endTransaction();
1333 }
Christopher Tatec868b642012-09-12 17:41:04 -07001334 }
1335 upgradeVersion = 88;
1336 }
1337
Jeff Sharkey625239a2012-09-26 22:03:49 -07001338 if (upgradeVersion == 88) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001339 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jeff Sharkey625239a2012-09-26 22:03:49 -07001340 db.beginTransaction();
1341 try {
1342 String[] settingsToMove = {
1343 Settings.Global.BATTERY_DISCHARGE_DURATION_THRESHOLD,
1344 Settings.Global.BATTERY_DISCHARGE_THRESHOLD,
1345 Settings.Global.SEND_ACTION_APP_ERROR,
1346 Settings.Global.DROPBOX_AGE_SECONDS,
1347 Settings.Global.DROPBOX_MAX_FILES,
1348 Settings.Global.DROPBOX_QUOTA_KB,
1349 Settings.Global.DROPBOX_QUOTA_PERCENT,
1350 Settings.Global.DROPBOX_RESERVE_PERCENT,
1351 Settings.Global.DROPBOX_TAG_PREFIX,
1352 Settings.Global.ERROR_LOGCAT_PREFIX,
1353 Settings.Global.SYS_FREE_STORAGE_LOG_INTERVAL,
1354 Settings.Global.DISK_FREE_CHANGE_REPORTING_THRESHOLD,
1355 Settings.Global.SYS_STORAGE_THRESHOLD_PERCENTAGE,
1356 Settings.Global.SYS_STORAGE_THRESHOLD_MAX_BYTES,
1357 Settings.Global.SYS_STORAGE_FULL_THRESHOLD_BYTES,
1358 Settings.Global.SYNC_MAX_RETRY_DELAY_IN_SECONDS,
1359 Settings.Global.CONNECTIVITY_CHANGE_DELAY,
1360 Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED,
1361 Settings.Global.CAPTIVE_PORTAL_SERVER,
1362 Settings.Global.NSD_ON,
1363 Settings.Global.SET_INSTALL_LOCATION,
1364 Settings.Global.DEFAULT_INSTALL_LOCATION,
1365 Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY,
1366 Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY,
1367 Settings.Global.READ_EXTERNAL_STORAGE_ENFORCED_DEFAULT,
1368 Settings.Global.HTTP_PROXY,
1369 Settings.Global.GLOBAL_HTTP_PROXY_HOST,
1370 Settings.Global.GLOBAL_HTTP_PROXY_PORT,
1371 Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST,
1372 Settings.Global.SET_GLOBAL_HTTP_PROXY,
1373 Settings.Global.DEFAULT_DNS_SERVER,
1374 };
1375 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1376 db.setTransactionSuccessful();
1377 } finally {
1378 db.endTransaction();
1379 }
1380 }
1381 upgradeVersion = 89;
1382 }
1383
Jeff Sharkey0ac10282012-10-01 12:50:22 -07001384 if (upgradeVersion == 89) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001385 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jeff Sharkey0ac10282012-10-01 12:50:22 -07001386 db.beginTransaction();
1387 try {
1388 String[] prefixesToMove = {
1389 Settings.Global.BLUETOOTH_HEADSET_PRIORITY_PREFIX,
1390 Settings.Global.BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX,
1391 Settings.Global.BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX,
1392 };
1393
1394 movePrefixedSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, prefixesToMove);
1395
1396 db.setTransactionSuccessful();
1397 } finally {
1398 db.endTransaction();
1399 }
1400 }
1401 upgradeVersion = 90;
1402 }
1403
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001404 if (upgradeVersion == 90) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001405 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001406 db.beginTransaction();
1407 try {
1408 String[] systemToGlobal = {
1409 Settings.Global.WINDOW_ANIMATION_SCALE,
1410 Settings.Global.TRANSITION_ANIMATION_SCALE,
1411 Settings.Global.ANIMATOR_DURATION_SCALE,
1412 Settings.Global.FANCY_IME_ANIMATIONS,
1413 Settings.Global.COMPATIBILITY_MODE,
1414 Settings.Global.EMERGENCY_TONE,
1415 Settings.Global.CALL_AUTO_RETRY,
1416 Settings.Global.DEBUG_APP,
1417 Settings.Global.WAIT_FOR_DEBUGGER,
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001418 Settings.Global.ALWAYS_FINISH_ACTIVITIES,
1419 };
1420 String[] secureToGlobal = {
1421 Settings.Global.PREFERRED_NETWORK_MODE,
Naveen Kallab4d485c2013-07-03 16:39:27 -07001422 Settings.Global.CDMA_SUBSCRIPTION_MODE,
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001423 };
1424
1425 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, systemToGlobal, true);
1426 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, secureToGlobal, true);
1427
1428 db.setTransactionSuccessful();
1429 } finally {
1430 db.endTransaction();
1431 }
1432 }
1433 upgradeVersion = 91;
1434 }
1435
Eric Laurent55b02222012-10-03 11:56:23 -07001436 if (upgradeVersion == 91) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001437 if (mUserHandle == UserHandle.USER_SYSTEM) {
Eric Laurent55b02222012-10-03 11:56:23 -07001438 db.beginTransaction();
1439 try {
1440 // Move ringer mode from system to global settings
Amith Yamasani531c2372012-10-08 14:43:20 -07001441 String[] settingsToMove = { Settings.Global.MODE_RINGER };
Eric Laurent55b02222012-10-03 11:56:23 -07001442 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
1443
1444 db.setTransactionSuccessful();
1445 } finally {
1446 db.endTransaction();
1447 }
1448 }
1449 upgradeVersion = 92;
1450 }
1451
John Spurlock7f1c2482012-10-05 11:15:28 -04001452 if (upgradeVersion == 92) {
1453 SQLiteStatement stmt = null;
1454 try {
1455 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1456 + " VALUES(?,?);");
Xiaohui Chen43765b72015-08-31 10:57:33 -07001457 if (mUserHandle == UserHandle.USER_SYSTEM) {
John Spurlock7f1c2482012-10-05 11:15:28 -04001458 // consider existing primary users to have made it through user setup
1459 // if the globally-scoped device-provisioned bit is set
1460 // (indicating they already made it through setup as primary)
1461 int deviceProvisioned = getIntValueFromTable(db, TABLE_GLOBAL,
1462 Settings.Global.DEVICE_PROVISIONED, 0);
1463 loadSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
1464 deviceProvisioned);
1465 } else {
1466 // otherwise use the default
1467 loadBooleanSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
1468 R.bool.def_user_setup_complete);
1469 }
1470 } finally {
1471 if (stmt != null) stmt.close();
1472 }
1473 upgradeVersion = 93;
1474 }
1475
Amith Yamasani531c2372012-10-08 14:43:20 -07001476 if (upgradeVersion == 93) {
1477 // Redo this step, since somehow it didn't work the first time for some users
Xiaohui Chen43765b72015-08-31 10:57:33 -07001478 if (mUserHandle == UserHandle.USER_SYSTEM) {
Amith Yamasani531c2372012-10-08 14:43:20 -07001479 db.beginTransaction();
Amith Yamasani531c2372012-10-08 14:43:20 -07001480 try {
1481 // Migrate now-global settings
Svetoslav683914b2015-01-15 14:22:26 -08001482 String[] settingsToMove = setToStringArray(
1483 SettingsProvider.sSystemMovedToGlobalSettings);
Amith Yamasani531c2372012-10-08 14:43:20 -07001484 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
Svetoslav683914b2015-01-15 14:22:26 -08001485 settingsToMove = setToStringArray(
1486 SettingsProvider.sSecureMovedToGlobalSettings);
Amith Yamasani531c2372012-10-08 14:43:20 -07001487 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1488
1489 db.setTransactionSuccessful();
1490 } finally {
1491 db.endTransaction();
Amith Yamasani531c2372012-10-08 14:43:20 -07001492 }
1493 }
1494 upgradeVersion = 94;
1495 }
1496
Jeff Brown84e27562012-12-07 13:56:34 -08001497 if (upgradeVersion == 94) {
1498 // Add wireless charging started sound setting
Xiaohui Chen43765b72015-08-31 10:57:33 -07001499 if (mUserHandle == UserHandle.USER_SYSTEM) {
Amith Yamasani2d43fab2012-12-12 09:52:26 -08001500 db.beginTransaction();
1501 SQLiteStatement stmt = null;
1502 try {
1503 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1504 + " VALUES(?,?);");
Beverlyc1313eb2018-01-31 18:07:21 -05001505 loadStringSetting(stmt, Settings.Global.CHARGING_STARTED_SOUND,
Amith Yamasani2d43fab2012-12-12 09:52:26 -08001506 R.string.def_wireless_charging_started_sound);
1507 db.setTransactionSuccessful();
1508 } finally {
1509 db.endTransaction();
1510 if (stmt != null) stmt.close();
1511 }
Jeff Brown84e27562012-12-07 13:56:34 -08001512 }
1513 upgradeVersion = 95;
1514 }
1515
Christopher Tate58f41ec2013-01-11 15:40:36 -08001516 if (upgradeVersion == 95) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001517 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate58f41ec2013-01-11 15:40:36 -08001518 db.beginTransaction();
1519 try {
1520 String[] settingsToMove = { Settings.Global.BUGREPORT_IN_POWER_MENU };
1521 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1522 db.setTransactionSuccessful();
1523 } finally {
1524 db.endTransaction();
1525 }
1526 }
1527 upgradeVersion = 96;
1528 }
1529
Mike Clerond1ed3ce2013-02-01 18:36:41 +00001530 if (upgradeVersion == 96) {
Svetoslav Ganov447d9462013-02-01 19:46:20 +00001531 // NOP bump due to a reverted change that some people got on upgrade.
Mike Clerond1ed3ce2013-02-01 18:36:41 +00001532 upgradeVersion = 97;
1533 }
1534
Daniel Sandlerdea64622013-09-23 16:05:57 -04001535 if (upgradeVersion == 97) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001536 if (mUserHandle == UserHandle.USER_SYSTEM) {
Daniel Sandlerdea64622013-09-23 16:05:57 -04001537 db.beginTransaction();
1538 SQLiteStatement stmt = null;
1539 try {
1540 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1541 + " VALUES(?,?);");
1542 loadIntegerSetting(stmt, Settings.Global.LOW_BATTERY_SOUND_TIMEOUT,
1543 R.integer.def_low_battery_sound_timeout);
1544 db.setTransactionSuccessful();
1545 } finally {
1546 db.endTransaction();
1547 if (stmt != null) stmt.close();
1548 }
1549 }
1550 upgradeVersion = 98;
1551 }
1552
Dan Sandler82a6c5c2014-02-20 14:43:20 -05001553 if (upgradeVersion == 98) {
Dan Sandler52e5701e2014-07-22 23:14:54 -04001554 // no-op; LOCK_SCREEN_SHOW_NOTIFICATIONS now handled in version 106
Dan Sandler82a6c5c2014-02-20 14:43:20 -05001555 upgradeVersion = 99;
1556 }
1557
Chris Wren1cdd7dd2014-02-28 17:49:20 -05001558 if (upgradeVersion == 99) {
Dan Sandler52e5701e2014-07-22 23:14:54 -04001559 // no-op; HEADS_UP_NOTIFICATIONS_ENABLED now handled in version 100
1560 upgradeVersion = 100;
1561 }
1562
1563 if (upgradeVersion == 100) {
1564 // note: LOCK_SCREEN_SHOW_NOTIFICATIONS now handled in version 106
Xiaohui Chen43765b72015-08-31 10:57:33 -07001565 if (mUserHandle == UserHandle.USER_SYSTEM) {
Chris Wren1cdd7dd2014-02-28 17:49:20 -05001566 db.beginTransaction();
1567 SQLiteStatement stmt = null;
1568 try {
1569 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1570 + " VALUES(?,?);");
1571 loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED,
1572 R.integer.def_heads_up_enabled);
1573 db.setTransactionSuccessful();
1574 } finally {
1575 db.endTransaction();
1576 if (stmt != null) stmt.close();
1577 }
1578 }
Chris Wren5242cf32014-03-19 16:16:48 -04001579 upgradeVersion = 101;
1580 }
Chris Wren1cdd7dd2014-02-28 17:49:20 -05001581
Jerome Poichet147b4d72014-05-12 18:13:27 -07001582 if (upgradeVersion == 101) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001583 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jerome Poichet147b4d72014-05-12 18:13:27 -07001584 db.beginTransaction();
1585 SQLiteStatement stmt = null;
1586 try {
1587 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
1588 + " VALUES(?,?);");
1589 loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName());
1590 db.setTransactionSuccessful();
1591 } finally {
1592 db.endTransaction();
1593 if (stmt != null) stmt.close();
1594 }
1595 }
1596 upgradeVersion = 102;
1597 }
1598
Christopher Tateaa036a22014-05-19 16:33:27 -07001599 if (upgradeVersion == 102) {
1600 db.beginTransaction();
1601 SQLiteStatement stmt = null;
1602 try {
1603 // The INSTALL_NON_MARKET_APPS setting is becoming per-user rather
1604 // than device-global.
Xiaohui Chen43765b72015-08-31 10:57:33 -07001605 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tateaa036a22014-05-19 16:33:27 -07001606 // In the owner user, the global table exists so we can migrate the
1607 // entry from there to the secure table, preserving its value.
1608 String[] globalToSecure = {
1609 Settings.Secure.INSTALL_NON_MARKET_APPS
1610 };
1611 moveSettingsToNewTable(db, TABLE_GLOBAL, TABLE_SECURE, globalToSecure, true);
1612 } else {
1613 // Secondary users' dbs don't have the global table, so institute the
1614 // default.
1615 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1616 + " VALUES(?,?);");
1617 loadBooleanSetting(stmt, Settings.Secure.INSTALL_NON_MARKET_APPS,
1618 R.bool.def_install_non_market_apps);
1619 }
1620 db.setTransactionSuccessful();
1621 } finally {
1622 db.endTransaction();
1623 if (stmt != null) stmt.close();
1624 }
1625 upgradeVersion = 103;
1626 }
Jeff Browna20dda42014-05-27 20:57:24 -07001627
1628 if (upgradeVersion == 103) {
1629 db.beginTransaction();
1630 SQLiteStatement stmt = null;
1631 try {
1632 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1633 + " VALUES(?,?);");
1634 loadBooleanSetting(stmt, Settings.Secure.WAKE_GESTURE_ENABLED,
1635 R.bool.def_wake_gesture_enabled);
1636 db.setTransactionSuccessful();
1637 } finally {
1638 db.endTransaction();
1639 if (stmt != null) stmt.close();
1640 }
1641 upgradeVersion = 104;
1642 }
1643
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001644 if (upgradeVersion < 105) {
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07001645 // No-op: GUEST_USER_ENABLED setting was removed
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001646 upgradeVersion = 105;
1647 }
1648
Dan Sandler52e5701e2014-07-22 23:14:54 -04001649 if (upgradeVersion < 106) {
1650 // LOCK_SCREEN_SHOW_NOTIFICATIONS is now per-user.
1651 db.beginTransaction();
1652 SQLiteStatement stmt = null;
1653 try {
1654 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1655 + " VALUES(?,?);");
Chris Wrencd8f4f72014-08-27 18:48:13 -04001656 loadIntegerSetting(stmt, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
1657 R.integer.def_lock_screen_show_notifications);
Xiaohui Chen43765b72015-08-31 10:57:33 -07001658 if (mUserHandle == UserHandle.USER_SYSTEM) {
Dan Sandler52e5701e2014-07-22 23:14:54 -04001659 final int oldShow = getIntValueFromTable(db,
1660 TABLE_GLOBAL, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, -1);
1661 if (oldShow >= 0) {
1662 // overwrite the default with whatever you had
1663 loadSetting(stmt, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, oldShow);
1664 final SQLiteStatement deleteStmt
1665 = db.compileStatement("DELETE FROM global WHERE name=?");
1666 deleteStmt.bindString(1, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS);
1667 deleteStmt.execute();
1668 }
1669 }
1670 db.setTransactionSuccessful();
1671 } finally {
1672 db.endTransaction();
1673 if (stmt != null) stmt.close();
1674 }
1675 upgradeVersion = 106;
1676 }
Adrian Roos49e057d2014-08-13 17:14:51 +02001677
1678 if (upgradeVersion < 107) {
1679 // Add trusted sound setting
Xiaohui Chen43765b72015-08-31 10:57:33 -07001680 if (mUserHandle == UserHandle.USER_SYSTEM) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001681 db.beginTransaction();
1682 SQLiteStatement stmt = null;
1683 try {
1684 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1685 + " VALUES(?,?);");
1686 loadStringSetting(stmt, Settings.Global.TRUSTED_SOUND,
1687 R.string.def_trusted_sound);
1688 db.setTransactionSuccessful();
1689 } finally {
1690 db.endTransaction();
1691 if (stmt != null) stmt.close();
1692 }
1693 }
1694 upgradeVersion = 107;
1695 }
1696
Jeff Brown49cb6132014-08-20 14:32:38 -07001697 if (upgradeVersion < 108) {
1698 // Reset the auto-brightness setting to default since the behavior
1699 // of the feature is now quite different and is being presented to
1700 // the user in a new way as "adaptive brightness".
1701 db.beginTransaction();
1702 SQLiteStatement stmt = null;
1703 try {
1704 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1705 + " VALUES(?,?);");
1706 loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE,
1707 R.bool.def_screen_brightness_automatic_mode);
1708 db.setTransactionSuccessful();
1709 } finally {
1710 db.endTransaction();
1711 if (stmt != null) stmt.close();
1712 }
1713 upgradeVersion = 108;
1714 }
1715
Chris Wrencd8f4f72014-08-27 18:48:13 -04001716 if (upgradeVersion < 109) {
1717 db.beginTransaction();
1718 SQLiteStatement stmt = null;
1719 try {
1720 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1721 + " VALUES(?,?);");
1722 loadBooleanSetting(stmt, Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
1723 R.bool.def_lock_screen_allow_private_notifications);
1724 db.setTransactionSuccessful();
1725 } finally {
1726 db.endTransaction();
1727 if (stmt != null) stmt.close();
1728 }
1729 upgradeVersion = 109;
1730 }
1731
Tyler Gunn2c830a22014-09-02 08:39:35 -07001732 if (upgradeVersion < 110) {
1733 // The SIP_CALL_OPTIONS value SIP_ASK_EACH_TIME is being deprecated.
1734 // If the SIP_CALL_OPTIONS setting is set to SIP_ASK_EACH_TIME, default to
1735 // SIP_ADDRESS_ONLY.
1736 db.beginTransaction();
1737 SQLiteStatement stmt = null;
1738 try {
1739 stmt = db.compileStatement("UPDATE system SET value = ? " +
1740 "WHERE name = ? AND value = ?;");
1741 stmt.bindString(1, Settings.System.SIP_ADDRESS_ONLY);
1742 stmt.bindString(2, Settings.System.SIP_CALL_OPTIONS);
1743 stmt.bindString(3, Settings.System.SIP_ASK_ME_EACH_TIME);
1744 stmt.execute();
1745 db.setTransactionSuccessful();
1746 } finally {
1747 db.endTransaction();
1748 if (stmt != null) stmt.close();
1749 }
1750 upgradeVersion = 110;
1751 }
1752
John Spurlock7d424b62014-09-09 17:05:54 -04001753 if (upgradeVersion < 111) {
1754 // reset ringer mode, so it doesn't force zen mode to follow
Xiaohui Chen43765b72015-08-31 10:57:33 -07001755 if (mUserHandle == UserHandle.USER_SYSTEM) {
John Spurlock7d424b62014-09-09 17:05:54 -04001756 db.beginTransaction();
1757 SQLiteStatement stmt = null;
1758 try {
1759 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1760 + " VALUES(?,?);");
1761 loadSetting(stmt, Settings.Global.MODE_RINGER, AudioManager.RINGER_MODE_NORMAL);
1762 db.setTransactionSuccessful();
1763 } finally {
1764 db.endTransaction();
1765 if (stmt != null) stmt.close();
1766 }
1767 }
1768 upgradeVersion = 111;
1769 }
1770
Jerome Poichet550021e2014-09-11 10:38:12 -07001771 if (upgradeVersion < 112) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001772 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jerome Poichet550021e2014-09-11 10:38:12 -07001773 // When device name was added, we went with Manufacturer + Model, device name should
1774 // actually be Model only.
1775 // Update device name to Model if it wasn't modified by user.
1776 db.beginTransaction();
1777 SQLiteStatement stmt = null;
1778 try {
1779 stmt = db.compileStatement("UPDATE global SET value = ? "
1780 + " WHERE name = ? AND value = ?");
1781 stmt.bindString(1, getDefaultDeviceName()); // new default device name
1782 stmt.bindString(2, Settings.Global.DEVICE_NAME);
1783 stmt.bindString(3, getOldDefaultDeviceName()); // old default device name
1784 stmt.execute();
1785 db.setTransactionSuccessful();
1786 } finally {
1787 db.endTransaction();
1788 if (stmt != null) stmt.close();
1789 }
1790 }
1791 upgradeVersion = 112;
1792 }
1793
Jeff Brown05af6ad2014-09-30 20:54:30 -07001794 if (upgradeVersion < 113) {
1795 db.beginTransaction();
1796 SQLiteStatement stmt = null;
1797 try {
1798 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1799 + " VALUES(?,?);");
1800 loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT,
1801 R.integer.def_sleep_timeout);
1802 db.setTransactionSuccessful();
1803 } finally {
1804 db.endTransaction();
1805 if (stmt != null) stmt.close();
1806 }
1807 upgradeVersion = 113;
1808 }
1809
Bryce Leefb1cf362014-10-22 16:56:08 -07001810 // We skipped 114 to handle a merge conflict with the introduction of theater mode.
1811
1812 if (upgradeVersion < 115) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001813 if (mUserHandle == UserHandle.USER_SYSTEM) {
Bryce Leefb1cf362014-10-22 16:56:08 -07001814 db.beginTransaction();
1815 SQLiteStatement stmt = null;
1816 try {
1817 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
1818 + " VALUES(?,?);");
1819 loadBooleanSetting(stmt, Global.THEATER_MODE_ON,
1820 R.bool.def_theater_mode_on);
1821 db.setTransactionSuccessful();
1822 } finally {
1823 db.endTransaction();
1824 if (stmt != null) stmt.close();
1825 }
Bryce Lee584a4452014-10-21 15:55:55 -07001826 }
Bryce Leefb1cf362014-10-22 16:56:08 -07001827 upgradeVersion = 115;
1828 }
1829
1830 if (upgradeVersion < 116) {
manabu, shimoda14723e32017-10-06 14:39:01 +09001831 /*
1832 * To control the default value by carrier config manager, initializing
1833 * ENHANCED_4G_MODE_ENABLED has been removed.
1834 */
Bryce Leefb1cf362014-10-22 16:56:08 -07001835 upgradeVersion = 116;
Libin.Tang@motorola.com0499bb52014-10-10 14:55:57 -05001836 }
Bryce Lee584a4452014-10-21 15:55:55 -07001837
Jason Monk94cfd9d2014-10-31 13:18:21 -04001838 if (upgradeVersion < 117) {
1839 db.beginTransaction();
1840 try {
1841 String[] systemToSecure = {
1842 Settings.Secure.LOCK_TO_APP_EXIT_LOCKED
1843 };
1844 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, systemToSecure, true);
1845 db.setTransactionSuccessful();
1846 } finally {
1847 db.endTransaction();
1848 }
1849 upgradeVersion = 117;
1850 }
1851
John Spurlock8c51d0b2014-11-07 15:14:21 -05001852 if (upgradeVersion < 118) {
1853 // Reset rotation-lock-for-accessibility on upgrade, since it now hides the display
1854 // setting.
1855 db.beginTransaction();
1856 SQLiteStatement stmt = null;
1857 try {
1858 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1859 + " VALUES(?,?);");
1860 loadSetting(stmt, Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0);
1861 db.setTransactionSuccessful();
1862 } finally {
1863 db.endTransaction();
1864 if (stmt != null) stmt.close();
1865 }
1866 upgradeVersion = 118;
1867 }
Svetoslav683914b2015-01-15 14:22:26 -08001868
Jeff Brown503cffc2015-03-26 18:08:51 -07001869 /*
Svetoslav683914b2015-01-15 14:22:26 -08001870 * IMPORTANT: Do not add any more upgrade steps here as the global,
1871 * secure, and system settings are no longer stored in a database
Jeff Brown503cffc2015-03-26 18:08:51 -07001872 * but are kept in memory and persisted to XML.
Svetoslav683914b2015-01-15 14:22:26 -08001873 *
Jeff Brown503cffc2015-03-26 18:08:51 -07001874 * See: SettingsProvider.UpgradeController#onUpgradeLocked
Svetoslav683914b2015-01-15 14:22:26 -08001875 */
1876
Daniel Sandler1c7fa482010-03-10 09:45:01 -05001877 if (upgradeVersion != currentVersion) {
Svetoslav683914b2015-01-15 14:22:26 -08001878 recreateDatabase(db, oldVersion, upgradeVersion, currentVersion);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001879 }
1880 }
1881
Svetoslav683914b2015-01-15 14:22:26 -08001882 public void recreateDatabase(SQLiteDatabase db, int oldVersion,
1883 int upgradeVersion, int currentVersion) {
1884 db.execSQL("DROP TABLE IF EXISTS global");
1885 db.execSQL("DROP TABLE IF EXISTS globalIndex1");
1886 db.execSQL("DROP TABLE IF EXISTS system");
1887 db.execSQL("DROP INDEX IF EXISTS systemIndex1");
1888 db.execSQL("DROP TABLE IF EXISTS secure");
1889 db.execSQL("DROP INDEX IF EXISTS secureIndex1");
1890 db.execSQL("DROP TABLE IF EXISTS gservices");
1891 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1");
1892 db.execSQL("DROP TABLE IF EXISTS bluetooth_devices");
1893 db.execSQL("DROP TABLE IF EXISTS bookmarks");
1894 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex1");
1895 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex2");
1896 db.execSQL("DROP TABLE IF EXISTS favorites");
1897
1898 onCreate(db);
1899
1900 // Added for diagnosing settings.db wipes after the fact
1901 String wipeReason = oldVersion + "/" + upgradeVersion + "/" + currentVersion;
1902 db.execSQL("INSERT INTO secure(name,value) values('" +
1903 "wiped_db_reason" + "','" + wipeReason + "');");
1904 }
1905
1906 private String[] setToStringArray(Set<String> set) {
Christopher Tatea96798e42012-09-06 19:07:19 -07001907 String[] array = new String[set.size()];
1908 return set.toArray(array);
1909 }
1910
Christopher Tate06efb532012-08-24 15:29:27 -07001911 private void moveSettingsToNewTable(SQLiteDatabase db,
1912 String sourceTable, String destTable,
Christopher Tate92198742012-09-07 12:00:13 -07001913 String[] settingsToMove, boolean doIgnore) {
Christopher Tate06efb532012-08-24 15:29:27 -07001914 // Copy settings values from the source table to the dest, and remove from the source
Amith Yamasani156c4352010-03-05 17:10:03 -08001915 SQLiteStatement insertStmt = null;
1916 SQLiteStatement deleteStmt = null;
1917
1918 db.beginTransaction();
1919 try {
Christopher Tate92198742012-09-07 12:00:13 -07001920 insertStmt = db.compileStatement("INSERT "
1921 + (doIgnore ? " OR IGNORE " : "")
1922 + " INTO " + destTable + " (name,value) SELECT name,value FROM "
Christopher Tate06efb532012-08-24 15:29:27 -07001923 + sourceTable + " WHERE name=?");
1924 deleteStmt = db.compileStatement("DELETE FROM " + sourceTable + " WHERE name=?");
Amith Yamasani156c4352010-03-05 17:10:03 -08001925
1926 for (String setting : settingsToMove) {
1927 insertStmt.bindString(1, setting);
1928 insertStmt.execute();
1929
1930 deleteStmt.bindString(1, setting);
1931 deleteStmt.execute();
1932 }
1933 db.setTransactionSuccessful();
1934 } finally {
1935 db.endTransaction();
1936 if (insertStmt != null) {
1937 insertStmt.close();
1938 }
1939 if (deleteStmt != null) {
1940 deleteStmt.close();
1941 }
1942 }
1943 }
1944
Jeff Sharkey0ac10282012-10-01 12:50:22 -07001945 /**
1946 * Move any settings with the given prefixes from the source table to the
1947 * destination table.
1948 */
1949 private void movePrefixedSettingsToNewTable(
1950 SQLiteDatabase db, String sourceTable, String destTable, String[] prefixesToMove) {
1951 SQLiteStatement insertStmt = null;
1952 SQLiteStatement deleteStmt = null;
1953
1954 db.beginTransaction();
1955 try {
1956 insertStmt = db.compileStatement("INSERT INTO " + destTable
1957 + " (name,value) SELECT name,value FROM " + sourceTable
1958 + " WHERE substr(name,0,?)=?");
1959 deleteStmt = db.compileStatement(
1960 "DELETE FROM " + sourceTable + " WHERE substr(name,0,?)=?");
1961
1962 for (String prefix : prefixesToMove) {
1963 insertStmt.bindLong(1, prefix.length() + 1);
1964 insertStmt.bindString(2, prefix);
1965 insertStmt.execute();
1966
1967 deleteStmt.bindLong(1, prefix.length() + 1);
1968 deleteStmt.bindString(2, prefix);
1969 deleteStmt.execute();
1970 }
1971 db.setTransactionSuccessful();
1972 } finally {
1973 db.endTransaction();
1974 if (insertStmt != null) {
1975 insertStmt.close();
1976 }
1977 if (deleteStmt != null) {
1978 deleteStmt.close();
1979 }
1980 }
1981 }
1982
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001983 private void upgradeLockPatternLocation(SQLiteDatabase db) {
Christopher Tate06efb532012-08-24 15:29:27 -07001984 Cursor c = db.query(TABLE_SYSTEM, new String[] {"_id", "value"}, "name='lock_pattern'",
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001985 null, null, null, null);
1986 if (c.getCount() > 0) {
1987 c.moveToFirst();
1988 String lockPattern = c.getString(1);
1989 if (!TextUtils.isEmpty(lockPattern)) {
1990 // Convert lock pattern
1991 try {
Jim Miller31f90b62010-01-20 13:35:20 -08001992 LockPatternUtils lpu = new LockPatternUtils(mContext);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07001993 List<LockPatternView.Cell> cellPattern =
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001994 LockPatternUtils.stringToPattern(lockPattern);
Xiaohui Chen43765b72015-08-31 10:57:33 -07001995 lpu.saveLockPattern(cellPattern, null, UserHandle.USER_SYSTEM);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001996 } catch (IllegalArgumentException e) {
1997 // Don't want corrupted lock pattern to hang the reboot process
1998 }
1999 }
2000 c.close();
Christopher Tate06efb532012-08-24 15:29:27 -07002001 db.delete(TABLE_SYSTEM, "name='lock_pattern'", null);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002002 } else {
2003 c.close();
2004 }
2005 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002006
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07002007 private void upgradeScreenTimeoutFromNever(SQLiteDatabase db) {
2008 // See if the timeout is -1 (for "Never").
Christopher Tate06efb532012-08-24 15:29:27 -07002009 Cursor c = db.query(TABLE_SYSTEM, new String[] { "_id", "value" }, "name=? AND value=?",
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07002010 new String[] { Settings.System.SCREEN_OFF_TIMEOUT, "-1" },
2011 null, null, null);
2012
2013 SQLiteStatement stmt = null;
2014 if (c.getCount() > 0) {
2015 c.close();
2016 try {
2017 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
2018 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002019
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07002020 // Set the timeout to 30 minutes in milliseconds
Amith Yamasanicd66caf2010-04-12 15:49:12 -07002021 loadSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
2022 Integer.toString(30 * 60 * 1000));
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07002023 } finally {
2024 if (stmt != null) stmt.close();
2025 }
2026 } else {
2027 c.close();
2028 }
2029 }
2030
Amith Yamasani398c83c2011-12-13 10:38:47 -08002031 private void upgradeVibrateSettingFromNone(SQLiteDatabase db) {
2032 int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON, 0);
2033 // If the ringer vibrate value is invalid, set it to the default
2034 if ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_OFF) {
John Spurlock61560172015-02-06 19:46:04 -05002035 vibrateSetting = AudioSystem.getValueForVibrateSetting(0,
Amith Yamasani398c83c2011-12-13 10:38:47 -08002036 AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
2037 }
2038 // Apply the same setting to the notification vibrate value
John Spurlock61560172015-02-06 19:46:04 -05002039 vibrateSetting = AudioSystem.getValueForVibrateSetting(vibrateSetting,
Amith Yamasani398c83c2011-12-13 10:38:47 -08002040 AudioManager.VIBRATE_TYPE_NOTIFICATION, vibrateSetting);
2041
2042 SQLiteStatement stmt = null;
2043 try {
2044 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
2045 + " VALUES(?,?);");
2046 loadSetting(stmt, Settings.System.VIBRATE_ON, vibrateSetting);
2047 } finally {
2048 if (stmt != null)
2049 stmt.close();
2050 }
2051 }
2052
Amith Yamasani79373f62010-11-18 16:32:48 -08002053 private void upgradeScreenTimeout(SQLiteDatabase db) {
2054 // Change screen timeout to current default
2055 db.beginTransaction();
2056 SQLiteStatement stmt = null;
2057 try {
2058 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
2059 + " VALUES(?,?);");
2060 loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
2061 R.integer.def_screen_off_timeout);
2062 db.setTransactionSuccessful();
2063 } finally {
2064 db.endTransaction();
2065 if (stmt != null)
2066 stmt.close();
2067 }
2068 }
2069
Amith Yamasanif50c5112011-01-07 11:32:30 -08002070 private void upgradeAutoBrightness(SQLiteDatabase db) {
2071 db.beginTransaction();
2072 try {
2073 String value =
2074 mContext.getResources().getBoolean(
2075 R.bool.def_screen_brightness_automatic_mode) ? "1" : "0";
2076 db.execSQL("INSERT OR REPLACE INTO system(name,value) values('" +
2077 Settings.System.SCREEN_BRIGHTNESS_MODE + "','" + value + "');");
2078 db.setTransactionSuccessful();
2079 } finally {
2080 db.endTransaction();
2081 }
2082 }
2083
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002084 /**
2085 * Loads the default set of bookmarked shortcuts from an xml file.
2086 *
2087 * @param db The database to write the values into
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002088 */
Jeff Brown6651a632011-11-28 12:59:11 -08002089 private void loadBookmarks(SQLiteDatabase db) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002090 ContentValues values = new ContentValues();
2091
2092 PackageManager packageManager = mContext.getPackageManager();
Romain Guyf02811f2010-03-09 16:33:51 -08002093 try {
2094 XmlResourceParser parser = mContext.getResources().getXml(R.xml.bookmarks);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002095 XmlUtils.beginDocument(parser, "bookmarks");
2096
Romain Guyf02811f2010-03-09 16:33:51 -08002097 final int depth = parser.getDepth();
2098 int type;
2099
2100 while (((type = parser.next()) != XmlPullParser.END_TAG ||
2101 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
2102
2103 if (type != XmlPullParser.START_TAG) {
2104 continue;
2105 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002106
2107 String name = parser.getName();
2108 if (!"bookmark".equals(name)) {
2109 break;
2110 }
2111
2112 String pkg = parser.getAttributeValue(null, "package");
2113 String cls = parser.getAttributeValue(null, "class");
2114 String shortcutStr = parser.getAttributeValue(null, "shortcut");
Jeff Brown6651a632011-11-28 12:59:11 -08002115 String category = parser.getAttributeValue(null, "category");
Romain Guyf02811f2010-03-09 16:33:51 -08002116
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -07002117 int shortcutValue = shortcutStr.charAt(0);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002118 if (TextUtils.isEmpty(shortcutStr)) {
2119 Log.w(TAG, "Unable to get shortcut for: " + pkg + "/" + cls);
Jeff Brown6651a632011-11-28 12:59:11 -08002120 continue;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002121 }
Romain Guyf02811f2010-03-09 16:33:51 -08002122
Jeff Brown6651a632011-11-28 12:59:11 -08002123 final Intent intent;
2124 final String title;
2125 if (pkg != null && cls != null) {
2126 ActivityInfo info = null;
2127 ComponentName cn = new ComponentName(pkg, cls);
Romain Guyf02811f2010-03-09 16:33:51 -08002128 try {
2129 info = packageManager.getActivityInfo(cn, 0);
Jeff Brown6651a632011-11-28 12:59:11 -08002130 } catch (PackageManager.NameNotFoundException e) {
2131 String[] packages = packageManager.canonicalToCurrentPackageNames(
2132 new String[] { pkg });
2133 cn = new ComponentName(packages[0], cls);
2134 try {
2135 info = packageManager.getActivityInfo(cn, 0);
2136 } catch (PackageManager.NameNotFoundException e1) {
2137 Log.w(TAG, "Unable to add bookmark: " + pkg + "/" + cls, e);
2138 continue;
2139 }
Romain Guyf02811f2010-03-09 16:33:51 -08002140 }
Jeff Brown6651a632011-11-28 12:59:11 -08002141
2142 intent = new Intent(Intent.ACTION_MAIN, null);
2143 intent.addCategory(Intent.CATEGORY_LAUNCHER);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002144 intent.setComponent(cn);
Jeff Brown6651a632011-11-28 12:59:11 -08002145 title = info.loadLabel(packageManager).toString();
2146 } else if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002147 intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002148 title = "";
2149 } else {
2150 Log.w(TAG, "Unable to add bookmark for shortcut " + shortcutStr
2151 + ": missing package/class or category attributes");
2152 continue;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002153 }
Jeff Brown6651a632011-11-28 12:59:11 -08002154
2155 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2156 values.put(Settings.Bookmarks.INTENT, intent.toUri(0));
2157 values.put(Settings.Bookmarks.TITLE, title);
2158 values.put(Settings.Bookmarks.SHORTCUT, shortcutValue);
2159 db.delete("bookmarks", "shortcut = ?",
2160 new String[] { Integer.toString(shortcutValue) });
2161 db.insert("bookmarks", null, values);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002162 }
2163 } catch (XmlPullParserException e) {
2164 Log.w(TAG, "Got execption parsing bookmarks.", e);
2165 } catch (IOException e) {
2166 Log.w(TAG, "Got execption parsing bookmarks.", e);
2167 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002168 }
2169
2170 /**
2171 * Loads the default volume levels. It is actually inserting the index of
2172 * the volume array for each of the volume controls.
2173 *
2174 * @param db the database to insert the volume levels into
2175 */
2176 private void loadVolumeLevels(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07002177 SQLiteStatement stmt = null;
2178 try {
2179 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
2180 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002181
Vasu Nori89206fdb2010-03-22 10:37:03 -07002182 loadSetting(stmt, Settings.System.VOLUME_MUSIC,
John Spurlock61560172015-02-06 19:46:04 -05002183 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_MUSIC));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002184 loadSetting(stmt, Settings.System.VOLUME_RING,
John Spurlock61560172015-02-06 19:46:04 -05002185 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_RING));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002186 loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
John Spurlock61560172015-02-06 19:46:04 -05002187 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_SYSTEM));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002188 loadSetting(
2189 stmt,
2190 Settings.System.VOLUME_VOICE,
John Spurlock61560172015-02-06 19:46:04 -05002191 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_VOICE_CALL));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002192 loadSetting(stmt, Settings.System.VOLUME_ALARM,
John Spurlock61560172015-02-06 19:46:04 -05002193 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_ALARM));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002194 loadSetting(
2195 stmt,
2196 Settings.System.VOLUME_NOTIFICATION,
John Spurlock61560172015-02-06 19:46:04 -05002197 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_NOTIFICATION));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002198 loadSetting(
2199 stmt,
2200 Settings.System.VOLUME_BLUETOOTH_SCO,
John Spurlock61560172015-02-06 19:46:04 -05002201 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002202
Eric Laurentc1d41662011-07-19 11:21:13 -07002203 // By default:
2204 // - ringtones, notification, system and music streams are affected by ringer mode
2205 // on non voice capable devices (tablets)
2206 // - ringtones, notification and system streams are affected by ringer mode
2207 // on voice capable devices (phones)
2208 int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
2209 (1 << AudioManager.STREAM_NOTIFICATION) |
2210 (1 << AudioManager.STREAM_SYSTEM) |
2211 (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
2212 if (!mContext.getResources().getBoolean(
2213 com.android.internal.R.bool.config_voice_capable)) {
2214 ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
2215 }
Vasu Nori89206fdb2010-03-22 10:37:03 -07002216 loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
Eric Laurentc1d41662011-07-19 11:21:13 -07002217 ringerModeAffectedStreams);
2218
Vasu Nori89206fdb2010-03-22 10:37:03 -07002219 loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
John Spurlock61560172015-02-06 19:46:04 -05002220 AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED);
Vasu Nori89206fdb2010-03-22 10:37:03 -07002221 } finally {
2222 if (stmt != null) stmt.close();
2223 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002224 }
2225
2226 private void loadVibrateSetting(SQLiteDatabase db, boolean deleteOld) {
2227 if (deleteOld) {
2228 db.execSQL("DELETE FROM system WHERE name='" + Settings.System.VIBRATE_ON + "'");
2229 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002230
Vasu Nori89206fdb2010-03-22 10:37:03 -07002231 SQLiteStatement stmt = null;
2232 try {
2233 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
2234 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002235
Amith Yamasani5cd15002011-11-16 11:19:48 -08002236 // Vibrate on by default for ringer, on for notification
Vasu Nori89206fdb2010-03-22 10:37:03 -07002237 int vibrate = 0;
John Spurlock61560172015-02-06 19:46:04 -05002238 vibrate = AudioSystem.getValueForVibrateSetting(vibrate,
Amith Yamasani5cd15002011-11-16 11:19:48 -08002239 AudioManager.VIBRATE_TYPE_NOTIFICATION,
2240 AudioManager.VIBRATE_SETTING_ONLY_SILENT);
John Spurlock61560172015-02-06 19:46:04 -05002241 vibrate |= AudioSystem.getValueForVibrateSetting(vibrate,
Amith Yamasani5cd15002011-11-16 11:19:48 -08002242 AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
Vasu Nori89206fdb2010-03-22 10:37:03 -07002243 loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate);
2244 } finally {
2245 if (stmt != null) stmt.close();
2246 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002247 }
2248
2249 private void loadSettings(SQLiteDatabase db) {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002250 loadSystemSettings(db);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002251 loadSecureSettings(db);
Xiaohui Chen43765b72015-08-31 10:57:33 -07002252 // The global table only exists for the 'owner/system' user
2253 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate06efb532012-08-24 15:29:27 -07002254 loadGlobalSettings(db);
2255 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002256 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002257
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002258 private void loadSystemSettings(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07002259 SQLiteStatement stmt = null;
2260 try {
2261 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
2262 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002263
Vasu Nori89206fdb2010-03-22 10:37:03 -07002264 loadBooleanSetting(stmt, Settings.System.DIM_SCREEN,
2265 R.bool.def_dim_screen);
Vasu Nori89206fdb2010-03-22 10:37:03 -07002266 loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
2267 R.integer.def_screen_off_timeout);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002268
Vasu Nori89206fdb2010-03-22 10:37:03 -07002269 // Set default cdma DTMF type
2270 loadSetting(stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002271
Vasu Nori89206fdb2010-03-22 10:37:03 -07002272 // Set default hearing aid
2273 loadSetting(stmt, Settings.System.HEARING_AID, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002274
Vasu Nori89206fdb2010-03-22 10:37:03 -07002275 // Set default tty mode
2276 loadSetting(stmt, Settings.System.TTY_MODE, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002277
Vasu Nori89206fdb2010-03-22 10:37:03 -07002278 loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS,
2279 R.integer.def_screen_brightness);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002280
Santos Cordon5177da32018-02-07 14:03:14 -08002281 loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_FOR_VR,
2282 com.android.internal.R.integer.config_screenBrightnessForVrSettingDefault);
2283
Vasu Nori89206fdb2010-03-22 10:37:03 -07002284 loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE,
2285 R.bool.def_screen_brightness_automatic_mode);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002286
Vasu Nori89206fdb2010-03-22 10:37:03 -07002287 loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION,
2288 R.bool.def_accelerometer_rotation);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002289
Vasu Nori89206fdb2010-03-22 10:37:03 -07002290 loadDefaultHapticSettings(stmt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002291
Vasu Nori89206fdb2010-03-22 10:37:03 -07002292 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
2293 R.bool.def_notification_pulse);
Amith Yamasani42722bf2011-07-22 10:34:27 -07002294
Vasu Nori89206fdb2010-03-22 10:37:03 -07002295 loadUISoundEffectsSettings(stmt);
Amith Yamasani42722bf2011-07-22 10:34:27 -07002296
Jeff Brown1a84fd12011-06-02 01:26:32 -07002297 loadIntegerSetting(stmt, Settings.System.POINTER_SPEED,
2298 R.integer.def_pointer_speed);
Jeff Brown503cffc2015-03-26 18:08:51 -07002299
2300 /*
2301 * IMPORTANT: Do not add any more upgrade steps here as the global,
2302 * secure, and system settings are no longer stored in a database
2303 * but are kept in memory and persisted to XML.
2304 *
2305 * See: SettingsProvider.UpgradeController#onUpgradeLocked
2306 */
Vasu Nori89206fdb2010-03-22 10:37:03 -07002307 } finally {
2308 if (stmt != null) stmt.close();
2309 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002310 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002311
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002312 private void loadUISoundEffectsSettings(SQLiteStatement stmt) {
Amith Yamasani42722bf2011-07-22 10:34:27 -07002313 loadBooleanSetting(stmt, Settings.System.DTMF_TONE_WHEN_DIALING,
2314 R.bool.def_dtmf_tones_enabled);
2315 loadBooleanSetting(stmt, Settings.System.SOUND_EFFECTS_ENABLED,
2316 R.bool.def_sound_effects_enabled);
2317 loadBooleanSetting(stmt, Settings.System.HAPTIC_FEEDBACK_ENABLED,
2318 R.bool.def_haptic_feedback);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002319
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002320 loadIntegerSetting(stmt, Settings.System.LOCKSCREEN_SOUNDS_ENABLED,
2321 R.integer.def_lockscreen_sounds_enabled);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002322 }
2323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 private void loadDefaultAnimationSettings(SQLiteStatement stmt) {
2325 loadFractionSetting(stmt, Settings.System.WINDOW_ANIMATION_SCALE,
2326 R.fraction.def_window_animation_scale, 1);
2327 loadFractionSetting(stmt, Settings.System.TRANSITION_ANIMATION_SCALE,
2328 R.fraction.def_window_transition_scale, 1);
2329 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002330
Dianne Hackborn075a18d2009-09-26 12:43:19 -07002331 private void loadDefaultHapticSettings(SQLiteStatement stmt) {
2332 loadBooleanSetting(stmt, Settings.System.HAPTIC_FEEDBACK_ENABLED,
2333 R.bool.def_haptic_feedback);
2334 }
2335
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002336 private void loadSecureSettings(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07002337 SQLiteStatement stmt = null;
2338 try {
2339 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
2340 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002341
Vasu Nori89206fdb2010-03-22 10:37:03 -07002342 loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
2343 R.string.def_location_providers_allowed);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002344
Vasu Nori89206fdb2010-03-22 10:37:03 -07002345 // Don't do this. The SystemServer will initialize ADB_ENABLED from a
2346 // persistent system property instead.
2347 //loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002348
Vasu Nori89206fdb2010-03-22 10:37:03 -07002349 // Allow mock locations default, based on build
2350 loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION,
2351 "1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002352
Vasu Nori89206fdb2010-03-22 10:37:03 -07002353 loadSecure35Settings(stmt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002354
Vasu Nori89206fdb2010-03-22 10:37:03 -07002355 loadBooleanSetting(stmt, Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND,
2356 R.bool.def_mount_play_notification_snd);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002357
Vasu Nori89206fdb2010-03-22 10:37:03 -07002358 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_AUTOSTART,
2359 R.bool.def_mount_ums_autostart);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002360
Vasu Nori89206fdb2010-03-22 10:37:03 -07002361 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_PROMPT,
2362 R.bool.def_mount_ums_prompt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002363
Vasu Nori89206fdb2010-03-22 10:37:03 -07002364 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED,
2365 R.bool.def_mount_ums_notify_enabled);
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -07002366
Svetoslav Ganov54d068e2011-03-02 12:58:40 -08002367 loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT,
2368 R.integer.def_long_press_timeout_millis);
Svetoslav Ganova28a16d2011-07-28 11:24:21 -07002369
2370 loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED,
2371 R.bool.def_touch_exploration_enabled);
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08002372
2373 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD,
2374 R.bool.def_accessibility_speak_password);
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08002375
Amith Yamasanid1645f82012-06-12 11:53:26 -07002376 if (SystemProperties.getBoolean("ro.lockscreen.disable.default", false) == true) {
2377 loadSetting(stmt, Settings.System.LOCKSCREEN_DISABLED, "1");
2378 } else {
2379 loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED,
2380 R.bool.def_lockscreen_disabled);
2381 }
Mike Lockwood23955272011-10-21 11:22:48 -04002382
John Spurlock634471e2012-08-09 10:41:37 -04002383 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED,
John Spurlocked108f32012-10-18 16:49:24 -04002384 com.android.internal.R.bool.config_dreamsEnabledByDefault);
John Spurlock634471e2012-08-09 10:41:37 -04002385 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
John Spurlocked108f32012-10-18 16:49:24 -04002386 com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04002387 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
John Spurlocked108f32012-10-18 16:49:24 -04002388 com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04002389 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_COMPONENTS,
John Spurlocked108f32012-10-18 16:49:24 -04002390 com.android.internal.R.string.config_dreamsDefaultComponent);
John Spurlock1a868b72012-08-22 09:56:51 -04002391 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT,
John Spurlocked108f32012-10-18 16:49:24 -04002392 com.android.internal.R.string.config_dreamsDefaultComponent);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07002393
2394 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
2395 R.bool.def_accessibility_display_magnification_enabled);
2396
2397 loadFractionSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
2398 R.fraction.def_accessibility_display_magnification_scale, 1);
2399
John Spurlock7f1c2482012-10-05 11:15:28 -04002400 loadBooleanSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
2401 R.bool.def_user_setup_complete);
Mike Lockwoodc02c4a72014-01-07 14:46:22 -08002402
2403 loadStringSetting(stmt, Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS,
2404 R.string.def_immersive_mode_confirmations);
2405
Christopher Tateaa036a22014-05-19 16:33:27 -07002406 loadBooleanSetting(stmt, Settings.Secure.INSTALL_NON_MARKET_APPS,
2407 R.bool.def_install_non_market_apps);
2408
Jeff Browna20dda42014-05-27 20:57:24 -07002409 loadBooleanSetting(stmt, Settings.Secure.WAKE_GESTURE_ENABLED,
2410 R.bool.def_wake_gesture_enabled);
2411
Dan Sandler52e5701e2014-07-22 23:14:54 -04002412 loadIntegerSetting(stmt, Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
2413 R.integer.def_lock_screen_show_notifications);
2414
Chris Wrencd8f4f72014-08-27 18:48:13 -04002415 loadBooleanSetting(stmt, Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
2416 R.bool.def_lock_screen_allow_private_notifications);
2417
Jeff Brown05af6ad2014-09-30 20:54:30 -07002418 loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT,
2419 R.integer.def_sleep_timeout);
Jeff Brown503cffc2015-03-26 18:08:51 -07002420
2421 /*
2422 * IMPORTANT: Do not add any more upgrade steps here as the global,
2423 * secure, and system settings are no longer stored in a database
2424 * but are kept in memory and persisted to XML.
2425 *
2426 * See: SettingsProvider.UpgradeController#onUpgradeLocked
2427 */
Vasu Nori89206fdb2010-03-22 10:37:03 -07002428 } finally {
2429 if (stmt != null) stmt.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002431 }
2432
Dianne Hackborncf098292009-07-01 19:55:20 -07002433 private void loadSecure35Settings(SQLiteStatement stmt) {
2434 loadBooleanSetting(stmt, Settings.Secure.BACKUP_ENABLED,
2435 R.bool.def_backup_enabled);
Jim Miller31f90b62010-01-20 13:35:20 -08002436
Dianne Hackborncf098292009-07-01 19:55:20 -07002437 loadStringSetting(stmt, Settings.Secure.BACKUP_TRANSPORT,
2438 R.string.def_backup_transport);
2439 }
Jim Miller61766772010-02-12 14:56:49 -08002440
Christopher Tate06efb532012-08-24 15:29:27 -07002441 private void loadGlobalSettings(SQLiteDatabase db) {
2442 SQLiteStatement stmt = null;
2443 try {
2444 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
2445 + " VALUES(?,?);");
2446
2447 // --- Previously in 'system'
2448 loadBooleanSetting(stmt, Settings.Global.AIRPLANE_MODE_ON,
2449 R.bool.def_airplane_mode_on);
2450
Bryce Lee584a4452014-10-21 15:55:55 -07002451 loadBooleanSetting(stmt, Settings.Global.THEATER_MODE_ON,
2452 R.bool.def_theater_mode_on);
2453
Christopher Tate06efb532012-08-24 15:29:27 -07002454 loadStringSetting(stmt, Settings.Global.AIRPLANE_MODE_RADIOS,
2455 R.string.def_airplane_mode_radios);
2456
2457 loadStringSetting(stmt, Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
2458 R.string.airplane_mode_toggleable_radios);
2459
2460 loadBooleanSetting(stmt, Settings.Global.ASSISTED_GPS_ENABLED,
2461 R.bool.assisted_gps_enabled);
2462
2463 loadBooleanSetting(stmt, Settings.Global.AUTO_TIME,
2464 R.bool.def_auto_time); // Sync time to NITZ
2465
2466 loadBooleanSetting(stmt, Settings.Global.AUTO_TIME_ZONE,
2467 R.bool.def_auto_time_zone); // Sync timezone to NITZ
2468
2469 loadSetting(stmt, Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
2470 ("1".equals(SystemProperties.get("ro.kernel.qemu")) ||
2471 mContext.getResources().getBoolean(R.bool.def_stay_on_while_plugged_in))
2472 ? 1 : 0);
2473
2474 loadIntegerSetting(stmt, Settings.Global.WIFI_SLEEP_POLICY,
2475 R.integer.def_wifi_sleep_policy);
2476
Eric Laurent55b02222012-10-03 11:56:23 -07002477 loadSetting(stmt, Settings.Global.MODE_RINGER,
2478 AudioManager.RINGER_MODE_NORMAL);
2479
Terry Heo86e76782017-06-12 18:39:48 +09002480 loadDefaultAnimationSettings(stmt);
2481
Christopher Tate06efb532012-08-24 15:29:27 -07002482 // --- Previously in 'secure'
Christopher Tate6f5a9a92012-09-14 17:24:28 -07002483 loadBooleanSetting(stmt, Settings.Global.PACKAGE_VERIFIER_ENABLE,
2484 R.bool.def_package_verifier_enable);
2485
2486 loadBooleanSetting(stmt, Settings.Global.WIFI_ON,
2487 R.bool.def_wifi_on);
2488
2489 loadBooleanSetting(stmt, Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
2490 R.bool.def_networks_available_notification_on);
2491
Christopher Tate06efb532012-08-24 15:29:27 -07002492 loadBooleanSetting(stmt, Settings.Global.BLUETOOTH_ON,
2493 R.bool.def_bluetooth_on);
2494
2495 // Enable or disable Cell Broadcast SMS
2496 loadSetting(stmt, Settings.Global.CDMA_CELL_BROADCAST_SMS,
2497 RILConstants.CDMA_CELL_BROADCAST_SMS_DISABLED);
2498
2499 // Data roaming default, based on build
2500 loadSetting(stmt, Settings.Global.DATA_ROAMING,
2501 "true".equalsIgnoreCase(
2502 SystemProperties.get("ro.com.android.dataroaming",
2503 "false")) ? 1 : 0);
2504
2505 loadBooleanSetting(stmt, Settings.Global.DEVICE_PROVISIONED,
2506 R.bool.def_device_provisioned);
2507
2508 final int maxBytes = mContext.getResources().getInteger(
2509 R.integer.def_download_manager_max_bytes_over_mobile);
2510 if (maxBytes > 0) {
2511 loadSetting(stmt, Settings.Global.DOWNLOAD_MAX_BYTES_OVER_MOBILE,
2512 Integer.toString(maxBytes));
2513 }
2514
2515 final int recommendedMaxBytes = mContext.getResources().getInteger(
2516 R.integer.def_download_manager_recommended_max_bytes_over_mobile);
2517 if (recommendedMaxBytes > 0) {
2518 loadSetting(stmt, Settings.Global.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE,
2519 Integer.toString(recommendedMaxBytes));
2520 }
2521
2522 // Mobile Data default, based on build
2523 loadSetting(stmt, Settings.Global.MOBILE_DATA,
2524 "true".equalsIgnoreCase(
2525 SystemProperties.get("ro.com.android.mobiledata",
2526 "true")) ? 1 : 0);
2527
2528 loadBooleanSetting(stmt, Settings.Global.NETSTATS_ENABLED,
2529 R.bool.def_netstats_enabled);
2530
Christopher Tate06efb532012-08-24 15:29:27 -07002531 loadBooleanSetting(stmt, Settings.Global.USB_MASS_STORAGE_ENABLED,
2532 R.bool.def_usb_mass_storage_enabled);
2533
2534 loadIntegerSetting(stmt, Settings.Global.WIFI_MAX_DHCP_RETRY_COUNT,
2535 R.integer.def_max_dhcp_retries);
2536
Jeff Brown89d55462012-09-19 11:33:42 -07002537 loadBooleanSetting(stmt, Settings.Global.WIFI_DISPLAY_ON,
2538 R.bool.def_wifi_display_on);
2539
Jim Millerb14288d2012-09-30 18:25:05 -07002540 loadStringSetting(stmt, Settings.Global.LOCK_SOUND,
2541 R.string.def_lock_sound);
Jim Millerb14288d2012-09-30 18:25:05 -07002542 loadStringSetting(stmt, Settings.Global.UNLOCK_SOUND,
2543 R.string.def_unlock_sound);
Adrian Roos49e057d2014-08-13 17:14:51 +02002544 loadStringSetting(stmt, Settings.Global.TRUSTED_SOUND,
2545 R.string.def_trusted_sound);
Amith Yamasani531c2372012-10-08 14:43:20 -07002546 loadIntegerSetting(stmt, Settings.Global.POWER_SOUNDS_ENABLED,
2547 R.integer.def_power_sounds_enabled);
2548 loadStringSetting(stmt, Settings.Global.LOW_BATTERY_SOUND,
2549 R.string.def_low_battery_sound);
2550 loadIntegerSetting(stmt, Settings.Global.DOCK_SOUNDS_ENABLED,
2551 R.integer.def_dock_sounds_enabled);
Vinod Krishnancf11cea2016-10-20 22:57:02 -07002552 loadIntegerSetting(stmt, Settings.Global.DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY,
2553 R.integer.def_dock_sounds_enabled_when_accessibility);
Amith Yamasani531c2372012-10-08 14:43:20 -07002554 loadStringSetting(stmt, Settings.Global.DESK_DOCK_SOUND,
2555 R.string.def_desk_dock_sound);
2556 loadStringSetting(stmt, Settings.Global.DESK_UNDOCK_SOUND,
2557 R.string.def_desk_undock_sound);
2558 loadStringSetting(stmt, Settings.Global.CAR_DOCK_SOUND,
2559 R.string.def_car_dock_sound);
2560 loadStringSetting(stmt, Settings.Global.CAR_UNDOCK_SOUND,
2561 R.string.def_car_undock_sound);
Beverlyc1313eb2018-01-31 18:07:21 -05002562 loadStringSetting(stmt, Settings.Global.CHARGING_STARTED_SOUND,
Jeff Brown84e27562012-12-07 13:56:34 -08002563 R.string.def_wireless_charging_started_sound);
Jim Millerb14288d2012-09-30 18:25:05 -07002564
Dmytro Dubovyk729f6682012-12-18 18:07:50 +02002565 loadIntegerSetting(stmt, Settings.Global.DOCK_AUDIO_MEDIA_ENABLED,
2566 R.integer.def_dock_audio_media_enabled);
2567
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07002568 loadSetting(stmt, Settings.Global.SET_INSTALL_LOCATION, 0);
2569 loadSetting(stmt, Settings.Global.DEFAULT_INSTALL_LOCATION,
2570 PackageHelper.APP_INSTALL_AUTO);
2571
2572 // Set default cdma emergency tone
2573 loadSetting(stmt, Settings.Global.EMERGENCY_TONE, 0);
2574
2575 // Set default cdma call auto retry
2576 loadSetting(stmt, Settings.Global.CALL_AUTO_RETRY, 0);
2577
Naveen Kalla97ecc9e2012-07-13 20:10:22 -07002578 // Set the preferred network mode to target desired value or Default
Sandeep Gutta2a7c0d32016-03-16 21:37:25 +05302579 // value defined in system property
2580 String val = "";
2581 String mode;
2582 for (int phoneId = 0;
2583 phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
2584 mode = TelephonyManager.getTelephonyProperty(phoneId,
2585 "ro.telephony.default_network",
2586 Integer.toString(RILConstants.PREFERRED_NETWORK_MODE));
2587 if (phoneId == 0) {
2588 val = mode;
2589 } else {
2590 val = val + "," + mode;
2591 }
2592 }
2593 loadSetting(stmt, Settings.Global.PREFERRED_NETWORK_MODE, val);
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07002594
Naveen Kallab4d485c2013-07-03 16:39:27 -07002595 // Set the preferred cdma subscription source to target desired value or default
Grace Chen6ad1c5e2017-06-13 16:07:45 -07002596 // value defined in Phone
Sandeep Gutta2a7c0d32016-03-16 21:37:25 +05302597 int type = SystemProperties.getInt("ro.telephony.default_cdma_sub",
2598 Phone.PREFERRED_CDMA_SUBSCRIPTION);
Naveen Kallab4d485c2013-07-03 16:39:27 -07002599 loadSetting(stmt, Settings.Global.CDMA_SUBSCRIPTION_MODE, type);
2600
Daniel Sandlerdea64622013-09-23 16:05:57 -04002601 loadIntegerSetting(stmt, Settings.Global.LOW_BATTERY_SOUND_TIMEOUT,
2602 R.integer.def_low_battery_sound_timeout);
2603
Oskar Grönqvist2c4254e2013-12-11 14:14:33 +01002604 loadIntegerSetting(stmt, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE,
2605 R.integer.def_wifi_scan_always_available);
2606
Chris Wren5242cf32014-03-19 16:16:48 -04002607 loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED,
2608 R.integer.def_heads_up_enabled);
2609
Jerome Poichet147b4d72014-05-12 18:13:27 -07002610 loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName());
2611
Jeff Brown503cffc2015-03-26 18:08:51 -07002612 /*
2613 * IMPORTANT: Do not add any more upgrade steps here as the global,
2614 * secure, and system settings are no longer stored in a database
2615 * but are kept in memory and persisted to XML.
2616 *
2617 * See: SettingsProvider.UpgradeController#onUpgradeLocked
2618 */
Christopher Tate06efb532012-08-24 15:29:27 -07002619 } finally {
2620 if (stmt != null) stmt.close();
2621 }
2622 }
2623
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002624 private void loadSetting(SQLiteStatement stmt, String key, Object value) {
2625 stmt.bindString(1, key);
2626 stmt.bindString(2, value.toString());
2627 stmt.execute();
2628 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002630 private void loadStringSetting(SQLiteStatement stmt, String key, int resid) {
2631 loadSetting(stmt, key, mContext.getResources().getString(resid));
2632 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002634 private void loadBooleanSetting(SQLiteStatement stmt, String key, int resid) {
2635 loadSetting(stmt, key,
2636 mContext.getResources().getBoolean(resid) ? "1" : "0");
2637 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002639 private void loadIntegerSetting(SQLiteStatement stmt, String key, int resid) {
2640 loadSetting(stmt, key,
2641 Integer.toString(mContext.getResources().getInteger(resid)));
2642 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002644 private void loadFractionSetting(SQLiteStatement stmt, String key, int resid, int base) {
2645 loadSetting(stmt, key,
2646 Float.toString(mContext.getResources().getFraction(resid, base, base)));
2647 }
Amith Yamasani5cd15002011-11-16 11:19:48 -08002648
2649 private int getIntValueFromSystem(SQLiteDatabase db, String name, int defaultValue) {
Christopher Tate06efb532012-08-24 15:29:27 -07002650 return getIntValueFromTable(db, TABLE_SYSTEM, name, defaultValue);
Svetoslav Ganov86317012012-08-15 22:13:00 -07002651 }
2652
2653 private int getIntValueFromTable(SQLiteDatabase db, String table, String name,
2654 int defaultValue) {
2655 String value = getStringValueFromTable(db, table, name, null);
2656 return (value != null) ? Integer.parseInt(value) : defaultValue;
2657 }
2658
2659 private String getStringValueFromTable(SQLiteDatabase db, String table, String name,
2660 String defaultValue) {
Amith Yamasani5cd15002011-11-16 11:19:48 -08002661 Cursor c = null;
2662 try {
Svetoslav Ganov86317012012-08-15 22:13:00 -07002663 c = db.query(table, new String[] { Settings.System.VALUE }, "name='" + name + "'",
Amith Yamasani5cd15002011-11-16 11:19:48 -08002664 null, null, null, null);
2665 if (c != null && c.moveToFirst()) {
2666 String val = c.getString(0);
Svetoslav Ganov86317012012-08-15 22:13:00 -07002667 return val == null ? defaultValue : val;
Amith Yamasani5cd15002011-11-16 11:19:48 -08002668 }
2669 } finally {
2670 if (c != null) c.close();
2671 }
Svetoslav Ganov86317012012-08-15 22:13:00 -07002672 return defaultValue;
Amith Yamasani5cd15002011-11-16 11:19:48 -08002673 }
Jerome Poichet147b4d72014-05-12 18:13:27 -07002674
Jerome Poichet550021e2014-09-11 10:38:12 -07002675 private String getOldDefaultDeviceName() {
Jeff Sharkeyad59c432014-09-12 15:56:30 -07002676 return mContext.getResources().getString(R.string.def_device_name,
Jerome Poichet550021e2014-09-11 10:38:12 -07002677 Build.MANUFACTURER, Build.MODEL);
2678 }
2679
Jerome Poichet147b4d72014-05-12 18:13:27 -07002680 private String getDefaultDeviceName() {
Jeff Sharkeyad59c432014-09-12 15:56:30 -07002681 return mContext.getResources().getString(R.string.def_device_name_simple, Build.MODEL);
Jerome Poichet147b4d72014-05-12 18:13:27 -07002682 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002683}