Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.contacts.common.model.account; |
| 18 | |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 19 | import android.accounts.AuthenticatorDescription; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.util.Log; |
| 22 | |
| 23 | import com.android.contacts.common.R; |
| 24 | import com.android.contacts.common.model.dataitem.DataKind; |
Walter Jang | 3a0b483 | 2016-10-12 11:02:54 -0700 | [diff] [blame] | 25 | import com.android.contactsbind.FeedbackHelper; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 26 | |
| 27 | public 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 Wang | 48e108d | 2016-06-30 12:25:06 -0700 | [diff] [blame] | 34 | this.iconRes = R.drawable.ic_device; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 35 | |
| 36 | // Note those are only set for unit tests. |
| 37 | this.resourcePackageName = resPackageName; |
| 38 | this.syncAdapterPackageName = resPackageName; |
| 39 | |
| 40 | try { |
| 41 | addDataKindStructuredName(context); |
Gary Mai | 7a6daea | 2016-10-10 15:41:48 -0700 | [diff] [blame] | 42 | addDataKindName(context); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 43 | 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 Jang | 33ec69b | 2016-03-14 14:49:37 -0700 | [diff] [blame] | 54 | addDataKindGroupMembership(context); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 55 | |
| 56 | mIsInitialized = true; |
| 57 | } catch (DefinitionException e) { |
Walter Jang | 3a0b483 | 2016-10-12 11:02:54 -0700 | [diff] [blame] | 58 | FeedbackHelper.sendFeedback(context, TAG, "Failed to build fallback account type", e); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 59 | } |
| 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 Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 71 | static AccountType createWithPackageNameForTest(Context context, String resPackageName) { |
| 72 | return new FallbackAccountType(context, resPackageName); |
| 73 | } |
| 74 | |
| 75 | @Override |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 76 | 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 Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 82 | public boolean areContactsWritable() { |
| 83 | return true; |
| 84 | } |
| 85 | } |