Merge "Handle Account Manager database downgrade."
This commit is contained in:
committed by
Android (Google) Code Review
commit
b8a61803ec
@@ -58,7 +58,6 @@ class AccountsDb implements AutoCloseable {
|
||||
private static final int CE_DATABASE_VERSION = 10;
|
||||
private static final int DE_DATABASE_VERSION = 3; // Added visibility support in O
|
||||
|
||||
|
||||
static final String TABLE_ACCOUNTS = "accounts";
|
||||
private static final String ACCOUNTS_ID = "_id";
|
||||
private static final String ACCOUNTS_NAME = "name";
|
||||
@@ -266,6 +265,13 @@ class AccountsDb implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
Log.e(TAG, "onDowngrade: recreate accounts CE table");
|
||||
resetDatabase(db);
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(SQLiteDatabase db) {
|
||||
if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "opened database " + CE_DATABASE_NAME);
|
||||
@@ -616,6 +622,13 @@ class AccountsDb implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
Log.e(TAG, "onDowngrade: recreate accounts DE table");
|
||||
resetDatabase(db);
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
public SQLiteDatabase getReadableDatabaseUserIsUnlocked() {
|
||||
if(!mCeAttached) {
|
||||
Log.wtf(TAG, "getReadableDatabaseUserIsUnlocked called while user " + mUserId
|
||||
@@ -1399,4 +1412,26 @@ class AccountsDb implements AutoCloseable {
|
||||
return new AccountsDb(deDatabaseHelper, context, preNDatabaseFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all tables and triggers created by AccountManager.
|
||||
*/
|
||||
private static void resetDatabase(SQLiteDatabase db) {
|
||||
try (Cursor c = db.rawQuery("SELECT name FROM sqlite_master WHERE type ='table'", null)) {
|
||||
while (c.moveToNext()) {
|
||||
String name = c.getString(0);
|
||||
// Skip tables managed by SQLiteDatabase
|
||||
if ("android_metadata".equals(name) || "sqlite_sequence".equals(name)) {
|
||||
continue;
|
||||
}
|
||||
db.execSQL("DROP TABLE IF EXISTS " + name);
|
||||
}
|
||||
}
|
||||
|
||||
try (Cursor c = db.rawQuery("SELECT name FROM sqlite_master WHERE type ='trigger'", null)) {
|
||||
while (c.moveToNext()) {
|
||||
String name = c.getString(0);
|
||||
db.execSQL("DROP TRIGGER IF EXISTS " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user