Java Code Examples for com.android.providers.contacts.MetadataEntryParser

Following code examples demonstrate how to use com.android.providers.contacts.MetadataEntryParserfrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use com.android.providers.contacts.MetadataEntryParserand various code implementation of this class.

    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) {
        }
    } 


    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) {
        }
    } 

    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<AggregationData> 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<UsageStats> usageStats1List = new ArrayList<>();
        usageStats1List.add(usageStats1_1);
        usageStats1List.add(usageStats1_2);
        FieldData fieldData1 = new FieldData(dataHashId1, true, true, usageStats1List);

        ArrayList<UsageStats> usageStats2List = new ArrayList<>();
        usageStats2List.add(usageStats2);
        FieldData fieldData2 = new FieldData(dataHashId2, false, false, usageStats2List);

        ArrayList<FieldData> 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 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) {
        }
    } 

    public void testErrorForEmptyInput() {
        try {
            MetadataEntryParser.parseDataToMetaDataEntry("");
        } catch (IllegalArgumentException e) {
        }
    } 

    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) {
        }
    } 

    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\": \"\"}]" +
                "}"; 

    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) {
        }
    }