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

Commit c4180ac3 authored by Mengjun Leng's avatar Mengjun Leng Committed by Linux Build Service Account
Browse files

Reducing binder invoking when scrolling

Drawing frame is delay due to losts of binder invoking from
getAccountIcon. When fetching the account icon, need call
getAccountOrNull every time that invokes two remote methods
such as getDefaultDialerPackage and getCallCapablePhoneAccounts.

Put the drawable of the icon into cache so that reduces invoking
getAccountOrNull, otherwise avoid to call the remote method
isVoiceMailNumber.

Change-Id: Ib03975cc6586980189a10f2992df445a26add18b
CRs-Fixed: 1033851
parent 9e2159f4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -513,7 +513,7 @@ public class CallLogAdapter extends GroupingListAdapter
        final PhoneAccountHandle accountHandle = PhoneAccountUtils.getAccount(
                c.getString(CallLogQuery.ACCOUNT_COMPONENT_NAME),
                c.getString(CallLogQuery.ACCOUNT_ID));
        final Drawable accountIcon = PhoneAccountUtils.getAccountIcon(mContext, accountHandle);
        final Drawable accountIcon = mCallLogCache.getAccountIcon(accountHandle);
        final ContactInfo cachedContactInfo = ContactInfoHelper.getContactInfo(c);
        final boolean isVoicemailNumber =
                mCallLogCache.isVoicemailNumber(accountHandle, number);
+1 −1
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ public class PhoneAccountUtils {
     * single registered and enabled account, return null.
     */
    @Nullable
    private static PhoneAccount getAccountOrNull(Context context,
    public static PhoneAccount getAccountOrNull(Context context,
            @Nullable PhoneAccountHandle accountHandle) {
        if (TelecomUtil.getCallCapablePhoneAccounts(context).size() < 1) {
            return null;
+6 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.dialer.calllog.calllogcache;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.telecom.PhoneAccountHandle;

import com.android.contacts.common.CallUtil;
@@ -93,4 +94,9 @@ public abstract class CallLogCache {
     * @return {@code true} if calling with a note is supported, {@code false} otherwise.
     */
    public abstract boolean doesAccountSupportCallSubject(PhoneAccountHandle accountHandle);

    /**
     * Returns the account icon if present, else null.
     */
    public abstract Drawable getAccountIcon(PhoneAccountHandle phoneAccount);
}
+6 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.dialer.calllog.calllogcache;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telephony.PhoneNumberUtils;
@@ -70,4 +71,9 @@ class CallLogCacheLollipop extends CallLogCache {
    public boolean doesAccountSupportCallSubject(PhoneAccountHandle accountHandle) {
        return false;
    }

    @Override
    public Drawable getAccountIcon(PhoneAccountHandle accountHandle) {
        return null;
    }
}
+49 −10
Original line number Diff line number Diff line
@@ -17,7 +17,12 @@
package com.android.dialer.calllog.calllogcache;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telephony.PhoneNumberUtils;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Pair;

@@ -37,22 +42,27 @@ import java.util.Map;
class CallLogCacheLollipopMr1 extends CallLogCache {
    // 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.
    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 final Map<PhoneAccountHandle, Boolean> mPhoneAccountCallWithNoteCache = new HashMap<>();
    private final Map<PhoneAccountHandle, Drawable> mPhoneAccountCallWithDrawableCache
            = new HashMap<>();
    private final Map<PhoneAccountHandle, String> mPhoneAccountCallWithVoiceMailNumberCache
            = new HashMap<>();
    private TelephonyManager mTelephonyManager;

    /* package */ CallLogCacheLollipopMr1(Context context) {
        super(context);
        mTelephonyManager = TelephonyManager.from(context);
    }

    @Override
    public void reset() {
        mVoicemailQueryCache.clear();
        mPhoneAccountLabelCache.clear();
        mPhoneAccountColorCache.clear();
        mPhoneAccountCallWithNoteCache.clear();
        mPhoneAccountCallWithDrawableCache.clear();
        mPhoneAccountCallWithVoiceMailNumberCache.clear();

        super.reset();
    }
@@ -63,16 +73,29 @@ class CallLogCacheLollipopMr1 extends CallLogCache {
            return false;
        }

        Pair<PhoneAccountHandle, CharSequence> key = new Pair<>(accountHandle, number);
        if (mVoicemailQueryCache.containsKey(key)) {
            return mVoicemailQueryCache.get(key);
        String curNumber = PhoneNumberUtils.extractNetworkPortionAlt(number.toString());
        if (mPhoneAccountCallWithVoiceMailNumberCache.containsKey(accountHandle)) {
            String vmNumber = mPhoneAccountCallWithVoiceMailNumberCache.get(accountHandle);
            return !TextUtils.isEmpty(curNumber) && PhoneNumberUtils.compare(curNumber, vmNumber);
        } else {
            Boolean isVoicemail =
                    PhoneNumberUtil.isVoicemailNumber(mContext, accountHandle, number.toString());
            mVoicemailQueryCache.put(key, isVoicemail);
            return isVoicemail;
            PhoneAccount account = PhoneAccountUtils.getAccountOrNull(mContext, accountHandle);
            if (account != null
                    && account.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) {
                try {
                    int subId = Integer.parseInt(accountHandle.getId());
                    String vmNumber =  mTelephonyManager.getVoiceMailNumber(subId);
                    mPhoneAccountCallWithVoiceMailNumberCache.put(accountHandle, vmNumber);
                    return !TextUtils.isEmpty(curNumber)
                            && PhoneNumberUtils.compare(curNumber, vmNumber);
                } catch (NumberFormatException e) {
                    mPhoneAccountCallWithVoiceMailNumberCache.put(accountHandle, null);
                }
            } else {
                mPhoneAccountCallWithVoiceMailNumberCache.put(accountHandle, null);
            }
        }
        return false;
    }

    @Override
    public String getAccountLabel(PhoneAccountHandle accountHandle) {
@@ -107,4 +130,20 @@ class CallLogCacheLollipopMr1 extends CallLogCache {
            return supportsCallWithNote;
        }
    }

    @Override
    public Drawable getAccountIcon(PhoneAccountHandle accountHandle) {
        if (mPhoneAccountCallWithDrawableCache.containsKey(accountHandle)) {
            return mPhoneAccountCallWithDrawableCache.get(accountHandle);
        } else {
            PhoneAccount account = PhoneAccountUtils.getAccountOrNull(mContext, accountHandle);
            if (account == null) {
                mPhoneAccountCallWithDrawableCache.put(accountHandle, null);
                return null;
            }
            Drawable drawable = account.getIcon().loadDrawable(mContext);
            mPhoneAccountCallWithDrawableCache.put(accountHandle, drawable);
            return drawable;
        }
    }
}
Loading