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 |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 3 | * |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 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 |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 7 | * |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 9 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 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 | |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 19 | import android.app.ActionBar; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 20 | import android.app.Activity; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 21 | import android.app.AlarmManager; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 24 | import android.content.res.Configuration; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 25 | import android.os.Bundle; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 26 | import android.os.SystemClock; |
Yukiko Fujimura | 913c143 | 2019-02-21 17:14:30 +0900 | [diff] [blame] | 27 | import android.telephony.CarrierConfigManager; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 28 | import android.text.Editable; |
| 29 | import android.text.InputFilter; |
Yoshiaki Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 30 | import android.text.TextUtils; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 31 | import android.text.TextWatcher; |
| 32 | import android.text.method.PasswordTransformationMethod; |
| 33 | import android.view.KeyEvent; |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 34 | import android.view.Menu; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 35 | import android.view.MenuItem; |
| 36 | import android.view.View; |
Jiyong Park | 0cfe55a | 2018-08-14 18:48:20 +0900 | [diff] [blame] | 37 | import android.view.Window; |
Kazuhiro Uto | 1287091 | 2018-07-18 17:43:56 +0900 | [diff] [blame] | 38 | import android.view.WindowManager; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 39 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 40 | import android.widget.Button; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 41 | import android.widget.EditText; |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 42 | import android.widget.ImageView; |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 43 | import android.widget.PopupMenu; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 44 | import android.widget.TextView; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 45 | import android.widget.TextView.BufferType; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 46 | |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 47 | import androidx.appcompat.app.AppCompatActivity; |
| 48 | import androidx.appcompat.widget.Toolbar; |
| 49 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 50 | import com.android.internal.telephony.cat.CatLog; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 51 | import com.android.internal.telephony.cat.Input; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 52 | |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 53 | import com.google.android.material.textfield.TextInputLayout; |
| 54 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 55 | /** |
| 56 | * Display a request for a text input a long with a text edit form. |
| 57 | */ |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 58 | public class StkInputActivity extends AppCompatActivity implements View.OnClickListener, |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 59 | TextWatcher { |
| 60 | |
| 61 | // Members |
| 62 | private int mState; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 63 | private EditText mTextIn = null; |
| 64 | private TextView mPromptView = null; |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 65 | private View mMoreOptions = null; |
| 66 | private PopupMenu mPopupMenu = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 67 | private View mYesNoLayout = null; |
| 68 | private View mNormalLayout = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 69 | |
| 70 | // Constants |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 71 | private static final String LOG_TAG = |
| 72 | new Object(){}.getClass().getEnclosingClass().getSimpleName(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 73 | |
| 74 | private Input mStkInput = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 75 | // Constants |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 76 | private static final int STATE_TEXT = 1; |
| 77 | private static final int STATE_YES_NO = 2; |
| 78 | |
| 79 | static final String YES_STR_RESPONSE = "YES"; |
| 80 | static final String NO_STR_RESPONSE = "NO"; |
| 81 | |
| 82 | // Font size factor values. |
| 83 | static final float NORMAL_FONT_FACTOR = 1; |
| 84 | static final float LARGE_FONT_FACTOR = 2; |
| 85 | static final float SMALL_FONT_FACTOR = (1 / 2); |
| 86 | |
Takanori Nakano | 71f9ee2 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 87 | // Keys for saving the state of the activity in the bundle |
Takanori Nakano | 71f9ee2 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 88 | private static final String RESPONSE_SENT_KEY = "response_sent"; |
| 89 | private static final String INPUT_STRING_KEY = "input_string"; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 90 | private static final String ALARM_TIME_KEY = "alarm_time"; |
Takanori Nakano | 71f9ee2 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 91 | |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 92 | private static final String INPUT_ALARM_TAG = LOG_TAG; |
| 93 | private static final long NO_INPUT_ALARM = -1; |
| 94 | private long mAlarmTime = NO_INPUT_ALARM; |
| 95 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 96 | private StkAppService appService = StkAppService.getInstance(); |
| 97 | |
| 98 | private boolean mIsResponseSent = false; |
| 99 | private int mSlotId = -1; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 100 | |
| 101 | // Click listener to handle buttons press.. |
| 102 | public void onClick(View v) { |
| 103 | String input = null; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 104 | if (mIsResponseSent) { |
| 105 | CatLog.d(LOG_TAG, "Already responded"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 106 | return; |
| 107 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 108 | |
Amit Mahajan | d51bbb5 | 2020-02-07 20:03:11 +0000 | [diff] [blame] | 109 | switch (v.getId()) { |
| 110 | case R.id.button_ok: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 111 | input = mTextIn.getText().toString(); |
Amit Mahajan | d51bbb5 | 2020-02-07 20:03:11 +0000 | [diff] [blame] | 112 | break; |
| 113 | case R.id.button_cancel: |
Takanori Nakano | 260df9a | 2017-12-05 22:26:30 +0900 | [diff] [blame] | 114 | sendResponse(StkAppService.RES_ID_END_SESSION); |
Yoshiaki Naka | 03a79d9 | 2018-08-09 18:41:31 +0900 | [diff] [blame] | 115 | finish(); |
Takanori Nakano | 260df9a | 2017-12-05 22:26:30 +0900 | [diff] [blame] | 116 | return; |
Amit Mahajan | d51bbb5 | 2020-02-07 20:03:11 +0000 | [diff] [blame] | 117 | // Yes/No layout buttons. |
| 118 | case R.id.button_yes: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 119 | input = YES_STR_RESPONSE; |
Amit Mahajan | d51bbb5 | 2020-02-07 20:03:11 +0000 | [diff] [blame] | 120 | break; |
| 121 | case R.id.button_no: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 122 | input = NO_STR_RESPONSE; |
Amit Mahajan | d51bbb5 | 2020-02-07 20:03:11 +0000 | [diff] [blame] | 123 | break; |
| 124 | case R.id.more: |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 125 | if (mPopupMenu == null) { |
| 126 | mPopupMenu = new PopupMenu(this, v); |
| 127 | Menu menu = mPopupMenu.getMenu(); |
| 128 | createOptionsMenuInternal(menu); |
| 129 | prepareOptionsMenuInternal(menu); |
| 130 | mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { |
| 131 | public boolean onMenuItemClick(MenuItem item) { |
| 132 | optionsItemSelectedInternal(item); |
| 133 | return true; |
| 134 | } |
| 135 | }); |
| 136 | mPopupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() { |
| 137 | public void onDismiss(PopupMenu menu) { |
| 138 | mPopupMenu = null; |
| 139 | } |
| 140 | }); |
| 141 | mPopupMenu.show(); |
| 142 | } |
| 143 | return; |
Amit Mahajan | d51bbb5 | 2020-02-07 20:03:11 +0000 | [diff] [blame] | 144 | default: |
| 145 | break; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 146 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 147 | CatLog.d(LOG_TAG, "handleClick, ready to response"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 148 | sendResponse(StkAppService.RES_ID_INPUT, input, false); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | @Override |
Takanori Nakano | 71f9ee2 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 152 | public void onCreate(Bundle savedInstanceState) { |
| 153 | super.onCreate(savedInstanceState); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 154 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 155 | CatLog.d(LOG_TAG, "onCreate - mIsResponseSent[" + mIsResponseSent + "]"); |
| 156 | |
Ryuto Sawada | ba9b86b | 2016-10-03 14:03:16 +0900 | [diff] [blame] | 157 | // appService can be null if this activity is automatically recreated by the system |
| 158 | // with the saved instance state right after the phone process is killed. |
| 159 | if (appService == null) { |
| 160 | CatLog.d(LOG_TAG, "onCreate - appService is null"); |
| 161 | finish(); |
| 162 | return; |
| 163 | } |
| 164 | |
Umashankar Godachi | c77445b | 2018-02-28 02:51:56 +0530 | [diff] [blame] | 165 | requestWindowFeature(Window.FEATURE_NO_TITLE); |
Steven Laver | 6d224df | 2019-11-09 19:05:05 -0800 | [diff] [blame] | 166 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 167 | // Set the layout for this activity. |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 168 | setContentView(R.layout.stk_input); |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 169 | setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 170 | |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 171 | if (getResources().getBoolean(R.bool.show_menu_title_only_on_menu)) { |
| 172 | getSupportActionBar().hide(); |
| 173 | |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 174 | mMoreOptions = findViewById(R.id.more); |
| 175 | mMoreOptions.setVisibility(View.VISIBLE); |
| 176 | mMoreOptions.setOnClickListener(this); |
| 177 | } |
| 178 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 179 | // Initialize members |
| 180 | mTextIn = (EditText) this.findViewById(R.id.in_text); |
| 181 | mPromptView = (TextView) this.findViewById(R.id.prompt); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 182 | // Set buttons listeners. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 183 | Button okButton = (Button) findViewById(R.id.button_ok); |
Takanori Nakano | 260df9a | 2017-12-05 22:26:30 +0900 | [diff] [blame] | 184 | Button cancelButton = (Button) findViewById(R.id.button_cancel); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 185 | Button yesButton = (Button) findViewById(R.id.button_yes); |
| 186 | Button noButton = (Button) findViewById(R.id.button_no); |
| 187 | |
| 188 | okButton.setOnClickListener(this); |
Takanori Nakano | 260df9a | 2017-12-05 22:26:30 +0900 | [diff] [blame] | 189 | cancelButton.setOnClickListener(this); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 190 | yesButton.setOnClickListener(this); |
| 191 | noButton.setOnClickListener(this); |
| 192 | |
| 193 | mYesNoLayout = findViewById(R.id.yes_no_layout); |
| 194 | mNormalLayout = findViewById(R.id.normal_layout); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 195 | initFromIntent(getIntent()); |
Anna Suzuki | 35309b0 | 2019-02-15 16:24:59 +0900 | [diff] [blame] | 196 | appService.getStkContext(mSlotId).setPendingActivityInstance(this); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | @Override |
| 200 | protected void onPostCreate(Bundle savedInstanceState) { |
| 201 | super.onPostCreate(savedInstanceState); |
| 202 | |
| 203 | mTextIn.addTextChangedListener(this); |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public void onResume() { |
| 208 | super.onResume(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 209 | CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent + |
| 210 | "], slot id: " + mSlotId); |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 211 | if (mAlarmTime == NO_INPUT_ALARM) { |
| 212 | startTimeOut(); |
| 213 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | @Override |
| 217 | public void onPause() { |
| 218 | super.onPause(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 219 | CatLog.d(LOG_TAG, "onPause - mIsResponseSent[" + mIsResponseSent + "]"); |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 220 | if (mPopupMenu != null) { |
| 221 | mPopupMenu.dismiss(); |
| 222 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 223 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 224 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 225 | @Override |
| 226 | public void onStop() { |
| 227 | super.onStop(); |
| 228 | CatLog.d(LOG_TAG, "onStop - mIsResponseSent[" + mIsResponseSent + "]"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public void onDestroy() { |
| 233 | super.onDestroy(); |
| 234 | CatLog.d(LOG_TAG, "onDestroy - before Send End Session mIsResponseSent[" + |
| 235 | mIsResponseSent + " , " + mSlotId + "]"); |
Ryuto Sawada | ba9b86b | 2016-10-03 14:03:16 +0900 | [diff] [blame] | 236 | if (appService == null) { |
| 237 | return; |
| 238 | } |
Takanori Nakano | 71f9ee2 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 239 | // Avoid sending the terminal response while the activty is being restarted |
| 240 | // due to some kind of configuration change. |
| 241 | if (!isChangingConfigurations()) { |
| 242 | // If the input activity is finished by stkappservice |
| 243 | // when receiving OP_LAUNCH_APP from the other SIM, we can not send TR here, |
| 244 | // since the input cmd is waiting user to process. |
| 245 | if (!mIsResponseSent && !appService.isInputPending(mSlotId)) { |
| 246 | CatLog.d(LOG_TAG, "handleDestroy - Send End Session"); |
| 247 | sendResponse(StkAppService.RES_ID_END_SESSION); |
| 248 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 249 | } |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 250 | cancelTimeOut(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | @Override |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 254 | public void onConfigurationChanged(Configuration newConfig) { |
| 255 | super.onConfigurationChanged(newConfig); |
| 256 | if (mPopupMenu != null) { |
| 257 | mPopupMenu.dismiss(); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | @Override |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 262 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 263 | if (mIsResponseSent) { |
| 264 | CatLog.d(LOG_TAG, "Already responded"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 265 | return true; |
| 266 | } |
| 267 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 268 | switch (keyCode) { |
| 269 | case KeyEvent.KEYCODE_BACK: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 270 | CatLog.d(LOG_TAG, "onKeyDown - KEYCODE_BACK"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 271 | sendResponse(StkAppService.RES_ID_BACKWARD, null, false); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 272 | return true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 273 | } |
| 274 | return super.onKeyDown(keyCode, event); |
| 275 | } |
| 276 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 277 | void sendResponse(int resId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 278 | sendResponse(resId, null, false); |
| 279 | } |
| 280 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 281 | void sendResponse(int resId, String input, boolean help) { |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 282 | cancelTimeOut(); |
| 283 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 284 | if (mSlotId == -1) { |
| 285 | CatLog.d(LOG_TAG, "slot id is invalid"); |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | if (StkAppService.getInstance() == null) { |
| 290 | CatLog.d(LOG_TAG, "StkAppService is null, Ignore response: id is " + resId); |
| 291 | return; |
| 292 | } |
| 293 | |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 294 | if (mMoreOptions != null) { |
| 295 | mMoreOptions.setVisibility(View.INVISIBLE); |
| 296 | } |
| 297 | |
Cuihtlauac ALVARADO | bde7f03 | 2015-05-29 16:25:12 +0200 | [diff] [blame] | 298 | CatLog.d(LOG_TAG, "sendResponse resID[" + resId + "] input[*****] help[" |
| 299 | + help + "]"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 300 | mIsResponseSent = true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 301 | Bundle args = new Bundle(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 302 | args.putInt(StkAppService.RES_ID, resId); |
| 303 | if (input != null) { |
| 304 | args.putString(StkAppService.INPUT, input); |
| 305 | } |
| 306 | args.putBoolean(StkAppService.HELP, help); |
Takanori Nakano | 43dacc0 | 2018-07-26 11:27:39 +0900 | [diff] [blame] | 307 | appService.sendResponse(args, mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | @Override |
| 311 | public boolean onCreateOptionsMenu(android.view.Menu menu) { |
| 312 | super.onCreateOptionsMenu(menu); |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 313 | createOptionsMenuInternal(menu); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 314 | return true; |
| 315 | } |
| 316 | |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 317 | private void createOptionsMenuInternal(Menu menu) { |
| 318 | menu.add(Menu.NONE, StkApp.MENU_ID_END_SESSION, 1, R.string.menu_end_session); |
| 319 | menu.add(0, StkApp.MENU_ID_HELP, 2, R.string.help); |
| 320 | } |
| 321 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 322 | @Override |
| 323 | public boolean onPrepareOptionsMenu(android.view.Menu menu) { |
| 324 | super.onPrepareOptionsMenu(menu); |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 325 | prepareOptionsMenuInternal(menu); |
| 326 | return true; |
| 327 | } |
| 328 | |
| 329 | private void prepareOptionsMenuInternal(Menu menu) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 330 | menu.findItem(StkApp.MENU_ID_END_SESSION).setVisible(true); |
| 331 | menu.findItem(StkApp.MENU_ID_HELP).setVisible(mStkInput.helpAvailable); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | @Override |
| 335 | public boolean onOptionsItemSelected(MenuItem item) { |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 336 | if (optionsItemSelectedInternal(item)) { |
| 337 | return true; |
| 338 | } |
| 339 | return super.onOptionsItemSelected(item); |
| 340 | } |
| 341 | |
| 342 | private boolean optionsItemSelectedInternal(MenuItem item) { |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 343 | if (mIsResponseSent) { |
| 344 | CatLog.d(LOG_TAG, "Already responded"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 345 | return true; |
| 346 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 347 | switch (item.getItemId()) { |
| 348 | case StkApp.MENU_ID_END_SESSION: |
| 349 | sendResponse(StkAppService.RES_ID_END_SESSION); |
| 350 | finish(); |
| 351 | return true; |
| 352 | case StkApp.MENU_ID_HELP: |
| 353 | sendResponse(StkAppService.RES_ID_INPUT, "", true); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 354 | return true; |
| 355 | } |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 356 | return false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 359 | @Override |
| 360 | protected void onSaveInstanceState(Bundle outState) { |
| 361 | CatLog.d(LOG_TAG, "onSaveInstanceState: " + mSlotId); |
Takanori Nakano | 71f9ee2 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 362 | outState.putBoolean(RESPONSE_SENT_KEY, mIsResponseSent); |
| 363 | outState.putString(INPUT_STRING_KEY, mTextIn.getText().toString()); |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 364 | outState.putLong(ALARM_TIME_KEY, mAlarmTime); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | @Override |
| 368 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 369 | CatLog.d(LOG_TAG, "onRestoreInstanceState: " + mSlotId); |
Takanori Nakano | 71f9ee2 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 370 | |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 371 | mIsResponseSent = savedInstanceState.getBoolean(RESPONSE_SENT_KEY); |
| 372 | if (mIsResponseSent && (mMoreOptions != null)) { |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 373 | mMoreOptions.setVisibility(View.INVISIBLE); |
| 374 | } |
Takanori Nakano | 71f9ee2 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 375 | |
Takanori Nakano | 71f9ee2 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 376 | String savedString = savedInstanceState.getString(INPUT_STRING_KEY); |
Miyu Iijima | 1e28c65 | 2018-11-14 10:08:05 +0900 | [diff] [blame] | 377 | mTextIn.setText(savedString); |
| 378 | updateButton(); |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 379 | |
| 380 | mAlarmTime = savedInstanceState.getLong(ALARM_TIME_KEY, NO_INPUT_ALARM); |
| 381 | if (mAlarmTime != NO_INPUT_ALARM) { |
| 382 | startTimeOut(); |
| 383 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 384 | } |
| 385 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 386 | public void beforeTextChanged(CharSequence s, int start, int count, |
| 387 | int after) { |
| 388 | } |
| 389 | |
| 390 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 391 | // Reset timeout. |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 392 | cancelTimeOut(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 393 | startTimeOut(); |
Miyu Iijima | c9a1720 | 2018-10-17 19:17:14 +0900 | [diff] [blame] | 394 | updateButton(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | public void afterTextChanged(Editable s) { |
| 398 | } |
| 399 | |
Miyu Iijima | c9a1720 | 2018-10-17 19:17:14 +0900 | [diff] [blame] | 400 | private void updateButton() { |
| 401 | // Disable the button if the length of the input text does not meet the expectation. |
| 402 | Button okButton = (Button) findViewById(R.id.button_ok); |
| 403 | okButton.setEnabled((mTextIn.getText().length() < mStkInput.minLen) ? false : true); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | private void cancelTimeOut() { |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 407 | if (mAlarmTime != NO_INPUT_ALARM) { |
| 408 | CatLog.d(LOG_TAG, "cancelTimeOut - slot id: " + mSlotId); |
| 409 | AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); |
| 410 | am.cancel(mAlarmListener); |
| 411 | mAlarmTime = NO_INPUT_ALARM; |
| 412 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | private void startTimeOut() { |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 416 | // No need to set alarm if device sent TERMINAL RESPONSE already. |
| 417 | if (mIsResponseSent) { |
| 418 | return; |
Abhishek Adappa | c7c3a46 | 2013-02-14 13:36:57 -0800 | [diff] [blame] | 419 | } |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 420 | |
| 421 | if (mAlarmTime == NO_INPUT_ALARM) { |
| 422 | int duration = StkApp.calculateDurationInMilis(mStkInput.duration); |
| 423 | if (duration <= 0) { |
| 424 | duration = StkApp.UI_TIMEOUT; |
| 425 | } |
| 426 | mAlarmTime = SystemClock.elapsedRealtime() + duration; |
| 427 | } |
| 428 | |
| 429 | CatLog.d(LOG_TAG, "startTimeOut: " + mAlarmTime + "ms, slot id: " + mSlotId); |
| 430 | AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); |
| 431 | am.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, mAlarmTime, INPUT_ALARM_TAG, |
| 432 | mAlarmListener, null); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | private void configInputDisplay() { |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 436 | TextInputLayout textInput = (TextInputLayout) findViewById(R.id.text_input_layout); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 437 | |
| 438 | int inTypeId = R.string.alphabet; |
| 439 | |
| 440 | // set the prompt. |
Yoshiaki Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 441 | if ((mStkInput.icon == null || !mStkInput.iconSelfExplanatory) |
| 442 | && !TextUtils.isEmpty(mStkInput.text)) { |
Takeshi Shinohara | c658900 | 2013-05-27 11:01:06 +0900 | [diff] [blame] | 443 | mPromptView.setText(mStkInput.text); |
Yoshiaki Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 444 | mPromptView.setVisibility(View.VISIBLE); |
Takeshi Shinohara | c658900 | 2013-05-27 11:01:06 +0900 | [diff] [blame] | 445 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 446 | |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 447 | // Set input type (alphabet/digit) info close to the InText form. |
Yukiko Fujimura | 913c143 | 2019-02-21 17:14:30 +0900 | [diff] [blame] | 448 | boolean hideHelper = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 449 | if (mStkInput.digitOnly) { |
| 450 | mTextIn.setKeyListener(StkDigitsKeyListener.getInstance()); |
| 451 | inTypeId = R.string.digits; |
Yukiko Fujimura | 913c143 | 2019-02-21 17:14:30 +0900 | [diff] [blame] | 452 | hideHelper = StkAppService.getBooleanCarrierConfig(this, |
| 453 | CarrierConfigManager.KEY_HIDE_DIGITS_HELPER_TEXT_ON_STK_INPUT_SCREEN_BOOL, |
| 454 | mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 455 | } |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 456 | textInput.setHelperText(getResources().getString(inTypeId)); |
Yukiko Fujimura | 913c143 | 2019-02-21 17:14:30 +0900 | [diff] [blame] | 457 | textInput.setHelperTextEnabled(!hideHelper); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 458 | |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 459 | setTitle(R.string.app_name); |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 460 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 461 | if (mStkInput.icon != null) { |
Yoshiaki Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 462 | ImageView imageView = (ImageView) findViewById(R.id.icon); |
Umashankar Godachi | c77445b | 2018-02-28 02:51:56 +0530 | [diff] [blame] | 463 | imageView.setContentDescription(StkAppService.TEXT_ICON_FROM_COMMAND + ": " |
| 464 | + mStkInput.text); |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 465 | imageView.setImageBitmap(mStkInput.icon); |
| 466 | imageView.setVisibility(View.VISIBLE); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | // Handle specific global and text attributes. |
| 470 | switch (mState) { |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 471 | case STATE_TEXT: |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 472 | mTextIn.setFilters(new InputFilter[] {new InputFilter.LengthFilter(mStkInput.maxLen)}); |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 473 | |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 474 | textInput.setCounterMaxLength(mStkInput.maxLen); |
Nazanin | ddb13bb | 2021-08-23 16:30:05 -0700 | [diff] [blame] | 475 | //do not show the length helper for the text input |
| 476 | textInput.setCounterEnabled(false); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 477 | |
| 478 | if (!mStkInput.echo) { |
Yujing Gu | 6b9716c | 2014-04-23 13:50:50 +0800 | [diff] [blame] | 479 | mTextIn.setTransformationMethod(PasswordTransformationMethod |
| 480 | .getInstance()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 481 | } |
Srikanth Chintala | a091b73 | 2016-02-04 14:46:43 +0530 | [diff] [blame] | 482 | mTextIn.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN); |
Kazuhiro Uto | 1287091 | 2018-07-18 17:43:56 +0900 | [diff] [blame] | 483 | // Request the initial focus on the edit box and show the software keyboard. |
| 484 | mTextIn.requestFocus(); |
| 485 | getWindow().setSoftInputMode( |
| 486 | WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 487 | // Set default text if present. |
| 488 | if (mStkInput.defaultText != null) { |
| 489 | mTextIn.setText(mStkInput.defaultText); |
| 490 | } else { |
| 491 | // make sure the text is cleared |
| 492 | mTextIn.setText("", BufferType.EDITABLE); |
| 493 | } |
Miyu Iijima | c9a1720 | 2018-10-17 19:17:14 +0900 | [diff] [blame] | 494 | updateButton(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 495 | |
| 496 | break; |
| 497 | case STATE_YES_NO: |
| 498 | // Set display mode - normal / yes-no layout |
| 499 | mYesNoLayout.setVisibility(View.VISIBLE); |
| 500 | mNormalLayout.setVisibility(View.GONE); |
| 501 | break; |
| 502 | } |
| 503 | } |
| 504 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 505 | private void initFromIntent(Intent intent) { |
| 506 | // Get the calling intent type: text/key, and setup the |
| 507 | // display parameters. |
| 508 | CatLog.d(LOG_TAG, "initFromIntent - slot id: " + mSlotId); |
| 509 | if (intent != null) { |
| 510 | mStkInput = intent.getParcelableExtra("INPUT"); |
| 511 | mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1); |
| 512 | CatLog.d(LOG_TAG, "onCreate - slot id: " + mSlotId); |
| 513 | if (mStkInput == null) { |
| 514 | finish(); |
| 515 | } else { |
| 516 | mState = mStkInput.yesNo ? STATE_YES_NO : |
| 517 | STATE_TEXT; |
| 518 | configInputDisplay(); |
| 519 | } |
| 520 | } else { |
| 521 | finish(); |
| 522 | } |
| 523 | } |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 524 | |
| 525 | private final AlarmManager.OnAlarmListener mAlarmListener = |
| 526 | new AlarmManager.OnAlarmListener() { |
| 527 | @Override |
| 528 | public void onAlarm() { |
| 529 | CatLog.d(LOG_TAG, "The alarm time is reached"); |
| 530 | mAlarmTime = NO_INPUT_ALARM; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 531 | sendResponse(StkAppService.RES_ID_TIMEOUT); |
| 532 | } |
| 533 | }; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 534 | } |