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