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