Merge "The main menu shall not be launched when the current session ends"
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index daccad2..dc551a6 100644
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -119,7 +119,6 @@
         protected int mOpCode = -1;
         private Activity mActivityInstance = null;
         private Activity mDialogInstance = null;
-        private Activity mMainActivityInstance = null;
         private int mSlotId = 0;
         private SetupEventListSettings mSetupEventListSettings = null;
         private boolean mClearSelectItem = false;
@@ -145,15 +144,6 @@
                     mDialogInstance);
             return mDialogInstance;
         }
-        final synchronized void setMainActivityInstance(Activity act) {
-            CatLog.d(this, "setMainActivityInstance act : " + mSlotId + ", " + act);
-            callSetActivityInstMsg(OP_SET_MAINACT_INST, mSlotId, act);
-        }
-        final synchronized Activity getMainActivityInstance() {
-            CatLog.d(this, "getMainActivityInstance act : " + mSlotId + ", " +
-                    mMainActivityInstance);
-            return mMainActivityInstance;
-        }
     }
 
     private volatile Looper mServiceLooper;
@@ -207,10 +197,9 @@
     static final int OP_CARD_STATUS_CHANGED = 7;
     static final int OP_SET_ACT_INST = 8;
     static final int OP_SET_DAL_INST = 9;
-    static final int OP_SET_MAINACT_INST = 10;
-    static final int OP_LOCALE_CHANGED = 11;
-    static final int OP_ALPHA_NOTIFY = 12;
-    static final int OP_IDLE_SCREEN = 13;
+    static final int OP_LOCALE_CHANGED = 10;
+    static final int OP_ALPHA_NOTIFY = 11;
+    static final int OP_IDLE_SCREEN = 12;
 
     //Invalid SetupEvent
     static final int INVALID_SETUP_EVENT = 0xFF;
@@ -628,12 +617,6 @@
                 dal = (Activity) msg.obj;
                 mStkContext[slotId].mDialogInstance = dal;
                 break;
-            case OP_SET_MAINACT_INST:
-                Activity mainAct = new Activity();
-                mainAct = (Activity) msg.obj;
-                CatLog.d(LOG_TAG, "Set activity instance. " + mainAct);
-                mStkContext[slotId].mMainActivityInstance = mainAct;
-                break;
             case OP_LOCALE_CHANGED:
                 CatLog.d(this, "Locale Changed");
                 for (int slot = PhoneConstants.SIM_ID_1; slot < mSimCount; slot++) {
@@ -860,12 +843,9 @@
             mStkContext[slotId].mCurrentMenu = mStkContext[slotId].mMainCmd.getMenu();
         }
         CatLog.d(LOG_TAG, "[handleSessionEnd][mMenuState]" + mStkContext[slotId].mMenuIsVisible);
-        // In mutiple instance architecture, the main menu for slotId will be finished when user
-        // goes to the Stk menu of the other SIM. So, we should launch a new instance for the
-        // main menu if the main menu instance has been finished.
-        // If the current menu is secondary menu, we should launch main menu.
+
         if (StkMenuActivity.STATE_SECONDARY == mStkContext[slotId].mMenuState) {
-            launchMenuActivity(null, slotId);
+            mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN;
         }
 
         // Send a local broadcast as a notice that this service handled the session end event.
@@ -1385,15 +1365,6 @@
         if (menu == null) {
             // We assume this was initiated by the user pressing the tool kit icon
             intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.yes, slotId);
-            if (mStkContext[slotId].mOpCode == OP_END_SESSION) {
-                CatLog.d(LOG_TAG, "launchMenuActivity, return OP_END_SESSION");
-                mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN;
-                if (mStkContext[slotId].mMainActivityInstance != null) {
-                    CatLog.d(LOG_TAG, "launchMenuActivity, mMainActivityInstance is not null");
-                    return;
-                }
-            }
-
             //If the last pending menu is secondary menu, "STATE" should be "STATE_SECONDARY".
             //Otherwise, it should be "STATE_MAIN".
             if (mStkContext[slotId].mOpCode == OP_LAUNCH_APP &&
diff --git a/src/com/android/stk/StkMenuActivity.java b/src/com/android/stk/StkMenuActivity.java
index 8dab6fd..9f268d1 100644
--- a/src/com/android/stk/StkMenuActivity.java
+++ b/src/com/android/stk/StkMenuActivity.java
@@ -178,7 +178,6 @@
                 return true;
             case STATE_MAIN:
                 CatLog.d(LOG_TAG, "STATE_MAIN");
-                appService.getStkContext(mSlotId).setMainActivityInstance(null);
                 cancelTimeOut();
                 finish();
                 return true;
@@ -211,12 +210,6 @@
             finish();
             return;
         }
-        //Set main menu instance here for clean up stack by other SIMs
-        //when receiving OP_LAUNCH_APP.
-        if (mState == STATE_MAIN) {
-            CatLog.d(LOG_TAG, "set main menu instance.");
-            appService.getStkContext(mSlotId).setMainActivityInstance(this);
-        }
         displayMenu();
         startTimeOut();
         invalidateOptionsMenu();
@@ -290,14 +283,6 @@
             CatLog.d(LOG_TAG, "handleDestroy - Send End Session");
             sendResponse(StkAppService.RES_ID_END_SESSION);
         }
-        if (mState == STATE_MAIN) {
-            if (appService != null) {
-                appService.getStkContext(mSlotId).setMainActivityInstance(null);
-            } else {
-                CatLog.d(LOG_TAG, "onDestroy: null appService.");
-            }
-        }
-
         LocalBroadcastManager.getInstance(this).unregisterReceiver(mLocalBroadcastReceiver);
     }