Home | History | Annotate | Download | only in calllogcache
      1 /*
      2  * Copyright (C) 2015 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.dialer.calllog.calllogcache;
     18 
     19 import android.content.Context;
     20 import android.telecom.PhoneAccountHandle;
     21 
     22 import com.android.contacts.common.CallUtil;
     23 import com.android.contacts.common.compat.CompatUtils;
     24 import com.android.dialer.calllog.CallLogAdapter;
     25 
     26 /**
     27  * This is the base class for the CallLogCaches.
     28  *
     29  * Keeps a cache of recently made queries to the Telecom/Telephony processes. The aim of this cache
     30  * is to reduce the number of cross-process requests to TelecomManager, which can negatively affect
     31  * performance.
     32  *
     33  * This is designed with the specific use case of the {@link CallLogAdapter} in mind.
     34  */
     35 public abstract class CallLogCache {
     36     // TODO: Dialer should be fixed so as not to check isVoicemail() so often but at the time of
     37     // this writing, that was a much larger undertaking than creating this cache.
     38 
     39     protected final Context mContext;
     40 
     41     private boolean mHasCheckedForVideoEnabled;
     42     private boolean mIsVideoEnabled;
     43 
     44     public CallLogCache(Context context) {
     45         mContext = context;
     46     }
     47 
     48     /**
     49      * Return the most compatible version of the TelecomCallLogCache.
     50      */
     51     public static CallLogCache getCallLogCache(Context context) {
     52         if (CompatUtils.isClassAvailable("android.telecom.PhoneAccountHandle")) {
     53             return new CallLogCacheLollipopMr1(context);
     54         }
     55         return new CallLogCacheLollipop(context);
     56     }
     57 
     58     public void reset() {
     59         mHasCheckedForVideoEnabled = false;
     60         mIsVideoEnabled = false;
     61     }
     62 
     63     /**
     64      * Returns true if the given number is the number of the configured voicemail. To be able to
     65      * mock-out this, it is not a static method.
     66      */
     67     public abstract boolean isVoicemailNumber(PhoneAccountHandle accountHandle,
     68             CharSequence number);
     69 
     70     public boolean isVideoEnabled() {
     71         if (!mHasCheckedForVideoEnabled) {
     72             mIsVideoEnabled = CallUtil.isVideoEnabled(mContext);
     73             mHasCheckedForVideoEnabled = true;
     74         }
     75         return mIsVideoEnabled;
     76     }
     77 
     78     /**
     79      * Extract account label from PhoneAccount object.
     80      */
     81     public abstract String getAccountLabel(PhoneAccountHandle accountHandle);
     82 
     83     /**
     84      * Extract account color from PhoneAccount object.
     85      */
     86     public abstract int getAccountColor(PhoneAccountHandle accountHandle);
     87 
     88     /**
     89      * Determines if the PhoneAccount supports specifying a call subject (i.e. calling with a note)
     90      * for outgoing calls.
     91      *
     92      * @param accountHandle The PhoneAccount handle.
     93      * @return {@code true} if calling with a note is supported, {@code false} otherwise.
     94      */
     95     public abstract boolean doesAccountSupportCallSubject(PhoneAccountHandle accountHandle);
     96 }
     97