diff options
author | Marcus Hagerott <mhagerott@google.com> | 2021-11-02 10:35:27 -0700 |
---|---|---|
committer | Marcus Hagerott <mhagerott@google.com> | 2021-12-03 09:40:35 -0800 |
commit | 5f48b2ce4c02fc18c205479add7b8451ce63317c (patch) | |
tree | faf01813851efabb334c0079d809ba466829b0e5 /tests/src/com/android | |
parent | 7c94fba31988343706f5f3abf0c0231aa1a8ef21 (diff) | |
download | ContactsProvider-5f48b2ce4c02fc18c205479add7b8451ce63317c.tar.gz |
Revert "Migrate custom local account to AOSP local account"
This reverts commit 20428525d38d92bf6f4631fe040dd26b02be4c97 which
added the 1602 DB upgrade and adds a 1603 updgrade to clean up the
changes that were made in 1602. Reverting because partners are
concerned about backwards compatibility.
Test: atest ContactsProviderTests CtsContactsProviderTestCases
BUG=188347648
BUG=179694648
Change-Id: Ib5f675c7794aca57088b492084dcea30169923a5
Diffstat (limited to 'tests/src/com/android')
3 files changed, 0 insertions, 249 deletions
diff --git a/tests/src/com/android/providers/contacts/ContactLookupKeyTest.java b/tests/src/com/android/providers/contacts/ContactLookupKeyTest.java index 2fe1596f..047e8ea5 100644 --- a/tests/src/com/android/providers/contacts/ContactLookupKeyTest.java +++ b/tests/src/com/android/providers/contacts/ContactLookupKeyTest.java @@ -16,7 +16,6 @@ package com.android.providers.contacts; -import android.accounts.Account; import android.content.ContentUris; import android.net.Uri; import android.provider.ContactsContract.AggregationExceptions; @@ -166,80 +165,6 @@ public class ContactLookupKeyTest extends BaseContactsProvider2Test { assertStoredValue(lookupUri, Contacts._ID, largerContactId); } - public void testRawContactLookupKeyOriginalLocalAccount() { - Account originalLocalAccount = new Account("Phone", "Local"); - ContactsDatabaseHelper dbHelper = getContactsProvider().getContactsDatabaseHelperForTest(); - dbHelper.setOriginalLocalAccount( - new AccountWithDataSet(originalLocalAccount.name, originalLocalAccount.type, null)); - dbHelper.createLocalAccountCompatViews(dbHelper.getWritableDatabase()); - - long localRawContactId1 = RawContactUtil.createRawContactWithName(mResolver, "John", "Doe"); - storeValue(ContentUris.withAppendedId(RawContacts.CONTENT_URI, localRawContactId1), - RawContacts.SOURCE_ID, "sid_r1"); - long localRawContactId2 = RawContactUtil.createRawContactWithName(mResolver, "Jane", "Doe"); - long nonLocalRawContactId = RawContactUtil.createRawContactWithName( - mResolver, "Jack", "Bean", new Account("foo", "bar")); - - StringBuilder local1LookupKeyBuilder = new StringBuilder(); - ContactLookupKey.appendToLookupKey( - local1LookupKeyBuilder, "Local", "Phone", localRawContactId1, "sid_r1", null); - StringBuilder local2LookupKeyBuilder = new StringBuilder(); - ContactLookupKey.appendToLookupKey( - local2LookupKeyBuilder, "Local", "Phone", localRawContactId2, null, null); - StringBuilder local2ByNameLookupKeyBuilder = new StringBuilder(); - ContactLookupKey.appendToLookupKey( - local2ByNameLookupKeyBuilder, "Local", "Phone", 10000, null, "Jane Doe"); - - assertStoredValue( - Contacts.CONTENT_LOOKUP_URI.buildUpon() - .appendPath(local1LookupKeyBuilder.toString()).build(), - Contacts.DISPLAY_NAME, "John Doe"); - assertStoredValue( - Contacts.CONTENT_LOOKUP_URI.buildUpon() - .appendPath(local2LookupKeyBuilder.toString()).build(), - Contacts.DISPLAY_NAME, "Jane Doe"); - assertStoredValue( - Contacts.CONTENT_LOOKUP_URI.buildUpon() - .appendPath(local2ByNameLookupKeyBuilder.toString()).build(), - Contacts.DISPLAY_NAME, "Jane Doe"); - - local1LookupKeyBuilder.delete(0, local1LookupKeyBuilder.length()); - ContactLookupKey.appendToLookupKey( - local1LookupKeyBuilder, null, null, localRawContactId1, "sid_r1", null); - local2LookupKeyBuilder.delete(0, local2LookupKeyBuilder.length()); - ContactLookupKey.appendToLookupKey( - local2LookupKeyBuilder, null, null, localRawContactId2, null, null); - local2ByNameLookupKeyBuilder.delete(0, local2ByNameLookupKeyBuilder.length()); - ContactLookupKey.appendToLookupKey( - local2ByNameLookupKeyBuilder, null, null, 100, null, "Jane Doe"); - - assertStoredValue( - Contacts.CONTENT_LOOKUP_URI.buildUpon() - .appendPath(local1LookupKeyBuilder.toString()).build(), - Contacts.DISPLAY_NAME, "John Doe"); - assertStoredValue( - Contacts.CONTENT_LOOKUP_URI.buildUpon() - .appendPath(local2LookupKeyBuilder.toString()).build(), - Contacts.DISPLAY_NAME, "Jane Doe"); - assertStoredValue( - Contacts.CONTENT_LOOKUP_URI.buildUpon() - .appendPath(local2ByNameLookupKeyBuilder.toString()).build(), - Contacts.DISPLAY_NAME, "Jane Doe"); - - - // Lookup key for a non-local raw contact using local accounts should not resolve. - StringBuilder bogusNonLocalLookupKeyBuilder = new StringBuilder(); - ContactLookupKey.appendToLookupKey( - bogusNonLocalLookupKeyBuilder, null, null, nonLocalRawContactId, null, null); - ContactLookupKey.appendToLookupKey( - bogusNonLocalLookupKeyBuilder, "Phone", "Local", nonLocalRawContactId, null, null); - assertNoRowsAndClose( - mResolver.query( - Contacts.CONTENT_LOOKUP_URI.buildUpon() - .appendPath(bogusNonLocalLookupKeyBuilder.toString()).build(), - new String[] { RawContacts._ID }, null, null, null)); - } - public void testGetLookupUri() { long rawContactId1 = RawContactUtil.createRawContactWithName(mResolver, "John", "Doe"); storeValue(RawContacts.CONTENT_URI, rawContactId1, RawContacts.SOURCE_ID, "1"); diff --git a/tests/src/com/android/providers/contacts/ContactsDatabaseHelperTest.java b/tests/src/com/android/providers/contacts/ContactsDatabaseHelperTest.java index 143cc6c6..8c060cbc 100644 --- a/tests/src/com/android/providers/contacts/ContactsDatabaseHelperTest.java +++ b/tests/src/com/android/providers/contacts/ContactsDatabaseHelperTest.java @@ -129,31 +129,6 @@ public class ContactsDatabaseHelperTest extends BaseContactsProvider2Test { mDbHelper.getOrCreateAccountIdInTransaction(a5b)); } - public void testGetOrCreateAccountId_originalLocalAccount() { - AccountWithDataSet originalLocalAccount = new AccountWithDataSet("Phone", "Local", null); - mDbHelper.setOriginalLocalAccount(originalLocalAccount); - - Long idNewLocal = mDbHelper.getOrCreateAccountIdInTransaction(AccountWithDataSet.LOCAL); - - assertEquals(idNewLocal, mDbHelper.getAccountIdOrNull(originalLocalAccount)); - - // Remove all accounts. - mDbHelper.getWritableDatabase().execSQL("delete from " + Tables.ACCOUNTS); - - // This is created as the new local account. - Long idOriginalLocal = mDbHelper.getOrCreateAccountIdInTransaction(originalLocalAccount); - try (Cursor cursor = mDbHelper.getReadableDatabase().query(Tables.ACCOUNTS, new String[]{ - ContactsDatabaseHelper.AccountsColumns.ACCOUNT_NAME, - ContactsDatabaseHelper.AccountsColumns.ACCOUNT_TYPE - }, null, null, null, null, null)) { - assertTrue(cursor.moveToFirst()); - assertNull(cursor.getString(0)); - assertNull(cursor.getString(1)); - } - - assertEquals(idOriginalLocal, mDbHelper.getAccountIdOrNull(AccountWithDataSet.LOCAL)); - } - /** * Test for {@link ContactsDatabaseHelper#queryIdWithOneArg} and * {@link ContactsDatabaseHelper#insertWithOneArgAndReturnId}. diff --git a/tests/src/com/android/providers/contacts/ContactsDatabaseHelperUpgradeTest.java b/tests/src/com/android/providers/contacts/ContactsDatabaseHelperUpgradeTest.java index f0fb24ed..7ed996dd 100644 --- a/tests/src/com/android/providers/contacts/ContactsDatabaseHelperUpgradeTest.java +++ b/tests/src/com/android/providers/contacts/ContactsDatabaseHelperUpgradeTest.java @@ -19,9 +19,7 @@ package com.android.providers.contacts; import static com.android.providers.contacts.TestUtils.cv; import static com.android.providers.contacts.TestUtils.executeSqlFromAssetFile; -import android.content.ContentValues; import android.database.Cursor; -import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import android.provider.BaseColumns; import android.provider.CallLog.Calls; @@ -62,9 +60,6 @@ import com.android.providers.contacts.ContactsDatabaseHelper.StatusUpdatesColumn import com.android.providers.contacts.ContactsDatabaseHelper.Tables; import com.android.providers.contacts.util.PropertyUtils; -import java.util.ArrayList; -import java.util.List; - /** * Unit tests for database create/upgrade operations in {@link ContactsDatabaseHelper}. * @@ -128,7 +123,6 @@ public class ContactsDatabaseHelperUpgradeTest extends BaseDatabaseHelperUpgrade oldVersion = upgradeTo1109(oldVersion); oldVersion = upgradeTo1600(oldVersion); oldVersion = upgradeTo1601(oldVersion); - oldVersion = upgradeTo1602(oldVersion); oldVersion = upgrade(oldVersion, ContactsDatabaseHelper.DATABASE_VERSION); assertEquals(ContactsDatabaseHelper.DATABASE_VERSION, oldVersion); assertDatabaseStructureSameAsList(TABLE_LIST, /* isNewDatabase =*/ false); @@ -303,149 +297,6 @@ public class ContactsDatabaseHelperUpgradeTest extends BaseDatabaseHelperUpgrade return MY_VERSION; } - private int upgradeTo1602(int upgradeFrom) { - final int MY_VERSION = 1602; - - mDb.beginTransaction(); - try { - executeSqlFromAssetFile(getTestContext(), mDb, "upgradeTest/pre_upgrade1602.sql"); - mHelper.setOriginalLocalAccount( - new AccountWithDataSet("Phone", "LocalAccount", null)); - mHelper.onUpgrade(mDb, upgradeFrom, MY_VERSION); - - try (Cursor c = mDb.rawQuery("select " - + "_id, account_name, account_type, data_set " - + "from accounts order by _id", null)) { - BaseContactsProvider2Test.assertCursorValuesOrderly(c, - cv(AccountsColumns._ID, 1, - "account_name", null, - "account_type", null, - "data_set", null - ), - cv(AccountsColumns._ID, 2, - "account_name", "Phone", - "account_type", "LocalAccount", - "data_set", "local_data_set" - ), - cv(AccountsColumns._ID, 3, - "account_name", "Phone2", - "account_type", "LocalAccount", - "data_set", null - ), - cv(AccountsColumns._ID, 4, - "account_name", "Phone", - "account_type", "NonLocalAccount", - "data_set", null - ), - cv(AccountsColumns._ID, 5, - "account_name", "Other", - "account_type", "NonLocalAccount", - "data_set", null - )); - } - } finally { - // Rollback so we can test the upgrade again with different before data - mDb.endTransaction(); - } - - mDb.beginTransaction(); - try { - executeSqlFromAssetFile( - getTestContext(), mDb, "upgradeTest/pre_upgrade1602_multiple_local.sql"); - long nonLocalAccountId = 1; - long localAccountId = 2; - mHelper.setOriginalLocalAccount( - new AccountWithDataSet("Phone", "LocalAccount", null)); - - mHelper.onUpgrade(mDb, upgradeFrom, MY_VERSION); - - try (Cursor c = mDb.rawQuery("select " - + "_id, account_name, account_type, data_set " - + "from accounts order by _id", null)) { - // The local account with _id = 3 was removed. - assertEquals(c.getCount(), 2); - BaseContactsProvider2Test.assertCursorValuesOrderly(c, - cv(AccountsColumns._ID, nonLocalAccountId, - "account_name", "Other", - "account_type", "NonLocalAccount", - "data_set", null - ), - cv(AccountsColumns._ID, localAccountId, - "account_name", null, - "account_type", null, - "data_set", null - )); - } - try (Cursor c = mDb.rawQuery("select " - + "_id, account_id " - + "from raw_contacts " + " order by _id", null)) { - BaseContactsProvider2Test.assertCursorValuesOrderly(c, - cv("_id", 1, - "account_id", nonLocalAccountId - ), - cv("_id", 2, - "account_id", localAccountId - ), - cv("_id", 3, - "account_id", localAccountId - ), - cv("_id", 4, - "account_id", localAccountId - ), - cv("_id", 5, - "account_id", nonLocalAccountId - ), - cv("_id", 6, - "account_id", localAccountId - )); - } - try (Cursor c = mDb.rawQuery("select " - + "_id, account_id " - + "from groups " + " order by _id", null)) { - BaseContactsProvider2Test.assertCursorValuesOrderly(c, - cv("_id", 1, - "account_id", nonLocalAccountId - ), - cv("_id", 2, - "account_id", localAccountId - )); - } - } finally { - // Rollback so we can test the upgrade again with the AOSP local account. - mDb.endTransaction(); - } - - executeSqlFromAssetFile(getTestContext(), mDb, "upgradeTest/pre_upgrade1602.sql"); - mHelper.setOriginalLocalAccount(AccountWithDataSet.LOCAL); - List<ContentValues> before = new ArrayList<>(); - try (Cursor c = mDb.rawQuery("select " - + "_id, account_name, account_type, data_set " - + "from accounts order by _id", null)) { - while (c.moveToNext()) { - ContentValues values = new ContentValues(); - DatabaseUtils.cursorRowToContentValues(c, values); - before.add(values); - } - } - - mHelper.onUpgrade(mDb, upgradeFrom, MY_VERSION); - - List<ContentValues> after = new ArrayList<>(); - try (Cursor c = mDb.rawQuery("select " - + "_id, account_name, account_type, data_set " - + "from accounts order by _id", null)) { - while (c.moveToNext()) { - ContentValues values = new ContentValues(); - DatabaseUtils.cursorRowToContentValues(c, values); - after.add(values); - } - } - // Upgrade is a no-op when the original local account is the AOSP local account. - assertEquals(before, after); - - return MY_VERSION; - } - private int upgrade(int upgradeFrom, int upgradeTo) { if (upgradeFrom < upgradeTo) { mHelper.onUpgrade(mDb, upgradeFrom, upgradeTo); |