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 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 19 | import android.app.ActivityManager; |
| 20 | import android.app.ActivityManager.RunningTaskInfo; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 21 | import android.app.AlertDialog; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 22 | import android.app.Notification; |
fionaxu | 2c91c75 | 2017-04-21 18:11:57 -0700 | [diff] [blame] | 23 | import android.app.NotificationChannel; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 24 | import android.app.NotificationManager; |
| 25 | import android.app.PendingIntent; |
| 26 | import android.app.Service; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 27 | import android.app.Activity; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 28 | import android.content.Context; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 29 | import android.content.DialogInterface; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 30 | import android.content.Intent; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 31 | import android.content.res.Configuration; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 32 | import android.content.res.Resources; |
| 33 | import android.content.res.Resources.NotFoundException; |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 34 | import android.graphics.Bitmap; |
| 35 | import android.graphics.BitmapFactory; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 36 | import android.net.Uri; |
| 37 | import android.os.Bundle; |
| 38 | import android.os.Handler; |
| 39 | import android.os.IBinder; |
| 40 | import android.os.Looper; |
| 41 | import android.os.Message; |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 42 | import android.os.PersistableBundle; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 43 | import android.os.PowerManager; |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 44 | import android.os.SystemProperties; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 45 | import android.os.Vibrator; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 46 | import android.provider.Settings; |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 47 | import android.telephony.CarrierConfigManager; |
Wink Saville | 56469d5 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 48 | import android.telephony.TelephonyManager; |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 49 | import android.text.TextUtils; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 50 | import android.view.Gravity; |
| 51 | import android.view.LayoutInflater; |
| 52 | import android.view.View; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 53 | import android.view.WindowManager; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 54 | import android.widget.ImageView; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 55 | import android.widget.TextView; |
| 56 | import android.widget.Toast; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 57 | import android.content.IntentFilter; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 58 | |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 59 | import com.android.internal.telephony.cat.AppInterface; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 60 | import com.android.internal.telephony.cat.LaunchBrowserMode; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 61 | import com.android.internal.telephony.cat.Menu; |
| 62 | import com.android.internal.telephony.cat.Item; |
| 63 | import com.android.internal.telephony.cat.ResultCode; |
| 64 | import com.android.internal.telephony.cat.CatCmdMessage; |
| 65 | import com.android.internal.telephony.cat.CatCmdMessage.BrowserSettings; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 66 | import com.android.internal.telephony.cat.CatCmdMessage.SetupEventListSettings; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 67 | import com.android.internal.telephony.cat.CatLog; |
| 68 | import com.android.internal.telephony.cat.CatResponseMessage; |
| 69 | import com.android.internal.telephony.cat.TextMessage; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 70 | import com.android.internal.telephony.cat.ToneSettings; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 71 | import com.android.internal.telephony.uicc.IccRefreshResponse; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 72 | import com.android.internal.telephony.PhoneConstants; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 73 | import com.android.internal.telephony.GsmAlphabet; |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 74 | import com.android.internal.telephony.cat.CatService; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 75 | |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 76 | import java.util.Iterator; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 77 | import java.util.LinkedList; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 78 | import java.lang.System; |
| 79 | import java.util.List; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 80 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 81 | import static com.android.internal.telephony.cat.CatCmdMessage. |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 82 | SetupEventListConstants.IDLE_SCREEN_AVAILABLE_EVENT; |
| 83 | import static com.android.internal.telephony.cat.CatCmdMessage. |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 84 | SetupEventListConstants.LANGUAGE_SELECTION_EVENT; |
| 85 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 86 | /** |
| 87 | * SIM toolkit application level service. Interacts with Telephopny messages, |
| 88 | * application's launch and user input from STK UI elements. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 89 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 90 | */ |
| 91 | public class StkAppService extends Service implements Runnable { |
| 92 | |
| 93 | // members |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 94 | protected class StkContext { |
| 95 | protected CatCmdMessage mMainCmd = null; |
| 96 | protected CatCmdMessage mCurrentCmd = null; |
| 97 | protected CatCmdMessage mCurrentMenuCmd = null; |
| 98 | protected Menu mCurrentMenu = null; |
| 99 | protected String lastSelectedItem = null; |
| 100 | protected boolean mMenuIsVisible = false; |
| 101 | protected boolean mIsInputPending = false; |
| 102 | protected boolean mIsMenuPending = false; |
| 103 | protected boolean mIsDialogPending = false; |
| 104 | protected boolean responseNeeded = true; |
| 105 | protected boolean launchBrowser = false; |
| 106 | protected BrowserSettings mBrowserSettings = null; |
| 107 | protected LinkedList<DelayedCmd> mCmdsQ = null; |
| 108 | protected boolean mCmdInProgress = false; |
| 109 | protected int mStkServiceState = STATE_UNKNOWN; |
| 110 | protected int mSetupMenuState = STATE_UNKNOWN; |
| 111 | protected int mMenuState = StkMenuActivity.STATE_INIT; |
| 112 | protected int mOpCode = -1; |
| 113 | private Activity mActivityInstance = null; |
| 114 | private Activity mDialogInstance = null; |
| 115 | private Activity mMainActivityInstance = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 116 | private int mSlotId = 0; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 117 | private SetupEventListSettings mSetupEventListSettings = null; |
| 118 | private boolean mClearSelectItem = false; |
| 119 | private boolean mDisplayTextDlgIsVisibile = false; |
| 120 | private CatCmdMessage mCurrentSetupEventCmd = null; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 121 | private CatCmdMessage mIdleModeTextCmd = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 122 | final synchronized void setPendingActivityInstance(Activity act) { |
| 123 | CatLog.d(this, "setPendingActivityInstance act : " + mSlotId + ", " + act); |
| 124 | callSetActivityInstMsg(OP_SET_ACT_INST, mSlotId, act); |
| 125 | } |
| 126 | final synchronized Activity getPendingActivityInstance() { |
| 127 | CatLog.d(this, "getPendingActivityInstance act : " + mSlotId + ", " + |
| 128 | mActivityInstance); |
| 129 | return mActivityInstance; |
| 130 | } |
| 131 | final synchronized void setPendingDialogInstance(Activity act) { |
| 132 | CatLog.d(this, "setPendingDialogInstance act : " + mSlotId + ", " + act); |
| 133 | callSetActivityInstMsg(OP_SET_DAL_INST, mSlotId, act); |
| 134 | } |
| 135 | final synchronized Activity getPendingDialogInstance() { |
| 136 | CatLog.d(this, "getPendingDialogInstance act : " + mSlotId + ", " + |
| 137 | mDialogInstance); |
| 138 | return mDialogInstance; |
| 139 | } |
| 140 | final synchronized void setMainActivityInstance(Activity act) { |
| 141 | CatLog.d(this, "setMainActivityInstance act : " + mSlotId + ", " + act); |
| 142 | callSetActivityInstMsg(OP_SET_MAINACT_INST, mSlotId, act); |
| 143 | } |
| 144 | final synchronized Activity getMainActivityInstance() { |
| 145 | CatLog.d(this, "getMainActivityInstance act : " + mSlotId + ", " + |
| 146 | mMainActivityInstance); |
| 147 | return mMainActivityInstance; |
| 148 | } |
| 149 | } |
| 150 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 151 | private volatile Looper mServiceLooper; |
| 152 | private volatile ServiceHandler mServiceHandler; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 153 | private Context mContext = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 154 | private NotificationManager mNotificationManager = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 155 | static StkAppService sInstance = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 156 | private AppInterface[] mStkService = null; |
| 157 | private StkContext[] mStkContext = null; |
| 158 | private int mSimCount = 0; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 159 | private PowerManager mPowerManager = null; |
| 160 | private StkCmdReceiver mStkCmdReceiver = null; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 161 | private TonePlayer mTonePlayer = null; |
| 162 | private Vibrator mVibrator = null; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 163 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 164 | // Used for setting FLAG_ACTIVITY_NO_USER_ACTION when |
| 165 | // creating an intent. |
| 166 | private enum InitiatedByUserAction { |
| 167 | yes, // The action was started via a user initiated action |
| 168 | unknown, // Not known for sure if user initated the action |
| 169 | } |
| 170 | |
| 171 | // constants |
| 172 | static final String OPCODE = "op"; |
| 173 | static final String CMD_MSG = "cmd message"; |
| 174 | static final String RES_ID = "response id"; |
| 175 | static final String MENU_SELECTION = "menu selection"; |
| 176 | static final String INPUT = "input"; |
| 177 | static final String HELP = "help"; |
| 178 | static final String CONFIRMATION = "confirm"; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 179 | static final String CHOICE = "choice"; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 180 | static final String SLOT_ID = "SLOT_ID"; |
| 181 | static final String STK_CMD = "STK CMD"; |
| 182 | static final String STK_DIALOG_URI = "stk://com.android.stk/dialog/"; |
| 183 | static final String STK_MENU_URI = "stk://com.android.stk/menu/"; |
| 184 | static final String STK_INPUT_URI = "stk://com.android.stk/input/"; |
| 185 | static final String STK_TONE_URI = "stk://com.android.stk/tone/"; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 186 | static final String FINISH_TONE_ACTIVITY_ACTION = |
| 187 | "android.intent.action.stk.finish_activity"; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 188 | |
| 189 | // These below constants are used for SETUP_EVENT_LIST |
| 190 | static final String SETUP_EVENT_TYPE = "event"; |
| 191 | static final String SETUP_EVENT_CAUSE = "cause"; |
| 192 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 193 | // operations ids for different service functionality. |
| 194 | static final int OP_CMD = 1; |
| 195 | static final int OP_RESPONSE = 2; |
| 196 | static final int OP_LAUNCH_APP = 3; |
| 197 | static final int OP_END_SESSION = 4; |
| 198 | static final int OP_BOOT_COMPLETED = 5; |
| 199 | private static final int OP_DELAYED_MSG = 6; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 200 | static final int OP_CARD_STATUS_CHANGED = 7; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 201 | static final int OP_SET_ACT_INST = 8; |
| 202 | static final int OP_SET_DAL_INST = 9; |
| 203 | static final int OP_SET_MAINACT_INST = 10; |
Preeti Ahuja | b3d0e61 | 2014-11-20 13:29:25 -0800 | [diff] [blame] | 204 | static final int OP_LOCALE_CHANGED = 11; |
| 205 | static final int OP_ALPHA_NOTIFY = 12; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 206 | static final int OP_IDLE_SCREEN = 13; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 207 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 208 | //Invalid SetupEvent |
| 209 | static final int INVALID_SETUP_EVENT = 0xFF; |
| 210 | |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 211 | // Message id to signal stop tone due to play tone timeout. |
| 212 | private static final int OP_STOP_TONE = 16; |
| 213 | |
| 214 | // Message id to signal stop tone on user keyback. |
| 215 | static final int OP_STOP_TONE_USER = 17; |
| 216 | |
| 217 | // Message id to remove stop tone message from queue. |
| 218 | private static final int STOP_TONE_WHAT = 100; |
| 219 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 220 | // Response ids |
| 221 | static final int RES_ID_MENU_SELECTION = 11; |
| 222 | static final int RES_ID_INPUT = 12; |
| 223 | static final int RES_ID_CONFIRM = 13; |
| 224 | static final int RES_ID_DONE = 14; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 225 | static final int RES_ID_CHOICE = 15; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 226 | |
| 227 | static final int RES_ID_TIMEOUT = 20; |
| 228 | static final int RES_ID_BACKWARD = 21; |
| 229 | static final int RES_ID_END_SESSION = 22; |
| 230 | static final int RES_ID_EXIT = 23; |
Srikanth Chintala | ba10300 | 2015-11-30 10:49:52 -0800 | [diff] [blame] | 231 | static final int RES_ID_ERROR = 24; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 232 | |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 233 | static final int YES = 1; |
| 234 | static final int NO = 0; |
| 235 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 236 | static final int STATE_UNKNOWN = -1; |
| 237 | static final int STATE_NOT_EXIST = 0; |
| 238 | static final int STATE_EXIST = 1; |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 239 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 240 | private static final String PACKAGE_NAME = "com.android.stk"; |
| 241 | private static final String STK_MENU_ACTIVITY_NAME = PACKAGE_NAME + ".StkMenuActivity"; |
| 242 | private static final String STK_INPUT_ACTIVITY_NAME = PACKAGE_NAME + ".StkInputActivity"; |
| 243 | 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] | 244 | // Notification id used to display Idle Mode text in NotificationManager. |
| 245 | private static final int STK_NOTIFICATION_ID = 333; |
fionaxu | 2c91c75 | 2017-04-21 18:11:57 -0700 | [diff] [blame] | 246 | // Notification channel containing all mobile service messages notifications. |
| 247 | private static final String STK_NOTIFICATION_CHANNEL_ID = "mobileServiceMessages"; |
| 248 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 249 | private static final String LOG_TAG = new Object(){}.getClass().getEnclosingClass().getName(); |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 250 | |
| 251 | // Inner class used for queuing telephony messages (proactive commands, |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 252 | // session end) while the service is busy processing a previous message. |
| 253 | private class DelayedCmd { |
| 254 | // members |
| 255 | int id; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 256 | CatCmdMessage msg; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 257 | int slotId; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 258 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 259 | DelayedCmd(int id, CatCmdMessage msg, int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 260 | this.id = id; |
| 261 | this.msg = msg; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 262 | this.slotId = slotId; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 266 | // system property to set the STK specific default url for launch browser proactive cmds |
| 267 | private static final String STK_BROWSER_DEFAULT_URL_SYSPROP = "persist.radio.stk.default_url"; |
| 268 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 269 | @Override |
| 270 | public void onCreate() { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 271 | CatLog.d(LOG_TAG, "onCreate()+"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 272 | // Initialize members |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 273 | int i = 0; |
| 274 | mContext = getBaseContext(); |
| 275 | mSimCount = TelephonyManager.from(mContext).getSimCount(); |
| 276 | CatLog.d(LOG_TAG, "simCount: " + mSimCount); |
| 277 | mStkService = new AppInterface[mSimCount]; |
| 278 | mStkContext = new StkContext[mSimCount]; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 279 | mPowerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); |
| 280 | mStkCmdReceiver = new StkCmdReceiver(); |
| 281 | registerReceiver(mStkCmdReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF)); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 282 | for (i = 0; i < mSimCount; i++) { |
| 283 | CatLog.d(LOG_TAG, "slotId: " + i); |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 284 | mStkService[i] = CatService.getInstance(i); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 285 | mStkContext[i] = new StkContext(); |
| 286 | mStkContext[i].mSlotId = i; |
| 287 | mStkContext[i].mCmdsQ = new LinkedList<DelayedCmd>(); |
| 288 | } |
| 289 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 290 | Thread serviceThread = new Thread(null, this, "Stk App Service"); |
| 291 | serviceThread.start(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 292 | mNotificationManager = (NotificationManager) mContext |
| 293 | .getSystemService(Context.NOTIFICATION_SERVICE); |
| 294 | sInstance = this; |
| 295 | } |
| 296 | |
| 297 | @Override |
| 298 | public void onStart(Intent intent, int startId) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 299 | if (intent == null) { |
| 300 | CatLog.d(LOG_TAG, "StkAppService onStart intent is null so return"); |
Banavathu, Srinivas Naik | 87cda96 | 2012-07-17 15:32:44 +0530 | [diff] [blame] | 301 | return; |
| 302 | } |
| 303 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 304 | Bundle args = intent.getExtras(); |
| 305 | if (args == null) { |
| 306 | CatLog.d(LOG_TAG, "StkAppService onStart args is null so return"); |
| 307 | return; |
| 308 | } |
| 309 | |
| 310 | int op = args.getInt(OPCODE); |
| 311 | int slotId = 0; |
| 312 | int i = 0; |
| 313 | if (op != OP_BOOT_COMPLETED) { |
| 314 | slotId = args.getInt(SLOT_ID); |
| 315 | } |
Cuihtlauac ALVARADO | bde7f03 | 2015-05-29 16:25:12 +0200 | [diff] [blame] | 316 | CatLog.d(LOG_TAG, "onStart sim id: " + slotId + ", op: " + op + ", *****"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 317 | if ((slotId >= 0 && slotId < mSimCount) && mStkService[slotId] == null) { |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 318 | mStkService[slotId] = CatService.getInstance(slotId); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 319 | if (mStkService[slotId] == null) { |
| 320 | CatLog.d(LOG_TAG, "mStkService is: " + mStkContext[slotId].mStkServiceState); |
| 321 | mStkContext[slotId].mStkServiceState = STATE_NOT_EXIST; |
| 322 | //Check other StkService state. |
| 323 | //If all StkServices are not available, stop itself and uninstall apk. |
| 324 | for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) { |
| 325 | if (i != slotId |
Tsukasa Goto | 029332b | 2016-10-05 17:12:06 +0900 | [diff] [blame] | 326 | && (mStkService[i] != null) |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 327 | && (mStkContext[i].mStkServiceState == STATE_UNKNOWN |
| 328 | || mStkContext[i].mStkServiceState == STATE_EXIST)) { |
| 329 | break; |
| 330 | } |
| 331 | } |
| 332 | } else { |
| 333 | mStkContext[slotId].mStkServiceState = STATE_EXIST; |
| 334 | } |
| 335 | if (i == mSimCount) { |
| 336 | stopSelf(); |
| 337 | StkAppInstaller.unInstall(mContext); |
| 338 | return; |
| 339 | } |
| 340 | } |
| 341 | |
Banavathu, Srinivas Naik | 87cda96 | 2012-07-17 15:32:44 +0530 | [diff] [blame] | 342 | waitForLooper(); |
John Wang | 62acae4 | 2009-10-08 11:20:23 -0700 | [diff] [blame] | 343 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 344 | Message msg = mServiceHandler.obtainMessage(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 345 | msg.arg1 = op; |
| 346 | msg.arg2 = slotId; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 347 | switch(msg.arg1) { |
| 348 | case OP_CMD: |
| 349 | msg.obj = args.getParcelable(CMD_MSG); |
| 350 | break; |
| 351 | case OP_RESPONSE: |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 352 | case OP_CARD_STATUS_CHANGED: |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 353 | case OP_LOCALE_CHANGED: |
Preeti Ahuja | 0f4cf2f | 2012-08-09 11:45:08 +0530 | [diff] [blame] | 354 | case OP_ALPHA_NOTIFY: |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 355 | case OP_IDLE_SCREEN: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 356 | msg.obj = args; |
| 357 | /* falls through */ |
| 358 | case OP_LAUNCH_APP: |
| 359 | case OP_END_SESSION: |
| 360 | case OP_BOOT_COMPLETED: |
| 361 | break; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 362 | case OP_STOP_TONE_USER: |
| 363 | msg.obj = args; |
| 364 | msg.what = STOP_TONE_WHAT; |
| 365 | break; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 366 | default: |
| 367 | return; |
| 368 | } |
| 369 | mServiceHandler.sendMessage(msg); |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public void onDestroy() { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 374 | CatLog.d(LOG_TAG, "onDestroy()"); |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 375 | if (mStkCmdReceiver != null) { |
| 376 | unregisterReceiver(mStkCmdReceiver); |
| 377 | mStkCmdReceiver = null; |
| 378 | } |
| 379 | mPowerManager = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 380 | waitForLooper(); |
| 381 | mServiceLooper.quit(); |
| 382 | } |
| 383 | |
| 384 | @Override |
| 385 | public IBinder onBind(Intent intent) { |
| 386 | return null; |
| 387 | } |
| 388 | |
| 389 | public void run() { |
| 390 | Looper.prepare(); |
| 391 | |
| 392 | mServiceLooper = Looper.myLooper(); |
| 393 | mServiceHandler = new ServiceHandler(); |
| 394 | |
| 395 | Looper.loop(); |
| 396 | } |
| 397 | |
| 398 | /* |
| 399 | * Package api used by StkMenuActivity to indicate if its on the foreground. |
| 400 | */ |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 401 | void indicateMenuVisibility(boolean visibility, int slotId) { |
| 402 | if (slotId >= 0 && slotId < mSimCount) { |
| 403 | mStkContext[slotId].mMenuIsVisible = visibility; |
| 404 | } |
| 405 | } |
| 406 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 407 | /* |
| 408 | * Package api used by StkDialogActivity to indicate if its on the foreground. |
| 409 | */ |
| 410 | void setDisplayTextDlgVisibility(boolean visibility, int slotId) { |
| 411 | if (slotId >= 0 && slotId < mSimCount) { |
| 412 | mStkContext[slotId].mDisplayTextDlgIsVisibile = visibility; |
| 413 | } |
| 414 | } |
| 415 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 416 | boolean isInputPending(int slotId) { |
| 417 | if (slotId >= 0 && slotId < mSimCount) { |
| 418 | CatLog.d(LOG_TAG, "isInputFinishBySrv: " + mStkContext[slotId].mIsInputPending); |
| 419 | return mStkContext[slotId].mIsInputPending; |
| 420 | } |
| 421 | return false; |
| 422 | } |
| 423 | |
| 424 | boolean isMenuPending(int slotId) { |
| 425 | if (slotId >= 0 && slotId < mSimCount) { |
| 426 | CatLog.d(LOG_TAG, "isMenuPending: " + mStkContext[slotId].mIsMenuPending); |
| 427 | return mStkContext[slotId].mIsMenuPending; |
| 428 | } |
| 429 | return false; |
| 430 | } |
| 431 | |
| 432 | boolean isDialogPending(int slotId) { |
| 433 | if (slotId >= 0 && slotId < mSimCount) { |
| 434 | CatLog.d(LOG_TAG, "isDialogPending: " + mStkContext[slotId].mIsDialogPending); |
| 435 | return mStkContext[slotId].mIsDialogPending; |
| 436 | } |
| 437 | return false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /* |
| 441 | * Package api used by StkMenuActivity to get its Menu parameter. |
| 442 | */ |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 443 | Menu getMenu(int slotId) { |
| 444 | CatLog.d(LOG_TAG, "StkAppService, getMenu, sim id: " + slotId); |
| 445 | if (slotId >=0 && slotId < mSimCount) { |
| 446 | return mStkContext[slotId].mCurrentMenu; |
| 447 | } else { |
| 448 | return null; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | /* |
| 453 | * Package api used by StkMenuActivity to get its Main Menu parameter. |
| 454 | */ |
| 455 | Menu getMainMenu(int slotId) { |
| 456 | CatLog.d(LOG_TAG, "StkAppService, getMainMenu, sim id: " + slotId); |
w30234 | a08cffe | 2015-02-04 15:13:25 -0800 | [diff] [blame] | 457 | if (slotId >=0 && slotId < mSimCount && (mStkContext[slotId].mMainCmd != null)) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 458 | return mStkContext[slotId].mMainCmd.getMenu(); |
| 459 | } else { |
| 460 | return null; |
| 461 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | /* |
| 465 | * Package api used by UI Activities and Dialogs to communicate directly |
| 466 | * with the service to deliver state information and parameters. |
| 467 | */ |
| 468 | static StkAppService getInstance() { |
| 469 | return sInstance; |
| 470 | } |
| 471 | |
| 472 | private void waitForLooper() { |
| 473 | while (mServiceHandler == null) { |
| 474 | synchronized (this) { |
| 475 | try { |
| 476 | wait(100); |
| 477 | } catch (InterruptedException e) { |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | private final class ServiceHandler extends Handler { |
| 484 | @Override |
| 485 | public void handleMessage(Message msg) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 486 | if(null == msg) { |
| 487 | CatLog.d(LOG_TAG, "ServiceHandler handleMessage msg is null"); |
| 488 | return; |
| 489 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 490 | int opcode = msg.arg1; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 491 | int slotId = msg.arg2; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 492 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 493 | CatLog.d(LOG_TAG, "handleMessage opcode[" + opcode + "], sim id[" + slotId + "]"); |
| 494 | if (opcode == OP_CMD && msg.obj != null && |
| 495 | ((CatCmdMessage)msg.obj).getCmdType()!= null) { |
| 496 | CatLog.d(LOG_TAG, "cmdName[" + ((CatCmdMessage)msg.obj).getCmdType().name() + "]"); |
| 497 | } |
| 498 | mStkContext[slotId].mOpCode = opcode; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 499 | switch (opcode) { |
| 500 | case OP_LAUNCH_APP: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 501 | if (mStkContext[slotId].mMainCmd == null) { |
| 502 | CatLog.d(LOG_TAG, "mMainCmd is null"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 503 | // nothing todo when no SET UP MENU command didn't arrive. |
| 504 | return; |
| 505 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 506 | CatLog.d(LOG_TAG, "handleMessage OP_LAUNCH_APP - mCmdInProgress[" + |
| 507 | mStkContext[slotId].mCmdInProgress + "]"); |
| 508 | |
| 509 | //If there is a pending activity for the slot id, |
| 510 | //just finish it and create a new one to handle the pending command. |
| 511 | cleanUpInstanceStackBySlot(slotId); |
| 512 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 513 | CatLog.d(LOG_TAG, "Current cmd type: " + |
| 514 | mStkContext[slotId].mCurrentCmd.getCmdType()); |
| 515 | //Restore the last command from stack by slot id. |
| 516 | restoreInstanceFromStackBySlot(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 517 | break; |
| 518 | case OP_CMD: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 519 | CatLog.d(LOG_TAG, "[OP_CMD]"); |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 520 | CatCmdMessage cmdMsg = (CatCmdMessage) msg.obj; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 521 | // There are two types of commands: |
| 522 | // 1. Interactive - user's response is required. |
| 523 | // 2. Informative - display a message, no interaction with the user. |
| 524 | // |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 525 | // Informative commands can be handled immediately without any delay. |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 526 | // Interactive commands can't override each other. So if a command |
| 527 | // is already in progress, we need to queue the next command until |
| 528 | // the user has responded or a timeout expired. |
| 529 | if (!isCmdInteractive(cmdMsg)) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 530 | handleCmd(cmdMsg, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 531 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 532 | if (!mStkContext[slotId].mCmdInProgress) { |
| 533 | mStkContext[slotId].mCmdInProgress = true; |
| 534 | handleCmd((CatCmdMessage) msg.obj, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 535 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 536 | CatLog.d(LOG_TAG, "[Interactive][in progress]"); |
| 537 | mStkContext[slotId].mCmdsQ.addLast(new DelayedCmd(OP_CMD, |
| 538 | (CatCmdMessage) msg.obj, slotId)); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | break; |
| 542 | case OP_RESPONSE: |
Preeti Ahuja | 414bc41 | 2013-06-25 19:31:49 -0700 | [diff] [blame] | 543 | handleCmdResponse((Bundle) msg.obj, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 544 | // call delayed commands if needed. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 545 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 546 | callDelayedMsg(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 547 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 548 | mStkContext[slotId].mCmdInProgress = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 549 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 550 | break; |
| 551 | case OP_END_SESSION: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 552 | if (!mStkContext[slotId].mCmdInProgress) { |
| 553 | mStkContext[slotId].mCmdInProgress = true; |
| 554 | handleSessionEnd(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 555 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 556 | mStkContext[slotId].mCmdsQ.addLast( |
| 557 | new DelayedCmd(OP_END_SESSION, null, slotId)); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 558 | } |
| 559 | break; |
| 560 | case OP_BOOT_COMPLETED: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 561 | CatLog.d(LOG_TAG, " OP_BOOT_COMPLETED"); |
| 562 | int i = 0; |
| 563 | for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) { |
| 564 | if (mStkContext[i].mMainCmd != null) { |
| 565 | break; |
| 566 | } |
| 567 | } |
| 568 | if (i == mSimCount) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 569 | StkAppInstaller.unInstall(mContext); |
| 570 | } |
| 571 | break; |
| 572 | case OP_DELAYED_MSG: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 573 | handleDelayedCmd(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 574 | break; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 575 | case OP_CARD_STATUS_CHANGED: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 576 | CatLog.d(LOG_TAG, "Card/Icc Status change received"); |
| 577 | handleCardStatusChangeAndIccRefresh((Bundle) msg.obj, slotId); |
| 578 | break; |
| 579 | case OP_SET_ACT_INST: |
| 580 | Activity act = new Activity(); |
| 581 | act = (Activity) msg.obj; |
| 582 | CatLog.d(LOG_TAG, "Set activity instance. " + act); |
| 583 | mStkContext[slotId].mActivityInstance = act; |
| 584 | break; |
| 585 | case OP_SET_DAL_INST: |
| 586 | Activity dal = new Activity(); |
| 587 | CatLog.d(LOG_TAG, "Set dialog instance. " + dal); |
| 588 | dal = (Activity) msg.obj; |
| 589 | mStkContext[slotId].mDialogInstance = dal; |
| 590 | break; |
| 591 | case OP_SET_MAINACT_INST: |
| 592 | Activity mainAct = new Activity(); |
| 593 | mainAct = (Activity) msg.obj; |
| 594 | CatLog.d(LOG_TAG, "Set activity instance. " + mainAct); |
| 595 | mStkContext[slotId].mMainActivityInstance = mainAct; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 596 | break; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 597 | case OP_LOCALE_CHANGED: |
| 598 | CatLog.d(this, "Locale Changed"); |
Yuta Ui | 1481b17 | 2016-02-03 15:34:31 +0900 | [diff] [blame] | 599 | for (int slot = PhoneConstants.SIM_ID_1; slot < mSimCount; slot++) { |
| 600 | checkForSetupEvent(LANGUAGE_SELECTION_EVENT, (Bundle) msg.obj, slot); |
| 601 | } |
fionaxu | 805eb57 | 2017-05-02 10:57:30 -0700 | [diff] [blame] | 602 | // rename all registered notification channels on locale change |
| 603 | createAllChannels(); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 604 | break; |
Preeti Ahuja | 0f4cf2f | 2012-08-09 11:45:08 +0530 | [diff] [blame] | 605 | case OP_ALPHA_NOTIFY: |
| 606 | handleAlphaNotify((Bundle) msg.obj); |
| 607 | break; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 608 | case OP_IDLE_SCREEN: |
| 609 | for (int slot = 0; slot < mSimCount; slot++) { |
| 610 | if (mStkContext[slot] != null) { |
| 611 | handleIdleScreen(slot); |
| 612 | } |
| 613 | } |
| 614 | break; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 615 | case OP_STOP_TONE_USER: |
| 616 | case OP_STOP_TONE: |
| 617 | CatLog.d(this, "Stop tone"); |
| 618 | handleStopTone(msg, slotId); |
| 619 | break; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 623 | private void handleCardStatusChangeAndIccRefresh(Bundle args, int slotId) { |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 624 | boolean cardStatus = args.getBoolean(AppInterface.CARD_STATUS); |
| 625 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 626 | CatLog.d(LOG_TAG, "CardStatus: " + cardStatus); |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 627 | if (cardStatus == false) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 628 | CatLog.d(LOG_TAG, "CARD is ABSENT"); |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 629 | // Uninstall STKAPP, Clear Idle text, Stop StkAppService |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 630 | mNotificationManager.cancel(getNotificationId(slotId)); |
Srikanth Chintala | 7c5a04c | 2016-09-22 19:05:01 +0530 | [diff] [blame] | 631 | mStkContext[slotId].mCurrentMenu = null; |
| 632 | mStkContext[slotId].mMainCmd = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 633 | if (isAllOtherCardsAbsent(slotId)) { |
| 634 | CatLog.d(LOG_TAG, "All CARDs are ABSENT"); |
| 635 | StkAppInstaller.unInstall(mContext); |
| 636 | stopSelf(); |
| 637 | } |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 638 | } else { |
| 639 | IccRefreshResponse state = new IccRefreshResponse(); |
| 640 | state.refreshResult = args.getInt(AppInterface.REFRESH_RESULT); |
| 641 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 642 | CatLog.d(LOG_TAG, "Icc Refresh Result: "+ state.refreshResult); |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 643 | if ((state.refreshResult == IccRefreshResponse.REFRESH_RESULT_INIT) || |
| 644 | (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET)) { |
| 645 | // Clear Idle Text |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 646 | mNotificationManager.cancel(getNotificationId(slotId)); |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | if (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET) { |
| 650 | // Uninstall STkmenu |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 651 | if (isAllOtherCardsAbsent(slotId)) { |
| 652 | StkAppInstaller.unInstall(mContext); |
| 653 | } |
| 654 | mStkContext[slotId].mCurrentMenu = null; |
| 655 | mStkContext[slotId].mMainCmd = null; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 656 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 660 | /* |
| 661 | * Check if all SIMs are absent except the id of slot equals "slotId". |
| 662 | */ |
| 663 | private boolean isAllOtherCardsAbsent(int slotId) { |
| 664 | TelephonyManager mTm = (TelephonyManager) mContext.getSystemService( |
| 665 | Context.TELEPHONY_SERVICE); |
| 666 | int i = 0; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 667 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 668 | for (i = 0; i < mSimCount; i++) { |
| 669 | if (i != slotId && mTm.hasIccCard(i)) { |
| 670 | break; |
| 671 | } |
| 672 | } |
| 673 | if (i == mSimCount) { |
| 674 | return true; |
| 675 | } else { |
| 676 | return false; |
| 677 | } |
| 678 | } |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 679 | |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 680 | /* |
| 681 | * If the device is not in an interactive state, we can assume |
| 682 | * that the screen is idle. |
| 683 | */ |
| 684 | private boolean isScreenIdle() { |
| 685 | return (!mPowerManager.isInteractive()); |
| 686 | } |
| 687 | |
| 688 | private void handleIdleScreen(int slotId) { |
| 689 | |
| 690 | // If the idle screen event is present in the list need to send the |
| 691 | // response to SIM. |
| 692 | CatLog.d(this, "Need to send IDLE SCREEN Available event to SIM"); |
| 693 | checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId); |
| 694 | |
| 695 | if (mStkContext[slotId].mIdleModeTextCmd != null) { |
| 696 | launchIdleText(slotId); |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | private void sendScreenBusyResponse(int slotId) { |
| 701 | if (mStkContext[slotId].mCurrentCmd == null) { |
| 702 | return; |
| 703 | } |
| 704 | CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd); |
| 705 | CatLog.d(this, "SCREEN_BUSY"); |
| 706 | resMsg.setResultCode(ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS); |
| 707 | mStkService[slotId].onCmdResponse(resMsg); |
| 708 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 709 | callDelayedMsg(slotId); |
| 710 | } else { |
| 711 | mStkContext[slotId].mCmdInProgress = false; |
| 712 | } |
| 713 | } |
| 714 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 715 | private void sendResponse(int resId, int slotId, boolean confirm) { |
| 716 | Message msg = mServiceHandler.obtainMessage(); |
| 717 | msg.arg1 = OP_RESPONSE; |
Takanori Nakano | 49b1272 | 2016-02-16 14:34:14 +0900 | [diff] [blame] | 718 | msg.arg2 = slotId; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 719 | Bundle args = new Bundle(); |
| 720 | args.putInt(StkAppService.RES_ID, resId); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 721 | args.putBoolean(StkAppService.CONFIRMATION, confirm); |
| 722 | msg.obj = args; |
| 723 | mServiceHandler.sendMessage(msg); |
| 724 | } |
| 725 | |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 726 | private boolean isCmdInteractive(CatCmdMessage cmd) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 727 | switch (cmd.getCmdType()) { |
| 728 | case SEND_DTMF: |
| 729 | case SEND_SMS: |
| 730 | case SEND_SS: |
| 731 | case SEND_USSD: |
| 732 | case SET_UP_IDLE_MODE_TEXT: |
| 733 | case SET_UP_MENU: |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 734 | case CLOSE_CHANNEL: |
| 735 | case RECEIVE_DATA: |
| 736 | case SEND_DATA: |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 737 | case SET_UP_EVENT_LIST: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 738 | return false; |
| 739 | } |
| 740 | |
| 741 | return true; |
| 742 | } |
| 743 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 744 | private void handleDelayedCmd(int slotId) { |
| 745 | CatLog.d(LOG_TAG, "handleDelayedCmd, slotId: " + slotId); |
| 746 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 747 | DelayedCmd cmd = mStkContext[slotId].mCmdsQ.poll(); |
| 748 | if (cmd != null) { |
| 749 | CatLog.d(LOG_TAG, "handleDelayedCmd - queue size: " + |
| 750 | mStkContext[slotId].mCmdsQ.size() + |
| 751 | " id: " + cmd.id + "sim id: " + cmd.slotId); |
| 752 | switch (cmd.id) { |
| 753 | case OP_CMD: |
| 754 | handleCmd(cmd.msg, cmd.slotId); |
| 755 | break; |
| 756 | case OP_END_SESSION: |
| 757 | handleSessionEnd(cmd.slotId); |
| 758 | break; |
| 759 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 760 | } |
| 761 | } |
| 762 | } |
| 763 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 764 | private void callDelayedMsg(int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 765 | Message msg = mServiceHandler.obtainMessage(); |
| 766 | msg.arg1 = OP_DELAYED_MSG; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 767 | msg.arg2 = slotId; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 768 | mServiceHandler.sendMessage(msg); |
| 769 | } |
| 770 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 771 | private void callSetActivityInstMsg(int inst_type, int slotId, Object obj) { |
| 772 | Message msg = mServiceHandler.obtainMessage(); |
| 773 | msg.obj = obj; |
| 774 | msg.arg1 = inst_type; |
| 775 | msg.arg2 = slotId; |
| 776 | mServiceHandler.sendMessage(msg); |
| 777 | } |
| 778 | |
| 779 | private void handleSessionEnd(int slotId) { |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 780 | // We should finish all pending activity if receiving END SESSION command. |
| 781 | cleanUpInstanceStackBySlot(slotId); |
| 782 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 783 | mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd; |
| 784 | CatLog.d(LOG_TAG, "[handleSessionEnd] - mCurrentCmd changed to mMainCmd!."); |
| 785 | mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mMainCmd; |
| 786 | CatLog.d(LOG_TAG, "slotId: " + slotId + ", mMenuState: " + |
| 787 | mStkContext[slotId].mMenuState); |
| 788 | |
| 789 | mStkContext[slotId].mIsInputPending = false; |
| 790 | mStkContext[slotId].mIsMenuPending = false; |
| 791 | mStkContext[slotId].mIsDialogPending = false; |
| 792 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 793 | if (mStkContext[slotId].mMainCmd == null) { |
| 794 | CatLog.d(LOG_TAG, "[handleSessionEnd][mMainCmd is null!]"); |
| 795 | } |
| 796 | mStkContext[slotId].lastSelectedItem = null; |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 797 | // 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] | 798 | // update the current menu member. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 799 | if (mStkContext[slotId].mCurrentMenu != null && mStkContext[slotId].mMainCmd != null) { |
| 800 | mStkContext[slotId].mCurrentMenu = mStkContext[slotId].mMainCmd.getMenu(); |
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 | CatLog.d(LOG_TAG, "[handleSessionEnd][mMenuState]" + mStkContext[slotId].mMenuIsVisible); |
| 803 | // In mutiple instance architecture, the main menu for slotId will be finished when user |
| 804 | // goes to the Stk menu of the other SIM. So, we should launch a new instance for the |
| 805 | // main menu if the main menu instance has been finished. |
| 806 | // If the current menu is secondary menu, we should launch main menu. |
| 807 | if (StkMenuActivity.STATE_SECONDARY == mStkContext[slotId].mMenuState) { |
| 808 | launchMenuActivity(null, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 809 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 810 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 811 | callDelayedMsg(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 812 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 813 | mStkContext[slotId].mCmdInProgress = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 814 | } |
| 815 | // In case a launch browser command was just confirmed, launch that url. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 816 | if (mStkContext[slotId].launchBrowser) { |
| 817 | mStkContext[slotId].launchBrowser = false; |
| 818 | launchBrowser(mStkContext[slotId].mBrowserSettings); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 819 | } |
| 820 | } |
| 821 | |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 822 | // returns true if any Stk related activity already has focus on the screen |
| 823 | private boolean isTopOfStack() { |
pkanwar | eab12f3 | 2017-02-06 08:35:03 -0800 | [diff] [blame] | 824 | ActivityManager mActivityManager = (ActivityManager) mContext |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 825 | .getSystemService(ACTIVITY_SERVICE); |
pkanwar | eab12f3 | 2017-02-06 08:35:03 -0800 | [diff] [blame] | 826 | String currentPackageName = null; |
| 827 | List<RunningTaskInfo> tasks = mActivityManager.getRunningTasks(1); |
| 828 | if (tasks == null || tasks.get(0).topActivity == null) { |
| 829 | return false; |
| 830 | } |
| 831 | currentPackageName = tasks.get(0).topActivity.getPackageName(); |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 832 | if (null != currentPackageName) { |
| 833 | return currentPackageName.equals(PACKAGE_NAME); |
| 834 | } |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 835 | return false; |
| 836 | } |
| 837 | |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 838 | /** |
| 839 | * Get the boolean config from carrier config manager. |
| 840 | * |
| 841 | * @param context the context to get carrier service |
| 842 | * @param key config key defined in CarrierConfigManager |
| 843 | * @return boolean value of corresponding key. |
| 844 | */ |
| 845 | private static boolean getBooleanCarrierConfig(Context context, String key) { |
| 846 | CarrierConfigManager configManager = (CarrierConfigManager) context.getSystemService( |
| 847 | Context.CARRIER_CONFIG_SERVICE); |
| 848 | PersistableBundle b = null; |
| 849 | if (configManager != null) { |
| 850 | b = configManager.getConfig(); |
| 851 | } |
| 852 | if (b != null) { |
| 853 | return b.getBoolean(key); |
| 854 | } else { |
| 855 | // Return static default defined in CarrierConfigManager. |
| 856 | return CarrierConfigManager.getDefaultConfig().getBoolean(key); |
| 857 | } |
| 858 | } |
| 859 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 860 | private void handleCmd(CatCmdMessage cmdMsg, int slotId) { |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 861 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 862 | if (cmdMsg == null) { |
| 863 | return; |
| 864 | } |
| 865 | // save local reference for state tracking. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 866 | mStkContext[slotId].mCurrentCmd = cmdMsg; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 867 | boolean waitForUsersResponse = true; |
| 868 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 869 | mStkContext[slotId].mIsInputPending = false; |
| 870 | mStkContext[slotId].mIsMenuPending = false; |
| 871 | mStkContext[slotId].mIsDialogPending = false; |
| 872 | |
| 873 | CatLog.d(LOG_TAG,"[handleCmd]" + cmdMsg.getCmdType().name()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 874 | switch (cmdMsg.getCmdType()) { |
| 875 | case DISPLAY_TEXT: |
| 876 | TextMessage msg = cmdMsg.geTextMessage(); |
Jeevaka Badrappan | 854a25c | 2012-12-01 16:32:03 +0200 | [diff] [blame] | 877 | waitForUsersResponse = msg.responseNeeded; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 878 | if (mStkContext[slotId].lastSelectedItem != null) { |
| 879 | msg.title = mStkContext[slotId].lastSelectedItem; |
| 880 | } else if (mStkContext[slotId].mMainCmd != null){ |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 881 | if (!getResources().getBoolean(R.bool.show_menu_title_only_on_menu)) { |
| 882 | msg.title = mStkContext[slotId].mMainCmd.getMenu().title; |
| 883 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 884 | } |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 885 | //If we receive a low priority Display Text and the device is |
| 886 | // not displaying any STK related activity and the screen is not idle |
| 887 | // ( that is, device is in an interactive state), then send a screen busy |
| 888 | // terminal response. Otherwise display the message. The existing |
| 889 | // displayed message shall be updated with the new display text |
| 890 | // proactive command (Refer to ETSI TS 102 384 section 27.22.4.1.4.4.2). |
| 891 | if (!(msg.isHighPriority || mStkContext[slotId].mMenuIsVisible |
| 892 | || mStkContext[slotId].mDisplayTextDlgIsVisibile || isTopOfStack())) { |
| 893 | if(!isScreenIdle()) { |
| 894 | CatLog.d(LOG_TAG, "Screen is not idle"); |
| 895 | sendScreenBusyResponse(slotId); |
| 896 | } else { |
| 897 | launchTextDialog(slotId); |
| 898 | } |
| 899 | } else { |
| 900 | launchTextDialog(slotId); |
| 901 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 902 | break; |
| 903 | case SELECT_ITEM: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 904 | CatLog.d(LOG_TAG, "SELECT_ITEM +"); |
| 905 | mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd; |
| 906 | mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu(); |
| 907 | launchMenuActivity(cmdMsg.getMenu(), slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 908 | break; |
| 909 | case SET_UP_MENU: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 910 | mStkContext[slotId].mCmdInProgress = false; |
| 911 | mStkContext[slotId].mMainCmd = mStkContext[slotId].mCurrentCmd; |
| 912 | mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd; |
| 913 | mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu(); |
| 914 | CatLog.d(LOG_TAG, "SET_UP_MENU [" + removeMenu(slotId) + "]"); |
| 915 | |
| 916 | if (removeMenu(slotId)) { |
| 917 | int i = 0; |
| 918 | CatLog.d(LOG_TAG, "removeMenu() - Uninstall App"); |
| 919 | mStkContext[slotId].mCurrentMenu = null; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 920 | mStkContext[slotId].mMainCmd = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 921 | //Check other setup menu state. If all setup menu are removed, uninstall apk. |
| 922 | for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) { |
| 923 | if (i != slotId |
Ryuto Sawada | f51e5e0 | 2016-11-25 17:12:49 +0900 | [diff] [blame] | 924 | && (mStkContext[i].mSetupMenuState == STATE_UNKNOWN |
| 925 | || mStkContext[i].mSetupMenuState == STATE_EXIST)) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 926 | CatLog.d(LOG_TAG, "Not Uninstall App:" + i + "," |
Ryuto Sawada | f51e5e0 | 2016-11-25 17:12:49 +0900 | [diff] [blame] | 927 | + mStkContext[i].mSetupMenuState); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 928 | break; |
| 929 | } |
| 930 | } |
| 931 | if (i == mSimCount) { |
| 932 | StkAppInstaller.unInstall(mContext); |
| 933 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 934 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 935 | CatLog.d(LOG_TAG, "install App"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 936 | StkAppInstaller.install(mContext); |
| 937 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 938 | if (mStkContext[slotId].mMenuIsVisible) { |
| 939 | launchMenuActivity(null, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 940 | } |
| 941 | break; |
| 942 | case GET_INPUT: |
| 943 | case GET_INKEY: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 944 | launchInputActivity(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 945 | break; |
| 946 | case SET_UP_IDLE_MODE_TEXT: |
| 947 | waitForUsersResponse = false; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 948 | mStkContext[slotId].mIdleModeTextCmd = mStkContext[slotId].mCurrentCmd; |
| 949 | TextMessage idleModeText = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
| 950 | if (idleModeText == null) { |
| 951 | launchIdleText(slotId); |
| 952 | mStkContext[slotId].mIdleModeTextCmd = null; |
| 953 | } |
| 954 | mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd; |
| 955 | if ((mStkContext[slotId].mIdleModeTextCmd != null) && isScreenIdle()) { |
| 956 | CatLog.d(this, "set up idle mode"); |
| 957 | launchIdleText(slotId); |
| 958 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 959 | break; |
| 960 | case SEND_DTMF: |
| 961 | case SEND_SMS: |
| 962 | case SEND_SS: |
| 963 | case SEND_USSD: |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 964 | case GET_CHANNEL_STATUS: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 965 | waitForUsersResponse = false; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 966 | launchEventMessage(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 967 | break; |
| 968 | case LAUNCH_BROWSER: |
Ryuto Sawada | 0bdc719 | 2016-04-18 12:10:56 +0900 | [diff] [blame] | 969 | // The device setup process should not be interrupted by launching browser. |
| 970 | if (Settings.Global.getInt(mContext.getContentResolver(), |
| 971 | Settings.Global.DEVICE_PROVISIONED, 0) == 0) { |
| 972 | CatLog.d(this, "The command is not performed if the setup has not been completed."); |
| 973 | sendScreenBusyResponse(slotId); |
| 974 | break; |
| 975 | } |
Sooraj Sasindran | a416047 | 2016-10-12 16:28:25 -0700 | [diff] [blame] | 976 | |
| 977 | /* Check if Carrier would not want to launch browser */ |
| 978 | if (getBooleanCarrierConfig(mContext, |
| 979 | CarrierConfigManager.KEY_STK_DISABLE_LAUNCH_BROWSER_BOOL)) { |
| 980 | CatLog.d(this, "Browser is not launched as per carrier."); |
| 981 | sendResponse(RES_ID_DONE, slotId, true); |
| 982 | break; |
| 983 | } |
| 984 | |
Srikanth Chintala | ba10300 | 2015-11-30 10:49:52 -0800 | [diff] [blame] | 985 | mStkContext[slotId].mBrowserSettings = |
| 986 | mStkContext[slotId].mCurrentCmd.getBrowserSettings(); |
| 987 | if (!isUrlAvailableToLaunchBrowser(mStkContext[slotId].mBrowserSettings)) { |
| 988 | CatLog.d(this, "Browser url property is not set - send error"); |
| 989 | sendResponse(RES_ID_ERROR, slotId, true); |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 990 | } else { |
Srikanth Chintala | ba10300 | 2015-11-30 10:49:52 -0800 | [diff] [blame] | 991 | TextMessage alphaId = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
| 992 | if ((alphaId == null) || TextUtils.isEmpty(alphaId.text)) { |
| 993 | // don't need user confirmation in this case |
| 994 | // just launch the browser or spawn a new tab |
| 995 | CatLog.d(this, "user confirmation is not currently needed.\n" + |
| 996 | "supressing confirmation dialogue and confirming silently..."); |
| 997 | mStkContext[slotId].launchBrowser = true; |
| 998 | sendResponse(RES_ID_CONFIRM, slotId, true); |
| 999 | } else { |
| 1000 | launchConfirmationDialog(alphaId, slotId); |
| 1001 | } |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 1002 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1003 | break; |
| 1004 | case SET_UP_CALL: |
Preeti Ahuja | dd24010 | 2013-08-30 17:25:06 -0700 | [diff] [blame] | 1005 | TextMessage mesg = mStkContext[slotId].mCurrentCmd.getCallSettings().confirmMsg; |
| 1006 | if((mesg != null) && (mesg.text == null || mesg.text.length() == 0)) { |
| 1007 | mesg.text = getResources().getString(R.string.default_setup_call_msg); |
| 1008 | } |
| 1009 | CatLog.d(this, "SET_UP_CALL mesg.text " + mesg.text); |
| 1010 | launchConfirmationDialog(mesg, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1011 | break; |
| 1012 | case PLAY_TONE: |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 1013 | handlePlayTone(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1014 | break; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1015 | case OPEN_CHANNEL: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1016 | launchOpenChannelDialog(slotId); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1017 | break; |
| 1018 | case CLOSE_CHANNEL: |
| 1019 | case RECEIVE_DATA: |
| 1020 | case SEND_DATA: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1021 | TextMessage m = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1022 | |
| 1023 | if ((m != null) && (m.text == null)) { |
| 1024 | switch(cmdMsg.getCmdType()) { |
| 1025 | case CLOSE_CHANNEL: |
| 1026 | m.text = getResources().getString(R.string.default_close_channel_msg); |
| 1027 | break; |
| 1028 | case RECEIVE_DATA: |
| 1029 | m.text = getResources().getString(R.string.default_receive_data_msg); |
| 1030 | break; |
| 1031 | case SEND_DATA: |
| 1032 | m.text = getResources().getString(R.string.default_send_data_msg); |
| 1033 | break; |
| 1034 | } |
| 1035 | } |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1036 | /* |
| 1037 | * Display indication in the form of a toast to the user if required. |
| 1038 | */ |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1039 | launchEventMessage(slotId); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1040 | break; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1041 | case SET_UP_EVENT_LIST: |
| 1042 | mStkContext[slotId].mSetupEventListSettings = |
| 1043 | mStkContext[slotId].mCurrentCmd.getSetEventList(); |
| 1044 | mStkContext[slotId].mCurrentSetupEventCmd = mStkContext[slotId].mCurrentCmd; |
| 1045 | mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1046 | if (isScreenIdle()) { |
| 1047 | CatLog.d(this," Check if IDLE_SCREEN_AVAILABLE_EVENT is present in List"); |
| 1048 | checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId); |
| 1049 | } |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1050 | break; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | if (!waitForUsersResponse) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1054 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 1055 | callDelayedMsg(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1056 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1057 | mStkContext[slotId].mCmdInProgress = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | } |
| 1061 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1062 | private void handleCmdResponse(Bundle args, int slotId) { |
| 1063 | CatLog.d(LOG_TAG, "handleCmdResponse, sim id: " + slotId); |
| 1064 | if (mStkContext[slotId].mCurrentCmd == null) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1065 | return; |
| 1066 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1067 | |
| 1068 | if (mStkService[slotId] == null) { |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 1069 | mStkService[slotId] = CatService.getInstance(slotId); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1070 | if (mStkService[slotId] == null) { |
Alex Yakavenka | d8e2ecd | 2012-04-20 17:10:15 -0700 | [diff] [blame] | 1071 | // This should never happen (we should be responding only to a message |
| 1072 | // that arrived from StkService). It has to exist by this time |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1073 | CatLog.d(LOG_TAG, "Exception! mStkService is null when we need to send response."); |
Alex Yakavenka | d8e2ecd | 2012-04-20 17:10:15 -0700 | [diff] [blame] | 1074 | throw new RuntimeException("mStkService is null when we need to send response"); |
| 1075 | } |
| 1076 | } |
| 1077 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1078 | CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1079 | |
| 1080 | // set result code |
| 1081 | boolean helpRequired = args.getBoolean(HELP, false); |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1082 | boolean confirmed = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1083 | |
| 1084 | switch(args.getInt(RES_ID)) { |
| 1085 | case RES_ID_MENU_SELECTION: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1086 | CatLog.d(LOG_TAG, "MENU_SELECTION=" + mStkContext[slotId]. |
| 1087 | mCurrentMenuCmd.getCmdType()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1088 | int menuSelection = args.getInt(MENU_SELECTION); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1089 | switch(mStkContext[slotId].mCurrentMenuCmd.getCmdType()) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1090 | case SET_UP_MENU: |
| 1091 | case SELECT_ITEM: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1092 | mStkContext[slotId].lastSelectedItem = getItemName(menuSelection, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1093 | if (helpRequired) { |
| 1094 | resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED); |
| 1095 | } else { |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 1096 | resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ? |
| 1097 | ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1098 | } |
| 1099 | resMsg.setMenuSelection(menuSelection); |
| 1100 | break; |
| 1101 | } |
| 1102 | break; |
| 1103 | case RES_ID_INPUT: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1104 | CatLog.d(LOG_TAG, "RES_ID_INPUT"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1105 | String input = args.getString(INPUT); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1106 | if (input != null && (null != mStkContext[slotId].mCurrentCmd.geInput()) && |
| 1107 | (mStkContext[slotId].mCurrentCmd.geInput().yesNo)) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1108 | boolean yesNoSelection = input |
| 1109 | .equals(StkInputActivity.YES_STR_RESPONSE); |
| 1110 | resMsg.setYesNo(yesNoSelection); |
| 1111 | } else { |
| 1112 | if (helpRequired) { |
| 1113 | resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED); |
| 1114 | } else { |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 1115 | resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ? |
| 1116 | ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1117 | resMsg.setInput(input); |
| 1118 | } |
| 1119 | } |
| 1120 | break; |
| 1121 | case RES_ID_CONFIRM: |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 1122 | CatLog.d(this, "RES_ID_CONFIRM"); |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1123 | confirmed = args.getBoolean(CONFIRMATION); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1124 | switch (mStkContext[slotId].mCurrentCmd.getCmdType()) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1125 | case DISPLAY_TEXT: |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 1126 | if (confirmed) { |
| 1127 | resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ? |
| 1128 | ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK); |
| 1129 | } else { |
| 1130 | resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER); |
| 1131 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1132 | break; |
| 1133 | case LAUNCH_BROWSER: |
| 1134 | resMsg.setResultCode(confirmed ? ResultCode.OK |
| 1135 | : ResultCode.UICC_SESSION_TERM_BY_USER); |
| 1136 | if (confirmed) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1137 | mStkContext[slotId].launchBrowser = true; |
| 1138 | mStkContext[slotId].mBrowserSettings = |
| 1139 | mStkContext[slotId].mCurrentCmd.getBrowserSettings(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1140 | } |
| 1141 | break; |
| 1142 | case SET_UP_CALL: |
| 1143 | resMsg.setResultCode(ResultCode.OK); |
| 1144 | resMsg.setConfirmation(confirmed); |
| 1145 | if (confirmed) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1146 | launchEventMessage(slotId, |
| 1147 | mStkContext[slotId].mCurrentCmd.getCallSettings().callMsg); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1148 | } |
| 1149 | break; |
| 1150 | } |
| 1151 | break; |
| 1152 | case RES_ID_DONE: |
| 1153 | resMsg.setResultCode(ResultCode.OK); |
| 1154 | break; |
| 1155 | case RES_ID_BACKWARD: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1156 | CatLog.d(LOG_TAG, "RES_ID_BACKWARD"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1157 | resMsg.setResultCode(ResultCode.BACKWARD_MOVE_BY_USER); |
| 1158 | break; |
| 1159 | case RES_ID_END_SESSION: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1160 | CatLog.d(LOG_TAG, "RES_ID_END_SESSION"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1161 | resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER); |
| 1162 | break; |
| 1163 | case RES_ID_TIMEOUT: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1164 | CatLog.d(LOG_TAG, "RES_ID_TIMEOUT"); |
Naveen Kalla | d517689 | 2009-11-30 12:45:29 -0800 | [diff] [blame] | 1165 | // GCF test-case 27.22.4.1.1 Expected Sequence 1.5 (DISPLAY TEXT, |
| 1166 | // Clear message after delay, successful) expects result code OK. |
| 1167 | // If the command qualifier specifies no user response is required |
| 1168 | // then send OK instead of NO_RESPONSE_FROM_USER |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1169 | if ((mStkContext[slotId].mCurrentCmd.getCmdType().value() == |
| 1170 | AppInterface.CommandType.DISPLAY_TEXT.value()) |
| 1171 | && (mStkContext[slotId].mCurrentCmd.geTextMessage().userClear == false)) { |
Naveen Kalla | d517689 | 2009-11-30 12:45:29 -0800 | [diff] [blame] | 1172 | resMsg.setResultCode(ResultCode.OK); |
| 1173 | } else { |
| 1174 | resMsg.setResultCode(ResultCode.NO_RESPONSE_FROM_USER); |
| 1175 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1176 | break; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1177 | case RES_ID_CHOICE: |
| 1178 | int choice = args.getInt(CHOICE); |
| 1179 | CatLog.d(this, "User Choice=" + choice); |
| 1180 | switch (choice) { |
| 1181 | case YES: |
| 1182 | resMsg.setResultCode(ResultCode.OK); |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1183 | confirmed = true; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1184 | break; |
| 1185 | case NO: |
| 1186 | resMsg.setResultCode(ResultCode.USER_NOT_ACCEPT); |
| 1187 | break; |
| 1188 | } |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1189 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1190 | if (mStkContext[slotId].mCurrentCmd.getCmdType().value() == |
| 1191 | AppInterface.CommandType.OPEN_CHANNEL.value()) { |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1192 | resMsg.setConfirmation(confirmed); |
| 1193 | } |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1194 | break; |
Srikanth Chintala | ba10300 | 2015-11-30 10:49:52 -0800 | [diff] [blame] | 1195 | case RES_ID_ERROR: |
| 1196 | CatLog.d(LOG_TAG, "RES_ID_ERROR"); |
| 1197 | switch (mStkContext[slotId].mCurrentCmd.getCmdType()) { |
| 1198 | case LAUNCH_BROWSER: |
| 1199 | resMsg.setResultCode(ResultCode.LAUNCH_BROWSER_ERROR); |
| 1200 | break; |
| 1201 | } |
| 1202 | break; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1203 | default: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1204 | CatLog.d(LOG_TAG, "Unknown result id"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1205 | return; |
| 1206 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1207 | |
| 1208 | if (null != mStkContext[slotId].mCurrentCmd && |
| 1209 | null != mStkContext[slotId].mCurrentCmd.getCmdType()) { |
| 1210 | CatLog.d(LOG_TAG, "handleCmdResponse- cmdName[" + |
| 1211 | mStkContext[slotId].mCurrentCmd.getCmdType().name() + "]"); |
| 1212 | } |
| 1213 | mStkService[slotId].onCmdResponse(resMsg); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | /** |
| 1217 | * Returns 0 or FLAG_ACTIVITY_NO_USER_ACTION, 0 means the user initiated the action. |
| 1218 | * |
| 1219 | * @param userAction If the userAction is yes then we always return 0 otherwise |
| 1220 | * mMenuIsVisible is used to determine what to return. If mMenuIsVisible is true |
| 1221 | * then we are the foreground app and we'll return 0 as from our perspective a |
| 1222 | * user action did cause. If it's false than we aren't the foreground app and |
| 1223 | * FLAG_ACTIVITY_NO_USER_ACTION is returned. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 1224 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1225 | * @return 0 or FLAG_ACTIVITY_NO_USER_ACTION |
| 1226 | */ |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1227 | private int getFlagActivityNoUserAction(InitiatedByUserAction userAction, int slotId) { |
| 1228 | return ((userAction == InitiatedByUserAction.yes) | mStkContext[slotId].mMenuIsVisible) |
| 1229 | ? 0 : Intent.FLAG_ACTIVITY_NO_USER_ACTION; |
| 1230 | } |
| 1231 | /** |
| 1232 | * This method is used for cleaning up pending instances in stack. |
| 1233 | */ |
| 1234 | private void cleanUpInstanceStackBySlot(int slotId) { |
| 1235 | Activity activity = mStkContext[slotId].getPendingActivityInstance(); |
| 1236 | Activity dialog = mStkContext[slotId].getPendingDialogInstance(); |
| 1237 | CatLog.d(LOG_TAG, "cleanUpInstanceStackBySlot slotId: " + slotId); |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 1238 | if (mStkContext[slotId].mCurrentCmd == null) { |
| 1239 | CatLog.d(LOG_TAG, "current cmd is null."); |
| 1240 | return; |
| 1241 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1242 | if (activity != null) { |
| 1243 | CatLog.d(LOG_TAG, "current cmd type: " + |
| 1244 | mStkContext[slotId].mCurrentCmd.getCmdType()); |
| 1245 | if (mStkContext[slotId].mCurrentCmd.getCmdType().value() == |
| 1246 | AppInterface.CommandType.GET_INPUT.value() || |
| 1247 | mStkContext[slotId].mCurrentCmd.getCmdType().value() == |
| 1248 | AppInterface.CommandType.GET_INKEY.value()) { |
| 1249 | mStkContext[slotId].mIsInputPending = true; |
| 1250 | } else if (mStkContext[slotId].mCurrentCmd.getCmdType().value() == |
| 1251 | AppInterface.CommandType.SET_UP_MENU.value() || |
| 1252 | mStkContext[slotId].mCurrentCmd.getCmdType().value() == |
| 1253 | AppInterface.CommandType.SELECT_ITEM.value()) { |
| 1254 | mStkContext[slotId].mIsMenuPending = true; |
| 1255 | } else { |
| 1256 | } |
| 1257 | CatLog.d(LOG_TAG, "finish pending activity."); |
| 1258 | activity.finish(); |
| 1259 | mStkContext[slotId].mActivityInstance = null; |
| 1260 | } |
| 1261 | if (dialog != null) { |
| 1262 | CatLog.d(LOG_TAG, "finish pending dialog."); |
| 1263 | mStkContext[slotId].mIsDialogPending = true; |
| 1264 | dialog.finish(); |
| 1265 | mStkContext[slotId].mDialogInstance = null; |
| 1266 | } |
| 1267 | } |
| 1268 | /** |
| 1269 | * This method is used for restoring pending instances from stack. |
| 1270 | */ |
| 1271 | private void restoreInstanceFromStackBySlot(int slotId) { |
| 1272 | AppInterface.CommandType cmdType = mStkContext[slotId].mCurrentCmd.getCmdType(); |
| 1273 | |
| 1274 | CatLog.d(LOG_TAG, "restoreInstanceFromStackBySlot cmdType : " + cmdType); |
| 1275 | switch(cmdType) { |
| 1276 | case GET_INPUT: |
| 1277 | case GET_INKEY: |
| 1278 | launchInputActivity(slotId); |
| 1279 | //Set mMenuIsVisible to true for showing main menu for |
| 1280 | //following session end command. |
| 1281 | mStkContext[slotId].mMenuIsVisible = true; |
| 1282 | break; |
| 1283 | case DISPLAY_TEXT: |
| 1284 | launchTextDialog(slotId); |
| 1285 | break; |
| 1286 | case LAUNCH_BROWSER: |
| 1287 | launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.geTextMessage(), |
| 1288 | slotId); |
| 1289 | break; |
| 1290 | case OPEN_CHANNEL: |
| 1291 | launchOpenChannelDialog(slotId); |
| 1292 | break; |
| 1293 | case SET_UP_CALL: |
| 1294 | launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.getCallSettings(). |
| 1295 | confirmMsg, slotId); |
| 1296 | break; |
| 1297 | case SET_UP_MENU: |
| 1298 | case SELECT_ITEM: |
| 1299 | launchMenuActivity(null, slotId); |
| 1300 | break; |
| 1301 | default: |
| 1302 | break; |
| 1303 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1304 | } |
| 1305 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1306 | private void launchMenuActivity(Menu menu, int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1307 | Intent newIntent = new Intent(Intent.ACTION_VIEW); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1308 | String targetActivity = STK_MENU_ACTIVITY_NAME; |
| 1309 | String uriString = STK_MENU_URI + System.currentTimeMillis(); |
| 1310 | //Set unique URI to create a new instance of activity for different slotId. |
| 1311 | Uri uriData = Uri.parse(uriString); |
| 1312 | |
| 1313 | CatLog.d(LOG_TAG, "launchMenuActivity, slotId: " + slotId + " , " + |
| 1314 | uriData.toString() + " , " + mStkContext[slotId].mOpCode + ", " |
| 1315 | + mStkContext[slotId].mMenuState); |
| 1316 | newIntent.setClassName(PACKAGE_NAME, targetActivity); |
| 1317 | int intentFlags = Intent.FLAG_ACTIVITY_NEW_TASK; |
| 1318 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1319 | if (menu == null) { |
| 1320 | // 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] | 1321 | intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.yes, slotId); |
| 1322 | if (mStkContext[slotId].mOpCode == OP_END_SESSION) { |
| 1323 | CatLog.d(LOG_TAG, "launchMenuActivity, return OP_END_SESSION"); |
| 1324 | mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN; |
| 1325 | if (mStkContext[slotId].mMainActivityInstance != null) { |
| 1326 | CatLog.d(LOG_TAG, "launchMenuActivity, mMainActivityInstance is not null"); |
| 1327 | return; |
| 1328 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1329 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1330 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1331 | //If the last pending menu is secondary menu, "STATE" should be "STATE_SECONDARY". |
| 1332 | //Otherwise, it should be "STATE_MAIN". |
| 1333 | if (mStkContext[slotId].mOpCode == OP_LAUNCH_APP && |
| 1334 | mStkContext[slotId].mMenuState == StkMenuActivity.STATE_SECONDARY) { |
| 1335 | newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY); |
| 1336 | } else { |
| 1337 | newIntent.putExtra("STATE", StkMenuActivity.STATE_MAIN); |
| 1338 | mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN; |
| 1339 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1340 | } else { |
| 1341 | // We don't know and we'll let getFlagActivityNoUserAction decide. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1342 | intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1343 | newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1344 | mStkContext[slotId].mMenuState = StkMenuActivity.STATE_SECONDARY; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1345 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1346 | newIntent.putExtra(SLOT_ID, slotId); |
| 1347 | newIntent.setData(uriData); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1348 | newIntent.setFlags(intentFlags); |
| 1349 | mContext.startActivity(newIntent); |
| 1350 | } |
| 1351 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1352 | private void launchInputActivity(int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1353 | Intent newIntent = new Intent(Intent.ACTION_VIEW); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1354 | String targetActivity = STK_INPUT_ACTIVITY_NAME; |
| 1355 | String uriString = STK_INPUT_URI + System.currentTimeMillis(); |
| 1356 | //Set unique URI to create a new instance of activity for different slotId. |
| 1357 | Uri uriData = Uri.parse(uriString); |
| 1358 | |
| 1359 | CatLog.d(LOG_TAG, "launchInputActivity, slotId: " + slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1360 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1361 | | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); |
| 1362 | newIntent.setClassName(PACKAGE_NAME, targetActivity); |
| 1363 | newIntent.putExtra("INPUT", mStkContext[slotId].mCurrentCmd.geInput()); |
| 1364 | newIntent.putExtra(SLOT_ID, slotId); |
| 1365 | newIntent.setData(uriData); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1366 | mContext.startActivity(newIntent); |
| 1367 | } |
| 1368 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1369 | private void launchTextDialog(int slotId) { |
| 1370 | CatLog.d(LOG_TAG, "launchTextDialog, slotId: " + slotId); |
| 1371 | Intent newIntent = new Intent(); |
| 1372 | String targetActivity = STK_DIALOG_ACTIVITY_NAME; |
| 1373 | int action = getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId); |
| 1374 | String uriString = STK_DIALOG_URI + System.currentTimeMillis(); |
| 1375 | //Set unique URI to create a new instance of activity for different slotId. |
| 1376 | Uri uriData = Uri.parse(uriString); |
| 1377 | if (newIntent != null) { |
| 1378 | newIntent.setClassName(PACKAGE_NAME, targetActivity); |
| 1379 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1380 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 1381 | | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); |
| 1382 | newIntent.setData(uriData); |
| 1383 | newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage()); |
| 1384 | newIntent.putExtra(SLOT_ID, slotId); |
| 1385 | startActivity(newIntent); |
Preeti Ahuja | 414bc41 | 2013-06-25 19:31:49 -0700 | [diff] [blame] | 1386 | // For display texts with immediate response, send the terminal response |
| 1387 | // immediately. responseNeeded will be false, if display text command has |
| 1388 | // the immediate response tlv. |
| 1389 | if (!mStkContext[slotId].mCurrentCmd.geTextMessage().responseNeeded) { |
| 1390 | sendResponse(RES_ID_CONFIRM, slotId, true); |
| 1391 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1392 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1393 | } |
| 1394 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1395 | public boolean isStkDialogActivated(Context context) { |
| 1396 | String stkDialogActivity = "com.android.stk.StkDialogActivity"; |
| 1397 | boolean activated = false; |
| 1398 | final ActivityManager am = (ActivityManager) context.getSystemService( |
| 1399 | Context.ACTIVITY_SERVICE); |
| 1400 | String topActivity = am.getRunningTasks(1).get(0).topActivity.getClassName(); |
| 1401 | |
| 1402 | CatLog.d(LOG_TAG, "isStkDialogActivated: " + topActivity); |
| 1403 | if (topActivity.equals(stkDialogActivity)) { |
| 1404 | activated = true; |
| 1405 | } |
| 1406 | CatLog.d(LOG_TAG, "activated : " + activated); |
| 1407 | return activated; |
Johan Hellman | 3aec01c | 2011-02-10 10:15:28 +0100 | [diff] [blame] | 1408 | } |
| 1409 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1410 | private void sendSetUpEventResponse(int event, byte[] addedInfo, int slotId) { |
Preeti Ahuja | 414bc41 | 2013-06-25 19:31:49 -0700 | [diff] [blame] | 1411 | CatLog.d(this, "sendSetUpEventResponse: event : " + event + "slotId = " + slotId); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1412 | |
| 1413 | if (mStkContext[slotId].mCurrentSetupEventCmd == null){ |
| 1414 | CatLog.e(this, "mCurrentSetupEventCmd is null"); |
| 1415 | return; |
| 1416 | } |
| 1417 | |
| 1418 | CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentSetupEventCmd); |
| 1419 | |
| 1420 | resMsg.setResultCode(ResultCode.OK); |
| 1421 | resMsg.setEventDownload(event, addedInfo); |
| 1422 | |
| 1423 | mStkService[slotId].onCmdResponse(resMsg); |
| 1424 | } |
| 1425 | |
| 1426 | private void checkForSetupEvent(int event, Bundle args, int slotId) { |
| 1427 | boolean eventPresent = false; |
| 1428 | byte[] addedInfo = null; |
| 1429 | CatLog.d(this, "Event :" + event); |
| 1430 | |
| 1431 | if (mStkContext[slotId].mSetupEventListSettings != null) { |
| 1432 | /* Checks if the event is present in the EventList updated by last |
| 1433 | * SetupEventList Proactive Command */ |
| 1434 | for (int i : mStkContext[slotId].mSetupEventListSettings.eventList) { |
| 1435 | if (event == i) { |
| 1436 | eventPresent = true; |
| 1437 | break; |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | /* If Event is present send the response to ICC */ |
| 1442 | if (eventPresent == true) { |
| 1443 | CatLog.d(this, " Event " + event + "exists in the EventList"); |
| 1444 | |
| 1445 | switch (event) { |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1446 | case IDLE_SCREEN_AVAILABLE_EVENT: |
| 1447 | sendSetUpEventResponse(event, addedInfo, slotId); |
| 1448 | removeSetUpEvent(event, slotId); |
| 1449 | break; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1450 | case LANGUAGE_SELECTION_EVENT: |
| 1451 | String language = mContext |
| 1452 | .getResources().getConfiguration().locale.getLanguage(); |
| 1453 | CatLog.d(this, "language: " + language); |
| 1454 | // Each language code is a pair of alpha-numeric characters. |
| 1455 | // Each alpha-numeric character shall be coded on one byte |
| 1456 | // using the SMS default 7-bit coded alphabet |
| 1457 | addedInfo = GsmAlphabet.stringToGsm8BitPacked(language); |
| 1458 | sendSetUpEventResponse(event, addedInfo, slotId); |
| 1459 | break; |
| 1460 | default: |
| 1461 | break; |
| 1462 | } |
| 1463 | } else { |
| 1464 | CatLog.e(this, " Event does not exist in the EventList"); |
| 1465 | } |
| 1466 | } else { |
| 1467 | CatLog.e(this, "SetupEventList is not received. Ignoring the event: " + event); |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | private void removeSetUpEvent(int event, int slotId) { |
| 1472 | CatLog.d(this, "Remove Event :" + event); |
| 1473 | |
| 1474 | if (mStkContext[slotId].mSetupEventListSettings != null) { |
| 1475 | /* |
| 1476 | * Make new Eventlist without the event |
| 1477 | */ |
| 1478 | for (int i = 0; i < mStkContext[slotId].mSetupEventListSettings.eventList.length; i++) { |
| 1479 | if (event == mStkContext[slotId].mSetupEventListSettings.eventList[i]) { |
| 1480 | mStkContext[slotId].mSetupEventListSettings.eventList[i] = INVALID_SETUP_EVENT; |
| 1481 | break; |
| 1482 | } |
| 1483 | } |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | private void launchEventMessage(int slotId) { |
| 1488 | launchEventMessage(slotId, mStkContext[slotId].mCurrentCmd.geTextMessage()); |
| 1489 | } |
| 1490 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1491 | private void launchEventMessage(int slotId, TextMessage msg) { |
| 1492 | if (msg == null || (msg.text != null && msg.text.length() == 0)) { |
| 1493 | CatLog.d(LOG_TAG, "launchEventMessage return"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1494 | return; |
| 1495 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1496 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1497 | Toast toast = new Toast(mContext.getApplicationContext()); |
| 1498 | LayoutInflater inflate = (LayoutInflater) mContext |
| 1499 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 1500 | View v = inflate.inflate(R.layout.stk_event_msg, null); |
| 1501 | TextView tv = (TextView) v |
| 1502 | .findViewById(com.android.internal.R.id.message); |
| 1503 | ImageView iv = (ImageView) v |
| 1504 | .findViewById(com.android.internal.R.id.icon); |
| 1505 | if (msg.icon != null) { |
| 1506 | iv.setImageBitmap(msg.icon); |
| 1507 | } else { |
| 1508 | iv.setVisibility(View.GONE); |
| 1509 | } |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 1510 | /* In case of 'self explanatory' stkapp should display the specified |
| 1511 | * icon in proactive command (but not the alpha string). |
| 1512 | * If icon is non-self explanatory and if the icon could not be displayed |
| 1513 | * then alpha string or text data should be displayed |
| 1514 | * Ref: ETSI 102.223,section 6.5.4 |
| 1515 | */ |
| 1516 | if (mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() || |
| 1517 | msg.icon == null || !msg.iconSelfExplanatory) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1518 | tv.setText(msg.text); |
| 1519 | } |
| 1520 | |
| 1521 | toast.setView(v); |
| 1522 | toast.setDuration(Toast.LENGTH_LONG); |
| 1523 | toast.setGravity(Gravity.BOTTOM, 0, 0); |
| 1524 | toast.show(); |
| 1525 | } |
| 1526 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1527 | private void launchConfirmationDialog(TextMessage msg, int slotId) { |
| 1528 | msg.title = mStkContext[slotId].lastSelectedItem; |
| 1529 | Intent newIntent = new Intent(); |
| 1530 | String targetActivity = STK_DIALOG_ACTIVITY_NAME; |
| 1531 | String uriString = STK_DIALOG_URI + System.currentTimeMillis(); |
| 1532 | //Set unique URI to create a new instance of activity for different slotId. |
| 1533 | Uri uriData = Uri.parse(uriString); |
| 1534 | |
| 1535 | if (newIntent != null) { |
| 1536 | newIntent.setClassName(this, targetActivity); |
| 1537 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1538 | | Intent.FLAG_ACTIVITY_NO_HISTORY |
| 1539 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 1540 | | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); |
| 1541 | newIntent.putExtra("TEXT", msg); |
| 1542 | newIntent.putExtra(SLOT_ID, slotId); |
| 1543 | newIntent.setData(uriData); |
| 1544 | startActivity(newIntent); |
| 1545 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | private void launchBrowser(BrowserSettings settings) { |
| 1549 | if (settings == null) { |
| 1550 | return; |
| 1551 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1552 | |
Abhishek Adappa | 840c82f | 2013-02-26 10:19:49 -0800 | [diff] [blame] | 1553 | Uri data = null; |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 1554 | String url; |
| 1555 | if (settings.url == null) { |
Abhishek Adappa | 840c82f | 2013-02-26 10:19:49 -0800 | [diff] [blame] | 1556 | // if the command did not contain a URL, |
| 1557 | // launch the browser to the default homepage. |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 1558 | CatLog.d(this, "no url data provided by proactive command." + |
| 1559 | " launching browser with stk default URL ... "); |
| 1560 | url = SystemProperties.get(STK_BROWSER_DEFAULT_URL_SYSPROP, |
| 1561 | "http://www.google.com"); |
| 1562 | } else { |
| 1563 | CatLog.d(this, "launch browser command has attached url = " + settings.url); |
| 1564 | url = settings.url; |
Abhishek Adappa | 840c82f | 2013-02-26 10:19:49 -0800 | [diff] [blame] | 1565 | } |
David Brown | 7c03cfe | 2011-10-20 15:36:12 -0700 | [diff] [blame] | 1566 | |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 1567 | if (url.startsWith("http://") || url.startsWith("https://")) { |
| 1568 | data = Uri.parse(url); |
| 1569 | CatLog.d(this, "launching browser with url = " + url); |
| 1570 | } else { |
| 1571 | String modifiedUrl = "http://" + url; |
| 1572 | data = Uri.parse(modifiedUrl); |
| 1573 | CatLog.d(this, "launching browser with modified url = " + modifiedUrl); |
| 1574 | } |
| 1575 | |
| 1576 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 1577 | intent.setData(data); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1578 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1579 | switch (settings.mode) { |
| 1580 | case USE_EXISTING_BROWSER: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1581 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 1582 | break; |
| 1583 | case LAUNCH_NEW_BROWSER: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1584 | intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); |
| 1585 | break; |
| 1586 | case LAUNCH_IF_NOT_ALREADY_LAUNCHED: |
| 1587 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 1588 | break; |
| 1589 | } |
| 1590 | // start browser activity |
| 1591 | startActivity(intent); |
| 1592 | // a small delay, let the browser start, before processing the next command. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 1593 | // 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] | 1594 | // followed immediately. |
| 1595 | try { |
Ryuto Sawada | 350aaa6 | 2016-06-13 14:47:22 +0900 | [diff] [blame] | 1596 | Thread.sleep(3000); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1597 | } catch (InterruptedException e) {} |
| 1598 | } |
| 1599 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1600 | private void launchIdleText(int slotId) { |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1601 | TextMessage msg = mStkContext[slotId].mIdleModeTextCmd.geTextMessage(); |
dujin.cha | 2a0eb2a | 2011-11-11 15:03:57 +0900 | [diff] [blame] | 1602 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1603 | if (msg == null || msg.text ==null) { |
| 1604 | CatLog.d(LOG_TAG, msg == null ? "mCurrent.getTextMessage is NULL" |
| 1605 | : "mCurrent.getTextMessage.text is NULL"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1606 | mNotificationManager.cancel(getNotificationId(slotId)); |
Wink Saville | 046db4b | 2011-11-01 20:42:54 -0700 | [diff] [blame] | 1607 | return; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1608 | } else { |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1609 | CatLog.d(LOG_TAG, "launchIdleText - text[" + msg.text |
| 1610 | + "] iconSelfExplanatory[" + msg.iconSelfExplanatory |
| 1611 | + "] icon[" + msg.icon + "], sim id: " + slotId); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1612 | CatLog.d(LOG_TAG, "Add IdleMode text"); |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 1613 | PendingIntent pendingIntent = PendingIntent.getService(mContext, 0, |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1614 | new Intent(mContext, StkAppService.class), 0); |
fionaxu | 805eb57 | 2017-05-02 10:57:30 -0700 | [diff] [blame] | 1615 | createAllChannels(); |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 1616 | final Notification.Builder notificationBuilder = new Notification.Builder( |
fionaxu | 2c91c75 | 2017-04-21 18:11:57 -0700 | [diff] [blame] | 1617 | StkAppService.this, STK_NOTIFICATION_CHANNEL_ID); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1618 | if (mStkContext[slotId].mMainCmd != null && |
| 1619 | mStkContext[slotId].mMainCmd.getMenu() != null) { |
| 1620 | notificationBuilder.setContentTitle(mStkContext[slotId].mMainCmd.getMenu().title); |
Christopher Posselwhite | 2ad2ab7 | 2013-05-27 07:51:06 +0200 | [diff] [blame] | 1621 | } else { |
| 1622 | notificationBuilder.setContentTitle(""); |
| 1623 | } |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 1624 | notificationBuilder |
| 1625 | .setSmallIcon(com.android.internal.R.drawable.stat_notify_sim_toolkit); |
| 1626 | notificationBuilder.setContentIntent(pendingIntent); |
| 1627 | notificationBuilder.setOngoing(true); |
| 1628 | // Set text and icon for the status bar and notification body. |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 1629 | if (mStkContext[slotId].mIdleModeTextCmd.hasIconLoadFailed() || |
| 1630 | !msg.iconSelfExplanatory) { |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 1631 | notificationBuilder.setContentText(msg.text); |
Christopher Posselwhite | 2ad2ab7 | 2013-05-27 07:51:06 +0200 | [diff] [blame] | 1632 | notificationBuilder.setTicker(msg.text); |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 1633 | } |
| 1634 | if (msg.icon != null) { |
| 1635 | notificationBuilder.setLargeIcon(msg.icon); |
| 1636 | } else { |
| 1637 | Bitmap bitmapIcon = BitmapFactory.decodeResource(StkAppService.this |
| 1638 | .getResources().getSystem(), |
| 1639 | com.android.internal.R.drawable.stat_notify_sim_toolkit); |
| 1640 | notificationBuilder.setLargeIcon(bitmapIcon); |
| 1641 | } |
Selim Cinek | 62eb3fe | 2014-08-27 17:52:23 +0200 | [diff] [blame] | 1642 | notificationBuilder.setColor(mContext.getResources().getColor( |
| 1643 | com.android.internal.R.color.system_notification_accent_color)); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1644 | mNotificationManager.notify(getNotificationId(slotId), notificationBuilder.build()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1645 | } |
| 1646 | } |
| 1647 | |
fionaxu | 805eb57 | 2017-05-02 10:57:30 -0700 | [diff] [blame] | 1648 | /** Creates the notification channel and registers it with NotificationManager. |
| 1649 | * If a channel with the same ID is already registered, NotificationManager will |
| 1650 | * ignore this call. |
| 1651 | */ |
| 1652 | private void createAllChannels() { |
| 1653 | mNotificationManager.createNotificationChannel(new NotificationChannel( |
| 1654 | STK_NOTIFICATION_CHANNEL_ID, |
| 1655 | getResources().getString(R.string.stk_channel_name), |
| 1656 | NotificationManager.IMPORTANCE_MIN)); |
| 1657 | } |
| 1658 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1659 | private void launchToneDialog(int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1660 | Intent newIntent = new Intent(this, ToneDialog.class); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1661 | String uriString = STK_TONE_URI + slotId; |
| 1662 | Uri uriData = Uri.parse(uriString); |
| 1663 | //Set unique URI to create a new instance of activity for different slotId. |
| 1664 | CatLog.d(LOG_TAG, "launchToneDialog, slotId: " + slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1665 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1666 | | Intent.FLAG_ACTIVITY_NO_HISTORY |
| 1667 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1668 | | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); |
| 1669 | newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage()); |
| 1670 | newIntent.putExtra("TONE", mStkContext[slotId].mCurrentCmd.getToneSettings()); |
| 1671 | newIntent.putExtra(SLOT_ID, slotId); |
| 1672 | newIntent.setData(uriData); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1673 | startActivity(newIntent); |
| 1674 | } |
| 1675 | |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 1676 | private void handlePlayTone(int slotId) { |
| 1677 | TextMessage toneMsg = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
| 1678 | |
| 1679 | boolean showUser = true; |
| 1680 | boolean displayDialog = true; |
| 1681 | Resources resource = Resources.getSystem(); |
| 1682 | try { |
| 1683 | displayDialog = !resource.getBoolean( |
| 1684 | com.android.internal.R.bool.config_stkNoAlphaUsrCnf); |
| 1685 | } catch (NotFoundException e) { |
| 1686 | displayDialog = true; |
| 1687 | } |
| 1688 | |
| 1689 | // As per the spec 3GPP TS 11.14, 6.4.5. Play Tone. |
| 1690 | // If there is no alpha identifier tlv present, UE may show the |
| 1691 | // user information. 'config_stkNoAlphaUsrCnf' value will decide |
| 1692 | // whether to show it or not. |
| 1693 | // If alpha identifier tlv is present and its data is null, play only tone |
| 1694 | // without showing user any information. |
| 1695 | // Alpha Id is Present, but the text data is null. |
| 1696 | if ((toneMsg.text != null ) && (toneMsg.text.equals(""))) { |
| 1697 | CatLog.d(this, "Alpha identifier data is null, play only tone"); |
| 1698 | showUser = false; |
| 1699 | } |
| 1700 | // Alpha Id is not present AND we need to show info to the user. |
| 1701 | if (toneMsg.text == null && displayDialog) { |
| 1702 | CatLog.d(this, "toneMsg.text " + toneMsg.text |
| 1703 | + " Starting ToneDialog activity with default message."); |
| 1704 | toneMsg.text = getResources().getString(R.string.default_tone_dialog_msg); |
| 1705 | showUser = true; |
| 1706 | } |
| 1707 | // Dont show user info, if config setting is true. |
| 1708 | if (toneMsg.text == null && !displayDialog) { |
| 1709 | CatLog.d(this, "config value stkNoAlphaUsrCnf is true"); |
| 1710 | showUser = false; |
| 1711 | } |
| 1712 | |
| 1713 | CatLog.d(this, "toneMsg.text: " + toneMsg.text + "showUser: " +showUser + |
| 1714 | "displayDialog: " +displayDialog); |
| 1715 | playTone(showUser, slotId); |
| 1716 | } |
| 1717 | |
| 1718 | private void playTone(boolean showUserInfo, int slotId) { |
| 1719 | // Start playing tone and vibration |
| 1720 | ToneSettings settings = mStkContext[slotId].mCurrentCmd.getToneSettings(); |
| 1721 | if (null == settings) { |
| 1722 | CatLog.d(this, "null settings, not playing tone."); |
| 1723 | return; |
| 1724 | } |
| 1725 | |
| 1726 | mVibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE); |
| 1727 | mTonePlayer = new TonePlayer(); |
| 1728 | mTonePlayer.play(settings.tone); |
| 1729 | int timeout = StkApp.calculateDurationInMilis(settings.duration); |
| 1730 | if (timeout == 0) { |
| 1731 | timeout = StkApp.TONE_DEFAULT_TIMEOUT; |
| 1732 | } |
| 1733 | |
| 1734 | Message msg = mServiceHandler.obtainMessage(); |
| 1735 | msg.arg1 = OP_STOP_TONE; |
| 1736 | msg.arg2 = slotId; |
| 1737 | msg.obj = (Integer)(showUserInfo ? 1 : 0); |
| 1738 | msg.what = STOP_TONE_WHAT; |
| 1739 | mServiceHandler.sendMessageDelayed(msg, timeout); |
| 1740 | if (settings.vibrate) { |
| 1741 | mVibrator.vibrate(timeout); |
| 1742 | } |
| 1743 | |
| 1744 | // Start Tone dialog Activity to show user the information. |
| 1745 | if (showUserInfo) { |
| 1746 | Intent newIntent = new Intent(sInstance, ToneDialog.class); |
| 1747 | String uriString = STK_TONE_URI + slotId; |
| 1748 | Uri uriData = Uri.parse(uriString); |
| 1749 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1750 | | Intent.FLAG_ACTIVITY_NO_HISTORY |
| 1751 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 1752 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 1753 | | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); |
| 1754 | newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage()); |
| 1755 | newIntent.putExtra(SLOT_ID, slotId); |
| 1756 | newIntent.setData(uriData); |
| 1757 | startActivity(newIntent); |
| 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | private void finishToneDialogActivity() { |
| 1762 | Intent finishIntent = new Intent(FINISH_TONE_ACTIVITY_ACTION); |
| 1763 | sendBroadcast(finishIntent); |
| 1764 | } |
| 1765 | |
| 1766 | private void handleStopTone(Message msg, int slotId) { |
| 1767 | int resId = 0; |
| 1768 | |
| 1769 | // Stop the play tone in following cases: |
| 1770 | // 1.OP_STOP_TONE: play tone timer expires. |
| 1771 | // 2.STOP_TONE_USER: user pressed the back key. |
| 1772 | if (msg.arg1 == OP_STOP_TONE) { |
| 1773 | resId = RES_ID_DONE; |
| 1774 | // Dismiss Tone dialog, after finishing off playing the tone. |
| 1775 | int finishActivity = (Integer) msg.obj; |
| 1776 | if (finishActivity == 1) finishToneDialogActivity(); |
| 1777 | } else if (msg.arg1 == OP_STOP_TONE_USER) { |
| 1778 | resId = RES_ID_END_SESSION; |
| 1779 | } |
| 1780 | |
| 1781 | sendResponse(resId, slotId, true); |
| 1782 | mServiceHandler.removeMessages(STOP_TONE_WHAT); |
| 1783 | if (mTonePlayer != null) { |
| 1784 | mTonePlayer.stop(); |
| 1785 | mTonePlayer.release(); |
| 1786 | mTonePlayer = null; |
| 1787 | } |
| 1788 | if (mVibrator != null) { |
| 1789 | mVibrator.cancel(); |
| 1790 | mVibrator = null; |
| 1791 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1792 | } |
| 1793 | |
Takanori Nakano | 49b1272 | 2016-02-16 14:34:14 +0900 | [diff] [blame] | 1794 | private void launchOpenChannelDialog(final int slotId) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1795 | TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1796 | if (msg == null) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1797 | CatLog.d(LOG_TAG, "msg is null, return here"); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1798 | return; |
| 1799 | } |
| 1800 | |
| 1801 | msg.title = getResources().getString(R.string.stk_dialog_title); |
| 1802 | if (msg.text == null) { |
| 1803 | msg.text = getResources().getString(R.string.default_open_channel_msg); |
| 1804 | } |
| 1805 | |
| 1806 | final AlertDialog dialog = new AlertDialog.Builder(mContext) |
| 1807 | .setIconAttribute(android.R.attr.alertDialogIcon) |
| 1808 | .setTitle(msg.title) |
| 1809 | .setMessage(msg.text) |
| 1810 | .setCancelable(false) |
| 1811 | .setPositiveButton(getResources().getString(R.string.stk_dialog_accept), |
| 1812 | new DialogInterface.OnClickListener() { |
| 1813 | public void onClick(DialogInterface dialog, int which) { |
| 1814 | Bundle args = new Bundle(); |
| 1815 | args.putInt(RES_ID, RES_ID_CHOICE); |
| 1816 | args.putInt(CHOICE, YES); |
| 1817 | Message message = mServiceHandler.obtainMessage(); |
| 1818 | message.arg1 = OP_RESPONSE; |
Takanori Nakano | 49b1272 | 2016-02-16 14:34:14 +0900 | [diff] [blame] | 1819 | message.arg2 = slotId; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1820 | message.obj = args; |
| 1821 | mServiceHandler.sendMessage(message); |
| 1822 | } |
| 1823 | }) |
| 1824 | .setNegativeButton(getResources().getString(R.string.stk_dialog_reject), |
| 1825 | new DialogInterface.OnClickListener() { |
| 1826 | public void onClick(DialogInterface dialog, int which) { |
| 1827 | Bundle args = new Bundle(); |
| 1828 | args.putInt(RES_ID, RES_ID_CHOICE); |
| 1829 | args.putInt(CHOICE, NO); |
| 1830 | Message message = mServiceHandler.obtainMessage(); |
| 1831 | message.arg1 = OP_RESPONSE; |
Takanori Nakano | 49b1272 | 2016-02-16 14:34:14 +0900 | [diff] [blame] | 1832 | message.arg2 = slotId; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1833 | message.obj = args; |
| 1834 | mServiceHandler.sendMessage(message); |
| 1835 | } |
| 1836 | }) |
| 1837 | .create(); |
| 1838 | |
| 1839 | dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
| 1840 | if (!mContext.getResources().getBoolean( |
| 1841 | com.android.internal.R.bool.config_sf_slowBlur)) { |
| 1842 | dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
| 1843 | } |
| 1844 | |
| 1845 | dialog.show(); |
| 1846 | } |
| 1847 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1848 | private void launchTransientEventMessage(int slotId) { |
| 1849 | TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1850 | if (msg == null) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1851 | CatLog.d(LOG_TAG, "msg is null, return here"); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1852 | return; |
| 1853 | } |
| 1854 | |
| 1855 | msg.title = getResources().getString(R.string.stk_dialog_title); |
| 1856 | |
| 1857 | final AlertDialog dialog = new AlertDialog.Builder(mContext) |
| 1858 | .setIconAttribute(android.R.attr.alertDialogIcon) |
| 1859 | .setTitle(msg.title) |
| 1860 | .setMessage(msg.text) |
| 1861 | .setCancelable(false) |
| 1862 | .setPositiveButton(getResources().getString(android.R.string.ok), |
| 1863 | new DialogInterface.OnClickListener() { |
| 1864 | public void onClick(DialogInterface dialog, int which) { |
| 1865 | } |
| 1866 | }) |
| 1867 | .create(); |
| 1868 | |
| 1869 | dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
| 1870 | if (!mContext.getResources().getBoolean( |
| 1871 | com.android.internal.R.bool.config_sf_slowBlur)) { |
| 1872 | dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
| 1873 | } |
| 1874 | |
| 1875 | dialog.show(); |
| 1876 | } |
| 1877 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1878 | private int getNotificationId(int slotId) { |
| 1879 | int notifyId = STK_NOTIFICATION_ID; |
| 1880 | if (slotId >= 0 && slotId < mSimCount) { |
| 1881 | notifyId += slotId; |
| 1882 | } else { |
| 1883 | CatLog.d(LOG_TAG, "invalid slotId: " + slotId); |
| 1884 | } |
| 1885 | CatLog.d(LOG_TAG, "getNotificationId, slotId: " + slotId + ", notifyId: " + notifyId); |
| 1886 | return notifyId; |
| 1887 | } |
| 1888 | |
| 1889 | private String getItemName(int itemId, int slotId) { |
| 1890 | Menu menu = mStkContext[slotId].mCurrentCmd.getMenu(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1891 | if (menu == null) { |
| 1892 | return null; |
| 1893 | } |
| 1894 | for (Item item : menu.items) { |
| 1895 | if (item.id == itemId) { |
| 1896 | return item.text; |
| 1897 | } |
| 1898 | } |
| 1899 | return null; |
| 1900 | } |
| 1901 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1902 | private boolean removeMenu(int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1903 | try { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1904 | if (mStkContext[slotId].mCurrentMenu.items.size() == 1 && |
| 1905 | mStkContext[slotId].mCurrentMenu.items.get(0) == null) { |
| 1906 | mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1907 | return true; |
| 1908 | } |
| 1909 | } catch (NullPointerException e) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1910 | CatLog.d(LOG_TAG, "Unable to get Menu's items size"); |
| 1911 | mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1912 | return true; |
| 1913 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1914 | mStkContext[slotId].mSetupMenuState = STATE_EXIST; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1915 | return false; |
| 1916 | } |
Preeti Ahuja | 0f4cf2f | 2012-08-09 11:45:08 +0530 | [diff] [blame] | 1917 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1918 | StkContext getStkContext(int slotId) { |
| 1919 | if (slotId >= 0 && slotId < mSimCount) { |
| 1920 | return mStkContext[slotId]; |
| 1921 | } else { |
| 1922 | CatLog.d(LOG_TAG, "invalid slotId: " + slotId); |
| 1923 | return null; |
| 1924 | } |
| 1925 | } |
Preeti Ahuja | 0f4cf2f | 2012-08-09 11:45:08 +0530 | [diff] [blame] | 1926 | |
| 1927 | private void handleAlphaNotify(Bundle args) { |
| 1928 | String alphaString = args.getString(AppInterface.ALPHA_STRING); |
| 1929 | |
| 1930 | CatLog.d(this, "Alpha string received from card: " + alphaString); |
| 1931 | Toast toast = Toast.makeText(sInstance, alphaString, Toast.LENGTH_LONG); |
| 1932 | toast.setGravity(Gravity.TOP, 0, 0); |
| 1933 | toast.show(); |
| 1934 | } |
Srikanth Chintala | ba10300 | 2015-11-30 10:49:52 -0800 | [diff] [blame] | 1935 | |
| 1936 | private boolean isUrlAvailableToLaunchBrowser(BrowserSettings settings) { |
| 1937 | String url = SystemProperties.get(STK_BROWSER_DEFAULT_URL_SYSPROP, ""); |
| 1938 | if (url == "" && settings.url == null) { |
| 1939 | return false; |
| 1940 | } |
| 1941 | return true; |
| 1942 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1943 | } |