summaryrefslogtreecommitdiff
path: root/src/com/android
diff options
context:
space:
mode:
authorAndrew Lee <anwlee@google.com>2015-06-25 16:53:56 -0700
committerAndrew Lee <anwlee@google.com>2015-06-26 16:42:09 -0700
commitd3f6a6c56dec7d47bae1121ed1030f67c26736fe (patch)
tree8cfb3c4141d56449711e95aecebe6ed832f74802 /src/com/android
parent0feab0229c1c70248ca411d0e95f79aa2ac70c00 (diff)
Cache repeated Telecom requests from call log.
This improves call log scrolling performance. + Split "Wrapper" into a utility and a cache. + Use cache for repeated calls related to call logs. + In the process of fixing plumbing and typer, moved some phone call detail classes into the more appropriate call log package. + Update tests. Bug: 20524705 Change-Id: Ib8ee21e417c19f98f6474a5793416e8f99103b55
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/dialer/CallDetailActivity.java11
-rw-r--r--src/com/android/dialer/calllog/CallLogAdapter.java30
-rw-r--r--src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java8
-rw-r--r--src/com/android/dialer/calllog/CallLogListItemHelper.java16
-rw-r--r--src/com/android/dialer/calllog/CallLogListItemViewHolder.java30
-rw-r--r--src/com/android/dialer/calllog/PhoneAccountUtils.java4
-rw-r--r--src/com/android/dialer/calllog/PhoneCallDetailsHelper.java (renamed from src/com/android/dialer/PhoneCallDetailsHelper.java)24
-rw-r--r--src/com/android/dialer/calllog/PhoneCallDetailsViews.java (renamed from src/com/android/dialer/PhoneCallDetailsViews.java)4
-rw-r--r--src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java3
-rw-r--r--src/com/android/dialer/calllog/TelecomCallLogCache.java124
-rw-r--r--src/com/android/dialer/util/PhoneNumberUtil.java (renamed from src/com/android/dialer/calllog/PhoneNumberUtilsWrapper.java)62
11 files changed, 203 insertions, 113 deletions
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java
index b851372c0..734e78f46 100644
--- a/src/com/android/dialer/CallDetailActivity.java
+++ b/src/com/android/dialer/CallDetailActivity.java
@@ -57,9 +57,9 @@ import com.android.dialer.calllog.ContactInfo;
import com.android.dialer.calllog.ContactInfoHelper;
import com.android.dialer.calllog.PhoneAccountUtils;
import com.android.dialer.calllog.PhoneNumberDisplayUtil;
-import com.android.dialer.calllog.PhoneNumberUtilsWrapper;
-import com.android.dialer.util.IntentUtil;
import com.android.dialer.util.DialerUtils;
+import com.android.dialer.util.IntentUtil;
+import com.android.dialer.util.PhoneNumberUtil;
import com.android.dialer.util.TelecomUtil;
import java.util.List;
@@ -116,11 +116,10 @@ public class CallDetailActivity extends Activity
// Cache the details about the phone number.
final boolean canPlaceCallsTo =
- PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation);
- final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(mContext);
+ PhoneNumberUtil.canPlaceCallsTo(mNumber, numberPresentation);
mIsVoicemailNumber =
- phoneUtils.isVoicemailNumber(accountHandle, mNumber);
- final boolean isSipNumber = PhoneNumberUtilsWrapper.isSipNumber(mNumber);
+ PhoneNumberUtil.isVoicemailNumber(mContext, accountHandle, mNumber);
+ final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber);
final CharSequence callLocationOrType = getNumberTypeOrLocation(firstDetails);
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index 2ba257a3b..bb776d29e 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -42,10 +42,10 @@ import android.view.accessibility.AccessibilityEvent;
import com.android.contacts.common.util.PermissionsUtil;
import com.android.dialer.PhoneCallDetails;
-import com.android.dialer.PhoneCallDetailsHelper;
import com.android.dialer.R;
import com.android.dialer.contactinfo.ContactInfoCache;
import com.android.dialer.contactinfo.ContactInfoCache.OnContactInfoChangedListener;
+import com.android.dialer.util.PhoneNumberUtil;
import com.android.dialer.voicemail.VoicemailPlaybackPresenter;
import com.google.common.annotations.VisibleForTesting;
@@ -123,10 +123,11 @@ public class CallLogAdapter extends GroupingListAdapter
private boolean mShowPromoCard = false;
/** Instance of helper class for managing views. */
- private final CallLogListItemHelper mCallLogViewsHelper;
+ private final CallLogListItemHelper mCallLogListItemHelper;
+
+ /** Cache for repeated requests to TelecomManager. */
+ protected final TelecomCallLogCache mTelecomCallLogCache;
- /** Helper to access Telephony phone number utils class */
- protected final PhoneNumberUtilsWrapper mPhoneNumberUtilsWrapper;
/** Helper to group call log entries. */
private final CallLogGroupBuilder mCallLogGroupBuilder;
@@ -256,10 +257,11 @@ public class CallLogAdapter extends GroupingListAdapter
Resources resources = mContext.getResources();
CallTypeHelper callTypeHelper = new CallTypeHelper(resources);
- mPhoneNumberUtilsWrapper = new PhoneNumberUtilsWrapper(mContext);
+ mTelecomCallLogCache = new TelecomCallLogCache(mContext);
PhoneCallDetailsHelper phoneCallDetailsHelper =
- new PhoneCallDetailsHelper(mContext, resources, mPhoneNumberUtilsWrapper);
- mCallLogViewsHelper = new CallLogListItemHelper(phoneCallDetailsHelper, resources);
+ new PhoneCallDetailsHelper(mContext, resources, mTelecomCallLogCache);
+ mCallLogListItemHelper =
+ new CallLogListItemHelper(phoneCallDetailsHelper, resources, mTelecomCallLogCache);
mCallLogGroupBuilder = new CallLogGroupBuilder(this);
mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
maybeShowVoicemailPromoCard();
@@ -329,6 +331,7 @@ public class CallLogAdapter extends GroupingListAdapter
public void pauseCache() {
mContactInfoCache.stop();
+ mTelecomCallLogCache.reset();
}
@Override
@@ -359,8 +362,8 @@ public class CallLogAdapter extends GroupingListAdapter
view,
mContext,
mExpandCollapseListener,
- mPhoneNumberUtilsWrapper,
- mCallLogViewsHelper,
+ mTelecomCallLogCache,
+ mCallLogListItemHelper,
mVoicemailPlaybackPresenter);
viewHolder.callLogEntryView.setTag(viewHolder);
@@ -432,14 +435,13 @@ public class CallLogAdapter extends GroupingListAdapter
final String countryIso = c.getString(CallLogQuery.COUNTRY_ISO);
final ContactInfo cachedContactInfo = mContactInfoHelper.getContactInfo(c);
final boolean isVoicemailNumber =
- mPhoneNumberUtilsWrapper.isVoicemailNumber(accountHandle, number);
+ mTelecomCallLogCache.isVoicemailNumber(accountHandle, number);
// Note: Binding of the action buttons is done as required in configureActionViews when the
// user expands the actions ViewStub.
ContactInfo info = ContactInfo.EMPTY;
- if (PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)
- && !isVoicemailNumber) {
+ if (PhoneNumberUtil.canPlaceCallsTo(number, numberPresentation) && !isVoicemailNumber) {
// Lookup contacts with this number
info = mContactInfoCache.getValue(number, countryIso, cachedContactInfo);
}
@@ -499,7 +501,7 @@ public class CallLogAdapter extends GroupingListAdapter
views.dayGroupHeader.setVisibility(View.GONE);
}
- mCallLogViewsHelper.setPhoneCallDetails(mContext, views, details);
+ mCallLogListItemHelper.setPhoneCallDetails(views, details);
if (mCurrentlyExpandedRowId == views.rowId) {
// In case ViewHolders were added/removed, update the expanded position if the rowIds
@@ -522,7 +524,7 @@ public class CallLogAdapter extends GroupingListAdapter
views.setPhoto(info.photoId, info.photoUri, info.lookupUri, nameForDefaultImage,
isVoicemailNumber, mContactInfoHelper.isBusiness(info.sourceType));
- mCallLogViewsHelper.setPhoneCallDetails(mContext, views, details);
+ mCallLogListItemHelper.setPhoneCallDetails(views, details);
// Listen for the first draw
if (mViewTreeObserver == null) {
diff --git a/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java b/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java
index 812e1a77a..1becc89af 100644
--- a/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java
+++ b/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java
@@ -32,6 +32,7 @@ import com.android.contacts.common.GeoUtil;
import com.android.dialer.PhoneCallDetails;
import com.android.dialer.util.AsyncTaskExecutor;
import com.android.dialer.util.AsyncTaskExecutors;
+import com.android.dialer.util.PhoneNumberUtil;
import com.android.dialer.util.TelecomUtil;
import com.google.common.annotations.VisibleForTesting;
@@ -151,12 +152,9 @@ public class CallLogAsyncTaskUtil {
// If this is not a regular number, there is no point in looking it up in the contacts.
ContactInfoHelper contactInfoHelper =
new ContactInfoHelper(context, GeoUtil.getCurrentCountryIso(context));
- PhoneNumberUtilsWrapper phoneNumberUtilsWrapper =
- new PhoneNumberUtilsWrapper(context);
- boolean isVoicemail = phoneNumberUtilsWrapper.isVoicemailNumber(accountHandle, number);
+ boolean isVoicemail = PhoneNumberUtil.isVoicemailNumber(context, accountHandle, number);
boolean shouldLookupNumber =
- PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)
- && !isVoicemail;
+ PhoneNumberUtil.canPlaceCallsTo(number, numberPresentation) && !isVoicemail;
ContactInfo info = shouldLookupNumber
? contactInfoHelper.lookupNumber(number, countryIso)
: ContactInfo.EMPTY;
diff --git a/src/com/android/dialer/calllog/CallLogListItemHelper.java b/src/com/android/dialer/calllog/CallLogListItemHelper.java
index d08810706..1c8e397e4 100644
--- a/src/com/android/dialer/calllog/CallLogListItemHelper.java
+++ b/src/com/android/dialer/calllog/CallLogListItemHelper.java
@@ -24,7 +24,6 @@ import android.text.TextUtils;
import android.util.Log;
import com.android.dialer.PhoneCallDetails;
-import com.android.dialer.PhoneCallDetailsHelper;
import com.android.dialer.R;
/**
@@ -37,6 +36,7 @@ import com.android.dialer.R;
private final PhoneCallDetailsHelper mPhoneCallDetailsHelper;
/** Resources to look up strings. */
private final Resources mResources;
+ private final TelecomCallLogCache mTelecomCallLogCache;
/**
* Creates a new helper instance.
@@ -45,9 +45,12 @@ import com.android.dialer.R;
* @param phoneNumberHelper used to process phone number
*/
public CallLogListItemHelper(
- PhoneCallDetailsHelper phoneCallDetailsHelper, Resources resources) {
+ PhoneCallDetailsHelper phoneCallDetailsHelper,
+ Resources resources,
+ TelecomCallLogCache telecomCallLogCache) {
mPhoneCallDetailsHelper = phoneCallDetailsHelper;
mResources = resources;
+ mTelecomCallLogCache = telecomCallLogCache;
}
/**
@@ -58,14 +61,15 @@ import com.android.dialer.R;
* @param details the details of a phone call needed to fill in the data
*/
public void setPhoneCallDetails(
- Context context, CallLogListItemViewHolder views, PhoneCallDetails details) {
+ CallLogListItemViewHolder views,
+ PhoneCallDetails details) {
mPhoneCallDetailsHelper.setPhoneCallDetails(views.phoneCallDetailsViews, details);
// Set the accessibility text for the contact badge
views.quickContactView.setContentDescription(getContactBadgeDescription(details));
// Set the primary action accessibility description
- views.primaryActionView.setContentDescription(getCallDescription(context, details));
+ views.primaryActionView.setContentDescription(getCallDescription(details));
// Cache name or number of caller. Used when setting the content descriptions of buttons
// when the actions ViewStub is inflated.
@@ -151,7 +155,7 @@ import com.android.dialer.R;
* @param details Details of call.
* @return Return call action description.
*/
- public CharSequence getCallDescription(Context context, PhoneCallDetails details) {
+ public CharSequence getCallDescription(PhoneCallDetails details) {
int lastCallType = getLastCallType(details.callTypes);
boolean isVoiceMail = lastCallType == Calls.VOICEMAIL_TYPE;
@@ -183,7 +187,7 @@ import com.android.dialer.R;
}
int stringID = getCallDescriptionStringID(details.callTypes);
- String accountLabel = PhoneAccountUtils.getAccountLabel(context, details.accountHandle);
+ String accountLabel = mTelecomCallLogCache.getAccountLabel(details.accountHandle);
// Use chosen string resource to build up the message.
CharSequence onAccountLabel = accountLabel == null
diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
index f54720b31..361e1c7a3 100644
--- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
+++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
@@ -39,11 +39,10 @@ import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
import com.android.contacts.common.testing.NeededForTesting;
import com.android.contacts.common.util.UriUtils;
-import com.android.dialer.PhoneCallDetailsHelper;
-import com.android.dialer.PhoneCallDetailsViews;
import com.android.dialer.R;
import com.android.dialer.calllog.CallLogAsyncTaskUtil;
import com.android.dialer.util.DialerUtils;
+import com.android.dialer.util.PhoneNumberUtil;
import com.android.dialer.voicemail.VoicemailPlaybackPresenter;
import com.android.dialer.voicemail.VoicemailPlaybackLayout;
@@ -139,7 +138,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder
private static final int VOICEMAIL_TRANSCRIPTION_MAX_LINES = 10;
private final Context mContext;
- private final PhoneNumberUtilsWrapper mPhoneNumberUtilsWrapper;
+ private final TelecomCallLogCache mTelecomCallLogCache;
private final CallLogListItemHelper mCallLogListItemHelper;
private final VoicemailPlaybackPresenter mVoicemailPlaybackPresenter;
@@ -151,7 +150,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder
private CallLogListItemViewHolder(
Context context,
View.OnClickListener expandCollapseListener,
- PhoneNumberUtilsWrapper phoneNumberUtilsWrapper,
+ TelecomCallLogCache telecomCallLogCache,
CallLogListItemHelper callLogListItemHelper,
VoicemailPlaybackPresenter voicemailPlaybackPresenter,
View rootView,
@@ -165,7 +164,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder
mContext = context;
mExpandCollapseListener = expandCollapseListener;
- mPhoneNumberUtilsWrapper = phoneNumberUtilsWrapper;
+ mTelecomCallLogCache = telecomCallLogCache;
mCallLogListItemHelper = callLogListItemHelper;
mVoicemailPlaybackPresenter = voicemailPlaybackPresenter;
@@ -194,14 +193,14 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder
View view,
Context context,
View.OnClickListener expandCollapseListener,
- PhoneNumberUtilsWrapper phoneNumberUtilsWrapper,
+ TelecomCallLogCache telecomCallLogCache,
CallLogListItemHelper callLogListItemHelper,
VoicemailPlaybackPresenter voicemailPlaybackPresenter) {
return new CallLogListItemViewHolder(
context,
expandCollapseListener,
- phoneNumberUtilsWrapper,
+ telecomCallLogCache,
callLogListItemHelper,
voicemailPlaybackPresenter,
view,
@@ -263,11 +262,11 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder
} else {
// Treat as normal list item; show call button, if possible.
boolean canPlaceCallToNumber =
- PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation);
+ PhoneNumberUtil.canPlaceCallsTo(number, numberPresentation);
if (canPlaceCallToNumber) {
boolean isVoicemailNumber =
- mPhoneNumberUtilsWrapper.isVoicemailNumber(accountHandle, number);
+ mTelecomCallLogCache.isVoicemailNumber(accountHandle, number);
if (isVoicemailNumber) {
// Call to generic voicemail number, in case there are multiple accounts.
primaryActionButtonView.setTag(
@@ -294,8 +293,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder
* buttons.
*/
private void bindActionButtons() {
- boolean canPlaceCallToNumber =
- PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation);
+ boolean canPlaceCallToNumber = PhoneNumberUtil.canPlaceCallsTo(number, numberPresentation);
if (!TextUtils.isEmpty(voicemailUri) && canPlaceCallToNumber) {
callButtonView.setTag(IntentProvider.getReturnCallIntentProvider(number));
@@ -309,7 +307,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder
}
// If one of the calls had video capabilities, show the video call button.
- if (CallUtil.isVideoEnabled(mContext) && canPlaceCallToNumber &&
+ if (mTelecomCallLogCache.isVideoEnabled() && canPlaceCallToNumber &&
phoneCallDetailsViews.callTypeIcons.isVideoShown()) {
videoCallButtonView.setTag(IntentProvider.getReturnVideoCallIntentProvider(number));
videoCallButtonView.setVisibility(View.VISIBLE);
@@ -440,15 +438,15 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder
@NeededForTesting
public static CallLogListItemViewHolder createForTest(Context context) {
Resources resources = context.getResources();
- PhoneNumberUtilsWrapper phoneNumberUtilsWrapper = new PhoneNumberUtilsWrapper(context);
+ TelecomCallLogCache telecomCallLogCache = new TelecomCallLogCache(context);
PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper(
- context, resources, phoneNumberUtilsWrapper);
+ context, resources, telecomCallLogCache);
CallLogListItemViewHolder viewHolder = new CallLogListItemViewHolder(
context,
null /* expandCollapseListener */,
- phoneNumberUtilsWrapper,
- new CallLogListItemHelper(phoneCallDetailsHelper, resources),
+ telecomCallLogCache,
+ new CallLogListItemHelper(phoneCallDetailsHelper, resources, telecomCallLogCache),
null /* voicemailPlaybackPresenter */,
new View(context),
new QuickContactBadge(context),
diff --git a/src/com/android/dialer/calllog/PhoneAccountUtils.java b/src/com/android/dialer/calllog/PhoneAccountUtils.java
index d63b940e7..7eaa523f4 100644
--- a/src/com/android/dialer/calllog/PhoneAccountUtils.java
+++ b/src/com/android/dialer/calllog/PhoneAccountUtils.java
@@ -27,7 +27,7 @@ import java.util.ArrayList;
import java.util.List;
/**
- * Methods to help extract {@code PhoneAccount} information from database and Telecomm sources
+ * Methods to help extract {@code PhoneAccount} information from database and Telecomm sources.
*/
public class PhoneAccountUtils {
/**
@@ -87,7 +87,7 @@ public class PhoneAccountUtils {
* Retrieve the account metadata, but if the account does not exist or the device has only a
* single registered and enabled account, return null.
*/
- private static PhoneAccount getAccountOrNull(Context context,
+ static PhoneAccount getAccountOrNull(Context context,
PhoneAccountHandle accountHandle) {
TelecomManager telecomManager =
(TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
diff --git a/src/com/android/dialer/PhoneCallDetailsHelper.java b/src/com/android/dialer/calllog/PhoneCallDetailsHelper.java
index 2dc0810e8..df5fe0606 100644
--- a/src/com/android/dialer/PhoneCallDetailsHelper.java
+++ b/src/com/android/dialer/calllog/PhoneCallDetailsHelper.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.dialer;
+package com.android.dialer.calllog;
import android.content.Context;
import android.content.res.Resources;
@@ -31,10 +31,10 @@ import android.widget.TextView;
import com.android.contacts.common.testing.NeededForTesting;
import com.android.contacts.common.util.PhoneNumberHelper;
-import com.android.dialer.calllog.ContactInfo;
-import com.android.dialer.calllog.PhoneAccountUtils;
-import com.android.dialer.calllog.PhoneNumberUtilsWrapper;
+import com.android.dialer.PhoneCallDetails;
+import com.android.dialer.R;
import com.android.dialer.util.DialerUtils;
+import com.android.dialer.util.PhoneNumberUtil;
import com.google.common.collect.Lists;
@@ -51,8 +51,7 @@ public class PhoneCallDetailsHelper {
private final Resources mResources;
/** The injected current time in milliseconds since the epoch. Used only by tests. */
private Long mCurrentTimeMillisForTest;
- // Helper classes.
- private final PhoneNumberUtilsWrapper mPhoneNumberUtilsWrapper;
+ private final TelecomCallLogCache mTelecomCallLogCache;
/**
* List of items to be concatenated together for accessibility descriptions
@@ -66,11 +65,13 @@ public class PhoneCallDetailsHelper {
*
* @param resources used to look up strings
*/
- public PhoneCallDetailsHelper(Context context, Resources resources,
- PhoneNumberUtilsWrapper phoneUtils) {
+ public PhoneCallDetailsHelper(
+ Context context,
+ Resources resources,
+ TelecomCallLogCache telecomCallLogCache) {
mContext = context;
mResources = resources;
- mPhoneNumberUtilsWrapper = phoneUtils;
+ mTelecomCallLogCache = telecomCallLogCache;
}
/** Fills the call details views with content. */
@@ -106,7 +107,7 @@ public class PhoneCallDetailsHelper {
setCallCountAndDate(views, callCount, callLocationAndDate);
// Set the account label if it exists.
- String accountLabel = PhoneAccountUtils.getAccountLabel(mContext, details.accountHandle);
+ String accountLabel = mTelecomCallLogCache.getAccountLabel(details.accountHandle);
if (accountLabel != null) {
views.callAccountLabel.setVisibility(View.VISIBLE);
@@ -185,8 +186,7 @@ public class PhoneCallDetailsHelper {
// Only show a label if the number is shown and it is not a SIP address.
if (!TextUtils.isEmpty(details.number)
&& !PhoneNumberHelper.isUriNumber(details.number.toString())
- && !mPhoneNumberUtilsWrapper.isVoicemailNumber(details.accountHandle,
- details.number)) {
+ && !mTelecomCallLogCache.isVoicemailNumber(details.accountHandle, details.number)) {
if (TextUtils.isEmpty(details.name) && !TextUtils.isEmpty(details.geocode)) {
numberFormattedLabel = details.geocode;
diff --git a/src/com/android/dialer/PhoneCallDetailsViews.java b/src/com/android/dialer/calllog/PhoneCallDetailsViews.java
index 05026d6ee..94f4411b0 100644
--- a/src/com/android/dialer/PhoneCallDetailsViews.java
+++ b/src/com/android/dialer/calllog/PhoneCallDetailsViews.java
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package com.android.dialer;
+package com.android.dialer.calllog;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
-import com.android.dialer.calllog.CallTypeIconsView;
+import com.android.dialer.R;
/**
* Encapsulates the views that are used to display the details of a phone call in the call log.
diff --git a/src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java b/src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java
index f80c2bc6a..5030efd48 100644
--- a/src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java
+++ b/src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java
@@ -23,6 +23,7 @@ import android.text.TextUtils;
import android.util.Log;
import com.android.dialer.R;
+import com.android.dialer.util.PhoneNumberUtil;
/**
* Helper for formatting and managing the display of phone numbers.
@@ -49,7 +50,7 @@ public class PhoneNumberDisplayUtil {
if (isVoicemail) {
return context.getResources().getString(R.string.voicemail);
}
- if (PhoneNumberUtilsWrapper.isLegacyUnknownNumbers(number)) {
+ if (PhoneNumberUtil.isLegacyUnknownNumbers(number)) {
return context.getResources().getString(R.string.unknown);
}
return "";
diff --git a/src/com/android/dialer/calllog/TelecomCallLogCache.java b/src/com/android/dialer/calllog/TelecomCallLogCache.java
new file mode 100644
index 000000000..ec1d24191
--- /dev/null
+++ b/src/com/android/dialer/calllog/TelecomCallLogCache.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.dialer.calllog;
+
+import android.content.Context;
+import android.provider.CallLog;
+import android.telecom.PhoneAccount;
+import android.telecom.PhoneAccountHandle;
+import android.telecom.TelecomManager;
+import android.text.TextUtils;
+import android.util.Log;
+import android.util.Pair;
+
+import com.android.contacts.common.CallUtil;
+import com.android.contacts.common.util.PhoneNumberHelper;
+import com.android.dialer.util.PhoneNumberUtil;
+import com.google.common.collect.Sets;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Keeps a cache of recently made queries to the Telecom process. The aim of this cache is to
+ * reduce the number of cross-process requests to TelecomManager, which can negatively affect
+ * performance.
+ *
+ * This is designed with the specific use case of the {@link CallLogAdapter} in mind.
+ */
+public class TelecomCallLogCache {
+ private final Context mContext;
+
+ // Maps from a phone-account/number pair to a boolean because multiple numbers could return true
+ // for the voicemail number if those numbers are not pre-normalized.
+ // TODO: Dialer should be fixed so as not to check isVoicemail() so often but at the time of
+ // this writing, that was a much larger undertaking than creating this cache.
+ private final Map<Pair<PhoneAccountHandle, CharSequence>, Boolean> mVoicemailQueryCache =
+ new HashMap<>();
+ private final Map<PhoneAccountHandle, String> mPhoneAccountLabelCache = new HashMap<>();
+ private final Map<PhoneAccountHandle, Integer> mPhoneAccountColorCache = new HashMap<>();
+
+ private boolean mHasCheckedForVideoEnabled;
+ private boolean mIsVideoEnabled;
+
+ public TelecomCallLogCache(Context context) {
+ mContext = context;
+ }
+
+ public void reset() {
+ mVoicemailQueryCache.clear();
+ mPhoneAccountLabelCache.clear();
+ mPhoneAccountColorCache.clear();
+
+ mHasCheckedForVideoEnabled = false;
+ mIsVideoEnabled = false;
+ }
+
+ /**
+ * Returns true if the given number is the number of the configured voicemail. To be able to
+ * mock-out this, it is not a static method.
+ */
+ public boolean isVoicemailNumber(PhoneAccountHandle accountHandle, CharSequence number) {
+ if (TextUtils.isEmpty(number)) {
+ return false;
+ }
+
+ Pair<PhoneAccountHandle, CharSequence> key = new Pair<>(accountHandle, number);
+ if (mVoicemailQueryCache.containsKey(key)) {
+ return mVoicemailQueryCache.get(key);
+ } else {
+ Boolean isVoicemail =
+ PhoneNumberUtil.isVoicemailNumber(mContext, accountHandle, number.toString());
+ mVoicemailQueryCache.put(key, isVoicemail);
+ return isVoicemail;
+ }
+ }
+
+ /**
+ * Extract account label from PhoneAccount object.
+ */
+ public String getAccountLabel(PhoneAccountHandle accountHandle) {
+ if (mPhoneAccountLabelCache.containsKey(accountHandle)) {
+ return mPhoneAccountLabelCache.get(accountHandle);
+ } else {
+ String label = PhoneAccountUtils.getAccountLabel(mContext, accountHandle);
+ mPhoneAccountLabelCache.put(accountHandle, label);
+ return label;
+ }
+ }
+
+ /**
+ * Extract account color from PhoneAccount object.
+ */
+ public int getAccountColor(PhoneAccountHandle accountHandle) {
+ if (mPhoneAccountColorCache.containsKey(accountHandle)) {
+ return mPhoneAccountColorCache.get(accountHandle);
+ } else {
+ Integer color = PhoneAccountUtils.getAccountColor(mContext, accountHandle);
+ mPhoneAccountColorCache.put(accountHandle, color);
+ return color;
+ }
+ }
+
+ public boolean isVideoEnabled() {
+ if (!mHasCheckedForVideoEnabled) {
+ mIsVideoEnabled = CallUtil.isVideoEnabled(mContext);
+ }
+ return mIsVideoEnabled;
+ }
+}
diff --git a/src/com/android/dialer/calllog/PhoneNumberUtilsWrapper.java b/src/com/android/dialer/util/PhoneNumberUtil.java
index 6fa81435f..84f58aa85 100644
--- a/src/com/android/dialer/calllog/PhoneNumberUtilsWrapper.java
+++ b/src/com/android/dialer/util/PhoneNumberUtil.java
@@ -14,7 +14,7 @@
* limitations under the License
*/
-package com.android.dialer.calllog;
+package com.android.dialer.util;
import android.content.Context;
import android.provider.CallLog;
@@ -31,28 +31,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-/**
- *
- */
-public class PhoneNumberUtilsWrapper {
+public class PhoneNumberUtil {
private static final Set<String> LEGACY_UNKNOWN_NUMBERS = Sets.newHashSet("-1", "-2", "-3");
- private static final long MAX_VOICEMAIL_CACHE_AGE_IN_MS = 60 * 1000; // 60 seconds
- private final Context mContext;
-
- // Keeps a cache of recently-made voicemail queries. The entire point of this cache is to
- // reduce the number of cross-process requests to TelecomManager.
- // Maps from a phone-account/number pair to a boolean because multiple numbers could return true
- // for the voicemail number if those numbers are not pre-normalized.
- //
- // TODO: Dialer should be fixed so as not to check isVoicemail() so often but at the time of
- // this writing, that was a much larger undertaking than creating this cache.
- private final Map<Pair<PhoneAccountHandle, CharSequence>, Boolean> mVoicemailQueryCache =
- new HashMap<>();
- private long mVoicemailCacheTimestamp = 0;
-
- public PhoneNumberUtilsWrapper(Context context) {
- mContext = context;
- }
/** Returns true if it is possible to place a call to the given number. */
public static boolean canPlaceCallsTo(CharSequence number, int presentation) {
@@ -64,34 +44,15 @@ public class PhoneNumberUtilsWrapper {
* Returns true if the given number is the number of the configured voicemail. To be able to
* mock-out this, it is not a static method.
*/
- public boolean isVoicemailNumber(PhoneAccountHandle accountHandle, CharSequence number) {
+ public static boolean isVoicemailNumber(
+ Context context, PhoneAccountHandle accountHandle, CharSequence number) {
if (TextUtils.isEmpty(number)) {
return false;
}
- long currentTime = System.currentTimeMillis();
- // check the age of the voicemail cache first.
- if (currentTime - mVoicemailCacheTimestamp > MAX_VOICEMAIL_CACHE_AGE_IN_MS) {
- mVoicemailQueryCache.clear();
-
- // We set the timestamp of the voicemail cache to the point where the cache is recreated
- // instead of when an item is added.
- // 1) This is easier to write
- // 2) Ensures that the oldest entry is never older than MAX_VOICEMAIL_CACHE_AGE
- mVoicemailCacheTimestamp = currentTime;
- }
-
- Pair<PhoneAccountHandle, CharSequence> key = new Pair<>(accountHandle, number);
- if (mVoicemailQueryCache.containsKey(key)) {
- return mVoicemailQueryCache.get(key);
- } else {
- final TelecomManager telecomManager =
- (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
- Boolean isVoicemail =
- telecomManager.isVoiceMailNumber(accountHandle, number.toString());
- mVoicemailQueryCache.put(key, isVoicemail);
- return isVoicemail;
- }
+ final TelecomManager telecomManager =
+ (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
+ return telecomManager.isVoiceMailNumber(accountHandle, number.toString());
}
/**
@@ -102,8 +63,11 @@ public class PhoneNumberUtilsWrapper {
return number != null && PhoneNumberHelper.isUriNumber(number.toString());
}
- public boolean isUnknownNumberThatCanBeLookedUp(PhoneAccountHandle accountHandle,
- CharSequence number, int presentation) {
+ public static boolean isUnknownNumberThatCanBeLookedUp(
+ Context context,
+ PhoneAccountHandle accountHandle,
+ CharSequence number,
+ int presentation) {
if (presentation == CallLog.Calls.PRESENTATION_UNKNOWN) {
return false;
}
@@ -116,7 +80,7 @@ public class PhoneNumberUtilsWrapper {
if (TextUtils.isEmpty(number)) {
return false;
}
- if (isVoicemailNumber(accountHandle, number)) {
+ if (isVoicemailNumber(context, accountHandle, number)) {
return false;
}
if (isLegacyUnknownNumbers(number)) {