blob: 675d832786dec04b82f97913d20b1cd9950bb7d4 [file] [log] [blame]
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001/*
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
17package com.android.stk;
18
Preeti Ahuja95919342013-10-01 18:18:55 -070019import android.app.ActivityManager;
20import android.app.ActivityManager.RunningTaskInfo;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -050021import android.app.AlertDialog;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080022import android.app.Notification;
23import android.app.NotificationManager;
24import android.app.PendingIntent;
25import android.app.Service;
Wink Savillee68857d2014-10-17 15:23:05 -070026import android.app.Activity;
27import android.app.ActivityManager;
28import android.app.ActivityManager.RecentTaskInfo;
29import android.app.ActivityManager.RunningAppProcessInfo;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080030import android.content.Context;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -050031import android.content.DialogInterface;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080032import android.content.Intent;
Preeti Ahuja95919342013-10-01 18:18:55 -070033import android.content.res.Configuration;
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +010034import android.graphics.Bitmap;
35import android.graphics.BitmapFactory;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080036import android.net.Uri;
37import android.os.Bundle;
38import android.os.Handler;
39import android.os.IBinder;
40import android.os.Looper;
41import android.os.Message;
Preeti Ahuja95919342013-10-01 18:18:55 -070042import android.provider.Settings;
Wink Saville56469d52009-04-02 01:37:03 -070043import android.telephony.TelephonyManager;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080044import android.view.Gravity;
45import android.view.LayoutInflater;
46import android.view.View;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -050047import android.view.Window;
48import android.view.WindowManager;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080049import android.widget.ImageView;
50import android.widget.RemoteViews;
51import android.widget.TextView;
52import android.widget.Toast;
Wink Savillee68857d2014-10-17 15:23:05 -070053import android.content.BroadcastReceiver;
54import android.content.IntentFilter;
55import android.content.pm.ApplicationInfo;
56import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080057
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070058import com.android.internal.telephony.cat.AppInterface;
Preeti Ahuja95919342013-10-01 18:18:55 -070059import com.android.internal.telephony.cat.LaunchBrowserMode;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070060import com.android.internal.telephony.cat.Menu;
61import com.android.internal.telephony.cat.Item;
Pierre Fröjd97503262010-11-08 13:59:36 +010062import com.android.internal.telephony.cat.Input;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070063import com.android.internal.telephony.cat.ResultCode;
64import com.android.internal.telephony.cat.CatCmdMessage;
65import com.android.internal.telephony.cat.CatCmdMessage.BrowserSettings;
Preeti Ahuja95919342013-10-01 18:18:55 -070066import com.android.internal.telephony.cat.CatCmdMessage.SetupEventListSettings;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070067import com.android.internal.telephony.cat.CatLog;
68import com.android.internal.telephony.cat.CatResponseMessage;
69import com.android.internal.telephony.cat.TextMessage;
Wink Saville94e982b2014-07-11 07:38:14 -070070import com.android.internal.telephony.uicc.IccRefreshResponse;
71import com.android.internal.telephony.uicc.IccCardStatus.CardState;
Wink Savillee68857d2014-10-17 15:23:05 -070072import com.android.internal.telephony.PhoneConstants;
73import com.android.internal.telephony.TelephonyIntents;
74import com.android.internal.telephony.IccCardConstants;
75import com.android.internal.telephony.uicc.UiccController;
Preeti Ahuja95919342013-10-01 18:18:55 -070076import com.android.internal.telephony.GsmAlphabet;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080077
78import java.util.LinkedList;
Wink Savillee68857d2014-10-17 15:23:05 -070079import java.lang.System;
80import java.util.List;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080081
Preeti Ahuja95919342013-10-01 18:18:55 -070082import static com.android.internal.telephony.cat.CatCmdMessage.
83 SetupEventListConstants.IDLE_SCREEN_AVAILABLE_EVENT;
84import static com.android.internal.telephony.cat.CatCmdMessage.
85 SetupEventListConstants.LANGUAGE_SELECTION_EVENT;
86
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080087/**
88 * SIM toolkit application level service. Interacts with Telephopny messages,
89 * application's launch and user input from STK UI elements.
Wink Saville79085fc2009-06-09 10:27:23 -070090 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080091 */
92public class StkAppService extends Service implements Runnable {
93
94 // members
Wink Savillee68857d2014-10-17 15:23:05 -070095 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 Ahuja95919342013-10-01 18:18:55 -0700119 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 Savillee68857d2014-10-17 15:23:05 -0700126 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 Project9d9730a2009-03-03 19:32:37 -0800155 private volatile Looper mServiceLooper;
156 private volatile ServiceHandler mServiceHandler;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800157 private Context mContext = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800158 private NotificationManager mNotificationManager = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800159 static StkAppService sInstance = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700160 private AppInterface[] mStkService = null;
161 private StkContext[] mStkContext = null;
162 private int mSimCount = 0;
Preeti Ahuja95919342013-10-01 18:18:55 -0700163
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800164 // 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 Ondo764167c2011-10-21 16:05:05 -0500179 static final String CHOICE = "choice";
Wink Savillee68857d2014-10-17 15:23:05 -0700180 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 Ahuja95919342013-10-01 18:18:55 -0700186 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 Project9d9730a2009-03-03 19:32:37 -0800193 // 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 Saville94e982b2014-07-11 07:38:14 -0700200 static final int OP_CARD_STATUS_CHANGED = 7;
Wink Savillee68857d2014-10-17 15:23:05 -0700201 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 Ahuja95919342013-10-01 18:18:55 -0700204 static final int OP_IDLE_SCREEN = 11;
205 static final int OP_LOCALE_CHANGED = 12;
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +0530206 static final int OP_ALPHA_NOTIFY = 13;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800207
Preeti Ahuja95919342013-10-01 18:18:55 -0700208 //Invalid SetupEvent
209 static final int INVALID_SETUP_EVENT = 0xFF;
210
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800211 // 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 Ondo764167c2011-10-21 16:05:05 -0500216 static final int RES_ID_CHOICE = 15;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800217
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 Ondo764167c2011-10-21 16:05:05 -0500223 static final int YES = 1;
224 static final int NO = 0;
225
Wink Savillee68857d2014-10-17 15:23:05 -0700226 static final int STATE_UNKNOWN = -1;
227 static final int STATE_NOT_EXIST = 0;
228 static final int STATE_EXIST = 1;
Wink Saville79085fc2009-06-09 10:27:23 -0700229
Wink Savillee68857d2014-10-17 15:23:05 -0700230 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 Project9d9730a2009-03-03 19:32:37 -0800234 // Notification id used to display Idle Mode text in NotificationManager.
235 private static final int STK_NOTIFICATION_ID = 333;
Wink Savillee68857d2014-10-17 15:23:05 -0700236 private static final String LOG_TAG = new Object(){}.getClass().getEnclosingClass().getName();
Wink Saville79085fc2009-06-09 10:27:23 -0700237
238 // Inner class used for queuing telephony messages (proactive commands,
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800239 // session end) while the service is busy processing a previous message.
240 private class DelayedCmd {
241 // members
242 int id;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -0700243 CatCmdMessage msg;
Wink Savillee68857d2014-10-17 15:23:05 -0700244 int slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800245
Wink Savillee68857d2014-10-17 15:23:05 -0700246 DelayedCmd(int id, CatCmdMessage msg, int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800247 this.id = id;
248 this.msg = msg;
Wink Savillee68857d2014-10-17 15:23:05 -0700249 this.slotId = slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800250 }
251 }
252
253 @Override
254 public void onCreate() {
Wink Savillee68857d2014-10-17 15:23:05 -0700255 CatLog.d(LOG_TAG, "onCreate()+");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800256 // Initialize members
Wink Savillee68857d2014-10-17 15:23:05 -0700257 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 Project9d9730a2009-03-03 19:32:37 -0800277 Thread serviceThread = new Thread(null, this, "Stk App Service");
278 serviceThread.start();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800279 mNotificationManager = (NotificationManager) mContext
280 .getSystemService(Context.NOTIFICATION_SERVICE);
281 sInstance = this;
282 }
283
284 @Override
285 public void onStart(Intent intent, int startId) {
Wink Savillee68857d2014-10-17 15:23:05 -0700286 if (intent == null) {
287 CatLog.d(LOG_TAG, "StkAppService onStart intent is null so return");
Banavathu, Srinivas Naik87cda962012-07-17 15:32:44 +0530288 return;
289 }
290
Wink Savillee68857d2014-10-17 15:23:05 -0700291 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 Naik87cda962012-07-17 15:32:44 +0530335 waitForLooper();
John Wang62acae42009-10-08 11:20:23 -0700336 // 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 Project9d9730a2009-03-03 19:32:37 -0800342 Message msg = mServiceHandler.obtainMessage();
Wink Savillee68857d2014-10-17 15:23:05 -0700343 msg.arg1 = op;
344 msg.arg2 = slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800345 switch(msg.arg1) {
346 case OP_CMD:
347 msg.obj = args.getParcelable(CMD_MSG);
348 break;
349 case OP_RESPONSE:
Wink Saville94e982b2014-07-11 07:38:14 -0700350 case OP_CARD_STATUS_CHANGED:
Preeti Ahuja95919342013-10-01 18:18:55 -0700351 case OP_IDLE_SCREEN:
352 case OP_LOCALE_CHANGED:
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +0530353 case OP_ALPHA_NOTIFY:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800354 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 Savillee68857d2014-10-17 15:23:05 -0700368 CatLog.d(LOG_TAG, "onDestroy()");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800369 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 Savillee68857d2014-10-17 15:23:05 -0700390 void indicateMenuVisibility(boolean visibility, int slotId) {
391 if (slotId >= 0 && slotId < mSimCount) {
392 mStkContext[slotId].mMenuIsVisible = visibility;
393 }
394 }
395
Preeti Ahuja95919342013-10-01 18:18:55 -0700396 /*
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 Savillee68857d2014-10-17 15:23:05 -0700405 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 Project9d9730a2009-03-03 19:32:37 -0800427 }
428
429 /*
430 * Package api used by StkMenuActivity to get its Menu parameter.
431 */
Wink Savillee68857d2014-10-17 15:23:05 -0700432 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 Project9d9730a2009-03-03 19:32:37 -0800451 }
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 Savillee68857d2014-10-17 15:23:05 -0700475 if(null == msg) {
476 CatLog.d(LOG_TAG, "ServiceHandler handleMessage msg is null");
477 return;
478 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800479 int opcode = msg.arg1;
Wink Savillee68857d2014-10-17 15:23:05 -0700480 int slotId = msg.arg2;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800481
Wink Savillee68857d2014-10-17 15:23:05 -0700482 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 Project9d9730a2009-03-03 19:32:37 -0800488 switch (opcode) {
489 case OP_LAUNCH_APP:
Wink Savillee68857d2014-10-17 15:23:05 -0700490 if (mStkContext[slotId].mMainCmd == null) {
491 CatLog.d(LOG_TAG, "mMainCmd is null");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800492 // nothing todo when no SET UP MENU command didn't arrive.
493 return;
494 }
Wink Savillee68857d2014-10-17 15:23:05 -0700495 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 Project9d9730a2009-03-03 19:32:37 -0800535 break;
536 case OP_CMD:
Wink Savillee68857d2014-10-17 15:23:05 -0700537 CatLog.d(LOG_TAG, "[OP_CMD]");
Alex Yakavenkad41f1d92010-07-12 14:13:13 -0700538 CatCmdMessage cmdMsg = (CatCmdMessage) msg.obj;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800539 // 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 Saville79085fc2009-06-09 10:27:23 -0700543 // Informative commands can be handled immediately without any delay.
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800544 // 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 Savillee68857d2014-10-17 15:23:05 -0700548 handleCmd(cmdMsg, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800549 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700550 if (!mStkContext[slotId].mCmdInProgress) {
551 mStkContext[slotId].mCmdInProgress = true;
552 handleCmd((CatCmdMessage) msg.obj, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800553 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700554 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 Project9d9730a2009-03-03 19:32:37 -0800557 }
558 }
559 break;
560 case OP_RESPONSE:
Wink Savillee68857d2014-10-17 15:23:05 -0700561 if (mStkContext[slotId].responseNeeded) {
562 handleCmdResponse((Bundle) msg.obj, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800563 }
564 // call delayed commands if needed.
Wink Savillee68857d2014-10-17 15:23:05 -0700565 if (mStkContext[slotId].mCmdsQ.size() != 0) {
566 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800567 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700568 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800569 }
570 // reset response needed state var to its original value.
Wink Savillee68857d2014-10-17 15:23:05 -0700571 mStkContext[slotId].responseNeeded = true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800572 break;
573 case OP_END_SESSION:
Wink Savillee68857d2014-10-17 15:23:05 -0700574 if (!mStkContext[slotId].mCmdInProgress) {
575 mStkContext[slotId].mCmdInProgress = true;
576 handleSessionEnd(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800577 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700578 mStkContext[slotId].mCmdsQ.addLast(
579 new DelayedCmd(OP_END_SESSION, null, slotId));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800580 }
581 break;
582 case OP_BOOT_COMPLETED:
Wink Savillee68857d2014-10-17 15:23:05 -0700583 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 Project9d9730a2009-03-03 19:32:37 -0800591 StkAppInstaller.unInstall(mContext);
592 }
593 break;
594 case OP_DELAYED_MSG:
Wink Savillee68857d2014-10-17 15:23:05 -0700595 handleDelayedCmd(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800596 break;
Wink Saville94e982b2014-07-11 07:38:14 -0700597 case OP_CARD_STATUS_CHANGED:
Wink Savillee68857d2014-10-17 15:23:05 -0700598 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 Saville94e982b2014-07-11 07:38:14 -0700618 break;
Preeti Ahuja95919342013-10-01 18:18:55 -0700619 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 Ahuja0f4cf2f2012-08-09 11:45:08 +0530630 case OP_ALPHA_NOTIFY:
631 handleAlphaNotify((Bundle) msg.obj);
632 break;
Wink Saville94e982b2014-07-11 07:38:14 -0700633 }
634 }
635
Wink Savillee68857d2014-10-17 15:23:05 -0700636 private void handleCardStatusChangeAndIccRefresh(Bundle args, int slotId) {
Wink Saville94e982b2014-07-11 07:38:14 -0700637 boolean cardStatus = args.getBoolean(AppInterface.CARD_STATUS);
638
Wink Savillee68857d2014-10-17 15:23:05 -0700639 CatLog.d(LOG_TAG, "CardStatus: " + cardStatus);
Wink Saville94e982b2014-07-11 07:38:14 -0700640 if (cardStatus == false) {
Wink Savillee68857d2014-10-17 15:23:05 -0700641 CatLog.d(LOG_TAG, "CARD is ABSENT");
Wink Saville94e982b2014-07-11 07:38:14 -0700642 // Uninstall STKAPP, Clear Idle text, Stop StkAppService
Wink Savillee68857d2014-10-17 15:23:05 -0700643 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 Saville94e982b2014-07-11 07:38:14 -0700649 } else {
650 IccRefreshResponse state = new IccRefreshResponse();
651 state.refreshResult = args.getInt(AppInterface.REFRESH_RESULT);
652
Wink Savillee68857d2014-10-17 15:23:05 -0700653 CatLog.d(LOG_TAG, "Icc Refresh Result: "+ state.refreshResult);
Wink Saville94e982b2014-07-11 07:38:14 -0700654 if ((state.refreshResult == IccRefreshResponse.REFRESH_RESULT_INIT) ||
655 (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET)) {
656 // Clear Idle Text
Wink Savillee68857d2014-10-17 15:23:05 -0700657 mNotificationManager.cancel(getNotificationId(slotId));
Wink Saville94e982b2014-07-11 07:38:14 -0700658 }
659
660 if (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET) {
661 // Uninstall STkmenu
Wink Savillee68857d2014-10-17 15:23:05 -0700662 if (isAllOtherCardsAbsent(slotId)) {
663 StkAppInstaller.unInstall(mContext);
664 }
665 mStkContext[slotId].mCurrentMenu = null;
666 mStkContext[slotId].mMainCmd = null;
Wink Saville94e982b2014-07-11 07:38:14 -0700667 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800668 }
669 }
670 }
Wink Savillee68857d2014-10-17 15:23:05 -0700671 /*
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 Project9d9730a2009-03-03 19:32:37 -0800678
Wink Savillee68857d2014-10-17 15:23:05 -0700679 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 Ahuja95919342013-10-01 18:18:55 -0700690
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 Yakavenkad41f1d92010-07-12 14:13:13 -0700748 private boolean isCmdInteractive(CatCmdMessage cmd) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800749 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 Ondo764167c2011-10-21 16:05:05 -0500756 case CLOSE_CHANNEL:
757 case RECEIVE_DATA:
758 case SEND_DATA:
Preeti Ahuja95919342013-10-01 18:18:55 -0700759 case SET_UP_EVENT_LIST:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800760 return false;
761 }
762
763 return true;
764 }
765
Wink Savillee68857d2014-10-17 15:23:05 -0700766 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 Project9d9730a2009-03-03 19:32:37 -0800782 }
783 }
784 }
785
Wink Savillee68857d2014-10-17 15:23:05 -0700786 private void callDelayedMsg(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800787 Message msg = mServiceHandler.obtainMessage();
788 msg.arg1 = OP_DELAYED_MSG;
Wink Savillee68857d2014-10-17 15:23:05 -0700789 msg.arg2 = slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800790 mServiceHandler.sendMessage(msg);
791 }
792
Wink Savillee68857d2014-10-17 15:23:05 -0700793 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 Saville79085fc2009-06-09 10:27:23 -0700819 // In case of SET UP MENU command which removed the app, don't
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800820 // update the current menu member.
Wink Savillee68857d2014-10-17 15:23:05 -0700821 if (mStkContext[slotId].mCurrentMenu != null && mStkContext[slotId].mMainCmd != null) {
822 mStkContext[slotId].mCurrentMenu = mStkContext[slotId].mMainCmd.getMenu();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800823 }
Wink Savillee68857d2014-10-17 15:23:05 -0700824 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 Project9d9730a2009-03-03 19:32:37 -0800831 }
Wink Savillee68857d2014-10-17 15:23:05 -0700832 if (mStkContext[slotId].mCmdsQ.size() != 0) {
833 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800834 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700835 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800836 }
837 // In case a launch browser command was just confirmed, launch that url.
Wink Savillee68857d2014-10-17 15:23:05 -0700838 if (mStkContext[slotId].launchBrowser) {
839 mStkContext[slotId].launchBrowser = false;
840 launchBrowser(mStkContext[slotId].mBrowserSettings);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800841 }
842 }
843
Preeti Ahuja95919342013-10-01 18:18:55 -0700844 // 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 Savillee68857d2014-10-17 15:23:05 -0700858 private void handleCmd(CatCmdMessage cmdMsg, int slotId) {
Preeti Ahuja95919342013-10-01 18:18:55 -0700859
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800860 if (cmdMsg == null) {
861 return;
862 }
863 // save local reference for state tracking.
Wink Savillee68857d2014-10-17 15:23:05 -0700864 mStkContext[slotId].mCurrentCmd = cmdMsg;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800865 boolean waitForUsersResponse = true;
866
Wink Savillee68857d2014-10-17 15:23:05 -0700867 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 Project9d9730a2009-03-03 19:32:37 -0800872 switch (cmdMsg.getCmdType()) {
873 case DISPLAY_TEXT:
874 TextMessage msg = cmdMsg.geTextMessage();
Wink Savillee68857d2014-10-17 15:23:05 -0700875 mStkContext[slotId].responseNeeded = msg.responseNeeded;
Jeevaka Badrappan854a25c2012-12-01 16:32:03 +0200876 waitForUsersResponse = msg.responseNeeded;
Wink Savillee68857d2014-10-17 15:23:05 -0700877 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 Project9d9730a2009-03-03 19:32:37 -0800881 } else {
882 // TODO: get the carrier name from the SIM
883 msg.title = "";
884 }
Preeti Ahuja95919342013-10-01 18:18:55 -0700885
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 Project9d9730a2009-03-03 19:32:37 -0800901 break;
902 case SELECT_ITEM:
Wink Savillee68857d2014-10-17 15:23:05 -0700903 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 Project9d9730a2009-03-03 19:32:37 -0800907 break;
908 case SET_UP_MENU:
Wink Savillee68857d2014-10-17 15:23:05 -0700909 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 Ahuja95919342013-10-01 18:18:55 -0700919 mStkContext[slotId].mMainCmd = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700920 //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 Project9d9730a2009-03-03 19:32:37 -0800933 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700934 CatLog.d(LOG_TAG, "install App");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800935 StkAppInstaller.install(mContext);
936 }
Wink Savillee68857d2014-10-17 15:23:05 -0700937 if (mStkContext[slotId].mMenuIsVisible) {
938 launchMenuActivity(null, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800939 }
940 break;
941 case GET_INPUT:
942 case GET_INKEY:
Wink Savillee68857d2014-10-17 15:23:05 -0700943 launchInputActivity(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800944 break;
945 case SET_UP_IDLE_MODE_TEXT:
946 waitForUsersResponse = false;
Preeti Ahuja95919342013-10-01 18:18:55 -0700947 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 Project9d9730a2009-03-03 19:32:37 -0800958 break;
959 case SEND_DTMF:
960 case SEND_SMS:
961 case SEND_SS:
962 case SEND_USSD:
Preeti Ahuja95919342013-10-01 18:18:55 -0700963 case GET_CHANNEL_STATUS:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800964 waitForUsersResponse = false;
Wink Savillee68857d2014-10-17 15:23:05 -0700965 launchEventMessage(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800966 break;
967 case LAUNCH_BROWSER:
Wink Savillee68857d2014-10-17 15:23:05 -0700968 launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.geTextMessage(), slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800969 break;
970 case SET_UP_CALL:
Wink Savillee68857d2014-10-17 15:23:05 -0700971 launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.getCallSettings()
972 .confirmMsg, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800973 break;
974 case PLAY_TONE:
Wink Savillee68857d2014-10-17 15:23:05 -0700975 launchToneDialog(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800976 break;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500977 case OPEN_CHANNEL:
Wink Savillee68857d2014-10-17 15:23:05 -0700978 launchOpenChannelDialog(slotId);
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500979 break;
980 case CLOSE_CHANNEL:
981 case RECEIVE_DATA:
982 case SEND_DATA:
Wink Savillee68857d2014-10-17 15:23:05 -0700983 TextMessage m = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500984
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 Pothapragadacacf7b82012-04-16 19:42:38 -0700998 /*
999 * Display indication in the form of a toast to the user if required.
1000 */
Wink Savillee68857d2014-10-17 15:23:05 -07001001 launchEventMessage(slotId);
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001002 break;
Preeti Ahuja95919342013-10-01 18:18:55 -07001003 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 Project9d9730a2009-03-03 19:32:37 -08001023 }
1024
1025 if (!waitForUsersResponse) {
Wink Savillee68857d2014-10-17 15:23:05 -07001026 if (mStkContext[slotId].mCmdsQ.size() != 0) {
1027 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001028 } else {
Wink Savillee68857d2014-10-17 15:23:05 -07001029 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001030 }
1031 }
1032 }
1033
Wink Savillee68857d2014-10-17 15:23:05 -07001034 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 Project9d9730a2009-03-03 19:32:37 -08001037 return;
1038 }
Wink Savillee68857d2014-10-17 15:23:05 -07001039
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 Yakavenkad8e2ecd2012-04-20 17:10:15 -07001050 // 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 Savillee68857d2014-10-17 15:23:05 -07001052 CatLog.d(LOG_TAG, "Exception! mStkService is null when we need to send response.");
Alex Yakavenkad8e2ecd2012-04-20 17:10:15 -07001053 throw new RuntimeException("mStkService is null when we need to send response");
1054 }
1055 }
1056
Wink Savillee68857d2014-10-17 15:23:05 -07001057 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001058
1059 // set result code
1060 boolean helpRequired = args.getBoolean(HELP, false);
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001061 boolean confirmed = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001062
1063 switch(args.getInt(RES_ID)) {
1064 case RES_ID_MENU_SELECTION:
Wink Savillee68857d2014-10-17 15:23:05 -07001065 CatLog.d(LOG_TAG, "MENU_SELECTION=" + mStkContext[slotId].
1066 mCurrentMenuCmd.getCmdType());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001067 int menuSelection = args.getInt(MENU_SELECTION);
Wink Savillee68857d2014-10-17 15:23:05 -07001068 switch(mStkContext[slotId].mCurrentMenuCmd.getCmdType()) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001069 case SET_UP_MENU:
1070 case SELECT_ITEM:
Wink Savillee68857d2014-10-17 15:23:05 -07001071 mStkContext[slotId].lastSelectedItem = getItemName(menuSelection, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001072 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 Savillee68857d2014-10-17 15:23:05 -07001082 CatLog.d(LOG_TAG, "RES_ID_INPUT");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001083 String input = args.getString(INPUT);
Wink Savillee68857d2014-10-17 15:23:05 -07001084 if (input != null && (null != mStkContext[slotId].mCurrentCmd.geInput()) &&
1085 (mStkContext[slotId].mCurrentCmd.geInput().yesNo)) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001086 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 Yakavenkad41f1d92010-07-12 14:13:13 -07001099 CatLog.d(this, "RES_ID_CONFIRM");
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001100 confirmed = args.getBoolean(CONFIRMATION);
Wink Savillee68857d2014-10-17 15:23:05 -07001101 switch (mStkContext[slotId].mCurrentCmd.getCmdType()) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001102 case DISPLAY_TEXT:
1103 resMsg.setResultCode(confirmed ? ResultCode.OK
Preeti Ahuja95919342013-10-01 18:18:55 -07001104 : ResultCode.UICC_SESSION_TERM_BY_USER);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001105 break;
1106 case LAUNCH_BROWSER:
1107 resMsg.setResultCode(confirmed ? ResultCode.OK
1108 : ResultCode.UICC_SESSION_TERM_BY_USER);
1109 if (confirmed) {
Wink Savillee68857d2014-10-17 15:23:05 -07001110 mStkContext[slotId].launchBrowser = true;
1111 mStkContext[slotId].mBrowserSettings =
1112 mStkContext[slotId].mCurrentCmd.getBrowserSettings();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001113 }
1114 break;
1115 case SET_UP_CALL:
1116 resMsg.setResultCode(ResultCode.OK);
1117 resMsg.setConfirmation(confirmed);
1118 if (confirmed) {
Wink Savillee68857d2014-10-17 15:23:05 -07001119 launchEventMessage(slotId,
1120 mStkContext[slotId].mCurrentCmd.getCallSettings().callMsg);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001121 }
1122 break;
1123 }
1124 break;
1125 case RES_ID_DONE:
1126 resMsg.setResultCode(ResultCode.OK);
1127 break;
1128 case RES_ID_BACKWARD:
Wink Savillee68857d2014-10-17 15:23:05 -07001129 CatLog.d(LOG_TAG, "RES_ID_BACKWARD");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001130 resMsg.setResultCode(ResultCode.BACKWARD_MOVE_BY_USER);
1131 break;
1132 case RES_ID_END_SESSION:
Wink Savillee68857d2014-10-17 15:23:05 -07001133 CatLog.d(LOG_TAG, "RES_ID_END_SESSION");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001134 resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER);
1135 break;
1136 case RES_ID_TIMEOUT:
Wink Savillee68857d2014-10-17 15:23:05 -07001137 CatLog.d(LOG_TAG, "RES_ID_TIMEOUT");
Naveen Kallad5176892009-11-30 12:45:29 -08001138 // 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 Savillee68857d2014-10-17 15:23:05 -07001142 if ((mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1143 AppInterface.CommandType.DISPLAY_TEXT.value())
1144 && (mStkContext[slotId].mCurrentCmd.geTextMessage().userClear == false)) {
Naveen Kallad5176892009-11-30 12:45:29 -08001145 resMsg.setResultCode(ResultCode.OK);
1146 } else {
1147 resMsg.setResultCode(ResultCode.NO_RESPONSE_FROM_USER);
1148 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001149 break;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001150 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 Pothapragadacacf7b82012-04-16 19:42:38 -07001156 confirmed = true;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001157 break;
1158 case NO:
1159 resMsg.setResultCode(ResultCode.USER_NOT_ACCEPT);
1160 break;
1161 }
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001162
Wink Savillee68857d2014-10-17 15:23:05 -07001163 if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1164 AppInterface.CommandType.OPEN_CHANNEL.value()) {
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001165 resMsg.setConfirmation(confirmed);
1166 }
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001167 break;
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001168
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001169 default:
Wink Savillee68857d2014-10-17 15:23:05 -07001170 CatLog.d(LOG_TAG, "Unknown result id");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001171 return;
1172 }
Wink Savillee68857d2014-10-17 15:23:05 -07001173
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 Project9d9730a2009-03-03 19:32:37 -08001180 }
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 Saville79085fc2009-06-09 10:27:23 -07001190 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001191 * @return 0 or FLAG_ACTIVITY_NO_USER_ACTION
1192 */
Wink Savillee68857d2014-10-17 15:23:05 -07001193 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 Project9d9730a2009-03-03 19:32:37 -08001266 }
1267
Wink Savillee68857d2014-10-17 15:23:05 -07001268 private void launchMenuActivity(Menu menu, int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001269 Intent newIntent = new Intent(Intent.ACTION_VIEW);
Wink Savillee68857d2014-10-17 15:23:05 -07001270 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 Project9d9730a2009-03-03 19:32:37 -08001281 if (menu == null) {
1282 // We assume this was initiated by the user pressing the tool kit icon
Wink Savillee68857d2014-10-17 15:23:05 -07001283 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 Project9d9730a2009-03-03 19:32:37 -08001300
Wink Savillee68857d2014-10-17 15:23:05 -07001301 //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 Project9d9730a2009-03-03 19:32:37 -08001310 } else {
1311 // We don't know and we'll let getFlagActivityNoUserAction decide.
Wink Savillee68857d2014-10-17 15:23:05 -07001312 intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001313 newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY);
Wink Savillee68857d2014-10-17 15:23:05 -07001314 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_SECONDARY;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001315 }
Wink Savillee68857d2014-10-17 15:23:05 -07001316 newIntent.putExtra(SLOT_ID, slotId);
1317 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001318 newIntent.setFlags(intentFlags);
1319 mContext.startActivity(newIntent);
1320 }
1321
Wink Savillee68857d2014-10-17 15:23:05 -07001322 private void launchInputActivity(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001323 Intent newIntent = new Intent(Intent.ACTION_VIEW);
Wink Savillee68857d2014-10-17 15:23:05 -07001324 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 Project9d9730a2009-03-03 19:32:37 -08001330 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
Wink Savillee68857d2014-10-17 15:23:05 -07001331 | 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 Project9d9730a2009-03-03 19:32:37 -08001336 mContext.startActivity(newIntent);
1337 }
1338
Wink Savillee68857d2014-10-17 15:23:05 -07001339 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 Project9d9730a2009-03-03 19:32:37 -08001357 }
1358
Wink Savillee68857d2014-10-17 15:23:05 -07001359 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 Hellman3aec01c2011-02-10 10:15:28 +01001372 }
1373
Preeti Ahuja95919342013-10-01 18:18:55 -07001374 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 Savillee68857d2014-10-17 15:23:05 -07001455 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 Project9d9730a2009-03-03 19:32:37 -08001458 return;
1459 }
Wink Savillee68857d2014-10-17 15:23:05 -07001460
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001461 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 Savillee68857d2014-10-17 15:23:05 -07001484 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 Project9d9730a2009-03-03 19:32:37 -08001503 }
1504
1505 private void launchBrowser(BrowserSettings settings) {
1506 if (settings == null) {
1507 return;
1508 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001509
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001510 Intent intent = null;
1511 Uri data = null;
David Brown7c03cfe2011-10-20 15:36:12 -07001512
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001513 if (settings.url != null) {
Wink Savillee68857d2014-10-17 15:23:05 -07001514 CatLog.d(LOG_TAG, "settings.url = " + settings.url);
dujin.cha2a0eb2a2011-11-11 15:03:57 +09001515 if ((settings.url.startsWith("http://") || (settings.url.startsWith("https://")))) {
dujin.cha486c1d02011-11-02 22:14:25 +09001516 data = Uri.parse(settings.url);
1517 } else {
1518 String modifiedUrl = "http://" + settings.url;
Wink Savillee68857d2014-10-17 15:23:05 -07001519 CatLog.d(LOG_TAG, "modifiedUrl = " + modifiedUrl);
dujin.cha486c1d02011-11-02 22:14:25 +09001520 data = Uri.parse(modifiedUrl);
1521 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001522 }
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001523 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 Savillee68857d2014-10-17 15:23:05 -07001529 CatLog.d(LOG_TAG, "launch browser with default URL ");
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001530 intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
1531 Intent.CATEGORY_APP_BROWSER);
1532 }
David Brown7c03cfe2011-10-20 15:36:12 -07001533
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001534 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1535 switch (settings.mode) {
1536 case USE_EXISTING_BROWSER:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001537 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1538 break;
1539 case LAUNCH_NEW_BROWSER:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001540 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 Saville79085fc2009-06-09 10:27:23 -07001549 // this is good for scenarios where a related DISPLAY TEXT command is
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001550 // followed immediately.
1551 try {
1552 Thread.sleep(10000);
1553 } catch (InterruptedException e) {}
1554 }
1555
Wink Savillee68857d2014-10-17 15:23:05 -07001556 private void launchIdleText(int slotId) {
Preeti Ahuja95919342013-10-01 18:18:55 -07001557 TextMessage msg = mStkContext[slotId].mIdleModeTextCmd.geTextMessage();
dujin.cha2a0eb2a2011-11-11 15:03:57 +09001558
Preeti Ahuja95919342013-10-01 18:18:55 -07001559 if (msg == null || msg.text ==null) {
1560 CatLog.d(LOG_TAG, msg == null ? "mCurrent.getTextMessage is NULL"
1561 : "mCurrent.getTextMessage.text is NULL");
Wink Savillee68857d2014-10-17 15:23:05 -07001562 mNotificationManager.cancel(getNotificationId(slotId));
Wink Saville046db4b2011-11-01 20:42:54 -07001563 return;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001564 } else {
Preeti Ahuja95919342013-10-01 18:18:55 -07001565 CatLog.d(LOG_TAG, "launchIdleText - text[" + msg.text
1566 + "] iconSelfExplanatory[" + msg.iconSelfExplanatory
1567 + "] icon[" + msg.icon + "], sim id: " + slotId);
Wink Savillee68857d2014-10-17 15:23:05 -07001568 CatLog.d(LOG_TAG, "Add IdleMode text");
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001569 PendingIntent pendingIntent = PendingIntent.getService(mContext, 0,
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001570 new Intent(mContext, StkAppService.class), 0);
1571
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001572 final Notification.Builder notificationBuilder = new Notification.Builder(
1573 StkAppService.this);
Wink Savillee68857d2014-10-17 15:23:05 -07001574 if (mStkContext[slotId].mMainCmd != null &&
1575 mStkContext[slotId].mMainCmd.getMenu() != null) {
1576 notificationBuilder.setContentTitle(mStkContext[slotId].mMainCmd.getMenu().title);
Christopher Posselwhite2ad2ab72013-05-27 07:51:06 +02001577 } else {
1578 notificationBuilder.setContentTitle("");
1579 }
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001580 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 Posselwhite2ad2ab72013-05-27 07:51:06 +02001587 notificationBuilder.setTicker(msg.text);
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001588 }
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 Cinek62eb3fe2014-08-27 17:52:23 +02001597 notificationBuilder.setColor(mContext.getResources().getColor(
1598 com.android.internal.R.color.system_notification_accent_color));
Wink Savillee68857d2014-10-17 15:23:05 -07001599 mNotificationManager.notify(getNotificationId(slotId), notificationBuilder.build());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001600 }
1601 }
1602
Wink Savillee68857d2014-10-17 15:23:05 -07001603 private void launchToneDialog(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001604 Intent newIntent = new Intent(this, ToneDialog.class);
Wink Savillee68857d2014-10-17 15:23:05 -07001605 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 Project9d9730a2009-03-03 19:32:37 -08001609 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1610 | Intent.FLAG_ACTIVITY_NO_HISTORY
1611 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
Wink Savillee68857d2014-10-17 15:23:05 -07001612 | 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 Project9d9730a2009-03-03 19:32:37 -08001617 startActivity(newIntent);
1618 }
1619
Wink Savillee68857d2014-10-17 15:23:05 -07001620 private void launchOpenChannelDialog(int slotId) {
1621 TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001622 if (msg == null) {
Wink Savillee68857d2014-10-17 15:23:05 -07001623 CatLog.d(LOG_TAG, "msg is null, return here");
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001624 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 Savillee68857d2014-10-17 15:23:05 -07001672 private void launchTransientEventMessage(int slotId) {
1673 TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001674 if (msg == null) {
Wink Savillee68857d2014-10-17 15:23:05 -07001675 CatLog.d(LOG_TAG, "msg is null, return here");
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001676 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 Savillee68857d2014-10-17 15:23:05 -07001702 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 Project9d9730a2009-03-03 19:32:37 -08001715 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 Savillee68857d2014-10-17 15:23:05 -07001726 private boolean removeMenu(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001727 try {
Wink Savillee68857d2014-10-17 15:23:05 -07001728 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 Project9d9730a2009-03-03 19:32:37 -08001731 return true;
1732 }
1733 } catch (NullPointerException e) {
Wink Savillee68857d2014-10-17 15:23:05 -07001734 CatLog.d(LOG_TAG, "Unable to get Menu's items size");
1735 mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001736 return true;
1737 }
Wink Savillee68857d2014-10-17 15:23:05 -07001738 mStkContext[slotId].mSetupMenuState = STATE_EXIST;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001739 return false;
1740 }
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +05301741
Wink Savillee68857d2014-10-17 15:23:05 -07001742 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 Ahuja0f4cf2f2012-08-09 11:45:08 +05301750
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 Project9d9730a2009-03-03 19:32:37 -08001759}