Stk: These changes are related to DISPLAY Text pro cmd

1. Handle high priority and normal priority display text
command correctly.

2. For display text with immediate response, send the terminal
response immediately after showing the text dialog. Block all
responses from StkDialogActivity, if display text is
with immediate response. Remove the check for response needed
in StkAppService, since un wanted responses are already
blocked in StkDialogActivity.

3. While the text is being displayed if a next Proactive command is
received, it should be acted upon immediately.

Bug: 17553408
Change-Id: I8dd74e0fb1434b0753cedfea2f2fcc1ba2f18067
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index 675d832..4fb5f91 100755
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -117,7 +117,7 @@
         private boolean mBackGroundTRSent = false;
         private int mSlotId = 0;
         private CatCmdMessage mIdleModeTextCmd = null;
-        private boolean mDisplayText = false;
+        private boolean mIsDisplayTextPending = false;
         private boolean mScreenIdle = true;
         private SetupEventListSettings mSetupEventListSettings = null;
         private boolean mClearSelectItem = false;
@@ -558,17 +558,15 @@
                 }
                 break;
             case OP_RESPONSE:
-                if (mStkContext[slotId].responseNeeded) {
-                    handleCmdResponse((Bundle) msg.obj, slotId);
-                }
+                handleCmdResponse((Bundle) msg.obj, slotId);
                 // call delayed commands if needed.
                 if (mStkContext[slotId].mCmdsQ.size() != 0) {
                     callDelayedMsg(slotId);
                 } else {
                     mStkContext[slotId].mCmdInProgress = false;
                 }
-                // reset response needed state var to its original value.
-                mStkContext[slotId].responseNeeded = true;
+                //reset mIsDisplayTextPending after sending the  response.
+                mStkContext[slotId].mIsDisplayTextPending = false;
                 break;
             case OP_END_SESSION:
                 if (!mStkContext[slotId].mCmdInProgress) {
@@ -700,13 +698,15 @@
         if (mStkContext[slotId].mIdleModeTextCmd != null && mStkContext[slotId].mScreenIdle) {
            launchIdleText(slotId);
         }
-        if (mStkContext[slotId].mDisplayText) {
+        // Show user the display text or send screen busy response
+        // if previous display text command is pending.
+        if (mStkContext[slotId].mIsDisplayTextPending) {
             if (!mStkContext[slotId].mScreenIdle) {
                 sendScreenBusyResponse(slotId);
             } else {
                 launchTextDialog(slotId);
             }
-            mStkContext[slotId].mDisplayText = false;
+            mStkContext[slotId].mIsDisplayTextPending = false;
             // If an idle text proactive command is set then the
             // request for getting screen status still holds true.
             if (mStkContext[slotId].mIdleModeTextCmd == null) {
@@ -725,8 +725,6 @@
         CatLog.d(this, "SCREEN_BUSY");
         resMsg.setResultCode(ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS);
         mStkService[slotId].onCmdResponse(resMsg);
-        // reset response needed state var to its original value.
-        mStkContext[slotId].responseNeeded = true;
         if (mStkContext[slotId].mCmdsQ.size() != 0) {
             callDelayedMsg(slotId);
         } else {
@@ -872,7 +870,6 @@
         switch (cmdMsg.getCmdType()) {
         case DISPLAY_TEXT:
             TextMessage msg = cmdMsg.geTextMessage();
-            mStkContext[slotId].responseNeeded = msg.responseNeeded;
             waitForUsersResponse = msg.responseNeeded;
             if (mStkContext[slotId].lastSelectedItem != null) {
                 msg.title = mStkContext[slotId].lastSelectedItem;
@@ -894,7 +891,7 @@
                 Intent StkIntent = new Intent(AppInterface.CHECK_SCREEN_IDLE_ACTION);
                 StkIntent.putExtra(SCREEN_STATUS_REQUEST, true);
                 sendBroadcast(StkIntent);
-                mStkContext[slotId].mDisplayText = true;
+                mStkContext[slotId].mIsDisplayTextPending = true;
             } else {
                 launchTextDialog(slotId);
             }
@@ -1006,8 +1003,7 @@
             mStkContext[slotId].mCurrentSetupEventCmd = mStkContext[slotId].mCurrentCmd;
             mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
             if ((mStkContext[slotId].mIdleModeTextCmd == null)
-                    && (!mStkContext[slotId].mDisplayText)) {
-
+                    && (!mStkContext[slotId].mIsDisplayTextPending)) {
                 for (int i : mStkContext[slotId].mSetupEventListSettings.eventList) {
                     if (i == IDLE_SCREEN_AVAILABLE_EVENT) {
                         CatLog.d(this," IDLE_SCREEN_AVAILABLE_EVENT present in List");
@@ -1353,6 +1349,12 @@
             newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage());
             newIntent.putExtra(SLOT_ID, slotId);
             startActivity(newIntent);
+            // For display texts with immediate response, send the terminal response
+            // immediately. responseNeeded will be false, if display text command has
+            // the immediate response tlv.
+            if (!mStkContext[slotId].mCurrentCmd.geTextMessage().responseNeeded) {
+                sendResponse(RES_ID_CONFIRM, slotId, true);
+            }
         }
     }
 
@@ -1372,7 +1374,7 @@
     }
 
     private void sendSetUpEventResponse(int event, byte[] addedInfo, int slotId) {
-        CatLog.d(this, "sendSetUpEventResponse: event : " + event);
+        CatLog.d(this, "sendSetUpEventResponse: event : " + event + "slotId = " + slotId);
 
         if (mStkContext[slotId].mCurrentSetupEventCmd == null){
             CatLog.e(this, "mCurrentSetupEventCmd is null");