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