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