blob: b017a3e9f9ed3c2c38e204edc800cfa447d0257f [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;
Sooraj Sasindrana4160472016-10-12 16:28:25 -070043import android.os.PersistableBundle;
Preeti Ahuja560be362014-11-25 19:38:24 -080044import android.os.PowerManager;
Preeti Ahujaa7cdca22013-10-01 18:20:56 -070045import android.os.SystemProperties;
Preeti Ahuja95919342013-10-01 18:18:55 -070046import android.provider.Settings;
Sooraj Sasindrana4160472016-10-12 16:28:25 -070047import android.telephony.CarrierConfigManager;
Wink Saville56469d52009-04-02 01:37:03 -070048import android.telephony.TelephonyManager;
Preeti Ahujaa7cdca22013-10-01 18:20:56 -070049import android.text.TextUtils;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080050import android.view.Gravity;
51import android.view.LayoutInflater;
52import android.view.View;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -050053import android.view.Window;
54import android.view.WindowManager;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080055import android.widget.ImageView;
56import android.widget.RemoteViews;
57import android.widget.TextView;
58import android.widget.Toast;
Wink Savillee68857d2014-10-17 15:23:05 -070059import android.content.BroadcastReceiver;
60import android.content.IntentFilter;
61import android.content.pm.ApplicationInfo;
62import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080063
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070064import com.android.internal.telephony.cat.AppInterface;
Preeti Ahuja95919342013-10-01 18:18:55 -070065import com.android.internal.telephony.cat.LaunchBrowserMode;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070066import com.android.internal.telephony.cat.Menu;
67import com.android.internal.telephony.cat.Item;
Pierre Fröjd97503262010-11-08 13:59:36 +010068import com.android.internal.telephony.cat.Input;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070069import com.android.internal.telephony.cat.ResultCode;
70import com.android.internal.telephony.cat.CatCmdMessage;
71import com.android.internal.telephony.cat.CatCmdMessage.BrowserSettings;
Preeti Ahuja95919342013-10-01 18:18:55 -070072import com.android.internal.telephony.cat.CatCmdMessage.SetupEventListSettings;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070073import com.android.internal.telephony.cat.CatLog;
74import com.android.internal.telephony.cat.CatResponseMessage;
75import com.android.internal.telephony.cat.TextMessage;
Wink Saville94e982b2014-07-11 07:38:14 -070076import com.android.internal.telephony.uicc.IccRefreshResponse;
77import com.android.internal.telephony.uicc.IccCardStatus.CardState;
Wink Savillee68857d2014-10-17 15:23:05 -070078import com.android.internal.telephony.PhoneConstants;
79import com.android.internal.telephony.TelephonyIntents;
80import com.android.internal.telephony.IccCardConstants;
81import com.android.internal.telephony.uicc.UiccController;
Preeti Ahuja95919342013-10-01 18:18:55 -070082import com.android.internal.telephony.GsmAlphabet;
Legler Wuaeefef52014-10-27 00:57:18 +080083import com.android.internal.telephony.cat.CatService;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080084
Preeti Ahujaa7cdca22013-10-01 18:20:56 -070085import java.util.Iterator;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080086import java.util.LinkedList;
Wink Savillee68857d2014-10-17 15:23:05 -070087import java.lang.System;
88import java.util.List;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080089
Preeti Ahuja95919342013-10-01 18:18:55 -070090import static com.android.internal.telephony.cat.CatCmdMessage.
Preeti Ahuja560be362014-11-25 19:38:24 -080091 SetupEventListConstants.IDLE_SCREEN_AVAILABLE_EVENT;
92import static com.android.internal.telephony.cat.CatCmdMessage.
Preeti Ahuja95919342013-10-01 18:18:55 -070093 SetupEventListConstants.LANGUAGE_SELECTION_EVENT;
94
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080095/**
96 * SIM toolkit application level service. Interacts with Telephopny messages,
97 * application's launch and user input from STK UI elements.
Wink Saville79085fc2009-06-09 10:27:23 -070098 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080099 */
100public class StkAppService extends Service implements Runnable {
101
102 // members
Wink Savillee68857d2014-10-17 15:23:05 -0700103 protected class StkContext {
104 protected CatCmdMessage mMainCmd = null;
105 protected CatCmdMessage mCurrentCmd = null;
106 protected CatCmdMessage mCurrentMenuCmd = null;
107 protected Menu mCurrentMenu = null;
108 protected String lastSelectedItem = null;
109 protected boolean mMenuIsVisible = false;
110 protected boolean mIsInputPending = false;
111 protected boolean mIsMenuPending = false;
112 protected boolean mIsDialogPending = false;
113 protected boolean responseNeeded = true;
114 protected boolean launchBrowser = false;
115 protected BrowserSettings mBrowserSettings = null;
116 protected LinkedList<DelayedCmd> mCmdsQ = null;
117 protected boolean mCmdInProgress = false;
118 protected int mStkServiceState = STATE_UNKNOWN;
119 protected int mSetupMenuState = STATE_UNKNOWN;
120 protected int mMenuState = StkMenuActivity.STATE_INIT;
121 protected int mOpCode = -1;
122 private Activity mActivityInstance = null;
123 private Activity mDialogInstance = null;
124 private Activity mMainActivityInstance = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700125 private int mSlotId = 0;
Preeti Ahuja95919342013-10-01 18:18:55 -0700126 private SetupEventListSettings mSetupEventListSettings = null;
127 private boolean mClearSelectItem = false;
128 private boolean mDisplayTextDlgIsVisibile = false;
129 private CatCmdMessage mCurrentSetupEventCmd = null;
Preeti Ahuja560be362014-11-25 19:38:24 -0800130 private CatCmdMessage mIdleModeTextCmd = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700131 final synchronized void setPendingActivityInstance(Activity act) {
132 CatLog.d(this, "setPendingActivityInstance act : " + mSlotId + ", " + act);
133 callSetActivityInstMsg(OP_SET_ACT_INST, mSlotId, act);
134 }
135 final synchronized Activity getPendingActivityInstance() {
136 CatLog.d(this, "getPendingActivityInstance act : " + mSlotId + ", " +
137 mActivityInstance);
138 return mActivityInstance;
139 }
140 final synchronized void setPendingDialogInstance(Activity act) {
141 CatLog.d(this, "setPendingDialogInstance act : " + mSlotId + ", " + act);
142 callSetActivityInstMsg(OP_SET_DAL_INST, mSlotId, act);
143 }
144 final synchronized Activity getPendingDialogInstance() {
145 CatLog.d(this, "getPendingDialogInstance act : " + mSlotId + ", " +
146 mDialogInstance);
147 return mDialogInstance;
148 }
149 final synchronized void setMainActivityInstance(Activity act) {
150 CatLog.d(this, "setMainActivityInstance act : " + mSlotId + ", " + act);
151 callSetActivityInstMsg(OP_SET_MAINACT_INST, mSlotId, act);
152 }
153 final synchronized Activity getMainActivityInstance() {
154 CatLog.d(this, "getMainActivityInstance act : " + mSlotId + ", " +
155 mMainActivityInstance);
156 return mMainActivityInstance;
157 }
158 }
159
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800160 private volatile Looper mServiceLooper;
161 private volatile ServiceHandler mServiceHandler;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800162 private Context mContext = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800163 private NotificationManager mNotificationManager = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800164 static StkAppService sInstance = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700165 private AppInterface[] mStkService = null;
166 private StkContext[] mStkContext = null;
167 private int mSimCount = 0;
Preeti Ahuja560be362014-11-25 19:38:24 -0800168 private PowerManager mPowerManager = null;
169 private StkCmdReceiver mStkCmdReceiver = null;
Preeti Ahuja95919342013-10-01 18:18:55 -0700170
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800171 // Used for setting FLAG_ACTIVITY_NO_USER_ACTION when
172 // creating an intent.
173 private enum InitiatedByUserAction {
174 yes, // The action was started via a user initiated action
175 unknown, // Not known for sure if user initated the action
176 }
177
178 // constants
179 static final String OPCODE = "op";
180 static final String CMD_MSG = "cmd message";
181 static final String RES_ID = "response id";
182 static final String MENU_SELECTION = "menu selection";
183 static final String INPUT = "input";
184 static final String HELP = "help";
185 static final String CONFIRMATION = "confirm";
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500186 static final String CHOICE = "choice";
Wink Savillee68857d2014-10-17 15:23:05 -0700187 static final String SLOT_ID = "SLOT_ID";
188 static final String STK_CMD = "STK CMD";
189 static final String STK_DIALOG_URI = "stk://com.android.stk/dialog/";
190 static final String STK_MENU_URI = "stk://com.android.stk/menu/";
191 static final String STK_INPUT_URI = "stk://com.android.stk/input/";
192 static final String STK_TONE_URI = "stk://com.android.stk/tone/";
Preeti Ahuja95919342013-10-01 18:18:55 -0700193
194 // These below constants are used for SETUP_EVENT_LIST
195 static final String SETUP_EVENT_TYPE = "event";
196 static final String SETUP_EVENT_CAUSE = "cause";
197
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800198 // operations ids for different service functionality.
199 static final int OP_CMD = 1;
200 static final int OP_RESPONSE = 2;
201 static final int OP_LAUNCH_APP = 3;
202 static final int OP_END_SESSION = 4;
203 static final int OP_BOOT_COMPLETED = 5;
204 private static final int OP_DELAYED_MSG = 6;
Wink Saville94e982b2014-07-11 07:38:14 -0700205 static final int OP_CARD_STATUS_CHANGED = 7;
Wink Savillee68857d2014-10-17 15:23:05 -0700206 static final int OP_SET_ACT_INST = 8;
207 static final int OP_SET_DAL_INST = 9;
208 static final int OP_SET_MAINACT_INST = 10;
Preeti Ahujab3d0e612014-11-20 13:29:25 -0800209 static final int OP_LOCALE_CHANGED = 11;
210 static final int OP_ALPHA_NOTIFY = 12;
Preeti Ahuja560be362014-11-25 19:38:24 -0800211 static final int OP_IDLE_SCREEN = 13;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800212
Preeti Ahuja95919342013-10-01 18:18:55 -0700213 //Invalid SetupEvent
214 static final int INVALID_SETUP_EVENT = 0xFF;
215
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800216 // Response ids
217 static final int RES_ID_MENU_SELECTION = 11;
218 static final int RES_ID_INPUT = 12;
219 static final int RES_ID_CONFIRM = 13;
220 static final int RES_ID_DONE = 14;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500221 static final int RES_ID_CHOICE = 15;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800222
223 static final int RES_ID_TIMEOUT = 20;
224 static final int RES_ID_BACKWARD = 21;
225 static final int RES_ID_END_SESSION = 22;
226 static final int RES_ID_EXIT = 23;
227
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500228 static final int YES = 1;
229 static final int NO = 0;
230
Wink Savillee68857d2014-10-17 15:23:05 -0700231 static final int STATE_UNKNOWN = -1;
232 static final int STATE_NOT_EXIST = 0;
233 static final int STATE_EXIST = 1;
Wink Saville79085fc2009-06-09 10:27:23 -0700234
Wink Savillee68857d2014-10-17 15:23:05 -0700235 private static final String PACKAGE_NAME = "com.android.stk";
236 private static final String STK_MENU_ACTIVITY_NAME = PACKAGE_NAME + ".StkMenuActivity";
237 private static final String STK_INPUT_ACTIVITY_NAME = PACKAGE_NAME + ".StkInputActivity";
238 private static final String STK_DIALOG_ACTIVITY_NAME = PACKAGE_NAME + ".StkDialogActivity";
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800239 // Notification id used to display Idle Mode text in NotificationManager.
240 private static final int STK_NOTIFICATION_ID = 333;
Wink Savillee68857d2014-10-17 15:23:05 -0700241 private static final String LOG_TAG = new Object(){}.getClass().getEnclosingClass().getName();
Wink Saville79085fc2009-06-09 10:27:23 -0700242
243 // Inner class used for queuing telephony messages (proactive commands,
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800244 // session end) while the service is busy processing a previous message.
245 private class DelayedCmd {
246 // members
247 int id;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -0700248 CatCmdMessage msg;
Wink Savillee68857d2014-10-17 15:23:05 -0700249 int slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800250
Wink Savillee68857d2014-10-17 15:23:05 -0700251 DelayedCmd(int id, CatCmdMessage msg, int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800252 this.id = id;
253 this.msg = msg;
Wink Savillee68857d2014-10-17 15:23:05 -0700254 this.slotId = slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800255 }
256 }
257
Preeti Ahujaa7cdca22013-10-01 18:20:56 -0700258 // system property to set the STK specific default url for launch browser proactive cmds
259 private static final String STK_BROWSER_DEFAULT_URL_SYSPROP = "persist.radio.stk.default_url";
260
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800261 @Override
262 public void onCreate() {
Wink Savillee68857d2014-10-17 15:23:05 -0700263 CatLog.d(LOG_TAG, "onCreate()+");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800264 // Initialize members
Wink Savillee68857d2014-10-17 15:23:05 -0700265 int i = 0;
266 mContext = getBaseContext();
267 mSimCount = TelephonyManager.from(mContext).getSimCount();
268 CatLog.d(LOG_TAG, "simCount: " + mSimCount);
269 mStkService = new AppInterface[mSimCount];
270 mStkContext = new StkContext[mSimCount];
Preeti Ahuja560be362014-11-25 19:38:24 -0800271 mPowerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
272 mStkCmdReceiver = new StkCmdReceiver();
273 registerReceiver(mStkCmdReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
Wink Savillee68857d2014-10-17 15:23:05 -0700274 for (i = 0; i < mSimCount; i++) {
275 CatLog.d(LOG_TAG, "slotId: " + i);
Legler Wuaeefef52014-10-27 00:57:18 +0800276 mStkService[i] = CatService.getInstance(i);
Wink Savillee68857d2014-10-17 15:23:05 -0700277 mStkContext[i] = new StkContext();
278 mStkContext[i].mSlotId = i;
279 mStkContext[i].mCmdsQ = new LinkedList<DelayedCmd>();
280 }
281
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800282 Thread serviceThread = new Thread(null, this, "Stk App Service");
283 serviceThread.start();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800284 mNotificationManager = (NotificationManager) mContext
285 .getSystemService(Context.NOTIFICATION_SERVICE);
286 sInstance = this;
287 }
288
289 @Override
290 public void onStart(Intent intent, int startId) {
Wink Savillee68857d2014-10-17 15:23:05 -0700291 if (intent == null) {
292 CatLog.d(LOG_TAG, "StkAppService onStart intent is null so return");
Banavathu, Srinivas Naik87cda962012-07-17 15:32:44 +0530293 return;
294 }
295
Wink Savillee68857d2014-10-17 15:23:05 -0700296 Bundle args = intent.getExtras();
297 if (args == null) {
298 CatLog.d(LOG_TAG, "StkAppService onStart args is null so return");
299 return;
300 }
301
302 int op = args.getInt(OPCODE);
303 int slotId = 0;
304 int i = 0;
305 if (op != OP_BOOT_COMPLETED) {
306 slotId = args.getInt(SLOT_ID);
307 }
Cuihtlauac ALVARADObde7f032015-05-29 16:25:12 +0200308 CatLog.d(LOG_TAG, "onStart sim id: " + slotId + ", op: " + op + ", *****");
Wink Savillee68857d2014-10-17 15:23:05 -0700309 if ((slotId >= 0 && slotId < mSimCount) && mStkService[slotId] == null) {
Legler Wuaeefef52014-10-27 00:57:18 +0800310 mStkService[slotId] = CatService.getInstance(slotId);
Wink Savillee68857d2014-10-17 15:23:05 -0700311 if (mStkService[slotId] == null) {
312 CatLog.d(LOG_TAG, "mStkService is: " + mStkContext[slotId].mStkServiceState);
313 mStkContext[slotId].mStkServiceState = STATE_NOT_EXIST;
314 //Check other StkService state.
315 //If all StkServices are not available, stop itself and uninstall apk.
316 for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) {
317 if (i != slotId
Tsukasa Goto029332b2016-10-05 17:12:06 +0900318 && (mStkService[i] != null)
Wink Savillee68857d2014-10-17 15:23:05 -0700319 && (mStkContext[i].mStkServiceState == STATE_UNKNOWN
320 || mStkContext[i].mStkServiceState == STATE_EXIST)) {
321 break;
322 }
323 }
324 } else {
325 mStkContext[slotId].mStkServiceState = STATE_EXIST;
326 }
327 if (i == mSimCount) {
328 stopSelf();
329 StkAppInstaller.unInstall(mContext);
330 return;
331 }
332 }
333
Banavathu, Srinivas Naik87cda962012-07-17 15:32:44 +0530334 waitForLooper();
John Wang62acae42009-10-08 11:20:23 -0700335
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800336 Message msg = mServiceHandler.obtainMessage();
Wink Savillee68857d2014-10-17 15:23:05 -0700337 msg.arg1 = op;
338 msg.arg2 = slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800339 switch(msg.arg1) {
340 case OP_CMD:
341 msg.obj = args.getParcelable(CMD_MSG);
342 break;
343 case OP_RESPONSE:
Wink Saville94e982b2014-07-11 07:38:14 -0700344 case OP_CARD_STATUS_CHANGED:
Preeti Ahuja95919342013-10-01 18:18:55 -0700345 case OP_LOCALE_CHANGED:
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +0530346 case OP_ALPHA_NOTIFY:
Preeti Ahuja560be362014-11-25 19:38:24 -0800347 case OP_IDLE_SCREEN:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800348 msg.obj = args;
349 /* falls through */
350 case OP_LAUNCH_APP:
351 case OP_END_SESSION:
352 case OP_BOOT_COMPLETED:
353 break;
354 default:
355 return;
356 }
357 mServiceHandler.sendMessage(msg);
358 }
359
360 @Override
361 public void onDestroy() {
Wink Savillee68857d2014-10-17 15:23:05 -0700362 CatLog.d(LOG_TAG, "onDestroy()");
Preeti Ahuja560be362014-11-25 19:38:24 -0800363 if (mStkCmdReceiver != null) {
364 unregisterReceiver(mStkCmdReceiver);
365 mStkCmdReceiver = null;
366 }
367 mPowerManager = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800368 waitForLooper();
369 mServiceLooper.quit();
370 }
371
372 @Override
373 public IBinder onBind(Intent intent) {
374 return null;
375 }
376
377 public void run() {
378 Looper.prepare();
379
380 mServiceLooper = Looper.myLooper();
381 mServiceHandler = new ServiceHandler();
382
383 Looper.loop();
384 }
385
386 /*
387 * Package api used by StkMenuActivity to indicate if its on the foreground.
388 */
Wink Savillee68857d2014-10-17 15:23:05 -0700389 void indicateMenuVisibility(boolean visibility, int slotId) {
390 if (slotId >= 0 && slotId < mSimCount) {
391 mStkContext[slotId].mMenuIsVisible = visibility;
392 }
393 }
394
Preeti Ahuja95919342013-10-01 18:18:55 -0700395 /*
396 * Package api used by StkDialogActivity to indicate if its on the foreground.
397 */
398 void setDisplayTextDlgVisibility(boolean visibility, int slotId) {
399 if (slotId >= 0 && slotId < mSimCount) {
400 mStkContext[slotId].mDisplayTextDlgIsVisibile = visibility;
401 }
402 }
403
Wink Savillee68857d2014-10-17 15:23:05 -0700404 boolean isInputPending(int slotId) {
405 if (slotId >= 0 && slotId < mSimCount) {
406 CatLog.d(LOG_TAG, "isInputFinishBySrv: " + mStkContext[slotId].mIsInputPending);
407 return mStkContext[slotId].mIsInputPending;
408 }
409 return false;
410 }
411
412 boolean isMenuPending(int slotId) {
413 if (slotId >= 0 && slotId < mSimCount) {
414 CatLog.d(LOG_TAG, "isMenuPending: " + mStkContext[slotId].mIsMenuPending);
415 return mStkContext[slotId].mIsMenuPending;
416 }
417 return false;
418 }
419
420 boolean isDialogPending(int slotId) {
421 if (slotId >= 0 && slotId < mSimCount) {
422 CatLog.d(LOG_TAG, "isDialogPending: " + mStkContext[slotId].mIsDialogPending);
423 return mStkContext[slotId].mIsDialogPending;
424 }
425 return false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800426 }
427
428 /*
429 * Package api used by StkMenuActivity to get its Menu parameter.
430 */
Wink Savillee68857d2014-10-17 15:23:05 -0700431 Menu getMenu(int slotId) {
432 CatLog.d(LOG_TAG, "StkAppService, getMenu, sim id: " + slotId);
433 if (slotId >=0 && slotId < mSimCount) {
434 return mStkContext[slotId].mCurrentMenu;
435 } else {
436 return null;
437 }
438 }
439
440 /*
441 * Package api used by StkMenuActivity to get its Main Menu parameter.
442 */
443 Menu getMainMenu(int slotId) {
444 CatLog.d(LOG_TAG, "StkAppService, getMainMenu, sim id: " + slotId);
w30234a08cffe2015-02-04 15:13:25 -0800445 if (slotId >=0 && slotId < mSimCount && (mStkContext[slotId].mMainCmd != null)) {
Wink Savillee68857d2014-10-17 15:23:05 -0700446 return mStkContext[slotId].mMainCmd.getMenu();
447 } else {
448 return null;
449 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800450 }
451
452 /*
453 * Package api used by UI Activities and Dialogs to communicate directly
454 * with the service to deliver state information and parameters.
455 */
456 static StkAppService getInstance() {
457 return sInstance;
458 }
459
460 private void waitForLooper() {
461 while (mServiceHandler == null) {
462 synchronized (this) {
463 try {
464 wait(100);
465 } catch (InterruptedException e) {
466 }
467 }
468 }
469 }
470
471 private final class ServiceHandler extends Handler {
472 @Override
473 public void handleMessage(Message msg) {
Wink Savillee68857d2014-10-17 15:23:05 -0700474 if(null == msg) {
475 CatLog.d(LOG_TAG, "ServiceHandler handleMessage msg is null");
476 return;
477 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800478 int opcode = msg.arg1;
Wink Savillee68857d2014-10-17 15:23:05 -0700479 int slotId = msg.arg2;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800480
Wink Savillee68857d2014-10-17 15:23:05 -0700481 CatLog.d(LOG_TAG, "handleMessage opcode[" + opcode + "], sim id[" + slotId + "]");
482 if (opcode == OP_CMD && msg.obj != null &&
483 ((CatCmdMessage)msg.obj).getCmdType()!= null) {
484 CatLog.d(LOG_TAG, "cmdName[" + ((CatCmdMessage)msg.obj).getCmdType().name() + "]");
485 }
486 mStkContext[slotId].mOpCode = opcode;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800487 switch (opcode) {
488 case OP_LAUNCH_APP:
Wink Savillee68857d2014-10-17 15:23:05 -0700489 if (mStkContext[slotId].mMainCmd == null) {
490 CatLog.d(LOG_TAG, "mMainCmd is null");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800491 // nothing todo when no SET UP MENU command didn't arrive.
492 return;
493 }
Wink Savillee68857d2014-10-17 15:23:05 -0700494 CatLog.d(LOG_TAG, "handleMessage OP_LAUNCH_APP - mCmdInProgress[" +
495 mStkContext[slotId].mCmdInProgress + "]");
496
497 //If there is a pending activity for the slot id,
498 //just finish it and create a new one to handle the pending command.
499 cleanUpInstanceStackBySlot(slotId);
500
Wink Savillee68857d2014-10-17 15:23:05 -0700501 CatLog.d(LOG_TAG, "Current cmd type: " +
502 mStkContext[slotId].mCurrentCmd.getCmdType());
503 //Restore the last command from stack by slot id.
504 restoreInstanceFromStackBySlot(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800505 break;
506 case OP_CMD:
Wink Savillee68857d2014-10-17 15:23:05 -0700507 CatLog.d(LOG_TAG, "[OP_CMD]");
Alex Yakavenkad41f1d92010-07-12 14:13:13 -0700508 CatCmdMessage cmdMsg = (CatCmdMessage) msg.obj;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800509 // There are two types of commands:
510 // 1. Interactive - user's response is required.
511 // 2. Informative - display a message, no interaction with the user.
512 //
Wink Saville79085fc2009-06-09 10:27:23 -0700513 // Informative commands can be handled immediately without any delay.
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800514 // Interactive commands can't override each other. So if a command
515 // is already in progress, we need to queue the next command until
516 // the user has responded or a timeout expired.
517 if (!isCmdInteractive(cmdMsg)) {
Wink Savillee68857d2014-10-17 15:23:05 -0700518 handleCmd(cmdMsg, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800519 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700520 if (!mStkContext[slotId].mCmdInProgress) {
521 mStkContext[slotId].mCmdInProgress = true;
522 handleCmd((CatCmdMessage) msg.obj, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800523 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700524 CatLog.d(LOG_TAG, "[Interactive][in progress]");
525 mStkContext[slotId].mCmdsQ.addLast(new DelayedCmd(OP_CMD,
526 (CatCmdMessage) msg.obj, slotId));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800527 }
528 }
529 break;
530 case OP_RESPONSE:
Preeti Ahuja414bc412013-06-25 19:31:49 -0700531 handleCmdResponse((Bundle) msg.obj, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800532 // call delayed commands if needed.
Wink Savillee68857d2014-10-17 15:23:05 -0700533 if (mStkContext[slotId].mCmdsQ.size() != 0) {
534 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800535 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700536 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800537 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800538 break;
539 case OP_END_SESSION:
Wink Savillee68857d2014-10-17 15:23:05 -0700540 if (!mStkContext[slotId].mCmdInProgress) {
541 mStkContext[slotId].mCmdInProgress = true;
542 handleSessionEnd(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800543 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700544 mStkContext[slotId].mCmdsQ.addLast(
545 new DelayedCmd(OP_END_SESSION, null, slotId));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800546 }
547 break;
548 case OP_BOOT_COMPLETED:
Wink Savillee68857d2014-10-17 15:23:05 -0700549 CatLog.d(LOG_TAG, " OP_BOOT_COMPLETED");
550 int i = 0;
551 for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) {
552 if (mStkContext[i].mMainCmd != null) {
553 break;
554 }
555 }
556 if (i == mSimCount) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800557 StkAppInstaller.unInstall(mContext);
558 }
559 break;
560 case OP_DELAYED_MSG:
Wink Savillee68857d2014-10-17 15:23:05 -0700561 handleDelayedCmd(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800562 break;
Wink Saville94e982b2014-07-11 07:38:14 -0700563 case OP_CARD_STATUS_CHANGED:
Wink Savillee68857d2014-10-17 15:23:05 -0700564 CatLog.d(LOG_TAG, "Card/Icc Status change received");
565 handleCardStatusChangeAndIccRefresh((Bundle) msg.obj, slotId);
566 break;
567 case OP_SET_ACT_INST:
568 Activity act = new Activity();
569 act = (Activity) msg.obj;
570 CatLog.d(LOG_TAG, "Set activity instance. " + act);
571 mStkContext[slotId].mActivityInstance = act;
572 break;
573 case OP_SET_DAL_INST:
574 Activity dal = new Activity();
575 CatLog.d(LOG_TAG, "Set dialog instance. " + dal);
576 dal = (Activity) msg.obj;
577 mStkContext[slotId].mDialogInstance = dal;
578 break;
579 case OP_SET_MAINACT_INST:
580 Activity mainAct = new Activity();
581 mainAct = (Activity) msg.obj;
582 CatLog.d(LOG_TAG, "Set activity instance. " + mainAct);
583 mStkContext[slotId].mMainActivityInstance = mainAct;
Wink Saville94e982b2014-07-11 07:38:14 -0700584 break;
Preeti Ahuja95919342013-10-01 18:18:55 -0700585 case OP_LOCALE_CHANGED:
586 CatLog.d(this, "Locale Changed");
Yuta Ui1481b172016-02-03 15:34:31 +0900587 for (int slot = PhoneConstants.SIM_ID_1; slot < mSimCount; slot++) {
588 checkForSetupEvent(LANGUAGE_SELECTION_EVENT, (Bundle) msg.obj, slot);
589 }
Preeti Ahuja95919342013-10-01 18:18:55 -0700590 break;
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +0530591 case OP_ALPHA_NOTIFY:
592 handleAlphaNotify((Bundle) msg.obj);
593 break;
Preeti Ahuja560be362014-11-25 19:38:24 -0800594 case OP_IDLE_SCREEN:
595 for (int slot = 0; slot < mSimCount; slot++) {
596 if (mStkContext[slot] != null) {
597 handleIdleScreen(slot);
598 }
599 }
600 break;
Wink Saville94e982b2014-07-11 07:38:14 -0700601 }
602 }
603
Wink Savillee68857d2014-10-17 15:23:05 -0700604 private void handleCardStatusChangeAndIccRefresh(Bundle args, int slotId) {
Wink Saville94e982b2014-07-11 07:38:14 -0700605 boolean cardStatus = args.getBoolean(AppInterface.CARD_STATUS);
606
Wink Savillee68857d2014-10-17 15:23:05 -0700607 CatLog.d(LOG_TAG, "CardStatus: " + cardStatus);
Wink Saville94e982b2014-07-11 07:38:14 -0700608 if (cardStatus == false) {
Wink Savillee68857d2014-10-17 15:23:05 -0700609 CatLog.d(LOG_TAG, "CARD is ABSENT");
Wink Saville94e982b2014-07-11 07:38:14 -0700610 // Uninstall STKAPP, Clear Idle text, Stop StkAppService
Wink Savillee68857d2014-10-17 15:23:05 -0700611 mNotificationManager.cancel(getNotificationId(slotId));
612 if (isAllOtherCardsAbsent(slotId)) {
613 CatLog.d(LOG_TAG, "All CARDs are ABSENT");
614 StkAppInstaller.unInstall(mContext);
615 stopSelf();
616 }
Wink Saville94e982b2014-07-11 07:38:14 -0700617 } else {
618 IccRefreshResponse state = new IccRefreshResponse();
619 state.refreshResult = args.getInt(AppInterface.REFRESH_RESULT);
620
Wink Savillee68857d2014-10-17 15:23:05 -0700621 CatLog.d(LOG_TAG, "Icc Refresh Result: "+ state.refreshResult);
Wink Saville94e982b2014-07-11 07:38:14 -0700622 if ((state.refreshResult == IccRefreshResponse.REFRESH_RESULT_INIT) ||
623 (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET)) {
624 // Clear Idle Text
Wink Savillee68857d2014-10-17 15:23:05 -0700625 mNotificationManager.cancel(getNotificationId(slotId));
Wink Saville94e982b2014-07-11 07:38:14 -0700626 }
627
628 if (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET) {
629 // Uninstall STkmenu
Wink Savillee68857d2014-10-17 15:23:05 -0700630 if (isAllOtherCardsAbsent(slotId)) {
631 StkAppInstaller.unInstall(mContext);
632 }
633 mStkContext[slotId].mCurrentMenu = null;
634 mStkContext[slotId].mMainCmd = null;
Wink Saville94e982b2014-07-11 07:38:14 -0700635 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800636 }
637 }
638 }
Wink Savillee68857d2014-10-17 15:23:05 -0700639 /*
640 * Check if all SIMs are absent except the id of slot equals "slotId".
641 */
642 private boolean isAllOtherCardsAbsent(int slotId) {
643 TelephonyManager mTm = (TelephonyManager) mContext.getSystemService(
644 Context.TELEPHONY_SERVICE);
645 int i = 0;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800646
Wink Savillee68857d2014-10-17 15:23:05 -0700647 for (i = 0; i < mSimCount; i++) {
648 if (i != slotId && mTm.hasIccCard(i)) {
649 break;
650 }
651 }
652 if (i == mSimCount) {
653 return true;
654 } else {
655 return false;
656 }
657 }
Preeti Ahuja95919342013-10-01 18:18:55 -0700658
Preeti Ahuja560be362014-11-25 19:38:24 -0800659 /*
660 * If the device is not in an interactive state, we can assume
661 * that the screen is idle.
662 */
663 private boolean isScreenIdle() {
664 return (!mPowerManager.isInteractive());
665 }
666
667 private void handleIdleScreen(int slotId) {
668
669 // If the idle screen event is present in the list need to send the
670 // response to SIM.
671 CatLog.d(this, "Need to send IDLE SCREEN Available event to SIM");
672 checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId);
673
674 if (mStkContext[slotId].mIdleModeTextCmd != null) {
675 launchIdleText(slotId);
676 }
677 }
678
679 private void sendScreenBusyResponse(int slotId) {
680 if (mStkContext[slotId].mCurrentCmd == null) {
681 return;
682 }
683 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd);
684 CatLog.d(this, "SCREEN_BUSY");
685 resMsg.setResultCode(ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS);
686 mStkService[slotId].onCmdResponse(resMsg);
687 if (mStkContext[slotId].mCmdsQ.size() != 0) {
688 callDelayedMsg(slotId);
689 } else {
690 mStkContext[slotId].mCmdInProgress = false;
691 }
692 }
693
Preeti Ahuja95919342013-10-01 18:18:55 -0700694 private void sendResponse(int resId, int slotId, boolean confirm) {
695 Message msg = mServiceHandler.obtainMessage();
696 msg.arg1 = OP_RESPONSE;
Takanori Nakano49b12722016-02-16 14:34:14 +0900697 msg.arg2 = slotId;
Preeti Ahuja95919342013-10-01 18:18:55 -0700698 Bundle args = new Bundle();
699 args.putInt(StkAppService.RES_ID, resId);
Preeti Ahuja95919342013-10-01 18:18:55 -0700700 args.putBoolean(StkAppService.CONFIRMATION, confirm);
701 msg.obj = args;
702 mServiceHandler.sendMessage(msg);
703 }
704
Alex Yakavenkad41f1d92010-07-12 14:13:13 -0700705 private boolean isCmdInteractive(CatCmdMessage cmd) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800706 switch (cmd.getCmdType()) {
707 case SEND_DTMF:
708 case SEND_SMS:
709 case SEND_SS:
710 case SEND_USSD:
711 case SET_UP_IDLE_MODE_TEXT:
712 case SET_UP_MENU:
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500713 case CLOSE_CHANNEL:
714 case RECEIVE_DATA:
715 case SEND_DATA:
Preeti Ahuja95919342013-10-01 18:18:55 -0700716 case SET_UP_EVENT_LIST:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800717 return false;
718 }
719
720 return true;
721 }
722
Wink Savillee68857d2014-10-17 15:23:05 -0700723 private void handleDelayedCmd(int slotId) {
724 CatLog.d(LOG_TAG, "handleDelayedCmd, slotId: " + slotId);
725 if (mStkContext[slotId].mCmdsQ.size() != 0) {
726 DelayedCmd cmd = mStkContext[slotId].mCmdsQ.poll();
727 if (cmd != null) {
728 CatLog.d(LOG_TAG, "handleDelayedCmd - queue size: " +
729 mStkContext[slotId].mCmdsQ.size() +
730 " id: " + cmd.id + "sim id: " + cmd.slotId);
731 switch (cmd.id) {
732 case OP_CMD:
733 handleCmd(cmd.msg, cmd.slotId);
734 break;
735 case OP_END_SESSION:
736 handleSessionEnd(cmd.slotId);
737 break;
738 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800739 }
740 }
741 }
742
Wink Savillee68857d2014-10-17 15:23:05 -0700743 private void callDelayedMsg(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800744 Message msg = mServiceHandler.obtainMessage();
745 msg.arg1 = OP_DELAYED_MSG;
Wink Savillee68857d2014-10-17 15:23:05 -0700746 msg.arg2 = slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800747 mServiceHandler.sendMessage(msg);
748 }
749
Wink Savillee68857d2014-10-17 15:23:05 -0700750 private void callSetActivityInstMsg(int inst_type, int slotId, Object obj) {
751 Message msg = mServiceHandler.obtainMessage();
752 msg.obj = obj;
753 msg.arg1 = inst_type;
754 msg.arg2 = slotId;
755 mServiceHandler.sendMessage(msg);
756 }
757
758 private void handleSessionEnd(int slotId) {
Legler Wuaeefef52014-10-27 00:57:18 +0800759 // We should finish all pending activity if receiving END SESSION command.
760 cleanUpInstanceStackBySlot(slotId);
761
Wink Savillee68857d2014-10-17 15:23:05 -0700762 mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
763 CatLog.d(LOG_TAG, "[handleSessionEnd] - mCurrentCmd changed to mMainCmd!.");
764 mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mMainCmd;
765 CatLog.d(LOG_TAG, "slotId: " + slotId + ", mMenuState: " +
766 mStkContext[slotId].mMenuState);
767
768 mStkContext[slotId].mIsInputPending = false;
769 mStkContext[slotId].mIsMenuPending = false;
770 mStkContext[slotId].mIsDialogPending = false;
771
Wink Savillee68857d2014-10-17 15:23:05 -0700772 if (mStkContext[slotId].mMainCmd == null) {
773 CatLog.d(LOG_TAG, "[handleSessionEnd][mMainCmd is null!]");
774 }
775 mStkContext[slotId].lastSelectedItem = null;
Wink Saville79085fc2009-06-09 10:27:23 -0700776 // In case of SET UP MENU command which removed the app, don't
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800777 // update the current menu member.
Wink Savillee68857d2014-10-17 15:23:05 -0700778 if (mStkContext[slotId].mCurrentMenu != null && mStkContext[slotId].mMainCmd != null) {
779 mStkContext[slotId].mCurrentMenu = mStkContext[slotId].mMainCmd.getMenu();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800780 }
Wink Savillee68857d2014-10-17 15:23:05 -0700781 CatLog.d(LOG_TAG, "[handleSessionEnd][mMenuState]" + mStkContext[slotId].mMenuIsVisible);
782 // In mutiple instance architecture, the main menu for slotId will be finished when user
783 // goes to the Stk menu of the other SIM. So, we should launch a new instance for the
784 // main menu if the main menu instance has been finished.
785 // If the current menu is secondary menu, we should launch main menu.
786 if (StkMenuActivity.STATE_SECONDARY == mStkContext[slotId].mMenuState) {
787 launchMenuActivity(null, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800788 }
Wink Savillee68857d2014-10-17 15:23:05 -0700789 if (mStkContext[slotId].mCmdsQ.size() != 0) {
790 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800791 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700792 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800793 }
794 // In case a launch browser command was just confirmed, launch that url.
Wink Savillee68857d2014-10-17 15:23:05 -0700795 if (mStkContext[slotId].launchBrowser) {
796 mStkContext[slotId].launchBrowser = false;
797 launchBrowser(mStkContext[slotId].mBrowserSettings);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800798 }
799 }
800
Preeti Ahuja560be362014-11-25 19:38:24 -0800801 // returns true if any Stk related activity already has focus on the screen
802 private boolean isTopOfStack() {
803 ActivityManager mAcivityManager = (ActivityManager) mContext
804 .getSystemService(ACTIVITY_SERVICE);
805 String currentPackageName = mAcivityManager.getRunningTasks(1).get(0).topActivity
806 .getPackageName();
807 if (null != currentPackageName) {
808 return currentPackageName.equals(PACKAGE_NAME);
809 }
810
811 return false;
812 }
813
Sooraj Sasindrana4160472016-10-12 16:28:25 -0700814 /**
815 * Get the boolean config from carrier config manager.
816 *
817 * @param context the context to get carrier service
818 * @param key config key defined in CarrierConfigManager
819 * @return boolean value of corresponding key.
820 */
821 private static boolean getBooleanCarrierConfig(Context context, String key) {
822 CarrierConfigManager configManager = (CarrierConfigManager) context.getSystemService(
823 Context.CARRIER_CONFIG_SERVICE);
824 PersistableBundle b = null;
825 if (configManager != null) {
826 b = configManager.getConfig();
827 }
828 if (b != null) {
829 return b.getBoolean(key);
830 } else {
831 // Return static default defined in CarrierConfigManager.
832 return CarrierConfigManager.getDefaultConfig().getBoolean(key);
833 }
834 }
835
Wink Savillee68857d2014-10-17 15:23:05 -0700836 private void handleCmd(CatCmdMessage cmdMsg, int slotId) {
Preeti Ahuja95919342013-10-01 18:18:55 -0700837
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800838 if (cmdMsg == null) {
839 return;
840 }
841 // save local reference for state tracking.
Wink Savillee68857d2014-10-17 15:23:05 -0700842 mStkContext[slotId].mCurrentCmd = cmdMsg;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800843 boolean waitForUsersResponse = true;
844
Wink Savillee68857d2014-10-17 15:23:05 -0700845 mStkContext[slotId].mIsInputPending = false;
846 mStkContext[slotId].mIsMenuPending = false;
847 mStkContext[slotId].mIsDialogPending = false;
848
849 CatLog.d(LOG_TAG,"[handleCmd]" + cmdMsg.getCmdType().name());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800850 switch (cmdMsg.getCmdType()) {
851 case DISPLAY_TEXT:
852 TextMessage msg = cmdMsg.geTextMessage();
Jeevaka Badrappan854a25c2012-12-01 16:32:03 +0200853 waitForUsersResponse = msg.responseNeeded;
Wink Savillee68857d2014-10-17 15:23:05 -0700854 if (mStkContext[slotId].lastSelectedItem != null) {
855 msg.title = mStkContext[slotId].lastSelectedItem;
856 } else if (mStkContext[slotId].mMainCmd != null){
857 msg.title = mStkContext[slotId].mMainCmd.getMenu().title;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800858 } else {
859 // TODO: get the carrier name from the SIM
860 msg.title = "";
861 }
Preeti Ahuja560be362014-11-25 19:38:24 -0800862 //If we receive a low priority Display Text and the device is
863 // not displaying any STK related activity and the screen is not idle
864 // ( that is, device is in an interactive state), then send a screen busy
865 // terminal response. Otherwise display the message. The existing
866 // displayed message shall be updated with the new display text
867 // proactive command (Refer to ETSI TS 102 384 section 27.22.4.1.4.4.2).
868 if (!(msg.isHighPriority || mStkContext[slotId].mMenuIsVisible
869 || mStkContext[slotId].mDisplayTextDlgIsVisibile || isTopOfStack())) {
870 if(!isScreenIdle()) {
871 CatLog.d(LOG_TAG, "Screen is not idle");
872 sendScreenBusyResponse(slotId);
873 } else {
874 launchTextDialog(slotId);
875 }
876 } else {
877 launchTextDialog(slotId);
878 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800879 break;
880 case SELECT_ITEM:
Wink Savillee68857d2014-10-17 15:23:05 -0700881 CatLog.d(LOG_TAG, "SELECT_ITEM +");
882 mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd;
883 mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu();
884 launchMenuActivity(cmdMsg.getMenu(), slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800885 break;
886 case SET_UP_MENU:
Wink Savillee68857d2014-10-17 15:23:05 -0700887 mStkContext[slotId].mCmdInProgress = false;
888 mStkContext[slotId].mMainCmd = mStkContext[slotId].mCurrentCmd;
889 mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd;
890 mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu();
891 CatLog.d(LOG_TAG, "SET_UP_MENU [" + removeMenu(slotId) + "]");
892
893 if (removeMenu(slotId)) {
894 int i = 0;
895 CatLog.d(LOG_TAG, "removeMenu() - Uninstall App");
896 mStkContext[slotId].mCurrentMenu = null;
Preeti Ahuja95919342013-10-01 18:18:55 -0700897 mStkContext[slotId].mMainCmd = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700898 //Check other setup menu state. If all setup menu are removed, uninstall apk.
899 for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) {
900 if (i != slotId
901 && (mStkContext[slotId].mSetupMenuState == STATE_UNKNOWN
902 || mStkContext[slotId].mSetupMenuState == STATE_EXIST)) {
903 CatLog.d(LOG_TAG, "Not Uninstall App:" + i + ","
904 + mStkContext[slotId].mSetupMenuState);
905 break;
906 }
907 }
908 if (i == mSimCount) {
909 StkAppInstaller.unInstall(mContext);
910 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800911 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700912 CatLog.d(LOG_TAG, "install App");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800913 StkAppInstaller.install(mContext);
914 }
Wink Savillee68857d2014-10-17 15:23:05 -0700915 if (mStkContext[slotId].mMenuIsVisible) {
916 launchMenuActivity(null, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800917 }
918 break;
919 case GET_INPUT:
920 case GET_INKEY:
Wink Savillee68857d2014-10-17 15:23:05 -0700921 launchInputActivity(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800922 break;
923 case SET_UP_IDLE_MODE_TEXT:
924 waitForUsersResponse = false;
Preeti Ahuja560be362014-11-25 19:38:24 -0800925 mStkContext[slotId].mIdleModeTextCmd = mStkContext[slotId].mCurrentCmd;
926 TextMessage idleModeText = mStkContext[slotId].mCurrentCmd.geTextMessage();
927 if (idleModeText == null) {
928 launchIdleText(slotId);
929 mStkContext[slotId].mIdleModeTextCmd = null;
930 }
931 mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
932 if ((mStkContext[slotId].mIdleModeTextCmd != null) && isScreenIdle()) {
933 CatLog.d(this, "set up idle mode");
934 launchIdleText(slotId);
935 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800936 break;
937 case SEND_DTMF:
938 case SEND_SMS:
939 case SEND_SS:
940 case SEND_USSD:
Preeti Ahuja95919342013-10-01 18:18:55 -0700941 case GET_CHANNEL_STATUS:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800942 waitForUsersResponse = false;
Wink Savillee68857d2014-10-17 15:23:05 -0700943 launchEventMessage(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800944 break;
945 case LAUNCH_BROWSER:
Ryuto Sawada0bdc7192016-04-18 12:10:56 +0900946 // The device setup process should not be interrupted by launching browser.
947 if (Settings.Global.getInt(mContext.getContentResolver(),
948 Settings.Global.DEVICE_PROVISIONED, 0) == 0) {
949 CatLog.d(this, "The command is not performed if the setup has not been completed.");
950 sendScreenBusyResponse(slotId);
951 break;
952 }
Sooraj Sasindrana4160472016-10-12 16:28:25 -0700953
954 /* Check if Carrier would not want to launch browser */
955 if (getBooleanCarrierConfig(mContext,
956 CarrierConfigManager.KEY_STK_DISABLE_LAUNCH_BROWSER_BOOL)) {
957 CatLog.d(this, "Browser is not launched as per carrier.");
958 sendResponse(RES_ID_DONE, slotId, true);
959 break;
960 }
961
Preeti Ahujaa7cdca22013-10-01 18:20:56 -0700962 TextMessage alphaId = mStkContext[slotId].mCurrentCmd.geTextMessage();
963 if ((mStkContext[slotId].mCurrentCmd.getBrowserSettings().mode
964 == LaunchBrowserMode.LAUNCH_IF_NOT_ALREADY_LAUNCHED) &&
965 ((alphaId == null) || TextUtils.isEmpty(alphaId.text))) {
966 // don't need user confirmation in this case
967 // just launch the browser or spawn a new tab
968 CatLog.d(this, "Browser mode is: launch if not already launched " +
969 "and user confirmation is not currently needed.\n" +
970 "supressing confirmation dialogue and confirming silently...");
971 mStkContext[slotId].launchBrowser = true;
972 mStkContext[slotId].mBrowserSettings =
973 mStkContext[slotId].mCurrentCmd.getBrowserSettings();
974 sendResponse(RES_ID_CONFIRM, slotId, true);
975 } else {
976 launchConfirmationDialog(alphaId, slotId);
977 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800978 break;
979 case SET_UP_CALL:
Preeti Ahujadd240102013-08-30 17:25:06 -0700980 TextMessage mesg = mStkContext[slotId].mCurrentCmd.getCallSettings().confirmMsg;
981 if((mesg != null) && (mesg.text == null || mesg.text.length() == 0)) {
982 mesg.text = getResources().getString(R.string.default_setup_call_msg);
983 }
984 CatLog.d(this, "SET_UP_CALL mesg.text " + mesg.text);
985 launchConfirmationDialog(mesg, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800986 break;
987 case PLAY_TONE:
Wink Savillee68857d2014-10-17 15:23:05 -0700988 launchToneDialog(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800989 break;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500990 case OPEN_CHANNEL:
Wink Savillee68857d2014-10-17 15:23:05 -0700991 launchOpenChannelDialog(slotId);
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500992 break;
993 case CLOSE_CHANNEL:
994 case RECEIVE_DATA:
995 case SEND_DATA:
Wink Savillee68857d2014-10-17 15:23:05 -0700996 TextMessage m = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500997
998 if ((m != null) && (m.text == null)) {
999 switch(cmdMsg.getCmdType()) {
1000 case CLOSE_CHANNEL:
1001 m.text = getResources().getString(R.string.default_close_channel_msg);
1002 break;
1003 case RECEIVE_DATA:
1004 m.text = getResources().getString(R.string.default_receive_data_msg);
1005 break;
1006 case SEND_DATA:
1007 m.text = getResources().getString(R.string.default_send_data_msg);
1008 break;
1009 }
1010 }
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001011 /*
1012 * Display indication in the form of a toast to the user if required.
1013 */
Wink Savillee68857d2014-10-17 15:23:05 -07001014 launchEventMessage(slotId);
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001015 break;
Preeti Ahuja95919342013-10-01 18:18:55 -07001016 case SET_UP_EVENT_LIST:
1017 mStkContext[slotId].mSetupEventListSettings =
1018 mStkContext[slotId].mCurrentCmd.getSetEventList();
1019 mStkContext[slotId].mCurrentSetupEventCmd = mStkContext[slotId].mCurrentCmd;
1020 mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
Preeti Ahuja560be362014-11-25 19:38:24 -08001021 if (isScreenIdle()) {
1022 CatLog.d(this," Check if IDLE_SCREEN_AVAILABLE_EVENT is present in List");
1023 checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId);
1024 }
Preeti Ahuja95919342013-10-01 18:18:55 -07001025 break;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001026 }
1027
1028 if (!waitForUsersResponse) {
Wink Savillee68857d2014-10-17 15:23:05 -07001029 if (mStkContext[slotId].mCmdsQ.size() != 0) {
1030 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001031 } else {
Wink Savillee68857d2014-10-17 15:23:05 -07001032 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001033 }
1034 }
1035 }
1036
Wink Savillee68857d2014-10-17 15:23:05 -07001037 private void handleCmdResponse(Bundle args, int slotId) {
1038 CatLog.d(LOG_TAG, "handleCmdResponse, sim id: " + slotId);
1039 if (mStkContext[slotId].mCurrentCmd == null) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001040 return;
1041 }
Wink Savillee68857d2014-10-17 15:23:05 -07001042
1043 if (mStkService[slotId] == null) {
Legler Wuaeefef52014-10-27 00:57:18 +08001044 mStkService[slotId] = CatService.getInstance(slotId);
Wink Savillee68857d2014-10-17 15:23:05 -07001045 if (mStkService[slotId] == null) {
Alex Yakavenkad8e2ecd2012-04-20 17:10:15 -07001046 // This should never happen (we should be responding only to a message
1047 // that arrived from StkService). It has to exist by this time
Wink Savillee68857d2014-10-17 15:23:05 -07001048 CatLog.d(LOG_TAG, "Exception! mStkService is null when we need to send response.");
Alex Yakavenkad8e2ecd2012-04-20 17:10:15 -07001049 throw new RuntimeException("mStkService is null when we need to send response");
1050 }
1051 }
1052
Wink Savillee68857d2014-10-17 15:23:05 -07001053 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001054
1055 // set result code
1056 boolean helpRequired = args.getBoolean(HELP, false);
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001057 boolean confirmed = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001058
1059 switch(args.getInt(RES_ID)) {
1060 case RES_ID_MENU_SELECTION:
Wink Savillee68857d2014-10-17 15:23:05 -07001061 CatLog.d(LOG_TAG, "MENU_SELECTION=" + mStkContext[slotId].
1062 mCurrentMenuCmd.getCmdType());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001063 int menuSelection = args.getInt(MENU_SELECTION);
Wink Savillee68857d2014-10-17 15:23:05 -07001064 switch(mStkContext[slotId].mCurrentMenuCmd.getCmdType()) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001065 case SET_UP_MENU:
1066 case SELECT_ITEM:
Wink Savillee68857d2014-10-17 15:23:05 -07001067 mStkContext[slotId].lastSelectedItem = getItemName(menuSelection, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001068 if (helpRequired) {
1069 resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED);
1070 } else {
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301071 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1072 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001073 }
1074 resMsg.setMenuSelection(menuSelection);
1075 break;
1076 }
1077 break;
1078 case RES_ID_INPUT:
Wink Savillee68857d2014-10-17 15:23:05 -07001079 CatLog.d(LOG_TAG, "RES_ID_INPUT");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001080 String input = args.getString(INPUT);
Wink Savillee68857d2014-10-17 15:23:05 -07001081 if (input != null && (null != mStkContext[slotId].mCurrentCmd.geInput()) &&
1082 (mStkContext[slotId].mCurrentCmd.geInput().yesNo)) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001083 boolean yesNoSelection = input
1084 .equals(StkInputActivity.YES_STR_RESPONSE);
1085 resMsg.setYesNo(yesNoSelection);
1086 } else {
1087 if (helpRequired) {
1088 resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED);
1089 } else {
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301090 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1091 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001092 resMsg.setInput(input);
1093 }
1094 }
1095 break;
1096 case RES_ID_CONFIRM:
Alex Yakavenkad41f1d92010-07-12 14:13:13 -07001097 CatLog.d(this, "RES_ID_CONFIRM");
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001098 confirmed = args.getBoolean(CONFIRMATION);
Wink Savillee68857d2014-10-17 15:23:05 -07001099 switch (mStkContext[slotId].mCurrentCmd.getCmdType()) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001100 case DISPLAY_TEXT:
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301101 if (confirmed) {
1102 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1103 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
1104 } else {
1105 resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER);
1106 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001107 break;
1108 case LAUNCH_BROWSER:
1109 resMsg.setResultCode(confirmed ? ResultCode.OK
1110 : ResultCode.UICC_SESSION_TERM_BY_USER);
1111 if (confirmed) {
Wink Savillee68857d2014-10-17 15:23:05 -07001112 mStkContext[slotId].launchBrowser = true;
1113 mStkContext[slotId].mBrowserSettings =
1114 mStkContext[slotId].mCurrentCmd.getBrowserSettings();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001115 }
1116 break;
1117 case SET_UP_CALL:
1118 resMsg.setResultCode(ResultCode.OK);
1119 resMsg.setConfirmation(confirmed);
1120 if (confirmed) {
Wink Savillee68857d2014-10-17 15:23:05 -07001121 launchEventMessage(slotId,
1122 mStkContext[slotId].mCurrentCmd.getCallSettings().callMsg);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001123 }
1124 break;
1125 }
1126 break;
1127 case RES_ID_DONE:
1128 resMsg.setResultCode(ResultCode.OK);
1129 break;
1130 case RES_ID_BACKWARD:
Wink Savillee68857d2014-10-17 15:23:05 -07001131 CatLog.d(LOG_TAG, "RES_ID_BACKWARD");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001132 resMsg.setResultCode(ResultCode.BACKWARD_MOVE_BY_USER);
1133 break;
1134 case RES_ID_END_SESSION:
Wink Savillee68857d2014-10-17 15:23:05 -07001135 CatLog.d(LOG_TAG, "RES_ID_END_SESSION");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001136 resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER);
1137 break;
1138 case RES_ID_TIMEOUT:
Wink Savillee68857d2014-10-17 15:23:05 -07001139 CatLog.d(LOG_TAG, "RES_ID_TIMEOUT");
Naveen Kallad5176892009-11-30 12:45:29 -08001140 // GCF test-case 27.22.4.1.1 Expected Sequence 1.5 (DISPLAY TEXT,
1141 // Clear message after delay, successful) expects result code OK.
1142 // If the command qualifier specifies no user response is required
1143 // then send OK instead of NO_RESPONSE_FROM_USER
Wink Savillee68857d2014-10-17 15:23:05 -07001144 if ((mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1145 AppInterface.CommandType.DISPLAY_TEXT.value())
1146 && (mStkContext[slotId].mCurrentCmd.geTextMessage().userClear == false)) {
Naveen Kallad5176892009-11-30 12:45:29 -08001147 resMsg.setResultCode(ResultCode.OK);
1148 } else {
1149 resMsg.setResultCode(ResultCode.NO_RESPONSE_FROM_USER);
1150 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001151 break;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001152 case RES_ID_CHOICE:
1153 int choice = args.getInt(CHOICE);
1154 CatLog.d(this, "User Choice=" + choice);
1155 switch (choice) {
1156 case YES:
1157 resMsg.setResultCode(ResultCode.OK);
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001158 confirmed = true;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001159 break;
1160 case NO:
1161 resMsg.setResultCode(ResultCode.USER_NOT_ACCEPT);
1162 break;
1163 }
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001164
Wink Savillee68857d2014-10-17 15:23:05 -07001165 if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1166 AppInterface.CommandType.OPEN_CHANNEL.value()) {
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001167 resMsg.setConfirmation(confirmed);
1168 }
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001169 break;
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001170
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001171 default:
Wink Savillee68857d2014-10-17 15:23:05 -07001172 CatLog.d(LOG_TAG, "Unknown result id");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001173 return;
1174 }
Wink Savillee68857d2014-10-17 15:23:05 -07001175
1176 if (null != mStkContext[slotId].mCurrentCmd &&
1177 null != mStkContext[slotId].mCurrentCmd.getCmdType()) {
1178 CatLog.d(LOG_TAG, "handleCmdResponse- cmdName[" +
1179 mStkContext[slotId].mCurrentCmd.getCmdType().name() + "]");
1180 }
1181 mStkService[slotId].onCmdResponse(resMsg);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001182 }
1183
1184 /**
1185 * Returns 0 or FLAG_ACTIVITY_NO_USER_ACTION, 0 means the user initiated the action.
1186 *
1187 * @param userAction If the userAction is yes then we always return 0 otherwise
1188 * mMenuIsVisible is used to determine what to return. If mMenuIsVisible is true
1189 * then we are the foreground app and we'll return 0 as from our perspective a
1190 * user action did cause. If it's false than we aren't the foreground app and
1191 * FLAG_ACTIVITY_NO_USER_ACTION is returned.
Wink Saville79085fc2009-06-09 10:27:23 -07001192 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001193 * @return 0 or FLAG_ACTIVITY_NO_USER_ACTION
1194 */
Wink Savillee68857d2014-10-17 15:23:05 -07001195 private int getFlagActivityNoUserAction(InitiatedByUserAction userAction, int slotId) {
1196 return ((userAction == InitiatedByUserAction.yes) | mStkContext[slotId].mMenuIsVisible)
1197 ? 0 : Intent.FLAG_ACTIVITY_NO_USER_ACTION;
1198 }
1199 /**
1200 * This method is used for cleaning up pending instances in stack.
1201 */
1202 private void cleanUpInstanceStackBySlot(int slotId) {
1203 Activity activity = mStkContext[slotId].getPendingActivityInstance();
1204 Activity dialog = mStkContext[slotId].getPendingDialogInstance();
1205 CatLog.d(LOG_TAG, "cleanUpInstanceStackBySlot slotId: " + slotId);
Legler Wuaeefef52014-10-27 00:57:18 +08001206 if (mStkContext[slotId].mCurrentCmd == null) {
1207 CatLog.d(LOG_TAG, "current cmd is null.");
1208 return;
1209 }
Wink Savillee68857d2014-10-17 15:23:05 -07001210 if (activity != null) {
1211 CatLog.d(LOG_TAG, "current cmd type: " +
1212 mStkContext[slotId].mCurrentCmd.getCmdType());
1213 if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1214 AppInterface.CommandType.GET_INPUT.value() ||
1215 mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1216 AppInterface.CommandType.GET_INKEY.value()) {
1217 mStkContext[slotId].mIsInputPending = true;
1218 } else if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1219 AppInterface.CommandType.SET_UP_MENU.value() ||
1220 mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1221 AppInterface.CommandType.SELECT_ITEM.value()) {
1222 mStkContext[slotId].mIsMenuPending = true;
1223 } else {
1224 }
1225 CatLog.d(LOG_TAG, "finish pending activity.");
1226 activity.finish();
1227 mStkContext[slotId].mActivityInstance = null;
1228 }
1229 if (dialog != null) {
1230 CatLog.d(LOG_TAG, "finish pending dialog.");
1231 mStkContext[slotId].mIsDialogPending = true;
1232 dialog.finish();
1233 mStkContext[slotId].mDialogInstance = null;
1234 }
1235 }
1236 /**
1237 * This method is used for restoring pending instances from stack.
1238 */
1239 private void restoreInstanceFromStackBySlot(int slotId) {
1240 AppInterface.CommandType cmdType = mStkContext[slotId].mCurrentCmd.getCmdType();
1241
1242 CatLog.d(LOG_TAG, "restoreInstanceFromStackBySlot cmdType : " + cmdType);
1243 switch(cmdType) {
1244 case GET_INPUT:
1245 case GET_INKEY:
1246 launchInputActivity(slotId);
1247 //Set mMenuIsVisible to true for showing main menu for
1248 //following session end command.
1249 mStkContext[slotId].mMenuIsVisible = true;
1250 break;
1251 case DISPLAY_TEXT:
1252 launchTextDialog(slotId);
1253 break;
1254 case LAUNCH_BROWSER:
1255 launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.geTextMessage(),
1256 slotId);
1257 break;
1258 case OPEN_CHANNEL:
1259 launchOpenChannelDialog(slotId);
1260 break;
1261 case SET_UP_CALL:
1262 launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.getCallSettings().
1263 confirmMsg, slotId);
1264 break;
1265 case SET_UP_MENU:
1266 case SELECT_ITEM:
1267 launchMenuActivity(null, slotId);
1268 break;
1269 default:
1270 break;
1271 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001272 }
1273
Wink Savillee68857d2014-10-17 15:23:05 -07001274 private void launchMenuActivity(Menu menu, int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001275 Intent newIntent = new Intent(Intent.ACTION_VIEW);
Wink Savillee68857d2014-10-17 15:23:05 -07001276 String targetActivity = STK_MENU_ACTIVITY_NAME;
1277 String uriString = STK_MENU_URI + System.currentTimeMillis();
1278 //Set unique URI to create a new instance of activity for different slotId.
1279 Uri uriData = Uri.parse(uriString);
1280
1281 CatLog.d(LOG_TAG, "launchMenuActivity, slotId: " + slotId + " , " +
1282 uriData.toString() + " , " + mStkContext[slotId].mOpCode + ", "
1283 + mStkContext[slotId].mMenuState);
1284 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1285 int intentFlags = Intent.FLAG_ACTIVITY_NEW_TASK;
1286
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001287 if (menu == null) {
1288 // We assume this was initiated by the user pressing the tool kit icon
Wink Savillee68857d2014-10-17 15:23:05 -07001289 intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.yes, slotId);
1290 if (mStkContext[slotId].mOpCode == OP_END_SESSION) {
1291 CatLog.d(LOG_TAG, "launchMenuActivity, return OP_END_SESSION");
1292 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN;
1293 if (mStkContext[slotId].mMainActivityInstance != null) {
1294 CatLog.d(LOG_TAG, "launchMenuActivity, mMainActivityInstance is not null");
1295 return;
1296 }
Wink Savillee68857d2014-10-17 15:23:05 -07001297 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001298
Wink Savillee68857d2014-10-17 15:23:05 -07001299 //If the last pending menu is secondary menu, "STATE" should be "STATE_SECONDARY".
1300 //Otherwise, it should be "STATE_MAIN".
1301 if (mStkContext[slotId].mOpCode == OP_LAUNCH_APP &&
1302 mStkContext[slotId].mMenuState == StkMenuActivity.STATE_SECONDARY) {
1303 newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY);
1304 } else {
1305 newIntent.putExtra("STATE", StkMenuActivity.STATE_MAIN);
1306 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN;
1307 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001308 } else {
1309 // We don't know and we'll let getFlagActivityNoUserAction decide.
Wink Savillee68857d2014-10-17 15:23:05 -07001310 intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001311 newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY);
Wink Savillee68857d2014-10-17 15:23:05 -07001312 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_SECONDARY;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001313 }
Wink Savillee68857d2014-10-17 15:23:05 -07001314 newIntent.putExtra(SLOT_ID, slotId);
1315 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001316 newIntent.setFlags(intentFlags);
1317 mContext.startActivity(newIntent);
1318 }
1319
Wink Savillee68857d2014-10-17 15:23:05 -07001320 private void launchInputActivity(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001321 Intent newIntent = new Intent(Intent.ACTION_VIEW);
Wink Savillee68857d2014-10-17 15:23:05 -07001322 String targetActivity = STK_INPUT_ACTIVITY_NAME;
1323 String uriString = STK_INPUT_URI + System.currentTimeMillis();
1324 //Set unique URI to create a new instance of activity for different slotId.
1325 Uri uriData = Uri.parse(uriString);
1326
1327 CatLog.d(LOG_TAG, "launchInputActivity, slotId: " + slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001328 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
Wink Savillee68857d2014-10-17 15:23:05 -07001329 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1330 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1331 newIntent.putExtra("INPUT", mStkContext[slotId].mCurrentCmd.geInput());
1332 newIntent.putExtra(SLOT_ID, slotId);
1333 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001334 mContext.startActivity(newIntent);
1335 }
1336
Wink Savillee68857d2014-10-17 15:23:05 -07001337 private void launchTextDialog(int slotId) {
1338 CatLog.d(LOG_TAG, "launchTextDialog, slotId: " + slotId);
1339 Intent newIntent = new Intent();
1340 String targetActivity = STK_DIALOG_ACTIVITY_NAME;
1341 int action = getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId);
1342 String uriString = STK_DIALOG_URI + System.currentTimeMillis();
1343 //Set unique URI to create a new instance of activity for different slotId.
1344 Uri uriData = Uri.parse(uriString);
1345 if (newIntent != null) {
1346 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1347 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1348 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
1349 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1350 newIntent.setData(uriData);
1351 newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage());
1352 newIntent.putExtra(SLOT_ID, slotId);
1353 startActivity(newIntent);
Preeti Ahuja414bc412013-06-25 19:31:49 -07001354 // For display texts with immediate response, send the terminal response
1355 // immediately. responseNeeded will be false, if display text command has
1356 // the immediate response tlv.
1357 if (!mStkContext[slotId].mCurrentCmd.geTextMessage().responseNeeded) {
1358 sendResponse(RES_ID_CONFIRM, slotId, true);
1359 }
Wink Savillee68857d2014-10-17 15:23:05 -07001360 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001361 }
1362
Wink Savillee68857d2014-10-17 15:23:05 -07001363 public boolean isStkDialogActivated(Context context) {
1364 String stkDialogActivity = "com.android.stk.StkDialogActivity";
1365 boolean activated = false;
1366 final ActivityManager am = (ActivityManager) context.getSystemService(
1367 Context.ACTIVITY_SERVICE);
1368 String topActivity = am.getRunningTasks(1).get(0).topActivity.getClassName();
1369
1370 CatLog.d(LOG_TAG, "isStkDialogActivated: " + topActivity);
1371 if (topActivity.equals(stkDialogActivity)) {
1372 activated = true;
1373 }
1374 CatLog.d(LOG_TAG, "activated : " + activated);
1375 return activated;
Johan Hellman3aec01c2011-02-10 10:15:28 +01001376 }
1377
Preeti Ahuja95919342013-10-01 18:18:55 -07001378 private void sendSetUpEventResponse(int event, byte[] addedInfo, int slotId) {
Preeti Ahuja414bc412013-06-25 19:31:49 -07001379 CatLog.d(this, "sendSetUpEventResponse: event : " + event + "slotId = " + slotId);
Preeti Ahuja95919342013-10-01 18:18:55 -07001380
1381 if (mStkContext[slotId].mCurrentSetupEventCmd == null){
1382 CatLog.e(this, "mCurrentSetupEventCmd is null");
1383 return;
1384 }
1385
1386 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentSetupEventCmd);
1387
1388 resMsg.setResultCode(ResultCode.OK);
1389 resMsg.setEventDownload(event, addedInfo);
1390
1391 mStkService[slotId].onCmdResponse(resMsg);
1392 }
1393
1394 private void checkForSetupEvent(int event, Bundle args, int slotId) {
1395 boolean eventPresent = false;
1396 byte[] addedInfo = null;
1397 CatLog.d(this, "Event :" + event);
1398
1399 if (mStkContext[slotId].mSetupEventListSettings != null) {
1400 /* Checks if the event is present in the EventList updated by last
1401 * SetupEventList Proactive Command */
1402 for (int i : mStkContext[slotId].mSetupEventListSettings.eventList) {
1403 if (event == i) {
1404 eventPresent = true;
1405 break;
1406 }
1407 }
1408
1409 /* If Event is present send the response to ICC */
1410 if (eventPresent == true) {
1411 CatLog.d(this, " Event " + event + "exists in the EventList");
1412
1413 switch (event) {
Preeti Ahuja560be362014-11-25 19:38:24 -08001414 case IDLE_SCREEN_AVAILABLE_EVENT:
1415 sendSetUpEventResponse(event, addedInfo, slotId);
1416 removeSetUpEvent(event, slotId);
1417 break;
Preeti Ahuja95919342013-10-01 18:18:55 -07001418 case LANGUAGE_SELECTION_EVENT:
1419 String language = mContext
1420 .getResources().getConfiguration().locale.getLanguage();
1421 CatLog.d(this, "language: " + language);
1422 // Each language code is a pair of alpha-numeric characters.
1423 // Each alpha-numeric character shall be coded on one byte
1424 // using the SMS default 7-bit coded alphabet
1425 addedInfo = GsmAlphabet.stringToGsm8BitPacked(language);
1426 sendSetUpEventResponse(event, addedInfo, slotId);
1427 break;
1428 default:
1429 break;
1430 }
1431 } else {
1432 CatLog.e(this, " Event does not exist in the EventList");
1433 }
1434 } else {
1435 CatLog.e(this, "SetupEventList is not received. Ignoring the event: " + event);
1436 }
1437 }
1438
1439 private void removeSetUpEvent(int event, int slotId) {
1440 CatLog.d(this, "Remove Event :" + event);
1441
1442 if (mStkContext[slotId].mSetupEventListSettings != null) {
1443 /*
1444 * Make new Eventlist without the event
1445 */
1446 for (int i = 0; i < mStkContext[slotId].mSetupEventListSettings.eventList.length; i++) {
1447 if (event == mStkContext[slotId].mSetupEventListSettings.eventList[i]) {
1448 mStkContext[slotId].mSetupEventListSettings.eventList[i] = INVALID_SETUP_EVENT;
1449 break;
1450 }
1451 }
1452 }
1453 }
1454
1455 private void launchEventMessage(int slotId) {
1456 launchEventMessage(slotId, mStkContext[slotId].mCurrentCmd.geTextMessage());
1457 }
1458
Wink Savillee68857d2014-10-17 15:23:05 -07001459 private void launchEventMessage(int slotId, TextMessage msg) {
1460 if (msg == null || (msg.text != null && msg.text.length() == 0)) {
1461 CatLog.d(LOG_TAG, "launchEventMessage return");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001462 return;
1463 }
Wink Savillee68857d2014-10-17 15:23:05 -07001464
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001465 Toast toast = new Toast(mContext.getApplicationContext());
1466 LayoutInflater inflate = (LayoutInflater) mContext
1467 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
1468 View v = inflate.inflate(R.layout.stk_event_msg, null);
1469 TextView tv = (TextView) v
1470 .findViewById(com.android.internal.R.id.message);
1471 ImageView iv = (ImageView) v
1472 .findViewById(com.android.internal.R.id.icon);
1473 if (msg.icon != null) {
1474 iv.setImageBitmap(msg.icon);
1475 } else {
1476 iv.setVisibility(View.GONE);
1477 }
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301478 /* In case of 'self explanatory' stkapp should display the specified
1479 * icon in proactive command (but not the alpha string).
1480 * If icon is non-self explanatory and if the icon could not be displayed
1481 * then alpha string or text data should be displayed
1482 * Ref: ETSI 102.223,section 6.5.4
1483 */
1484 if (mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ||
1485 msg.icon == null || !msg.iconSelfExplanatory) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001486 tv.setText(msg.text);
1487 }
1488
1489 toast.setView(v);
1490 toast.setDuration(Toast.LENGTH_LONG);
1491 toast.setGravity(Gravity.BOTTOM, 0, 0);
1492 toast.show();
1493 }
1494
Wink Savillee68857d2014-10-17 15:23:05 -07001495 private void launchConfirmationDialog(TextMessage msg, int slotId) {
1496 msg.title = mStkContext[slotId].lastSelectedItem;
1497 Intent newIntent = new Intent();
1498 String targetActivity = STK_DIALOG_ACTIVITY_NAME;
1499 String uriString = STK_DIALOG_URI + System.currentTimeMillis();
1500 //Set unique URI to create a new instance of activity for different slotId.
1501 Uri uriData = Uri.parse(uriString);
1502
1503 if (newIntent != null) {
1504 newIntent.setClassName(this, targetActivity);
1505 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1506 | Intent.FLAG_ACTIVITY_NO_HISTORY
1507 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
1508 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1509 newIntent.putExtra("TEXT", msg);
1510 newIntent.putExtra(SLOT_ID, slotId);
1511 newIntent.setData(uriData);
1512 startActivity(newIntent);
1513 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001514 }
1515
1516 private void launchBrowser(BrowserSettings settings) {
1517 if (settings == null) {
1518 return;
1519 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001520
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001521 Uri data = null;
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001522 String url;
1523 if (settings.url == null) {
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001524 // if the command did not contain a URL,
1525 // launch the browser to the default homepage.
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001526 CatLog.d(this, "no url data provided by proactive command." +
1527 " launching browser with stk default URL ... ");
1528 url = SystemProperties.get(STK_BROWSER_DEFAULT_URL_SYSPROP,
1529 "http://www.google.com");
1530 } else {
1531 CatLog.d(this, "launch browser command has attached url = " + settings.url);
1532 url = settings.url;
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001533 }
David Brown7c03cfe2011-10-20 15:36:12 -07001534
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001535 if (url.startsWith("http://") || url.startsWith("https://")) {
1536 data = Uri.parse(url);
1537 CatLog.d(this, "launching browser with url = " + url);
1538 } else {
1539 String modifiedUrl = "http://" + url;
1540 data = Uri.parse(modifiedUrl);
1541 CatLog.d(this, "launching browser with modified url = " + modifiedUrl);
1542 }
1543
1544 Intent intent = new Intent(Intent.ACTION_VIEW);
1545 intent.setData(data);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001546 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1547 switch (settings.mode) {
1548 case USE_EXISTING_BROWSER:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001549 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1550 break;
1551 case LAUNCH_NEW_BROWSER:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001552 intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
1553 break;
1554 case LAUNCH_IF_NOT_ALREADY_LAUNCHED:
1555 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1556 break;
1557 }
1558 // start browser activity
1559 startActivity(intent);
1560 // a small delay, let the browser start, before processing the next command.
Wink Saville79085fc2009-06-09 10:27:23 -07001561 // this is good for scenarios where a related DISPLAY TEXT command is
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001562 // followed immediately.
1563 try {
Ryuto Sawada350aaa62016-06-13 14:47:22 +09001564 Thread.sleep(3000);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001565 } catch (InterruptedException e) {}
1566 }
1567
Wink Savillee68857d2014-10-17 15:23:05 -07001568 private void launchIdleText(int slotId) {
Preeti Ahuja560be362014-11-25 19:38:24 -08001569 TextMessage msg = mStkContext[slotId].mIdleModeTextCmd.geTextMessage();
dujin.cha2a0eb2a2011-11-11 15:03:57 +09001570
Preeti Ahuja95919342013-10-01 18:18:55 -07001571 if (msg == null || msg.text ==null) {
1572 CatLog.d(LOG_TAG, msg == null ? "mCurrent.getTextMessage is NULL"
1573 : "mCurrent.getTextMessage.text is NULL");
Wink Savillee68857d2014-10-17 15:23:05 -07001574 mNotificationManager.cancel(getNotificationId(slotId));
Wink Saville046db4b2011-11-01 20:42:54 -07001575 return;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001576 } else {
Preeti Ahuja95919342013-10-01 18:18:55 -07001577 CatLog.d(LOG_TAG, "launchIdleText - text[" + msg.text
1578 + "] iconSelfExplanatory[" + msg.iconSelfExplanatory
1579 + "] icon[" + msg.icon + "], sim id: " + slotId);
Wink Savillee68857d2014-10-17 15:23:05 -07001580 CatLog.d(LOG_TAG, "Add IdleMode text");
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001581 PendingIntent pendingIntent = PendingIntent.getService(mContext, 0,
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001582 new Intent(mContext, StkAppService.class), 0);
1583
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001584 final Notification.Builder notificationBuilder = new Notification.Builder(
1585 StkAppService.this);
Wink Savillee68857d2014-10-17 15:23:05 -07001586 if (mStkContext[slotId].mMainCmd != null &&
1587 mStkContext[slotId].mMainCmd.getMenu() != null) {
1588 notificationBuilder.setContentTitle(mStkContext[slotId].mMainCmd.getMenu().title);
Christopher Posselwhite2ad2ab72013-05-27 07:51:06 +02001589 } else {
1590 notificationBuilder.setContentTitle("");
1591 }
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001592 notificationBuilder
1593 .setSmallIcon(com.android.internal.R.drawable.stat_notify_sim_toolkit);
1594 notificationBuilder.setContentIntent(pendingIntent);
1595 notificationBuilder.setOngoing(true);
1596 // Set text and icon for the status bar and notification body.
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301597 if (mStkContext[slotId].mIdleModeTextCmd.hasIconLoadFailed() ||
1598 !msg.iconSelfExplanatory) {
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001599 notificationBuilder.setContentText(msg.text);
Christopher Posselwhite2ad2ab72013-05-27 07:51:06 +02001600 notificationBuilder.setTicker(msg.text);
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001601 }
1602 if (msg.icon != null) {
1603 notificationBuilder.setLargeIcon(msg.icon);
1604 } else {
1605 Bitmap bitmapIcon = BitmapFactory.decodeResource(StkAppService.this
1606 .getResources().getSystem(),
1607 com.android.internal.R.drawable.stat_notify_sim_toolkit);
1608 notificationBuilder.setLargeIcon(bitmapIcon);
1609 }
Selim Cinek62eb3fe2014-08-27 17:52:23 +02001610 notificationBuilder.setColor(mContext.getResources().getColor(
1611 com.android.internal.R.color.system_notification_accent_color));
Wink Savillee68857d2014-10-17 15:23:05 -07001612 mNotificationManager.notify(getNotificationId(slotId), notificationBuilder.build());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001613 }
1614 }
1615
Wink Savillee68857d2014-10-17 15:23:05 -07001616 private void launchToneDialog(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001617 Intent newIntent = new Intent(this, ToneDialog.class);
Wink Savillee68857d2014-10-17 15:23:05 -07001618 String uriString = STK_TONE_URI + slotId;
1619 Uri uriData = Uri.parse(uriString);
1620 //Set unique URI to create a new instance of activity for different slotId.
1621 CatLog.d(LOG_TAG, "launchToneDialog, slotId: " + slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001622 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1623 | Intent.FLAG_ACTIVITY_NO_HISTORY
1624 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
Wink Savillee68857d2014-10-17 15:23:05 -07001625 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1626 newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage());
1627 newIntent.putExtra("TONE", mStkContext[slotId].mCurrentCmd.getToneSettings());
1628 newIntent.putExtra(SLOT_ID, slotId);
1629 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001630 startActivity(newIntent);
1631 }
1632
Takanori Nakano49b12722016-02-16 14:34:14 +09001633 private void launchOpenChannelDialog(final int slotId) {
Wink Savillee68857d2014-10-17 15:23:05 -07001634 TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001635 if (msg == null) {
Wink Savillee68857d2014-10-17 15:23:05 -07001636 CatLog.d(LOG_TAG, "msg is null, return here");
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001637 return;
1638 }
1639
1640 msg.title = getResources().getString(R.string.stk_dialog_title);
1641 if (msg.text == null) {
1642 msg.text = getResources().getString(R.string.default_open_channel_msg);
1643 }
1644
1645 final AlertDialog dialog = new AlertDialog.Builder(mContext)
1646 .setIconAttribute(android.R.attr.alertDialogIcon)
1647 .setTitle(msg.title)
1648 .setMessage(msg.text)
1649 .setCancelable(false)
1650 .setPositiveButton(getResources().getString(R.string.stk_dialog_accept),
1651 new DialogInterface.OnClickListener() {
1652 public void onClick(DialogInterface dialog, int which) {
1653 Bundle args = new Bundle();
1654 args.putInt(RES_ID, RES_ID_CHOICE);
1655 args.putInt(CHOICE, YES);
1656 Message message = mServiceHandler.obtainMessage();
1657 message.arg1 = OP_RESPONSE;
Takanori Nakano49b12722016-02-16 14:34:14 +09001658 message.arg2 = slotId;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001659 message.obj = args;
1660 mServiceHandler.sendMessage(message);
1661 }
1662 })
1663 .setNegativeButton(getResources().getString(R.string.stk_dialog_reject),
1664 new DialogInterface.OnClickListener() {
1665 public void onClick(DialogInterface dialog, int which) {
1666 Bundle args = new Bundle();
1667 args.putInt(RES_ID, RES_ID_CHOICE);
1668 args.putInt(CHOICE, NO);
1669 Message message = mServiceHandler.obtainMessage();
1670 message.arg1 = OP_RESPONSE;
Takanori Nakano49b12722016-02-16 14:34:14 +09001671 message.arg2 = slotId;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001672 message.obj = args;
1673 mServiceHandler.sendMessage(message);
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 void launchTransientEventMessage(int slotId) {
1688 TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001689 if (msg == null) {
Wink Savillee68857d2014-10-17 15:23:05 -07001690 CatLog.d(LOG_TAG, "msg is null, return here");
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001691 return;
1692 }
1693
1694 msg.title = getResources().getString(R.string.stk_dialog_title);
1695
1696 final AlertDialog dialog = new AlertDialog.Builder(mContext)
1697 .setIconAttribute(android.R.attr.alertDialogIcon)
1698 .setTitle(msg.title)
1699 .setMessage(msg.text)
1700 .setCancelable(false)
1701 .setPositiveButton(getResources().getString(android.R.string.ok),
1702 new DialogInterface.OnClickListener() {
1703 public void onClick(DialogInterface dialog, int which) {
1704 }
1705 })
1706 .create();
1707
1708 dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
1709 if (!mContext.getResources().getBoolean(
1710 com.android.internal.R.bool.config_sf_slowBlur)) {
1711 dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
1712 }
1713
1714 dialog.show();
1715 }
1716
Wink Savillee68857d2014-10-17 15:23:05 -07001717 private int getNotificationId(int slotId) {
1718 int notifyId = STK_NOTIFICATION_ID;
1719 if (slotId >= 0 && slotId < mSimCount) {
1720 notifyId += slotId;
1721 } else {
1722 CatLog.d(LOG_TAG, "invalid slotId: " + slotId);
1723 }
1724 CatLog.d(LOG_TAG, "getNotificationId, slotId: " + slotId + ", notifyId: " + notifyId);
1725 return notifyId;
1726 }
1727
1728 private String getItemName(int itemId, int slotId) {
1729 Menu menu = mStkContext[slotId].mCurrentCmd.getMenu();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001730 if (menu == null) {
1731 return null;
1732 }
1733 for (Item item : menu.items) {
1734 if (item.id == itemId) {
1735 return item.text;
1736 }
1737 }
1738 return null;
1739 }
1740
Wink Savillee68857d2014-10-17 15:23:05 -07001741 private boolean removeMenu(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001742 try {
Wink Savillee68857d2014-10-17 15:23:05 -07001743 if (mStkContext[slotId].mCurrentMenu.items.size() == 1 &&
1744 mStkContext[slotId].mCurrentMenu.items.get(0) == null) {
1745 mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001746 return true;
1747 }
1748 } catch (NullPointerException e) {
Wink Savillee68857d2014-10-17 15:23:05 -07001749 CatLog.d(LOG_TAG, "Unable to get Menu's items size");
1750 mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001751 return true;
1752 }
Wink Savillee68857d2014-10-17 15:23:05 -07001753 mStkContext[slotId].mSetupMenuState = STATE_EXIST;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001754 return false;
1755 }
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +05301756
Wink Savillee68857d2014-10-17 15:23:05 -07001757 StkContext getStkContext(int slotId) {
1758 if (slotId >= 0 && slotId < mSimCount) {
1759 return mStkContext[slotId];
1760 } else {
1761 CatLog.d(LOG_TAG, "invalid slotId: " + slotId);
1762 return null;
1763 }
1764 }
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +05301765
1766 private void handleAlphaNotify(Bundle args) {
1767 String alphaString = args.getString(AppInterface.ALPHA_STRING);
1768
1769 CatLog.d(this, "Alpha string received from card: " + alphaString);
1770 Toast toast = Toast.makeText(sInstance, alphaString, Toast.LENGTH_LONG);
1771 toast.setGravity(Gravity.TOP, 0, 0);
1772 toast.show();
1773 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001774}