Support preset STK names and icons for MSIM model

This change provides an easy way to replace the STK application name and
icon displayed on the launcher activity with preset resources. There are
many SIM cards in the market that send SET-UP MENU command with no alpha
identifier. This change improves the usability of multi-SIM models in
such cases.

Bug: 31295893

Change-Id: I437fa761cdd8bf47eee660c7bb2828b84c91e8af
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index a0ad403..21315db 100644
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -39,6 +39,7 @@
 import android.os.IBinder;
 import android.os.Looper;
 import android.os.Message;
+import android.os.Parcel;
 import android.os.PersistableBundle;
 import android.os.PowerManager;
 import android.os.SystemProperties;
@@ -455,7 +456,28 @@
     Menu getMainMenu(int slotId) {
         CatLog.d(LOG_TAG, "StkAppService, getMainMenu, sim id: " + slotId);
         if (slotId >=0 && slotId < mSimCount && (mStkContext[slotId].mMainCmd != null)) {
-            return mStkContext[slotId].mMainCmd.getMenu();
+            Menu menu = mStkContext[slotId].mMainCmd.getMenu();
+            if (menu != null && mSimCount > PhoneConstants.MAX_PHONE_COUNT_SINGLE_SIM) {
+                // If alpha identifier or icon identifier with the self-explanatory qualifier is
+                // specified in SET-UP MENU command, it should be more prioritized than preset ones.
+                if (menu.title == null
+                        && (menu.titleIcon == null || !menu.titleIconSelfExplanatory)) {
+                    StkMenuConfig config = StkMenuConfig.getInstance(getApplicationContext());
+                    String label = config.getLabel(slotId);
+                    Bitmap icon = config.getIcon(slotId);
+                    if (label != null || icon != null) {
+                        Parcel parcel = Parcel.obtain();
+                        menu.writeToParcel(parcel, 0);
+                        parcel.setDataPosition(0);
+                        menu = Menu.CREATOR.createFromParcel(parcel);
+                        parcel.recycle();
+                        menu.title = label;
+                        menu.titleIcon = icon;
+                        menu.titleIconSelfExplanatory = false;
+                    }
+                }
+            }
+            return menu;
         } else {
             return null;
         }