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