• 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.app.calllog.calllogcache;
18 
19 import android.content.Context;
20 import android.support.annotation.Nullable;
21 import android.telecom.PhoneAccountHandle;
22 import android.text.TextUtils;
23 import android.util.ArrayMap;
24 import com.android.dialer.calllogutils.PhoneAccountUtils;
25 import com.android.dialer.telecom.TelecomUtil;
26 import java.util.Map;
27 
28 /**
29  * This is the CallLogCache for versions of dialer Lollipop Mr1 and above with support for multi-SIM
30  * devices.
31  *
32  * <p>This class should not be initialized directly and instead be acquired from {@link
33  * CallLogCache#getCallLogCache}.
34  */
35 class CallLogCacheLollipopMr1 extends CallLogCache {
36 
37   private final Map<PhoneAccountHandle, String> mPhoneAccountLabelCache = new ArrayMap<>();
38   private final Map<PhoneAccountHandle, Integer> mPhoneAccountColorCache = new ArrayMap<>();
39   private final Map<PhoneAccountHandle, Boolean> mPhoneAccountCallWithNoteCache = new ArrayMap<>();
40 
CallLogCacheLollipopMr1(Context context)41   /* package */ CallLogCacheLollipopMr1(Context context) {
42     super(context);
43   }
44 
45   @Override
reset()46   public void reset() {
47     mPhoneAccountLabelCache.clear();
48     mPhoneAccountColorCache.clear();
49     mPhoneAccountCallWithNoteCache.clear();
50 
51     super.reset();
52   }
53 
54   @Override
isVoicemailNumber( PhoneAccountHandle accountHandle, @Nullable CharSequence number)55   public boolean isVoicemailNumber(
56       PhoneAccountHandle accountHandle, @Nullable CharSequence number) {
57     if (TextUtils.isEmpty(number)) {
58       return false;
59     }
60     return TelecomUtil.isVoicemailNumber(mContext, accountHandle, number.toString());
61   }
62 
63   @Override
getAccountLabel(PhoneAccountHandle accountHandle)64   public String getAccountLabel(PhoneAccountHandle accountHandle) {
65     if (mPhoneAccountLabelCache.containsKey(accountHandle)) {
66       return mPhoneAccountLabelCache.get(accountHandle);
67     } else {
68       String label = PhoneAccountUtils.getAccountLabel(mContext, accountHandle);
69       mPhoneAccountLabelCache.put(accountHandle, label);
70       return label;
71     }
72   }
73 
74   @Override
getAccountColor(PhoneAccountHandle accountHandle)75   public int getAccountColor(PhoneAccountHandle accountHandle) {
76     if (mPhoneAccountColorCache.containsKey(accountHandle)) {
77       return mPhoneAccountColorCache.get(accountHandle);
78     } else {
79       Integer color = PhoneAccountUtils.getAccountColor(mContext, accountHandle);
80       mPhoneAccountColorCache.put(accountHandle, color);
81       return color;
82     }
83   }
84 
85   @Override
doesAccountSupportCallSubject(PhoneAccountHandle accountHandle)86   public boolean doesAccountSupportCallSubject(PhoneAccountHandle accountHandle) {
87     if (mPhoneAccountCallWithNoteCache.containsKey(accountHandle)) {
88       return mPhoneAccountCallWithNoteCache.get(accountHandle);
89     } else {
90       Boolean supportsCallWithNote =
91           PhoneAccountUtils.getAccountSupportsCallSubject(mContext, accountHandle);
92       mPhoneAccountCallWithNoteCache.put(accountHandle, supportsCallWithNote);
93       return supportsCallWithNote;
94     }
95   }
96 }
97