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