Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b9bbfc41 authored by Danny Baumann's avatar Danny Baumann Committed by Gerrit Code Review
Browse files

Improve performance of call log.

Avoid binder calls in each layout pass by caching the results of
TelecomManager.getPhoneAccount() and TelecomManager.isVoiceMailNumber().
Do the latter by caching the actual voicemail number and doing the
comparison by ourselves.

Change-Id: I531cf7c9b3f0e99be8e1774605d6e0ee1ea229ab
parent f66a0fb5
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware

    private CallDetailHeader mCallDetailHeader;
    private CallTypeHelper mCallTypeHelper;
    private PhoneNumberUtilsWrapper mUtilsWrapper;
    private PhoneNumberDisplayHelper mPhoneNumberHelper;
    private AsyncTaskExecutor mAsyncTaskExecutor;
    private ContactInfoHelper mContactInfoHelper;
@@ -249,7 +250,8 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
        mResources = getResources();

        mCallTypeHelper = new CallTypeHelper(getResources());
        mPhoneNumberHelper = new PhoneNumberDisplayHelper(this, mResources);
        mUtilsWrapper = new PhoneNumberUtilsWrapper(this);
        mPhoneNumberHelper = new PhoneNumberDisplayHelper(this, mResources, mUtilsWrapper);
        mCallDetailHeader = new CallDetailHeader(this, mPhoneNumberHelper);
        mVoicemailStatusHelper = new VoicemailStatusHelperImpl();
        mAsyncQueryHandler = new CallDetailActivityQueryHandler(this);
@@ -390,11 +392,13 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
            public PhoneCallDetails[] doInBackground(Void... params) {
                // TODO: All phone calls correspond to the same person, so we can make a single
                // lookup.
                final PhoneNumberUtilsWrapper phoneUtils =
                        new PhoneNumberUtilsWrapper(CallDetailActivity.this);
                final int numCalls = callUris.length;
                PhoneCallDetails[] details = new PhoneCallDetails[numCalls];
                try {
                    for (int index = 0; index < numCalls; ++index) {
                        details[index] = getPhoneCallDetailsForUri(callUris[index]);
                        details[index] = getPhoneCallDetailsForUri(callUris[index], phoneUtils);
                    }
                    return details;
                } catch (IllegalArgumentException e) {
@@ -432,9 +436,8 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
                // Cache the details about the phone number.
                final boolean canPlaceCallsTo =
                    PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation);
                final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(context);
                final boolean isVoicemailNumber =
                        phoneUtils.isVoicemailNumber(accountHandle, mNumber);
                        mUtilsWrapper.isVoicemailNumber(accountHandle, mNumber);
                final boolean isSipNumber = PhoneNumberUtilsWrapper.isSipNumber(mNumber);

                final CharSequence callLocationOrType = getNumberTypeOrLocation(firstDetails);
@@ -499,7 +502,8 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
    }

    /** Return the phone call details for a given call log URI. */
    private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri) {
    private PhoneCallDetails getPhoneCallDetailsForUri(Uri callUri,
            PhoneNumberUtilsWrapper phoneUtils) {
        ContentResolver resolver = getContentResolver();
        Cursor callCursor = resolver.query(callUri, CALL_LOG_PROJECTION, null, null, null);
        try {
@@ -539,7 +543,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
            // If this is not a regular number, there is no point in looking it up in the contacts.
            ContactInfo info =
                    PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)
                    && !new PhoneNumberUtilsWrapper(this).isVoicemailNumber(accountHandle, number)
                    && !phoneUtils.isVoicemailNumber(accountHandle, number)
                            ? mContactInfoHelper.lookupNumber(number, countryIso)
                            : null;
            if (info == null) {
+4 −3
Original line number Diff line number Diff line
@@ -244,10 +244,11 @@ public class CallLogAdapter extends GroupingListAdapter
        mPhotoSize = resources.getDimensionPixelSize(R.dimen.contact_photo_size);

        mContactPhotoManager = ContactPhotoManager.getInstance(mContext);
        mPhoneNumberHelper = new PhoneNumberDisplayHelper(mContext, resources);
        mAdapterHelper = new CallLogAdapterHelper(context, this,
                contactInfoHelper, mPhoneNumberHelper);
        mPhoneNumberUtilsWrapper = new PhoneNumberUtilsWrapper(mContext);
        mPhoneNumberHelper = new PhoneNumberDisplayHelper(mContext,
                resources, mPhoneNumberUtilsWrapper);
        mAdapterHelper = new CallLogAdapterHelper(mContext, this,
                contactInfoHelper, mPhoneNumberHelper, mPhoneNumberUtilsWrapper);
        PhoneCallDetailsHelper phoneCallDetailsHelper =
                new PhoneCallDetailsHelper(mContext, resources, mPhoneNumberUtilsWrapper);
        mCallLogViewsHelper =
+5 −2
Original line number Diff line number Diff line
@@ -186,6 +186,7 @@ public class CallLogAdapterHelper implements ViewTreeObserver.OnPreDrawListener
    private Callback mCb;
    private final Context mContext;
    private final ContactInfoHelper mContactInfoHelper;
    private final PhoneNumberUtilsWrapper mPhoneNumberUtilsWrapper;
    private final PhoneNumberDisplayHelper mPhoneNumberHelper;

    /**
@@ -410,7 +411,7 @@ public class CallLogAdapterHelper implements ViewTreeObserver.OnPreDrawListener
                mContactInfoCache.getCachedValue(numberCountryIso);
        ContactInfo info = cachedInfo == null ? null : cachedInfo.getValue();
        if (!PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)
                || new PhoneNumberUtilsWrapper(mContext).isVoicemailNumber(accountHandle, number)) {
                || mPhoneNumberUtilsWrapper.isVoicemailNumber(accountHandle, number)) {
            // If this is a number that cannot be dialed, there is no point in looking up a contact
            // for it.
            info = ContactInfo.EMPTY;
@@ -446,11 +447,13 @@ public class CallLogAdapterHelper implements ViewTreeObserver.OnPreDrawListener

    public CallLogAdapterHelper(Context context, Callback cb,
            ContactInfoHelper contactInfoHelper,
            PhoneNumberDisplayHelper phoneNumberHelper) {
            PhoneNumberDisplayHelper phoneNumberHelper,
            PhoneNumberUtilsWrapper utilsWrapper) {
        mContext = context;
        mCb = cb;
        mContactInfoHelper = contactInfoHelper;
        mPhoneNumberHelper = phoneNumberHelper;
        mPhoneNumberUtilsWrapper = utilsWrapper;

        mContactInfoCache = ExpirableCache.create(CONTACT_INFO_CACHE_SIZE);
        mRequests = new LinkedList<ContactInfoRequest>();
+2 −1
Original line number Diff line number Diff line
@@ -357,6 +357,7 @@ public class DefaultVoicemailNotifier implements VoicemailNotifier {
     * called from the main thread.
     */
    public static PhoneNumberDisplayHelper createPhoneNumberHelper(Context context) {
        return new PhoneNumberDisplayHelper(context, context.getResources());
        return new PhoneNumberDisplayHelper(context, context.getResources(),
                new PhoneNumberUtilsWrapper(context));
    }
}
+15 −5
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.text.TextUtils;

import com.android.dialer.util.AgingCache;

import java.util.ArrayList;
import java.util.List;

@@ -74,27 +76,35 @@ public class PhoneAccountUtils {
     * Extract account color from PhoneAccount object.
     */
    public static int getAccountColor(Context context, PhoneAccountHandle accountHandle) {
        TelecomManager telecomManager =
                (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
        final PhoneAccount account = telecomManager.getPhoneAccount(accountHandle);
        final PhoneAccount account = getAccountOrNull(context, accountHandle);

        // For single-sim devices the PhoneAccount will be NO_HIGHLIGHT_COLOR by default, so it is
        // safe to always use the account highlight color.
        return account == null ? PhoneAccount.NO_HIGHLIGHT_COLOR : account.getHighlightColor();
    }

    private static final AgingCache<PhoneAccountHandle, PhoneAccount> sAccountCache =
            new AgingCache<>(5000);

    /**
     * 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,
            PhoneAccountHandle accountHandle) {
        PhoneAccount account = sAccountCache.get(accountHandle);
        if (account != null) {
            return account;
        }

        TelecomManager telecomManager =
                (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
        final PhoneAccount account = telecomManager.getPhoneAccount(accountHandle);
        if (!telecomManager.hasMultipleCallCapableAccounts()) {
            return null;
            account = null;
        } else {
            account = telecomManager.getPhoneAccount(accountHandle);
        }
        sAccountCache.put(accountHandle, account);
        return account;
    }
}
Loading