• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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 import android.text.TextUtils;
22 import android.util.Pair;
23 
24 import com.android.dialer.calllog.PhoneAccountUtils;
25 import com.android.dialer.util.PhoneNumberUtil;
26 
27 import java.util.HashMap;
28 import java.util.Map;
29 
30 /**
31  * This is the CallLogCache for versions of dialer Lollipop Mr1 and above with support for
32  * multi-SIM devices.
33  *
34  * This class should not be initialized directly and instead be acquired from
35  * {@link CallLogCache#getCallLogCache}.
36  */
37 class CallLogCacheLollipopMr1 extends CallLogCache {
38     // Maps from a phone-account/number pair to a boolean because multiple numbers could return true
39     // for the voicemail number if those numbers are not pre-normalized.
40     private final Map<Pair<PhoneAccountHandle, CharSequence>, Boolean> mVoicemailQueryCache =
41             new HashMap<>();
42     private final Map<PhoneAccountHandle, String> mPhoneAccountLabelCache = new HashMap<>();
43     private final Map<PhoneAccountHandle, Integer> mPhoneAccountColorCache = new HashMap<>();
44     private final Map<PhoneAccountHandle, Boolean> mPhoneAccountCallWithNoteCache = new HashMap<>();
45 
CallLogCacheLollipopMr1(Context context)46     /* package */ CallLogCacheLollipopMr1(Context context) {
47         super(context);
48     }
49 
50     @Override
reset()51     public void reset() {
52         mVoicemailQueryCache.clear();
53         mPhoneAccountLabelCache.clear();
54         mPhoneAccountColorCache.clear();
55         mPhoneAccountCallWithNoteCache.clear();
56 
57         super.reset();
58     }
59 
60     @Override
isVoicemailNumber(PhoneAccountHandle accountHandle, CharSequence number)61     public boolean isVoicemailNumber(PhoneAccountHandle accountHandle, CharSequence number) {
62         if (TextUtils.isEmpty(number)) {
63             return false;
64         }
65 
66         Pair<PhoneAccountHandle, CharSequence> key = new Pair<>(accountHandle, number);
67         if (mVoicemailQueryCache.containsKey(key)) {
68             return mVoicemailQueryCache.get(key);
69         } else {
70             Boolean isVoicemail =
71                     PhoneNumberUtil.isVoicemailNumber(mContext, accountHandle, number.toString());
72             mVoicemailQueryCache.put(key, isVoicemail);
73             return isVoicemail;
74         }
75     }
76 
77     @Override
getAccountLabel(PhoneAccountHandle accountHandle)78     public String getAccountLabel(PhoneAccountHandle accountHandle) {
79         if (mPhoneAccountLabelCache.containsKey(accountHandle)) {
80             return mPhoneAccountLabelCache.get(accountHandle);
81         } else {
82             String label = PhoneAccountUtils.getAccountLabel(mContext, accountHandle);
83             mPhoneAccountLabelCache.put(accountHandle, label);
84             return label;
85         }
86     }
87 
88     @Override
getAccountColor(PhoneAccountHandle accountHandle)89     public int getAccountColor(PhoneAccountHandle accountHandle) {
90         if (mPhoneAccountColorCache.containsKey(accountHandle)) {
91             return mPhoneAccountColorCache.get(accountHandle);
92         } else {
93             Integer color = PhoneAccountUtils.getAccountColor(mContext, accountHandle);
94             mPhoneAccountColorCache.put(accountHandle, color);
95             return color;
96         }
97     }
98 
99     @Override
doesAccountSupportCallSubject(PhoneAccountHandle accountHandle)100     public boolean doesAccountSupportCallSubject(PhoneAccountHandle accountHandle) {
101         if (mPhoneAccountCallWithNoteCache.containsKey(accountHandle)) {
102             return mPhoneAccountCallWithNoteCache.get(accountHandle);
103         } else {
104             Boolean supportsCallWithNote =
105                     PhoneAccountUtils.getAccountSupportsCallSubject(mContext, accountHandle);
106             mPhoneAccountCallWithNoteCache.put(accountHandle, supportsCallWithNote);
107             return supportsCallWithNote;
108         }
109     }
110 }
111