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