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