Merge tag 'android-11.0.0_r48' into int/11/fp3

Android 11.0.0 Release 48 (RD2A.211001.002)

* tag 'android-11.0.0_r48':

Change-Id: If8f8ea6d756ee255bed9623e6b1c802090cedcd0
diff --git a/res/layout/stk_input.xml b/res/layout/stk_input.xml
index 427ad42..d0cbe01 100644
--- a/res/layout/stk_input.xml
+++ b/res/layout/stk_input.xml
@@ -26,6 +26,16 @@
        android:background="?android:attr/colorBackground"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
+    <LinearLayout android:id="@+id/titleBar"
+        android:layout_width="match_parent"
+        android:layout_height="50dp"
+        android:orientation="horizontal">
+        <ImageView android:id="@+id/icon"
+            android:layout_width="25dp"
+            android:layout_height="25dp"
+            android:layout_alignParentLeft="true"
+            android:layout_marginLeft="8dp" />
+    </LinearLayout>
     <ImageButton
         style="@style/Widget.AppCompat.ActionButton.Overflow"
         android:id="@+id/more"
@@ -37,6 +47,7 @@
     <ScrollView
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
+        android:layoutDirection="locale"
         android:layout_height="wrap_content">
         <LinearLayout
             android:layout_width="match_parent"
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index 4ef5f6c..9606a78 100644
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -292,6 +292,10 @@
     // system property to set the STK specific default url for launch browser proactive cmds
     private static final String STK_BROWSER_DEFAULT_URL_SYSPROP = "persist.radio.stk.default_url";
 
+    // Description of the Icon that is being dispalyed in a Stk activity.
+    public static final String TEXT_DEFAULT_ICON = "Stk Default Icon";
+    public static final String TEXT_ICON_FROM_COMMAND="Stk Icon from Command";
+
     private static final int NOTIFICATION_ON_KEYGUARD = 1;
     private static final long[] VIBRATION_PATTERN = new long[] { 0, 350, 250, 350 };
     private BroadcastReceiver mUserPresentReceiver = null;
@@ -744,8 +748,10 @@
             } else {
                 IccRefreshResponse state = new IccRefreshResponse();
                 state.refreshResult = args.getInt(AppInterface.REFRESH_RESULT);
+                state.aid = args.getString(AppInterface.AID);
 
-                CatLog.d(LOG_TAG, "Icc Refresh Result: "+ state.refreshResult);
+                CatLog.d(LOG_TAG, "Icc Refresh Result: "+ state.refreshResult
+                        + " aid: " + state.aid);
                 if ((state.refreshResult == IccRefreshResponse.REFRESH_RESULT_INIT) ||
                     (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET)) {
                     // Clear Idle Text
@@ -1088,13 +1094,6 @@
         case DISPLAY_TEXT:
             TextMessage msg = cmdMsg.geTextMessage();
             waitForUsersResponse = msg.responseNeeded;
-            if (mStkContext[slotId].lastSelectedItem != null) {
-                msg.title = mStkContext[slotId].lastSelectedItem;
-            } else if (mStkContext[slotId].mMainCmd != null){
-                if (!getResources().getBoolean(R.bool.show_menu_title_only_on_menu)) {
-                    msg.title = mStkContext[slotId].mMainCmd.getMenu().title;
-                }
-            }
             //If we receive a low priority Display Text and the device is
             // not displaying any STK related activity and the screen is not idle
             // ( that is, device is in an interactive state), then send a screen busy
@@ -1173,13 +1172,26 @@
             break;
         case SEND_DTMF:
         case SEND_SMS:
-        case REFRESH:
         case RUN_AT:
         case SEND_SS:
         case SEND_USSD:
         case GET_CHANNEL_STATUS:
             waitForUsersResponse = false;
             launchEventMessage(slotId);
+            //Reset the mCurrentCmd to mMainCmd, to avoid wrong TR sent for
+            //SEND_SMS/SS/USSD, when user launches STK app next time and do
+            //a menu selection.
+            mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
+            break;
+        case REFRESH:
+            waitForUsersResponse = false;
+            launchEventMessage(slotId);
+            // Idle mode text needs to be cleared for init or reset modes of refresh
+            if (cmdMsg.isRefreshResetOrInit()) {
+                mNotificationManager.cancel(getNotificationId(slotId));
+                mStkContext[slotId].mIdleModeTextCmd = null;
+                CatLog.d(this, "Clean idle mode text due to refresh");
+            }
             break;
         case LAUNCH_BROWSER:
             // The device setup process should not be interrupted by launching browser.
@@ -2033,6 +2045,7 @@
         ImageView iv = (ImageView) v
                 .findViewById(com.android.internal.R.id.icon);
         if (msg.icon != null) {
+            iv.setContentDescription(TEXT_ICON_FROM_COMMAND);
             iv.setImageBitmap(msg.icon);
         } else {
             iv.setVisibility(View.GONE);
@@ -2155,6 +2168,8 @@
                     .setSmallIcon(R.drawable.stat_notify_sim_toolkit);
             notificationBuilder.setContentIntent(pendingIntent);
             notificationBuilder.setOngoing(true);
+            notificationBuilder.setStyle(new Notification.BigTextStyle(notificationBuilder)
+                    .bigText(msg.text));
             notificationBuilder.setOnlyAlertOnce(true);
             // Set text and icon for the status bar and notification body.
             if (mStkContext[slotId].mIdleModeTextCmd.hasIconLoadFailed() ||
@@ -2286,17 +2301,13 @@
                     | Intent.FLAG_ACTIVITY_SINGLE_TOP
                     | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
             newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage());
+            newIntent.putExtra("TONE", mStkContext[slotId].mCurrentCmd.getToneSettings());
             newIntent.putExtra(SLOT_ID, slotId);
             newIntent.setData(uriData);
             startActivity(newIntent);
         }
     }
 
-    private void finishToneDialogActivity() {
-        Intent finishIntent = new Intent(FINISH_TONE_ACTIVITY_ACTION);
-        sendBroadcast(finishIntent);
-    }
-
     private void handleStopTone(Message msg, int slotId) {
         int resId = 0;
 
@@ -2305,8 +2316,6 @@
         // 2.STOP_TONE_USER: user pressed the back key.
         if (msg.what == OP_STOP_TONE) {
             resId = RES_ID_DONE;
-            // Dismiss Tone dialog, after finishing off playing the tone.
-            if (PLAY_TONE_WITH_DIALOG.equals((Integer) msg.obj)) finishToneDialogActivity();
         } else if (msg.what == OP_STOP_TONE_USER) {
             resId = RES_ID_END_SESSION;
         }
diff --git a/src/com/android/stk/StkCmdReceiver.java b/src/com/android/stk/StkCmdReceiver.java
index 025b68e..517c70a 100644
--- a/src/com/android/stk/StkCmdReceiver.java
+++ b/src/com/android/stk/StkCmdReceiver.java
@@ -75,6 +75,7 @@
             args.putInt(AppInterface.REFRESH_RESULT,
                     intent.getIntExtra(AppInterface.REFRESH_RESULT,
                     IccRefreshResponse.REFRESH_RESULT_FILE_UPDATE));
+            args.putString(AppInterface.AID, intent.getStringExtra(AppInterface.AID));
         } else if (StkAppService.OP_ALPHA_NOTIFY == op) {
             String alphaString = intent.getStringExtra(AppInterface.ALPHA_STRING);
             args.putString(AppInterface.ALPHA_STRING, alphaString);
diff --git a/src/com/android/stk/StkDialogActivity.java b/src/com/android/stk/StkDialogActivity.java
index 49dd501..f48d74b 100644
--- a/src/com/android/stk/StkDialogActivity.java
+++ b/src/com/android/stk/StkDialogActivity.java
@@ -24,6 +24,7 @@
 import android.content.Intent;
 import android.os.Bundle;
 import android.os.SystemClock;
+import android.os.SystemProperties;
 import android.telephony.SubscriptionManager;
 import android.text.TextUtils;
 import android.view.LayoutInflater;
@@ -62,6 +63,10 @@
 
     private AlertDialog mAlertDialog;
 
+    // system property to enable/disable adding content description
+    private static String ENABLE_CONTENT_DESCRIPTION = "persist.vendor.stk.enable_content";
+    private boolean mEnableContent = SystemProperties.getBoolean(ENABLE_CONTENT_DESCRIPTION, false);
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -135,8 +140,16 @@
 
         if (mTextMsg.icon != null) {
             iv.setImageBitmap(mTextMsg.icon);
+            if (mEnableContent) {
+                iv.setContentDescription(StkAppService.TEXT_ICON_FROM_COMMAND + ": "
+                    + mTextMsg.text);
+            }
         } else {
-            iv.setVisibility(View.GONE);
+            if (mEnableContent) {
+                iv.setContentDescription(StkAppService.TEXT_DEFAULT_ICON);
+            } else {
+                iv.setVisibility(View.GONE);
+            }
         }
 
         // Per spec, only set text if the icon is not provided or not self-explanatory
diff --git a/src/com/android/stk/StkInputActivity.java b/src/com/android/stk/StkInputActivity.java
index 0af6767..8a36a53 100644
--- a/src/com/android/stk/StkInputActivity.java
+++ b/src/com/android/stk/StkInputActivity.java
@@ -34,6 +34,7 @@
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
+import android.view.Window;
 import android.view.WindowManager;
 import android.view.inputmethod.EditorInfo;
 import android.widget.Button;
@@ -161,6 +162,8 @@
             return;
         }
 
+        requestWindowFeature(Window.FEATURE_NO_TITLE);
+
         // Set the layout for this activity.
         setContentView(R.layout.stk_input);
         setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
@@ -457,6 +460,8 @@
 
         if (mStkInput.icon != null) {
             ImageView imageView = (ImageView) findViewById(R.id.icon);
+            imageView.setContentDescription(StkAppService.TEXT_ICON_FROM_COMMAND + ": "
+                    + mStkInput.text);
             imageView.setImageBitmap(mStkInput.icon);
             imageView.setVisibility(View.VISIBLE);
         }
diff --git a/src/com/android/stk/StkMenuActivity.java b/src/com/android/stk/StkMenuActivity.java
index c75e3ab..b35877f 100644
--- a/src/com/android/stk/StkMenuActivity.java
+++ b/src/com/android/stk/StkMenuActivity.java
@@ -380,6 +380,7 @@
             // Display title & title icon
             if (mStkMenu.titleIcon != null) {
                 mTitleIconView.setImageBitmap(mStkMenu.titleIcon);
+                mTitleIconView.setContentDescription(StkAppService.TEXT_ICON_FROM_COMMAND);
                 mTitleIconView.setVisibility(View.VISIBLE);
                 mTitleTextView.setVisibility(View.INVISIBLE);
                 if (!mStkMenu.titleIconSelfExplanatory) {
diff --git a/src/com/android/stk/StkMenuAdapter.java b/src/com/android/stk/StkMenuAdapter.java
index c53b3ac..4398280 100644
--- a/src/com/android/stk/StkMenuAdapter.java
+++ b/src/com/android/stk/StkMenuAdapter.java
@@ -60,6 +60,8 @@
         } else {
             imageView.setImageBitmap(item.icon);
             imageView.setVisibility(View.VISIBLE);
+            // Add content description for the icon.
+            imageView.setContentDescription(StkAppService.TEXT_ICON_FROM_COMMAND);
         }
 
         return convertView;
diff --git a/src/com/android/stk/ToneDialog.java b/src/com/android/stk/ToneDialog.java
index 2efeecd..5ce50bf 100644
--- a/src/com/android/stk/ToneDialog.java
+++ b/src/com/android/stk/ToneDialog.java
@@ -32,7 +32,7 @@
 import android.widget.TextView;
 import com.android.internal.telephony.cat.CatLog;
 import com.android.internal.telephony.cat.TextMessage;
-import com.android.internal.telephony.cat.CatLog;
+import com.android.internal.telephony.cat.ToneSettings;
 
 /**
  * Activity used to display tone dialog.
@@ -40,12 +40,28 @@
  */
 public class ToneDialog extends Activity {
     TextMessage toneMsg = null;
+    ToneSettings settings = null;
     int mSlotId = -1;
     private AlertDialog mAlertDialog;
 
     private static final String LOG_TAG =
             new Object(){}.getClass().getEnclosingClass().getSimpleName();
 
+    Handler mToneStopper = new Handler() {
+            @Override
+            public void handleMessage(Message msg) {
+                switch (msg.what) {
+                case MSG_ID_STOP_TONE:
+                    CatLog.d(LOG_TAG, "Finishing Tone dialog activity");
+                    finish();
+                    break;
+                }
+            }
+    };
+
+    // Message id to signal tone duration timeout.
+    private static final int MSG_ID_STOP_TONE = 0xda;
+
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
@@ -54,8 +70,6 @@
         initFromIntent(getIntent());
         // Register receiver
         IntentFilter filter = new IntentFilter();
-        filter.addAction(StkAppService.FINISH_TONE_ACTIVITY_ACTION);
-        registerReceiver(mFinishActivityReceiver, filter);
 
         AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
         LayoutInflater inflater = this.getLayoutInflater();
@@ -82,6 +96,18 @@
             tv.setVisibility(View.GONE);
         }
 
+        if (null == settings) {
+            CatLog.d(LOG_TAG, "onCreate - null settings - finish");
+            finish();
+            return;
+        }
+
+        int timeout = StkApp.calculateDurationInMilis(settings.duration);
+        if (timeout == 0) {
+            timeout = StkApp.TONE_DEFAULT_TIMEOUT;
+        }
+        mToneStopper.sendEmptyMessageDelayed(MSG_ID_STOP_TONE, timeout);
+
         alertDialogBuilder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                     @Override
                     public void onCancel(DialogInterface dialog) {
@@ -97,33 +123,21 @@
     @Override
     protected void onDestroy() {
         CatLog.d(LOG_TAG, "onDestroy");
+        mToneStopper.removeMessages(MSG_ID_STOP_TONE);
         super.onDestroy();
 
-        unregisterReceiver(mFinishActivityReceiver);
-
         if (mAlertDialog != null && mAlertDialog.isShowing()) {
             mAlertDialog.dismiss();
             mAlertDialog = null;
         }
     }
 
-    private BroadcastReceiver mFinishActivityReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // Intent received from StkAppService to finish ToneDialog activity,
-            // after finishing off playing the tone.
-            if (intent.getAction().equals(StkAppService.FINISH_TONE_ACTIVITY_ACTION)) {
-                CatLog.d(LOG_TAG, "Finishing Tone dialog activity");
-                finish();
-            }
-        }
-    };
-
     private void initFromIntent(Intent intent) {
         if (intent == null) {
             finish();
         }
         toneMsg = intent.getParcelableExtra("TEXT");
+        settings = intent.getParcelableExtra("TONE");
         mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1);
     }