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