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