blob: 9e40ffe8c8efc784a3cbce99e8d05445563f4783 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
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
17package com.android.phone;
18
Tyler Gunnc5428972018-03-28 14:15:34 -070019import static android.telephony.ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN;
20
Chihhang Chuangf264cfb2018-06-05 15:29:06 +080021import android.animation.Animator;
22import android.animation.AnimatorListenerAdapter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.app.Activity;
24import android.app.AlertDialog;
25import android.app.Dialog;
Shaotang Li8662a912018-07-04 16:53:01 +080026import android.app.KeyguardManager;
Lucas Dupineb9c5702017-05-10 16:57:09 -070027import android.app.WallpaperManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.content.BroadcastReceiver;
29import android.content.Context;
30import android.content.Intent;
31import android.content.IntentFilter;
CY Cheng9a69c182018-06-15 21:20:10 +080032import android.database.DataSetObserver;
Chihhang Chuangf8d33002018-07-02 11:08:50 +080033import android.graphics.Color;
Lucas Dupineb9c5702017-05-10 16:57:09 -070034import android.graphics.Point;
Shaotang Li8662a912018-07-04 16:53:01 +080035import android.hardware.Sensor;
36import android.hardware.SensorEvent;
37import android.hardware.SensorEventListener;
38import android.hardware.SensorManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.media.AudioManager;
40import android.media.ToneGenerator;
Shaotang Li8662a912018-07-04 16:53:01 +080041import android.metrics.LogMaker;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.net.Uri;
Tyler Gunnc5428972018-03-28 14:15:34 -070043import android.os.AsyncTask;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Bundle;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070045import android.os.PersistableBundle;
Shaotang Li8662a912018-07-04 16:53:01 +080046import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.provider.Settings;
Shaotang Li5d906c12018-07-19 17:32:42 +080048import android.telecom.ParcelableCallAnalytics;
Tyler Gunn4d45d1c2014-09-12 22:17:53 -070049import android.telecom.PhoneAccount;
Tyler Gunnfa77e202018-03-23 07:47:00 -070050import android.telecom.TelecomManager;
Jonathan Basseri3649bdb2015-04-30 22:39:11 -070051import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.telephony.PhoneNumberUtils;
Billy Chi17ec2282018-06-15 19:00:15 +080053import android.telephony.Rlog;
Tyler Gunnc5428972018-03-28 14:15:34 -070054import android.telephony.ServiceState;
Santos Cordone137eed2015-06-23 15:34:47 -070055import android.telephony.SubscriptionManager;
Tyler Gunnc5428972018-03-28 14:15:34 -070056import android.telephony.TelephonyManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.text.Editable;
Hall Liubdc9c882016-05-25 15:25:28 -070058import android.text.InputType;
Hall Liudc274312016-03-01 16:34:45 -080059import android.text.Spannable;
60import android.text.SpannableString;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import android.text.TextUtils;
62import android.text.TextWatcher;
63import android.text.method.DialerKeyListener;
Ihab Awadf7c1a5a2014-12-08 19:24:23 -080064import android.text.style.TtsSpan;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.util.Log;
Tyler Gunnc5428972018-03-28 14:15:34 -070066import android.util.TypedValue;
Yorke Lee116dd072015-08-31 11:38:39 -070067import android.view.HapticFeedbackConstants;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.view.KeyEvent;
Andrew Leed5631e82014-10-08 16:03:58 -070069import android.view.MenuItem;
Adrian Roos1c4b47f2015-04-13 14:53:32 -070070import android.view.MotionEvent;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import android.view.View;
Chihhang Chuangcaba0da2018-08-02 22:25:06 +080072import android.view.View.AccessibilityDelegate;
Chihhang Chuang92cfe512018-06-07 16:25:27 +080073import android.view.ViewGroup;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.view.WindowManager;
Chihhang Chuangcaba0da2018-08-02 22:25:06 +080075import android.view.accessibility.AccessibilityEvent;
Chihhang Chuang92cfe512018-06-07 16:25:27 +080076import android.widget.TextView;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077
Lucas Dupinaf9e9912017-06-22 12:39:39 -070078import com.android.internal.colorextraction.ColorExtractor;
79import com.android.internal.colorextraction.ColorExtractor.GradientColors;
80import com.android.internal.colorextraction.drawable.GradientDrawable;
Shaotang Li8662a912018-07-04 16:53:01 +080081import com.android.internal.logging.MetricsLogger;
82import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Yorke Lee23a70732014-08-14 17:12:01 -070083import com.android.phone.common.dialpad.DialpadKeyButton;
Sai Cheemalapati14462b62014-06-18 13:53:56 -070084import com.android.phone.common.util.ViewUtil;
Tyler Gunnc5428972018-03-28 14:15:34 -070085import com.android.phone.common.widget.ResizingTextEditText;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086
Chihhang Chuang92cfe512018-06-07 16:25:27 +080087import java.util.ArrayList;
88import java.util.List;
CY Cheng9a69c182018-06-15 21:20:10 +080089import java.util.Locale;
Chihhang Chuang92cfe512018-06-07 16:25:27 +080090
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091/**
92 * EmergencyDialer is a special dialer that is used ONLY for dialing emergency calls.
93 *
94 * It's a simplified version of the regular dialer (i.e. the TwelveKeyDialer
95 * activity from apps/Contacts) that:
Leo Hsu83ab2332018-12-18 15:20:45 +080096 * 1. Allows ONLY emergency calls to be dialed
97 * 2. Disallows voicemail functionality
98 * 3. Allows this activity to stay in front of the keyguard.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099 *
100 * TODO: Even though this is an ultra-simplified version of the normal
101 * dialer, there's still lots of code duplication between this class and
102 * the TwelveKeyDialer class from apps/Contacts. Could the common code be
103 * moved into a shared base class that would live in the framework?
104 * Or could we figure out some way to move *this* class into apps/Contacts
105 * also?
106 */
107public class EmergencyDialer extends Activity implements View.OnClickListener,
Yorke Lee23a70732014-08-14 17:12:01 -0700108 View.OnLongClickListener, View.OnKeyListener, TextWatcher,
Chihhang Chuang92cfe512018-06-07 16:25:27 +0800109 DialpadKeyButton.OnPressedListener, ColorExtractor.OnColorsChangedListener,
Wesley.CW Wang5e785392018-08-09 20:11:34 +0800110 EmergencyShortcutButton.OnConfirmClickListener, SensorEventListener,
111 EmergencyInfoGroup.OnConfirmClickListener {
Shaotang Li8662a912018-07-04 16:53:01 +0800112
113 private class MetricsWriter {
Shaotang Li8662a912018-07-04 16:53:01 +0800114 // Metrics constants indicating the UI that user made phone call.
115 public static final int CALL_SOURCE_DIALPAD = 0;
116 public static final int CALL_SOURCE_SHORTCUT = 1;
117
118 // Metrics constants indicating the phone number type of a call user made.
119 public static final int PHONE_NUMBER_TYPE_GENERAL = 0;
120 public static final int PHONE_NUMBER_TYPE_EMERGENCY = 1;
121
122 // Metrics constants indicating the actions performed by user.
123 public static final int USER_ACTION_NONE = 0x0;
124 public static final int USER_ACTION_OPEN_DIALPAD = 0x1;
125 public static final int USER_ACTION_OPEN_EMERGENCY_INFO = 0x2;
126 public static final int USER_ACTION_MAKE_CALL_VIA_DIALPAD = 0x4;
127 public static final int USER_ACTION_MAKE_CALL_VIA_SHORTCUT = 0x8;
128
129 private MetricsLogger mMetricsLogger = new MetricsLogger();
130
131 public void writeMetricsForEnter() {
Leo Hsuaeb32d82018-12-25 16:01:27 +0800132 if (!mIsShortcutViewEnabled) {
133 return;
134 }
135
Shaotang Li8662a912018-07-04 16:53:01 +0800136 KeyguardManager keyguard = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
137 mMetricsLogger.write(new LogMaker(MetricsEvent.EMERGENCY_DIALER)
138 .setType(MetricsEvent.TYPE_OPEN)
Leo Hsue3512b62019-02-14 15:53:00 +0800139 .setSubtype(mEntryType)
Shaotang Li8662a912018-07-04 16:53:01 +0800140 .addTaggedData(MetricsEvent.FIELD_EMERGENCY_DIALER_IS_SCREEN_LOCKED,
141 keyguard.isKeyguardLocked() ? 1 : 0));
142 }
143
144 public void writeMetricsForExit() {
Leo Hsuaeb32d82018-12-25 16:01:27 +0800145 if (!mIsShortcutViewEnabled) {
146 return;
147 }
148
Shaotang Li8662a912018-07-04 16:53:01 +0800149 long userStayDuration = SystemClock.elapsedRealtime() - mUserEnterTimeMillis;
150 mMetricsLogger.write(new LogMaker(MetricsEvent.EMERGENCY_DIALER)
151 .setType(MetricsEvent.TYPE_CLOSE)
Leo Hsue3512b62019-02-14 15:53:00 +0800152 .setSubtype(mEntryType)
Shaotang Li8662a912018-07-04 16:53:01 +0800153 .addTaggedData(MetricsEvent.FIELD_EMERGENCY_DIALER_USER_ACTIONS, mUserActions)
154 .addTaggedData(
155 MetricsEvent.FIELD_EMERGENCY_DIALER_DURATION_MS, userStayDuration));
156 }
157
158 public void writeMetricsForMakingCall(int callSource, int phoneNumberType,
159 boolean hasShortcut) {
Leo Hsuaeb32d82018-12-25 16:01:27 +0800160 if (!mIsShortcutViewEnabled) {
161 return;
162 }
163
Shaotang Li8662a912018-07-04 16:53:01 +0800164 mMetricsLogger.write(new LogMaker(MetricsEvent.EMERGENCY_DIALER_MAKE_CALL)
165 .setType(MetricsEvent.TYPE_ACTION)
166 .setSubtype(callSource)
167 .addTaggedData(MetricsEvent.FIELD_EMERGENCY_DIALER_PHONE_NUMBER_TYPE,
168 phoneNumberType)
169 .addTaggedData(MetricsEvent.FIELD_EMERGENCY_DIALER_PHONE_NUMBER_HAS_SHORTCUT,
170 hasShortcut ? 1 : 0)
171 .addTaggedData(MetricsEvent.FIELD_EMERGENCY_DIALER_IN_POCKET,
172 mIsProximityNear ? 1 : 0));
173 }
174 }
175
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176 // Keys used with onSaveInstanceState().
177 private static final String LAST_NUMBER = "lastNumber";
178
179 // Intent action for this activity.
180 public static final String ACTION_DIAL = "com.android.phone.EmergencyDialer.DIAL";
181
Shaotang Li8662a912018-07-04 16:53:01 +0800182 /**
183 * Extra included in {@link #ACTION_DIAL} to indicate the entry type that user starts
184 * the emergency dialer.
185 */
186 public static final String EXTRA_ENTRY_TYPE =
187 "com.android.phone.EmergencyDialer.extra.ENTRY_TYPE";
188
Leo Hsue3512b62019-02-14 15:53:00 +0800189 // Constants indicating the entry type that user opened emergency dialer.
190 // This info is sent from system UI with EXTRA_ENTRY_TYPE. Please make them being
191 // in sync with those in com.android.systemui.util.EmergencyDialerConstants.
192 public static final int ENTRY_TYPE_UNKNOWN = 0;
193 public static final int ENTRY_TYPE_LOCKSCREEN_BUTTON = 1;
194 public static final int ENTRY_TYPE_POWER_MENU = 2;
195
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196 // List of dialer button IDs.
Leo Hsu83ab2332018-12-18 15:20:45 +0800197 private static final int[] DIALER_KEYS = new int[]{
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198 R.id.one, R.id.two, R.id.three,
199 R.id.four, R.id.five, R.id.six,
200 R.id.seven, R.id.eight, R.id.nine,
Leo Hsu83ab2332018-12-18 15:20:45 +0800201 R.id.star, R.id.zero, R.id.pound};
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202
203 // Debug constants.
204 private static final boolean DBG = false;
205 private static final String LOG_TAG = "EmergencyDialer";
206
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207 /** The length of DTMF tones in milliseconds */
208 private static final int TONE_LENGTH_MS = 150;
209
210 /** The DTMF tone volume relative to other sounds in the stream */
211 private static final int TONE_RELATIVE_VOLUME = 80;
212
213 /** Stream type used to play the DTMF tones off call, and mapped to the volume control keys */
214 private static final int DIAL_TONE_STREAM_TYPE = AudioManager.STREAM_DTMF;
215
216 private static final int BAD_EMERGENCY_NUMBER_DIALOG = 0;
217
Lucas Dupineb9c5702017-05-10 16:57:09 -0700218 /** 90% opacity, different from other gradients **/
219 private static final int BACKGROUND_GRADIENT_ALPHA = 230;
220
Chihhang Chuangf8d33002018-07-02 11:08:50 +0800221 /** 85% opacity for black background **/
222 private static final int BLACK_BACKGROUND_GRADIENT_ALPHA = 217;
223
CY Cheng9a69c182018-06-15 21:20:10 +0800224 /** Size limit of emergency shortcut buttons container. **/
225 private static final int SHORTCUT_SIZE_LIMIT = 3;
226
Tyler Gunnc5428972018-03-28 14:15:34 -0700227 ResizingTextEditText mDigits;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228 private View mDialButton;
229 private View mDelete;
Chihhang Chuangf264cfb2018-06-05 15:29:06 +0800230 private View mEmergencyShortcutView;
231 private View mDialpadView;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232
Leo Hsu43d670a2018-12-04 15:40:36 +0800233 private ShortcutViewUtils.PhoneInfo mPhoneInfo;
CY Cheng9a69c182018-06-15 21:20:10 +0800234
Chihhang Chuang92cfe512018-06-07 16:25:27 +0800235 private List<EmergencyShortcutButton> mEmergencyShortcutButtonList;
CY Cheng9a69c182018-06-15 21:20:10 +0800236 private EccShortcutAdapter mShortcutAdapter;
237 private DataSetObserver mShortcutDataSetObserver = null;
Chihhang Chuang92cfe512018-06-07 16:25:27 +0800238
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239 private ToneGenerator mToneGenerator;
240 private Object mToneGeneratorLock = new Object();
241
242 // determines if we want to playback local DTMF tones.
243 private boolean mDTMFToneEnabled;
244
Adrian Roos1c4b47f2015-04-13 14:53:32 -0700245 private EmergencyActionGroup mEmergencyActionGroup;
246
Wesley.CW Wang5e785392018-08-09 20:11:34 +0800247 private EmergencyInfoGroup mEmergencyInfoGroup;
248
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249 // close activity when screen turns off
250 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
251 @Override
252 public void onReceive(Context context, Intent intent) {
253 if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
Adrian Roos061c7232015-04-21 12:37:07 -0700254 finishAndRemoveTask();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255 }
256 }
257 };
258
Chihhang Chuangcaba0da2018-08-02 22:25:06 +0800259 /**
260 * Customize accessibility methods in View.
261 */
262 private AccessibilityDelegate mAccessibilityDelegate = new AccessibilityDelegate() {
263
264 /**
265 * Stop AccessiblityService from reading the title of a hidden View.
266 *
267 * <p>The crossfade animation will set the visibility of fade out view to {@link View.GONE}
268 * in the animation end. The view with an accessibility pane title would call the
269 * {@link AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED} event, which would trigger the
270 * accessibility service to read the pane title of fade out view instead of pane title of
271 * fade in view. So it need to filter out the event called by vanished pane.
272 */
273 @Override
274 public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
275 if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
276 && host.getVisibility() == View.GONE) {
277 return;
278 }
279 super.onPopulateAccessibilityEvent(host, event);
280 }
281 };
282
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283 private String mLastNumber; // last number we tried to dial. Used to restore error dialog.
284
Lucas Dupineb9c5702017-05-10 16:57:09 -0700285 // Background gradient
286 private ColorExtractor mColorExtractor;
287 private GradientDrawable mBackgroundGradient;
288 private boolean mSupportsDarkText;
289
Tyler Gunnc5428972018-03-28 14:15:34 -0700290 private boolean mIsWfcEmergencyCallingWarningEnabled;
291 private float mDefaultDigitsTextSize;
292
Leo Hsue3512b62019-02-14 15:53:00 +0800293 private int mEntryType;
Leo Hsu83ab2332018-12-18 15:20:45 +0800294 private boolean mIsShortcutViewEnabled;
Chihhang Chuangf264cfb2018-06-05 15:29:06 +0800295
Shaotang Li8662a912018-07-04 16:53:01 +0800296 private MetricsWriter mMetricsWriter;
297 private SensorManager mSensorManager;
298 private Sensor mProximitySensor;
299 private boolean mIsProximityNear = false;
300
301 /**
302 * The time, in millis, since boot when user opened emergency dialer.
303 * This is used when calculating the user stay duration for metrics data.
304 */
305 private long mUserEnterTimeMillis = 0;
306
307 /**
308 * Bit flag indicating the actions performed by user. This is used for metrics data.
309 */
310 private int mUserActions = MetricsWriter.USER_ACTION_NONE;
311
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312 @Override
313 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
314 // Do nothing
315 }
316
317 @Override
318 public void onTextChanged(CharSequence input, int start, int before, int changeCount) {
Tyler Gunnc5428972018-03-28 14:15:34 -0700319 maybeChangeHintSize();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700320 }
321
322 @Override
323 public void afterTextChanged(Editable input) {
324 // Check for special sequences, in particular the "**04" or "**05"
325 // sequences that allow you to enter PIN or PUK-related codes.
326 //
327 // But note we *don't* allow most other special sequences here,
328 // like "secret codes" (*#*#<code>#*#*) or IMEI display ("*#06#"),
329 // since those shouldn't be available if the device is locked.
330 //
331 // So we call SpecialCharSequenceMgr.handleCharsForLockedDevice()
332 // here, not the regular handleChars() method.
333 if (SpecialCharSequenceMgr.handleCharsForLockedDevice(this, input.toString(), this)) {
334 // A special sequence was entered, clear the digits
335 mDigits.getText().clear();
336 }
337
338 updateDialAndDeleteButtonStateEnabledAttr();
Ihab Awadf7c1a5a2014-12-08 19:24:23 -0800339 updateTtsSpans();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340 }
341
342 @Override
343 protected void onCreate(Bundle icicle) {
344 super.onCreate(icicle);
345
Leo Hsue3512b62019-02-14 15:53:00 +0800346 mEntryType = getIntent().getIntExtra(EXTRA_ENTRY_TYPE, ENTRY_TYPE_UNKNOWN);
347 Log.d(LOG_TAG, "Launched from " + entryTypeToString(mEntryType));
348
Shaotang Li8662a912018-07-04 16:53:01 +0800349 mMetricsWriter = new MetricsWriter();
350 mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
351 if (mSensorManager != null) {
352 mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
353 }
354
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 // Allow this activity to be displayed in front of the keyguard / lockscreen.
Mengjun Lengb9d14f02017-10-31 14:28:14 +0800356 setShowWhenLocked(true);
357 // Allow turning screen on
358 setTurnScreenOn(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359
Chuck Liaocdeebb42018-10-30 12:07:18 +0800360 CarrierConfigManager configMgr = getSystemService(CarrierConfigManager.class);
361 PersistableBundle carrierConfig =
362 configMgr.getConfigForSubId(SubscriptionManager.getDefaultVoiceSubscriptionId());
363
Leo Hsu83ab2332018-12-18 15:20:45 +0800364 mIsShortcutViewEnabled = false;
Leo Hsu43d670a2018-12-04 15:40:36 +0800365 mPhoneInfo = null;
Leo Hsu83ab2332018-12-18 15:20:45 +0800366 if (canEnableShortcutView(carrierConfig)) {
Leo Hsu43d670a2018-12-04 15:40:36 +0800367 mPhoneInfo = ShortcutViewUtils.pickPreferredPhone(this);
368 if (mPhoneInfo != null) {
Leo Hsu83ab2332018-12-18 15:20:45 +0800369 mIsShortcutViewEnabled = true;
Leo Hsu233f5b32018-11-07 11:08:03 +0800370 }
Chuck Liaocdeebb42018-10-30 12:07:18 +0800371 }
CY Cheng9a69c182018-06-15 21:20:10 +0800372 Log.d(LOG_TAG, "Enable emergency dialer shortcut: "
Leo Hsu83ab2332018-12-18 15:20:45 +0800373 + mIsShortcutViewEnabled);
Chihhang Chuangf8d33002018-07-02 11:08:50 +0800374
Lucas Dupineb9c5702017-05-10 16:57:09 -0700375 mColorExtractor = new ColorExtractor(this);
Chihhang Chuangf8d33002018-07-02 11:08:50 +0800376
Leo Hsu83ab2332018-12-18 15:20:45 +0800377 if (mIsShortcutViewEnabled) {
378 // Shortcut view doesn't support dark text theme.
Chihhang Chuangf8d33002018-07-02 11:08:50 +0800379 updateTheme(false);
380 } else {
381 GradientColors lockScreenColors = mColorExtractor.getColors(WallpaperManager.FLAG_LOCK,
382 ColorExtractor.TYPE_EXTRA_DARK);
383 updateTheme(lockScreenColors.supportsDarkText());
384 }
Lucas Dupineb9c5702017-05-10 16:57:09 -0700385
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 setContentView(R.layout.emergency_dialer);
387
Tyler Gunnc5428972018-03-28 14:15:34 -0700388 mDigits = (ResizingTextEditText) findViewById(R.id.digits);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389 mDigits.setKeyListener(DialerKeyListener.getInstance());
390 mDigits.setOnClickListener(this);
391 mDigits.setOnKeyListener(this);
392 mDigits.setLongClickable(false);
Hall Liubdc9c882016-05-25 15:25:28 -0700393 mDigits.setInputType(InputType.TYPE_NULL);
Tyler Gunnc5428972018-03-28 14:15:34 -0700394 mDefaultDigitsTextSize = mDigits.getScaledTextSize();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 maybeAddNumberFormatting();
396
Lucas Dupineb9c5702017-05-10 16:57:09 -0700397 mBackgroundGradient = new GradientDrawable(this);
398 Point displaySize = new Point();
399 ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
400 .getDefaultDisplay().getSize(displaySize);
401 mBackgroundGradient.setScreenSize(displaySize.x, displaySize.y);
Leo Hsu83ab2332018-12-18 15:20:45 +0800402 mBackgroundGradient.setAlpha(mIsShortcutViewEnabled
Chihhang Chuangf8d33002018-07-02 11:08:50 +0800403 ? BLACK_BACKGROUND_GRADIENT_ALPHA : BACKGROUND_GRADIENT_ALPHA);
Lucas Dupineb9c5702017-05-10 16:57:09 -0700404 getWindow().setBackgroundDrawable(mBackgroundGradient);
405
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 // Check for the presence of the keypad
407 View view = findViewById(R.id.one);
408 if (view != null) {
409 setupKeypad();
410 }
411
412 mDelete = findViewById(R.id.deleteButton);
413 mDelete.setOnClickListener(this);
414 mDelete.setOnLongClickListener(this);
415
Sai Cheemalapati14462b62014-06-18 13:53:56 -0700416 mDialButton = findViewById(R.id.floating_action_button);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
418 // Check whether we should show the onscreen "Dial" button and co.
Jonathan Basserie619a4c2015-06-26 14:52:26 -0700419 // Read carrier config through the public API because PhoneGlobals is not available when we
420 // run as a secondary user.
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700421 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_ONSCREEN_DIAL_BUTTON_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 mDialButton.setOnClickListener(this);
423 } else {
424 mDialButton.setVisibility(View.GONE);
425 }
Tyler Gunnc5428972018-03-28 14:15:34 -0700426 mIsWfcEmergencyCallingWarningEnabled = carrierConfig.getInt(
427 CarrierConfigManager.KEY_EMERGENCY_NOTIFICATION_DELAY_INT) > -1;
428 maybeShowWfcEmergencyCallingWarning();
429
Adrian Roosc9fdb6c2015-05-25 15:10:21 -0700430 ViewUtil.setupFloatingActionButton(mDialButton, getResources());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431
432 if (icicle != null) {
433 super.onRestoreInstanceState(icicle);
434 }
435
436 // Extract phone number from intent
437 Uri data = getIntent().getData();
Jay Shrauner137458b2014-09-05 14:27:25 -0700438 if (data != null && (PhoneAccount.SCHEME_TEL.equals(data.getScheme()))) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 String number = PhoneNumberUtils.getNumberFromIntent(getIntent(), this);
440 if (number != null) {
441 mDigits.setText(number);
442 }
443 }
444
445 // if the mToneGenerator creation fails, just continue without it. It is
446 // a local audio signal, and is not as important as the dtmf tone itself.
447 synchronized (mToneGeneratorLock) {
448 if (mToneGenerator == null) {
449 try {
450 mToneGenerator = new ToneGenerator(DIAL_TONE_STREAM_TYPE, TONE_RELATIVE_VOLUME);
451 } catch (RuntimeException e) {
452 Log.w(LOG_TAG, "Exception caught while creating local tone generator: " + e);
453 mToneGenerator = null;
454 }
455 }
456 }
457
458 final IntentFilter intentFilter = new IntentFilter();
459 intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
460 registerReceiver(mBroadcastReceiver, intentFilter);
461
Adrian Roos1c4b47f2015-04-13 14:53:32 -0700462 mEmergencyActionGroup = (EmergencyActionGroup) findViewById(R.id.emergency_action_group);
Chihhang Chuangf264cfb2018-06-05 15:29:06 +0800463
Wesley.CW Wang5e785392018-08-09 20:11:34 +0800464 mEmergencyInfoGroup = (EmergencyInfoGroup) findViewById(R.id.emergency_info_button);
465
Leo Hsu83ab2332018-12-18 15:20:45 +0800466 if (mIsShortcutViewEnabled) {
Chihhang Chuangf264cfb2018-06-05 15:29:06 +0800467 setupEmergencyShortcutsView();
468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 }
470
471 @Override
472 protected void onDestroy() {
473 super.onDestroy();
474 synchronized (mToneGeneratorLock) {
475 if (mToneGenerator != null) {
476 mToneGenerator.release();
477 mToneGenerator = null;
478 }
479 }
480 unregisterReceiver(mBroadcastReceiver);
CY Cheng9a69c182018-06-15 21:20:10 +0800481 if (mShortcutAdapter != null && mShortcutDataSetObserver != null) {
482 mShortcutAdapter.unregisterDataSetObserver(mShortcutDataSetObserver);
483 mShortcutDataSetObserver = null;
484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485 }
486
487 @Override
488 protected void onRestoreInstanceState(Bundle icicle) {
489 mLastNumber = icicle.getString(LAST_NUMBER);
490 }
491
492 @Override
493 protected void onSaveInstanceState(Bundle outState) {
494 super.onSaveInstanceState(outState);
495 outState.putString(LAST_NUMBER, mLastNumber);
496 }
497
498 /**
499 * Explicitly turn off number formatting, since it gets in the way of the emergency
500 * number detector
501 */
502 protected void maybeAddNumberFormatting() {
503 // Do nothing.
504 }
505
506 @Override
507 protected void onPostCreate(Bundle savedInstanceState) {
508 super.onPostCreate(savedInstanceState);
509
510 // This can't be done in onCreate(), since the auto-restoring of the digits
511 // will play DTMF tones for all the old digits if it is when onRestoreSavedInstanceState()
512 // is called. This method will be called every time the activity is created, and
513 // will always happen after onRestoreSavedInstanceState().
514 mDigits.addTextChangedListener(this);
515 }
516
517 private void setupKeypad() {
518 // Setup the listeners for the buttons
519 for (int id : DIALER_KEYS) {
Yorke Lee23a70732014-08-14 17:12:01 -0700520 final DialpadKeyButton key = (DialpadKeyButton) findViewById(id);
521 key.setOnPressedListener(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700522 }
523
524 View view = findViewById(R.id.zero);
525 view.setOnLongClickListener(this);
526 }
527
Chihhang Chuangf264cfb2018-06-05 15:29:06 +0800528 @Override
529 public void onBackPressed() {
Leo Hsu83ab2332018-12-18 15:20:45 +0800530 // If shortcut view is enabled and Dialpad view is visible, pressing the back key will
531 // back to display EmergencyShortcutView view. Otherwise, it would finish the activity.
532 if (mIsShortcutViewEnabled && mDialpadView != null
Chihhang Chuangf264cfb2018-06-05 15:29:06 +0800533 && mDialpadView.getVisibility() == View.VISIBLE) {
534 switchView(mEmergencyShortcutView, mDialpadView, true);
535 return;
536 }
537 super.onBackPressed();
538 }
539
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 /**
541 * handle key events
542 */
543 @Override
544 public boolean onKeyDown(int keyCode, KeyEvent event) {
545 switch (keyCode) {
546 // Happen when there's a "Call" hard button.
547 case KeyEvent.KEYCODE_CALL: {
548 if (TextUtils.isEmpty(mDigits.getText().toString())) {
549 // if we are adding a call from the InCallScreen and the phone
550 // number entered is empty, we just close the dialer to expose
551 // the InCallScreen under it.
552 finish();
553 } else {
554 // otherwise, we place the call.
555 placeCall();
556 }
557 return true;
558 }
559 }
560 return super.onKeyDown(keyCode, event);
561 }
562
563 private void keyPressed(int keyCode) {
Yorke Lee116dd072015-08-31 11:38:39 -0700564 mDigits.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700565 KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
566 mDigits.onKeyDown(keyCode, event);
567 }
568
569 @Override
570 public boolean onKey(View view, int keyCode, KeyEvent event) {
571 switch (view.getId()) {
572 case R.id.digits:
573 // Happen when "Done" button of the IME is pressed. This can happen when this
574 // Activity is forced into landscape mode due to a desk dock.
575 if (keyCode == KeyEvent.KEYCODE_ENTER
576 && event.getAction() == KeyEvent.ACTION_UP) {
577 placeCall();
578 return true;
579 }
580 break;
581 }
582 return false;
583 }
584
585 @Override
Adrian Roos1c4b47f2015-04-13 14:53:32 -0700586 public boolean dispatchTouchEvent(MotionEvent ev) {
Chihhang Chuang92cfe512018-06-07 16:25:27 +0800587 onPreTouchEvent(ev);
Adrian Roos1c4b47f2015-04-13 14:53:32 -0700588 boolean handled = super.dispatchTouchEvent(ev);
Chihhang Chuang92cfe512018-06-07 16:25:27 +0800589 onPostTouchEvent(ev);
Adrian Roos1c4b47f2015-04-13 14:53:32 -0700590 return handled;
591 }
592
593 @Override
Chihhang Chuang92cfe512018-06-07 16:25:27 +0800594 public void onConfirmClick(EmergencyShortcutButton button) {
595 if (button == null) return;
596
Shaotang Li8662a912018-07-04 16:53:01 +0800597 mUserActions |= MetricsWriter.USER_ACTION_MAKE_CALL_VIA_SHORTCUT;
598
599 // We interest on the context when user has intention to make phone call,
600 // so write metrics here for shortcut number even the call may not be created.
601 mMetricsWriter.writeMetricsForMakingCall(MetricsWriter.CALL_SOURCE_SHORTCUT,
602 MetricsWriter.PHONE_NUMBER_TYPE_EMERGENCY, true);
603
Chihhang Chuang92cfe512018-06-07 16:25:27 +0800604 String phoneNumber = button.getPhoneNumber();
605
606 if (!TextUtils.isEmpty(phoneNumber)) {
Billy Chi17ec2282018-06-15 19:00:15 +0800607 if (DBG) Log.d(LOG_TAG, "dial emergency number: " + Rlog.pii(LOG_TAG, phoneNumber));
Leo Hsu43d670a2018-12-04 15:40:36 +0800608 placeCall(phoneNumber, ParcelableCallAnalytics.CALL_SOURCE_EMERGENCY_SHORTCUT,
609 mPhoneInfo);
Chihhang Chuang92cfe512018-06-07 16:25:27 +0800610 } else {
611 Log.d(LOG_TAG, "emergency number is empty");
612 }
613 }
614
615 @Override
Wesley.CW Wang5e785392018-08-09 20:11:34 +0800616 public void onConfirmClick(EmergencyInfoGroup button) {
617 if (button == null) return;
618
619 mUserActions |= MetricsWriter.USER_ACTION_OPEN_EMERGENCY_INFO;
620 Intent intent = (Intent) button.getTag(R.id.tag_intent);
621 if (intent != null) {
622 startActivity(intent);
623 }
624 }
625
626 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700627 public void onClick(View view) {
628 switch (view.getId()) {
Yorke Lee23a70732014-08-14 17:12:01 -0700629 case R.id.deleteButton: {
630 keyPressed(KeyEvent.KEYCODE_DEL);
631 return;
632 }
633 case R.id.floating_action_button: {
Yorke Lee116dd072015-08-31 11:38:39 -0700634 view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Yorke Lee23a70732014-08-14 17:12:01 -0700635 placeCall();
636 return;
637 }
638 case R.id.digits: {
639 if (mDigits.length() != 0) {
640 mDigits.setCursorVisible(true);
641 }
642 return;
643 }
Chihhang Chuangf264cfb2018-06-05 15:29:06 +0800644 case R.id.floating_action_button_dialpad: {
Shaotang Li8662a912018-07-04 16:53:01 +0800645 mUserActions |= MetricsWriter.USER_ACTION_OPEN_DIALPAD;
Chihhang Chuangf8d33002018-07-02 11:08:50 +0800646 mDigits.getText().clear();
Chihhang Chuangf264cfb2018-06-05 15:29:06 +0800647 switchView(mDialpadView, mEmergencyShortcutView, true);
648 return;
649 }
Yorke Lee23a70732014-08-14 17:12:01 -0700650 }
651 }
652
653 @Override
654 public void onPressed(View view, boolean pressed) {
655 if (!pressed) {
656 return;
657 }
658 switch (view.getId()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700659 case R.id.one: {
660 playTone(ToneGenerator.TONE_DTMF_1);
661 keyPressed(KeyEvent.KEYCODE_1);
662 return;
663 }
664 case R.id.two: {
665 playTone(ToneGenerator.TONE_DTMF_2);
666 keyPressed(KeyEvent.KEYCODE_2);
667 return;
668 }
669 case R.id.three: {
670 playTone(ToneGenerator.TONE_DTMF_3);
671 keyPressed(KeyEvent.KEYCODE_3);
672 return;
673 }
674 case R.id.four: {
675 playTone(ToneGenerator.TONE_DTMF_4);
676 keyPressed(KeyEvent.KEYCODE_4);
677 return;
678 }
679 case R.id.five: {
680 playTone(ToneGenerator.TONE_DTMF_5);
681 keyPressed(KeyEvent.KEYCODE_5);
682 return;
683 }
684 case R.id.six: {
685 playTone(ToneGenerator.TONE_DTMF_6);
686 keyPressed(KeyEvent.KEYCODE_6);
687 return;
688 }
689 case R.id.seven: {
690 playTone(ToneGenerator.TONE_DTMF_7);
691 keyPressed(KeyEvent.KEYCODE_7);
692 return;
693 }
694 case R.id.eight: {
695 playTone(ToneGenerator.TONE_DTMF_8);
696 keyPressed(KeyEvent.KEYCODE_8);
697 return;
698 }
699 case R.id.nine: {
700 playTone(ToneGenerator.TONE_DTMF_9);
701 keyPressed(KeyEvent.KEYCODE_9);
702 return;
703 }
704 case R.id.zero: {
705 playTone(ToneGenerator.TONE_DTMF_0);
706 keyPressed(KeyEvent.KEYCODE_0);
707 return;
708 }
709 case R.id.pound: {
710 playTone(ToneGenerator.TONE_DTMF_P);
711 keyPressed(KeyEvent.KEYCODE_POUND);
712 return;
713 }
714 case R.id.star: {
715 playTone(ToneGenerator.TONE_DTMF_S);
716 keyPressed(KeyEvent.KEYCODE_STAR);
717 return;
718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700719 }
720 }
721
722 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700723 * called for long touch events
724 */
725 @Override
726 public boolean onLongClick(View view) {
727 int id = view.getId();
728 switch (id) {
729 case R.id.deleteButton: {
730 mDigits.getText().clear();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700731 return true;
732 }
733 case R.id.zero: {
Yorke Lee91311662014-10-24 14:50:45 -0700734 removePreviousDigitIfPossible();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700735 keyPressed(KeyEvent.KEYCODE_PLUS);
736 return true;
737 }
738 }
739 return false;
740 }
741
742 @Override
Lucas Dupineb9c5702017-05-10 16:57:09 -0700743 protected void onStart() {
744 super.onStart();
Shaotang Li8662a912018-07-04 16:53:01 +0800745
746 mUserEnterTimeMillis = SystemClock.elapsedRealtime();
747 mUserActions = MetricsWriter.USER_ACTION_NONE;
748 mMetricsWriter.writeMetricsForEnter();
749
Leo Hsu83ab2332018-12-18 15:20:45 +0800750 if (mIsShortcutViewEnabled) {
751 // Shortcut view doesn't support dark text theme.
Chihhang Chuangf8d33002018-07-02 11:08:50 +0800752 mBackgroundGradient.setColors(Color.BLACK, Color.BLACK, false);
753 updateTheme(false);
754 } else {
755 mColorExtractor.addOnColorsChangedListener(this);
756 GradientColors lockScreenColors = mColorExtractor.getColors(WallpaperManager.FLAG_LOCK,
757 ColorExtractor.TYPE_EXTRA_DARK);
758 // Do not animate when view isn't visible yet, just set an initial state.
759 mBackgroundGradient.setColors(lockScreenColors, false);
760 updateTheme(lockScreenColors.supportsDarkText());
761 }
CY Cheng9a69c182018-06-15 21:20:10 +0800762
Leo Hsu43d670a2018-12-04 15:40:36 +0800763 if (mIsShortcutViewEnabled) {
764 mPhoneInfo = ShortcutViewUtils.pickPreferredPhone(this);
765 updateLocationAndEccInfo();
CY Cheng9a69c182018-06-15 21:20:10 +0800766 }
Lucas Dupineb9c5702017-05-10 16:57:09 -0700767 }
768
769 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700770 protected void onResume() {
771 super.onResume();
772
Shaotang Li8662a912018-07-04 16:53:01 +0800773 if (mProximitySensor != null) {
774 mSensorManager.registerListener(
775 this, mProximitySensor, SensorManager.SENSOR_DELAY_NORMAL);
776 }
777
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700778 // retrieve the DTMF tone play back setting.
779 mDTMFToneEnabled = Settings.System.getInt(getContentResolver(),
780 Settings.System.DTMF_TONE_WHEN_DIALING, 1) == 1;
781
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700782 // if the mToneGenerator creation fails, just continue without it. It is
783 // a local audio signal, and is not as important as the dtmf tone itself.
784 synchronized (mToneGeneratorLock) {
785 if (mToneGenerator == null) {
786 try {
787 mToneGenerator = new ToneGenerator(AudioManager.STREAM_DTMF,
788 TONE_RELATIVE_VOLUME);
789 } catch (RuntimeException e) {
790 Log.w(LOG_TAG, "Exception caught while creating local tone generator: " + e);
791 mToneGenerator = null;
792 }
793 }
794 }
795
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700796 updateDialAndDeleteButtonStateEnabledAttr();
797 }
798
799 @Override
800 public void onPause() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700801 super.onPause();
Shaotang Li8662a912018-07-04 16:53:01 +0800802 if (mProximitySensor != null) {
803 mSensorManager.unregisterListener(this, mProximitySensor);
804 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700805 }
806
Lucas Dupineb9c5702017-05-10 16:57:09 -0700807 @Override
808 protected void onStop() {
809 super.onStop();
Shaotang Li8662a912018-07-04 16:53:01 +0800810 mMetricsWriter.writeMetricsForExit();
Lucas Dupineb9c5702017-05-10 16:57:09 -0700811 mColorExtractor.removeOnColorsChangedListener(this);
812 }
813
Leo Hsu83ab2332018-12-18 15:20:45 +0800814 private boolean canEnableShortcutView(PersistableBundle carrierConfig) {
Leo Hsue3512b62019-02-14 15:53:00 +0800815 if (mEntryType != ENTRY_TYPE_POWER_MENU) {
816 Log.d(LOG_TAG, "Disables shortcut view since it's not launched from power menu");
817 return false;
818 }
Leo Hsu83ab2332018-12-18 15:20:45 +0800819 if (!carrierConfig.getBoolean(
820 CarrierConfigManager.KEY_SUPPORT_EMERGENCY_DIALER_SHORTCUT_BOOL)) {
821 Log.d(LOG_TAG, "Disables shortcut view by carrier requirement");
822 return false;
823 }
824 return true;
825 }
826
Lucas Dupineb9c5702017-05-10 16:57:09 -0700827 /**
828 * Sets theme based on gradient colors
Leo Hsu83ab2332018-12-18 15:20:45 +0800829 *
Lucas Dupineb9c5702017-05-10 16:57:09 -0700830 * @param supportsDarkText true if gradient supports dark text
831 */
832 private void updateTheme(boolean supportsDarkText) {
833 if (mSupportsDarkText == supportsDarkText) {
834 return;
835 }
836 mSupportsDarkText = supportsDarkText;
837
838 // We can't change themes after inflation, in this case we'll have to recreate
839 // the whole activity.
840 if (mBackgroundGradient != null) {
841 recreate();
842 return;
843 }
844
845 int vis = getWindow().getDecorView().getSystemUiVisibility();
846 if (supportsDarkText) {
847 vis |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
848 vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
849 setTheme(R.style.EmergencyDialerThemeDark);
850 } else {
851 vis &= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
852 vis &= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
853 setTheme(R.style.EmergencyDialerTheme);
854 }
855 getWindow().getDecorView().setSystemUiVisibility(vis);
856 }
857
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700858 /**
859 * place the call, but check to make sure it is a viable number.
860 */
861 private void placeCall() {
Shaotang Li8662a912018-07-04 16:53:01 +0800862 mUserActions |= MetricsWriter.USER_ACTION_MAKE_CALL_VIA_DIALPAD;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700863 mLastNumber = mDigits.getText().toString();
Wei Huang6904b142017-04-21 19:06:40 +0900864
865 // Convert into emergency number according to emergency conversion map.
866 // If conversion map is not defined (this is default), this method does
867 // nothing and just returns input number.
868 mLastNumber = PhoneNumberUtils.convertToEmergencyNumber(this, mLastNumber);
869
Leo Hsu43d670a2018-12-04 15:40:36 +0800870 boolean isEmergencyNumber = false;
871 ShortcutViewUtils.PhoneInfo phoneToMakeCall = null;
872 if (mPhoneInfo != null) {
873 isEmergencyNumber = mPhoneInfo.hasPromotedEmergencyNumber(mLastNumber);
874 if (isEmergencyNumber) {
875 phoneToMakeCall = mPhoneInfo;
876 }
877 }
878 if (!isEmergencyNumber) {
879 TelephonyManager tm = getSystemService(TelephonyManager.class);
880 isEmergencyNumber = tm.isCurrentEmergencyNumber(mLastNumber);
881 }
882
883 if (isEmergencyNumber) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700884 if (DBG) Log.d(LOG_TAG, "placing call to " + mLastNumber);
885
886 // place the call if it is a valid number
887 if (mLastNumber == null || !TextUtils.isGraphic(mLastNumber)) {
888 // There is no number entered.
889 playTone(ToneGenerator.TONE_PROP_NACK);
890 return;
891 }
Shaotang Li8662a912018-07-04 16:53:01 +0800892
893 mMetricsWriter.writeMetricsForMakingCall(MetricsWriter.CALL_SOURCE_DIALPAD,
894 MetricsWriter.PHONE_NUMBER_TYPE_EMERGENCY, isShortcutNumber(mLastNumber));
895
Leo Hsu43d670a2018-12-04 15:40:36 +0800896 placeCall(mLastNumber, ParcelableCallAnalytics.CALL_SOURCE_EMERGENCY_DIALPAD,
897 phoneToMakeCall);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700898 } else {
899 if (DBG) Log.d(LOG_TAG, "rejecting bad requested number " + mLastNumber);
900
Shaotang Li8662a912018-07-04 16:53:01 +0800901 // We interest on the context when user has intention to make phone call,
902 // so write metrics here for non-emergency numbers even these numbers are rejected.
903 mMetricsWriter.writeMetricsForMakingCall(MetricsWriter.CALL_SOURCE_DIALPAD,
904 MetricsWriter.PHONE_NUMBER_TYPE_GENERAL, false);
905
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700906 showDialog(BAD_EMERGENCY_NUMBER_DIALOG);
907 }
Yorke Lee9b341512014-10-17 11:36:41 -0700908 mDigits.getText().delete(0, mDigits.getText().length());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700909 }
910
Leo Hsu43d670a2018-12-04 15:40:36 +0800911 private void placeCall(String number, int callSource, ShortcutViewUtils.PhoneInfo phone) {
Leo Hsue3512b62019-02-14 15:53:00 +0800912 Log.d(LOG_TAG, "Place emergency call from " + callSourceToString(callSource)
913 + ", entry = " + entryTypeToString(mEntryType));
914
Leo Hsu43d670a2018-12-04 15:40:36 +0800915 Bundle extras = new Bundle();
916 extras.putInt(TelecomManager.EXTRA_CALL_SOURCE, callSource);
sqian756f6062019-02-08 21:47:14 -0800917 /**
918 * This is used for Telecom and Telephony to tell modem user's intent is emergency call,
919 * when the dialed number is ambiguous and identified as both emergency number and any
920 * other non-emergency number; e.g. in some situation, 611 could be both an emergency
921 * number in a country and a non-emergency number of a carrier's customer service hotline.
922 */
923 extras.putBoolean(TelecomManager.EXTRA_IS_USER_INTENT_EMERGENCY_CALL, true);
Leo Hsu43d670a2018-12-04 15:40:36 +0800924
925 if (phone != null && phone.getPhoneAccountHandle() != null) {
926 // Requests to dial through the specified phone.
927 extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE,
928 phone.getPhoneAccountHandle());
929 }
930
931 TelecomManager tm = this.getSystemService(TelecomManager.class);
932 tm.placeCall(Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null), extras);
933 }
934
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700935 /**
936 * Plays the specified tone for TONE_LENGTH_MS milliseconds.
937 *
938 * The tone is played locally, using the audio stream for phone calls.
939 * Tones are played only if the "Audible touch tones" user preference
940 * is checked, and are NOT played if the device is in silent mode.
941 *
942 * @param tone a tone code from {@link ToneGenerator}
943 */
944 void playTone(int tone) {
945 // if local tone playback is disabled, just return.
946 if (!mDTMFToneEnabled) {
947 return;
948 }
949
950 // Also do nothing if the phone is in silent mode.
951 // We need to re-check the ringer mode for *every* playTone()
952 // call, rather than keeping a local flag that's updated in
953 // onResume(), since it's possible to toggle silent mode without
954 // leaving the current activity (via the ENDCALL-longpress menu.)
955 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
956 int ringerMode = audioManager.getRingerMode();
957 if ((ringerMode == AudioManager.RINGER_MODE_SILENT)
Leo Hsu233f5b32018-11-07 11:08:03 +0800958 || (ringerMode == AudioManager.RINGER_MODE_VIBRATE)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700959 return;
960 }
961
962 synchronized (mToneGeneratorLock) {
963 if (mToneGenerator == null) {
964 Log.w(LOG_TAG, "playTone: mToneGenerator == null, tone: " + tone);
965 return;
966 }
967
968 // Start the new tone (will stop any playing tone)
969 mToneGenerator.startTone(tone, TONE_LENGTH_MS);
970 }
971 }
972
973 private CharSequence createErrorMessage(String number) {
974 if (!TextUtils.isEmpty(number)) {
Hall Liudc274312016-03-01 16:34:45 -0800975 String errorString = getString(R.string.dial_emergency_error, number);
976 int startingPosition = errorString.indexOf(number);
977 int endingPosition = startingPosition + number.length();
978 Spannable result = new SpannableString(errorString);
979 PhoneNumberUtils.addTtsSpan(result, startingPosition, endingPosition);
980 return result;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700981 } else {
982 return getText(R.string.dial_emergency_empty_error).toString();
983 }
984 }
985
986 @Override
987 protected Dialog onCreateDialog(int id) {
988 AlertDialog dialog = null;
989 if (id == BAD_EMERGENCY_NUMBER_DIALOG) {
990 // construct dialog
Lucas Dupin0d666f92017-06-01 14:04:48 -0700991 dialog = new AlertDialog.Builder(this, R.style.EmergencyDialerAlertDialogTheme)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700992 .setTitle(getText(R.string.emergency_enable_radio_dialog_title))
993 .setMessage(createErrorMessage(mLastNumber))
994 .setPositiveButton(R.string.ok, null)
995 .setCancelable(true).create();
996
997 // blur stuff behind the dialog
998 dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Tyler Gunncd6a1a92018-03-29 13:48:29 -0700999 setShowWhenLocked(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001000 }
1001 return dialog;
1002 }
1003
1004 @Override
1005 protected void onPrepareDialog(int id, Dialog dialog) {
1006 super.onPrepareDialog(id, dialog);
1007 if (id == BAD_EMERGENCY_NUMBER_DIALOG) {
1008 AlertDialog alert = (AlertDialog) dialog;
1009 alert.setMessage(createErrorMessage(mLastNumber));
1010 }
1011 }
1012
Andrew Leed5631e82014-10-08 16:03:58 -07001013 @Override
1014 public boolean onOptionsItemSelected(MenuItem item) {
1015 final int itemId = item.getItemId();
1016 if (itemId == android.R.id.home) {
1017 onBackPressed();
1018 return true;
1019 }
1020 return super.onOptionsItemSelected(item);
1021 }
1022
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001023 /**
1024 * Update the enabledness of the "Dial" and "Backspace" buttons if applicable.
1025 */
1026 private void updateDialAndDeleteButtonStateEnabledAttr() {
1027 final boolean notEmpty = mDigits.length() != 0;
1028
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001029 mDelete.setEnabled(notEmpty);
1030 }
Yorke Lee91311662014-10-24 14:50:45 -07001031
1032 /**
1033 * Remove the digit just before the current position. Used by various long pressed callbacks
1034 * to remove the digit that was populated as a result of the short click.
1035 */
1036 private void removePreviousDigitIfPossible() {
1037 final int currentPosition = mDigits.getSelectionStart();
1038 if (currentPosition > 0) {
1039 mDigits.setSelection(currentPosition);
1040 mDigits.getText().delete(currentPosition - 1, currentPosition);
1041 }
1042 }
Ihab Awadf7c1a5a2014-12-08 19:24:23 -08001043
1044 /**
1045 * Update the text-to-speech annotations in the edit field.
1046 */
1047 private void updateTtsSpans() {
1048 for (Object o : mDigits.getText().getSpans(0, mDigits.getText().length(), TtsSpan.class)) {
1049 mDigits.getText().removeSpan(o);
1050 }
1051 PhoneNumberUtils.ttsSpanAsPhoneNumber(mDigits.getText(), 0, mDigits.getText().length());
1052 }
Lucas Dupineb9c5702017-05-10 16:57:09 -07001053
1054 @Override
Lucas Dupin94b566f2017-05-28 11:45:52 -07001055 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupineb9c5702017-05-10 16:57:09 -07001056 if ((which & WallpaperManager.FLAG_LOCK) != 0) {
Lucas Dupin94b566f2017-05-28 11:45:52 -07001057 GradientColors colors = extractor.getColors(WallpaperManager.FLAG_LOCK,
1058 ColorExtractor.TYPE_EXTRA_DARK);
Lucas Dupineb9c5702017-05-10 16:57:09 -07001059 mBackgroundGradient.setColors(colors);
1060 updateTheme(colors.supportsDarkText());
1061 }
1062 }
Tyler Gunnc5428972018-03-28 14:15:34 -07001063
1064 /**
1065 * Where a carrier requires a warning that emergency calling is not available while on WFC,
1066 * add hint text above the dial pad which warns the user of this case.
1067 */
1068 private void maybeShowWfcEmergencyCallingWarning() {
1069 if (!mIsWfcEmergencyCallingWarningEnabled) {
1070 Log.i(LOG_TAG, "maybeShowWfcEmergencyCallingWarning: warning disabled by carrier.");
1071 return;
1072 }
1073
1074 // Use an async task rather than calling into Telephony on UI thread.
1075 AsyncTask<Void, Void, Boolean> showWfcWarningTask = new AsyncTask<Void, Void, Boolean>() {
1076 @Override
1077 protected Boolean doInBackground(Void... voids) {
Leo Hsu43d670a2018-12-04 15:40:36 +08001078 TelephonyManager tm = getSystemService(TelephonyManager.class);
Tyler Gunnc5428972018-03-28 14:15:34 -07001079 boolean isWfcAvailable = tm.isWifiCallingAvailable();
1080 ServiceState ss = tm.getServiceState();
1081 boolean isCellAvailable =
1082 ss.getRilVoiceRadioTechnology() != RIL_RADIO_TECHNOLOGY_UNKNOWN;
1083 Log.i(LOG_TAG, "showWfcWarningTask: isWfcAvailable=" + isWfcAvailable
Leo Hsu233f5b32018-11-07 11:08:03 +08001084 + " isCellAvailable=" + isCellAvailable
1085 + "(rat=" + ss.getRilVoiceRadioTechnology() + ")");
Tyler Gunnc5428972018-03-28 14:15:34 -07001086 return isWfcAvailable && !isCellAvailable;
1087 }
1088
1089 @Override
1090 protected void onPostExecute(Boolean result) {
1091 if (result.booleanValue()) {
1092 Log.i(LOG_TAG, "showWfcWarningTask: showing ecall warning");
1093 mDigits.setHint(R.string.dial_emergency_calling_not_available);
1094 } else {
1095 Log.i(LOG_TAG, "showWfcWarningTask: hiding ecall warning");
1096 mDigits.setHint("");
1097 }
1098 maybeChangeHintSize();
1099 }
1100 };
1101 showWfcWarningTask.execute((Void) null);
1102 }
1103
1104 /**
1105 * Where a hint is applied and there are no digits dialed, disable autoresize of the dial digits
1106 * edit view and set the font size to a smaller size appropriate for the emergency calling
1107 * warning.
1108 */
1109 private void maybeChangeHintSize() {
1110 if (TextUtils.isEmpty(mDigits.getHint())
1111 || !TextUtils.isEmpty(mDigits.getText().toString())) {
1112 // No hint or there are dialed digits, so use default size.
1113 mDigits.setTextSize(TypedValue.COMPLEX_UNIT_SP, mDefaultDigitsTextSize);
1114 // By default, the digits view auto-resizes to fit the text it contains, so
1115 // enable that now.
1116 mDigits.setResizeEnabled(true);
1117 Log.i(LOG_TAG, "no hint - setting to " + mDigits.getScaledTextSize());
1118 } else {
1119 // Hint present and no dialed digits, set custom font size appropriate for the warning.
1120 mDigits.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(
1121 R.dimen.emergency_call_warning_size));
1122 // Since we're populating this with a static text string, disable auto-resize.
1123 mDigits.setResizeEnabled(false);
1124 Log.i(LOG_TAG, "hint - setting to " + mDigits.getScaledTextSize());
1125 }
1126 }
Chihhang Chuangf264cfb2018-06-05 15:29:06 +08001127
1128 private void setupEmergencyShortcutsView() {
1129 mEmergencyShortcutView = findViewById(R.id.emergency_dialer_shortcuts);
1130 mDialpadView = findViewById(R.id.emergency_dialer);
1131
Chihhang Chuangcaba0da2018-08-02 22:25:06 +08001132 mEmergencyShortcutView.setAccessibilityDelegate(mAccessibilityDelegate);
1133 mDialpadView.setAccessibilityDelegate(mAccessibilityDelegate);
1134
Chihhang Chuangf264cfb2018-06-05 15:29:06 +08001135 final View dialpadButton = findViewById(R.id.floating_action_button_dialpad);
1136 dialpadButton.setOnClickListener(this);
1137
Wesley.CW Wang5e785392018-08-09 20:11:34 +08001138 mEmergencyInfoGroup.setOnConfirmClickListener(this);
Chihhang Chuangf264cfb2018-06-05 15:29:06 +08001139
1140 // EmergencyActionGroup is replaced by EmergencyInfoGroup.
1141 mEmergencyActionGroup.setVisibility(View.GONE);
1142
1143 // Setup dialpad title.
1144 final View emergencyDialpadTitle = findViewById(R.id.emergency_dialpad_title_container);
1145 emergencyDialpadTitle.setVisibility(View.VISIBLE);
1146
Chihhang Chuang92cfe512018-06-07 16:25:27 +08001147 mEmergencyShortcutButtonList = new ArrayList<>();
1148 setupEmergencyCallShortcutButton();
1149
Leo Hsu43d670a2018-12-04 15:40:36 +08001150 updateLocationAndEccInfo();
CY Cheng9a69c182018-06-15 21:20:10 +08001151
Chihhang Chuangf264cfb2018-06-05 15:29:06 +08001152 switchView(mEmergencyShortcutView, mDialpadView, false);
1153 }
1154
Leo Hsu43d670a2018-12-04 15:40:36 +08001155 private void setLocationInfo() {
Chihhang Chuang92cfe512018-06-07 16:25:27 +08001156 final View locationInfo = findViewById(R.id.location_info);
1157
Leo Hsu43d670a2018-12-04 15:40:36 +08001158 String countryIso = mPhoneInfo != null ? mPhoneInfo.getCountryIso() : null;
CY Cheng9a69c182018-06-15 21:20:10 +08001159 String countryName = null;
1160 if (!TextUtils.isEmpty(countryIso)) {
1161 Locale locale = Locale.getDefault();
1162 countryName = new Locale(locale.getLanguage(), countryIso, locale.getVariant())
1163 .getDisplayCountry();
1164 }
1165 if (TextUtils.isEmpty(countryName)) {
Chihhang Chuang92cfe512018-06-07 16:25:27 +08001166 locationInfo.setVisibility(View.INVISIBLE);
1167 } else {
1168 final TextView location = (TextView) locationInfo.findViewById(R.id.location_text);
CY Cheng9a69c182018-06-15 21:20:10 +08001169 location.setText(countryName);
Chihhang Chuang92cfe512018-06-07 16:25:27 +08001170 locationInfo.setVisibility(View.VISIBLE);
1171 }
1172 }
1173
Chihhang Chuang92cfe512018-06-07 16:25:27 +08001174 private void setupEmergencyCallShortcutButton() {
1175 final ViewGroup shortcutButtonContainer = findViewById(
1176 R.id.emergency_shortcut_buttons_container);
1177 shortcutButtonContainer.setClipToOutline(true);
CY Cheng9a69c182018-06-15 21:20:10 +08001178 final TextView emergencyNumberTitle = findViewById(R.id.emergency_number_title);
Chihhang Chuang92cfe512018-06-07 16:25:27 +08001179
CY Cheng9a69c182018-06-15 21:20:10 +08001180 mShortcutAdapter = new EccShortcutAdapter(this) {
1181 @Override
1182 public View inflateView(View convertView, ViewGroup parent, CharSequence number,
1183 CharSequence description, int iconRes) {
1184 EmergencyShortcutButton button = (EmergencyShortcutButton) getLayoutInflater()
1185 .inflate(R.layout.emergency_shortcut_button, parent, false);
1186 button.setPhoneNumber(number);
1187 button.setPhoneDescription(description);
1188 button.setPhoneTypeIcon(iconRes);
1189 button.setOnConfirmClickListener(EmergencyDialer.this);
1190 return button;
1191 }
1192 };
1193 mShortcutDataSetObserver = new DataSetObserver() {
1194 @Override
1195 public void onChanged() {
1196 super.onChanged();
1197 updateLayout();
1198 }
Chihhang Chuang92cfe512018-06-07 16:25:27 +08001199
CY Cheng9a69c182018-06-15 21:20:10 +08001200 @Override
1201 public void onInvalidated() {
1202 super.onInvalidated();
1203 updateLayout();
1204 }
Chihhang Chuang92cfe512018-06-07 16:25:27 +08001205
CY Cheng9a69c182018-06-15 21:20:10 +08001206 private void updateLayout() {
1207 // clear previous added buttons
1208 shortcutButtonContainer.removeAllViews();
1209 mEmergencyShortcutButtonList.clear();
Chihhang Chuang92cfe512018-06-07 16:25:27 +08001210
CY Cheng9a69c182018-06-15 21:20:10 +08001211 for (int i = 0; i < mShortcutAdapter.getCount() && i < SHORTCUT_SIZE_LIMIT; ++i) {
1212 EmergencyShortcutButton button = (EmergencyShortcutButton)
1213 mShortcutAdapter.getView(i, null, shortcutButtonContainer);
1214 mEmergencyShortcutButtonList.add(button);
1215 shortcutButtonContainer.addView(button);
1216 }
1217
Wesley.CW Wang5e785392018-08-09 20:11:34 +08001218 // Update emergency numbers title for numerous buttons.
CY Cheng9a69c182018-06-15 21:20:10 +08001219 if (mEmergencyShortcutButtonList.size() > 1) {
1220 emergencyNumberTitle.setText(getString(
1221 R.string.numerous_emergency_numbers_title));
Wesley.CW Wang5e785392018-08-09 20:11:34 +08001222 // Update mEmergencyInfoGroup margin to avoid UI overlay when
1223 // emergency shortcut button more than 2.
1224 if (mEmergencyShortcutButtonList.size() > 2) {
1225 mEmergencyInfoGroup.updateLayoutMargin();
1226 }
CY Cheng9a69c182018-06-15 21:20:10 +08001227 } else {
1228 emergencyNumberTitle.setText(getText(R.string.single_emergency_number_title));
1229 }
1230 }
1231 };
1232 mShortcutAdapter.registerDataSetObserver(mShortcutDataSetObserver);
1233 }
1234
Leo Hsu43d670a2018-12-04 15:40:36 +08001235 private void updateLocationAndEccInfo() {
CY Cheng9a69c182018-06-15 21:20:10 +08001236 if (!isFinishing() && !isDestroyed()) {
Leo Hsu43d670a2018-12-04 15:40:36 +08001237 setLocationInfo();
CY Cheng9a69c182018-06-15 21:20:10 +08001238 if (mShortcutAdapter != null) {
Leo Hsu43d670a2018-12-04 15:40:36 +08001239 mShortcutAdapter.updateCountryEccInfo(this, mPhoneInfo);
CY Cheng9a69c182018-06-15 21:20:10 +08001240 }
Chihhang Chuang92cfe512018-06-07 16:25:27 +08001241 }
1242 }
1243
1244 /**
1245 * Called by the activity before a touch event is dispatched to the view hierarchy.
1246 */
1247 private void onPreTouchEvent(MotionEvent event) {
1248 mEmergencyActionGroup.onPreTouchEvent(event);
Wesley.CW Wang5e785392018-08-09 20:11:34 +08001249 mEmergencyInfoGroup.onPreTouchEvent(event);
Chihhang Chuang92cfe512018-06-07 16:25:27 +08001250
1251 if (mEmergencyShortcutButtonList != null) {
1252 for (EmergencyShortcutButton button : mEmergencyShortcutButtonList) {
1253 button.onPreTouchEvent(event);
1254 }
1255 }
1256 }
1257
1258 /**
1259 * Called by the activity after a touch event is dispatched to the view hierarchy.
1260 */
1261 private void onPostTouchEvent(MotionEvent event) {
1262 mEmergencyActionGroup.onPostTouchEvent(event);
Wesley.CW Wang5e785392018-08-09 20:11:34 +08001263 mEmergencyInfoGroup.onPostTouchEvent(event);
Chihhang Chuang92cfe512018-06-07 16:25:27 +08001264
1265 if (mEmergencyShortcutButtonList != null) {
1266 for (EmergencyShortcutButton button : mEmergencyShortcutButtonList) {
1267 button.onPostTouchEvent(event);
1268 }
1269 }
1270 }
1271
Chihhang Chuangf264cfb2018-06-05 15:29:06 +08001272 /**
1273 * Switch two view.
1274 *
Leo Hsu83ab2332018-12-18 15:20:45 +08001275 * @param displayView the view would be displayed.
1276 * @param hideView the view would be hidden.
Chihhang Chuangf264cfb2018-06-05 15:29:06 +08001277 * @param hasAnimation is {@code true} when the view should be displayed with animation.
1278 */
1279 private void switchView(View displayView, View hideView, boolean hasAnimation) {
1280 if (displayView == null || hideView == null) {
1281 return;
1282 }
1283
1284 if (displayView.getVisibility() == View.VISIBLE) {
1285 return;
1286 }
1287
1288 if (hasAnimation) {
1289 crossfade(hideView, displayView);
1290 } else {
1291 hideView.setVisibility(View.GONE);
1292 displayView.setVisibility(View.VISIBLE);
1293 }
1294 }
1295
1296 /**
1297 * Fade out and fade in animation between two view transition.
1298 */
1299 private void crossfade(View fadeOutView, View fadeInView) {
1300 if (fadeOutView == null || fadeInView == null) {
1301 return;
1302 }
1303 final int shortAnimationDuration = getResources().getInteger(
1304 android.R.integer.config_shortAnimTime);
1305
1306 fadeInView.setAlpha(0f);
1307 fadeInView.setVisibility(View.VISIBLE);
1308
1309 fadeInView.animate()
1310 .alpha(1f)
1311 .setDuration(shortAnimationDuration)
1312 .setListener(null);
1313
1314 fadeOutView.animate()
1315 .alpha(0f)
1316 .setDuration(shortAnimationDuration)
1317 .setListener(new AnimatorListenerAdapter() {
1318 @Override
1319 public void onAnimationEnd(Animator animation) {
1320 fadeOutView.setVisibility(View.GONE);
1321 }
1322 });
1323 }
Shaotang Li8662a912018-07-04 16:53:01 +08001324
1325 @Override
1326 public void onSensorChanged(SensorEvent event) {
1327 float distance = event.values[0];
1328 mIsProximityNear = (distance < mProximitySensor.getMaximumRange());
1329 }
1330
1331 @Override
1332 public void onAccuracyChanged(Sensor sensor, int accuracy) {
1333 // Not used.
1334 }
1335
1336 private boolean isShortcutNumber(String number) {
1337 if (TextUtils.isEmpty(number) || mEmergencyShortcutButtonList == null) {
1338 return false;
1339 }
1340
1341 boolean isShortcut = false;
1342 for (EmergencyShortcutButton button : mEmergencyShortcutButtonList) {
1343 if (button != null && number.equals(button.getPhoneNumber())) {
1344 isShortcut = true;
1345 break;
1346 }
1347 }
1348 return isShortcut;
1349 }
Leo Hsue3512b62019-02-14 15:53:00 +08001350
1351 private String entryTypeToString(int entryType) {
1352 switch (entryType) {
1353 case ENTRY_TYPE_LOCKSCREEN_BUTTON:
1354 return "LockScreen";
1355 case ENTRY_TYPE_POWER_MENU:
1356 return "PowerMenu";
1357 default:
1358 return "Unknown-" + entryType;
1359 }
1360 }
1361
1362 private String callSourceToString(int callSource) {
1363 switch (callSource) {
1364 case ParcelableCallAnalytics.CALL_SOURCE_EMERGENCY_DIALPAD:
1365 return "DialPad";
1366 case ParcelableCallAnalytics.CALL_SOURCE_EMERGENCY_SHORTCUT:
1367 return "Shortcut";
1368 default:
1369 return "Unknown-" + callSource;
1370 }
1371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372}