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

Commit f507886d authored by Nancy Chen's avatar Nancy Chen Committed by Android (Google) Code Review
Browse files

Merge "Enable use of phone accounts for voicemail info display." into lmp-sprout-dev

parents b9925c43 e80d6222
Loading
Loading
Loading
Loading
+29 −25
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.provider.CallLog.Calls;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.VoicemailContract.Voicemails;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telephony.TelephonyManager;
import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
@@ -78,9 +79,6 @@ import java.util.List;
public class CallDetailActivity extends AnalyticsActivity implements ProximitySensorAware {
    private static final String TAG = "CallDetail";

    private static final int LOADER_ID = 0;
    private static final String BUNDLE_CONTACT_URI_EXTRA = "contact_uri_extra";

    private static final char LEFT_TO_RIGHT_EMBEDDING = '\u202A';
    private static final char POP_DIRECTIONAL_FORMATTING = '\u202C';

@@ -238,7 +236,7 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe
        mResources = getResources();

        mCallTypeHelper = new CallTypeHelper(getResources());
        mPhoneNumberHelper = new PhoneNumberDisplayHelper(mResources);
        mPhoneNumberHelper = new PhoneNumberDisplayHelper(this, mResources);
        mVoicemailStatusHelper = new VoicemailStatusHelperImpl();
        mAsyncQueryHandler = new CallDetailActivityQueryHandler(this);

@@ -379,7 +377,7 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe
    /**
     * Update user interface with details of given call.
     *
     * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed
     * @param callUris URIs into {@link android.provider.CallLog.Calls} of the calls to be displayed
     */
    private void updateData(final Uri... callUris) {
        class UpdateContactDetailsTask extends AsyncTask<Void, Void, PhoneCallDetails[]> {
@@ -403,9 +401,11 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe

            @Override
            public void onPostExecute(PhoneCallDetails[] details) {
                Context context = CallDetailActivity.this;

                if (details == null) {
                    // Somewhere went wrong: we're going to bail out and show error to users.
                    Toast.makeText(CallDetailActivity.this, R.string.toast_call_detail_error,
                    Toast.makeText(context, R.string.toast_call_detail_error,
                            Toast.LENGTH_SHORT).show();
                    finish();
                    return;
@@ -418,24 +418,27 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe
                final int numberPresentation = firstDetails.numberPresentation;
                final Uri contactUri = firstDetails.contactUri;
                final Uri photoUri = firstDetails.photoUri;
                final PhoneAccountHandle accountHandle = firstDetails.accountHandle;

                // Cache the details about the phone number.
                final boolean canPlaceCallsTo =
                    PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation);
                final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper();
                final boolean isVoicemailNumber = phoneUtils.isVoicemailNumber(mNumber);
                final boolean isSipNumber = phoneUtils.isSipNumber(mNumber);
                final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(context);
                final boolean isVoicemailNumber =
                        phoneUtils.isVoicemailNumber(accountHandle, mNumber);
                final boolean isSipNumber = PhoneNumberUtilsWrapper.isSipNumber(mNumber);

                final CharSequence callLocationOrType = getNumberTypeOrLocation(firstDetails);

                final CharSequence displayNumber = mPhoneNumberHelper.getDisplayNumber(
                final CharSequence displayNumber =
                        mPhoneNumberHelper.getDisplayNumber(
                                firstDetails.accountHandle,
                                firstDetails.number,
                                firstDetails.numberPresentation,
                                firstDetails.formattedNumber);
                final String displayNumberStr = mBidiFormatter.unicodeWrap(
                        displayNumber.toString(), TextDirectionHeuristics.LTR);


                if (!TextUtils.isEmpty(firstDetails.name)) {
                    mCallerName.setText(firstDetails.name);
                    mCallerNumber.setText(callLocationOrType + " " + displayNumberStr);
@@ -449,8 +452,9 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe
                    }
                }

                if (!TextUtils.isEmpty(firstDetails.accountLabel)) {
                    mAccountLabel.setText(firstDetails.accountLabel);
                String accountLabel = PhoneAccountUtils.getAccountLabel(context, accountHandle);
                if (!TextUtils.isEmpty(accountLabel)) {
                    mAccountLabel.setText(accountLabel);
                    mAccountLabel.setVisibility(View.VISIBLE);
                } else {
                    mAccountLabel.setVisibility(View.GONE);
@@ -464,8 +468,7 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe

                ListView historyList = (ListView) findViewById(R.id.history);
                historyList.setAdapter(
                        new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater,
                                mCallTypeHelper, details));
                        new CallDetailHistoryAdapter(context, mInflater, mCallTypeHelper, details));

                String lookupKey = contactUri == null ? null
                        : ContactInfoHelper.getLookupKeyFromUri(contactUri);
@@ -479,7 +482,9 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe

                String nameForDefaultImage;
                if (TextUtils.isEmpty(firstDetails.name)) {
                    nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(firstDetails.number,
                    nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(
                            firstDetails.accountHandle,
                            firstDetails.number,
                            firstDetails.numberPresentation,
                            firstDetails.formattedNumber).toString();
                } else {
@@ -535,10 +540,9 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe
            final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX);
            final String transcription = callCursor.getString(TRANSCRIPTION_COLUMN_INDEX);

            final String accountLabel = PhoneAccountUtils.getAccountLabel(this,
                    PhoneAccountUtils.getAccount(
            final PhoneAccountHandle accountHandle = PhoneAccountUtils.getAccount(
                    callCursor.getString(ACCOUNT_COMPONENT_NAME),
                    callCursor.getString(ACCOUNT_ID)));
                    callCursor.getString(ACCOUNT_ID));

            if (TextUtils.isEmpty(countryIso)) {
                countryIso = mDefaultCountryIso;
@@ -556,11 +560,11 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe
            // 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().isVoicemailNumber(number)
                    && !new PhoneNumberUtilsWrapper(this).isVoicemailNumber(accountHandle, number)
                            ? mContactInfoHelper.lookupNumber(number, countryIso)
                            : null;
            if (info == null) {
                formattedNumber = mPhoneNumberHelper.getDisplayNumber(number,
                formattedNumber = mPhoneNumberHelper.getDisplayNumber(accountHandle, number,
                        numberPresentation, null);
                nameText = "";
                numberType = 0;
@@ -586,7 +590,7 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe
                    formattedNumber, countryIso, geocode,
                    new int[]{ callType }, date, duration,
                    nameText, numberType, numberLabel, lookupUri, photoUri, sourceType,
                    accountLabel, null, features, dataUsage, transcription);
                    accountHandle, features, dataUsage, transcription);
        } finally {
            if (callCursor != null) {
                callCursor.close();
+13 −16
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.telecom.PhoneAccountHandle;

/**
 * The details of a phone call to be shown in the UI.
@@ -66,14 +67,11 @@ public class PhoneCallDetails {
     * The source type of the contact associated with this call.
     */
    public final int sourceType;

    /**
     * The unique identifier for the account associated with the call.
     */
    public final String accountLabel;
    /**
     * The icon for the account associated with the call.
     */
    public final Drawable accountIcon;
    public final PhoneAccountHandle accountHandle;
    /**
     * Features applicable to this call.
     */
@@ -96,26 +94,26 @@ public class PhoneCallDetails {
            CharSequence formattedNumber, String countryIso, String geocode,
            int[] callTypes, long date, long duration) {
        this (number, numberPresentation, formattedNumber, countryIso, geocode,
        callTypes, date, duration, "", 0, "", null, null, 0, null, null, 0, null, null);
                callTypes, date, duration, "", 0, "", null, null, 0, null, 0, null, null);
    }

    /** Create the details for a call with a number not associated with a contact. */
    public PhoneCallDetails(CharSequence number, int numberPresentation,
            CharSequence formattedNumber, String countryIso, String geocode,
            int[] callTypes, long date, long duration, String accountLabel, Drawable accountIcon,
            int features, Long dataUsage, String transcription) {
        this(number, numberPresentation, formattedNumber, countryIso, geocode,
                callTypes, date, duration, "", 0, "", null, null, 0, accountLabel, accountIcon,
                features, dataUsage, transcription);
            int[] callTypes, long date, long duration,
            PhoneAccountHandle accountHandle, int features, Long dataUsage, String transcription) {
        this(number, numberPresentation, formattedNumber, countryIso, geocode, callTypes, date,
                duration, "", 0, "", null, null, 0, accountHandle, features, dataUsage,
                transcription);
    }

    /** Create the details for a call with a number associated with a contact. */
    public PhoneCallDetails(CharSequence number, int numberPresentation,
            CharSequence formattedNumber, String countryIso, String geocode,
            int[] callTypes, long date, long duration, CharSequence name,
            int numberType, CharSequence numberLabel, Uri contactUri,
            Uri photoUri, int sourceType, String accountLabel, Drawable accountIcon, int features,
            Long dataUsage, String transcription) {
            int numberType, CharSequence numberLabel, Uri contactUri, Uri photoUri,
            int sourceType, PhoneAccountHandle accountHandle, int features, Long dataUsage,
            String transcription) {
        this.number = number;
        this.numberPresentation = numberPresentation;
        this.formattedNumber = formattedNumber;
@@ -130,8 +128,7 @@ public class PhoneCallDetails {
        this.contactUri = contactUri;
        this.photoUri = photoUri;
        this.sourceType = sourceType;
        this.accountLabel = accountLabel;
        this.accountIcon = accountIcon;
        this.accountHandle = accountHandle;
        this.features = features;
        this.dataUsage = dataUsage;
        this.transcription = transcription;
+18 −11
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@

package com.android.dialer;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract.CommonDataKinds.Phone;
@@ -28,8 +30,8 @@ import android.widget.TextView;
import com.android.contacts.common.CallUtil;
import com.android.contacts.common.testing.NeededForTesting;
import com.android.contacts.common.util.PhoneNumberHelper;
import com.android.dialer.calllog.CallTypeHelper;
import com.android.dialer.calllog.ContactInfo;
import com.android.dialer.calllog.PhoneAccountUtils;
import com.android.dialer.calllog.PhoneNumberDisplayHelper;
import com.android.dialer.calllog.PhoneNumberUtilsWrapper;
import com.android.dialer.util.DialerUtils;
@@ -44,6 +46,7 @@ public class PhoneCallDetailsHelper {
    /** The maximum number of icons will be shown to represent the call types in a group. */
    private static final int MAX_CALL_TYPE_ICONS = 3;

    private final Context mContext;
    private final Resources mResources;
    /** The injected current time in milliseconds since the epoch. Used only by tests. */
    private Long mCurrentTimeMillisForTest;
@@ -63,11 +66,12 @@ public class PhoneCallDetailsHelper {
     *
     * @param resources used to look up strings
     */
    public PhoneCallDetailsHelper(Resources resources, CallTypeHelper callTypeHelper,
    public PhoneCallDetailsHelper(Context context, Resources resources,
            PhoneNumberUtilsWrapper phoneUtils) {
        mContext = context;
        mResources = resources;
        mPhoneNumberUtilsWrapper = phoneUtils;
        mPhoneNumberHelper = new PhoneNumberDisplayHelper(mPhoneNumberUtilsWrapper, resources);
        mPhoneNumberHelper = new PhoneNumberDisplayHelper(context, resources, phoneUtils);
    }

    /** Fills the call details views with content. */
@@ -103,16 +107,17 @@ public class PhoneCallDetailsHelper {
        setCallCountAndDate(views, callCount, callLocationAndDate);

        // set the account icon if it exists
        if (details.accountIcon != null) {
        Drawable accountIcon = PhoneAccountUtils.getAccountIcon(mContext, details.accountHandle);
        if (accountIcon != null) {
            views.callAccountIcon.setVisibility(View.VISIBLE);
            views.callAccountIcon.setImageDrawable(details.accountIcon);
            views.callAccountIcon.setImageDrawable(accountIcon);
        } else {
            views.callAccountIcon.setVisibility(View.GONE);
        }

        final CharSequence nameText;
        final CharSequence displayNumber =
            mPhoneNumberHelper.getDisplayNumber(details.number,
            mPhoneNumberHelper.getDisplayNumber(details.accountHandle, details.number,
                    details.numberPresentation, details.formattedNumber);
        if (TextUtils.isEmpty(details.name)) {
            nameText = displayNumber;
@@ -169,7 +174,8 @@ 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.number)) {
                && !mPhoneNumberUtilsWrapper.isVoicemailNumber(details.accountHandle,
                        details.number)) {

            if (details.numberLabel == ContactInfo.GEOCODE_AS_LABEL) {
                numberFormattedLabel = details.geocode;
@@ -180,8 +186,8 @@ public class PhoneCallDetailsHelper {
        }

        if (!TextUtils.isEmpty(details.name) && TextUtils.isEmpty(numberFormattedLabel)) {
            numberFormattedLabel = mPhoneNumberHelper.getDisplayNumber(details.number,
                    details.numberPresentation, details.formattedNumber);
            numberFormattedLabel = mPhoneNumberHelper.getDisplayNumber(details.accountHandle,
                    details.number, details.numberPresentation, details.formattedNumber);
        }
        return numberFormattedLabel;
    }
@@ -204,7 +210,8 @@ public class PhoneCallDetailsHelper {
    public void setCallDetailsHeader(TextView nameView, PhoneCallDetails details) {
        final CharSequence nameText;
        final CharSequence displayNumber =
            mPhoneNumberHelper.getDisplayNumber(details.number, details.numberPresentation,
            mPhoneNumberHelper.getDisplayNumber(details.accountHandle, details.number,
                    details.numberPresentation,
                    mResources.getString(R.string.recentCalls_addToContact));
        if (TextUtils.isEmpty(details.name)) {
            nameText = displayNumber;
+15 −15
Original line number Diff line number Diff line
@@ -248,6 +248,8 @@ public class CallLogAdapter extends GroupingListAdapter
    private final ContactPhotoManager mContactPhotoManager;
    /** Helper to parse and process phone numbers. */
    private PhoneNumberDisplayHelper mPhoneNumberHelper;
    /** Helper to access Telephony phone number utils class */
    protected final PhoneNumberUtilsWrapper mPhoneNumberUtilsWrapper;
    /** Helper to group call log entries. */
    private final CallLogGroupBuilder mCallLogGroupBuilder;

@@ -365,9 +367,10 @@ public class CallLogAdapter extends GroupingListAdapter
        mExpandedTranslationZ = resources.getDimension(R.dimen.call_log_expanded_translation_z);

        mContactPhotoManager = ContactPhotoManager.getInstance(mContext);
        mPhoneNumberHelper = new PhoneNumberDisplayHelper(resources);
        PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper(
                resources, callTypeHelper, new PhoneNumberUtilsWrapper());
        mPhoneNumberHelper = new PhoneNumberDisplayHelper(mContext, resources);
        mPhoneNumberUtilsWrapper = new PhoneNumberUtilsWrapper(mContext);
        PhoneCallDetailsHelper phoneCallDetailsHelper =
                new PhoneCallDetailsHelper(mContext, resources, mPhoneNumberUtilsWrapper);
        mCallLogViewsHelper =
                new CallLogListItemHelper(
                        phoneCallDetailsHelper, mPhoneNumberHelper, resources);
@@ -641,8 +644,6 @@ 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 String countryIso = c.getString(CallLogQuery.COUNTRY_ISO);

        final long rowId = c.getLong(CallLogQuery.ID);
@@ -677,7 +678,7 @@ public class CallLogAdapter extends GroupingListAdapter
        final ContactInfo cachedContactInfo = getContactInfoFromCallLog(c);

        final boolean isVoicemailNumber =
                PhoneNumberUtilsWrapper.INSTANCE.isVoicemailNumber(number);
                mPhoneNumberUtilsWrapper.isVoicemailNumber(accountHandle, number);

        // Where binding and not in the call log, use default behaviour of invoking a call when
        // tapping the primary view.
@@ -769,14 +770,13 @@ public class CallLogAdapter extends GroupingListAdapter
        expandOrCollapseActions(callLogItemView, isExpanded(rowId));

        if (TextUtils.isEmpty(name)) {
            details = new PhoneCallDetails(number, numberPresentation,
                    formattedNumber, countryIso, geocode, callTypes, date,
                    duration, null, accountIcon, features, dataUsage, transcription);
            details = new PhoneCallDetails(number, numberPresentation, formattedNumber, countryIso,
                    geocode, callTypes, date, duration, accountHandle, features, dataUsage,
                    transcription);
        } else {
            details = new PhoneCallDetails(number, numberPresentation,
                    formattedNumber, countryIso, geocode, callTypes, date,
                    duration, name, ntype, label, lookupUri, photoUri, sourceType,
                    null, accountIcon, features, dataUsage, transcription);
            details = new PhoneCallDetails(number, numberPresentation, formattedNumber, countryIso,
                    geocode, callTypes, date, duration, name, ntype, label, lookupUri, photoUri,
                    sourceType, accountHandle, features, dataUsage, transcription);
        }

        mCallLogViewsHelper.setPhoneCallDetails(mContext, views, details);
@@ -794,8 +794,8 @@ public class CallLogAdapter extends GroupingListAdapter

        String nameForDefaultImage = null;
        if (TextUtils.isEmpty(name)) {
            nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(details.number,
                    details.numberPresentation, details.formattedNumber).toString();
            nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(details.accountHandle,
                    details.number, details.numberPresentation, details.formattedNumber).toString();
        } else {
            nameForDefaultImage = name;
        }
+1 −1
Original line number Diff line number Diff line
@@ -222,7 +222,7 @@ import com.android.dialer.R;
        if (!TextUtils.isEmpty(details.name)) {
            recipient = details.name;
        } else {
            recipient = mPhoneNumberHelper.getDisplayNumber(
            recipient = mPhoneNumberHelper.getDisplayNumber(details.accountHandle,
                    details.number, details.numberPresentation, details.formattedNumber);
        }
        return recipient;
Loading