Remove unnecessary content title from notifications

NotificationBuilder.setContentTitle() is called with the application
name in some scenarios, but it is unnecessary in many cases because the
header area also shows the application name. Content title should be
specified only when it is helpful to differentiate multiple SIM cards.

Bug: 170175877
Test: Manually tested various SSIM/MSIM scenarios

Change-Id: I118a7b0998ddd74184a1def30d6b483aa6854e01
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index 0f9f0e8..6b81df6 100644
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -1667,17 +1667,10 @@
 
     private void launchNotificationOnKeyguard(int slotId, String message) {
         Notification.Builder builder = new Notification.Builder(this, STK_NOTIFICATION_CHANNEL_ID);
+        setNotificationTitle(slotId, builder);
 
         builder.setStyle(new Notification.BigTextStyle(builder).bigText(message));
         builder.setContentText(message);
-
-        Menu menu = getMainMenu(slotId);
-        if (menu == null || TextUtils.isEmpty(menu.title)) {
-            builder.setContentTitle("");
-        } else {
-            builder.setContentTitle(menu.title);
-        }
-
         builder.setSmallIcon(R.drawable.stat_notify_sim_toolkit);
         builder.setOngoing(true);
         builder.setOnlyAlertOnce(true);
@@ -2138,12 +2131,7 @@
             createAllChannels();
             final Notification.Builder notificationBuilder = new Notification.Builder(
                     StkAppService.this, STK_NOTIFICATION_CHANNEL_ID);
-            if (mStkContext[slotId].mMainCmd != null &&
-                    mStkContext[slotId].mMainCmd.getMenu() != null) {
-                notificationBuilder.setContentTitle(mStkContext[slotId].mMainCmd.getMenu().title);
-            } else {
-                notificationBuilder.setContentTitle("");
-            }
+            setNotificationTitle(slotId, notificationBuilder);
             notificationBuilder
                     .setSmallIcon(R.drawable.stat_notify_sim_toolkit);
             notificationBuilder.setContentIntent(pendingIntent);
@@ -2172,6 +2160,30 @@
         }
     }
 
+    private void setNotificationTitle(int slotId, Notification.Builder builder) {
+        Menu menu = getMainMenu(slotId);
+        if (menu == null || TextUtils.isEmpty(menu.title)
+                || TextUtils.equals(menu.title, getResources().getString(R.string.app_name))) {
+            // No need to set a content title in the content area if no title (alpha identifier
+            // of SET-UP MENU command) is available for the specified slot or the title is same
+            // as the application label.
+            return;
+        }
+
+        for (int index = 0; index < mSimCount; index++) {
+            if (index != slotId) {
+                Menu otherMenu = getMainMenu(index);
+                if (otherMenu != null && !TextUtils.equals(menu.title, otherMenu.title)) {
+                    // Set the title (alpha identifier of SET-UP MENU command) as the content title
+                    // to differentiate it from other main menu with different alpha identifier
+                    // (including null) is available.
+                    builder.setContentTitle(menu.title);
+                    return;
+                }
+            }
+        }
+    }
+
     /** Creates the notification channel and registers it with NotificationManager.
      * If a channel with the same ID is already registered, NotificationManager will
      * ignore this call.