From 712533da14e5541b20097c8609905db1d52d0f10 Mon Sep 17 00:00:00 2001 From: Zheng Fu Date: Wed, 10 Jun 2015 14:02:21 -0700 Subject: Revert metadata_sync table and related code from M Bug:20553119 Change-Id: I89b48cc5a39a57ebeafe7821f07c410dac871258 --- .../test1/testFileDeviceContactMetadataJSON.txt | 69 ----- .../providers/contacts/ContactsProvider2Test.java | 109 -------- .../contacts/MetadataEntryParserTest.java | 305 --------------------- 3 files changed, 483 deletions(-) delete mode 100644 tests/assets/test1/testFileDeviceContactMetadataJSON.txt delete mode 100644 tests/src/com/android/providers/contacts/MetadataEntryParserTest.java (limited to 'tests') diff --git a/tests/assets/test1/testFileDeviceContactMetadataJSON.txt b/tests/assets/test1/testFileDeviceContactMetadataJSON.txt deleted file mode 100644 index 65e624d..0000000 --- a/tests/assets/test1/testFileDeviceContactMetadataJSON.txt +++ /dev/null @@ -1,69 +0,0 @@ -{ - "unique_contact_id": { - "account_type": "CUSTOM_ACCOUNT", - "custom_account_type": "facebook", - "account_name": "android-test", - "contact_id": "1111111", - "data_set": "FOCUS" - }, - "contact_prefs": { - "send_to_voicemail": true, - "starred": false, - "pinned": 2 - }, - "aggregation_data": [ - { - "type": "TOGETHER", - "contact_ids": [ - { - "account_type": "GOOGLE_ACCOUNT", - "account_name": "android-test2", - "contact_id": "2222222", - "data_set": "GOOGLE_PLUS" - }, - { - "account_type": "GOOGLE_ACCOUNT", - "account_name": "android-test3", - "contact_id": "3333333", - "data_set": "CUSTOM", - "custom_data_set": "custom type" - } - ] - } - ], - "field_data": [ - { - "field_data_id": "1001", - "field_data_prefs": { - "is_primary": true, - "is_super_primary": true - }, - "usage_stats": [ - { - "usage_type": "CALL", - "last_time_used": 10000001, - "usage_count": 10 - }, - { - "usage_type": "SHORT_TEXT", - "last_time_used": 20000002, - "usage_count": 20 - } - ] - }, - { - "field_data_id": "1002", - "field_data_prefs": { - "is_primary": false, - "is_super_primary": false - }, - "usage_stats": [ - { - "usage_type": "LONG_TEXT", - "last_time_used": 30000003, - "usage_count": 30 - } - ] - } - ] -} \ No newline at end of file diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index d75996c..1bc8b7a 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -84,11 +84,6 @@ import com.android.providers.contacts.ContactsDatabaseHelper.DbProperties; import com.android.providers.contacts.ContactsDatabaseHelper.PresenceColumns; import com.android.providers.contacts.ContactsDatabaseHelper.RawContactsColumns; import com.android.providers.contacts.ContactsDatabaseHelper.Tables; -import com.android.providers.contacts.MetadataEntryParser.AggregationData; -import com.android.providers.contacts.MetadataEntryParser.FieldData; -import com.android.providers.contacts.MetadataEntryParser.MetadataEntry; -import com.android.providers.contacts.MetadataEntryParser.RawContactInfo; -import com.android.providers.contacts.MetadataEntryParser.UsageStats; import com.android.providers.contacts.testutil.CommonDatabaseUtils; import com.android.providers.contacts.testutil.ContactUtil; import com.android.providers.contacts.testutil.DataUtil; @@ -2734,110 +2729,6 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { assertStoredValuesOrderly(filterUri1, new ContentValues[] { v2, v1, v4, v3 }); } - public void testUpdateFromMetadataEntry() { - String accountType1 = "accountType1"; - String accountName1 = "accountName1"; - String dataSet1 = "plus"; - Account account1 = new Account(accountName1, accountType1); - long rawContactId = RawContactUtil.createRawContactWithName(mResolver, account1); - Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); - // Add backup_id for the raw contact. - String backupId = "backupId100001"; - ContentValues values = new ContentValues(); - values.put(RawContacts.BACKUP_ID, backupId); - assertEquals(1, mResolver.update(rawContactUri, values, null, null)); - - String emailAddress = "address@email.com"; - Uri dataUri = insertEmail(rawContactId, emailAddress); - String hashId = "hashId100002"; - ContentValues dataValues = new ContentValues(); - dataValues.put(Data.HASH_ID, hashId); - assertEquals(1, mResolver.update(dataUri, dataValues, null, null)); - - // Another data that should not be updated. - String phoneNumber = "111-111-1111"; - Uri dataUri2 = insertPhoneNumber(rawContactId, phoneNumber); - String hashId2 = "hashId100004"; - ContentValues dataValues2 = new ContentValues(); - dataValues.put(Data.HASH_ID, hashId2); - mResolver.update(dataUri2, dataValues2, null, null); - - String accountType2 = "accountType2"; - String accountName2 = "accountName2"; - Account account2 = new Account(accountName2, accountType2); - long rawContactId2 = RawContactUtil.createRawContactWithName(mResolver, account2); - Uri rawContactUri2 = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId2); - String backupId2 = "backupId100003"; - ContentValues values2 = new ContentValues(); - values2.put(RawContacts.BACKUP_ID, backupId2); - assertEquals(1, mResolver.update(rawContactUri2, values2, null, null)); - - String usageTypeString = "CALL"; - int lastTimeUsed = 1111111; - int timesUsed = 5; - String aggregationTypeString = "SEPARATE"; - int aggregationType = AggregationExceptions.TYPE_KEEP_SEPARATE; - - RawContactInfo rawContactInfo = new RawContactInfo( - backupId, accountType1, accountName1, null); - UsageStats usageStats = new UsageStats(usageTypeString, lastTimeUsed, timesUsed); - ArrayList usageStatsList = new ArrayList<>(); - usageStatsList.add(usageStats); - FieldData fieldData = new FieldData(hashId, true, true, usageStatsList); - ArrayList fieldDataList = new ArrayList<>(); - fieldDataList.add(fieldData); - ArrayList aggregationDataList = new ArrayList<>(); - MetadataEntry metadataEntry = new MetadataEntry(rawContactInfo, - 1, 1, 1, fieldDataList, aggregationDataList); - - ContactsProvider2 provider = (ContactsProvider2) getProvider(); - final ContactsDatabaseHelper helper = - ((ContactsDatabaseHelper) provider.getDatabaseHelper()); - SQLiteDatabase db = helper.getWritableDatabase(); - - // Before updating tables from MetadataEntry. - assertStoredValue(rawContactUri, RawContacts.ACCOUNT_TYPE, accountType1); - assertStoredValue(rawContactUri, RawContacts.ACCOUNT_NAME, accountName1); - assertStoredValue(rawContactUri, RawContacts.SEND_TO_VOICEMAIL, "0"); - assertStoredValue(rawContactUri, RawContacts.STARRED, "0"); - assertStoredValue(rawContactUri, RawContacts.PINNED, "0"); - assertStoredValue(dataUri, Data.IS_PRIMARY, 0); - assertStoredValue(dataUri, Data.IS_SUPER_PRIMARY, 0); - - // Update tables without aggregation first, since aggregator will affect pinned value. - provider.updateFromMetaDataEntry(db, metadataEntry); - - // After updating tables from MetadataEntry. - assertStoredValue(rawContactUri, RawContacts.ACCOUNT_TYPE, accountType1); - assertStoredValue(rawContactUri, RawContacts.ACCOUNT_NAME, accountName1); - assertStoredValue(rawContactUri, RawContacts.SEND_TO_VOICEMAIL, "1"); - assertStoredValue(rawContactUri, RawContacts.STARRED, "1"); - assertStoredValue(rawContactUri, RawContacts.PINNED, "1"); - assertStoredValue(dataUri, Data.IS_PRIMARY, 1); - assertStoredValue(dataUri, Data.IS_SUPER_PRIMARY, 1); - final Uri dataUriWithUsageType = Data.CONTENT_URI.buildUpon().appendQueryParameter( - DataUsageFeedback.USAGE_TYPE, usageTypeString).build(); - assertDataUsageCursorContains(dataUriWithUsageType, emailAddress, timesUsed, lastTimeUsed); - - // Update AggregationException table. - RawContactInfo aggregationContact = new RawContactInfo( - backupId2, accountType2, accountName2, null); - AggregationData aggregationData = new AggregationData( - rawContactInfo, aggregationContact, aggregationTypeString); - aggregationDataList.add(aggregationData); - metadataEntry = new MetadataEntry(rawContactInfo, - 1, 1, 1, fieldDataList, aggregationDataList); - provider.updateFromMetaDataEntry(db, metadataEntry); - - // Check if AggregationException table is updated. - assertStoredValue(AggregationExceptions.CONTENT_URI, AggregationExceptions.RAW_CONTACT_ID1, - rawContactId); - assertStoredValue(AggregationExceptions.CONTENT_URI, AggregationExceptions.RAW_CONTACT_ID2, - rawContactId2); - assertStoredValue(AggregationExceptions.CONTENT_URI, AggregationExceptions.TYPE, - aggregationType); - } - public void testPostalsQuery() { long rawContactId = RawContactUtil.createRawContactWithName(mResolver, "Alice", "Nextore"); Uri dataUri = insertPostalAddress(rawContactId, "1600 Amphiteatre Ave, Mountain View"); diff --git a/tests/src/com/android/providers/contacts/MetadataEntryParserTest.java b/tests/src/com/android/providers/contacts/MetadataEntryParserTest.java deleted file mode 100644 index be4df57..0000000 --- a/tests/src/com/android/providers/contacts/MetadataEntryParserTest.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.providers.contacts; - -import android.content.Context; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; -import com.android.providers.contacts.MetadataEntryParser.AggregationData; -import com.android.providers.contacts.MetadataEntryParser.FieldData; -import com.android.providers.contacts.MetadataEntryParser.MetadataEntry; -import com.android.providers.contacts.MetadataEntryParser.RawContactInfo; -import com.android.providers.contacts.MetadataEntryParser.UsageStats; -import org.json.JSONException; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; - -/** - * Unit tests for {@link MetadataEntryParser}. - * - * Run the test like this: - * - adb shell am instrument -e class com.android.providers.contacts.MetadataEntryParserTest -w \ - com.android.providers.contacts.tests/android.test.InstrumentationTestRunner - * - */ -@SmallTest -public class MetadataEntryParserTest extends AndroidTestCase { - - public void testErrorForEmptyInput() { - try { - MetadataEntryParser.parseDataToMetaDataEntry(""); - } catch (IllegalArgumentException e) { - // Expected. - } - } - - public void testParseDataToMetadataEntry() throws IOException { - String contactBackupId = "1111111"; - String accountType = "facebook"; - String accountName = "android-test"; - String dataSet = null; - int sendToVoicemail = 1; - int starred = 0; - int pinned = 2; - String dataHashId1 = "1001"; - String usageType1_1 = "CALL"; - long lastTimeUsed1_1 = 10000001; - int timesUsed1_1 = 10; - String usageType1_2 = "SHORT_TEXT"; - long lastTimeUsed1_2 = 20000002; - int timesUsed1_2 = 20; - String dataHashId2 = "1002"; - String usageType2 = "LONG_TEXT"; - long lastTimeUsed2 = 30000003; - int timesUsed2 = 30; - String aggregationContactBackupId1 = "2222222"; - String aggregationAccountType1 = "com.google"; - String aggregationAccountName1 = "android-test2"; - String aggregationDataSet1 = "plus"; - String aggregationContactBackupId2 = "3333333"; - String aggregationAccountType2 = "com.google"; - String aggregationAccountName2 = "android-test3"; - String aggregationDataSet2 = "custom type"; - String type = "TOGETHER"; - String inputFile = "test1/testFileDeviceContactMetadataJSON.txt"; - - RawContactInfo rawContactInfo = new RawContactInfo( - contactBackupId, accountType, accountName, dataSet); - RawContactInfo aggregationContact1 = new RawContactInfo(aggregationContactBackupId1, - aggregationAccountType1, aggregationAccountName1, aggregationDataSet1); - RawContactInfo aggregationContact2 = new RawContactInfo(aggregationContactBackupId2, - aggregationAccountType2, aggregationAccountName2, aggregationDataSet2); - AggregationData aggregationData = new AggregationData( - aggregationContact1, aggregationContact2, type); - ArrayList aggregationDataList = new ArrayList<>(); - aggregationDataList.add(aggregationData); - - UsageStats usageStats1_1 = new UsageStats(usageType1_1, lastTimeUsed1_1, timesUsed1_1); - UsageStats usageStats1_2 = new UsageStats(usageType1_2, lastTimeUsed1_2, timesUsed1_2); - UsageStats usageStats2 = new UsageStats(usageType2, lastTimeUsed2, timesUsed2); - - ArrayList usageStats1List = new ArrayList<>(); - usageStats1List.add(usageStats1_1); - usageStats1List.add(usageStats1_2); - FieldData fieldData1 = new FieldData(dataHashId1, true, true, usageStats1List); - - ArrayList usageStats2List = new ArrayList<>(); - usageStats2List.add(usageStats2); - FieldData fieldData2 = new FieldData(dataHashId2, false, false, usageStats2List); - - ArrayList fieldDataList = new ArrayList<>(); - fieldDataList.add(fieldData1); - fieldDataList.add(fieldData2); - - MetadataEntry expectedResult = new MetadataEntry(rawContactInfo, - sendToVoicemail, starred, pinned, fieldDataList, aggregationDataList); - - String inputJson = readAssetAsString(inputFile); - MetadataEntry metadataEntry = MetadataEntryParser.parseDataToMetaDataEntry( - inputJson.toString()); - assertMetaDataEntry(expectedResult, metadataEntry); - } - - public void testErrorForMissingContactId() { - String input = "{\"unique_contact_id\": {\n" + - " \"account_type\": \"CUSTOM_ACCOUNT\",\n" + - " \"custom_account_type\": \"facebook\",\n" + - " \"account_name\": \"android-test\"\n" + - " }}"; - try { - MetadataEntryParser.parseDataToMetaDataEntry(input); - } catch (IllegalArgumentException e) { - // Expected. - } - } - - public void testErrorForNullContactId() throws JSONException { - String input = "{\"unique_contact_id\": {\n" + - " \"account_type\": \"CUSTOM_ACCOUNT\",\n" + - " \"custom_account_type\": \"facebook\",\n" + - " \"account_name\": \"android-test\",\n" + - " \"contact_id\": \"\"\n" + - " }}"; - try { - MetadataEntryParser.parseDataToMetaDataEntry(input); - } catch (IllegalArgumentException e) { - // Expected. - } - } - - public void testErrorForNullAccountType() throws JSONException { - String input = "{\"unique_contact_id\": {\n" + - " \"account_type\": \"\",\n" + - " \"custom_account_type\": \"facebook\",\n" + - " \"account_name\": \"android-test\",\n" + - " \"contact_id\": \"\"\n" + - " }}"; - try { - MetadataEntryParser.parseDataToMetaDataEntry(input); - } catch (IllegalArgumentException e) { - // Expected. - } - } - - public void testErrorForNullAccountName() throws JSONException { - String input = "{\"unique_contact_id\": {\n" + - " \"account_type\": \"CUSTOM_ACCOUNT\",\n" + - " \"custom_account_type\": \"facebook\",\n" + - " \"account_name\": \"\",\n" + - " \"contact_id\": \"1111111\"\n" + - " }}"; - try { - MetadataEntryParser.parseDataToMetaDataEntry(input); - } catch (IllegalArgumentException e) { - // Expected. - } - } - - public void testErrorForNullFieldDataId() throws JSONException { - String input = "{\"unique_contact_id\": {\n" + - " \"account_type\": \"CUSTOM_ACCOUNT\",\n" + - " \"custom_account_type\": \"facebook\",\n" + - " \"account_name\": \"android-test\",\n" + - " \"contact_id\": \"1111111\"\n" + - " },\n" + - " \"contact_prefs\": {\n" + - " \"send_to_voicemail\": true,\n" + - " \"starred\": false,\n" + - " \"pinned\": 2\n" + - " }," + - " \"field_data\": [{\n" + - " \"field_data_id\": \"\"}]" + - "}"; - try { - MetadataEntryParser.parseDataToMetaDataEntry(input); - } catch (IllegalArgumentException e) { - // Expected. - } - } - - public void testErrorForNullAggregationType() throws JSONException { - String input = "{\n" + - " \"unique_contact_id\": {\n" + - " \"account_type\": \"CUSTOM_ACCOUNT\",\n" + - " \"custom_account_type\": \"facebook\",\n" + - " \"account_name\": \"android-test\",\n" + - " \"contact_id\": \"1111111\"\n" + - " },\n" + - " \"contact_prefs\": {\n" + - " \"send_to_voicemail\": true,\n" + - " \"starred\": false,\n" + - " \"pinned\": 2\n" + - " },\n" + - " \"aggregation_data\": [\n" + - " {\n" + - " \"type\": \"\",\n" + - " \"contact_ids\": [\n" + - " {\n" + - " \"contact_id\": \"2222222\"\n" + - " },\n" + - " {\n" + - " \"contact_id\": \"3333333\"\n" + - " }\n" + - " ]\n" + - " }\n" + - " ]}"; - try { - MetadataEntryParser.parseDataToMetaDataEntry(input); - } catch (IllegalArgumentException e) { - // Expected. - } - } - - private String readAssetAsString(String fileName) throws IOException { - Context context = getTestContext(); - InputStream input = context.getAssets().open(fileName); - ByteArrayOutputStream contents = new ByteArrayOutputStream(); - int len; - byte[] data = new byte[1024]; - do { - len = input.read(data); - if (len > 0) contents.write(data, 0, len); - } while (len == data.length); - return contents.toString(); - } - - private void assertMetaDataEntry(MetadataEntry entry1, MetadataEntry entry2) { - assertRawContactInfoEquals(entry1.mRawContactInfo, entry2.mRawContactInfo); - assertEquals(entry1.mSendToVoicemail, entry2.mSendToVoicemail); - assertEquals(entry1.mStarred, entry2.mStarred); - assertEquals(entry1.mPinned, entry2.mPinned); - assertAggregationDataListEquals(entry1.mAggregationDatas, entry2.mAggregationDatas); - assertFieldDataListEquals(entry1.mFieldDatas, entry2.mFieldDatas); - } - - private void assertRawContactInfoEquals(RawContactInfo contact1, RawContactInfo contact2) { - assertEquals(contact1.mBackupId, contact2.mBackupId); - assertEquals(contact1.mAccountType, contact2.mAccountType); - assertEquals(contact1.mAccountName, contact2.mAccountName); - assertEquals(contact1.mDataSet, contact2.mDataSet); - } - - private void assertAggregationDataListEquals(ArrayList aggregationList1, - ArrayList aggregationList2) { - assertEquals(aggregationList1.size(), aggregationList2.size()); - for (int i = 0; i < aggregationList1.size(); i++) { - assertAggregationDataEquals(aggregationList1.get(i), aggregationList2.get(i)); - } - } - - private void assertAggregationDataEquals(AggregationData aggregationData1, - AggregationData aggregationData2) { - assertRawContactInfoEquals(aggregationData1.mRawContactInfo1, - aggregationData2.mRawContactInfo1); - assertRawContactInfoEquals(aggregationData1.mRawContactInfo2, - aggregationData2.mRawContactInfo2); - assertEquals(aggregationData1.mType, aggregationData2.mType); - } - - private void assertFieldDataListEquals(ArrayList fieldDataList1, - ArrayList fieldDataList2) { - assertEquals(fieldDataList1.size(), fieldDataList2.size()); - for (int i = 0; i < fieldDataList1.size(); i++) { - assertFieldDataEquals(fieldDataList1.get(i), fieldDataList2.get(i)); - } - } - - private void assertFieldDataEquals(FieldData fieldData1, FieldData fieldData2) { - assertEquals(fieldData1.mDataHashId, fieldData2.mDataHashId); - assertEquals(fieldData1.mIsPrimary, fieldData2.mIsPrimary); - assertEquals(fieldData1.mIsSuperPrimary, fieldData2.mIsSuperPrimary); - assertUsageStatsListEquals(fieldData1.mUsageStatsList, fieldData2.mUsageStatsList); - } - - private void assertUsageStatsListEquals(ArrayList usageStatsList1, - ArrayList usageStatsList2) { - assertEquals(usageStatsList1.size(), usageStatsList2.size()); - for (int i = 0; i < usageStatsList1.size(); i++) { - assertUsageStatsEquals(usageStatsList1.get(i), usageStatsList2.get(i)); - } - } - - private void assertUsageStatsEquals(UsageStats usageStats1, UsageStats usageStats2) { - assertEquals(usageStats1.mUsageType, usageStats2.mUsageType); - assertEquals(usageStats1.mLastTimeUsed, usageStats2.mLastTimeUsed); - assertEquals(usageStats1.mTimesUsed, usageStats2.mTimesUsed); - } -} -- cgit v1.1