From 9f4d6b56e87a3ad243ca5754c9f85a6c025de761 Mon Sep 17 00:00:00 2001 From: Sebastian Achim Date: Thu, 9 Mar 2023 14:31:03 +0100 Subject: Remove migrateFromLegacyTables() migrateFromLegacyTables can be called from a device encrypted storage context which wrongfully creates contacts2.db under DE storage. The migrateFromLegacyTables() call was only needed to migrate call log from pre-N devices, not needed now, so remove it. Also removed related testMigration test that was added to test migrateFromLegacyTables. Test: atest ContactsProviderTests Bug: 268590477 Change-Id: I84767284669f2342fb018a9ebee78a40c32b923d --- .../providers/contacts/CallLogDatabaseHelper.java | 82 ---------------------- 1 file changed, 82 deletions(-) (limited to 'src') diff --git a/src/com/android/providers/contacts/CallLogDatabaseHelper.java b/src/com/android/providers/contacts/CallLogDatabaseHelper.java index c5052d70..73480994 100644 --- a/src/com/android/providers/contacts/CallLogDatabaseHelper.java +++ b/src/com/android/providers/contacts/CallLogDatabaseHelper.java @@ -203,7 +203,6 @@ public class CallLogDatabaseHelper { VoicemailContract.Status.SOURCE_TYPE + " TEXT" + ");"); - migrateFromLegacyTables(db); } @Override @@ -532,87 +531,6 @@ public class CallLogDatabaseHelper { mPhoneAccountHandleMigrationUtils.migrateIccIdToSubId(db); } - /** - * Perform the migration from the contacts2.db (of the latest version) to the current calllog/ - * voicemail status tables. - */ - private void migrateFromLegacyTables(SQLiteDatabase calllog) { - final SQLiteDatabase contacts = getContactsWritableDatabaseForMigration(); - - if (contacts == null) { - Log.w(TAG, "Contacts DB == null, skipping migration. (running tests?)"); - return; - } - if (DEBUG) { - Log.d(TAG, "migrateFromLegacyTables"); - } - - if ("1".equals(PropertyUtils.getProperty(calllog, DbProperties.DATA_MIGRATED, ""))) { - return; - } - - Log.i(TAG, "Migrating from old tables..."); - - contacts.beginTransaction(); - try { - if (!tableExists(contacts, LegacyConstants.CALLS_LEGACY) - || !tableExists(contacts, LegacyConstants.VOICEMAIL_STATUS_LEGACY)) { - // This is fine on new devices. (or after a "clear data".) - Log.i(TAG, "Source tables don't exist."); - return; - } - calllog.beginTransaction(); - try { - - final ContentValues cv = new ContentValues(); - - try (Cursor source = contacts.rawQuery( - "SELECT * FROM " + LegacyConstants.CALLS_LEGACY, null)) { - while (source.moveToNext()) { - cv.clear(); - - DatabaseUtils.cursorRowToContentValues(source, cv); - - calllog.insertOrThrow(Tables.CALLS, null, cv); - } - } - - try (Cursor source = contacts.rawQuery("SELECT * FROM " + - LegacyConstants.VOICEMAIL_STATUS_LEGACY, null)) { - while (source.moveToNext()) { - cv.clear(); - - DatabaseUtils.cursorRowToContentValues(source, cv); - - calllog.insertOrThrow(Tables.VOICEMAIL_STATUS, null, cv); - } - } - - contacts.execSQL("DROP TABLE " + LegacyConstants.CALLS_LEGACY + ";"); - contacts.execSQL("DROP TABLE " + LegacyConstants.VOICEMAIL_STATUS_LEGACY + ";"); - - // Also copy the last sync time. - PropertyUtils.setProperty(calllog, DbProperties.CALL_LOG_LAST_SYNCED, - PropertyUtils.getProperty(contacts, - LegacyConstants.CALL_LOG_LAST_SYNCED_LEGACY, null)); - - Log.i(TAG, "Migration completed."); - - calllog.setTransactionSuccessful(); - } finally { - calllog.endTransaction(); - } - - contacts.setTransactionSuccessful(); - } catch (RuntimeException e) { - // We don't want to be stuck here, so we just swallow exceptions... - Log.w(TAG, "Exception caught during migration", e); - } finally { - contacts.endTransaction(); - } - PropertyUtils.setProperty(calllog, DbProperties.DATA_MIGRATED, "1"); - } - @VisibleForTesting static boolean tableExists(SQLiteDatabase db, String table) { return DatabaseUtils.longForQuery(db, -- cgit v1.2.3