From 68665286e88abdd369bbf48ac77fc2422f9f3b9b Mon Sep 17 00:00:00 2001 From: Danesh M Date: Wed, 11 May 2016 18:59:00 -0700 Subject: CMSettings : Move force_show_navbar to global Keep feature inline with 12.1, only allow owner to control the feature and mirror across users. Also add additional checks for moved settings. Change-Id: Ida11b71bc5ce9463628f8c5d76e59902d47d59bb --- .../cyanogenmod/cmsettings/CMDatabaseHelper.java | 46 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/CMSettingsProvider/src/org/cyanogenmod/cmsettings/CMDatabaseHelper.java b/packages/CMSettingsProvider/src/org/cyanogenmod/cmsettings/CMDatabaseHelper.java index 5a1e50d..5a3bb9b 100644 --- a/packages/CMSettingsProvider/src/org/cyanogenmod/cmsettings/CMDatabaseHelper.java +++ b/packages/CMSettingsProvider/src/org/cyanogenmod/cmsettings/CMDatabaseHelper.java @@ -46,7 +46,7 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{ private static final boolean LOCAL_LOGV = false; private static final String DATABASE_NAME = "cmsettings.db"; - private static final int DATABASE_VERSION = 5; + private static final int DATABASE_VERSION = 6; public static class CMTableNames { public static final String TABLE_SYSTEM = "system"; @@ -219,6 +219,16 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{ upgradeVersion = 5; } + if (upgradeVersion < 6) { + // Move force_show_navbar to global + if (mUserHandle == UserHandle.USER_OWNER) { + moveSettingsToNewTable(db, CMTableNames.TABLE_SECURE, + CMTableNames.TABLE_GLOBAL, new String[] { + CMSettings.Secure.DEV_FORCE_SHOW_NAVBAR + }, true); + } + upgradeVersion = 6; + } // *** Remember to update DATABASE_VERSION above! if (upgradeVersion < newVersion) { @@ -237,6 +247,40 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{ } } + private void moveSettingsToNewTable(SQLiteDatabase db, + String sourceTable, String destTable, + 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 " + + (doIgnore ? " OR IGNORE " : "") + + " INTO " + destTable + " (name,value) SELECT name,value FROM " + + sourceTable + " WHERE name=?"); + deleteStmt = db.compileStatement("DELETE FROM " + sourceTable + " WHERE name=?"); + + for (String setting : settingsToMove) { + insertStmt.bindString(1, setting); + insertStmt.execute(); + + deleteStmt.bindString(1, setting); + deleteStmt.execute(); + } + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + if (insertStmt != null) { + insertStmt.close(); + } + if (deleteStmt != null) { + deleteStmt.close(); + } + } + } + /** * Drops the table and index for the specified database and table name * @param db The {@link SQLiteDatabase} to drop the table and index in. -- cgit v1.1