blob: 011e1486369a694ab81ce341d58c46da6da8b7a8 [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;
Preeti Ahujaa7cdca22013-10-01 18:20:56 -070030import android.content.ComponentName;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080031import android.content.Context;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -050032import android.content.DialogInterface;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080033import android.content.Intent;
Preeti Ahuja95919342013-10-01 18:18:55 -070034import android.content.res.Configuration;
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +010035import android.graphics.Bitmap;
36import android.graphics.BitmapFactory;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080037import android.net.Uri;
38import android.os.Bundle;
39import android.os.Handler;
40import android.os.IBinder;
41import android.os.Looper;
42import android.os.Message;
Preeti Ahuja560be362014-11-25 19:38:24 -080043import android.os.PowerManager;
Preeti Ahujaa7cdca22013-10-01 18:20:56 -070044import android.os.SystemProperties;
Preeti Ahuja95919342013-10-01 18:18:55 -070045import android.provider.Settings;
Wink Saville56469d52009-04-02 01:37:03 -070046import android.telephony.TelephonyManager;
Preeti Ahujaa7cdca22013-10-01 18:20:56 -070047import android.text.TextUtils;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080048import android.view.Gravity;
49import android.view.LayoutInflater;
50import android.view.View;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -050051import android.view.Window;
52import android.view.WindowManager;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080053import android.widget.ImageView;
54import android.widget.RemoteViews;
55import android.widget.TextView;
56import android.widget.Toast;
Wink Savillee68857d2014-10-17 15:23:05 -070057import android.content.BroadcastReceiver;
58import android.content.IntentFilter;
59import android.content.pm.ApplicationInfo;
60import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080061
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070062import com.android.internal.telephony.cat.AppInterface;
Preeti Ahuja95919342013-10-01 18:18:55 -070063import com.android.internal.telephony.cat.LaunchBrowserMode;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070064import com.android.internal.telephony.cat.Menu;
65import com.android.internal.telephony.cat.Item;
Pierre Fröjd97503262010-11-08 13:59:36 +010066import com.android.internal.telephony.cat.Input;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070067import com.android.internal.telephony.cat.ResultCode;
68import com.android.internal.telephony.cat.CatCmdMessage;
69import com.android.internal.telephony.cat.CatCmdMessage.BrowserSettings;
Preeti Ahuja95919342013-10-01 18:18:55 -070070import com.android.internal.telephony.cat.CatCmdMessage.SetupEventListSettings;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070071import com.android.internal.telephony.cat.CatLog;
72import com.android.internal.telephony.cat.CatResponseMessage;
73import com.android.internal.telephony.cat.TextMessage;
Wink Saville94e982b2014-07-11 07:38:14 -070074import com.android.internal.telephony.uicc.IccRefreshResponse;
75import com.android.internal.telephony.uicc.IccCardStatus.CardState;
Wink Savillee68857d2014-10-17 15:23:05 -070076import com.android.internal.telephony.PhoneConstants;
77import com.android.internal.telephony.TelephonyIntents;
78import com.android.internal.telephony.IccCardConstants;
79import com.android.internal.telephony.uicc.UiccController;
Preeti Ahuja95919342013-10-01 18:18:55 -070080import com.android.internal.telephony.GsmAlphabet;
Legler Wuaeefef52014-10-27 00:57:18 +080081import com.android.internal.telephony.cat.CatService;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080082
Preeti Ahujaa7cdca22013-10-01 18:20:56 -070083import java.util.Iterator;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080084import java.util.LinkedList;
Wink Savillee68857d2014-10-17 15:23:05 -070085import java.lang.System;
86import java.util.List;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080087
Preeti Ahuja95919342013-10-01 18:18:55 -070088import static com.android.internal.telephony.cat.CatCmdMessage.
Preeti Ahuja560be362014-11-25 19:38:24 -080089 SetupEventListConstants.IDLE_SCREEN_AVAILABLE_EVENT;
90import static com.android.internal.telephony.cat.CatCmdMessage.
Preeti Ahuja95919342013-10-01 18:18:55 -070091 SetupEventListConstants.LANGUAGE_SELECTION_EVENT;
92
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080093/**
94 * SIM toolkit application level service. Interacts with Telephopny messages,
95 * application's launch and user input from STK UI elements.
Wink Saville79085fc2009-06-09 10:27:23 -070096 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080097 */
98public class StkAppService extends Service implements Runnable {
99
100 // members
Wink Savillee68857d2014-10-17 15:23:05 -0700101 protected class StkContext {
102 protected CatCmdMessage mMainCmd = null;
103 protected CatCmdMessage mCurrentCmd = null;
104 protected CatCmdMessage mCurrentMenuCmd = null;
105 protected Menu mCurrentMenu = null;
106 protected String lastSelectedItem = null;
107 protected boolean mMenuIsVisible = false;
108 protected boolean mIsInputPending = false;
109 protected boolean mIsMenuPending = false;
110 protected boolean mIsDialogPending = false;
111 protected boolean responseNeeded = true;
112 protected boolean launchBrowser = false;
113 protected BrowserSettings mBrowserSettings = null;
114 protected LinkedList<DelayedCmd> mCmdsQ = null;
115 protected boolean mCmdInProgress = false;
116 protected int mStkServiceState = STATE_UNKNOWN;
117 protected int mSetupMenuState = STATE_UNKNOWN;
118 protected int mMenuState = StkMenuActivity.STATE_INIT;
119 protected int mOpCode = -1;
120 private Activity mActivityInstance = null;
121 private Activity mDialogInstance = null;
122 private Activity mMainActivityInstance = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700123 private int mSlotId = 0;
Preeti Ahuja95919342013-10-01 18:18:55 -0700124 private SetupEventListSettings mSetupEventListSettings = null;
125 private boolean mClearSelectItem = false;
126 private boolean mDisplayTextDlgIsVisibile = false;
127 private CatCmdMessage mCurrentSetupEventCmd = null;
Preeti Ahuja560be362014-11-25 19:38:24 -0800128 private CatCmdMessage mIdleModeTextCmd = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700129 final synchronized void setPendingActivityInstance(Activity act) {
130 CatLog.d(this, "setPendingActivityInstance act : " + mSlotId + ", " + act);
131 callSetActivityInstMsg(OP_SET_ACT_INST, mSlotId, act);
132 }
133 final synchronized Activity getPendingActivityInstance() {
134 CatLog.d(this, "getPendingActivityInstance act : " + mSlotId + ", " +
135 mActivityInstance);
136 return mActivityInstance;
137 }
138 final synchronized void setPendingDialogInstance(Activity act) {
139 CatLog.d(this, "setPendingDialogInstance act : " + mSlotId + ", " + act);
140 callSetActivityInstMsg(OP_SET_DAL_INST, mSlotId, act);
141 }
142 final synchronized Activity getPendingDialogInstance() {
143 CatLog.d(this, "getPendingDialogInstance act : " + mSlotId + ", " +
144 mDialogInstance);
145 return mDialogInstance;
146 }
147 final synchronized void setMainActivityInstance(Activity act) {
148 CatLog.d(this, "setMainActivityInstance act : " + mSlotId + ", " + act);
149 callSetActivityInstMsg(OP_SET_MAINACT_INST, mSlotId, act);
150 }
151 final synchronized Activity getMainActivityInstance() {
152 CatLog.d(this, "getMainActivityInstance act : " + mSlotId + ", " +
153 mMainActivityInstance);
154 return mMainActivityInstance;
155 }
156 }
157
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800158 private volatile Looper mServiceLooper;
159 private volatile ServiceHandler mServiceHandler;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800160 private Context mContext = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800161 private NotificationManager mNotificationManager = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800162 static StkAppService sInstance = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700163 private AppInterface[] mStkService = null;
164 private StkContext[] mStkContext = null;
165 private int mSimCount = 0;
Preeti Ahuja560be362014-11-25 19:38:24 -0800166 private PowerManager mPowerManager = null;
167 private StkCmdReceiver mStkCmdReceiver = null;
Preeti Ahuja95919342013-10-01 18:18:55 -0700168
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800169 // Used for setting FLAG_ACTIVITY_NO_USER_ACTION when
170 // creating an intent.
171 private enum InitiatedByUserAction {
172 yes, // The action was started via a user initiated action
173 unknown, // Not known for sure if user initated the action
174 }
175
176 // constants
177 static final String OPCODE = "op";
178 static final String CMD_MSG = "cmd message";
179 static final String RES_ID = "response id";
180 static final String MENU_SELECTION = "menu selection";
181 static final String INPUT = "input";
182 static final String HELP = "help";
183 static final String CONFIRMATION = "confirm";
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500184 static final String CHOICE = "choice";
Wink Savillee68857d2014-10-17 15:23:05 -0700185 static final String SLOT_ID = "SLOT_ID";
186 static final String STK_CMD = "STK CMD";
187 static final String STK_DIALOG_URI = "stk://com.android.stk/dialog/";
188 static final String STK_MENU_URI = "stk://com.android.stk/menu/";
189 static final String STK_INPUT_URI = "stk://com.android.stk/input/";
190 static final String STK_TONE_URI = "stk://com.android.stk/tone/";
Preeti Ahuja95919342013-10-01 18:18:55 -0700191
192 // These below constants are used for SETUP_EVENT_LIST
193 static final String SETUP_EVENT_TYPE = "event";
194 static final String SETUP_EVENT_CAUSE = "cause";
195
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800196 // operations ids for different service functionality.
197 static final int OP_CMD = 1;
198 static final int OP_RESPONSE = 2;
199 static final int OP_LAUNCH_APP = 3;
200 static final int OP_END_SESSION = 4;
201 static final int OP_BOOT_COMPLETED = 5;
202 private static final int OP_DELAYED_MSG = 6;
Wink Saville94e982b2014-07-11 07:38:14 -0700203 static final int OP_CARD_STATUS_CHANGED = 7;
Wink Savillee68857d2014-10-17 15:23:05 -0700204 static final int OP_SET_ACT_INST = 8;
205 static final int OP_SET_DAL_INST = 9;
206 static final int OP_SET_MAINACT_INST = 10;
Preeti Ahujab3d0e612014-11-20 13:29:25 -0800207 static final int OP_LOCALE_CHANGED = 11;
208 static final int OP_ALPHA_NOTIFY = 12;
Preeti Ahuja560be362014-11-25 19:38:24 -0800209 static final int OP_IDLE_SCREEN = 13;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800210
Preeti Ahuja95919342013-10-01 18:18:55 -0700211 //Invalid SetupEvent
212 static final int INVALID_SETUP_EVENT = 0xFF;
213
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800214 // Response ids
215 static final int RES_ID_MENU_SELECTION = 11;
216 static final int RES_ID_INPUT = 12;
217 static final int RES_ID_CONFIRM = 13;
218 static final int RES_ID_DONE = 14;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500219 static final int RES_ID_CHOICE = 15;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800220
221 static final int RES_ID_TIMEOUT = 20;
222 static final int RES_ID_BACKWARD = 21;
223 static final int RES_ID_END_SESSION = 22;
224 static final int RES_ID_EXIT = 23;
225
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500226 static final int YES = 1;
227 static final int NO = 0;
228
Wink Savillee68857d2014-10-17 15:23:05 -0700229 static final int STATE_UNKNOWN = -1;
230 static final int STATE_NOT_EXIST = 0;
231 static final int STATE_EXIST = 1;
Wink Saville79085fc2009-06-09 10:27:23 -0700232
Wink Savillee68857d2014-10-17 15:23:05 -0700233 private static final String PACKAGE_NAME = "com.android.stk";
234 private static final String STK_MENU_ACTIVITY_NAME = PACKAGE_NAME + ".StkMenuActivity";
235 private static final String STK_INPUT_ACTIVITY_NAME = PACKAGE_NAME + ".StkInputActivity";
236 private static final String STK_DIALOG_ACTIVITY_NAME = PACKAGE_NAME + ".StkDialogActivity";
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800237 // Notification id used to display Idle Mode text in NotificationManager.
238 private static final int STK_NOTIFICATION_ID = 333;
Wink Savillee68857d2014-10-17 15:23:05 -0700239 private static final String LOG_TAG = new Object(){}.getClass().getEnclosingClass().getName();
Wink Saville79085fc2009-06-09 10:27:23 -0700240
241 // Inner class used for queuing telephony messages (proactive commands,
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800242 // session end) while the service is busy processing a previous message.
243 private class DelayedCmd {
244 // members
245 int id;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -0700246 CatCmdMessage msg;
Wink Savillee68857d2014-10-17 15:23:05 -0700247 int slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800248
Wink Savillee68857d2014-10-17 15:23:05 -0700249 DelayedCmd(int id, CatCmdMessage msg, int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800250 this.id = id;
251 this.msg = msg;
Wink Savillee68857d2014-10-17 15:23:05 -0700252 this.slotId = slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800253 }
254 }
255
Preeti Ahujaa7cdca22013-10-01 18:20:56 -0700256 // system property to set the STK specific default url for launch browser proactive cmds
257 private static final String STK_BROWSER_DEFAULT_URL_SYSPROP = "persist.radio.stk.default_url";
258
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800259 @Override
260 public void onCreate() {
Wink Savillee68857d2014-10-17 15:23:05 -0700261 CatLog.d(LOG_TAG, "onCreate()+");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800262 // Initialize members
Wink Savillee68857d2014-10-17 15:23:05 -0700263 int i = 0;
264 mContext = getBaseContext();
265 mSimCount = TelephonyManager.from(mContext).getSimCount();
266 CatLog.d(LOG_TAG, "simCount: " + mSimCount);
267 mStkService = new AppInterface[mSimCount];
268 mStkContext = new StkContext[mSimCount];
Preeti Ahuja560be362014-11-25 19:38:24 -0800269 mPowerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
270 mStkCmdReceiver = new StkCmdReceiver();
271 registerReceiver(mStkCmdReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
Wink Savillee68857d2014-10-17 15:23:05 -0700272 for (i = 0; i < mSimCount; i++) {
273 CatLog.d(LOG_TAG, "slotId: " + i);
Legler Wuaeefef52014-10-27 00:57:18 +0800274 mStkService[i] = CatService.getInstance(i);
Wink Savillee68857d2014-10-17 15:23:05 -0700275 mStkContext[i] = new StkContext();
276 mStkContext[i].mSlotId = i;
277 mStkContext[i].mCmdsQ = new LinkedList<DelayedCmd>();
278 }
279
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800280 Thread serviceThread = new Thread(null, this, "Stk App Service");
281 serviceThread.start();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800282 mNotificationManager = (NotificationManager) mContext
283 .getSystemService(Context.NOTIFICATION_SERVICE);
284 sInstance = this;
285 }
286
287 @Override
288 public void onStart(Intent intent, int startId) {
Wink Savillee68857d2014-10-17 15:23:05 -0700289 if (intent == null) {
290 CatLog.d(LOG_TAG, "StkAppService onStart intent is null so return");
Banavathu, Srinivas Naik87cda962012-07-17 15:32:44 +0530291 return;
292 }
293
Wink Savillee68857d2014-10-17 15:23:05 -0700294 Bundle args = intent.getExtras();
295 if (args == null) {
296 CatLog.d(LOG_TAG, "StkAppService onStart args is null so return");
297 return;
298 }
299
300 int op = args.getInt(OPCODE);
301 int slotId = 0;
302 int i = 0;
303 if (op != OP_BOOT_COMPLETED) {
304 slotId = args.getInt(SLOT_ID);
305 }
Cuihtlauac ALVARADObde7f032015-05-29 16:25:12 +0200306 CatLog.d(LOG_TAG, "onStart sim id: " + slotId + ", op: " + op + ", *****");
Wink Savillee68857d2014-10-17 15:23:05 -0700307 if ((slotId >= 0 && slotId < mSimCount) && mStkService[slotId] == null) {
Legler Wuaeefef52014-10-27 00:57:18 +0800308 mStkService[slotId] = CatService.getInstance(slotId);
Wink Savillee68857d2014-10-17 15:23:05 -0700309 if (mStkService[slotId] == null) {
310 CatLog.d(LOG_TAG, "mStkService is: " + mStkContext[slotId].mStkServiceState);
311 mStkContext[slotId].mStkServiceState = STATE_NOT_EXIST;
312 //Check other StkService state.
313 //If all StkServices are not available, stop itself and uninstall apk.
314 for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) {
315 if (i != slotId
316 && (mStkContext[i].mStkServiceState == STATE_UNKNOWN
317 || mStkContext[i].mStkServiceState == STATE_EXIST)) {
318 break;
319 }
320 }
321 } else {
322 mStkContext[slotId].mStkServiceState = STATE_EXIST;
323 }
324 if (i == mSimCount) {
325 stopSelf();
326 StkAppInstaller.unInstall(mContext);
327 return;
328 }
329 }
330
Banavathu, Srinivas Naik87cda962012-07-17 15:32:44 +0530331 waitForLooper();
John Wang62acae42009-10-08 11:20:23 -0700332
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800333 Message msg = mServiceHandler.obtainMessage();
Wink Savillee68857d2014-10-17 15:23:05 -0700334 msg.arg1 = op;
335 msg.arg2 = slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800336 switch(msg.arg1) {
337 case OP_CMD:
338 msg.obj = args.getParcelable(CMD_MSG);
339 break;
340 case OP_RESPONSE:
Wink Saville94e982b2014-07-11 07:38:14 -0700341 case OP_CARD_STATUS_CHANGED:
Preeti Ahuja95919342013-10-01 18:18:55 -0700342 case OP_LOCALE_CHANGED:
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +0530343 case OP_ALPHA_NOTIFY:
Preeti Ahuja560be362014-11-25 19:38:24 -0800344 case OP_IDLE_SCREEN:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800345 msg.obj = args;
346 /* falls through */
347 case OP_LAUNCH_APP:
348 case OP_END_SESSION:
349 case OP_BOOT_COMPLETED:
350 break;
351 default:
352 return;
353 }
354 mServiceHandler.sendMessage(msg);
355 }
356
357 @Override
358 public void onDestroy() {
Wink Savillee68857d2014-10-17 15:23:05 -0700359 CatLog.d(LOG_TAG, "onDestroy()");
Preeti Ahuja560be362014-11-25 19:38:24 -0800360 if (mStkCmdReceiver != null) {
361 unregisterReceiver(mStkCmdReceiver);
362 mStkCmdReceiver = null;
363 }
364 mPowerManager = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800365 waitForLooper();
366 mServiceLooper.quit();
367 }
368
369 @Override
370 public IBinder onBind(Intent intent) {
371 return null;
372 }
373
374 public void run() {
375 Looper.prepare();
376
377 mServiceLooper = Looper.myLooper();
378 mServiceHandler = new ServiceHandler();
379
380 Looper.loop();
381 }
382
383 /*
384 * Package api used by StkMenuActivity to indicate if its on the foreground.
385 */
Wink Savillee68857d2014-10-17 15:23:05 -0700386 void indicateMenuVisibility(boolean visibility, int slotId) {
387 if (slotId >= 0 && slotId < mSimCount) {
388 mStkContext[slotId].mMenuIsVisible = visibility;
389 }
390 }
391
Preeti Ahuja95919342013-10-01 18:18:55 -0700392 /*
393 * Package api used by StkDialogActivity to indicate if its on the foreground.
394 */
395 void setDisplayTextDlgVisibility(boolean visibility, int slotId) {
396 if (slotId >= 0 && slotId < mSimCount) {
397 mStkContext[slotId].mDisplayTextDlgIsVisibile = visibility;
398 }
399 }
400
Wink Savillee68857d2014-10-17 15:23:05 -0700401 boolean isInputPending(int slotId) {
402 if (slotId >= 0 && slotId < mSimCount) {
403 CatLog.d(LOG_TAG, "isInputFinishBySrv: " + mStkContext[slotId].mIsInputPending);
404 return mStkContext[slotId].mIsInputPending;
405 }
406 return false;
407 }
408
409 boolean isMenuPending(int slotId) {
410 if (slotId >= 0 && slotId < mSimCount) {
411 CatLog.d(LOG_TAG, "isMenuPending: " + mStkContext[slotId].mIsMenuPending);
412 return mStkContext[slotId].mIsMenuPending;
413 }
414 return false;
415 }
416
417 boolean isDialogPending(int slotId) {
418 if (slotId >= 0 && slotId < mSimCount) {
419 CatLog.d(LOG_TAG, "isDialogPending: " + mStkContext[slotId].mIsDialogPending);
420 return mStkContext[slotId].mIsDialogPending;
421 }
422 return false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800423 }
424
425 /*
426 * Package api used by StkMenuActivity to get its Menu parameter.
427 */
Wink Savillee68857d2014-10-17 15:23:05 -0700428 Menu getMenu(int slotId) {
429 CatLog.d(LOG_TAG, "StkAppService, getMenu, sim id: " + slotId);
430 if (slotId >=0 && slotId < mSimCount) {
431 return mStkContext[slotId].mCurrentMenu;
432 } else {
433 return null;
434 }
435 }
436
437 /*
438 * Package api used by StkMenuActivity to get its Main Menu parameter.
439 */
440 Menu getMainMenu(int slotId) {
441 CatLog.d(LOG_TAG, "StkAppService, getMainMenu, sim id: " + slotId);
w30234a08cffe2015-02-04 15:13:25 -0800442 if (slotId >=0 && slotId < mSimCount && (mStkContext[slotId].mMainCmd != null)) {
Wink Savillee68857d2014-10-17 15:23:05 -0700443 return mStkContext[slotId].mMainCmd.getMenu();
444 } else {
445 return null;
446 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800447 }
448
449 /*
450 * Package api used by UI Activities and Dialogs to communicate directly
451 * with the service to deliver state information and parameters.
452 */
453 static StkAppService getInstance() {
454 return sInstance;
455 }
456
457 private void waitForLooper() {
458 while (mServiceHandler == null) {
459 synchronized (this) {
460 try {
461 wait(100);
462 } catch (InterruptedException e) {
463 }
464 }
465 }
466 }
467
468 private final class ServiceHandler extends Handler {
469 @Override
470 public void handleMessage(Message msg) {
Wink Savillee68857d2014-10-17 15:23:05 -0700471 if(null == msg) {
472 CatLog.d(LOG_TAG, "ServiceHandler handleMessage msg is null");
473 return;
474 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800475 int opcode = msg.arg1;
Wink Savillee68857d2014-10-17 15:23:05 -0700476 int slotId = msg.arg2;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800477
Wink Savillee68857d2014-10-17 15:23:05 -0700478 CatLog.d(LOG_TAG, "handleMessage opcode[" + opcode + "], sim id[" + slotId + "]");
479 if (opcode == OP_CMD && msg.obj != null &&
480 ((CatCmdMessage)msg.obj).getCmdType()!= null) {
481 CatLog.d(LOG_TAG, "cmdName[" + ((CatCmdMessage)msg.obj).getCmdType().name() + "]");
482 }
483 mStkContext[slotId].mOpCode = opcode;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800484 switch (opcode) {
485 case OP_LAUNCH_APP:
Wink Savillee68857d2014-10-17 15:23:05 -0700486 if (mStkContext[slotId].mMainCmd == null) {
487 CatLog.d(LOG_TAG, "mMainCmd is null");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800488 // nothing todo when no SET UP MENU command didn't arrive.
489 return;
490 }
Wink Savillee68857d2014-10-17 15:23:05 -0700491 CatLog.d(LOG_TAG, "handleMessage OP_LAUNCH_APP - mCmdInProgress[" +
492 mStkContext[slotId].mCmdInProgress + "]");
493
494 //If there is a pending activity for the slot id,
495 //just finish it and create a new one to handle the pending command.
496 cleanUpInstanceStackBySlot(slotId);
497
Wink Savillee68857d2014-10-17 15:23:05 -0700498 CatLog.d(LOG_TAG, "Current cmd type: " +
499 mStkContext[slotId].mCurrentCmd.getCmdType());
500 //Restore the last command from stack by slot id.
501 restoreInstanceFromStackBySlot(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800502 break;
503 case OP_CMD:
Wink Savillee68857d2014-10-17 15:23:05 -0700504 CatLog.d(LOG_TAG, "[OP_CMD]");
Alex Yakavenkad41f1d92010-07-12 14:13:13 -0700505 CatCmdMessage cmdMsg = (CatCmdMessage) msg.obj;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800506 // There are two types of commands:
507 // 1. Interactive - user's response is required.
508 // 2. Informative - display a message, no interaction with the user.
509 //
Wink Saville79085fc2009-06-09 10:27:23 -0700510 // Informative commands can be handled immediately without any delay.
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800511 // Interactive commands can't override each other. So if a command
512 // is already in progress, we need to queue the next command until
513 // the user has responded or a timeout expired.
514 if (!isCmdInteractive(cmdMsg)) {
Wink Savillee68857d2014-10-17 15:23:05 -0700515 handleCmd(cmdMsg, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800516 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700517 if (!mStkContext[slotId].mCmdInProgress) {
518 mStkContext[slotId].mCmdInProgress = true;
519 handleCmd((CatCmdMessage) msg.obj, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800520 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700521 CatLog.d(LOG_TAG, "[Interactive][in progress]");
522 mStkContext[slotId].mCmdsQ.addLast(new DelayedCmd(OP_CMD,
523 (CatCmdMessage) msg.obj, slotId));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800524 }
525 }
526 break;
527 case OP_RESPONSE:
Preeti Ahuja414bc412013-06-25 19:31:49 -0700528 handleCmdResponse((Bundle) msg.obj, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800529 // call delayed commands if needed.
Wink Savillee68857d2014-10-17 15:23:05 -0700530 if (mStkContext[slotId].mCmdsQ.size() != 0) {
531 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800532 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700533 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800534 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800535 break;
536 case OP_END_SESSION:
Wink Savillee68857d2014-10-17 15:23:05 -0700537 if (!mStkContext[slotId].mCmdInProgress) {
538 mStkContext[slotId].mCmdInProgress = true;
539 handleSessionEnd(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800540 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700541 mStkContext[slotId].mCmdsQ.addLast(
542 new DelayedCmd(OP_END_SESSION, null, slotId));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800543 }
544 break;
545 case OP_BOOT_COMPLETED:
Wink Savillee68857d2014-10-17 15:23:05 -0700546 CatLog.d(LOG_TAG, " OP_BOOT_COMPLETED");
547 int i = 0;
548 for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) {
549 if (mStkContext[i].mMainCmd != null) {
550 break;
551 }
552 }
553 if (i == mSimCount) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800554 StkAppInstaller.unInstall(mContext);
555 }
556 break;
557 case OP_DELAYED_MSG:
Wink Savillee68857d2014-10-17 15:23:05 -0700558 handleDelayedCmd(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800559 break;
Wink Saville94e982b2014-07-11 07:38:14 -0700560 case OP_CARD_STATUS_CHANGED:
Wink Savillee68857d2014-10-17 15:23:05 -0700561 CatLog.d(LOG_TAG, "Card/Icc Status change received");
562 handleCardStatusChangeAndIccRefresh((Bundle) msg.obj, slotId);
563 break;
564 case OP_SET_ACT_INST:
565 Activity act = new Activity();
566 act = (Activity) msg.obj;
567 CatLog.d(LOG_TAG, "Set activity instance. " + act);
568 mStkContext[slotId].mActivityInstance = act;
569 break;
570 case OP_SET_DAL_INST:
571 Activity dal = new Activity();
572 CatLog.d(LOG_TAG, "Set dialog instance. " + dal);
573 dal = (Activity) msg.obj;
574 mStkContext[slotId].mDialogInstance = dal;
575 break;
576 case OP_SET_MAINACT_INST:
577 Activity mainAct = new Activity();
578 mainAct = (Activity) msg.obj;
579 CatLog.d(LOG_TAG, "Set activity instance. " + mainAct);
580 mStkContext[slotId].mMainActivityInstance = mainAct;
Wink Saville94e982b2014-07-11 07:38:14 -0700581 break;
Preeti Ahuja95919342013-10-01 18:18:55 -0700582 case OP_LOCALE_CHANGED:
583 CatLog.d(this, "Locale Changed");
584 checkForSetupEvent(LANGUAGE_SELECTION_EVENT,(Bundle) msg.obj, slotId);
585 break;
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +0530586 case OP_ALPHA_NOTIFY:
587 handleAlphaNotify((Bundle) msg.obj);
588 break;
Preeti Ahuja560be362014-11-25 19:38:24 -0800589 case OP_IDLE_SCREEN:
590 for (int slot = 0; slot < mSimCount; slot++) {
591 if (mStkContext[slot] != null) {
592 handleIdleScreen(slot);
593 }
594 }
595 break;
Wink Saville94e982b2014-07-11 07:38:14 -0700596 }
597 }
598
Wink Savillee68857d2014-10-17 15:23:05 -0700599 private void handleCardStatusChangeAndIccRefresh(Bundle args, int slotId) {
Wink Saville94e982b2014-07-11 07:38:14 -0700600 boolean cardStatus = args.getBoolean(AppInterface.CARD_STATUS);
601
Wink Savillee68857d2014-10-17 15:23:05 -0700602 CatLog.d(LOG_TAG, "CardStatus: " + cardStatus);
Wink Saville94e982b2014-07-11 07:38:14 -0700603 if (cardStatus == false) {
Wink Savillee68857d2014-10-17 15:23:05 -0700604 CatLog.d(LOG_TAG, "CARD is ABSENT");
Wink Saville94e982b2014-07-11 07:38:14 -0700605 // Uninstall STKAPP, Clear Idle text, Stop StkAppService
Wink Savillee68857d2014-10-17 15:23:05 -0700606 mNotificationManager.cancel(getNotificationId(slotId));
607 if (isAllOtherCardsAbsent(slotId)) {
608 CatLog.d(LOG_TAG, "All CARDs are ABSENT");
609 StkAppInstaller.unInstall(mContext);
610 stopSelf();
611 }
Wink Saville94e982b2014-07-11 07:38:14 -0700612 } else {
613 IccRefreshResponse state = new IccRefreshResponse();
614 state.refreshResult = args.getInt(AppInterface.REFRESH_RESULT);
615
Wink Savillee68857d2014-10-17 15:23:05 -0700616 CatLog.d(LOG_TAG, "Icc Refresh Result: "+ state.refreshResult);
Wink Saville94e982b2014-07-11 07:38:14 -0700617 if ((state.refreshResult == IccRefreshResponse.REFRESH_RESULT_INIT) ||
618 (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET)) {
619 // Clear Idle Text
Wink Savillee68857d2014-10-17 15:23:05 -0700620 mNotificationManager.cancel(getNotificationId(slotId));
Wink Saville94e982b2014-07-11 07:38:14 -0700621 }
622
623 if (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET) {
624 // Uninstall STkmenu
Wink Savillee68857d2014-10-17 15:23:05 -0700625 if (isAllOtherCardsAbsent(slotId)) {
626 StkAppInstaller.unInstall(mContext);
627 }
628 mStkContext[slotId].mCurrentMenu = null;
629 mStkContext[slotId].mMainCmd = null;
Wink Saville94e982b2014-07-11 07:38:14 -0700630 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800631 }
632 }
633 }
Wink Savillee68857d2014-10-17 15:23:05 -0700634 /*
635 * Check if all SIMs are absent except the id of slot equals "slotId".
636 */
637 private boolean isAllOtherCardsAbsent(int slotId) {
638 TelephonyManager mTm = (TelephonyManager) mContext.getSystemService(
639 Context.TELEPHONY_SERVICE);
640 int i = 0;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800641
Wink Savillee68857d2014-10-17 15:23:05 -0700642 for (i = 0; i < mSimCount; i++) {
643 if (i != slotId && mTm.hasIccCard(i)) {
644 break;
645 }
646 }
647 if (i == mSimCount) {
648 return true;
649 } else {
650 return false;
651 }
652 }
Preeti Ahuja95919342013-10-01 18:18:55 -0700653
Preeti Ahuja560be362014-11-25 19:38:24 -0800654 /*
655 * If the device is not in an interactive state, we can assume
656 * that the screen is idle.
657 */
658 private boolean isScreenIdle() {
659 return (!mPowerManager.isInteractive());
660 }
661
662 private void handleIdleScreen(int slotId) {
663
664 // If the idle screen event is present in the list need to send the
665 // response to SIM.
666 CatLog.d(this, "Need to send IDLE SCREEN Available event to SIM");
667 checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId);
668
669 if (mStkContext[slotId].mIdleModeTextCmd != null) {
670 launchIdleText(slotId);
671 }
672 }
673
674 private void sendScreenBusyResponse(int slotId) {
675 if (mStkContext[slotId].mCurrentCmd == null) {
676 return;
677 }
678 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd);
679 CatLog.d(this, "SCREEN_BUSY");
680 resMsg.setResultCode(ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS);
681 mStkService[slotId].onCmdResponse(resMsg);
682 if (mStkContext[slotId].mCmdsQ.size() != 0) {
683 callDelayedMsg(slotId);
684 } else {
685 mStkContext[slotId].mCmdInProgress = false;
686 }
687 }
688
Preeti Ahuja95919342013-10-01 18:18:55 -0700689 private void sendResponse(int resId, int slotId, boolean confirm) {
690 Message msg = mServiceHandler.obtainMessage();
691 msg.arg1 = OP_RESPONSE;
692 Bundle args = new Bundle();
693 args.putInt(StkAppService.RES_ID, resId);
694 args.putInt(SLOT_ID, slotId);
695 args.putBoolean(StkAppService.CONFIRMATION, confirm);
696 msg.obj = args;
697 mServiceHandler.sendMessage(msg);
698 }
699
Alex Yakavenkad41f1d92010-07-12 14:13:13 -0700700 private boolean isCmdInteractive(CatCmdMessage cmd) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800701 switch (cmd.getCmdType()) {
702 case SEND_DTMF:
703 case SEND_SMS:
704 case SEND_SS:
705 case SEND_USSD:
706 case SET_UP_IDLE_MODE_TEXT:
707 case SET_UP_MENU:
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500708 case CLOSE_CHANNEL:
709 case RECEIVE_DATA:
710 case SEND_DATA:
Preeti Ahuja95919342013-10-01 18:18:55 -0700711 case SET_UP_EVENT_LIST:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800712 return false;
713 }
714
715 return true;
716 }
717
Wink Savillee68857d2014-10-17 15:23:05 -0700718 private void handleDelayedCmd(int slotId) {
719 CatLog.d(LOG_TAG, "handleDelayedCmd, slotId: " + slotId);
720 if (mStkContext[slotId].mCmdsQ.size() != 0) {
721 DelayedCmd cmd = mStkContext[slotId].mCmdsQ.poll();
722 if (cmd != null) {
723 CatLog.d(LOG_TAG, "handleDelayedCmd - queue size: " +
724 mStkContext[slotId].mCmdsQ.size() +
725 " id: " + cmd.id + "sim id: " + cmd.slotId);
726 switch (cmd.id) {
727 case OP_CMD:
728 handleCmd(cmd.msg, cmd.slotId);
729 break;
730 case OP_END_SESSION:
731 handleSessionEnd(cmd.slotId);
732 break;
733 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800734 }
735 }
736 }
737
Wink Savillee68857d2014-10-17 15:23:05 -0700738 private void callDelayedMsg(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800739 Message msg = mServiceHandler.obtainMessage();
740 msg.arg1 = OP_DELAYED_MSG;
Wink Savillee68857d2014-10-17 15:23:05 -0700741 msg.arg2 = slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800742 mServiceHandler.sendMessage(msg);
743 }
744
Wink Savillee68857d2014-10-17 15:23:05 -0700745 private void callSetActivityInstMsg(int inst_type, int slotId, Object obj) {
746 Message msg = mServiceHandler.obtainMessage();
747 msg.obj = obj;
748 msg.arg1 = inst_type;
749 msg.arg2 = slotId;
750 mServiceHandler.sendMessage(msg);
751 }
752
753 private void handleSessionEnd(int slotId) {
Legler Wuaeefef52014-10-27 00:57:18 +0800754 // We should finish all pending activity if receiving END SESSION command.
755 cleanUpInstanceStackBySlot(slotId);
756
Wink Savillee68857d2014-10-17 15:23:05 -0700757 mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
758 CatLog.d(LOG_TAG, "[handleSessionEnd] - mCurrentCmd changed to mMainCmd!.");
759 mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mMainCmd;
760 CatLog.d(LOG_TAG, "slotId: " + slotId + ", mMenuState: " +
761 mStkContext[slotId].mMenuState);
762
763 mStkContext[slotId].mIsInputPending = false;
764 mStkContext[slotId].mIsMenuPending = false;
765 mStkContext[slotId].mIsDialogPending = false;
766
Wink Savillee68857d2014-10-17 15:23:05 -0700767 if (mStkContext[slotId].mMainCmd == null) {
768 CatLog.d(LOG_TAG, "[handleSessionEnd][mMainCmd is null!]");
769 }
770 mStkContext[slotId].lastSelectedItem = null;
Wink Saville79085fc2009-06-09 10:27:23 -0700771 // In case of SET UP MENU command which removed the app, don't
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800772 // update the current menu member.
Wink Savillee68857d2014-10-17 15:23:05 -0700773 if (mStkContext[slotId].mCurrentMenu != null && mStkContext[slotId].mMainCmd != null) {
774 mStkContext[slotId].mCurrentMenu = mStkContext[slotId].mMainCmd.getMenu();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800775 }
Wink Savillee68857d2014-10-17 15:23:05 -0700776 CatLog.d(LOG_TAG, "[handleSessionEnd][mMenuState]" + mStkContext[slotId].mMenuIsVisible);
777 // In mutiple instance architecture, the main menu for slotId will be finished when user
778 // goes to the Stk menu of the other SIM. So, we should launch a new instance for the
779 // main menu if the main menu instance has been finished.
780 // If the current menu is secondary menu, we should launch main menu.
781 if (StkMenuActivity.STATE_SECONDARY == mStkContext[slotId].mMenuState) {
782 launchMenuActivity(null, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800783 }
Wink Savillee68857d2014-10-17 15:23:05 -0700784 if (mStkContext[slotId].mCmdsQ.size() != 0) {
785 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800786 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700787 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800788 }
789 // In case a launch browser command was just confirmed, launch that url.
Wink Savillee68857d2014-10-17 15:23:05 -0700790 if (mStkContext[slotId].launchBrowser) {
791 mStkContext[slotId].launchBrowser = false;
792 launchBrowser(mStkContext[slotId].mBrowserSettings);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800793 }
794 }
795
Preeti Ahuja560be362014-11-25 19:38:24 -0800796 // returns true if any Stk related activity already has focus on the screen
797 private boolean isTopOfStack() {
798 ActivityManager mAcivityManager = (ActivityManager) mContext
799 .getSystemService(ACTIVITY_SERVICE);
800 String currentPackageName = mAcivityManager.getRunningTasks(1).get(0).topActivity
801 .getPackageName();
802 if (null != currentPackageName) {
803 return currentPackageName.equals(PACKAGE_NAME);
804 }
805
806 return false;
807 }
808
Wink Savillee68857d2014-10-17 15:23:05 -0700809 private void handleCmd(CatCmdMessage cmdMsg, int slotId) {
Preeti Ahuja95919342013-10-01 18:18:55 -0700810
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800811 if (cmdMsg == null) {
812 return;
813 }
814 // save local reference for state tracking.
Wink Savillee68857d2014-10-17 15:23:05 -0700815 mStkContext[slotId].mCurrentCmd = cmdMsg;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800816 boolean waitForUsersResponse = true;
817
Wink Savillee68857d2014-10-17 15:23:05 -0700818 mStkContext[slotId].mIsInputPending = false;
819 mStkContext[slotId].mIsMenuPending = false;
820 mStkContext[slotId].mIsDialogPending = false;
821
822 CatLog.d(LOG_TAG,"[handleCmd]" + cmdMsg.getCmdType().name());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800823 switch (cmdMsg.getCmdType()) {
824 case DISPLAY_TEXT:
825 TextMessage msg = cmdMsg.geTextMessage();
Jeevaka Badrappan854a25c2012-12-01 16:32:03 +0200826 waitForUsersResponse = msg.responseNeeded;
Wink Savillee68857d2014-10-17 15:23:05 -0700827 if (mStkContext[slotId].lastSelectedItem != null) {
828 msg.title = mStkContext[slotId].lastSelectedItem;
829 } else if (mStkContext[slotId].mMainCmd != null){
830 msg.title = mStkContext[slotId].mMainCmd.getMenu().title;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800831 } else {
832 // TODO: get the carrier name from the SIM
833 msg.title = "";
834 }
Preeti Ahuja560be362014-11-25 19:38:24 -0800835 //If we receive a low priority Display Text and the device is
836 // not displaying any STK related activity and the screen is not idle
837 // ( that is, device is in an interactive state), then send a screen busy
838 // terminal response. Otherwise display the message. The existing
839 // displayed message shall be updated with the new display text
840 // proactive command (Refer to ETSI TS 102 384 section 27.22.4.1.4.4.2).
841 if (!(msg.isHighPriority || mStkContext[slotId].mMenuIsVisible
842 || mStkContext[slotId].mDisplayTextDlgIsVisibile || isTopOfStack())) {
843 if(!isScreenIdle()) {
844 CatLog.d(LOG_TAG, "Screen is not idle");
845 sendScreenBusyResponse(slotId);
846 } else {
847 launchTextDialog(slotId);
848 }
849 } else {
850 launchTextDialog(slotId);
851 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800852 break;
853 case SELECT_ITEM:
Wink Savillee68857d2014-10-17 15:23:05 -0700854 CatLog.d(LOG_TAG, "SELECT_ITEM +");
855 mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd;
856 mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu();
857 launchMenuActivity(cmdMsg.getMenu(), slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800858 break;
859 case SET_UP_MENU:
Wink Savillee68857d2014-10-17 15:23:05 -0700860 mStkContext[slotId].mCmdInProgress = false;
861 mStkContext[slotId].mMainCmd = mStkContext[slotId].mCurrentCmd;
862 mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd;
863 mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu();
864 CatLog.d(LOG_TAG, "SET_UP_MENU [" + removeMenu(slotId) + "]");
865
866 if (removeMenu(slotId)) {
867 int i = 0;
868 CatLog.d(LOG_TAG, "removeMenu() - Uninstall App");
869 mStkContext[slotId].mCurrentMenu = null;
Preeti Ahuja95919342013-10-01 18:18:55 -0700870 mStkContext[slotId].mMainCmd = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700871 //Check other setup menu state. If all setup menu are removed, uninstall apk.
872 for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) {
873 if (i != slotId
874 && (mStkContext[slotId].mSetupMenuState == STATE_UNKNOWN
875 || mStkContext[slotId].mSetupMenuState == STATE_EXIST)) {
876 CatLog.d(LOG_TAG, "Not Uninstall App:" + i + ","
877 + mStkContext[slotId].mSetupMenuState);
878 break;
879 }
880 }
881 if (i == mSimCount) {
882 StkAppInstaller.unInstall(mContext);
883 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800884 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700885 CatLog.d(LOG_TAG, "install App");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800886 StkAppInstaller.install(mContext);
887 }
Wink Savillee68857d2014-10-17 15:23:05 -0700888 if (mStkContext[slotId].mMenuIsVisible) {
889 launchMenuActivity(null, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800890 }
891 break;
892 case GET_INPUT:
893 case GET_INKEY:
Wink Savillee68857d2014-10-17 15:23:05 -0700894 launchInputActivity(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800895 break;
896 case SET_UP_IDLE_MODE_TEXT:
897 waitForUsersResponse = false;
Preeti Ahuja560be362014-11-25 19:38:24 -0800898 mStkContext[slotId].mIdleModeTextCmd = mStkContext[slotId].mCurrentCmd;
899 TextMessage idleModeText = mStkContext[slotId].mCurrentCmd.geTextMessage();
900 if (idleModeText == null) {
901 launchIdleText(slotId);
902 mStkContext[slotId].mIdleModeTextCmd = null;
903 }
904 mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
905 if ((mStkContext[slotId].mIdleModeTextCmd != null) && isScreenIdle()) {
906 CatLog.d(this, "set up idle mode");
907 launchIdleText(slotId);
908 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800909 break;
910 case SEND_DTMF:
911 case SEND_SMS:
912 case SEND_SS:
913 case SEND_USSD:
Preeti Ahuja95919342013-10-01 18:18:55 -0700914 case GET_CHANNEL_STATUS:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800915 waitForUsersResponse = false;
Wink Savillee68857d2014-10-17 15:23:05 -0700916 launchEventMessage(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800917 break;
918 case LAUNCH_BROWSER:
Ryuto Sawada0bdc7192016-04-18 12:10:56 +0900919 // The device setup process should not be interrupted by launching browser.
920 if (Settings.Global.getInt(mContext.getContentResolver(),
921 Settings.Global.DEVICE_PROVISIONED, 0) == 0) {
922 CatLog.d(this, "The command is not performed if the setup has not been completed.");
923 sendScreenBusyResponse(slotId);
924 break;
925 }
Preeti Ahujaa7cdca22013-10-01 18:20:56 -0700926 TextMessage alphaId = mStkContext[slotId].mCurrentCmd.geTextMessage();
927 if ((mStkContext[slotId].mCurrentCmd.getBrowserSettings().mode
928 == LaunchBrowserMode.LAUNCH_IF_NOT_ALREADY_LAUNCHED) &&
929 ((alphaId == null) || TextUtils.isEmpty(alphaId.text))) {
930 // don't need user confirmation in this case
931 // just launch the browser or spawn a new tab
932 CatLog.d(this, "Browser mode is: launch if not already launched " +
933 "and user confirmation is not currently needed.\n" +
934 "supressing confirmation dialogue and confirming silently...");
935 mStkContext[slotId].launchBrowser = true;
936 mStkContext[slotId].mBrowserSettings =
937 mStkContext[slotId].mCurrentCmd.getBrowserSettings();
938 sendResponse(RES_ID_CONFIRM, slotId, true);
939 } else {
940 launchConfirmationDialog(alphaId, slotId);
941 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800942 break;
943 case SET_UP_CALL:
Preeti Ahujadd240102013-08-30 17:25:06 -0700944 TextMessage mesg = mStkContext[slotId].mCurrentCmd.getCallSettings().confirmMsg;
945 if((mesg != null) && (mesg.text == null || mesg.text.length() == 0)) {
946 mesg.text = getResources().getString(R.string.default_setup_call_msg);
947 }
948 CatLog.d(this, "SET_UP_CALL mesg.text " + mesg.text);
949 launchConfirmationDialog(mesg, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800950 break;
951 case PLAY_TONE:
Wink Savillee68857d2014-10-17 15:23:05 -0700952 launchToneDialog(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800953 break;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500954 case OPEN_CHANNEL:
Wink Savillee68857d2014-10-17 15:23:05 -0700955 launchOpenChannelDialog(slotId);
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500956 break;
957 case CLOSE_CHANNEL:
958 case RECEIVE_DATA:
959 case SEND_DATA:
Wink Savillee68857d2014-10-17 15:23:05 -0700960 TextMessage m = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500961
962 if ((m != null) && (m.text == null)) {
963 switch(cmdMsg.getCmdType()) {
964 case CLOSE_CHANNEL:
965 m.text = getResources().getString(R.string.default_close_channel_msg);
966 break;
967 case RECEIVE_DATA:
968 m.text = getResources().getString(R.string.default_receive_data_msg);
969 break;
970 case SEND_DATA:
971 m.text = getResources().getString(R.string.default_send_data_msg);
972 break;
973 }
974 }
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -0700975 /*
976 * Display indication in the form of a toast to the user if required.
977 */
Wink Savillee68857d2014-10-17 15:23:05 -0700978 launchEventMessage(slotId);
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500979 break;
Preeti Ahuja95919342013-10-01 18:18:55 -0700980 case SET_UP_EVENT_LIST:
981 mStkContext[slotId].mSetupEventListSettings =
982 mStkContext[slotId].mCurrentCmd.getSetEventList();
983 mStkContext[slotId].mCurrentSetupEventCmd = mStkContext[slotId].mCurrentCmd;
984 mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
Preeti Ahuja560be362014-11-25 19:38:24 -0800985 if (isScreenIdle()) {
986 CatLog.d(this," Check if IDLE_SCREEN_AVAILABLE_EVENT is present in List");
987 checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId);
988 }
Preeti Ahuja95919342013-10-01 18:18:55 -0700989 break;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800990 }
991
992 if (!waitForUsersResponse) {
Wink Savillee68857d2014-10-17 15:23:05 -0700993 if (mStkContext[slotId].mCmdsQ.size() != 0) {
994 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800995 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700996 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800997 }
998 }
999 }
1000
Wink Savillee68857d2014-10-17 15:23:05 -07001001 private void handleCmdResponse(Bundle args, int slotId) {
1002 CatLog.d(LOG_TAG, "handleCmdResponse, sim id: " + slotId);
1003 if (mStkContext[slotId].mCurrentCmd == null) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001004 return;
1005 }
Wink Savillee68857d2014-10-17 15:23:05 -07001006
1007 if (mStkService[slotId] == null) {
Legler Wuaeefef52014-10-27 00:57:18 +08001008 mStkService[slotId] = CatService.getInstance(slotId);
Wink Savillee68857d2014-10-17 15:23:05 -07001009 if (mStkService[slotId] == null) {
Alex Yakavenkad8e2ecd2012-04-20 17:10:15 -07001010 // This should never happen (we should be responding only to a message
1011 // that arrived from StkService). It has to exist by this time
Wink Savillee68857d2014-10-17 15:23:05 -07001012 CatLog.d(LOG_TAG, "Exception! mStkService is null when we need to send response.");
Alex Yakavenkad8e2ecd2012-04-20 17:10:15 -07001013 throw new RuntimeException("mStkService is null when we need to send response");
1014 }
1015 }
1016
Wink Savillee68857d2014-10-17 15:23:05 -07001017 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001018
1019 // set result code
1020 boolean helpRequired = args.getBoolean(HELP, false);
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001021 boolean confirmed = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001022
1023 switch(args.getInt(RES_ID)) {
1024 case RES_ID_MENU_SELECTION:
Wink Savillee68857d2014-10-17 15:23:05 -07001025 CatLog.d(LOG_TAG, "MENU_SELECTION=" + mStkContext[slotId].
1026 mCurrentMenuCmd.getCmdType());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001027 int menuSelection = args.getInt(MENU_SELECTION);
Wink Savillee68857d2014-10-17 15:23:05 -07001028 switch(mStkContext[slotId].mCurrentMenuCmd.getCmdType()) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001029 case SET_UP_MENU:
1030 case SELECT_ITEM:
Wink Savillee68857d2014-10-17 15:23:05 -07001031 mStkContext[slotId].lastSelectedItem = getItemName(menuSelection, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001032 if (helpRequired) {
1033 resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED);
1034 } else {
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301035 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1036 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001037 }
1038 resMsg.setMenuSelection(menuSelection);
1039 break;
1040 }
1041 break;
1042 case RES_ID_INPUT:
Wink Savillee68857d2014-10-17 15:23:05 -07001043 CatLog.d(LOG_TAG, "RES_ID_INPUT");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001044 String input = args.getString(INPUT);
Wink Savillee68857d2014-10-17 15:23:05 -07001045 if (input != null && (null != mStkContext[slotId].mCurrentCmd.geInput()) &&
1046 (mStkContext[slotId].mCurrentCmd.geInput().yesNo)) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001047 boolean yesNoSelection = input
1048 .equals(StkInputActivity.YES_STR_RESPONSE);
1049 resMsg.setYesNo(yesNoSelection);
1050 } else {
1051 if (helpRequired) {
1052 resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED);
1053 } else {
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301054 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1055 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001056 resMsg.setInput(input);
1057 }
1058 }
1059 break;
1060 case RES_ID_CONFIRM:
Alex Yakavenkad41f1d92010-07-12 14:13:13 -07001061 CatLog.d(this, "RES_ID_CONFIRM");
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001062 confirmed = args.getBoolean(CONFIRMATION);
Wink Savillee68857d2014-10-17 15:23:05 -07001063 switch (mStkContext[slotId].mCurrentCmd.getCmdType()) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001064 case DISPLAY_TEXT:
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301065 if (confirmed) {
1066 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1067 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
1068 } else {
1069 resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER);
1070 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001071 break;
1072 case LAUNCH_BROWSER:
1073 resMsg.setResultCode(confirmed ? ResultCode.OK
1074 : ResultCode.UICC_SESSION_TERM_BY_USER);
1075 if (confirmed) {
Wink Savillee68857d2014-10-17 15:23:05 -07001076 mStkContext[slotId].launchBrowser = true;
1077 mStkContext[slotId].mBrowserSettings =
1078 mStkContext[slotId].mCurrentCmd.getBrowserSettings();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001079 }
1080 break;
1081 case SET_UP_CALL:
1082 resMsg.setResultCode(ResultCode.OK);
1083 resMsg.setConfirmation(confirmed);
1084 if (confirmed) {
w302345ad585e2014-11-04 12:13:38 -08001085 CatLog.d(this, "Going back to mainMenu before starting a call.");
1086 launchMenuActivity(null, slotId);
Wink Savillee68857d2014-10-17 15:23:05 -07001087 launchEventMessage(slotId,
1088 mStkContext[slotId].mCurrentCmd.getCallSettings().callMsg);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001089 }
1090 break;
1091 }
1092 break;
1093 case RES_ID_DONE:
1094 resMsg.setResultCode(ResultCode.OK);
1095 break;
1096 case RES_ID_BACKWARD:
Wink Savillee68857d2014-10-17 15:23:05 -07001097 CatLog.d(LOG_TAG, "RES_ID_BACKWARD");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001098 resMsg.setResultCode(ResultCode.BACKWARD_MOVE_BY_USER);
1099 break;
1100 case RES_ID_END_SESSION:
Wink Savillee68857d2014-10-17 15:23:05 -07001101 CatLog.d(LOG_TAG, "RES_ID_END_SESSION");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001102 resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER);
1103 break;
1104 case RES_ID_TIMEOUT:
Wink Savillee68857d2014-10-17 15:23:05 -07001105 CatLog.d(LOG_TAG, "RES_ID_TIMEOUT");
Naveen Kallad5176892009-11-30 12:45:29 -08001106 // GCF test-case 27.22.4.1.1 Expected Sequence 1.5 (DISPLAY TEXT,
1107 // Clear message after delay, successful) expects result code OK.
1108 // If the command qualifier specifies no user response is required
1109 // then send OK instead of NO_RESPONSE_FROM_USER
Wink Savillee68857d2014-10-17 15:23:05 -07001110 if ((mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1111 AppInterface.CommandType.DISPLAY_TEXT.value())
1112 && (mStkContext[slotId].mCurrentCmd.geTextMessage().userClear == false)) {
Naveen Kallad5176892009-11-30 12:45:29 -08001113 resMsg.setResultCode(ResultCode.OK);
1114 } else {
1115 resMsg.setResultCode(ResultCode.NO_RESPONSE_FROM_USER);
1116 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001117 break;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001118 case RES_ID_CHOICE:
1119 int choice = args.getInt(CHOICE);
1120 CatLog.d(this, "User Choice=" + choice);
1121 switch (choice) {
1122 case YES:
1123 resMsg.setResultCode(ResultCode.OK);
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001124 confirmed = true;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001125 break;
1126 case NO:
1127 resMsg.setResultCode(ResultCode.USER_NOT_ACCEPT);
1128 break;
1129 }
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001130
Wink Savillee68857d2014-10-17 15:23:05 -07001131 if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1132 AppInterface.CommandType.OPEN_CHANNEL.value()) {
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001133 resMsg.setConfirmation(confirmed);
1134 }
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001135 break;
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001136
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001137 default:
Wink Savillee68857d2014-10-17 15:23:05 -07001138 CatLog.d(LOG_TAG, "Unknown result id");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001139 return;
1140 }
Wink Savillee68857d2014-10-17 15:23:05 -07001141
1142 if (null != mStkContext[slotId].mCurrentCmd &&
1143 null != mStkContext[slotId].mCurrentCmd.getCmdType()) {
1144 CatLog.d(LOG_TAG, "handleCmdResponse- cmdName[" +
1145 mStkContext[slotId].mCurrentCmd.getCmdType().name() + "]");
1146 }
1147 mStkService[slotId].onCmdResponse(resMsg);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001148 }
1149
1150 /**
1151 * Returns 0 or FLAG_ACTIVITY_NO_USER_ACTION, 0 means the user initiated the action.
1152 *
1153 * @param userAction If the userAction is yes then we always return 0 otherwise
1154 * mMenuIsVisible is used to determine what to return. If mMenuIsVisible is true
1155 * then we are the foreground app and we'll return 0 as from our perspective a
1156 * user action did cause. If it's false than we aren't the foreground app and
1157 * FLAG_ACTIVITY_NO_USER_ACTION is returned.
Wink Saville79085fc2009-06-09 10:27:23 -07001158 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001159 * @return 0 or FLAG_ACTIVITY_NO_USER_ACTION
1160 */
Wink Savillee68857d2014-10-17 15:23:05 -07001161 private int getFlagActivityNoUserAction(InitiatedByUserAction userAction, int slotId) {
1162 return ((userAction == InitiatedByUserAction.yes) | mStkContext[slotId].mMenuIsVisible)
1163 ? 0 : Intent.FLAG_ACTIVITY_NO_USER_ACTION;
1164 }
1165 /**
1166 * This method is used for cleaning up pending instances in stack.
1167 */
1168 private void cleanUpInstanceStackBySlot(int slotId) {
1169 Activity activity = mStkContext[slotId].getPendingActivityInstance();
1170 Activity dialog = mStkContext[slotId].getPendingDialogInstance();
1171 CatLog.d(LOG_TAG, "cleanUpInstanceStackBySlot slotId: " + slotId);
Legler Wuaeefef52014-10-27 00:57:18 +08001172 if (mStkContext[slotId].mCurrentCmd == null) {
1173 CatLog.d(LOG_TAG, "current cmd is null.");
1174 return;
1175 }
Wink Savillee68857d2014-10-17 15:23:05 -07001176 if (activity != null) {
1177 CatLog.d(LOG_TAG, "current cmd type: " +
1178 mStkContext[slotId].mCurrentCmd.getCmdType());
1179 if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1180 AppInterface.CommandType.GET_INPUT.value() ||
1181 mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1182 AppInterface.CommandType.GET_INKEY.value()) {
1183 mStkContext[slotId].mIsInputPending = true;
1184 } else if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1185 AppInterface.CommandType.SET_UP_MENU.value() ||
1186 mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1187 AppInterface.CommandType.SELECT_ITEM.value()) {
1188 mStkContext[slotId].mIsMenuPending = true;
1189 } else {
1190 }
1191 CatLog.d(LOG_TAG, "finish pending activity.");
1192 activity.finish();
1193 mStkContext[slotId].mActivityInstance = null;
1194 }
1195 if (dialog != null) {
1196 CatLog.d(LOG_TAG, "finish pending dialog.");
1197 mStkContext[slotId].mIsDialogPending = true;
1198 dialog.finish();
1199 mStkContext[slotId].mDialogInstance = null;
1200 }
1201 }
1202 /**
1203 * This method is used for restoring pending instances from stack.
1204 */
1205 private void restoreInstanceFromStackBySlot(int slotId) {
1206 AppInterface.CommandType cmdType = mStkContext[slotId].mCurrentCmd.getCmdType();
1207
1208 CatLog.d(LOG_TAG, "restoreInstanceFromStackBySlot cmdType : " + cmdType);
1209 switch(cmdType) {
1210 case GET_INPUT:
1211 case GET_INKEY:
1212 launchInputActivity(slotId);
1213 //Set mMenuIsVisible to true for showing main menu for
1214 //following session end command.
1215 mStkContext[slotId].mMenuIsVisible = true;
1216 break;
1217 case DISPLAY_TEXT:
1218 launchTextDialog(slotId);
1219 break;
1220 case LAUNCH_BROWSER:
1221 launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.geTextMessage(),
1222 slotId);
1223 break;
1224 case OPEN_CHANNEL:
1225 launchOpenChannelDialog(slotId);
1226 break;
1227 case SET_UP_CALL:
1228 launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.getCallSettings().
1229 confirmMsg, slotId);
1230 break;
1231 case SET_UP_MENU:
1232 case SELECT_ITEM:
1233 launchMenuActivity(null, slotId);
1234 break;
1235 default:
1236 break;
1237 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001238 }
1239
Wink Savillee68857d2014-10-17 15:23:05 -07001240 private void launchMenuActivity(Menu menu, int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001241 Intent newIntent = new Intent(Intent.ACTION_VIEW);
Wink Savillee68857d2014-10-17 15:23:05 -07001242 String targetActivity = STK_MENU_ACTIVITY_NAME;
1243 String uriString = STK_MENU_URI + System.currentTimeMillis();
1244 //Set unique URI to create a new instance of activity for different slotId.
1245 Uri uriData = Uri.parse(uriString);
1246
1247 CatLog.d(LOG_TAG, "launchMenuActivity, slotId: " + slotId + " , " +
1248 uriData.toString() + " , " + mStkContext[slotId].mOpCode + ", "
1249 + mStkContext[slotId].mMenuState);
1250 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1251 int intentFlags = Intent.FLAG_ACTIVITY_NEW_TASK;
1252
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001253 if (menu == null) {
1254 // We assume this was initiated by the user pressing the tool kit icon
Wink Savillee68857d2014-10-17 15:23:05 -07001255 intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.yes, slotId);
1256 if (mStkContext[slotId].mOpCode == OP_END_SESSION) {
1257 CatLog.d(LOG_TAG, "launchMenuActivity, return OP_END_SESSION");
1258 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN;
1259 if (mStkContext[slotId].mMainActivityInstance != null) {
1260 CatLog.d(LOG_TAG, "launchMenuActivity, mMainActivityInstance is not null");
1261 return;
1262 }
Wink Savillee68857d2014-10-17 15:23:05 -07001263 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001264
Wink Savillee68857d2014-10-17 15:23:05 -07001265 //If the last pending menu is secondary menu, "STATE" should be "STATE_SECONDARY".
1266 //Otherwise, it should be "STATE_MAIN".
1267 if (mStkContext[slotId].mOpCode == OP_LAUNCH_APP &&
1268 mStkContext[slotId].mMenuState == StkMenuActivity.STATE_SECONDARY) {
1269 newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY);
1270 } else {
1271 newIntent.putExtra("STATE", StkMenuActivity.STATE_MAIN);
1272 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN;
1273 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001274 } else {
1275 // We don't know and we'll let getFlagActivityNoUserAction decide.
Wink Savillee68857d2014-10-17 15:23:05 -07001276 intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001277 newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY);
Wink Savillee68857d2014-10-17 15:23:05 -07001278 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_SECONDARY;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001279 }
Wink Savillee68857d2014-10-17 15:23:05 -07001280 newIntent.putExtra(SLOT_ID, slotId);
1281 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001282 newIntent.setFlags(intentFlags);
1283 mContext.startActivity(newIntent);
1284 }
1285
Wink Savillee68857d2014-10-17 15:23:05 -07001286 private void launchInputActivity(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001287 Intent newIntent = new Intent(Intent.ACTION_VIEW);
Wink Savillee68857d2014-10-17 15:23:05 -07001288 String targetActivity = STK_INPUT_ACTIVITY_NAME;
1289 String uriString = STK_INPUT_URI + System.currentTimeMillis();
1290 //Set unique URI to create a new instance of activity for different slotId.
1291 Uri uriData = Uri.parse(uriString);
1292
1293 CatLog.d(LOG_TAG, "launchInputActivity, slotId: " + slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001294 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
Wink Savillee68857d2014-10-17 15:23:05 -07001295 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1296 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1297 newIntent.putExtra("INPUT", mStkContext[slotId].mCurrentCmd.geInput());
1298 newIntent.putExtra(SLOT_ID, slotId);
1299 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001300 mContext.startActivity(newIntent);
1301 }
1302
Wink Savillee68857d2014-10-17 15:23:05 -07001303 private void launchTextDialog(int slotId) {
1304 CatLog.d(LOG_TAG, "launchTextDialog, slotId: " + slotId);
1305 Intent newIntent = new Intent();
1306 String targetActivity = STK_DIALOG_ACTIVITY_NAME;
1307 int action = getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId);
1308 String uriString = STK_DIALOG_URI + System.currentTimeMillis();
1309 //Set unique URI to create a new instance of activity for different slotId.
1310 Uri uriData = Uri.parse(uriString);
1311 if (newIntent != null) {
1312 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1313 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1314 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
1315 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1316 newIntent.setData(uriData);
1317 newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage());
1318 newIntent.putExtra(SLOT_ID, slotId);
1319 startActivity(newIntent);
Preeti Ahuja414bc412013-06-25 19:31:49 -07001320 // For display texts with immediate response, send the terminal response
1321 // immediately. responseNeeded will be false, if display text command has
1322 // the immediate response tlv.
1323 if (!mStkContext[slotId].mCurrentCmd.geTextMessage().responseNeeded) {
1324 sendResponse(RES_ID_CONFIRM, slotId, true);
1325 }
Wink Savillee68857d2014-10-17 15:23:05 -07001326 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001327 }
1328
Wink Savillee68857d2014-10-17 15:23:05 -07001329 public boolean isStkDialogActivated(Context context) {
1330 String stkDialogActivity = "com.android.stk.StkDialogActivity";
1331 boolean activated = false;
1332 final ActivityManager am = (ActivityManager) context.getSystemService(
1333 Context.ACTIVITY_SERVICE);
1334 String topActivity = am.getRunningTasks(1).get(0).topActivity.getClassName();
1335
1336 CatLog.d(LOG_TAG, "isStkDialogActivated: " + topActivity);
1337 if (topActivity.equals(stkDialogActivity)) {
1338 activated = true;
1339 }
1340 CatLog.d(LOG_TAG, "activated : " + activated);
1341 return activated;
Johan Hellman3aec01c2011-02-10 10:15:28 +01001342 }
1343
Preeti Ahuja95919342013-10-01 18:18:55 -07001344 private void sendSetUpEventResponse(int event, byte[] addedInfo, int slotId) {
Preeti Ahuja414bc412013-06-25 19:31:49 -07001345 CatLog.d(this, "sendSetUpEventResponse: event : " + event + "slotId = " + slotId);
Preeti Ahuja95919342013-10-01 18:18:55 -07001346
1347 if (mStkContext[slotId].mCurrentSetupEventCmd == null){
1348 CatLog.e(this, "mCurrentSetupEventCmd is null");
1349 return;
1350 }
1351
1352 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentSetupEventCmd);
1353
1354 resMsg.setResultCode(ResultCode.OK);
1355 resMsg.setEventDownload(event, addedInfo);
1356
1357 mStkService[slotId].onCmdResponse(resMsg);
1358 }
1359
1360 private void checkForSetupEvent(int event, Bundle args, int slotId) {
1361 boolean eventPresent = false;
1362 byte[] addedInfo = null;
1363 CatLog.d(this, "Event :" + event);
1364
1365 if (mStkContext[slotId].mSetupEventListSettings != null) {
1366 /* Checks if the event is present in the EventList updated by last
1367 * SetupEventList Proactive Command */
1368 for (int i : mStkContext[slotId].mSetupEventListSettings.eventList) {
1369 if (event == i) {
1370 eventPresent = true;
1371 break;
1372 }
1373 }
1374
1375 /* If Event is present send the response to ICC */
1376 if (eventPresent == true) {
1377 CatLog.d(this, " Event " + event + "exists in the EventList");
1378
1379 switch (event) {
Preeti Ahuja560be362014-11-25 19:38:24 -08001380 case IDLE_SCREEN_AVAILABLE_EVENT:
1381 sendSetUpEventResponse(event, addedInfo, slotId);
1382 removeSetUpEvent(event, slotId);
1383 break;
Preeti Ahuja95919342013-10-01 18:18:55 -07001384 case LANGUAGE_SELECTION_EVENT:
1385 String language = mContext
1386 .getResources().getConfiguration().locale.getLanguage();
1387 CatLog.d(this, "language: " + language);
1388 // Each language code is a pair of alpha-numeric characters.
1389 // Each alpha-numeric character shall be coded on one byte
1390 // using the SMS default 7-bit coded alphabet
1391 addedInfo = GsmAlphabet.stringToGsm8BitPacked(language);
1392 sendSetUpEventResponse(event, addedInfo, slotId);
1393 break;
1394 default:
1395 break;
1396 }
1397 } else {
1398 CatLog.e(this, " Event does not exist in the EventList");
1399 }
1400 } else {
1401 CatLog.e(this, "SetupEventList is not received. Ignoring the event: " + event);
1402 }
1403 }
1404
1405 private void removeSetUpEvent(int event, int slotId) {
1406 CatLog.d(this, "Remove Event :" + event);
1407
1408 if (mStkContext[slotId].mSetupEventListSettings != null) {
1409 /*
1410 * Make new Eventlist without the event
1411 */
1412 for (int i = 0; i < mStkContext[slotId].mSetupEventListSettings.eventList.length; i++) {
1413 if (event == mStkContext[slotId].mSetupEventListSettings.eventList[i]) {
1414 mStkContext[slotId].mSetupEventListSettings.eventList[i] = INVALID_SETUP_EVENT;
1415 break;
1416 }
1417 }
1418 }
1419 }
1420
1421 private void launchEventMessage(int slotId) {
1422 launchEventMessage(slotId, mStkContext[slotId].mCurrentCmd.geTextMessage());
1423 }
1424
Wink Savillee68857d2014-10-17 15:23:05 -07001425 private void launchEventMessage(int slotId, TextMessage msg) {
1426 if (msg == null || (msg.text != null && msg.text.length() == 0)) {
1427 CatLog.d(LOG_TAG, "launchEventMessage return");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001428 return;
1429 }
Wink Savillee68857d2014-10-17 15:23:05 -07001430
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001431 Toast toast = new Toast(mContext.getApplicationContext());
1432 LayoutInflater inflate = (LayoutInflater) mContext
1433 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
1434 View v = inflate.inflate(R.layout.stk_event_msg, null);
1435 TextView tv = (TextView) v
1436 .findViewById(com.android.internal.R.id.message);
1437 ImageView iv = (ImageView) v
1438 .findViewById(com.android.internal.R.id.icon);
1439 if (msg.icon != null) {
1440 iv.setImageBitmap(msg.icon);
1441 } else {
1442 iv.setVisibility(View.GONE);
1443 }
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301444 /* In case of 'self explanatory' stkapp should display the specified
1445 * icon in proactive command (but not the alpha string).
1446 * If icon is non-self explanatory and if the icon could not be displayed
1447 * then alpha string or text data should be displayed
1448 * Ref: ETSI 102.223,section 6.5.4
1449 */
1450 if (mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ||
1451 msg.icon == null || !msg.iconSelfExplanatory) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001452 tv.setText(msg.text);
1453 }
1454
1455 toast.setView(v);
1456 toast.setDuration(Toast.LENGTH_LONG);
1457 toast.setGravity(Gravity.BOTTOM, 0, 0);
1458 toast.show();
1459 }
1460
Wink Savillee68857d2014-10-17 15:23:05 -07001461 private void launchConfirmationDialog(TextMessage msg, int slotId) {
1462 msg.title = mStkContext[slotId].lastSelectedItem;
1463 Intent newIntent = new Intent();
1464 String targetActivity = STK_DIALOG_ACTIVITY_NAME;
1465 String uriString = STK_DIALOG_URI + System.currentTimeMillis();
1466 //Set unique URI to create a new instance of activity for different slotId.
1467 Uri uriData = Uri.parse(uriString);
1468
1469 if (newIntent != null) {
1470 newIntent.setClassName(this, targetActivity);
1471 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1472 | Intent.FLAG_ACTIVITY_NO_HISTORY
1473 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
1474 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1475 newIntent.putExtra("TEXT", msg);
1476 newIntent.putExtra(SLOT_ID, slotId);
1477 newIntent.setData(uriData);
1478 startActivity(newIntent);
1479 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001480 }
1481
1482 private void launchBrowser(BrowserSettings settings) {
1483 if (settings == null) {
1484 return;
1485 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001486
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001487 Uri data = null;
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001488 String url;
1489 if (settings.url == null) {
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001490 // if the command did not contain a URL,
1491 // launch the browser to the default homepage.
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001492 CatLog.d(this, "no url data provided by proactive command." +
1493 " launching browser with stk default URL ... ");
1494 url = SystemProperties.get(STK_BROWSER_DEFAULT_URL_SYSPROP,
1495 "http://www.google.com");
1496 } else {
1497 CatLog.d(this, "launch browser command has attached url = " + settings.url);
1498 url = settings.url;
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001499 }
David Brown7c03cfe2011-10-20 15:36:12 -07001500
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001501 if (url.startsWith("http://") || url.startsWith("https://")) {
1502 data = Uri.parse(url);
1503 CatLog.d(this, "launching browser with url = " + url);
1504 } else {
1505 String modifiedUrl = "http://" + url;
1506 data = Uri.parse(modifiedUrl);
1507 CatLog.d(this, "launching browser with modified url = " + modifiedUrl);
1508 }
1509
1510 Intent intent = new Intent(Intent.ACTION_VIEW);
1511 intent.setData(data);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001512 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1513 switch (settings.mode) {
1514 case USE_EXISTING_BROWSER:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001515 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1516 break;
1517 case LAUNCH_NEW_BROWSER:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001518 intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
1519 break;
1520 case LAUNCH_IF_NOT_ALREADY_LAUNCHED:
1521 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1522 break;
1523 }
1524 // start browser activity
1525 startActivity(intent);
1526 // a small delay, let the browser start, before processing the next command.
Wink Saville79085fc2009-06-09 10:27:23 -07001527 // this is good for scenarios where a related DISPLAY TEXT command is
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001528 // followed immediately.
1529 try {
Ryuto Sawada350aaa62016-06-13 14:47:22 +09001530 Thread.sleep(3000);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001531 } catch (InterruptedException e) {}
1532 }
1533
Wink Savillee68857d2014-10-17 15:23:05 -07001534 private void launchIdleText(int slotId) {
Preeti Ahuja560be362014-11-25 19:38:24 -08001535 TextMessage msg = mStkContext[slotId].mIdleModeTextCmd.geTextMessage();
dujin.cha2a0eb2a2011-11-11 15:03:57 +09001536
Preeti Ahuja95919342013-10-01 18:18:55 -07001537 if (msg == null || msg.text ==null) {
1538 CatLog.d(LOG_TAG, msg == null ? "mCurrent.getTextMessage is NULL"
1539 : "mCurrent.getTextMessage.text is NULL");
Wink Savillee68857d2014-10-17 15:23:05 -07001540 mNotificationManager.cancel(getNotificationId(slotId));
Wink Saville046db4b2011-11-01 20:42:54 -07001541 return;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001542 } else {
Preeti Ahuja95919342013-10-01 18:18:55 -07001543 CatLog.d(LOG_TAG, "launchIdleText - text[" + msg.text
1544 + "] iconSelfExplanatory[" + msg.iconSelfExplanatory
1545 + "] icon[" + msg.icon + "], sim id: " + slotId);
Wink Savillee68857d2014-10-17 15:23:05 -07001546 CatLog.d(LOG_TAG, "Add IdleMode text");
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001547 PendingIntent pendingIntent = PendingIntent.getService(mContext, 0,
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001548 new Intent(mContext, StkAppService.class), 0);
1549
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001550 final Notification.Builder notificationBuilder = new Notification.Builder(
1551 StkAppService.this);
Wink Savillee68857d2014-10-17 15:23:05 -07001552 if (mStkContext[slotId].mMainCmd != null &&
1553 mStkContext[slotId].mMainCmd.getMenu() != null) {
1554 notificationBuilder.setContentTitle(mStkContext[slotId].mMainCmd.getMenu().title);
Christopher Posselwhite2ad2ab72013-05-27 07:51:06 +02001555 } else {
1556 notificationBuilder.setContentTitle("");
1557 }
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001558 notificationBuilder
1559 .setSmallIcon(com.android.internal.R.drawable.stat_notify_sim_toolkit);
1560 notificationBuilder.setContentIntent(pendingIntent);
1561 notificationBuilder.setOngoing(true);
1562 // Set text and icon for the status bar and notification body.
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301563 if (mStkContext[slotId].mIdleModeTextCmd.hasIconLoadFailed() ||
1564 !msg.iconSelfExplanatory) {
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001565 notificationBuilder.setContentText(msg.text);
Christopher Posselwhite2ad2ab72013-05-27 07:51:06 +02001566 notificationBuilder.setTicker(msg.text);
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001567 }
1568 if (msg.icon != null) {
1569 notificationBuilder.setLargeIcon(msg.icon);
1570 } else {
1571 Bitmap bitmapIcon = BitmapFactory.decodeResource(StkAppService.this
1572 .getResources().getSystem(),
1573 com.android.internal.R.drawable.stat_notify_sim_toolkit);
1574 notificationBuilder.setLargeIcon(bitmapIcon);
1575 }
Selim Cinek62eb3fe2014-08-27 17:52:23 +02001576 notificationBuilder.setColor(mContext.getResources().getColor(
1577 com.android.internal.R.color.system_notification_accent_color));
Wink Savillee68857d2014-10-17 15:23:05 -07001578 mNotificationManager.notify(getNotificationId(slotId), notificationBuilder.build());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001579 }
1580 }
1581
Wink Savillee68857d2014-10-17 15:23:05 -07001582 private void launchToneDialog(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001583 Intent newIntent = new Intent(this, ToneDialog.class);
Wink Savillee68857d2014-10-17 15:23:05 -07001584 String uriString = STK_TONE_URI + slotId;
1585 Uri uriData = Uri.parse(uriString);
1586 //Set unique URI to create a new instance of activity for different slotId.
1587 CatLog.d(LOG_TAG, "launchToneDialog, slotId: " + slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001588 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1589 | Intent.FLAG_ACTIVITY_NO_HISTORY
1590 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
Wink Savillee68857d2014-10-17 15:23:05 -07001591 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1592 newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage());
1593 newIntent.putExtra("TONE", mStkContext[slotId].mCurrentCmd.getToneSettings());
1594 newIntent.putExtra(SLOT_ID, slotId);
1595 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001596 startActivity(newIntent);
1597 }
1598
Wink Savillee68857d2014-10-17 15:23:05 -07001599 private void launchOpenChannelDialog(int slotId) {
1600 TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001601 if (msg == null) {
Wink Savillee68857d2014-10-17 15:23:05 -07001602 CatLog.d(LOG_TAG, "msg is null, return here");
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001603 return;
1604 }
1605
1606 msg.title = getResources().getString(R.string.stk_dialog_title);
1607 if (msg.text == null) {
1608 msg.text = getResources().getString(R.string.default_open_channel_msg);
1609 }
1610
1611 final AlertDialog dialog = new AlertDialog.Builder(mContext)
1612 .setIconAttribute(android.R.attr.alertDialogIcon)
1613 .setTitle(msg.title)
1614 .setMessage(msg.text)
1615 .setCancelable(false)
1616 .setPositiveButton(getResources().getString(R.string.stk_dialog_accept),
1617 new DialogInterface.OnClickListener() {
1618 public void onClick(DialogInterface dialog, int which) {
1619 Bundle args = new Bundle();
1620 args.putInt(RES_ID, RES_ID_CHOICE);
1621 args.putInt(CHOICE, YES);
1622 Message message = mServiceHandler.obtainMessage();
1623 message.arg1 = OP_RESPONSE;
1624 message.obj = args;
1625 mServiceHandler.sendMessage(message);
1626 }
1627 })
1628 .setNegativeButton(getResources().getString(R.string.stk_dialog_reject),
1629 new DialogInterface.OnClickListener() {
1630 public void onClick(DialogInterface dialog, int which) {
1631 Bundle args = new Bundle();
1632 args.putInt(RES_ID, RES_ID_CHOICE);
1633 args.putInt(CHOICE, NO);
1634 Message message = mServiceHandler.obtainMessage();
1635 message.arg1 = OP_RESPONSE;
1636 message.obj = args;
1637 mServiceHandler.sendMessage(message);
1638 }
1639 })
1640 .create();
1641
1642 dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
1643 if (!mContext.getResources().getBoolean(
1644 com.android.internal.R.bool.config_sf_slowBlur)) {
1645 dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
1646 }
1647
1648 dialog.show();
1649 }
1650
Wink Savillee68857d2014-10-17 15:23:05 -07001651 private void launchTransientEventMessage(int slotId) {
1652 TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001653 if (msg == null) {
Wink Savillee68857d2014-10-17 15:23:05 -07001654 CatLog.d(LOG_TAG, "msg is null, return here");
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001655 return;
1656 }
1657
1658 msg.title = getResources().getString(R.string.stk_dialog_title);
1659
1660 final AlertDialog dialog = new AlertDialog.Builder(mContext)
1661 .setIconAttribute(android.R.attr.alertDialogIcon)
1662 .setTitle(msg.title)
1663 .setMessage(msg.text)
1664 .setCancelable(false)
1665 .setPositiveButton(getResources().getString(android.R.string.ok),
1666 new DialogInterface.OnClickListener() {
1667 public void onClick(DialogInterface dialog, int which) {
1668 }
1669 })
1670 .create();
1671
1672 dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
1673 if (!mContext.getResources().getBoolean(
1674 com.android.internal.R.bool.config_sf_slowBlur)) {
1675 dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
1676 }
1677
1678 dialog.show();
1679 }
1680
Wink Savillee68857d2014-10-17 15:23:05 -07001681 private int getNotificationId(int slotId) {
1682 int notifyId = STK_NOTIFICATION_ID;
1683 if (slotId >= 0 && slotId < mSimCount) {
1684 notifyId += slotId;
1685 } else {
1686 CatLog.d(LOG_TAG, "invalid slotId: " + slotId);
1687 }
1688 CatLog.d(LOG_TAG, "getNotificationId, slotId: " + slotId + ", notifyId: " + notifyId);
1689 return notifyId;
1690 }
1691
1692 private String getItemName(int itemId, int slotId) {
1693 Menu menu = mStkContext[slotId].mCurrentCmd.getMenu();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001694 if (menu == null) {
1695 return null;
1696 }
1697 for (Item item : menu.items) {
1698 if (item.id == itemId) {
1699 return item.text;
1700 }
1701 }
1702 return null;
1703 }
1704
Wink Savillee68857d2014-10-17 15:23:05 -07001705 private boolean removeMenu(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001706 try {
Wink Savillee68857d2014-10-17 15:23:05 -07001707 if (mStkContext[slotId].mCurrentMenu.items.size() == 1 &&
1708 mStkContext[slotId].mCurrentMenu.items.get(0) == null) {
1709 mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001710 return true;
1711 }
1712 } catch (NullPointerException e) {
Wink Savillee68857d2014-10-17 15:23:05 -07001713 CatLog.d(LOG_TAG, "Unable to get Menu's items size");
1714 mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001715 return true;
1716 }
Wink Savillee68857d2014-10-17 15:23:05 -07001717 mStkContext[slotId].mSetupMenuState = STATE_EXIST;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001718 return false;
1719 }
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +05301720
Wink Savillee68857d2014-10-17 15:23:05 -07001721 StkContext getStkContext(int slotId) {
1722 if (slotId >= 0 && slotId < mSimCount) {
1723 return mStkContext[slotId];
1724 } else {
1725 CatLog.d(LOG_TAG, "invalid slotId: " + slotId);
1726 return null;
1727 }
1728 }
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +05301729
1730 private void handleAlphaNotify(Bundle args) {
1731 String alphaString = args.getString(AppInterface.ALPHA_STRING);
1732
1733 CatLog.d(this, "Alpha string received from card: " + alphaString);
1734 Toast toast = Toast.makeText(sInstance, alphaString, Toast.LENGTH_LONG);
1735 toast.setGravity(Gravity.TOP, 0, 0);
1736 toast.show();
1737 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001738}