Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 970683c5 authored by Christopher Tate's avatar Christopher Tate Committed by Android (Google) Code Review
Browse files

Merge "Further fixup of migration to global settings" into jb-mr1-dev

parents 4db5d23d 9219874b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -878,6 +878,8 @@ public final class Settings {
        private static final HashSet<String> MOVED_TO_GLOBAL;
        static {
            MOVED_TO_GLOBAL = new HashSet<String>();
            // these were originally in system but migrated to secure in the past,
            // so are duplicated in the Secure.* namespace
            MOVED_TO_GLOBAL.add(Global.ADB_ENABLED);
            MOVED_TO_GLOBAL.add(Global.BLUETOOTH_ON);
            MOVED_TO_GLOBAL.add(Global.DATA_ROAMING);
@@ -885,6 +887,7 @@ public final class Settings {
            MOVED_TO_GLOBAL.add(Global.INSTALL_NON_MARKET_APPS);
            MOVED_TO_GLOBAL.add(Global.USB_MASS_STORAGE_ENABLED);

            // these are moving directly from system to global
            MOVED_TO_GLOBAL.add(Settings.Global.AIRPLANE_MODE_ON);
            MOVED_TO_GLOBAL.add(Settings.Global.AIRPLANE_MODE_RADIOS);
            MOVED_TO_GLOBAL.add(Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
+28 −11
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
    // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
    // is properly propagated through your change.  Not doing so will result in a loss of user
    // settings.
    private static final int DATABASE_VERSION = 85;
    private static final int DATABASE_VERSION = 86;

    private Context mContext;
    private int mUserHandle;
@@ -308,7 +308,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
                    Settings.Secure.WIFI_WATCHDOG_PING_DELAY_MS,
                    Settings.Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS,
                };
            moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove);
            moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
            upgradeVersion = 28;
        }

@@ -674,7 +674,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
                   "lockscreen.lockedoutpermanently",
                   "lockscreen.password_salt"
           };
           moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove);
           moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
           upgradeVersion = 52;
       }

@@ -724,7 +724,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
                    Secure.SET_INSTALL_LOCATION,
                    Secure.DEFAULT_INSTALL_LOCATION
            };
            moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove);
            moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, settingsToMove, false);
            db.beginTransaction();
            SQLiteStatement stmt = null;
            try {
@@ -1209,9 +1209,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
                // new users can be created.
                createGlobalTable(db);
                String[] settingsToMove = hashsetToStringArray(SettingsProvider.sSystemGlobalKeys);
                moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove);
                moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, false);
                settingsToMove = hashsetToStringArray(SettingsProvider.sSecureGlobalKeys);
                moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove);
                moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, false);

                db.setTransactionSuccessful();
            } finally {
@@ -1254,7 +1254,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            db.beginTransaction();
            SQLiteStatement stmt = null;
            try {
                // Patch up the slightly-wrong key migration from 82 -> 83
                // Patch up the slightly-wrong key migration from 82 -> 83 for those
                // devices that missed it, ignoring if the move is redundant
                String[] settingsToMove = {
                        Settings.Secure.ADB_ENABLED,
                        Settings.Secure.BLUETOOTH_ON,
@@ -1263,7 +1264,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
                        Settings.Secure.INSTALL_NON_MARKET_APPS,
                        Settings.Secure.USB_MASS_STORAGE_ENABLED
                };
                moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove);
                moveSettingsToNewTable(db, TABLE_SECURE, TABLE_GLOBAL, settingsToMove, true);
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
@@ -1272,6 +1273,21 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            upgradeVersion = 85;
        }

        if (upgradeVersion == 85) {
            db.beginTransaction();
            try {
                // Fix up the migration, ignoring already-migrated elements, to snap up to
                // date with new changes to the set of global versus system/secure settings
                String[] settingsToMove = { Settings.System.STAY_ON_WHILE_PLUGGED_IN };
                moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_GLOBAL, settingsToMove, true);

                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }
            upgradeVersion = 86;
        }

        // *** Remember to update DATABASE_VERSION above!

        if (upgradeVersion != currentVersion) {
@@ -1306,15 +1322,16 @@ public class DatabaseHelper extends SQLiteOpenHelper {

    private void moveSettingsToNewTable(SQLiteDatabase db,
            String sourceTable, String destTable,
            String[] settingsToMove) {
            String[] settingsToMove, boolean doIgnore) {
        // Copy settings values from the source table to the dest, and remove from the source
        SQLiteStatement insertStmt = null;
        SQLiteStatement deleteStmt = null;

        db.beginTransaction();
        try {
            insertStmt = db.compileStatement("INSERT INTO "
                    + destTable + " (name,value) SELECT name,value FROM "
            insertStmt = db.compileStatement("INSERT "
                    + (doIgnore ? " OR IGNORE " : "")
                    + " INTO " + destTable + " (name,value) SELECT name,value FROM "
                    + sourceTable + " WHERE name=?");
            deleteStmt = db.compileStatement("DELETE FROM " + sourceTable + " WHERE name=?");

+7 −6
Original line number Diff line number Diff line
@@ -113,17 +113,22 @@ public class SettingsProvider extends ContentProvider {
        // table, shared across all users
        // These must match Settings.Secure.MOVED_TO_GLOBAL
        sSecureGlobalKeys = new HashSet<String>();
        sSecureGlobalKeys.add(Settings.Secure.ADB_ENABLED);
        sSecureGlobalKeys.add(Settings.Secure.ASSISTED_GPS_ENABLED);
        sSecureGlobalKeys.add(Settings.Secure.BLUETOOTH_ON);
        sSecureGlobalKeys.add(Settings.Secure.CDMA_CELL_BROADCAST_SMS);
        sSecureGlobalKeys.add(Settings.Secure.CDMA_ROAMING_MODE);
        sSecureGlobalKeys.add(Settings.Secure.CDMA_SUBSCRIPTION_MODE);
        sSecureGlobalKeys.add(Settings.Secure.DATA_ACTIVITY_TIMEOUT_MOBILE);
        sSecureGlobalKeys.add(Settings.Secure.DATA_ACTIVITY_TIMEOUT_WIFI);
        sSecureGlobalKeys.add(Settings.Secure.DATA_ROAMING);
        sSecureGlobalKeys.add(Settings.Secure.DEVELOPMENT_SETTINGS_ENABLED);
        sSecureGlobalKeys.add(Settings.Secure.DEVICE_PROVISIONED);
        sSecureGlobalKeys.add(Settings.Secure.DISPLAY_DENSITY_FORCED);
        sSecureGlobalKeys.add(Settings.Secure.DISPLAY_SIZE_FORCED);
        sSecureGlobalKeys.add(Settings.Secure.DOWNLOAD_MAX_BYTES_OVER_MOBILE);
        sSecureGlobalKeys.add(Settings.Secure.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE);
        sSecureGlobalKeys.add(Settings.Secure.INSTALL_NON_MARKET_APPS);
        sSecureGlobalKeys.add(Settings.Secure.MOBILE_DATA);
        sSecureGlobalKeys.add(Settings.Secure.NETSTATS_DEV_BUCKET_DURATION);
        sSecureGlobalKeys.add(Settings.Secure.NETSTATS_DEV_DELETE_AGE);
@@ -167,6 +172,7 @@ public class SettingsProvider extends ContentProvider {
        sSecureGlobalKeys.add(Settings.Secure.THROTTLE_RESET_DAY);
        sSecureGlobalKeys.add(Settings.Secure.THROTTLE_THRESHOLD_BYTES);
        sSecureGlobalKeys.add(Settings.Secure.THROTTLE_VALUE_KBITSPS);
        sSecureGlobalKeys.add(Settings.Secure.USB_MASS_STORAGE_ENABLED);
        sSecureGlobalKeys.add(Settings.Secure.USE_GOOGLE_MAIL);
        sSecureGlobalKeys.add(Settings.Secure.WEB_AUTOFILL_QUERY_URL);
        sSecureGlobalKeys.add(Settings.Secure.WIFI_COUNTRY_CODE);
@@ -193,12 +199,6 @@ public class SettingsProvider extends ContentProvider {
        // Keys from the 'system' table now moved to 'global'
        // These must match Settings.System.MOVED_TO_GLOBAL
        sSystemGlobalKeys = new HashSet<String>();
        sSystemGlobalKeys.add(Settings.Secure.ADB_ENABLED);
        sSystemGlobalKeys.add(Settings.Secure.BLUETOOTH_ON);
        sSystemGlobalKeys.add(Settings.Secure.DATA_ROAMING);
        sSystemGlobalKeys.add(Settings.Secure.DEVICE_PROVISIONED);
        sSystemGlobalKeys.add(Settings.Secure.INSTALL_NON_MARKET_APPS);
        sSystemGlobalKeys.add(Settings.Secure.USB_MASS_STORAGE_ENABLED);

        sSystemGlobalKeys.add(Settings.System.AIRPLANE_MODE_ON);
        sSystemGlobalKeys.add(Settings.System.AIRPLANE_MODE_RADIOS);
@@ -214,6 +214,7 @@ public class SettingsProvider extends ContentProvider {
        sSystemGlobalKeys.add(Settings.System.UNLOCK_SOUND);
        sSystemGlobalKeys.add(Settings.System.LOW_BATTERY_SOUND);
        sSystemGlobalKeys.add(Settings.System.POWER_SOUNDS_ENABLED);
        sSystemGlobalKeys.add(Settings.System.STAY_ON_WHILE_PLUGGED_IN);
        sSystemGlobalKeys.add(Settings.System.WIFI_SLEEP_POLICY);
    }