blob: 39f767d94db8da4214666458df990e64970050e8 [file] [log] [blame]
Chiao Chenge88fcd32012-11-13 18:38:05 -08001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.contacts.common.model.account;
18
Marcus Hagerottfac695a2016-08-24 17:02:40 -070019import android.accounts.AuthenticatorDescription;
Chiao Chenge88fcd32012-11-13 18:38:05 -080020import android.content.Context;
21import android.util.Log;
22
23import com.android.contacts.common.R;
24import com.android.contacts.common.model.dataitem.DataKind;
Walter Jang3a0b4832016-10-12 11:02:54 -070025import com.android.contactsbind.FeedbackHelper;
Chiao Chenge88fcd32012-11-13 18:38:05 -080026
27public class FallbackAccountType extends BaseAccountType {
28 private static final String TAG = "FallbackAccountType";
29
30 private FallbackAccountType(Context context, String resPackageName) {
31 this.accountType = null;
32 this.dataSet = null;
33 this.titleRes = R.string.account_phone;
Wenyi Wang48e108d2016-06-30 12:25:06 -070034 this.iconRes = R.drawable.ic_device;
Chiao Chenge88fcd32012-11-13 18:38:05 -080035
36 // Note those are only set for unit tests.
37 this.resourcePackageName = resPackageName;
38 this.syncAdapterPackageName = resPackageName;
39
40 try {
41 addDataKindStructuredName(context);
Gary Mai7a6daea2016-10-10 15:41:48 -070042 addDataKindName(context);
Chiao Chenge88fcd32012-11-13 18:38:05 -080043 addDataKindPhoneticName(context);
44 addDataKindNickname(context);
45 addDataKindPhone(context);
46 addDataKindEmail(context);
47 addDataKindStructuredPostal(context);
48 addDataKindIm(context);
49 addDataKindOrganization(context);
50 addDataKindPhoto(context);
51 addDataKindNote(context);
52 addDataKindWebsite(context);
53 addDataKindSipAddress(context);
Walter Jang33ec69b2016-03-14 14:49:37 -070054 addDataKindGroupMembership(context);
Chiao Chenge88fcd32012-11-13 18:38:05 -080055
56 mIsInitialized = true;
57 } catch (DefinitionException e) {
Walter Jang3a0b4832016-10-12 11:02:54 -070058 FeedbackHelper.sendFeedback(context, TAG, "Failed to build fallback account type", e);
Chiao Chenge88fcd32012-11-13 18:38:05 -080059 }
60 }
61
62 public FallbackAccountType(Context context) {
63 this(context, null);
64 }
65
66 /**
67 * Used to compare with an {@link ExternalAccountType} built from a test contacts.xml.
68 * In order to build {@link DataKind}s with the same resource package name,
69 * {@code resPackageName} is injectable.
70 */
Chiao Chenge88fcd32012-11-13 18:38:05 -080071 static AccountType createWithPackageNameForTest(Context context, String resPackageName) {
72 return new FallbackAccountType(context, resPackageName);
73 }
74
75 @Override
Marcus Hagerottfac695a2016-08-24 17:02:40 -070076 public void initializeFieldsFromAuthenticator(AuthenticatorDescription authenticator) {
77 // Do nothing. For "Device" accounts we want to just display them using our own strings
78 // and icons.
79 }
80
81 @Override
Chiao Chenge88fcd32012-11-13 18:38:05 -080082 public boolean areContactsWritable() {
83 return true;
84 }
85}