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