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 <roman@cyngn.com>
This commit is contained in:
Roman Birg 2016-06-07 11:19:05 -07:00
parent aa1f592e9f
commit 5b6638051e
2 changed files with 40 additions and 12 deletions

View File

@ -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();
}

View File

@ -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";