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