Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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.phone; |
| 18 | |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 19 | import static android.telephony.ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN; |
| 20 | |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 21 | import android.animation.Animator; |
| 22 | import android.animation.AnimatorListenerAdapter; |
Grace Jia | 835d8e6 | 2020-04-01 15:47:39 -0700 | [diff] [blame] | 23 | import android.annotation.ColorInt; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import android.app.Activity; |
| 25 | import android.app.AlertDialog; |
| 26 | import android.app.Dialog; |
Michele | f6a5ea2 | 2019-10-15 16:08:54 -0700 | [diff] [blame] | 27 | import android.app.WallpaperColors; |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 28 | import android.app.WallpaperManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 29 | import android.content.BroadcastReceiver; |
| 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
| 32 | import android.content.IntentFilter; |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 33 | import android.database.DataSetObserver; |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 34 | import android.graphics.Color; |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 35 | import android.graphics.Point; |
Michele | f6a5ea2 | 2019-10-15 16:08:54 -0700 | [diff] [blame] | 36 | import android.graphics.drawable.ColorDrawable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.media.AudioManager; |
| 38 | import android.media.ToneGenerator; |
| 39 | import android.net.Uri; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 40 | import android.os.AsyncTask; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Bundle; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 42 | import android.os.PersistableBundle; |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 43 | import android.os.UserHandle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.provider.Settings; |
Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 45 | import android.telecom.PhoneAccount; |
Tyler Gunn | fa77e20 | 2018-03-23 07:47:00 -0700 | [diff] [blame] | 46 | import android.telecom.TelecomManager; |
Jonathan Basseri | 3649bdb | 2015-04-30 22:39:11 -0700 | [diff] [blame] | 47 | import android.telephony.CarrierConfigManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.telephony.PhoneNumberUtils; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 49 | import android.telephony.ServiceState; |
Santos Cordon | e137eed | 2015-06-23 15:34:47 -0700 | [diff] [blame] | 50 | import android.telephony.SubscriptionManager; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 51 | import android.telephony.TelephonyManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.text.Editable; |
Hall Liu | bdc9c88 | 2016-05-25 15:25:28 -0700 | [diff] [blame] | 53 | import android.text.InputType; |
Hall Liu | dc27431 | 2016-03-01 16:34:45 -0800 | [diff] [blame] | 54 | import android.text.Spannable; |
| 55 | import android.text.SpannableString; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.text.TextUtils; |
| 57 | import android.text.TextWatcher; |
| 58 | import android.text.method.DialerKeyListener; |
Ihab Awad | f7c1a5a | 2014-12-08 19:24:23 -0800 | [diff] [blame] | 59 | import android.text.style.TtsSpan; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 60 | import android.util.Log; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 61 | import android.util.TypedValue; |
Yorke Lee | 116dd07 | 2015-08-31 11:38:39 -0700 | [diff] [blame] | 62 | import android.view.HapticFeedbackConstants; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 63 | import android.view.KeyEvent; |
Andrew Lee | d5631e8 | 2014-10-08 16:03:58 -0700 | [diff] [blame] | 64 | import android.view.MenuItem; |
Adrian Roos | 1c4b47f | 2015-04-13 14:53:32 -0700 | [diff] [blame] | 65 | import android.view.MotionEvent; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 66 | import android.view.View; |
Chihhang Chuang | caba0da | 2018-08-02 22:25:06 +0800 | [diff] [blame] | 67 | import android.view.View.AccessibilityDelegate; |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 68 | import android.view.ViewGroup; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 69 | import android.view.WindowManager; |
Chihhang Chuang | caba0da | 2018-08-02 22:25:06 +0800 | [diff] [blame] | 70 | import android.view.accessibility.AccessibilityEvent; |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 71 | import android.widget.TextView; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 72 | |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 73 | import com.android.phone.common.dialpad.DialpadKeyButton; |
Sai Cheemalapati | 14462b6 | 2014-06-18 13:53:56 -0700 | [diff] [blame] | 74 | import com.android.phone.common.util.ViewUtil; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 75 | import com.android.phone.common.widget.ResizingTextEditText; |
Grace Jia | 835d8e6 | 2020-04-01 15:47:39 -0700 | [diff] [blame] | 76 | import com.android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 77 | |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 78 | import java.util.ArrayList; |
| 79 | import java.util.List; |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 80 | import java.util.Locale; |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 81 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 82 | /** |
| 83 | * EmergencyDialer is a special dialer that is used ONLY for dialing emergency calls. |
| 84 | * |
| 85 | * It's a simplified version of the regular dialer (i.e. the TwelveKeyDialer |
| 86 | * activity from apps/Contacts) that: |
Leo Hsu | 83ab233 | 2018-12-18 15:20:45 +0800 | [diff] [blame] | 87 | * 1. Allows ONLY emergency calls to be dialed |
| 88 | * 2. Disallows voicemail functionality |
| 89 | * 3. Allows this activity to stay in front of the keyguard. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 90 | * |
| 91 | * TODO: Even though this is an ultra-simplified version of the normal |
| 92 | * dialer, there's still lots of code duplication between this class and |
| 93 | * the TwelveKeyDialer class from apps/Contacts. Could the common code be |
| 94 | * moved into a shared base class that would live in the framework? |
| 95 | * Or could we figure out some way to move *this* class into apps/Contacts |
| 96 | * also? |
| 97 | */ |
| 98 | public class EmergencyDialer extends Activity implements View.OnClickListener, |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 99 | View.OnLongClickListener, View.OnKeyListener, TextWatcher, |
Michele | f6a5ea2 | 2019-10-15 16:08:54 -0700 | [diff] [blame] | 100 | DialpadKeyButton.OnPressedListener, |
| 101 | WallpaperManager.OnColorsChangedListener, |
Leo Hsu | 7bcfb8e | 2019-05-03 21:54:45 +0800 | [diff] [blame] | 102 | EmergencyShortcutButton.OnConfirmClickListener, |
Wesley.CW Wang | 5e78539 | 2018-08-09 20:11:34 +0800 | [diff] [blame] | 103 | EmergencyInfoGroup.OnConfirmClickListener { |
Shaotang Li | 8662a91 | 2018-07-04 16:53:01 +0800 | [diff] [blame] | 104 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 105 | // Keys used with onSaveInstanceState(). |
| 106 | private static final String LAST_NUMBER = "lastNumber"; |
| 107 | |
| 108 | // Intent action for this activity. |
| 109 | public static final String ACTION_DIAL = "com.android.phone.EmergencyDialer.DIAL"; |
| 110 | |
Shaotang Li | 8662a91 | 2018-07-04 16:53:01 +0800 | [diff] [blame] | 111 | /** |
| 112 | * Extra included in {@link #ACTION_DIAL} to indicate the entry type that user starts |
| 113 | * the emergency dialer. |
| 114 | */ |
| 115 | public static final String EXTRA_ENTRY_TYPE = |
| 116 | "com.android.phone.EmergencyDialer.extra.ENTRY_TYPE"; |
| 117 | |
Leo Hsu | e3512b6 | 2019-02-14 15:53:00 +0800 | [diff] [blame] | 118 | // Constants indicating the entry type that user opened emergency dialer. |
| 119 | // This info is sent from system UI with EXTRA_ENTRY_TYPE. Please make them being |
| 120 | // in sync with those in com.android.systemui.util.EmergencyDialerConstants. |
| 121 | public static final int ENTRY_TYPE_UNKNOWN = 0; |
| 122 | public static final int ENTRY_TYPE_LOCKSCREEN_BUTTON = 1; |
| 123 | public static final int ENTRY_TYPE_POWER_MENU = 2; |
| 124 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | // List of dialer button IDs. |
Leo Hsu | 83ab233 | 2018-12-18 15:20:45 +0800 | [diff] [blame] | 126 | private static final int[] DIALER_KEYS = new int[]{ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 127 | R.id.one, R.id.two, R.id.three, |
| 128 | R.id.four, R.id.five, R.id.six, |
| 129 | R.id.seven, R.id.eight, R.id.nine, |
Leo Hsu | 83ab233 | 2018-12-18 15:20:45 +0800 | [diff] [blame] | 130 | R.id.star, R.id.zero, R.id.pound}; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | |
| 132 | // Debug constants. |
| 133 | private static final boolean DBG = false; |
| 134 | private static final String LOG_TAG = "EmergencyDialer"; |
| 135 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 136 | /** The length of DTMF tones in milliseconds */ |
| 137 | private static final int TONE_LENGTH_MS = 150; |
| 138 | |
| 139 | /** The DTMF tone volume relative to other sounds in the stream */ |
| 140 | private static final int TONE_RELATIVE_VOLUME = 80; |
| 141 | |
| 142 | /** Stream type used to play the DTMF tones off call, and mapped to the volume control keys */ |
| 143 | private static final int DIAL_TONE_STREAM_TYPE = AudioManager.STREAM_DTMF; |
| 144 | |
| 145 | private static final int BAD_EMERGENCY_NUMBER_DIALOG = 0; |
| 146 | |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 147 | /** 90% opacity, different from other gradients **/ |
| 148 | private static final int BACKGROUND_GRADIENT_ALPHA = 230; |
| 149 | |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 150 | /** 85% opacity for black background **/ |
| 151 | private static final int BLACK_BACKGROUND_GRADIENT_ALPHA = 217; |
| 152 | |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 153 | /** Size limit of emergency shortcut buttons container. **/ |
| 154 | private static final int SHORTCUT_SIZE_LIMIT = 3; |
| 155 | |
Grace Jia | 835d8e6 | 2020-04-01 15:47:39 -0700 | [diff] [blame] | 156 | private static final float COLOR_DELTA = 1.0f / 16.0f; |
| 157 | |
| 158 | /** Dial button color, from packages/apps/PhoneCommon/res/drawable-mdpi/fab_green.png **/ |
| 159 | @ColorInt private static final int DIALER_GREEN = 0xff00c853; |
| 160 | |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 161 | ResizingTextEditText mDigits; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 162 | private View mDialButton; |
| 163 | private View mDelete; |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 164 | private View mEmergencyShortcutView; |
| 165 | private View mDialpadView; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 166 | |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 167 | private List<EmergencyShortcutButton> mEmergencyShortcutButtonList; |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 168 | private EccShortcutAdapter mShortcutAdapter; |
| 169 | private DataSetObserver mShortcutDataSetObserver = null; |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 170 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 171 | private ToneGenerator mToneGenerator; |
| 172 | private Object mToneGeneratorLock = new Object(); |
| 173 | |
| 174 | // determines if we want to playback local DTMF tones. |
| 175 | private boolean mDTMFToneEnabled; |
| 176 | |
Fan Zhang | 39d81f5 | 2022-03-21 22:47:21 +0000 | [diff] [blame] | 177 | private EmergencyInfoGroup mEmergencyInfoInDialpad; |
| 178 | private EmergencyInfoGroup mEmergencyInfoInShortcut; |
Wesley.CW Wang | 5e78539 | 2018-08-09 20:11:34 +0800 | [diff] [blame] | 179 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 180 | // close activity when screen turns off |
| 181 | private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 182 | @Override |
| 183 | public void onReceive(Context context, Intent intent) { |
| 184 | if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) { |
Adrian Roos | 061c723 | 2015-04-21 12:37:07 -0700 | [diff] [blame] | 185 | finishAndRemoveTask(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | }; |
| 189 | |
Chihhang Chuang | caba0da | 2018-08-02 22:25:06 +0800 | [diff] [blame] | 190 | /** |
| 191 | * Customize accessibility methods in View. |
| 192 | */ |
| 193 | private AccessibilityDelegate mAccessibilityDelegate = new AccessibilityDelegate() { |
| 194 | |
| 195 | /** |
| 196 | * Stop AccessiblityService from reading the title of a hidden View. |
| 197 | * |
| 198 | * <p>The crossfade animation will set the visibility of fade out view to {@link View.GONE} |
| 199 | * in the animation end. The view with an accessibility pane title would call the |
| 200 | * {@link AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED} event, which would trigger the |
| 201 | * accessibility service to read the pane title of fade out view instead of pane title of |
| 202 | * fade in view. So it need to filter out the event called by vanished pane. |
| 203 | */ |
| 204 | @Override |
| 205 | public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 206 | if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED |
| 207 | && host.getVisibility() == View.GONE) { |
| 208 | return; |
| 209 | } |
| 210 | super.onPopulateAccessibilityEvent(host, event); |
| 211 | } |
| 212 | }; |
| 213 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 214 | private String mLastNumber; // last number we tried to dial. Used to restore error dialog. |
| 215 | |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 216 | // Background gradient |
Michele | f6a5ea2 | 2019-10-15 16:08:54 -0700 | [diff] [blame] | 217 | private ColorDrawable mBackgroundDrawable; |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 218 | private boolean mSupportsDarkText; |
| 219 | |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 220 | private boolean mIsWfcEmergencyCallingWarningEnabled; |
| 221 | private float mDefaultDigitsTextSize; |
| 222 | |
Leo Hsu | e3512b6 | 2019-02-14 15:53:00 +0800 | [diff] [blame] | 223 | private int mEntryType; |
Leo Hsu | bc7553a | 2019-03-05 15:47:23 +0800 | [diff] [blame] | 224 | private ShortcutViewUtils.Config mShortcutViewConfig; |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 225 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 226 | @Override |
| 227 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 228 | // Do nothing |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public void onTextChanged(CharSequence input, int start, int before, int changeCount) { |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 233 | maybeChangeHintSize(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | @Override |
| 237 | public void afterTextChanged(Editable input) { |
| 238 | // Check for special sequences, in particular the "**04" or "**05" |
| 239 | // sequences that allow you to enter PIN or PUK-related codes. |
| 240 | // |
| 241 | // But note we *don't* allow most other special sequences here, |
| 242 | // like "secret codes" (*#*#<code>#*#*) or IMEI display ("*#06#"), |
| 243 | // since those shouldn't be available if the device is locked. |
| 244 | // |
| 245 | // So we call SpecialCharSequenceMgr.handleCharsForLockedDevice() |
| 246 | // here, not the regular handleChars() method. |
| 247 | if (SpecialCharSequenceMgr.handleCharsForLockedDevice(this, input.toString(), this)) { |
| 248 | // A special sequence was entered, clear the digits |
| 249 | mDigits.getText().clear(); |
| 250 | } |
| 251 | |
| 252 | updateDialAndDeleteButtonStateEnabledAttr(); |
Ihab Awad | f7c1a5a | 2014-12-08 19:24:23 -0800 | [diff] [blame] | 253 | updateTtsSpans(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | @Override |
| 257 | protected void onCreate(Bundle icicle) { |
| 258 | super.onCreate(icicle); |
| 259 | |
Tyler Gunn | 662cb39 | 2025-01-17 23:34:46 +0000 | [diff] [blame^] | 260 | getWindow().addSystemFlags( |
| 261 | android.view.WindowManager.LayoutParams |
| 262 | .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); |
| 263 | |
Leo Hsu | e3512b6 | 2019-02-14 15:53:00 +0800 | [diff] [blame] | 264 | mEntryType = getIntent().getIntExtra(EXTRA_ENTRY_TYPE, ENTRY_TYPE_UNKNOWN); |
| 265 | Log.d(LOG_TAG, "Launched from " + entryTypeToString(mEntryType)); |
| 266 | |
Mengjun Leng | b9d14f0 | 2017-10-31 14:28:14 +0800 | [diff] [blame] | 267 | // Allow turning screen on |
| 268 | setTurnScreenOn(true); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 269 | |
Chuck Liao | cdeebb4 | 2018-10-30 12:07:18 +0800 | [diff] [blame] | 270 | CarrierConfigManager configMgr = getSystemService(CarrierConfigManager.class); |
Tomasz Wasilczyk | 8919d70 | 2024-04-01 10:58:20 -0700 | [diff] [blame] | 271 | PersistableBundle carrierConfig = configMgr == null ? null : |
Chuck Liao | cdeebb4 | 2018-10-30 12:07:18 +0800 | [diff] [blame] | 272 | configMgr.getConfigForSubId(SubscriptionManager.getDefaultVoiceSubscriptionId()); |
| 273 | |
Leo Hsu | bc7553a | 2019-03-05 15:47:23 +0800 | [diff] [blame] | 274 | mShortcutViewConfig = new ShortcutViewUtils.Config(this, carrierConfig, mEntryType); |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 275 | Log.d(LOG_TAG, "Enable emergency dialer shortcut: " |
Leo Hsu | bc7553a | 2019-03-05 15:47:23 +0800 | [diff] [blame] | 276 | + mShortcutViewConfig.isEnabled()); |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 277 | |
Leo Hsu | bc7553a | 2019-03-05 15:47:23 +0800 | [diff] [blame] | 278 | if (mShortcutViewConfig.isEnabled()) { |
Leo Hsu | 83ab233 | 2018-12-18 15:20:45 +0800 | [diff] [blame] | 279 | // Shortcut view doesn't support dark text theme. |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 280 | updateTheme(false); |
| 281 | } else { |
Michele | f6a5ea2 | 2019-10-15 16:08:54 -0700 | [diff] [blame] | 282 | WallpaperColors wallpaperColors = |
| 283 | getWallpaperManager().getWallpaperColors(WallpaperManager.FLAG_LOCK); |
| 284 | updateTheme(supportsDarkText(wallpaperColors)); |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 285 | } |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 286 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 287 | setContentView(R.layout.emergency_dialer); |
| 288 | |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 289 | mDigits = (ResizingTextEditText) findViewById(R.id.digits); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 290 | mDigits.setKeyListener(DialerKeyListener.getInstance()); |
| 291 | mDigits.setOnClickListener(this); |
| 292 | mDigits.setOnKeyListener(this); |
| 293 | mDigits.setLongClickable(false); |
Hall Liu | bdc9c88 | 2016-05-25 15:25:28 -0700 | [diff] [blame] | 294 | mDigits.setInputType(InputType.TYPE_NULL); |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 295 | mDefaultDigitsTextSize = mDigits.getScaledTextSize(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 296 | maybeAddNumberFormatting(); |
| 297 | |
Michele | f6a5ea2 | 2019-10-15 16:08:54 -0700 | [diff] [blame] | 298 | mBackgroundDrawable = new ColorDrawable(); |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 299 | Point displaySize = new Point(); |
| 300 | ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) |
| 301 | .getDefaultDisplay().getSize(displaySize); |
Lucas Dupin | 4946f6f | 2019-04-09 15:03:19 -0700 | [diff] [blame] | 302 | mBackgroundDrawable.setAlpha(mShortcutViewConfig.isEnabled() |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 303 | ? BLACK_BACKGROUND_GRADIENT_ALPHA : BACKGROUND_GRADIENT_ALPHA); |
Lucas Dupin | 4946f6f | 2019-04-09 15:03:19 -0700 | [diff] [blame] | 304 | getWindow().setBackgroundDrawable(mBackgroundDrawable); |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 305 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 306 | // Check for the presence of the keypad |
| 307 | View view = findViewById(R.id.one); |
| 308 | if (view != null) { |
| 309 | setupKeypad(); |
| 310 | } |
| 311 | |
| 312 | mDelete = findViewById(R.id.deleteButton); |
| 313 | mDelete.setOnClickListener(this); |
| 314 | mDelete.setOnLongClickListener(this); |
| 315 | |
Sai Cheemalapati | 14462b6 | 2014-06-18 13:53:56 -0700 | [diff] [blame] | 316 | mDialButton = findViewById(R.id.floating_action_button); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 317 | |
| 318 | // Check whether we should show the onscreen "Dial" button and co. |
Jonathan Basseri | e619a4c | 2015-06-26 14:52:26 -0700 | [diff] [blame] | 319 | // Read carrier config through the public API because PhoneGlobals is not available when we |
| 320 | // run as a secondary user. |
Tomasz Wasilczyk | 8919d70 | 2024-04-01 10:58:20 -0700 | [diff] [blame] | 321 | if (carrierConfig != null |
| 322 | && carrierConfig.getBoolean( |
| 323 | CarrierConfigManager.KEY_SHOW_ONSCREEN_DIAL_BUTTON_BOOL)) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 324 | mDialButton.setOnClickListener(this); |
| 325 | } else { |
| 326 | mDialButton.setVisibility(View.GONE); |
| 327 | } |
Tomasz Wasilczyk | 8919d70 | 2024-04-01 10:58:20 -0700 | [diff] [blame] | 328 | mIsWfcEmergencyCallingWarningEnabled = carrierConfig != null && carrierConfig.getInt( |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 329 | CarrierConfigManager.KEY_EMERGENCY_NOTIFICATION_DELAY_INT) > -1; |
| 330 | maybeShowWfcEmergencyCallingWarning(); |
| 331 | |
Adrian Roos | c9fdb6c | 2015-05-25 15:10:21 -0700 | [diff] [blame] | 332 | ViewUtil.setupFloatingActionButton(mDialButton, getResources()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 333 | |
| 334 | if (icicle != null) { |
| 335 | super.onRestoreInstanceState(icicle); |
| 336 | } |
| 337 | |
| 338 | // Extract phone number from intent |
| 339 | Uri data = getIntent().getData(); |
Jay Shrauner | 137458b | 2014-09-05 14:27:25 -0700 | [diff] [blame] | 340 | if (data != null && (PhoneAccount.SCHEME_TEL.equals(data.getScheme()))) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 341 | String number = PhoneNumberUtils.getNumberFromIntent(getIntent(), this); |
| 342 | if (number != null) { |
| 343 | mDigits.setText(number); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | // if the mToneGenerator creation fails, just continue without it. It is |
| 348 | // a local audio signal, and is not as important as the dtmf tone itself. |
| 349 | synchronized (mToneGeneratorLock) { |
| 350 | if (mToneGenerator == null) { |
| 351 | try { |
| 352 | mToneGenerator = new ToneGenerator(DIAL_TONE_STREAM_TYPE, TONE_RELATIVE_VOLUME); |
| 353 | } catch (RuntimeException e) { |
| 354 | Log.w(LOG_TAG, "Exception caught while creating local tone generator: " + e); |
| 355 | mToneGenerator = null; |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | final IntentFilter intentFilter = new IntentFilter(); |
| 361 | intentFilter.addAction(Intent.ACTION_SCREEN_OFF); |
| 362 | registerReceiver(mBroadcastReceiver, intentFilter); |
| 363 | |
Fan Zhang | 39d81f5 | 2022-03-21 22:47:21 +0000 | [diff] [blame] | 364 | mEmergencyInfoInDialpad = findViewById(R.id.emergency_dialer) |
| 365 | .findViewById(R.id.emergency_info_button); |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 366 | |
Fan Zhang | 39d81f5 | 2022-03-21 22:47:21 +0000 | [diff] [blame] | 367 | mEmergencyInfoInShortcut = findViewById(R.id.emergency_dialer_shortcuts) |
| 368 | .findViewById(R.id.emergency_info_button); |
| 369 | |
| 370 | setupEmergencyDialpadViews(); |
Wesley.CW Wang | 5e78539 | 2018-08-09 20:11:34 +0800 | [diff] [blame] | 371 | |
Leo Hsu | bc7553a | 2019-03-05 15:47:23 +0800 | [diff] [blame] | 372 | if (mShortcutViewConfig.isEnabled()) { |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 373 | setupEmergencyShortcutsView(); |
| 374 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | @Override |
| 378 | protected void onDestroy() { |
| 379 | super.onDestroy(); |
| 380 | synchronized (mToneGeneratorLock) { |
| 381 | if (mToneGenerator != null) { |
| 382 | mToneGenerator.release(); |
| 383 | mToneGenerator = null; |
| 384 | } |
| 385 | } |
| 386 | unregisterReceiver(mBroadcastReceiver); |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 387 | if (mShortcutAdapter != null && mShortcutDataSetObserver != null) { |
| 388 | mShortcutAdapter.unregisterDataSetObserver(mShortcutDataSetObserver); |
| 389 | mShortcutDataSetObserver = null; |
| 390 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | @Override |
| 394 | protected void onRestoreInstanceState(Bundle icicle) { |
| 395 | mLastNumber = icicle.getString(LAST_NUMBER); |
| 396 | } |
| 397 | |
| 398 | @Override |
| 399 | protected void onSaveInstanceState(Bundle outState) { |
| 400 | super.onSaveInstanceState(outState); |
| 401 | outState.putString(LAST_NUMBER, mLastNumber); |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * Explicitly turn off number formatting, since it gets in the way of the emergency |
| 406 | * number detector |
| 407 | */ |
| 408 | protected void maybeAddNumberFormatting() { |
| 409 | // Do nothing. |
| 410 | } |
| 411 | |
| 412 | @Override |
| 413 | protected void onPostCreate(Bundle savedInstanceState) { |
| 414 | super.onPostCreate(savedInstanceState); |
| 415 | |
| 416 | // This can't be done in onCreate(), since the auto-restoring of the digits |
| 417 | // will play DTMF tones for all the old digits if it is when onRestoreSavedInstanceState() |
| 418 | // is called. This method will be called every time the activity is created, and |
| 419 | // will always happen after onRestoreSavedInstanceState(). |
| 420 | mDigits.addTextChangedListener(this); |
| 421 | } |
| 422 | |
| 423 | private void setupKeypad() { |
| 424 | // Setup the listeners for the buttons |
| 425 | for (int id : DIALER_KEYS) { |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 426 | final DialpadKeyButton key = (DialpadKeyButton) findViewById(id); |
| 427 | key.setOnPressedListener(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | View view = findViewById(R.id.zero); |
| 431 | view.setOnLongClickListener(this); |
| 432 | } |
| 433 | |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 434 | @Override |
| 435 | public void onBackPressed() { |
Leo Hsu | 83ab233 | 2018-12-18 15:20:45 +0800 | [diff] [blame] | 436 | // If shortcut view is enabled and Dialpad view is visible, pressing the back key will |
| 437 | // back to display EmergencyShortcutView view. Otherwise, it would finish the activity. |
Leo Hsu | bc7553a | 2019-03-05 15:47:23 +0800 | [diff] [blame] | 438 | if (mShortcutViewConfig.isEnabled() && mDialpadView != null |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 439 | && mDialpadView.getVisibility() == View.VISIBLE) { |
| 440 | switchView(mEmergencyShortcutView, mDialpadView, true); |
| 441 | return; |
| 442 | } |
| 443 | super.onBackPressed(); |
| 444 | } |
| 445 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 446 | /** |
| 447 | * handle key events |
| 448 | */ |
| 449 | @Override |
| 450 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 451 | switch (keyCode) { |
| 452 | // Happen when there's a "Call" hard button. |
| 453 | case KeyEvent.KEYCODE_CALL: { |
| 454 | if (TextUtils.isEmpty(mDigits.getText().toString())) { |
| 455 | // if we are adding a call from the InCallScreen and the phone |
| 456 | // number entered is empty, we just close the dialer to expose |
| 457 | // the InCallScreen under it. |
| 458 | finish(); |
| 459 | } else { |
| 460 | // otherwise, we place the call. |
| 461 | placeCall(); |
| 462 | } |
| 463 | return true; |
| 464 | } |
| 465 | } |
| 466 | return super.onKeyDown(keyCode, event); |
| 467 | } |
| 468 | |
| 469 | private void keyPressed(int keyCode) { |
Yorke Lee | 116dd07 | 2015-08-31 11:38:39 -0700 | [diff] [blame] | 470 | mDigits.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 471 | KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode); |
| 472 | mDigits.onKeyDown(keyCode, event); |
| 473 | } |
| 474 | |
| 475 | @Override |
| 476 | public boolean onKey(View view, int keyCode, KeyEvent event) { |
Amit Mahajan | 28a499c | 2019-11-20 15:13:42 -0800 | [diff] [blame] | 477 | if (view.getId() |
| 478 | == R.id.digits) { // Happen when "Done" button of the IME is pressed. This can |
| 479 | // happen when this |
| 480 | // Activity is forced into landscape mode due to a desk dock. |
| 481 | if (keyCode == KeyEvent.KEYCODE_ENTER |
| 482 | && event.getAction() == KeyEvent.ACTION_UP) { |
| 483 | placeCall(); |
| 484 | return true; |
| 485 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 486 | } |
| 487 | return false; |
| 488 | } |
| 489 | |
| 490 | @Override |
Adrian Roos | 1c4b47f | 2015-04-13 14:53:32 -0700 | [diff] [blame] | 491 | public boolean dispatchTouchEvent(MotionEvent ev) { |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 492 | onPreTouchEvent(ev); |
Adrian Roos | 1c4b47f | 2015-04-13 14:53:32 -0700 | [diff] [blame] | 493 | boolean handled = super.dispatchTouchEvent(ev); |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 494 | onPostTouchEvent(ev); |
Adrian Roos | 1c4b47f | 2015-04-13 14:53:32 -0700 | [diff] [blame] | 495 | return handled; |
| 496 | } |
| 497 | |
| 498 | @Override |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 499 | public void onConfirmClick(EmergencyShortcutButton button) { |
| 500 | if (button == null) return; |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 501 | String phoneNumber = button.getPhoneNumber(); |
| 502 | |
| 503 | if (!TextUtils.isEmpty(phoneNumber)) { |
Billy Chi | 17ec228 | 2018-06-15 19:00:15 +0800 | [diff] [blame] | 504 | if (DBG) Log.d(LOG_TAG, "dial emergency number: " + Rlog.pii(LOG_TAG, phoneNumber)); |
Leo Hsu | 7bcfb8e | 2019-05-03 21:54:45 +0800 | [diff] [blame] | 505 | |
Hall Liu | 6f35de9 | 2020-01-23 14:29:26 -0800 | [diff] [blame] | 506 | placeCall(phoneNumber, TelecomManager.CALL_SOURCE_EMERGENCY_SHORTCUT, |
Leo Hsu | bc7553a | 2019-03-05 15:47:23 +0800 | [diff] [blame] | 507 | mShortcutViewConfig.getPhoneInfo()); |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 508 | } else { |
| 509 | Log.d(LOG_TAG, "emergency number is empty"); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | @Override |
Wesley.CW Wang | 5e78539 | 2018-08-09 20:11:34 +0800 | [diff] [blame] | 514 | public void onConfirmClick(EmergencyInfoGroup button) { |
| 515 | if (button == null) return; |
| 516 | |
Wesley.CW Wang | 5e78539 | 2018-08-09 20:11:34 +0800 | [diff] [blame] | 517 | Intent intent = (Intent) button.getTag(R.id.tag_intent); |
| 518 | if (intent != null) { |
Jack Yu | 58d04bd | 2024-09-10 17:32:39 -0700 | [diff] [blame] | 519 | startActivityAsUser(intent, UserHandle.CURRENT); |
Wesley.CW Wang | 5e78539 | 2018-08-09 20:11:34 +0800 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | |
| 523 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 524 | public void onClick(View view) { |
Amit Mahajan | 28a499c | 2019-11-20 15:13:42 -0800 | [diff] [blame] | 525 | if (view.getId() == R.id.deleteButton) { |
| 526 | keyPressed(KeyEvent.KEYCODE_DEL); |
| 527 | return; |
| 528 | } else if (view.getId() == R.id.floating_action_button) { |
| 529 | view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 530 | placeCall(); |
| 531 | return; |
| 532 | } else if (view.getId() == R.id.digits) { |
| 533 | if (mDigits.length() != 0) { |
| 534 | mDigits.setCursorVisible(true); |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 535 | } |
Amit Mahajan | 28a499c | 2019-11-20 15:13:42 -0800 | [diff] [blame] | 536 | return; |
| 537 | } else if (view.getId() == R.id.floating_action_button_dialpad) { |
| 538 | mDigits.getText().clear(); |
| 539 | switchView(mDialpadView, mEmergencyShortcutView, true); |
| 540 | return; |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
| 544 | @Override |
| 545 | public void onPressed(View view, boolean pressed) { |
| 546 | if (!pressed) { |
| 547 | return; |
| 548 | } |
Amit Mahajan | 28a499c | 2019-11-20 15:13:42 -0800 | [diff] [blame] | 549 | if (view.getId() == R.id.one) { |
| 550 | playTone(ToneGenerator.TONE_DTMF_1); |
| 551 | keyPressed(KeyEvent.KEYCODE_1); |
| 552 | return; |
| 553 | } else if (view.getId() == R.id.two) { |
| 554 | playTone(ToneGenerator.TONE_DTMF_2); |
| 555 | keyPressed(KeyEvent.KEYCODE_2); |
| 556 | return; |
| 557 | } else if (view.getId() == R.id.three) { |
| 558 | playTone(ToneGenerator.TONE_DTMF_3); |
| 559 | keyPressed(KeyEvent.KEYCODE_3); |
| 560 | return; |
| 561 | } else if (view.getId() == R.id.four) { |
| 562 | playTone(ToneGenerator.TONE_DTMF_4); |
| 563 | keyPressed(KeyEvent.KEYCODE_4); |
| 564 | return; |
| 565 | } else if (view.getId() == R.id.five) { |
| 566 | playTone(ToneGenerator.TONE_DTMF_5); |
| 567 | keyPressed(KeyEvent.KEYCODE_5); |
| 568 | return; |
| 569 | } else if (view.getId() == R.id.six) { |
| 570 | playTone(ToneGenerator.TONE_DTMF_6); |
| 571 | keyPressed(KeyEvent.KEYCODE_6); |
| 572 | return; |
| 573 | } else if (view.getId() == R.id.seven) { |
| 574 | playTone(ToneGenerator.TONE_DTMF_7); |
| 575 | keyPressed(KeyEvent.KEYCODE_7); |
| 576 | return; |
| 577 | } else if (view.getId() == R.id.eight) { |
| 578 | playTone(ToneGenerator.TONE_DTMF_8); |
| 579 | keyPressed(KeyEvent.KEYCODE_8); |
| 580 | return; |
| 581 | } else if (view.getId() == R.id.nine) { |
| 582 | playTone(ToneGenerator.TONE_DTMF_9); |
| 583 | keyPressed(KeyEvent.KEYCODE_9); |
| 584 | return; |
| 585 | } else if (view.getId() == R.id.zero) { |
| 586 | playTone(ToneGenerator.TONE_DTMF_0); |
| 587 | keyPressed(KeyEvent.KEYCODE_0); |
| 588 | return; |
| 589 | } else if (view.getId() == R.id.pound) { |
| 590 | playTone(ToneGenerator.TONE_DTMF_P); |
| 591 | keyPressed(KeyEvent.KEYCODE_POUND); |
| 592 | return; |
| 593 | } else if (view.getId() == R.id.star) { |
| 594 | playTone(ToneGenerator.TONE_DTMF_S); |
| 595 | keyPressed(KeyEvent.KEYCODE_STAR); |
| 596 | return; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
| 600 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 601 | * called for long touch events |
| 602 | */ |
| 603 | @Override |
| 604 | public boolean onLongClick(View view) { |
| 605 | int id = view.getId(); |
Amit Mahajan | 28a499c | 2019-11-20 15:13:42 -0800 | [diff] [blame] | 606 | if (id == R.id.deleteButton) { |
| 607 | mDigits.getText().clear(); |
| 608 | return true; |
| 609 | } else if (id == R.id.zero) { |
| 610 | removePreviousDigitIfPossible(); |
| 611 | keyPressed(KeyEvent.KEYCODE_PLUS); |
| 612 | return true; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 613 | } |
| 614 | return false; |
| 615 | } |
| 616 | |
| 617 | @Override |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 618 | protected void onStart() { |
| 619 | super.onStart(); |
Shaotang Li | 8662a91 | 2018-07-04 16:53:01 +0800 | [diff] [blame] | 620 | |
Leo Hsu | bc7553a | 2019-03-05 15:47:23 +0800 | [diff] [blame] | 621 | if (mShortcutViewConfig.isEnabled()) { |
Leo Hsu | 83ab233 | 2018-12-18 15:20:45 +0800 | [diff] [blame] | 622 | // Shortcut view doesn't support dark text theme. |
Michele | f6a5ea2 | 2019-10-15 16:08:54 -0700 | [diff] [blame] | 623 | mBackgroundDrawable.setColor(Color.BLACK); |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 624 | updateTheme(false); |
| 625 | } else { |
Michele | f6a5ea2 | 2019-10-15 16:08:54 -0700 | [diff] [blame] | 626 | WallpaperManager wallpaperManager = getWallpaperManager(); |
| 627 | if (wallpaperManager.isWallpaperSupported()) { |
| 628 | wallpaperManager.addOnColorsChangedListener(this, null); |
| 629 | } |
| 630 | |
| 631 | WallpaperColors wallpaperColors = |
| 632 | wallpaperManager.getWallpaperColors(WallpaperManager.FLAG_LOCK); |
| 633 | mBackgroundDrawable.setColor(getPrimaryColor(wallpaperColors)); |
| 634 | updateTheme(supportsDarkText(wallpaperColors)); |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 635 | } |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 636 | |
Leo Hsu | bc7553a | 2019-03-05 15:47:23 +0800 | [diff] [blame] | 637 | if (mShortcutViewConfig.isEnabled()) { |
Leo Hsu | 43d670a | 2018-12-04 15:40:36 +0800 | [diff] [blame] | 638 | updateLocationAndEccInfo(); |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 639 | } |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 643 | protected void onResume() { |
| 644 | super.onResume(); |
| 645 | |
| 646 | // retrieve the DTMF tone play back setting. |
| 647 | mDTMFToneEnabled = Settings.System.getInt(getContentResolver(), |
| 648 | Settings.System.DTMF_TONE_WHEN_DIALING, 1) == 1; |
| 649 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 650 | // if the mToneGenerator creation fails, just continue without it. It is |
| 651 | // a local audio signal, and is not as important as the dtmf tone itself. |
| 652 | synchronized (mToneGeneratorLock) { |
| 653 | if (mToneGenerator == null) { |
| 654 | try { |
| 655 | mToneGenerator = new ToneGenerator(AudioManager.STREAM_DTMF, |
| 656 | TONE_RELATIVE_VOLUME); |
| 657 | } catch (RuntimeException e) { |
| 658 | Log.w(LOG_TAG, "Exception caught while creating local tone generator: " + e); |
| 659 | mToneGenerator = null; |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 664 | updateDialAndDeleteButtonStateEnabledAttr(); |
| 665 | } |
| 666 | |
| 667 | @Override |
| 668 | public void onPause() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 669 | super.onPause(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 672 | @Override |
| 673 | protected void onStop() { |
| 674 | super.onStop(); |
Michele | f6a5ea2 | 2019-10-15 16:08:54 -0700 | [diff] [blame] | 675 | |
| 676 | WallpaperManager wallpaperManager = getWallpaperManager(); |
| 677 | if (wallpaperManager.isWallpaperSupported()) { |
| 678 | wallpaperManager.removeOnColorsChangedListener(this); |
| 679 | } |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | /** |
| 683 | * Sets theme based on gradient colors |
Leo Hsu | 83ab233 | 2018-12-18 15:20:45 +0800 | [diff] [blame] | 684 | * |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 685 | * @param supportsDarkText true if gradient supports dark text |
| 686 | */ |
| 687 | private void updateTheme(boolean supportsDarkText) { |
| 688 | if (mSupportsDarkText == supportsDarkText) { |
| 689 | return; |
| 690 | } |
| 691 | mSupportsDarkText = supportsDarkText; |
| 692 | |
| 693 | // We can't change themes after inflation, in this case we'll have to recreate |
| 694 | // the whole activity. |
Lucas Dupin | 4946f6f | 2019-04-09 15:03:19 -0700 | [diff] [blame] | 695 | if (mBackgroundDrawable != null) { |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 696 | recreate(); |
| 697 | return; |
| 698 | } |
| 699 | |
| 700 | int vis = getWindow().getDecorView().getSystemUiVisibility(); |
| 701 | if (supportsDarkText) { |
| 702 | vis |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 703 | vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 704 | setTheme(R.style.EmergencyDialerThemeDark); |
| 705 | } else { |
| 706 | vis &= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 707 | vis &= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 708 | setTheme(R.style.EmergencyDialerTheme); |
| 709 | } |
| 710 | getWindow().getDecorView().setSystemUiVisibility(vis); |
| 711 | } |
| 712 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 713 | /** |
| 714 | * place the call, but check to make sure it is a viable number. |
| 715 | */ |
| 716 | private void placeCall() { |
| 717 | mLastNumber = mDigits.getText().toString(); |
Wei Huang | 6904b14 | 2017-04-21 19:06:40 +0900 | [diff] [blame] | 718 | |
| 719 | // Convert into emergency number according to emergency conversion map. |
| 720 | // If conversion map is not defined (this is default), this method does |
| 721 | // nothing and just returns input number. |
| 722 | mLastNumber = PhoneNumberUtils.convertToEmergencyNumber(this, mLastNumber); |
| 723 | |
Leo Hsu | bc7553a | 2019-03-05 15:47:23 +0800 | [diff] [blame] | 724 | boolean isEmergencyNumber; |
Leo Hsu | 43d670a | 2018-12-04 15:40:36 +0800 | [diff] [blame] | 725 | ShortcutViewUtils.PhoneInfo phoneToMakeCall = null; |
Leo Hsu | 7bcfb8e | 2019-05-03 21:54:45 +0800 | [diff] [blame] | 726 | if (mShortcutAdapter != null && mShortcutAdapter.hasShortcut(mLastNumber)) { |
Leo Hsu | bc7553a | 2019-03-05 15:47:23 +0800 | [diff] [blame] | 727 | isEmergencyNumber = true; |
| 728 | phoneToMakeCall = mShortcutViewConfig.getPhoneInfo(); |
Leo Hsu | 7bcfb8e | 2019-05-03 21:54:45 +0800 | [diff] [blame] | 729 | } else if (mShortcutViewConfig.hasPromotedEmergencyNumber(mLastNumber)) { |
| 730 | // If a number from SIM/network/... is categoried as police/ambulance/fire, |
| 731 | // hasPromotedEmergencyNumber() will return true, but it maybe not promoted as a |
| 732 | // shortcut button because a number provided by database has higher priority. |
| 733 | isEmergencyNumber = true; |
| 734 | phoneToMakeCall = mShortcutViewConfig.getPhoneInfo(); |
Leo Hsu | bc7553a | 2019-03-05 15:47:23 +0800 | [diff] [blame] | 735 | } else { |
Automerger Merge Worker | 96417f1 | 2020-02-27 19:34:58 +0000 | [diff] [blame] | 736 | try { |
| 737 | isEmergencyNumber = getSystemService(TelephonyManager.class) |
| 738 | .isEmergencyNumber(mLastNumber); |
| 739 | } catch (IllegalStateException ise) { |
| 740 | isEmergencyNumber = false; |
| 741 | } |
Leo Hsu | 43d670a | 2018-12-04 15:40:36 +0800 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | if (isEmergencyNumber) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 745 | if (DBG) Log.d(LOG_TAG, "placing call to " + mLastNumber); |
| 746 | |
| 747 | // place the call if it is a valid number |
| 748 | if (mLastNumber == null || !TextUtils.isGraphic(mLastNumber)) { |
| 749 | // There is no number entered. |
| 750 | playTone(ToneGenerator.TONE_PROP_NACK); |
| 751 | return; |
| 752 | } |
Shaotang Li | 8662a91 | 2018-07-04 16:53:01 +0800 | [diff] [blame] | 753 | |
Hall Liu | 6f35de9 | 2020-01-23 14:29:26 -0800 | [diff] [blame] | 754 | placeCall(mLastNumber, TelecomManager.CALL_SOURCE_EMERGENCY_DIALPAD, |
Leo Hsu | 43d670a | 2018-12-04 15:40:36 +0800 | [diff] [blame] | 755 | phoneToMakeCall); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 756 | } else { |
| 757 | if (DBG) Log.d(LOG_TAG, "rejecting bad requested number " + mLastNumber); |
| 758 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 759 | showDialog(BAD_EMERGENCY_NUMBER_DIALOG); |
| 760 | } |
Yorke Lee | 9b34151 | 2014-10-17 11:36:41 -0700 | [diff] [blame] | 761 | mDigits.getText().delete(0, mDigits.getText().length()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Leo Hsu | 43d670a | 2018-12-04 15:40:36 +0800 | [diff] [blame] | 764 | private void placeCall(String number, int callSource, ShortcutViewUtils.PhoneInfo phone) { |
Leo Hsu | e3512b6 | 2019-02-14 15:53:00 +0800 | [diff] [blame] | 765 | Log.d(LOG_TAG, "Place emergency call from " + callSourceToString(callSource) |
| 766 | + ", entry = " + entryTypeToString(mEntryType)); |
| 767 | |
Leo Hsu | 43d670a | 2018-12-04 15:40:36 +0800 | [diff] [blame] | 768 | Bundle extras = new Bundle(); |
| 769 | extras.putInt(TelecomManager.EXTRA_CALL_SOURCE, callSource); |
sqian | 756f606 | 2019-02-08 21:47:14 -0800 | [diff] [blame] | 770 | /** |
| 771 | * This is used for Telecom and Telephony to tell modem user's intent is emergency call, |
| 772 | * when the dialed number is ambiguous and identified as both emergency number and any |
| 773 | * other non-emergency number; e.g. in some situation, 611 could be both an emergency |
| 774 | * number in a country and a non-emergency number of a carrier's customer service hotline. |
| 775 | */ |
| 776 | extras.putBoolean(TelecomManager.EXTRA_IS_USER_INTENT_EMERGENCY_CALL, true); |
Leo Hsu | 43d670a | 2018-12-04 15:40:36 +0800 | [diff] [blame] | 777 | |
| 778 | if (phone != null && phone.getPhoneAccountHandle() != null) { |
| 779 | // Requests to dial through the specified phone. |
| 780 | extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, |
| 781 | phone.getPhoneAccountHandle()); |
| 782 | } |
| 783 | |
| 784 | TelecomManager tm = this.getSystemService(TelecomManager.class); |
| 785 | tm.placeCall(Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null), extras); |
| 786 | } |
| 787 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 788 | /** |
| 789 | * Plays the specified tone for TONE_LENGTH_MS milliseconds. |
| 790 | * |
| 791 | * The tone is played locally, using the audio stream for phone calls. |
| 792 | * Tones are played only if the "Audible touch tones" user preference |
| 793 | * is checked, and are NOT played if the device is in silent mode. |
| 794 | * |
| 795 | * @param tone a tone code from {@link ToneGenerator} |
| 796 | */ |
| 797 | void playTone(int tone) { |
| 798 | // if local tone playback is disabled, just return. |
| 799 | if (!mDTMFToneEnabled) { |
| 800 | return; |
| 801 | } |
| 802 | |
| 803 | // Also do nothing if the phone is in silent mode. |
| 804 | // We need to re-check the ringer mode for *every* playTone() |
| 805 | // call, rather than keeping a local flag that's updated in |
| 806 | // onResume(), since it's possible to toggle silent mode without |
| 807 | // leaving the current activity (via the ENDCALL-longpress menu.) |
| 808 | AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
| 809 | int ringerMode = audioManager.getRingerMode(); |
| 810 | if ((ringerMode == AudioManager.RINGER_MODE_SILENT) |
Leo Hsu | 233f5b3 | 2018-11-07 11:08:03 +0800 | [diff] [blame] | 811 | || (ringerMode == AudioManager.RINGER_MODE_VIBRATE)) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 812 | return; |
| 813 | } |
| 814 | |
| 815 | synchronized (mToneGeneratorLock) { |
| 816 | if (mToneGenerator == null) { |
| 817 | Log.w(LOG_TAG, "playTone: mToneGenerator == null, tone: " + tone); |
| 818 | return; |
| 819 | } |
| 820 | |
| 821 | // Start the new tone (will stop any playing tone) |
| 822 | mToneGenerator.startTone(tone, TONE_LENGTH_MS); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | private CharSequence createErrorMessage(String number) { |
| 827 | if (!TextUtils.isEmpty(number)) { |
Hall Liu | dc27431 | 2016-03-01 16:34:45 -0800 | [diff] [blame] | 828 | String errorString = getString(R.string.dial_emergency_error, number); |
| 829 | int startingPosition = errorString.indexOf(number); |
| 830 | int endingPosition = startingPosition + number.length(); |
| 831 | Spannable result = new SpannableString(errorString); |
| 832 | PhoneNumberUtils.addTtsSpan(result, startingPosition, endingPosition); |
| 833 | return result; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 834 | } else { |
| 835 | return getText(R.string.dial_emergency_empty_error).toString(); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | @Override |
| 840 | protected Dialog onCreateDialog(int id) { |
| 841 | AlertDialog dialog = null; |
| 842 | if (id == BAD_EMERGENCY_NUMBER_DIALOG) { |
| 843 | // construct dialog |
Lucas Dupin | 0d666f9 | 2017-06-01 14:04:48 -0700 | [diff] [blame] | 844 | dialog = new AlertDialog.Builder(this, R.style.EmergencyDialerAlertDialogTheme) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 845 | .setTitle(getText(R.string.emergency_enable_radio_dialog_title)) |
| 846 | .setMessage(createErrorMessage(mLastNumber)) |
| 847 | .setPositiveButton(R.string.ok, null) |
| 848 | .setCancelable(true).create(); |
| 849 | |
| 850 | // blur stuff behind the dialog |
| 851 | dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
Tyler Gunn | cd6a1a9 | 2018-03-29 13:48:29 -0700 | [diff] [blame] | 852 | setShowWhenLocked(true); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 853 | } |
| 854 | return dialog; |
| 855 | } |
| 856 | |
| 857 | @Override |
| 858 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 859 | super.onPrepareDialog(id, dialog); |
| 860 | if (id == BAD_EMERGENCY_NUMBER_DIALOG) { |
| 861 | AlertDialog alert = (AlertDialog) dialog; |
| 862 | alert.setMessage(createErrorMessage(mLastNumber)); |
| 863 | } |
| 864 | } |
| 865 | |
Andrew Lee | d5631e8 | 2014-10-08 16:03:58 -0700 | [diff] [blame] | 866 | @Override |
| 867 | public boolean onOptionsItemSelected(MenuItem item) { |
| 868 | final int itemId = item.getItemId(); |
| 869 | if (itemId == android.R.id.home) { |
| 870 | onBackPressed(); |
| 871 | return true; |
| 872 | } |
| 873 | return super.onOptionsItemSelected(item); |
| 874 | } |
| 875 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 876 | /** |
| 877 | * Update the enabledness of the "Dial" and "Backspace" buttons if applicable. |
| 878 | */ |
| 879 | private void updateDialAndDeleteButtonStateEnabledAttr() { |
| 880 | final boolean notEmpty = mDigits.length() != 0; |
| 881 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 882 | mDelete.setEnabled(notEmpty); |
| 883 | } |
Yorke Lee | 9131166 | 2014-10-24 14:50:45 -0700 | [diff] [blame] | 884 | |
| 885 | /** |
| 886 | * Remove the digit just before the current position. Used by various long pressed callbacks |
| 887 | * to remove the digit that was populated as a result of the short click. |
| 888 | */ |
| 889 | private void removePreviousDigitIfPossible() { |
| 890 | final int currentPosition = mDigits.getSelectionStart(); |
| 891 | if (currentPosition > 0) { |
| 892 | mDigits.setSelection(currentPosition); |
| 893 | mDigits.getText().delete(currentPosition - 1, currentPosition); |
| 894 | } |
| 895 | } |
Ihab Awad | f7c1a5a | 2014-12-08 19:24:23 -0800 | [diff] [blame] | 896 | |
| 897 | /** |
| 898 | * Update the text-to-speech annotations in the edit field. |
| 899 | */ |
| 900 | private void updateTtsSpans() { |
| 901 | for (Object o : mDigits.getText().getSpans(0, mDigits.getText().length(), TtsSpan.class)) { |
| 902 | mDigits.getText().removeSpan(o); |
| 903 | } |
| 904 | PhoneNumberUtils.ttsSpanAsPhoneNumber(mDigits.getText(), 0, mDigits.getText().length()); |
| 905 | } |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 906 | |
| 907 | @Override |
Michele | f6a5ea2 | 2019-10-15 16:08:54 -0700 | [diff] [blame] | 908 | public void onColorsChanged(WallpaperColors colors, int which) { |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 909 | if ((which & WallpaperManager.FLAG_LOCK) != 0) { |
Michele | f6a5ea2 | 2019-10-15 16:08:54 -0700 | [diff] [blame] | 910 | mBackgroundDrawable.setColor(getPrimaryColor(colors)); |
| 911 | updateTheme(supportsDarkText(colors)); |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 912 | } |
| 913 | } |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 914 | |
| 915 | /** |
| 916 | * Where a carrier requires a warning that emergency calling is not available while on WFC, |
| 917 | * add hint text above the dial pad which warns the user of this case. |
| 918 | */ |
| 919 | private void maybeShowWfcEmergencyCallingWarning() { |
| 920 | if (!mIsWfcEmergencyCallingWarningEnabled) { |
| 921 | Log.i(LOG_TAG, "maybeShowWfcEmergencyCallingWarning: warning disabled by carrier."); |
| 922 | return; |
| 923 | } |
| 924 | |
| 925 | // Use an async task rather than calling into Telephony on UI thread. |
| 926 | AsyncTask<Void, Void, Boolean> showWfcWarningTask = new AsyncTask<Void, Void, Boolean>() { |
| 927 | @Override |
| 928 | protected Boolean doInBackground(Void... voids) { |
Leo Hsu | 43d670a | 2018-12-04 15:40:36 +0800 | [diff] [blame] | 929 | TelephonyManager tm = getSystemService(TelephonyManager.class); |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 930 | boolean isWfcAvailable = tm.isWifiCallingAvailable(); |
| 931 | ServiceState ss = tm.getServiceState(); |
| 932 | boolean isCellAvailable = |
| 933 | ss.getRilVoiceRadioTechnology() != RIL_RADIO_TECHNOLOGY_UNKNOWN; |
| 934 | Log.i(LOG_TAG, "showWfcWarningTask: isWfcAvailable=" + isWfcAvailable |
Leo Hsu | 233f5b3 | 2018-11-07 11:08:03 +0800 | [diff] [blame] | 935 | + " isCellAvailable=" + isCellAvailable |
| 936 | + "(rat=" + ss.getRilVoiceRadioTechnology() + ")"); |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 937 | return isWfcAvailable && !isCellAvailable; |
| 938 | } |
| 939 | |
| 940 | @Override |
| 941 | protected void onPostExecute(Boolean result) { |
| 942 | if (result.booleanValue()) { |
| 943 | Log.i(LOG_TAG, "showWfcWarningTask: showing ecall warning"); |
| 944 | mDigits.setHint(R.string.dial_emergency_calling_not_available); |
| 945 | } else { |
| 946 | Log.i(LOG_TAG, "showWfcWarningTask: hiding ecall warning"); |
| 947 | mDigits.setHint(""); |
| 948 | } |
| 949 | maybeChangeHintSize(); |
| 950 | } |
| 951 | }; |
| 952 | showWfcWarningTask.execute((Void) null); |
| 953 | } |
| 954 | |
| 955 | /** |
| 956 | * Where a hint is applied and there are no digits dialed, disable autoresize of the dial digits |
| 957 | * edit view and set the font size to a smaller size appropriate for the emergency calling |
| 958 | * warning. |
| 959 | */ |
| 960 | private void maybeChangeHintSize() { |
| 961 | if (TextUtils.isEmpty(mDigits.getHint()) |
| 962 | || !TextUtils.isEmpty(mDigits.getText().toString())) { |
| 963 | // No hint or there are dialed digits, so use default size. |
| 964 | mDigits.setTextSize(TypedValue.COMPLEX_UNIT_SP, mDefaultDigitsTextSize); |
| 965 | // By default, the digits view auto-resizes to fit the text it contains, so |
| 966 | // enable that now. |
| 967 | mDigits.setResizeEnabled(true); |
| 968 | Log.i(LOG_TAG, "no hint - setting to " + mDigits.getScaledTextSize()); |
| 969 | } else { |
| 970 | // Hint present and no dialed digits, set custom font size appropriate for the warning. |
| 971 | mDigits.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize( |
| 972 | R.dimen.emergency_call_warning_size)); |
| 973 | // Since we're populating this with a static text string, disable auto-resize. |
| 974 | mDigits.setResizeEnabled(false); |
| 975 | Log.i(LOG_TAG, "hint - setting to " + mDigits.getScaledTextSize()); |
| 976 | } |
| 977 | } |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 978 | |
Fan Zhang | 39d81f5 | 2022-03-21 22:47:21 +0000 | [diff] [blame] | 979 | private void setupEmergencyDialpadViews() { |
| 980 | mEmergencyInfoInDialpad.setOnConfirmClickListener(this); |
| 981 | } |
| 982 | |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 983 | private void setupEmergencyShortcutsView() { |
| 984 | mEmergencyShortcutView = findViewById(R.id.emergency_dialer_shortcuts); |
| 985 | mDialpadView = findViewById(R.id.emergency_dialer); |
| 986 | |
Chihhang Chuang | caba0da | 2018-08-02 22:25:06 +0800 | [diff] [blame] | 987 | mEmergencyShortcutView.setAccessibilityDelegate(mAccessibilityDelegate); |
| 988 | mDialpadView.setAccessibilityDelegate(mAccessibilityDelegate); |
| 989 | |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 990 | final View dialpadButton = findViewById(R.id.floating_action_button_dialpad); |
| 991 | dialpadButton.setOnClickListener(this); |
| 992 | |
Fan Zhang | 39d81f5 | 2022-03-21 22:47:21 +0000 | [diff] [blame] | 993 | mEmergencyInfoInShortcut.setOnConfirmClickListener(this); |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 994 | |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 995 | mEmergencyShortcutButtonList = new ArrayList<>(); |
| 996 | setupEmergencyCallShortcutButton(); |
| 997 | |
Leo Hsu | 43d670a | 2018-12-04 15:40:36 +0800 | [diff] [blame] | 998 | updateLocationAndEccInfo(); |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 999 | |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 1000 | switchView(mEmergencyShortcutView, mDialpadView, false); |
| 1001 | } |
| 1002 | |
Leo Hsu | 43d670a | 2018-12-04 15:40:36 +0800 | [diff] [blame] | 1003 | private void setLocationInfo() { |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 1004 | final View locationInfo = findViewById(R.id.location_info); |
| 1005 | |
Leo Hsu | bc7553a | 2019-03-05 15:47:23 +0800 | [diff] [blame] | 1006 | String countryIso = mShortcutViewConfig.getCountryIso(); |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 1007 | String countryName = null; |
| 1008 | if (!TextUtils.isEmpty(countryIso)) { |
| 1009 | Locale locale = Locale.getDefault(); |
| 1010 | countryName = new Locale(locale.getLanguage(), countryIso, locale.getVariant()) |
| 1011 | .getDisplayCountry(); |
| 1012 | } |
| 1013 | if (TextUtils.isEmpty(countryName)) { |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 1014 | locationInfo.setVisibility(View.INVISIBLE); |
| 1015 | } else { |
| 1016 | final TextView location = (TextView) locationInfo.findViewById(R.id.location_text); |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 1017 | location.setText(countryName); |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 1018 | locationInfo.setVisibility(View.VISIBLE); |
| 1019 | } |
| 1020 | } |
| 1021 | |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 1022 | private void setupEmergencyCallShortcutButton() { |
| 1023 | final ViewGroup shortcutButtonContainer = findViewById( |
| 1024 | R.id.emergency_shortcut_buttons_container); |
| 1025 | shortcutButtonContainer.setClipToOutline(true); |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 1026 | final TextView emergencyNumberTitle = findViewById(R.id.emergency_number_title); |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 1027 | |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 1028 | mShortcutAdapter = new EccShortcutAdapter(this) { |
| 1029 | @Override |
| 1030 | public View inflateView(View convertView, ViewGroup parent, CharSequence number, |
| 1031 | CharSequence description, int iconRes) { |
| 1032 | EmergencyShortcutButton button = (EmergencyShortcutButton) getLayoutInflater() |
| 1033 | .inflate(R.layout.emergency_shortcut_button, parent, false); |
| 1034 | button.setPhoneNumber(number); |
| 1035 | button.setPhoneDescription(description); |
| 1036 | button.setPhoneTypeIcon(iconRes); |
| 1037 | button.setOnConfirmClickListener(EmergencyDialer.this); |
| 1038 | return button; |
| 1039 | } |
| 1040 | }; |
| 1041 | mShortcutDataSetObserver = new DataSetObserver() { |
| 1042 | @Override |
| 1043 | public void onChanged() { |
| 1044 | super.onChanged(); |
| 1045 | updateLayout(); |
| 1046 | } |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 1047 | |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 1048 | @Override |
| 1049 | public void onInvalidated() { |
| 1050 | super.onInvalidated(); |
| 1051 | updateLayout(); |
| 1052 | } |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 1053 | |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 1054 | private void updateLayout() { |
| 1055 | // clear previous added buttons |
| 1056 | shortcutButtonContainer.removeAllViews(); |
| 1057 | mEmergencyShortcutButtonList.clear(); |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 1058 | |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 1059 | for (int i = 0; i < mShortcutAdapter.getCount() && i < SHORTCUT_SIZE_LIMIT; ++i) { |
| 1060 | EmergencyShortcutButton button = (EmergencyShortcutButton) |
| 1061 | mShortcutAdapter.getView(i, null, shortcutButtonContainer); |
| 1062 | mEmergencyShortcutButtonList.add(button); |
| 1063 | shortcutButtonContainer.addView(button); |
| 1064 | } |
| 1065 | |
Wesley.CW Wang | 5e78539 | 2018-08-09 20:11:34 +0800 | [diff] [blame] | 1066 | // Update emergency numbers title for numerous buttons. |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 1067 | if (mEmergencyShortcutButtonList.size() > 1) { |
| 1068 | emergencyNumberTitle.setText(getString( |
| 1069 | R.string.numerous_emergency_numbers_title)); |
| 1070 | } else { |
| 1071 | emergencyNumberTitle.setText(getText(R.string.single_emergency_number_title)); |
| 1072 | } |
| 1073 | } |
| 1074 | }; |
| 1075 | mShortcutAdapter.registerDataSetObserver(mShortcutDataSetObserver); |
| 1076 | } |
| 1077 | |
Leo Hsu | 43d670a | 2018-12-04 15:40:36 +0800 | [diff] [blame] | 1078 | private void updateLocationAndEccInfo() { |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 1079 | if (!isFinishing() && !isDestroyed()) { |
Leo Hsu | 43d670a | 2018-12-04 15:40:36 +0800 | [diff] [blame] | 1080 | setLocationInfo(); |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 1081 | if (mShortcutAdapter != null) { |
Leo Hsu | bc7553a | 2019-03-05 15:47:23 +0800 | [diff] [blame] | 1082 | mShortcutAdapter.updateCountryEccInfo(this, mShortcutViewConfig.getPhoneInfo()); |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 1083 | } |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | /** |
| 1088 | * Called by the activity before a touch event is dispatched to the view hierarchy. |
| 1089 | */ |
| 1090 | private void onPreTouchEvent(MotionEvent event) { |
Fan Zhang | 39d81f5 | 2022-03-21 22:47:21 +0000 | [diff] [blame] | 1091 | mEmergencyInfoInDialpad.onPreTouchEvent(event); |
| 1092 | mEmergencyInfoInShortcut.onPreTouchEvent(event); |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 1093 | |
| 1094 | if (mEmergencyShortcutButtonList != null) { |
| 1095 | for (EmergencyShortcutButton button : mEmergencyShortcutButtonList) { |
| 1096 | button.onPreTouchEvent(event); |
| 1097 | } |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | /** |
| 1102 | * Called by the activity after a touch event is dispatched to the view hierarchy. |
| 1103 | */ |
| 1104 | private void onPostTouchEvent(MotionEvent event) { |
Fan Zhang | 39d81f5 | 2022-03-21 22:47:21 +0000 | [diff] [blame] | 1105 | mEmergencyInfoInDialpad.onPostTouchEvent(event); |
| 1106 | mEmergencyInfoInShortcut.onPostTouchEvent(event); |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 1107 | |
| 1108 | if (mEmergencyShortcutButtonList != null) { |
| 1109 | for (EmergencyShortcutButton button : mEmergencyShortcutButtonList) { |
| 1110 | button.onPostTouchEvent(event); |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 1115 | /** |
| 1116 | * Switch two view. |
| 1117 | * |
Leo Hsu | 83ab233 | 2018-12-18 15:20:45 +0800 | [diff] [blame] | 1118 | * @param displayView the view would be displayed. |
| 1119 | * @param hideView the view would be hidden. |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 1120 | * @param hasAnimation is {@code true} when the view should be displayed with animation. |
| 1121 | */ |
| 1122 | private void switchView(View displayView, View hideView, boolean hasAnimation) { |
| 1123 | if (displayView == null || hideView == null) { |
| 1124 | return; |
| 1125 | } |
| 1126 | |
| 1127 | if (displayView.getVisibility() == View.VISIBLE) { |
| 1128 | return; |
| 1129 | } |
| 1130 | |
| 1131 | if (hasAnimation) { |
| 1132 | crossfade(hideView, displayView); |
| 1133 | } else { |
| 1134 | hideView.setVisibility(View.GONE); |
| 1135 | displayView.setVisibility(View.VISIBLE); |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | /** |
| 1140 | * Fade out and fade in animation between two view transition. |
| 1141 | */ |
| 1142 | private void crossfade(View fadeOutView, View fadeInView) { |
| 1143 | if (fadeOutView == null || fadeInView == null) { |
| 1144 | return; |
| 1145 | } |
| 1146 | final int shortAnimationDuration = getResources().getInteger( |
| 1147 | android.R.integer.config_shortAnimTime); |
| 1148 | |
| 1149 | fadeInView.setAlpha(0f); |
| 1150 | fadeInView.setVisibility(View.VISIBLE); |
| 1151 | |
| 1152 | fadeInView.animate() |
| 1153 | .alpha(1f) |
| 1154 | .setDuration(shortAnimationDuration) |
| 1155 | .setListener(null); |
| 1156 | |
| 1157 | fadeOutView.animate() |
| 1158 | .alpha(0f) |
| 1159 | .setDuration(shortAnimationDuration) |
| 1160 | .setListener(new AnimatorListenerAdapter() { |
| 1161 | @Override |
| 1162 | public void onAnimationEnd(Animator animation) { |
| 1163 | fadeOutView.setVisibility(View.GONE); |
| 1164 | } |
| 1165 | }); |
| 1166 | } |
Shaotang Li | 8662a91 | 2018-07-04 16:53:01 +0800 | [diff] [blame] | 1167 | |
Shaotang Li | 8662a91 | 2018-07-04 16:53:01 +0800 | [diff] [blame] | 1168 | private boolean isShortcutNumber(String number) { |
| 1169 | if (TextUtils.isEmpty(number) || mEmergencyShortcutButtonList == null) { |
| 1170 | return false; |
| 1171 | } |
| 1172 | |
| 1173 | boolean isShortcut = false; |
| 1174 | for (EmergencyShortcutButton button : mEmergencyShortcutButtonList) { |
| 1175 | if (button != null && number.equals(button.getPhoneNumber())) { |
| 1176 | isShortcut = true; |
| 1177 | break; |
| 1178 | } |
| 1179 | } |
| 1180 | return isShortcut; |
| 1181 | } |
Leo Hsu | e3512b6 | 2019-02-14 15:53:00 +0800 | [diff] [blame] | 1182 | |
| 1183 | private String entryTypeToString(int entryType) { |
| 1184 | switch (entryType) { |
| 1185 | case ENTRY_TYPE_LOCKSCREEN_BUTTON: |
| 1186 | return "LockScreen"; |
| 1187 | case ENTRY_TYPE_POWER_MENU: |
| 1188 | return "PowerMenu"; |
| 1189 | default: |
| 1190 | return "Unknown-" + entryType; |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | private String callSourceToString(int callSource) { |
| 1195 | switch (callSource) { |
Hall Liu | 6f35de9 | 2020-01-23 14:29:26 -0800 | [diff] [blame] | 1196 | case TelecomManager.CALL_SOURCE_EMERGENCY_DIALPAD: |
Leo Hsu | e3512b6 | 2019-02-14 15:53:00 +0800 | [diff] [blame] | 1197 | return "DialPad"; |
Hall Liu | 6f35de9 | 2020-01-23 14:29:26 -0800 | [diff] [blame] | 1198 | case TelecomManager.CALL_SOURCE_EMERGENCY_SHORTCUT: |
Leo Hsu | e3512b6 | 2019-02-14 15:53:00 +0800 | [diff] [blame] | 1199 | return "Shortcut"; |
| 1200 | default: |
| 1201 | return "Unknown-" + callSource; |
| 1202 | } |
| 1203 | } |
Michele | f6a5ea2 | 2019-10-15 16:08:54 -0700 | [diff] [blame] | 1204 | |
| 1205 | private WallpaperManager getWallpaperManager() { |
| 1206 | return getSystemService(WallpaperManager.class); |
| 1207 | } |
| 1208 | |
| 1209 | private static boolean supportsDarkText(WallpaperColors colors) { |
| 1210 | if (colors != null) { |
| 1211 | return (colors.getColorHints() & WallpaperColors.HINT_SUPPORTS_DARK_TEXT) != 0; |
| 1212 | } |
| 1213 | // It's possible that wallpaper colors are null (e.g. when colors are being |
| 1214 | // processed or a live wallpaper is used). In this case, fallback to same |
| 1215 | // behavior as when shortcut view is enabled. |
| 1216 | return false; |
| 1217 | } |
| 1218 | |
Grace Jia | 4c2e6ae | 2020-04-21 15:35:49 -0700 | [diff] [blame] | 1219 | private int getPrimaryColor(WallpaperColors colors) { |
Michele | f6a5ea2 | 2019-10-15 16:08:54 -0700 | [diff] [blame] | 1220 | if (colors != null) { |
Grace Jia | 835d8e6 | 2020-04-01 15:47:39 -0700 | [diff] [blame] | 1221 | // Android accessibility scanner |
| 1222 | // (https://support.google.com/accessibility/android/answer/7158390) |
| 1223 | // suggest small text and graphics have a contrast ratio greater than |
| 1224 | // 4.5 with background color. The color generated from wallpaper may not |
| 1225 | // follow this rule. Calculate a proper color here. |
| 1226 | Color primary = colors.getPrimaryColor(); |
Grace Jia | 4c2e6ae | 2020-04-21 15:35:49 -0700 | [diff] [blame] | 1227 | Color text; |
| 1228 | if (mSupportsDarkText) { |
| 1229 | text = Color.valueOf(Color.BLACK); |
| 1230 | } else { |
| 1231 | text = Color.valueOf(Color.WHITE); |
| 1232 | } |
Grace Jia | 835d8e6 | 2020-04-01 15:47:39 -0700 | [diff] [blame] | 1233 | Color dial = Color.valueOf(DIALER_GREEN); |
| 1234 | // If current primary color can't follow the contrast ratio rule, make it |
Grace Jia | 4c2e6ae | 2020-04-21 15:35:49 -0700 | [diff] [blame] | 1235 | // deeper/lighter and try again. |
Grace Jia | 835d8e6 | 2020-04-01 15:47:39 -0700 | [diff] [blame] | 1236 | while (!checkContrastRatio(primary, text)) { |
Grace Jia | 4c2e6ae | 2020-04-21 15:35:49 -0700 | [diff] [blame] | 1237 | primary = getNextColor(primary, mSupportsDarkText); |
Grace Jia | 835d8e6 | 2020-04-01 15:47:39 -0700 | [diff] [blame] | 1238 | } |
Grace Jia | 4c2e6ae | 2020-04-21 15:35:49 -0700 | [diff] [blame] | 1239 | if (!mSupportsDarkText) { |
| 1240 | while (!checkContrastRatio(primary, dial)) { |
| 1241 | primary = getNextColor(primary, mSupportsDarkText); |
| 1242 | } |
Grace Jia | 835d8e6 | 2020-04-01 15:47:39 -0700 | [diff] [blame] | 1243 | } |
| 1244 | return primary.toArgb(); |
Michele | f6a5ea2 | 2019-10-15 16:08:54 -0700 | [diff] [blame] | 1245 | } |
| 1246 | // It's possible that wallpaper colors are null (e.g. when colors are being |
| 1247 | // processed or a live wallpaper is used). In this case, fallback to same |
| 1248 | // behavior as when shortcut view is enabled. |
| 1249 | return Color.BLACK; |
| 1250 | } |
Grace Jia | 835d8e6 | 2020-04-01 15:47:39 -0700 | [diff] [blame] | 1251 | |
Grace Jia | 4c2e6ae | 2020-04-21 15:35:49 -0700 | [diff] [blame] | 1252 | private Color getNextColor(Color color, boolean darkText) { |
| 1253 | float sign = darkText ? 1.f : -1.f; |
| 1254 | float r = color.red() + sign * COLOR_DELTA; |
| 1255 | float g = color.green() + sign * COLOR_DELTA; |
| 1256 | float b = color.blue() + sign * COLOR_DELTA; |
Grace Jia | 835d8e6 | 2020-04-01 15:47:39 -0700 | [diff] [blame] | 1257 | if (r < 0f) r = 0f; |
| 1258 | if (g < 0f) g = 0f; |
| 1259 | if (b < 0f) b = 0f; |
Grace Jia | 4c2e6ae | 2020-04-21 15:35:49 -0700 | [diff] [blame] | 1260 | if (r > 1f) r = 1f; |
| 1261 | if (g > 1f) g = 1f; |
| 1262 | if (b > 1f) b = 1f; |
Grace Jia | 835d8e6 | 2020-04-01 15:47:39 -0700 | [diff] [blame] | 1263 | return Color.valueOf(r, g, b); |
| 1264 | } |
| 1265 | |
Grace Jia | 4c2e6ae | 2020-04-21 15:35:49 -0700 | [diff] [blame] | 1266 | private boolean checkContrastRatio(Color color1, Color color2) { |
Grace Jia | 835d8e6 | 2020-04-01 15:47:39 -0700 | [diff] [blame] | 1267 | float lum1 = color1.luminance(); |
| 1268 | float lum2 = color2.luminance(); |
| 1269 | double cr; |
| 1270 | if (lum1 >= lum2) { |
| 1271 | cr = (lum1 + 0.05) / (lum2 + 0.05); |
| 1272 | } else { |
| 1273 | cr = (lum2 + 0.05) / (lum1 + 0.05); |
| 1274 | } |
| 1275 | |
| 1276 | // Make cr greater than 5.0 instead of 4.5 to guarantee that transparent white |
| 1277 | // text and graphics can have contrast ratio greather than 4.5 with background. |
| 1278 | return cr > 5.0; |
| 1279 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1280 | } |