From 5b6638051e85986d79fe2fc7b1b08cce12499751 Mon Sep 17 00:00:00 2001 From: Roman Birg Date: Tue, 7 Jun 2016 11:19:05 -0700 Subject: [PATCH] CMSettingsProvider: load provisioned flag when creating DB If the database needs to be created, it will not be upgraded. So, if the device was provisioned and the table wasn't created, we don't upgrade and so we cannot bring the old flag to the new location. Fix this by setting the new cm provisioned flag on database creation. Ticket: CYNGNOS-3017 Change-Id: I1e961f1cb2d06c55c1e92ef63c6dbaee17dbc304 Signed-off-by: Roman Birg --- .../cmsettings/CMDatabaseHelper.java | 31 ++++++++++++------- .../tests/CMSettingsProviderTest.java | 21 +++++++++++++ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/packages/CMSettingsProvider/src/org/cyanogenmod/cmsettings/CMDatabaseHelper.java b/packages/CMSettingsProvider/src/org/cyanogenmod/cmsettings/CMDatabaseHelper.java index 5a3bb9b..eee47ea 100644 --- a/packages/CMSettingsProvider/src/org/cyanogenmod/cmsettings/CMDatabaseHelper.java +++ b/packages/CMSettingsProvider/src/org/cyanogenmod/cmsettings/CMDatabaseHelper.java @@ -153,6 +153,7 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{ @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + if (LOCAL_LOGV) Log.d(TAG, "Upgrading from version: " + oldVersion + " to " + newVersion); int upgradeVersion = oldVersion; if (upgradeVersion < 2) { @@ -185,18 +186,20 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{ } if (upgradeVersion < 4) { - db.beginTransaction(); - SQLiteStatement stmt = null; - try { - stmt = db.compileStatement("INSERT INTO secure(name,value)" - + " VALUES(?,?);"); - loadSetting(stmt, CMSettings.Secure.CM_SETUP_WIZARD_COMPLETED, - Settings.Global.getString(mContext.getContentResolver(), - Settings.Global.DEVICE_PROVISIONED)); - db.setTransactionSuccessful(); - } finally { - if (stmt != null) stmt.close(); - db.endTransaction(); + if (mUserHandle == UserHandle.USER_OWNER) { + db.beginTransaction(); + SQLiteStatement stmt = null; + try { + stmt = db.compileStatement("INSERT INTO secure(name,value)" + + " VALUES(?,?);"); + final String provisionedFlag = Settings.Global.getString( + mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED); + loadSetting(stmt, CMSettings.Secure.CM_SETUP_WIZARD_COMPLETED, provisionedFlag); + db.setTransactionSuccessful(); + } finally { + if (stmt != null) stmt.close(); + db.endTransaction(); + } } upgradeVersion = 4; } @@ -343,6 +346,10 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{ loadStringSetting(stmt, CMSettings.Secure.PROTECTED_COMPONENT_MANAGERS, R.string.def_protected_component_managers); + + final String provisionedFlag = Settings.Global.getString(mContext.getContentResolver(), + Settings.Global.DEVICE_PROVISIONED); + loadSetting(stmt, CMSettings.Secure.CM_SETUP_WIZARD_COMPLETED, provisionedFlag); } finally { if (stmt != null) stmt.close(); } diff --git a/packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsProviderTest.java b/packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsProviderTest.java index a5cd57f..306436f 100644 --- a/packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsProviderTest.java +++ b/packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsProviderTest.java @@ -119,6 +119,27 @@ import java.util.Map; assertEquals(cmProviderValue, settingsProviderValue); } + /** + * The new {@link CMSettings.Secure#CM_SETUP_WIZARD_COMPLETED} cm specific provisioned flag + * should be equal to the old {@link Settings.Global#DEVICE_PROVISIONED} flag on boot, or on + * upgrade. These flags will almost always be equal, except during the provisioning process, + * they may change at slightly different times. + * + * Test whether the setting was properly set and is not null. + */ + @SmallTest + public void testCMProvisionedFlagFallbackSet() { + final String newCmFlag = CMSettings.Secure.getStringForUser( + getContext().getContentResolver(), CMSettings.Secure.CM_SETUP_WIZARD_COMPLETED, + UserHandle.USER_OWNER); + assertNotNull(newCmFlag); + + final String previousFlag = Settings.Global.getStringForUser( + getContext().getContentResolver(), Settings.Global.DEVICE_PROVISIONED, + UserHandle.USER_OWNER); + assertEquals(previousFlag, newCmFlag); + } + private void testMigrateSettingsForUser(int userId) { // Setup values in Settings /*final String expectedPullDownValue = "testQuickPullDownValue";