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