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 | |
Christopher Posselwhite | cfe4d7f | 2013-09-04 09:01:50 +0200 | [diff] [blame] | 19 | import com.android.internal.telephony.cat.CatLog; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 20 | import com.android.internal.telephony.cat.TextMessage; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 21 | |
| 22 | import android.app.Activity; |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 23 | import android.app.AlarmManager; |
Sanket Padawe | 7b70fb4 | 2017-04-05 15:35:34 -0700 | [diff] [blame] | 24 | import android.app.AlertDialog; |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 25 | import android.app.PendingIntent; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 26 | import android.content.Intent; |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 27 | import android.content.IntentFilter; |
| 28 | import android.content.BroadcastReceiver; |
| 29 | import android.content.Context; |
Sanket Padawe | 7b70fb4 | 2017-04-05 15:35:34 -0700 | [diff] [blame] | 30 | import android.content.DialogInterface; |
Sanket Padawe | 7b70fb4 | 2017-04-05 15:35:34 -0700 | [diff] [blame] | 31 | |
Yoshiaki Naka | 25273c9 | 2017-10-31 20:00:33 +0900 | [diff] [blame] | 32 | import android.os.Build; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 33 | import android.os.Bundle; |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 34 | import android.os.SystemClock; |
Yoshiaki Naka | 9018313 | 2017-08-31 19:25:33 +0900 | [diff] [blame] | 35 | import android.telephony.SubscriptionManager; |
Takanori Nakano | 9ecdba7 | 2017-07-21 15:27:49 +0900 | [diff] [blame] | 36 | import android.text.TextUtils; |
| 37 | import android.view.LayoutInflater; |
| 38 | import android.view.View; |
| 39 | import android.widget.ImageView; |
| 40 | import android.widget.TextView; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 41 | |
| 42 | /** |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 43 | * AlertDialog used for DISPLAY TEXT commands. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 44 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 45 | */ |
Sanket Padawe | 7b70fb4 | 2017-04-05 15:35:34 -0700 | [diff] [blame] | 46 | public class StkDialogActivity extends Activity { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 47 | // members |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 48 | private static final String className = new Object(){}.getClass().getEnclosingClass().getName(); |
| 49 | private static final String LOG_TAG = className.substring(className.lastIndexOf('.') + 1); |
| 50 | TextMessage mTextMsg = null; |
| 51 | private int mSlotId = -1; |
| 52 | private StkAppService appService = StkAppService.getInstance(); |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 53 | // Determines whether Terminal Response (TR) has been sent |
Johannes Carlsson | ef243a2 | 2011-10-25 10:37:24 +0200 | [diff] [blame] | 54 | private boolean mIsResponseSent = false; |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 55 | private Context mContext; |
| 56 | // Utilize AlarmManager for real-time countdown |
| 57 | private PendingIntent mTimeoutIntent; |
| 58 | private AlarmManager mAlarmManager; |
| 59 | private final static String ALARM_TIMEOUT = "com.android.stk.DIALOG_ALARM_TIMEOUT"; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 60 | |
Takanori Nakano | 1d3f3c1 | 2016-08-30 10:34:24 +0900 | [diff] [blame] | 61 | // Keys for saving the state of the dialog in the bundle |
| 62 | private static final String TEXT_KEY = "text"; |
| 63 | private static final String TIMEOUT_INTENT_KEY = "timeout"; |
| 64 | private static final String SLOT_ID_KEY = "slotid"; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 65 | |
Takanori Nakano | cbe32d3 | 2017-07-20 17:10:46 +0900 | [diff] [blame] | 66 | private AlertDialog mAlertDialog; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 67 | |
| 68 | @Override |
Takanori Nakano | 1d3f3c1 | 2016-08-30 10:34:24 +0900 | [diff] [blame] | 69 | protected void onCreate(Bundle savedInstanceState) { |
| 70 | super.onCreate(savedInstanceState); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 71 | |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 72 | CatLog.d(LOG_TAG, "onCreate, sim id: " + mSlotId); |
Ryuto Sawada | ba9b86b | 2016-10-03 14:03:16 +0900 | [diff] [blame] | 73 | |
| 74 | // appService can be null if this activity is automatically recreated by the system |
| 75 | // with the saved instance state right after the phone process is killed. |
| 76 | if (appService == null) { |
| 77 | CatLog.d(LOG_TAG, "onCreate - appService is null"); |
| 78 | finish(); |
| 79 | return; |
| 80 | } |
| 81 | |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 82 | // New Dialog is created - set to no response sent |
| 83 | mIsResponseSent = false; |
| 84 | |
Takanori Nakano | cbe32d3 | 2017-07-20 17:10:46 +0900 | [diff] [blame] | 85 | AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 86 | |
Sanket Padawe | 7b70fb4 | 2017-04-05 15:35:34 -0700 | [diff] [blame] | 87 | alertDialogBuilder.setPositiveButton(R.string.button_ok, new |
| 88 | DialogInterface.OnClickListener() { |
| 89 | @Override |
| 90 | public void onClick(DialogInterface dialog, int id) { |
| 91 | CatLog.d(LOG_TAG, "OK Clicked!, mSlotId: " + mSlotId); |
| 92 | cancelTimeOut(); |
| 93 | sendResponse(StkAppService.RES_ID_CONFIRM, true); |
| 94 | finish(); |
| 95 | } |
| 96 | }); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 97 | |
Sanket Padawe | 7b70fb4 | 2017-04-05 15:35:34 -0700 | [diff] [blame] | 98 | alertDialogBuilder.setNegativeButton(R.string.button_cancel, new |
| 99 | DialogInterface.OnClickListener() { |
| 100 | @Override |
| 101 | public void onClick(DialogInterface dialog,int id) { |
| 102 | CatLog.d(LOG_TAG, "Cancel Clicked!, mSlotId: " + mSlotId); |
| 103 | cancelTimeOut(); |
| 104 | sendResponse(StkAppService.RES_ID_CONFIRM, false); |
| 105 | finish(); |
| 106 | } |
| 107 | }); |
Takuro Nishi | ef00cb1 | 2017-07-04 11:46:28 +0900 | [diff] [blame] | 108 | |
| 109 | alertDialogBuilder.setOnCancelListener(new DialogInterface.OnCancelListener() { |
| 110 | @Override |
| 111 | public void onCancel(DialogInterface dialog) { |
| 112 | CatLog.d(LOG_TAG, "Moving backward!, mSlotId: " + mSlotId); |
| 113 | cancelTimeOut(); |
| 114 | sendResponse(StkAppService.RES_ID_BACKWARD); |
| 115 | finish(); |
| 116 | } |
| 117 | }); |
| 118 | |
Sanket Padawe | 7b70fb4 | 2017-04-05 15:35:34 -0700 | [diff] [blame] | 119 | alertDialogBuilder.create(); |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 120 | |
Takanori Nakano | cbe32d3 | 2017-07-20 17:10:46 +0900 | [diff] [blame] | 121 | initFromIntent(getIntent()); |
| 122 | if (mTextMsg == null) { |
| 123 | finish(); |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | if (!mTextMsg.responseNeeded) { |
| 128 | alertDialogBuilder.setNegativeButton(null, null); |
Yoshiaki Naka | 9018313 | 2017-08-31 19:25:33 +0900 | [diff] [blame] | 129 | // Register the instance of this activity because the dialog displayed for DISPLAY TEXT |
| 130 | // command with an immediate response object should disappear when the terminal receives |
| 131 | // a subsequent proactive command containing display data. |
| 132 | appService.getStkContext(mSlotId).setImmediateDialogInstance(this); |
Takanori Nakano | cbe32d3 | 2017-07-20 17:10:46 +0900 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | alertDialogBuilder.setTitle(mTextMsg.title); |
| 136 | |
Takanori Nakano | 9ecdba7 | 2017-07-21 15:27:49 +0900 | [diff] [blame] | 137 | LayoutInflater inflater = this.getLayoutInflater(); |
| 138 | View dialogView = inflater.inflate(R.layout.stk_msg_dialog, null); |
| 139 | alertDialogBuilder.setView(dialogView); |
| 140 | TextView tv = (TextView) dialogView.findViewById(R.id.message); |
| 141 | ImageView iv = (ImageView) dialogView.findViewById(R.id.icon); |
| 142 | |
| 143 | if (mTextMsg.icon != null) { |
| 144 | iv.setImageBitmap(mTextMsg.icon); |
| 145 | } else { |
| 146 | iv.setVisibility(View.GONE); |
| 147 | } |
| 148 | |
| 149 | // Per spec, only set text if the icon is not provided or not self-explanatory |
| 150 | if ((mTextMsg.icon == null || !mTextMsg.iconSelfExplanatory) |
| 151 | && !TextUtils.isEmpty(mTextMsg.text)) { |
| 152 | tv.setText(mTextMsg.text); |
| 153 | } else { |
| 154 | tv.setVisibility(View.GONE); |
Takanori Nakano | cbe32d3 | 2017-07-20 17:10:46 +0900 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | mAlertDialog = alertDialogBuilder.create(); |
| 158 | mAlertDialog.setCanceledOnTouchOutside(false); |
| 159 | mAlertDialog.show(); |
| 160 | |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 161 | mContext = getBaseContext(); |
| 162 | IntentFilter intentFilter = new IntentFilter(); |
| 163 | intentFilter.addAction(ALARM_TIMEOUT); |
| 164 | mContext.registerReceiver(mBroadcastReceiver, intentFilter); |
| 165 | mAlarmManager =(AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void onResume() { |
| 170 | super.onResume(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 171 | CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent + |
| 172 | "], sim id: " + mSlotId); |
Preeti Ahuja | 414bc41 | 2013-06-25 19:31:49 -0700 | [diff] [blame] | 173 | |
Christopher Posselwhite | cfe4d7f | 2013-09-04 09:01:50 +0200 | [diff] [blame] | 174 | /* |
Preeti Ahuja | 414bc41 | 2013-06-25 19:31:49 -0700 | [diff] [blame] | 175 | * If the userClear flag is set and dialogduration is set to 0, the display Text |
| 176 | * should be displayed to user forever until some high priority event occurs |
| 177 | * (incoming call, MMI code execution etc as mentioned under section |
| 178 | * ETSI 102.223, 6.4.1) |
Christopher Posselwhite | cfe4d7f | 2013-09-04 09:01:50 +0200 | [diff] [blame] | 179 | */ |
Preeti Ahuja | 414bc41 | 2013-06-25 19:31:49 -0700 | [diff] [blame] | 180 | if (StkApp.calculateDurationInMilis(mTextMsg.duration) == 0 && |
Sanket Padawe | 7b70fb4 | 2017-04-05 15:35:34 -0700 | [diff] [blame] | 181 | !mTextMsg.responseNeeded && mTextMsg.userClear) { |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 182 | CatLog.d(LOG_TAG, "User should clear text..showing message forever"); |
Christopher Posselwhite | cfe4d7f | 2013-09-04 09:01:50 +0200 | [diff] [blame] | 183 | return; |
| 184 | } |
| 185 | |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 186 | appService.setDisplayTextDlgVisibility(true, mSlotId); |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 187 | |
| 188 | /* |
| 189 | * When another activity takes the foreground, we do not want the Terminal |
| 190 | * Response timer to be restarted when our activity resumes. Hence we will |
| 191 | * check if there is an existing timer, and resume it. In this way we will |
Sanket Padawe | 7b70fb4 | 2017-04-05 15:35:34 -0700 | [diff] [blame] | 192 | * inform the SIM in correct time when there is no response from the User |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 193 | * to a dialog. |
| 194 | */ |
| 195 | if (mTimeoutIntent != null) { |
| 196 | CatLog.d(LOG_TAG, "Pending Alarm! Let it finish counting down..."); |
| 197 | } |
| 198 | else { |
| 199 | CatLog.d(LOG_TAG, "No Pending Alarm! OK to start timer..."); |
| 200 | startTimeOut(mTextMsg.userClear); |
| 201 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public void onPause() { |
| 206 | super.onPause(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 207 | CatLog.d(LOG_TAG, "onPause, sim id: " + mSlotId); |
Preeti Ahuja | 9591934 | 2013-10-01 18:18:55 -0700 | [diff] [blame] | 208 | appService.setDisplayTextDlgVisibility(false, mSlotId); |
Preeti Ahuja | 03be667 | 2012-08-30 19:21:25 +0530 | [diff] [blame] | 209 | |
| 210 | /* |
| 211 | * do not cancel the timer here cancelTimeOut(). If any higher/lower |
| 212 | * priority events such as incoming call, new sms, screen off intent, |
| 213 | * notification alerts, user actions such as 'User moving to another activtiy' |
| 214 | * etc.. occur during Display Text ongoing session, |
| 215 | * this activity would receive 'onPause()' event resulting in |
| 216 | * cancellation of the timer. As a result no terminal response is |
| 217 | * sent to the card. |
| 218 | */ |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | @Override |
Johannes Carlsson | ef243a2 | 2011-10-25 10:37:24 +0200 | [diff] [blame] | 222 | protected void onStart() { |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 223 | CatLog.d(LOG_TAG, "onStart, sim id: " + mSlotId); |
Johannes Carlsson | ef243a2 | 2011-10-25 10:37:24 +0200 | [diff] [blame] | 224 | super.onStart(); |
Johannes Carlsson | ef243a2 | 2011-10-25 10:37:24 +0200 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | @Override |
| 228 | public void onStop() { |
| 229 | super.onStop(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 230 | CatLog.d(LOG_TAG, "onStop - before Send CONFIRM false mIsResponseSent[" + |
| 231 | mIsResponseSent + "], sim id: " + mSlotId); |
Takanori Nakano | 1d3f3c1 | 2016-08-30 10:34:24 +0900 | [diff] [blame] | 232 | |
| 233 | // Avoid calling finish() or setPendingDialogInstance() |
| 234 | // if the activity is being restarted now. |
| 235 | if (isChangingConfigurations()) { |
| 236 | return; |
| 237 | } |
| 238 | |
Tsukasa Gotou | 2aa6456 | 2016-02-09 18:52:33 +0900 | [diff] [blame] | 239 | if (!mTextMsg.responseNeeded) { |
| 240 | return; |
| 241 | } |
Johannes Carlsson | ef243a2 | 2011-10-25 10:37:24 +0200 | [diff] [blame] | 242 | if (!mIsResponseSent) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 243 | appService.getStkContext(mSlotId).setPendingDialogInstance(this); |
| 244 | } else { |
| 245 | CatLog.d(LOG_TAG, "finish."); |
| 246 | appService.getStkContext(mSlotId).setPendingDialogInstance(null); |
| 247 | cancelTimeOut(); |
| 248 | finish(); |
Johannes Carlsson | ef243a2 | 2011-10-25 10:37:24 +0200 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
| 252 | @Override |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 253 | public void onDestroy() { |
| 254 | super.onDestroy(); |
| 255 | CatLog.d(LOG_TAG, "onDestroy - mIsResponseSent[" + mIsResponseSent + |
| 256 | "], sim id: " + mSlotId); |
Takanori Nakano | cbe32d3 | 2017-07-20 17:10:46 +0900 | [diff] [blame] | 257 | |
| 258 | if (mAlertDialog != null && mAlertDialog.isShowing()) { |
| 259 | mAlertDialog.dismiss(); |
| 260 | mAlertDialog = null; |
| 261 | } |
| 262 | |
Ryuto Sawada | ba9b86b | 2016-10-03 14:03:16 +0900 | [diff] [blame] | 263 | if (appService == null) { |
| 264 | return; |
| 265 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 266 | // if dialog activity is finished by stkappservice |
| 267 | // when receiving OP_LAUNCH_APP from the other SIM, we can not send TR here |
| 268 | // , since the dialog cmd is waiting user to process. |
Takanori Nakano | 1d3f3c1 | 2016-08-30 10:34:24 +0900 | [diff] [blame] | 269 | if (!isChangingConfigurations()) { |
| 270 | if (!mIsResponseSent && appService != null && !appService.isDialogPending(mSlotId)) { |
| 271 | sendResponse(StkAppService.RES_ID_CONFIRM, false); |
| 272 | } |
| 273 | cancelTimeOut(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 274 | } |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 275 | // Cleanup broadcast receivers to avoid leaks |
| 276 | if (mBroadcastReceiver != null) { |
| 277 | unregisterReceiver(mBroadcastReceiver); |
| 278 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | @Override |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 282 | public void onSaveInstanceState(Bundle outState) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 283 | CatLog.d(LOG_TAG, "onSaveInstanceState"); |
| 284 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 285 | super.onSaveInstanceState(outState); |
| 286 | |
Takanori Nakano | 1d3f3c1 | 2016-08-30 10:34:24 +0900 | [diff] [blame] | 287 | outState.putParcelable(TEXT_KEY, mTextMsg); |
| 288 | outState.putParcelable(TIMEOUT_INTENT_KEY, mTimeoutIntent); |
| 289 | outState.putInt(SLOT_ID_KEY, mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | @Override |
| 293 | public void onRestoreInstanceState(Bundle savedInstanceState) { |
| 294 | super.onRestoreInstanceState(savedInstanceState); |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 295 | |
Takanori Nakano | 1d3f3c1 | 2016-08-30 10:34:24 +0900 | [diff] [blame] | 296 | mTextMsg = savedInstanceState.getParcelable(TEXT_KEY); |
| 297 | mTimeoutIntent = savedInstanceState.getParcelable(TIMEOUT_INTENT_KEY); |
| 298 | mSlotId = savedInstanceState.getInt(SLOT_ID_KEY); |
| 299 | appService.getStkContext(mSlotId).setPendingDialogInstance(this); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 300 | CatLog.d(LOG_TAG, "onRestoreInstanceState - [" + mTextMsg + "]"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 301 | } |
| 302 | |
Preeti Ahuja | 414bc41 | 2013-06-25 19:31:49 -0700 | [diff] [blame] | 303 | @Override |
| 304 | protected void onNewIntent(Intent intent) { |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 305 | CatLog.d(LOG_TAG, "onNewIntent - updating the same Dialog box"); |
Preeti Ahuja | 414bc41 | 2013-06-25 19:31:49 -0700 | [diff] [blame] | 306 | setIntent(intent); |
| 307 | } |
| 308 | |
Yoshiaki Naka | 9018313 | 2017-08-31 19:25:33 +0900 | [diff] [blame] | 309 | @Override |
| 310 | public void finish() { |
| 311 | super.finish(); |
| 312 | // Unregister the instance for DISPLAY TEXT command with an immediate response object |
| 313 | // as it is unnecessary to ask the service to finish this anymore. |
| 314 | if ((appService != null) && (mTextMsg != null) && !mTextMsg.responseNeeded) { |
| 315 | if (SubscriptionManager.isValidSlotIndex(mSlotId)) { |
| 316 | appService.getStkContext(mSlotId).setImmediateDialogInstance(null); |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 321 | private void sendResponse(int resId, boolean confirmed) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 322 | if (mSlotId == -1) { |
| 323 | CatLog.d(LOG_TAG, "sim id is invalid"); |
| 324 | return; |
| 325 | } |
| 326 | |
| 327 | if (StkAppService.getInstance() == null) { |
| 328 | CatLog.d(LOG_TAG, "Ignore response: id is " + resId); |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | CatLog.d(LOG_TAG, "sendResponse resID[" + resId + "] confirmed[" + confirmed + "]"); |
| 333 | |
Preeti Ahuja | 414bc41 | 2013-06-25 19:31:49 -0700 | [diff] [blame] | 334 | if (mTextMsg.responseNeeded) { |
| 335 | Bundle args = new Bundle(); |
| 336 | args.putInt(StkAppService.OPCODE, StkAppService.OP_RESPONSE); |
| 337 | args.putInt(StkAppService.SLOT_ID, mSlotId); |
| 338 | args.putInt(StkAppService.RES_ID, resId); |
| 339 | args.putBoolean(StkAppService.CONFIRMATION, confirmed); |
| 340 | startService(new Intent(this, StkAppService.class).putExtras(args)); |
| 341 | mIsResponseSent = true; |
| 342 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | private void sendResponse(int resId) { |
| 346 | sendResponse(resId, true); |
| 347 | } |
| 348 | |
| 349 | private void initFromIntent(Intent intent) { |
| 350 | |
| 351 | if (intent != null) { |
| 352 | mTextMsg = intent.getParcelableExtra("TEXT"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 353 | mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 354 | } else { |
| 355 | finish(); |
| 356 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 357 | |
Yoshiaki Naka | 25273c9 | 2017-10-31 20:00:33 +0900 | [diff] [blame] | 358 | CatLog.d(LOG_TAG, "initFromIntent - [" + (Build.IS_DEBUGGABLE ? mTextMsg : "********") |
| 359 | + "], slot id: " + mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | private void cancelTimeOut() { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 363 | CatLog.d(LOG_TAG, "cancelTimeOut: " + mSlotId); |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 364 | if (mTimeoutIntent != null) { |
| 365 | mAlarmManager.cancel(mTimeoutIntent); |
| 366 | mTimeoutIntent = null; |
| 367 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 368 | } |
| 369 | |
Christopher.Posselwhite | 1772c04 | 2012-11-22 12:15:54 +0100 | [diff] [blame] | 370 | private void startTimeOut(boolean waitForUserToClear) { |
Preeti Ahuja | 414bc41 | 2013-06-25 19:31:49 -0700 | [diff] [blame] | 371 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 372 | // Reset timeout. |
| 373 | cancelTimeOut(); |
| 374 | int dialogDuration = StkApp.calculateDurationInMilis(mTextMsg.duration); |
Christopher.Posselwhite | 1772c04 | 2012-11-22 12:15:54 +0100 | [diff] [blame] | 375 | // If duration is specified, this has priority. If not, set timeout |
| 376 | // according to condition given by the card. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 377 | if (mTextMsg.userClear == true && mTextMsg.responseNeeded == false) { |
| 378 | return; |
| 379 | } else { |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 380 | // userClear = false. will disappear after a while. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 381 | if (dialogDuration == 0) { |
| 382 | if (waitForUserToClear) { |
| 383 | dialogDuration = StkApp.DISP_TEXT_WAIT_FOR_USER_TIMEOUT; |
| 384 | } else { |
| 385 | dialogDuration = StkApp.DISP_TEXT_CLEAR_AFTER_DELAY_TIMEOUT; |
| 386 | } |
Christopher.Posselwhite | 1772c04 | 2012-11-22 12:15:54 +0100 | [diff] [blame] | 387 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 388 | CatLog.d(LOG_TAG, "startTimeOut: " + mSlotId); |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 389 | Intent mAlarmIntent = new Intent(ALARM_TIMEOUT); |
| 390 | mAlarmIntent.putExtra(StkAppService.SLOT_ID, mSlotId); |
| 391 | mTimeoutIntent = PendingIntent.getBroadcast(mContext, 0, mAlarmIntent, PendingIntent.FLAG_CANCEL_CURRENT); |
| 392 | |
| 393 | // Try to use a more stringent timer not affected by system sleep. |
| 394 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { |
| 395 | mAlarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, |
Sanket Padawe | 7b70fb4 | 2017-04-05 15:35:34 -0700 | [diff] [blame] | 396 | SystemClock.elapsedRealtime() + dialogDuration, mTimeoutIntent); |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 397 | } |
| 398 | else { |
| 399 | mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, |
Sanket Padawe | 7b70fb4 | 2017-04-05 15:35:34 -0700 | [diff] [blame] | 400 | SystemClock.elapsedRealtime() + dialogDuration, mTimeoutIntent); |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 401 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 402 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 403 | } |
w30234 | 8bf95af | 2015-01-09 10:54:41 -0800 | [diff] [blame] | 404 | |
| 405 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 406 | @Override public void onReceive(Context context, Intent intent) { |
| 407 | String action = intent.getAction(); |
| 408 | int slotID = intent.getIntExtra(StkAppService.SLOT_ID, 0); |
| 409 | |
| 410 | if (action == null || slotID != mSlotId) return; |
| 411 | CatLog.d(LOG_TAG, "onReceive, action=" + action + ", sim id: " + slotID); |
| 412 | if (action.equals(ALARM_TIMEOUT)) { |
| 413 | CatLog.d(LOG_TAG, "ALARM_TIMEOUT rcvd"); |
| 414 | mTimeoutIntent = null; |
| 415 | sendResponse(StkAppService.RES_ID_TIMEOUT); |
| 416 | finish(); |
| 417 | } |
| 418 | } |
| 419 | }; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 420 | } |