Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1cffe3c3 authored by Adrian Roos's avatar Adrian Roos
Browse files

Show keyguard when SIM is removed

If the device has a secure lockscreen and the device'
SIM card is removed, lock the device.

Change-Id: I5b0deea8851b38781059732a3cf6fa0a4a00e3ca
Fixes: 30997251
Test: set up lock screen, insert SIM card, unlock phone, remove SIM card, observe that screen is locked
parent 9a4c8a20
Loading
Loading
Loading
Loading
+28 −5
Original line number Diff line number Diff line
@@ -59,6 +59,8 @@ import android.view.WindowManagerPolicy;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.policy.IKeyguardDismissCallback;
import com.android.internal.policy.IKeyguardDrawnCallback;
import com.android.internal.policy.IKeyguardExitCallback;
@@ -325,6 +327,7 @@ public class KeyguardViewMediator extends SystemUI {

    private boolean mWakeAndUnlocking;
    private IKeyguardDrawnCallback mDrawnCallback;
    private boolean mLockWhenSimRemoved;

    KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {

@@ -415,7 +418,7 @@ public class KeyguardViewMediator extends SystemUI {
                case ABSENT:
                    // only force lock screen in case of missing sim if user hasn't
                    // gone through setup wizard
                    synchronized (this) {
                    synchronized (KeyguardViewMediator.this) {
                        if (shouldWaitForProvisioning()) {
                            if (!mShowing) {
                                if (DEBUG_SIM_STATES) Log.d(TAG, "ICC_ABSENT isn't showing,"
@@ -426,11 +429,12 @@ public class KeyguardViewMediator extends SystemUI {
                                resetStateLocked();
                            }
                        }
                        onSimNotReadyLocked();
                    }
                    break;
                case PIN_REQUIRED:
                case PUK_REQUIRED:
                    synchronized (this) {
                    synchronized (KeyguardViewMediator.this) {
                        if (!mShowing) {
                            if (DEBUG_SIM_STATES) Log.d(TAG,
                                    "INTENT_VALUE_ICC_LOCKED and keygaurd isn't "
@@ -442,7 +446,7 @@ public class KeyguardViewMediator extends SystemUI {
                    }
                    break;
                case PERM_DISABLED:
                    synchronized (this) {
                    synchronized (KeyguardViewMediator.this) {
                        if (!mShowing) {
                            if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED and "
                                  + "keygaurd isn't showing.");
@@ -452,21 +456,40 @@ public class KeyguardViewMediator extends SystemUI {
                                  + "show permanently disabled message in lockscreen.");
                            resetStateLocked();
                        }
                        onSimNotReadyLocked();
                    }
                    break;
                case READY:
                    synchronized (this) {
                    synchronized (KeyguardViewMediator.this) {
                        if (mShowing) {
                            resetStateLocked();
                        }
                        mLockWhenSimRemoved = true;
                    }
                    break;
                default:
                    if (DEBUG_SIM_STATES) Log.v(TAG, "Ignoring state: " + simState);
                    if (DEBUG_SIM_STATES) Log.v(TAG, "Unspecific state: " + simState);
                    synchronized (KeyguardViewMediator.this) {
                        onSimNotReadyLocked();
                    }
                    break;
            }
        }

        private void onSimNotReadyLocked() {
            if (isSecure() && mLockWhenSimRemoved) {
                mLockWhenSimRemoved = false;
                MetricsLogger.action(mContext,
                        MetricsProto.MetricsEvent.ACTION_LOCK_BECAUSE_SIM_REMOVED, mShowing);
                if (!mShowing) {
                    if (DEBUG_SIM_STATES) Log.d(TAG, "SIM removed, showing keyguard");
                    doKeyguardLocked(null);
                } else {
                    resetStateLocked();
                }
            }
        }

        @Override
        public void onFingerprintAuthFailed() {
            final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
+8 −0
Original line number Diff line number Diff line
@@ -2232,6 +2232,14 @@ message MetricsEvent {

    // ---- End N-MR1 Constants, all N-MR1 constants go above this line ----

    // ACTION: The lockscreen gets shown because the SIM card was removed
    // SUBTYPE: false: device was previously unlocked, true: device was previously locked
    // CATEGORY: GLOBAL_SYSTEM_UI
    // OS: N-MR2
    ACTION_LOCK_BECAUSE_SIM_REMOVED = 496;

    // ---- End N-MR2 Constants, all N-MR2 constants go above this line ----

    // ------- Begin N Keyboard Shortcuts Helper -----
    // Keyboard Shortcuts Helper is opened/closed.
    KEYBOARD_SHORTCUTS_HELPER = 500;