blob: b09aa40aa4e9598b74a706a5d77f671e45ce9af5 [file] [log] [blame]
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001/*
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
17package com.android.stk;
18
Christopher Posselwhitecfe4d7f2013-09-04 09:01:50 +020019import com.android.internal.telephony.cat.CatLog;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070020import com.android.internal.telephony.cat.TextMessage;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080021
22import android.app.Activity;
23import android.content.Intent;
24import android.graphics.drawable.BitmapDrawable;
25import android.os.Bundle;
26import android.os.Handler;
27import android.os.Message;
28import android.view.KeyEvent;
29import android.view.View;
30import android.view.Window;
31import android.widget.Button;
32import android.widget.TextView;
33
34/**
35 * AlretDialog used for DISPLAY TEXT commands.
Wink Saville79085fc2009-06-09 10:27:23 -070036 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080037 */
38public class StkDialogActivity extends Activity implements View.OnClickListener {
39 // members
Wink Savillee68857d2014-10-17 15:23:05 -070040 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 Carlssonef243a22011-10-25 10:37:24 +020045 private boolean mIsResponseSent = false;
Wink Savillee68857d2014-10-17 15:23:05 -070046
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080047 Handler mTimeoutHandler = new Handler() {
48 @Override
49 public void handleMessage(Message msg) {
50 switch(msg.what) {
51 case MSG_ID_TIMEOUT:
Wink Savillee68857d2014-10-17 15:23:05 -070052 CatLog.d(LOG_TAG, "MSG_ID_TIMEOUT finish.");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080053 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 Saville79085fc2009-06-09 10:27:23 -070063 // message id for time out
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080064 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 Savillee68857d2014-10-17 15:23:05 -070074 CatLog.d(LOG_TAG, "onCreate");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080075 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 Saville79085fc2009-06-09 10:27:23 -070096 mMessageView.setText(mTextMsg.text);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080097 }
98
99 if (mTextMsg.icon == null) {
Wink Savillee68857d2014-10-17 15:23:05 -0700100 CatLog.d(LOG_TAG, "onCreate icon is null");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800101 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 Savillee68857d2014-10-17 15:23:05 -0700114 CatLog.d(LOG_TAG, "OK Clicked!, mSlotId: " + mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800115 sendResponse(StkAppService.RES_ID_CONFIRM, true);
Wink Savillee68857d2014-10-17 15:23:05 -0700116 cancelTimeOut();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800117 finish();
118 break;
119 case CANCEL_BUTTON:
Wink Savillee68857d2014-10-17 15:23:05 -0700120 CatLog.d(LOG_TAG, "Cancel Clicked!, mSlotId: " + mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800121 sendResponse(StkAppService.RES_ID_CONFIRM, false);
Wink Savillee68857d2014-10-17 15:23:05 -0700122 cancelTimeOut();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800123 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 Savillee68857d2014-10-17 15:23:05 -0700132 CatLog.d(LOG_TAG, "onKeyDown - KEYCODE_BACK");
133 cancelTimeOut();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800134 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 Savillee68857d2014-10-17 15:23:05 -0700144 CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent +
145 "], sim id: " + mSlotId);
Christopher Posselwhitecfe4d7f2013-09-04 09:01:50 +0200146 /*
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.Posselwhite1772c042012-11-22 12:15:54 +0100162 startTimeOut(mTextMsg.userClear);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800163 }
164
165 @Override
166 public void onPause() {
167 super.onPause();
Wink Savillee68857d2014-10-17 15:23:05 -0700168 CatLog.d(LOG_TAG, "onPause, sim id: " + mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800169 cancelTimeOut();
170 }
171
172 @Override
Johannes Carlssonef243a22011-10-25 10:37:24 +0200173 protected void onStart() {
174 super.onStart();
175 mIsResponseSent = false;
176 }
177
178 @Override
179 public void onStop() {
180 super.onStop();
Wink Savillee68857d2014-10-17 15:23:05 -0700181 CatLog.d(LOG_TAG, "onStop - before Send CONFIRM false mIsResponseSent[" +
182 mIsResponseSent + "], sim id: " + mSlotId);
Johannes Carlssonef243a22011-10-25 10:37:24 +0200183 if (!mIsResponseSent) {
Wink Savillee68857d2014-10-17 15:23:05 -0700184 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 Carlssonef243a22011-10-25 10:37:24 +0200191 }
192 }
193
194 @Override
Wink Savillee68857d2014-10-17 15:23:05 -0700195 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 Project9d9730a2009-03-03 19:32:37 -0800209 public void onSaveInstanceState(Bundle outState) {
Wink Savillee68857d2014-10-17 15:23:05 -0700210 CatLog.d(LOG_TAG, "onSaveInstanceState");
211
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800212 super.onSaveInstanceState(outState);
213
214 outState.putParcelable(TEXT, mTextMsg);
215 }
216
217 @Override
218 public void onRestoreInstanceState(Bundle savedInstanceState) {
219 super.onRestoreInstanceState(savedInstanceState);
Wink Saville79085fc2009-06-09 10:27:23 -0700220
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800221 mTextMsg = savedInstanceState.getParcelable(TEXT);
Wink Savillee68857d2014-10-17 15:23:05 -0700222 CatLog.d(LOG_TAG, "onRestoreInstanceState - [" + mTextMsg + "]");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800223 }
224
225 private void sendResponse(int resId, boolean confirmed) {
Wink Savillee68857d2014-10-17 15:23:05 -0700226 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 Project9d9730a2009-03-03 19:32:37 -0800238 Bundle args = new Bundle();
239 args.putInt(StkAppService.OPCODE, StkAppService.OP_RESPONSE);
Wink Savillee68857d2014-10-17 15:23:05 -0700240 args.putInt(StkAppService.SLOT_ID, mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800241 args.putInt(StkAppService.RES_ID, resId);
242 args.putBoolean(StkAppService.CONFIRMATION, confirmed);
243 startService(new Intent(this, StkAppService.class).putExtras(args));
Johannes Carlssonef243a22011-10-25 10:37:24 +0200244 mIsResponseSent = true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800245 }
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 Savillee68857d2014-10-17 15:23:05 -0700255 mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800256 } else {
257 finish();
258 }
Wink Savillee68857d2014-10-17 15:23:05 -0700259
260 CatLog.d(LOG_TAG, "initFromIntent - [" + mTextMsg + "], sim id: " + mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800261 }
262
263 private void cancelTimeOut() {
Wink Savillee68857d2014-10-17 15:23:05 -0700264 CatLog.d(LOG_TAG, "cancelTimeOut: " + mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800265 mTimeoutHandler.removeMessages(MSG_ID_TIMEOUT);
266 }
267
Christopher.Posselwhite1772c042012-11-22 12:15:54 +0100268 private void startTimeOut(boolean waitForUserToClear) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800269 // Reset timeout.
270 cancelTimeOut();
271 int dialogDuration = StkApp.calculateDurationInMilis(mTextMsg.duration);
Christopher.Posselwhite1772c042012-11-22 12:15:54 +0100272 // If duration is specified, this has priority. If not, set timeout
273 // according to condition given by the card.
Wink Savillee68857d2014-10-17 15:23:05 -0700274 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.Posselwhite1772c042012-11-22 12:15:54 +0100284 }
Wink Savillee68857d2014-10-17 15:23:05 -0700285 CatLog.d(LOG_TAG, "startTimeOut: " + mSlotId);
286 mTimeoutHandler.sendMessageDelayed(mTimeoutHandler
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800287 .obtainMessage(MSG_ID_TIMEOUT), dialogDuration);
Wink Savillee68857d2014-10-17 15:23:05 -0700288 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800289 }
290}