blob: 9eec59e986d4d241e29e0757fae2a7ecd0d17b54 [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() {
pkanwareab12f32017-02-06 08:35:03 -0800801 ActivityManager mActivityManager = (ActivityManager) mContext
Preeti Ahuja560be362014-11-25 19:38:24 -0800802 .getSystemService(ACTIVITY_SERVICE);
pkanwareab12f32017-02-06 08:35:03 -0800803 String currentPackageName = null;
804 List<RunningTaskInfo> tasks = mActivityManager.getRunningTasks(1);
805 if (tasks == null || tasks.get(0).topActivity == null) {
806 return false;
807 }
808 currentPackageName = tasks.get(0).topActivity.getPackageName();
Preeti Ahuja560be362014-11-25 19:38:24 -0800809 if (null != currentPackageName) {
810 return currentPackageName.equals(PACKAGE_NAME);
811 }
Preeti Ahuja560be362014-11-25 19:38:24 -0800812 return false;
813 }
814
Wink Savillee68857d2014-10-17 15:23:05 -0700815 private void handleCmd(CatCmdMessage cmdMsg, int slotId) {
Preeti Ahuja95919342013-10-01 18:18:55 -0700816
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800817 if (cmdMsg == null) {
818 return;
819 }
820 // save local reference for state tracking.
Wink Savillee68857d2014-10-17 15:23:05 -0700821 mStkContext[slotId].mCurrentCmd = cmdMsg;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800822 boolean waitForUsersResponse = true;
823
Wink Savillee68857d2014-10-17 15:23:05 -0700824 mStkContext[slotId].mIsInputPending = false;
825 mStkContext[slotId].mIsMenuPending = false;
826 mStkContext[slotId].mIsDialogPending = false;
827
828 CatLog.d(LOG_TAG,"[handleCmd]" + cmdMsg.getCmdType().name());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800829 switch (cmdMsg.getCmdType()) {
830 case DISPLAY_TEXT:
831 TextMessage msg = cmdMsg.geTextMessage();
Jeevaka Badrappan854a25c2012-12-01 16:32:03 +0200832 waitForUsersResponse = msg.responseNeeded;
Wink Savillee68857d2014-10-17 15:23:05 -0700833 if (mStkContext[slotId].lastSelectedItem != null) {
834 msg.title = mStkContext[slotId].lastSelectedItem;
835 } else if (mStkContext[slotId].mMainCmd != null){
836 msg.title = mStkContext[slotId].mMainCmd.getMenu().title;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800837 } else {
838 // TODO: get the carrier name from the SIM
839 msg.title = "";
840 }
Preeti Ahuja560be362014-11-25 19:38:24 -0800841 //If we receive a low priority Display Text and the device is
842 // not displaying any STK related activity and the screen is not idle
843 // ( that is, device is in an interactive state), then send a screen busy
844 // terminal response. Otherwise display the message. The existing
845 // displayed message shall be updated with the new display text
846 // proactive command (Refer to ETSI TS 102 384 section 27.22.4.1.4.4.2).
847 if (!(msg.isHighPriority || mStkContext[slotId].mMenuIsVisible
848 || mStkContext[slotId].mDisplayTextDlgIsVisibile || isTopOfStack())) {
849 if(!isScreenIdle()) {
850 CatLog.d(LOG_TAG, "Screen is not idle");
851 sendScreenBusyResponse(slotId);
852 } else {
853 launchTextDialog(slotId);
854 }
855 } else {
856 launchTextDialog(slotId);
857 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800858 break;
859 case SELECT_ITEM:
Wink Savillee68857d2014-10-17 15:23:05 -0700860 CatLog.d(LOG_TAG, "SELECT_ITEM +");
861 mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd;
862 mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu();
863 launchMenuActivity(cmdMsg.getMenu(), slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800864 break;
865 case SET_UP_MENU:
Wink Savillee68857d2014-10-17 15:23:05 -0700866 mStkContext[slotId].mCmdInProgress = false;
867 mStkContext[slotId].mMainCmd = mStkContext[slotId].mCurrentCmd;
868 mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd;
869 mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu();
870 CatLog.d(LOG_TAG, "SET_UP_MENU [" + removeMenu(slotId) + "]");
871
872 if (removeMenu(slotId)) {
873 int i = 0;
874 CatLog.d(LOG_TAG, "removeMenu() - Uninstall App");
875 mStkContext[slotId].mCurrentMenu = null;
Preeti Ahuja95919342013-10-01 18:18:55 -0700876 mStkContext[slotId].mMainCmd = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700877 //Check other setup menu state. If all setup menu are removed, uninstall apk.
878 for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) {
879 if (i != slotId
880 && (mStkContext[slotId].mSetupMenuState == STATE_UNKNOWN
881 || mStkContext[slotId].mSetupMenuState == STATE_EXIST)) {
882 CatLog.d(LOG_TAG, "Not Uninstall App:" + i + ","
883 + mStkContext[slotId].mSetupMenuState);
884 break;
885 }
886 }
887 if (i == mSimCount) {
888 StkAppInstaller.unInstall(mContext);
889 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800890 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700891 CatLog.d(LOG_TAG, "install App");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800892 StkAppInstaller.install(mContext);
893 }
Wink Savillee68857d2014-10-17 15:23:05 -0700894 if (mStkContext[slotId].mMenuIsVisible) {
895 launchMenuActivity(null, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800896 }
897 break;
898 case GET_INPUT:
899 case GET_INKEY:
Wink Savillee68857d2014-10-17 15:23:05 -0700900 launchInputActivity(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800901 break;
902 case SET_UP_IDLE_MODE_TEXT:
903 waitForUsersResponse = false;
Preeti Ahuja560be362014-11-25 19:38:24 -0800904 mStkContext[slotId].mIdleModeTextCmd = mStkContext[slotId].mCurrentCmd;
905 TextMessage idleModeText = mStkContext[slotId].mCurrentCmd.geTextMessage();
906 if (idleModeText == null) {
907 launchIdleText(slotId);
908 mStkContext[slotId].mIdleModeTextCmd = null;
909 }
910 mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
911 if ((mStkContext[slotId].mIdleModeTextCmd != null) && isScreenIdle()) {
912 CatLog.d(this, "set up idle mode");
913 launchIdleText(slotId);
914 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800915 break;
916 case SEND_DTMF:
917 case SEND_SMS:
918 case SEND_SS:
919 case SEND_USSD:
Preeti Ahuja95919342013-10-01 18:18:55 -0700920 case GET_CHANNEL_STATUS:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800921 waitForUsersResponse = false;
Wink Savillee68857d2014-10-17 15:23:05 -0700922 launchEventMessage(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800923 break;
924 case LAUNCH_BROWSER:
Ryuto Sawada0bdc7192016-04-18 12:10:56 +0900925 // The device setup process should not be interrupted by launching browser.
926 if (Settings.Global.getInt(mContext.getContentResolver(),
927 Settings.Global.DEVICE_PROVISIONED, 0) == 0) {
928 CatLog.d(this, "The command is not performed if the setup has not been completed.");
929 sendScreenBusyResponse(slotId);
930 break;
931 }
Preeti Ahujaa7cdca22013-10-01 18:20:56 -0700932 TextMessage alphaId = mStkContext[slotId].mCurrentCmd.geTextMessage();
933 if ((mStkContext[slotId].mCurrentCmd.getBrowserSettings().mode
934 == LaunchBrowserMode.LAUNCH_IF_NOT_ALREADY_LAUNCHED) &&
935 ((alphaId == null) || TextUtils.isEmpty(alphaId.text))) {
936 // don't need user confirmation in this case
937 // just launch the browser or spawn a new tab
938 CatLog.d(this, "Browser mode is: launch if not already launched " +
939 "and user confirmation is not currently needed.\n" +
940 "supressing confirmation dialogue and confirming silently...");
941 mStkContext[slotId].launchBrowser = true;
942 mStkContext[slotId].mBrowserSettings =
943 mStkContext[slotId].mCurrentCmd.getBrowserSettings();
944 sendResponse(RES_ID_CONFIRM, slotId, true);
945 } else {
946 launchConfirmationDialog(alphaId, slotId);
947 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800948 break;
949 case SET_UP_CALL:
Preeti Ahujadd240102013-08-30 17:25:06 -0700950 TextMessage mesg = mStkContext[slotId].mCurrentCmd.getCallSettings().confirmMsg;
951 if((mesg != null) && (mesg.text == null || mesg.text.length() == 0)) {
952 mesg.text = getResources().getString(R.string.default_setup_call_msg);
953 }
954 CatLog.d(this, "SET_UP_CALL mesg.text " + mesg.text);
955 launchConfirmationDialog(mesg, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800956 break;
957 case PLAY_TONE:
Wink Savillee68857d2014-10-17 15:23:05 -0700958 launchToneDialog(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800959 break;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500960 case OPEN_CHANNEL:
Wink Savillee68857d2014-10-17 15:23:05 -0700961 launchOpenChannelDialog(slotId);
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500962 break;
963 case CLOSE_CHANNEL:
964 case RECEIVE_DATA:
965 case SEND_DATA:
Wink Savillee68857d2014-10-17 15:23:05 -0700966 TextMessage m = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500967
968 if ((m != null) && (m.text == null)) {
969 switch(cmdMsg.getCmdType()) {
970 case CLOSE_CHANNEL:
971 m.text = getResources().getString(R.string.default_close_channel_msg);
972 break;
973 case RECEIVE_DATA:
974 m.text = getResources().getString(R.string.default_receive_data_msg);
975 break;
976 case SEND_DATA:
977 m.text = getResources().getString(R.string.default_send_data_msg);
978 break;
979 }
980 }
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -0700981 /*
982 * Display indication in the form of a toast to the user if required.
983 */
Wink Savillee68857d2014-10-17 15:23:05 -0700984 launchEventMessage(slotId);
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500985 break;
Preeti Ahuja95919342013-10-01 18:18:55 -0700986 case SET_UP_EVENT_LIST:
987 mStkContext[slotId].mSetupEventListSettings =
988 mStkContext[slotId].mCurrentCmd.getSetEventList();
989 mStkContext[slotId].mCurrentSetupEventCmd = mStkContext[slotId].mCurrentCmd;
990 mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
Preeti Ahuja560be362014-11-25 19:38:24 -0800991 if (isScreenIdle()) {
992 CatLog.d(this," Check if IDLE_SCREEN_AVAILABLE_EVENT is present in List");
993 checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId);
994 }
Preeti Ahuja95919342013-10-01 18:18:55 -0700995 break;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800996 }
997
998 if (!waitForUsersResponse) {
Wink Savillee68857d2014-10-17 15:23:05 -0700999 if (mStkContext[slotId].mCmdsQ.size() != 0) {
1000 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001001 } else {
Wink Savillee68857d2014-10-17 15:23:05 -07001002 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001003 }
1004 }
1005 }
1006
Wink Savillee68857d2014-10-17 15:23:05 -07001007 private void handleCmdResponse(Bundle args, int slotId) {
1008 CatLog.d(LOG_TAG, "handleCmdResponse, sim id: " + slotId);
1009 if (mStkContext[slotId].mCurrentCmd == null) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001010 return;
1011 }
Wink Savillee68857d2014-10-17 15:23:05 -07001012
1013 if (mStkService[slotId] == null) {
Legler Wuaeefef52014-10-27 00:57:18 +08001014 mStkService[slotId] = CatService.getInstance(slotId);
Wink Savillee68857d2014-10-17 15:23:05 -07001015 if (mStkService[slotId] == null) {
Alex Yakavenkad8e2ecd2012-04-20 17:10:15 -07001016 // This should never happen (we should be responding only to a message
1017 // that arrived from StkService). It has to exist by this time
Wink Savillee68857d2014-10-17 15:23:05 -07001018 CatLog.d(LOG_TAG, "Exception! mStkService is null when we need to send response.");
Alex Yakavenkad8e2ecd2012-04-20 17:10:15 -07001019 throw new RuntimeException("mStkService is null when we need to send response");
1020 }
1021 }
1022
Wink Savillee68857d2014-10-17 15:23:05 -07001023 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001024
1025 // set result code
1026 boolean helpRequired = args.getBoolean(HELP, false);
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001027 boolean confirmed = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001028
1029 switch(args.getInt(RES_ID)) {
1030 case RES_ID_MENU_SELECTION:
Wink Savillee68857d2014-10-17 15:23:05 -07001031 CatLog.d(LOG_TAG, "MENU_SELECTION=" + mStkContext[slotId].
1032 mCurrentMenuCmd.getCmdType());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001033 int menuSelection = args.getInt(MENU_SELECTION);
Wink Savillee68857d2014-10-17 15:23:05 -07001034 switch(mStkContext[slotId].mCurrentMenuCmd.getCmdType()) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001035 case SET_UP_MENU:
1036 case SELECT_ITEM:
Wink Savillee68857d2014-10-17 15:23:05 -07001037 mStkContext[slotId].lastSelectedItem = getItemName(menuSelection, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001038 if (helpRequired) {
1039 resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED);
1040 } else {
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301041 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1042 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001043 }
1044 resMsg.setMenuSelection(menuSelection);
1045 break;
1046 }
1047 break;
1048 case RES_ID_INPUT:
Wink Savillee68857d2014-10-17 15:23:05 -07001049 CatLog.d(LOG_TAG, "RES_ID_INPUT");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001050 String input = args.getString(INPUT);
Wink Savillee68857d2014-10-17 15:23:05 -07001051 if (input != null && (null != mStkContext[slotId].mCurrentCmd.geInput()) &&
1052 (mStkContext[slotId].mCurrentCmd.geInput().yesNo)) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001053 boolean yesNoSelection = input
1054 .equals(StkInputActivity.YES_STR_RESPONSE);
1055 resMsg.setYesNo(yesNoSelection);
1056 } else {
1057 if (helpRequired) {
1058 resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED);
1059 } else {
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301060 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1061 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001062 resMsg.setInput(input);
1063 }
1064 }
1065 break;
1066 case RES_ID_CONFIRM:
Alex Yakavenkad41f1d92010-07-12 14:13:13 -07001067 CatLog.d(this, "RES_ID_CONFIRM");
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001068 confirmed = args.getBoolean(CONFIRMATION);
Wink Savillee68857d2014-10-17 15:23:05 -07001069 switch (mStkContext[slotId].mCurrentCmd.getCmdType()) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001070 case DISPLAY_TEXT:
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301071 if (confirmed) {
1072 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1073 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
1074 } else {
1075 resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER);
1076 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001077 break;
1078 case LAUNCH_BROWSER:
1079 resMsg.setResultCode(confirmed ? ResultCode.OK
1080 : ResultCode.UICC_SESSION_TERM_BY_USER);
1081 if (confirmed) {
Wink Savillee68857d2014-10-17 15:23:05 -07001082 mStkContext[slotId].launchBrowser = true;
1083 mStkContext[slotId].mBrowserSettings =
1084 mStkContext[slotId].mCurrentCmd.getBrowserSettings();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001085 }
1086 break;
1087 case SET_UP_CALL:
1088 resMsg.setResultCode(ResultCode.OK);
1089 resMsg.setConfirmation(confirmed);
1090 if (confirmed) {
Wink Savillee68857d2014-10-17 15:23:05 -07001091 launchEventMessage(slotId,
1092 mStkContext[slotId].mCurrentCmd.getCallSettings().callMsg);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001093 }
1094 break;
1095 }
1096 break;
1097 case RES_ID_DONE:
1098 resMsg.setResultCode(ResultCode.OK);
1099 break;
1100 case RES_ID_BACKWARD:
Wink Savillee68857d2014-10-17 15:23:05 -07001101 CatLog.d(LOG_TAG, "RES_ID_BACKWARD");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001102 resMsg.setResultCode(ResultCode.BACKWARD_MOVE_BY_USER);
1103 break;
1104 case RES_ID_END_SESSION:
Wink Savillee68857d2014-10-17 15:23:05 -07001105 CatLog.d(LOG_TAG, "RES_ID_END_SESSION");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001106 resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER);
1107 break;
1108 case RES_ID_TIMEOUT:
Wink Savillee68857d2014-10-17 15:23:05 -07001109 CatLog.d(LOG_TAG, "RES_ID_TIMEOUT");
Naveen Kallad5176892009-11-30 12:45:29 -08001110 // GCF test-case 27.22.4.1.1 Expected Sequence 1.5 (DISPLAY TEXT,
1111 // Clear message after delay, successful) expects result code OK.
1112 // If the command qualifier specifies no user response is required
1113 // then send OK instead of NO_RESPONSE_FROM_USER
Wink Savillee68857d2014-10-17 15:23:05 -07001114 if ((mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1115 AppInterface.CommandType.DISPLAY_TEXT.value())
1116 && (mStkContext[slotId].mCurrentCmd.geTextMessage().userClear == false)) {
Naveen Kallad5176892009-11-30 12:45:29 -08001117 resMsg.setResultCode(ResultCode.OK);
1118 } else {
1119 resMsg.setResultCode(ResultCode.NO_RESPONSE_FROM_USER);
1120 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001121 break;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001122 case RES_ID_CHOICE:
1123 int choice = args.getInt(CHOICE);
1124 CatLog.d(this, "User Choice=" + choice);
1125 switch (choice) {
1126 case YES:
1127 resMsg.setResultCode(ResultCode.OK);
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001128 confirmed = true;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001129 break;
1130 case NO:
1131 resMsg.setResultCode(ResultCode.USER_NOT_ACCEPT);
1132 break;
1133 }
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001134
Wink Savillee68857d2014-10-17 15:23:05 -07001135 if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1136 AppInterface.CommandType.OPEN_CHANNEL.value()) {
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001137 resMsg.setConfirmation(confirmed);
1138 }
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001139 break;
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001140
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001141 default:
Wink Savillee68857d2014-10-17 15:23:05 -07001142 CatLog.d(LOG_TAG, "Unknown result id");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001143 return;
1144 }
Wink Savillee68857d2014-10-17 15:23:05 -07001145
1146 if (null != mStkContext[slotId].mCurrentCmd &&
1147 null != mStkContext[slotId].mCurrentCmd.getCmdType()) {
1148 CatLog.d(LOG_TAG, "handleCmdResponse- cmdName[" +
1149 mStkContext[slotId].mCurrentCmd.getCmdType().name() + "]");
1150 }
1151 mStkService[slotId].onCmdResponse(resMsg);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001152 }
1153
1154 /**
1155 * Returns 0 or FLAG_ACTIVITY_NO_USER_ACTION, 0 means the user initiated the action.
1156 *
1157 * @param userAction If the userAction is yes then we always return 0 otherwise
1158 * mMenuIsVisible is used to determine what to return. If mMenuIsVisible is true
1159 * then we are the foreground app and we'll return 0 as from our perspective a
1160 * user action did cause. If it's false than we aren't the foreground app and
1161 * FLAG_ACTIVITY_NO_USER_ACTION is returned.
Wink Saville79085fc2009-06-09 10:27:23 -07001162 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001163 * @return 0 or FLAG_ACTIVITY_NO_USER_ACTION
1164 */
Wink Savillee68857d2014-10-17 15:23:05 -07001165 private int getFlagActivityNoUserAction(InitiatedByUserAction userAction, int slotId) {
1166 return ((userAction == InitiatedByUserAction.yes) | mStkContext[slotId].mMenuIsVisible)
1167 ? 0 : Intent.FLAG_ACTIVITY_NO_USER_ACTION;
1168 }
1169 /**
1170 * This method is used for cleaning up pending instances in stack.
1171 */
1172 private void cleanUpInstanceStackBySlot(int slotId) {
1173 Activity activity = mStkContext[slotId].getPendingActivityInstance();
1174 Activity dialog = mStkContext[slotId].getPendingDialogInstance();
1175 CatLog.d(LOG_TAG, "cleanUpInstanceStackBySlot slotId: " + slotId);
Legler Wuaeefef52014-10-27 00:57:18 +08001176 if (mStkContext[slotId].mCurrentCmd == null) {
1177 CatLog.d(LOG_TAG, "current cmd is null.");
1178 return;
1179 }
Wink Savillee68857d2014-10-17 15:23:05 -07001180 if (activity != null) {
1181 CatLog.d(LOG_TAG, "current cmd type: " +
1182 mStkContext[slotId].mCurrentCmd.getCmdType());
1183 if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1184 AppInterface.CommandType.GET_INPUT.value() ||
1185 mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1186 AppInterface.CommandType.GET_INKEY.value()) {
1187 mStkContext[slotId].mIsInputPending = true;
1188 } else if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1189 AppInterface.CommandType.SET_UP_MENU.value() ||
1190 mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1191 AppInterface.CommandType.SELECT_ITEM.value()) {
1192 mStkContext[slotId].mIsMenuPending = true;
1193 } else {
1194 }
1195 CatLog.d(LOG_TAG, "finish pending activity.");
1196 activity.finish();
1197 mStkContext[slotId].mActivityInstance = null;
1198 }
1199 if (dialog != null) {
1200 CatLog.d(LOG_TAG, "finish pending dialog.");
1201 mStkContext[slotId].mIsDialogPending = true;
1202 dialog.finish();
1203 mStkContext[slotId].mDialogInstance = null;
1204 }
1205 }
1206 /**
1207 * This method is used for restoring pending instances from stack.
1208 */
1209 private void restoreInstanceFromStackBySlot(int slotId) {
1210 AppInterface.CommandType cmdType = mStkContext[slotId].mCurrentCmd.getCmdType();
1211
1212 CatLog.d(LOG_TAG, "restoreInstanceFromStackBySlot cmdType : " + cmdType);
1213 switch(cmdType) {
1214 case GET_INPUT:
1215 case GET_INKEY:
1216 launchInputActivity(slotId);
1217 //Set mMenuIsVisible to true for showing main menu for
1218 //following session end command.
1219 mStkContext[slotId].mMenuIsVisible = true;
1220 break;
1221 case DISPLAY_TEXT:
1222 launchTextDialog(slotId);
1223 break;
1224 case LAUNCH_BROWSER:
1225 launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.geTextMessage(),
1226 slotId);
1227 break;
1228 case OPEN_CHANNEL:
1229 launchOpenChannelDialog(slotId);
1230 break;
1231 case SET_UP_CALL:
1232 launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.getCallSettings().
1233 confirmMsg, slotId);
1234 break;
1235 case SET_UP_MENU:
1236 case SELECT_ITEM:
1237 launchMenuActivity(null, slotId);
1238 break;
1239 default:
1240 break;
1241 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001242 }
1243
Wink Savillee68857d2014-10-17 15:23:05 -07001244 private void launchMenuActivity(Menu menu, int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001245 Intent newIntent = new Intent(Intent.ACTION_VIEW);
Wink Savillee68857d2014-10-17 15:23:05 -07001246 String targetActivity = STK_MENU_ACTIVITY_NAME;
1247 String uriString = STK_MENU_URI + System.currentTimeMillis();
1248 //Set unique URI to create a new instance of activity for different slotId.
1249 Uri uriData = Uri.parse(uriString);
1250
1251 CatLog.d(LOG_TAG, "launchMenuActivity, slotId: " + slotId + " , " +
1252 uriData.toString() + " , " + mStkContext[slotId].mOpCode + ", "
1253 + mStkContext[slotId].mMenuState);
1254 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1255 int intentFlags = Intent.FLAG_ACTIVITY_NEW_TASK;
1256
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001257 if (menu == null) {
1258 // We assume this was initiated by the user pressing the tool kit icon
Wink Savillee68857d2014-10-17 15:23:05 -07001259 intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.yes, slotId);
1260 if (mStkContext[slotId].mOpCode == OP_END_SESSION) {
1261 CatLog.d(LOG_TAG, "launchMenuActivity, return OP_END_SESSION");
1262 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN;
1263 if (mStkContext[slotId].mMainActivityInstance != null) {
1264 CatLog.d(LOG_TAG, "launchMenuActivity, mMainActivityInstance is not null");
1265 return;
1266 }
Wink Savillee68857d2014-10-17 15:23:05 -07001267 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001268
Wink Savillee68857d2014-10-17 15:23:05 -07001269 //If the last pending menu is secondary menu, "STATE" should be "STATE_SECONDARY".
1270 //Otherwise, it should be "STATE_MAIN".
1271 if (mStkContext[slotId].mOpCode == OP_LAUNCH_APP &&
1272 mStkContext[slotId].mMenuState == StkMenuActivity.STATE_SECONDARY) {
1273 newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY);
1274 } else {
1275 newIntent.putExtra("STATE", StkMenuActivity.STATE_MAIN);
1276 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN;
1277 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001278 } else {
1279 // We don't know and we'll let getFlagActivityNoUserAction decide.
Wink Savillee68857d2014-10-17 15:23:05 -07001280 intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001281 newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY);
Wink Savillee68857d2014-10-17 15:23:05 -07001282 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_SECONDARY;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001283 }
Wink Savillee68857d2014-10-17 15:23:05 -07001284 newIntent.putExtra(SLOT_ID, slotId);
1285 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001286 newIntent.setFlags(intentFlags);
1287 mContext.startActivity(newIntent);
1288 }
1289
Wink Savillee68857d2014-10-17 15:23:05 -07001290 private void launchInputActivity(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001291 Intent newIntent = new Intent(Intent.ACTION_VIEW);
Wink Savillee68857d2014-10-17 15:23:05 -07001292 String targetActivity = STK_INPUT_ACTIVITY_NAME;
1293 String uriString = STK_INPUT_URI + System.currentTimeMillis();
1294 //Set unique URI to create a new instance of activity for different slotId.
1295 Uri uriData = Uri.parse(uriString);
1296
1297 CatLog.d(LOG_TAG, "launchInputActivity, slotId: " + slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001298 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
Wink Savillee68857d2014-10-17 15:23:05 -07001299 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1300 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1301 newIntent.putExtra("INPUT", mStkContext[slotId].mCurrentCmd.geInput());
1302 newIntent.putExtra(SLOT_ID, slotId);
1303 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001304 mContext.startActivity(newIntent);
1305 }
1306
Wink Savillee68857d2014-10-17 15:23:05 -07001307 private void launchTextDialog(int slotId) {
1308 CatLog.d(LOG_TAG, "launchTextDialog, slotId: " + slotId);
1309 Intent newIntent = new Intent();
1310 String targetActivity = STK_DIALOG_ACTIVITY_NAME;
1311 int action = getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId);
1312 String uriString = STK_DIALOG_URI + System.currentTimeMillis();
1313 //Set unique URI to create a new instance of activity for different slotId.
1314 Uri uriData = Uri.parse(uriString);
1315 if (newIntent != null) {
1316 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1317 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1318 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
1319 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1320 newIntent.setData(uriData);
1321 newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage());
1322 newIntent.putExtra(SLOT_ID, slotId);
1323 startActivity(newIntent);
Preeti Ahuja414bc412013-06-25 19:31:49 -07001324 // For display texts with immediate response, send the terminal response
1325 // immediately. responseNeeded will be false, if display text command has
1326 // the immediate response tlv.
1327 if (!mStkContext[slotId].mCurrentCmd.geTextMessage().responseNeeded) {
1328 sendResponse(RES_ID_CONFIRM, slotId, true);
1329 }
Wink Savillee68857d2014-10-17 15:23:05 -07001330 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001331 }
1332
Wink Savillee68857d2014-10-17 15:23:05 -07001333 public boolean isStkDialogActivated(Context context) {
1334 String stkDialogActivity = "com.android.stk.StkDialogActivity";
1335 boolean activated = false;
1336 final ActivityManager am = (ActivityManager) context.getSystemService(
1337 Context.ACTIVITY_SERVICE);
1338 String topActivity = am.getRunningTasks(1).get(0).topActivity.getClassName();
1339
1340 CatLog.d(LOG_TAG, "isStkDialogActivated: " + topActivity);
1341 if (topActivity.equals(stkDialogActivity)) {
1342 activated = true;
1343 }
1344 CatLog.d(LOG_TAG, "activated : " + activated);
1345 return activated;
Johan Hellman3aec01c2011-02-10 10:15:28 +01001346 }
1347
Preeti Ahuja95919342013-10-01 18:18:55 -07001348 private void sendSetUpEventResponse(int event, byte[] addedInfo, int slotId) {
Preeti Ahuja414bc412013-06-25 19:31:49 -07001349 CatLog.d(this, "sendSetUpEventResponse: event : " + event + "slotId = " + slotId);
Preeti Ahuja95919342013-10-01 18:18:55 -07001350
1351 if (mStkContext[slotId].mCurrentSetupEventCmd == null){
1352 CatLog.e(this, "mCurrentSetupEventCmd is null");
1353 return;
1354 }
1355
1356 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentSetupEventCmd);
1357
1358 resMsg.setResultCode(ResultCode.OK);
1359 resMsg.setEventDownload(event, addedInfo);
1360
1361 mStkService[slotId].onCmdResponse(resMsg);
1362 }
1363
1364 private void checkForSetupEvent(int event, Bundle args, int slotId) {
1365 boolean eventPresent = false;
1366 byte[] addedInfo = null;
1367 CatLog.d(this, "Event :" + event);
1368
1369 if (mStkContext[slotId].mSetupEventListSettings != null) {
1370 /* Checks if the event is present in the EventList updated by last
1371 * SetupEventList Proactive Command */
1372 for (int i : mStkContext[slotId].mSetupEventListSettings.eventList) {
1373 if (event == i) {
1374 eventPresent = true;
1375 break;
1376 }
1377 }
1378
1379 /* If Event is present send the response to ICC */
1380 if (eventPresent == true) {
1381 CatLog.d(this, " Event " + event + "exists in the EventList");
1382
1383 switch (event) {
Preeti Ahuja560be362014-11-25 19:38:24 -08001384 case IDLE_SCREEN_AVAILABLE_EVENT:
1385 sendSetUpEventResponse(event, addedInfo, slotId);
1386 removeSetUpEvent(event, slotId);
1387 break;
Preeti Ahuja95919342013-10-01 18:18:55 -07001388 case LANGUAGE_SELECTION_EVENT:
1389 String language = mContext
1390 .getResources().getConfiguration().locale.getLanguage();
1391 CatLog.d(this, "language: " + language);
1392 // Each language code is a pair of alpha-numeric characters.
1393 // Each alpha-numeric character shall be coded on one byte
1394 // using the SMS default 7-bit coded alphabet
1395 addedInfo = GsmAlphabet.stringToGsm8BitPacked(language);
1396 sendSetUpEventResponse(event, addedInfo, slotId);
1397 break;
1398 default:
1399 break;
1400 }
1401 } else {
1402 CatLog.e(this, " Event does not exist in the EventList");
1403 }
1404 } else {
1405 CatLog.e(this, "SetupEventList is not received. Ignoring the event: " + event);
1406 }
1407 }
1408
1409 private void removeSetUpEvent(int event, int slotId) {
1410 CatLog.d(this, "Remove Event :" + event);
1411
1412 if (mStkContext[slotId].mSetupEventListSettings != null) {
1413 /*
1414 * Make new Eventlist without the event
1415 */
1416 for (int i = 0; i < mStkContext[slotId].mSetupEventListSettings.eventList.length; i++) {
1417 if (event == mStkContext[slotId].mSetupEventListSettings.eventList[i]) {
1418 mStkContext[slotId].mSetupEventListSettings.eventList[i] = INVALID_SETUP_EVENT;
1419 break;
1420 }
1421 }
1422 }
1423 }
1424
1425 private void launchEventMessage(int slotId) {
1426 launchEventMessage(slotId, mStkContext[slotId].mCurrentCmd.geTextMessage());
1427 }
1428
Wink Savillee68857d2014-10-17 15:23:05 -07001429 private void launchEventMessage(int slotId, TextMessage msg) {
1430 if (msg == null || (msg.text != null && msg.text.length() == 0)) {
1431 CatLog.d(LOG_TAG, "launchEventMessage return");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001432 return;
1433 }
Wink Savillee68857d2014-10-17 15:23:05 -07001434
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001435 Toast toast = new Toast(mContext.getApplicationContext());
1436 LayoutInflater inflate = (LayoutInflater) mContext
1437 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
1438 View v = inflate.inflate(R.layout.stk_event_msg, null);
1439 TextView tv = (TextView) v
1440 .findViewById(com.android.internal.R.id.message);
1441 ImageView iv = (ImageView) v
1442 .findViewById(com.android.internal.R.id.icon);
1443 if (msg.icon != null) {
1444 iv.setImageBitmap(msg.icon);
1445 } else {
1446 iv.setVisibility(View.GONE);
1447 }
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301448 /* In case of 'self explanatory' stkapp should display the specified
1449 * icon in proactive command (but not the alpha string).
1450 * If icon is non-self explanatory and if the icon could not be displayed
1451 * then alpha string or text data should be displayed
1452 * Ref: ETSI 102.223,section 6.5.4
1453 */
1454 if (mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ||
1455 msg.icon == null || !msg.iconSelfExplanatory) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001456 tv.setText(msg.text);
1457 }
1458
1459 toast.setView(v);
1460 toast.setDuration(Toast.LENGTH_LONG);
1461 toast.setGravity(Gravity.BOTTOM, 0, 0);
1462 toast.show();
1463 }
1464
Wink Savillee68857d2014-10-17 15:23:05 -07001465 private void launchConfirmationDialog(TextMessage msg, int slotId) {
1466 msg.title = mStkContext[slotId].lastSelectedItem;
1467 Intent newIntent = new Intent();
1468 String targetActivity = STK_DIALOG_ACTIVITY_NAME;
1469 String uriString = STK_DIALOG_URI + System.currentTimeMillis();
1470 //Set unique URI to create a new instance of activity for different slotId.
1471 Uri uriData = Uri.parse(uriString);
1472
1473 if (newIntent != null) {
1474 newIntent.setClassName(this, targetActivity);
1475 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1476 | Intent.FLAG_ACTIVITY_NO_HISTORY
1477 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
1478 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1479 newIntent.putExtra("TEXT", msg);
1480 newIntent.putExtra(SLOT_ID, slotId);
1481 newIntent.setData(uriData);
1482 startActivity(newIntent);
1483 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001484 }
1485
1486 private void launchBrowser(BrowserSettings settings) {
1487 if (settings == null) {
1488 return;
1489 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001490
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001491 Uri data = null;
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001492 String url;
1493 if (settings.url == null) {
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001494 // if the command did not contain a URL,
1495 // launch the browser to the default homepage.
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001496 CatLog.d(this, "no url data provided by proactive command." +
1497 " launching browser with stk default URL ... ");
1498 url = SystemProperties.get(STK_BROWSER_DEFAULT_URL_SYSPROP,
1499 "http://www.google.com");
1500 } else {
1501 CatLog.d(this, "launch browser command has attached url = " + settings.url);
1502 url = settings.url;
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001503 }
David Brown7c03cfe2011-10-20 15:36:12 -07001504
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001505 if (url.startsWith("http://") || url.startsWith("https://")) {
1506 data = Uri.parse(url);
1507 CatLog.d(this, "launching browser with url = " + url);
1508 } else {
1509 String modifiedUrl = "http://" + url;
1510 data = Uri.parse(modifiedUrl);
1511 CatLog.d(this, "launching browser with modified url = " + modifiedUrl);
1512 }
1513
1514 Intent intent = new Intent(Intent.ACTION_VIEW);
1515 intent.setData(data);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001516 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1517 switch (settings.mode) {
1518 case USE_EXISTING_BROWSER:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001519 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1520 break;
1521 case LAUNCH_NEW_BROWSER:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001522 intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
1523 break;
1524 case LAUNCH_IF_NOT_ALREADY_LAUNCHED:
1525 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1526 break;
1527 }
1528 // start browser activity
1529 startActivity(intent);
1530 // a small delay, let the browser start, before processing the next command.
Wink Saville79085fc2009-06-09 10:27:23 -07001531 // this is good for scenarios where a related DISPLAY TEXT command is
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001532 // followed immediately.
1533 try {
Ryuto Sawada350aaa62016-06-13 14:47:22 +09001534 Thread.sleep(3000);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001535 } catch (InterruptedException e) {}
1536 }
1537
Wink Savillee68857d2014-10-17 15:23:05 -07001538 private void launchIdleText(int slotId) {
Preeti Ahuja560be362014-11-25 19:38:24 -08001539 TextMessage msg = mStkContext[slotId].mIdleModeTextCmd.geTextMessage();
dujin.cha2a0eb2a2011-11-11 15:03:57 +09001540
Preeti Ahuja95919342013-10-01 18:18:55 -07001541 if (msg == null || msg.text ==null) {
1542 CatLog.d(LOG_TAG, msg == null ? "mCurrent.getTextMessage is NULL"
1543 : "mCurrent.getTextMessage.text is NULL");
Wink Savillee68857d2014-10-17 15:23:05 -07001544 mNotificationManager.cancel(getNotificationId(slotId));
Wink Saville046db4b2011-11-01 20:42:54 -07001545 return;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001546 } else {
Preeti Ahuja95919342013-10-01 18:18:55 -07001547 CatLog.d(LOG_TAG, "launchIdleText - text[" + msg.text
1548 + "] iconSelfExplanatory[" + msg.iconSelfExplanatory
1549 + "] icon[" + msg.icon + "], sim id: " + slotId);
Wink Savillee68857d2014-10-17 15:23:05 -07001550 CatLog.d(LOG_TAG, "Add IdleMode text");
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001551 PendingIntent pendingIntent = PendingIntent.getService(mContext, 0,
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001552 new Intent(mContext, StkAppService.class), 0);
1553
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001554 final Notification.Builder notificationBuilder = new Notification.Builder(
1555 StkAppService.this);
Wink Savillee68857d2014-10-17 15:23:05 -07001556 if (mStkContext[slotId].mMainCmd != null &&
1557 mStkContext[slotId].mMainCmd.getMenu() != null) {
1558 notificationBuilder.setContentTitle(mStkContext[slotId].mMainCmd.getMenu().title);
Christopher Posselwhite2ad2ab72013-05-27 07:51:06 +02001559 } else {
1560 notificationBuilder.setContentTitle("");
1561 }
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001562 notificationBuilder
1563 .setSmallIcon(com.android.internal.R.drawable.stat_notify_sim_toolkit);
1564 notificationBuilder.setContentIntent(pendingIntent);
1565 notificationBuilder.setOngoing(true);
1566 // Set text and icon for the status bar and notification body.
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301567 if (mStkContext[slotId].mIdleModeTextCmd.hasIconLoadFailed() ||
1568 !msg.iconSelfExplanatory) {
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001569 notificationBuilder.setContentText(msg.text);
Christopher Posselwhite2ad2ab72013-05-27 07:51:06 +02001570 notificationBuilder.setTicker(msg.text);
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001571 }
1572 if (msg.icon != null) {
1573 notificationBuilder.setLargeIcon(msg.icon);
1574 } else {
1575 Bitmap bitmapIcon = BitmapFactory.decodeResource(StkAppService.this
1576 .getResources().getSystem(),
1577 com.android.internal.R.drawable.stat_notify_sim_toolkit);
1578 notificationBuilder.setLargeIcon(bitmapIcon);
1579 }
Selim Cinek62eb3fe2014-08-27 17:52:23 +02001580 notificationBuilder.setColor(mContext.getResources().getColor(
1581 com.android.internal.R.color.system_notification_accent_color));
Wink Savillee68857d2014-10-17 15:23:05 -07001582 mNotificationManager.notify(getNotificationId(slotId), notificationBuilder.build());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001583 }
1584 }
1585
Wink Savillee68857d2014-10-17 15:23:05 -07001586 private void launchToneDialog(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001587 Intent newIntent = new Intent(this, ToneDialog.class);
Wink Savillee68857d2014-10-17 15:23:05 -07001588 String uriString = STK_TONE_URI + slotId;
1589 Uri uriData = Uri.parse(uriString);
1590 //Set unique URI to create a new instance of activity for different slotId.
1591 CatLog.d(LOG_TAG, "launchToneDialog, slotId: " + slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001592 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1593 | Intent.FLAG_ACTIVITY_NO_HISTORY
1594 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
Wink Savillee68857d2014-10-17 15:23:05 -07001595 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1596 newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage());
1597 newIntent.putExtra("TONE", mStkContext[slotId].mCurrentCmd.getToneSettings());
1598 newIntent.putExtra(SLOT_ID, slotId);
1599 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001600 startActivity(newIntent);
1601 }
1602
Takanori Nakano49b12722016-02-16 14:34:14 +09001603 private void launchOpenChannelDialog(final int slotId) {
Wink Savillee68857d2014-10-17 15:23:05 -07001604 TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001605 if (msg == null) {
Wink Savillee68857d2014-10-17 15:23:05 -07001606 CatLog.d(LOG_TAG, "msg is null, return here");
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001607 return;
1608 }
1609
1610 msg.title = getResources().getString(R.string.stk_dialog_title);
1611 if (msg.text == null) {
1612 msg.text = getResources().getString(R.string.default_open_channel_msg);
1613 }
1614
1615 final AlertDialog dialog = new AlertDialog.Builder(mContext)
1616 .setIconAttribute(android.R.attr.alertDialogIcon)
1617 .setTitle(msg.title)
1618 .setMessage(msg.text)
1619 .setCancelable(false)
1620 .setPositiveButton(getResources().getString(R.string.stk_dialog_accept),
1621 new DialogInterface.OnClickListener() {
1622 public void onClick(DialogInterface dialog, int which) {
1623 Bundle args = new Bundle();
1624 args.putInt(RES_ID, RES_ID_CHOICE);
1625 args.putInt(CHOICE, YES);
1626 Message message = mServiceHandler.obtainMessage();
1627 message.arg1 = OP_RESPONSE;
Takanori Nakano49b12722016-02-16 14:34:14 +09001628 message.arg2 = slotId;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001629 message.obj = args;
1630 mServiceHandler.sendMessage(message);
1631 }
1632 })
1633 .setNegativeButton(getResources().getString(R.string.stk_dialog_reject),
1634 new DialogInterface.OnClickListener() {
1635 public void onClick(DialogInterface dialog, int which) {
1636 Bundle args = new Bundle();
1637 args.putInt(RES_ID, RES_ID_CHOICE);
1638 args.putInt(CHOICE, NO);
1639 Message message = mServiceHandler.obtainMessage();
1640 message.arg1 = OP_RESPONSE;
Takanori Nakano49b12722016-02-16 14:34:14 +09001641 message.arg2 = slotId;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001642 message.obj = args;
1643 mServiceHandler.sendMessage(message);
1644 }
1645 })
1646 .create();
1647
1648 dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
1649 if (!mContext.getResources().getBoolean(
1650 com.android.internal.R.bool.config_sf_slowBlur)) {
1651 dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
1652 }
1653
1654 dialog.show();
1655 }
1656
Wink Savillee68857d2014-10-17 15:23:05 -07001657 private void launchTransientEventMessage(int slotId) {
1658 TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001659 if (msg == null) {
Wink Savillee68857d2014-10-17 15:23:05 -07001660 CatLog.d(LOG_TAG, "msg is null, return here");
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001661 return;
1662 }
1663
1664 msg.title = getResources().getString(R.string.stk_dialog_title);
1665
1666 final AlertDialog dialog = new AlertDialog.Builder(mContext)
1667 .setIconAttribute(android.R.attr.alertDialogIcon)
1668 .setTitle(msg.title)
1669 .setMessage(msg.text)
1670 .setCancelable(false)
1671 .setPositiveButton(getResources().getString(android.R.string.ok),
1672 new DialogInterface.OnClickListener() {
1673 public void onClick(DialogInterface dialog, int which) {
1674 }
1675 })
1676 .create();
1677
1678 dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
1679 if (!mContext.getResources().getBoolean(
1680 com.android.internal.R.bool.config_sf_slowBlur)) {
1681 dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
1682 }
1683
1684 dialog.show();
1685 }
1686
Wink Savillee68857d2014-10-17 15:23:05 -07001687 private int getNotificationId(int slotId) {
1688 int notifyId = STK_NOTIFICATION_ID;
1689 if (slotId >= 0 && slotId < mSimCount) {
1690 notifyId += slotId;
1691 } else {
1692 CatLog.d(LOG_TAG, "invalid slotId: " + slotId);
1693 }
1694 CatLog.d(LOG_TAG, "getNotificationId, slotId: " + slotId + ", notifyId: " + notifyId);
1695 return notifyId;
1696 }
1697
1698 private String getItemName(int itemId, int slotId) {
1699 Menu menu = mStkContext[slotId].mCurrentCmd.getMenu();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001700 if (menu == null) {
1701 return null;
1702 }
1703 for (Item item : menu.items) {
1704 if (item.id == itemId) {
1705 return item.text;
1706 }
1707 }
1708 return null;
1709 }
1710
Wink Savillee68857d2014-10-17 15:23:05 -07001711 private boolean removeMenu(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001712 try {
Wink Savillee68857d2014-10-17 15:23:05 -07001713 if (mStkContext[slotId].mCurrentMenu.items.size() == 1 &&
1714 mStkContext[slotId].mCurrentMenu.items.get(0) == null) {
1715 mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001716 return true;
1717 }
1718 } catch (NullPointerException e) {
Wink Savillee68857d2014-10-17 15:23:05 -07001719 CatLog.d(LOG_TAG, "Unable to get Menu's items size");
1720 mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001721 return true;
1722 }
Wink Savillee68857d2014-10-17 15:23:05 -07001723 mStkContext[slotId].mSetupMenuState = STATE_EXIST;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001724 return false;
1725 }
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +05301726
Wink Savillee68857d2014-10-17 15:23:05 -07001727 StkContext getStkContext(int slotId) {
1728 if (slotId >= 0 && slotId < mSimCount) {
1729 return mStkContext[slotId];
1730 } else {
1731 CatLog.d(LOG_TAG, "invalid slotId: " + slotId);
1732 return null;
1733 }
1734 }
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +05301735
1736 private void handleAlphaNotify(Bundle args) {
1737 String alphaString = args.getString(AppInterface.ALPHA_STRING);
1738
1739 CatLog.d(this, "Alpha string received from card: " + alphaString);
1740 Toast toast = Toast.makeText(sInstance, alphaString, Toast.LENGTH_LONG);
1741 toast.setGravity(Gravity.TOP, 0, 0);
1742 toast.show();
1743 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001744}