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; |
| 23 | import android.content.Intent; |
| 24 | import android.graphics.drawable.BitmapDrawable; |
| 25 | import android.os.Bundle; |
| 26 | import android.os.Handler; |
| 27 | import android.os.Message; |
| 28 | import android.view.KeyEvent; |
| 29 | import android.view.View; |
| 30 | import android.view.Window; |
| 31 | import android.widget.Button; |
| 32 | import android.widget.TextView; |
| 33 | |
| 34 | /** |
| 35 | * AlretDialog used for DISPLAY TEXT commands. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 36 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 37 | */ |
| 38 | public class StkDialogActivity extends Activity implements View.OnClickListener { |
| 39 | // members |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 40 | private static final String className = new Object(){}.getClass().getEnclosingClass().getName(); |
| 41 | private static final String LOG_TAG = className.substring(className.lastIndexOf('.') + 1); |
| 42 | TextMessage mTextMsg = null; |
| 43 | private int mSlotId = -1; |
| 44 | private StkAppService appService = StkAppService.getInstance(); |
Johannes Carlsson | ef243a2 | 2011-10-25 10:37:24 +0200 | [diff] [blame] | 45 | private boolean mIsResponseSent = false; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 46 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 47 | Handler mTimeoutHandler = new Handler() { |
| 48 | @Override |
| 49 | public void handleMessage(Message msg) { |
| 50 | switch(msg.what) { |
| 51 | case MSG_ID_TIMEOUT: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 52 | CatLog.d(LOG_TAG, "MSG_ID_TIMEOUT finish."); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 53 | sendResponse(StkAppService.RES_ID_TIMEOUT); |
| 54 | finish(); |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | //keys) for saving the state of the dialog in the icicle |
| 61 | private static final String TEXT = "text"; |
| 62 | |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 63 | // message id for time out |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 64 | private static final int MSG_ID_TIMEOUT = 1; |
| 65 | |
| 66 | // buttons id |
| 67 | public static final int OK_BUTTON = R.id.button_ok; |
| 68 | public static final int CANCEL_BUTTON = R.id.button_cancel; |
| 69 | |
| 70 | @Override |
| 71 | protected void onCreate(Bundle icicle) { |
| 72 | super.onCreate(icicle); |
| 73 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 74 | CatLog.d(LOG_TAG, "onCreate"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 75 | initFromIntent(getIntent()); |
| 76 | if (mTextMsg == null) { |
| 77 | finish(); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | requestWindowFeature(Window.FEATURE_LEFT_ICON); |
| 82 | Window window = getWindow(); |
| 83 | |
| 84 | setContentView(R.layout.stk_msg_dialog); |
| 85 | TextView mMessageView = (TextView) window |
| 86 | .findViewById(R.id.dialog_message); |
| 87 | |
| 88 | Button okButton = (Button) findViewById(R.id.button_ok); |
| 89 | Button cancelButton = (Button) findViewById(R.id.button_cancel); |
| 90 | |
| 91 | okButton.setOnClickListener(this); |
| 92 | cancelButton.setOnClickListener(this); |
| 93 | |
| 94 | setTitle(mTextMsg.title); |
| 95 | if (!(mTextMsg.iconSelfExplanatory && mTextMsg.icon != null)) { |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 96 | mMessageView.setText(mTextMsg.text); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | if (mTextMsg.icon == null) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 100 | CatLog.d(LOG_TAG, "onCreate icon is null"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 101 | window.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, |
| 102 | com.android.internal.R.drawable.stat_notify_sim_toolkit); |
| 103 | } else { |
| 104 | window.setFeatureDrawable(Window.FEATURE_LEFT_ICON, |
| 105 | new BitmapDrawable(mTextMsg.icon)); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | public void onClick(View v) { |
| 110 | String input = null; |
| 111 | |
| 112 | switch (v.getId()) { |
| 113 | case OK_BUTTON: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 114 | CatLog.d(LOG_TAG, "OK Clicked!, mSlotId: " + mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 115 | sendResponse(StkAppService.RES_ID_CONFIRM, true); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 116 | cancelTimeOut(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 117 | finish(); |
| 118 | break; |
| 119 | case CANCEL_BUTTON: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 120 | CatLog.d(LOG_TAG, "Cancel Clicked!, mSlotId: " + mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 121 | sendResponse(StkAppService.RES_ID_CONFIRM, false); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 122 | cancelTimeOut(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 123 | finish(); |
| 124 | break; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 130 | switch (keyCode) { |
| 131 | case KeyEvent.KEYCODE_BACK: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 132 | CatLog.d(LOG_TAG, "onKeyDown - KEYCODE_BACK"); |
| 133 | cancelTimeOut(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 134 | sendResponse(StkAppService.RES_ID_BACKWARD); |
| 135 | finish(); |
| 136 | break; |
| 137 | } |
| 138 | return false; |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public void onResume() { |
| 143 | super.onResume(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 144 | CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent + |
| 145 | "], sim id: " + mSlotId); |
Christopher Posselwhite | cfe4d7f | 2013-09-04 09:01:50 +0200 | [diff] [blame] | 146 | /* |
| 147 | * The user should be shown the message forever or until some high |
| 148 | * priority event occurs (such as incoming call, MMI code execution |
| 149 | * etc as mentioned in ETSI 102.223, 6.4.1). |
| 150 | * |
| 151 | * Since mTextMsg.responseNeeded is false (because the response has |
| 152 | * already been sent) and duration of the dialog is zero and userClear |
| 153 | * is true, don't set the timeout. |
| 154 | */ |
| 155 | if (!mTextMsg.responseNeeded && |
| 156 | StkApp.calculateDurationInMilis(mTextMsg.duration) == 0 && |
| 157 | mTextMsg.userClear) { |
| 158 | CatLog.d(this, "User should clear text..show message forever"); |
| 159 | return; |
| 160 | } |
| 161 | |
Christopher.Posselwhite | 1772c04 | 2012-11-22 12:15:54 +0100 | [diff] [blame] | 162 | startTimeOut(mTextMsg.userClear); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public void onPause() { |
| 167 | super.onPause(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 168 | CatLog.d(LOG_TAG, "onPause, sim id: " + mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 169 | cancelTimeOut(); |
| 170 | } |
| 171 | |
| 172 | @Override |
Johannes Carlsson | ef243a2 | 2011-10-25 10:37:24 +0200 | [diff] [blame] | 173 | protected void onStart() { |
| 174 | super.onStart(); |
| 175 | mIsResponseSent = false; |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public void onStop() { |
| 180 | super.onStop(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 181 | CatLog.d(LOG_TAG, "onStop - before Send CONFIRM false mIsResponseSent[" + |
| 182 | mIsResponseSent + "], sim id: " + mSlotId); |
Johannes Carlsson | ef243a2 | 2011-10-25 10:37:24 +0200 | [diff] [blame] | 183 | if (!mIsResponseSent) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 184 | appService.getStkContext(mSlotId).setPendingDialogInstance(this); |
| 185 | } else { |
| 186 | CatLog.d(LOG_TAG, "finish."); |
| 187 | appService.getStkContext(mSlotId).setPendingDialogInstance(null); |
| 188 | cancelTimeOut(); |
| 189 | finish(); |
| 190 | CatLog.d(LOG_TAG, "finish."); |
Johannes Carlsson | ef243a2 | 2011-10-25 10:37:24 +0200 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
| 194 | @Override |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 195 | public void onDestroy() { |
| 196 | super.onDestroy(); |
| 197 | CatLog.d(LOG_TAG, "onDestroy - mIsResponseSent[" + mIsResponseSent + |
| 198 | "], sim id: " + mSlotId); |
| 199 | // if dialog activity is finished by stkappservice |
| 200 | // when receiving OP_LAUNCH_APP from the other SIM, we can not send TR here |
| 201 | // , since the dialog cmd is waiting user to process. |
| 202 | if (!mIsResponseSent && !appService.isDialogPending(mSlotId)) { |
| 203 | sendResponse(StkAppService.RES_ID_CONFIRM, false); |
| 204 | } |
| 205 | cancelTimeOut(); |
| 206 | } |
| 207 | |
| 208 | @Override |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 209 | public void onSaveInstanceState(Bundle outState) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 210 | CatLog.d(LOG_TAG, "onSaveInstanceState"); |
| 211 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 212 | super.onSaveInstanceState(outState); |
| 213 | |
| 214 | outState.putParcelable(TEXT, mTextMsg); |
| 215 | } |
| 216 | |
| 217 | @Override |
| 218 | public void onRestoreInstanceState(Bundle savedInstanceState) { |
| 219 | super.onRestoreInstanceState(savedInstanceState); |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 220 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 221 | mTextMsg = savedInstanceState.getParcelable(TEXT); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 222 | CatLog.d(LOG_TAG, "onRestoreInstanceState - [" + mTextMsg + "]"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | private void sendResponse(int resId, boolean confirmed) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 226 | if (mSlotId == -1) { |
| 227 | CatLog.d(LOG_TAG, "sim id is invalid"); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | if (StkAppService.getInstance() == null) { |
| 232 | CatLog.d(LOG_TAG, "Ignore response: id is " + resId); |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | CatLog.d(LOG_TAG, "sendResponse resID[" + resId + "] confirmed[" + confirmed + "]"); |
| 237 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 238 | Bundle args = new Bundle(); |
| 239 | args.putInt(StkAppService.OPCODE, StkAppService.OP_RESPONSE); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 240 | args.putInt(StkAppService.SLOT_ID, mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 241 | args.putInt(StkAppService.RES_ID, resId); |
| 242 | args.putBoolean(StkAppService.CONFIRMATION, confirmed); |
| 243 | startService(new Intent(this, StkAppService.class).putExtras(args)); |
Johannes Carlsson | ef243a2 | 2011-10-25 10:37:24 +0200 | [diff] [blame] | 244 | mIsResponseSent = true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | private void sendResponse(int resId) { |
| 248 | sendResponse(resId, true); |
| 249 | } |
| 250 | |
| 251 | private void initFromIntent(Intent intent) { |
| 252 | |
| 253 | if (intent != null) { |
| 254 | mTextMsg = intent.getParcelableExtra("TEXT"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 255 | mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 256 | } else { |
| 257 | finish(); |
| 258 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 259 | |
| 260 | CatLog.d(LOG_TAG, "initFromIntent - [" + mTextMsg + "], sim id: " + mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | private void cancelTimeOut() { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 264 | CatLog.d(LOG_TAG, "cancelTimeOut: " + mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 265 | mTimeoutHandler.removeMessages(MSG_ID_TIMEOUT); |
| 266 | } |
| 267 | |
Christopher.Posselwhite | 1772c04 | 2012-11-22 12:15:54 +0100 | [diff] [blame] | 268 | private void startTimeOut(boolean waitForUserToClear) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 269 | // Reset timeout. |
| 270 | cancelTimeOut(); |
| 271 | int dialogDuration = StkApp.calculateDurationInMilis(mTextMsg.duration); |
Christopher.Posselwhite | 1772c04 | 2012-11-22 12:15:54 +0100 | [diff] [blame] | 272 | // If duration is specified, this has priority. If not, set timeout |
| 273 | // according to condition given by the card. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 274 | if (mTextMsg.userClear == true && mTextMsg.responseNeeded == false) { |
| 275 | return; |
| 276 | } else { |
| 277 | // userClear = false. will dissapear after a while. |
| 278 | if (dialogDuration == 0) { |
| 279 | if (waitForUserToClear) { |
| 280 | dialogDuration = StkApp.DISP_TEXT_WAIT_FOR_USER_TIMEOUT; |
| 281 | } else { |
| 282 | dialogDuration = StkApp.DISP_TEXT_CLEAR_AFTER_DELAY_TIMEOUT; |
| 283 | } |
Christopher.Posselwhite | 1772c04 | 2012-11-22 12:15:54 +0100 | [diff] [blame] | 284 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 285 | CatLog.d(LOG_TAG, "startTimeOut: " + mSlotId); |
| 286 | mTimeoutHandler.sendMessageDelayed(mTimeoutHandler |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 287 | .obtainMessage(MSG_ID_TIMEOUT), dialogDuration); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame^] | 288 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 289 | } |
| 290 | } |