blob: 5e2b7c86ee934c42d84667555205f156fcfef11f [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;
Edward Savage-Jonesce7a01f2015-12-09 21:16:50 +010026import android.content.res.Resources;
Romain Guyf02811f2010-03-09 16:33:51 -080027import android.content.res.XmlResourceParser;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070028import android.database.Cursor;
29import android.database.sqlite.SQLiteDatabase;
30import android.database.sqlite.SQLiteOpenHelper;
31import android.database.sqlite.SQLiteStatement;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070032import android.media.AudioManager;
Beverlyf9af4082019-01-09 15:31:18 -050033import android.media.AudioSystem;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070034import android.net.ConnectivityManager;
Jerome Poichet147b4d72014-05-12 18:13:27 -070035import android.os.Build;
Christopher Tate06efb532012-08-24 15:29:27 -070036import android.os.Environment;
Dianne Hackborn13579ed2012-11-28 18:05:36 -080037import android.os.RemoteException;
38import android.os.ServiceManager;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070039import android.os.SystemProperties;
Christopher Tate06efb532012-08-24 15:29:27 -070040import android.os.UserHandle;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070041import android.provider.Settings;
Jeff Sharkey625239a2012-09-26 22:03:49 -070042import android.provider.Settings.Global;
Amith Yamasani156c4352010-03-05 17:10:03 -080043import android.provider.Settings.Secure;
Sandeep Gutta2a7c0d32016-03-16 21:37:25 +053044import android.telephony.TelephonyManager;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070045import android.text.TextUtils;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070046import android.util.Log;
Suchi Amalapurapu40e47252010-04-07 16:15:50 -070047
Gilles Debunnefa53d302011-07-08 10:40:51 -070048import com.android.internal.content.PackageHelper;
Grace Chen6ad1c5e2017-06-13 16:07:45 -070049import com.android.internal.telephony.Phone;
Gilles Debunnefa53d302011-07-08 10:40:51 -070050import com.android.internal.telephony.RILConstants;
51import com.android.internal.util.XmlUtils;
52import com.android.internal.widget.LockPatternUtils;
53import com.android.internal.widget.LockPatternView;
54
55import org.xmlpull.v1.XmlPullParser;
56import org.xmlpull.v1.XmlPullParserException;
57
Christopher Tate06efb532012-08-24 15:29:27 -070058import java.io.File;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070059import java.io.IOException;
Dianne Hackborn24117ce2010-07-12 15:54:38 -070060import java.util.HashSet;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070061import java.util.List;
Svetoslav683914b2015-01-15 14:22:26 -080062import java.util.Set;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070063
64/**
Jeff Brown503cffc2015-03-26 18:08:51 -070065 * Legacy settings database helper class for {@link SettingsProvider}.
66 *
67 * IMPORTANT: Do not add any more upgrade steps here as the global,
68 * secure, and system settings are no longer stored in a database
69 * but are kept in memory and persisted to XML.
70 *
71 * See: SettingsProvider.UpgradeController#onUpgradeLocked
72 *
73 * @deprecated The implementation is frozen. Do not add any new code to this class!
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070074 */
Jeff Brown503cffc2015-03-26 18:08:51 -070075@Deprecated
76class DatabaseHelper extends SQLiteOpenHelper {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070077 private static final String TAG = "SettingsProvider";
78 private static final String DATABASE_NAME = "settings.db";
Jim Millerf1860552009-09-09 17:46:35 -070079
80 // Please, please please. If you update the database version, check to make sure the
81 // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
82 // is properly propagated through your change. Not doing so will result in a loss of user
83 // settings.
John Spurlock8c51d0b2014-11-07 15:14:21 -050084 private static final int DATABASE_VERSION = 118;
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -070085
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070086 private Context mContext;
Christopher Tate06efb532012-08-24 15:29:27 -070087 private int mUserHandle;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070088
Dianne Hackborn24117ce2010-07-12 15:54:38 -070089 private static final HashSet<String> mValidTables = new HashSet<String>();
90
Svetoslav683914b2015-01-15 14:22:26 -080091 private static final String DATABASE_BACKUP_SUFFIX = "-backup";
92
Christopher Tate06efb532012-08-24 15:29:27 -070093 private static final String TABLE_SYSTEM = "system";
94 private static final String TABLE_SECURE = "secure";
95 private static final String TABLE_GLOBAL = "global";
96
Dianne Hackborn24117ce2010-07-12 15:54:38 -070097 static {
Christopher Tate06efb532012-08-24 15:29:27 -070098 mValidTables.add(TABLE_SYSTEM);
99 mValidTables.add(TABLE_SECURE);
100 mValidTables.add(TABLE_GLOBAL);
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700101
102 // These are old.
Svetoslav683914b2015-01-15 14:22:26 -0800103 mValidTables.add("bluetooth_devices");
104 mValidTables.add("bookmarks");
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700105 mValidTables.add("favorites");
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700106 mValidTables.add("old_favorites");
Svetoslav683914b2015-01-15 14:22:26 -0800107 mValidTables.add("android_metadata");
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700108 }
109
Christopher Tate06efb532012-08-24 15:29:27 -0700110 static String dbNameForUser(final int userHandle) {
111 // The owner gets the unadorned db name;
Xiaohui Chen43765b72015-08-31 10:57:33 -0700112 if (userHandle == UserHandle.USER_SYSTEM) {
Christopher Tate06efb532012-08-24 15:29:27 -0700113 return DATABASE_NAME;
114 } else {
115 // Place the database in the user-specific data tree so that it's
116 // cleaned up automatically when the user is deleted.
117 File databaseFile = new File(
118 Environment.getUserSystemDirectory(userHandle), DATABASE_NAME);
Fyodor Kupolov497b5fa2015-12-17 10:47:33 -0800119 // If databaseFile doesn't exist, database can be kept in memory. It's safe because the
120 // database will be migrated and disposed of immediately after onCreate finishes
121 if (!databaseFile.exists()) {
122 Log.i(TAG, "No previous database file exists - running in in-memory mode");
123 return null;
124 }
Christopher Tate06efb532012-08-24 15:29:27 -0700125 return databaseFile.getPath();
126 }
127 }
128
129 public DatabaseHelper(Context context, int userHandle) {
130 super(context, dbNameForUser(userHandle), null, DATABASE_VERSION);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700131 mContext = context;
Christopher Tate06efb532012-08-24 15:29:27 -0700132 mUserHandle = userHandle;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700133 }
134
Dianne Hackborn24117ce2010-07-12 15:54:38 -0700135 public static boolean isValidTable(String name) {
136 return mValidTables.contains(name);
137 }
138
Fyodor Kupolov497b5fa2015-12-17 10:47:33 -0800139 private boolean isInMemory() {
140 return getDatabaseName() == null;
141 }
142
Svetoslav683914b2015-01-15 14:22:26 -0800143 public void dropDatabase() {
144 close();
Fyodor Kupolov497b5fa2015-12-17 10:47:33 -0800145 // No need to remove files if db is in memory
146 if (isInMemory()) {
147 return;
148 }
Svetoslav683914b2015-01-15 14:22:26 -0800149 File databaseFile = mContext.getDatabasePath(getDatabaseName());
150 if (databaseFile.exists()) {
Fyodor Kupolov15e7c622018-01-25 18:14:53 -0800151 SQLiteDatabase.deleteDatabase(databaseFile);
Svetoslav683914b2015-01-15 14:22:26 -0800152 }
153 }
154
155 public void backupDatabase() {
156 close();
Fyodor Kupolov497b5fa2015-12-17 10:47:33 -0800157 // No need to backup files if db is in memory
158 if (isInMemory()) {
159 return;
160 }
Svetoslav683914b2015-01-15 14:22:26 -0800161 File databaseFile = mContext.getDatabasePath(getDatabaseName());
162 if (!databaseFile.exists()) {
163 return;
164 }
165 File backupFile = mContext.getDatabasePath(getDatabaseName()
166 + DATABASE_BACKUP_SUFFIX);
167 if (backupFile.exists()) {
168 return;
169 }
170 databaseFile.renameTo(backupFile);
171 }
172
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800173 private void createSecureTable(SQLiteDatabase db) {
174 db.execSQL("CREATE TABLE secure (" +
175 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
176 "name TEXT UNIQUE ON CONFLICT REPLACE," +
177 "value TEXT" +
178 ");");
179 db.execSQL("CREATE INDEX secureIndex1 ON secure (name);");
180 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700181
Christopher Tate06efb532012-08-24 15:29:27 -0700182 private void createGlobalTable(SQLiteDatabase db) {
183 db.execSQL("CREATE TABLE global (" +
184 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
185 "name TEXT UNIQUE ON CONFLICT REPLACE," +
186 "value TEXT" +
187 ");");
188 db.execSQL("CREATE INDEX globalIndex1 ON global (name);");
189 }
190
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700191 @Override
192 public void onCreate(SQLiteDatabase db) {
193 db.execSQL("CREATE TABLE system (" +
194 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
195 "name TEXT UNIQUE ON CONFLICT REPLACE," +
196 "value TEXT" +
197 ");");
198 db.execSQL("CREATE INDEX systemIndex1 ON system (name);");
199
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800200 createSecureTable(db);
201
Xiaohui Chen43765b72015-08-31 10:57:33 -0700202 // Only create the global table for the singleton 'owner/system' user
203 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate06efb532012-08-24 15:29:27 -0700204 createGlobalTable(db);
205 }
206
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700207 db.execSQL("CREATE TABLE bluetooth_devices (" +
208 "_id INTEGER PRIMARY KEY," +
209 "name TEXT," +
210 "addr TEXT," +
211 "channel INTEGER," +
212 "type INTEGER" +
213 ");");
214
215 db.execSQL("CREATE TABLE bookmarks (" +
216 "_id INTEGER PRIMARY KEY," +
217 "title TEXT," +
218 "folder TEXT," +
219 "intent TEXT," +
220 "shortcut INTEGER," +
221 "ordering INTEGER" +
222 ");");
223
224 db.execSQL("CREATE INDEX bookmarksIndex1 ON bookmarks (folder);");
225 db.execSQL("CREATE INDEX bookmarksIndex2 ON bookmarks (shortcut);");
226
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700227 // Populate bookmarks table with initial bookmarks
Dianne Hackborn13579ed2012-11-28 18:05:36 -0800228 boolean onlyCore = false;
229 try {
230 onlyCore = IPackageManager.Stub.asInterface(ServiceManager.getService(
231 "package")).isOnlyCoreApps();
232 } catch (RemoteException e) {
233 }
234 if (!onlyCore) {
235 loadBookmarks(db);
236 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700237
238 // Load initial volume levels into DB
239 loadVolumeLevels(db);
240
241 // Load inital settings values
242 loadSettings(db);
243 }
244
245 @Override
246 public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700247 Log.w(TAG, "Upgrading settings database from version " + oldVersion + " to "
248 + currentVersion);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700249
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700250 int upgradeVersion = oldVersion;
251
252 // Pattern for upgrade blocks:
253 //
254 // if (upgradeVersion == [the DATABASE_VERSION you set] - 1) {
255 // .. your upgrade logic..
256 // upgradeVersion = [the DATABASE_VERSION you set]
257 // }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700258
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700259 if (upgradeVersion == 20) {
260 /*
261 * Version 21 is part of the volume control refresh. There is no
262 * longer a UI-visible for setting notification vibrate on/off (in
263 * our design), but the functionality still exists. Force the
264 * notification vibrate to on.
265 */
266 loadVibrateSetting(db, true);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700267
268 upgradeVersion = 21;
269 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700270
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700271 if (upgradeVersion < 22) {
272 upgradeVersion = 22;
273 // Upgrade the lock gesture storage location and format
274 upgradeLockPatternLocation(db);
275 }
276
277 if (upgradeVersion < 23) {
278 db.execSQL("UPDATE favorites SET iconResource=0 WHERE iconType=0");
279 upgradeVersion = 23;
280 }
281
282 if (upgradeVersion == 23) {
283 db.beginTransaction();
284 try {
285 db.execSQL("ALTER TABLE favorites ADD spanX INTEGER");
286 db.execSQL("ALTER TABLE favorites ADD spanY INTEGER");
287 // Shortcuts, applications, folders
288 db.execSQL("UPDATE favorites SET spanX=1, spanY=1 WHERE itemType<=0");
289 // Photo frames, clocks
Wink Saville04e71b32009-04-02 11:00:54 -0700290 db.execSQL(
291 "UPDATE favorites SET spanX=2, spanY=2 WHERE itemType=1000 or itemType=1002");
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700292 // Search boxes
293 db.execSQL("UPDATE favorites SET spanX=4, spanY=1 WHERE itemType=1001");
294 db.setTransactionSuccessful();
295 } finally {
296 db.endTransaction();
297 }
298 upgradeVersion = 24;
299 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700300
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700301 if (upgradeVersion == 24) {
302 db.beginTransaction();
303 try {
304 // The value of the constants for preferring wifi or preferring mobile have been
305 // swapped, so reload the default.
306 db.execSQL("DELETE FROM system WHERE name='network_preference'");
307 db.execSQL("INSERT INTO system ('name', 'value') values ('network_preference', '" +
308 ConnectivityManager.DEFAULT_NETWORK_PREFERENCE + "')");
309 db.setTransactionSuccessful();
310 } finally {
311 db.endTransaction();
312 }
313 upgradeVersion = 25;
314 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800315
316 if (upgradeVersion == 25) {
317 db.beginTransaction();
318 try {
319 db.execSQL("ALTER TABLE favorites ADD uri TEXT");
320 db.execSQL("ALTER TABLE favorites ADD displayMode INTEGER");
321 db.setTransactionSuccessful();
322 } finally {
323 db.endTransaction();
324 }
325 upgradeVersion = 26;
326 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700327
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800328 if (upgradeVersion == 26) {
329 // This introduces the new secure settings table.
330 db.beginTransaction();
331 try {
332 createSecureTable(db);
333 db.setTransactionSuccessful();
334 } finally {
335 db.endTransaction();
336 }
337 upgradeVersion = 27;
338 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700339
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800340 if (upgradeVersion == 27) {
Amith Yamasani156c4352010-03-05 17:10:03 -0800341 String[] settingsToMove = {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800342 Settings.Secure.ADB_ENABLED,
343 Settings.Secure.ANDROID_ID,
344 Settings.Secure.BLUETOOTH_ON,
345 Settings.Secure.DATA_ROAMING,
346 Settings.Secure.DEVICE_PROVISIONED,
347 Settings.Secure.HTTP_PROXY,
348 Settings.Secure.INSTALL_NON_MARKET_APPS,
349 Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
350 Settings.Secure.LOGGING_ID,
351 Settings.Secure.NETWORK_PREFERENCE,
352 Settings.Secure.PARENTAL_CONTROL_ENABLED,
353 Settings.Secure.PARENTAL_CONTROL_LAST_UPDATE,
354 Settings.Secure.PARENTAL_CONTROL_REDIRECT_URL,
355 Settings.Secure.SETTINGS_CLASSNAME,
356 Settings.Secure.USB_MASS_STORAGE_ENABLED,
357 Settings.Secure.USE_GOOGLE_MAIL,
358 Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
359 Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,
360 Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT,
361 Settings.Secure.WIFI_ON,
362 Settings.Secure.WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE,
363 Settings.Secure.WIFI_WATCHDOG_AP_COUNT,
364 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS,
365 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED,
366 Settings.Secure.WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS,
367 Settings.Secure.WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT,
368 Settings.Secure.WIFI_WATCHDOG_MAX_AP_CHECKS,
369 Settings.Secure.WIFI_WATCHDOG_ON,
370 Settings.Secure.WIFI_WATCHDOG_PING_COUNT,
371 Settings.Secure.WIFI_WATCHDOG_PING_DELAY_MS,
372 Settings.Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS,
373 };
Christopher Tate92198742012-09-07 12:00:13 -0700374 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800375 upgradeVersion = 28;
376 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700377
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800378 if (upgradeVersion == 28 || upgradeVersion == 29) {
379 // Note: The upgrade to 28 was flawed since it didn't delete the old
380 // setting first before inserting. Combining 28 and 29 with the
381 // fixed version.
382
383 // This upgrade adds the STREAM_NOTIFICATION type to the list of
384 // types affected by ringer modes (silent, vibrate, etc.)
385 db.beginTransaction();
386 try {
387 db.execSQL("DELETE FROM system WHERE name='"
388 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
389 int newValue = (1 << AudioManager.STREAM_RING)
390 | (1 << AudioManager.STREAM_NOTIFICATION)
391 | (1 << AudioManager.STREAM_SYSTEM);
392 db.execSQL("INSERT INTO system ('name', 'value') values ('"
393 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
394 + String.valueOf(newValue) + "')");
395 db.setTransactionSuccessful();
396 } finally {
397 db.endTransaction();
398 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700399
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800400 upgradeVersion = 30;
401 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700402
The Android Open Source Project9266c552009-01-15 16:12:10 -0800403 if (upgradeVersion == 30) {
404 /*
405 * Upgrade 31 clears the title for all quick launch shortcuts so the
406 * activities' titles will be resolved at display time. Also, the
407 * folder is changed to '@quicklaunch'.
408 */
409 db.beginTransaction();
410 try {
411 db.execSQL("UPDATE bookmarks SET folder = '@quicklaunch'");
412 db.execSQL("UPDATE bookmarks SET title = ''");
413 db.setTransactionSuccessful();
414 } finally {
415 db.endTransaction();
416 }
417 upgradeVersion = 31;
418 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 if (upgradeVersion == 31) {
421 /*
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700422 * Animations are now managed in preferences, and may be
423 * enabled or disabled based on product resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 */
425 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700426 SQLiteStatement stmt = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 try {
428 db.execSQL("DELETE FROM system WHERE name='"
429 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
430 db.execSQL("DELETE FROM system WHERE name='"
431 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700432 stmt = db.compileStatement("INSERT INTO system(name,value)"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 + " VALUES(?,?);");
434 loadDefaultAnimationSettings(stmt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 db.setTransactionSuccessful();
436 } finally {
437 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700438 if (stmt != null) stmt.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 }
440 upgradeVersion = 32;
441 }
442
443 if (upgradeVersion == 32) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 upgradeVersion = 33;
445 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -0700446
The Android Open Source Project4df24232009-03-05 14:34:35 -0800447 if (upgradeVersion == 33) {
448 // Set the default zoom controls to: tap-twice to bring up +/-
449 db.beginTransaction();
450 try {
451 db.execSQL("INSERT INTO system(name,value) values('zoom','2');");
452 db.setTransactionSuccessful();
453 } finally {
454 db.endTransaction();
455 }
456 upgradeVersion = 34;
457 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458
Mike Lockwoodbcab8df2009-06-25 16:39:09 -0400459 if (upgradeVersion == 34) {
460 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700461 SQLiteStatement stmt = null;
Mike Lockwoodbcab8df2009-06-25 16:39:09 -0400462 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700463 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
Dianne Hackborncf098292009-07-01 19:55:20 -0700464 + " VALUES(?,?);");
465 loadSecure35Settings(stmt);
Dianne Hackborncf098292009-07-01 19:55:20 -0700466 db.setTransactionSuccessful();
467 } finally {
468 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700469 if (stmt != null) stmt.close();
Dianne Hackborncf098292009-07-01 19:55:20 -0700470 }
Jim Millerf1860552009-09-09 17:46:35 -0700471 upgradeVersion = 35;
Mike Lockwood02901eb2009-08-25 15:11:17 -0700472 }
473 // due to a botched merge from donut to eclair, the initialization of ASSISTED_GPS_ENABLED
474 // was accidentally done out of order here.
475 // to fix this, ASSISTED_GPS_ENABLED is now initialized while upgrading from 38 to 39,
476 // and we intentionally do nothing from 35 to 36 now.
477 if (upgradeVersion == 35) {
The Android Open Source Project575d1af2009-07-03 08:55:59 -0700478 upgradeVersion = 36;
Dianne Hackborncf098292009-07-01 19:55:20 -0700479 }
Mike Lockwood02901eb2009-08-25 15:11:17 -0700480
Eric Laurenta553c252009-07-17 12:17:14 -0700481 if (upgradeVersion == 36) {
482 // This upgrade adds the STREAM_SYSTEM_ENFORCED type to the list of
483 // types affected by ringer modes (silent, vibrate, etc.)
484 db.beginTransaction();
485 try {
486 db.execSQL("DELETE FROM system WHERE name='"
487 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
488 int newValue = (1 << AudioManager.STREAM_RING)
489 | (1 << AudioManager.STREAM_NOTIFICATION)
490 | (1 << AudioManager.STREAM_SYSTEM)
491 | (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
492 db.execSQL("INSERT INTO system ('name', 'value') values ('"
493 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
494 + String.valueOf(newValue) + "')");
495 db.setTransactionSuccessful();
496 } finally {
497 db.endTransaction();
498 }
Jim Miller48805752009-08-04 18:59:20 -0700499 upgradeVersion = 37;
Eric Laurenta553c252009-07-17 12:17:14 -0700500 }
501
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700502 if (upgradeVersion == 37) {
503 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700504 SQLiteStatement stmt = null;
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700505 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700506 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700507 + " VALUES(?,?);");
508 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
509 R.string.airplane_mode_toggleable_radios);
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700510 db.setTransactionSuccessful();
511 } finally {
512 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700513 if (stmt != null) stmt.close();
Mike Lockwoodbd5ddf02009-07-29 21:37:14 -0700514 }
515 upgradeVersion = 38;
516 }
517
Mike Lockwood02901eb2009-08-25 15:11:17 -0700518 if (upgradeVersion == 38) {
519 db.beginTransaction();
520 try {
521 String value =
522 mContext.getResources().getBoolean(R.bool.assisted_gps_enabled) ? "1" : "0";
523 db.execSQL("INSERT OR IGNORE INTO secure(name,value) values('" +
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -0700524 Settings.Global.ASSISTED_GPS_ENABLED + "','" + value + "');");
Mike Lockwood02901eb2009-08-25 15:11:17 -0700525 db.setTransactionSuccessful();
526 } finally {
527 db.endTransaction();
528 }
529
530 upgradeVersion = 39;
531 }
532
Dan Murphy951764b2009-08-27 14:59:03 -0500533 if (upgradeVersion == 39) {
Amith Yamasanif50c5112011-01-07 11:32:30 -0800534 upgradeAutoBrightness(db);
Dan Murphy951764b2009-08-27 14:59:03 -0500535 upgradeVersion = 40;
536 }
537
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700538 if (upgradeVersion == 40) {
539 /*
540 * All animations are now turned on by default!
541 */
542 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700543 SQLiteStatement stmt = null;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700544 try {
545 db.execSQL("DELETE FROM system WHERE name='"
546 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
547 db.execSQL("DELETE FROM system WHERE name='"
548 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700549 stmt = db.compileStatement("INSERT INTO system(name,value)"
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700550 + " VALUES(?,?);");
551 loadDefaultAnimationSettings(stmt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700552 db.setTransactionSuccessful();
553 } finally {
554 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700555 if (stmt != null) stmt.close();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700556 }
557 upgradeVersion = 41;
558 }
559
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700560 if (upgradeVersion == 41) {
561 /*
562 * Initialize newly public haptic feedback setting
563 */
564 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700565 SQLiteStatement stmt = null;
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700566 try {
567 db.execSQL("DELETE FROM system WHERE name='"
568 + Settings.System.HAPTIC_FEEDBACK_ENABLED + "'");
Vasu Nori89206fdb2010-03-22 10:37:03 -0700569 stmt = db.compileStatement("INSERT INTO system(name,value)"
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700570 + " VALUES(?,?);");
571 loadDefaultHapticSettings(stmt);
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700572 db.setTransactionSuccessful();
573 } finally {
574 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700575 if (stmt != null) stmt.close();
Dianne Hackborn075a18d2009-09-26 12:43:19 -0700576 }
577 upgradeVersion = 42;
578 }
579
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800580 if (upgradeVersion == 42) {
581 /*
582 * Initialize new notification pulse setting
583 */
584 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700585 SQLiteStatement stmt = null;
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800586 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700587 stmt = db.compileStatement("INSERT INTO system(name,value)"
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800588 + " VALUES(?,?);");
589 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
590 R.bool.def_notification_pulse);
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800591 db.setTransactionSuccessful();
592 } finally {
593 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700594 if (stmt != null) stmt.close();
Amith Yamasaniae3ed702009-12-01 19:02:05 -0800595 }
596 upgradeVersion = 43;
597 }
598
Eric Laurent484d2882009-12-08 09:05:45 -0800599 if (upgradeVersion == 43) {
600 /*
601 * This upgrade stores bluetooth volume separately from voice volume
602 */
603 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700604 SQLiteStatement stmt = null;
Eric Laurent484d2882009-12-08 09:05:45 -0800605 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700606 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
Eric Laurent484d2882009-12-08 09:05:45 -0800607 + " VALUES(?,?);");
608 loadSetting(stmt, Settings.System.VOLUME_BLUETOOTH_SCO,
John Spurlock61560172015-02-06 19:46:04 -0500609 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
Eric Laurent484d2882009-12-08 09:05:45 -0800610 db.setTransactionSuccessful();
611 } finally {
612 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700613 if (stmt != null) stmt.close();
Eric Laurent484d2882009-12-08 09:05:45 -0800614 }
615 upgradeVersion = 44;
616 }
617
Doug Zongkeraed8f8e2010-01-07 18:07:50 -0800618 if (upgradeVersion == 44) {
619 /*
620 * Gservices was moved into vendor/google.
621 */
622 db.execSQL("DROP TABLE IF EXISTS gservices");
623 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1");
624 upgradeVersion = 45;
625 }
San Mehat87734d32010-01-08 12:53:06 -0800626
627 if (upgradeVersion == 45) {
628 /*
Sudheer Shanka2250d562016-11-07 15:41:02 -0800629 * New settings for StorageManagerService
San Mehat87734d32010-01-08 12:53:06 -0800630 */
631 db.beginTransaction();
632 try {
633 db.execSQL("INSERT INTO secure(name,value) values('" +
634 Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND + "','1');");
635 db.execSQL("INSERT INTO secure(name,value) values('" +
636 Settings.Secure.MOUNT_UMS_AUTOSTART + "','0');");
637 db.execSQL("INSERT INTO secure(name,value) values('" +
638 Settings.Secure.MOUNT_UMS_PROMPT + "','1');");
639 db.execSQL("INSERT INTO secure(name,value) values('" +
640 Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED + "','1');");
641 db.setTransactionSuccessful();
642 } finally {
643 db.endTransaction();
644 }
645 upgradeVersion = 46;
646 }
647
Dianne Hackborndf83afa2010-01-20 13:37:26 -0800648 if (upgradeVersion == 46) {
649 /*
650 * The password mode constants have changed; reset back to no
651 * password.
652 */
653 db.beginTransaction();
654 try {
655 db.execSQL("DELETE FROM system WHERE name='lockscreen.password_type';");
656 db.setTransactionSuccessful();
657 } finally {
658 db.endTransaction();
659 }
660 upgradeVersion = 47;
661 }
662
Jim Miller61766772010-02-12 14:56:49 -0800663
Dianne Hackborn9327f4f2010-01-29 10:38:29 -0800664 if (upgradeVersion == 47) {
665 /*
666 * The password mode constants have changed again; reset back to no
667 * password.
668 */
669 db.beginTransaction();
670 try {
671 db.execSQL("DELETE FROM system WHERE name='lockscreen.password_type';");
672 db.setTransactionSuccessful();
673 } finally {
674 db.endTransaction();
675 }
676 upgradeVersion = 48;
677 }
Jim Miller61766772010-02-12 14:56:49 -0800678
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800679 if (upgradeVersion == 48) {
680 /*
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800681 * Default recognition service no longer initialized here,
682 * moved to RecognitionManagerService.
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800683 */
Mike LeBeau5d34e9b2010-02-10 19:34:56 -0800684 upgradeVersion = 49;
685 }
Jim Miller31f90b62010-01-20 13:35:20 -0800686
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500687 if (upgradeVersion == 49) {
688 /*
689 * New settings for new user interface noises.
690 */
691 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700692 SQLiteStatement stmt = null;
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500693 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700694 stmt = db.compileStatement("INSERT INTO system(name,value)"
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500695 + " VALUES(?,?);");
696 loadUISoundEffectsSettings(stmt);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500697 db.setTransactionSuccessful();
698 } finally {
699 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700700 if (stmt != null) stmt.close();
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500701 }
702
703 upgradeVersion = 50;
704 }
705
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800706 if (upgradeVersion == 50) {
707 /*
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700708 * Install location no longer initiated here.
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800709 */
Oscar Montemayorf1cbfff2010-02-22 16:12:07 -0800710 upgradeVersion = 51;
711 }
712
Amith Yamasani156c4352010-03-05 17:10:03 -0800713 if (upgradeVersion == 51) {
714 /* Move the lockscreen related settings to Secure, including some private ones. */
715 String[] settingsToMove = {
716 Secure.LOCK_PATTERN_ENABLED,
717 Secure.LOCK_PATTERN_VISIBLE,
718 Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED,
719 "lockscreen.password_type",
720 "lockscreen.lockoutattemptdeadline",
721 "lockscreen.patterneverchosen",
722 "lock_pattern_autolock",
723 "lockscreen.lockedoutpermanently",
724 "lockscreen.password_salt"
725 };
Christopher Tate92198742012-09-07 12:00:13 -0700726 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
Amith Yamasani156c4352010-03-05 17:10:03 -0800727 upgradeVersion = 52;
728 }
729
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500730 if (upgradeVersion == 52) {
731 // new vibration/silent mode settings
732 db.beginTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700733 SQLiteStatement stmt = null;
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500734 try {
Vasu Nori89206fdb2010-03-22 10:37:03 -0700735 stmt = db.compileStatement("INSERT INTO system(name,value)"
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500736 + " VALUES(?,?);");
737 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
738 R.bool.def_vibrate_in_silent);
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500739 db.setTransactionSuccessful();
740 } finally {
741 db.endTransaction();
Vasu Nori89206fdb2010-03-22 10:37:03 -0700742 if (stmt != null) stmt.close();
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500743 }
744
745 upgradeVersion = 53;
746 }
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -0700747
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800748 if (upgradeVersion == 53) {
749 /*
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700750 * New settings for set install location UI no longer initiated here.
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800751 */
Suchi Amalapurapu089262d2010-03-10 14:19:21 -0800752 upgradeVersion = 54;
753 }
Daniel Sandler1c7fa482010-03-10 09:45:01 -0500754
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -0700755 if (upgradeVersion == 54) {
756 /*
757 * Update the screen timeout value if set to never
758 */
759 db.beginTransaction();
760 try {
761 upgradeScreenTimeoutFromNever(db);
762 db.setTransactionSuccessful();
763 } finally {
764 db.endTransaction();
765 }
766
767 upgradeVersion = 55;
768 }
769
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700770 if (upgradeVersion == 55) {
771 /* Move the install location settings. */
772 String[] settingsToMove = {
Jeff Sharkey625239a2012-09-26 22:03:49 -0700773 Global.SET_INSTALL_LOCATION,
774 Global.DEFAULT_INSTALL_LOCATION
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700775 };
Christopher Tate92198742012-09-07 12:00:13 -0700776 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700777 db.beginTransaction();
778 SQLiteStatement stmt = null;
779 try {
780 stmt = db.compileStatement("INSERT INTO system(name,value)"
781 + " VALUES(?,?);");
Jeff Sharkey625239a2012-09-26 22:03:49 -0700782 loadSetting(stmt, Global.SET_INSTALL_LOCATION, 0);
783 loadSetting(stmt, Global.DEFAULT_INSTALL_LOCATION,
Suchi Amalapurapu40e47252010-04-07 16:15:50 -0700784 PackageHelper.APP_INSTALL_AUTO);
785 db.setTransactionSuccessful();
786 } finally {
787 db.endTransaction();
788 if (stmt != null) stmt.close();
789 }
790 upgradeVersion = 56;
791 }
Jake Hamby66592842010-08-24 19:55:20 -0700792
793 if (upgradeVersion == 56) {
794 /*
795 * Add Bluetooth to list of toggleable radios in airplane mode
796 */
797 db.beginTransaction();
798 SQLiteStatement stmt = null;
799 try {
800 db.execSQL("DELETE FROM system WHERE name='"
801 + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS + "'");
802 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
803 + " VALUES(?,?);");
804 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
805 R.string.airplane_mode_toggleable_radios);
806 db.setTransactionSuccessful();
807 } finally {
808 db.endTransaction();
809 if (stmt != null) stmt.close();
810 }
811 upgradeVersion = 57;
812 }
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700813
Amith Yamasani5cd15002011-11-16 11:19:48 -0800814 /************* The following are Honeycomb changes ************/
815
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700816 if (upgradeVersion == 57) {
817 /*
Phil Weaver09d4ff82017-03-31 11:22:17 -0700818 * No longer initializing deleted setting ACCESSIBILITY_SCRIPT_INJECTION.
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700819 */
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -0700820 upgradeVersion = 58;
821 }
822
Amith Yamasaniad450be2010-09-16 16:47:00 -0700823 if (upgradeVersion == 58) {
824 /* Add default for new Auto Time Zone */
Amith Yamasani5cd15002011-11-16 11:19:48 -0800825 int autoTimeValue = getIntValueFromSystem(db, Settings.System.AUTO_TIME, 0);
Amith Yamasaniad450be2010-09-16 16:47:00 -0700826 db.beginTransaction();
827 SQLiteStatement stmt = null;
828 try {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800829 stmt = db.compileStatement("INSERT INTO system(name,value)" + " VALUES(?,?);");
830 loadSetting(stmt, Settings.System.AUTO_TIME_ZONE,
831 autoTimeValue); // Sync timezone to NITZ if auto_time was enabled
Amith Yamasaniad450be2010-09-16 16:47:00 -0700832 db.setTransactionSuccessful();
833 } finally {
834 db.endTransaction();
835 if (stmt != null) stmt.close();
836 }
837 upgradeVersion = 59;
838 }
839
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400840 if (upgradeVersion == 59) {
841 // Persistence for the rotation lock feature.
842 db.beginTransaction();
843 SQLiteStatement stmt = null;
844 try {
845 stmt = db.compileStatement("INSERT INTO system(name,value)"
846 + " VALUES(?,?);");
847 loadBooleanSetting(stmt, Settings.System.USER_ROTATION,
848 R.integer.def_user_rotation); // should be zero degrees
849 db.setTransactionSuccessful();
850 } finally {
851 db.endTransaction();
852 if (stmt != null) stmt.close();
853 }
854 upgradeVersion = 60;
855 }
856
Amith Yamasani00389312010-11-05 11:22:21 -0700857 if (upgradeVersion == 60) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800858 // Don't do this for upgrades from Gingerbread
859 // Were only required for intra-Honeycomb upgrades for testing
860 // upgradeScreenTimeout(db);
Amith Yamasani00389312010-11-05 11:22:21 -0700861 upgradeVersion = 61;
862 }
863
Amith Yamasani79373f62010-11-18 16:32:48 -0800864 if (upgradeVersion == 61) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800865 // Don't do this for upgrades from Gingerbread
866 // Were only required for intra-Honeycomb upgrades for testing
867 // upgradeScreenTimeout(db);
Amith Yamasani79373f62010-11-18 16:32:48 -0800868 upgradeVersion = 62;
869 }
870
Amith Yamasanif50c5112011-01-07 11:32:30 -0800871 // Change the default for screen auto-brightness mode
872 if (upgradeVersion == 62) {
Amith Yamasani5cd15002011-11-16 11:19:48 -0800873 // Don't do this for upgrades from Gingerbread
874 // Were only required for intra-Honeycomb upgrades for testing
875 // upgradeAutoBrightness(db);
Amith Yamasanif50c5112011-01-07 11:32:30 -0800876 upgradeVersion = 63;
877 }
878
Eric Laurent25101b02011-02-02 09:33:30 -0800879 if (upgradeVersion == 63) {
880 // This upgrade adds the STREAM_MUSIC type to the list of
881 // types affected by ringer modes (silent, vibrate, etc.)
882 db.beginTransaction();
883 try {
884 db.execSQL("DELETE FROM system WHERE name='"
885 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
886 int newValue = (1 << AudioManager.STREAM_RING)
887 | (1 << AudioManager.STREAM_NOTIFICATION)
888 | (1 << AudioManager.STREAM_SYSTEM)
889 | (1 << AudioManager.STREAM_SYSTEM_ENFORCED)
890 | (1 << AudioManager.STREAM_MUSIC);
891 db.execSQL("INSERT INTO system ('name', 'value') values ('"
892 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
893 + String.valueOf(newValue) + "')");
894 db.setTransactionSuccessful();
895 } finally {
896 db.endTransaction();
897 }
898 upgradeVersion = 64;
899 }
900
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800901 if (upgradeVersion == 64) {
902 // New setting to configure the long press timeout.
903 db.beginTransaction();
904 SQLiteStatement stmt = null;
905 try {
906 stmt = db.compileStatement("INSERT INTO secure(name,value)"
907 + " VALUES(?,?);");
908 loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT,
909 R.integer.def_long_press_timeout_millis);
910 stmt.close();
911 db.setTransactionSuccessful();
912 } finally {
913 db.endTransaction();
914 if (stmt != null) stmt.close();
915 }
916 upgradeVersion = 65;
917 }
918
Amith Yamasani5cd15002011-11-16 11:19:48 -0800919 /************* The following are Ice Cream Sandwich changes ************/
920
Gilles Debunnefa53d302011-07-08 10:40:51 -0700921 if (upgradeVersion == 65) {
922 /*
923 * Animations are removed from Settings. Turned on by default
924 */
925 db.beginTransaction();
926 SQLiteStatement stmt = null;
927 try {
928 db.execSQL("DELETE FROM system WHERE name='"
929 + Settings.System.WINDOW_ANIMATION_SCALE + "'");
930 db.execSQL("DELETE FROM system WHERE name='"
931 + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
932 stmt = db.compileStatement("INSERT INTO system(name,value)"
933 + " VALUES(?,?);");
934 loadDefaultAnimationSettings(stmt);
935 db.setTransactionSuccessful();
936 } finally {
937 db.endTransaction();
938 if (stmt != null) stmt.close();
939 }
940 upgradeVersion = 66;
941 }
942
Eric Laurentc1d41662011-07-19 11:21:13 -0700943 if (upgradeVersion == 66) {
Amith Yamasani42722bf2011-07-22 10:34:27 -0700944 // This upgrade makes sure that MODE_RINGER_STREAMS_AFFECTED is set
945 // according to device voice capability
946 db.beginTransaction();
947 try {
948 int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
949 (1 << AudioManager.STREAM_NOTIFICATION) |
950 (1 << AudioManager.STREAM_SYSTEM) |
951 (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
952 if (!mContext.getResources().getBoolean(
953 com.android.internal.R.bool.config_voice_capable)) {
954 ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
955 }
956 db.execSQL("DELETE FROM system WHERE name='"
957 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
958 db.execSQL("INSERT INTO system ('name', 'value') values ('"
959 + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
960 + String.valueOf(ringerModeAffectedStreams) + "')");
961 db.setTransactionSuccessful();
962 } finally {
963 db.endTransaction();
964 }
965 upgradeVersion = 67;
966 }
Eric Laurentc1d41662011-07-19 11:21:13 -0700967
Svetoslav Ganova28a16d2011-07-28 11:24:21 -0700968 if (upgradeVersion == 67) {
969 // New setting to enable touch exploration.
970 db.beginTransaction();
971 SQLiteStatement stmt = null;
972 try {
973 stmt = db.compileStatement("INSERT INTO secure(name,value)"
974 + " VALUES(?,?);");
975 loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED,
976 R.bool.def_touch_exploration_enabled);
977 stmt.close();
978 db.setTransactionSuccessful();
979 } finally {
980 db.endTransaction();
981 if (stmt != null) stmt.close();
982 }
983 upgradeVersion = 68;
984 }
985
Amith Yamasani42722bf2011-07-22 10:34:27 -0700986 if (upgradeVersion == 68) {
987 // Enable all system sounds by default
988 db.beginTransaction();
Amith Yamasani42722bf2011-07-22 10:34:27 -0700989 try {
Amith Yamasani42722bf2011-07-22 10:34:27 -0700990 db.execSQL("DELETE FROM system WHERE name='"
991 + Settings.System.NOTIFICATIONS_USE_RING_VOLUME + "'");
Amith Yamasani42722bf2011-07-22 10:34:27 -0700992 db.setTransactionSuccessful();
993 } finally {
994 db.endTransaction();
Amith Yamasani42722bf2011-07-22 10:34:27 -0700995 }
996 upgradeVersion = 69;
997 }
Svetoslav Ganova28a16d2011-07-28 11:24:21 -0700998
Nick Pelly8d32a012011-08-09 07:03:49 -0700999 if (upgradeVersion == 69) {
1000 // Add RADIO_NFC to AIRPLANE_MODE_RADIO and AIRPLANE_MODE_TOGGLEABLE_RADIOS
1001 String airplaneRadios = mContext.getResources().getString(
1002 R.string.def_airplane_mode_radios);
1003 String toggleableRadios = mContext.getResources().getString(
1004 R.string.airplane_mode_toggleable_radios);
1005 db.beginTransaction();
1006 try {
1007 db.execSQL("UPDATE system SET value='" + airplaneRadios + "' " +
1008 "WHERE name='" + Settings.System.AIRPLANE_MODE_RADIOS + "'");
1009 db.execSQL("UPDATE system SET value='" + toggleableRadios + "' " +
1010 "WHERE name='" + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS + "'");
1011 db.setTransactionSuccessful();
1012 } finally {
1013 db.endTransaction();
1014 }
1015 upgradeVersion = 70;
1016 }
1017
Jeff Brown6651a632011-11-28 12:59:11 -08001018 if (upgradeVersion == 70) {
1019 // Update all built-in bookmarks. Some of the package names have changed.
1020 loadBookmarks(db);
1021 upgradeVersion = 71;
1022 }
1023
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08001024 if (upgradeVersion == 71) {
1025 // New setting to specify whether to speak passwords in accessibility mode.
1026 db.beginTransaction();
1027 SQLiteStatement stmt = null;
1028 try {
1029 stmt = db.compileStatement("INSERT INTO secure(name,value)"
1030 + " VALUES(?,?);");
1031 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD,
1032 R.bool.def_accessibility_speak_password);
Amith Yamasani6243edd2011-12-05 19:58:48 -08001033 db.setTransactionSuccessful();
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08001034 } finally {
1035 db.endTransaction();
1036 if (stmt != null) stmt.close();
1037 }
1038 upgradeVersion = 72;
1039 }
1040
Amith Yamasani6243edd2011-12-05 19:58:48 -08001041 if (upgradeVersion == 72) {
1042 // update vibration settings
1043 db.beginTransaction();
1044 SQLiteStatement stmt = null;
1045 try {
1046 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1047 + " VALUES(?,?);");
1048 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
1049 R.bool.def_vibrate_in_silent);
1050 db.setTransactionSuccessful();
1051 } finally {
1052 db.endTransaction();
1053 if (stmt != null) stmt.close();
1054 }
1055 upgradeVersion = 73;
1056 }
1057
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001058 if (upgradeVersion == 73) {
Amith Yamasani398c83c2011-12-13 10:38:47 -08001059 upgradeVibrateSettingFromNone(db);
1060 upgradeVersion = 74;
1061 }
1062
1063 if (upgradeVersion == 74) {
Phil Weaver09d4ff82017-03-31 11:22:17 -07001064 // No longer using URL from which WebView loads a JavaScript based screen-reader.
Amith Yamasani398c83c2011-12-13 10:38:47 -08001065 upgradeVersion = 75;
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001066 }
Mike Lockwood7bef7392011-10-20 16:51:53 -04001067 if (upgradeVersion == 75) {
1068 db.beginTransaction();
1069 SQLiteStatement stmt = null;
1070 Cursor c = null;
1071 try {
Christopher Tate06efb532012-08-24 15:29:27 -07001072 c = db.query(TABLE_SECURE, new String[] {"_id", "value"},
Mike Lockwood7bef7392011-10-20 16:51:53 -04001073 "name='lockscreen.disabled'",
1074 null, null, null, null);
1075 // only set default if it has not yet been set
1076 if (c == null || c.getCount() == 0) {
1077 stmt = db.compileStatement("INSERT INTO system(name,value)"
1078 + " VALUES(?,?);");
1079 loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED,
1080 R.bool.def_lockscreen_disabled);
1081 }
1082 db.setTransactionSuccessful();
1083 } finally {
1084 db.endTransaction();
1085 if (c != null) c.close();
1086 if (stmt != null) stmt.close();
1087 }
1088 upgradeVersion = 76;
1089 }
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08001090
Eric Laurentbffc3d12012-05-07 17:43:49 -07001091 /************* The following are Jelly Bean changes ************/
1092
1093 if (upgradeVersion == 76) {
1094 // Removed VIBRATE_IN_SILENT setting
1095 db.beginTransaction();
1096 try {
1097 db.execSQL("DELETE FROM system WHERE name='"
1098 + Settings.System.VIBRATE_IN_SILENT + "'");
1099 db.setTransactionSuccessful();
1100 } finally {
1101 db.endTransaction();
1102 }
1103
1104 upgradeVersion = 77;
1105 }
1106
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001107 if (upgradeVersion == 77) {
Beverlyf9af4082019-01-09 15:31:18 -05001108 // "vibrate when ringing" setting moved to SettingsProvider version 168
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07001109 upgradeVersion = 78;
1110 }
Eric Laurentbffc3d12012-05-07 17:43:49 -07001111
alanv3a67eb32012-06-22 10:47:28 -07001112 if (upgradeVersion == 78) {
Phil Weaver09d4ff82017-03-31 11:22:17 -07001113 // ACCESSIBILITY_SCREEN_READER_URL has been removed
alanv3a67eb32012-06-22 10:47:28 -07001114 upgradeVersion = 79;
1115 }
1116
Svetoslav Ganov86317012012-08-15 22:13:00 -07001117 if (upgradeVersion == 79) {
1118 // Before touch exploration was a global setting controlled by the user
1119 // via the UI. However, if the enabled accessibility services do not
1120 // handle touch exploration mode, enabling it makes no sense. Therefore,
1121 // now the services request touch exploration mode and the user is
1122 // presented with a dialog to allow that and if she does we store that
1123 // in the database. As a result of this change a user that has enabled
1124 // accessibility, touch exploration, and some accessibility services
1125 // may lose touch exploration state, thus rendering the device useless
1126 // unless sighted help is provided, since the enabled service(s) are
1127 // not in the list of services to which the user granted a permission
1128 // to put the device in touch explore mode. Here we are allowing all
1129 // enabled accessibility services to toggle touch exploration provided
1130 // accessibility and touch exploration are enabled and no services can
1131 // toggle touch exploration. Note that the user has already manually
1132 // enabled the services and touch exploration which means the she has
1133 // given consent to have these services work in touch exploration mode.
Christopher Tate06efb532012-08-24 15:29:27 -07001134 final boolean accessibilityEnabled = getIntValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001135 Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;
Christopher Tate06efb532012-08-24 15:29:27 -07001136 final boolean touchExplorationEnabled = getIntValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001137 Settings.Secure.TOUCH_EXPLORATION_ENABLED, 0) == 1;
1138 if (accessibilityEnabled && touchExplorationEnabled) {
Christopher Tate06efb532012-08-24 15:29:27 -07001139 String enabledServices = getStringValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001140 Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "");
Christopher Tate06efb532012-08-24 15:29:27 -07001141 String touchExplorationGrantedServices = getStringValueFromTable(db, TABLE_SECURE,
Svetoslav Ganov86317012012-08-15 22:13:00 -07001142 Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, "");
1143 if (TextUtils.isEmpty(touchExplorationGrantedServices)
1144 && !TextUtils.isEmpty(enabledServices)) {
1145 SQLiteStatement stmt = null;
1146 try {
1147 db.beginTransaction();
1148 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1149 + " VALUES(?,?);");
1150 loadSetting(stmt,
1151 Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES,
1152 enabledServices);
1153 db.setTransactionSuccessful();
1154 } finally {
1155 db.endTransaction();
1156 if (stmt != null) stmt.close();
1157 }
1158 }
1159 }
1160 upgradeVersion = 80;
1161 }
1162
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001163 // vvv Jelly Bean MR1 changes begin here vvv
1164
Svetoslav Ganovca34bcf2012-08-16 12:22:23 -07001165 if (upgradeVersion == 80) {
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001166 // update screensaver settings
1167 db.beginTransaction();
1168 SQLiteStatement stmt = null;
1169 try {
1170 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1171 + " VALUES(?,?);");
1172 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED,
John Spurlocked108f32012-10-18 16:49:24 -04001173 com.android.internal.R.bool.config_dreamsEnabledByDefault);
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001174 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
John Spurlocked108f32012-10-18 16:49:24 -04001175 com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04001176 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
John Spurlocked108f32012-10-18 16:49:24 -04001177 com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04001178 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_COMPONENTS,
John Spurlocked108f32012-10-18 16:49:24 -04001179 com.android.internal.R.string.config_dreamsDefaultComponent);
1180 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT,
1181 com.android.internal.R.string.config_dreamsDefaultComponent);
Christopher Tate06efb532012-08-24 15:29:27 -07001182
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001183 db.setTransactionSuccessful();
1184 } finally {
1185 db.endTransaction();
1186 if (stmt != null) stmt.close();
1187 }
Svetoslav Ganovca34bcf2012-08-16 12:22:23 -07001188 upgradeVersion = 81;
Daniel Sandlerfdb7c362012-08-06 17:02:55 -04001189 }
1190
rich cannings16e119e2012-09-06 12:04:37 -07001191 if (upgradeVersion == 81) {
1192 // Add package verification setting
1193 db.beginTransaction();
1194 SQLiteStatement stmt = null;
1195 try {
1196 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1197 + " VALUES(?,?);");
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001198 loadBooleanSetting(stmt, Settings.Global.PACKAGE_VERIFIER_ENABLE,
rich cannings16e119e2012-09-06 12:04:37 -07001199 R.bool.def_package_verifier_enable);
1200 db.setTransactionSuccessful();
1201 } finally {
1202 db.endTransaction();
1203 if (stmt != null) stmt.close();
1204 }
1205 upgradeVersion = 82;
1206 }
1207
Christopher Tate06efb532012-08-24 15:29:27 -07001208 if (upgradeVersion == 82) {
1209 // Move to per-user settings dbs
Xiaohui Chen43765b72015-08-31 10:57:33 -07001210 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate06efb532012-08-24 15:29:27 -07001211
Christopher Tate59c5bee2012-09-13 14:38:33 -07001212 db.beginTransaction();
1213 SQLiteStatement stmt = null;
1214 try {
1215 // Migrate now-global settings. Note that this happens before
1216 // new users can be created.
1217 createGlobalTable(db);
Svetoslav683914b2015-01-15 14:22:26 -08001218 String[] settingsToMove = setToStringArray(
1219 SettingsProvider.sSystemMovedToGlobalSettings);
Christopher Tate59c5bee2012-09-13 14:38:33 -07001220 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, false);
Svetoslav683914b2015-01-15 14:22:26 -08001221 settingsToMove = setToStringArray(
1222 SettingsProvider.sSecureMovedToGlobalSettings);
Christopher Tate59c5bee2012-09-13 14:38:33 -07001223 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, false);
1224
1225 db.setTransactionSuccessful();
1226 } finally {
1227 db.endTransaction();
1228 if (stmt != null) stmt.close();
1229 }
Christopher Tate06efb532012-08-24 15:29:27 -07001230 }
1231 upgradeVersion = 83;
1232 }
1233
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001234 if (upgradeVersion == 83) {
1235 // 1. Setting whether screen magnification is enabled.
1236 // 2. Setting for screen magnification scale.
1237 // 3. Setting for screen magnification auto update.
1238 db.beginTransaction();
1239 SQLiteStatement stmt = null;
1240 try {
1241 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
1242 loadBooleanSetting(stmt,
1243 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
1244 R.bool.def_accessibility_display_magnification_enabled);
1245 stmt.close();
1246 stmt = db.compileStatement("INSERT INTO secure(name,value) VALUES(?,?);");
1247 loadFractionSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
1248 R.fraction.def_accessibility_display_magnification_scale, 1);
1249 stmt.close();
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001250
1251 db.setTransactionSuccessful();
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001252 } finally {
1253 db.endTransaction();
1254 if (stmt != null) stmt.close();
1255 }
1256 upgradeVersion = 84;
1257 }
1258
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001259 if (upgradeVersion == 84) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001260 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001261 db.beginTransaction();
1262 SQLiteStatement stmt = null;
1263 try {
1264 // Patch up the slightly-wrong key migration from 82 -> 83 for those
1265 // devices that missed it, ignoring if the move is redundant
1266 String[] settingsToMove = {
1267 Settings.Secure.ADB_ENABLED,
1268 Settings.Secure.BLUETOOTH_ON,
1269 Settings.Secure.DATA_ROAMING,
1270 Settings.Secure.DEVICE_PROVISIONED,
1271 Settings.Secure.INSTALL_NON_MARKET_APPS,
1272 Settings.Secure.USB_MASS_STORAGE_ENABLED
1273 };
1274 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1275 db.setTransactionSuccessful();
1276 } finally {
1277 db.endTransaction();
1278 if (stmt != null) stmt.close();
1279 }
Christopher Tate1a9c0dfd2012-09-06 22:17:43 -07001280 }
1281 upgradeVersion = 85;
1282 }
1283
Christopher Tate92198742012-09-07 12:00:13 -07001284 if (upgradeVersion == 85) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001285 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001286 db.beginTransaction();
1287 try {
1288 // Fix up the migration, ignoring already-migrated elements, to snap up to
1289 // date with new changes to the set of global versus system/secure settings
1290 String[] settingsToMove = { Settings.System.STAY_ON_WHILE_PLUGGED_IN };
1291 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
Christopher Tate92198742012-09-07 12:00:13 -07001292
Christopher Tate59c5bee2012-09-13 14:38:33 -07001293 db.setTransactionSuccessful();
1294 } finally {
1295 db.endTransaction();
1296 }
Christopher Tate92198742012-09-07 12:00:13 -07001297 }
1298 upgradeVersion = 86;
1299 }
1300
rich cannings4d8fc792012-09-07 14:43:43 -07001301 if (upgradeVersion == 86) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001302 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001303 db.beginTransaction();
1304 try {
1305 String[] settingsToMove = {
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001306 Settings.Global.PACKAGE_VERIFIER_ENABLE,
1307 Settings.Global.PACKAGE_VERIFIER_TIMEOUT,
1308 Settings.Global.PACKAGE_VERIFIER_DEFAULT_RESPONSE
Christopher Tate59c5bee2012-09-13 14:38:33 -07001309 };
1310 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
rich cannings4d8fc792012-09-07 14:43:43 -07001311
Christopher Tate59c5bee2012-09-13 14:38:33 -07001312 db.setTransactionSuccessful();
1313 } finally {
1314 db.endTransaction();
1315 }
rich cannings4d8fc792012-09-07 14:43:43 -07001316 }
1317 upgradeVersion = 87;
1318 }
1319
Christopher Tatec868b642012-09-12 17:41:04 -07001320 if (upgradeVersion == 87) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001321 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate59c5bee2012-09-13 14:38:33 -07001322 db.beginTransaction();
1323 try {
1324 String[] settingsToMove = {
Jeff Sharkeybdfce2e2012-09-26 15:54:06 -07001325 Settings.Global.DATA_STALL_ALARM_NON_AGGRESSIVE_DELAY_IN_MS,
1326 Settings.Global.DATA_STALL_ALARM_AGGRESSIVE_DELAY_IN_MS,
1327 Settings.Global.GPRS_REGISTER_CHECK_PERIOD_MS
Christopher Tate59c5bee2012-09-13 14:38:33 -07001328 };
1329 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
Christopher Tatec868b642012-09-12 17:41:04 -07001330
Christopher Tate59c5bee2012-09-13 14:38:33 -07001331 db.setTransactionSuccessful();
1332 } finally {
1333 db.endTransaction();
1334 }
Christopher Tatec868b642012-09-12 17:41:04 -07001335 }
1336 upgradeVersion = 88;
1337 }
1338
Jeff Sharkey625239a2012-09-26 22:03:49 -07001339 if (upgradeVersion == 88) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001340 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jeff Sharkey625239a2012-09-26 22:03:49 -07001341 db.beginTransaction();
1342 try {
1343 String[] settingsToMove = {
1344 Settings.Global.BATTERY_DISCHARGE_DURATION_THRESHOLD,
1345 Settings.Global.BATTERY_DISCHARGE_THRESHOLD,
1346 Settings.Global.SEND_ACTION_APP_ERROR,
1347 Settings.Global.DROPBOX_AGE_SECONDS,
1348 Settings.Global.DROPBOX_MAX_FILES,
1349 Settings.Global.DROPBOX_QUOTA_KB,
1350 Settings.Global.DROPBOX_QUOTA_PERCENT,
1351 Settings.Global.DROPBOX_RESERVE_PERCENT,
1352 Settings.Global.DROPBOX_TAG_PREFIX,
1353 Settings.Global.ERROR_LOGCAT_PREFIX,
1354 Settings.Global.SYS_FREE_STORAGE_LOG_INTERVAL,
1355 Settings.Global.DISK_FREE_CHANGE_REPORTING_THRESHOLD,
1356 Settings.Global.SYS_STORAGE_THRESHOLD_PERCENTAGE,
1357 Settings.Global.SYS_STORAGE_THRESHOLD_MAX_BYTES,
1358 Settings.Global.SYS_STORAGE_FULL_THRESHOLD_BYTES,
1359 Settings.Global.SYNC_MAX_RETRY_DELAY_IN_SECONDS,
1360 Settings.Global.CONNECTIVITY_CHANGE_DELAY,
1361 Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED,
1362 Settings.Global.CAPTIVE_PORTAL_SERVER,
1363 Settings.Global.NSD_ON,
1364 Settings.Global.SET_INSTALL_LOCATION,
1365 Settings.Global.DEFAULT_INSTALL_LOCATION,
1366 Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY,
1367 Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY,
1368 Settings.Global.READ_EXTERNAL_STORAGE_ENFORCED_DEFAULT,
1369 Settings.Global.HTTP_PROXY,
1370 Settings.Global.GLOBAL_HTTP_PROXY_HOST,
1371 Settings.Global.GLOBAL_HTTP_PROXY_PORT,
1372 Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST,
1373 Settings.Global.SET_GLOBAL_HTTP_PROXY,
1374 Settings.Global.DEFAULT_DNS_SERVER,
1375 };
1376 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1377 db.setTransactionSuccessful();
1378 } finally {
1379 db.endTransaction();
1380 }
1381 }
1382 upgradeVersion = 89;
1383 }
1384
Jeff Sharkey0ac10282012-10-01 12:50:22 -07001385 if (upgradeVersion == 89) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001386 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jeff Sharkey0ac10282012-10-01 12:50:22 -07001387 db.beginTransaction();
1388 try {
1389 String[] prefixesToMove = {
1390 Settings.Global.BLUETOOTH_HEADSET_PRIORITY_PREFIX,
1391 Settings.Global.BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX,
1392 Settings.Global.BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX,
1393 };
1394
1395 movePrefixedSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, prefixesToMove);
1396
1397 db.setTransactionSuccessful();
1398 } finally {
1399 db.endTransaction();
1400 }
1401 }
1402 upgradeVersion = 90;
1403 }
1404
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001405 if (upgradeVersion == 90) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001406 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001407 db.beginTransaction();
1408 try {
1409 String[] systemToGlobal = {
1410 Settings.Global.WINDOW_ANIMATION_SCALE,
1411 Settings.Global.TRANSITION_ANIMATION_SCALE,
1412 Settings.Global.ANIMATOR_DURATION_SCALE,
1413 Settings.Global.FANCY_IME_ANIMATIONS,
1414 Settings.Global.COMPATIBILITY_MODE,
1415 Settings.Global.EMERGENCY_TONE,
1416 Settings.Global.CALL_AUTO_RETRY,
1417 Settings.Global.DEBUG_APP,
1418 Settings.Global.WAIT_FOR_DEBUGGER,
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001419 Settings.Global.ALWAYS_FINISH_ACTIVITIES,
1420 };
1421 String[] secureToGlobal = {
1422 Settings.Global.PREFERRED_NETWORK_MODE,
Naveen Kallab4d485c2013-07-03 16:39:27 -07001423 Settings.Global.CDMA_SUBSCRIPTION_MODE,
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07001424 };
1425
1426 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, systemToGlobal, true);
1427 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, secureToGlobal, true);
1428
1429 db.setTransactionSuccessful();
1430 } finally {
1431 db.endTransaction();
1432 }
1433 }
1434 upgradeVersion = 91;
1435 }
1436
Eric Laurent55b02222012-10-03 11:56:23 -07001437 if (upgradeVersion == 91) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001438 if (mUserHandle == UserHandle.USER_SYSTEM) {
Eric Laurent55b02222012-10-03 11:56:23 -07001439 db.beginTransaction();
1440 try {
1441 // Move ringer mode from system to global settings
Amith Yamasani531c2372012-10-08 14:43:20 -07001442 String[] settingsToMove = { Settings.Global.MODE_RINGER };
Eric Laurent55b02222012-10-03 11:56:23 -07001443 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
1444
1445 db.setTransactionSuccessful();
1446 } finally {
1447 db.endTransaction();
1448 }
1449 }
1450 upgradeVersion = 92;
1451 }
1452
John Spurlock7f1c2482012-10-05 11:15:28 -04001453 if (upgradeVersion == 92) {
1454 SQLiteStatement stmt = null;
1455 try {
1456 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1457 + " VALUES(?,?);");
Xiaohui Chen43765b72015-08-31 10:57:33 -07001458 if (mUserHandle == UserHandle.USER_SYSTEM) {
John Spurlock7f1c2482012-10-05 11:15:28 -04001459 // consider existing primary users to have made it through user setup
1460 // if the globally-scoped device-provisioned bit is set
1461 // (indicating they already made it through setup as primary)
1462 int deviceProvisioned = getIntValueFromTable(db, TABLE_GLOBAL,
1463 Settings.Global.DEVICE_PROVISIONED, 0);
1464 loadSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
1465 deviceProvisioned);
1466 } else {
1467 // otherwise use the default
1468 loadBooleanSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
1469 R.bool.def_user_setup_complete);
1470 }
1471 } finally {
1472 if (stmt != null) stmt.close();
1473 }
1474 upgradeVersion = 93;
1475 }
1476
Amith Yamasani531c2372012-10-08 14:43:20 -07001477 if (upgradeVersion == 93) {
1478 // Redo this step, since somehow it didn't work the first time for some users
Xiaohui Chen43765b72015-08-31 10:57:33 -07001479 if (mUserHandle == UserHandle.USER_SYSTEM) {
Amith Yamasani531c2372012-10-08 14:43:20 -07001480 db.beginTransaction();
Amith Yamasani531c2372012-10-08 14:43:20 -07001481 try {
1482 // Migrate now-global settings
Svetoslav683914b2015-01-15 14:22:26 -08001483 String[] settingsToMove = setToStringArray(
1484 SettingsProvider.sSystemMovedToGlobalSettings);
Amith Yamasani531c2372012-10-08 14:43:20 -07001485 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);
Svetoslav683914b2015-01-15 14:22:26 -08001486 settingsToMove = setToStringArray(
1487 SettingsProvider.sSecureMovedToGlobalSettings);
Amith Yamasani531c2372012-10-08 14:43:20 -07001488 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1489
1490 db.setTransactionSuccessful();
1491 } finally {
1492 db.endTransaction();
Amith Yamasani531c2372012-10-08 14:43:20 -07001493 }
1494 }
1495 upgradeVersion = 94;
1496 }
1497
Jeff Brown84e27562012-12-07 13:56:34 -08001498 if (upgradeVersion == 94) {
1499 // Add wireless charging started sound setting
Xiaohui Chen43765b72015-08-31 10:57:33 -07001500 if (mUserHandle == UserHandle.USER_SYSTEM) {
Amith Yamasani2d43fab2012-12-12 09:52:26 -08001501 db.beginTransaction();
1502 SQLiteStatement stmt = null;
1503 try {
1504 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1505 + " VALUES(?,?);");
Beverlyc1313eb2018-01-31 18:07:21 -05001506 loadStringSetting(stmt, Settings.Global.CHARGING_STARTED_SOUND,
Amith Yamasani2d43fab2012-12-12 09:52:26 -08001507 R.string.def_wireless_charging_started_sound);
1508 db.setTransactionSuccessful();
1509 } finally {
1510 db.endTransaction();
1511 if (stmt != null) stmt.close();
1512 }
Jeff Brown84e27562012-12-07 13:56:34 -08001513 }
1514 upgradeVersion = 95;
1515 }
1516
Christopher Tate58f41ec2013-01-11 15:40:36 -08001517 if (upgradeVersion == 95) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001518 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate58f41ec2013-01-11 15:40:36 -08001519 db.beginTransaction();
1520 try {
1521 String[] settingsToMove = { Settings.Global.BUGREPORT_IN_POWER_MENU };
1522 moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
1523 db.setTransactionSuccessful();
1524 } finally {
1525 db.endTransaction();
1526 }
1527 }
1528 upgradeVersion = 96;
1529 }
1530
Mike Clerond1ed3ce2013-02-01 18:36:41 +00001531 if (upgradeVersion == 96) {
Svetoslav Ganov447d9462013-02-01 19:46:20 +00001532 // NOP bump due to a reverted change that some people got on upgrade.
Mike Clerond1ed3ce2013-02-01 18:36:41 +00001533 upgradeVersion = 97;
1534 }
1535
Daniel Sandlerdea64622013-09-23 16:05:57 -04001536 if (upgradeVersion == 97) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001537 if (mUserHandle == UserHandle.USER_SYSTEM) {
Daniel Sandlerdea64622013-09-23 16:05:57 -04001538 db.beginTransaction();
1539 SQLiteStatement stmt = null;
1540 try {
1541 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1542 + " VALUES(?,?);");
1543 loadIntegerSetting(stmt, Settings.Global.LOW_BATTERY_SOUND_TIMEOUT,
1544 R.integer.def_low_battery_sound_timeout);
1545 db.setTransactionSuccessful();
1546 } finally {
1547 db.endTransaction();
1548 if (stmt != null) stmt.close();
1549 }
1550 }
1551 upgradeVersion = 98;
1552 }
1553
Dan Sandler82a6c5c2014-02-20 14:43:20 -05001554 if (upgradeVersion == 98) {
Dan Sandler52e5701e2014-07-22 23:14:54 -04001555 // no-op; LOCK_SCREEN_SHOW_NOTIFICATIONS now handled in version 106
Dan Sandler82a6c5c2014-02-20 14:43:20 -05001556 upgradeVersion = 99;
1557 }
1558
Chris Wren1cdd7dd2014-02-28 17:49:20 -05001559 if (upgradeVersion == 99) {
Dan Sandler52e5701e2014-07-22 23:14:54 -04001560 // no-op; HEADS_UP_NOTIFICATIONS_ENABLED now handled in version 100
1561 upgradeVersion = 100;
1562 }
1563
1564 if (upgradeVersion == 100) {
1565 // note: LOCK_SCREEN_SHOW_NOTIFICATIONS now handled in version 106
Xiaohui Chen43765b72015-08-31 10:57:33 -07001566 if (mUserHandle == UserHandle.USER_SYSTEM) {
Chris Wren1cdd7dd2014-02-28 17:49:20 -05001567 db.beginTransaction();
1568 SQLiteStatement stmt = null;
1569 try {
1570 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1571 + " VALUES(?,?);");
1572 loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED,
1573 R.integer.def_heads_up_enabled);
1574 db.setTransactionSuccessful();
1575 } finally {
1576 db.endTransaction();
1577 if (stmt != null) stmt.close();
1578 }
1579 }
Chris Wren5242cf32014-03-19 16:16:48 -04001580 upgradeVersion = 101;
1581 }
Chris Wren1cdd7dd2014-02-28 17:49:20 -05001582
Jerome Poichet147b4d72014-05-12 18:13:27 -07001583 if (upgradeVersion == 101) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001584 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jerome Poichet147b4d72014-05-12 18:13:27 -07001585 db.beginTransaction();
1586 SQLiteStatement stmt = null;
1587 try {
1588 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
1589 + " VALUES(?,?);");
1590 loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName());
1591 db.setTransactionSuccessful();
1592 } finally {
1593 db.endTransaction();
1594 if (stmt != null) stmt.close();
1595 }
1596 }
1597 upgradeVersion = 102;
1598 }
1599
Christopher Tateaa036a22014-05-19 16:33:27 -07001600 if (upgradeVersion == 102) {
1601 db.beginTransaction();
1602 SQLiteStatement stmt = null;
1603 try {
1604 // The INSTALL_NON_MARKET_APPS setting is becoming per-user rather
1605 // than device-global.
Xiaohui Chen43765b72015-08-31 10:57:33 -07001606 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tateaa036a22014-05-19 16:33:27 -07001607 // In the owner user, the global table exists so we can migrate the
1608 // entry from there to the secure table, preserving its value.
1609 String[] globalToSecure = {
1610 Settings.Secure.INSTALL_NON_MARKET_APPS
1611 };
1612 moveSettingsToNewTable(db, TABLE_GLOBAL, TABLE_SECURE, globalToSecure, true);
1613 } else {
1614 // Secondary users' dbs don't have the global table, so institute the
1615 // default.
1616 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1617 + " VALUES(?,?);");
1618 loadBooleanSetting(stmt, Settings.Secure.INSTALL_NON_MARKET_APPS,
1619 R.bool.def_install_non_market_apps);
1620 }
1621 db.setTransactionSuccessful();
1622 } finally {
1623 db.endTransaction();
1624 if (stmt != null) stmt.close();
1625 }
1626 upgradeVersion = 103;
1627 }
Jeff Browna20dda42014-05-27 20:57:24 -07001628
1629 if (upgradeVersion == 103) {
1630 db.beginTransaction();
1631 SQLiteStatement stmt = null;
1632 try {
1633 stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1634 + " VALUES(?,?);");
1635 loadBooleanSetting(stmt, Settings.Secure.WAKE_GESTURE_ENABLED,
1636 R.bool.def_wake_gesture_enabled);
1637 db.setTransactionSuccessful();
1638 } finally {
1639 db.endTransaction();
1640 if (stmt != null) stmt.close();
1641 }
1642 upgradeVersion = 104;
1643 }
1644
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001645 if (upgradeVersion < 105) {
Fyodor Kupolovcd86ebf2015-09-29 17:06:50 -07001646 // No-op: GUEST_USER_ENABLED setting was removed
Amith Yamasani1e9c2182014-06-11 17:25:51 -07001647 upgradeVersion = 105;
1648 }
1649
Dan Sandler52e5701e2014-07-22 23:14:54 -04001650 if (upgradeVersion < 106) {
1651 // LOCK_SCREEN_SHOW_NOTIFICATIONS is now per-user.
1652 db.beginTransaction();
1653 SQLiteStatement stmt = null;
1654 try {
1655 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1656 + " VALUES(?,?);");
Chris Wrencd8f4f72014-08-27 18:48:13 -04001657 loadIntegerSetting(stmt, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
1658 R.integer.def_lock_screen_show_notifications);
Xiaohui Chen43765b72015-08-31 10:57:33 -07001659 if (mUserHandle == UserHandle.USER_SYSTEM) {
Dan Sandler52e5701e2014-07-22 23:14:54 -04001660 final int oldShow = getIntValueFromTable(db,
1661 TABLE_GLOBAL, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, -1);
1662 if (oldShow >= 0) {
1663 // overwrite the default with whatever you had
1664 loadSetting(stmt, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, oldShow);
1665 final SQLiteStatement deleteStmt
1666 = db.compileStatement("DELETE FROM global WHERE name=?");
1667 deleteStmt.bindString(1, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS);
1668 deleteStmt.execute();
1669 }
1670 }
1671 db.setTransactionSuccessful();
1672 } finally {
1673 db.endTransaction();
1674 if (stmt != null) stmt.close();
1675 }
1676 upgradeVersion = 106;
1677 }
Adrian Roos49e057d2014-08-13 17:14:51 +02001678
1679 if (upgradeVersion < 107) {
1680 // Add trusted sound setting
Xiaohui Chen43765b72015-08-31 10:57:33 -07001681 if (mUserHandle == UserHandle.USER_SYSTEM) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001682 db.beginTransaction();
1683 SQLiteStatement stmt = null;
1684 try {
1685 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1686 + " VALUES(?,?);");
1687 loadStringSetting(stmt, Settings.Global.TRUSTED_SOUND,
1688 R.string.def_trusted_sound);
1689 db.setTransactionSuccessful();
1690 } finally {
1691 db.endTransaction();
1692 if (stmt != null) stmt.close();
1693 }
1694 }
1695 upgradeVersion = 107;
1696 }
1697
Jeff Brown49cb6132014-08-20 14:32:38 -07001698 if (upgradeVersion < 108) {
1699 // Reset the auto-brightness setting to default since the behavior
1700 // of the feature is now quite different and is being presented to
1701 // the user in a new way as "adaptive brightness".
1702 db.beginTransaction();
1703 SQLiteStatement stmt = null;
1704 try {
1705 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1706 + " VALUES(?,?);");
1707 loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE,
1708 R.bool.def_screen_brightness_automatic_mode);
1709 db.setTransactionSuccessful();
1710 } finally {
1711 db.endTransaction();
1712 if (stmt != null) stmt.close();
1713 }
1714 upgradeVersion = 108;
1715 }
1716
Chris Wrencd8f4f72014-08-27 18:48:13 -04001717 if (upgradeVersion < 109) {
1718 db.beginTransaction();
1719 SQLiteStatement stmt = null;
1720 try {
1721 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1722 + " VALUES(?,?);");
1723 loadBooleanSetting(stmt, Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
1724 R.bool.def_lock_screen_allow_private_notifications);
1725 db.setTransactionSuccessful();
1726 } finally {
1727 db.endTransaction();
1728 if (stmt != null) stmt.close();
1729 }
1730 upgradeVersion = 109;
1731 }
1732
Tyler Gunn2c830a22014-09-02 08:39:35 -07001733 if (upgradeVersion < 110) {
1734 // The SIP_CALL_OPTIONS value SIP_ASK_EACH_TIME is being deprecated.
1735 // If the SIP_CALL_OPTIONS setting is set to SIP_ASK_EACH_TIME, default to
1736 // SIP_ADDRESS_ONLY.
1737 db.beginTransaction();
1738 SQLiteStatement stmt = null;
1739 try {
1740 stmt = db.compileStatement("UPDATE system SET value = ? " +
1741 "WHERE name = ? AND value = ?;");
1742 stmt.bindString(1, Settings.System.SIP_ADDRESS_ONLY);
1743 stmt.bindString(2, Settings.System.SIP_CALL_OPTIONS);
1744 stmt.bindString(3, Settings.System.SIP_ASK_ME_EACH_TIME);
1745 stmt.execute();
1746 db.setTransactionSuccessful();
1747 } finally {
1748 db.endTransaction();
1749 if (stmt != null) stmt.close();
1750 }
1751 upgradeVersion = 110;
1752 }
1753
John Spurlock7d424b62014-09-09 17:05:54 -04001754 if (upgradeVersion < 111) {
1755 // reset ringer mode, so it doesn't force zen mode to follow
Xiaohui Chen43765b72015-08-31 10:57:33 -07001756 if (mUserHandle == UserHandle.USER_SYSTEM) {
John Spurlock7d424b62014-09-09 17:05:54 -04001757 db.beginTransaction();
1758 SQLiteStatement stmt = null;
1759 try {
1760 stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
1761 + " VALUES(?,?);");
1762 loadSetting(stmt, Settings.Global.MODE_RINGER, AudioManager.RINGER_MODE_NORMAL);
1763 db.setTransactionSuccessful();
1764 } finally {
1765 db.endTransaction();
1766 if (stmt != null) stmt.close();
1767 }
1768 }
1769 upgradeVersion = 111;
1770 }
1771
Jerome Poichet550021e2014-09-11 10:38:12 -07001772 if (upgradeVersion < 112) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001773 if (mUserHandle == UserHandle.USER_SYSTEM) {
Jerome Poichet550021e2014-09-11 10:38:12 -07001774 // When device name was added, we went with Manufacturer + Model, device name should
1775 // actually be Model only.
1776 // Update device name to Model if it wasn't modified by user.
1777 db.beginTransaction();
1778 SQLiteStatement stmt = null;
1779 try {
1780 stmt = db.compileStatement("UPDATE global SET value = ? "
1781 + " WHERE name = ? AND value = ?");
1782 stmt.bindString(1, getDefaultDeviceName()); // new default device name
1783 stmt.bindString(2, Settings.Global.DEVICE_NAME);
1784 stmt.bindString(3, getOldDefaultDeviceName()); // old default device name
1785 stmt.execute();
1786 db.setTransactionSuccessful();
1787 } finally {
1788 db.endTransaction();
1789 if (stmt != null) stmt.close();
1790 }
1791 }
1792 upgradeVersion = 112;
1793 }
1794
Jeff Brown05af6ad2014-09-30 20:54:30 -07001795 if (upgradeVersion < 113) {
1796 db.beginTransaction();
1797 SQLiteStatement stmt = null;
1798 try {
1799 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
1800 + " VALUES(?,?);");
1801 loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT,
1802 R.integer.def_sleep_timeout);
1803 db.setTransactionSuccessful();
1804 } finally {
1805 db.endTransaction();
1806 if (stmt != null) stmt.close();
1807 }
1808 upgradeVersion = 113;
1809 }
1810
Bryce Leefb1cf362014-10-22 16:56:08 -07001811 // We skipped 114 to handle a merge conflict with the introduction of theater mode.
1812
1813 if (upgradeVersion < 115) {
Xiaohui Chen43765b72015-08-31 10:57:33 -07001814 if (mUserHandle == UserHandle.USER_SYSTEM) {
Bryce Leefb1cf362014-10-22 16:56:08 -07001815 db.beginTransaction();
1816 SQLiteStatement stmt = null;
1817 try {
1818 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
1819 + " VALUES(?,?);");
1820 loadBooleanSetting(stmt, Global.THEATER_MODE_ON,
1821 R.bool.def_theater_mode_on);
1822 db.setTransactionSuccessful();
1823 } finally {
1824 db.endTransaction();
1825 if (stmt != null) stmt.close();
1826 }
Bryce Lee584a4452014-10-21 15:55:55 -07001827 }
Bryce Leefb1cf362014-10-22 16:56:08 -07001828 upgradeVersion = 115;
1829 }
1830
1831 if (upgradeVersion < 116) {
manabu, shimoda14723e32017-10-06 14:39:01 +09001832 /*
1833 * To control the default value by carrier config manager, initializing
1834 * ENHANCED_4G_MODE_ENABLED has been removed.
1835 */
Bryce Leefb1cf362014-10-22 16:56:08 -07001836 upgradeVersion = 116;
Libin.Tang@motorola.com0499bb52014-10-10 14:55:57 -05001837 }
Bryce Lee584a4452014-10-21 15:55:55 -07001838
Jason Monk94cfd9d2014-10-31 13:18:21 -04001839 if (upgradeVersion < 117) {
1840 db.beginTransaction();
1841 try {
1842 String[] systemToSecure = {
1843 Settings.Secure.LOCK_TO_APP_EXIT_LOCKED
1844 };
1845 moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, systemToSecure, true);
1846 db.setTransactionSuccessful();
1847 } finally {
1848 db.endTransaction();
1849 }
1850 upgradeVersion = 117;
1851 }
1852
John Spurlock8c51d0b2014-11-07 15:14:21 -05001853 if (upgradeVersion < 118) {
1854 // Reset rotation-lock-for-accessibility on upgrade, since it now hides the display
1855 // setting.
1856 db.beginTransaction();
1857 SQLiteStatement stmt = null;
1858 try {
1859 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
1860 + " VALUES(?,?);");
1861 loadSetting(stmt, Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0);
1862 db.setTransactionSuccessful();
1863 } finally {
1864 db.endTransaction();
1865 if (stmt != null) stmt.close();
1866 }
1867 upgradeVersion = 118;
1868 }
Svetoslav683914b2015-01-15 14:22:26 -08001869
Jeff Brown503cffc2015-03-26 18:08:51 -07001870 /*
Svetoslav683914b2015-01-15 14:22:26 -08001871 * IMPORTANT: Do not add any more upgrade steps here as the global,
1872 * secure, and system settings are no longer stored in a database
Jeff Brown503cffc2015-03-26 18:08:51 -07001873 * but are kept in memory and persisted to XML.
Svetoslav683914b2015-01-15 14:22:26 -08001874 *
Jeff Brown503cffc2015-03-26 18:08:51 -07001875 * See: SettingsProvider.UpgradeController#onUpgradeLocked
Svetoslav683914b2015-01-15 14:22:26 -08001876 */
1877
Daniel Sandler1c7fa482010-03-10 09:45:01 -05001878 if (upgradeVersion != currentVersion) {
Svetoslav683914b2015-01-15 14:22:26 -08001879 recreateDatabase(db, oldVersion, upgradeVersion, currentVersion);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001880 }
1881 }
1882
Svetoslav683914b2015-01-15 14:22:26 -08001883 public void recreateDatabase(SQLiteDatabase db, int oldVersion,
1884 int upgradeVersion, int currentVersion) {
1885 db.execSQL("DROP TABLE IF EXISTS global");
1886 db.execSQL("DROP TABLE IF EXISTS globalIndex1");
1887 db.execSQL("DROP TABLE IF EXISTS system");
1888 db.execSQL("DROP INDEX IF EXISTS systemIndex1");
1889 db.execSQL("DROP TABLE IF EXISTS secure");
1890 db.execSQL("DROP INDEX IF EXISTS secureIndex1");
1891 db.execSQL("DROP TABLE IF EXISTS gservices");
1892 db.execSQL("DROP INDEX IF EXISTS gservicesIndex1");
1893 db.execSQL("DROP TABLE IF EXISTS bluetooth_devices");
1894 db.execSQL("DROP TABLE IF EXISTS bookmarks");
1895 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex1");
1896 db.execSQL("DROP INDEX IF EXISTS bookmarksIndex2");
1897 db.execSQL("DROP TABLE IF EXISTS favorites");
1898
1899 onCreate(db);
1900
1901 // Added for diagnosing settings.db wipes after the fact
1902 String wipeReason = oldVersion + "/" + upgradeVersion + "/" + currentVersion;
1903 db.execSQL("INSERT INTO secure(name,value) values('" +
1904 "wiped_db_reason" + "','" + wipeReason + "');");
1905 }
1906
1907 private String[] setToStringArray(Set<String> set) {
Christopher Tatea96798e42012-09-06 19:07:19 -07001908 String[] array = new String[set.size()];
1909 return set.toArray(array);
1910 }
1911
Christopher Tate06efb532012-08-24 15:29:27 -07001912 private void moveSettingsToNewTable(SQLiteDatabase db,
1913 String sourceTable, String destTable,
Christopher Tate92198742012-09-07 12:00:13 -07001914 String[] settingsToMove, boolean doIgnore) {
Christopher Tate06efb532012-08-24 15:29:27 -07001915 // Copy settings values from the source table to the dest, and remove from the source
Amith Yamasani156c4352010-03-05 17:10:03 -08001916 SQLiteStatement insertStmt = null;
1917 SQLiteStatement deleteStmt = null;
1918
1919 db.beginTransaction();
1920 try {
Christopher Tate92198742012-09-07 12:00:13 -07001921 insertStmt = db.compileStatement("INSERT "
1922 + (doIgnore ? " OR IGNORE " : "")
1923 + " INTO " + destTable + " (name,value) SELECT name,value FROM "
Christopher Tate06efb532012-08-24 15:29:27 -07001924 + sourceTable + " WHERE name=?");
1925 deleteStmt = db.compileStatement("DELETE FROM " + sourceTable + " WHERE name=?");
Amith Yamasani156c4352010-03-05 17:10:03 -08001926
1927 for (String setting : settingsToMove) {
1928 insertStmt.bindString(1, setting);
1929 insertStmt.execute();
1930
1931 deleteStmt.bindString(1, setting);
1932 deleteStmt.execute();
1933 }
1934 db.setTransactionSuccessful();
1935 } finally {
1936 db.endTransaction();
1937 if (insertStmt != null) {
1938 insertStmt.close();
1939 }
1940 if (deleteStmt != null) {
1941 deleteStmt.close();
1942 }
1943 }
1944 }
1945
Jeff Sharkey0ac10282012-10-01 12:50:22 -07001946 /**
1947 * Move any settings with the given prefixes from the source table to the
1948 * destination table.
1949 */
1950 private void movePrefixedSettingsToNewTable(
1951 SQLiteDatabase db, String sourceTable, String destTable, String[] prefixesToMove) {
1952 SQLiteStatement insertStmt = null;
1953 SQLiteStatement deleteStmt = null;
1954
1955 db.beginTransaction();
1956 try {
1957 insertStmt = db.compileStatement("INSERT INTO " + destTable
1958 + " (name,value) SELECT name,value FROM " + sourceTable
1959 + " WHERE substr(name,0,?)=?");
1960 deleteStmt = db.compileStatement(
1961 "DELETE FROM " + sourceTable + " WHERE substr(name,0,?)=?");
1962
1963 for (String prefix : prefixesToMove) {
1964 insertStmt.bindLong(1, prefix.length() + 1);
1965 insertStmt.bindString(2, prefix);
1966 insertStmt.execute();
1967
1968 deleteStmt.bindLong(1, prefix.length() + 1);
1969 deleteStmt.bindString(2, prefix);
1970 deleteStmt.execute();
1971 }
1972 db.setTransactionSuccessful();
1973 } finally {
1974 db.endTransaction();
1975 if (insertStmt != null) {
1976 insertStmt.close();
1977 }
1978 if (deleteStmt != null) {
1979 deleteStmt.close();
1980 }
1981 }
1982 }
1983
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001984 private void upgradeLockPatternLocation(SQLiteDatabase db) {
Christopher Tate06efb532012-08-24 15:29:27 -07001985 Cursor c = db.query(TABLE_SYSTEM, new String[] {"_id", "value"}, "name='lock_pattern'",
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001986 null, null, null, null);
1987 if (c.getCount() > 0) {
1988 c.moveToFirst();
1989 String lockPattern = c.getString(1);
1990 if (!TextUtils.isEmpty(lockPattern)) {
1991 // Convert lock pattern
1992 try {
Jim Miller31f90b62010-01-20 13:35:20 -08001993 LockPatternUtils lpu = new LockPatternUtils(mContext);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07001994 List<LockPatternView.Cell> cellPattern =
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001995 LockPatternUtils.stringToPattern(lockPattern);
Xiaohui Chen43765b72015-08-31 10:57:33 -07001996 lpu.saveLockPattern(cellPattern, null, UserHandle.USER_SYSTEM);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001997 } catch (IllegalArgumentException e) {
1998 // Don't want corrupted lock pattern to hang the reboot process
1999 }
2000 }
2001 c.close();
Christopher Tate06efb532012-08-24 15:29:27 -07002002 db.delete(TABLE_SYSTEM, "name='lock_pattern'", null);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002003 } else {
2004 c.close();
2005 }
2006 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002007
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07002008 private void upgradeScreenTimeoutFromNever(SQLiteDatabase db) {
2009 // See if the timeout is -1 (for "Never").
Christopher Tate06efb532012-08-24 15:29:27 -07002010 Cursor c = db.query(TABLE_SYSTEM, new String[] { "_id", "value" }, "name=? AND value=?",
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07002011 new String[] { Settings.System.SCREEN_OFF_TIMEOUT, "-1" },
2012 null, null, null);
2013
2014 SQLiteStatement stmt = null;
2015 if (c.getCount() > 0) {
2016 c.close();
2017 try {
2018 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
2019 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002020
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07002021 // Set the timeout to 30 minutes in milliseconds
Amith Yamasanicd66caf2010-04-12 15:49:12 -07002022 loadSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
2023 Integer.toString(30 * 60 * 1000));
Amith Yamasanib6e6ffa2010-03-29 17:58:53 -07002024 } finally {
2025 if (stmt != null) stmt.close();
2026 }
2027 } else {
2028 c.close();
2029 }
2030 }
2031
Amith Yamasani398c83c2011-12-13 10:38:47 -08002032 private void upgradeVibrateSettingFromNone(SQLiteDatabase db) {
2033 int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON, 0);
2034 // If the ringer vibrate value is invalid, set it to the default
2035 if ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_OFF) {
John Spurlock61560172015-02-06 19:46:04 -05002036 vibrateSetting = AudioSystem.getValueForVibrateSetting(0,
Amith Yamasani398c83c2011-12-13 10:38:47 -08002037 AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
2038 }
2039 // Apply the same setting to the notification vibrate value
John Spurlock61560172015-02-06 19:46:04 -05002040 vibrateSetting = AudioSystem.getValueForVibrateSetting(vibrateSetting,
Amith Yamasani398c83c2011-12-13 10:38:47 -08002041 AudioManager.VIBRATE_TYPE_NOTIFICATION, vibrateSetting);
2042
2043 SQLiteStatement stmt = null;
2044 try {
2045 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
2046 + " VALUES(?,?);");
2047 loadSetting(stmt, Settings.System.VIBRATE_ON, vibrateSetting);
2048 } finally {
2049 if (stmt != null)
2050 stmt.close();
2051 }
2052 }
2053
Amith Yamasani79373f62010-11-18 16:32:48 -08002054 private void upgradeScreenTimeout(SQLiteDatabase db) {
2055 // Change screen timeout to current default
2056 db.beginTransaction();
2057 SQLiteStatement stmt = null;
2058 try {
2059 stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
2060 + " VALUES(?,?);");
2061 loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
2062 R.integer.def_screen_off_timeout);
2063 db.setTransactionSuccessful();
2064 } finally {
2065 db.endTransaction();
2066 if (stmt != null)
2067 stmt.close();
2068 }
2069 }
2070
Amith Yamasanif50c5112011-01-07 11:32:30 -08002071 private void upgradeAutoBrightness(SQLiteDatabase db) {
2072 db.beginTransaction();
2073 try {
2074 String value =
2075 mContext.getResources().getBoolean(
2076 R.bool.def_screen_brightness_automatic_mode) ? "1" : "0";
2077 db.execSQL("INSERT OR REPLACE INTO system(name,value) values('" +
2078 Settings.System.SCREEN_BRIGHTNESS_MODE + "','" + value + "');");
2079 db.setTransactionSuccessful();
2080 } finally {
2081 db.endTransaction();
2082 }
2083 }
2084
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002085 /**
2086 * Loads the default set of bookmarked shortcuts from an xml file.
2087 *
2088 * @param db The database to write the values into
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002089 */
Jeff Brown6651a632011-11-28 12:59:11 -08002090 private void loadBookmarks(SQLiteDatabase db) {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002091 ContentValues values = new ContentValues();
2092
2093 PackageManager packageManager = mContext.getPackageManager();
Romain Guyf02811f2010-03-09 16:33:51 -08002094 try {
2095 XmlResourceParser parser = mContext.getResources().getXml(R.xml.bookmarks);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002096 XmlUtils.beginDocument(parser, "bookmarks");
2097
Romain Guyf02811f2010-03-09 16:33:51 -08002098 final int depth = parser.getDepth();
2099 int type;
2100
2101 while (((type = parser.next()) != XmlPullParser.END_TAG ||
2102 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
2103
2104 if (type != XmlPullParser.START_TAG) {
2105 continue;
2106 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002107
2108 String name = parser.getName();
2109 if (!"bookmark".equals(name)) {
2110 break;
2111 }
2112
2113 String pkg = parser.getAttributeValue(null, "package");
2114 String cls = parser.getAttributeValue(null, "class");
2115 String shortcutStr = parser.getAttributeValue(null, "shortcut");
Jeff Brown6651a632011-11-28 12:59:11 -08002116 String category = parser.getAttributeValue(null, "category");
Romain Guyf02811f2010-03-09 16:33:51 -08002117
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -07002118 int shortcutValue = shortcutStr.charAt(0);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002119 if (TextUtils.isEmpty(shortcutStr)) {
2120 Log.w(TAG, "Unable to get shortcut for: " + pkg + "/" + cls);
Jeff Brown6651a632011-11-28 12:59:11 -08002121 continue;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002122 }
Romain Guyf02811f2010-03-09 16:33:51 -08002123
Jeff Brown6651a632011-11-28 12:59:11 -08002124 final Intent intent;
2125 final String title;
2126 if (pkg != null && cls != null) {
2127 ActivityInfo info = null;
2128 ComponentName cn = new ComponentName(pkg, cls);
Romain Guyf02811f2010-03-09 16:33:51 -08002129 try {
2130 info = packageManager.getActivityInfo(cn, 0);
Jeff Brown6651a632011-11-28 12:59:11 -08002131 } catch (PackageManager.NameNotFoundException e) {
2132 String[] packages = packageManager.canonicalToCurrentPackageNames(
2133 new String[] { pkg });
2134 cn = new ComponentName(packages[0], cls);
2135 try {
2136 info = packageManager.getActivityInfo(cn, 0);
2137 } catch (PackageManager.NameNotFoundException e1) {
2138 Log.w(TAG, "Unable to add bookmark: " + pkg + "/" + cls, e);
2139 continue;
2140 }
Romain Guyf02811f2010-03-09 16:33:51 -08002141 }
Jeff Brown6651a632011-11-28 12:59:11 -08002142
2143 intent = new Intent(Intent.ACTION_MAIN, null);
2144 intent.addCategory(Intent.CATEGORY_LAUNCHER);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002145 intent.setComponent(cn);
Jeff Brown6651a632011-11-28 12:59:11 -08002146 title = info.loadLabel(packageManager).toString();
2147 } else if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002148 intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002149 title = "";
2150 } else {
2151 Log.w(TAG, "Unable to add bookmark for shortcut " + shortcutStr
2152 + ": missing package/class or category attributes");
2153 continue;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002154 }
Jeff Brown6651a632011-11-28 12:59:11 -08002155
2156 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2157 values.put(Settings.Bookmarks.INTENT, intent.toUri(0));
2158 values.put(Settings.Bookmarks.TITLE, title);
2159 values.put(Settings.Bookmarks.SHORTCUT, shortcutValue);
2160 db.delete("bookmarks", "shortcut = ?",
2161 new String[] { Integer.toString(shortcutValue) });
2162 db.insert("bookmarks", null, values);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002163 }
2164 } catch (XmlPullParserException e) {
2165 Log.w(TAG, "Got execption parsing bookmarks.", e);
2166 } catch (IOException e) {
2167 Log.w(TAG, "Got execption parsing bookmarks.", e);
2168 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002169 }
2170
2171 /**
2172 * Loads the default volume levels. It is actually inserting the index of
2173 * the volume array for each of the volume controls.
2174 *
2175 * @param db the database to insert the volume levels into
2176 */
2177 private void loadVolumeLevels(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07002178 SQLiteStatement stmt = null;
2179 try {
2180 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
2181 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002182
Vasu Nori89206fdb2010-03-22 10:37:03 -07002183 loadSetting(stmt, Settings.System.VOLUME_MUSIC,
John Spurlock61560172015-02-06 19:46:04 -05002184 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_MUSIC));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002185 loadSetting(stmt, Settings.System.VOLUME_RING,
John Spurlock61560172015-02-06 19:46:04 -05002186 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_RING));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002187 loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
John Spurlock61560172015-02-06 19:46:04 -05002188 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_SYSTEM));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002189 loadSetting(
2190 stmt,
2191 Settings.System.VOLUME_VOICE,
John Spurlock61560172015-02-06 19:46:04 -05002192 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_VOICE_CALL));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002193 loadSetting(stmt, Settings.System.VOLUME_ALARM,
John Spurlock61560172015-02-06 19:46:04 -05002194 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_ALARM));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002195 loadSetting(
2196 stmt,
2197 Settings.System.VOLUME_NOTIFICATION,
John Spurlock61560172015-02-06 19:46:04 -05002198 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_NOTIFICATION));
Vasu Nori89206fdb2010-03-22 10:37:03 -07002199 loadSetting(
2200 stmt,
2201 Settings.System.VOLUME_BLUETOOTH_SCO,
John Spurlock61560172015-02-06 19:46:04 -05002202 AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002203
Eric Laurentc1d41662011-07-19 11:21:13 -07002204 // By default:
2205 // - ringtones, notification, system and music streams are affected by ringer mode
2206 // on non voice capable devices (tablets)
2207 // - ringtones, notification and system streams are affected by ringer mode
2208 // on voice capable devices (phones)
2209 int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
2210 (1 << AudioManager.STREAM_NOTIFICATION) |
2211 (1 << AudioManager.STREAM_SYSTEM) |
2212 (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
2213 if (!mContext.getResources().getBoolean(
2214 com.android.internal.R.bool.config_voice_capable)) {
2215 ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
2216 }
Vasu Nori89206fdb2010-03-22 10:37:03 -07002217 loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
Eric Laurentc1d41662011-07-19 11:21:13 -07002218 ringerModeAffectedStreams);
2219
Vasu Nori89206fdb2010-03-22 10:37:03 -07002220 loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
John Spurlock61560172015-02-06 19:46:04 -05002221 AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED);
Vasu Nori89206fdb2010-03-22 10:37:03 -07002222 } finally {
2223 if (stmt != null) stmt.close();
2224 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002225 }
2226
2227 private void loadVibrateSetting(SQLiteDatabase db, boolean deleteOld) {
2228 if (deleteOld) {
2229 db.execSQL("DELETE FROM system WHERE name='" + Settings.System.VIBRATE_ON + "'");
2230 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002231
Vasu Nori89206fdb2010-03-22 10:37:03 -07002232 SQLiteStatement stmt = null;
2233 try {
2234 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
2235 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002236
Amith Yamasani5cd15002011-11-16 11:19:48 -08002237 // Vibrate on by default for ringer, on for notification
Vasu Nori89206fdb2010-03-22 10:37:03 -07002238 int vibrate = 0;
John Spurlock61560172015-02-06 19:46:04 -05002239 vibrate = AudioSystem.getValueForVibrateSetting(vibrate,
Amith Yamasani5cd15002011-11-16 11:19:48 -08002240 AudioManager.VIBRATE_TYPE_NOTIFICATION,
2241 AudioManager.VIBRATE_SETTING_ONLY_SILENT);
John Spurlock61560172015-02-06 19:46:04 -05002242 vibrate |= AudioSystem.getValueForVibrateSetting(vibrate,
Amith Yamasani5cd15002011-11-16 11:19:48 -08002243 AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
Vasu Nori89206fdb2010-03-22 10:37:03 -07002244 loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate);
2245 } finally {
2246 if (stmt != null) stmt.close();
2247 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002248 }
2249
2250 private void loadSettings(SQLiteDatabase db) {
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002251 loadSystemSettings(db);
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002252 loadSecureSettings(db);
Xiaohui Chen43765b72015-08-31 10:57:33 -07002253 // The global table only exists for the 'owner/system' user
2254 if (mUserHandle == UserHandle.USER_SYSTEM) {
Christopher Tate06efb532012-08-24 15:29:27 -07002255 loadGlobalSettings(db);
2256 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002257 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002258
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002259 private void loadSystemSettings(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07002260 SQLiteStatement stmt = null;
2261 try {
2262 stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
2263 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002264
Vasu Nori89206fdb2010-03-22 10:37:03 -07002265 loadBooleanSetting(stmt, Settings.System.DIM_SCREEN,
2266 R.bool.def_dim_screen);
Vasu Nori89206fdb2010-03-22 10:37:03 -07002267 loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
2268 R.integer.def_screen_off_timeout);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002269
Vasu Nori89206fdb2010-03-22 10:37:03 -07002270 // Set default cdma DTMF type
2271 loadSetting(stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002272
Vasu Nori89206fdb2010-03-22 10:37:03 -07002273 // Set default hearing aid
2274 loadSetting(stmt, Settings.System.HEARING_AID, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002275
Vasu Nori89206fdb2010-03-22 10:37:03 -07002276 // Set default tty mode
2277 loadSetting(stmt, Settings.System.TTY_MODE, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002278
Vasu Nori89206fdb2010-03-22 10:37:03 -07002279 loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS,
2280 R.integer.def_screen_brightness);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002281
Santos Cordon5177da32018-02-07 14:03:14 -08002282 loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_FOR_VR,
2283 com.android.internal.R.integer.config_screenBrightnessForVrSettingDefault);
2284
Vasu Nori89206fdb2010-03-22 10:37:03 -07002285 loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE,
2286 R.bool.def_screen_brightness_automatic_mode);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002287
Vasu Nori89206fdb2010-03-22 10:37:03 -07002288 loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION,
2289 R.bool.def_accelerometer_rotation);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002290
Vasu Nori89206fdb2010-03-22 10:37:03 -07002291 loadDefaultHapticSettings(stmt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002292
Vasu Nori89206fdb2010-03-22 10:37:03 -07002293 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
2294 R.bool.def_notification_pulse);
Amith Yamasani42722bf2011-07-22 10:34:27 -07002295
Vasu Nori89206fdb2010-03-22 10:37:03 -07002296 loadUISoundEffectsSettings(stmt);
Amith Yamasani42722bf2011-07-22 10:34:27 -07002297
Jeff Brown1a84fd12011-06-02 01:26:32 -07002298 loadIntegerSetting(stmt, Settings.System.POINTER_SPEED,
2299 R.integer.def_pointer_speed);
Jeff Brown503cffc2015-03-26 18:08:51 -07002300
2301 /*
2302 * IMPORTANT: Do not add any more upgrade steps here as the global,
2303 * secure, and system settings are no longer stored in a database
2304 * but are kept in memory and persisted to XML.
2305 *
2306 * See: SettingsProvider.UpgradeController#onUpgradeLocked
2307 */
Vasu Nori89206fdb2010-03-22 10:37:03 -07002308 } finally {
2309 if (stmt != null) stmt.close();
2310 }
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002311 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002312
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002313 private void loadUISoundEffectsSettings(SQLiteStatement stmt) {
Amith Yamasani42722bf2011-07-22 10:34:27 -07002314 loadBooleanSetting(stmt, Settings.System.DTMF_TONE_WHEN_DIALING,
2315 R.bool.def_dtmf_tones_enabled);
2316 loadBooleanSetting(stmt, Settings.System.SOUND_EFFECTS_ENABLED,
2317 R.bool.def_sound_effects_enabled);
2318 loadBooleanSetting(stmt, Settings.System.HAPTIC_FEEDBACK_ENABLED,
2319 R.bool.def_haptic_feedback);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002320
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002321 loadIntegerSetting(stmt, Settings.System.LOCKSCREEN_SOUNDS_ENABLED,
2322 R.integer.def_lockscreen_sounds_enabled);
Daniel Sandler0e9d2af2010-01-25 11:33:03 -05002323 }
2324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 private void loadDefaultAnimationSettings(SQLiteStatement stmt) {
2326 loadFractionSetting(stmt, Settings.System.WINDOW_ANIMATION_SCALE,
2327 R.fraction.def_window_animation_scale, 1);
2328 loadFractionSetting(stmt, Settings.System.TRANSITION_ANIMATION_SCALE,
2329 R.fraction.def_window_transition_scale, 1);
2330 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002331
Dianne Hackborn075a18d2009-09-26 12:43:19 -07002332 private void loadDefaultHapticSettings(SQLiteStatement stmt) {
2333 loadBooleanSetting(stmt, Settings.System.HAPTIC_FEEDBACK_ENABLED,
2334 R.bool.def_haptic_feedback);
2335 }
2336
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -08002337 private void loadSecureSettings(SQLiteDatabase db) {
Vasu Nori89206fdb2010-03-22 10:37:03 -07002338 SQLiteStatement stmt = null;
2339 try {
2340 stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
2341 + " VALUES(?,?);");
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002342
Vasu Nori89206fdb2010-03-22 10:37:03 -07002343 // Don't do this. The SystemServer will initialize ADB_ENABLED from a
2344 // persistent system property instead.
2345 //loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002346
Vasu Nori89206fdb2010-03-22 10:37:03 -07002347 // Allow mock locations default, based on build
2348 loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION,
2349 "1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002350
Vasu Nori89206fdb2010-03-22 10:37:03 -07002351 loadSecure35Settings(stmt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002352
Vasu Nori89206fdb2010-03-22 10:37:03 -07002353 loadBooleanSetting(stmt, Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND,
2354 R.bool.def_mount_play_notification_snd);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002355
Vasu Nori89206fdb2010-03-22 10:37:03 -07002356 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_AUTOSTART,
2357 R.bool.def_mount_ums_autostart);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002358
Vasu Nori89206fdb2010-03-22 10:37:03 -07002359 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_PROMPT,
2360 R.bool.def_mount_ums_prompt);
Daisuke Miyakawa3c60eeb2012-05-08 12:08:25 -07002361
Vasu Nori89206fdb2010-03-22 10:37:03 -07002362 loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED,
2363 R.bool.def_mount_ums_notify_enabled);
Svetoslav Ganov585f13f8d2010-08-10 07:59:15 -07002364
Svetoslav Ganov54d068e2011-03-02 12:58:40 -08002365 loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT,
2366 R.integer.def_long_press_timeout_millis);
Svetoslav Ganova28a16d2011-07-28 11:24:21 -07002367
2368 loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED,
2369 R.bool.def_touch_exploration_enabled);
Svetoslav Ganov55f937a2011-12-05 11:42:07 -08002370
2371 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD,
2372 R.bool.def_accessibility_speak_password);
Svetoslav Ganov3ca5a742011-12-06 15:24:37 -08002373
Amith Yamasanid1645f82012-06-12 11:53:26 -07002374 if (SystemProperties.getBoolean("ro.lockscreen.disable.default", false) == true) {
2375 loadSetting(stmt, Settings.System.LOCKSCREEN_DISABLED, "1");
2376 } else {
2377 loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED,
2378 R.bool.def_lockscreen_disabled);
2379 }
Mike Lockwood23955272011-10-21 11:22:48 -04002380
John Spurlock634471e2012-08-09 10:41:37 -04002381 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED,
John Spurlocked108f32012-10-18 16:49:24 -04002382 com.android.internal.R.bool.config_dreamsEnabledByDefault);
John Spurlock634471e2012-08-09 10:41:37 -04002383 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
John Spurlocked108f32012-10-18 16:49:24 -04002384 com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04002385 loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
John Spurlocked108f32012-10-18 16:49:24 -04002386 com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault);
John Spurlock1a868b72012-08-22 09:56:51 -04002387 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_COMPONENTS,
John Spurlocked108f32012-10-18 16:49:24 -04002388 com.android.internal.R.string.config_dreamsDefaultComponent);
John Spurlock1a868b72012-08-22 09:56:51 -04002389 loadStringSetting(stmt, Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT,
John Spurlocked108f32012-10-18 16:49:24 -04002390 com.android.internal.R.string.config_dreamsDefaultComponent);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07002391
2392 loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
2393 R.bool.def_accessibility_display_magnification_enabled);
2394
2395 loadFractionSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
2396 R.fraction.def_accessibility_display_magnification_scale, 1);
2397
John Spurlock7f1c2482012-10-05 11:15:28 -04002398 loadBooleanSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE,
2399 R.bool.def_user_setup_complete);
Mike Lockwoodc02c4a72014-01-07 14:46:22 -08002400
2401 loadStringSetting(stmt, Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS,
2402 R.string.def_immersive_mode_confirmations);
2403
Christopher Tateaa036a22014-05-19 16:33:27 -07002404 loadBooleanSetting(stmt, Settings.Secure.INSTALL_NON_MARKET_APPS,
2405 R.bool.def_install_non_market_apps);
2406
Jeff Browna20dda42014-05-27 20:57:24 -07002407 loadBooleanSetting(stmt, Settings.Secure.WAKE_GESTURE_ENABLED,
2408 R.bool.def_wake_gesture_enabled);
2409
Dan Sandler52e5701e2014-07-22 23:14:54 -04002410 loadIntegerSetting(stmt, Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
2411 R.integer.def_lock_screen_show_notifications);
2412
Chris Wrencd8f4f72014-08-27 18:48:13 -04002413 loadBooleanSetting(stmt, Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
2414 R.bool.def_lock_screen_allow_private_notifications);
2415
Jeff Brown05af6ad2014-09-30 20:54:30 -07002416 loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT,
2417 R.integer.def_sleep_timeout);
Jeff Brown503cffc2015-03-26 18:08:51 -07002418
2419 /*
2420 * IMPORTANT: Do not add any more upgrade steps here as the global,
2421 * secure, and system settings are no longer stored in a database
2422 * but are kept in memory and persisted to XML.
2423 *
2424 * See: SettingsProvider.UpgradeController#onUpgradeLocked
2425 */
Vasu Nori89206fdb2010-03-22 10:37:03 -07002426 } finally {
2427 if (stmt != null) stmt.close();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002429 }
2430
Dianne Hackborncf098292009-07-01 19:55:20 -07002431 private void loadSecure35Settings(SQLiteStatement stmt) {
2432 loadBooleanSetting(stmt, Settings.Secure.BACKUP_ENABLED,
2433 R.bool.def_backup_enabled);
Jim Miller31f90b62010-01-20 13:35:20 -08002434
Dianne Hackborncf098292009-07-01 19:55:20 -07002435 loadStringSetting(stmt, Settings.Secure.BACKUP_TRANSPORT,
2436 R.string.def_backup_transport);
2437 }
Jim Miller61766772010-02-12 14:56:49 -08002438
Christopher Tate06efb532012-08-24 15:29:27 -07002439 private void loadGlobalSettings(SQLiteDatabase db) {
2440 SQLiteStatement stmt = null;
Edward Savage-Jonesce7a01f2015-12-09 21:16:50 +01002441 final Resources res = mContext.getResources();
Christopher Tate06efb532012-08-24 15:29:27 -07002442 try {
2443 stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
2444 + " VALUES(?,?);");
2445
2446 // --- Previously in 'system'
2447 loadBooleanSetting(stmt, Settings.Global.AIRPLANE_MODE_ON,
2448 R.bool.def_airplane_mode_on);
2449
Bryce Lee584a4452014-10-21 15:55:55 -07002450 loadBooleanSetting(stmt, Settings.Global.THEATER_MODE_ON,
2451 R.bool.def_theater_mode_on);
2452
Christopher Tate06efb532012-08-24 15:29:27 -07002453 loadStringSetting(stmt, Settings.Global.AIRPLANE_MODE_RADIOS,
2454 R.string.def_airplane_mode_radios);
2455
2456 loadStringSetting(stmt, Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
2457 R.string.airplane_mode_toggleable_radios);
2458
2459 loadBooleanSetting(stmt, Settings.Global.ASSISTED_GPS_ENABLED,
2460 R.bool.assisted_gps_enabled);
2461
2462 loadBooleanSetting(stmt, Settings.Global.AUTO_TIME,
2463 R.bool.def_auto_time); // Sync time to NITZ
2464
2465 loadBooleanSetting(stmt, Settings.Global.AUTO_TIME_ZONE,
2466 R.bool.def_auto_time_zone); // Sync timezone to NITZ
2467
2468 loadSetting(stmt, Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
2469 ("1".equals(SystemProperties.get("ro.kernel.qemu")) ||
Edward Savage-Jonesce7a01f2015-12-09 21:16:50 +01002470 res.getBoolean(R.bool.def_stay_on_while_plugged_in))
Christopher Tate06efb532012-08-24 15:29:27 -07002471 ? 1 : 0);
2472
2473 loadIntegerSetting(stmt, Settings.Global.WIFI_SLEEP_POLICY,
2474 R.integer.def_wifi_sleep_policy);
2475
Eric Laurent55b02222012-10-03 11:56:23 -07002476 loadSetting(stmt, Settings.Global.MODE_RINGER,
2477 AudioManager.RINGER_MODE_NORMAL);
2478
Terry Heo86e76782017-06-12 18:39:48 +09002479 loadDefaultAnimationSettings(stmt);
2480
Christopher Tate06efb532012-08-24 15:29:27 -07002481 // --- Previously in 'secure'
Christopher Tate6f5a9a92012-09-14 17:24:28 -07002482 loadBooleanSetting(stmt, Settings.Global.PACKAGE_VERIFIER_ENABLE,
2483 R.bool.def_package_verifier_enable);
2484
2485 loadBooleanSetting(stmt, Settings.Global.WIFI_ON,
2486 R.bool.def_wifi_on);
2487
2488 loadBooleanSetting(stmt, Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
2489 R.bool.def_networks_available_notification_on);
2490
Christopher Tate06efb532012-08-24 15:29:27 -07002491 loadBooleanSetting(stmt, Settings.Global.BLUETOOTH_ON,
2492 R.bool.def_bluetooth_on);
2493
2494 // Enable or disable Cell Broadcast SMS
2495 loadSetting(stmt, Settings.Global.CDMA_CELL_BROADCAST_SMS,
2496 RILConstants.CDMA_CELL_BROADCAST_SMS_DISABLED);
2497
2498 // Data roaming default, based on build
2499 loadSetting(stmt, Settings.Global.DATA_ROAMING,
2500 "true".equalsIgnoreCase(
2501 SystemProperties.get("ro.com.android.dataroaming",
2502 "false")) ? 1 : 0);
2503
2504 loadBooleanSetting(stmt, Settings.Global.DEVICE_PROVISIONED,
2505 R.bool.def_device_provisioned);
2506
Edward Savage-Jonesce7a01f2015-12-09 21:16:50 +01002507 final int maxBytes = res.getInteger(
Christopher Tate06efb532012-08-24 15:29:27 -07002508 R.integer.def_download_manager_max_bytes_over_mobile);
2509 if (maxBytes > 0) {
2510 loadSetting(stmt, Settings.Global.DOWNLOAD_MAX_BYTES_OVER_MOBILE,
2511 Integer.toString(maxBytes));
2512 }
2513
Edward Savage-Jonesce7a01f2015-12-09 21:16:50 +01002514 final int recommendedMaxBytes = res.getInteger(
Christopher Tate06efb532012-08-24 15:29:27 -07002515 R.integer.def_download_manager_recommended_max_bytes_over_mobile);
2516 if (recommendedMaxBytes > 0) {
2517 loadSetting(stmt, Settings.Global.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE,
2518 Integer.toString(recommendedMaxBytes));
2519 }
2520
2521 // Mobile Data default, based on build
2522 loadSetting(stmt, Settings.Global.MOBILE_DATA,
2523 "true".equalsIgnoreCase(
2524 SystemProperties.get("ro.com.android.mobiledata",
2525 "true")) ? 1 : 0);
2526
2527 loadBooleanSetting(stmt, Settings.Global.NETSTATS_ENABLED,
2528 R.bool.def_netstats_enabled);
2529
Christopher Tate06efb532012-08-24 15:29:27 -07002530 loadBooleanSetting(stmt, Settings.Global.USB_MASS_STORAGE_ENABLED,
2531 R.bool.def_usb_mass_storage_enabled);
2532
2533 loadIntegerSetting(stmt, Settings.Global.WIFI_MAX_DHCP_RETRY_COUNT,
2534 R.integer.def_max_dhcp_retries);
2535
Jeff Brown89d55462012-09-19 11:33:42 -07002536 loadBooleanSetting(stmt, Settings.Global.WIFI_DISPLAY_ON,
2537 R.bool.def_wifi_display_on);
2538
Jim Millerb14288d2012-09-30 18:25:05 -07002539 loadStringSetting(stmt, Settings.Global.LOCK_SOUND,
2540 R.string.def_lock_sound);
Jim Millerb14288d2012-09-30 18:25:05 -07002541 loadStringSetting(stmt, Settings.Global.UNLOCK_SOUND,
2542 R.string.def_unlock_sound);
Adrian Roos49e057d2014-08-13 17:14:51 +02002543 loadStringSetting(stmt, Settings.Global.TRUSTED_SOUND,
2544 R.string.def_trusted_sound);
Amith Yamasani531c2372012-10-08 14:43:20 -07002545 loadIntegerSetting(stmt, Settings.Global.POWER_SOUNDS_ENABLED,
2546 R.integer.def_power_sounds_enabled);
2547 loadStringSetting(stmt, Settings.Global.LOW_BATTERY_SOUND,
2548 R.string.def_low_battery_sound);
2549 loadIntegerSetting(stmt, Settings.Global.DOCK_SOUNDS_ENABLED,
2550 R.integer.def_dock_sounds_enabled);
Vinod Krishnancf11cea2016-10-20 22:57:02 -07002551 loadIntegerSetting(stmt, Settings.Global.DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY,
2552 R.integer.def_dock_sounds_enabled_when_accessibility);
Amith Yamasani531c2372012-10-08 14:43:20 -07002553 loadStringSetting(stmt, Settings.Global.DESK_DOCK_SOUND,
2554 R.string.def_desk_dock_sound);
2555 loadStringSetting(stmt, Settings.Global.DESK_UNDOCK_SOUND,
2556 R.string.def_desk_undock_sound);
2557 loadStringSetting(stmt, Settings.Global.CAR_DOCK_SOUND,
2558 R.string.def_car_dock_sound);
2559 loadStringSetting(stmt, Settings.Global.CAR_UNDOCK_SOUND,
2560 R.string.def_car_undock_sound);
Beverlyc1313eb2018-01-31 18:07:21 -05002561 loadStringSetting(stmt, Settings.Global.CHARGING_STARTED_SOUND,
Jeff Brown84e27562012-12-07 13:56:34 -08002562 R.string.def_wireless_charging_started_sound);
Jim Millerb14288d2012-09-30 18:25:05 -07002563
Dmytro Dubovyk729f6682012-12-18 18:07:50 +02002564 loadIntegerSetting(stmt, Settings.Global.DOCK_AUDIO_MEDIA_ENABLED,
2565 R.integer.def_dock_audio_media_enabled);
2566
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07002567 loadSetting(stmt, Settings.Global.SET_INSTALL_LOCATION, 0);
2568 loadSetting(stmt, Settings.Global.DEFAULT_INSTALL_LOCATION,
2569 PackageHelper.APP_INSTALL_AUTO);
2570
2571 // Set default cdma emergency tone
2572 loadSetting(stmt, Settings.Global.EMERGENCY_TONE, 0);
2573
2574 // Set default cdma call auto retry
2575 loadSetting(stmt, Settings.Global.CALL_AUTO_RETRY, 0);
2576
Naveen Kalla97ecc9e2012-07-13 20:10:22 -07002577 // Set the preferred network mode to target desired value or Default
Sandeep Gutta2a7c0d32016-03-16 21:37:25 +05302578 // value defined in system property
2579 String val = "";
2580 String mode;
2581 for (int phoneId = 0;
2582 phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
2583 mode = TelephonyManager.getTelephonyProperty(phoneId,
2584 "ro.telephony.default_network",
2585 Integer.toString(RILConstants.PREFERRED_NETWORK_MODE));
2586 if (phoneId == 0) {
2587 val = mode;
2588 } else {
2589 val = val + "," + mode;
2590 }
2591 }
2592 loadSetting(stmt, Settings.Global.PREFERRED_NETWORK_MODE, val);
Jeff Sharkey6e2bee72012-10-01 13:39:08 -07002593
Naveen Kallab4d485c2013-07-03 16:39:27 -07002594 // Set the preferred cdma subscription source to target desired value or default
Grace Chen6ad1c5e2017-06-13 16:07:45 -07002595 // value defined in Phone
Sandeep Gutta2a7c0d32016-03-16 21:37:25 +05302596 int type = SystemProperties.getInt("ro.telephony.default_cdma_sub",
2597 Phone.PREFERRED_CDMA_SUBSCRIPTION);
Naveen Kallab4d485c2013-07-03 16:39:27 -07002598 loadSetting(stmt, Settings.Global.CDMA_SUBSCRIPTION_MODE, type);
2599
Daniel Sandlerdea64622013-09-23 16:05:57 -04002600 loadIntegerSetting(stmt, Settings.Global.LOW_BATTERY_SOUND_TIMEOUT,
2601 R.integer.def_low_battery_sound_timeout);
2602
Oskar Grönqvist2c4254e2013-12-11 14:14:33 +01002603 loadIntegerSetting(stmt, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE,
2604 R.integer.def_wifi_scan_always_available);
2605
Chris Wren5242cf32014-03-19 16:16:48 -04002606 loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED,
2607 R.integer.def_heads_up_enabled);
2608
Jerome Poichet147b4d72014-05-12 18:13:27 -07002609 loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName());
2610
Edward Savage-Jonesce7a01f2015-12-09 21:16:50 +01002611 // Set default lid/cover behaviour according to legacy device config
2612 final int defaultLidBehavior;
2613 if (res.getBoolean(com.android.internal.R.bool.config_lidControlsSleep)) {
2614 // WindowManagerFuncs.LID_BEHAVIOR_SLEEP
2615 defaultLidBehavior = 1;
2616 } else if (res.getBoolean(com.android.internal.R.bool.config_lidControlsScreenLock)) {
2617 // WindowManagerFuncs.LID_BEHAVIOR_LOCK
2618 defaultLidBehavior = 2;
2619 } else {
2620 // WindowManagerFuncs.LID_BEHAVIOR_NONE
2621 defaultLidBehavior = 0;
2622 }
2623 loadSetting(stmt, Settings.Global.LID_BEHAVIOR, defaultLidBehavior);
2624
Jeff Brown503cffc2015-03-26 18:08:51 -07002625 /*
2626 * IMPORTANT: Do not add any more upgrade steps here as the global,
2627 * secure, and system settings are no longer stored in a database
2628 * but are kept in memory and persisted to XML.
2629 *
2630 * See: SettingsProvider.UpgradeController#onUpgradeLocked
2631 */
Christopher Tate06efb532012-08-24 15:29:27 -07002632 } finally {
2633 if (stmt != null) stmt.close();
2634 }
2635 }
2636
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002637 private void loadSetting(SQLiteStatement stmt, String key, Object value) {
2638 stmt.bindString(1, key);
2639 stmt.bindString(2, value.toString());
2640 stmt.execute();
2641 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002643 private void loadStringSetting(SQLiteStatement stmt, String key, int resid) {
2644 loadSetting(stmt, key, mContext.getResources().getString(resid));
2645 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 private void loadBooleanSetting(SQLiteStatement stmt, String key, int resid) {
2648 loadSetting(stmt, key,
2649 mContext.getResources().getBoolean(resid) ? "1" : "0");
2650 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002652 private void loadIntegerSetting(SQLiteStatement stmt, String key, int resid) {
2653 loadSetting(stmt, key,
2654 Integer.toString(mContext.getResources().getInteger(resid)));
2655 }
Jaikumar Ganesh9bfbfbd2009-05-15 12:05:56 -07002656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 private void loadFractionSetting(SQLiteStatement stmt, String key, int resid, int base) {
2658 loadSetting(stmt, key,
2659 Float.toString(mContext.getResources().getFraction(resid, base, base)));
2660 }
Amith Yamasani5cd15002011-11-16 11:19:48 -08002661
2662 private int getIntValueFromSystem(SQLiteDatabase db, String name, int defaultValue) {
Christopher Tate06efb532012-08-24 15:29:27 -07002663 return getIntValueFromTable(db, TABLE_SYSTEM, name, defaultValue);
Svetoslav Ganov86317012012-08-15 22:13:00 -07002664 }
2665
2666 private int getIntValueFromTable(SQLiteDatabase db, String table, String name,
2667 int defaultValue) {
2668 String value = getStringValueFromTable(db, table, name, null);
2669 return (value != null) ? Integer.parseInt(value) : defaultValue;
2670 }
2671
2672 private String getStringValueFromTable(SQLiteDatabase db, String table, String name,
2673 String defaultValue) {
Amith Yamasani5cd15002011-11-16 11:19:48 -08002674 Cursor c = null;
2675 try {
Svetoslav Ganov86317012012-08-15 22:13:00 -07002676 c = db.query(table, new String[] { Settings.System.VALUE }, "name='" + name + "'",
Amith Yamasani5cd15002011-11-16 11:19:48 -08002677 null, null, null, null);
2678 if (c != null && c.moveToFirst()) {
2679 String val = c.getString(0);
Svetoslav Ganov86317012012-08-15 22:13:00 -07002680 return val == null ? defaultValue : val;
Amith Yamasani5cd15002011-11-16 11:19:48 -08002681 }
2682 } finally {
2683 if (c != null) c.close();
2684 }
Svetoslav Ganov86317012012-08-15 22:13:00 -07002685 return defaultValue;
Amith Yamasani5cd15002011-11-16 11:19:48 -08002686 }
Jerome Poichet147b4d72014-05-12 18:13:27 -07002687
Jerome Poichet550021e2014-09-11 10:38:12 -07002688 private String getOldDefaultDeviceName() {
Jeff Sharkeyad59c432014-09-12 15:56:30 -07002689 return mContext.getResources().getString(R.string.def_device_name,
Jerome Poichet550021e2014-09-11 10:38:12 -07002690 Build.MANUFACTURER, Build.MODEL);
2691 }
2692
Jerome Poichet147b4d72014-05-12 18:13:27 -07002693 private String getDefaultDeviceName() {
Jeff Sharkeyad59c432014-09-12 15:56:30 -07002694 return mContext.getResources().getString(R.string.def_device_name_simple, Build.MODEL);
Jerome Poichet147b4d72014-05-12 18:13:27 -07002695 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07002696}