summaryrefslogtreecommitdiff
path: root/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java
diff options
context:
space:
mode:
authorScott Lobdell <slobdell@google.com>2021-03-29 16:12:49 +0000
committerScott Lobdell <slobdell@google.com>2021-04-02 22:35:29 +0000
commit21cdef883cc867db55340b25d5c95e19b12ab383 (patch)
tree93d1444ebe783f53f5f0ae2647592723b27b3fb8 /packages/SystemUI/src/com/android/keyguard/EmergencyButton.java
parent7deab3736bb5f3a92be8ac820096926dce2366ad (diff)
parentd1d45f856fdf68835f5b42eacecab44e6dfa8545 (diff)
Merge SP1A.210329.001
Change-Id: I1e21c5890b5b2e2f2855f09960bc8eec8aa922bf
Diffstat (limited to 'packages/SystemUI/src/com/android/keyguard/EmergencyButton.java')
-rw-r--r--packages/SystemUI/src/com/android/keyguard/EmergencyButton.java172
1 files changed, 5 insertions, 167 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java b/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java
index 37272950622b..1bd55e8de607 100644
--- a/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java
+++ b/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java
@@ -16,39 +16,21 @@
package com.android.keyguard;
-import static com.android.systemui.DejankUtils.whitelistIpcs;
-
-import android.app.ActivityOptions;
-import android.app.ActivityTaskManager;
import android.content.Context;
-import android.content.Intent;
-import android.content.res.Configuration;
-import android.os.PowerManager;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.os.UserHandle;
-import android.telecom.TelecomManager;
-import android.telephony.CellInfo;
+import com.android.systemui.Dependency;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.AttributeSet;
-import android.util.Log;
-import android.util.Slog;
-import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.Button;
-import com.android.internal.logging.MetricsLogger;
-import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.util.EmergencyAffordanceManager;
import com.android.internal.widget.LockPatternUtils;
import com.android.settingslib.Utils;
-import com.android.systemui.Dependency;
import com.android.systemui.R;
-import com.android.systemui.util.EmergencyDialerConstants;
import java.util.List;
@@ -60,43 +42,14 @@ import java.util.List;
*/
public class EmergencyButton extends Button {
- private static final String LOG_TAG = "EmergencyButton";
private final EmergencyAffordanceManager mEmergencyAffordanceManager;
private int mDownX;
private int mDownY;
- KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() {
-
- @Override
- public void onSimStateChanged(int subId, int slotId, int simState) {
- requestCellInfoUpdate();
- updateEmergencyCallButton();
- }
-
- @Override
- public void onPhoneStateChanged(int phoneState) {
- requestCellInfoUpdate();
- updateEmergencyCallButton();
- }
-
- @Override
- public void onServiceStateChanged(int subId, ServiceState state) {
- mServiceState = state;
- requestCellInfoUpdate();
- updateEmergencyCallButton();
- }
- };
private boolean mLongPressWasDragged;
- public interface EmergencyButtonCallback {
- public void onEmergencyButtonClickedWhenInCall();
- }
-
private LockPatternUtils mLockPatternUtils;
- private PowerManager mPowerManager;
- private EmergencyButtonCallback mEmergencyButtonCallback;
- private final boolean mIsVoiceCapable;
private final boolean mEnableEmergencyCallWhileSimLocked;
private boolean mIsCellAvailable;
private ServiceState mServiceState;
@@ -107,35 +60,15 @@ public class EmergencyButton extends Button {
public EmergencyButton(Context context, AttributeSet attrs) {
super(context, attrs);
- mIsVoiceCapable = getTelephonyManager().isVoiceCapable();
mEnableEmergencyCallWhileSimLocked = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_enable_emergency_call_while_sim_locked);
mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
}
- private TelephonyManager getTelephonyManager() {
- return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
- }
-
- @Override
- protected void onAttachedToWindow() {
- super.onAttachedToWindow();
- Dependency.get(KeyguardUpdateMonitor.class).registerCallback(mInfoCallback);
- requestCellInfoUpdate();
- }
-
- @Override
- protected void onDetachedFromWindow() {
- super.onDetachedFromWindow();
- Dependency.get(KeyguardUpdateMonitor.class).removeCallback(mInfoCallback);
- }
-
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mLockPatternUtils = new LockPatternUtils(mContext);
- mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
- setOnClickListener(v -> takeEmergencyCallAction());
if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
setOnLongClickListener(v -> {
if (!mLongPressWasDragged
@@ -146,8 +79,6 @@ public class EmergencyButton extends Button {
return false;
});
}
- requestCellInfoUpdate();
- whitelistIpcs(this::updateEmergencyCallButton);
}
@Override
@@ -185,66 +116,13 @@ public class EmergencyButton extends Button {
return super.performLongClick();
}
- @Override
- protected void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- requestCellInfoUpdate();
- updateEmergencyCallButton();
- }
-
- /**
- * Shows the emergency dialer or returns the user to the existing call.
- */
- public void takeEmergencyCallAction() {
- MetricsLogger.action(mContext, MetricsEvent.ACTION_EMERGENCY_CALL);
- if (mPowerManager != null) {
- mPowerManager.userActivity(SystemClock.uptimeMillis(), true);
- }
- try {
- ActivityTaskManager.getService().stopSystemLockTaskMode();
- } catch (RemoteException e) {
- Slog.w(LOG_TAG, "Failed to stop app pinning");
- }
- if (isInCall()) {
- resumeCall();
- if (mEmergencyButtonCallback != null) {
- mEmergencyButtonCallback.onEmergencyButtonClickedWhenInCall();
- }
- } else {
- KeyguardUpdateMonitor updateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
- if (updateMonitor != null) {
- updateMonitor.reportEmergencyCallAction(true /* bypassHandler */);
- } else {
- Log.w(LOG_TAG, "KeyguardUpdateMonitor was null, launching intent anyway.");
- }
- TelecomManager telecomManager = getTelecommManager();
- if (telecomManager == null) {
- Log.wtf(LOG_TAG, "TelecomManager was null, cannot launch emergency dialer");
- return;
- }
- Intent emergencyDialIntent =
- telecomManager.createLaunchEmergencyDialerIntent(null /* number*/)
- .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
- | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
- | Intent.FLAG_ACTIVITY_CLEAR_TOP)
- .putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
- EmergencyDialerConstants.ENTRY_TYPE_LOCKSCREEN_BUTTON);
-
- getContext().startActivityAsUser(emergencyDialIntent,
- ActivityOptions.makeCustomAnimation(getContext(), 0, 0).toBundle(),
- new UserHandle(KeyguardUpdateMonitor.getCurrentUser()));
- }
- }
-
- public void updateEmergencyCallButton() {
+ public void updateEmergencyCallButton(boolean isInCall, boolean isVoiceCapable, boolean simLocked) {
boolean visible = false;
- if (mIsVoiceCapable) {
+ if (isVoiceCapable) {
// Emergency calling requires voice capability.
- if (isInCall()) {
+ if (isInCall) {
visible = true; // always show "return to call" if phone is off-hook
} else {
- final boolean simLocked = Dependency.get(KeyguardUpdateMonitor.class)
- .isSimPinVoiceSecure();
if (simLocked) {
// Some countries can't handle emergency calls while SIM is locked.
visible = mEnableEmergencyCallWhileSimLocked;
@@ -263,7 +141,7 @@ public class EmergencyButton extends Button {
setVisibility(View.VISIBLE);
int textId;
- if (isInCall()) {
+ if (isInCall) {
textId = com.android.internal.R.string.lockscreen_return_to_call;
} else {
textId = com.android.internal.R.string.lockscreen_emergency_call;
@@ -274,46 +152,6 @@ public class EmergencyButton extends Button {
}
}
- public void setCallback(EmergencyButtonCallback callback) {
- mEmergencyButtonCallback = callback;
- }
-
- /**
- * Resumes a call in progress.
- */
- private void resumeCall() {
- getTelecommManager().showInCallScreen(false);
- }
-
- /**
- * @return {@code true} if there is a call currently in progress.
- */
- private boolean isInCall() {
- return getTelecommManager().isInCall();
- }
-
- private TelecomManager getTelecommManager() {
- return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
- }
-
- private void requestCellInfoUpdate(){
- TelephonyManager tmWithoutSim = getTelephonyManager()
- .createForSubscriptionId(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
- tmWithoutSim.requestCellInfoUpdate(mContext.getMainExecutor(),
- new TelephonyManager.CellInfoCallback() {
- @Override
- public void onCellInfo(List<CellInfo> cellInfos) {
- if ( cellInfos == null || cellInfos.isEmpty()) {
- Log.d(LOG_TAG, "requestCellInfoUpdate.onCellInfo is null or empty");
- mIsCellAvailable = false;
- }else{
- mIsCellAvailable = true;
- }
- updateEmergencyCallButton();
- }
- });
- }
-
private boolean isEmergencyCapable() {
KeyguardUpdateMonitor monitor = Dependency.get(KeyguardUpdateMonitor.class);
return (!monitor.isOOS()