blob: c8c8e3822fa63958133897bba48b216cde87c263 [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
Tsukasa Goto029332b2016-10-05 17:12:06 +0900316 && (mStkService[i] != null)
Wink Savillee68857d2014-10-17 15:23:05 -0700317 && (mStkContext[i].mStkServiceState == STATE_UNKNOWN
318 || mStkContext[i].mStkServiceState == STATE_EXIST)) {
319 break;
320 }
321 }
322 } else {
323 mStkContext[slotId].mStkServiceState = STATE_EXIST;
324 }
325 if (i == mSimCount) {
326 stopSelf();
327 StkAppInstaller.unInstall(mContext);
328 return;
329 }
330 }
331
Banavathu, Srinivas Naik87cda962012-07-17 15:32:44 +0530332 waitForLooper();
John Wang62acae42009-10-08 11:20:23 -0700333
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800334 Message msg = mServiceHandler.obtainMessage();
Wink Savillee68857d2014-10-17 15:23:05 -0700335 msg.arg1 = op;
336 msg.arg2 = slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800337 switch(msg.arg1) {
338 case OP_CMD:
339 msg.obj = args.getParcelable(CMD_MSG);
340 break;
341 case OP_RESPONSE:
Wink Saville94e982b2014-07-11 07:38:14 -0700342 case OP_CARD_STATUS_CHANGED:
Preeti Ahuja95919342013-10-01 18:18:55 -0700343 case OP_LOCALE_CHANGED:
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +0530344 case OP_ALPHA_NOTIFY:
Preeti Ahuja560be362014-11-25 19:38:24 -0800345 case OP_IDLE_SCREEN:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800346 msg.obj = args;
347 /* falls through */
348 case OP_LAUNCH_APP:
349 case OP_END_SESSION:
350 case OP_BOOT_COMPLETED:
351 break;
352 default:
353 return;
354 }
355 mServiceHandler.sendMessage(msg);
356 }
357
358 @Override
359 public void onDestroy() {
Wink Savillee68857d2014-10-17 15:23:05 -0700360 CatLog.d(LOG_TAG, "onDestroy()");
Preeti Ahuja560be362014-11-25 19:38:24 -0800361 if (mStkCmdReceiver != null) {
362 unregisterReceiver(mStkCmdReceiver);
363 mStkCmdReceiver = null;
364 }
365 mPowerManager = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800366 waitForLooper();
367 mServiceLooper.quit();
368 }
369
370 @Override
371 public IBinder onBind(Intent intent) {
372 return null;
373 }
374
375 public void run() {
376 Looper.prepare();
377
378 mServiceLooper = Looper.myLooper();
379 mServiceHandler = new ServiceHandler();
380
381 Looper.loop();
382 }
383
384 /*
385 * Package api used by StkMenuActivity to indicate if its on the foreground.
386 */
Wink Savillee68857d2014-10-17 15:23:05 -0700387 void indicateMenuVisibility(boolean visibility, int slotId) {
388 if (slotId >= 0 && slotId < mSimCount) {
389 mStkContext[slotId].mMenuIsVisible = visibility;
390 }
391 }
392
Preeti Ahuja95919342013-10-01 18:18:55 -0700393 /*
394 * Package api used by StkDialogActivity to indicate if its on the foreground.
395 */
396 void setDisplayTextDlgVisibility(boolean visibility, int slotId) {
397 if (slotId >= 0 && slotId < mSimCount) {
398 mStkContext[slotId].mDisplayTextDlgIsVisibile = visibility;
399 }
400 }
401
Wink Savillee68857d2014-10-17 15:23:05 -0700402 boolean isInputPending(int slotId) {
403 if (slotId >= 0 && slotId < mSimCount) {
404 CatLog.d(LOG_TAG, "isInputFinishBySrv: " + mStkContext[slotId].mIsInputPending);
405 return mStkContext[slotId].mIsInputPending;
406 }
407 return false;
408 }
409
410 boolean isMenuPending(int slotId) {
411 if (slotId >= 0 && slotId < mSimCount) {
412 CatLog.d(LOG_TAG, "isMenuPending: " + mStkContext[slotId].mIsMenuPending);
413 return mStkContext[slotId].mIsMenuPending;
414 }
415 return false;
416 }
417
418 boolean isDialogPending(int slotId) {
419 if (slotId >= 0 && slotId < mSimCount) {
420 CatLog.d(LOG_TAG, "isDialogPending: " + mStkContext[slotId].mIsDialogPending);
421 return mStkContext[slotId].mIsDialogPending;
422 }
423 return false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800424 }
425
426 /*
427 * Package api used by StkMenuActivity to get its Menu parameter.
428 */
Wink Savillee68857d2014-10-17 15:23:05 -0700429 Menu getMenu(int slotId) {
430 CatLog.d(LOG_TAG, "StkAppService, getMenu, sim id: " + slotId);
431 if (slotId >=0 && slotId < mSimCount) {
432 return mStkContext[slotId].mCurrentMenu;
433 } else {
434 return null;
435 }
436 }
437
438 /*
439 * Package api used by StkMenuActivity to get its Main Menu parameter.
440 */
441 Menu getMainMenu(int slotId) {
442 CatLog.d(LOG_TAG, "StkAppService, getMainMenu, sim id: " + slotId);
w30234a08cffe2015-02-04 15:13:25 -0800443 if (slotId >=0 && slotId < mSimCount && (mStkContext[slotId].mMainCmd != null)) {
Wink Savillee68857d2014-10-17 15:23:05 -0700444 return mStkContext[slotId].mMainCmd.getMenu();
445 } else {
446 return null;
447 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800448 }
449
450 /*
451 * Package api used by UI Activities and Dialogs to communicate directly
452 * with the service to deliver state information and parameters.
453 */
454 static StkAppService getInstance() {
455 return sInstance;
456 }
457
458 private void waitForLooper() {
459 while (mServiceHandler == null) {
460 synchronized (this) {
461 try {
462 wait(100);
463 } catch (InterruptedException e) {
464 }
465 }
466 }
467 }
468
469 private final class ServiceHandler extends Handler {
470 @Override
471 public void handleMessage(Message msg) {
Wink Savillee68857d2014-10-17 15:23:05 -0700472 if(null == msg) {
473 CatLog.d(LOG_TAG, "ServiceHandler handleMessage msg is null");
474 return;
475 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800476 int opcode = msg.arg1;
Wink Savillee68857d2014-10-17 15:23:05 -0700477 int slotId = msg.arg2;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800478
Wink Savillee68857d2014-10-17 15:23:05 -0700479 CatLog.d(LOG_TAG, "handleMessage opcode[" + opcode + "], sim id[" + slotId + "]");
480 if (opcode == OP_CMD && msg.obj != null &&
481 ((CatCmdMessage)msg.obj).getCmdType()!= null) {
482 CatLog.d(LOG_TAG, "cmdName[" + ((CatCmdMessage)msg.obj).getCmdType().name() + "]");
483 }
484 mStkContext[slotId].mOpCode = opcode;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800485 switch (opcode) {
486 case OP_LAUNCH_APP:
Wink Savillee68857d2014-10-17 15:23:05 -0700487 if (mStkContext[slotId].mMainCmd == null) {
488 CatLog.d(LOG_TAG, "mMainCmd is null");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800489 // nothing todo when no SET UP MENU command didn't arrive.
490 return;
491 }
Wink Savillee68857d2014-10-17 15:23:05 -0700492 CatLog.d(LOG_TAG, "handleMessage OP_LAUNCH_APP - mCmdInProgress[" +
493 mStkContext[slotId].mCmdInProgress + "]");
494
495 //If there is a pending activity for the slot id,
496 //just finish it and create a new one to handle the pending command.
497 cleanUpInstanceStackBySlot(slotId);
498
Wink Savillee68857d2014-10-17 15:23:05 -0700499 CatLog.d(LOG_TAG, "Current cmd type: " +
500 mStkContext[slotId].mCurrentCmd.getCmdType());
501 //Restore the last command from stack by slot id.
502 restoreInstanceFromStackBySlot(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800503 break;
504 case OP_CMD:
Wink Savillee68857d2014-10-17 15:23:05 -0700505 CatLog.d(LOG_TAG, "[OP_CMD]");
Alex Yakavenkad41f1d92010-07-12 14:13:13 -0700506 CatCmdMessage cmdMsg = (CatCmdMessage) msg.obj;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800507 // There are two types of commands:
508 // 1. Interactive - user's response is required.
509 // 2. Informative - display a message, no interaction with the user.
510 //
Wink Saville79085fc2009-06-09 10:27:23 -0700511 // Informative commands can be handled immediately without any delay.
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800512 // Interactive commands can't override each other. So if a command
513 // is already in progress, we need to queue the next command until
514 // the user has responded or a timeout expired.
515 if (!isCmdInteractive(cmdMsg)) {
Wink Savillee68857d2014-10-17 15:23:05 -0700516 handleCmd(cmdMsg, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800517 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700518 if (!mStkContext[slotId].mCmdInProgress) {
519 mStkContext[slotId].mCmdInProgress = true;
520 handleCmd((CatCmdMessage) msg.obj, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800521 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700522 CatLog.d(LOG_TAG, "[Interactive][in progress]");
523 mStkContext[slotId].mCmdsQ.addLast(new DelayedCmd(OP_CMD,
524 (CatCmdMessage) msg.obj, slotId));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800525 }
526 }
527 break;
528 case OP_RESPONSE:
Preeti Ahuja414bc412013-06-25 19:31:49 -0700529 handleCmdResponse((Bundle) msg.obj, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800530 // call delayed commands if needed.
Wink Savillee68857d2014-10-17 15:23:05 -0700531 if (mStkContext[slotId].mCmdsQ.size() != 0) {
532 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800533 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700534 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800535 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800536 break;
537 case OP_END_SESSION:
Wink Savillee68857d2014-10-17 15:23:05 -0700538 if (!mStkContext[slotId].mCmdInProgress) {
539 mStkContext[slotId].mCmdInProgress = true;
540 handleSessionEnd(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800541 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700542 mStkContext[slotId].mCmdsQ.addLast(
543 new DelayedCmd(OP_END_SESSION, null, slotId));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800544 }
545 break;
546 case OP_BOOT_COMPLETED:
Wink Savillee68857d2014-10-17 15:23:05 -0700547 CatLog.d(LOG_TAG, " OP_BOOT_COMPLETED");
548 int i = 0;
549 for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) {
550 if (mStkContext[i].mMainCmd != null) {
551 break;
552 }
553 }
554 if (i == mSimCount) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800555 StkAppInstaller.unInstall(mContext);
556 }
557 break;
558 case OP_DELAYED_MSG:
Wink Savillee68857d2014-10-17 15:23:05 -0700559 handleDelayedCmd(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800560 break;
Wink Saville94e982b2014-07-11 07:38:14 -0700561 case OP_CARD_STATUS_CHANGED:
Wink Savillee68857d2014-10-17 15:23:05 -0700562 CatLog.d(LOG_TAG, "Card/Icc Status change received");
563 handleCardStatusChangeAndIccRefresh((Bundle) msg.obj, slotId);
564 break;
565 case OP_SET_ACT_INST:
566 Activity act = new Activity();
567 act = (Activity) msg.obj;
568 CatLog.d(LOG_TAG, "Set activity instance. " + act);
569 mStkContext[slotId].mActivityInstance = act;
570 break;
571 case OP_SET_DAL_INST:
572 Activity dal = new Activity();
573 CatLog.d(LOG_TAG, "Set dialog instance. " + dal);
574 dal = (Activity) msg.obj;
575 mStkContext[slotId].mDialogInstance = dal;
576 break;
577 case OP_SET_MAINACT_INST:
578 Activity mainAct = new Activity();
579 mainAct = (Activity) msg.obj;
580 CatLog.d(LOG_TAG, "Set activity instance. " + mainAct);
581 mStkContext[slotId].mMainActivityInstance = mainAct;
Wink Saville94e982b2014-07-11 07:38:14 -0700582 break;
Preeti Ahuja95919342013-10-01 18:18:55 -0700583 case OP_LOCALE_CHANGED:
584 CatLog.d(this, "Locale Changed");
Yuta Ui1481b172016-02-03 15:34:31 +0900585 for (int slot = PhoneConstants.SIM_ID_1; slot < mSimCount; slot++) {
586 checkForSetupEvent(LANGUAGE_SELECTION_EVENT, (Bundle) msg.obj, slot);
587 }
Preeti Ahuja95919342013-10-01 18:18:55 -0700588 break;
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +0530589 case OP_ALPHA_NOTIFY:
590 handleAlphaNotify((Bundle) msg.obj);
591 break;
Preeti Ahuja560be362014-11-25 19:38:24 -0800592 case OP_IDLE_SCREEN:
593 for (int slot = 0; slot < mSimCount; slot++) {
594 if (mStkContext[slot] != null) {
595 handleIdleScreen(slot);
596 }
597 }
598 break;
Wink Saville94e982b2014-07-11 07:38:14 -0700599 }
600 }
601
Wink Savillee68857d2014-10-17 15:23:05 -0700602 private void handleCardStatusChangeAndIccRefresh(Bundle args, int slotId) {
Wink Saville94e982b2014-07-11 07:38:14 -0700603 boolean cardStatus = args.getBoolean(AppInterface.CARD_STATUS);
604
Wink Savillee68857d2014-10-17 15:23:05 -0700605 CatLog.d(LOG_TAG, "CardStatus: " + cardStatus);
Wink Saville94e982b2014-07-11 07:38:14 -0700606 if (cardStatus == false) {
Wink Savillee68857d2014-10-17 15:23:05 -0700607 CatLog.d(LOG_TAG, "CARD is ABSENT");
Wink Saville94e982b2014-07-11 07:38:14 -0700608 // Uninstall STKAPP, Clear Idle text, Stop StkAppService
Wink Savillee68857d2014-10-17 15:23:05 -0700609 mNotificationManager.cancel(getNotificationId(slotId));
610 if (isAllOtherCardsAbsent(slotId)) {
611 CatLog.d(LOG_TAG, "All CARDs are ABSENT");
612 StkAppInstaller.unInstall(mContext);
613 stopSelf();
614 }
Wink Saville94e982b2014-07-11 07:38:14 -0700615 } else {
616 IccRefreshResponse state = new IccRefreshResponse();
617 state.refreshResult = args.getInt(AppInterface.REFRESH_RESULT);
618
Wink Savillee68857d2014-10-17 15:23:05 -0700619 CatLog.d(LOG_TAG, "Icc Refresh Result: "+ state.refreshResult);
Wink Saville94e982b2014-07-11 07:38:14 -0700620 if ((state.refreshResult == IccRefreshResponse.REFRESH_RESULT_INIT) ||
621 (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET)) {
622 // Clear Idle Text
Wink Savillee68857d2014-10-17 15:23:05 -0700623 mNotificationManager.cancel(getNotificationId(slotId));
Wink Saville94e982b2014-07-11 07:38:14 -0700624 }
625
626 if (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET) {
627 // Uninstall STkmenu
Wink Savillee68857d2014-10-17 15:23:05 -0700628 if (isAllOtherCardsAbsent(slotId)) {
629 StkAppInstaller.unInstall(mContext);
630 }
631 mStkContext[slotId].mCurrentMenu = null;
632 mStkContext[slotId].mMainCmd = null;
Wink Saville94e982b2014-07-11 07:38:14 -0700633 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800634 }
635 }
636 }
Wink Savillee68857d2014-10-17 15:23:05 -0700637 /*
638 * Check if all SIMs are absent except the id of slot equals "slotId".
639 */
640 private boolean isAllOtherCardsAbsent(int slotId) {
641 TelephonyManager mTm = (TelephonyManager) mContext.getSystemService(
642 Context.TELEPHONY_SERVICE);
643 int i = 0;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800644
Wink Savillee68857d2014-10-17 15:23:05 -0700645 for (i = 0; i < mSimCount; i++) {
646 if (i != slotId && mTm.hasIccCard(i)) {
647 break;
648 }
649 }
650 if (i == mSimCount) {
651 return true;
652 } else {
653 return false;
654 }
655 }
Preeti Ahuja95919342013-10-01 18:18:55 -0700656
Preeti Ahuja560be362014-11-25 19:38:24 -0800657 /*
658 * If the device is not in an interactive state, we can assume
659 * that the screen is idle.
660 */
661 private boolean isScreenIdle() {
662 return (!mPowerManager.isInteractive());
663 }
664
665 private void handleIdleScreen(int slotId) {
666
667 // If the idle screen event is present in the list need to send the
668 // response to SIM.
669 CatLog.d(this, "Need to send IDLE SCREEN Available event to SIM");
670 checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId);
671
672 if (mStkContext[slotId].mIdleModeTextCmd != null) {
673 launchIdleText(slotId);
674 }
675 }
676
677 private void sendScreenBusyResponse(int slotId) {
678 if (mStkContext[slotId].mCurrentCmd == null) {
679 return;
680 }
681 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd);
682 CatLog.d(this, "SCREEN_BUSY");
683 resMsg.setResultCode(ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS);
684 mStkService[slotId].onCmdResponse(resMsg);
685 if (mStkContext[slotId].mCmdsQ.size() != 0) {
686 callDelayedMsg(slotId);
687 } else {
688 mStkContext[slotId].mCmdInProgress = false;
689 }
690 }
691
Preeti Ahuja95919342013-10-01 18:18:55 -0700692 private void sendResponse(int resId, int slotId, boolean confirm) {
693 Message msg = mServiceHandler.obtainMessage();
694 msg.arg1 = OP_RESPONSE;
Takanori Nakano49b12722016-02-16 14:34:14 +0900695 msg.arg2 = slotId;
Preeti Ahuja95919342013-10-01 18:18:55 -0700696 Bundle args = new Bundle();
697 args.putInt(StkAppService.RES_ID, resId);
Preeti Ahuja95919342013-10-01 18:18:55 -0700698 args.putBoolean(StkAppService.CONFIRMATION, confirm);
699 msg.obj = args;
700 mServiceHandler.sendMessage(msg);
701 }
702
Alex Yakavenkad41f1d92010-07-12 14:13:13 -0700703 private boolean isCmdInteractive(CatCmdMessage cmd) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800704 switch (cmd.getCmdType()) {
705 case SEND_DTMF:
706 case SEND_SMS:
707 case SEND_SS:
708 case SEND_USSD:
709 case SET_UP_IDLE_MODE_TEXT:
710 case SET_UP_MENU:
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500711 case CLOSE_CHANNEL:
712 case RECEIVE_DATA:
713 case SEND_DATA:
Preeti Ahuja95919342013-10-01 18:18:55 -0700714 case SET_UP_EVENT_LIST:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800715 return false;
716 }
717
718 return true;
719 }
720
Wink Savillee68857d2014-10-17 15:23:05 -0700721 private void handleDelayedCmd(int slotId) {
722 CatLog.d(LOG_TAG, "handleDelayedCmd, slotId: " + slotId);
723 if (mStkContext[slotId].mCmdsQ.size() != 0) {
724 DelayedCmd cmd = mStkContext[slotId].mCmdsQ.poll();
725 if (cmd != null) {
726 CatLog.d(LOG_TAG, "handleDelayedCmd - queue size: " +
727 mStkContext[slotId].mCmdsQ.size() +
728 " id: " + cmd.id + "sim id: " + cmd.slotId);
729 switch (cmd.id) {
730 case OP_CMD:
731 handleCmd(cmd.msg, cmd.slotId);
732 break;
733 case OP_END_SESSION:
734 handleSessionEnd(cmd.slotId);
735 break;
736 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800737 }
738 }
739 }
740
Wink Savillee68857d2014-10-17 15:23:05 -0700741 private void callDelayedMsg(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800742 Message msg = mServiceHandler.obtainMessage();
743 msg.arg1 = OP_DELAYED_MSG;
Wink Savillee68857d2014-10-17 15:23:05 -0700744 msg.arg2 = slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800745 mServiceHandler.sendMessage(msg);
746 }
747
Wink Savillee68857d2014-10-17 15:23:05 -0700748 private void callSetActivityInstMsg(int inst_type, int slotId, Object obj) {
749 Message msg = mServiceHandler.obtainMessage();
750 msg.obj = obj;
751 msg.arg1 = inst_type;
752 msg.arg2 = slotId;
753 mServiceHandler.sendMessage(msg);
754 }
755
756 private void handleSessionEnd(int slotId) {
Legler Wuaeefef52014-10-27 00:57:18 +0800757 // We should finish all pending activity if receiving END SESSION command.
758 cleanUpInstanceStackBySlot(slotId);
759
Wink Savillee68857d2014-10-17 15:23:05 -0700760 mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
761 CatLog.d(LOG_TAG, "[handleSessionEnd] - mCurrentCmd changed to mMainCmd!.");
762 mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mMainCmd;
763 CatLog.d(LOG_TAG, "slotId: " + slotId + ", mMenuState: " +
764 mStkContext[slotId].mMenuState);
765
766 mStkContext[slotId].mIsInputPending = false;
767 mStkContext[slotId].mIsMenuPending = false;
768 mStkContext[slotId].mIsDialogPending = false;
769
Wink Savillee68857d2014-10-17 15:23:05 -0700770 if (mStkContext[slotId].mMainCmd == null) {
771 CatLog.d(LOG_TAG, "[handleSessionEnd][mMainCmd is null!]");
772 }
773 mStkContext[slotId].lastSelectedItem = null;
Wink Saville79085fc2009-06-09 10:27:23 -0700774 // In case of SET UP MENU command which removed the app, don't
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800775 // update the current menu member.
Wink Savillee68857d2014-10-17 15:23:05 -0700776 if (mStkContext[slotId].mCurrentMenu != null && mStkContext[slotId].mMainCmd != null) {
777 mStkContext[slotId].mCurrentMenu = mStkContext[slotId].mMainCmd.getMenu();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800778 }
Wink Savillee68857d2014-10-17 15:23:05 -0700779 CatLog.d(LOG_TAG, "[handleSessionEnd][mMenuState]" + mStkContext[slotId].mMenuIsVisible);
780 // In mutiple instance architecture, the main menu for slotId will be finished when user
781 // goes to the Stk menu of the other SIM. So, we should launch a new instance for the
782 // main menu if the main menu instance has been finished.
783 // If the current menu is secondary menu, we should launch main menu.
784 if (StkMenuActivity.STATE_SECONDARY == mStkContext[slotId].mMenuState) {
785 launchMenuActivity(null, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800786 }
Wink Savillee68857d2014-10-17 15:23:05 -0700787 if (mStkContext[slotId].mCmdsQ.size() != 0) {
788 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800789 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700790 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800791 }
792 // In case a launch browser command was just confirmed, launch that url.
Wink Savillee68857d2014-10-17 15:23:05 -0700793 if (mStkContext[slotId].launchBrowser) {
794 mStkContext[slotId].launchBrowser = false;
795 launchBrowser(mStkContext[slotId].mBrowserSettings);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800796 }
797 }
798
Preeti Ahuja560be362014-11-25 19:38:24 -0800799 // returns true if any Stk related activity already has focus on the screen
800 private boolean isTopOfStack() {
801 ActivityManager mAcivityManager = (ActivityManager) mContext
802 .getSystemService(ACTIVITY_SERVICE);
803 String currentPackageName = mAcivityManager.getRunningTasks(1).get(0).topActivity
804 .getPackageName();
805 if (null != currentPackageName) {
806 return currentPackageName.equals(PACKAGE_NAME);
807 }
808
809 return false;
810 }
811
Wink Savillee68857d2014-10-17 15:23:05 -0700812 private void handleCmd(CatCmdMessage cmdMsg, int slotId) {
Preeti Ahuja95919342013-10-01 18:18:55 -0700813
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800814 if (cmdMsg == null) {
815 return;
816 }
817 // save local reference for state tracking.
Wink Savillee68857d2014-10-17 15:23:05 -0700818 mStkContext[slotId].mCurrentCmd = cmdMsg;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800819 boolean waitForUsersResponse = true;
820
Wink Savillee68857d2014-10-17 15:23:05 -0700821 mStkContext[slotId].mIsInputPending = false;
822 mStkContext[slotId].mIsMenuPending = false;
823 mStkContext[slotId].mIsDialogPending = false;
824
825 CatLog.d(LOG_TAG,"[handleCmd]" + cmdMsg.getCmdType().name());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800826 switch (cmdMsg.getCmdType()) {
827 case DISPLAY_TEXT:
828 TextMessage msg = cmdMsg.geTextMessage();
Jeevaka Badrappan854a25c2012-12-01 16:32:03 +0200829 waitForUsersResponse = msg.responseNeeded;
Wink Savillee68857d2014-10-17 15:23:05 -0700830 if (mStkContext[slotId].lastSelectedItem != null) {
831 msg.title = mStkContext[slotId].lastSelectedItem;
832 } else if (mStkContext[slotId].mMainCmd != null){
833 msg.title = mStkContext[slotId].mMainCmd.getMenu().title;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800834 } else {
835 // TODO: get the carrier name from the SIM
836 msg.title = "";
837 }
Preeti Ahuja560be362014-11-25 19:38:24 -0800838 //If we receive a low priority Display Text and the device is
839 // not displaying any STK related activity and the screen is not idle
840 // ( that is, device is in an interactive state), then send a screen busy
841 // terminal response. Otherwise display the message. The existing
842 // displayed message shall be updated with the new display text
843 // proactive command (Refer to ETSI TS 102 384 section 27.22.4.1.4.4.2).
844 if (!(msg.isHighPriority || mStkContext[slotId].mMenuIsVisible
845 || mStkContext[slotId].mDisplayTextDlgIsVisibile || isTopOfStack())) {
846 if(!isScreenIdle()) {
847 CatLog.d(LOG_TAG, "Screen is not idle");
848 sendScreenBusyResponse(slotId);
849 } else {
850 launchTextDialog(slotId);
851 }
852 } else {
853 launchTextDialog(slotId);
854 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800855 break;
856 case SELECT_ITEM:
Wink Savillee68857d2014-10-17 15:23:05 -0700857 CatLog.d(LOG_TAG, "SELECT_ITEM +");
858 mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd;
859 mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu();
860 launchMenuActivity(cmdMsg.getMenu(), slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800861 break;
862 case SET_UP_MENU:
Wink Savillee68857d2014-10-17 15:23:05 -0700863 mStkContext[slotId].mCmdInProgress = false;
864 mStkContext[slotId].mMainCmd = mStkContext[slotId].mCurrentCmd;
865 mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd;
866 mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu();
867 CatLog.d(LOG_TAG, "SET_UP_MENU [" + removeMenu(slotId) + "]");
868
869 if (removeMenu(slotId)) {
870 int i = 0;
871 CatLog.d(LOG_TAG, "removeMenu() - Uninstall App");
872 mStkContext[slotId].mCurrentMenu = null;
Preeti Ahuja95919342013-10-01 18:18:55 -0700873 mStkContext[slotId].mMainCmd = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700874 //Check other setup menu state. If all setup menu are removed, uninstall apk.
875 for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) {
876 if (i != slotId
877 && (mStkContext[slotId].mSetupMenuState == STATE_UNKNOWN
878 || mStkContext[slotId].mSetupMenuState == STATE_EXIST)) {
879 CatLog.d(LOG_TAG, "Not Uninstall App:" + i + ","
880 + mStkContext[slotId].mSetupMenuState);
881 break;
882 }
883 }
884 if (i == mSimCount) {
885 StkAppInstaller.unInstall(mContext);
886 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800887 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700888 CatLog.d(LOG_TAG, "install App");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800889 StkAppInstaller.install(mContext);
890 }
Wink Savillee68857d2014-10-17 15:23:05 -0700891 if (mStkContext[slotId].mMenuIsVisible) {
892 launchMenuActivity(null, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800893 }
894 break;
895 case GET_INPUT:
896 case GET_INKEY:
Wink Savillee68857d2014-10-17 15:23:05 -0700897 launchInputActivity(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800898 break;
899 case SET_UP_IDLE_MODE_TEXT:
900 waitForUsersResponse = false;
Preeti Ahuja560be362014-11-25 19:38:24 -0800901 mStkContext[slotId].mIdleModeTextCmd = mStkContext[slotId].mCurrentCmd;
902 TextMessage idleModeText = mStkContext[slotId].mCurrentCmd.geTextMessage();
903 if (idleModeText == null) {
904 launchIdleText(slotId);
905 mStkContext[slotId].mIdleModeTextCmd = null;
906 }
907 mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
908 if ((mStkContext[slotId].mIdleModeTextCmd != null) && isScreenIdle()) {
909 CatLog.d(this, "set up idle mode");
910 launchIdleText(slotId);
911 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800912 break;
913 case SEND_DTMF:
914 case SEND_SMS:
915 case SEND_SS:
916 case SEND_USSD:
Preeti Ahuja95919342013-10-01 18:18:55 -0700917 case GET_CHANNEL_STATUS:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800918 waitForUsersResponse = false;
Wink Savillee68857d2014-10-17 15:23:05 -0700919 launchEventMessage(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800920 break;
921 case LAUNCH_BROWSER:
Ryuto Sawada0bdc7192016-04-18 12:10:56 +0900922 // The device setup process should not be interrupted by launching browser.
923 if (Settings.Global.getInt(mContext.getContentResolver(),
924 Settings.Global.DEVICE_PROVISIONED, 0) == 0) {
925 CatLog.d(this, "The command is not performed if the setup has not been completed.");
926 sendScreenBusyResponse(slotId);
927 break;
928 }
Preeti Ahujaa7cdca22013-10-01 18:20:56 -0700929 TextMessage alphaId = mStkContext[slotId].mCurrentCmd.geTextMessage();
930 if ((mStkContext[slotId].mCurrentCmd.getBrowserSettings().mode
931 == LaunchBrowserMode.LAUNCH_IF_NOT_ALREADY_LAUNCHED) &&
932 ((alphaId == null) || TextUtils.isEmpty(alphaId.text))) {
933 // don't need user confirmation in this case
934 // just launch the browser or spawn a new tab
935 CatLog.d(this, "Browser mode is: launch if not already launched " +
936 "and user confirmation is not currently needed.\n" +
937 "supressing confirmation dialogue and confirming silently...");
938 mStkContext[slotId].launchBrowser = true;
939 mStkContext[slotId].mBrowserSettings =
940 mStkContext[slotId].mCurrentCmd.getBrowserSettings();
941 sendResponse(RES_ID_CONFIRM, slotId, true);
942 } else {
943 launchConfirmationDialog(alphaId, slotId);
944 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800945 break;
946 case SET_UP_CALL:
Preeti Ahujadd240102013-08-30 17:25:06 -0700947 TextMessage mesg = mStkContext[slotId].mCurrentCmd.getCallSettings().confirmMsg;
948 if((mesg != null) && (mesg.text == null || mesg.text.length() == 0)) {
949 mesg.text = getResources().getString(R.string.default_setup_call_msg);
950 }
951 CatLog.d(this, "SET_UP_CALL mesg.text " + mesg.text);
952 launchConfirmationDialog(mesg, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800953 break;
954 case PLAY_TONE:
Wink Savillee68857d2014-10-17 15:23:05 -0700955 launchToneDialog(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800956 break;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500957 case OPEN_CHANNEL:
Wink Savillee68857d2014-10-17 15:23:05 -0700958 launchOpenChannelDialog(slotId);
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500959 break;
960 case CLOSE_CHANNEL:
961 case RECEIVE_DATA:
962 case SEND_DATA:
Wink Savillee68857d2014-10-17 15:23:05 -0700963 TextMessage m = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500964
965 if ((m != null) && (m.text == null)) {
966 switch(cmdMsg.getCmdType()) {
967 case CLOSE_CHANNEL:
968 m.text = getResources().getString(R.string.default_close_channel_msg);
969 break;
970 case RECEIVE_DATA:
971 m.text = getResources().getString(R.string.default_receive_data_msg);
972 break;
973 case SEND_DATA:
974 m.text = getResources().getString(R.string.default_send_data_msg);
975 break;
976 }
977 }
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -0700978 /*
979 * Display indication in the form of a toast to the user if required.
980 */
Wink Savillee68857d2014-10-17 15:23:05 -0700981 launchEventMessage(slotId);
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500982 break;
Preeti Ahuja95919342013-10-01 18:18:55 -0700983 case SET_UP_EVENT_LIST:
984 mStkContext[slotId].mSetupEventListSettings =
985 mStkContext[slotId].mCurrentCmd.getSetEventList();
986 mStkContext[slotId].mCurrentSetupEventCmd = mStkContext[slotId].mCurrentCmd;
987 mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
Preeti Ahuja560be362014-11-25 19:38:24 -0800988 if (isScreenIdle()) {
989 CatLog.d(this," Check if IDLE_SCREEN_AVAILABLE_EVENT is present in List");
990 checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId);
991 }
Preeti Ahuja95919342013-10-01 18:18:55 -0700992 break;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800993 }
994
995 if (!waitForUsersResponse) {
Wink Savillee68857d2014-10-17 15:23:05 -0700996 if (mStkContext[slotId].mCmdsQ.size() != 0) {
997 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800998 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700999 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001000 }
1001 }
1002 }
1003
Wink Savillee68857d2014-10-17 15:23:05 -07001004 private void handleCmdResponse(Bundle args, int slotId) {
1005 CatLog.d(LOG_TAG, "handleCmdResponse, sim id: " + slotId);
1006 if (mStkContext[slotId].mCurrentCmd == null) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001007 return;
1008 }
Wink Savillee68857d2014-10-17 15:23:05 -07001009
1010 if (mStkService[slotId] == null) {
Legler Wuaeefef52014-10-27 00:57:18 +08001011 mStkService[slotId] = CatService.getInstance(slotId);
Wink Savillee68857d2014-10-17 15:23:05 -07001012 if (mStkService[slotId] == null) {
Alex Yakavenkad8e2ecd2012-04-20 17:10:15 -07001013 // This should never happen (we should be responding only to a message
1014 // that arrived from StkService). It has to exist by this time
Wink Savillee68857d2014-10-17 15:23:05 -07001015 CatLog.d(LOG_TAG, "Exception! mStkService is null when we need to send response.");
Alex Yakavenkad8e2ecd2012-04-20 17:10:15 -07001016 throw new RuntimeException("mStkService is null when we need to send response");
1017 }
1018 }
1019
Wink Savillee68857d2014-10-17 15:23:05 -07001020 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001021
1022 // set result code
1023 boolean helpRequired = args.getBoolean(HELP, false);
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001024 boolean confirmed = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001025
1026 switch(args.getInt(RES_ID)) {
1027 case RES_ID_MENU_SELECTION:
Wink Savillee68857d2014-10-17 15:23:05 -07001028 CatLog.d(LOG_TAG, "MENU_SELECTION=" + mStkContext[slotId].
1029 mCurrentMenuCmd.getCmdType());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001030 int menuSelection = args.getInt(MENU_SELECTION);
Wink Savillee68857d2014-10-17 15:23:05 -07001031 switch(mStkContext[slotId].mCurrentMenuCmd.getCmdType()) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001032 case SET_UP_MENU:
1033 case SELECT_ITEM:
Wink Savillee68857d2014-10-17 15:23:05 -07001034 mStkContext[slotId].lastSelectedItem = getItemName(menuSelection, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001035 if (helpRequired) {
1036 resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED);
1037 } else {
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301038 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1039 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001040 }
1041 resMsg.setMenuSelection(menuSelection);
1042 break;
1043 }
1044 break;
1045 case RES_ID_INPUT:
Wink Savillee68857d2014-10-17 15:23:05 -07001046 CatLog.d(LOG_TAG, "RES_ID_INPUT");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001047 String input = args.getString(INPUT);
Wink Savillee68857d2014-10-17 15:23:05 -07001048 if (input != null && (null != mStkContext[slotId].mCurrentCmd.geInput()) &&
1049 (mStkContext[slotId].mCurrentCmd.geInput().yesNo)) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001050 boolean yesNoSelection = input
1051 .equals(StkInputActivity.YES_STR_RESPONSE);
1052 resMsg.setYesNo(yesNoSelection);
1053 } else {
1054 if (helpRequired) {
1055 resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED);
1056 } else {
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301057 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1058 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001059 resMsg.setInput(input);
1060 }
1061 }
1062 break;
1063 case RES_ID_CONFIRM:
Alex Yakavenkad41f1d92010-07-12 14:13:13 -07001064 CatLog.d(this, "RES_ID_CONFIRM");
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001065 confirmed = args.getBoolean(CONFIRMATION);
Wink Savillee68857d2014-10-17 15:23:05 -07001066 switch (mStkContext[slotId].mCurrentCmd.getCmdType()) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001067 case DISPLAY_TEXT:
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301068 if (confirmed) {
1069 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1070 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
1071 } else {
1072 resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER);
1073 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001074 break;
1075 case LAUNCH_BROWSER:
1076 resMsg.setResultCode(confirmed ? ResultCode.OK
1077 : ResultCode.UICC_SESSION_TERM_BY_USER);
1078 if (confirmed) {
Wink Savillee68857d2014-10-17 15:23:05 -07001079 mStkContext[slotId].launchBrowser = true;
1080 mStkContext[slotId].mBrowserSettings =
1081 mStkContext[slotId].mCurrentCmd.getBrowserSettings();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001082 }
1083 break;
1084 case SET_UP_CALL:
1085 resMsg.setResultCode(ResultCode.OK);
1086 resMsg.setConfirmation(confirmed);
1087 if (confirmed) {
Wink Savillee68857d2014-10-17 15:23:05 -07001088 launchEventMessage(slotId,
1089 mStkContext[slotId].mCurrentCmd.getCallSettings().callMsg);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001090 }
1091 break;
1092 }
1093 break;
1094 case RES_ID_DONE:
1095 resMsg.setResultCode(ResultCode.OK);
1096 break;
1097 case RES_ID_BACKWARD:
Wink Savillee68857d2014-10-17 15:23:05 -07001098 CatLog.d(LOG_TAG, "RES_ID_BACKWARD");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001099 resMsg.setResultCode(ResultCode.BACKWARD_MOVE_BY_USER);
1100 break;
1101 case RES_ID_END_SESSION:
Wink Savillee68857d2014-10-17 15:23:05 -07001102 CatLog.d(LOG_TAG, "RES_ID_END_SESSION");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001103 resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER);
1104 break;
1105 case RES_ID_TIMEOUT:
Wink Savillee68857d2014-10-17 15:23:05 -07001106 CatLog.d(LOG_TAG, "RES_ID_TIMEOUT");
Naveen Kallad5176892009-11-30 12:45:29 -08001107 // GCF test-case 27.22.4.1.1 Expected Sequence 1.5 (DISPLAY TEXT,
1108 // Clear message after delay, successful) expects result code OK.
1109 // If the command qualifier specifies no user response is required
1110 // then send OK instead of NO_RESPONSE_FROM_USER
Wink Savillee68857d2014-10-17 15:23:05 -07001111 if ((mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1112 AppInterface.CommandType.DISPLAY_TEXT.value())
1113 && (mStkContext[slotId].mCurrentCmd.geTextMessage().userClear == false)) {
Naveen Kallad5176892009-11-30 12:45:29 -08001114 resMsg.setResultCode(ResultCode.OK);
1115 } else {
1116 resMsg.setResultCode(ResultCode.NO_RESPONSE_FROM_USER);
1117 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001118 break;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001119 case RES_ID_CHOICE:
1120 int choice = args.getInt(CHOICE);
1121 CatLog.d(this, "User Choice=" + choice);
1122 switch (choice) {
1123 case YES:
1124 resMsg.setResultCode(ResultCode.OK);
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001125 confirmed = true;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001126 break;
1127 case NO:
1128 resMsg.setResultCode(ResultCode.USER_NOT_ACCEPT);
1129 break;
1130 }
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001131
Wink Savillee68857d2014-10-17 15:23:05 -07001132 if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1133 AppInterface.CommandType.OPEN_CHANNEL.value()) {
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001134 resMsg.setConfirmation(confirmed);
1135 }
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001136 break;
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001137
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001138 default:
Wink Savillee68857d2014-10-17 15:23:05 -07001139 CatLog.d(LOG_TAG, "Unknown result id");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001140 return;
1141 }
Wink Savillee68857d2014-10-17 15:23:05 -07001142
1143 if (null != mStkContext[slotId].mCurrentCmd &&
1144 null != mStkContext[slotId].mCurrentCmd.getCmdType()) {
1145 CatLog.d(LOG_TAG, "handleCmdResponse- cmdName[" +
1146 mStkContext[slotId].mCurrentCmd.getCmdType().name() + "]");
1147 }
1148 mStkService[slotId].onCmdResponse(resMsg);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001149 }
1150
1151 /**
1152 * Returns 0 or FLAG_ACTIVITY_NO_USER_ACTION, 0 means the user initiated the action.
1153 *
1154 * @param userAction If the userAction is yes then we always return 0 otherwise
1155 * mMenuIsVisible is used to determine what to return. If mMenuIsVisible is true
1156 * then we are the foreground app and we'll return 0 as from our perspective a
1157 * user action did cause. If it's false than we aren't the foreground app and
1158 * FLAG_ACTIVITY_NO_USER_ACTION is returned.
Wink Saville79085fc2009-06-09 10:27:23 -07001159 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001160 * @return 0 or FLAG_ACTIVITY_NO_USER_ACTION
1161 */
Wink Savillee68857d2014-10-17 15:23:05 -07001162 private int getFlagActivityNoUserAction(InitiatedByUserAction userAction, int slotId) {
1163 return ((userAction == InitiatedByUserAction.yes) | mStkContext[slotId].mMenuIsVisible)
1164 ? 0 : Intent.FLAG_ACTIVITY_NO_USER_ACTION;
1165 }
1166 /**
1167 * This method is used for cleaning up pending instances in stack.
1168 */
1169 private void cleanUpInstanceStackBySlot(int slotId) {
1170 Activity activity = mStkContext[slotId].getPendingActivityInstance();
1171 Activity dialog = mStkContext[slotId].getPendingDialogInstance();
1172 CatLog.d(LOG_TAG, "cleanUpInstanceStackBySlot slotId: " + slotId);
Legler Wuaeefef52014-10-27 00:57:18 +08001173 if (mStkContext[slotId].mCurrentCmd == null) {
1174 CatLog.d(LOG_TAG, "current cmd is null.");
1175 return;
1176 }
Wink Savillee68857d2014-10-17 15:23:05 -07001177 if (activity != null) {
1178 CatLog.d(LOG_TAG, "current cmd type: " +
1179 mStkContext[slotId].mCurrentCmd.getCmdType());
1180 if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1181 AppInterface.CommandType.GET_INPUT.value() ||
1182 mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1183 AppInterface.CommandType.GET_INKEY.value()) {
1184 mStkContext[slotId].mIsInputPending = true;
1185 } else if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1186 AppInterface.CommandType.SET_UP_MENU.value() ||
1187 mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1188 AppInterface.CommandType.SELECT_ITEM.value()) {
1189 mStkContext[slotId].mIsMenuPending = true;
1190 } else {
1191 }
1192 CatLog.d(LOG_TAG, "finish pending activity.");
1193 activity.finish();
1194 mStkContext[slotId].mActivityInstance = null;
1195 }
1196 if (dialog != null) {
1197 CatLog.d(LOG_TAG, "finish pending dialog.");
1198 mStkContext[slotId].mIsDialogPending = true;
1199 dialog.finish();
1200 mStkContext[slotId].mDialogInstance = null;
1201 }
1202 }
1203 /**
1204 * This method is used for restoring pending instances from stack.
1205 */
1206 private void restoreInstanceFromStackBySlot(int slotId) {
1207 AppInterface.CommandType cmdType = mStkContext[slotId].mCurrentCmd.getCmdType();
1208
1209 CatLog.d(LOG_TAG, "restoreInstanceFromStackBySlot cmdType : " + cmdType);
1210 switch(cmdType) {
1211 case GET_INPUT:
1212 case GET_INKEY:
1213 launchInputActivity(slotId);
1214 //Set mMenuIsVisible to true for showing main menu for
1215 //following session end command.
1216 mStkContext[slotId].mMenuIsVisible = true;
1217 break;
1218 case DISPLAY_TEXT:
1219 launchTextDialog(slotId);
1220 break;
1221 case LAUNCH_BROWSER:
1222 launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.geTextMessage(),
1223 slotId);
1224 break;
1225 case OPEN_CHANNEL:
1226 launchOpenChannelDialog(slotId);
1227 break;
1228 case SET_UP_CALL:
1229 launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.getCallSettings().
1230 confirmMsg, slotId);
1231 break;
1232 case SET_UP_MENU:
1233 case SELECT_ITEM:
1234 launchMenuActivity(null, slotId);
1235 break;
1236 default:
1237 break;
1238 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001239 }
1240
Wink Savillee68857d2014-10-17 15:23:05 -07001241 private void launchMenuActivity(Menu menu, int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001242 Intent newIntent = new Intent(Intent.ACTION_VIEW);
Wink Savillee68857d2014-10-17 15:23:05 -07001243 String targetActivity = STK_MENU_ACTIVITY_NAME;
1244 String uriString = STK_MENU_URI + System.currentTimeMillis();
1245 //Set unique URI to create a new instance of activity for different slotId.
1246 Uri uriData = Uri.parse(uriString);
1247
1248 CatLog.d(LOG_TAG, "launchMenuActivity, slotId: " + slotId + " , " +
1249 uriData.toString() + " , " + mStkContext[slotId].mOpCode + ", "
1250 + mStkContext[slotId].mMenuState);
1251 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1252 int intentFlags = Intent.FLAG_ACTIVITY_NEW_TASK;
1253
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001254 if (menu == null) {
1255 // We assume this was initiated by the user pressing the tool kit icon
Wink Savillee68857d2014-10-17 15:23:05 -07001256 intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.yes, slotId);
1257 if (mStkContext[slotId].mOpCode == OP_END_SESSION) {
1258 CatLog.d(LOG_TAG, "launchMenuActivity, return OP_END_SESSION");
1259 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN;
1260 if (mStkContext[slotId].mMainActivityInstance != null) {
1261 CatLog.d(LOG_TAG, "launchMenuActivity, mMainActivityInstance is not null");
1262 return;
1263 }
Wink Savillee68857d2014-10-17 15:23:05 -07001264 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001265
Wink Savillee68857d2014-10-17 15:23:05 -07001266 //If the last pending menu is secondary menu, "STATE" should be "STATE_SECONDARY".
1267 //Otherwise, it should be "STATE_MAIN".
1268 if (mStkContext[slotId].mOpCode == OP_LAUNCH_APP &&
1269 mStkContext[slotId].mMenuState == StkMenuActivity.STATE_SECONDARY) {
1270 newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY);
1271 } else {
1272 newIntent.putExtra("STATE", StkMenuActivity.STATE_MAIN);
1273 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN;
1274 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001275 } else {
1276 // We don't know and we'll let getFlagActivityNoUserAction decide.
Wink Savillee68857d2014-10-17 15:23:05 -07001277 intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001278 newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY);
Wink Savillee68857d2014-10-17 15:23:05 -07001279 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_SECONDARY;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001280 }
Wink Savillee68857d2014-10-17 15:23:05 -07001281 newIntent.putExtra(SLOT_ID, slotId);
1282 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001283 newIntent.setFlags(intentFlags);
1284 mContext.startActivity(newIntent);
1285 }
1286
Wink Savillee68857d2014-10-17 15:23:05 -07001287 private void launchInputActivity(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001288 Intent newIntent = new Intent(Intent.ACTION_VIEW);
Wink Savillee68857d2014-10-17 15:23:05 -07001289 String targetActivity = STK_INPUT_ACTIVITY_NAME;
1290 String uriString = STK_INPUT_URI + System.currentTimeMillis();
1291 //Set unique URI to create a new instance of activity for different slotId.
1292 Uri uriData = Uri.parse(uriString);
1293
1294 CatLog.d(LOG_TAG, "launchInputActivity, slotId: " + slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001295 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
Wink Savillee68857d2014-10-17 15:23:05 -07001296 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1297 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1298 newIntent.putExtra("INPUT", mStkContext[slotId].mCurrentCmd.geInput());
1299 newIntent.putExtra(SLOT_ID, slotId);
1300 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001301 mContext.startActivity(newIntent);
1302 }
1303
Wink Savillee68857d2014-10-17 15:23:05 -07001304 private void launchTextDialog(int slotId) {
1305 CatLog.d(LOG_TAG, "launchTextDialog, slotId: " + slotId);
1306 Intent newIntent = new Intent();
1307 String targetActivity = STK_DIALOG_ACTIVITY_NAME;
1308 int action = getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId);
1309 String uriString = STK_DIALOG_URI + System.currentTimeMillis();
1310 //Set unique URI to create a new instance of activity for different slotId.
1311 Uri uriData = Uri.parse(uriString);
1312 if (newIntent != null) {
1313 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1314 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1315 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
1316 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1317 newIntent.setData(uriData);
1318 newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage());
1319 newIntent.putExtra(SLOT_ID, slotId);
1320 startActivity(newIntent);
Preeti Ahuja414bc412013-06-25 19:31:49 -07001321 // For display texts with immediate response, send the terminal response
1322 // immediately. responseNeeded will be false, if display text command has
1323 // the immediate response tlv.
1324 if (!mStkContext[slotId].mCurrentCmd.geTextMessage().responseNeeded) {
1325 sendResponse(RES_ID_CONFIRM, slotId, true);
1326 }
Wink Savillee68857d2014-10-17 15:23:05 -07001327 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001328 }
1329
Wink Savillee68857d2014-10-17 15:23:05 -07001330 public boolean isStkDialogActivated(Context context) {
1331 String stkDialogActivity = "com.android.stk.StkDialogActivity";
1332 boolean activated = false;
1333 final ActivityManager am = (ActivityManager) context.getSystemService(
1334 Context.ACTIVITY_SERVICE);
1335 String topActivity = am.getRunningTasks(1).get(0).topActivity.getClassName();
1336
1337 CatLog.d(LOG_TAG, "isStkDialogActivated: " + topActivity);
1338 if (topActivity.equals(stkDialogActivity)) {
1339 activated = true;
1340 }
1341 CatLog.d(LOG_TAG, "activated : " + activated);
1342 return activated;
Johan Hellman3aec01c2011-02-10 10:15:28 +01001343 }
1344
Preeti Ahuja95919342013-10-01 18:18:55 -07001345 private void sendSetUpEventResponse(int event, byte[] addedInfo, int slotId) {
Preeti Ahuja414bc412013-06-25 19:31:49 -07001346 CatLog.d(this, "sendSetUpEventResponse: event : " + event + "slotId = " + slotId);
Preeti Ahuja95919342013-10-01 18:18:55 -07001347
1348 if (mStkContext[slotId].mCurrentSetupEventCmd == null){
1349 CatLog.e(this, "mCurrentSetupEventCmd is null");
1350 return;
1351 }
1352
1353 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentSetupEventCmd);
1354
1355 resMsg.setResultCode(ResultCode.OK);
1356 resMsg.setEventDownload(event, addedInfo);
1357
1358 mStkService[slotId].onCmdResponse(resMsg);
1359 }
1360
1361 private void checkForSetupEvent(int event, Bundle args, int slotId) {
1362 boolean eventPresent = false;
1363 byte[] addedInfo = null;
1364 CatLog.d(this, "Event :" + event);
1365
1366 if (mStkContext[slotId].mSetupEventListSettings != null) {
1367 /* Checks if the event is present in the EventList updated by last
1368 * SetupEventList Proactive Command */
1369 for (int i : mStkContext[slotId].mSetupEventListSettings.eventList) {
1370 if (event == i) {
1371 eventPresent = true;
1372 break;
1373 }
1374 }
1375
1376 /* If Event is present send the response to ICC */
1377 if (eventPresent == true) {
1378 CatLog.d(this, " Event " + event + "exists in the EventList");
1379
1380 switch (event) {
Preeti Ahuja560be362014-11-25 19:38:24 -08001381 case IDLE_SCREEN_AVAILABLE_EVENT:
1382 sendSetUpEventResponse(event, addedInfo, slotId);
1383 removeSetUpEvent(event, slotId);
1384 break;
Preeti Ahuja95919342013-10-01 18:18:55 -07001385 case LANGUAGE_SELECTION_EVENT:
1386 String language = mContext
1387 .getResources().getConfiguration().locale.getLanguage();
1388 CatLog.d(this, "language: " + language);
1389 // Each language code is a pair of alpha-numeric characters.
1390 // Each alpha-numeric character shall be coded on one byte
1391 // using the SMS default 7-bit coded alphabet
1392 addedInfo = GsmAlphabet.stringToGsm8BitPacked(language);
1393 sendSetUpEventResponse(event, addedInfo, slotId);
1394 break;
1395 default:
1396 break;
1397 }
1398 } else {
1399 CatLog.e(this, " Event does not exist in the EventList");
1400 }
1401 } else {
1402 CatLog.e(this, "SetupEventList is not received. Ignoring the event: " + event);
1403 }
1404 }
1405
1406 private void removeSetUpEvent(int event, int slotId) {
1407 CatLog.d(this, "Remove Event :" + event);
1408
1409 if (mStkContext[slotId].mSetupEventListSettings != null) {
1410 /*
1411 * Make new Eventlist without the event
1412 */
1413 for (int i = 0; i < mStkContext[slotId].mSetupEventListSettings.eventList.length; i++) {
1414 if (event == mStkContext[slotId].mSetupEventListSettings.eventList[i]) {
1415 mStkContext[slotId].mSetupEventListSettings.eventList[i] = INVALID_SETUP_EVENT;
1416 break;
1417 }
1418 }
1419 }
1420 }
1421
1422 private void launchEventMessage(int slotId) {
1423 launchEventMessage(slotId, mStkContext[slotId].mCurrentCmd.geTextMessage());
1424 }
1425
Wink Savillee68857d2014-10-17 15:23:05 -07001426 private void launchEventMessage(int slotId, TextMessage msg) {
1427 if (msg == null || (msg.text != null && msg.text.length() == 0)) {
1428 CatLog.d(LOG_TAG, "launchEventMessage return");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001429 return;
1430 }
Wink Savillee68857d2014-10-17 15:23:05 -07001431
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001432 Toast toast = new Toast(mContext.getApplicationContext());
1433 LayoutInflater inflate = (LayoutInflater) mContext
1434 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
1435 View v = inflate.inflate(R.layout.stk_event_msg, null);
1436 TextView tv = (TextView) v
1437 .findViewById(com.android.internal.R.id.message);
1438 ImageView iv = (ImageView) v
1439 .findViewById(com.android.internal.R.id.icon);
1440 if (msg.icon != null) {
1441 iv.setImageBitmap(msg.icon);
1442 } else {
1443 iv.setVisibility(View.GONE);
1444 }
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301445 /* In case of 'self explanatory' stkapp should display the specified
1446 * icon in proactive command (but not the alpha string).
1447 * If icon is non-self explanatory and if the icon could not be displayed
1448 * then alpha string or text data should be displayed
1449 * Ref: ETSI 102.223,section 6.5.4
1450 */
1451 if (mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ||
1452 msg.icon == null || !msg.iconSelfExplanatory) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001453 tv.setText(msg.text);
1454 }
1455
1456 toast.setView(v);
1457 toast.setDuration(Toast.LENGTH_LONG);
1458 toast.setGravity(Gravity.BOTTOM, 0, 0);
1459 toast.show();
1460 }
1461
Wink Savillee68857d2014-10-17 15:23:05 -07001462 private void launchConfirmationDialog(TextMessage msg, int slotId) {
1463 msg.title = mStkContext[slotId].lastSelectedItem;
1464 Intent newIntent = new Intent();
1465 String targetActivity = STK_DIALOG_ACTIVITY_NAME;
1466 String uriString = STK_DIALOG_URI + System.currentTimeMillis();
1467 //Set unique URI to create a new instance of activity for different slotId.
1468 Uri uriData = Uri.parse(uriString);
1469
1470 if (newIntent != null) {
1471 newIntent.setClassName(this, targetActivity);
1472 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1473 | Intent.FLAG_ACTIVITY_NO_HISTORY
1474 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
1475 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1476 newIntent.putExtra("TEXT", msg);
1477 newIntent.putExtra(SLOT_ID, slotId);
1478 newIntent.setData(uriData);
1479 startActivity(newIntent);
1480 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001481 }
1482
1483 private void launchBrowser(BrowserSettings settings) {
1484 if (settings == null) {
1485 return;
1486 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001487
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001488 Uri data = null;
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001489 String url;
1490 if (settings.url == null) {
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001491 // if the command did not contain a URL,
1492 // launch the browser to the default homepage.
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001493 CatLog.d(this, "no url data provided by proactive command." +
1494 " launching browser with stk default URL ... ");
1495 url = SystemProperties.get(STK_BROWSER_DEFAULT_URL_SYSPROP,
1496 "http://www.google.com");
1497 } else {
1498 CatLog.d(this, "launch browser command has attached url = " + settings.url);
1499 url = settings.url;
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001500 }
David Brown7c03cfe2011-10-20 15:36:12 -07001501
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001502 if (url.startsWith("http://") || url.startsWith("https://")) {
1503 data = Uri.parse(url);
1504 CatLog.d(this, "launching browser with url = " + url);
1505 } else {
1506 String modifiedUrl = "http://" + url;
1507 data = Uri.parse(modifiedUrl);
1508 CatLog.d(this, "launching browser with modified url = " + modifiedUrl);
1509 }
1510
1511 Intent intent = new Intent(Intent.ACTION_VIEW);
1512 intent.setData(data);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001513 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1514 switch (settings.mode) {
1515 case USE_EXISTING_BROWSER:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001516 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1517 break;
1518 case LAUNCH_NEW_BROWSER:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001519 intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
1520 break;
1521 case LAUNCH_IF_NOT_ALREADY_LAUNCHED:
1522 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1523 break;
1524 }
1525 // start browser activity
1526 startActivity(intent);
1527 // a small delay, let the browser start, before processing the next command.
Wink Saville79085fc2009-06-09 10:27:23 -07001528 // this is good for scenarios where a related DISPLAY TEXT command is
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001529 // followed immediately.
1530 try {
Ryuto Sawada350aaa62016-06-13 14:47:22 +09001531 Thread.sleep(3000);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001532 } catch (InterruptedException e) {}
1533 }
1534
Wink Savillee68857d2014-10-17 15:23:05 -07001535 private void launchIdleText(int slotId) {
Preeti Ahuja560be362014-11-25 19:38:24 -08001536 TextMessage msg = mStkContext[slotId].mIdleModeTextCmd.geTextMessage();
dujin.cha2a0eb2a2011-11-11 15:03:57 +09001537
Preeti Ahuja95919342013-10-01 18:18:55 -07001538 if (msg == null || msg.text ==null) {
1539 CatLog.d(LOG_TAG, msg == null ? "mCurrent.getTextMessage is NULL"
1540 : "mCurrent.getTextMessage.text is NULL");
Wink Savillee68857d2014-10-17 15:23:05 -07001541 mNotificationManager.cancel(getNotificationId(slotId));
Wink Saville046db4b2011-11-01 20:42:54 -07001542 return;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001543 } else {
Preeti Ahuja95919342013-10-01 18:18:55 -07001544 CatLog.d(LOG_TAG, "launchIdleText - text[" + msg.text
1545 + "] iconSelfExplanatory[" + msg.iconSelfExplanatory
1546 + "] icon[" + msg.icon + "], sim id: " + slotId);
Wink Savillee68857d2014-10-17 15:23:05 -07001547 CatLog.d(LOG_TAG, "Add IdleMode text");
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001548 PendingIntent pendingIntent = PendingIntent.getService(mContext, 0,
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001549 new Intent(mContext, StkAppService.class), 0);
1550
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001551 final Notification.Builder notificationBuilder = new Notification.Builder(
1552 StkAppService.this);
Wink Savillee68857d2014-10-17 15:23:05 -07001553 if (mStkContext[slotId].mMainCmd != null &&
1554 mStkContext[slotId].mMainCmd.getMenu() != null) {
1555 notificationBuilder.setContentTitle(mStkContext[slotId].mMainCmd.getMenu().title);
Christopher Posselwhite2ad2ab72013-05-27 07:51:06 +02001556 } else {
1557 notificationBuilder.setContentTitle("");
1558 }
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001559 notificationBuilder
1560 .setSmallIcon(com.android.internal.R.drawable.stat_notify_sim_toolkit);
1561 notificationBuilder.setContentIntent(pendingIntent);
1562 notificationBuilder.setOngoing(true);
1563 // Set text and icon for the status bar and notification body.
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301564 if (mStkContext[slotId].mIdleModeTextCmd.hasIconLoadFailed() ||
1565 !msg.iconSelfExplanatory) {
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001566 notificationBuilder.setContentText(msg.text);
Christopher Posselwhite2ad2ab72013-05-27 07:51:06 +02001567 notificationBuilder.setTicker(msg.text);
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001568 }
1569 if (msg.icon != null) {
1570 notificationBuilder.setLargeIcon(msg.icon);
1571 } else {
1572 Bitmap bitmapIcon = BitmapFactory.decodeResource(StkAppService.this
1573 .getResources().getSystem(),
1574 com.android.internal.R.drawable.stat_notify_sim_toolkit);
1575 notificationBuilder.setLargeIcon(bitmapIcon);
1576 }
Selim Cinek62eb3fe2014-08-27 17:52:23 +02001577 notificationBuilder.setColor(mContext.getResources().getColor(
1578 com.android.internal.R.color.system_notification_accent_color));
Wink Savillee68857d2014-10-17 15:23:05 -07001579 mNotificationManager.notify(getNotificationId(slotId), notificationBuilder.build());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001580 }
1581 }
1582
Wink Savillee68857d2014-10-17 15:23:05 -07001583 private void launchToneDialog(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001584 Intent newIntent = new Intent(this, ToneDialog.class);
Wink Savillee68857d2014-10-17 15:23:05 -07001585 String uriString = STK_TONE_URI + slotId;
1586 Uri uriData = Uri.parse(uriString);
1587 //Set unique URI to create a new instance of activity for different slotId.
1588 CatLog.d(LOG_TAG, "launchToneDialog, slotId: " + slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001589 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1590 | Intent.FLAG_ACTIVITY_NO_HISTORY
1591 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
Wink Savillee68857d2014-10-17 15:23:05 -07001592 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1593 newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage());
1594 newIntent.putExtra("TONE", mStkContext[slotId].mCurrentCmd.getToneSettings());
1595 newIntent.putExtra(SLOT_ID, slotId);
1596 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001597 startActivity(newIntent);
1598 }
1599
Takanori Nakano49b12722016-02-16 14:34:14 +09001600 private void launchOpenChannelDialog(final int slotId) {
Wink Savillee68857d2014-10-17 15:23:05 -07001601 TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001602 if (msg == null) {
Wink Savillee68857d2014-10-17 15:23:05 -07001603 CatLog.d(LOG_TAG, "msg is null, return here");
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001604 return;
1605 }
1606
1607 msg.title = getResources().getString(R.string.stk_dialog_title);
1608 if (msg.text == null) {
1609 msg.text = getResources().getString(R.string.default_open_channel_msg);
1610 }
1611
1612 final AlertDialog dialog = new AlertDialog.Builder(mContext)
1613 .setIconAttribute(android.R.attr.alertDialogIcon)
1614 .setTitle(msg.title)
1615 .setMessage(msg.text)
1616 .setCancelable(false)
1617 .setPositiveButton(getResources().getString(R.string.stk_dialog_accept),
1618 new DialogInterface.OnClickListener() {
1619 public void onClick(DialogInterface dialog, int which) {
1620 Bundle args = new Bundle();
1621 args.putInt(RES_ID, RES_ID_CHOICE);
1622 args.putInt(CHOICE, YES);
1623 Message message = mServiceHandler.obtainMessage();
1624 message.arg1 = OP_RESPONSE;
Takanori Nakano49b12722016-02-16 14:34:14 +09001625 message.arg2 = slotId;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001626 message.obj = args;
1627 mServiceHandler.sendMessage(message);
1628 }
1629 })
1630 .setNegativeButton(getResources().getString(R.string.stk_dialog_reject),
1631 new DialogInterface.OnClickListener() {
1632 public void onClick(DialogInterface dialog, int which) {
1633 Bundle args = new Bundle();
1634 args.putInt(RES_ID, RES_ID_CHOICE);
1635 args.putInt(CHOICE, NO);
1636 Message message = mServiceHandler.obtainMessage();
1637 message.arg1 = OP_RESPONSE;
Takanori Nakano49b12722016-02-16 14:34:14 +09001638 message.arg2 = slotId;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001639 message.obj = args;
1640 mServiceHandler.sendMessage(message);
1641 }
1642 })
1643 .create();
1644
1645 dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
1646 if (!mContext.getResources().getBoolean(
1647 com.android.internal.R.bool.config_sf_slowBlur)) {
1648 dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
1649 }
1650
1651 dialog.show();
1652 }
1653
Wink Savillee68857d2014-10-17 15:23:05 -07001654 private void launchTransientEventMessage(int slotId) {
1655 TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001656 if (msg == null) {
Wink Savillee68857d2014-10-17 15:23:05 -07001657 CatLog.d(LOG_TAG, "msg is null, return here");
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001658 return;
1659 }
1660
1661 msg.title = getResources().getString(R.string.stk_dialog_title);
1662
1663 final AlertDialog dialog = new AlertDialog.Builder(mContext)
1664 .setIconAttribute(android.R.attr.alertDialogIcon)
1665 .setTitle(msg.title)
1666 .setMessage(msg.text)
1667 .setCancelable(false)
1668 .setPositiveButton(getResources().getString(android.R.string.ok),
1669 new DialogInterface.OnClickListener() {
1670 public void onClick(DialogInterface dialog, int which) {
1671 }
1672 })
1673 .create();
1674
1675 dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
1676 if (!mContext.getResources().getBoolean(
1677 com.android.internal.R.bool.config_sf_slowBlur)) {
1678 dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
1679 }
1680
1681 dialog.show();
1682 }
1683
Wink Savillee68857d2014-10-17 15:23:05 -07001684 private int getNotificationId(int slotId) {
1685 int notifyId = STK_NOTIFICATION_ID;
1686 if (slotId >= 0 && slotId < mSimCount) {
1687 notifyId += slotId;
1688 } else {
1689 CatLog.d(LOG_TAG, "invalid slotId: " + slotId);
1690 }
1691 CatLog.d(LOG_TAG, "getNotificationId, slotId: " + slotId + ", notifyId: " + notifyId);
1692 return notifyId;
1693 }
1694
1695 private String getItemName(int itemId, int slotId) {
1696 Menu menu = mStkContext[slotId].mCurrentCmd.getMenu();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001697 if (menu == null) {
1698 return null;
1699 }
1700 for (Item item : menu.items) {
1701 if (item.id == itemId) {
1702 return item.text;
1703 }
1704 }
1705 return null;
1706 }
1707
Wink Savillee68857d2014-10-17 15:23:05 -07001708 private boolean removeMenu(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001709 try {
Wink Savillee68857d2014-10-17 15:23:05 -07001710 if (mStkContext[slotId].mCurrentMenu.items.size() == 1 &&
1711 mStkContext[slotId].mCurrentMenu.items.get(0) == null) {
1712 mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001713 return true;
1714 }
1715 } catch (NullPointerException e) {
Wink Savillee68857d2014-10-17 15:23:05 -07001716 CatLog.d(LOG_TAG, "Unable to get Menu's items size");
1717 mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001718 return true;
1719 }
Wink Savillee68857d2014-10-17 15:23:05 -07001720 mStkContext[slotId].mSetupMenuState = STATE_EXIST;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001721 return false;
1722 }
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +05301723
Wink Savillee68857d2014-10-17 15:23:05 -07001724 StkContext getStkContext(int slotId) {
1725 if (slotId >= 0 && slotId < mSimCount) {
1726 return mStkContext[slotId];
1727 } else {
1728 CatLog.d(LOG_TAG, "invalid slotId: " + slotId);
1729 return null;
1730 }
1731 }
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +05301732
1733 private void handleAlphaNotify(Bundle args) {
1734 String alphaString = args.getString(AppInterface.ALPHA_STRING);
1735
1736 CatLog.d(this, "Alpha string received from card: " + alphaString);
1737 Toast toast = Toast.makeText(sInstance, alphaString, Toast.LENGTH_LONG);
1738 toast.setGravity(Gravity.TOP, 0, 0);
1739 toast.show();
1740 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001741}