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/StkDialogActivity.java b/src/com/android/stk/StkDialogActivity.java
index dd80434..da92b24 100755
--- a/src/com/android/stk/StkDialogActivity.java
+++ b/src/com/android/stk/StkDialogActivity.java
@@ -18,6 +18,7 @@
 
 import com.android.internal.telephony.cat.CatLog;
 import com.android.internal.telephony.cat.TextMessage;
+import com.android.internal.telephony.cat.CatLog;
 
 import android.app.Activity;
 import android.content.Intent;
@@ -71,44 +72,19 @@
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
 
-        CatLog.d(LOG_TAG, "onCreate");
-        initFromIntent(getIntent());
-        if (mTextMsg == null) {
-            finish();
-            return;
-        }
-
         requestWindowFeature(Window.FEATURE_LEFT_ICON);
-        Window window = getWindow();
 
         setContentView(R.layout.stk_msg_dialog);
-        TextView mMessageView = (TextView) window
-                .findViewById(R.id.dialog_message);
 
         Button okButton = (Button) findViewById(R.id.button_ok);
         Button cancelButton = (Button) findViewById(R.id.button_cancel);
 
         okButton.setOnClickListener(this);
         cancelButton.setOnClickListener(this);
-
-        setTitle(mTextMsg.title);
-        if (!(mTextMsg.iconSelfExplanatory && mTextMsg.icon != null)) {
-            mMessageView.setText(mTextMsg.text);
-        }
-
-        if (mTextMsg.icon == null) {
-            CatLog.d(LOG_TAG, "onCreate icon is null");
-            window.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
-                    com.android.internal.R.drawable.stat_notify_sim_toolkit);
-        } else {
-            window.setFeatureDrawable(Window.FEATURE_LEFT_ICON,
-                    new BitmapDrawable(mTextMsg.icon));
-        }
     }
 
     public void onClick(View v) {
         String input = null;
-
         switch (v.getId()) {
         case OK_BUTTON:
             CatLog.d(LOG_TAG, "OK Clicked!, mSlotId: " + mSlotId);
@@ -142,24 +118,45 @@
         super.onResume();
         CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent +
                 "], sim id: " + mSlotId);
+
+        initFromIntent(getIntent());
+        if (mTextMsg == null) {
+            finish();
+            return;
+        }
+
+        Window window = getWindow();
+
+        TextView mMessageView = (TextView) window
+                .findViewById(R.id.dialog_message);
+
+        setTitle(mTextMsg.title);
+
+        if (!(mTextMsg.iconSelfExplanatory && mTextMsg.icon != null)) {
+            mMessageView.setText(mTextMsg.text);
+        }
+
+        if (mTextMsg.icon == null) {
+            window.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
+                    com.android.internal.R.drawable.stat_notify_sim_toolkit);
+        } else {
+            window.setFeatureDrawable(Window.FEATURE_LEFT_ICON,
+                    new BitmapDrawable(mTextMsg.icon));
+        }
+
         /*
-         * The user should be shown the message forever or until some high
-         * priority event occurs (such as incoming call, MMI code execution
-         * etc as mentioned in ETSI 102.223, 6.4.1).
-         *
-         * Since mTextMsg.responseNeeded is false (because the response has
-         * already been sent) and duration of the dialog is zero and userClear
-         * is true, don't set the timeout.
+         * If the userClear flag is set and dialogduration is set to 0, the display Text
+         * should be displayed to user forever until some high priority event occurs
+         * (incoming call, MMI code execution etc as mentioned under section
+         * ETSI 102.223, 6.4.1)
          */
-        if (!mTextMsg.responseNeeded &&
-                StkApp.calculateDurationInMilis(mTextMsg.duration) == 0 &&
-                mTextMsg.userClear) {
-            CatLog.d(this, "User should clear text..show message forever");
+        if (StkApp.calculateDurationInMilis(mTextMsg.duration) == 0 &&
+            !mTextMsg.responseNeeded && mTextMsg.userClear) {
+            CatLog.d(this, "User should clear text..showing message forever");
             return;
         }
 
         appService.setDisplayTextDlgVisibility(true, mSlotId);
-
         startTimeOut(mTextMsg.userClear);
     }
 
@@ -233,6 +230,12 @@
         CatLog.d(LOG_TAG, "onRestoreInstanceState - [" + mTextMsg + "]");
     }
 
+    @Override
+    protected void onNewIntent(Intent intent) {
+        CatLog.d(this, "onNewIntent - updating the same Dialog box");
+        setIntent(intent);
+    }
+
     private void sendResponse(int resId, boolean confirmed) {
         if (mSlotId == -1) {
             CatLog.d(LOG_TAG, "sim id is invalid");
@@ -246,13 +249,15 @@
 
         CatLog.d(LOG_TAG, "sendResponse resID[" + resId + "] confirmed[" + confirmed + "]");
 
-        Bundle args = new Bundle();
-        args.putInt(StkAppService.OPCODE, StkAppService.OP_RESPONSE);
-        args.putInt(StkAppService.SLOT_ID, mSlotId);
-        args.putInt(StkAppService.RES_ID, resId);
-        args.putBoolean(StkAppService.CONFIRMATION, confirmed);
-        startService(new Intent(this, StkAppService.class).putExtras(args));
-        mIsResponseSent = true;
+        if (mTextMsg.responseNeeded) {
+            Bundle args = new Bundle();
+            args.putInt(StkAppService.OPCODE, StkAppService.OP_RESPONSE);
+            args.putInt(StkAppService.SLOT_ID, mSlotId);
+            args.putInt(StkAppService.RES_ID, resId);
+            args.putBoolean(StkAppService.CONFIRMATION, confirmed);
+            startService(new Intent(this, StkAppService.class).putExtras(args));
+            mIsResponseSent = true;
+        }
     }
 
     private void sendResponse(int resId) {
@@ -277,6 +282,7 @@
     }
 
     private void startTimeOut(boolean waitForUserToClear) {
+
         // Reset timeout.
         cancelTimeOut();
         int dialogDuration = StkApp.calculateDurationInMilis(mTextMsg.duration);