The STK menu activity cannot treat subsequent user input

The boolean field 'mAcceptUsersInput' is mistakenly left in some
use-cases after it is changed to false. That causes an issue that user
cannot do anything on the STK main menu.

The boolean field is changed to false when user clicks one of the menu
items on the STK main menu. It is changed back to true in onResume()
when screen transition happens. However, we cannot say that screen
transition always happens after selecting the item on the main menu.

That is why we have to introduce one more trigger to reset the value of
'mAcceptUsersInput' when the current session is ended.

Bug: 31288411
Change-Id: I15ac01269a474e1dbc04ad250762066dfdb70f1e
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index ea30d80..96d596e 100644
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -45,6 +45,7 @@
 import android.os.SystemProperties;
 import android.os.Vibrator;
 import android.provider.Settings;
+import android.support.v4.content.LocalBroadcastManager;
 import android.telephony.CarrierConfigManager;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
@@ -249,6 +250,8 @@
 
     private static final String LOG_TAG = new Object(){}.getClass().getEnclosingClass().getName();
 
+    static final String SESSION_ENDED = "session_ended";
+
     // Inner class used for queuing telephony messages (proactive commands,
     // session end) while the service is busy processing a previous message.
     private class DelayedCmd {
@@ -438,6 +441,14 @@
         return false;
     }
 
+    boolean isMainMenuAvailable(int slotId) {
+        if (slotId >= 0 && slotId < mSimCount) {
+            // The main menu can handle the next user operation if the previous session finished.
+            return (mStkContext[slotId].lastSelectedItem == null) ? true : false;
+        }
+        return false;
+    }
+
     /*
      * Package api used by StkMenuActivity to get its Menu parameter.
      */
@@ -836,6 +847,12 @@
         if (StkMenuActivity.STATE_SECONDARY == mStkContext[slotId].mMenuState) {
             launchMenuActivity(null, slotId);
         }
+
+        // Send a local broadcast as a notice that this service handled the session end event.
+        Intent intent = new Intent(SESSION_ENDED);
+        intent.putExtra(SLOT_ID, slotId);
+        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
+
         if (mStkContext[slotId].mCmdsQ.size() != 0) {
             callDelayedMsg(slotId);
         } else {