diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2020-04-28 20:26:35 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2020-04-28 20:26:35 +0000 |
commit | 9178616acd1bd3045588d4927daa8bc01f3111fd (patch) | |
tree | 79e8f303f0f02d283dc528630e6e9c599c476eb1 | |
parent | aa3387247de6ad7d68b081c07f84ca2926d33b80 (diff) | |
parent | 7cc38e300917317ef6588f0c63c2feffdcd0ea0b (diff) | |
download | Stk-q_tzdata_aml_295500001.tar.gz |
Snap for 6439596 from 7cc38e300917317ef6588f0c63c2feffdcd0ea0b to qt-aml-tzdata-releaseq_tzdata_aml_297100400q_tzdata_aml_297100300q_tzdata_aml_297100000q_tzdata_aml_296200000q_tzdata_aml_295600118q_tzdata_aml_295600110q_tzdata_aml_295500002q_tzdata_aml_295500001q_tzdata_aml_294400310android-mainline-12.0.0_r54android-mainline-12.0.0_r111android-mainline-10.0.0_r13android-mainline-10.0.0_r12android-mainline-10.0.0_r11q_tzdata_aml_297100000android12-mainline-tzdata-releaseandroid10-mainline-tzdata-releaseandroid10-android13-mainline-tzdata-release
Change-Id: I8cc723e3efb2a7f1faeaecf394aa30715d86e964
27 files changed, 430 insertions, 332 deletions
@@ -3,9 +3,8 @@ android_app { name: "Stk", libs: ["telephony-common"], - static_libs: ["com.google.android.material_material"], + static_libs: ["android-support-v4"], srcs: ["**/*.java"], - jarjar_rules: "jarjar-rules.txt", platform_apis: true, certificate: "platform", } diff --git a/AndroidManifest.xml b/AndroidManifest.xml index c49ff86..3ab0e05 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -44,7 +44,6 @@ android:label="@string/app_name" android:enabled="false" android:exported="true" - android:autoRemoveFromRecents="true" android:taskAffinity="android.task.stk.StkLauncherActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> @@ -53,10 +52,9 @@ </activity> <activity android:name="StkLauncherActivity" - android:theme="@android:style/Theme.DeviceDefault.DayNight" + android:theme="@android:style/Theme.Material.Light" android:label="@string/app_name" android:exported="false" - android:autoRemoveFromRecents="true" android:taskAffinity="android.task.stk.StkLauncherActivity"> <intent-filter> <action android:name="android.intent.action.VIEW" /> @@ -66,12 +64,11 @@ </activity> <activity android:name="StkMenuActivity" - android:theme="@android:style/Theme.DeviceDefault.DayNight" + android:theme="@android:style/Theme.Material.Light" android:icon="@drawable/ic_launcher_sim_toolkit" android:label="@string/app_name" android:configChanges="orientation|locale|screenSize|keyboardHidden|mnc|mcc" android:exported="false" - android:autoRemoveFromRecents="true" android:taskAffinity="android.task.stk.StkLauncherActivity"> <intent-filter> <action android:name="android.intent.action.VIEW" /> @@ -83,10 +80,9 @@ <activity android:name="StkInputActivity" android:label="@string/app_name" android:icon="@drawable/ic_launcher_sim_toolkit" - android:theme="@style/Theme.AppCompat.DayNight.NoActionBar" + android:theme="@android:style/Theme.Material.Light" android:configChanges="orientation|locale|screenSize|keyboardHidden" android:exported="false" - android:autoRemoveFromRecents="true" android:taskAffinity="android.task.stk.StkLauncherActivity"> <intent-filter> <action android:name="android.intent.action.VIEW" /> @@ -98,14 +94,12 @@ android:configChanges="orientation|locale|screenSize|keyboardHidden" android:theme="@style/Transparent" android:exported="false" - android:autoRemoveFromRecents="true" android:taskAffinity="android.task.stk.StkLauncherActivity"> </activity> <activity android:name="ToneDialog" android:exported="false" android:theme="@style/Transparent" - android:autoRemoveFromRecents="true" android:taskAffinity="android.task.stk.StkLauncherActivity"> </activity> @@ -2,5 +2,5 @@ amitmahajan@google.com rgreenwalt@google.com jminjie@google.com hallliu@google.com +paulye@google.com breadley@google.com -jackyu@google.com
\ No newline at end of file diff --git a/jarjar-rules.txt b/jarjar-rules.txt deleted file mode 100644 index b0d73d3..0000000 --- a/jarjar-rules.txt +++ /dev/null @@ -1 +0,0 @@ -rule com.android.internal.util.XmlUtils* com.android.internal.telephony.XmlUtils@1 diff --git a/res/layout/stk_input.xml b/res/layout/stk_input.xml index 427ad42..7f8f96d 100644 --- a/res/layout/stk_input.xml +++ b/res/layout/stk_input.xml @@ -19,15 +19,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar" - android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - android:background="?android:attr/colorBackground" - android:elevation="4dp" - android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/> <ImageButton - style="@style/Widget.AppCompat.ActionButton.Overflow" + style="@android:style/Widget.Material.ActionButton.Overflow" android:id="@+id/more" android:layout_width="wrap_content" android:layout_height="wrap_content" @@ -69,17 +62,32 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> - <com.google.android.material.textfield.TextInputLayout - android:id="@+id/text_input_layout" - android:layout_width="match_parent" + <LinearLayout + android:id="@+id/input_restriction_info" + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginBottom="16dip" + android:layout_marginLeft="4dip" android:orientation="vertical"> - <com.google.android.material.textfield.TextInputEditText - android:id="@+id/in_text" - android:layout_width="match_parent" - android:layout_height="wrap_content"/> - </com.google.android.material.textfield.TextInputLayout> + <TextView + android:id="@+id/input_type" + android:gravity="start" + android:textAppearance="?android:attr/textAppearanceMedium" + android:textColor="?android:attr/textColorSecondary" + android:layout_width="wrap_content" + android:layout_height="wrap_content" /> + <TextView + android:id="@+id/num_of_chars" + android:textAppearance="?android:attr/textAppearanceMedium" + android:textColor="?android:attr/textColorSecondary" + android:layout_width="wrap_content" + android:layout_height="wrap_content" /> + </LinearLayout> + <EditText + android:id="@+id/in_text" + android:layout_gravity="center_horizontal" + 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" @@ -94,13 +102,13 @@ android:layout_weight="1" android:gravity="center_vertical" android:paddingStart="0dip" - style="@style/Widget.AppCompat.Button.Borderless.Colored" + style="@android:style/Widget.Material.Button.Borderless.Colored" android:text="@string/button_cancel" /> <Button android:id="@+id/button_ok" android:layout_height="48dip" android:layout_width="wrap_content" - style="@style/Widget.AppCompat.Button.Colored" + style="@android:style/Widget.Material.Button.Colored" android:text="@string/button_ok" /> </LinearLayout> </LinearLayout> @@ -115,13 +123,13 @@ android:id="@+id/button_no" android:layout_height="wrap_content" android:layout_width="wrap_content" - style="@style/Widget.AppCompat.Button.Borderless.Colored" + 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="@style/Widget.AppCompat.Button.Colored" + style="@android:style/Widget.Material.Button.Colored" android:text="@string/button_yes" /> </LinearLayout> </LinearLayout> diff --git a/res/values-bs/strings.xml b/res/values-bs/strings.xml index 5b17537..5adf46e 100644 --- a/res/values-bs/strings.xml +++ b/res/values-bs/strings.xml @@ -22,7 +22,7 @@ <string name="menu_back" msgid="301227740977453364">"Nazad"</string> <string name="service_name" msgid="6860303747999592491">"Ime usluge"</string> <string name="stk_no_service" msgid="5427773116839809131">"Usluga nije dostupna"</string> - <string name="button_ok" msgid="5760722312558549555">"UREDU"</string> + <string name="button_ok" msgid="5760722312558549555">"Uredu"</string> <string name="button_cancel" msgid="1997847915560800261">"Otkaži"</string> <string name="button_yes" msgid="624420260648337203">"Da"</string> <string name="button_no" msgid="1824959157582605627">"Ne"</string> diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index d61ed31..39b75f0 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -22,7 +22,7 @@ <string name="menu_back" msgid="301227740977453364">"Zurück"</string> <string name="service_name" msgid="6860303747999592491">"Name des Dienstes"</string> <string name="stk_no_service" msgid="5427773116839809131">"Kein Dienst verfügbar"</string> - <string name="button_ok" msgid="5760722312558549555">"OK"</string> + <string name="button_ok" msgid="5760722312558549555">"Ok"</string> <string name="button_cancel" msgid="1997847915560800261">"Abbrechen"</string> <string name="button_yes" msgid="624420260648337203">"\"Ja\""</string> <string name="button_no" msgid="1824959157582605627">"Nein"</string> diff --git a/res/values-hi/strings.xml b/res/values-hi/strings.xml index 5b38f4b..8ace2a1 100644 --- a/res/values-hi/strings.xml +++ b/res/values-hi/strings.xml @@ -17,7 +17,7 @@ <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">"सिम टूलकिट"</string> - <string name="menu_end_session" msgid="7368541737750982217">"सत्र समाप्त करें"</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> @@ -30,14 +30,14 @@ <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="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">"सिम टूलकिट"</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_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> diff --git a/res/values-hr/strings.xml b/res/values-hr/strings.xml index 81b4243..c468d74 100644 --- a/res/values-hr/strings.xml +++ b/res/values-hr/strings.xml @@ -16,7 +16,7 @@ <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">"Alatni komplet za SIM"</string> + <string name="app_name" msgid="8396461461738434341">"Alati za SIM"</string> <string name="menu_end_session" msgid="7368541737750982217">"Završi sesiju"</string> <string name="help" msgid="9209980881219397319">"Pomoć"</string> <string name="menu_back" msgid="301227740977453364">"Natrag"</string> diff --git a/res/values-hu/strings.xml b/res/values-hu/strings.xml index 9c7c290..fe06396 100644 --- a/res/values-hu/strings.xml +++ b/res/values-hu/strings.xml @@ -16,7 +16,7 @@ <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 kártya eszközkészlete"</string> + <string name="app_name" msgid="8396461461738434341">"SIM-kártya eszközkészlete"</string> <string name="menu_end_session" msgid="7368541737750982217">"Munkamenet befejezése"</string> <string name="help" msgid="9209980881219397319">"Súgó"</string> <string name="menu_back" msgid="301227740977453364">"Vissza"</string> @@ -33,7 +33,7 @@ <string name="stk_app_state" msgid="18582277302584082">"Alkalmazás állapota"</string> <string name="enable_app" msgid="3701224550936728203">"Engedélyezve"</string> <string name="disable_app" msgid="6725081975611415214">"Letiltva"</string> - <string name="stk_dialog_title" msgid="6954825385456886726">"SIM kártya eszközkészlete"</string> + <string name="stk_dialog_title" msgid="6954825385456886726">"SIM-kártya eszközkészlete"</string> <string name="default_tone_dialog_msg" msgid="4595366992944391641">"Playing Tone"</string> <string name="default_open_channel_msg" msgid="2216070254100295924">"Megnyitja a csatornát?"</string> <string name="default_send_data_msg" msgid="6011219698689931272">"Adatok küldése"</string> diff --git a/res/values-kk/strings.xml b/res/values-kk/strings.xml index c030ff5..ddb76fa 100644 --- a/res/values-kk/strings.xml +++ b/res/values-kk/strings.xml @@ -16,7 +16,7 @@ <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="app_name" msgid="8396461461738434341">"SIM Toolkit"</string> <string name="menu_end_session" msgid="7368541737750982217">"Сессияны аяқтау"</string> <string name="help" msgid="9209980881219397319">"Көмек"</string> <string name="menu_back" msgid="301227740977453364">"Артқа"</string> @@ -33,7 +33,7 @@ <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="stk_dialog_title" msgid="6954825385456886726">"SIM ToolKit"</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> diff --git a/res/values-nl/strings.xml b/res/values-nl/strings.xml index 5ed9a87..ebe14b9 100644 --- a/res/values-nl/strings.xml +++ b/res/values-nl/strings.xml @@ -18,7 +18,7 @@ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <string name="app_name" msgid="8396461461738434341">"SIM-toolkit"</string> <string name="menu_end_session" msgid="7368541737750982217">"Sessie beëindigen"</string> - <string name="help" msgid="9209980881219397319">"Help"</string> + <string name="help" msgid="9209980881219397319">"Hulp"</string> <string name="menu_back" msgid="301227740977453364">"Terug"</string> <string name="service_name" msgid="6860303747999592491">"Servicenaam"</string> <string name="stk_no_service" msgid="5427773116839809131">"Geen service beschikbaar"</string> diff --git a/res/values-ta/strings.xml b/res/values-ta/strings.xml index 01eb52f..0440ce9 100644 --- a/res/values-ta/strings.xml +++ b/res/values-ta/strings.xml @@ -30,7 +30,7 @@ <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="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">"சிம் கருவிப்பெட்டி"</string> diff --git a/res/values-uz/strings.xml b/res/values-uz/strings.xml index d9ecefb..6793f15 100644 --- a/res/values-uz/strings.xml +++ b/res/values-uz/strings.xml @@ -32,7 +32,7 @@ <string name="default_setup_call_msg" msgid="6126904475461162162">"Qo‘ng‘iroq sozlanmoqda"</string> <string name="stk_app_state" msgid="18582277302584082">"Ilova holati"</string> <string name="enable_app" msgid="3701224550936728203">"Yoniq"</string> - <string name="disable_app" msgid="6725081975611415214">"O‘chiq"</string> + <string name="disable_app" msgid="6725081975611415214">"Yoqilmagan"</string> <string name="stk_dialog_title" msgid="6954825385456886726">"SIM menyusi"</string> <string name="default_tone_dialog_msg" msgid="4595366992944391641">"Signal ijrosi"</string> <string name="default_open_channel_msg" msgid="2216070254100295924">"Kanal ochilsinmi?"</string> diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml index 59db8c4..1169b6b 100644 --- a/res/values-zh-rCN/strings.xml +++ b/res/values-zh-rCN/strings.xml @@ -16,7 +16,7 @@ <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="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> @@ -33,7 +33,7 @@ <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="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> diff --git a/res/values/styles.xml b/res/values/styles.xml index 7d43798..a786fdc 100644..100755 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -15,7 +15,7 @@ --> <resources> - <style name="Transparent" parent="@android:style/Theme.DeviceDefault.DayNight"> + <style name="Transparent" parent="@android:style/Theme.Material.Light"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowContentOverlay">@null</item> diff --git a/src/com/android/stk/BootCompletedReceiver.java b/src/com/android/stk/BootCompletedReceiver.java index e972e35..d162910 100644 --- a/src/com/android/stk/BootCompletedReceiver.java +++ b/src/com/android/stk/BootCompletedReceiver.java @@ -30,8 +30,7 @@ import com.android.internal.telephony.cat.CatLog; * */ public class BootCompletedReceiver extends BroadcastReceiver { - private static final String LOG_TAG = - new Object(){}.getClass().getEnclosingClass().getSimpleName(); + private static final String LOG_TAG = new Object(){}.getClass().getEnclosingClass().getName(); @Override public void onReceive(Context context, Intent intent) { diff --git a/src/com/android/stk/StkAppInstaller.java b/src/com/android/stk/StkAppInstaller.java index 50bc96e..2d06e59 100644 --- a/src/com/android/stk/StkAppInstaller.java +++ b/src/com/android/stk/StkAppInstaller.java @@ -32,8 +32,7 @@ import android.os.SystemProperties; */ abstract class StkAppInstaller { private static final String STK_MAIN_ACTIVITY = "com.android.stk.StkMain"; - private static final String LOG_TAG = - new Object(){}.getClass().getEnclosingClass().getSimpleName(); + private static final String LOG_TAG = "StkAppInstaller"; private StkAppInstaller() { CatLog.d(LOG_TAG, "init"); diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java index 4140d15..cb9564e 100644 --- a/src/com/android/stk/StkAppService.java +++ b/src/com/android/stk/StkAppService.java @@ -40,6 +40,7 @@ import android.content.res.Resources; import android.content.res.Resources.NotFoundException; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.media.RingtoneManager; import android.net.Uri; import android.os.Bundle; import android.os.Handler; @@ -54,6 +55,7 @@ import android.os.ServiceManager; 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.SubscriptionInfo; import android.telephony.SubscriptionManager; @@ -70,9 +72,6 @@ import android.widget.TextView; import android.widget.Toast; import android.content.IntentFilter; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; - -import com.android.internal.telephony.PhoneConfigurationManager; import com.android.internal.telephony.cat.AppInterface; import com.android.internal.telephony.cat.Input; import com.android.internal.telephony.cat.LaunchBrowserMode; @@ -144,29 +143,29 @@ public class StkAppService extends Service implements Runnable { // Determins whether the current session was initiated by user operation. protected boolean mIsSessionFromUser = false; final synchronized void setPendingActivityInstance(Activity act) { - CatLog.d(LOG_TAG, "setPendingActivityInstance act : " + mSlotId + ", " + act); + CatLog.d(this, "setPendingActivityInstance act : " + mSlotId + ", " + act); callSetActivityInstMsg(OP_SET_ACT_INST, mSlotId, act); } final synchronized Activity getPendingActivityInstance() { - CatLog.d(LOG_TAG, "getPendingActivityInstance act : " + mSlotId + ", " + + CatLog.d(this, "getPendingActivityInstance act : " + mSlotId + ", " + mActivityInstance); return mActivityInstance; } final synchronized void setPendingDialogInstance(Activity act) { - CatLog.d(LOG_TAG, "setPendingDialogInstance act : " + mSlotId + ", " + act); + CatLog.d(this, "setPendingDialogInstance act : " + mSlotId + ", " + act); callSetActivityInstMsg(OP_SET_DAL_INST, mSlotId, act); } final synchronized Activity getPendingDialogInstance() { - CatLog.d(LOG_TAG, "getPendingDialogInstance act : " + mSlotId + ", " + + CatLog.d(this, "getPendingDialogInstance act : " + mSlotId + ", " + mDialogInstance); return mDialogInstance; } final synchronized void setImmediateDialogInstance(Activity act) { - CatLog.d(LOG_TAG, "setImmediateDialogInstance act : " + mSlotId + ", " + act); + CatLog.d(this, "setImmediateDialogInstance act : " + mSlotId + ", " + act); callSetActivityInstMsg(OP_SET_IMMED_DAL_INST, mSlotId, act); } final synchronized Activity getImmediateDialogInstance() { - CatLog.d(LOG_TAG, "getImmediateDialogInstance act : " + mSlotId + ", " + + CatLog.d(this, "getImmediateDialogInstance act : " + mSlotId + ", " + mImmediateDialogInstance); return mImmediateDialogInstance; } @@ -229,7 +228,6 @@ public class StkAppService extends Service implements Runnable { static final int OP_ALPHA_NOTIFY = 11; static final int OP_IDLE_SCREEN = 12; static final int OP_SET_IMMED_DAL_INST = 13; - static final int OP_HOME_KEY_PRESSED = 14; //Invalid SetupEvent static final int INVALID_SETUP_EVENT = 0xFF; @@ -240,12 +238,12 @@ public class StkAppService extends Service implements Runnable { // Message id to signal stop tone on user keyback. static final int OP_STOP_TONE_USER = 17; + // Message id to remove stop tone message from queue. + private static final int STOP_TONE_WHAT = 100; + // Message id to send user activity event to card. private static final int OP_USER_ACTIVITY = 20; - // Message id that multi-SIM config has changed (ss <-> ds). - private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 21; - // Response ids static final int RES_ID_MENU_SELECTION = 11; static final int RES_ID_INPUT = 12; @@ -266,9 +264,6 @@ public class StkAppService extends Service implements Runnable { static final int STATE_NOT_EXIST = 0; static final int STATE_EXIST = 1; - private static final Integer PLAY_TONE_ONLY = 0; - private static final Integer PLAY_TONE_WITH_DIALOG = 1; - private static final String PACKAGE_NAME = "com.android.stk"; private static final String STK_MENU_ACTIVITY_NAME = PACKAGE_NAME + ".StkMenuActivity"; private static final String STK_INPUT_ACTIVITY_NAME = PACKAGE_NAME + ".StkInputActivity"; @@ -278,8 +273,7 @@ public class StkAppService extends Service implements Runnable { // Notification channel containing all mobile service messages notifications. private static final String STK_NOTIFICATION_CHANNEL_ID = "mobileServiceMessages"; - private static final String LOG_TAG = - new Object(){}.getClass().getEnclosingClass().getSimpleName(); + private static final String LOG_TAG = new Object(){}.getClass().getEnclosingClass().getName(); static final String SESSION_ENDED = "session_ended"; @@ -305,22 +299,16 @@ public class StkAppService extends Service implements Runnable { private static final long[] VIBRATION_PATTERN = new long[] { 0, 350, 250, 350 }; private BroadcastReceiver mUserPresentReceiver = null; - // The reason based on Intent.ACTION_CLOSE_SYSTEM_DIALOGS. - private static final String SYSTEM_DIALOG_REASON_KEY = "reason"; - private static final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; - private BroadcastReceiver mHomeKeyEventReceiver = null; - @Override public void onCreate() { CatLog.d(LOG_TAG, "onCreate()+"); // Initialize members int i = 0; mContext = getBaseContext(); - mSimCount = TelephonyManager.from(mContext).getActiveModemCount(); - int maxSimCount = TelephonyManager.from(mContext).getSupportedModemCount(); + mSimCount = TelephonyManager.from(mContext).getSimCount(); CatLog.d(LOG_TAG, "simCount: " + mSimCount); - mStkService = new AppInterface[maxSimCount]; - mStkContext = new StkContext[maxSimCount]; + mStkService = new AppInterface[mSimCount]; + mStkContext = new StkContext[mSimCount]; for (i = 0; i < mSimCount; i++) { CatLog.d(LOG_TAG, "slotId: " + i); @@ -334,8 +322,6 @@ public class StkAppService extends Service implements Runnable { serviceThread.start(); mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); - PhoneConfigurationManager.registerForMultiSimConfigChange(mServiceHandler, - EVENT_MULTI_SIM_CONFIG_CHANGED, null); sInstance = this; } @@ -366,7 +352,7 @@ public class StkAppService extends Service implements Runnable { mStkContext[slotId].mStkServiceState = STATE_NOT_EXIST; //Check other StkService state. //If all StkServices are not available, stop itself and uninstall apk. - for (i = 0; i < mSimCount; i++) { + for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) { if (i != slotId && (mStkService[i] != null) && (mStkContext[i].mStkServiceState == STATE_UNKNOWN @@ -386,8 +372,10 @@ public class StkAppService extends Service implements Runnable { waitForLooper(); - Message msg = mServiceHandler.obtainMessage(op, 0, slotId); - switch (op) { + Message msg = mServiceHandler.obtainMessage(); + msg.arg1 = op; + msg.arg2 = slotId; + switch(msg.arg1) { case OP_CMD: msg.obj = args.getParcelable(CMD_MSG); break; @@ -396,13 +384,16 @@ public class StkAppService extends Service implements Runnable { case OP_LOCALE_CHANGED: case OP_ALPHA_NOTIFY: case OP_IDLE_SCREEN: - case OP_STOP_TONE_USER: msg.obj = args; /* falls through */ case OP_LAUNCH_APP: case OP_END_SESSION: case OP_BOOT_COMPLETED: break; + case OP_STOP_TONE_USER: + msg.obj = args; + msg.what = STOP_TONE_WHAT; + break; default: return; } @@ -415,7 +406,6 @@ public class StkAppService extends Service implements Runnable { unregisterUserActivityReceiver(); unregisterProcessObserver(); unregisterLocaleChangeReceiver(); - unregisterHomeKeyEventReceiver(); sInstance = null; waitForLooper(); mServiceLooper.quit(); @@ -438,7 +428,7 @@ public class StkAppService extends Service implements Runnable { /* * Package api used by StkMenuActivity to indicate if its on the foreground. */ - synchronized void indicateMenuVisibility(boolean visibility, int slotId) { + void indicateMenuVisibility(boolean visibility, int slotId) { if (slotId >= 0 && slotId < mSimCount) { mStkContext[slotId].mMenuIsVisible = visibility; } @@ -447,13 +437,13 @@ public class StkAppService extends Service implements Runnable { /* * Package api used by StkDialogActivity to indicate if its on the foreground. */ - synchronized void setDisplayTextDlgVisibility(boolean visibility, int slotId) { + void setDisplayTextDlgVisibility(boolean visibility, int slotId) { if (slotId >= 0 && slotId < mSimCount) { mStkContext[slotId].mDisplayTextDlgIsVisibile = visibility; } } - synchronized boolean isInputPending(int slotId) { + boolean isInputPending(int slotId) { if (slotId >= 0 && slotId < mSimCount) { CatLog.d(LOG_TAG, "isInputFinishBySrv: " + mStkContext[slotId].mIsInputPending); return mStkContext[slotId].mIsInputPending; @@ -461,7 +451,7 @@ public class StkAppService extends Service implements Runnable { return false; } - synchronized boolean isMenuPending(int slotId) { + boolean isMenuPending(int slotId) { if (slotId >= 0 && slotId < mSimCount) { CatLog.d(LOG_TAG, "isMenuPending: " + mStkContext[slotId].mIsMenuPending); return mStkContext[slotId].mIsMenuPending; @@ -469,7 +459,7 @@ public class StkAppService extends Service implements Runnable { return false; } - synchronized boolean isDialogPending(int slotId) { + boolean isDialogPending(int slotId) { if (slotId >= 0 && slotId < mSimCount) { CatLog.d(LOG_TAG, "isDialogPending: " + mStkContext[slotId].mIsDialogPending); return mStkContext[slotId].mIsDialogPending; @@ -477,7 +467,7 @@ public class StkAppService extends Service implements Runnable { return false; } - synchronized boolean isMainMenuAvailable(int slotId) { + 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; @@ -488,7 +478,7 @@ public class StkAppService extends Service implements Runnable { /* * Package api used by StkMenuActivity to get its Menu parameter. */ - synchronized Menu getMenu(int slotId) { + Menu getMenu(int slotId) { CatLog.d(LOG_TAG, "StkAppService, getMenu, sim id: " + slotId); if (slotId >=0 && slotId < mSimCount) { return mStkContext[slotId].mCurrentMenu; @@ -500,7 +490,7 @@ public class StkAppService extends Service implements Runnable { /* * Package api used by StkMenuActivity to get its Main Menu parameter. */ - synchronized Menu getMainMenu(int slotId) { + Menu getMainMenu(int slotId) { CatLog.d(LOG_TAG, "StkAppService, getMainMenu, sim id: " + slotId); if (slotId >=0 && slotId < mSimCount && (mStkContext[slotId].mMainCmd != null)) { Menu menu = mStkContext[slotId].mMainCmd.getMenu(); @@ -556,7 +546,7 @@ public class StkAppService extends Service implements Runnable { CatLog.d(LOG_TAG, "ServiceHandler handleMessage msg is null"); return; } - int opcode = msg.what; + int opcode = msg.arg1; int slotId = msg.arg2; CatLog.d(LOG_TAG, "handleMessage opcode[" + opcode + "], sim id[" + slotId + "]"); @@ -564,11 +554,6 @@ public class StkAppService extends Service implements Runnable { ((CatCmdMessage)msg.obj).getCmdType()!= null) { CatLog.d(LOG_TAG, "cmdName[" + ((CatCmdMessage)msg.obj).getCmdType().name() + "]"); } - if (slotId >= mStkContext.length || mStkContext[slotId] == null) { - CatLog.d(LOG_TAG, "invalid slotId " + slotId); - return; - } - mStkContext[slotId].mOpCode = opcode; switch (opcode) { case OP_LAUNCH_APP: @@ -634,7 +619,7 @@ public class StkAppService extends Service implements Runnable { case OP_BOOT_COMPLETED: CatLog.d(LOG_TAG, " OP_BOOT_COMPLETED"); int i = 0; - for (i = 0; i < mSimCount; i++) { + for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) { if (mStkContext[i].mMainCmd != null) { break; } @@ -663,12 +648,18 @@ public class StkAppService extends Service implements Runnable { CatLog.d(LOG_TAG, "Finish the previous pending activity - " + previous); previous.finish(); } - } - // Clear pending dialog instance if it has not been cleared yet. - Activity dialog = mStkContext[slotId].getPendingDialogInstance(); - if (dialog != null && (dialog.isDestroyed() || dialog.isFinishing())) { - CatLog.d(LOG_TAG, "Clear pending dialog instance - " + dialog); - mStkContext[slotId].mDialogInstance = null; + // Pending activity is registered in the following 2 scnarios; + // A. TERMINAL RESPONSE was sent to the card. + // B. Activity was moved to the background before TR is sent to the card. + // No need to observe idle screen for the pending activity in the scenario A. + if (act != null && mStkContext[slotId].mCmdInProgress) { + startToObserveIdleScreen(slotId); + } else { + if (mStkContext[slotId].mCurrentCmd != null) { + unregisterProcessObserver( + mStkContext[slotId].mCurrentCmd.getCmdType(), slotId); + } + } } break; case OP_SET_DAL_INST: @@ -676,6 +667,14 @@ public class StkAppService extends Service implements Runnable { if (mStkContext[slotId].mDialogInstance != dal) { CatLog.d(LOG_TAG, "Set pending dialog instance - " + dal); mStkContext[slotId].mDialogInstance = dal; + if (dal != null) { + startToObserveIdleScreen(slotId); + } else { + if (mStkContext[slotId].mCurrentCmd != null) { + unregisterProcessObserver( + mStkContext[slotId].mCurrentCmd.getCmdType(), slotId); + } + } } break; case OP_SET_IMMED_DAL_INST: @@ -684,8 +683,8 @@ public class StkAppService extends Service implements Runnable { mStkContext[slotId].mImmediateDialogInstance = immedDal; break; case OP_LOCALE_CHANGED: - CatLog.d(LOG_TAG, "Locale Changed"); - for (int slot = 0; slot < mSimCount; slot++) { + CatLog.d(this, "Locale Changed"); + for (int slot = PhoneConstants.SIM_ID_1; slot < mSimCount; slot++) { checkForSetupEvent(LANGUAGE_SELECTION_EVENT, (Bundle) msg.obj, slot); } // rename all registered notification channels on locale change @@ -703,25 +702,14 @@ public class StkAppService extends Service implements Runnable { break; case OP_STOP_TONE_USER: case OP_STOP_TONE: - CatLog.d(LOG_TAG, "Stop tone"); + CatLog.d(this, "Stop tone"); handleStopTone(msg, slotId); break; case OP_USER_ACTIVITY: - for (int slot = 0; slot < mSimCount; slot++) { + for (int slot = PhoneConstants.SIM_ID_1; slot < mSimCount; slot++) { checkForSetupEvent(USER_ACTIVITY_EVENT, null, slot); } break; - case EVENT_MULTI_SIM_CONFIG_CHANGED: - handleMultiSimConfigChanged(); - break; - case OP_HOME_KEY_PRESSED: - CatLog.d(LOG_TAG, "Process the home key pressed event"); - for (int slot = 0; slot < mSimCount; slot++) { - if (mStkContext[slot] != null) { - handleHomeKeyPressed(slot); - } - } - break; } } @@ -736,12 +724,6 @@ public class StkAppService extends Service implements Runnable { mStkContext[slotId].mCurrentMenu = null; mStkContext[slotId].mMainCmd = null; mStkService[slotId] = null; - // Stop the tone currently being played if the relevant SIM is removed or disabled. - if (mStkContext[slotId].mCurrentCmd != null - && mStkContext[slotId].mCurrentCmd.getCmdType().value() - == AppInterface.CommandType.PLAY_TONE.value()) { - terminateTone(slotId); - } if (isAllOtherCardsAbsent(slotId)) { CatLog.d(LOG_TAG, "All CARDs are ABSENT"); StkAppInstaller.unInstall(mContext); @@ -760,28 +742,6 @@ public class StkAppService extends Service implements Runnable { } } } - - private synchronized void handleMultiSimConfigChanged() { - int oldSimCount = mSimCount; - mSimCount = TelephonyManager.from(mContext).getActiveModemCount(); - for (int i = oldSimCount; i < mSimCount; i++) { - CatLog.d(LOG_TAG, "slotId: " + i); - mStkService[i] = CatService.getInstance(i); - mStkContext[i] = new StkContext(); - mStkContext[i].mSlotId = i; - mStkContext[i].mCmdsQ = new LinkedList<DelayedCmd>(); - } - - for (int i = mSimCount; i < oldSimCount; i++) { - CatLog.d(LOG_TAG, "slotId: " + i); - if (mStkService[i] != null) { - mStkService[i].dispose(); - mStkService[i] = null; - } - mStkContext[i] = null; - } - } - /* * Check if all SIMs are absent except the id of slot equals "slotId". */ @@ -829,57 +789,39 @@ public class StkAppService extends Service implements Runnable { return false; } - private synchronized void startToObserveHomeKeyEvent(int slotId) { - if (mStkContext[slotId].mIsSessionFromUser || mHomeKeyEventReceiver != null) { - return; - } - mHomeKeyEventReceiver = new BroadcastReceiver() { - @Override public void onReceive(Context context, Intent intent) { - if (SYSTEM_DIALOG_REASON_HOME_KEY.equals( - intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY))) { - Message message = mServiceHandler.obtainMessage(); - message.arg1 = OP_HOME_KEY_PRESSED; - mServiceHandler.sendMessage(message); + private void startToObserveIdleScreen(int slotId) { + if (!mStkContext[slotId].mIsSessionFromUser) { + if (!isScreenIdle()) { + synchronized (this) { + if (mProcessObserver == null && !mServiceHandler.hasMessages(OP_IDLE_SCREEN)) { + registerProcessObserver(); + } } + } else { + handleIdleScreen(slotId); } - }; - CatLog.d(LOG_TAG, "Started to observe home key event"); - registerReceiver(mHomeKeyEventReceiver, - new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); - } - - private synchronized void unregisterHomeKeyEventReceiver() { - if (mHomeKeyEventReceiver != null) { - CatLog.d(LOG_TAG, "Stopped to observe home key event"); - unregisterReceiver(mHomeKeyEventReceiver); - mHomeKeyEventReceiver = null; - } - if (mServiceHandler != null) { - mServiceHandler.removeMessages(OP_HOME_KEY_PRESSED); } } - private void handleHomeKeyPressed(int slotId) { + private void handleIdleScreen(int slotId) { // It might be hard for user to recognize that the dialog or screens belong to SIM Toolkit // application if the current session was not initiated by user but by the SIM card, - // so it is recommended to send TERMINAL RESPONSE if user press the home key. + // so it is recommended to send TERMINAL RESPONSE if user goes to the idle screen. if (!mStkContext[slotId].mIsSessionFromUser) { Activity dialog = mStkContext[slotId].getPendingDialogInstance(); - Activity activity = mStkContext[slotId].getPendingActivityInstance(); if (dialog != null) { dialog.finish(); mStkContext[slotId].mDialogInstance = null; - } else if (activity != null) { + } + Activity activity = mStkContext[slotId].getPendingActivityInstance(); + if (activity != null) { activity.finish(); mStkContext[slotId].mActivityInstance = null; } } - } - - private void handleIdleScreen(int slotId) { // If the idle screen event is present in the list need to send the // response to SIM. - CatLog.d(LOG_TAG, "Need to send IDLE SCREEN Available event to SIM"); + CatLog.d(this, "Need to send IDLE SCREEN Available event to SIM"); checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId); if (mStkContext[slotId].mIdleModeTextCmd != null @@ -893,7 +835,7 @@ public class StkAppService extends Service implements Runnable { return; } CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd); - CatLog.d(LOG_TAG, "SCREEN_BUSY"); + CatLog.d(this, "SCREEN_BUSY"); resMsg.setResultCode(ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS); mStkService[slotId].onCmdResponse(resMsg); if (mStkContext[slotId].mCmdsQ.size() != 0) { @@ -910,23 +852,22 @@ public class StkAppService extends Service implements Runnable { * @param slotId slot identifier */ public void sendResponse(Bundle args, int slotId) { - Message msg = mServiceHandler.obtainMessage(OP_RESPONSE, 0, slotId, args); + Message msg = mServiceHandler.obtainMessage(); + msg.arg1 = OP_RESPONSE; + msg.arg2 = slotId; + msg.obj = args; mServiceHandler.sendMessage(msg); } private void sendResponse(int resId, int slotId, boolean confirm) { + Message msg = mServiceHandler.obtainMessage(); + msg.arg1 = OP_RESPONSE; + msg.arg2 = slotId; Bundle args = new Bundle(); args.putInt(StkAppService.RES_ID, resId); args.putBoolean(StkAppService.CONFIRMATION, confirm); - sendResponse(args, slotId); - } - - private void terminateTone(int slotId) { - Message msg = new Message(); - msg.what = OP_STOP_TONE; - msg.obj = mServiceHandler.hasMessages(OP_STOP_TONE, PLAY_TONE_WITH_DIALOG) - ? PLAY_TONE_WITH_DIALOG : PLAY_TONE_ONLY; - handleStopTone(msg, slotId); + msg.obj = args; + mServiceHandler.sendMessage(msg); } private boolean isCmdInteractive(CatCmdMessage cmd) { @@ -970,12 +911,17 @@ public class StkAppService extends Service implements Runnable { } private void callDelayedMsg(int slotId) { - Message msg = mServiceHandler.obtainMessage(OP_DELAYED_MSG, 0, slotId); + Message msg = mServiceHandler.obtainMessage(); + msg.arg1 = OP_DELAYED_MSG; + msg.arg2 = slotId; mServiceHandler.sendMessage(msg); } - private void callSetActivityInstMsg(int opcode, int slotId, Object obj) { - Message msg = mServiceHandler.obtainMessage(opcode, 0, slotId, obj); + private void callSetActivityInstMsg(int inst_type, int slotId, Object obj) { + Message msg = mServiceHandler.obtainMessage(); + msg.obj = obj; + msg.arg1 = inst_type; + msg.arg2 = slotId; mServiceHandler.sendMessage(msg); } @@ -1046,15 +992,13 @@ public class StkAppService extends Service implements Runnable { /** * Get the boolean config from carrier config manager. * - * @param context the context to get carrier service * @param key config key defined in CarrierConfigManager * @param slotId slot ID. * @return boolean value of corresponding key. */ - /* package */ static boolean getBooleanCarrierConfig(Context context, String key, int slotId) { - CarrierConfigManager ccm = (CarrierConfigManager) context.getSystemService( - Context.CARRIER_CONFIG_SERVICE); - SubscriptionManager sm = (SubscriptionManager) context.getSystemService( + private boolean getBooleanCarrierConfig(String key, int slotId) { + CarrierConfigManager ccm = (CarrierConfigManager) getSystemService(CARRIER_CONFIG_SERVICE); + SubscriptionManager sm = (SubscriptionManager) getSystemService( Context.TELEPHONY_SUBSCRIPTION_SERVICE); PersistableBundle b = null; if (ccm != null && sm != null) { @@ -1070,10 +1014,6 @@ public class StkAppService extends Service implements Runnable { return CarrierConfigManager.getDefaultConfig().getBoolean(key); } - private boolean getBooleanCarrierConfig(String key, int slotId) { - return getBooleanCarrierConfig(this, key, slotId); - } - private void handleCmd(CatCmdMessage cmdMsg, int slotId) { if (cmdMsg == null) { @@ -1136,7 +1076,7 @@ public class StkAppService extends Service implements Runnable { mStkContext[slotId].mCurrentMenu = null; mStkContext[slotId].mMainCmd = null; //Check other setup menu state. If all setup menu are removed, uninstall apk. - for (i = 0; i < mSimCount; i++) { + for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) { if (i != slotId && mStkContext[i].mSetupMenuState != STATE_NOT_EXIST) { CatLog.d(LOG_TAG, "Not Uninstall App:" + i + "," + mStkContext[i].mSetupMenuState); @@ -1168,7 +1108,7 @@ public class StkAppService extends Service implements Runnable { mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd; if (mStkContext[slotId].mIdleModeTextCmd != null) { if (mStkContext[slotId].mIdleModeTextVisible || isScreenIdle()) { - CatLog.d(LOG_TAG, "set up idle mode"); + CatLog.d(this, "set up idle mode"); launchIdleText(slotId); } else { registerProcessObserver(); @@ -1189,7 +1129,7 @@ public class StkAppService extends Service implements Runnable { // The device setup process should not be interrupted by launching browser. if (Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) == 0) { - CatLog.d(LOG_TAG, "Not perform if the setup process has not been completed."); + CatLog.d(this, "The command is not performed if the setup has not been completed."); sendScreenBusyResponse(slotId); break; } @@ -1197,7 +1137,7 @@ public class StkAppService extends Service implements Runnable { /* Check if Carrier would not want to launch browser */ if (getBooleanCarrierConfig(CarrierConfigManager.KEY_STK_DISABLE_LAUNCH_BROWSER_BOOL, slotId)) { - CatLog.d(LOG_TAG, "Browser is not launched as per carrier."); + CatLog.d(this, "Browser is not launched as per carrier."); sendResponse(RES_ID_DONE, slotId, true); break; } @@ -1205,14 +1145,14 @@ public class StkAppService extends Service implements Runnable { mStkContext[slotId].mBrowserSettings = mStkContext[slotId].mCurrentCmd.getBrowserSettings(); if (!isUrlAvailableToLaunchBrowser(mStkContext[slotId].mBrowserSettings)) { - CatLog.d(LOG_TAG, "Browser url property is not set - send error"); + CatLog.d(this, "Browser url property is not set - send error"); sendResponse(RES_ID_ERROR, slotId, true); } else { TextMessage alphaId = mStkContext[slotId].mCurrentCmd.geTextMessage(); if ((alphaId == null) || TextUtils.isEmpty(alphaId.text)) { // don't need user confirmation in this case // just launch the browser or spawn a new tab - CatLog.d(LOG_TAG, "user confirmation is not currently needed.\n" + + CatLog.d(this, "user confirmation is not currently needed.\n" + "supressing confirmation dialogue and confirming silently..."); mStkContext[slotId].launchBrowser = true; sendResponse(RES_ID_CONFIRM, slotId, true); @@ -1226,7 +1166,7 @@ public class StkAppService extends Service implements Runnable { if((mesg != null) && (mesg.text == null || mesg.text.length() == 0)) { mesg.text = getResources().getString(R.string.default_setup_call_msg); } - CatLog.d(LOG_TAG, "SET_UP_CALL mesg.text " + mesg.text); + CatLog.d(this, "SET_UP_CALL mesg.text " + mesg.text); launchConfirmationDialog(mesg, slotId); break; case PLAY_TONE: @@ -1261,7 +1201,7 @@ public class StkAppService extends Service implements Runnable { case SET_UP_EVENT_LIST: replaceEventList(slotId); if (isScreenIdle()) { - CatLog.d(LOG_TAG," Check if IDLE_SCREEN_AVAILABLE_EVENT is present in List"); + CatLog.d(this," Check if IDLE_SCREEN_AVAILABLE_EVENT is present in List"); checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId); } break; @@ -1279,7 +1219,6 @@ public class StkAppService extends Service implements Runnable { @SuppressWarnings("FallThrough") private void handleCmdResponse(Bundle args, int slotId) { CatLog.d(LOG_TAG, "handleCmdResponse, sim id: " + slotId); - unregisterHomeKeyEventReceiver(); if (mStkContext[slotId].mCurrentCmd == null) { return; } @@ -1287,11 +1226,10 @@ public class StkAppService extends Service implements Runnable { if (mStkService[slotId] == null) { mStkService[slotId] = CatService.getInstance(slotId); if (mStkService[slotId] == null) { - // CatService is disposed when the relevant SIM is removed or disabled. - // StkAppService can also be stopped when the absent state is notified, - // so this situation can happen. - CatLog.d(LOG_TAG, "No response is sent back to the missing CatService."); - return; + // This should never happen (we should be responding only to a message + // that arrived from StkService). It has to exist by this time + CatLog.d(LOG_TAG, "Exception! mStkService is null when we need to send response."); + throw new RuntimeException("mStkService is null when we need to send response"); } } @@ -1341,7 +1279,7 @@ public class StkAppService extends Service implements Runnable { } break; case RES_ID_CONFIRM: - CatLog.d(LOG_TAG, "RES_ID_CONFIRM"); + CatLog.d(this, "RES_ID_CONFIRM"); confirmed = args.getBoolean(CONFIRMATION); switch (mStkContext[slotId].mCurrentCmd.getCmdType()) { case DISPLAY_TEXT: @@ -1398,7 +1336,7 @@ public class StkAppService extends Service implements Runnable { break; case RES_ID_CHOICE: int choice = args.getInt(CHOICE); - CatLog.d(LOG_TAG, "User Choice=" + choice); + CatLog.d(this, "User Choice=" + choice); switch (choice) { case YES: resMsg.setResultCode(ResultCode.OK); @@ -1587,9 +1525,6 @@ public class StkAppService extends Service implements Runnable { newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY); mStkContext[slotId].mMenuState = StkMenuActivity.STATE_SECONDARY; } - if (mStkContext[slotId].mMenuState == StkMenuActivity.STATE_SECONDARY) { - startToObserveHomeKeyEvent(slotId); - } newIntent.putExtra(SLOT_ID, slotId); newIntent.setData(uriData); newIntent.setFlags(intentFlags); @@ -1616,7 +1551,6 @@ public class StkAppService extends Service implements Runnable { notifyUserIfNecessary(slotId, input.text); } startActivity(newIntent); - startToObserveHomeKeyEvent(slotId); } private void launchTextDialog(int slotId) { @@ -1631,6 +1565,7 @@ public class StkAppService extends Service implements Runnable { newIntent.setClassName(PACKAGE_NAME, targetActivity); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); newIntent.setData(uriData); newIntent.putExtra("TEXT", textMessage); @@ -1645,8 +1580,6 @@ public class StkAppService extends Service implements Runnable { // the immediate response tlv. if (!mStkContext[slotId].mCurrentCmd.geTextMessage().responseNeeded) { sendResponse(RES_ID_CONFIRM, slotId, true); - } else { - startToObserveHomeKeyEvent(slotId); } } @@ -1667,6 +1600,22 @@ public class StkAppService extends Service implements Runnable { // if user cannot see the message from the card right now because of it. // The notification can be dismissed if user removed the keyguard screen. launchNotificationOnKeyguard(slotId, message); + } else if (!(pm.isInteractive() && isTopOfStack())) { + // User might be doing something but it is not related to the SIM Toolkit. + // Play the tone and do vibration in order to attract user's attention. + // User will see the input screen or the dialog soon in this case. + NotificationChannel channel = mNotificationManager + .getNotificationChannel(STK_NOTIFICATION_CHANNEL_ID); + Uri uri = channel.getSound(); + if (uri != null && !Uri.EMPTY.equals(uri) + && (NotificationManager.IMPORTANCE_LOW) < channel.getImportance()) { + RingtoneManager.getRingtone(getApplicationContext(), uri).play(); + } + long[] pattern = channel.getVibrationPattern(); + if (pattern != null && channel.shouldVibrate()) { + ((Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE)) + .vibrate(pattern, -1); + } } // Turn on the screen. @@ -1724,7 +1673,7 @@ public class StkAppService extends Service implements Runnable { private synchronized void unregisterUserPresentReceiver(int slotId) { if (mUserPresentReceiver != null) { - for (int slot = 0; slot < mSimCount; slot++) { + for (int slot = PhoneConstants.SIM_ID_1; slot < mSimCount; slot++) { if (slot != slotId) { if (mStkContext[slot].mNotificationOnKeyguard) { // The broadcast receiver is still necessary for other SIM card. @@ -1741,6 +1690,25 @@ public class StkAppService extends Service implements Runnable { return getNotificationId(slotId) + (notificationType * mSimCount); } + /** + * Checks whether the dialog exists as the top activity of this task. + * + * @return true if the top activity of this task is the dialog. + */ + public boolean isStkDialogActivated() { + ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); + ComponentName componentName = am.getAppTasks().get(0).getTaskInfo().topActivity; + if (componentName != null) { + String[] split = componentName.getClassName().split(Pattern.quote(".")); + String topActivity = split[split.length - 1]; + CatLog.d(LOG_TAG, "Top activity: " + topActivity); + if (TextUtils.equals(topActivity, StkDialogActivity.class.getSimpleName())) { + return true; + } + } + return false; + } + private void replaceEventList(int slotId) { if (mStkContext[slotId].mSetupEventListSettings != null) { for (int current : mStkContext[slotId].mSetupEventListSettings.eventList) { @@ -1769,7 +1737,7 @@ public class StkAppService extends Service implements Runnable { } private void unregisterEvent(int event, int slotId) { - for (int slot = 0; slot < mSimCount; slot++) { + 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)) { @@ -1823,7 +1791,8 @@ public class StkAppService extends Service implements Runnable { @Override public void onReceive(Context context, Intent intent) { if (WindowManagerPolicyConstants.ACTION_USER_ACTIVITY_NOTIFICATION.equals( intent.getAction())) { - Message message = mServiceHandler.obtainMessage(OP_USER_ACTIVITY); + Message message = mServiceHandler.obtainMessage(); + message.arg1 = OP_USER_ACTIVITY; mServiceHandler.sendMessage(message); unregisterUserActivityReceiver(); } @@ -1836,7 +1805,7 @@ public class StkAppService extends Service implements Runnable { ServiceManager.getService(Context.WINDOW_SERVICE)); wm.requestUserActivityNotification(); } catch (RemoteException e) { - CatLog.e(LOG_TAG, "failed to init WindowManager:" + e); + CatLog.e(this, "failed to init WindowManager:" + e); } } } @@ -1855,7 +1824,8 @@ public class StkAppService extends Service implements Runnable { @Override public void onForegroundActivitiesChanged(int pid, int uid, boolean fg) { if (isScreenIdle()) { - Message message = mServiceHandler.obtainMessage(OP_IDLE_SCREEN); + Message message = mServiceHandler.obtainMessage(); + message.arg1 = OP_IDLE_SCREEN; mServiceHandler.sendMessage(message); unregisterProcessObserver(); } @@ -1870,10 +1840,10 @@ public class StkAppService extends Service implements Runnable { } }; ActivityManagerNative.getDefault().registerProcessObserver(observer); - CatLog.d(LOG_TAG, "Started to observe the foreground activity"); + CatLog.d(this, "Started to observe the foreground activity"); mProcessObserver = observer; } catch (RemoteException e) { - CatLog.e(LOG_TAG, "Failed to register the process observer"); + CatLog.d(this, "Failed to register the process observer"); } } } @@ -1881,7 +1851,7 @@ public class StkAppService extends Service implements Runnable { private void unregisterProcessObserver(AppInterface.CommandType command, int slotId) { // Check if there is any pending command which still needs the process observer // except for the current command and slot. - for (int slot = 0; slot < mSimCount; slot++) { + for (int slot = PhoneConstants.SIM_ID_1; slot < mSimCount; slot++) { if (command != AppInterface.CommandType.SET_UP_IDLE_MODE_TEXT || slot != slotId) { if (mStkContext[slot].mIdleModeTextCmd != null && !mStkContext[slot].mIdleModeTextVisible) { @@ -1908,10 +1878,10 @@ public class StkAppService extends Service implements Runnable { if (mProcessObserver != null) { try { ActivityManagerNative.getDefault().unregisterProcessObserver(mProcessObserver); - CatLog.d(LOG_TAG, "Stopped to observe the foreground activity"); + CatLog.d(this, "Stopped to observe the foreground activity"); mProcessObserver = null; } catch (RemoteException e) { - CatLog.d(LOG_TAG, "Failed to unregister the process observer"); + CatLog.d(this, "Failed to unregister the process observer"); } } } @@ -1921,7 +1891,8 @@ public class StkAppService extends Service implements Runnable { mLocaleChangeReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_LOCALE_CHANGED.equals(intent.getAction())) { - Message message = mServiceHandler.obtainMessage(OP_LOCALE_CHANGED); + Message message = mServiceHandler.obtainMessage(); + message.arg1 = OP_LOCALE_CHANGED; mServiceHandler.sendMessage(message); } } @@ -1938,10 +1909,10 @@ public class StkAppService extends Service implements Runnable { } private void sendSetUpEventResponse(int event, byte[] addedInfo, int slotId) { - CatLog.d(LOG_TAG, "sendSetUpEventResponse: event : " + event + "slotId = " + slotId); + CatLog.d(this, "sendSetUpEventResponse: event : " + event + "slotId = " + slotId); if (mStkContext[slotId].mCurrentSetupEventCmd == null){ - CatLog.e(LOG_TAG, "mCurrentSetupEventCmd is null"); + CatLog.e(this, "mCurrentSetupEventCmd is null"); return; } @@ -1956,7 +1927,7 @@ public class StkAppService extends Service implements Runnable { private void checkForSetupEvent(int event, Bundle args, int slotId) { boolean eventPresent = false; byte[] addedInfo = null; - CatLog.d(LOG_TAG, "Event :" + event); + CatLog.d(this, "Event :" + event); if (mStkContext[slotId].mSetupEventListSettings != null) { /* Checks if the event is present in the EventList updated by last @@ -1970,7 +1941,7 @@ public class StkAppService extends Service implements Runnable { /* If Event is present send the response to ICC */ if (eventPresent == true) { - CatLog.d(LOG_TAG, " Event " + event + "exists in the EventList"); + CatLog.d(this, " Event " + event + "exists in the EventList"); switch (event) { case USER_ACTIVITY_EVENT: @@ -1981,7 +1952,7 @@ public class StkAppService extends Service implements Runnable { case LANGUAGE_SELECTION_EVENT: String language = mContext .getResources().getConfiguration().locale.getLanguage(); - CatLog.d(LOG_TAG, "language: " + language); + CatLog.d(this, "language: " + language); // Each language code is a pair of alpha-numeric characters. // Each alpha-numeric character shall be coded on one byte // using the SMS default 7-bit coded alphabet @@ -1992,15 +1963,15 @@ public class StkAppService extends Service implements Runnable { break; } } else { - CatLog.e(LOG_TAG, " Event does not exist in the EventList"); + CatLog.e(this, " Event does not exist in the EventList"); } } else { - CatLog.e(LOG_TAG, "SetupEventList is not received. Ignoring the event: " + event); + CatLog.e(this, "SetupEventList is not received. Ignoring the event: " + event); } } private void removeSetUpEvent(int event, int slotId) { - CatLog.d(LOG_TAG, "Remove Event :" + event); + CatLog.d(this, "Remove Event :" + event); if (mStkContext[slotId].mSetupEventListSettings != null) { /* @@ -2099,22 +2070,22 @@ public class StkAppService extends Service implements Runnable { if (settings.url == null) { // if the command did not contain a URL, // launch the browser to the default homepage. - CatLog.d(LOG_TAG, "no url data provided by proactive command." + + CatLog.d(this, "no url data provided by proactive command." + " launching browser with stk default URL ... "); url = SystemProperties.get(STK_BROWSER_DEFAULT_URL_SYSPROP, "http://www.google.com"); } else { - CatLog.d(LOG_TAG, "launch browser command has attached url = " + settings.url); + CatLog.d(this, "launch browser command has attached url = " + settings.url); url = settings.url; } if (url.startsWith("http://") || url.startsWith("https://")) { data = Uri.parse(url); - CatLog.d(LOG_TAG, "launching browser with url = " + url); + CatLog.d(this, "launching browser with url = " + url); } else { String modifiedUrl = "http://" + url; data = Uri.parse(modifiedUrl); - CatLog.d(LOG_TAG, "launching browser with modified url = " + modifiedUrl); + CatLog.d(this, "launching browser with modified url = " + modifiedUrl); } Intent intent = new Intent(Intent.ACTION_VIEW); @@ -2249,23 +2220,23 @@ public class StkAppService extends Service implements Runnable { // without showing user any information. // Alpha Id is Present, but the text data is null. if ((toneMsg.text != null ) && (toneMsg.text.equals(""))) { - CatLog.d(LOG_TAG, "Alpha identifier data is null, play only tone"); + CatLog.d(this, "Alpha identifier data is null, play only tone"); showUser = false; } // Alpha Id is not present AND we need to show info to the user. if (toneMsg.text == null && displayDialog) { - CatLog.d(LOG_TAG, "toneMsg.text " + toneMsg.text + CatLog.d(this, "toneMsg.text " + toneMsg.text + " Starting ToneDialog activity with default message."); toneMsg.text = getResources().getString(R.string.default_tone_dialog_msg); showUser = true; } // Dont show user info, if config setting is true. if (toneMsg.text == null && !displayDialog) { - CatLog.d(LOG_TAG, "config value stkNoAlphaUsrCnf is true"); + CatLog.d(this, "config value stkNoAlphaUsrCnf is true"); showUser = false; } - CatLog.d(LOG_TAG, "toneMsg.text: " + toneMsg.text + "showUser: " +showUser + + CatLog.d(this, "toneMsg.text: " + toneMsg.text + "showUser: " +showUser + "displayDialog: " +displayDialog); playTone(showUser, slotId); } @@ -2274,7 +2245,7 @@ public class StkAppService extends Service implements Runnable { // Start playing tone and vibration ToneSettings settings = mStkContext[slotId].mCurrentCmd.getToneSettings(); if (null == settings) { - CatLog.d(LOG_TAG, "null settings, not playing tone."); + CatLog.d(this, "null settings, not playing tone."); return; } @@ -2286,8 +2257,11 @@ public class StkAppService extends Service implements Runnable { timeout = StkApp.TONE_DEFAULT_TIMEOUT; } - Message msg = mServiceHandler.obtainMessage(OP_STOP_TONE, 0, slotId, - (showUserInfo ? PLAY_TONE_WITH_DIALOG : PLAY_TONE_ONLY)); + Message msg = mServiceHandler.obtainMessage(); + msg.arg1 = OP_STOP_TONE; + msg.arg2 = slotId; + msg.obj = (Integer)(showUserInfo ? 1 : 0); + msg.what = STOP_TONE_WHAT; mServiceHandler.sendMessageDelayed(msg, timeout); if (settings.vibrate) { mVibrator.vibrate(timeout); @@ -2299,7 +2273,9 @@ public class StkAppService extends Service implements Runnable { String uriString = STK_TONE_URI + slotId; Uri uriData = Uri.parse(uriString); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_SINGLE_TOP + | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage()); newIntent.putExtra(SLOT_ID, slotId); @@ -2319,20 +2295,18 @@ public class StkAppService extends Service implements Runnable { // Stop the play tone in following cases: // 1.OP_STOP_TONE: play tone timer expires. // 2.STOP_TONE_USER: user pressed the back key. - if (msg.what == OP_STOP_TONE) { + if (msg.arg1 == 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) { + int finishActivity = (Integer) msg.obj; + if (finishActivity == 1) finishToneDialogActivity(); + } else if (msg.arg1 == OP_STOP_TONE_USER) { resId = RES_ID_END_SESSION; } sendResponse(resId, slotId, true); - - mServiceHandler.removeMessages(OP_STOP_TONE); - mServiceHandler.removeMessages(OP_STOP_TONE_USER); - - if (mTonePlayer != null) { + mServiceHandler.removeMessages(STOP_TONE_WHAT); + if (mTonePlayer != null) { mTonePlayer.stop(); mTonePlayer.release(); mTonePlayer = null; @@ -2366,7 +2340,11 @@ public class StkAppService extends Service implements Runnable { Bundle args = new Bundle(); args.putInt(RES_ID, RES_ID_CHOICE); args.putInt(CHOICE, YES); - sendResponse(args, slotId); + Message message = mServiceHandler.obtainMessage(); + message.arg1 = OP_RESPONSE; + message.arg2 = slotId; + message.obj = args; + mServiceHandler.sendMessage(message); } }) .setNegativeButton(getResources().getString(R.string.stk_dialog_reject), @@ -2375,7 +2353,11 @@ public class StkAppService extends Service implements Runnable { Bundle args = new Bundle(); args.putInt(RES_ID, RES_ID_CHOICE); args.putInt(CHOICE, NO); - sendResponse(args, slotId); + Message message = mServiceHandler.obtainMessage(); + message.arg1 = OP_RESPONSE; + message.arg2 = slotId; + message.obj = args; + mServiceHandler.sendMessage(message); } }) .create(); @@ -2459,7 +2441,7 @@ public class StkAppService extends Service implements Runnable { return false; } - synchronized StkContext getStkContext(int slotId) { + StkContext getStkContext(int slotId) { if (slotId >= 0 && slotId < mSimCount) { return mStkContext[slotId]; } else { @@ -2471,7 +2453,7 @@ public class StkAppService extends Service implements Runnable { private void handleAlphaNotify(Bundle args) { String alphaString = args.getString(AppInterface.ALPHA_STRING); - CatLog.d(LOG_TAG, "Alpha string received from card: " + alphaString); + CatLog.d(this, "Alpha string received from card: " + alphaString); Toast toast = Toast.makeText(sInstance, alphaString, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); diff --git a/src/com/android/stk/StkCmdReceiver.java b/src/com/android/stk/StkCmdReceiver.java index 025b68e..aeb4e22 100644 --- a/src/com/android/stk/StkCmdReceiver.java +++ b/src/com/android/stk/StkCmdReceiver.java @@ -31,8 +31,6 @@ import com.android.internal.telephony.cat.AppInterface; * */ public class StkCmdReceiver extends BroadcastReceiver { - private static final String LOG_TAG = - new Object(){}.getClass().getEnclosingClass().getSimpleName(); @Override public void onReceive(Context context, Intent intent) { @@ -80,7 +78,7 @@ public class StkCmdReceiver extends BroadcastReceiver { args.putString(AppInterface.ALPHA_STRING, alphaString); } - CatLog.d(LOG_TAG, "handleAction, op: " + op + + CatLog.d("StkCmdReceiver", "handleAction, op: " + op + "args: " + args + ", slot id: " + slot_id); Intent toService = new Intent(context, StkAppService.class); toService.putExtras(args); diff --git a/src/com/android/stk/StkDialogActivity.java b/src/com/android/stk/StkDialogActivity.java index 49dd501..1462480 100644 --- a/src/com/android/stk/StkDialogActivity.java +++ b/src/com/android/stk/StkDialogActivity.java @@ -22,6 +22,7 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.os.Build; import android.os.Bundle; import android.os.SystemClock; import android.telephony.SubscriptionManager; @@ -33,7 +34,6 @@ import android.widget.TextView; import com.android.internal.telephony.cat.CatLog; import com.android.internal.telephony.cat.TextMessage; -import com.android.internal.telephony.util.TelephonyUtils; /** * AlertDialog used for DISPLAY TEXT commands. @@ -41,13 +41,15 @@ import com.android.internal.telephony.util.TelephonyUtils; */ public class StkDialogActivity extends Activity { // members - private static final String LOG_TAG = - new Object(){}.getClass().getEnclosingClass().getSimpleName(); + private static final String className = new Object(){}.getClass().getEnclosingClass().getName(); + private static final String LOG_TAG = className.substring(className.lastIndexOf('.') + 1); TextMessage mTextMsg = null; private int mSlotId = -1; private StkAppService appService = StkAppService.getInstance(); // Determines whether Terminal Response (TR) has been sent private boolean mIsResponseSent = false; + // Determines whether this is in the pending state. + private boolean mIsPending = false; // Utilize AlarmManager for real-time countdown private static final String DIALOG_ALARM_TAG = LOG_TAG; private static final long NO_DIALOG_ALARM = -1; @@ -58,6 +60,7 @@ public class StkDialogActivity extends Activity { private static final String ALARM_TIME_KEY = "alarm_time"; private static final String RESPONSE_SENT_KEY = "response_sent"; private static final String SLOT_ID_KEY = "slotid"; + private static final String PENDING = "pending"; private AlertDialog mAlertDialog; @@ -121,8 +124,6 @@ public class StkDialogActivity extends Activity { // command with an immediate response object should disappear when the terminal receives // a subsequent proactive command containing display data. appService.getStkContext(mSlotId).setImmediateDialogInstance(this); - } else { - appService.getStkContext(mSlotId).setPendingDialogInstance(this); } alertDialogBuilder.setTitle(mTextMsg.title); @@ -157,6 +158,9 @@ public class StkDialogActivity extends Activity { super.onResume(); CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent + "], sim id: " + mSlotId); + // The pending dialog is unregistered if this instance was registered as it before. + setPendingState(false); + /* * 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 @@ -211,6 +215,14 @@ public class StkDialogActivity extends Activity { super.onStop(); CatLog.d(LOG_TAG, "onStop - before Send CONFIRM false mIsResponseSent[" + mIsResponseSent + "], sim id: " + mSlotId); + + // Nothing should be done here if this activity is being finished or restarted now. + if (isFinishing() || isChangingConfigurations()) { + return; + } + + // This is registered as the pending dialog as this was sent to the background. + setPendingState(true); } @Override @@ -248,6 +260,7 @@ public class StkDialogActivity extends Activity { outState.putBoolean(RESPONSE_SENT_KEY, mIsResponseSent); outState.putLong(ALARM_TIME_KEY, mAlarmTime); outState.putInt(SLOT_ID_KEY, mSlotId); + outState.putBoolean(PENDING, mIsPending); } @Override @@ -261,6 +274,11 @@ public class StkDialogActivity extends Activity { mAlarmTime = savedInstanceState.getLong(ALARM_TIME_KEY, NO_DIALOG_ALARM); mSlotId = savedInstanceState.getInt(SLOT_ID_KEY); + // The pending dialog must be replaced if the previous instance was in the pending state. + if (savedInstanceState.getBoolean(PENDING)) { + setPendingState(true); + } + if (mAlarmTime != NO_DIALOG_ALARM) { startTimeOut(); } @@ -285,6 +303,15 @@ public class StkDialogActivity extends Activity { } } + private void setPendingState(boolean on) { + if (mTextMsg.responseNeeded) { + if (mIsPending != on) { + appService.getStkContext(mSlotId).setPendingDialogInstance(on ? this : null); + mIsPending = on; + } + } + } + private void sendResponse(int resId, boolean confirmed) { cancelTimeOut(); @@ -328,7 +355,7 @@ public class StkDialogActivity extends Activity { finish(); } - CatLog.d(LOG_TAG, "initFromIntent - [" + (TelephonyUtils.IS_DEBUGGABLE ? mTextMsg : "********") + CatLog.d(LOG_TAG, "initFromIntent - [" + (Build.IS_DEBUGGABLE ? mTextMsg : "********") + "], slot id: " + mSlotId); } diff --git a/src/com/android/stk/StkInputActivity.java b/src/com/android/stk/StkInputActivity.java index 0af6767..356bcfc 100644 --- a/src/com/android/stk/StkInputActivity.java +++ b/src/com/android/stk/StkInputActivity.java @@ -24,7 +24,6 @@ import android.content.Intent; import android.content.res.Configuration; import android.os.Bundle; import android.os.SystemClock; -import android.telephony.CarrierConfigManager; import android.text.Editable; import android.text.InputFilter; import android.text.TextUtils; @@ -43,18 +42,13 @@ import android.widget.PopupMenu; import android.widget.TextView; import android.widget.TextView.BufferType; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; - import com.android.internal.telephony.cat.CatLog; import com.android.internal.telephony.cat.Input; -import com.google.android.material.textfield.TextInputLayout; - /** * Display a request for a text input a long with a text edit form. */ -public class StkInputActivity extends AppCompatActivity implements View.OnClickListener, +public class StkInputActivity extends Activity implements View.OnClickListener, TextWatcher { // Members @@ -67,8 +61,8 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL private View mNormalLayout = null; // Constants - private static final String LOG_TAG = - new Object(){}.getClass().getEnclosingClass().getSimpleName(); + private static final String className = new Object(){}.getClass().getEnclosingClass().getName(); + private static final String LOG_TAG = className.substring(className.lastIndexOf('.') + 1); private Input mStkInput = null; // Constants @@ -87,6 +81,7 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL private static final String RESPONSE_SENT_KEY = "response_sent"; private static final String INPUT_STRING_KEY = "input_string"; private static final String ALARM_TIME_KEY = "alarm_time"; + private static final String PENDING = "pending"; private static final String INPUT_ALARM_TAG = LOG_TAG; private static final long NO_INPUT_ALARM = -1; @@ -95,6 +90,8 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL private StkAppService appService = StkAppService.getInstance(); private boolean mIsResponseSent = false; + // Determines whether this is in the pending state. + private boolean mIsPending = false; private int mSlotId = -1; // Click listener to handle buttons press.. @@ -161,13 +158,18 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL return; } + ActionBar actionBar = null; + if (getResources().getBoolean(R.bool.show_menu_title_only_on_menu)) { + actionBar = getActionBar(); + if (actionBar != null) { + actionBar.hide(); + } + } + // Set the layout for this activity. setContentView(R.layout.stk_input); - setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); - - if (getResources().getBoolean(R.bool.show_menu_title_only_on_menu)) { - getSupportActionBar().hide(); + if (actionBar != null) { mMoreOptions = findViewById(R.id.more); mMoreOptions.setVisibility(View.VISIBLE); mMoreOptions.setOnClickListener(this); @@ -190,7 +192,6 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL mYesNoLayout = findViewById(R.id.yes_no_layout); mNormalLayout = findViewById(R.id.normal_layout); initFromIntent(getIntent()); - appService.getStkContext(mSlotId).setPendingActivityInstance(this); } @Override @@ -205,6 +206,12 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL super.onResume(); CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent + "], slot id: " + mSlotId); + // If the terminal has already sent response to the card when this activity is resumed, + // keep this as a pending activity as this should be finished when the session ends. + if (!mIsResponseSent) { + setPendingState(false); + } + if (mAlarmTime == NO_INPUT_ALARM) { startTimeOut(); } @@ -223,6 +230,23 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL public void onStop() { super.onStop(); CatLog.d(LOG_TAG, "onStop - mIsResponseSent[" + mIsResponseSent + "]"); + + // Nothing should be done here if this activity is being finished or restarted now. + if (isFinishing() || isChangingConfigurations()) { + return; + } + + if (mIsResponseSent) { + // It is unnecessary to keep this activity if the response was already sent and + // the dialog activity is NOT on the top of this activity. + if (!appService.isStkDialogActivated()) { + finish(); + } + } else { + // This should be registered as the pending activity here + // only when no response has been sent back to the card. + setPendingState(true); + } } @Override @@ -302,6 +326,11 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL } args.putBoolean(StkAppService.HELP, help); appService.sendResponse(args, mSlotId); + + // This instance should be set as a pending activity and finished by the service + if (resId != StkAppService.RES_ID_END_SESSION) { + setPendingState(true); + } } @Override @@ -359,6 +388,7 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL outState.putBoolean(RESPONSE_SENT_KEY, mIsResponseSent); outState.putString(INPUT_STRING_KEY, mTextIn.getText().toString()); outState.putLong(ALARM_TIME_KEY, mAlarmTime); + outState.putBoolean(PENDING, mIsPending); } @Override @@ -378,6 +408,22 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL if (mAlarmTime != NO_INPUT_ALARM) { startTimeOut(); } + + if (!mIsResponseSent && !savedInstanceState.getBoolean(PENDING)) { + // If this is in the foreground and no response has been sent to the card, + // this must not be registered as pending activity by the previous instance. + // No need to renew nor clear pending activity in this case. + } else { + // Renew the instance of the pending activity. + setPendingState(true); + } + } + + private void setPendingState(boolean on) { + if (mIsPending != on) { + appService.getStkContext(mSlotId).setPendingActivityInstance(on ? this : null); + mIsPending = on; + } } public void beforeTextChanged(CharSequence s, int start, int count, @@ -430,7 +476,8 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL } private void configInputDisplay() { - TextInputLayout textInput = (TextInputLayout) findViewById(R.id.text_input_layout); + TextView numOfCharsView = (TextView) findViewById(R.id.num_of_chars); + TextView inTypeView = (TextView) findViewById(R.id.input_type); int inTypeId = R.string.alphabet; @@ -442,16 +489,11 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL } // Set input type (alphabet/digit) info close to the InText form. - boolean hideHelper = false; if (mStkInput.digitOnly) { mTextIn.setKeyListener(StkDigitsKeyListener.getInstance()); inTypeId = R.string.digits; - hideHelper = StkAppService.getBooleanCarrierConfig(this, - CarrierConfigManager.KEY_HIDE_DIGITS_HELPER_TEXT_ON_STK_INPUT_SCREEN_BOOL, - mSlotId); } - textInput.setHelperText(getResources().getString(inTypeId)); - textInput.setHelperTextEnabled(!hideHelper); + inTypeView.setText(inTypeId); setTitle(R.string.app_name); @@ -464,10 +506,17 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL // Handle specific global and text attributes. switch (mState) { case STATE_TEXT: - mTextIn.setFilters(new InputFilter[] {new InputFilter.LengthFilter(mStkInput.maxLen)}); - - textInput.setCounterMaxLength(mStkInput.maxLen); - textInput.setCounterEnabled(true); + int maxLen = mStkInput.maxLen; + int minLen = mStkInput.minLen; + mTextIn.setFilters(new InputFilter[] {new InputFilter.LengthFilter( + maxLen)}); + + // Set number of chars info. + String lengthLimit = String.valueOf(minLen); + if (maxLen != minLen) { + lengthLimit = minLen + " - " + maxLen; + } + numOfCharsView.setText(lengthLimit); if (!mStkInput.echo) { mTextIn.setTransformationMethod(PasswordTransformationMethod diff --git a/src/com/android/stk/StkLauncherActivity.java b/src/com/android/stk/StkLauncherActivity.java index f1100b2..9d2f60f 100644 --- a/src/com/android/stk/StkLauncherActivity.java +++ b/src/com/android/stk/StkLauncherActivity.java @@ -46,8 +46,8 @@ import java.util.ArrayList; public class StkLauncherActivity extends ListActivity { private TextView mTitleTextView = null; private ImageView mTitleIconView = null; - private static final String LOG_TAG = - new Object(){}.getClass().getEnclosingClass().getSimpleName(); + private static final String className = new Object(){}.getClass().getEnclosingClass().getName(); + private static final String LOG_TAG = className.substring(className.lastIndexOf('.') + 1); private ArrayList<Item> mStkMenuList = null; private int mSingleSimId = -1; private Context mContext = null; @@ -94,7 +94,7 @@ public class StkLauncherActivity extends ListActivity { return; } CatLog.d(LOG_TAG, "launch stk menu id: " + item.id); - if (item.id >= 0 && item.id < simCount) { + if (item.id >= PhoneConstants.SIM_ID_1 && item.id < simCount) { mAcceptUsersInput = false; launchSTKMainMenu(item.id); } @@ -220,7 +220,8 @@ public class StkLauncherActivity extends ListActivity { Bundle args = new Bundle(); CatLog.d(LOG_TAG, "launchSTKMainMenu."); args.putInt(StkAppService.OPCODE, StkAppService.OP_LAUNCH_APP); - args.putInt(StkAppService.SLOT_ID, slodId); + args.putInt(StkAppService.SLOT_ID + , PhoneConstants.SIM_ID_1 + slodId); startService(new Intent(this, StkAppService.class) .putExtras(args)); } diff --git a/src/com/android/stk/StkMain.java b/src/com/android/stk/StkMain.java index 0899d2b..2be33ab 100644 --- a/src/com/android/stk/StkMain.java +++ b/src/com/android/stk/StkMain.java @@ -36,8 +36,8 @@ import android.widget.Toast; * */ public class StkMain extends Activity { - private static final String LOG_TAG = - new Object(){}.getClass().getEnclosingClass().getSimpleName(); + private static final String className = new Object(){}.getClass().getEnclosingClass().getName(); + private static final String LOG_TAG = className.substring(className.lastIndexOf('.') + 1); private int mSingleSimId = -1; private Context mContext = null; private TelephonyManager mTm = null; @@ -96,7 +96,8 @@ import android.widget.Toast; Bundle args = new Bundle(); CatLog.d(LOG_TAG, "launchSTKMainMenu."); args.putInt(StkAppService.OPCODE, StkAppService.OP_LAUNCH_APP); - args.putInt(StkAppService.SLOT_ID, slotId); + args.putInt(StkAppService.SLOT_ID + , PhoneConstants.SIM_ID_1 + slotId); startService(new Intent(this, StkAppService.class) .putExtras(args)); } diff --git a/src/com/android/stk/StkMenuActivity.java b/src/com/android/stk/StkMenuActivity.java index c75e3ab..073de8d 100644 --- a/src/com/android/stk/StkMenuActivity.java +++ b/src/com/android/stk/StkMenuActivity.java @@ -25,6 +25,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.os.SystemClock; +import android.support.v4.content.LocalBroadcastManager; import android.telephony.SubscriptionManager; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -37,8 +38,6 @@ import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; - import com.android.internal.telephony.cat.CatLog; import com.android.internal.telephony.cat.Item; import com.android.internal.telephony.cat.Menu; @@ -55,13 +54,14 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex private boolean mAcceptUsersInput = true; private int mSlotId = -1; private boolean mIsResponseSent = false; + // Determines whether this is in the pending state. + private boolean mIsPending = false; private TextView mTitleTextView = null; private ImageView mTitleIconView = null; private ProgressBar mProgressView = null; - - private static final String LOG_TAG = - new Object(){}.getClass().getEnclosingClass().getSimpleName(); + private static final String className = new Object(){}.getClass().getEnclosingClass().getName(); + private static final String LOG_TAG = className.substring(className.lastIndexOf('.') + 1); private StkAppService appService = StkAppService.getInstance(); @@ -70,6 +70,7 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex private static final String ACCEPT_USERS_INPUT_KEY = "accept_users_input"; private static final String RESPONSE_SENT_KEY = "response_sent"; private static final String ALARM_TIME_KEY = "alarm_time"; + private static final String PENDING = "pending"; private static final String SELECT_ALARM_TAG = LOG_TAG; private static final long NO_SELECT_ALARM = -1; @@ -114,9 +115,6 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex finish(); return; } - if (mState == STATE_SECONDARY) { - appService.getStkContext(mSlotId).setPendingActivityInstance(this); - } } @Override @@ -183,6 +181,11 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex } displayMenu(); + // If the terminal has already sent response to the card when this activity is resumed, + // keep this as a pending activity as this should be finished when the session ends. + if (!mIsResponseSent) { + setPendingState(false); + } if (mAlarmTime == NO_SELECT_ALARM) { startTimeOut(); } @@ -217,6 +220,23 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex public void onStop() { super.onStop(); CatLog.d(LOG_TAG, "onStop, slot id: " + mSlotId + "," + mIsResponseSent + "," + mState); + + // Nothing should be done here if this activity is being finished or restarted now. + if (isFinishing() || isChangingConfigurations()) { + return; + } + + if (mIsResponseSent) { + // It is unnecessary to keep this activity if the response was already sent and + // the dialog activity is NOT on the top of this activity. + if (mState == STATE_SECONDARY && !appService.isStkDialogActivated()) { + finish(); + } + } else { + // This instance should be registered as the pending activity here + // only when no response has been sent back to the card. + setPendingState(true); + } } @Override @@ -282,13 +302,13 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { - CatLog.d(LOG_TAG, "onCreateContextMenu"); + CatLog.d(this, "onCreateContextMenu"); boolean helpVisible = false; if (mStkMenu != null) { helpVisible = mStkMenu.helpAvailable; } if (helpVisible) { - CatLog.d(LOG_TAG, "add menu"); + CatLog.d(this, "add menu"); menu.add(0, CONTEXT_MENU_HELP, 0, R.string.help); } } @@ -304,10 +324,10 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex switch (item.getItemId()) { case CONTEXT_MENU_HELP: int position = info.position; - CatLog.d(LOG_TAG, "Position:" + position); + CatLog.d(this, "Position:" + position); Item stkItem = getSelectedItem(position); if (stkItem != null) { - CatLog.d(LOG_TAG, "item id:" + stkItem.id); + CatLog.d(this, "item id:" + stkItem.id); sendResponse(StkAppService.RES_ID_MENU_SELECTION, stkItem.id, true); } return true; @@ -324,6 +344,7 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex outState.putBoolean(ACCEPT_USERS_INPUT_KEY, mAcceptUsersInput); outState.putBoolean(RESPONSE_SENT_KEY, mIsResponseSent); outState.putLong(ALARM_TIME_KEY, mAlarmTime); + outState.putBoolean(PENDING, mIsPending); } @Override @@ -345,6 +366,24 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex if (mAlarmTime != NO_SELECT_ALARM) { startTimeOut(); } + + if (!mIsResponseSent && !savedInstanceState.getBoolean(PENDING)) { + // If this is in the foreground and no response has been sent to the card, + // this must not be registered as pending activity by the previous instance. + // No need to renew nor clear pending activity in this case. + } else { + // Renew the instance of the pending activity. + setPendingState(true); + } + } + + private void setPendingState(boolean on) { + if (mState == STATE_SECONDARY) { + if (mIsPending != on) { + appService.getStkContext(mSlotId).setPendingActivityInstance(on ? this : null); + mIsPending = on; + } + } } private void cancelTimeOut() { @@ -462,6 +501,11 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex args.putInt(StkAppService.MENU_SELECTION, itemId); args.putBoolean(StkAppService.HELP, help); appService.sendResponse(args, mSlotId); + + // This instance should be set as a pending activity and finished by the service. + if (resId != StkAppService.RES_ID_END_SESSION) { + setPendingState(true); + } } private final BroadcastReceiver mLocalBroadcastReceiver = new BroadcastReceiver() { diff --git a/src/com/android/stk/StkMenuConfig.java b/src/com/android/stk/StkMenuConfig.java index 5414a6a..d0fa0d8 100644 --- a/src/com/android/stk/StkMenuConfig.java +++ b/src/com/android/stk/StkMenuConfig.java @@ -20,6 +20,7 @@ import android.content.Context; import android.content.res.XmlResourceParser; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.os.Build; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; @@ -27,7 +28,6 @@ import android.text.TextUtils; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.cat.CatLog; -import com.android.internal.telephony.util.TelephonyUtils; import com.android.internal.util.XmlUtils; import java.util.ArrayList; @@ -37,9 +37,8 @@ import java.util.ArrayList; * conbination of the inserted SIM card for Multi-SIM model. */ public class StkMenuConfig { - private static final String LOG_TAG = - new Object(){}.getClass().getEnclosingClass().getSimpleName(); - private static final boolean DBG = TelephonyUtils.IS_DEBUGGABLE; + private static final String LOG_TAG = "StkMenuConfig"; + private static final boolean DBG = Build.IS_DEBUGGABLE; private static final String XML_OPERATORS_TAG = "operators"; private static final String XML_OPERATOR_TAG = "operator"; diff --git a/src/com/android/stk/ToneDialog.java b/src/com/android/stk/ToneDialog.java index 2efeecd..1c5fca6 100644..100755 --- a/src/com/android/stk/ToneDialog.java +++ b/src/com/android/stk/ToneDialog.java @@ -43,8 +43,7 @@ public class ToneDialog extends Activity { int mSlotId = -1; private AlertDialog mAlertDialog; - private static final String LOG_TAG = - new Object(){}.getClass().getEnclosingClass().getSimpleName(); + private static final String LOG_TAG = new Object(){}.getClass().getEnclosingClass().getName(); @Override protected void onCreate(Bundle icicle) { @@ -113,7 +112,7 @@ public class ToneDialog extends Activity { // 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"); + CatLog.d(this, "Finishing Tone dialog activity"); finish(); } } |