The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.stk; |
| 18 | |
Peter Wang | c94b8e6 | 2019-12-30 17:09:10 -0800 | [diff] [blame] | 19 | import static com.android.internal.telephony.cat.CatCmdMessage.SetupEventListConstants.IDLE_SCREEN_AVAILABLE_EVENT; |
| 20 | import static com.android.internal.telephony.cat.CatCmdMessage.SetupEventListConstants.LANGUAGE_SELECTION_EVENT; |
| 21 | import static com.android.internal.telephony.cat.CatCmdMessage.SetupEventListConstants.USER_ACTIVITY_EVENT; |
feizhang | 5fd5c6f | 2021-06-30 13:59:02 +0800 | [diff] [blame] | 22 | //add by qingyang.yi 2016.6.21 PR:1137553 add for Browser termination EVENT |
| 23 | import static com.android.internal.telephony.cat.CatCmdMessage.SetupEventListConstants.BROWSER_TERMINATION_EVENT; |
| 24 | //add end by qingyang.yi |
Peter Wang | c94b8e6 | 2019-12-30 17:09:10 -0800 | [diff] [blame] | 25 | import android.app.Activity; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 26 | import android.app.ActivityManager; |
| 27 | import android.app.ActivityManager.RunningTaskInfo; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 28 | import android.app.AlertDialog; |
Hall Liu | 9d5d5ee | 2020-10-06 14:15:40 -0700 | [diff] [blame] | 29 | import android.app.HomeVisibilityListener; |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 30 | import android.app.KeyguardManager; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 31 | import android.app.Notification; |
fionaxu | 2c91c75 | 2017-04-21 18:11:57 -0700 | [diff] [blame] | 32 | import android.app.NotificationChannel; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 33 | import android.app.NotificationManager; |
| 34 | import android.app.PendingIntent; |
| 35 | import android.app.Service; |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 36 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 37 | import android.content.Context; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 38 | import android.content.DialogInterface; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 39 | import android.content.Intent; |
Peter Wang | c94b8e6 | 2019-12-30 17:09:10 -0800 | [diff] [blame] | 40 | import android.content.IntentFilter; |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 41 | import android.content.pm.PackageManager; |
| 42 | import android.content.pm.ResolveInfo; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 43 | import android.content.res.Resources; |
| 44 | import android.content.res.Resources.NotFoundException; |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 45 | import android.graphics.Bitmap; |
| 46 | import android.graphics.BitmapFactory; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 47 | import android.net.Uri; |
| 48 | import android.os.Bundle; |
| 49 | import android.os.Handler; |
| 50 | import android.os.IBinder; |
| 51 | import android.os.Looper; |
| 52 | import android.os.Message; |
Takanori Nakano | c8054ba | 2016-08-15 19:18:16 +0900 | [diff] [blame] | 53 | import android.os.Parcel; |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 54 | import android.os.PersistableBundle; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 55 | import android.os.PowerManager; |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 56 | import android.os.RemoteException; |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 57 | import android.os.SystemProperties; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 58 | import android.os.Vibrator; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 59 | import android.provider.Settings; |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 60 | import android.telephony.CarrierConfigManager; |
Yoshiaki Naka | 30d5a81 | 2018-11-12 12:43:34 +0900 | [diff] [blame] | 61 | import android.telephony.SubscriptionInfo; |
Yoshiaki Naka | 9018313 | 2017-08-31 19:25:33 +0900 | [diff] [blame] | 62 | import android.telephony.SubscriptionManager; |
Peter Wang | c94b8e6 | 2019-12-30 17:09:10 -0800 | [diff] [blame] | 63 | import android.telephony.TelephonyFrameworkInitializer; |
Wink Saville | 56469d5 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 64 | import android.telephony.TelephonyManager; |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 65 | import android.text.TextUtils; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 66 | import android.view.Gravity; |
| 67 | import android.view.LayoutInflater; |
| 68 | import android.view.View; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 69 | import android.view.WindowManager; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 70 | import android.widget.ImageView; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 71 | import android.widget.TextView; |
| 72 | import android.widget.Toast; |
| 73 | |
Peter Wang | 10da929 | 2020-01-27 12:36:00 +0800 | [diff] [blame] | 74 | import androidx.localbroadcastmanager.content.LocalBroadcastManager; |
| 75 | |
Peter Wang | c94b8e6 | 2019-12-30 17:09:10 -0800 | [diff] [blame] | 76 | import com.android.internal.telephony.GsmAlphabet; |
Peter Wang | a14d13d | 2020-01-15 14:13:51 -0800 | [diff] [blame] | 77 | import com.android.internal.telephony.ITelephony; |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 78 | import com.android.internal.telephony.PhoneConfigurationManager; |
Peter Wang | c94b8e6 | 2019-12-30 17:09:10 -0800 | [diff] [blame] | 79 | import com.android.internal.telephony.PhoneConstants; |
Peter Wang | 10da929 | 2020-01-27 12:36:00 +0800 | [diff] [blame] | 80 | import com.android.internal.telephony.TelephonyIntents; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 81 | import com.android.internal.telephony.cat.AppInterface; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 82 | import com.android.internal.telephony.cat.CatCmdMessage; |
| 83 | import com.android.internal.telephony.cat.CatCmdMessage.BrowserSettings; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 84 | import com.android.internal.telephony.cat.CatCmdMessage.SetupEventListSettings; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 85 | import com.android.internal.telephony.cat.CatLog; |
| 86 | import com.android.internal.telephony.cat.CatResponseMessage; |
Peter Wang | c94b8e6 | 2019-12-30 17:09:10 -0800 | [diff] [blame] | 87 | import com.android.internal.telephony.cat.CatService; |
| 88 | import com.android.internal.telephony.cat.Input; |
| 89 | import com.android.internal.telephony.cat.Item; |
| 90 | import com.android.internal.telephony.cat.Menu; |
| 91 | import com.android.internal.telephony.cat.ResultCode; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 92 | import com.android.internal.telephony.cat.TextMessage; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 93 | import com.android.internal.telephony.cat.ToneSettings; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 94 | import com.android.internal.telephony.uicc.IccRefreshResponse; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 95 | |
| 96 | import java.util.LinkedList; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 97 | import java.util.List; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 98 | |
| 99 | /** |
| 100 | * SIM toolkit application level service. Interacts with Telephopny messages, |
| 101 | * application's launch and user input from STK UI elements. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 102 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 103 | */ |
| 104 | public class StkAppService extends Service implements Runnable { |
| 105 | |
| 106 | // members |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 107 | protected class StkContext { |
| 108 | protected CatCmdMessage mMainCmd = null; |
| 109 | protected CatCmdMessage mCurrentCmd = null; |
| 110 | protected CatCmdMessage mCurrentMenuCmd = null; |
| 111 | protected Menu mCurrentMenu = null; |
| 112 | protected String lastSelectedItem = null; |
| 113 | protected boolean mMenuIsVisible = false; |
| 114 | protected boolean mIsInputPending = false; |
| 115 | protected boolean mIsMenuPending = false; |
| 116 | protected boolean mIsDialogPending = false; |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 117 | protected boolean mNotificationOnKeyguard = false; |
| 118 | protected boolean mNoResponseFromUser = false; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 119 | protected boolean launchBrowser = false; |
| 120 | protected BrowserSettings mBrowserSettings = null; |
| 121 | protected LinkedList<DelayedCmd> mCmdsQ = null; |
| 122 | protected boolean mCmdInProgress = false; |
| 123 | protected int mStkServiceState = STATE_UNKNOWN; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 124 | protected int mMenuState = StkMenuActivity.STATE_INIT; |
| 125 | protected int mOpCode = -1; |
| 126 | private Activity mActivityInstance = null; |
| 127 | private Activity mDialogInstance = null; |
Yoshiaki Naka | 9018313 | 2017-08-31 19:25:33 +0900 | [diff] [blame] | 128 | private Activity mImmediateDialogInstance = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 129 | private int mSlotId = 0; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 130 | private SetupEventListSettings mSetupEventListSettings = null; |
| 131 | private boolean mClearSelectItem = false; |
| 132 | private boolean mDisplayTextDlgIsVisibile = false; |
| 133 | private CatCmdMessage mCurrentSetupEventCmd = null; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 134 | private CatCmdMessage mIdleModeTextCmd = null; |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 135 | private boolean mIdleModeTextVisible = false; |
Takanori Nakano | 43dacc0 | 2018-07-26 11:27:39 +0900 | [diff] [blame] | 136 | // Determins whether the current session was initiated by user operation. |
| 137 | protected boolean mIsSessionFromUser = false; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 138 | final synchronized void setPendingActivityInstance(Activity act) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 139 | CatLog.d(LOG_TAG, "setPendingActivityInstance act : " + mSlotId + ", " + act); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 140 | callSetActivityInstMsg(OP_SET_ACT_INST, mSlotId, act); |
| 141 | } |
| 142 | final synchronized Activity getPendingActivityInstance() { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 143 | CatLog.d(LOG_TAG, "getPendingActivityInstance act : " + mSlotId + ", " + |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 144 | mActivityInstance); |
| 145 | return mActivityInstance; |
| 146 | } |
| 147 | final synchronized void setPendingDialogInstance(Activity act) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 148 | CatLog.d(LOG_TAG, "setPendingDialogInstance act : " + mSlotId + ", " + act); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 149 | callSetActivityInstMsg(OP_SET_DAL_INST, mSlotId, act); |
| 150 | } |
| 151 | final synchronized Activity getPendingDialogInstance() { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 152 | CatLog.d(LOG_TAG, "getPendingDialogInstance act : " + mSlotId + ", " + |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 153 | mDialogInstance); |
| 154 | return mDialogInstance; |
| 155 | } |
Yoshiaki Naka | 9018313 | 2017-08-31 19:25:33 +0900 | [diff] [blame] | 156 | final synchronized void setImmediateDialogInstance(Activity act) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 157 | CatLog.d(LOG_TAG, "setImmediateDialogInstance act : " + mSlotId + ", " + act); |
Yoshiaki Naka | 9018313 | 2017-08-31 19:25:33 +0900 | [diff] [blame] | 158 | callSetActivityInstMsg(OP_SET_IMMED_DAL_INST, mSlotId, act); |
| 159 | } |
| 160 | final synchronized Activity getImmediateDialogInstance() { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 161 | CatLog.d(LOG_TAG, "getImmediateDialogInstance act : " + mSlotId + ", " + |
Yoshiaki Naka | 9018313 | 2017-08-31 19:25:33 +0900 | [diff] [blame] | 162 | mImmediateDialogInstance); |
| 163 | return mImmediateDialogInstance; |
| 164 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 165 | } |
| 166 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 167 | private volatile Looper mServiceLooper; |
| 168 | private volatile ServiceHandler mServiceHandler; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 169 | private Context mContext = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 170 | private NotificationManager mNotificationManager = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 171 | static StkAppService sInstance = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 172 | private AppInterface[] mStkService = null; |
| 173 | private StkContext[] mStkContext = null; |
| 174 | private int mSimCount = 0; |
Hall Liu | 9d5d5ee | 2020-10-06 14:15:40 -0700 | [diff] [blame] | 175 | private HomeVisibilityListener mHomeVisibilityListener = null; |
Yoshiaki Naka | 0c2d2ba | 2017-11-17 21:51:55 +0900 | [diff] [blame] | 176 | private BroadcastReceiver mLocaleChangeReceiver = null; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 177 | private TonePlayer mTonePlayer = null; |
| 178 | private Vibrator mVibrator = null; |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 179 | private BroadcastReceiver mUserActivityReceiver = null; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 180 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 181 | // Used for setting FLAG_ACTIVITY_NO_USER_ACTION when |
| 182 | // creating an intent. |
| 183 | private enum InitiatedByUserAction { |
| 184 | yes, // The action was started via a user initiated action |
| 185 | unknown, // Not known for sure if user initated the action |
| 186 | } |
| 187 | |
| 188 | // constants |
| 189 | static final String OPCODE = "op"; |
| 190 | static final String CMD_MSG = "cmd message"; |
| 191 | static final String RES_ID = "response id"; |
| 192 | static final String MENU_SELECTION = "menu selection"; |
| 193 | static final String INPUT = "input"; |
| 194 | static final String HELP = "help"; |
| 195 | static final String CONFIRMATION = "confirm"; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 196 | static final String CHOICE = "choice"; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 197 | static final String SLOT_ID = "SLOT_ID"; |
| 198 | static final String STK_CMD = "STK CMD"; |
| 199 | static final String STK_DIALOG_URI = "stk://com.android.stk/dialog/"; |
| 200 | static final String STK_MENU_URI = "stk://com.android.stk/menu/"; |
| 201 | static final String STK_INPUT_URI = "stk://com.android.stk/input/"; |
| 202 | static final String STK_TONE_URI = "stk://com.android.stk/tone/"; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 203 | static final String FINISH_TONE_ACTIVITY_ACTION = |
| 204 | "android.intent.action.stk.finish_activity"; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 205 | |
| 206 | // These below constants are used for SETUP_EVENT_LIST |
| 207 | static final String SETUP_EVENT_TYPE = "event"; |
| 208 | static final String SETUP_EVENT_CAUSE = "cause"; |
| 209 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 210 | // operations ids for different service functionality. |
| 211 | static final int OP_CMD = 1; |
| 212 | static final int OP_RESPONSE = 2; |
| 213 | static final int OP_LAUNCH_APP = 3; |
| 214 | static final int OP_END_SESSION = 4; |
| 215 | static final int OP_BOOT_COMPLETED = 5; |
| 216 | private static final int OP_DELAYED_MSG = 6; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 217 | static final int OP_CARD_STATUS_CHANGED = 7; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 218 | static final int OP_SET_ACT_INST = 8; |
| 219 | static final int OP_SET_DAL_INST = 9; |
Ryuto Sawada | 08c821c | 2016-08-08 18:29:02 +0900 | [diff] [blame] | 220 | static final int OP_LOCALE_CHANGED = 10; |
| 221 | static final int OP_ALPHA_NOTIFY = 11; |
| 222 | static final int OP_IDLE_SCREEN = 12; |
Yoshiaki Naka | 9018313 | 2017-08-31 19:25:33 +0900 | [diff] [blame] | 223 | static final int OP_SET_IMMED_DAL_INST = 13; |
Anna Suzuki | b1cee23 | 2019-02-21 12:52:27 +0900 | [diff] [blame] | 224 | static final int OP_HOME_KEY_PRESSED = 14; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 225 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 226 | //Invalid SetupEvent |
| 227 | static final int INVALID_SETUP_EVENT = 0xFF; |
| 228 | |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 229 | // Message id to signal stop tone due to play tone timeout. |
| 230 | private static final int OP_STOP_TONE = 16; |
| 231 | |
| 232 | // Message id to signal stop tone on user keyback. |
| 233 | static final int OP_STOP_TONE_USER = 17; |
| 234 | |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 235 | // Message id to send user activity event to card. |
| 236 | private static final int OP_USER_ACTIVITY = 20; |
| 237 | |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 238 | // Message id that multi-SIM config has changed (ss <-> ds). |
| 239 | private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 21; |
| 240 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 241 | // Response ids |
| 242 | static final int RES_ID_MENU_SELECTION = 11; |
| 243 | static final int RES_ID_INPUT = 12; |
| 244 | static final int RES_ID_CONFIRM = 13; |
| 245 | static final int RES_ID_DONE = 14; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 246 | static final int RES_ID_CHOICE = 15; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 247 | |
| 248 | static final int RES_ID_TIMEOUT = 20; |
| 249 | static final int RES_ID_BACKWARD = 21; |
| 250 | static final int RES_ID_END_SESSION = 22; |
| 251 | static final int RES_ID_EXIT = 23; |
Srikanth Chintala | ba10300 | 2015-11-30 10:49:52 -0800 | [diff] [blame] | 252 | static final int RES_ID_ERROR = 24; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 253 | |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 254 | static final int YES = 1; |
| 255 | static final int NO = 0; |
| 256 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 257 | static final int STATE_UNKNOWN = -1; |
| 258 | static final int STATE_NOT_EXIST = 0; |
| 259 | static final int STATE_EXIST = 1; |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 260 | |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 261 | private static final Integer PLAY_TONE_ONLY = 0; |
| 262 | private static final Integer PLAY_TONE_WITH_DIALOG = 1; |
| 263 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 264 | private static final String PACKAGE_NAME = "com.android.stk"; |
| 265 | private static final String STK_MENU_ACTIVITY_NAME = PACKAGE_NAME + ".StkMenuActivity"; |
| 266 | private static final String STK_INPUT_ACTIVITY_NAME = PACKAGE_NAME + ".StkInputActivity"; |
| 267 | private static final String STK_DIALOG_ACTIVITY_NAME = PACKAGE_NAME + ".StkDialogActivity"; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 268 | // Notification id used to display Idle Mode text in NotificationManager. |
| 269 | private static final int STK_NOTIFICATION_ID = 333; |
fionaxu | 2c91c75 | 2017-04-21 18:11:57 -0700 | [diff] [blame] | 270 | // Notification channel containing all mobile service messages notifications. |
| 271 | private static final String STK_NOTIFICATION_CHANNEL_ID = "mobileServiceMessages"; |
| 272 | |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 273 | private static final String LOG_TAG = |
| 274 | new Object(){}.getClass().getEnclosingClass().getSimpleName(); |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 275 | |
Takanori Nakano | 3776e2c | 2016-10-14 16:54:28 +0900 | [diff] [blame] | 276 | static final String SESSION_ENDED = "session_ended"; |
| 277 | |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 278 | // Inner class used for queuing telephony messages (proactive commands, |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 279 | // session end) while the service is busy processing a previous message. |
| 280 | private class DelayedCmd { |
| 281 | // members |
| 282 | int id; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 283 | CatCmdMessage msg; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 284 | int slotId; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 285 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 286 | DelayedCmd(int id, CatCmdMessage msg, int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 287 | this.id = id; |
| 288 | this.msg = msg; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 289 | this.slotId = slotId; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 293 | // system property to set the STK specific default url for launch browser proactive cmds |
| 294 | private static final String STK_BROWSER_DEFAULT_URL_SYSPROP = "persist.radio.stk.default_url"; |
| 295 | |
Umashankar Godachi | c77445b | 2018-02-28 02:51:56 +0530 | [diff] [blame] | 296 | // Description of the Icon that is being dispalyed in a Stk activity. |
| 297 | public static final String TEXT_DEFAULT_ICON = "Stk Default Icon"; |
| 298 | public static final String TEXT_ICON_FROM_COMMAND="Stk Icon from Command"; |
feizhang | 5fd5c6f | 2021-06-30 13:59:02 +0800 | [diff] [blame] | 299 | //add by qingyang.yi 2016.6.21 PR:1137553 add for Browser termination EVENT |
| 300 | static final int OP_BROWSER_TERMINATION = 32; |
| 301 | private static final String BROWSER_TERMINATE_ACTION = "com.stk.intent.action.browser_terminate_action"; |
| 302 | private static final String BROWSER_TERMINATION_CAUSE = "browser_termination_cause"; |
| 303 | //add end by qingyang.yi |
Umashankar Godachi | c77445b | 2018-02-28 02:51:56 +0530 | [diff] [blame] | 304 | |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 305 | private static final int NOTIFICATION_ON_KEYGUARD = 1; |
| 306 | private static final long[] VIBRATION_PATTERN = new long[] { 0, 350, 250, 350 }; |
| 307 | private BroadcastReceiver mUserPresentReceiver = null; |
| 308 | |
Anna Suzuki | b1cee23 | 2019-02-21 12:52:27 +0900 | [diff] [blame] | 309 | // The reason based on Intent.ACTION_CLOSE_SYSTEM_DIALOGS. |
| 310 | private static final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 311 | private static final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jordan Liu | 79fa102 | 2020-08-04 11:34:03 -0700 | [diff] [blame] | 312 | private static final String SYSTEM_DIALOG_REASON_RECENTAPPS_KEY = "recentapps"; |
Anna Suzuki | b1cee23 | 2019-02-21 12:52:27 +0900 | [diff] [blame] | 313 | private BroadcastReceiver mHomeKeyEventReceiver = null; |
| 314 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 315 | @Override |
| 316 | public void onCreate() { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 317 | CatLog.d(LOG_TAG, "onCreate()+"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 318 | // Initialize members |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 319 | int i = 0; |
| 320 | mContext = getBaseContext(); |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 321 | mSimCount = TelephonyManager.from(mContext).getActiveModemCount(); |
| 322 | int maxSimCount = TelephonyManager.from(mContext).getSupportedModemCount(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 323 | CatLog.d(LOG_TAG, "simCount: " + mSimCount); |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 324 | mStkService = new AppInterface[maxSimCount]; |
| 325 | mStkContext = new StkContext[maxSimCount]; |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 326 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 327 | for (i = 0; i < mSimCount; i++) { |
| 328 | CatLog.d(LOG_TAG, "slotId: " + i); |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 329 | mStkService[i] = CatService.getInstance(i); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 330 | mStkContext[i] = new StkContext(); |
| 331 | mStkContext[i].mSlotId = i; |
| 332 | mStkContext[i].mCmdsQ = new LinkedList<DelayedCmd>(); |
| 333 | } |
| 334 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 335 | Thread serviceThread = new Thread(null, this, "Stk App Service"); |
| 336 | serviceThread.start(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 337 | mNotificationManager = (NotificationManager) mContext |
| 338 | .getSystemService(Context.NOTIFICATION_SERVICE); |
| 339 | sInstance = this; |
| 340 | } |
| 341 | |
| 342 | @Override |
| 343 | public void onStart(Intent intent, int startId) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 344 | if (intent == null) { |
| 345 | CatLog.d(LOG_TAG, "StkAppService onStart intent is null so return"); |
Banavathu, Srinivas Naik | 87cda96 | 2012-07-17 15:32:44 +0530 | [diff] [blame] | 346 | return; |
| 347 | } |
| 348 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 349 | Bundle args = intent.getExtras(); |
| 350 | if (args == null) { |
| 351 | CatLog.d(LOG_TAG, "StkAppService onStart args is null so return"); |
| 352 | return; |
| 353 | } |
| 354 | |
| 355 | int op = args.getInt(OPCODE); |
| 356 | int slotId = 0; |
| 357 | int i = 0; |
| 358 | if (op != OP_BOOT_COMPLETED) { |
| 359 | slotId = args.getInt(SLOT_ID); |
| 360 | } |
Cuihtlauac ALVARADO | bde7f03 | 2015-05-29 16:25:12 +0200 | [diff] [blame] | 361 | CatLog.d(LOG_TAG, "onStart sim id: " + slotId + ", op: " + op + ", *****"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 362 | if ((slotId >= 0 && slotId < mSimCount) && mStkService[slotId] == null) { |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 363 | mStkService[slotId] = CatService.getInstance(slotId); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 364 | if (mStkService[slotId] == null) { |
| 365 | CatLog.d(LOG_TAG, "mStkService is: " + mStkContext[slotId].mStkServiceState); |
| 366 | mStkContext[slotId].mStkServiceState = STATE_NOT_EXIST; |
| 367 | //Check other StkService state. |
| 368 | //If all StkServices are not available, stop itself and uninstall apk. |
Yoshiaki Naka | 8b960fb | 2019-10-31 10:44:07 +0900 | [diff] [blame] | 369 | for (i = 0; i < mSimCount; i++) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 370 | if (i != slotId |
Tsukasa Goto | 029332b | 2016-10-05 17:12:06 +0900 | [diff] [blame] | 371 | && (mStkService[i] != null) |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 372 | && (mStkContext[i].mStkServiceState == STATE_UNKNOWN |
| 373 | || mStkContext[i].mStkServiceState == STATE_EXIST)) { |
| 374 | break; |
| 375 | } |
| 376 | } |
| 377 | } else { |
| 378 | mStkContext[slotId].mStkServiceState = STATE_EXIST; |
| 379 | } |
| 380 | if (i == mSimCount) { |
| 381 | stopSelf(); |
Yoshiaki Naka | 835e300 | 2020-05-11 18:15:12 +0900 | [diff] [blame] | 382 | StkAppInstaller.uninstall(this); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 383 | return; |
| 384 | } |
| 385 | } |
| 386 | |
Banavathu, Srinivas Naik | 87cda96 | 2012-07-17 15:32:44 +0530 | [diff] [blame] | 387 | waitForLooper(); |
John Wang | 62acae4 | 2009-10-08 11:20:23 -0700 | [diff] [blame] | 388 | |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 389 | Message msg = mServiceHandler.obtainMessage(op, 0, slotId); |
| 390 | switch (op) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 391 | case OP_CMD: |
| 392 | msg.obj = args.getParcelable(CMD_MSG); |
| 393 | break; |
| 394 | case OP_RESPONSE: |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 395 | case OP_CARD_STATUS_CHANGED: |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 396 | case OP_LOCALE_CHANGED: |
Preeti Ahuja | 0f4cf2f | 2012-08-09 11:45:08 +0530 | [diff] [blame] | 397 | case OP_ALPHA_NOTIFY: |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 398 | case OP_IDLE_SCREEN: |
feizhang | 5fd5c6f | 2021-06-30 13:59:02 +0800 | [diff] [blame] | 399 | //add by qingyang.yi 2016.6.21 PR:1137553 add for Browser termination EVENT |
| 400 | case OP_BROWSER_TERMINATION: |
| 401 | //add end by qingyang.yi |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 402 | case OP_STOP_TONE_USER: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 403 | msg.obj = args; |
| 404 | /* falls through */ |
| 405 | case OP_LAUNCH_APP: |
| 406 | case OP_END_SESSION: |
| 407 | case OP_BOOT_COMPLETED: |
| 408 | break; |
| 409 | default: |
| 410 | return; |
| 411 | } |
| 412 | mServiceHandler.sendMessage(msg); |
| 413 | } |
| 414 | |
| 415 | @Override |
| 416 | public void onDestroy() { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 417 | CatLog.d(LOG_TAG, "onDestroy()"); |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 418 | unregisterUserActivityReceiver(); |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 419 | unregisterHomeVisibilityObserver(); |
Yoshiaki Naka | 0c2d2ba | 2017-11-17 21:51:55 +0900 | [diff] [blame] | 420 | unregisterLocaleChangeReceiver(); |
Anna Suzuki | b1cee23 | 2019-02-21 12:52:27 +0900 | [diff] [blame] | 421 | unregisterHomeKeyEventReceiver(); |
Tsukasa Gotou | 54afbdd | 2016-01-07 16:30:20 +0900 | [diff] [blame] | 422 | sInstance = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 423 | waitForLooper(); |
Yoshiaki Naka | f70e373 | 2020-01-24 18:57:22 +0900 | [diff] [blame] | 424 | PhoneConfigurationManager.unregisterForMultiSimConfigChange(mServiceHandler); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 425 | mServiceLooper.quit(); |
| 426 | } |
| 427 | |
| 428 | @Override |
| 429 | public IBinder onBind(Intent intent) { |
| 430 | return null; |
| 431 | } |
| 432 | |
| 433 | public void run() { |
| 434 | Looper.prepare(); |
| 435 | |
| 436 | mServiceLooper = Looper.myLooper(); |
| 437 | mServiceHandler = new ServiceHandler(); |
| 438 | |
Yoshiaki Naka | f70e373 | 2020-01-24 18:57:22 +0900 | [diff] [blame] | 439 | PhoneConfigurationManager.registerForMultiSimConfigChange(mServiceHandler, |
| 440 | EVENT_MULTI_SIM_CONFIG_CHANGED, null); |
| 441 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 442 | Looper.loop(); |
| 443 | } |
| 444 | |
| 445 | /* |
| 446 | * Package api used by StkMenuActivity to indicate if its on the foreground. |
| 447 | */ |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 448 | synchronized void indicateMenuVisibility(boolean visibility, int slotId) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 449 | if (slotId >= 0 && slotId < mSimCount) { |
| 450 | mStkContext[slotId].mMenuIsVisible = visibility; |
| 451 | } |
| 452 | } |
| 453 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 454 | /* |
| 455 | * Package api used by StkDialogActivity to indicate if its on the foreground. |
| 456 | */ |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 457 | synchronized void setDisplayTextDlgVisibility(boolean visibility, int slotId) { |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 458 | if (slotId >= 0 && slotId < mSimCount) { |
| 459 | mStkContext[slotId].mDisplayTextDlgIsVisibile = visibility; |
| 460 | } |
| 461 | } |
| 462 | |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 463 | synchronized boolean isInputPending(int slotId) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 464 | if (slotId >= 0 && slotId < mSimCount) { |
| 465 | CatLog.d(LOG_TAG, "isInputFinishBySrv: " + mStkContext[slotId].mIsInputPending); |
| 466 | return mStkContext[slotId].mIsInputPending; |
| 467 | } |
| 468 | return false; |
| 469 | } |
| 470 | |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 471 | synchronized boolean isMenuPending(int slotId) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 472 | if (slotId >= 0 && slotId < mSimCount) { |
| 473 | CatLog.d(LOG_TAG, "isMenuPending: " + mStkContext[slotId].mIsMenuPending); |
| 474 | return mStkContext[slotId].mIsMenuPending; |
| 475 | } |
| 476 | return false; |
| 477 | } |
| 478 | |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 479 | synchronized boolean isDialogPending(int slotId) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 480 | if (slotId >= 0 && slotId < mSimCount) { |
| 481 | CatLog.d(LOG_TAG, "isDialogPending: " + mStkContext[slotId].mIsDialogPending); |
| 482 | return mStkContext[slotId].mIsDialogPending; |
| 483 | } |
| 484 | return false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 487 | synchronized boolean isMainMenuAvailable(int slotId) { |
Takanori Nakano | 3776e2c | 2016-10-14 16:54:28 +0900 | [diff] [blame] | 488 | if (slotId >= 0 && slotId < mSimCount) { |
| 489 | // The main menu can handle the next user operation if the previous session finished. |
| 490 | return (mStkContext[slotId].lastSelectedItem == null) ? true : false; |
| 491 | } |
| 492 | return false; |
| 493 | } |
| 494 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 495 | /* |
| 496 | * Package api used by StkMenuActivity to get its Menu parameter. |
| 497 | */ |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 498 | synchronized Menu getMenu(int slotId) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 499 | CatLog.d(LOG_TAG, "StkAppService, getMenu, sim id: " + slotId); |
| 500 | if (slotId >=0 && slotId < mSimCount) { |
| 501 | return mStkContext[slotId].mCurrentMenu; |
| 502 | } else { |
| 503 | return null; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | /* |
| 508 | * Package api used by StkMenuActivity to get its Main Menu parameter. |
| 509 | */ |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 510 | synchronized Menu getMainMenu(int slotId) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 511 | CatLog.d(LOG_TAG, "StkAppService, getMainMenu, sim id: " + slotId); |
w30234 | a08cffe | 2015-02-04 15:13:25 -0800 | [diff] [blame] | 512 | if (slotId >=0 && slotId < mSimCount && (mStkContext[slotId].mMainCmd != null)) { |
Takanori Nakano | c8054ba | 2016-08-15 19:18:16 +0900 | [diff] [blame] | 513 | Menu menu = mStkContext[slotId].mMainCmd.getMenu(); |
Yoshiaki Naka | 835e300 | 2020-05-11 18:15:12 +0900 | [diff] [blame] | 514 | if (menu != null) { |
Takanori Nakano | c8054ba | 2016-08-15 19:18:16 +0900 | [diff] [blame] | 515 | // If alpha identifier or icon identifier with the self-explanatory qualifier is |
| 516 | // specified in SET-UP MENU command, it should be more prioritized than preset ones. |
| 517 | if (menu.title == null |
| 518 | && (menu.titleIcon == null || !menu.titleIconSelfExplanatory)) { |
| 519 | StkMenuConfig config = StkMenuConfig.getInstance(getApplicationContext()); |
| 520 | String label = config.getLabel(slotId); |
| 521 | Bitmap icon = config.getIcon(slotId); |
| 522 | if (label != null || icon != null) { |
| 523 | Parcel parcel = Parcel.obtain(); |
| 524 | menu.writeToParcel(parcel, 0); |
| 525 | parcel.setDataPosition(0); |
| 526 | menu = Menu.CREATOR.createFromParcel(parcel); |
| 527 | parcel.recycle(); |
| 528 | menu.title = label; |
| 529 | menu.titleIcon = icon; |
| 530 | menu.titleIconSelfExplanatory = false; |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | return menu; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 535 | } else { |
| 536 | return null; |
| 537 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | /* |
| 541 | * Package api used by UI Activities and Dialogs to communicate directly |
| 542 | * with the service to deliver state information and parameters. |
| 543 | */ |
| 544 | static StkAppService getInstance() { |
| 545 | return sInstance; |
| 546 | } |
| 547 | |
| 548 | private void waitForLooper() { |
| 549 | while (mServiceHandler == null) { |
| 550 | synchronized (this) { |
| 551 | try { |
| 552 | wait(100); |
| 553 | } catch (InterruptedException e) { |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | private final class ServiceHandler extends Handler { |
| 560 | @Override |
| 561 | public void handleMessage(Message msg) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 562 | if(null == msg) { |
| 563 | CatLog.d(LOG_TAG, "ServiceHandler handleMessage msg is null"); |
| 564 | return; |
| 565 | } |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 566 | int opcode = msg.what; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 567 | int slotId = msg.arg2; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 568 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 569 | CatLog.d(LOG_TAG, "handleMessage opcode[" + opcode + "], sim id[" + slotId + "]"); |
| 570 | if (opcode == OP_CMD && msg.obj != null && |
| 571 | ((CatCmdMessage)msg.obj).getCmdType()!= null) { |
| 572 | CatLog.d(LOG_TAG, "cmdName[" + ((CatCmdMessage)msg.obj).getCmdType().name() + "]"); |
| 573 | } |
Malcolm Chen | 7a9f2ad | 2019-11-06 11:07:09 -0800 | [diff] [blame] | 574 | if (slotId >= mStkContext.length || mStkContext[slotId] == null) { |
| 575 | CatLog.d(LOG_TAG, "invalid slotId " + slotId); |
| 576 | return; |
| 577 | } |
Malcolm Chen | 5e57640 | 2019-11-05 16:09:18 -0800 | [diff] [blame] | 578 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 579 | mStkContext[slotId].mOpCode = opcode; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 580 | switch (opcode) { |
| 581 | case OP_LAUNCH_APP: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 582 | if (mStkContext[slotId].mMainCmd == null) { |
| 583 | CatLog.d(LOG_TAG, "mMainCmd is null"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 584 | // nothing todo when no SET UP MENU command didn't arrive. |
| 585 | return; |
| 586 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 587 | CatLog.d(LOG_TAG, "handleMessage OP_LAUNCH_APP - mCmdInProgress[" + |
| 588 | mStkContext[slotId].mCmdInProgress + "]"); |
| 589 | |
| 590 | //If there is a pending activity for the slot id, |
| 591 | //just finish it and create a new one to handle the pending command. |
| 592 | cleanUpInstanceStackBySlot(slotId); |
| 593 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 594 | CatLog.d(LOG_TAG, "Current cmd type: " + |
| 595 | mStkContext[slotId].mCurrentCmd.getCmdType()); |
| 596 | //Restore the last command from stack by slot id. |
| 597 | restoreInstanceFromStackBySlot(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 598 | break; |
| 599 | case OP_CMD: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 600 | CatLog.d(LOG_TAG, "[OP_CMD]"); |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 601 | CatCmdMessage cmdMsg = (CatCmdMessage) msg.obj; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 602 | // There are two types of commands: |
| 603 | // 1. Interactive - user's response is required. |
| 604 | // 2. Informative - display a message, no interaction with the user. |
| 605 | // |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 606 | // Informative commands can be handled immediately without any delay. |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 607 | // Interactive commands can't override each other. So if a command |
| 608 | // is already in progress, we need to queue the next command until |
| 609 | // the user has responded or a timeout expired. |
| 610 | if (!isCmdInteractive(cmdMsg)) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 611 | handleCmd(cmdMsg, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 612 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 613 | if (!mStkContext[slotId].mCmdInProgress) { |
| 614 | mStkContext[slotId].mCmdInProgress = true; |
| 615 | handleCmd((CatCmdMessage) msg.obj, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 616 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 617 | CatLog.d(LOG_TAG, "[Interactive][in progress]"); |
| 618 | mStkContext[slotId].mCmdsQ.addLast(new DelayedCmd(OP_CMD, |
| 619 | (CatCmdMessage) msg.obj, slotId)); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | break; |
| 623 | case OP_RESPONSE: |
Preeti Ahuja | 414bc41 | 2013-06-25 19:31:49 -0700 | [diff] [blame] | 624 | handleCmdResponse((Bundle) msg.obj, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 625 | // call delayed commands if needed. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 626 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 627 | callDelayedMsg(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 628 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 629 | mStkContext[slotId].mCmdInProgress = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 630 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 631 | break; |
| 632 | case OP_END_SESSION: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 633 | if (!mStkContext[slotId].mCmdInProgress) { |
| 634 | mStkContext[slotId].mCmdInProgress = true; |
| 635 | handleSessionEnd(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 636 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 637 | mStkContext[slotId].mCmdsQ.addLast( |
| 638 | new DelayedCmd(OP_END_SESSION, null, slotId)); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 639 | } |
| 640 | break; |
| 641 | case OP_BOOT_COMPLETED: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 642 | CatLog.d(LOG_TAG, " OP_BOOT_COMPLETED"); |
Yoshiaki Naka | 58e0765 | 2019-04-26 17:58:52 +0900 | [diff] [blame] | 643 | uninstallIfUnnecessary(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 644 | break; |
| 645 | case OP_DELAYED_MSG: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 646 | handleDelayedCmd(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 647 | break; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 648 | case OP_CARD_STATUS_CHANGED: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 649 | CatLog.d(LOG_TAG, "Card/Icc Status change received"); |
| 650 | handleCardStatusChangeAndIccRefresh((Bundle) msg.obj, slotId); |
| 651 | break; |
| 652 | case OP_SET_ACT_INST: |
Yoshiaki Naka | 28d7a72 | 2017-10-24 17:32:16 +0900 | [diff] [blame] | 653 | Activity act = (Activity) msg.obj; |
| 654 | if (mStkContext[slotId].mActivityInstance != act) { |
Yoshiaki Naka | 03a79d9 | 2018-08-09 18:41:31 +0900 | [diff] [blame] | 655 | CatLog.d(LOG_TAG, "Set pending activity instance - " + act); |
Yoshiaki Naka | 28d7a72 | 2017-10-24 17:32:16 +0900 | [diff] [blame] | 656 | Activity previous = mStkContext[slotId].mActivityInstance; |
| 657 | mStkContext[slotId].mActivityInstance = act; |
Yoshiaki Naka | 03a79d9 | 2018-08-09 18:41:31 +0900 | [diff] [blame] | 658 | // Finish the previous one if it was replaced with new one |
| 659 | // but it has not been finished yet somehow. |
| 660 | if (act != null && previous != null && !previous.isDestroyed() |
| 661 | && !previous.isFinishing()) { |
Yoshiaki Naka | 28d7a72 | 2017-10-24 17:32:16 +0900 | [diff] [blame] | 662 | CatLog.d(LOG_TAG, "Finish the previous pending activity - " + previous); |
| 663 | previous.finish(); |
| 664 | } |
Anna Suzuki | 35309b0 | 2019-02-15 16:24:59 +0900 | [diff] [blame] | 665 | } |
| 666 | // Clear pending dialog instance if it has not been cleared yet. |
| 667 | Activity dialog = mStkContext[slotId].getPendingDialogInstance(); |
| 668 | if (dialog != null && (dialog.isDestroyed() || dialog.isFinishing())) { |
| 669 | CatLog.d(LOG_TAG, "Clear pending dialog instance - " + dialog); |
| 670 | mStkContext[slotId].mDialogInstance = null; |
Yoshiaki Naka | 28d7a72 | 2017-10-24 17:32:16 +0900 | [diff] [blame] | 671 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 672 | break; |
| 673 | case OP_SET_DAL_INST: |
Yoshiaki Naka | 9018313 | 2017-08-31 19:25:33 +0900 | [diff] [blame] | 674 | Activity dal = (Activity) msg.obj; |
Yoshiaki Naka | a1cea46 | 2018-08-09 20:33:36 +0900 | [diff] [blame] | 675 | if (mStkContext[slotId].mDialogInstance != dal) { |
| 676 | CatLog.d(LOG_TAG, "Set pending dialog instance - " + dal); |
| 677 | mStkContext[slotId].mDialogInstance = dal; |
| 678 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 679 | break; |
Yoshiaki Naka | 9018313 | 2017-08-31 19:25:33 +0900 | [diff] [blame] | 680 | case OP_SET_IMMED_DAL_INST: |
| 681 | Activity immedDal = (Activity) msg.obj; |
| 682 | CatLog.d(LOG_TAG, "Set dialog instance for immediate response. " + immedDal); |
| 683 | mStkContext[slotId].mImmediateDialogInstance = immedDal; |
| 684 | break; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 685 | case OP_LOCALE_CHANGED: |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 686 | CatLog.d(LOG_TAG, "Locale Changed"); |
Yoshiaki Naka | 8b960fb | 2019-10-31 10:44:07 +0900 | [diff] [blame] | 687 | for (int slot = 0; slot < mSimCount; slot++) { |
Yuta Ui | 1481b17 | 2016-02-03 15:34:31 +0900 | [diff] [blame] | 688 | checkForSetupEvent(LANGUAGE_SELECTION_EVENT, (Bundle) msg.obj, slot); |
| 689 | } |
fionaxu | 805eb57 | 2017-05-02 10:57:30 -0700 | [diff] [blame] | 690 | // rename all registered notification channels on locale change |
| 691 | createAllChannels(); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 692 | break; |
Preeti Ahuja | 0f4cf2f | 2012-08-09 11:45:08 +0530 | [diff] [blame] | 693 | case OP_ALPHA_NOTIFY: |
| 694 | handleAlphaNotify((Bundle) msg.obj); |
| 695 | break; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 696 | case OP_IDLE_SCREEN: |
| 697 | for (int slot = 0; slot < mSimCount; slot++) { |
| 698 | if (mStkContext[slot] != null) { |
| 699 | handleIdleScreen(slot); |
| 700 | } |
| 701 | } |
| 702 | break; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 703 | case OP_STOP_TONE_USER: |
| 704 | case OP_STOP_TONE: |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 705 | CatLog.d(LOG_TAG, "Stop tone"); |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 706 | handleStopTone(msg, slotId); |
| 707 | break; |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 708 | case OP_USER_ACTIVITY: |
Yoshiaki Naka | 8b960fb | 2019-10-31 10:44:07 +0900 | [diff] [blame] | 709 | for (int slot = 0; slot < mSimCount; slot++) { |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 710 | checkForSetupEvent(USER_ACTIVITY_EVENT, null, slot); |
| 711 | } |
| 712 | break; |
feizhang | 5fd5c6f | 2021-06-30 13:59:02 +0800 | [diff] [blame] | 713 | //add by qingyang.yi 2016.6.21 PR:1137553 add for Browser termination EVENT |
| 714 | case OP_BROWSER_TERMINATION: |
| 715 | CatLog.d(LOG_TAG, "Browser Closed"); |
| 716 | checkForSetupEvent(BROWSER_TERMINATION_EVENT, (Bundle) msg.obj,slotId); |
| 717 | break; |
| 718 | //add end by qingyang.yi |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 719 | case EVENT_MULTI_SIM_CONFIG_CHANGED: |
| 720 | handleMultiSimConfigChanged(); |
| 721 | break; |
Anna Suzuki | b1cee23 | 2019-02-21 12:52:27 +0900 | [diff] [blame] | 722 | case OP_HOME_KEY_PRESSED: |
| 723 | CatLog.d(LOG_TAG, "Process the home key pressed event"); |
| 724 | for (int slot = 0; slot < mSimCount; slot++) { |
| 725 | if (mStkContext[slot] != null) { |
| 726 | handleHomeKeyPressed(slot); |
| 727 | } |
| 728 | } |
| 729 | break; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 730 | } |
| 731 | } |
| 732 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 733 | private void handleCardStatusChangeAndIccRefresh(Bundle args, int slotId) { |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 734 | boolean cardStatus = args.getBoolean(AppInterface.CARD_STATUS); |
| 735 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 736 | CatLog.d(LOG_TAG, "CardStatus: " + cardStatus); |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 737 | if (cardStatus == false) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 738 | CatLog.d(LOG_TAG, "CARD is ABSENT"); |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 739 | // Uninstall STKAPP, Clear Idle text, Stop StkAppService |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 740 | cancelIdleText(slotId); |
Srikanth Chintala | 7c5a04c | 2016-09-22 19:05:01 +0530 | [diff] [blame] | 741 | mStkContext[slotId].mCurrentMenu = null; |
| 742 | mStkContext[slotId].mMainCmd = null; |
Umashankar Godachi | 39e2130 | 2017-11-07 12:26:40 +0530 | [diff] [blame] | 743 | mStkService[slotId] = null; |
Takanori Nakano | b82c875 | 2019-04-01 14:47:07 +0900 | [diff] [blame] | 744 | // Stop the tone currently being played if the relevant SIM is removed or disabled. |
| 745 | if (mStkContext[slotId].mCurrentCmd != null |
| 746 | && mStkContext[slotId].mCurrentCmd.getCmdType().value() |
| 747 | == AppInterface.CommandType.PLAY_TONE.value()) { |
| 748 | terminateTone(slotId); |
| 749 | } |
Yoshiaki Naka | 2d10bbb | 2019-05-09 15:35:21 +0900 | [diff] [blame] | 750 | if (!uninstallIfUnnecessary()) { |
| 751 | addToMenuSystemOrUpdateLabel(); |
| 752 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 753 | if (isAllOtherCardsAbsent(slotId)) { |
| 754 | CatLog.d(LOG_TAG, "All CARDs are ABSENT"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 755 | stopSelf(); |
| 756 | } |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 757 | } else { |
| 758 | IccRefreshResponse state = new IccRefreshResponse(); |
| 759 | state.refreshResult = args.getInt(AppInterface.REFRESH_RESULT); |
Umashankar Godachi | 40a72f7 | 2017-09-12 15:16:55 +0530 | [diff] [blame] | 760 | state.aid = args.getString(AppInterface.AID); |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 761 | |
Umashankar Godachi | 40a72f7 | 2017-09-12 15:16:55 +0530 | [diff] [blame] | 762 | CatLog.d(LOG_TAG, "Icc Refresh Result: "+ state.refreshResult |
| 763 | + " aid: " + state.aid); |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 764 | if ((state.refreshResult == IccRefreshResponse.REFRESH_RESULT_INIT) || |
| 765 | (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET)) { |
| 766 | // Clear Idle Text |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 767 | cancelIdleText(slotId); |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 768 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | } |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 772 | |
| 773 | private synchronized void handleMultiSimConfigChanged() { |
| 774 | int oldSimCount = mSimCount; |
| 775 | mSimCount = TelephonyManager.from(mContext).getActiveModemCount(); |
| 776 | for (int i = oldSimCount; i < mSimCount; i++) { |
| 777 | CatLog.d(LOG_TAG, "slotId: " + i); |
| 778 | mStkService[i] = CatService.getInstance(i); |
| 779 | mStkContext[i] = new StkContext(); |
| 780 | mStkContext[i].mSlotId = i; |
| 781 | mStkContext[i].mCmdsQ = new LinkedList<DelayedCmd>(); |
| 782 | } |
| 783 | |
| 784 | for (int i = mSimCount; i < oldSimCount; i++) { |
| 785 | CatLog.d(LOG_TAG, "slotId: " + i); |
| 786 | if (mStkService[i] != null) { |
| 787 | mStkService[i].dispose(); |
| 788 | mStkService[i] = null; |
| 789 | } |
| 790 | mStkContext[i] = null; |
| 791 | } |
| 792 | } |
| 793 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 794 | /* |
| 795 | * Check if all SIMs are absent except the id of slot equals "slotId". |
| 796 | */ |
| 797 | private boolean isAllOtherCardsAbsent(int slotId) { |
| 798 | TelephonyManager mTm = (TelephonyManager) mContext.getSystemService( |
| 799 | Context.TELEPHONY_SERVICE); |
| 800 | int i = 0; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 801 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 802 | for (i = 0; i < mSimCount; i++) { |
| 803 | if (i != slotId && mTm.hasIccCard(i)) { |
| 804 | break; |
| 805 | } |
| 806 | } |
| 807 | if (i == mSimCount) { |
| 808 | return true; |
| 809 | } else { |
| 810 | return false; |
| 811 | } |
| 812 | } |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 813 | |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 814 | /* package */ boolean isScreenIdle() { |
| 815 | ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); |
| 816 | List<RunningTaskInfo> tasks = am.getRunningTasks(1); |
| 817 | if (tasks == null || tasks.isEmpty()) { |
| 818 | return false; |
| 819 | } |
| 820 | |
| 821 | String top = tasks.get(0).topActivity.getPackageName(); |
| 822 | if (top == null) { |
| 823 | return false; |
| 824 | } |
| 825 | |
| 826 | // We can assume that the screen is idle if the home application is in the foreground. |
| 827 | final Intent intent = new Intent(Intent.ACTION_MAIN, null); |
| 828 | intent.addCategory(Intent.CATEGORY_HOME); |
| 829 | |
| 830 | ResolveInfo info = getPackageManager().resolveActivity(intent, |
| 831 | PackageManager.MATCH_DEFAULT_ONLY); |
| 832 | if (info != null) { |
| 833 | if (top.equals(info.activityInfo.packageName)) { |
| 834 | return true; |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | return false; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 839 | } |
| 840 | |
Anna Suzuki | b1cee23 | 2019-02-21 12:52:27 +0900 | [diff] [blame] | 841 | private synchronized void startToObserveHomeKeyEvent(int slotId) { |
| 842 | if (mStkContext[slotId].mIsSessionFromUser || mHomeKeyEventReceiver != null) { |
| 843 | return; |
| 844 | } |
| 845 | mHomeKeyEventReceiver = new BroadcastReceiver() { |
| 846 | @Override public void onReceive(Context context, Intent intent) { |
Jordan Liu | 79fa102 | 2020-08-04 11:34:03 -0700 | [diff] [blame] | 847 | final String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY); |
| 848 | // gesture-based launchers may interpret swipe-up as "recent apps" instead of |
| 849 | // "home" so we accept both here |
| 850 | if (SYSTEM_DIALOG_REASON_HOME_KEY.equals(reason) |
| 851 | || SYSTEM_DIALOG_REASON_RECENTAPPS_KEY.equals(reason)) { |
Jordan Liu | 468951a | 2020-08-21 09:16:23 -0700 | [diff] [blame] | 852 | Message message = mServiceHandler.obtainMessage(OP_HOME_KEY_PRESSED); |
Anna Suzuki | b1cee23 | 2019-02-21 12:52:27 +0900 | [diff] [blame] | 853 | mServiceHandler.sendMessage(message); |
Takanori Nakano | 43dacc0 | 2018-07-26 11:27:39 +0900 | [diff] [blame] | 854 | } |
Anna Suzuki | b1cee23 | 2019-02-21 12:52:27 +0900 | [diff] [blame] | 855 | } |
| 856 | }; |
| 857 | CatLog.d(LOG_TAG, "Started to observe home key event"); |
| 858 | registerReceiver(mHomeKeyEventReceiver, |
| 859 | new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); |
| 860 | } |
| 861 | |
| 862 | private synchronized void unregisterHomeKeyEventReceiver() { |
| 863 | if (mHomeKeyEventReceiver != null) { |
| 864 | CatLog.d(LOG_TAG, "Stopped to observe home key event"); |
| 865 | unregisterReceiver(mHomeKeyEventReceiver); |
| 866 | mHomeKeyEventReceiver = null; |
| 867 | } |
| 868 | if (mServiceHandler != null) { |
| 869 | mServiceHandler.removeMessages(OP_HOME_KEY_PRESSED); |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | private void handleHomeKeyPressed(int slotId) { |
| 874 | // It might be hard for user to recognize that the dialog or screens belong to SIM Toolkit |
| 875 | // application if the current session was not initiated by user but by the SIM card, |
| 876 | // so it is recommended to send TERMINAL RESPONSE if user press the home key. |
| 877 | if (!mStkContext[slotId].mIsSessionFromUser) { |
| 878 | Activity dialog = mStkContext[slotId].getPendingDialogInstance(); |
| 879 | Activity activity = mStkContext[slotId].getPendingActivityInstance(); |
| 880 | if (dialog != null) { |
| 881 | dialog.finish(); |
| 882 | mStkContext[slotId].mDialogInstance = null; |
| 883 | } else if (activity != null) { |
| 884 | activity.finish(); |
| 885 | mStkContext[slotId].mActivityInstance = null; |
Takanori Nakano | 43dacc0 | 2018-07-26 11:27:39 +0900 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | } |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 889 | |
Takanori Nakano | 43dacc0 | 2018-07-26 11:27:39 +0900 | [diff] [blame] | 890 | private void handleIdleScreen(int slotId) { |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 891 | // If the idle screen event is present in the list need to send the |
| 892 | // response to SIM. |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 893 | CatLog.d(LOG_TAG, "Need to send IDLE SCREEN Available event to SIM"); |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 894 | checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId); |
| 895 | |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 896 | if (mStkContext[slotId].mIdleModeTextCmd != null |
| 897 | && !mStkContext[slotId].mIdleModeTextVisible) { |
| 898 | launchIdleText(slotId); |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 899 | } |
| 900 | } |
| 901 | |
| 902 | private void sendScreenBusyResponse(int slotId) { |
| 903 | if (mStkContext[slotId].mCurrentCmd == null) { |
| 904 | return; |
| 905 | } |
| 906 | CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd); |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 907 | CatLog.d(LOG_TAG, "SCREEN_BUSY"); |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 908 | resMsg.setResultCode(ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS); |
| 909 | mStkService[slotId].onCmdResponse(resMsg); |
| 910 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 911 | callDelayedMsg(slotId); |
| 912 | } else { |
| 913 | mStkContext[slotId].mCmdInProgress = false; |
| 914 | } |
| 915 | } |
| 916 | |
Takanori Nakano | 43dacc0 | 2018-07-26 11:27:39 +0900 | [diff] [blame] | 917 | /** |
| 918 | * Sends TERMINAL RESPONSE or ENVELOPE |
| 919 | * |
| 920 | * @param args detailed parameters of the response |
| 921 | * @param slotId slot identifier |
| 922 | */ |
| 923 | public void sendResponse(Bundle args, int slotId) { |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 924 | Message msg = mServiceHandler.obtainMessage(OP_RESPONSE, 0, slotId, args); |
Takanori Nakano | 43dacc0 | 2018-07-26 11:27:39 +0900 | [diff] [blame] | 925 | mServiceHandler.sendMessage(msg); |
| 926 | } |
| 927 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 928 | private void sendResponse(int resId, int slotId, boolean confirm) { |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 929 | Bundle args = new Bundle(); |
| 930 | args.putInt(StkAppService.RES_ID, resId); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 931 | args.putBoolean(StkAppService.CONFIRMATION, confirm); |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 932 | sendResponse(args, slotId); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 933 | } |
| 934 | |
Takanori Nakano | b82c875 | 2019-04-01 14:47:07 +0900 | [diff] [blame] | 935 | private void terminateTone(int slotId) { |
| 936 | Message msg = new Message(); |
| 937 | msg.what = OP_STOP_TONE; |
| 938 | msg.obj = mServiceHandler.hasMessages(OP_STOP_TONE, PLAY_TONE_WITH_DIALOG) |
| 939 | ? PLAY_TONE_WITH_DIALOG : PLAY_TONE_ONLY; |
| 940 | handleStopTone(msg, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 941 | } |
| 942 | |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 943 | private boolean isCmdInteractive(CatCmdMessage cmd) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 944 | switch (cmd.getCmdType()) { |
| 945 | case SEND_DTMF: |
| 946 | case SEND_SMS: |
Yoshiaki.Naka | 7f74e02 | 2017-11-25 16:42:39 +0900 | [diff] [blame] | 947 | case REFRESH: |
Avinash Nalluri | e471813 | 2017-10-18 16:20:49 -0700 | [diff] [blame] | 948 | case RUN_AT: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 949 | case SEND_SS: |
| 950 | case SEND_USSD: |
| 951 | case SET_UP_IDLE_MODE_TEXT: |
| 952 | case SET_UP_MENU: |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 953 | case CLOSE_CHANNEL: |
| 954 | case RECEIVE_DATA: |
| 955 | case SEND_DATA: |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 956 | case SET_UP_EVENT_LIST: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 957 | return false; |
| 958 | } |
| 959 | |
| 960 | return true; |
| 961 | } |
| 962 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 963 | private void handleDelayedCmd(int slotId) { |
| 964 | CatLog.d(LOG_TAG, "handleDelayedCmd, slotId: " + slotId); |
| 965 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 966 | DelayedCmd cmd = mStkContext[slotId].mCmdsQ.poll(); |
| 967 | if (cmd != null) { |
| 968 | CatLog.d(LOG_TAG, "handleDelayedCmd - queue size: " + |
| 969 | mStkContext[slotId].mCmdsQ.size() + |
| 970 | " id: " + cmd.id + "sim id: " + cmd.slotId); |
| 971 | switch (cmd.id) { |
| 972 | case OP_CMD: |
| 973 | handleCmd(cmd.msg, cmd.slotId); |
| 974 | break; |
| 975 | case OP_END_SESSION: |
| 976 | handleSessionEnd(cmd.slotId); |
| 977 | break; |
| 978 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | } |
| 982 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 983 | private void callDelayedMsg(int slotId) { |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 984 | Message msg = mServiceHandler.obtainMessage(OP_DELAYED_MSG, 0, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 985 | mServiceHandler.sendMessage(msg); |
| 986 | } |
| 987 | |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 988 | private void callSetActivityInstMsg(int opcode, int slotId, Object obj) { |
| 989 | Message msg = mServiceHandler.obtainMessage(opcode, 0, slotId, obj); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 990 | mServiceHandler.sendMessage(msg); |
| 991 | } |
| 992 | |
| 993 | private void handleSessionEnd(int slotId) { |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 994 | // We should finish all pending activity if receiving END SESSION command. |
| 995 | cleanUpInstanceStackBySlot(slotId); |
| 996 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 997 | mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd; |
| 998 | CatLog.d(LOG_TAG, "[handleSessionEnd] - mCurrentCmd changed to mMainCmd!."); |
| 999 | mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mMainCmd; |
| 1000 | CatLog.d(LOG_TAG, "slotId: " + slotId + ", mMenuState: " + |
| 1001 | mStkContext[slotId].mMenuState); |
| 1002 | |
| 1003 | mStkContext[slotId].mIsInputPending = false; |
| 1004 | mStkContext[slotId].mIsMenuPending = false; |
| 1005 | mStkContext[slotId].mIsDialogPending = false; |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 1006 | mStkContext[slotId].mNoResponseFromUser = false; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1007 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1008 | if (mStkContext[slotId].mMainCmd == null) { |
| 1009 | CatLog.d(LOG_TAG, "[handleSessionEnd][mMainCmd is null!]"); |
| 1010 | } |
| 1011 | mStkContext[slotId].lastSelectedItem = null; |
Takanori Nakano | 43dacc0 | 2018-07-26 11:27:39 +0900 | [diff] [blame] | 1012 | mStkContext[slotId].mIsSessionFromUser = false; |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 1013 | // In case of SET UP MENU command which removed the app, don't |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1014 | // update the current menu member. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1015 | if (mStkContext[slotId].mCurrentMenu != null && mStkContext[slotId].mMainCmd != null) { |
| 1016 | mStkContext[slotId].mCurrentMenu = mStkContext[slotId].mMainCmd.getMenu(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1017 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1018 | CatLog.d(LOG_TAG, "[handleSessionEnd][mMenuState]" + mStkContext[slotId].mMenuIsVisible); |
Ryuto Sawada | 08c821c | 2016-08-08 18:29:02 +0900 | [diff] [blame] | 1019 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1020 | if (StkMenuActivity.STATE_SECONDARY == mStkContext[slotId].mMenuState) { |
Ryuto Sawada | 08c821c | 2016-08-08 18:29:02 +0900 | [diff] [blame] | 1021 | mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1022 | } |
Takanori Nakano | 3776e2c | 2016-10-14 16:54:28 +0900 | [diff] [blame] | 1023 | |
| 1024 | // Send a local broadcast as a notice that this service handled the session end event. |
| 1025 | Intent intent = new Intent(SESSION_ENDED); |
| 1026 | intent.putExtra(SLOT_ID, slotId); |
| 1027 | LocalBroadcastManager.getInstance(this).sendBroadcast(intent); |
| 1028 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1029 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 1030 | callDelayedMsg(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1031 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1032 | mStkContext[slotId].mCmdInProgress = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1033 | } |
| 1034 | // In case a launch browser command was just confirmed, launch that url. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1035 | if (mStkContext[slotId].launchBrowser) { |
| 1036 | mStkContext[slotId].launchBrowser = false; |
| 1037 | launchBrowser(mStkContext[slotId].mBrowserSettings); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1038 | } |
| 1039 | } |
| 1040 | |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1041 | // returns true if any Stk related activity already has focus on the screen |
Yoshiaki Naka | cec55b8 | 2017-10-20 15:53:43 +0900 | [diff] [blame] | 1042 | boolean isTopOfStack() { |
pkanwar | eab12f3 | 2017-02-06 08:35:03 -0800 | [diff] [blame] | 1043 | ActivityManager mActivityManager = (ActivityManager) mContext |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1044 | .getSystemService(ACTIVITY_SERVICE); |
pkanwar | eab12f3 | 2017-02-06 08:35:03 -0800 | [diff] [blame] | 1045 | String currentPackageName = null; |
| 1046 | List<RunningTaskInfo> tasks = mActivityManager.getRunningTasks(1); |
| 1047 | if (tasks == null || tasks.get(0).topActivity == null) { |
| 1048 | return false; |
| 1049 | } |
| 1050 | currentPackageName = tasks.get(0).topActivity.getPackageName(); |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1051 | if (null != currentPackageName) { |
| 1052 | return currentPackageName.equals(PACKAGE_NAME); |
| 1053 | } |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1054 | return false; |
| 1055 | } |
| 1056 | |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 1057 | /** |
| 1058 | * Get the boolean config from carrier config manager. |
| 1059 | * |
Yukiko Fujimura | 913c143 | 2019-02-21 17:14:30 +0900 | [diff] [blame] | 1060 | * @param context the context to get carrier service |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 1061 | * @param key config key defined in CarrierConfigManager |
Yoshiaki Naka | 028bb09 | 2018-08-30 16:57:47 +0900 | [diff] [blame] | 1062 | * @param slotId slot ID. |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 1063 | * @return boolean value of corresponding key. |
| 1064 | */ |
Yukiko Fujimura | 913c143 | 2019-02-21 17:14:30 +0900 | [diff] [blame] | 1065 | /* package */ static boolean getBooleanCarrierConfig(Context context, String key, int slotId) { |
| 1066 | CarrierConfigManager ccm = (CarrierConfigManager) context.getSystemService( |
| 1067 | Context.CARRIER_CONFIG_SERVICE); |
| 1068 | SubscriptionManager sm = (SubscriptionManager) context.getSystemService( |
Yoshiaki Naka | 30d5a81 | 2018-11-12 12:43:34 +0900 | [diff] [blame] | 1069 | Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 1070 | PersistableBundle b = null; |
Yoshiaki Naka | 30d5a81 | 2018-11-12 12:43:34 +0900 | [diff] [blame] | 1071 | if (ccm != null && sm != null) { |
| 1072 | SubscriptionInfo info = sm.getActiveSubscriptionInfoForSimSlotIndex(slotId); |
| 1073 | if (info != null) { |
| 1074 | b = ccm.getConfigForSubId(info.getSubscriptionId()); |
| 1075 | } |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 1076 | } |
| 1077 | if (b != null) { |
| 1078 | return b.getBoolean(key); |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 1079 | } |
Yoshiaki Naka | 028bb09 | 2018-08-30 16:57:47 +0900 | [diff] [blame] | 1080 | // Return static default defined in CarrierConfigManager. |
| 1081 | return CarrierConfigManager.getDefaultConfig().getBoolean(key); |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
Yukiko Fujimura | 913c143 | 2019-02-21 17:14:30 +0900 | [diff] [blame] | 1084 | private boolean getBooleanCarrierConfig(String key, int slotId) { |
| 1085 | return getBooleanCarrierConfig(this, key, slotId); |
| 1086 | } |
| 1087 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1088 | private void handleCmd(CatCmdMessage cmdMsg, int slotId) { |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1089 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1090 | if (cmdMsg == null) { |
| 1091 | return; |
| 1092 | } |
| 1093 | // save local reference for state tracking. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1094 | mStkContext[slotId].mCurrentCmd = cmdMsg; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1095 | boolean waitForUsersResponse = true; |
| 1096 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1097 | mStkContext[slotId].mIsInputPending = false; |
| 1098 | mStkContext[slotId].mIsMenuPending = false; |
| 1099 | mStkContext[slotId].mIsDialogPending = false; |
| 1100 | |
| 1101 | CatLog.d(LOG_TAG,"[handleCmd]" + cmdMsg.getCmdType().name()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1102 | switch (cmdMsg.getCmdType()) { |
| 1103 | case DISPLAY_TEXT: |
| 1104 | TextMessage msg = cmdMsg.geTextMessage(); |
Jeevaka Badrappan | 854a25c | 2012-12-01 16:32:03 +0200 | [diff] [blame] | 1105 | waitForUsersResponse = msg.responseNeeded; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1106 | //If we receive a low priority Display Text and the device is |
| 1107 | // not displaying any STK related activity and the screen is not idle |
| 1108 | // ( that is, device is in an interactive state), then send a screen busy |
| 1109 | // terminal response. Otherwise display the message. The existing |
| 1110 | // displayed message shall be updated with the new display text |
| 1111 | // proactive command (Refer to ETSI TS 102 384 section 27.22.4.1.4.4.2). |
| 1112 | if (!(msg.isHighPriority || mStkContext[slotId].mMenuIsVisible |
| 1113 | || mStkContext[slotId].mDisplayTextDlgIsVisibile || isTopOfStack())) { |
| 1114 | if(!isScreenIdle()) { |
| 1115 | CatLog.d(LOG_TAG, "Screen is not idle"); |
| 1116 | sendScreenBusyResponse(slotId); |
| 1117 | } else { |
| 1118 | launchTextDialog(slotId); |
| 1119 | } |
| 1120 | } else { |
| 1121 | launchTextDialog(slotId); |
| 1122 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1123 | break; |
| 1124 | case SELECT_ITEM: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1125 | CatLog.d(LOG_TAG, "SELECT_ITEM +"); |
| 1126 | mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd; |
| 1127 | mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu(); |
| 1128 | launchMenuActivity(cmdMsg.getMenu(), slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1129 | break; |
| 1130 | case SET_UP_MENU: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1131 | mStkContext[slotId].mCmdInProgress = false; |
| 1132 | mStkContext[slotId].mMainCmd = mStkContext[slotId].mCurrentCmd; |
| 1133 | mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd; |
| 1134 | mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu(); |
| 1135 | CatLog.d(LOG_TAG, "SET_UP_MENU [" + removeMenu(slotId) + "]"); |
| 1136 | |
| 1137 | if (removeMenu(slotId)) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1138 | mStkContext[slotId].mCurrentMenu = null; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1139 | mStkContext[slotId].mMainCmd = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1140 | //Check other setup menu state. If all setup menu are removed, uninstall apk. |
Yoshiaki Naka | 58e0765 | 2019-04-26 17:58:52 +0900 | [diff] [blame] | 1141 | if (!uninstallIfUnnecessary()) { |
Yoshiaki Naka | 835e300 | 2020-05-11 18:15:12 +0900 | [diff] [blame] | 1142 | addToMenuSystemOrUpdateLabel(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1143 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1144 | } else { |
Yoshiaki Naka | 835e300 | 2020-05-11 18:15:12 +0900 | [diff] [blame] | 1145 | addToMenuSystemOrUpdateLabel(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1146 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1147 | if (mStkContext[slotId].mMenuIsVisible) { |
| 1148 | launchMenuActivity(null, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1149 | } |
| 1150 | break; |
| 1151 | case GET_INPUT: |
| 1152 | case GET_INKEY: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1153 | launchInputActivity(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1154 | break; |
| 1155 | case SET_UP_IDLE_MODE_TEXT: |
| 1156 | waitForUsersResponse = false; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1157 | mStkContext[slotId].mIdleModeTextCmd = mStkContext[slotId].mCurrentCmd; |
| 1158 | TextMessage idleModeText = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1159 | if (idleModeText == null || TextUtils.isEmpty(idleModeText.text)) { |
| 1160 | cancelIdleText(slotId); |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1161 | } |
| 1162 | mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd; |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1163 | if (mStkContext[slotId].mIdleModeTextCmd != null) { |
| 1164 | if (mStkContext[slotId].mIdleModeTextVisible || isScreenIdle()) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 1165 | CatLog.d(LOG_TAG, "set up idle mode"); |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1166 | launchIdleText(slotId); |
| 1167 | } else { |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 1168 | registerHomeVisibilityObserver(); |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1169 | } |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1170 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1171 | break; |
| 1172 | case SEND_DTMF: |
| 1173 | case SEND_SMS: |
Avinash Nalluri | e471813 | 2017-10-18 16:20:49 -0700 | [diff] [blame] | 1174 | case RUN_AT: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1175 | case SEND_SS: |
| 1176 | case SEND_USSD: |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1177 | case GET_CHANNEL_STATUS: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1178 | waitForUsersResponse = false; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1179 | launchEventMessage(slotId); |
Umashankar Godachi | d3598a2 | 2018-03-01 02:20:28 +0530 | [diff] [blame] | 1180 | //Reset the mCurrentCmd to mMainCmd, to avoid wrong TR sent for |
| 1181 | //SEND_SMS/SS/USSD, when user launches STK app next time and do |
| 1182 | //a menu selection. |
| 1183 | mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1184 | break; |
Preeti Ahuja | 809fc5d | 2013-04-12 18:54:54 +0530 | [diff] [blame] | 1185 | case REFRESH: |
| 1186 | waitForUsersResponse = false; |
| 1187 | launchEventMessage(slotId); |
| 1188 | // Idle mode text needs to be cleared for init or reset modes of refresh |
| 1189 | if (cmdMsg.isRefreshResetOrInit()) { |
| 1190 | mNotificationManager.cancel(getNotificationId(slotId)); |
| 1191 | mStkContext[slotId].mIdleModeTextCmd = null; |
| 1192 | CatLog.d(this, "Clean idle mode text due to refresh"); |
| 1193 | } |
| 1194 | break; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1195 | case LAUNCH_BROWSER: |
Ryuto Sawada | 0bdc719 | 2016-04-18 12:10:56 +0900 | [diff] [blame] | 1196 | // The device setup process should not be interrupted by launching browser. |
| 1197 | if (Settings.Global.getInt(mContext.getContentResolver(), |
| 1198 | Settings.Global.DEVICE_PROVISIONED, 0) == 0) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 1199 | CatLog.d(LOG_TAG, "Not perform if the setup process has not been completed."); |
Ryuto Sawada | 0bdc719 | 2016-04-18 12:10:56 +0900 | [diff] [blame] | 1200 | sendScreenBusyResponse(slotId); |
| 1201 | break; |
| 1202 | } |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 1203 | |
| 1204 | /* Check if Carrier would not want to launch browser */ |
Yoshiaki Naka | 028bb09 | 2018-08-30 16:57:47 +0900 | [diff] [blame] | 1205 | if (getBooleanCarrierConfig(CarrierConfigManager.KEY_STK_DISABLE_LAUNCH_BROWSER_BOOL, |
| 1206 | slotId)) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 1207 | CatLog.d(LOG_TAG, "Browser is not launched as per carrier."); |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 1208 | sendResponse(RES_ID_DONE, slotId, true); |
| 1209 | break; |
| 1210 | } |
| 1211 | |
Srikanth Chintala | ba10300 | 2015-11-30 10:49:52 -0800 | [diff] [blame] | 1212 | mStkContext[slotId].mBrowserSettings = |
| 1213 | mStkContext[slotId].mCurrentCmd.getBrowserSettings(); |
| 1214 | if (!isUrlAvailableToLaunchBrowser(mStkContext[slotId].mBrowserSettings)) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 1215 | CatLog.d(LOG_TAG, "Browser url property is not set - send error"); |
Srikanth Chintala | ba10300 | 2015-11-30 10:49:52 -0800 | [diff] [blame] | 1216 | sendResponse(RES_ID_ERROR, slotId, true); |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 1217 | } else { |
Srikanth Chintala | ba10300 | 2015-11-30 10:49:52 -0800 | [diff] [blame] | 1218 | TextMessage alphaId = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
| 1219 | if ((alphaId == null) || TextUtils.isEmpty(alphaId.text)) { |
| 1220 | // don't need user confirmation in this case |
| 1221 | // just launch the browser or spawn a new tab |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 1222 | CatLog.d(LOG_TAG, "user confirmation is not currently needed.\n" + |
Srikanth Chintala | ba10300 | 2015-11-30 10:49:52 -0800 | [diff] [blame] | 1223 | "supressing confirmation dialogue and confirming silently..."); |
| 1224 | mStkContext[slotId].launchBrowser = true; |
| 1225 | sendResponse(RES_ID_CONFIRM, slotId, true); |
| 1226 | } else { |
| 1227 | launchConfirmationDialog(alphaId, slotId); |
| 1228 | } |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 1229 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1230 | break; |
| 1231 | case SET_UP_CALL: |
Preeti Ahuja | dd24010 | 2013-08-30 17:25:06 -0700 | [diff] [blame] | 1232 | TextMessage mesg = mStkContext[slotId].mCurrentCmd.getCallSettings().confirmMsg; |
| 1233 | if((mesg != null) && (mesg.text == null || mesg.text.length() == 0)) { |
| 1234 | mesg.text = getResources().getString(R.string.default_setup_call_msg); |
| 1235 | } |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 1236 | CatLog.d(LOG_TAG, "SET_UP_CALL mesg.text " + mesg.text); |
Preeti Ahuja | dd24010 | 2013-08-30 17:25:06 -0700 | [diff] [blame] | 1237 | launchConfirmationDialog(mesg, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1238 | break; |
| 1239 | case PLAY_TONE: |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 1240 | handlePlayTone(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1241 | break; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1242 | case OPEN_CHANNEL: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1243 | launchOpenChannelDialog(slotId); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1244 | break; |
| 1245 | case CLOSE_CHANNEL: |
| 1246 | case RECEIVE_DATA: |
| 1247 | case SEND_DATA: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1248 | TextMessage m = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1249 | |
| 1250 | if ((m != null) && (m.text == null)) { |
| 1251 | switch(cmdMsg.getCmdType()) { |
| 1252 | case CLOSE_CHANNEL: |
| 1253 | m.text = getResources().getString(R.string.default_close_channel_msg); |
| 1254 | break; |
| 1255 | case RECEIVE_DATA: |
| 1256 | m.text = getResources().getString(R.string.default_receive_data_msg); |
| 1257 | break; |
| 1258 | case SEND_DATA: |
| 1259 | m.text = getResources().getString(R.string.default_send_data_msg); |
| 1260 | break; |
| 1261 | } |
| 1262 | } |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1263 | /* |
| 1264 | * Display indication in the form of a toast to the user if required. |
| 1265 | */ |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1266 | launchEventMessage(slotId); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1267 | break; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1268 | case SET_UP_EVENT_LIST: |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1269 | replaceEventList(slotId); |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1270 | if (isScreenIdle()) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 1271 | CatLog.d(LOG_TAG," Check if IDLE_SCREEN_AVAILABLE_EVENT is present in List"); |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1272 | checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId); |
| 1273 | } |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1274 | break; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | if (!waitForUsersResponse) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1278 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 1279 | callDelayedMsg(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1280 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1281 | mStkContext[slotId].mCmdInProgress = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | |
Yoshiaki Naka | 835e300 | 2020-05-11 18:15:12 +0900 | [diff] [blame] | 1286 | private void addToMenuSystemOrUpdateLabel() { |
| 1287 | String candidateLabel = null; |
| 1288 | |
| 1289 | for (int slotId = 0; slotId < mSimCount; slotId++) { |
| 1290 | Menu menu = getMainMenu(slotId); |
| 1291 | if (menu != null) { |
| 1292 | if (!TextUtils.isEmpty(candidateLabel)) { |
| 1293 | if (!TextUtils.equals(menu.title, candidateLabel)) { |
| 1294 | // We should not display the alpha identifier of SET-UP MENU command |
| 1295 | // as the application label on the application launcher |
| 1296 | // if different alpha identifiers are provided by multiple SIMs. |
| 1297 | candidateLabel = null; |
| 1298 | break; |
| 1299 | } |
| 1300 | } else { |
| 1301 | if (TextUtils.isEmpty(menu.title)) { |
| 1302 | break; |
| 1303 | } |
| 1304 | candidateLabel = menu.title; |
| 1305 | } |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | StkAppInstaller.installOrUpdate(this, candidateLabel); |
| 1310 | } |
| 1311 | |
Takanori Nakano | 43dacc0 | 2018-07-26 11:27:39 +0900 | [diff] [blame] | 1312 | @SuppressWarnings("FallThrough") |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1313 | private void handleCmdResponse(Bundle args, int slotId) { |
| 1314 | CatLog.d(LOG_TAG, "handleCmdResponse, sim id: " + slotId); |
Anna Suzuki | b1cee23 | 2019-02-21 12:52:27 +0900 | [diff] [blame] | 1315 | unregisterHomeKeyEventReceiver(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1316 | if (mStkContext[slotId].mCurrentCmd == null) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1317 | return; |
| 1318 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1319 | |
| 1320 | if (mStkService[slotId] == null) { |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 1321 | mStkService[slotId] = CatService.getInstance(slotId); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1322 | if (mStkService[slotId] == null) { |
Takanori Nakano | eeed5db | 2019-04-08 12:21:29 +0900 | [diff] [blame] | 1323 | // CatService is disposed when the relevant SIM is removed or disabled. |
| 1324 | // StkAppService can also be stopped when the absent state is notified, |
| 1325 | // so this situation can happen. |
| 1326 | CatLog.d(LOG_TAG, "No response is sent back to the missing CatService."); |
| 1327 | return; |
Alex Yakavenka | d8e2ecd | 2012-04-20 17:10:15 -0700 | [diff] [blame] | 1328 | } |
| 1329 | } |
| 1330 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1331 | CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1332 | |
| 1333 | // set result code |
| 1334 | boolean helpRequired = args.getBoolean(HELP, false); |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1335 | boolean confirmed = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1336 | |
| 1337 | switch(args.getInt(RES_ID)) { |
| 1338 | case RES_ID_MENU_SELECTION: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1339 | CatLog.d(LOG_TAG, "MENU_SELECTION=" + mStkContext[slotId]. |
| 1340 | mCurrentMenuCmd.getCmdType()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1341 | int menuSelection = args.getInt(MENU_SELECTION); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1342 | switch(mStkContext[slotId].mCurrentMenuCmd.getCmdType()) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1343 | case SET_UP_MENU: |
Takanori Nakano | 43dacc0 | 2018-07-26 11:27:39 +0900 | [diff] [blame] | 1344 | mStkContext[slotId].mIsSessionFromUser = true; |
| 1345 | // Fall through |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1346 | case SELECT_ITEM: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1347 | mStkContext[slotId].lastSelectedItem = getItemName(menuSelection, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1348 | if (helpRequired) { |
| 1349 | resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED); |
| 1350 | } else { |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 1351 | resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ? |
| 1352 | ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1353 | } |
| 1354 | resMsg.setMenuSelection(menuSelection); |
| 1355 | break; |
| 1356 | } |
| 1357 | break; |
| 1358 | case RES_ID_INPUT: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1359 | CatLog.d(LOG_TAG, "RES_ID_INPUT"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1360 | String input = args.getString(INPUT); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1361 | if (input != null && (null != mStkContext[slotId].mCurrentCmd.geInput()) && |
| 1362 | (mStkContext[slotId].mCurrentCmd.geInput().yesNo)) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1363 | boolean yesNoSelection = input |
| 1364 | .equals(StkInputActivity.YES_STR_RESPONSE); |
| 1365 | resMsg.setYesNo(yesNoSelection); |
| 1366 | } else { |
| 1367 | if (helpRequired) { |
| 1368 | resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED); |
| 1369 | } else { |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 1370 | resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ? |
| 1371 | ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1372 | resMsg.setInput(input); |
| 1373 | } |
| 1374 | } |
| 1375 | break; |
| 1376 | case RES_ID_CONFIRM: |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 1377 | CatLog.d(LOG_TAG, "RES_ID_CONFIRM"); |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1378 | confirmed = args.getBoolean(CONFIRMATION); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1379 | switch (mStkContext[slotId].mCurrentCmd.getCmdType()) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1380 | case DISPLAY_TEXT: |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 1381 | if (confirmed) { |
| 1382 | resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ? |
| 1383 | ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK); |
| 1384 | } else { |
| 1385 | resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER); |
| 1386 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1387 | break; |
| 1388 | case LAUNCH_BROWSER: |
| 1389 | resMsg.setResultCode(confirmed ? ResultCode.OK |
| 1390 | : ResultCode.UICC_SESSION_TERM_BY_USER); |
| 1391 | if (confirmed) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1392 | mStkContext[slotId].launchBrowser = true; |
| 1393 | mStkContext[slotId].mBrowserSettings = |
| 1394 | mStkContext[slotId].mCurrentCmd.getBrowserSettings(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1395 | } |
| 1396 | break; |
| 1397 | case SET_UP_CALL: |
| 1398 | resMsg.setResultCode(ResultCode.OK); |
| 1399 | resMsg.setConfirmation(confirmed); |
| 1400 | if (confirmed) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1401 | launchEventMessage(slotId, |
| 1402 | mStkContext[slotId].mCurrentCmd.getCallSettings().callMsg); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1403 | } |
| 1404 | break; |
| 1405 | } |
| 1406 | break; |
| 1407 | case RES_ID_DONE: |
| 1408 | resMsg.setResultCode(ResultCode.OK); |
| 1409 | break; |
| 1410 | case RES_ID_BACKWARD: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1411 | CatLog.d(LOG_TAG, "RES_ID_BACKWARD"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1412 | resMsg.setResultCode(ResultCode.BACKWARD_MOVE_BY_USER); |
| 1413 | break; |
| 1414 | case RES_ID_END_SESSION: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1415 | CatLog.d(LOG_TAG, "RES_ID_END_SESSION"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1416 | resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER); |
| 1417 | break; |
| 1418 | case RES_ID_TIMEOUT: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1419 | CatLog.d(LOG_TAG, "RES_ID_TIMEOUT"); |
Naveen Kalla | d517689 | 2009-11-30 12:45:29 -0800 | [diff] [blame] | 1420 | // GCF test-case 27.22.4.1.1 Expected Sequence 1.5 (DISPLAY TEXT, |
| 1421 | // Clear message after delay, successful) expects result code OK. |
| 1422 | // If the command qualifier specifies no user response is required |
| 1423 | // then send OK instead of NO_RESPONSE_FROM_USER |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1424 | if ((mStkContext[slotId].mCurrentCmd.getCmdType().value() == |
| 1425 | AppInterface.CommandType.DISPLAY_TEXT.value()) |
| 1426 | && (mStkContext[slotId].mCurrentCmd.geTextMessage().userClear == false)) { |
Naveen Kalla | d517689 | 2009-11-30 12:45:29 -0800 | [diff] [blame] | 1427 | resMsg.setResultCode(ResultCode.OK); |
| 1428 | } else { |
| 1429 | resMsg.setResultCode(ResultCode.NO_RESPONSE_FROM_USER); |
| 1430 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1431 | break; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1432 | case RES_ID_CHOICE: |
| 1433 | int choice = args.getInt(CHOICE); |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 1434 | CatLog.d(LOG_TAG, "User Choice=" + choice); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1435 | switch (choice) { |
| 1436 | case YES: |
| 1437 | resMsg.setResultCode(ResultCode.OK); |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1438 | confirmed = true; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1439 | break; |
| 1440 | case NO: |
| 1441 | resMsg.setResultCode(ResultCode.USER_NOT_ACCEPT); |
| 1442 | break; |
| 1443 | } |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1444 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1445 | if (mStkContext[slotId].mCurrentCmd.getCmdType().value() == |
| 1446 | AppInterface.CommandType.OPEN_CHANNEL.value()) { |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1447 | resMsg.setConfirmation(confirmed); |
| 1448 | } |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1449 | break; |
Srikanth Chintala | ba10300 | 2015-11-30 10:49:52 -0800 | [diff] [blame] | 1450 | case RES_ID_ERROR: |
| 1451 | CatLog.d(LOG_TAG, "RES_ID_ERROR"); |
| 1452 | switch (mStkContext[slotId].mCurrentCmd.getCmdType()) { |
| 1453 | case LAUNCH_BROWSER: |
| 1454 | resMsg.setResultCode(ResultCode.LAUNCH_BROWSER_ERROR); |
| 1455 | break; |
| 1456 | } |
| 1457 | break; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1458 | default: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1459 | CatLog.d(LOG_TAG, "Unknown result id"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1460 | return; |
| 1461 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1462 | |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 1463 | switch (args.getInt(RES_ID)) { |
| 1464 | case RES_ID_MENU_SELECTION: |
| 1465 | case RES_ID_INPUT: |
| 1466 | case RES_ID_CONFIRM: |
| 1467 | case RES_ID_CHOICE: |
| 1468 | case RES_ID_BACKWARD: |
| 1469 | case RES_ID_END_SESSION: |
| 1470 | mStkContext[slotId].mNoResponseFromUser = false; |
| 1471 | break; |
| 1472 | case RES_ID_TIMEOUT: |
| 1473 | cancelNotificationOnKeyguard(slotId); |
| 1474 | mStkContext[slotId].mNoResponseFromUser = true; |
| 1475 | break; |
| 1476 | default: |
| 1477 | // The other IDs cannot be used to judge if there is no response from user. |
| 1478 | break; |
| 1479 | } |
| 1480 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1481 | if (null != mStkContext[slotId].mCurrentCmd && |
| 1482 | null != mStkContext[slotId].mCurrentCmd.getCmdType()) { |
| 1483 | CatLog.d(LOG_TAG, "handleCmdResponse- cmdName[" + |
| 1484 | mStkContext[slotId].mCurrentCmd.getCmdType().name() + "]"); |
| 1485 | } |
| 1486 | mStkService[slotId].onCmdResponse(resMsg); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | /** |
| 1490 | * Returns 0 or FLAG_ACTIVITY_NO_USER_ACTION, 0 means the user initiated the action. |
| 1491 | * |
| 1492 | * @param userAction If the userAction is yes then we always return 0 otherwise |
| 1493 | * mMenuIsVisible is used to determine what to return. If mMenuIsVisible is true |
| 1494 | * then we are the foreground app and we'll return 0 as from our perspective a |
| 1495 | * user action did cause. If it's false than we aren't the foreground app and |
| 1496 | * FLAG_ACTIVITY_NO_USER_ACTION is returned. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 1497 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1498 | * @return 0 or FLAG_ACTIVITY_NO_USER_ACTION |
| 1499 | */ |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1500 | private int getFlagActivityNoUserAction(InitiatedByUserAction userAction, int slotId) { |
| 1501 | return ((userAction == InitiatedByUserAction.yes) | mStkContext[slotId].mMenuIsVisible) |
| 1502 | ? 0 : Intent.FLAG_ACTIVITY_NO_USER_ACTION; |
| 1503 | } |
| 1504 | /** |
| 1505 | * This method is used for cleaning up pending instances in stack. |
Takanori Nakano | 28ce8b6 | 2018-02-22 12:10:44 +0900 | [diff] [blame] | 1506 | * No terminal response will be sent for pending instances. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1507 | */ |
| 1508 | private void cleanUpInstanceStackBySlot(int slotId) { |
| 1509 | Activity activity = mStkContext[slotId].getPendingActivityInstance(); |
| 1510 | Activity dialog = mStkContext[slotId].getPendingDialogInstance(); |
| 1511 | CatLog.d(LOG_TAG, "cleanUpInstanceStackBySlot slotId: " + slotId); |
| 1512 | if (activity != null) { |
Takanori Nakano | 28ce8b6 | 2018-02-22 12:10:44 +0900 | [diff] [blame] | 1513 | if (mStkContext[slotId].mCurrentCmd != null) { |
| 1514 | CatLog.d(LOG_TAG, "current cmd type: " + |
| 1515 | mStkContext[slotId].mCurrentCmd.getCmdType()); |
| 1516 | if (mStkContext[slotId].mCurrentCmd.getCmdType().value() |
| 1517 | == AppInterface.CommandType.GET_INPUT.value() |
| 1518 | || mStkContext[slotId].mCurrentCmd.getCmdType().value() |
| 1519 | == AppInterface.CommandType.GET_INKEY.value()) { |
| 1520 | mStkContext[slotId].mIsInputPending = true; |
| 1521 | } else if (mStkContext[slotId].mCurrentCmd.getCmdType().value() |
| 1522 | == AppInterface.CommandType.SET_UP_MENU.value() |
| 1523 | || mStkContext[slotId].mCurrentCmd.getCmdType().value() |
| 1524 | == AppInterface.CommandType.SELECT_ITEM.value()) { |
| 1525 | mStkContext[slotId].mIsMenuPending = true; |
| 1526 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1527 | } |
| 1528 | CatLog.d(LOG_TAG, "finish pending activity."); |
| 1529 | activity.finish(); |
| 1530 | mStkContext[slotId].mActivityInstance = null; |
| 1531 | } |
| 1532 | if (dialog != null) { |
| 1533 | CatLog.d(LOG_TAG, "finish pending dialog."); |
| 1534 | mStkContext[slotId].mIsDialogPending = true; |
| 1535 | dialog.finish(); |
| 1536 | mStkContext[slotId].mDialogInstance = null; |
| 1537 | } |
| 1538 | } |
| 1539 | /** |
| 1540 | * This method is used for restoring pending instances from stack. |
| 1541 | */ |
| 1542 | private void restoreInstanceFromStackBySlot(int slotId) { |
| 1543 | AppInterface.CommandType cmdType = mStkContext[slotId].mCurrentCmd.getCmdType(); |
| 1544 | |
| 1545 | CatLog.d(LOG_TAG, "restoreInstanceFromStackBySlot cmdType : " + cmdType); |
| 1546 | switch(cmdType) { |
| 1547 | case GET_INPUT: |
| 1548 | case GET_INKEY: |
| 1549 | launchInputActivity(slotId); |
| 1550 | //Set mMenuIsVisible to true for showing main menu for |
| 1551 | //following session end command. |
| 1552 | mStkContext[slotId].mMenuIsVisible = true; |
| 1553 | break; |
| 1554 | case DISPLAY_TEXT: |
| 1555 | launchTextDialog(slotId); |
| 1556 | break; |
| 1557 | case LAUNCH_BROWSER: |
| 1558 | launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.geTextMessage(), |
| 1559 | slotId); |
| 1560 | break; |
| 1561 | case OPEN_CHANNEL: |
| 1562 | launchOpenChannelDialog(slotId); |
| 1563 | break; |
| 1564 | case SET_UP_CALL: |
| 1565 | launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.getCallSettings(). |
| 1566 | confirmMsg, slotId); |
| 1567 | break; |
| 1568 | case SET_UP_MENU: |
| 1569 | case SELECT_ITEM: |
| 1570 | launchMenuActivity(null, slotId); |
| 1571 | break; |
| 1572 | default: |
| 1573 | break; |
| 1574 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1575 | } |
| 1576 | |
Yoshiaki Naka | 9018313 | 2017-08-31 19:25:33 +0900 | [diff] [blame] | 1577 | @Override |
| 1578 | public void startActivity(Intent intent) { |
| 1579 | int slotId = intent.getIntExtra(SLOT_ID, SubscriptionManager.INVALID_SIM_SLOT_INDEX); |
| 1580 | // Close the dialog displayed for DISPLAY TEXT command with an immediate response object |
| 1581 | // before new dialog is displayed. |
| 1582 | if (SubscriptionManager.isValidSlotIndex(slotId)) { |
| 1583 | Activity dialog = mStkContext[slotId].getImmediateDialogInstance(); |
| 1584 | if (dialog != null) { |
| 1585 | CatLog.d(LOG_TAG, "finish dialog for immediate response."); |
| 1586 | dialog.finish(); |
| 1587 | } |
| 1588 | } |
| 1589 | super.startActivity(intent); |
| 1590 | } |
| 1591 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1592 | private void launchMenuActivity(Menu menu, int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1593 | Intent newIntent = new Intent(Intent.ACTION_VIEW); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1594 | String targetActivity = STK_MENU_ACTIVITY_NAME; |
| 1595 | String uriString = STK_MENU_URI + System.currentTimeMillis(); |
| 1596 | //Set unique URI to create a new instance of activity for different slotId. |
| 1597 | Uri uriData = Uri.parse(uriString); |
| 1598 | |
| 1599 | CatLog.d(LOG_TAG, "launchMenuActivity, slotId: " + slotId + " , " + |
| 1600 | uriData.toString() + " , " + mStkContext[slotId].mOpCode + ", " |
| 1601 | + mStkContext[slotId].mMenuState); |
| 1602 | newIntent.setClassName(PACKAGE_NAME, targetActivity); |
| 1603 | int intentFlags = Intent.FLAG_ACTIVITY_NEW_TASK; |
| 1604 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1605 | if (menu == null) { |
| 1606 | // We assume this was initiated by the user pressing the tool kit icon |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1607 | intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.yes, slotId); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1608 | //If the last pending menu is secondary menu, "STATE" should be "STATE_SECONDARY". |
| 1609 | //Otherwise, it should be "STATE_MAIN". |
| 1610 | if (mStkContext[slotId].mOpCode == OP_LAUNCH_APP && |
| 1611 | mStkContext[slotId].mMenuState == StkMenuActivity.STATE_SECONDARY) { |
| 1612 | newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY); |
| 1613 | } else { |
| 1614 | newIntent.putExtra("STATE", StkMenuActivity.STATE_MAIN); |
| 1615 | mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN; |
| 1616 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1617 | } else { |
| 1618 | // We don't know and we'll let getFlagActivityNoUserAction decide. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1619 | intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1620 | newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1621 | mStkContext[slotId].mMenuState = StkMenuActivity.STATE_SECONDARY; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1622 | } |
Anna Suzuki | 35309b0 | 2019-02-15 16:24:59 +0900 | [diff] [blame] | 1623 | if (mStkContext[slotId].mMenuState == StkMenuActivity.STATE_SECONDARY) { |
Anna Suzuki | b1cee23 | 2019-02-21 12:52:27 +0900 | [diff] [blame] | 1624 | startToObserveHomeKeyEvent(slotId); |
Anna Suzuki | 35309b0 | 2019-02-15 16:24:59 +0900 | [diff] [blame] | 1625 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1626 | newIntent.putExtra(SLOT_ID, slotId); |
| 1627 | newIntent.setData(uriData); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1628 | newIntent.setFlags(intentFlags); |
Yoshiaki Naka | 9018313 | 2017-08-31 19:25:33 +0900 | [diff] [blame] | 1629 | startActivity(newIntent); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1630 | } |
| 1631 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1632 | private void launchInputActivity(int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1633 | Intent newIntent = new Intent(Intent.ACTION_VIEW); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1634 | String targetActivity = STK_INPUT_ACTIVITY_NAME; |
| 1635 | String uriString = STK_INPUT_URI + System.currentTimeMillis(); |
| 1636 | //Set unique URI to create a new instance of activity for different slotId. |
| 1637 | Uri uriData = Uri.parse(uriString); |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 1638 | Input input = mStkContext[slotId].mCurrentCmd.geInput(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1639 | |
| 1640 | CatLog.d(LOG_TAG, "launchInputActivity, slotId: " + slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1641 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1642 | | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); |
| 1643 | newIntent.setClassName(PACKAGE_NAME, targetActivity); |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 1644 | newIntent.putExtra("INPUT", input); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1645 | newIntent.putExtra(SLOT_ID, slotId); |
| 1646 | newIntent.setData(uriData); |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 1647 | |
| 1648 | if (input != null) { |
| 1649 | notifyUserIfNecessary(slotId, input.text); |
| 1650 | } |
Yoshiaki Naka | 9018313 | 2017-08-31 19:25:33 +0900 | [diff] [blame] | 1651 | startActivity(newIntent); |
Anna Suzuki | b1cee23 | 2019-02-21 12:52:27 +0900 | [diff] [blame] | 1652 | startToObserveHomeKeyEvent(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1653 | } |
| 1654 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1655 | private void launchTextDialog(int slotId) { |
| 1656 | CatLog.d(LOG_TAG, "launchTextDialog, slotId: " + slotId); |
| 1657 | Intent newIntent = new Intent(); |
| 1658 | String targetActivity = STK_DIALOG_ACTIVITY_NAME; |
| 1659 | int action = getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId); |
| 1660 | String uriString = STK_DIALOG_URI + System.currentTimeMillis(); |
| 1661 | //Set unique URI to create a new instance of activity for different slotId. |
| 1662 | Uri uriData = Uri.parse(uriString); |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 1663 | TextMessage textMessage = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
| 1664 | |
| 1665 | newIntent.setClassName(PACKAGE_NAME, targetActivity); |
| 1666 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 1667 | | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); |
| 1668 | newIntent.setData(uriData); |
| 1669 | newIntent.putExtra("TEXT", textMessage); |
| 1670 | newIntent.putExtra(SLOT_ID, slotId); |
| 1671 | |
| 1672 | if (textMessage != null) { |
| 1673 | notifyUserIfNecessary(slotId, textMessage.text); |
| 1674 | } |
| 1675 | startActivity(newIntent); |
| 1676 | // For display texts with immediate response, send the terminal response |
| 1677 | // immediately. responseNeeded will be false, if display text command has |
| 1678 | // the immediate response tlv. |
| 1679 | if (!mStkContext[slotId].mCurrentCmd.geTextMessage().responseNeeded) { |
| 1680 | sendResponse(RES_ID_CONFIRM, slotId, true); |
Anna Suzuki | 35309b0 | 2019-02-15 16:24:59 +0900 | [diff] [blame] | 1681 | } else { |
Anna Suzuki | b1cee23 | 2019-02-21 12:52:27 +0900 | [diff] [blame] | 1682 | startToObserveHomeKeyEvent(slotId); |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 1683 | } |
| 1684 | } |
| 1685 | |
| 1686 | private void notifyUserIfNecessary(int slotId, String message) { |
| 1687 | createAllChannels(); |
| 1688 | |
| 1689 | if (mStkContext[slotId].mNoResponseFromUser) { |
| 1690 | // No response from user was observed in the current session. |
| 1691 | // Do nothing in that case in order to avoid turning on the screen again and again |
| 1692 | // when the card repeatedly sends the same command in its retry procedure. |
| 1693 | return; |
| 1694 | } |
| 1695 | |
| 1696 | PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); |
| 1697 | |
| 1698 | if (((KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE)).isKeyguardLocked()) { |
| 1699 | // Display the notification on the keyguard screen |
| 1700 | // if user cannot see the message from the card right now because of it. |
| 1701 | // The notification can be dismissed if user removed the keyguard screen. |
| 1702 | launchNotificationOnKeyguard(slotId, message); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1703 | } |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 1704 | |
| 1705 | // Turn on the screen. |
| 1706 | PowerManager.WakeLock wakelock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |
| 1707 | | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, LOG_TAG); |
| 1708 | wakelock.acquire(); |
| 1709 | wakelock.release(); |
| 1710 | } |
| 1711 | |
| 1712 | private void launchNotificationOnKeyguard(int slotId, String message) { |
| 1713 | Notification.Builder builder = new Notification.Builder(this, STK_NOTIFICATION_CHANNEL_ID); |
| 1714 | |
| 1715 | builder.setStyle(new Notification.BigTextStyle(builder).bigText(message)); |
| 1716 | builder.setContentText(message); |
| 1717 | |
| 1718 | Menu menu = getMainMenu(slotId); |
Zhang Renjie | 717bb8d | 2021-08-20 17:38:24 +0800 | [diff] [blame] | 1719 | // add by T2M.zhangrenjie for FP4-2257 2021-08-20 begin |
| 1720 | |
| 1721 | /*if (menu == null || TextUtils.isEmpty(menu.title)) { |
Jordan Liu | 3bd92cd | 2020-08-12 11:49:48 -0700 | [diff] [blame] | 1722 | builder.setContentTitle(""); |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 1723 | } else { |
| 1724 | builder.setContentTitle(menu.title); |
Zhang Renjie | 717bb8d | 2021-08-20 17:38:24 +0800 | [diff] [blame] | 1725 | }*/ |
Zhang Renjie | c8ecd5f | 2021-08-27 16:45:50 +0800 | [diff] [blame^] | 1726 | Bundle extras = new Bundle(); |
| 1727 | extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, " "); |
| 1728 | builder.addExtras(extras); |
Zhang Renjie | 717bb8d | 2021-08-20 17:38:24 +0800 | [diff] [blame] | 1729 | builder.setContentTitle(""); |
Zhang Renjie | c8ecd5f | 2021-08-27 16:45:50 +0800 | [diff] [blame^] | 1730 | // add by T2M.zhangrenjie for FP4-2257 2021-08-20 end |
| 1731 | |
Sooraj Sasindran | 2b44d5b | 2020-01-29 15:17:48 -0800 | [diff] [blame] | 1732 | builder.setSmallIcon(R.drawable.stat_notify_sim_toolkit); |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 1733 | builder.setOngoing(true); |
| 1734 | builder.setOnlyAlertOnce(true); |
| 1735 | builder.setColor(getResources().getColor( |
| 1736 | com.android.internal.R.color.system_notification_accent_color)); |
| 1737 | |
| 1738 | registerUserPresentReceiver(); |
| 1739 | mNotificationManager.notify(getNotificationId(NOTIFICATION_ON_KEYGUARD, slotId), |
| 1740 | builder.build()); |
| 1741 | mStkContext[slotId].mNotificationOnKeyguard = true; |
| 1742 | } |
| 1743 | |
| 1744 | private void cancelNotificationOnKeyguard(int slotId) { |
| 1745 | mNotificationManager.cancel(getNotificationId(NOTIFICATION_ON_KEYGUARD, slotId)); |
| 1746 | mStkContext[slotId].mNotificationOnKeyguard = false; |
| 1747 | unregisterUserPresentReceiver(slotId); |
| 1748 | } |
| 1749 | |
| 1750 | private synchronized void registerUserPresentReceiver() { |
| 1751 | if (mUserPresentReceiver == null) { |
| 1752 | mUserPresentReceiver = new BroadcastReceiver() { |
| 1753 | @Override public void onReceive(Context context, Intent intent) { |
| 1754 | if (Intent.ACTION_USER_PRESENT.equals(intent.getAction())) { |
| 1755 | for (int slot = 0; slot < mSimCount; slot++) { |
| 1756 | cancelNotificationOnKeyguard(slot); |
| 1757 | } |
| 1758 | } |
| 1759 | } |
| 1760 | }; |
| 1761 | registerReceiver(mUserPresentReceiver, new IntentFilter(Intent.ACTION_USER_PRESENT)); |
| 1762 | } |
| 1763 | } |
| 1764 | |
| 1765 | private synchronized void unregisterUserPresentReceiver(int slotId) { |
| 1766 | if (mUserPresentReceiver != null) { |
Yoshiaki Naka | 8b960fb | 2019-10-31 10:44:07 +0900 | [diff] [blame] | 1767 | for (int slot = 0; slot < mSimCount; slot++) { |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 1768 | if (slot != slotId) { |
| 1769 | if (mStkContext[slot].mNotificationOnKeyguard) { |
| 1770 | // The broadcast receiver is still necessary for other SIM card. |
| 1771 | return; |
| 1772 | } |
| 1773 | } |
| 1774 | } |
| 1775 | unregisterReceiver(mUserPresentReceiver); |
| 1776 | mUserPresentReceiver = null; |
| 1777 | } |
| 1778 | } |
| 1779 | |
| 1780 | private int getNotificationId(int notificationType, int slotId) { |
| 1781 | return getNotificationId(slotId) + (notificationType * mSimCount); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1782 | } |
| 1783 | |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1784 | private void replaceEventList(int slotId) { |
| 1785 | if (mStkContext[slotId].mSetupEventListSettings != null) { |
| 1786 | for (int current : mStkContext[slotId].mSetupEventListSettings.eventList) { |
| 1787 | if (current != INVALID_SETUP_EVENT) { |
| 1788 | // Cancel the event notification if it is not listed in the new event list. |
| 1789 | if ((mStkContext[slotId].mCurrentCmd.getSetEventList() == null) |
| 1790 | || !findEvent(current, mStkContext[slotId].mCurrentCmd |
| 1791 | .getSetEventList().eventList)) { |
| 1792 | unregisterEvent(current, slotId); |
| 1793 | } |
| 1794 | } |
| 1795 | } |
| 1796 | } |
| 1797 | mStkContext[slotId].mSetupEventListSettings |
| 1798 | = mStkContext[slotId].mCurrentCmd.getSetEventList(); |
| 1799 | mStkContext[slotId].mCurrentSetupEventCmd = mStkContext[slotId].mCurrentCmd; |
| 1800 | mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd; |
| 1801 | registerEvents(slotId); |
| 1802 | } |
| 1803 | |
| 1804 | private boolean findEvent(int event, int[] eventList) { |
| 1805 | for (int content : eventList) { |
| 1806 | if (content == event) return true; |
| 1807 | } |
| 1808 | return false; |
| 1809 | } |
| 1810 | |
| 1811 | private void unregisterEvent(int event, int slotId) { |
Yoshiaki Naka | 8b960fb | 2019-10-31 10:44:07 +0900 | [diff] [blame] | 1812 | for (int slot = 0; slot < mSimCount; slot++) { |
Yoshiaki Naka | 0c2d2ba | 2017-11-17 21:51:55 +0900 | [diff] [blame] | 1813 | if (slot != slotId) { |
| 1814 | if (mStkContext[slot].mSetupEventListSettings != null) { |
| 1815 | if (findEvent(event, mStkContext[slot].mSetupEventListSettings.eventList)) { |
| 1816 | // The specified event shall never be canceled |
| 1817 | // if there is any other SIM card which requests the event. |
| 1818 | return; |
| 1819 | } |
| 1820 | } |
| 1821 | } |
| 1822 | } |
| 1823 | |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1824 | switch (event) { |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 1825 | case USER_ACTIVITY_EVENT: |
| 1826 | unregisterUserActivityReceiver(); |
| 1827 | break; |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1828 | case IDLE_SCREEN_AVAILABLE_EVENT: |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 1829 | unregisterHomeVisibilityObserver(AppInterface.CommandType.SET_UP_EVENT_LIST, slotId); |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1830 | break; |
| 1831 | case LANGUAGE_SELECTION_EVENT: |
Yoshiaki Naka | 0c2d2ba | 2017-11-17 21:51:55 +0900 | [diff] [blame] | 1832 | unregisterLocaleChangeReceiver(); |
| 1833 | break; |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1834 | default: |
| 1835 | break; |
| 1836 | } |
| 1837 | } |
| 1838 | |
| 1839 | private void registerEvents(int slotId) { |
| 1840 | if (mStkContext[slotId].mSetupEventListSettings == null) { |
| 1841 | return; |
| 1842 | } |
| 1843 | for (int event : mStkContext[slotId].mSetupEventListSettings.eventList) { |
| 1844 | switch (event) { |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 1845 | case USER_ACTIVITY_EVENT: |
| 1846 | registerUserActivityReceiver(); |
| 1847 | break; |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1848 | case IDLE_SCREEN_AVAILABLE_EVENT: |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 1849 | registerHomeVisibilityObserver(); |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1850 | break; |
| 1851 | case LANGUAGE_SELECTION_EVENT: |
Yoshiaki Naka | 0c2d2ba | 2017-11-17 21:51:55 +0900 | [diff] [blame] | 1852 | registerLocaleChangeReceiver(); |
| 1853 | break; |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1854 | default: |
| 1855 | break; |
| 1856 | } |
| 1857 | } |
| 1858 | } |
| 1859 | |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 1860 | private synchronized void registerUserActivityReceiver() { |
| 1861 | if (mUserActivityReceiver == null) { |
| 1862 | mUserActivityReceiver = new BroadcastReceiver() { |
| 1863 | @Override public void onReceive(Context context, Intent intent) { |
Peter Wang | 10da929 | 2020-01-27 12:36:00 +0800 | [diff] [blame] | 1864 | if (TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION.equals( |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 1865 | intent.getAction())) { |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 1866 | Message message = mServiceHandler.obtainMessage(OP_USER_ACTIVITY); |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 1867 | mServiceHandler.sendMessage(message); |
| 1868 | unregisterUserActivityReceiver(); |
| 1869 | } |
| 1870 | } |
| 1871 | }; |
| 1872 | registerReceiver(mUserActivityReceiver, new IntentFilter( |
Peter Wang | 10da929 | 2020-01-27 12:36:00 +0800 | [diff] [blame] | 1873 | TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION)); |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 1874 | try { |
Peter Wang | a14d13d | 2020-01-15 14:13:51 -0800 | [diff] [blame] | 1875 | ITelephony telephony = ITelephony.Stub.asInterface( |
Peter Wang | c94b8e6 | 2019-12-30 17:09:10 -0800 | [diff] [blame] | 1876 | TelephonyFrameworkInitializer |
| 1877 | .getTelephonyServiceManager() |
Peter Wang | a14d13d | 2020-01-15 14:13:51 -0800 | [diff] [blame] | 1878 | .getTelephonyServiceRegisterer() |
Peter Wang | c94b8e6 | 2019-12-30 17:09:10 -0800 | [diff] [blame] | 1879 | .get()); |
Peter Wang | a14d13d | 2020-01-15 14:13:51 -0800 | [diff] [blame] | 1880 | telephony.requestUserActivityNotification(); |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 1881 | } catch (RemoteException e) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 1882 | CatLog.e(LOG_TAG, "failed to init WindowManager:" + e); |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 1883 | } |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | private synchronized void unregisterUserActivityReceiver() { |
| 1888 | if (mUserActivityReceiver != null) { |
| 1889 | unregisterReceiver(mUserActivityReceiver); |
| 1890 | mUserActivityReceiver = null; |
| 1891 | } |
| 1892 | } |
| 1893 | |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 1894 | private synchronized void registerHomeVisibilityObserver() { |
Hall Liu | 9d5d5ee | 2020-10-06 14:15:40 -0700 | [diff] [blame] | 1895 | if (mHomeVisibilityListener == null) { |
| 1896 | mHomeVisibilityListener = new HomeVisibilityListener() { |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 1897 | @Override |
| 1898 | public void onHomeVisibilityChanged(boolean isHomeActivityVisible) { |
| 1899 | if (isHomeActivityVisible) { |
| 1900 | Message message = mServiceHandler.obtainMessage(OP_IDLE_SCREEN); |
| 1901 | mServiceHandler.sendMessage(message); |
| 1902 | unregisterHomeVisibilityObserver(); |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1903 | } |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 1904 | } |
| 1905 | }; |
| 1906 | ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); |
Hall Liu | 9d5d5ee | 2020-10-06 14:15:40 -0700 | [diff] [blame] | 1907 | am.addHomeVisibilityListener(Runnable::run, mHomeVisibilityListener); |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 1908 | CatLog.d(LOG_TAG, "Started to observe the foreground activity"); |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1909 | } |
| 1910 | } |
| 1911 | |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 1912 | private void unregisterHomeVisibilityObserver(AppInterface.CommandType command, int slotId) { |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1913 | // Check if there is any pending command which still needs the process observer |
| 1914 | // except for the current command and slot. |
Yoshiaki Naka | 8b960fb | 2019-10-31 10:44:07 +0900 | [diff] [blame] | 1915 | for (int slot = 0; slot < mSimCount; slot++) { |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1916 | if (command != AppInterface.CommandType.SET_UP_IDLE_MODE_TEXT || slot != slotId) { |
| 1917 | if (mStkContext[slot].mIdleModeTextCmd != null |
| 1918 | && !mStkContext[slot].mIdleModeTextVisible) { |
| 1919 | // Keep the process observer registered |
| 1920 | // as there is an idle mode text which has not been visible yet. |
| 1921 | return; |
| 1922 | } |
| 1923 | } |
| 1924 | if (command != AppInterface.CommandType.SET_UP_EVENT_LIST || slot != slotId) { |
| 1925 | if (mStkContext[slot].mSetupEventListSettings != null) { |
| 1926 | if (findEvent(IDLE_SCREEN_AVAILABLE_EVENT, |
| 1927 | mStkContext[slot].mSetupEventListSettings.eventList)) { |
| 1928 | // Keep the process observer registered |
| 1929 | // as there is a SIM card which still want IDLE SCREEN AVAILABLE event. |
| 1930 | return; |
| 1931 | } |
| 1932 | } |
| 1933 | } |
| 1934 | } |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 1935 | unregisterHomeVisibilityObserver(); |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1936 | } |
| 1937 | |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 1938 | private synchronized void unregisterHomeVisibilityObserver() { |
Hall Liu | 9d5d5ee | 2020-10-06 14:15:40 -0700 | [diff] [blame] | 1939 | if (mHomeVisibilityListener != null) { |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 1940 | ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); |
Hall Liu | 9d5d5ee | 2020-10-06 14:15:40 -0700 | [diff] [blame] | 1941 | am.removeHomeVisibilityListener(mHomeVisibilityListener); |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 1942 | CatLog.d(LOG_TAG, "Stopped to observe the foreground activity"); |
Hall Liu | 9d5d5ee | 2020-10-06 14:15:40 -0700 | [diff] [blame] | 1943 | mHomeVisibilityListener = null; |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 1944 | } |
| 1945 | } |
| 1946 | |
Yoshiaki Naka | 0c2d2ba | 2017-11-17 21:51:55 +0900 | [diff] [blame] | 1947 | private synchronized void registerLocaleChangeReceiver() { |
| 1948 | if (mLocaleChangeReceiver == null) { |
| 1949 | mLocaleChangeReceiver = new BroadcastReceiver() { |
| 1950 | @Override public void onReceive(Context context, Intent intent) { |
| 1951 | if (Intent.ACTION_LOCALE_CHANGED.equals(intent.getAction())) { |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 1952 | Message message = mServiceHandler.obtainMessage(OP_LOCALE_CHANGED); |
Yoshiaki Naka | 0c2d2ba | 2017-11-17 21:51:55 +0900 | [diff] [blame] | 1953 | mServiceHandler.sendMessage(message); |
| 1954 | } |
| 1955 | } |
| 1956 | }; |
| 1957 | registerReceiver(mLocaleChangeReceiver, new IntentFilter(Intent.ACTION_LOCALE_CHANGED)); |
| 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | private synchronized void unregisterLocaleChangeReceiver() { |
| 1962 | if (mLocaleChangeReceiver != null) { |
| 1963 | unregisterReceiver(mLocaleChangeReceiver); |
| 1964 | mLocaleChangeReceiver = null; |
| 1965 | } |
| 1966 | } |
| 1967 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1968 | private void sendSetUpEventResponse(int event, byte[] addedInfo, int slotId) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 1969 | CatLog.d(LOG_TAG, "sendSetUpEventResponse: event : " + event + "slotId = " + slotId); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1970 | |
| 1971 | if (mStkContext[slotId].mCurrentSetupEventCmd == null){ |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 1972 | CatLog.e(LOG_TAG, "mCurrentSetupEventCmd is null"); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1973 | return; |
| 1974 | } |
| 1975 | |
| 1976 | CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentSetupEventCmd); |
| 1977 | |
| 1978 | resMsg.setResultCode(ResultCode.OK); |
| 1979 | resMsg.setEventDownload(event, addedInfo); |
| 1980 | |
| 1981 | mStkService[slotId].onCmdResponse(resMsg); |
| 1982 | } |
| 1983 | |
| 1984 | private void checkForSetupEvent(int event, Bundle args, int slotId) { |
| 1985 | boolean eventPresent = false; |
| 1986 | byte[] addedInfo = null; |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 1987 | CatLog.d(LOG_TAG, "Event :" + event); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1988 | |
| 1989 | if (mStkContext[slotId].mSetupEventListSettings != null) { |
| 1990 | /* Checks if the event is present in the EventList updated by last |
| 1991 | * SetupEventList Proactive Command */ |
| 1992 | for (int i : mStkContext[slotId].mSetupEventListSettings.eventList) { |
| 1993 | if (event == i) { |
| 1994 | eventPresent = true; |
| 1995 | break; |
| 1996 | } |
| 1997 | } |
| 1998 | |
| 1999 | /* If Event is present send the response to ICC */ |
| 2000 | if (eventPresent == true) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2001 | CatLog.d(LOG_TAG, " Event " + event + "exists in the EventList"); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 2002 | |
| 2003 | switch (event) { |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 2004 | case USER_ACTIVITY_EVENT: |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 2005 | case IDLE_SCREEN_AVAILABLE_EVENT: |
| 2006 | sendSetUpEventResponse(event, addedInfo, slotId); |
| 2007 | removeSetUpEvent(event, slotId); |
| 2008 | break; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 2009 | case LANGUAGE_SELECTION_EVENT: |
| 2010 | String language = mContext |
| 2011 | .getResources().getConfiguration().locale.getLanguage(); |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2012 | CatLog.d(LOG_TAG, "language: " + language); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 2013 | // Each language code is a pair of alpha-numeric characters. |
| 2014 | // Each alpha-numeric character shall be coded on one byte |
| 2015 | // using the SMS default 7-bit coded alphabet |
| 2016 | addedInfo = GsmAlphabet.stringToGsm8BitPacked(language); |
| 2017 | sendSetUpEventResponse(event, addedInfo, slotId); |
| 2018 | break; |
feizhang | 5fd5c6f | 2021-06-30 13:59:02 +0800 | [diff] [blame] | 2019 | //add by qingyang.yi 2016.6.21 PR:1137553 add for Browser termination EVENT |
| 2020 | case BROWSER_TERMINATION_EVENT: |
| 2021 | int browserTerminationCause = args.getInt(BROWSER_TERMINATION_CAUSE); |
| 2022 | CatLog.d(this, "BrowserTerminationCause: " + browserTerminationCause); |
| 2023 | // Single byte is sufficient to represent browser termination cause. |
| 2024 | addedInfo = new byte[1]; |
| 2025 | addedInfo[0] = (byte) browserTerminationCause; |
| 2026 | sendSetUpEventResponse(event, addedInfo, slotId); |
| 2027 | break; |
| 2028 | //add end by qingyang.yi |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 2029 | default: |
| 2030 | break; |
| 2031 | } |
| 2032 | } else { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2033 | CatLog.e(LOG_TAG, " Event does not exist in the EventList"); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 2034 | } |
| 2035 | } else { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2036 | CatLog.e(LOG_TAG, "SetupEventList is not received. Ignoring the event: " + event); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 2037 | } |
| 2038 | } |
| 2039 | |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 2040 | private void removeSetUpEvent(int event, int slotId) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2041 | CatLog.d(LOG_TAG, "Remove Event :" + event); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 2042 | |
| 2043 | if (mStkContext[slotId].mSetupEventListSettings != null) { |
| 2044 | /* |
| 2045 | * Make new Eventlist without the event |
| 2046 | */ |
| 2047 | for (int i = 0; i < mStkContext[slotId].mSetupEventListSettings.eventList.length; i++) { |
| 2048 | if (event == mStkContext[slotId].mSetupEventListSettings.eventList[i]) { |
| 2049 | mStkContext[slotId].mSetupEventListSettings.eventList[i] = INVALID_SETUP_EVENT; |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 2050 | |
| 2051 | switch (event) { |
Yoshiaki Naka | fb99725 | 2017-09-19 20:14:58 +0900 | [diff] [blame] | 2052 | case USER_ACTIVITY_EVENT: |
| 2053 | // The broadcast receiver can be unregistered |
| 2054 | // as the event has already been sent to the card. |
| 2055 | unregisterUserActivityReceiver(); |
| 2056 | break; |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 2057 | case IDLE_SCREEN_AVAILABLE_EVENT: |
| 2058 | // The process observer can be unregistered |
| 2059 | // as the idle screen has already been available. |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 2060 | unregisterHomeVisibilityObserver(); |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 2061 | break; |
| 2062 | default: |
| 2063 | break; |
| 2064 | } |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 2065 | break; |
| 2066 | } |
| 2067 | } |
| 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | private void launchEventMessage(int slotId) { |
| 2072 | launchEventMessage(slotId, mStkContext[slotId].mCurrentCmd.geTextMessage()); |
| 2073 | } |
| 2074 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2075 | private void launchEventMessage(int slotId, TextMessage msg) { |
Ryuto Sawada | 2ba20cc | 2015-12-28 17:10:35 +0100 | [diff] [blame] | 2076 | if (msg == null || msg.text == null || (msg.text != null && msg.text.length() == 0)) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2077 | CatLog.d(LOG_TAG, "launchEventMessage return"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2078 | return; |
| 2079 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2080 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2081 | Toast toast = new Toast(mContext.getApplicationContext()); |
| 2082 | LayoutInflater inflate = (LayoutInflater) mContext |
| 2083 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 2084 | View v = inflate.inflate(R.layout.stk_event_msg, null); |
| 2085 | TextView tv = (TextView) v |
| 2086 | .findViewById(com.android.internal.R.id.message); |
| 2087 | ImageView iv = (ImageView) v |
| 2088 | .findViewById(com.android.internal.R.id.icon); |
| 2089 | if (msg.icon != null) { |
Umashankar Godachi | c77445b | 2018-02-28 02:51:56 +0530 | [diff] [blame] | 2090 | iv.setContentDescription(TEXT_ICON_FROM_COMMAND); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2091 | iv.setImageBitmap(msg.icon); |
| 2092 | } else { |
| 2093 | iv.setVisibility(View.GONE); |
| 2094 | } |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 2095 | /* In case of 'self explanatory' stkapp should display the specified |
| 2096 | * icon in proactive command (but not the alpha string). |
| 2097 | * If icon is non-self explanatory and if the icon could not be displayed |
| 2098 | * then alpha string or text data should be displayed |
| 2099 | * Ref: ETSI 102.223,section 6.5.4 |
| 2100 | */ |
| 2101 | if (mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() || |
| 2102 | msg.icon == null || !msg.iconSelfExplanatory) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2103 | tv.setText(msg.text); |
| 2104 | } |
| 2105 | |
| 2106 | toast.setView(v); |
| 2107 | toast.setDuration(Toast.LENGTH_LONG); |
| 2108 | toast.setGravity(Gravity.BOTTOM, 0, 0); |
| 2109 | toast.show(); |
| 2110 | } |
| 2111 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2112 | private void launchConfirmationDialog(TextMessage msg, int slotId) { |
| 2113 | msg.title = mStkContext[slotId].lastSelectedItem; |
| 2114 | Intent newIntent = new Intent(); |
| 2115 | String targetActivity = STK_DIALOG_ACTIVITY_NAME; |
| 2116 | String uriString = STK_DIALOG_URI + System.currentTimeMillis(); |
| 2117 | //Set unique URI to create a new instance of activity for different slotId. |
| 2118 | Uri uriData = Uri.parse(uriString); |
| 2119 | |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 2120 | newIntent.setClassName(this, targetActivity); |
| 2121 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2122 | | Intent.FLAG_ACTIVITY_NO_HISTORY |
| 2123 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 2124 | | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); |
| 2125 | newIntent.putExtra("TEXT", msg); |
| 2126 | newIntent.putExtra(SLOT_ID, slotId); |
| 2127 | newIntent.setData(uriData); |
| 2128 | startActivity(newIntent); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | private void launchBrowser(BrowserSettings settings) { |
| 2132 | if (settings == null) { |
| 2133 | return; |
| 2134 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2135 | |
Abhishek Adappa | 840c82f | 2013-02-26 10:19:49 -0800 | [diff] [blame] | 2136 | Uri data = null; |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 2137 | String url; |
| 2138 | if (settings.url == null) { |
Abhishek Adappa | 840c82f | 2013-02-26 10:19:49 -0800 | [diff] [blame] | 2139 | // if the command did not contain a URL, |
| 2140 | // launch the browser to the default homepage. |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2141 | CatLog.d(LOG_TAG, "no url data provided by proactive command." + |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 2142 | " launching browser with stk default URL ... "); |
| 2143 | url = SystemProperties.get(STK_BROWSER_DEFAULT_URL_SYSPROP, |
| 2144 | "http://www.google.com"); |
| 2145 | } else { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2146 | CatLog.d(LOG_TAG, "launch browser command has attached url = " + settings.url); |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 2147 | url = settings.url; |
Abhishek Adappa | 840c82f | 2013-02-26 10:19:49 -0800 | [diff] [blame] | 2148 | } |
David Brown | 7c03cfe | 2011-10-20 15:36:12 -0700 | [diff] [blame] | 2149 | |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 2150 | if (url.startsWith("http://") || url.startsWith("https://")) { |
| 2151 | data = Uri.parse(url); |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2152 | CatLog.d(LOG_TAG, "launching browser with url = " + url); |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 2153 | } else { |
| 2154 | String modifiedUrl = "http://" + url; |
| 2155 | data = Uri.parse(modifiedUrl); |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2156 | CatLog.d(LOG_TAG, "launching browser with modified url = " + modifiedUrl); |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 2160 | intent.setData(data); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2161 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2162 | switch (settings.mode) { |
| 2163 | case USE_EXISTING_BROWSER: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2164 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 2165 | break; |
| 2166 | case LAUNCH_NEW_BROWSER: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2167 | intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); |
| 2168 | break; |
| 2169 | case LAUNCH_IF_NOT_ALREADY_LAUNCHED: |
| 2170 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 2171 | break; |
| 2172 | } |
| 2173 | // start browser activity |
| 2174 | startActivity(intent); |
| 2175 | // a small delay, let the browser start, before processing the next command. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 2176 | // this is good for scenarios where a related DISPLAY TEXT command is |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2177 | // followed immediately. |
| 2178 | try { |
Ryuto Sawada | 350aaa6 | 2016-06-13 14:47:22 +0900 | [diff] [blame] | 2179 | Thread.sleep(3000); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2180 | } catch (InterruptedException e) {} |
| 2181 | } |
| 2182 | |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 2183 | private void cancelIdleText(int slotId) { |
Malcolm Chen | 549e21a | 2020-01-10 15:57:10 -0800 | [diff] [blame] | 2184 | unregisterHomeVisibilityObserver(AppInterface.CommandType.SET_UP_IDLE_MODE_TEXT, slotId); |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 2185 | mNotificationManager.cancel(getNotificationId(slotId)); |
| 2186 | mStkContext[slotId].mIdleModeTextCmd = null; |
| 2187 | mStkContext[slotId].mIdleModeTextVisible = false; |
| 2188 | } |
| 2189 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2190 | private void launchIdleText(int slotId) { |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 2191 | TextMessage msg = mStkContext[slotId].mIdleModeTextCmd.geTextMessage(); |
dujin.cha | 2a0eb2a | 2011-11-11 15:03:57 +0900 | [diff] [blame] | 2192 | |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 2193 | if (msg != null && !TextUtils.isEmpty(msg.text)) { |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 2194 | CatLog.d(LOG_TAG, "launchIdleText - text[" + msg.text |
| 2195 | + "] iconSelfExplanatory[" + msg.iconSelfExplanatory |
| 2196 | + "] icon[" + msg.icon + "], sim id: " + slotId); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2197 | CatLog.d(LOG_TAG, "Add IdleMode text"); |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 2198 | PendingIntent pendingIntent = PendingIntent.getService(mContext, 0, |
Jordan Liu | 79bc942 | 2021-02-19 15:29:14 -0800 | [diff] [blame] | 2199 | new Intent(mContext, StkAppService.class), PendingIntent.FLAG_IMMUTABLE); |
fionaxu | 805eb57 | 2017-05-02 10:57:30 -0700 | [diff] [blame] | 2200 | createAllChannels(); |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 2201 | final Notification.Builder notificationBuilder = new Notification.Builder( |
fionaxu | 2c91c75 | 2017-04-21 18:11:57 -0700 | [diff] [blame] | 2202 | StkAppService.this, STK_NOTIFICATION_CHANNEL_ID); |
Zhang Renjie | 717bb8d | 2021-08-20 17:38:24 +0800 | [diff] [blame] | 2203 | // add by T2M.zhangrenjie for FP4-2257 2021-08-20 begin |
| 2204 | /*if (mStkContext[slotId].mMainCmd != null && |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2205 | mStkContext[slotId].mMainCmd.getMenu() != null) { |
| 2206 | notificationBuilder.setContentTitle(mStkContext[slotId].mMainCmd.getMenu().title); |
Christopher Posselwhite | 2ad2ab7 | 2013-05-27 07:51:06 +0200 | [diff] [blame] | 2207 | } else { |
| 2208 | notificationBuilder.setContentTitle(""); |
Zhang Renjie | 717bb8d | 2021-08-20 17:38:24 +0800 | [diff] [blame] | 2209 | }*/ |
Zhang Renjie | c8ecd5f | 2021-08-27 16:45:50 +0800 | [diff] [blame^] | 2210 | Bundle extras = new Bundle(); |
| 2211 | extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, " "); |
| 2212 | notificationBuilder.addExtras(extras); |
Zhang Renjie | 717bb8d | 2021-08-20 17:38:24 +0800 | [diff] [blame] | 2213 | notificationBuilder.setContentTitle(""); |
| 2214 | // add by T2M.zhangrenjie for FP4-2257 2021-08-20 end |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 2215 | notificationBuilder |
Sooraj Sasindran | 2b44d5b | 2020-01-29 15:17:48 -0800 | [diff] [blame] | 2216 | .setSmallIcon(R.drawable.stat_notify_sim_toolkit); |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 2217 | notificationBuilder.setContentIntent(pendingIntent); |
| 2218 | notificationBuilder.setOngoing(true); |
Umashankar Godachi | d3598a2 | 2018-03-01 02:20:28 +0530 | [diff] [blame] | 2219 | notificationBuilder.setStyle(new Notification.BigTextStyle(notificationBuilder) |
| 2220 | .bigText(msg.text)); |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 2221 | notificationBuilder.setOnlyAlertOnce(true); |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 2222 | // Set text and icon for the status bar and notification body. |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 2223 | if (mStkContext[slotId].mIdleModeTextCmd.hasIconLoadFailed() || |
| 2224 | !msg.iconSelfExplanatory) { |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 2225 | notificationBuilder.setContentText(msg.text); |
Christopher Posselwhite | 2ad2ab7 | 2013-05-27 07:51:06 +0200 | [diff] [blame] | 2226 | notificationBuilder.setTicker(msg.text); |
samalin | c7f3bdf | 2018-04-26 15:04:31 +0800 | [diff] [blame] | 2227 | notificationBuilder.setStyle(new Notification.BigTextStyle(notificationBuilder) |
| 2228 | .bigText(msg.text)); |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 2229 | } |
| 2230 | if (msg.icon != null) { |
| 2231 | notificationBuilder.setLargeIcon(msg.icon); |
| 2232 | } else { |
| 2233 | Bitmap bitmapIcon = BitmapFactory.decodeResource(StkAppService.this |
| 2234 | .getResources().getSystem(), |
Sooraj Sasindran | 2b44d5b | 2020-01-29 15:17:48 -0800 | [diff] [blame] | 2235 | R.drawable.stat_notify_sim_toolkit); |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 2236 | notificationBuilder.setLargeIcon(bitmapIcon); |
| 2237 | } |
Selim Cinek | 62eb3fe | 2014-08-27 17:52:23 +0200 | [diff] [blame] | 2238 | notificationBuilder.setColor(mContext.getResources().getColor( |
| 2239 | com.android.internal.R.color.system_notification_accent_color)); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2240 | mNotificationManager.notify(getNotificationId(slotId), notificationBuilder.build()); |
Yoshiaki Naka | 62bfb0d | 2017-10-07 16:42:08 +0900 | [diff] [blame] | 2241 | mStkContext[slotId].mIdleModeTextVisible = true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2242 | } |
| 2243 | } |
| 2244 | |
fionaxu | 805eb57 | 2017-05-02 10:57:30 -0700 | [diff] [blame] | 2245 | /** Creates the notification channel and registers it with NotificationManager. |
| 2246 | * If a channel with the same ID is already registered, NotificationManager will |
| 2247 | * ignore this call. |
| 2248 | */ |
| 2249 | private void createAllChannels() { |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 2250 | NotificationChannel notificationChannel = new NotificationChannel( |
fionaxu | 805eb57 | 2017-05-02 10:57:30 -0700 | [diff] [blame] | 2251 | STK_NOTIFICATION_CHANNEL_ID, |
| 2252 | getResources().getString(R.string.stk_channel_name), |
Yuta Ui | fe96580 | 2017-11-07 20:12:37 +0900 | [diff] [blame] | 2253 | NotificationManager.IMPORTANCE_DEFAULT); |
| 2254 | |
| 2255 | notificationChannel.enableVibration(true); |
| 2256 | notificationChannel.setVibrationPattern(VIBRATION_PATTERN); |
| 2257 | |
| 2258 | mNotificationManager.createNotificationChannel(notificationChannel); |
fionaxu | 805eb57 | 2017-05-02 10:57:30 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2261 | private void launchToneDialog(int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2262 | Intent newIntent = new Intent(this, ToneDialog.class); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2263 | String uriString = STK_TONE_URI + slotId; |
| 2264 | Uri uriData = Uri.parse(uriString); |
| 2265 | //Set unique URI to create a new instance of activity for different slotId. |
| 2266 | CatLog.d(LOG_TAG, "launchToneDialog, slotId: " + slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2267 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2268 | | Intent.FLAG_ACTIVITY_NO_HISTORY |
| 2269 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2270 | | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); |
| 2271 | newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage()); |
| 2272 | newIntent.putExtra("TONE", mStkContext[slotId].mCurrentCmd.getToneSettings()); |
| 2273 | newIntent.putExtra(SLOT_ID, slotId); |
| 2274 | newIntent.setData(uriData); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2275 | startActivity(newIntent); |
| 2276 | } |
| 2277 | |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2278 | private void handlePlayTone(int slotId) { |
| 2279 | TextMessage toneMsg = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
| 2280 | |
| 2281 | boolean showUser = true; |
| 2282 | boolean displayDialog = true; |
| 2283 | Resources resource = Resources.getSystem(); |
| 2284 | try { |
| 2285 | displayDialog = !resource.getBoolean( |
Sooraj Sasindran | 2b44d5b | 2020-01-29 15:17:48 -0800 | [diff] [blame] | 2286 | R.bool.config_stkNoAlphaUsrCnf); |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2287 | } catch (NotFoundException e) { |
| 2288 | displayDialog = true; |
| 2289 | } |
| 2290 | |
| 2291 | // As per the spec 3GPP TS 11.14, 6.4.5. Play Tone. |
| 2292 | // If there is no alpha identifier tlv present, UE may show the |
| 2293 | // user information. 'config_stkNoAlphaUsrCnf' value will decide |
| 2294 | // whether to show it or not. |
| 2295 | // If alpha identifier tlv is present and its data is null, play only tone |
| 2296 | // without showing user any information. |
| 2297 | // Alpha Id is Present, but the text data is null. |
| 2298 | if ((toneMsg.text != null ) && (toneMsg.text.equals(""))) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2299 | CatLog.d(LOG_TAG, "Alpha identifier data is null, play only tone"); |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2300 | showUser = false; |
| 2301 | } |
| 2302 | // Alpha Id is not present AND we need to show info to the user. |
| 2303 | if (toneMsg.text == null && displayDialog) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2304 | CatLog.d(LOG_TAG, "toneMsg.text " + toneMsg.text |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2305 | + " Starting ToneDialog activity with default message."); |
| 2306 | toneMsg.text = getResources().getString(R.string.default_tone_dialog_msg); |
| 2307 | showUser = true; |
| 2308 | } |
| 2309 | // Dont show user info, if config setting is true. |
| 2310 | if (toneMsg.text == null && !displayDialog) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2311 | CatLog.d(LOG_TAG, "config value stkNoAlphaUsrCnf is true"); |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2312 | showUser = false; |
| 2313 | } |
| 2314 | |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2315 | CatLog.d(LOG_TAG, "toneMsg.text: " + toneMsg.text + "showUser: " +showUser + |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2316 | "displayDialog: " +displayDialog); |
| 2317 | playTone(showUser, slotId); |
| 2318 | } |
| 2319 | |
| 2320 | private void playTone(boolean showUserInfo, int slotId) { |
| 2321 | // Start playing tone and vibration |
| 2322 | ToneSettings settings = mStkContext[slotId].mCurrentCmd.getToneSettings(); |
| 2323 | if (null == settings) { |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2324 | CatLog.d(LOG_TAG, "null settings, not playing tone."); |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2325 | return; |
| 2326 | } |
| 2327 | |
| 2328 | mVibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE); |
| 2329 | mTonePlayer = new TonePlayer(); |
| 2330 | mTonePlayer.play(settings.tone); |
| 2331 | int timeout = StkApp.calculateDurationInMilis(settings.duration); |
| 2332 | if (timeout == 0) { |
| 2333 | timeout = StkApp.TONE_DEFAULT_TIMEOUT; |
| 2334 | } |
| 2335 | |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 2336 | Message msg = mServiceHandler.obtainMessage(OP_STOP_TONE, 0, slotId, |
| 2337 | (showUserInfo ? PLAY_TONE_WITH_DIALOG : PLAY_TONE_ONLY)); |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2338 | mServiceHandler.sendMessageDelayed(msg, timeout); |
| 2339 | if (settings.vibrate) { |
| 2340 | mVibrator.vibrate(timeout); |
| 2341 | } |
| 2342 | |
| 2343 | // Start Tone dialog Activity to show user the information. |
| 2344 | if (showUserInfo) { |
| 2345 | Intent newIntent = new Intent(sInstance, ToneDialog.class); |
| 2346 | String uriString = STK_TONE_URI + slotId; |
| 2347 | Uri uriData = Uri.parse(uriString); |
| 2348 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2349 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2350 | | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); |
| 2351 | newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage()); |
Umashankar Godachi | d345b36 | 2017-11-27 15:46:55 +0530 | [diff] [blame] | 2352 | newIntent.putExtra("TONE", mStkContext[slotId].mCurrentCmd.getToneSettings()); |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2353 | newIntent.putExtra(SLOT_ID, slotId); |
| 2354 | newIntent.setData(uriData); |
| 2355 | startActivity(newIntent); |
| 2356 | } |
| 2357 | } |
| 2358 | |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2359 | private void handleStopTone(Message msg, int slotId) { |
| 2360 | int resId = 0; |
| 2361 | |
| 2362 | // Stop the play tone in following cases: |
| 2363 | // 1.OP_STOP_TONE: play tone timer expires. |
| 2364 | // 2.STOP_TONE_USER: user pressed the back key. |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 2365 | if (msg.what == OP_STOP_TONE) { |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2366 | resId = RES_ID_DONE; |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 2367 | } else if (msg.what == OP_STOP_TONE_USER) { |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2368 | resId = RES_ID_END_SESSION; |
| 2369 | } |
| 2370 | |
| 2371 | sendResponse(resId, slotId, true); |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 2372 | |
| 2373 | mServiceHandler.removeMessages(OP_STOP_TONE); |
| 2374 | mServiceHandler.removeMessages(OP_STOP_TONE_USER); |
| 2375 | |
Takanori Nakano | b82c875 | 2019-04-01 14:47:07 +0900 | [diff] [blame] | 2376 | if (mTonePlayer != null) { |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 2377 | mTonePlayer.stop(); |
| 2378 | mTonePlayer.release(); |
| 2379 | mTonePlayer = null; |
| 2380 | } |
| 2381 | if (mVibrator != null) { |
| 2382 | mVibrator.cancel(); |
| 2383 | mVibrator = null; |
| 2384 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2385 | } |
| 2386 | |
Yoshiaki Naka | fac708c | 2020-01-22 19:49:27 +0900 | [diff] [blame] | 2387 | boolean isNoTonePlaying() { |
| 2388 | return mTonePlayer == null ? true : false; |
| 2389 | } |
| 2390 | |
Takanori Nakano | 49b1272 | 2016-02-16 14:34:14 +0900 | [diff] [blame] | 2391 | private void launchOpenChannelDialog(final int slotId) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2392 | TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 2393 | if (msg == null) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2394 | CatLog.d(LOG_TAG, "msg is null, return here"); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 2395 | return; |
| 2396 | } |
| 2397 | |
| 2398 | msg.title = getResources().getString(R.string.stk_dialog_title); |
| 2399 | if (msg.text == null) { |
| 2400 | msg.text = getResources().getString(R.string.default_open_channel_msg); |
| 2401 | } |
| 2402 | |
| 2403 | final AlertDialog dialog = new AlertDialog.Builder(mContext) |
| 2404 | .setIconAttribute(android.R.attr.alertDialogIcon) |
| 2405 | .setTitle(msg.title) |
| 2406 | .setMessage(msg.text) |
| 2407 | .setCancelable(false) |
| 2408 | .setPositiveButton(getResources().getString(R.string.stk_dialog_accept), |
| 2409 | new DialogInterface.OnClickListener() { |
| 2410 | public void onClick(DialogInterface dialog, int which) { |
| 2411 | Bundle args = new Bundle(); |
| 2412 | args.putInt(RES_ID, RES_ID_CHOICE); |
| 2413 | args.putInt(CHOICE, YES); |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 2414 | sendResponse(args, slotId); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 2415 | } |
| 2416 | }) |
| 2417 | .setNegativeButton(getResources().getString(R.string.stk_dialog_reject), |
| 2418 | new DialogInterface.OnClickListener() { |
| 2419 | public void onClick(DialogInterface dialog, int which) { |
| 2420 | Bundle args = new Bundle(); |
| 2421 | args.putInt(RES_ID, RES_ID_CHOICE); |
| 2422 | args.putInt(CHOICE, NO); |
Yoshiaki Naka | b80f8ce | 2019-04-25 14:36:03 +0900 | [diff] [blame] | 2423 | sendResponse(args, slotId); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 2424 | } |
| 2425 | }) |
| 2426 | .create(); |
| 2427 | |
| 2428 | dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
| 2429 | if (!mContext.getResources().getBoolean( |
Sooraj Sasindran | 2b44d5b | 2020-01-29 15:17:48 -0800 | [diff] [blame] | 2430 | R.bool.config_sf_slowBlur)) { |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 2431 | dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
| 2432 | } |
| 2433 | |
| 2434 | dialog.show(); |
| 2435 | } |
| 2436 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2437 | private void launchTransientEventMessage(int slotId) { |
| 2438 | TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 2439 | if (msg == null) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2440 | CatLog.d(LOG_TAG, "msg is null, return here"); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 2441 | return; |
| 2442 | } |
| 2443 | |
| 2444 | msg.title = getResources().getString(R.string.stk_dialog_title); |
| 2445 | |
| 2446 | final AlertDialog dialog = new AlertDialog.Builder(mContext) |
| 2447 | .setIconAttribute(android.R.attr.alertDialogIcon) |
| 2448 | .setTitle(msg.title) |
| 2449 | .setMessage(msg.text) |
| 2450 | .setCancelable(false) |
| 2451 | .setPositiveButton(getResources().getString(android.R.string.ok), |
| 2452 | new DialogInterface.OnClickListener() { |
| 2453 | public void onClick(DialogInterface dialog, int which) { |
| 2454 | } |
| 2455 | }) |
| 2456 | .create(); |
| 2457 | |
| 2458 | dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
Sooraj Sasindran | 2b44d5b | 2020-01-29 15:17:48 -0800 | [diff] [blame] | 2459 | if (!mContext.getResources().getBoolean(R.bool.config_sf_slowBlur)) { |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 2460 | dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
| 2461 | } |
| 2462 | |
| 2463 | dialog.show(); |
| 2464 | } |
| 2465 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2466 | private int getNotificationId(int slotId) { |
| 2467 | int notifyId = STK_NOTIFICATION_ID; |
| 2468 | if (slotId >= 0 && slotId < mSimCount) { |
| 2469 | notifyId += slotId; |
| 2470 | } else { |
| 2471 | CatLog.d(LOG_TAG, "invalid slotId: " + slotId); |
| 2472 | } |
| 2473 | CatLog.d(LOG_TAG, "getNotificationId, slotId: " + slotId + ", notifyId: " + notifyId); |
| 2474 | return notifyId; |
| 2475 | } |
| 2476 | |
| 2477 | private String getItemName(int itemId, int slotId) { |
| 2478 | Menu menu = mStkContext[slotId].mCurrentCmd.getMenu(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2479 | if (menu == null) { |
| 2480 | return null; |
| 2481 | } |
| 2482 | for (Item item : menu.items) { |
| 2483 | if (item.id == itemId) { |
| 2484 | return item.text; |
| 2485 | } |
| 2486 | } |
| 2487 | return null; |
| 2488 | } |
| 2489 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2490 | private boolean removeMenu(int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2491 | try { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2492 | if (mStkContext[slotId].mCurrentMenu.items.size() == 1 && |
| 2493 | mStkContext[slotId].mCurrentMenu.items.get(0) == null) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2494 | return true; |
| 2495 | } |
| 2496 | } catch (NullPointerException e) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2497 | CatLog.d(LOG_TAG, "Unable to get Menu's items size"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2498 | return true; |
| 2499 | } |
| 2500 | return false; |
| 2501 | } |
Preeti Ahuja | 0f4cf2f | 2012-08-09 11:45:08 +0530 | [diff] [blame] | 2502 | |
Yoshiaki Naka | 58e0765 | 2019-04-26 17:58:52 +0900 | [diff] [blame] | 2503 | private boolean uninstallIfUnnecessary() { |
| 2504 | for (int slot = 0; slot < mSimCount; slot++) { |
| 2505 | if (mStkContext[slot].mMainCmd != null) { |
| 2506 | return false; |
| 2507 | } |
| 2508 | } |
| 2509 | CatLog.d(LOG_TAG, "Uninstall App"); |
| 2510 | StkAppInstaller.uninstall(this); |
| 2511 | return true; |
| 2512 | } |
| 2513 | |
Malcolm Chen | f961b65 | 2019-10-24 19:53:48 -0700 | [diff] [blame] | 2514 | synchronized StkContext getStkContext(int slotId) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 2515 | if (slotId >= 0 && slotId < mSimCount) { |
| 2516 | return mStkContext[slotId]; |
| 2517 | } else { |
| 2518 | CatLog.d(LOG_TAG, "invalid slotId: " + slotId); |
| 2519 | return null; |
| 2520 | } |
| 2521 | } |
Preeti Ahuja | 0f4cf2f | 2012-08-09 11:45:08 +0530 | [diff] [blame] | 2522 | |
| 2523 | private void handleAlphaNotify(Bundle args) { |
| 2524 | String alphaString = args.getString(AppInterface.ALPHA_STRING); |
| 2525 | |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 2526 | CatLog.d(LOG_TAG, "Alpha string received from card: " + alphaString); |
Preeti Ahuja | 0f4cf2f | 2012-08-09 11:45:08 +0530 | [diff] [blame] | 2527 | Toast toast = Toast.makeText(sInstance, alphaString, Toast.LENGTH_LONG); |
| 2528 | toast.setGravity(Gravity.TOP, 0, 0); |
| 2529 | toast.show(); |
| 2530 | } |
Srikanth Chintala | ba10300 | 2015-11-30 10:49:52 -0800 | [diff] [blame] | 2531 | |
| 2532 | private boolean isUrlAvailableToLaunchBrowser(BrowserSettings settings) { |
| 2533 | String url = SystemProperties.get(STK_BROWSER_DEFAULT_URL_SYSPROP, ""); |
| 2534 | if (url == "" && settings.url == null) { |
| 2535 | return false; |
| 2536 | } |
| 2537 | return true; |
| 2538 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 2539 | } |