Merge "Tag incoming call notification with SIM label on multi-SIM devices" am: 087329e925
am: 0429052242
Change-Id: Id22646e44066922d984b96d0b4eb3df715822dc4
diff --git a/java/com/android/incallui/StatusBarNotifier.java b/java/com/android/incallui/StatusBarNotifier.java
index 86ad9ff..6ddba16 100644
--- a/java/com/android/incallui/StatusBarNotifier.java
+++ b/java/com/android/incallui/StatusBarNotifier.java
@@ -299,7 +299,7 @@
// 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 @@
if (!checkForChangeAndSaveData(
iconResId,
- content,
+ content.toString(),
largeIcon,
contentTitle,
callState,
@@ -681,7 +681,7 @@
}
/** 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 @@
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 @@
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 @@
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 74b3ef8..afadbf8 100644
--- a/java/com/android/incallui/res/values/strings.xml
+++ b/java/com/android/incallui/res/values/strings.xml
@@ -65,6 +65,8 @@
<string name="notification_on_hold">On hold</string>
<!-- The "label" of the in-call Notification for an incoming ringing call. [CHAR LIMIT=60] -->
<string name="notification_incoming_call">Incoming call</string>
+ <!-- The "label" of the in-call Notification for an incoming ringing call on a device with multiple SIMs. [CHAR LIMIT=60] -->
+ <string name="notification_incoming_call_mutli_sim">Incoming call via <xliff:g id="sim_label" example="SIM 1">%1$s</xliff:g></string>
<!-- The "label" of the in-call Notification for an incoming ringing call. [CHAR LIMIT=50] -->
<string name="notification_incoming_call_with_photo">Incoming call with photo</string>
<!-- The "label" of the in-call Notification for an incoming ringing call. [CHAR LIMIT=50] -->