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