blob: 1c1b33a77584021e6f94b605c51932140bdd197e [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;
fionaxu2c91c752017-04-21 18:11:57 -070023import android.app.NotificationChannel;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080024import android.app.NotificationManager;
25import android.app.PendingIntent;
26import android.app.Service;
Wink Savillee68857d2014-10-17 15:23:05 -070027import android.app.Activity;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080028import android.content.Context;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -050029import android.content.DialogInterface;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080030import android.content.Intent;
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +010031import android.graphics.Bitmap;
32import android.graphics.BitmapFactory;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080033import android.net.Uri;
34import android.os.Bundle;
35import android.os.Handler;
36import android.os.IBinder;
37import android.os.Looper;
38import android.os.Message;
Sooraj Sasindrana4160472016-10-12 16:28:25 -070039import android.os.PersistableBundle;
Preeti Ahuja560be362014-11-25 19:38:24 -080040import android.os.PowerManager;
Preeti Ahujaa7cdca22013-10-01 18:20:56 -070041import android.os.SystemProperties;
Preeti Ahuja95919342013-10-01 18:18:55 -070042import android.provider.Settings;
Sooraj Sasindrana4160472016-10-12 16:28:25 -070043import android.telephony.CarrierConfigManager;
Wink Saville56469d52009-04-02 01:37:03 -070044import android.telephony.TelephonyManager;
Preeti Ahujaa7cdca22013-10-01 18:20:56 -070045import android.text.TextUtils;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080046import android.view.Gravity;
47import android.view.LayoutInflater;
48import android.view.View;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -050049import android.view.WindowManager;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080050import android.widget.ImageView;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080051import android.widget.TextView;
52import android.widget.Toast;
Wink Savillee68857d2014-10-17 15:23:05 -070053import android.content.IntentFilter;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080054
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070055import com.android.internal.telephony.cat.AppInterface;
Preeti Ahuja95919342013-10-01 18:18:55 -070056import com.android.internal.telephony.cat.LaunchBrowserMode;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070057import com.android.internal.telephony.cat.Menu;
58import com.android.internal.telephony.cat.Item;
59import com.android.internal.telephony.cat.ResultCode;
60import com.android.internal.telephony.cat.CatCmdMessage;
61import com.android.internal.telephony.cat.CatCmdMessage.BrowserSettings;
Preeti Ahuja95919342013-10-01 18:18:55 -070062import com.android.internal.telephony.cat.CatCmdMessage.SetupEventListSettings;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070063import com.android.internal.telephony.cat.CatLog;
64import com.android.internal.telephony.cat.CatResponseMessage;
65import com.android.internal.telephony.cat.TextMessage;
Wink Saville94e982b2014-07-11 07:38:14 -070066import com.android.internal.telephony.uicc.IccRefreshResponse;
Wink Savillee68857d2014-10-17 15:23:05 -070067import com.android.internal.telephony.PhoneConstants;
Preeti Ahuja95919342013-10-01 18:18:55 -070068import com.android.internal.telephony.GsmAlphabet;
Legler Wuaeefef52014-10-27 00:57:18 +080069import com.android.internal.telephony.cat.CatService;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080070
Preeti Ahujaa7cdca22013-10-01 18:20:56 -070071import java.util.Iterator;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080072import java.util.LinkedList;
Wink Savillee68857d2014-10-17 15:23:05 -070073import java.lang.System;
74import java.util.List;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080075
Preeti Ahuja95919342013-10-01 18:18:55 -070076import static com.android.internal.telephony.cat.CatCmdMessage.
Preeti Ahuja560be362014-11-25 19:38:24 -080077 SetupEventListConstants.IDLE_SCREEN_AVAILABLE_EVENT;
78import static com.android.internal.telephony.cat.CatCmdMessage.
Preeti Ahuja95919342013-10-01 18:18:55 -070079 SetupEventListConstants.LANGUAGE_SELECTION_EVENT;
80
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080081/**
82 * SIM toolkit application level service. Interacts with Telephopny messages,
83 * application's launch and user input from STK UI elements.
Wink Saville79085fc2009-06-09 10:27:23 -070084 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080085 */
86public class StkAppService extends Service implements Runnable {
87
88 // members
Wink Savillee68857d2014-10-17 15:23:05 -070089 protected class StkContext {
90 protected CatCmdMessage mMainCmd = null;
91 protected CatCmdMessage mCurrentCmd = null;
92 protected CatCmdMessage mCurrentMenuCmd = null;
93 protected Menu mCurrentMenu = null;
94 protected String lastSelectedItem = null;
95 protected boolean mMenuIsVisible = false;
96 protected boolean mIsInputPending = false;
97 protected boolean mIsMenuPending = false;
98 protected boolean mIsDialogPending = false;
99 protected boolean responseNeeded = true;
100 protected boolean launchBrowser = false;
101 protected BrowserSettings mBrowserSettings = null;
102 protected LinkedList<DelayedCmd> mCmdsQ = null;
103 protected boolean mCmdInProgress = false;
104 protected int mStkServiceState = STATE_UNKNOWN;
105 protected int mSetupMenuState = STATE_UNKNOWN;
106 protected int mMenuState = StkMenuActivity.STATE_INIT;
107 protected int mOpCode = -1;
108 private Activity mActivityInstance = null;
109 private Activity mDialogInstance = null;
110 private Activity mMainActivityInstance = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700111 private int mSlotId = 0;
Preeti Ahuja95919342013-10-01 18:18:55 -0700112 private SetupEventListSettings mSetupEventListSettings = null;
113 private boolean mClearSelectItem = false;
114 private boolean mDisplayTextDlgIsVisibile = false;
115 private CatCmdMessage mCurrentSetupEventCmd = null;
Preeti Ahuja560be362014-11-25 19:38:24 -0800116 private CatCmdMessage mIdleModeTextCmd = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700117 final synchronized void setPendingActivityInstance(Activity act) {
118 CatLog.d(this, "setPendingActivityInstance act : " + mSlotId + ", " + act);
119 callSetActivityInstMsg(OP_SET_ACT_INST, mSlotId, act);
120 }
121 final synchronized Activity getPendingActivityInstance() {
122 CatLog.d(this, "getPendingActivityInstance act : " + mSlotId + ", " +
123 mActivityInstance);
124 return mActivityInstance;
125 }
126 final synchronized void setPendingDialogInstance(Activity act) {
127 CatLog.d(this, "setPendingDialogInstance act : " + mSlotId + ", " + act);
128 callSetActivityInstMsg(OP_SET_DAL_INST, mSlotId, act);
129 }
130 final synchronized Activity getPendingDialogInstance() {
131 CatLog.d(this, "getPendingDialogInstance act : " + mSlotId + ", " +
132 mDialogInstance);
133 return mDialogInstance;
134 }
135 final synchronized void setMainActivityInstance(Activity act) {
136 CatLog.d(this, "setMainActivityInstance act : " + mSlotId + ", " + act);
137 callSetActivityInstMsg(OP_SET_MAINACT_INST, mSlotId, act);
138 }
139 final synchronized Activity getMainActivityInstance() {
140 CatLog.d(this, "getMainActivityInstance act : " + mSlotId + ", " +
141 mMainActivityInstance);
142 return mMainActivityInstance;
143 }
144 }
145
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800146 private volatile Looper mServiceLooper;
147 private volatile ServiceHandler mServiceHandler;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800148 private Context mContext = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800149 private NotificationManager mNotificationManager = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800150 static StkAppService sInstance = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700151 private AppInterface[] mStkService = null;
152 private StkContext[] mStkContext = null;
153 private int mSimCount = 0;
Preeti Ahuja560be362014-11-25 19:38:24 -0800154 private PowerManager mPowerManager = null;
155 private StkCmdReceiver mStkCmdReceiver = null;
Preeti Ahuja95919342013-10-01 18:18:55 -0700156
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800157 // Used for setting FLAG_ACTIVITY_NO_USER_ACTION when
158 // creating an intent.
159 private enum InitiatedByUserAction {
160 yes, // The action was started via a user initiated action
161 unknown, // Not known for sure if user initated the action
162 }
163
164 // constants
165 static final String OPCODE = "op";
166 static final String CMD_MSG = "cmd message";
167 static final String RES_ID = "response id";
168 static final String MENU_SELECTION = "menu selection";
169 static final String INPUT = "input";
170 static final String HELP = "help";
171 static final String CONFIRMATION = "confirm";
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500172 static final String CHOICE = "choice";
Wink Savillee68857d2014-10-17 15:23:05 -0700173 static final String SLOT_ID = "SLOT_ID";
174 static final String STK_CMD = "STK CMD";
175 static final String STK_DIALOG_URI = "stk://com.android.stk/dialog/";
176 static final String STK_MENU_URI = "stk://com.android.stk/menu/";
177 static final String STK_INPUT_URI = "stk://com.android.stk/input/";
178 static final String STK_TONE_URI = "stk://com.android.stk/tone/";
Preeti Ahuja95919342013-10-01 18:18:55 -0700179
180 // These below constants are used for SETUP_EVENT_LIST
181 static final String SETUP_EVENT_TYPE = "event";
182 static final String SETUP_EVENT_CAUSE = "cause";
183
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800184 // operations ids for different service functionality.
185 static final int OP_CMD = 1;
186 static final int OP_RESPONSE = 2;
187 static final int OP_LAUNCH_APP = 3;
188 static final int OP_END_SESSION = 4;
189 static final int OP_BOOT_COMPLETED = 5;
190 private static final int OP_DELAYED_MSG = 6;
Wink Saville94e982b2014-07-11 07:38:14 -0700191 static final int OP_CARD_STATUS_CHANGED = 7;
Wink Savillee68857d2014-10-17 15:23:05 -0700192 static final int OP_SET_ACT_INST = 8;
193 static final int OP_SET_DAL_INST = 9;
194 static final int OP_SET_MAINACT_INST = 10;
Preeti Ahujab3d0e612014-11-20 13:29:25 -0800195 static final int OP_LOCALE_CHANGED = 11;
196 static final int OP_ALPHA_NOTIFY = 12;
Preeti Ahuja560be362014-11-25 19:38:24 -0800197 static final int OP_IDLE_SCREEN = 13;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800198
Preeti Ahuja95919342013-10-01 18:18:55 -0700199 //Invalid SetupEvent
200 static final int INVALID_SETUP_EVENT = 0xFF;
201
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800202 // Response ids
203 static final int RES_ID_MENU_SELECTION = 11;
204 static final int RES_ID_INPUT = 12;
205 static final int RES_ID_CONFIRM = 13;
206 static final int RES_ID_DONE = 14;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500207 static final int RES_ID_CHOICE = 15;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800208
209 static final int RES_ID_TIMEOUT = 20;
210 static final int RES_ID_BACKWARD = 21;
211 static final int RES_ID_END_SESSION = 22;
212 static final int RES_ID_EXIT = 23;
213
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500214 static final int YES = 1;
215 static final int NO = 0;
216
Wink Savillee68857d2014-10-17 15:23:05 -0700217 static final int STATE_UNKNOWN = -1;
218 static final int STATE_NOT_EXIST = 0;
219 static final int STATE_EXIST = 1;
Wink Saville79085fc2009-06-09 10:27:23 -0700220
Wink Savillee68857d2014-10-17 15:23:05 -0700221 private static final String PACKAGE_NAME = "com.android.stk";
222 private static final String STK_MENU_ACTIVITY_NAME = PACKAGE_NAME + ".StkMenuActivity";
223 private static final String STK_INPUT_ACTIVITY_NAME = PACKAGE_NAME + ".StkInputActivity";
224 private static final String STK_DIALOG_ACTIVITY_NAME = PACKAGE_NAME + ".StkDialogActivity";
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800225 // Notification id used to display Idle Mode text in NotificationManager.
226 private static final int STK_NOTIFICATION_ID = 333;
fionaxu2c91c752017-04-21 18:11:57 -0700227 // Notification channel containing all mobile service messages notifications.
228 private static final String STK_NOTIFICATION_CHANNEL_ID = "mobileServiceMessages";
229
Wink Savillee68857d2014-10-17 15:23:05 -0700230 private static final String LOG_TAG = new Object(){}.getClass().getEnclosingClass().getName();
Wink Saville79085fc2009-06-09 10:27:23 -0700231
232 // Inner class used for queuing telephony messages (proactive commands,
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800233 // session end) while the service is busy processing a previous message.
234 private class DelayedCmd {
235 // members
236 int id;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -0700237 CatCmdMessage msg;
Wink Savillee68857d2014-10-17 15:23:05 -0700238 int slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800239
Wink Savillee68857d2014-10-17 15:23:05 -0700240 DelayedCmd(int id, CatCmdMessage msg, int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800241 this.id = id;
242 this.msg = msg;
Wink Savillee68857d2014-10-17 15:23:05 -0700243 this.slotId = slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800244 }
245 }
246
Preeti Ahujaa7cdca22013-10-01 18:20:56 -0700247 // system property to set the STK specific default url for launch browser proactive cmds
248 private static final String STK_BROWSER_DEFAULT_URL_SYSPROP = "persist.radio.stk.default_url";
249
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800250 @Override
251 public void onCreate() {
Wink Savillee68857d2014-10-17 15:23:05 -0700252 CatLog.d(LOG_TAG, "onCreate()+");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800253 // Initialize members
Wink Savillee68857d2014-10-17 15:23:05 -0700254 int i = 0;
255 mContext = getBaseContext();
256 mSimCount = TelephonyManager.from(mContext).getSimCount();
257 CatLog.d(LOG_TAG, "simCount: " + mSimCount);
258 mStkService = new AppInterface[mSimCount];
259 mStkContext = new StkContext[mSimCount];
Preeti Ahuja560be362014-11-25 19:38:24 -0800260 mPowerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
261 mStkCmdReceiver = new StkCmdReceiver();
262 registerReceiver(mStkCmdReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
Wink Savillee68857d2014-10-17 15:23:05 -0700263 for (i = 0; i < mSimCount; i++) {
264 CatLog.d(LOG_TAG, "slotId: " + i);
Legler Wuaeefef52014-10-27 00:57:18 +0800265 mStkService[i] = CatService.getInstance(i);
Wink Savillee68857d2014-10-17 15:23:05 -0700266 mStkContext[i] = new StkContext();
267 mStkContext[i].mSlotId = i;
268 mStkContext[i].mCmdsQ = new LinkedList<DelayedCmd>();
269 }
270
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800271 Thread serviceThread = new Thread(null, this, "Stk App Service");
272 serviceThread.start();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800273 mNotificationManager = (NotificationManager) mContext
274 .getSystemService(Context.NOTIFICATION_SERVICE);
275 sInstance = this;
276 }
277
278 @Override
279 public void onStart(Intent intent, int startId) {
Wink Savillee68857d2014-10-17 15:23:05 -0700280 if (intent == null) {
281 CatLog.d(LOG_TAG, "StkAppService onStart intent is null so return");
Banavathu, Srinivas Naik87cda962012-07-17 15:32:44 +0530282 return;
283 }
284
Wink Savillee68857d2014-10-17 15:23:05 -0700285 Bundle args = intent.getExtras();
286 if (args == null) {
287 CatLog.d(LOG_TAG, "StkAppService onStart args is null so return");
288 return;
289 }
290
291 int op = args.getInt(OPCODE);
292 int slotId = 0;
293 int i = 0;
294 if (op != OP_BOOT_COMPLETED) {
295 slotId = args.getInt(SLOT_ID);
296 }
Cuihtlauac ALVARADObde7f032015-05-29 16:25:12 +0200297 CatLog.d(LOG_TAG, "onStart sim id: " + slotId + ", op: " + op + ", *****");
Wink Savillee68857d2014-10-17 15:23:05 -0700298 if ((slotId >= 0 && slotId < mSimCount) && mStkService[slotId] == null) {
Legler Wuaeefef52014-10-27 00:57:18 +0800299 mStkService[slotId] = CatService.getInstance(slotId);
Wink Savillee68857d2014-10-17 15:23:05 -0700300 if (mStkService[slotId] == null) {
301 CatLog.d(LOG_TAG, "mStkService is: " + mStkContext[slotId].mStkServiceState);
302 mStkContext[slotId].mStkServiceState = STATE_NOT_EXIST;
303 //Check other StkService state.
304 //If all StkServices are not available, stop itself and uninstall apk.
305 for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) {
306 if (i != slotId
Tsukasa Goto029332b2016-10-05 17:12:06 +0900307 && (mStkService[i] != null)
Wink Savillee68857d2014-10-17 15:23:05 -0700308 && (mStkContext[i].mStkServiceState == STATE_UNKNOWN
309 || mStkContext[i].mStkServiceState == STATE_EXIST)) {
310 break;
311 }
312 }
313 } else {
314 mStkContext[slotId].mStkServiceState = STATE_EXIST;
315 }
316 if (i == mSimCount) {
317 stopSelf();
318 StkAppInstaller.unInstall(mContext);
319 return;
320 }
321 }
322
Banavathu, Srinivas Naik87cda962012-07-17 15:32:44 +0530323 waitForLooper();
John Wang62acae42009-10-08 11:20:23 -0700324
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800325 Message msg = mServiceHandler.obtainMessage();
Wink Savillee68857d2014-10-17 15:23:05 -0700326 msg.arg1 = op;
327 msg.arg2 = slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800328 switch(msg.arg1) {
329 case OP_CMD:
330 msg.obj = args.getParcelable(CMD_MSG);
331 break;
332 case OP_RESPONSE:
Wink Saville94e982b2014-07-11 07:38:14 -0700333 case OP_CARD_STATUS_CHANGED:
Preeti Ahuja95919342013-10-01 18:18:55 -0700334 case OP_LOCALE_CHANGED:
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +0530335 case OP_ALPHA_NOTIFY:
Preeti Ahuja560be362014-11-25 19:38:24 -0800336 case OP_IDLE_SCREEN:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800337 msg.obj = args;
338 /* falls through */
339 case OP_LAUNCH_APP:
340 case OP_END_SESSION:
341 case OP_BOOT_COMPLETED:
342 break;
343 default:
344 return;
345 }
346 mServiceHandler.sendMessage(msg);
347 }
348
349 @Override
350 public void onDestroy() {
Wink Savillee68857d2014-10-17 15:23:05 -0700351 CatLog.d(LOG_TAG, "onDestroy()");
Preeti Ahuja560be362014-11-25 19:38:24 -0800352 if (mStkCmdReceiver != null) {
353 unregisterReceiver(mStkCmdReceiver);
354 mStkCmdReceiver = null;
355 }
356 mPowerManager = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800357 waitForLooper();
358 mServiceLooper.quit();
359 }
360
361 @Override
362 public IBinder onBind(Intent intent) {
363 return null;
364 }
365
366 public void run() {
367 Looper.prepare();
368
369 mServiceLooper = Looper.myLooper();
370 mServiceHandler = new ServiceHandler();
371
372 Looper.loop();
373 }
374
375 /*
376 * Package api used by StkMenuActivity to indicate if its on the foreground.
377 */
Wink Savillee68857d2014-10-17 15:23:05 -0700378 void indicateMenuVisibility(boolean visibility, int slotId) {
379 if (slotId >= 0 && slotId < mSimCount) {
380 mStkContext[slotId].mMenuIsVisible = visibility;
381 }
382 }
383
Preeti Ahuja95919342013-10-01 18:18:55 -0700384 /*
385 * Package api used by StkDialogActivity to indicate if its on the foreground.
386 */
387 void setDisplayTextDlgVisibility(boolean visibility, int slotId) {
388 if (slotId >= 0 && slotId < mSimCount) {
389 mStkContext[slotId].mDisplayTextDlgIsVisibile = visibility;
390 }
391 }
392
Wink Savillee68857d2014-10-17 15:23:05 -0700393 boolean isInputPending(int slotId) {
394 if (slotId >= 0 && slotId < mSimCount) {
395 CatLog.d(LOG_TAG, "isInputFinishBySrv: " + mStkContext[slotId].mIsInputPending);
396 return mStkContext[slotId].mIsInputPending;
397 }
398 return false;
399 }
400
401 boolean isMenuPending(int slotId) {
402 if (slotId >= 0 && slotId < mSimCount) {
403 CatLog.d(LOG_TAG, "isMenuPending: " + mStkContext[slotId].mIsMenuPending);
404 return mStkContext[slotId].mIsMenuPending;
405 }
406 return false;
407 }
408
409 boolean isDialogPending(int slotId) {
410 if (slotId >= 0 && slotId < mSimCount) {
411 CatLog.d(LOG_TAG, "isDialogPending: " + mStkContext[slotId].mIsDialogPending);
412 return mStkContext[slotId].mIsDialogPending;
413 }
414 return false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800415 }
416
417 /*
418 * Package api used by StkMenuActivity to get its Menu parameter.
419 */
Wink Savillee68857d2014-10-17 15:23:05 -0700420 Menu getMenu(int slotId) {
421 CatLog.d(LOG_TAG, "StkAppService, getMenu, sim id: " + slotId);
422 if (slotId >=0 && slotId < mSimCount) {
423 return mStkContext[slotId].mCurrentMenu;
424 } else {
425 return null;
426 }
427 }
428
429 /*
430 * Package api used by StkMenuActivity to get its Main Menu parameter.
431 */
432 Menu getMainMenu(int slotId) {
433 CatLog.d(LOG_TAG, "StkAppService, getMainMenu, sim id: " + slotId);
w30234a08cffe2015-02-04 15:13:25 -0800434 if (slotId >=0 && slotId < mSimCount && (mStkContext[slotId].mMainCmd != null)) {
Wink Savillee68857d2014-10-17 15:23:05 -0700435 return mStkContext[slotId].mMainCmd.getMenu();
436 } else {
437 return null;
438 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800439 }
440
441 /*
442 * Package api used by UI Activities and Dialogs to communicate directly
443 * with the service to deliver state information and parameters.
444 */
445 static StkAppService getInstance() {
446 return sInstance;
447 }
448
449 private void waitForLooper() {
450 while (mServiceHandler == null) {
451 synchronized (this) {
452 try {
453 wait(100);
454 } catch (InterruptedException e) {
455 }
456 }
457 }
458 }
459
460 private final class ServiceHandler extends Handler {
461 @Override
462 public void handleMessage(Message msg) {
Wink Savillee68857d2014-10-17 15:23:05 -0700463 if(null == msg) {
464 CatLog.d(LOG_TAG, "ServiceHandler handleMessage msg is null");
465 return;
466 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800467 int opcode = msg.arg1;
Wink Savillee68857d2014-10-17 15:23:05 -0700468 int slotId = msg.arg2;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800469
Wink Savillee68857d2014-10-17 15:23:05 -0700470 CatLog.d(LOG_TAG, "handleMessage opcode[" + opcode + "], sim id[" + slotId + "]");
471 if (opcode == OP_CMD && msg.obj != null &&
472 ((CatCmdMessage)msg.obj).getCmdType()!= null) {
473 CatLog.d(LOG_TAG, "cmdName[" + ((CatCmdMessage)msg.obj).getCmdType().name() + "]");
474 }
475 mStkContext[slotId].mOpCode = opcode;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800476 switch (opcode) {
477 case OP_LAUNCH_APP:
Wink Savillee68857d2014-10-17 15:23:05 -0700478 if (mStkContext[slotId].mMainCmd == null) {
479 CatLog.d(LOG_TAG, "mMainCmd is null");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800480 // nothing todo when no SET UP MENU command didn't arrive.
481 return;
482 }
Wink Savillee68857d2014-10-17 15:23:05 -0700483 CatLog.d(LOG_TAG, "handleMessage OP_LAUNCH_APP - mCmdInProgress[" +
484 mStkContext[slotId].mCmdInProgress + "]");
485
486 //If there is a pending activity for the slot id,
487 //just finish it and create a new one to handle the pending command.
488 cleanUpInstanceStackBySlot(slotId);
489
Wink Savillee68857d2014-10-17 15:23:05 -0700490 CatLog.d(LOG_TAG, "Current cmd type: " +
491 mStkContext[slotId].mCurrentCmd.getCmdType());
492 //Restore the last command from stack by slot id.
493 restoreInstanceFromStackBySlot(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800494 break;
495 case OP_CMD:
Wink Savillee68857d2014-10-17 15:23:05 -0700496 CatLog.d(LOG_TAG, "[OP_CMD]");
Alex Yakavenkad41f1d92010-07-12 14:13:13 -0700497 CatCmdMessage cmdMsg = (CatCmdMessage) msg.obj;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800498 // There are two types of commands:
499 // 1. Interactive - user's response is required.
500 // 2. Informative - display a message, no interaction with the user.
501 //
Wink Saville79085fc2009-06-09 10:27:23 -0700502 // Informative commands can be handled immediately without any delay.
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800503 // Interactive commands can't override each other. So if a command
504 // is already in progress, we need to queue the next command until
505 // the user has responded or a timeout expired.
506 if (!isCmdInteractive(cmdMsg)) {
Wink Savillee68857d2014-10-17 15:23:05 -0700507 handleCmd(cmdMsg, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800508 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700509 if (!mStkContext[slotId].mCmdInProgress) {
510 mStkContext[slotId].mCmdInProgress = true;
511 handleCmd((CatCmdMessage) msg.obj, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800512 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700513 CatLog.d(LOG_TAG, "[Interactive][in progress]");
514 mStkContext[slotId].mCmdsQ.addLast(new DelayedCmd(OP_CMD,
515 (CatCmdMessage) msg.obj, slotId));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800516 }
517 }
518 break;
519 case OP_RESPONSE:
Preeti Ahuja414bc412013-06-25 19:31:49 -0700520 handleCmdResponse((Bundle) msg.obj, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800521 // call delayed commands if needed.
Wink Savillee68857d2014-10-17 15:23:05 -0700522 if (mStkContext[slotId].mCmdsQ.size() != 0) {
523 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800524 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700525 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800526 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800527 break;
528 case OP_END_SESSION:
Wink Savillee68857d2014-10-17 15:23:05 -0700529 if (!mStkContext[slotId].mCmdInProgress) {
530 mStkContext[slotId].mCmdInProgress = true;
531 handleSessionEnd(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800532 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700533 mStkContext[slotId].mCmdsQ.addLast(
534 new DelayedCmd(OP_END_SESSION, null, slotId));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800535 }
536 break;
537 case OP_BOOT_COMPLETED:
Wink Savillee68857d2014-10-17 15:23:05 -0700538 CatLog.d(LOG_TAG, " OP_BOOT_COMPLETED");
539 int i = 0;
540 for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) {
541 if (mStkContext[i].mMainCmd != null) {
542 break;
543 }
544 }
545 if (i == mSimCount) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800546 StkAppInstaller.unInstall(mContext);
547 }
548 break;
549 case OP_DELAYED_MSG:
Wink Savillee68857d2014-10-17 15:23:05 -0700550 handleDelayedCmd(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800551 break;
Wink Saville94e982b2014-07-11 07:38:14 -0700552 case OP_CARD_STATUS_CHANGED:
Wink Savillee68857d2014-10-17 15:23:05 -0700553 CatLog.d(LOG_TAG, "Card/Icc Status change received");
554 handleCardStatusChangeAndIccRefresh((Bundle) msg.obj, slotId);
555 break;
556 case OP_SET_ACT_INST:
557 Activity act = new Activity();
558 act = (Activity) msg.obj;
559 CatLog.d(LOG_TAG, "Set activity instance. " + act);
560 mStkContext[slotId].mActivityInstance = act;
561 break;
562 case OP_SET_DAL_INST:
563 Activity dal = new Activity();
564 CatLog.d(LOG_TAG, "Set dialog instance. " + dal);
565 dal = (Activity) msg.obj;
566 mStkContext[slotId].mDialogInstance = dal;
567 break;
568 case OP_SET_MAINACT_INST:
569 Activity mainAct = new Activity();
570 mainAct = (Activity) msg.obj;
571 CatLog.d(LOG_TAG, "Set activity instance. " + mainAct);
572 mStkContext[slotId].mMainActivityInstance = mainAct;
Wink Saville94e982b2014-07-11 07:38:14 -0700573 break;
Preeti Ahuja95919342013-10-01 18:18:55 -0700574 case OP_LOCALE_CHANGED:
575 CatLog.d(this, "Locale Changed");
Yuta Ui1481b172016-02-03 15:34:31 +0900576 for (int slot = PhoneConstants.SIM_ID_1; slot < mSimCount; slot++) {
577 checkForSetupEvent(LANGUAGE_SELECTION_EVENT, (Bundle) msg.obj, slot);
578 }
Preeti Ahuja95919342013-10-01 18:18:55 -0700579 break;
Preeti Ahuja0f4cf2f2012-08-09 11:45:08 +0530580 case OP_ALPHA_NOTIFY:
581 handleAlphaNotify((Bundle) msg.obj);
582 break;
Preeti Ahuja560be362014-11-25 19:38:24 -0800583 case OP_IDLE_SCREEN:
584 for (int slot = 0; slot < mSimCount; slot++) {
585 if (mStkContext[slot] != null) {
586 handleIdleScreen(slot);
587 }
588 }
589 break;
Wink Saville94e982b2014-07-11 07:38:14 -0700590 }
591 }
592
Wink Savillee68857d2014-10-17 15:23:05 -0700593 private void handleCardStatusChangeAndIccRefresh(Bundle args, int slotId) {
Wink Saville94e982b2014-07-11 07:38:14 -0700594 boolean cardStatus = args.getBoolean(AppInterface.CARD_STATUS);
595
Wink Savillee68857d2014-10-17 15:23:05 -0700596 CatLog.d(LOG_TAG, "CardStatus: " + cardStatus);
Wink Saville94e982b2014-07-11 07:38:14 -0700597 if (cardStatus == false) {
Wink Savillee68857d2014-10-17 15:23:05 -0700598 CatLog.d(LOG_TAG, "CARD is ABSENT");
Wink Saville94e982b2014-07-11 07:38:14 -0700599 // Uninstall STKAPP, Clear Idle text, Stop StkAppService
Wink Savillee68857d2014-10-17 15:23:05 -0700600 mNotificationManager.cancel(getNotificationId(slotId));
601 if (isAllOtherCardsAbsent(slotId)) {
602 CatLog.d(LOG_TAG, "All CARDs are ABSENT");
603 StkAppInstaller.unInstall(mContext);
604 stopSelf();
605 }
Wink Saville94e982b2014-07-11 07:38:14 -0700606 } else {
607 IccRefreshResponse state = new IccRefreshResponse();
608 state.refreshResult = args.getInt(AppInterface.REFRESH_RESULT);
609
Wink Savillee68857d2014-10-17 15:23:05 -0700610 CatLog.d(LOG_TAG, "Icc Refresh Result: "+ state.refreshResult);
Wink Saville94e982b2014-07-11 07:38:14 -0700611 if ((state.refreshResult == IccRefreshResponse.REFRESH_RESULT_INIT) ||
612 (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET)) {
613 // Clear Idle Text
Wink Savillee68857d2014-10-17 15:23:05 -0700614 mNotificationManager.cancel(getNotificationId(slotId));
Wink Saville94e982b2014-07-11 07:38:14 -0700615 }
616
617 if (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET) {
618 // Uninstall STkmenu
Wink Savillee68857d2014-10-17 15:23:05 -0700619 if (isAllOtherCardsAbsent(slotId)) {
620 StkAppInstaller.unInstall(mContext);
621 }
622 mStkContext[slotId].mCurrentMenu = null;
623 mStkContext[slotId].mMainCmd = null;
Wink Saville94e982b2014-07-11 07:38:14 -0700624 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800625 }
626 }
627 }
Wink Savillee68857d2014-10-17 15:23:05 -0700628 /*
629 * Check if all SIMs are absent except the id of slot equals "slotId".
630 */
631 private boolean isAllOtherCardsAbsent(int slotId) {
632 TelephonyManager mTm = (TelephonyManager) mContext.getSystemService(
633 Context.TELEPHONY_SERVICE);
634 int i = 0;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800635
Wink Savillee68857d2014-10-17 15:23:05 -0700636 for (i = 0; i < mSimCount; i++) {
637 if (i != slotId && mTm.hasIccCard(i)) {
638 break;
639 }
640 }
641 if (i == mSimCount) {
642 return true;
643 } else {
644 return false;
645 }
646 }
Preeti Ahuja95919342013-10-01 18:18:55 -0700647
Preeti Ahuja560be362014-11-25 19:38:24 -0800648 /*
649 * If the device is not in an interactive state, we can assume
650 * that the screen is idle.
651 */
652 private boolean isScreenIdle() {
653 return (!mPowerManager.isInteractive());
654 }
655
656 private void handleIdleScreen(int slotId) {
657
658 // If the idle screen event is present in the list need to send the
659 // response to SIM.
660 CatLog.d(this, "Need to send IDLE SCREEN Available event to SIM");
661 checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId);
662
663 if (mStkContext[slotId].mIdleModeTextCmd != null) {
664 launchIdleText(slotId);
665 }
666 }
667
668 private void sendScreenBusyResponse(int slotId) {
669 if (mStkContext[slotId].mCurrentCmd == null) {
670 return;
671 }
672 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd);
673 CatLog.d(this, "SCREEN_BUSY");
674 resMsg.setResultCode(ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS);
675 mStkService[slotId].onCmdResponse(resMsg);
676 if (mStkContext[slotId].mCmdsQ.size() != 0) {
677 callDelayedMsg(slotId);
678 } else {
679 mStkContext[slotId].mCmdInProgress = false;
680 }
681 }
682
Preeti Ahuja95919342013-10-01 18:18:55 -0700683 private void sendResponse(int resId, int slotId, boolean confirm) {
684 Message msg = mServiceHandler.obtainMessage();
685 msg.arg1 = OP_RESPONSE;
Takanori Nakano49b12722016-02-16 14:34:14 +0900686 msg.arg2 = slotId;
Preeti Ahuja95919342013-10-01 18:18:55 -0700687 Bundle args = new Bundle();
688 args.putInt(StkAppService.RES_ID, resId);
Preeti Ahuja95919342013-10-01 18:18:55 -0700689 args.putBoolean(StkAppService.CONFIRMATION, confirm);
690 msg.obj = args;
691 mServiceHandler.sendMessage(msg);
692 }
693
Alex Yakavenkad41f1d92010-07-12 14:13:13 -0700694 private boolean isCmdInteractive(CatCmdMessage cmd) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800695 switch (cmd.getCmdType()) {
696 case SEND_DTMF:
697 case SEND_SMS:
698 case SEND_SS:
699 case SEND_USSD:
700 case SET_UP_IDLE_MODE_TEXT:
701 case SET_UP_MENU:
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500702 case CLOSE_CHANNEL:
703 case RECEIVE_DATA:
704 case SEND_DATA:
Preeti Ahuja95919342013-10-01 18:18:55 -0700705 case SET_UP_EVENT_LIST:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800706 return false;
707 }
708
709 return true;
710 }
711
Wink Savillee68857d2014-10-17 15:23:05 -0700712 private void handleDelayedCmd(int slotId) {
713 CatLog.d(LOG_TAG, "handleDelayedCmd, slotId: " + slotId);
714 if (mStkContext[slotId].mCmdsQ.size() != 0) {
715 DelayedCmd cmd = mStkContext[slotId].mCmdsQ.poll();
716 if (cmd != null) {
717 CatLog.d(LOG_TAG, "handleDelayedCmd - queue size: " +
718 mStkContext[slotId].mCmdsQ.size() +
719 " id: " + cmd.id + "sim id: " + cmd.slotId);
720 switch (cmd.id) {
721 case OP_CMD:
722 handleCmd(cmd.msg, cmd.slotId);
723 break;
724 case OP_END_SESSION:
725 handleSessionEnd(cmd.slotId);
726 break;
727 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800728 }
729 }
730 }
731
Wink Savillee68857d2014-10-17 15:23:05 -0700732 private void callDelayedMsg(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800733 Message msg = mServiceHandler.obtainMessage();
734 msg.arg1 = OP_DELAYED_MSG;
Wink Savillee68857d2014-10-17 15:23:05 -0700735 msg.arg2 = slotId;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800736 mServiceHandler.sendMessage(msg);
737 }
738
Wink Savillee68857d2014-10-17 15:23:05 -0700739 private void callSetActivityInstMsg(int inst_type, int slotId, Object obj) {
740 Message msg = mServiceHandler.obtainMessage();
741 msg.obj = obj;
742 msg.arg1 = inst_type;
743 msg.arg2 = slotId;
744 mServiceHandler.sendMessage(msg);
745 }
746
747 private void handleSessionEnd(int slotId) {
Legler Wuaeefef52014-10-27 00:57:18 +0800748 // We should finish all pending activity if receiving END SESSION command.
749 cleanUpInstanceStackBySlot(slotId);
750
Wink Savillee68857d2014-10-17 15:23:05 -0700751 mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
752 CatLog.d(LOG_TAG, "[handleSessionEnd] - mCurrentCmd changed to mMainCmd!.");
753 mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mMainCmd;
754 CatLog.d(LOG_TAG, "slotId: " + slotId + ", mMenuState: " +
755 mStkContext[slotId].mMenuState);
756
757 mStkContext[slotId].mIsInputPending = false;
758 mStkContext[slotId].mIsMenuPending = false;
759 mStkContext[slotId].mIsDialogPending = false;
760
Wink Savillee68857d2014-10-17 15:23:05 -0700761 if (mStkContext[slotId].mMainCmd == null) {
762 CatLog.d(LOG_TAG, "[handleSessionEnd][mMainCmd is null!]");
763 }
764 mStkContext[slotId].lastSelectedItem = null;
Wink Saville79085fc2009-06-09 10:27:23 -0700765 // In case of SET UP MENU command which removed the app, don't
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800766 // update the current menu member.
Wink Savillee68857d2014-10-17 15:23:05 -0700767 if (mStkContext[slotId].mCurrentMenu != null && mStkContext[slotId].mMainCmd != null) {
768 mStkContext[slotId].mCurrentMenu = mStkContext[slotId].mMainCmd.getMenu();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800769 }
Wink Savillee68857d2014-10-17 15:23:05 -0700770 CatLog.d(LOG_TAG, "[handleSessionEnd][mMenuState]" + mStkContext[slotId].mMenuIsVisible);
771 // In mutiple instance architecture, the main menu for slotId will be finished when user
772 // goes to the Stk menu of the other SIM. So, we should launch a new instance for the
773 // main menu if the main menu instance has been finished.
774 // If the current menu is secondary menu, we should launch main menu.
775 if (StkMenuActivity.STATE_SECONDARY == mStkContext[slotId].mMenuState) {
776 launchMenuActivity(null, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800777 }
Wink Savillee68857d2014-10-17 15:23:05 -0700778 if (mStkContext[slotId].mCmdsQ.size() != 0) {
779 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800780 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700781 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800782 }
783 // In case a launch browser command was just confirmed, launch that url.
Wink Savillee68857d2014-10-17 15:23:05 -0700784 if (mStkContext[slotId].launchBrowser) {
785 mStkContext[slotId].launchBrowser = false;
786 launchBrowser(mStkContext[slotId].mBrowserSettings);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800787 }
788 }
789
Preeti Ahuja560be362014-11-25 19:38:24 -0800790 // returns true if any Stk related activity already has focus on the screen
791 private boolean isTopOfStack() {
pkanwareab12f32017-02-06 08:35:03 -0800792 ActivityManager mActivityManager = (ActivityManager) mContext
Preeti Ahuja560be362014-11-25 19:38:24 -0800793 .getSystemService(ACTIVITY_SERVICE);
pkanwareab12f32017-02-06 08:35:03 -0800794 String currentPackageName = null;
795 List<RunningTaskInfo> tasks = mActivityManager.getRunningTasks(1);
796 if (tasks == null || tasks.get(0).topActivity == null) {
797 return false;
798 }
799 currentPackageName = tasks.get(0).topActivity.getPackageName();
Preeti Ahuja560be362014-11-25 19:38:24 -0800800 if (null != currentPackageName) {
801 return currentPackageName.equals(PACKAGE_NAME);
802 }
Preeti Ahuja560be362014-11-25 19:38:24 -0800803 return false;
804 }
805
Sooraj Sasindrana4160472016-10-12 16:28:25 -0700806 /**
807 * Get the boolean config from carrier config manager.
808 *
809 * @param context the context to get carrier service
810 * @param key config key defined in CarrierConfigManager
811 * @return boolean value of corresponding key.
812 */
813 private static boolean getBooleanCarrierConfig(Context context, String key) {
814 CarrierConfigManager configManager = (CarrierConfigManager) context.getSystemService(
815 Context.CARRIER_CONFIG_SERVICE);
816 PersistableBundle b = null;
817 if (configManager != null) {
818 b = configManager.getConfig();
819 }
820 if (b != null) {
821 return b.getBoolean(key);
822 } else {
823 // Return static default defined in CarrierConfigManager.
824 return CarrierConfigManager.getDefaultConfig().getBoolean(key);
825 }
826 }
827
Wink Savillee68857d2014-10-17 15:23:05 -0700828 private void handleCmd(CatCmdMessage cmdMsg, int slotId) {
Preeti Ahuja95919342013-10-01 18:18:55 -0700829
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800830 if (cmdMsg == null) {
831 return;
832 }
833 // save local reference for state tracking.
Wink Savillee68857d2014-10-17 15:23:05 -0700834 mStkContext[slotId].mCurrentCmd = cmdMsg;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800835 boolean waitForUsersResponse = true;
836
Wink Savillee68857d2014-10-17 15:23:05 -0700837 mStkContext[slotId].mIsInputPending = false;
838 mStkContext[slotId].mIsMenuPending = false;
839 mStkContext[slotId].mIsDialogPending = false;
840
841 CatLog.d(LOG_TAG,"[handleCmd]" + cmdMsg.getCmdType().name());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800842 switch (cmdMsg.getCmdType()) {
843 case DISPLAY_TEXT:
844 TextMessage msg = cmdMsg.geTextMessage();
Jeevaka Badrappan854a25c2012-12-01 16:32:03 +0200845 waitForUsersResponse = msg.responseNeeded;
Wink Savillee68857d2014-10-17 15:23:05 -0700846 if (mStkContext[slotId].lastSelectedItem != null) {
847 msg.title = mStkContext[slotId].lastSelectedItem;
848 } else if (mStkContext[slotId].mMainCmd != null){
849 msg.title = mStkContext[slotId].mMainCmd.getMenu().title;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800850 } else {
851 // TODO: get the carrier name from the SIM
852 msg.title = "";
853 }
Preeti Ahuja560be362014-11-25 19:38:24 -0800854 //If we receive a low priority Display Text and the device is
855 // not displaying any STK related activity and the screen is not idle
856 // ( that is, device is in an interactive state), then send a screen busy
857 // terminal response. Otherwise display the message. The existing
858 // displayed message shall be updated with the new display text
859 // proactive command (Refer to ETSI TS 102 384 section 27.22.4.1.4.4.2).
860 if (!(msg.isHighPriority || mStkContext[slotId].mMenuIsVisible
861 || mStkContext[slotId].mDisplayTextDlgIsVisibile || isTopOfStack())) {
862 if(!isScreenIdle()) {
863 CatLog.d(LOG_TAG, "Screen is not idle");
864 sendScreenBusyResponse(slotId);
865 } else {
866 launchTextDialog(slotId);
867 }
868 } else {
869 launchTextDialog(slotId);
870 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800871 break;
872 case SELECT_ITEM:
Wink Savillee68857d2014-10-17 15:23:05 -0700873 CatLog.d(LOG_TAG, "SELECT_ITEM +");
874 mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd;
875 mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu();
876 launchMenuActivity(cmdMsg.getMenu(), slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800877 break;
878 case SET_UP_MENU:
Wink Savillee68857d2014-10-17 15:23:05 -0700879 mStkContext[slotId].mCmdInProgress = false;
880 mStkContext[slotId].mMainCmd = mStkContext[slotId].mCurrentCmd;
881 mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd;
882 mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu();
883 CatLog.d(LOG_TAG, "SET_UP_MENU [" + removeMenu(slotId) + "]");
884
885 if (removeMenu(slotId)) {
886 int i = 0;
887 CatLog.d(LOG_TAG, "removeMenu() - Uninstall App");
888 mStkContext[slotId].mCurrentMenu = null;
Preeti Ahuja95919342013-10-01 18:18:55 -0700889 mStkContext[slotId].mMainCmd = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700890 //Check other setup menu state. If all setup menu are removed, uninstall apk.
891 for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) {
892 if (i != slotId
893 && (mStkContext[slotId].mSetupMenuState == STATE_UNKNOWN
894 || mStkContext[slotId].mSetupMenuState == STATE_EXIST)) {
895 CatLog.d(LOG_TAG, "Not Uninstall App:" + i + ","
896 + mStkContext[slotId].mSetupMenuState);
897 break;
898 }
899 }
900 if (i == mSimCount) {
901 StkAppInstaller.unInstall(mContext);
902 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800903 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700904 CatLog.d(LOG_TAG, "install App");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800905 StkAppInstaller.install(mContext);
906 }
Wink Savillee68857d2014-10-17 15:23:05 -0700907 if (mStkContext[slotId].mMenuIsVisible) {
908 launchMenuActivity(null, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800909 }
910 break;
911 case GET_INPUT:
912 case GET_INKEY:
Wink Savillee68857d2014-10-17 15:23:05 -0700913 launchInputActivity(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800914 break;
915 case SET_UP_IDLE_MODE_TEXT:
916 waitForUsersResponse = false;
Preeti Ahuja560be362014-11-25 19:38:24 -0800917 mStkContext[slotId].mIdleModeTextCmd = mStkContext[slotId].mCurrentCmd;
918 TextMessage idleModeText = mStkContext[slotId].mCurrentCmd.geTextMessage();
919 if (idleModeText == null) {
920 launchIdleText(slotId);
921 mStkContext[slotId].mIdleModeTextCmd = null;
922 }
923 mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
924 if ((mStkContext[slotId].mIdleModeTextCmd != null) && isScreenIdle()) {
925 CatLog.d(this, "set up idle mode");
926 launchIdleText(slotId);
927 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800928 break;
929 case SEND_DTMF:
930 case SEND_SMS:
931 case SEND_SS:
932 case SEND_USSD:
Preeti Ahuja95919342013-10-01 18:18:55 -0700933 case GET_CHANNEL_STATUS:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800934 waitForUsersResponse = false;
Wink Savillee68857d2014-10-17 15:23:05 -0700935 launchEventMessage(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800936 break;
937 case LAUNCH_BROWSER:
Ryuto Sawada0bdc7192016-04-18 12:10:56 +0900938 // The device setup process should not be interrupted by launching browser.
939 if (Settings.Global.getInt(mContext.getContentResolver(),
940 Settings.Global.DEVICE_PROVISIONED, 0) == 0) {
941 CatLog.d(this, "The command is not performed if the setup has not been completed.");
942 sendScreenBusyResponse(slotId);
943 break;
944 }
Sooraj Sasindrana4160472016-10-12 16:28:25 -0700945
946 /* Check if Carrier would not want to launch browser */
947 if (getBooleanCarrierConfig(mContext,
948 CarrierConfigManager.KEY_STK_DISABLE_LAUNCH_BROWSER_BOOL)) {
949 CatLog.d(this, "Browser is not launched as per carrier.");
950 sendResponse(RES_ID_DONE, slotId, true);
951 break;
952 }
953
Preeti Ahujaa7cdca22013-10-01 18:20:56 -0700954 TextMessage alphaId = mStkContext[slotId].mCurrentCmd.geTextMessage();
955 if ((mStkContext[slotId].mCurrentCmd.getBrowserSettings().mode
956 == LaunchBrowserMode.LAUNCH_IF_NOT_ALREADY_LAUNCHED) &&
957 ((alphaId == null) || TextUtils.isEmpty(alphaId.text))) {
958 // don't need user confirmation in this case
959 // just launch the browser or spawn a new tab
960 CatLog.d(this, "Browser mode is: launch if not already launched " +
961 "and user confirmation is not currently needed.\n" +
962 "supressing confirmation dialogue and confirming silently...");
963 mStkContext[slotId].launchBrowser = true;
964 mStkContext[slotId].mBrowserSettings =
965 mStkContext[slotId].mCurrentCmd.getBrowserSettings();
966 sendResponse(RES_ID_CONFIRM, slotId, true);
967 } else {
968 launchConfirmationDialog(alphaId, slotId);
969 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800970 break;
971 case SET_UP_CALL:
Preeti Ahujadd240102013-08-30 17:25:06 -0700972 TextMessage mesg = mStkContext[slotId].mCurrentCmd.getCallSettings().confirmMsg;
973 if((mesg != null) && (mesg.text == null || mesg.text.length() == 0)) {
974 mesg.text = getResources().getString(R.string.default_setup_call_msg);
975 }
976 CatLog.d(this, "SET_UP_CALL mesg.text " + mesg.text);
977 launchConfirmationDialog(mesg, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800978 break;
979 case PLAY_TONE:
Wink Savillee68857d2014-10-17 15:23:05 -0700980 launchToneDialog(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800981 break;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500982 case OPEN_CHANNEL:
Wink Savillee68857d2014-10-17 15:23:05 -0700983 launchOpenChannelDialog(slotId);
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500984 break;
985 case CLOSE_CHANNEL:
986 case RECEIVE_DATA:
987 case SEND_DATA:
Wink Savillee68857d2014-10-17 15:23:05 -0700988 TextMessage m = mStkContext[slotId].mCurrentCmd.geTextMessage();
Kazuhiro Ondo764167c2011-10-21 16:05:05 -0500989
990 if ((m != null) && (m.text == null)) {
991 switch(cmdMsg.getCmdType()) {
992 case CLOSE_CHANNEL:
993 m.text = getResources().getString(R.string.default_close_channel_msg);
994 break;
995 case RECEIVE_DATA:
996 m.text = getResources().getString(R.string.default_receive_data_msg);
997 break;
998 case SEND_DATA:
999 m.text = getResources().getString(R.string.default_send_data_msg);
1000 break;
1001 }
1002 }
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001003 /*
1004 * Display indication in the form of a toast to the user if required.
1005 */
Wink Savillee68857d2014-10-17 15:23:05 -07001006 launchEventMessage(slotId);
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001007 break;
Preeti Ahuja95919342013-10-01 18:18:55 -07001008 case SET_UP_EVENT_LIST:
1009 mStkContext[slotId].mSetupEventListSettings =
1010 mStkContext[slotId].mCurrentCmd.getSetEventList();
1011 mStkContext[slotId].mCurrentSetupEventCmd = mStkContext[slotId].mCurrentCmd;
1012 mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd;
Preeti Ahuja560be362014-11-25 19:38:24 -08001013 if (isScreenIdle()) {
1014 CatLog.d(this," Check if IDLE_SCREEN_AVAILABLE_EVENT is present in List");
1015 checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId);
1016 }
Preeti Ahuja95919342013-10-01 18:18:55 -07001017 break;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001018 }
1019
1020 if (!waitForUsersResponse) {
Wink Savillee68857d2014-10-17 15:23:05 -07001021 if (mStkContext[slotId].mCmdsQ.size() != 0) {
1022 callDelayedMsg(slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001023 } else {
Wink Savillee68857d2014-10-17 15:23:05 -07001024 mStkContext[slotId].mCmdInProgress = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001025 }
1026 }
1027 }
1028
Wink Savillee68857d2014-10-17 15:23:05 -07001029 private void handleCmdResponse(Bundle args, int slotId) {
1030 CatLog.d(LOG_TAG, "handleCmdResponse, sim id: " + slotId);
1031 if (mStkContext[slotId].mCurrentCmd == null) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001032 return;
1033 }
Wink Savillee68857d2014-10-17 15:23:05 -07001034
1035 if (mStkService[slotId] == null) {
Legler Wuaeefef52014-10-27 00:57:18 +08001036 mStkService[slotId] = CatService.getInstance(slotId);
Wink Savillee68857d2014-10-17 15:23:05 -07001037 if (mStkService[slotId] == null) {
Alex Yakavenkad8e2ecd2012-04-20 17:10:15 -07001038 // This should never happen (we should be responding only to a message
1039 // that arrived from StkService). It has to exist by this time
Wink Savillee68857d2014-10-17 15:23:05 -07001040 CatLog.d(LOG_TAG, "Exception! mStkService is null when we need to send response.");
Alex Yakavenkad8e2ecd2012-04-20 17:10:15 -07001041 throw new RuntimeException("mStkService is null when we need to send response");
1042 }
1043 }
1044
Wink Savillee68857d2014-10-17 15:23:05 -07001045 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001046
1047 // set result code
1048 boolean helpRequired = args.getBoolean(HELP, false);
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001049 boolean confirmed = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001050
1051 switch(args.getInt(RES_ID)) {
1052 case RES_ID_MENU_SELECTION:
Wink Savillee68857d2014-10-17 15:23:05 -07001053 CatLog.d(LOG_TAG, "MENU_SELECTION=" + mStkContext[slotId].
1054 mCurrentMenuCmd.getCmdType());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001055 int menuSelection = args.getInt(MENU_SELECTION);
Wink Savillee68857d2014-10-17 15:23:05 -07001056 switch(mStkContext[slotId].mCurrentMenuCmd.getCmdType()) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001057 case SET_UP_MENU:
1058 case SELECT_ITEM:
Wink Savillee68857d2014-10-17 15:23:05 -07001059 mStkContext[slotId].lastSelectedItem = getItemName(menuSelection, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001060 if (helpRequired) {
1061 resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED);
1062 } else {
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301063 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1064 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001065 }
1066 resMsg.setMenuSelection(menuSelection);
1067 break;
1068 }
1069 break;
1070 case RES_ID_INPUT:
Wink Savillee68857d2014-10-17 15:23:05 -07001071 CatLog.d(LOG_TAG, "RES_ID_INPUT");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001072 String input = args.getString(INPUT);
Wink Savillee68857d2014-10-17 15:23:05 -07001073 if (input != null && (null != mStkContext[slotId].mCurrentCmd.geInput()) &&
1074 (mStkContext[slotId].mCurrentCmd.geInput().yesNo)) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001075 boolean yesNoSelection = input
1076 .equals(StkInputActivity.YES_STR_RESPONSE);
1077 resMsg.setYesNo(yesNoSelection);
1078 } else {
1079 if (helpRequired) {
1080 resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED);
1081 } else {
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301082 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1083 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001084 resMsg.setInput(input);
1085 }
1086 }
1087 break;
1088 case RES_ID_CONFIRM:
Alex Yakavenkad41f1d92010-07-12 14:13:13 -07001089 CatLog.d(this, "RES_ID_CONFIRM");
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001090 confirmed = args.getBoolean(CONFIRMATION);
Wink Savillee68857d2014-10-17 15:23:05 -07001091 switch (mStkContext[slotId].mCurrentCmd.getCmdType()) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001092 case DISPLAY_TEXT:
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301093 if (confirmed) {
1094 resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ?
1095 ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK);
1096 } else {
1097 resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER);
1098 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001099 break;
1100 case LAUNCH_BROWSER:
1101 resMsg.setResultCode(confirmed ? ResultCode.OK
1102 : ResultCode.UICC_SESSION_TERM_BY_USER);
1103 if (confirmed) {
Wink Savillee68857d2014-10-17 15:23:05 -07001104 mStkContext[slotId].launchBrowser = true;
1105 mStkContext[slotId].mBrowserSettings =
1106 mStkContext[slotId].mCurrentCmd.getBrowserSettings();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001107 }
1108 break;
1109 case SET_UP_CALL:
1110 resMsg.setResultCode(ResultCode.OK);
1111 resMsg.setConfirmation(confirmed);
1112 if (confirmed) {
Wink Savillee68857d2014-10-17 15:23:05 -07001113 launchEventMessage(slotId,
1114 mStkContext[slotId].mCurrentCmd.getCallSettings().callMsg);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001115 }
1116 break;
1117 }
1118 break;
1119 case RES_ID_DONE:
1120 resMsg.setResultCode(ResultCode.OK);
1121 break;
1122 case RES_ID_BACKWARD:
Wink Savillee68857d2014-10-17 15:23:05 -07001123 CatLog.d(LOG_TAG, "RES_ID_BACKWARD");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001124 resMsg.setResultCode(ResultCode.BACKWARD_MOVE_BY_USER);
1125 break;
1126 case RES_ID_END_SESSION:
Wink Savillee68857d2014-10-17 15:23:05 -07001127 CatLog.d(LOG_TAG, "RES_ID_END_SESSION");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001128 resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER);
1129 break;
1130 case RES_ID_TIMEOUT:
Wink Savillee68857d2014-10-17 15:23:05 -07001131 CatLog.d(LOG_TAG, "RES_ID_TIMEOUT");
Naveen Kallad5176892009-11-30 12:45:29 -08001132 // GCF test-case 27.22.4.1.1 Expected Sequence 1.5 (DISPLAY TEXT,
1133 // Clear message after delay, successful) expects result code OK.
1134 // If the command qualifier specifies no user response is required
1135 // then send OK instead of NO_RESPONSE_FROM_USER
Wink Savillee68857d2014-10-17 15:23:05 -07001136 if ((mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1137 AppInterface.CommandType.DISPLAY_TEXT.value())
1138 && (mStkContext[slotId].mCurrentCmd.geTextMessage().userClear == false)) {
Naveen Kallad5176892009-11-30 12:45:29 -08001139 resMsg.setResultCode(ResultCode.OK);
1140 } else {
1141 resMsg.setResultCode(ResultCode.NO_RESPONSE_FROM_USER);
1142 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001143 break;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001144 case RES_ID_CHOICE:
1145 int choice = args.getInt(CHOICE);
1146 CatLog.d(this, "User Choice=" + choice);
1147 switch (choice) {
1148 case YES:
1149 resMsg.setResultCode(ResultCode.OK);
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001150 confirmed = true;
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001151 break;
1152 case NO:
1153 resMsg.setResultCode(ResultCode.USER_NOT_ACCEPT);
1154 break;
1155 }
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001156
Wink Savillee68857d2014-10-17 15:23:05 -07001157 if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1158 AppInterface.CommandType.OPEN_CHANNEL.value()) {
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001159 resMsg.setConfirmation(confirmed);
1160 }
Kazuhiro Ondo764167c2011-10-21 16:05:05 -05001161 break;
Siddartha Pothapragadacacf7b82012-04-16 19:42:38 -07001162
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001163 default:
Wink Savillee68857d2014-10-17 15:23:05 -07001164 CatLog.d(LOG_TAG, "Unknown result id");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001165 return;
1166 }
Wink Savillee68857d2014-10-17 15:23:05 -07001167
1168 if (null != mStkContext[slotId].mCurrentCmd &&
1169 null != mStkContext[slotId].mCurrentCmd.getCmdType()) {
1170 CatLog.d(LOG_TAG, "handleCmdResponse- cmdName[" +
1171 mStkContext[slotId].mCurrentCmd.getCmdType().name() + "]");
1172 }
1173 mStkService[slotId].onCmdResponse(resMsg);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001174 }
1175
1176 /**
1177 * Returns 0 or FLAG_ACTIVITY_NO_USER_ACTION, 0 means the user initiated the action.
1178 *
1179 * @param userAction If the userAction is yes then we always return 0 otherwise
1180 * mMenuIsVisible is used to determine what to return. If mMenuIsVisible is true
1181 * then we are the foreground app and we'll return 0 as from our perspective a
1182 * user action did cause. If it's false than we aren't the foreground app and
1183 * FLAG_ACTIVITY_NO_USER_ACTION is returned.
Wink Saville79085fc2009-06-09 10:27:23 -07001184 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001185 * @return 0 or FLAG_ACTIVITY_NO_USER_ACTION
1186 */
Wink Savillee68857d2014-10-17 15:23:05 -07001187 private int getFlagActivityNoUserAction(InitiatedByUserAction userAction, int slotId) {
1188 return ((userAction == InitiatedByUserAction.yes) | mStkContext[slotId].mMenuIsVisible)
1189 ? 0 : Intent.FLAG_ACTIVITY_NO_USER_ACTION;
1190 }
1191 /**
1192 * This method is used for cleaning up pending instances in stack.
1193 */
1194 private void cleanUpInstanceStackBySlot(int slotId) {
1195 Activity activity = mStkContext[slotId].getPendingActivityInstance();
1196 Activity dialog = mStkContext[slotId].getPendingDialogInstance();
1197 CatLog.d(LOG_TAG, "cleanUpInstanceStackBySlot slotId: " + slotId);
Legler Wuaeefef52014-10-27 00:57:18 +08001198 if (mStkContext[slotId].mCurrentCmd == null) {
1199 CatLog.d(LOG_TAG, "current cmd is null.");
1200 return;
1201 }
Wink Savillee68857d2014-10-17 15:23:05 -07001202 if (activity != null) {
1203 CatLog.d(LOG_TAG, "current cmd type: " +
1204 mStkContext[slotId].mCurrentCmd.getCmdType());
1205 if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1206 AppInterface.CommandType.GET_INPUT.value() ||
1207 mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1208 AppInterface.CommandType.GET_INKEY.value()) {
1209 mStkContext[slotId].mIsInputPending = true;
1210 } else if (mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1211 AppInterface.CommandType.SET_UP_MENU.value() ||
1212 mStkContext[slotId].mCurrentCmd.getCmdType().value() ==
1213 AppInterface.CommandType.SELECT_ITEM.value()) {
1214 mStkContext[slotId].mIsMenuPending = true;
1215 } else {
1216 }
1217 CatLog.d(LOG_TAG, "finish pending activity.");
1218 activity.finish();
1219 mStkContext[slotId].mActivityInstance = null;
1220 }
1221 if (dialog != null) {
1222 CatLog.d(LOG_TAG, "finish pending dialog.");
1223 mStkContext[slotId].mIsDialogPending = true;
1224 dialog.finish();
1225 mStkContext[slotId].mDialogInstance = null;
1226 }
1227 }
1228 /**
1229 * This method is used for restoring pending instances from stack.
1230 */
1231 private void restoreInstanceFromStackBySlot(int slotId) {
1232 AppInterface.CommandType cmdType = mStkContext[slotId].mCurrentCmd.getCmdType();
1233
1234 CatLog.d(LOG_TAG, "restoreInstanceFromStackBySlot cmdType : " + cmdType);
1235 switch(cmdType) {
1236 case GET_INPUT:
1237 case GET_INKEY:
1238 launchInputActivity(slotId);
1239 //Set mMenuIsVisible to true for showing main menu for
1240 //following session end command.
1241 mStkContext[slotId].mMenuIsVisible = true;
1242 break;
1243 case DISPLAY_TEXT:
1244 launchTextDialog(slotId);
1245 break;
1246 case LAUNCH_BROWSER:
1247 launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.geTextMessage(),
1248 slotId);
1249 break;
1250 case OPEN_CHANNEL:
1251 launchOpenChannelDialog(slotId);
1252 break;
1253 case SET_UP_CALL:
1254 launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.getCallSettings().
1255 confirmMsg, slotId);
1256 break;
1257 case SET_UP_MENU:
1258 case SELECT_ITEM:
1259 launchMenuActivity(null, slotId);
1260 break;
1261 default:
1262 break;
1263 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001264 }
1265
Wink Savillee68857d2014-10-17 15:23:05 -07001266 private void launchMenuActivity(Menu menu, int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001267 Intent newIntent = new Intent(Intent.ACTION_VIEW);
Wink Savillee68857d2014-10-17 15:23:05 -07001268 String targetActivity = STK_MENU_ACTIVITY_NAME;
1269 String uriString = STK_MENU_URI + System.currentTimeMillis();
1270 //Set unique URI to create a new instance of activity for different slotId.
1271 Uri uriData = Uri.parse(uriString);
1272
1273 CatLog.d(LOG_TAG, "launchMenuActivity, slotId: " + slotId + " , " +
1274 uriData.toString() + " , " + mStkContext[slotId].mOpCode + ", "
1275 + mStkContext[slotId].mMenuState);
1276 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1277 int intentFlags = Intent.FLAG_ACTIVITY_NEW_TASK;
1278
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001279 if (menu == null) {
1280 // We assume this was initiated by the user pressing the tool kit icon
Wink Savillee68857d2014-10-17 15:23:05 -07001281 intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.yes, slotId);
1282 if (mStkContext[slotId].mOpCode == OP_END_SESSION) {
1283 CatLog.d(LOG_TAG, "launchMenuActivity, return OP_END_SESSION");
1284 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN;
1285 if (mStkContext[slotId].mMainActivityInstance != null) {
1286 CatLog.d(LOG_TAG, "launchMenuActivity, mMainActivityInstance is not null");
1287 return;
1288 }
Wink Savillee68857d2014-10-17 15:23:05 -07001289 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001290
Wink Savillee68857d2014-10-17 15:23:05 -07001291 //If the last pending menu is secondary menu, "STATE" should be "STATE_SECONDARY".
1292 //Otherwise, it should be "STATE_MAIN".
1293 if (mStkContext[slotId].mOpCode == OP_LAUNCH_APP &&
1294 mStkContext[slotId].mMenuState == StkMenuActivity.STATE_SECONDARY) {
1295 newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY);
1296 } else {
1297 newIntent.putExtra("STATE", StkMenuActivity.STATE_MAIN);
1298 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN;
1299 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001300 } else {
1301 // We don't know and we'll let getFlagActivityNoUserAction decide.
Wink Savillee68857d2014-10-17 15:23:05 -07001302 intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001303 newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY);
Wink Savillee68857d2014-10-17 15:23:05 -07001304 mStkContext[slotId].mMenuState = StkMenuActivity.STATE_SECONDARY;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001305 }
Wink Savillee68857d2014-10-17 15:23:05 -07001306 newIntent.putExtra(SLOT_ID, slotId);
1307 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001308 newIntent.setFlags(intentFlags);
1309 mContext.startActivity(newIntent);
1310 }
1311
Wink Savillee68857d2014-10-17 15:23:05 -07001312 private void launchInputActivity(int slotId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001313 Intent newIntent = new Intent(Intent.ACTION_VIEW);
Wink Savillee68857d2014-10-17 15:23:05 -07001314 String targetActivity = STK_INPUT_ACTIVITY_NAME;
1315 String uriString = STK_INPUT_URI + System.currentTimeMillis();
1316 //Set unique URI to create a new instance of activity for different slotId.
1317 Uri uriData = Uri.parse(uriString);
1318
1319 CatLog.d(LOG_TAG, "launchInputActivity, slotId: " + slotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001320 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
Wink Savillee68857d2014-10-17 15:23:05 -07001321 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1322 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1323 newIntent.putExtra("INPUT", mStkContext[slotId].mCurrentCmd.geInput());
1324 newIntent.putExtra(SLOT_ID, slotId);
1325 newIntent.setData(uriData);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001326 mContext.startActivity(newIntent);
1327 }
1328
Wink Savillee68857d2014-10-17 15:23:05 -07001329 private void launchTextDialog(int slotId) {
1330 CatLog.d(LOG_TAG, "launchTextDialog, slotId: " + slotId);
1331 Intent newIntent = new Intent();
1332 String targetActivity = STK_DIALOG_ACTIVITY_NAME;
1333 int action = getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId);
1334 String uriString = STK_DIALOG_URI + System.currentTimeMillis();
1335 //Set unique URI to create a new instance of activity for different slotId.
1336 Uri uriData = Uri.parse(uriString);
1337 if (newIntent != null) {
1338 newIntent.setClassName(PACKAGE_NAME, targetActivity);
1339 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1340 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
1341 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1342 newIntent.setData(uriData);
1343 newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage());
1344 newIntent.putExtra(SLOT_ID, slotId);
1345 startActivity(newIntent);
Preeti Ahuja414bc412013-06-25 19:31:49 -07001346 // For display texts with immediate response, send the terminal response
1347 // immediately. responseNeeded will be false, if display text command has
1348 // the immediate response tlv.
1349 if (!mStkContext[slotId].mCurrentCmd.geTextMessage().responseNeeded) {
1350 sendResponse(RES_ID_CONFIRM, slotId, true);
1351 }
Wink Savillee68857d2014-10-17 15:23:05 -07001352 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001353 }
1354
Wink Savillee68857d2014-10-17 15:23:05 -07001355 public boolean isStkDialogActivated(Context context) {
1356 String stkDialogActivity = "com.android.stk.StkDialogActivity";
1357 boolean activated = false;
1358 final ActivityManager am = (ActivityManager) context.getSystemService(
1359 Context.ACTIVITY_SERVICE);
1360 String topActivity = am.getRunningTasks(1).get(0).topActivity.getClassName();
1361
1362 CatLog.d(LOG_TAG, "isStkDialogActivated: " + topActivity);
1363 if (topActivity.equals(stkDialogActivity)) {
1364 activated = true;
1365 }
1366 CatLog.d(LOG_TAG, "activated : " + activated);
1367 return activated;
Johan Hellman3aec01c2011-02-10 10:15:28 +01001368 }
1369
Preeti Ahuja95919342013-10-01 18:18:55 -07001370 private void sendSetUpEventResponse(int event, byte[] addedInfo, int slotId) {
Preeti Ahuja414bc412013-06-25 19:31:49 -07001371 CatLog.d(this, "sendSetUpEventResponse: event : " + event + "slotId = " + slotId);
Preeti Ahuja95919342013-10-01 18:18:55 -07001372
1373 if (mStkContext[slotId].mCurrentSetupEventCmd == null){
1374 CatLog.e(this, "mCurrentSetupEventCmd is null");
1375 return;
1376 }
1377
1378 CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentSetupEventCmd);
1379
1380 resMsg.setResultCode(ResultCode.OK);
1381 resMsg.setEventDownload(event, addedInfo);
1382
1383 mStkService[slotId].onCmdResponse(resMsg);
1384 }
1385
1386 private void checkForSetupEvent(int event, Bundle args, int slotId) {
1387 boolean eventPresent = false;
1388 byte[] addedInfo = null;
1389 CatLog.d(this, "Event :" + event);
1390
1391 if (mStkContext[slotId].mSetupEventListSettings != null) {
1392 /* Checks if the event is present in the EventList updated by last
1393 * SetupEventList Proactive Command */
1394 for (int i : mStkContext[slotId].mSetupEventListSettings.eventList) {
1395 if (event == i) {
1396 eventPresent = true;
1397 break;
1398 }
1399 }
1400
1401 /* If Event is present send the response to ICC */
1402 if (eventPresent == true) {
1403 CatLog.d(this, " Event " + event + "exists in the EventList");
1404
1405 switch (event) {
Preeti Ahuja560be362014-11-25 19:38:24 -08001406 case IDLE_SCREEN_AVAILABLE_EVENT:
1407 sendSetUpEventResponse(event, addedInfo, slotId);
1408 removeSetUpEvent(event, slotId);
1409 break;
Preeti Ahuja95919342013-10-01 18:18:55 -07001410 case LANGUAGE_SELECTION_EVENT:
1411 String language = mContext
1412 .getResources().getConfiguration().locale.getLanguage();
1413 CatLog.d(this, "language: " + language);
1414 // Each language code is a pair of alpha-numeric characters.
1415 // Each alpha-numeric character shall be coded on one byte
1416 // using the SMS default 7-bit coded alphabet
1417 addedInfo = GsmAlphabet.stringToGsm8BitPacked(language);
1418 sendSetUpEventResponse(event, addedInfo, slotId);
1419 break;
1420 default:
1421 break;
1422 }
1423 } else {
1424 CatLog.e(this, " Event does not exist in the EventList");
1425 }
1426 } else {
1427 CatLog.e(this, "SetupEventList is not received. Ignoring the event: " + event);
1428 }
1429 }
1430
1431 private void removeSetUpEvent(int event, int slotId) {
1432 CatLog.d(this, "Remove Event :" + event);
1433
1434 if (mStkContext[slotId].mSetupEventListSettings != null) {
1435 /*
1436 * Make new Eventlist without the event
1437 */
1438 for (int i = 0; i < mStkContext[slotId].mSetupEventListSettings.eventList.length; i++) {
1439 if (event == mStkContext[slotId].mSetupEventListSettings.eventList[i]) {
1440 mStkContext[slotId].mSetupEventListSettings.eventList[i] = INVALID_SETUP_EVENT;
1441 break;
1442 }
1443 }
1444 }
1445 }
1446
1447 private void launchEventMessage(int slotId) {
1448 launchEventMessage(slotId, mStkContext[slotId].mCurrentCmd.geTextMessage());
1449 }
1450
Wink Savillee68857d2014-10-17 15:23:05 -07001451 private void launchEventMessage(int slotId, TextMessage msg) {
1452 if (msg == null || (msg.text != null && msg.text.length() == 0)) {
1453 CatLog.d(LOG_TAG, "launchEventMessage return");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001454 return;
1455 }
Wink Savillee68857d2014-10-17 15:23:05 -07001456
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001457 Toast toast = new Toast(mContext.getApplicationContext());
1458 LayoutInflater inflate = (LayoutInflater) mContext
1459 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
1460 View v = inflate.inflate(R.layout.stk_event_msg, null);
1461 TextView tv = (TextView) v
1462 .findViewById(com.android.internal.R.id.message);
1463 ImageView iv = (ImageView) v
1464 .findViewById(com.android.internal.R.id.icon);
1465 if (msg.icon != null) {
1466 iv.setImageBitmap(msg.icon);
1467 } else {
1468 iv.setVisibility(View.GONE);
1469 }
Preeti Ahujaf33bf392013-09-28 19:11:31 +05301470 /* In case of 'self explanatory' stkapp should display the specified
1471 * icon in proactive command (but not the alpha string).
1472 * If icon is non-self explanatory and if the icon could not be displayed
1473 * then alpha string or text data should be displayed
1474 * Ref: ETSI 102.223,section 6.5.4
1475 */
1476 if (mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ||
1477 msg.icon == null || !msg.iconSelfExplanatory) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001478 tv.setText(msg.text);
1479 }
1480
1481 toast.setView(v);
1482 toast.setDuration(Toast.LENGTH_LONG);
1483 toast.setGravity(Gravity.BOTTOM, 0, 0);
1484 toast.show();
1485 }
1486
Wink Savillee68857d2014-10-17 15:23:05 -07001487 private void launchConfirmationDialog(TextMessage msg, int slotId) {
1488 msg.title = mStkContext[slotId].lastSelectedItem;
1489 Intent newIntent = new Intent();
1490 String targetActivity = STK_DIALOG_ACTIVITY_NAME;
1491 String uriString = STK_DIALOG_URI + System.currentTimeMillis();
1492 //Set unique URI to create a new instance of activity for different slotId.
1493 Uri uriData = Uri.parse(uriString);
1494
1495 if (newIntent != null) {
1496 newIntent.setClassName(this, targetActivity);
1497 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1498 | Intent.FLAG_ACTIVITY_NO_HISTORY
1499 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
1500 | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId));
1501 newIntent.putExtra("TEXT", msg);
1502 newIntent.putExtra(SLOT_ID, slotId);
1503 newIntent.setData(uriData);
1504 startActivity(newIntent);
1505 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001506 }
1507
1508 private void launchBrowser(BrowserSettings settings) {
1509 if (settings == null) {
1510 return;
1511 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001512
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001513 Uri data = null;
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001514 String url;
1515 if (settings.url == null) {
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001516 // if the command did not contain a URL,
1517 // launch the browser to the default homepage.
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001518 CatLog.d(this, "no url data provided by proactive command." +
1519 " launching browser with stk default URL ... ");
1520 url = SystemProperties.get(STK_BROWSER_DEFAULT_URL_SYSPROP,
1521 "http://www.google.com");
1522 } else {
1523 CatLog.d(this, "launch browser command has attached url = " + settings.url);
1524 url = settings.url;
Abhishek Adappa840c82f2013-02-26 10:19:49 -08001525 }
David Brown7c03cfe2011-10-20 15:36:12 -07001526
Preeti Ahujaa7cdca22013-10-01 18:20:56 -07001527 if (url.startsWith("http://") || url.startsWith("https://")) {
1528 data = Uri.parse(url);
1529 CatLog.d(this, "launching browser with url = " + url);
1530 } else {
1531 String modifiedUrl = "http://" + url;
1532 data = Uri.parse(modifiedUrl);
1533 CatLog.d(this, "launching browser with modified url = " + modifiedUrl);
1534 }
1535
1536 Intent intent = new Intent(Intent.ACTION_VIEW);
1537 intent.setData(data);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001538 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1539 switch (settings.mode) {
1540 case USE_EXISTING_BROWSER:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001541 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1542 break;
1543 case LAUNCH_NEW_BROWSER:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001544 intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
1545 break;
1546 case LAUNCH_IF_NOT_ALREADY_LAUNCHED:
1547 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
1548 break;
1549 }
1550 // start browser activity
1551 startActivity(intent);
1552 // a small delay, let the browser start, before processing the next command.
Wink Saville79085fc2009-06-09 10:27:23 -07001553 // this is good for scenarios where a related DISPLAY TEXT command is
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001554 // followed immediately.
1555 try {
Ryuto Sawada350aaa62016-06-13 14:47:22 +09001556 Thread.sleep(3000);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001557 } catch (InterruptedException e) {}
1558 }
1559
Wink Savillee68857d2014-10-17 15:23:05 -07001560 private void launchIdleText(int slotId) {
Preeti Ahuja560be362014-11-25 19:38:24 -08001561 TextMessage msg = mStkContext[slotId].mIdleModeTextCmd.geTextMessage();
dujin.cha2a0eb2a2011-11-11 15:03:57 +09001562
Preeti Ahuja95919342013-10-01 18:18:55 -07001563 if (msg == null || msg.text ==null) {
1564 CatLog.d(LOG_TAG, msg == null ? "mCurrent.getTextMessage is NULL"
1565 : "mCurrent.getTextMessage.text is NULL");
Wink Savillee68857d2014-10-17 15:23:05 -07001566 mNotificationManager.cancel(getNotificationId(slotId));
Wink Saville046db4b2011-11-01 20:42:54 -07001567 return;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001568 } else {
Preeti Ahuja95919342013-10-01 18:18:55 -07001569 CatLog.d(LOG_TAG, "launchIdleText - text[" + msg.text
1570 + "] iconSelfExplanatory[" + msg.iconSelfExplanatory
1571 + "] icon[" + msg.icon + "], sim id: " + slotId);
Wink Savillee68857d2014-10-17 15:23:05 -07001572 CatLog.d(LOG_TAG, "Add IdleMode text");
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001573 PendingIntent pendingIntent = PendingIntent.getService(mContext, 0,
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001574 new Intent(mContext, StkAppService.class), 0);
fionaxu2c91c752017-04-21 18:11:57 -07001575 /* Creates the notification channel and registers it with NotificationManager.
1576 * If a channel with the same ID is already registered, NotificationManager will
1577 * ignore this call.
1578 */
1579 mNotificationManager.createNotificationChannel(new NotificationChannel(
1580 STK_NOTIFICATION_CHANNEL_ID,
1581 getResources().getString(R.string.stk_channel_name),
1582 NotificationManager.IMPORTANCE_MIN));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001583
Alex Khlivnuik50e0a1d2013-01-25 12:50:48 +01001584 final Notification.Builder notificationBuilder = new Notification.Builder(
fionaxu2c91c752017-04-21 18:11:57 -07001585 StkAppService.this, STK_NOTIFICATION_CHANNEL_ID);
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}