diff options
Diffstat (limited to 'java')
3 files changed, 59 insertions, 10 deletions
diff --git a/java/com/android/dialer/calldetails/CallDetailsHeaderViewHolder.java b/java/com/android/dialer/calldetails/CallDetailsHeaderViewHolder.java index cd1752d74..44b5a4319 100644 --- a/java/com/android/dialer/calldetails/CallDetailsHeaderViewHolder.java +++ b/java/com/android/dialer/calldetails/CallDetailsHeaderViewHolder.java @@ -190,7 +190,13 @@ public class CallDetailsHeaderViewHolder extends RecyclerView.ViewHolder .loadQuickContactBadge(contactPhoto, headerInfo.getPhotoInfo()); nameView.setText(headerInfo.getPrimaryText()); - numberView.setText(headerInfo.getSecondaryText()); + if (!headerInfo.getSecondaryText().isEmpty()) { + numberView.setVisibility(View.VISIBLE); + numberView.setText(headerInfo.getSecondaryText()); + } else { + numberView.setVisibility(View.GONE); + numberView.setText(null); + } setCallbackAction(callbackAction); } diff --git a/java/com/android/dialer/calllogutils/CallLogEntryText.java b/java/com/android/dialer/calllogutils/CallLogEntryText.java index 1b7bb06fa..cd8fb44d9 100644 --- a/java/com/android/dialer/calllogutils/CallLogEntryText.java +++ b/java/com/android/dialer/calllogutils/CallLogEntryText.java @@ -21,6 +21,7 @@ import android.provider.CallLog.Calls; import android.text.TextUtils; import com.android.dialer.calllog.model.CoalescedRow; import com.android.dialer.duo.DuoComponent; +import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.time.Clock; import com.google.common.base.Optional; import com.google.common.collect.Collections2; @@ -42,28 +43,35 @@ public final class CallLogEntryText { * following the primary text.) */ public static CharSequence buildPrimaryText(Context context, CoalescedRow row) { - // Always prefer the presentation name, like "Restricted". + // Calls to emergency services should be shown as "Emergency number". + if (PhoneNumberHelper.isLocalEmergencyNumber(context, row.getNumber().getNormalizedNumber())) { + return context.getText(R.string.emergency_number); + } + + // Otherwise, follow the following order of preferences. + // 1st preference: the presentation name, like "Restricted". Optional<String> presentationName = PhoneNumberDisplayUtil.getNameForPresentation(context, row.getNumberPresentation()); if (presentationName.isPresent()) { return presentationName.get(); } + // 2nd preference: the voicemail tag if the call is one made to a voicemail box. if (row.getIsVoicemailCall() && !TextUtils.isEmpty(row.getVoicemailCallTag())) { return row.getVoicemailCallTag(); } - // Otherwise prefer the name. + // 3rd preference: the name associated with the number. if (!TextUtils.isEmpty(row.getNumberAttributes().getName())) { return row.getNumberAttributes().getName(); } - // Otherwise prefer the formatted number. + // 4th preference: the formatted number. if (!TextUtils.isEmpty(row.getFormattedNumber())) { return row.getFormattedNumber(); } - // If there's no formatted number, just return "Unknown". + // Last resort: show "Unknown". return context.getText(R.string.new_call_log_unknown); } @@ -73,6 +81,7 @@ public final class CallLogEntryText { * <p>Rules: * * <ul> + * <li>For emergency numbers: Date * <li>For numbers that are not spam or blocked: $Label(, Duo video|Carrier video)?|$Location • * Date * <li>For blocked non-spam numbers: Blocked • $Label(, Duo video|Carrier video)?|$Location • @@ -100,6 +109,12 @@ public final class CallLogEntryText { */ public static CharSequence buildSecondaryTextForEntries( Context context, Clock clock, CoalescedRow row) { + // For emergency numbers, the secondary text should contain only the timestamp. + if (PhoneNumberHelper.isLocalEmergencyNumber(context, row.getNumber().getNormalizedNumber())) { + return CallLogDates.newCallLogTimestampLabel( + context, clock.currentTimeMillis(), row.getTimestamp()); + } + List<CharSequence> components = new ArrayList<>(); if (row.getNumberAttributes().getIsBlocked()) { @@ -127,6 +142,8 @@ public final class CallLogEntryText { public static CharSequence buildSecondaryTextForBottomSheet(Context context, CoalescedRow row) { /* * Rules: + * For emergency numbers: + * Number * For numbers that are not spam or blocked: * $Label(, Duo video|Carrier video)?|$Location [• NumberIfNoName]? * For blocked non-spam numbers: @@ -149,6 +166,14 @@ public final class CallLogEntryText { * Mobile • 555-1234 * Brooklyn, NJ */ + + // For emergency numbers, the secondary text should contain only the number. + if (PhoneNumberHelper.isLocalEmergencyNumber(context, row.getNumber().getNormalizedNumber())) { + return !row.getFormattedNumber().isEmpty() + ? row.getFormattedNumber() + : row.getNumber().getNormalizedNumber(); + } + List<CharSequence> components = new ArrayList<>(); if (row.getNumberAttributes().getIsBlocked()) { diff --git a/java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java b/java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java index 9af08be50..86bb79daf 100644 --- a/java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java +++ b/java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java @@ -30,6 +30,7 @@ import com.android.dialer.common.Assert; import com.android.dialer.duo.Duo; import com.android.dialer.duo.DuoComponent; import com.android.dialer.logging.ReportingLocation; +import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.util.CallUtil; import com.android.dialer.util.UriUtils; import java.util.ArrayList; @@ -118,6 +119,7 @@ public final class HistoryItemActionModulesBuilder { * <p>This method is a no-op if * * <ul> + * <li>the call is one made to/received from an emergency number, * <li>the call is one made to a voicemail box, * <li>the number is blocked, or * <li>the number is marked as spam. @@ -138,7 +140,10 @@ public final class HistoryItemActionModulesBuilder { * capability, and Duo is available, add a Duo video call module. */ public HistoryItemActionModulesBuilder addModuleForVideoCall() { - if (moduleInfo.getIsVoicemailCall() || moduleInfo.getIsBlocked() || moduleInfo.getIsSpam()) { + if (isEmergencyNumber() + || moduleInfo.getIsVoicemailCall() + || moduleInfo.getIsBlocked() + || moduleInfo.getIsSpam()) { return this; } @@ -178,6 +183,7 @@ public final class HistoryItemActionModulesBuilder { * <p>The method is a no-op if * * <ul> + * <li>the call is one made to/received from an emergency number, * <li>the call is one made to a voicemail box, * <li>the number is blocked, or * <li>the number is empty. @@ -186,7 +192,8 @@ public final class HistoryItemActionModulesBuilder { public HistoryItemActionModulesBuilder addModuleForSendingTextMessage() { // TODO(zachh): There are other conditions where this module should not be shown // (e.g., business numbers). - if (moduleInfo.getIsVoicemailCall() + if (isEmergencyNumber() + || moduleInfo.getIsVoicemailCall() || moduleInfo.getIsBlocked() || TextUtils.isEmpty(moduleInfo.getNormalizedNumber())) { return this; @@ -217,6 +224,7 @@ public final class HistoryItemActionModulesBuilder { * <p>The method is a no-op if * * <ul> + * <li>the call is one made to/received from an emergency number, * <li>the call is one made to a voicemail box, * <li>the number is blocked, * <li>the number is marked as spam, @@ -225,7 +233,8 @@ public final class HistoryItemActionModulesBuilder { * </ul> */ public HistoryItemActionModulesBuilder addModuleForAddingToContacts() { - if (moduleInfo.getIsVoicemailCall() + if (isEmergencyNumber() + || moduleInfo.getIsVoicemailCall() || moduleInfo.getIsBlocked() || moduleInfo.getIsSpam() || isExistingContact() @@ -253,7 +262,12 @@ public final class HistoryItemActionModulesBuilder { /** * Add modules for blocking/unblocking a number and/or marking it as spam/not spam. * - * <p>The method is a no-op if the call is one made to a voicemail box. + * <p>The method is a no-op if + * + * <ul> + * <li>the call is one made to/received from an emergency number, or + * <li>the call is one made to a voicemail box. + * </ul> * * <p>If a number is marked as spam, add two modules: * @@ -267,7 +281,7 @@ public final class HistoryItemActionModulesBuilder { * <p>If a number is not blocked or marked as spam, add the "Block/Report spam" module. */ public HistoryItemActionModulesBuilder addModuleForBlockedOrSpamNumber() { - if (moduleInfo.getIsVoicemailCall()) { + if (isEmergencyNumber() || moduleInfo.getIsVoicemailCall()) { return this; } @@ -387,6 +401,10 @@ public final class HistoryItemActionModulesBuilder { && !UriUtils.isEncodedContactUri(Uri.parse(moduleInfo.getLookupUri())); } + private boolean isEmergencyNumber() { + return PhoneNumberHelper.isLocalEmergencyNumber(context, moduleInfo.getNormalizedNumber()); + } + /** * Maps the value of {@link HistoryItemActionModuleInfo#getHost()} to {@link * CallInitiationType.Type}, which is required by {@link CallIntentBuilder} to build a call |