Tidy up visuals/behaviors for MSIM notifications.

+ If MSIM device, show subscription display name on voicemail
or call forwarding notifications instead of some of the normal
title/summary text.
+ Use subscription colors to tint notification backgrounds.
+ Use PhoneAccountHandle to specify SIM to call with for voicemail
notifications.
+ Move code for getting PhoneAccountHandle from Phone into PhoneUtils
and update references throughout telephony. This assumes we only need
to do the conversion for PSTN phones; this seems to be a safe
assumption given how the notification manager previously got the
default Phone from the phone factory.

Bug: 18232725
Change-Id: I62574643de1d61ef716e06fb733467ce2f607586
diff --git a/src/com/android/phone/NotificationMgr.java b/src/com/android/phone/NotificationMgr.java
index 90b6595..65f7594 100644
--- a/src/com/android/phone/NotificationMgr.java
+++ b/src/com/android/phone/NotificationMgr.java
@@ -33,10 +33,13 @@
 import android.provider.ContactsContract.PhoneLookup;
 import android.provider.Settings;
 import android.telecom.PhoneAccount;
+import android.telecom.PhoneAccountHandle;
+import android.telecom.TelecomManager;
 import android.telephony.PhoneNumberUtils;
 import android.telephony.ServiceState;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.Log;
 import android.widget.Toast;
@@ -84,6 +87,8 @@
     private UserManager mUserManager;
     private Toast mToast;
     private SubscriptionManager mSubscriptionManager;
+    private TelecomManager mTelecomManager;
+    private TelephonyManager mTelephonyManager;
 
     public StatusBarHelper statusBarHelper;
 
@@ -105,6 +110,8 @@
         mPhone = app.phone;  // TODO: better style to use mCM.getDefaultPhone() everywhere instead
         statusBarHelper = new StatusBarHelper();
         mSubscriptionManager = SubscriptionManager.from(mContext);
+        mTelecomManager = TelecomManager.from(mContext);
+        mTelephonyManager = (TelephonyManager) app.getSystemService(Context.TELEPHONY_SERVICE);
     }
 
     /**
@@ -151,7 +158,7 @@
         private boolean mIsExpandedViewEnabled = true;
         private boolean mIsSystemBarNavigationEnabled = true;
 
-        private StatusBarHelper () {
+        private StatusBarHelper() {
         }
 
         /**
@@ -246,7 +253,13 @@
         if (visible) {
             Phone phone = PhoneGlobals.getPhone(subId);
             if (phone == null) {
-                Log.w(LOG_TAG, "Null phone returned for " + subId);
+                Log.w(LOG_TAG, "Found null phone for: " + subId);
+                return;
+            }
+
+            SubscriptionInfo subInfo = mSubscriptionManager.getActiveSubscriptionInfo(subId);
+            if (subInfo == null) {
+                Log.w(LOG_TAG, "Found null subscription info for: " + subId);
                 return;
             }
 
@@ -284,17 +297,24 @@
             }
 
             String notificationText;
-            if (TextUtils.isEmpty(vmNumber)) {
-                notificationText = mContext.getString(
-                        R.string.notification_voicemail_no_vm_number);
+            if (mTelephonyManager.getPhoneCount() > 1) {
+                notificationText = subInfo.getDisplayName().toString();
             } else {
-                notificationText = String.format(
-                        mContext.getString(R.string.notification_voicemail_text_format),
-                        PhoneNumberUtils.formatNumber(vmNumber));
+                if (TextUtils.isEmpty(vmNumber)) {
+                    notificationText = mContext.getString(
+                            R.string.notification_voicemail_no_vm_number);
+                } else {
+                    notificationText = String.format(
+                            mContext.getString(R.string.notification_voicemail_text_format),
+                            PhoneNumberUtils.formatNumber(vmNumber));
+                }
             }
 
-            Intent intent = new Intent(Intent.ACTION_CALL,
-                    Uri.fromParts(PhoneAccount.SCHEME_VOICEMAIL, "", null));
+            // This pathway only applies to PSTN accounts; only SIMS have subscription ids.
+            PhoneAccountHandle phoneAccountHandle = PhoneUtils.makePstnPhoneAccountHandle(phone);
+            Intent intent = new Intent(
+                    Intent.ACTION_CALL, Uri.fromParts(PhoneAccount.SCHEME_VOICEMAIL, "", null));
+            intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
             PendingIntent pendingIntent =
                     PendingIntent.getActivity(mContext, subId /* requestCode */, intent, 0);
             Uri ringtoneUri = VoicemailNotificationSettingsUtil.getRingtoneUri(phone);
@@ -302,6 +322,7 @@
             Notification.Builder builder = new Notification.Builder(mContext);
             builder.setSmallIcon(resId)
                     .setWhen(System.currentTimeMillis())
+                    .setColor(subInfo.getIconTint())
                     .setContentTitle(notificationTitle)
                     .setContentText(notificationText)
                     .setContentIntent(pendingIntent)
@@ -355,9 +376,23 @@
             // effort though, since there are multiple layers of messages that
             // will need to propagate that information.
 
+            SubscriptionInfo subInfo = mSubscriptionManager.getActiveSubscriptionInfo(subId);
+            if (subInfo == null) {
+                Log.w(LOG_TAG, "Found null subscription info for: " + subId);
+                return;
+            }
+
+            String notificationTitle;
+            if (mTelephonyManager.getPhoneCount() > 1) {
+                notificationTitle = subInfo.getDisplayName().toString();
+            } else {
+                notificationTitle = mContext.getString(R.string.labelCF);
+            }
+
             Notification.Builder builder = new Notification.Builder(mContext)
                     .setSmallIcon(R.drawable.stat_sys_phone_call_forward)
-                    .setContentTitle(mContext.getString(R.string.labelCF))
+                    .setColor(subInfo.getIconTint())
+                    .setContentTitle(notificationTitle)
                     .setContentText(mContext.getString(R.string.sum_cfu_enabled_indicator))
                     .setShowWhen(false)
                     .setOngoing(true);