Merge "Support ENVELOPE (EVENT DOWNLOAD - User activity) command" into pi-dev
am: dfa122d606

Change-Id: Ic627c1855f80e24a0726da73122322921658e738
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 29928eb..ee434c0 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -110,7 +110,6 @@
                 <action android:name= "com.android.internal.stk.session_end" />
                 <action android:name= "com.android.internal.stk.icc_status_change" />
                 <action android:name= "com.android.internal.stk.alpha_notify" />
-                <action android:name= "android.intent.action.LOCALE_CHANGED" />
             </intent-filter>
         </receiver>
 
diff --git a/res/layout/stk_input.xml b/res/layout/stk_input.xml
index c2a34aa..7f8f96d 100644
--- a/res/layout/stk_input.xml
+++ b/res/layout/stk_input.xml
@@ -52,7 +52,6 @@
                 android:layout_height="wrap_content"
                 android:textAppearance="?android:attr/textAppearanceMedium"
                 android:textColor="?android:attr/textColorPrimary"
-                android:gravity="center_horizontal"
                 android:paddingBottom="30dip" />
             <LinearLayout
                 android:layout_width="match_parent"
@@ -62,18 +61,16 @@
                     android:visibility="visible"
                     android:orientation="vertical"
                     android:layout_width="match_parent"
-                    android:layout_marginLeft="10dip"
-                    android:layout_marginRight="10dip"
                     android:layout_height="wrap_content">
                     <LinearLayout
                         android:id="@+id/input_restriction_info"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_marginLeft="4dip"
-                        android:orientation="horizontal">
+                        android:orientation="vertical">
                         <TextView
                             android:id="@+id/input_type"
-                            android:gravity="left"
+                            android:gravity="start"
                             android:textAppearance="?android:attr/textAppearanceMedium"
                             android:textColor="?android:attr/textColorSecondary"
                             android:layout_width="wrap_content"
@@ -83,29 +80,35 @@
                             android:textAppearance="?android:attr/textAppearanceMedium"
                             android:textColor="?android:attr/textColorSecondary"
                             android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:layout_marginLeft="4dip" />
+                            android:layout_height="wrap_content" />
                     </LinearLayout>
                     <EditText
                         android:id="@+id/in_text"
                         android:layout_gravity="center_horizontal"
-                        android:layout_marginBottom="20dip"
+                        android:layout_marginBottom="16dip"
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content" />
                     <LinearLayout
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         android:gravity="end"
+                        android:layout_marginStart="4dip"
+                        android:layout_marginBottom="16dip"
                         android:orientation="horizontal">
                         <Button
                             android:id="@+id/button_cancel"
-                            android:layout_height="wrap_content"
+                            android:layout_height="48dip"
                             android:layout_width="wrap_content"
+                            android:layout_weight="1"
+                            android:gravity="center_vertical"
+                            android:paddingStart="0dip"
+                            style="@android:style/Widget.Material.Button.Borderless.Colored"
                             android:text="@string/button_cancel" />
                         <Button
                             android:id="@+id/button_ok"
-                            android:layout_height="wrap_content"
+                            android:layout_height="48dip"
                             android:layout_width="wrap_content"
+                            style="@android:style/Widget.Material.Button.Colored"
                             android:text="@string/button_ok" />
                     </LinearLayout>
                 </LinearLayout>
@@ -120,11 +123,13 @@
                         android:id="@+id/button_no"
                         android:layout_height="wrap_content"
                         android:layout_width="wrap_content"
+                        style="@android:style/Widget.Material.Button.Borderless.Colored"
                         android:text="@string/button_no" />
                     <Button
                         android:id="@+id/button_yes"
                         android:layout_height="wrap_content"
                         android:layout_width="wrap_content"
+                        style="@android:style/Widget.Material.Button.Colored"
                         android:text="@string/button_yes" />
                 </LinearLayout>
             </LinearLayout>
diff --git a/res/values-or/strings.xml b/res/values-or/strings.xml
deleted file mode 100644
index e827784..0000000
--- a/res/values-or/strings.xml
+++ /dev/null
@@ -1,46 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2007 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_name" msgid="8396461461738434341">"SIM ଟୁଲକିଟ୍‌"</string>
-    <string name="menu_end_session" msgid="7368541737750982217">"ସେସନ୍‍ ସମାପ୍ତ କରନ୍ତୁ"</string>
-    <string name="help" msgid="9209980881219397319">"ସହାୟତା"</string>
-    <string name="menu_back" msgid="301227740977453364">"ପଛକୁ"</string>
-    <string name="service_name" msgid="6860303747999592491">"ସେବାର ନାମ"</string>
-    <string name="stk_no_service" msgid="5427773116839809131">"କୌଣସି ସେବା ଉପଲବ୍ଧ ନାହିଁ"</string>
-    <string name="button_ok" msgid="5760722312558549555">"ଠିକ୍‌ ଅଛି"</string>
-    <string name="button_cancel" msgid="1997847915560800261">"କ୍ୟାନ୍ସଲ୍‍ କରନ୍ତୁ"</string>
-    <string name="button_yes" msgid="624420260648337203">"ହଁ"</string>
-    <string name="button_no" msgid="1824959157582605627">"ନା"</string>
-    <string name="alphabet" msgid="1583185545938805861">"ଅକ୍ଷର"</string>
-    <string name="digits" msgid="1746796679021682388">"ସଂଖ୍ୟା (0-9, *, #, +)"</string>
-    <string name="default_call_setup_msg" msgid="7960194995759849940">"କଲ୍‌ ଚାଲୁଛି…"</string>
-    <string name="default_setup_call_msg" msgid="6126904475461162162">"କଲ୍‌ ସେଟଅପ୍‌ ହେଉଛି"</string>
-    <string name="stk_app_state" msgid="18582277302584082">"ଆପ୍ଲିକେଶନ୍‌ର ସ୍ଥିତି"</string>
-    <string name="enable_app" msgid="3701224550936728203">"ଚାଲୁ ହୋଇଛି"</string>
-    <string name="disable_app" msgid="6725081975611415214">"ବନ୍ଦ ହୋଇଛି"</string>
-    <string name="stk_dialog_title" msgid="6954825385456886726">"SIM ଟୁଲକିଟ୍‌"</string>
-    <string name="default_tone_dialog_msg" msgid="4595366992944391641">"ଟୋନ୍‌ ବଜାଯାଉଛି"</string>
-    <string name="default_open_channel_msg" msgid="2216070254100295924">"ଚ୍ୟାନେଲ୍‌ ଖୋଲିବେ?"</string>
-    <string name="default_send_data_msg" msgid="6011219698689931272">"ଡାଟା ପଠାଯାଉଛି"</string>
-    <string name="default_receive_data_msg" msgid="618096941772010682">"ଡାଟା ପ୍ରାପ୍ତ କରୁଛି"</string>
-    <string name="default_close_channel_msg" msgid="765364262263839824">"ଚ୍ୟାନେଲ୍‌ ବନ୍ଦ ଅଛି"</string>
-    <string name="stk_dialog_accept" msgid="8498901537508923727">"ହଁ"</string>
-    <string name="stk_dialog_reject" msgid="921848059485746796">"ନା"</string>
-    <string name="no_sim_card_inserted" msgid="5316620398365235988">"SIM ଟୁଲକିଟ୍‌ ଲଞ୍ଚ କରିବାଲାଗି ଦୟାକରି SIM କାର୍ଡ ଭର୍ତ୍ତି କରନ୍ତୁ"</string>
-    <string name="stk_channel_name" msgid="8828587788561382056">"ମୋବାଇଲ୍‍ ସେବା ମେସେଜ୍‌"</string>
-</resources>
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index c7f897e..c010185 100644
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -176,6 +176,7 @@
     private StkContext[] mStkContext = null;
     private int mSimCount = 0;
     private IProcessObserver.Stub mProcessObserver = null;
+    private BroadcastReceiver mLocaleChangeReceiver = null;
     private TonePlayer mTonePlayer = null;
     private Vibrator mVibrator = null;
     private BroadcastReceiver mUserActivityReceiver = null;
@@ -400,6 +401,7 @@
         CatLog.d(LOG_TAG, "onDestroy()");
         unregisterUserActivityReceiver();
         unregisterProcessObserver();
+        unregisterLocaleChangeReceiver();
         sInstance = null;
         waitForLooper();
         mServiceLooper.quit();
@@ -1662,6 +1664,18 @@
     }
 
     private void unregisterEvent(int event, int slotId) {
+        for (int slot = PhoneConstants.SIM_ID_1; slot < mSimCount; slot++) {
+            if (slot != slotId) {
+                if (mStkContext[slot].mSetupEventListSettings != null) {
+                    if (findEvent(event, mStkContext[slot].mSetupEventListSettings.eventList)) {
+                        // The specified event shall never be canceled
+                        // if there is any other SIM card which requests the event.
+                        return;
+                    }
+                }
+            }
+        }
+
         switch (event) {
             case USER_ACTIVITY_EVENT:
                 unregisterUserActivityReceiver();
@@ -1670,6 +1684,8 @@
                 unregisterProcessObserver(AppInterface.CommandType.SET_UP_EVENT_LIST, slotId);
                 break;
             case LANGUAGE_SELECTION_EVENT:
+                unregisterLocaleChangeReceiver();
+                break;
             default:
                 break;
         }
@@ -1688,6 +1704,8 @@
                     registerProcessObserver();
                     break;
                 case LANGUAGE_SELECTION_EVENT:
+                    registerLocaleChangeReceiver();
+                    break;
                 default:
                     break;
             }
@@ -1789,6 +1807,28 @@
         }
     }
 
+    private synchronized void registerLocaleChangeReceiver() {
+        if (mLocaleChangeReceiver == null) {
+            mLocaleChangeReceiver = new BroadcastReceiver() {
+                @Override public void onReceive(Context context, Intent intent) {
+                    if (Intent.ACTION_LOCALE_CHANGED.equals(intent.getAction())) {
+                        Message message = mServiceHandler.obtainMessage();
+                        message.arg1 = OP_LOCALE_CHANGED;
+                        mServiceHandler.sendMessage(message);
+                    }
+                }
+            };
+            registerReceiver(mLocaleChangeReceiver, new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
+        }
+    }
+
+    private synchronized void unregisterLocaleChangeReceiver() {
+        if (mLocaleChangeReceiver != null) {
+            unregisterReceiver(mLocaleChangeReceiver);
+            mLocaleChangeReceiver = null;
+        }
+    }
+
     private void sendSetUpEventResponse(int event, byte[] addedInfo, int slotId) {
         CatLog.d(this, "sendSetUpEventResponse: event : " + event + "slotId = " + slotId);
 
diff --git a/src/com/android/stk/StkCmdReceiver.java b/src/com/android/stk/StkCmdReceiver.java
index d011eee..aeb4e22 100644
--- a/src/com/android/stk/StkCmdReceiver.java
+++ b/src/com/android/stk/StkCmdReceiver.java
@@ -45,8 +45,6 @@
             handleAction(context, intent, StkAppService.OP_END_SESSION);
         } else if (action.equals(AppInterface.CAT_ICC_STATUS_CHANGE)) {
             handleAction(context, intent, StkAppService.OP_CARD_STATUS_CHANGED);
-        } else if (action.equals(Intent.ACTION_LOCALE_CHANGED)) {
-            handleLocaleChange(context);
         } else if (action.equals(AppInterface.CAT_ALPHA_NOTIFY_ACTION)) {
             handleAction(context, intent, StkAppService.OP_ALPHA_NOTIFY);
         }
@@ -86,11 +84,4 @@
         toService.putExtras(args);
         context.startService(toService);
     }
-
-    private void handleLocaleChange(Context context) {
-        Bundle args = new Bundle();
-        args.putInt(StkAppService.OPCODE, StkAppService.OP_LOCALE_CHANGED);
-        context.startService(new Intent(context, StkAppService.class)
-                .putExtras(args));
-    }
 }