From 829322759b3a0cf23ff520ba57e9c31250bc56a1 Mon Sep 17 00:00:00 2001 From: linyuh Date: Fri, 4 May 2018 11:23:07 -0700 Subject: Show calls to/from emergency numbers as "Emergency number" in call log & call details Bug: 71719349 Test: CallLogEntryText PiperOrigin-RevId: 195444242 Change-Id: I62268c02ef7ad277364869e713a1d58ab1928e7e --- .../dialer/calllogutils/CallLogEntryText.java | 33 +++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'java/com/android/dialer/calllogutils') 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 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 { *

Rules: * *