The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.stk; |
| 18 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 19 | import android.app.ActivityManager; |
| 20 | import android.app.ActivityManager.RunningTaskInfo; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 21 | import android.app.AlertDialog; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 22 | import android.app.Notification; |
| 23 | import android.app.NotificationManager; |
| 24 | import android.app.PendingIntent; |
| 25 | import android.app.Service; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 26 | import android.app.Activity; |
| 27 | import android.app.ActivityManager; |
| 28 | import android.app.ActivityManager.RecentTaskInfo; |
| 29 | import android.app.ActivityManager.RunningAppProcessInfo; |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 30 | import android.content.ComponentName; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 31 | import android.content.Context; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 32 | import android.content.DialogInterface; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 33 | import android.content.Intent; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 34 | import android.content.res.Configuration; |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 35 | import android.graphics.Bitmap; |
| 36 | import android.graphics.BitmapFactory; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 37 | import android.net.Uri; |
| 38 | import android.os.Bundle; |
| 39 | import android.os.Handler; |
| 40 | import android.os.IBinder; |
| 41 | import android.os.Looper; |
| 42 | import android.os.Message; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 43 | import android.os.PowerManager; |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 44 | import android.os.SystemProperties; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 45 | import android.provider.Settings; |
Wink Saville | 56469d5 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 46 | import android.telephony.TelephonyManager; |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 47 | import android.text.TextUtils; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 48 | import android.view.Gravity; |
| 49 | import android.view.LayoutInflater; |
| 50 | import android.view.View; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 51 | import android.view.Window; |
| 52 | import android.view.WindowManager; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 53 | import android.widget.ImageView; |
| 54 | import android.widget.RemoteViews; |
| 55 | import android.widget.TextView; |
| 56 | import android.widget.Toast; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 57 | import android.content.BroadcastReceiver; |
| 58 | import android.content.IntentFilter; |
| 59 | import android.content.pm.ApplicationInfo; |
| 60 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 61 | |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 62 | import com.android.internal.telephony.cat.AppInterface; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 63 | import com.android.internal.telephony.cat.LaunchBrowserMode; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 64 | import com.android.internal.telephony.cat.Menu; |
| 65 | import com.android.internal.telephony.cat.Item; |
Pierre Fröjd | 9750326 | 2010-11-08 13:59:36 +0100 | [diff] [blame] | 66 | import com.android.internal.telephony.cat.Input; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 67 | import com.android.internal.telephony.cat.ResultCode; |
| 68 | import com.android.internal.telephony.cat.CatCmdMessage; |
| 69 | import com.android.internal.telephony.cat.CatCmdMessage.BrowserSettings; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 70 | import com.android.internal.telephony.cat.CatCmdMessage.SetupEventListSettings; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 71 | import com.android.internal.telephony.cat.CatLog; |
| 72 | import com.android.internal.telephony.cat.CatResponseMessage; |
| 73 | import com.android.internal.telephony.cat.TextMessage; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 74 | import com.android.internal.telephony.uicc.IccRefreshResponse; |
| 75 | import com.android.internal.telephony.uicc.IccCardStatus.CardState; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 76 | import com.android.internal.telephony.PhoneConstants; |
| 77 | import com.android.internal.telephony.TelephonyIntents; |
| 78 | import com.android.internal.telephony.IccCardConstants; |
| 79 | import com.android.internal.telephony.uicc.UiccController; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 80 | import com.android.internal.telephony.GsmAlphabet; |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 81 | import com.android.internal.telephony.cat.CatService; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 82 | |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 83 | import java.util.Iterator; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 84 | import java.util.LinkedList; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 85 | import java.lang.System; |
| 86 | import java.util.List; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 87 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 88 | import static com.android.internal.telephony.cat.CatCmdMessage. |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 89 | SetupEventListConstants.IDLE_SCREEN_AVAILABLE_EVENT; |
| 90 | import static com.android.internal.telephony.cat.CatCmdMessage. |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 91 | SetupEventListConstants.LANGUAGE_SELECTION_EVENT; |
| 92 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 93 | /** |
| 94 | * SIM toolkit application level service. Interacts with Telephopny messages, |
| 95 | * application's launch and user input from STK UI elements. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 96 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 97 | */ |
| 98 | public class StkAppService extends Service implements Runnable { |
| 99 | |
| 100 | // members |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 101 | protected class StkContext { |
| 102 | protected CatCmdMessage mMainCmd = null; |
| 103 | protected CatCmdMessage mCurrentCmd = null; |
| 104 | protected CatCmdMessage mCurrentMenuCmd = null; |
| 105 | protected Menu mCurrentMenu = null; |
| 106 | protected String lastSelectedItem = null; |
| 107 | protected boolean mMenuIsVisible = false; |
| 108 | protected boolean mIsInputPending = false; |
| 109 | protected boolean mIsMenuPending = false; |
| 110 | protected boolean mIsDialogPending = false; |
| 111 | protected boolean responseNeeded = true; |
| 112 | protected boolean launchBrowser = false; |
| 113 | protected BrowserSettings mBrowserSettings = null; |
| 114 | protected LinkedList<DelayedCmd> mCmdsQ = null; |
| 115 | protected boolean mCmdInProgress = false; |
| 116 | protected int mStkServiceState = STATE_UNKNOWN; |
| 117 | protected int mSetupMenuState = STATE_UNKNOWN; |
| 118 | protected int mMenuState = StkMenuActivity.STATE_INIT; |
| 119 | protected int mOpCode = -1; |
| 120 | private Activity mActivityInstance = null; |
| 121 | private Activity mDialogInstance = null; |
| 122 | private Activity mMainActivityInstance = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 123 | private int mSlotId = 0; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 124 | private SetupEventListSettings mSetupEventListSettings = null; |
| 125 | private boolean mClearSelectItem = false; |
| 126 | private boolean mDisplayTextDlgIsVisibile = false; |
| 127 | private CatCmdMessage mCurrentSetupEventCmd = null; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 128 | private CatCmdMessage mIdleModeTextCmd = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 129 | final synchronized void setPendingActivityInstance(Activity act) { |
| 130 | CatLog.d(this, "setPendingActivityInstance act : " + mSlotId + ", " + act); |
| 131 | callSetActivityInstMsg(OP_SET_ACT_INST, mSlotId, act); |
| 132 | } |
| 133 | final synchronized Activity getPendingActivityInstance() { |
| 134 | CatLog.d(this, "getPendingActivityInstance act : " + mSlotId + ", " + |
| 135 | mActivityInstance); |
| 136 | return mActivityInstance; |
| 137 | } |
| 138 | final synchronized void setPendingDialogInstance(Activity act) { |
| 139 | CatLog.d(this, "setPendingDialogInstance act : " + mSlotId + ", " + act); |
| 140 | callSetActivityInstMsg(OP_SET_DAL_INST, mSlotId, act); |
| 141 | } |
| 142 | final synchronized Activity getPendingDialogInstance() { |
| 143 | CatLog.d(this, "getPendingDialogInstance act : " + mSlotId + ", " + |
| 144 | mDialogInstance); |
| 145 | return mDialogInstance; |
| 146 | } |
| 147 | final synchronized void setMainActivityInstance(Activity act) { |
| 148 | CatLog.d(this, "setMainActivityInstance act : " + mSlotId + ", " + act); |
| 149 | callSetActivityInstMsg(OP_SET_MAINACT_INST, mSlotId, act); |
| 150 | } |
| 151 | final synchronized Activity getMainActivityInstance() { |
| 152 | CatLog.d(this, "getMainActivityInstance act : " + mSlotId + ", " + |
| 153 | mMainActivityInstance); |
| 154 | return mMainActivityInstance; |
| 155 | } |
| 156 | } |
| 157 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 158 | private volatile Looper mServiceLooper; |
| 159 | private volatile ServiceHandler mServiceHandler; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 160 | private Context mContext = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 161 | private NotificationManager mNotificationManager = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 162 | static StkAppService sInstance = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 163 | private AppInterface[] mStkService = null; |
| 164 | private StkContext[] mStkContext = null; |
| 165 | private int mSimCount = 0; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 166 | private PowerManager mPowerManager = null; |
| 167 | private StkCmdReceiver mStkCmdReceiver = null; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 168 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 169 | // Used for setting FLAG_ACTIVITY_NO_USER_ACTION when |
| 170 | // creating an intent. |
| 171 | private enum InitiatedByUserAction { |
| 172 | yes, // The action was started via a user initiated action |
| 173 | unknown, // Not known for sure if user initated the action |
| 174 | } |
| 175 | |
| 176 | // constants |
| 177 | static final String OPCODE = "op"; |
| 178 | static final String CMD_MSG = "cmd message"; |
| 179 | static final String RES_ID = "response id"; |
| 180 | static final String MENU_SELECTION = "menu selection"; |
| 181 | static final String INPUT = "input"; |
| 182 | static final String HELP = "help"; |
| 183 | static final String CONFIRMATION = "confirm"; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 184 | static final String CHOICE = "choice"; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 185 | static final String SLOT_ID = "SLOT_ID"; |
| 186 | static final String STK_CMD = "STK CMD"; |
| 187 | static final String STK_DIALOG_URI = "stk://com.android.stk/dialog/"; |
| 188 | static final String STK_MENU_URI = "stk://com.android.stk/menu/"; |
| 189 | static final String STK_INPUT_URI = "stk://com.android.stk/input/"; |
| 190 | static final String STK_TONE_URI = "stk://com.android.stk/tone/"; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 191 | |
| 192 | // These below constants are used for SETUP_EVENT_LIST |
| 193 | static final String SETUP_EVENT_TYPE = "event"; |
| 194 | static final String SETUP_EVENT_CAUSE = "cause"; |
| 195 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 196 | // operations ids for different service functionality. |
| 197 | static final int OP_CMD = 1; |
| 198 | static final int OP_RESPONSE = 2; |
| 199 | static final int OP_LAUNCH_APP = 3; |
| 200 | static final int OP_END_SESSION = 4; |
| 201 | static final int OP_BOOT_COMPLETED = 5; |
| 202 | private static final int OP_DELAYED_MSG = 6; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 203 | static final int OP_CARD_STATUS_CHANGED = 7; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 204 | static final int OP_SET_ACT_INST = 8; |
| 205 | static final int OP_SET_DAL_INST = 9; |
| 206 | static final int OP_SET_MAINACT_INST = 10; |
Preeti Ahuja | b3d0e61 | 2014-11-20 13:29:25 -0800 | [diff] [blame] | 207 | static final int OP_LOCALE_CHANGED = 11; |
| 208 | static final int OP_ALPHA_NOTIFY = 12; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 209 | static final int OP_IDLE_SCREEN = 13; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 210 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 211 | //Invalid SetupEvent |
| 212 | static final int INVALID_SETUP_EVENT = 0xFF; |
| 213 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 214 | // Response ids |
| 215 | static final int RES_ID_MENU_SELECTION = 11; |
| 216 | static final int RES_ID_INPUT = 12; |
| 217 | static final int RES_ID_CONFIRM = 13; |
| 218 | static final int RES_ID_DONE = 14; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 219 | static final int RES_ID_CHOICE = 15; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 220 | |
| 221 | static final int RES_ID_TIMEOUT = 20; |
| 222 | static final int RES_ID_BACKWARD = 21; |
| 223 | static final int RES_ID_END_SESSION = 22; |
| 224 | static final int RES_ID_EXIT = 23; |
| 225 | |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 226 | static final int YES = 1; |
| 227 | static final int NO = 0; |
| 228 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 229 | static final int STATE_UNKNOWN = -1; |
| 230 | static final int STATE_NOT_EXIST = 0; |
| 231 | static final int STATE_EXIST = 1; |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 232 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 233 | private static final String PACKAGE_NAME = "com.android.stk"; |
| 234 | private static final String STK_MENU_ACTIVITY_NAME = PACKAGE_NAME + ".StkMenuActivity"; |
| 235 | private static final String STK_INPUT_ACTIVITY_NAME = PACKAGE_NAME + ".StkInputActivity"; |
| 236 | private static final String STK_DIALOG_ACTIVITY_NAME = PACKAGE_NAME + ".StkDialogActivity"; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 237 | // Notification id used to display Idle Mode text in NotificationManager. |
| 238 | private static final int STK_NOTIFICATION_ID = 333; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 239 | private static final String LOG_TAG = new Object(){}.getClass().getEnclosingClass().getName(); |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 240 | |
| 241 | // Inner class used for queuing telephony messages (proactive commands, |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 242 | // session end) while the service is busy processing a previous message. |
| 243 | private class DelayedCmd { |
| 244 | // members |
| 245 | int id; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 246 | CatCmdMessage msg; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 247 | int slotId; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 248 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 249 | DelayedCmd(int id, CatCmdMessage msg, int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 250 | this.id = id; |
| 251 | this.msg = msg; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 252 | this.slotId = slotId; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 256 | // system property to set the STK specific default url for launch browser proactive cmds |
| 257 | private static final String STK_BROWSER_DEFAULT_URL_SYSPROP = "persist.radio.stk.default_url"; |
| 258 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 259 | @Override |
| 260 | public void onCreate() { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 261 | CatLog.d(LOG_TAG, "onCreate()+"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 262 | // Initialize members |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 263 | int i = 0; |
| 264 | mContext = getBaseContext(); |
| 265 | mSimCount = TelephonyManager.from(mContext).getSimCount(); |
| 266 | CatLog.d(LOG_TAG, "simCount: " + mSimCount); |
| 267 | mStkService = new AppInterface[mSimCount]; |
| 268 | mStkContext = new StkContext[mSimCount]; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 269 | mPowerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); |
| 270 | mStkCmdReceiver = new StkCmdReceiver(); |
| 271 | registerReceiver(mStkCmdReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF)); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 272 | for (i = 0; i < mSimCount; i++) { |
| 273 | CatLog.d(LOG_TAG, "slotId: " + i); |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 274 | mStkService[i] = CatService.getInstance(i); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 275 | mStkContext[i] = new StkContext(); |
| 276 | mStkContext[i].mSlotId = i; |
| 277 | mStkContext[i].mCmdsQ = new LinkedList<DelayedCmd>(); |
| 278 | } |
| 279 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 280 | Thread serviceThread = new Thread(null, this, "Stk App Service"); |
| 281 | serviceThread.start(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 282 | mNotificationManager = (NotificationManager) mContext |
| 283 | .getSystemService(Context.NOTIFICATION_SERVICE); |
| 284 | sInstance = this; |
| 285 | } |
| 286 | |
| 287 | @Override |
| 288 | public void onStart(Intent intent, int startId) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 289 | if (intent == null) { |
| 290 | CatLog.d(LOG_TAG, "StkAppService onStart intent is null so return"); |
Banavathu, Srinivas Naik | 87cda96 | 2012-07-17 15:32:44 +0530 | [diff] [blame] | 291 | return; |
| 292 | } |
| 293 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 294 | Bundle args = intent.getExtras(); |
| 295 | if (args == null) { |
| 296 | CatLog.d(LOG_TAG, "StkAppService onStart args is null so return"); |
| 297 | return; |
| 298 | } |
| 299 | |
| 300 | int op = args.getInt(OPCODE); |
| 301 | int slotId = 0; |
| 302 | int i = 0; |
| 303 | if (op != OP_BOOT_COMPLETED) { |
| 304 | slotId = args.getInt(SLOT_ID); |
| 305 | } |
Cuihtlauac ALVARADO | bde7f03 | 2015-05-29 16:25:12 +0200 | [diff] [blame] | 306 | CatLog.d(LOG_TAG, "onStart sim id: " + slotId + ", op: " + op + ", *****"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 307 | if ((slotId >= 0 && slotId < mSimCount) && mStkService[slotId] == null) { |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 308 | mStkService[slotId] = CatService.getInstance(slotId); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 309 | if (mStkService[slotId] == null) { |
| 310 | CatLog.d(LOG_TAG, "mStkService is: " + mStkContext[slotId].mStkServiceState); |
| 311 | mStkContext[slotId].mStkServiceState = STATE_NOT_EXIST; |
| 312 | //Check other StkService state. |
| 313 | //If all StkServices are not available, stop itself and uninstall apk. |
| 314 | for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) { |
| 315 | if (i != slotId |
Tsukasa Goto | 029332b | 2016-10-05 17:12:06 +0900 | [diff] [blame] | 316 | && (mStkService[i] != null) |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 317 | && (mStkContext[i].mStkServiceState == STATE_UNKNOWN |
| 318 | || mStkContext[i].mStkServiceState == STATE_EXIST)) { |
| 319 | break; |
| 320 | } |
| 321 | } |
| 322 | } else { |
| 323 | mStkContext[slotId].mStkServiceState = STATE_EXIST; |
| 324 | } |
| 325 | if (i == mSimCount) { |
| 326 | stopSelf(); |
| 327 | StkAppInstaller.unInstall(mContext); |
| 328 | return; |
| 329 | } |
| 330 | } |
| 331 | |
Banavathu, Srinivas Naik | 87cda96 | 2012-07-17 15:32:44 +0530 | [diff] [blame] | 332 | waitForLooper(); |
John Wang | 62acae4 | 2009-10-08 11:20:23 -0700 | [diff] [blame] | 333 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 334 | Message msg = mServiceHandler.obtainMessage(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 335 | msg.arg1 = op; |
| 336 | msg.arg2 = slotId; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 337 | switch(msg.arg1) { |
| 338 | case OP_CMD: |
| 339 | msg.obj = args.getParcelable(CMD_MSG); |
| 340 | break; |
| 341 | case OP_RESPONSE: |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 342 | case OP_CARD_STATUS_CHANGED: |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 343 | case OP_LOCALE_CHANGED: |
Preeti Ahuja | 0f4cf2f | 2012-08-09 11:45:08 +0530 | [diff] [blame] | 344 | case OP_ALPHA_NOTIFY: |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 345 | case OP_IDLE_SCREEN: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 346 | msg.obj = args; |
| 347 | /* falls through */ |
| 348 | case OP_LAUNCH_APP: |
| 349 | case OP_END_SESSION: |
| 350 | case OP_BOOT_COMPLETED: |
| 351 | break; |
| 352 | default: |
| 353 | return; |
| 354 | } |
| 355 | mServiceHandler.sendMessage(msg); |
| 356 | } |
| 357 | |
| 358 | @Override |
| 359 | public void onDestroy() { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 360 | CatLog.d(LOG_TAG, "onDestroy()"); |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 361 | if (mStkCmdReceiver != null) { |
| 362 | unregisterReceiver(mStkCmdReceiver); |
| 363 | mStkCmdReceiver = null; |
| 364 | } |
| 365 | mPowerManager = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 366 | waitForLooper(); |
| 367 | mServiceLooper.quit(); |
| 368 | } |
| 369 | |
| 370 | @Override |
| 371 | public IBinder onBind(Intent intent) { |
| 372 | return null; |
| 373 | } |
| 374 | |
| 375 | public void run() { |
| 376 | Looper.prepare(); |
| 377 | |
| 378 | mServiceLooper = Looper.myLooper(); |
| 379 | mServiceHandler = new ServiceHandler(); |
| 380 | |
| 381 | Looper.loop(); |
| 382 | } |
| 383 | |
| 384 | /* |
| 385 | * Package api used by StkMenuActivity to indicate if its on the foreground. |
| 386 | */ |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 387 | void indicateMenuVisibility(boolean visibility, int slotId) { |
| 388 | if (slotId >= 0 && slotId < mSimCount) { |
| 389 | mStkContext[slotId].mMenuIsVisible = visibility; |
| 390 | } |
| 391 | } |
| 392 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 393 | /* |
| 394 | * Package api used by StkDialogActivity to indicate if its on the foreground. |
| 395 | */ |
| 396 | void setDisplayTextDlgVisibility(boolean visibility, int slotId) { |
| 397 | if (slotId >= 0 && slotId < mSimCount) { |
| 398 | mStkContext[slotId].mDisplayTextDlgIsVisibile = visibility; |
| 399 | } |
| 400 | } |
| 401 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 402 | boolean isInputPending(int slotId) { |
| 403 | if (slotId >= 0 && slotId < mSimCount) { |
| 404 | CatLog.d(LOG_TAG, "isInputFinishBySrv: " + mStkContext[slotId].mIsInputPending); |
| 405 | return mStkContext[slotId].mIsInputPending; |
| 406 | } |
| 407 | return false; |
| 408 | } |
| 409 | |
| 410 | boolean isMenuPending(int slotId) { |
| 411 | if (slotId >= 0 && slotId < mSimCount) { |
| 412 | CatLog.d(LOG_TAG, "isMenuPending: " + mStkContext[slotId].mIsMenuPending); |
| 413 | return mStkContext[slotId].mIsMenuPending; |
| 414 | } |
| 415 | return false; |
| 416 | } |
| 417 | |
| 418 | boolean isDialogPending(int slotId) { |
| 419 | if (slotId >= 0 && slotId < mSimCount) { |
| 420 | CatLog.d(LOG_TAG, "isDialogPending: " + mStkContext[slotId].mIsDialogPending); |
| 421 | return mStkContext[slotId].mIsDialogPending; |
| 422 | } |
| 423 | return false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | /* |
| 427 | * Package api used by StkMenuActivity to get its Menu parameter. |
| 428 | */ |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 429 | Menu getMenu(int slotId) { |
| 430 | CatLog.d(LOG_TAG, "StkAppService, getMenu, sim id: " + slotId); |
| 431 | if (slotId >=0 && slotId < mSimCount) { |
| 432 | return mStkContext[slotId].mCurrentMenu; |
| 433 | } else { |
| 434 | return null; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | /* |
| 439 | * Package api used by StkMenuActivity to get its Main Menu parameter. |
| 440 | */ |
| 441 | Menu getMainMenu(int slotId) { |
| 442 | CatLog.d(LOG_TAG, "StkAppService, getMainMenu, sim id: " + slotId); |
w30234 | a08cffe | 2015-02-04 15:13:25 -0800 | [diff] [blame] | 443 | if (slotId >=0 && slotId < mSimCount && (mStkContext[slotId].mMainCmd != null)) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 444 | return mStkContext[slotId].mMainCmd.getMenu(); |
| 445 | } else { |
| 446 | return null; |
| 447 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /* |
| 451 | * Package api used by UI Activities and Dialogs to communicate directly |
| 452 | * with the service to deliver state information and parameters. |
| 453 | */ |
| 454 | static StkAppService getInstance() { |
| 455 | return sInstance; |
| 456 | } |
| 457 | |
| 458 | private void waitForLooper() { |
| 459 | while (mServiceHandler == null) { |
| 460 | synchronized (this) { |
| 461 | try { |
| 462 | wait(100); |
| 463 | } catch (InterruptedException e) { |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | private final class ServiceHandler extends Handler { |
| 470 | @Override |
| 471 | public void handleMessage(Message msg) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 472 | if(null == msg) { |
| 473 | CatLog.d(LOG_TAG, "ServiceHandler handleMessage msg is null"); |
| 474 | return; |
| 475 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 476 | int opcode = msg.arg1; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 477 | int slotId = msg.arg2; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 478 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 479 | CatLog.d(LOG_TAG, "handleMessage opcode[" + opcode + "], sim id[" + slotId + "]"); |
| 480 | if (opcode == OP_CMD && msg.obj != null && |
| 481 | ((CatCmdMessage)msg.obj).getCmdType()!= null) { |
| 482 | CatLog.d(LOG_TAG, "cmdName[" + ((CatCmdMessage)msg.obj).getCmdType().name() + "]"); |
| 483 | } |
| 484 | mStkContext[slotId].mOpCode = opcode; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 485 | switch (opcode) { |
| 486 | case OP_LAUNCH_APP: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 487 | if (mStkContext[slotId].mMainCmd == null) { |
| 488 | CatLog.d(LOG_TAG, "mMainCmd is null"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 489 | // nothing todo when no SET UP MENU command didn't arrive. |
| 490 | return; |
| 491 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 492 | CatLog.d(LOG_TAG, "handleMessage OP_LAUNCH_APP - mCmdInProgress[" + |
| 493 | mStkContext[slotId].mCmdInProgress + "]"); |
| 494 | |
| 495 | //If there is a pending activity for the slot id, |
| 496 | //just finish it and create a new one to handle the pending command. |
| 497 | cleanUpInstanceStackBySlot(slotId); |
| 498 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 499 | CatLog.d(LOG_TAG, "Current cmd type: " + |
| 500 | mStkContext[slotId].mCurrentCmd.getCmdType()); |
| 501 | //Restore the last command from stack by slot id. |
| 502 | restoreInstanceFromStackBySlot(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 503 | break; |
| 504 | case OP_CMD: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 505 | CatLog.d(LOG_TAG, "[OP_CMD]"); |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 506 | CatCmdMessage cmdMsg = (CatCmdMessage) msg.obj; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 507 | // There are two types of commands: |
| 508 | // 1. Interactive - user's response is required. |
| 509 | // 2. Informative - display a message, no interaction with the user. |
| 510 | // |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 511 | // Informative commands can be handled immediately without any delay. |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 512 | // Interactive commands can't override each other. So if a command |
| 513 | // is already in progress, we need to queue the next command until |
| 514 | // the user has responded or a timeout expired. |
| 515 | if (!isCmdInteractive(cmdMsg)) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 516 | handleCmd(cmdMsg, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 517 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 518 | if (!mStkContext[slotId].mCmdInProgress) { |
| 519 | mStkContext[slotId].mCmdInProgress = true; |
| 520 | handleCmd((CatCmdMessage) msg.obj, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 521 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 522 | CatLog.d(LOG_TAG, "[Interactive][in progress]"); |
| 523 | mStkContext[slotId].mCmdsQ.addLast(new DelayedCmd(OP_CMD, |
| 524 | (CatCmdMessage) msg.obj, slotId)); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | break; |
| 528 | case OP_RESPONSE: |
Preeti Ahuja | 414bc41 | 2013-06-25 19:31:49 -0700 | [diff] [blame] | 529 | handleCmdResponse((Bundle) msg.obj, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 530 | // call delayed commands if needed. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 531 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 532 | callDelayedMsg(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 533 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 534 | mStkContext[slotId].mCmdInProgress = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 535 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 536 | break; |
| 537 | case OP_END_SESSION: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 538 | if (!mStkContext[slotId].mCmdInProgress) { |
| 539 | mStkContext[slotId].mCmdInProgress = true; |
| 540 | handleSessionEnd(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 541 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 542 | mStkContext[slotId].mCmdsQ.addLast( |
| 543 | new DelayedCmd(OP_END_SESSION, null, slotId)); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 544 | } |
| 545 | break; |
| 546 | case OP_BOOT_COMPLETED: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 547 | CatLog.d(LOG_TAG, " OP_BOOT_COMPLETED"); |
| 548 | int i = 0; |
| 549 | for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) { |
| 550 | if (mStkContext[i].mMainCmd != null) { |
| 551 | break; |
| 552 | } |
| 553 | } |
| 554 | if (i == mSimCount) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 555 | StkAppInstaller.unInstall(mContext); |
| 556 | } |
| 557 | break; |
| 558 | case OP_DELAYED_MSG: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 559 | handleDelayedCmd(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 560 | break; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 561 | case OP_CARD_STATUS_CHANGED: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 562 | CatLog.d(LOG_TAG, "Card/Icc Status change received"); |
| 563 | handleCardStatusChangeAndIccRefresh((Bundle) msg.obj, slotId); |
| 564 | break; |
| 565 | case OP_SET_ACT_INST: |
| 566 | Activity act = new Activity(); |
| 567 | act = (Activity) msg.obj; |
| 568 | CatLog.d(LOG_TAG, "Set activity instance. " + act); |
| 569 | mStkContext[slotId].mActivityInstance = act; |
| 570 | break; |
| 571 | case OP_SET_DAL_INST: |
| 572 | Activity dal = new Activity(); |
| 573 | CatLog.d(LOG_TAG, "Set dialog instance. " + dal); |
| 574 | dal = (Activity) msg.obj; |
| 575 | mStkContext[slotId].mDialogInstance = dal; |
| 576 | break; |
| 577 | case OP_SET_MAINACT_INST: |
| 578 | Activity mainAct = new Activity(); |
| 579 | mainAct = (Activity) msg.obj; |
| 580 | CatLog.d(LOG_TAG, "Set activity instance. " + mainAct); |
| 581 | mStkContext[slotId].mMainActivityInstance = mainAct; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 582 | break; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 583 | case OP_LOCALE_CHANGED: |
| 584 | CatLog.d(this, "Locale Changed"); |
Yuta Ui | 1481b17 | 2016-02-03 15:34:31 +0900 | [diff] [blame] | 585 | for (int slot = PhoneConstants.SIM_ID_1; slot < mSimCount; slot++) { |
| 586 | checkForSetupEvent(LANGUAGE_SELECTION_EVENT, (Bundle) msg.obj, slot); |
| 587 | } |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 588 | break; |
Preeti Ahuja | 0f4cf2f | 2012-08-09 11:45:08 +0530 | [diff] [blame] | 589 | case OP_ALPHA_NOTIFY: |
| 590 | handleAlphaNotify((Bundle) msg.obj); |
| 591 | break; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 592 | case OP_IDLE_SCREEN: |
| 593 | for (int slot = 0; slot < mSimCount; slot++) { |
| 594 | if (mStkContext[slot] != null) { |
| 595 | handleIdleScreen(slot); |
| 596 | } |
| 597 | } |
| 598 | break; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 602 | private void handleCardStatusChangeAndIccRefresh(Bundle args, int slotId) { |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 603 | boolean cardStatus = args.getBoolean(AppInterface.CARD_STATUS); |
| 604 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 605 | CatLog.d(LOG_TAG, "CardStatus: " + cardStatus); |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 606 | if (cardStatus == false) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 607 | CatLog.d(LOG_TAG, "CARD is ABSENT"); |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 608 | // Uninstall STKAPP, Clear Idle text, Stop StkAppService |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 609 | mNotificationManager.cancel(getNotificationId(slotId)); |
| 610 | if (isAllOtherCardsAbsent(slotId)) { |
| 611 | CatLog.d(LOG_TAG, "All CARDs are ABSENT"); |
| 612 | StkAppInstaller.unInstall(mContext); |
| 613 | stopSelf(); |
| 614 | } |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 615 | } else { |
| 616 | IccRefreshResponse state = new IccRefreshResponse(); |
| 617 | state.refreshResult = args.getInt(AppInterface.REFRESH_RESULT); |
| 618 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 619 | CatLog.d(LOG_TAG, "Icc Refresh Result: "+ state.refreshResult); |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 620 | if ((state.refreshResult == IccRefreshResponse.REFRESH_RESULT_INIT) || |
| 621 | (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET)) { |
| 622 | // Clear Idle Text |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 623 | mNotificationManager.cancel(getNotificationId(slotId)); |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | if (state.refreshResult == IccRefreshResponse.REFRESH_RESULT_RESET) { |
| 627 | // Uninstall STkmenu |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 628 | if (isAllOtherCardsAbsent(slotId)) { |
| 629 | StkAppInstaller.unInstall(mContext); |
| 630 | } |
| 631 | mStkContext[slotId].mCurrentMenu = null; |
| 632 | mStkContext[slotId].mMainCmd = null; |
Wink Saville | 94e982b | 2014-07-11 07:38:14 -0700 | [diff] [blame] | 633 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 637 | /* |
| 638 | * Check if all SIMs are absent except the id of slot equals "slotId". |
| 639 | */ |
| 640 | private boolean isAllOtherCardsAbsent(int slotId) { |
| 641 | TelephonyManager mTm = (TelephonyManager) mContext.getSystemService( |
| 642 | Context.TELEPHONY_SERVICE); |
| 643 | int i = 0; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 644 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 645 | for (i = 0; i < mSimCount; i++) { |
| 646 | if (i != slotId && mTm.hasIccCard(i)) { |
| 647 | break; |
| 648 | } |
| 649 | } |
| 650 | if (i == mSimCount) { |
| 651 | return true; |
| 652 | } else { |
| 653 | return false; |
| 654 | } |
| 655 | } |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 656 | |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 657 | /* |
| 658 | * If the device is not in an interactive state, we can assume |
| 659 | * that the screen is idle. |
| 660 | */ |
| 661 | private boolean isScreenIdle() { |
| 662 | return (!mPowerManager.isInteractive()); |
| 663 | } |
| 664 | |
| 665 | private void handleIdleScreen(int slotId) { |
| 666 | |
| 667 | // If the idle screen event is present in the list need to send the |
| 668 | // response to SIM. |
| 669 | CatLog.d(this, "Need to send IDLE SCREEN Available event to SIM"); |
| 670 | checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId); |
| 671 | |
| 672 | if (mStkContext[slotId].mIdleModeTextCmd != null) { |
| 673 | launchIdleText(slotId); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | private void sendScreenBusyResponse(int slotId) { |
| 678 | if (mStkContext[slotId].mCurrentCmd == null) { |
| 679 | return; |
| 680 | } |
| 681 | CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd); |
| 682 | CatLog.d(this, "SCREEN_BUSY"); |
| 683 | resMsg.setResultCode(ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS); |
| 684 | mStkService[slotId].onCmdResponse(resMsg); |
| 685 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 686 | callDelayedMsg(slotId); |
| 687 | } else { |
| 688 | mStkContext[slotId].mCmdInProgress = false; |
| 689 | } |
| 690 | } |
| 691 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 692 | private void sendResponse(int resId, int slotId, boolean confirm) { |
| 693 | Message msg = mServiceHandler.obtainMessage(); |
| 694 | msg.arg1 = OP_RESPONSE; |
Takanori Nakano | 49b1272 | 2016-02-16 14:34:14 +0900 | [diff] [blame] | 695 | msg.arg2 = slotId; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 696 | Bundle args = new Bundle(); |
| 697 | args.putInt(StkAppService.RES_ID, resId); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 698 | args.putBoolean(StkAppService.CONFIRMATION, confirm); |
| 699 | msg.obj = args; |
| 700 | mServiceHandler.sendMessage(msg); |
| 701 | } |
| 702 | |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 703 | private boolean isCmdInteractive(CatCmdMessage cmd) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 704 | switch (cmd.getCmdType()) { |
| 705 | case SEND_DTMF: |
| 706 | case SEND_SMS: |
| 707 | case SEND_SS: |
| 708 | case SEND_USSD: |
| 709 | case SET_UP_IDLE_MODE_TEXT: |
| 710 | case SET_UP_MENU: |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 711 | case CLOSE_CHANNEL: |
| 712 | case RECEIVE_DATA: |
| 713 | case SEND_DATA: |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 714 | case SET_UP_EVENT_LIST: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 715 | return false; |
| 716 | } |
| 717 | |
| 718 | return true; |
| 719 | } |
| 720 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 721 | private void handleDelayedCmd(int slotId) { |
| 722 | CatLog.d(LOG_TAG, "handleDelayedCmd, slotId: " + slotId); |
| 723 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 724 | DelayedCmd cmd = mStkContext[slotId].mCmdsQ.poll(); |
| 725 | if (cmd != null) { |
| 726 | CatLog.d(LOG_TAG, "handleDelayedCmd - queue size: " + |
| 727 | mStkContext[slotId].mCmdsQ.size() + |
| 728 | " id: " + cmd.id + "sim id: " + cmd.slotId); |
| 729 | switch (cmd.id) { |
| 730 | case OP_CMD: |
| 731 | handleCmd(cmd.msg, cmd.slotId); |
| 732 | break; |
| 733 | case OP_END_SESSION: |
| 734 | handleSessionEnd(cmd.slotId); |
| 735 | break; |
| 736 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | } |
| 740 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 741 | private void callDelayedMsg(int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 742 | Message msg = mServiceHandler.obtainMessage(); |
| 743 | msg.arg1 = OP_DELAYED_MSG; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 744 | msg.arg2 = slotId; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 745 | mServiceHandler.sendMessage(msg); |
| 746 | } |
| 747 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 748 | private void callSetActivityInstMsg(int inst_type, int slotId, Object obj) { |
| 749 | Message msg = mServiceHandler.obtainMessage(); |
| 750 | msg.obj = obj; |
| 751 | msg.arg1 = inst_type; |
| 752 | msg.arg2 = slotId; |
| 753 | mServiceHandler.sendMessage(msg); |
| 754 | } |
| 755 | |
| 756 | private void handleSessionEnd(int slotId) { |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 757 | // We should finish all pending activity if receiving END SESSION command. |
| 758 | cleanUpInstanceStackBySlot(slotId); |
| 759 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 760 | mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd; |
| 761 | CatLog.d(LOG_TAG, "[handleSessionEnd] - mCurrentCmd changed to mMainCmd!."); |
| 762 | mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mMainCmd; |
| 763 | CatLog.d(LOG_TAG, "slotId: " + slotId + ", mMenuState: " + |
| 764 | mStkContext[slotId].mMenuState); |
| 765 | |
| 766 | mStkContext[slotId].mIsInputPending = false; |
| 767 | mStkContext[slotId].mIsMenuPending = false; |
| 768 | mStkContext[slotId].mIsDialogPending = false; |
| 769 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 770 | if (mStkContext[slotId].mMainCmd == null) { |
| 771 | CatLog.d(LOG_TAG, "[handleSessionEnd][mMainCmd is null!]"); |
| 772 | } |
| 773 | mStkContext[slotId].lastSelectedItem = null; |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 774 | // In case of SET UP MENU command which removed the app, don't |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 775 | // update the current menu member. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 776 | if (mStkContext[slotId].mCurrentMenu != null && mStkContext[slotId].mMainCmd != null) { |
| 777 | mStkContext[slotId].mCurrentMenu = mStkContext[slotId].mMainCmd.getMenu(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 778 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 779 | CatLog.d(LOG_TAG, "[handleSessionEnd][mMenuState]" + mStkContext[slotId].mMenuIsVisible); |
| 780 | // In mutiple instance architecture, the main menu for slotId will be finished when user |
| 781 | // goes to the Stk menu of the other SIM. So, we should launch a new instance for the |
| 782 | // main menu if the main menu instance has been finished. |
| 783 | // If the current menu is secondary menu, we should launch main menu. |
| 784 | if (StkMenuActivity.STATE_SECONDARY == mStkContext[slotId].mMenuState) { |
| 785 | launchMenuActivity(null, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 786 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 787 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 788 | callDelayedMsg(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 789 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 790 | mStkContext[slotId].mCmdInProgress = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 791 | } |
| 792 | // In case a launch browser command was just confirmed, launch that url. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 793 | if (mStkContext[slotId].launchBrowser) { |
| 794 | mStkContext[slotId].launchBrowser = false; |
| 795 | launchBrowser(mStkContext[slotId].mBrowserSettings); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 796 | } |
| 797 | } |
| 798 | |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 799 | // returns true if any Stk related activity already has focus on the screen |
| 800 | private boolean isTopOfStack() { |
| 801 | ActivityManager mAcivityManager = (ActivityManager) mContext |
| 802 | .getSystemService(ACTIVITY_SERVICE); |
| 803 | String currentPackageName = mAcivityManager.getRunningTasks(1).get(0).topActivity |
| 804 | .getPackageName(); |
| 805 | if (null != currentPackageName) { |
| 806 | return currentPackageName.equals(PACKAGE_NAME); |
| 807 | } |
| 808 | |
| 809 | return false; |
| 810 | } |
| 811 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 812 | private void handleCmd(CatCmdMessage cmdMsg, int slotId) { |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 813 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 814 | if (cmdMsg == null) { |
| 815 | return; |
| 816 | } |
| 817 | // save local reference for state tracking. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 818 | mStkContext[slotId].mCurrentCmd = cmdMsg; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 819 | boolean waitForUsersResponse = true; |
| 820 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 821 | mStkContext[slotId].mIsInputPending = false; |
| 822 | mStkContext[slotId].mIsMenuPending = false; |
| 823 | mStkContext[slotId].mIsDialogPending = false; |
| 824 | |
| 825 | CatLog.d(LOG_TAG,"[handleCmd]" + cmdMsg.getCmdType().name()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 826 | switch (cmdMsg.getCmdType()) { |
| 827 | case DISPLAY_TEXT: |
| 828 | TextMessage msg = cmdMsg.geTextMessage(); |
Jeevaka Badrappan | 854a25c | 2012-12-01 16:32:03 +0200 | [diff] [blame] | 829 | waitForUsersResponse = msg.responseNeeded; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 830 | if (mStkContext[slotId].lastSelectedItem != null) { |
| 831 | msg.title = mStkContext[slotId].lastSelectedItem; |
| 832 | } else if (mStkContext[slotId].mMainCmd != null){ |
| 833 | msg.title = mStkContext[slotId].mMainCmd.getMenu().title; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 834 | } else { |
| 835 | // TODO: get the carrier name from the SIM |
| 836 | msg.title = ""; |
| 837 | } |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 838 | //If we receive a low priority Display Text and the device is |
| 839 | // not displaying any STK related activity and the screen is not idle |
| 840 | // ( that is, device is in an interactive state), then send a screen busy |
| 841 | // terminal response. Otherwise display the message. The existing |
| 842 | // displayed message shall be updated with the new display text |
| 843 | // proactive command (Refer to ETSI TS 102 384 section 27.22.4.1.4.4.2). |
| 844 | if (!(msg.isHighPriority || mStkContext[slotId].mMenuIsVisible |
| 845 | || mStkContext[slotId].mDisplayTextDlgIsVisibile || isTopOfStack())) { |
| 846 | if(!isScreenIdle()) { |
| 847 | CatLog.d(LOG_TAG, "Screen is not idle"); |
| 848 | sendScreenBusyResponse(slotId); |
| 849 | } else { |
| 850 | launchTextDialog(slotId); |
| 851 | } |
| 852 | } else { |
| 853 | launchTextDialog(slotId); |
| 854 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 855 | break; |
| 856 | case SELECT_ITEM: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 857 | CatLog.d(LOG_TAG, "SELECT_ITEM +"); |
| 858 | mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd; |
| 859 | mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu(); |
| 860 | launchMenuActivity(cmdMsg.getMenu(), slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 861 | break; |
| 862 | case SET_UP_MENU: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 863 | mStkContext[slotId].mCmdInProgress = false; |
| 864 | mStkContext[slotId].mMainCmd = mStkContext[slotId].mCurrentCmd; |
| 865 | mStkContext[slotId].mCurrentMenuCmd = mStkContext[slotId].mCurrentCmd; |
| 866 | mStkContext[slotId].mCurrentMenu = cmdMsg.getMenu(); |
| 867 | CatLog.d(LOG_TAG, "SET_UP_MENU [" + removeMenu(slotId) + "]"); |
| 868 | |
| 869 | if (removeMenu(slotId)) { |
| 870 | int i = 0; |
| 871 | CatLog.d(LOG_TAG, "removeMenu() - Uninstall App"); |
| 872 | mStkContext[slotId].mCurrentMenu = null; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 873 | mStkContext[slotId].mMainCmd = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 874 | //Check other setup menu state. If all setup menu are removed, uninstall apk. |
| 875 | for (i = PhoneConstants.SIM_ID_1; i < mSimCount; i++) { |
| 876 | if (i != slotId |
| 877 | && (mStkContext[slotId].mSetupMenuState == STATE_UNKNOWN |
| 878 | || mStkContext[slotId].mSetupMenuState == STATE_EXIST)) { |
| 879 | CatLog.d(LOG_TAG, "Not Uninstall App:" + i + "," |
| 880 | + mStkContext[slotId].mSetupMenuState); |
| 881 | break; |
| 882 | } |
| 883 | } |
| 884 | if (i == mSimCount) { |
| 885 | StkAppInstaller.unInstall(mContext); |
| 886 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 887 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 888 | CatLog.d(LOG_TAG, "install App"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 889 | StkAppInstaller.install(mContext); |
| 890 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 891 | if (mStkContext[slotId].mMenuIsVisible) { |
| 892 | launchMenuActivity(null, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 893 | } |
| 894 | break; |
| 895 | case GET_INPUT: |
| 896 | case GET_INKEY: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 897 | launchInputActivity(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 898 | break; |
| 899 | case SET_UP_IDLE_MODE_TEXT: |
| 900 | waitForUsersResponse = false; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 901 | mStkContext[slotId].mIdleModeTextCmd = mStkContext[slotId].mCurrentCmd; |
| 902 | TextMessage idleModeText = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
| 903 | if (idleModeText == null) { |
| 904 | launchIdleText(slotId); |
| 905 | mStkContext[slotId].mIdleModeTextCmd = null; |
| 906 | } |
| 907 | mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd; |
| 908 | if ((mStkContext[slotId].mIdleModeTextCmd != null) && isScreenIdle()) { |
| 909 | CatLog.d(this, "set up idle mode"); |
| 910 | launchIdleText(slotId); |
| 911 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 912 | break; |
| 913 | case SEND_DTMF: |
| 914 | case SEND_SMS: |
| 915 | case SEND_SS: |
| 916 | case SEND_USSD: |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 917 | case GET_CHANNEL_STATUS: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 918 | waitForUsersResponse = false; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 919 | launchEventMessage(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 920 | break; |
| 921 | case LAUNCH_BROWSER: |
Ryuto Sawada | 0bdc719 | 2016-04-18 12:10:56 +0900 | [diff] [blame] | 922 | // The device setup process should not be interrupted by launching browser. |
| 923 | if (Settings.Global.getInt(mContext.getContentResolver(), |
| 924 | Settings.Global.DEVICE_PROVISIONED, 0) == 0) { |
| 925 | CatLog.d(this, "The command is not performed if the setup has not been completed."); |
| 926 | sendScreenBusyResponse(slotId); |
| 927 | break; |
| 928 | } |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 929 | TextMessage alphaId = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
| 930 | if ((mStkContext[slotId].mCurrentCmd.getBrowserSettings().mode |
| 931 | == LaunchBrowserMode.LAUNCH_IF_NOT_ALREADY_LAUNCHED) && |
| 932 | ((alphaId == null) || TextUtils.isEmpty(alphaId.text))) { |
| 933 | // don't need user confirmation in this case |
| 934 | // just launch the browser or spawn a new tab |
| 935 | CatLog.d(this, "Browser mode is: launch if not already launched " + |
| 936 | "and user confirmation is not currently needed.\n" + |
| 937 | "supressing confirmation dialogue and confirming silently..."); |
| 938 | mStkContext[slotId].launchBrowser = true; |
| 939 | mStkContext[slotId].mBrowserSettings = |
| 940 | mStkContext[slotId].mCurrentCmd.getBrowserSettings(); |
| 941 | sendResponse(RES_ID_CONFIRM, slotId, true); |
| 942 | } else { |
| 943 | launchConfirmationDialog(alphaId, slotId); |
| 944 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 945 | break; |
| 946 | case SET_UP_CALL: |
Preeti Ahuja | dd24010 | 2013-08-30 17:25:06 -0700 | [diff] [blame] | 947 | TextMessage mesg = mStkContext[slotId].mCurrentCmd.getCallSettings().confirmMsg; |
| 948 | if((mesg != null) && (mesg.text == null || mesg.text.length() == 0)) { |
| 949 | mesg.text = getResources().getString(R.string.default_setup_call_msg); |
| 950 | } |
| 951 | CatLog.d(this, "SET_UP_CALL mesg.text " + mesg.text); |
| 952 | launchConfirmationDialog(mesg, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 953 | break; |
| 954 | case PLAY_TONE: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 955 | launchToneDialog(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 956 | break; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 957 | case OPEN_CHANNEL: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 958 | launchOpenChannelDialog(slotId); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 959 | break; |
| 960 | case CLOSE_CHANNEL: |
| 961 | case RECEIVE_DATA: |
| 962 | case SEND_DATA: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 963 | TextMessage m = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 964 | |
| 965 | if ((m != null) && (m.text == null)) { |
| 966 | switch(cmdMsg.getCmdType()) { |
| 967 | case CLOSE_CHANNEL: |
| 968 | m.text = getResources().getString(R.string.default_close_channel_msg); |
| 969 | break; |
| 970 | case RECEIVE_DATA: |
| 971 | m.text = getResources().getString(R.string.default_receive_data_msg); |
| 972 | break; |
| 973 | case SEND_DATA: |
| 974 | m.text = getResources().getString(R.string.default_send_data_msg); |
| 975 | break; |
| 976 | } |
| 977 | } |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 978 | /* |
| 979 | * Display indication in the form of a toast to the user if required. |
| 980 | */ |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 981 | launchEventMessage(slotId); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 982 | break; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 983 | case SET_UP_EVENT_LIST: |
| 984 | mStkContext[slotId].mSetupEventListSettings = |
| 985 | mStkContext[slotId].mCurrentCmd.getSetEventList(); |
| 986 | mStkContext[slotId].mCurrentSetupEventCmd = mStkContext[slotId].mCurrentCmd; |
| 987 | mStkContext[slotId].mCurrentCmd = mStkContext[slotId].mMainCmd; |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 988 | if (isScreenIdle()) { |
| 989 | CatLog.d(this," Check if IDLE_SCREEN_AVAILABLE_EVENT is present in List"); |
| 990 | checkForSetupEvent(IDLE_SCREEN_AVAILABLE_EVENT, null, slotId); |
| 991 | } |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 992 | break; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | if (!waitForUsersResponse) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 996 | if (mStkContext[slotId].mCmdsQ.size() != 0) { |
| 997 | callDelayedMsg(slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 998 | } else { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 999 | mStkContext[slotId].mCmdInProgress = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1004 | private void handleCmdResponse(Bundle args, int slotId) { |
| 1005 | CatLog.d(LOG_TAG, "handleCmdResponse, sim id: " + slotId); |
| 1006 | if (mStkContext[slotId].mCurrentCmd == null) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1007 | return; |
| 1008 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1009 | |
| 1010 | if (mStkService[slotId] == null) { |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 1011 | mStkService[slotId] = CatService.getInstance(slotId); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1012 | if (mStkService[slotId] == null) { |
Alex Yakavenka | d8e2ecd | 2012-04-20 17:10:15 -0700 | [diff] [blame] | 1013 | // This should never happen (we should be responding only to a message |
| 1014 | // that arrived from StkService). It has to exist by this time |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1015 | CatLog.d(LOG_TAG, "Exception! mStkService is null when we need to send response."); |
Alex Yakavenka | d8e2ecd | 2012-04-20 17:10:15 -0700 | [diff] [blame] | 1016 | throw new RuntimeException("mStkService is null when we need to send response"); |
| 1017 | } |
| 1018 | } |
| 1019 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1020 | CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentCmd); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1021 | |
| 1022 | // set result code |
| 1023 | boolean helpRequired = args.getBoolean(HELP, false); |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1024 | boolean confirmed = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1025 | |
| 1026 | switch(args.getInt(RES_ID)) { |
| 1027 | case RES_ID_MENU_SELECTION: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1028 | CatLog.d(LOG_TAG, "MENU_SELECTION=" + mStkContext[slotId]. |
| 1029 | mCurrentMenuCmd.getCmdType()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1030 | int menuSelection = args.getInt(MENU_SELECTION); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1031 | switch(mStkContext[slotId].mCurrentMenuCmd.getCmdType()) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1032 | case SET_UP_MENU: |
| 1033 | case SELECT_ITEM: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1034 | mStkContext[slotId].lastSelectedItem = getItemName(menuSelection, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1035 | if (helpRequired) { |
| 1036 | resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED); |
| 1037 | } else { |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 1038 | resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ? |
| 1039 | ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1040 | } |
| 1041 | resMsg.setMenuSelection(menuSelection); |
| 1042 | break; |
| 1043 | } |
| 1044 | break; |
| 1045 | case RES_ID_INPUT: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1046 | CatLog.d(LOG_TAG, "RES_ID_INPUT"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1047 | String input = args.getString(INPUT); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1048 | if (input != null && (null != mStkContext[slotId].mCurrentCmd.geInput()) && |
| 1049 | (mStkContext[slotId].mCurrentCmd.geInput().yesNo)) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1050 | boolean yesNoSelection = input |
| 1051 | .equals(StkInputActivity.YES_STR_RESPONSE); |
| 1052 | resMsg.setYesNo(yesNoSelection); |
| 1053 | } else { |
| 1054 | if (helpRequired) { |
| 1055 | resMsg.setResultCode(ResultCode.HELP_INFO_REQUIRED); |
| 1056 | } else { |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 1057 | resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ? |
| 1058 | ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1059 | resMsg.setInput(input); |
| 1060 | } |
| 1061 | } |
| 1062 | break; |
| 1063 | case RES_ID_CONFIRM: |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 1064 | CatLog.d(this, "RES_ID_CONFIRM"); |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1065 | confirmed = args.getBoolean(CONFIRMATION); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1066 | switch (mStkContext[slotId].mCurrentCmd.getCmdType()) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1067 | case DISPLAY_TEXT: |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 1068 | if (confirmed) { |
| 1069 | resMsg.setResultCode(mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() ? |
| 1070 | ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK); |
| 1071 | } else { |
| 1072 | resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER); |
| 1073 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1074 | break; |
| 1075 | case LAUNCH_BROWSER: |
| 1076 | resMsg.setResultCode(confirmed ? ResultCode.OK |
| 1077 | : ResultCode.UICC_SESSION_TERM_BY_USER); |
| 1078 | if (confirmed) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1079 | mStkContext[slotId].launchBrowser = true; |
| 1080 | mStkContext[slotId].mBrowserSettings = |
| 1081 | mStkContext[slotId].mCurrentCmd.getBrowserSettings(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1082 | } |
| 1083 | break; |
| 1084 | case SET_UP_CALL: |
| 1085 | resMsg.setResultCode(ResultCode.OK); |
| 1086 | resMsg.setConfirmation(confirmed); |
| 1087 | if (confirmed) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1088 | launchEventMessage(slotId, |
| 1089 | mStkContext[slotId].mCurrentCmd.getCallSettings().callMsg); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1090 | } |
| 1091 | break; |
| 1092 | } |
| 1093 | break; |
| 1094 | case RES_ID_DONE: |
| 1095 | resMsg.setResultCode(ResultCode.OK); |
| 1096 | break; |
| 1097 | case RES_ID_BACKWARD: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1098 | CatLog.d(LOG_TAG, "RES_ID_BACKWARD"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1099 | resMsg.setResultCode(ResultCode.BACKWARD_MOVE_BY_USER); |
| 1100 | break; |
| 1101 | case RES_ID_END_SESSION: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1102 | CatLog.d(LOG_TAG, "RES_ID_END_SESSION"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1103 | resMsg.setResultCode(ResultCode.UICC_SESSION_TERM_BY_USER); |
| 1104 | break; |
| 1105 | case RES_ID_TIMEOUT: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1106 | CatLog.d(LOG_TAG, "RES_ID_TIMEOUT"); |
Naveen Kalla | d517689 | 2009-11-30 12:45:29 -0800 | [diff] [blame] | 1107 | // GCF test-case 27.22.4.1.1 Expected Sequence 1.5 (DISPLAY TEXT, |
| 1108 | // Clear message after delay, successful) expects result code OK. |
| 1109 | // If the command qualifier specifies no user response is required |
| 1110 | // then send OK instead of NO_RESPONSE_FROM_USER |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1111 | if ((mStkContext[slotId].mCurrentCmd.getCmdType().value() == |
| 1112 | AppInterface.CommandType.DISPLAY_TEXT.value()) |
| 1113 | && (mStkContext[slotId].mCurrentCmd.geTextMessage().userClear == false)) { |
Naveen Kalla | d517689 | 2009-11-30 12:45:29 -0800 | [diff] [blame] | 1114 | resMsg.setResultCode(ResultCode.OK); |
| 1115 | } else { |
| 1116 | resMsg.setResultCode(ResultCode.NO_RESPONSE_FROM_USER); |
| 1117 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1118 | break; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1119 | case RES_ID_CHOICE: |
| 1120 | int choice = args.getInt(CHOICE); |
| 1121 | CatLog.d(this, "User Choice=" + choice); |
| 1122 | switch (choice) { |
| 1123 | case YES: |
| 1124 | resMsg.setResultCode(ResultCode.OK); |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1125 | confirmed = true; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1126 | break; |
| 1127 | case NO: |
| 1128 | resMsg.setResultCode(ResultCode.USER_NOT_ACCEPT); |
| 1129 | break; |
| 1130 | } |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1131 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1132 | if (mStkContext[slotId].mCurrentCmd.getCmdType().value() == |
| 1133 | AppInterface.CommandType.OPEN_CHANNEL.value()) { |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1134 | resMsg.setConfirmation(confirmed); |
| 1135 | } |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1136 | break; |
Siddartha Pothapragada | cacf7b8 | 2012-04-16 19:42:38 -0700 | [diff] [blame] | 1137 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1138 | default: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1139 | CatLog.d(LOG_TAG, "Unknown result id"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1140 | return; |
| 1141 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1142 | |
| 1143 | if (null != mStkContext[slotId].mCurrentCmd && |
| 1144 | null != mStkContext[slotId].mCurrentCmd.getCmdType()) { |
| 1145 | CatLog.d(LOG_TAG, "handleCmdResponse- cmdName[" + |
| 1146 | mStkContext[slotId].mCurrentCmd.getCmdType().name() + "]"); |
| 1147 | } |
| 1148 | mStkService[slotId].onCmdResponse(resMsg); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | /** |
| 1152 | * Returns 0 or FLAG_ACTIVITY_NO_USER_ACTION, 0 means the user initiated the action. |
| 1153 | * |
| 1154 | * @param userAction If the userAction is yes then we always return 0 otherwise |
| 1155 | * mMenuIsVisible is used to determine what to return. If mMenuIsVisible is true |
| 1156 | * then we are the foreground app and we'll return 0 as from our perspective a |
| 1157 | * user action did cause. If it's false than we aren't the foreground app and |
| 1158 | * FLAG_ACTIVITY_NO_USER_ACTION is returned. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 1159 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1160 | * @return 0 or FLAG_ACTIVITY_NO_USER_ACTION |
| 1161 | */ |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1162 | private int getFlagActivityNoUserAction(InitiatedByUserAction userAction, int slotId) { |
| 1163 | return ((userAction == InitiatedByUserAction.yes) | mStkContext[slotId].mMenuIsVisible) |
| 1164 | ? 0 : Intent.FLAG_ACTIVITY_NO_USER_ACTION; |
| 1165 | } |
| 1166 | /** |
| 1167 | * This method is used for cleaning up pending instances in stack. |
| 1168 | */ |
| 1169 | private void cleanUpInstanceStackBySlot(int slotId) { |
| 1170 | Activity activity = mStkContext[slotId].getPendingActivityInstance(); |
| 1171 | Activity dialog = mStkContext[slotId].getPendingDialogInstance(); |
| 1172 | CatLog.d(LOG_TAG, "cleanUpInstanceStackBySlot slotId: " + slotId); |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 1173 | if (mStkContext[slotId].mCurrentCmd == null) { |
| 1174 | CatLog.d(LOG_TAG, "current cmd is null."); |
| 1175 | return; |
| 1176 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1177 | if (activity != null) { |
| 1178 | CatLog.d(LOG_TAG, "current cmd type: " + |
| 1179 | mStkContext[slotId].mCurrentCmd.getCmdType()); |
| 1180 | if (mStkContext[slotId].mCurrentCmd.getCmdType().value() == |
| 1181 | AppInterface.CommandType.GET_INPUT.value() || |
| 1182 | mStkContext[slotId].mCurrentCmd.getCmdType().value() == |
| 1183 | AppInterface.CommandType.GET_INKEY.value()) { |
| 1184 | mStkContext[slotId].mIsInputPending = true; |
| 1185 | } else if (mStkContext[slotId].mCurrentCmd.getCmdType().value() == |
| 1186 | AppInterface.CommandType.SET_UP_MENU.value() || |
| 1187 | mStkContext[slotId].mCurrentCmd.getCmdType().value() == |
| 1188 | AppInterface.CommandType.SELECT_ITEM.value()) { |
| 1189 | mStkContext[slotId].mIsMenuPending = true; |
| 1190 | } else { |
| 1191 | } |
| 1192 | CatLog.d(LOG_TAG, "finish pending activity."); |
| 1193 | activity.finish(); |
| 1194 | mStkContext[slotId].mActivityInstance = null; |
| 1195 | } |
| 1196 | if (dialog != null) { |
| 1197 | CatLog.d(LOG_TAG, "finish pending dialog."); |
| 1198 | mStkContext[slotId].mIsDialogPending = true; |
| 1199 | dialog.finish(); |
| 1200 | mStkContext[slotId].mDialogInstance = null; |
| 1201 | } |
| 1202 | } |
| 1203 | /** |
| 1204 | * This method is used for restoring pending instances from stack. |
| 1205 | */ |
| 1206 | private void restoreInstanceFromStackBySlot(int slotId) { |
| 1207 | AppInterface.CommandType cmdType = mStkContext[slotId].mCurrentCmd.getCmdType(); |
| 1208 | |
| 1209 | CatLog.d(LOG_TAG, "restoreInstanceFromStackBySlot cmdType : " + cmdType); |
| 1210 | switch(cmdType) { |
| 1211 | case GET_INPUT: |
| 1212 | case GET_INKEY: |
| 1213 | launchInputActivity(slotId); |
| 1214 | //Set mMenuIsVisible to true for showing main menu for |
| 1215 | //following session end command. |
| 1216 | mStkContext[slotId].mMenuIsVisible = true; |
| 1217 | break; |
| 1218 | case DISPLAY_TEXT: |
| 1219 | launchTextDialog(slotId); |
| 1220 | break; |
| 1221 | case LAUNCH_BROWSER: |
| 1222 | launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.geTextMessage(), |
| 1223 | slotId); |
| 1224 | break; |
| 1225 | case OPEN_CHANNEL: |
| 1226 | launchOpenChannelDialog(slotId); |
| 1227 | break; |
| 1228 | case SET_UP_CALL: |
| 1229 | launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.getCallSettings(). |
| 1230 | confirmMsg, slotId); |
| 1231 | break; |
| 1232 | case SET_UP_MENU: |
| 1233 | case SELECT_ITEM: |
| 1234 | launchMenuActivity(null, slotId); |
| 1235 | break; |
| 1236 | default: |
| 1237 | break; |
| 1238 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1239 | } |
| 1240 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1241 | private void launchMenuActivity(Menu menu, int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1242 | Intent newIntent = new Intent(Intent.ACTION_VIEW); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1243 | String targetActivity = STK_MENU_ACTIVITY_NAME; |
| 1244 | String uriString = STK_MENU_URI + System.currentTimeMillis(); |
| 1245 | //Set unique URI to create a new instance of activity for different slotId. |
| 1246 | Uri uriData = Uri.parse(uriString); |
| 1247 | |
| 1248 | CatLog.d(LOG_TAG, "launchMenuActivity, slotId: " + slotId + " , " + |
| 1249 | uriData.toString() + " , " + mStkContext[slotId].mOpCode + ", " |
| 1250 | + mStkContext[slotId].mMenuState); |
| 1251 | newIntent.setClassName(PACKAGE_NAME, targetActivity); |
| 1252 | int intentFlags = Intent.FLAG_ACTIVITY_NEW_TASK; |
| 1253 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1254 | if (menu == null) { |
| 1255 | // We assume this was initiated by the user pressing the tool kit icon |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1256 | intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.yes, slotId); |
| 1257 | if (mStkContext[slotId].mOpCode == OP_END_SESSION) { |
| 1258 | CatLog.d(LOG_TAG, "launchMenuActivity, return OP_END_SESSION"); |
| 1259 | mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN; |
| 1260 | if (mStkContext[slotId].mMainActivityInstance != null) { |
| 1261 | CatLog.d(LOG_TAG, "launchMenuActivity, mMainActivityInstance is not null"); |
| 1262 | return; |
| 1263 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1264 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1265 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1266 | //If the last pending menu is secondary menu, "STATE" should be "STATE_SECONDARY". |
| 1267 | //Otherwise, it should be "STATE_MAIN". |
| 1268 | if (mStkContext[slotId].mOpCode == OP_LAUNCH_APP && |
| 1269 | mStkContext[slotId].mMenuState == StkMenuActivity.STATE_SECONDARY) { |
| 1270 | newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY); |
| 1271 | } else { |
| 1272 | newIntent.putExtra("STATE", StkMenuActivity.STATE_MAIN); |
| 1273 | mStkContext[slotId].mMenuState = StkMenuActivity.STATE_MAIN; |
| 1274 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1275 | } else { |
| 1276 | // We don't know and we'll let getFlagActivityNoUserAction decide. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1277 | intentFlags |= getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1278 | newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1279 | mStkContext[slotId].mMenuState = StkMenuActivity.STATE_SECONDARY; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1280 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1281 | newIntent.putExtra(SLOT_ID, slotId); |
| 1282 | newIntent.setData(uriData); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1283 | newIntent.setFlags(intentFlags); |
| 1284 | mContext.startActivity(newIntent); |
| 1285 | } |
| 1286 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1287 | private void launchInputActivity(int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1288 | Intent newIntent = new Intent(Intent.ACTION_VIEW); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1289 | String targetActivity = STK_INPUT_ACTIVITY_NAME; |
| 1290 | String uriString = STK_INPUT_URI + System.currentTimeMillis(); |
| 1291 | //Set unique URI to create a new instance of activity for different slotId. |
| 1292 | Uri uriData = Uri.parse(uriString); |
| 1293 | |
| 1294 | CatLog.d(LOG_TAG, "launchInputActivity, slotId: " + slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1295 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1296 | | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); |
| 1297 | newIntent.setClassName(PACKAGE_NAME, targetActivity); |
| 1298 | newIntent.putExtra("INPUT", mStkContext[slotId].mCurrentCmd.geInput()); |
| 1299 | newIntent.putExtra(SLOT_ID, slotId); |
| 1300 | newIntent.setData(uriData); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1301 | mContext.startActivity(newIntent); |
| 1302 | } |
| 1303 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1304 | private void launchTextDialog(int slotId) { |
| 1305 | CatLog.d(LOG_TAG, "launchTextDialog, slotId: " + slotId); |
| 1306 | Intent newIntent = new Intent(); |
| 1307 | String targetActivity = STK_DIALOG_ACTIVITY_NAME; |
| 1308 | int action = getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId); |
| 1309 | String uriString = STK_DIALOG_URI + System.currentTimeMillis(); |
| 1310 | //Set unique URI to create a new instance of activity for different slotId. |
| 1311 | Uri uriData = Uri.parse(uriString); |
| 1312 | if (newIntent != null) { |
| 1313 | newIntent.setClassName(PACKAGE_NAME, targetActivity); |
| 1314 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1315 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 1316 | | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); |
| 1317 | newIntent.setData(uriData); |
| 1318 | newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage()); |
| 1319 | newIntent.putExtra(SLOT_ID, slotId); |
| 1320 | startActivity(newIntent); |
Preeti Ahuja | 414bc41 | 2013-06-25 19:31:49 -0700 | [diff] [blame] | 1321 | // For display texts with immediate response, send the terminal response |
| 1322 | // immediately. responseNeeded will be false, if display text command has |
| 1323 | // the immediate response tlv. |
| 1324 | if (!mStkContext[slotId].mCurrentCmd.geTextMessage().responseNeeded) { |
| 1325 | sendResponse(RES_ID_CONFIRM, slotId, true); |
| 1326 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1327 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1328 | } |
| 1329 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1330 | public boolean isStkDialogActivated(Context context) { |
| 1331 | String stkDialogActivity = "com.android.stk.StkDialogActivity"; |
| 1332 | boolean activated = false; |
| 1333 | final ActivityManager am = (ActivityManager) context.getSystemService( |
| 1334 | Context.ACTIVITY_SERVICE); |
| 1335 | String topActivity = am.getRunningTasks(1).get(0).topActivity.getClassName(); |
| 1336 | |
| 1337 | CatLog.d(LOG_TAG, "isStkDialogActivated: " + topActivity); |
| 1338 | if (topActivity.equals(stkDialogActivity)) { |
| 1339 | activated = true; |
| 1340 | } |
| 1341 | CatLog.d(LOG_TAG, "activated : " + activated); |
| 1342 | return activated; |
Johan Hellman | 3aec01c | 2011-02-10 10:15:28 +0100 | [diff] [blame] | 1343 | } |
| 1344 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1345 | private void sendSetUpEventResponse(int event, byte[] addedInfo, int slotId) { |
Preeti Ahuja | 414bc41 | 2013-06-25 19:31:49 -0700 | [diff] [blame] | 1346 | CatLog.d(this, "sendSetUpEventResponse: event : " + event + "slotId = " + slotId); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1347 | |
| 1348 | if (mStkContext[slotId].mCurrentSetupEventCmd == null){ |
| 1349 | CatLog.e(this, "mCurrentSetupEventCmd is null"); |
| 1350 | return; |
| 1351 | } |
| 1352 | |
| 1353 | CatResponseMessage resMsg = new CatResponseMessage(mStkContext[slotId].mCurrentSetupEventCmd); |
| 1354 | |
| 1355 | resMsg.setResultCode(ResultCode.OK); |
| 1356 | resMsg.setEventDownload(event, addedInfo); |
| 1357 | |
| 1358 | mStkService[slotId].onCmdResponse(resMsg); |
| 1359 | } |
| 1360 | |
| 1361 | private void checkForSetupEvent(int event, Bundle args, int slotId) { |
| 1362 | boolean eventPresent = false; |
| 1363 | byte[] addedInfo = null; |
| 1364 | CatLog.d(this, "Event :" + event); |
| 1365 | |
| 1366 | if (mStkContext[slotId].mSetupEventListSettings != null) { |
| 1367 | /* Checks if the event is present in the EventList updated by last |
| 1368 | * SetupEventList Proactive Command */ |
| 1369 | for (int i : mStkContext[slotId].mSetupEventListSettings.eventList) { |
| 1370 | if (event == i) { |
| 1371 | eventPresent = true; |
| 1372 | break; |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | /* If Event is present send the response to ICC */ |
| 1377 | if (eventPresent == true) { |
| 1378 | CatLog.d(this, " Event " + event + "exists in the EventList"); |
| 1379 | |
| 1380 | switch (event) { |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1381 | case IDLE_SCREEN_AVAILABLE_EVENT: |
| 1382 | sendSetUpEventResponse(event, addedInfo, slotId); |
| 1383 | removeSetUpEvent(event, slotId); |
| 1384 | break; |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1385 | case LANGUAGE_SELECTION_EVENT: |
| 1386 | String language = mContext |
| 1387 | .getResources().getConfiguration().locale.getLanguage(); |
| 1388 | CatLog.d(this, "language: " + language); |
| 1389 | // Each language code is a pair of alpha-numeric characters. |
| 1390 | // Each alpha-numeric character shall be coded on one byte |
| 1391 | // using the SMS default 7-bit coded alphabet |
| 1392 | addedInfo = GsmAlphabet.stringToGsm8BitPacked(language); |
| 1393 | sendSetUpEventResponse(event, addedInfo, slotId); |
| 1394 | break; |
| 1395 | default: |
| 1396 | break; |
| 1397 | } |
| 1398 | } else { |
| 1399 | CatLog.e(this, " Event does not exist in the EventList"); |
| 1400 | } |
| 1401 | } else { |
| 1402 | CatLog.e(this, "SetupEventList is not received. Ignoring the event: " + event); |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | private void removeSetUpEvent(int event, int slotId) { |
| 1407 | CatLog.d(this, "Remove Event :" + event); |
| 1408 | |
| 1409 | if (mStkContext[slotId].mSetupEventListSettings != null) { |
| 1410 | /* |
| 1411 | * Make new Eventlist without the event |
| 1412 | */ |
| 1413 | for (int i = 0; i < mStkContext[slotId].mSetupEventListSettings.eventList.length; i++) { |
| 1414 | if (event == mStkContext[slotId].mSetupEventListSettings.eventList[i]) { |
| 1415 | mStkContext[slotId].mSetupEventListSettings.eventList[i] = INVALID_SETUP_EVENT; |
| 1416 | break; |
| 1417 | } |
| 1418 | } |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | private void launchEventMessage(int slotId) { |
| 1423 | launchEventMessage(slotId, mStkContext[slotId].mCurrentCmd.geTextMessage()); |
| 1424 | } |
| 1425 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1426 | private void launchEventMessage(int slotId, TextMessage msg) { |
| 1427 | if (msg == null || (msg.text != null && msg.text.length() == 0)) { |
| 1428 | CatLog.d(LOG_TAG, "launchEventMessage return"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1429 | return; |
| 1430 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1431 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1432 | Toast toast = new Toast(mContext.getApplicationContext()); |
| 1433 | LayoutInflater inflate = (LayoutInflater) mContext |
| 1434 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 1435 | View v = inflate.inflate(R.layout.stk_event_msg, null); |
| 1436 | TextView tv = (TextView) v |
| 1437 | .findViewById(com.android.internal.R.id.message); |
| 1438 | ImageView iv = (ImageView) v |
| 1439 | .findViewById(com.android.internal.R.id.icon); |
| 1440 | if (msg.icon != null) { |
| 1441 | iv.setImageBitmap(msg.icon); |
| 1442 | } else { |
| 1443 | iv.setVisibility(View.GONE); |
| 1444 | } |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 1445 | /* In case of 'self explanatory' stkapp should display the specified |
| 1446 | * icon in proactive command (but not the alpha string). |
| 1447 | * If icon is non-self explanatory and if the icon could not be displayed |
| 1448 | * then alpha string or text data should be displayed |
| 1449 | * Ref: ETSI 102.223,section 6.5.4 |
| 1450 | */ |
| 1451 | if (mStkContext[slotId].mCurrentCmd.hasIconLoadFailed() || |
| 1452 | msg.icon == null || !msg.iconSelfExplanatory) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1453 | tv.setText(msg.text); |
| 1454 | } |
| 1455 | |
| 1456 | toast.setView(v); |
| 1457 | toast.setDuration(Toast.LENGTH_LONG); |
| 1458 | toast.setGravity(Gravity.BOTTOM, 0, 0); |
| 1459 | toast.show(); |
| 1460 | } |
| 1461 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1462 | private void launchConfirmationDialog(TextMessage msg, int slotId) { |
| 1463 | msg.title = mStkContext[slotId].lastSelectedItem; |
| 1464 | Intent newIntent = new Intent(); |
| 1465 | String targetActivity = STK_DIALOG_ACTIVITY_NAME; |
| 1466 | String uriString = STK_DIALOG_URI + System.currentTimeMillis(); |
| 1467 | //Set unique URI to create a new instance of activity for different slotId. |
| 1468 | Uri uriData = Uri.parse(uriString); |
| 1469 | |
| 1470 | if (newIntent != null) { |
| 1471 | newIntent.setClassName(this, targetActivity); |
| 1472 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1473 | | Intent.FLAG_ACTIVITY_NO_HISTORY |
| 1474 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 1475 | | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); |
| 1476 | newIntent.putExtra("TEXT", msg); |
| 1477 | newIntent.putExtra(SLOT_ID, slotId); |
| 1478 | newIntent.setData(uriData); |
| 1479 | startActivity(newIntent); |
| 1480 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | private void launchBrowser(BrowserSettings settings) { |
| 1484 | if (settings == null) { |
| 1485 | return; |
| 1486 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1487 | |
Abhishek Adappa | 840c82f | 2013-02-26 10:19:49 -0800 | [diff] [blame] | 1488 | Uri data = null; |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 1489 | String url; |
| 1490 | if (settings.url == null) { |
Abhishek Adappa | 840c82f | 2013-02-26 10:19:49 -0800 | [diff] [blame] | 1491 | // if the command did not contain a URL, |
| 1492 | // launch the browser to the default homepage. |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 1493 | CatLog.d(this, "no url data provided by proactive command." + |
| 1494 | " launching browser with stk default URL ... "); |
| 1495 | url = SystemProperties.get(STK_BROWSER_DEFAULT_URL_SYSPROP, |
| 1496 | "http://www.google.com"); |
| 1497 | } else { |
| 1498 | CatLog.d(this, "launch browser command has attached url = " + settings.url); |
| 1499 | url = settings.url; |
Abhishek Adappa | 840c82f | 2013-02-26 10:19:49 -0800 | [diff] [blame] | 1500 | } |
David Brown | 7c03cfe | 2011-10-20 15:36:12 -0700 | [diff] [blame] | 1501 | |
Preeti Ahuja | a7cdca2 | 2013-10-01 18:20:56 -0700 | [diff] [blame] | 1502 | if (url.startsWith("http://") || url.startsWith("https://")) { |
| 1503 | data = Uri.parse(url); |
| 1504 | CatLog.d(this, "launching browser with url = " + url); |
| 1505 | } else { |
| 1506 | String modifiedUrl = "http://" + url; |
| 1507 | data = Uri.parse(modifiedUrl); |
| 1508 | CatLog.d(this, "launching browser with modified url = " + modifiedUrl); |
| 1509 | } |
| 1510 | |
| 1511 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 1512 | intent.setData(data); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1513 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1514 | switch (settings.mode) { |
| 1515 | case USE_EXISTING_BROWSER: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1516 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 1517 | break; |
| 1518 | case LAUNCH_NEW_BROWSER: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1519 | intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); |
| 1520 | break; |
| 1521 | case LAUNCH_IF_NOT_ALREADY_LAUNCHED: |
| 1522 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 1523 | break; |
| 1524 | } |
| 1525 | // start browser activity |
| 1526 | startActivity(intent); |
| 1527 | // a small delay, let the browser start, before processing the next command. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 1528 | // this is good for scenarios where a related DISPLAY TEXT command is |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1529 | // followed immediately. |
| 1530 | try { |
Ryuto Sawada | 350aaa6 | 2016-06-13 14:47:22 +0900 | [diff] [blame] | 1531 | Thread.sleep(3000); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1532 | } catch (InterruptedException e) {} |
| 1533 | } |
| 1534 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1535 | private void launchIdleText(int slotId) { |
Preeti Ahuja | 560be36 | 2014-11-25 19:38:24 -0800 | [diff] [blame] | 1536 | TextMessage msg = mStkContext[slotId].mIdleModeTextCmd.geTextMessage(); |
dujin.cha | 2a0eb2a | 2011-11-11 15:03:57 +0900 | [diff] [blame] | 1537 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1538 | if (msg == null || msg.text ==null) { |
| 1539 | CatLog.d(LOG_TAG, msg == null ? "mCurrent.getTextMessage is NULL" |
| 1540 | : "mCurrent.getTextMessage.text is NULL"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1541 | mNotificationManager.cancel(getNotificationId(slotId)); |
Wink Saville | 046db4b | 2011-11-01 20:42:54 -0700 | [diff] [blame] | 1542 | return; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1543 | } else { |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 1544 | CatLog.d(LOG_TAG, "launchIdleText - text[" + msg.text |
| 1545 | + "] iconSelfExplanatory[" + msg.iconSelfExplanatory |
| 1546 | + "] icon[" + msg.icon + "], sim id: " + slotId); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1547 | CatLog.d(LOG_TAG, "Add IdleMode text"); |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 1548 | PendingIntent pendingIntent = PendingIntent.getService(mContext, 0, |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1549 | new Intent(mContext, StkAppService.class), 0); |
| 1550 | |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 1551 | final Notification.Builder notificationBuilder = new Notification.Builder( |
| 1552 | StkAppService.this); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1553 | if (mStkContext[slotId].mMainCmd != null && |
| 1554 | mStkContext[slotId].mMainCmd.getMenu() != null) { |
| 1555 | notificationBuilder.setContentTitle(mStkContext[slotId].mMainCmd.getMenu().title); |
Christopher Posselwhite | 2ad2ab7 | 2013-05-27 07:51:06 +0200 | [diff] [blame] | 1556 | } else { |
| 1557 | notificationBuilder.setContentTitle(""); |
| 1558 | } |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 1559 | notificationBuilder |
| 1560 | .setSmallIcon(com.android.internal.R.drawable.stat_notify_sim_toolkit); |
| 1561 | notificationBuilder.setContentIntent(pendingIntent); |
| 1562 | notificationBuilder.setOngoing(true); |
| 1563 | // Set text and icon for the status bar and notification body. |
Preeti Ahuja | f33bf39 | 2013-09-28 19:11:31 +0530 | [diff] [blame] | 1564 | if (mStkContext[slotId].mIdleModeTextCmd.hasIconLoadFailed() || |
| 1565 | !msg.iconSelfExplanatory) { |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 1566 | notificationBuilder.setContentText(msg.text); |
Christopher Posselwhite | 2ad2ab7 | 2013-05-27 07:51:06 +0200 | [diff] [blame] | 1567 | notificationBuilder.setTicker(msg.text); |
Alex Khlivnuik | 50e0a1d | 2013-01-25 12:50:48 +0100 | [diff] [blame] | 1568 | } |
| 1569 | if (msg.icon != null) { |
| 1570 | notificationBuilder.setLargeIcon(msg.icon); |
| 1571 | } else { |
| 1572 | Bitmap bitmapIcon = BitmapFactory.decodeResource(StkAppService.this |
| 1573 | .getResources().getSystem(), |
| 1574 | com.android.internal.R.drawable.stat_notify_sim_toolkit); |
| 1575 | notificationBuilder.setLargeIcon(bitmapIcon); |
| 1576 | } |
Selim Cinek | 62eb3fe | 2014-08-27 17:52:23 +0200 | [diff] [blame] | 1577 | notificationBuilder.setColor(mContext.getResources().getColor( |
| 1578 | com.android.internal.R.color.system_notification_accent_color)); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1579 | mNotificationManager.notify(getNotificationId(slotId), notificationBuilder.build()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1580 | } |
| 1581 | } |
| 1582 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1583 | private void launchToneDialog(int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1584 | Intent newIntent = new Intent(this, ToneDialog.class); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1585 | String uriString = STK_TONE_URI + slotId; |
| 1586 | Uri uriData = Uri.parse(uriString); |
| 1587 | //Set unique URI to create a new instance of activity for different slotId. |
| 1588 | CatLog.d(LOG_TAG, "launchToneDialog, slotId: " + slotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1589 | newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1590 | | Intent.FLAG_ACTIVITY_NO_HISTORY |
| 1591 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1592 | | getFlagActivityNoUserAction(InitiatedByUserAction.unknown, slotId)); |
| 1593 | newIntent.putExtra("TEXT", mStkContext[slotId].mCurrentCmd.geTextMessage()); |
| 1594 | newIntent.putExtra("TONE", mStkContext[slotId].mCurrentCmd.getToneSettings()); |
| 1595 | newIntent.putExtra(SLOT_ID, slotId); |
| 1596 | newIntent.setData(uriData); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1597 | startActivity(newIntent); |
| 1598 | } |
| 1599 | |
Takanori Nakano | 49b1272 | 2016-02-16 14:34:14 +0900 | [diff] [blame] | 1600 | private void launchOpenChannelDialog(final int slotId) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1601 | TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1602 | if (msg == null) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1603 | CatLog.d(LOG_TAG, "msg is null, return here"); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1604 | return; |
| 1605 | } |
| 1606 | |
| 1607 | msg.title = getResources().getString(R.string.stk_dialog_title); |
| 1608 | if (msg.text == null) { |
| 1609 | msg.text = getResources().getString(R.string.default_open_channel_msg); |
| 1610 | } |
| 1611 | |
| 1612 | final AlertDialog dialog = new AlertDialog.Builder(mContext) |
| 1613 | .setIconAttribute(android.R.attr.alertDialogIcon) |
| 1614 | .setTitle(msg.title) |
| 1615 | .setMessage(msg.text) |
| 1616 | .setCancelable(false) |
| 1617 | .setPositiveButton(getResources().getString(R.string.stk_dialog_accept), |
| 1618 | new DialogInterface.OnClickListener() { |
| 1619 | public void onClick(DialogInterface dialog, int which) { |
| 1620 | Bundle args = new Bundle(); |
| 1621 | args.putInt(RES_ID, RES_ID_CHOICE); |
| 1622 | args.putInt(CHOICE, YES); |
| 1623 | Message message = mServiceHandler.obtainMessage(); |
| 1624 | message.arg1 = OP_RESPONSE; |
Takanori Nakano | 49b1272 | 2016-02-16 14:34:14 +0900 | [diff] [blame] | 1625 | message.arg2 = slotId; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1626 | message.obj = args; |
| 1627 | mServiceHandler.sendMessage(message); |
| 1628 | } |
| 1629 | }) |
| 1630 | .setNegativeButton(getResources().getString(R.string.stk_dialog_reject), |
| 1631 | new DialogInterface.OnClickListener() { |
| 1632 | public void onClick(DialogInterface dialog, int which) { |
| 1633 | Bundle args = new Bundle(); |
| 1634 | args.putInt(RES_ID, RES_ID_CHOICE); |
| 1635 | args.putInt(CHOICE, NO); |
| 1636 | Message message = mServiceHandler.obtainMessage(); |
| 1637 | message.arg1 = OP_RESPONSE; |
Takanori Nakano | 49b1272 | 2016-02-16 14:34:14 +0900 | [diff] [blame] | 1638 | message.arg2 = slotId; |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1639 | message.obj = args; |
| 1640 | mServiceHandler.sendMessage(message); |
| 1641 | } |
| 1642 | }) |
| 1643 | .create(); |
| 1644 | |
| 1645 | dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
| 1646 | if (!mContext.getResources().getBoolean( |
| 1647 | com.android.internal.R.bool.config_sf_slowBlur)) { |
| 1648 | dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
| 1649 | } |
| 1650 | |
| 1651 | dialog.show(); |
| 1652 | } |
| 1653 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1654 | private void launchTransientEventMessage(int slotId) { |
| 1655 | TextMessage msg = mStkContext[slotId].mCurrentCmd.geTextMessage(); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1656 | if (msg == null) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1657 | CatLog.d(LOG_TAG, "msg is null, return here"); |
Kazuhiro Ondo | 764167c | 2011-10-21 16:05:05 -0500 | [diff] [blame] | 1658 | return; |
| 1659 | } |
| 1660 | |
| 1661 | msg.title = getResources().getString(R.string.stk_dialog_title); |
| 1662 | |
| 1663 | final AlertDialog dialog = new AlertDialog.Builder(mContext) |
| 1664 | .setIconAttribute(android.R.attr.alertDialogIcon) |
| 1665 | .setTitle(msg.title) |
| 1666 | .setMessage(msg.text) |
| 1667 | .setCancelable(false) |
| 1668 | .setPositiveButton(getResources().getString(android.R.string.ok), |
| 1669 | new DialogInterface.OnClickListener() { |
| 1670 | public void onClick(DialogInterface dialog, int which) { |
| 1671 | } |
| 1672 | }) |
| 1673 | .create(); |
| 1674 | |
| 1675 | dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
| 1676 | if (!mContext.getResources().getBoolean( |
| 1677 | com.android.internal.R.bool.config_sf_slowBlur)) { |
| 1678 | dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
| 1679 | } |
| 1680 | |
| 1681 | dialog.show(); |
| 1682 | } |
| 1683 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1684 | private int getNotificationId(int slotId) { |
| 1685 | int notifyId = STK_NOTIFICATION_ID; |
| 1686 | if (slotId >= 0 && slotId < mSimCount) { |
| 1687 | notifyId += slotId; |
| 1688 | } else { |
| 1689 | CatLog.d(LOG_TAG, "invalid slotId: " + slotId); |
| 1690 | } |
| 1691 | CatLog.d(LOG_TAG, "getNotificationId, slotId: " + slotId + ", notifyId: " + notifyId); |
| 1692 | return notifyId; |
| 1693 | } |
| 1694 | |
| 1695 | private String getItemName(int itemId, int slotId) { |
| 1696 | Menu menu = mStkContext[slotId].mCurrentCmd.getMenu(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1697 | if (menu == null) { |
| 1698 | return null; |
| 1699 | } |
| 1700 | for (Item item : menu.items) { |
| 1701 | if (item.id == itemId) { |
| 1702 | return item.text; |
| 1703 | } |
| 1704 | } |
| 1705 | return null; |
| 1706 | } |
| 1707 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1708 | private boolean removeMenu(int slotId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1709 | try { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1710 | if (mStkContext[slotId].mCurrentMenu.items.size() == 1 && |
| 1711 | mStkContext[slotId].mCurrentMenu.items.get(0) == null) { |
| 1712 | mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1713 | return true; |
| 1714 | } |
| 1715 | } catch (NullPointerException e) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1716 | CatLog.d(LOG_TAG, "Unable to get Menu's items size"); |
| 1717 | mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1718 | return true; |
| 1719 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1720 | mStkContext[slotId].mSetupMenuState = STATE_EXIST; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1721 | return false; |
| 1722 | } |
Preeti Ahuja | 0f4cf2f | 2012-08-09 11:45:08 +0530 | [diff] [blame] | 1723 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 1724 | StkContext getStkContext(int slotId) { |
| 1725 | if (slotId >= 0 && slotId < mSimCount) { |
| 1726 | return mStkContext[slotId]; |
| 1727 | } else { |
| 1728 | CatLog.d(LOG_TAG, "invalid slotId: " + slotId); |
| 1729 | return null; |
| 1730 | } |
| 1731 | } |
Preeti Ahuja | 0f4cf2f | 2012-08-09 11:45:08 +0530 | [diff] [blame] | 1732 | |
| 1733 | private void handleAlphaNotify(Bundle args) { |
| 1734 | String alphaString = args.getString(AppInterface.ALPHA_STRING); |
| 1735 | |
| 1736 | CatLog.d(this, "Alpha string received from card: " + alphaString); |
| 1737 | Toast toast = Toast.makeText(sInstance, alphaString, Toast.LENGTH_LONG); |
| 1738 | toast.setGravity(Gravity.TOP, 0, 0); |
| 1739 | toast.show(); |
| 1740 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1741 | } |