Home | History | Annotate | Download | only in account
      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 
     19 import android.content.Context;
     20 import android.util.Log;
     21 
     22 import com.android.contacts.common.R;
     23 import com.android.contacts.common.model.dataitem.DataKind;
     24 import com.android.contacts.common.test.NeededForTesting;
     25 
     26 public class FallbackAccountType extends BaseAccountType {
     27     private static final String TAG = "FallbackAccountType";
     28 
     29     private FallbackAccountType(Context context, String resPackageName) {
     30         this.accountType = null;
     31         this.dataSet = null;
     32         this.titleRes = R.string.account_phone;
     33         this.iconRes = R.mipmap.ic_launcher_contacts;
     34 
     35         // Note those are only set for unit tests.
     36         this.resourcePackageName = resPackageName;
     37         this.syncAdapterPackageName = resPackageName;
     38 
     39         try {
     40             addDataKindStructuredName(context);
     41             addDataKindDisplayName(context);
     42             addDataKindPhoneticName(context);
     43             addDataKindNickname(context);
     44             addDataKindPhone(context);
     45             addDataKindEmail(context);
     46             addDataKindStructuredPostal(context);
     47             addDataKindIm(context);
     48             addDataKindOrganization(context);
     49             addDataKindPhoto(context);
     50             addDataKindNote(context);
     51             addDataKindWebsite(context);
     52             addDataKindSipAddress(context);
     53 
     54             mIsInitialized = true;
     55         } catch (DefinitionException e) {
     56             Log.e(TAG, "Problem building account type", e);
     57         }
     58     }
     59 
     60     public FallbackAccountType(Context context) {
     61         this(context, null);
     62     }
     63 
     64     /**
     65      * Used to compare with an {@link ExternalAccountType} built from a test contacts.xml.
     66      * In order to build {@link DataKind}s with the same resource package name,
     67      * {@code resPackageName} is injectable.
     68      */
     69     @NeededForTesting
     70     static AccountType createWithPackageNameForTest(Context context, String resPackageName) {
     71         return new FallbackAccountType(context, resPackageName);
     72     }
     73 
     74     @Override
     75     public boolean areContactsWritable() {
     76         return true;
     77     }
     78 }
     79