From d1d1d0c6726b9501cfb6f19317f9bf4e70e0d1dd Mon Sep 17 00:00:00 2001 From: twyen Date: Thu, 5 Oct 2017 17:34:43 -0700 Subject: Tag incoming call notification with SIM label on multi-SIM devices The label is colorized with the SIM color, if the system UI decides to respect it. screenshot: https://screenshot.googleplex.com/PzkCKdQJ7Wy Bug: 64215023 Test: StatusBarNotifierTest PiperOrigin-RevId: 171234005 Change-Id: I684753b6181bdfe601244d01ab608fcd5d5dc422 --- java/com/android/incallui/StatusBarNotifier.java | 32 +++++++++++++++++++++--- java/com/android/incallui/res/values/strings.xml | 2 ++ 2 files changed, 30 insertions(+), 4 deletions(-) (limited to 'java/com/android/incallui') diff --git a/java/com/android/incallui/StatusBarNotifier.java b/java/com/android/incallui/StatusBarNotifier.java index 86ad9ffe5..6ddba1613 100644 --- a/java/com/android/incallui/StatusBarNotifier.java +++ b/java/com/android/incallui/StatusBarNotifier.java @@ -299,7 +299,7 @@ public class StatusBarNotifier // Check if data has changed; if nothing is different, don't issue another notification. final int iconResId = getIconToDisplay(call); Bitmap largeIcon = getLargeIconToDisplay(mContext, contactInfo, call); - final String content = getContentString(call, contactInfo.userType); + final CharSequence content = getContentString(call, contactInfo.userType); final String contentTitle = getContentTitle(contactInfo, call); final boolean isVideoUpgradeRequest = @@ -329,7 +329,7 @@ public class StatusBarNotifier if (!checkForChangeAndSaveData( iconResId, - content, + content.toString(), largeIcon, contentTitle, callState, @@ -681,7 +681,7 @@ public class StatusBarNotifier } /** Returns the message to use with the notification. */ - private String getContentString(DialerCall call, @UserType long userType) { + private CharSequence getContentString(DialerCall call, @UserType long userType) { boolean isIncomingOrWaiting = call.getState() == DialerCall.State.INCOMING || call.getState() == DialerCall.State.CALL_WAITING; @@ -709,7 +709,8 @@ public class StatusBarNotifier resId = getECIncomingCallText(call.getEnrichedCallSession()); } else if (call.hasProperty(Details.PROPERTY_WIFI)) { resId = R.string.notification_incoming_call_wifi_template; - + } else if (call.getAccountHandle() != null && hasMultiplePhoneAccounts()) { + return getMultiSimIncomingText(call); } else { resId = R.string.notification_incoming_call; } @@ -812,6 +813,24 @@ public class StatusBarNotifier return resId; } + private CharSequence getMultiSimIncomingText(DialerCall call) { + PhoneAccount phoneAccount = + mContext.getSystemService(TelecomManager.class).getPhoneAccount(call.getAccountHandle()); + SpannableString string = + new SpannableString( + mContext.getString( + R.string.notification_incoming_call_mutli_sim, phoneAccount.getLabel())); + int accountStart = string.toString().lastIndexOf(phoneAccount.getLabel().toString()); + int accountEnd = accountStart + phoneAccount.getLabel().length(); + + string.setSpan( + new ForegroundColorSpan(phoneAccount.getHighlightColor()), + accountStart, + accountEnd, + Spannable.SPAN_INCLUSIVE_EXCLUSIVE); + return string; + } + /** Gets the most relevant call to display in the notification. */ private DialerCall getCallToShow(CallList callList) { if (callList == null) { @@ -1022,6 +1041,11 @@ public class StatusBarNotifier mStatusBarCallListener = listener; } + @SuppressWarnings("MissingPermission") + private boolean hasMultiplePhoneAccounts() { + return mContext.getSystemService(TelecomManager.class).getCallCapablePhoneAccounts().size() > 1; + } + @Override public void onAudioStateChanged(CallAudioState audioState) { if (CallList.getInstance().getActiveOrBackgroundCall() == null) { diff --git a/java/com/android/incallui/res/values/strings.xml b/java/com/android/incallui/res/values/strings.xml index 74b3ef80b..afadbf828 100644 --- a/java/com/android/incallui/res/values/strings.xml +++ b/java/com/android/incallui/res/values/strings.xml @@ -65,6 +65,8 @@ On hold Incoming call + + Incoming call via %1$s Incoming call with photo -- cgit v1.2.3