From 5866a4a23a1ce4497b04a58133201363f5ea5686 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Tue, 27 Jun 2023 12:03:40 -0700 Subject: [PATCH] Handle when sim state indicates that it is absent We want to update the sim state the view mediator when the sim state indicates that it is absent. When we disable the esim, we want to be able to update the sim state to indicate that we no longer have secure sim pin when we swipe to unlock. Additionally, we want to ensure that mPendingPinLock is set to false so that we do not show keyguard again after dismissing. Fixes: 286520191 Test: disable esim in sim when security method is None Test: unlock sim when security method is None Test: disable esim in simpuk when security method is None Test: unlock simpuk when securith method is None Test: disable esim in sim when security method is Swipe Test: unlock sim when security method is Swipe Test: disable esim in simpuk when security method is Swipe Test: unlock simpuk when securith method is Swipe Test: disable esim in sim when security method is Pin Test: unlock sim when security method is Pin Test: disable esim in simpuk when security method is Pin Test: unlock simpuk when securith method is Pin Change-Id: I69ef1698d1c3b3833cbbe925999dd4aa87cc00eb --- .../android/keyguard/KeyguardUpdateMonitor.java | 14 +++++++++----- .../systemui/keyguard/KeyguardViewMediator.java | 5 ++--- .../keyguard/KeyguardUpdateMonitorTest.java | 10 ++++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index c4ea45dbbec76..518baec6b089e 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -303,6 +303,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab private static final ComponentName FALLBACK_HOME_COMPONENT = new ComponentName( "com.android.settings", "com.android.settings.FallbackHome"); + private static final List ABSENT_SIM_STATE_LIST = Arrays.asList( + TelephonyManager.SIM_STATE_ABSENT, + TelephonyManager.SIM_STATE_UNKNOWN, + TelephonyManager.SIM_STATE_NOT_READY); + private final Context mContext; private final UserTracker mUserTracker; private final KeyguardUpdateMonitorLogger mLogger; @@ -3742,8 +3747,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab mLogger.logSimState(subId, slotId, state); boolean becameAbsent = false; - if (!SubscriptionManager.isValidSubscriptionId(subId) - && state != TelephonyManager.SIM_STATE_UNKNOWN) { + if (!SubscriptionManager.isValidSubscriptionId(subId)) { mLogger.w("invalid subId in handleSimStateChange()"); /* Only handle No SIM(ABSENT) and Card Error(CARD_IO_ERROR) due to * handleServiceStateChange() handle other case */ @@ -3761,11 +3765,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } } else if (state == TelephonyManager.SIM_STATE_CARD_IO_ERROR) { updateTelephonyCapable(true); - } else { - return; } } + becameAbsent |= ABSENT_SIM_STATE_LIST.contains(state); + SimData data = mSimDatas.get(subId); final boolean changed; if (data == null) { @@ -3778,7 +3782,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab data.subId = subId; data.slotId = slotId; } - if ((changed || becameAbsent) || state == TelephonyManager.SIM_STATE_UNKNOWN) { + if ((changed || becameAbsent)) { for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index 155e0231e9d25..fdec2094e1ba1 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -649,6 +649,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, switch (simState) { case TelephonyManager.SIM_STATE_NOT_READY: case TelephonyManager.SIM_STATE_ABSENT: + case TelephonyManager.SIM_STATE_UNKNOWN: + mPendingPinLock = false; // only force lock screen in case of missing sim if user hasn't // gone through setup wizard synchronized (KeyguardViewMediator.this) { @@ -713,9 +715,6 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable, } } break; - case TelephonyManager.SIM_STATE_UNKNOWN: - mPendingPinLock = false; - break; default: if (DEBUG_SIM_STATES) Log.v(TAG, "Unspecific state: " + simState); break; diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java index 4263091c5ee81..5abab6239b1e1 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java @@ -3001,6 +3001,16 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { TelephonyManager.SIM_STATE_UNKNOWN); } + @Test + public void testOnSimStateChanged_HandleSimStateNotReady() { + KeyguardUpdateMonitorCallback keyguardUpdateMonitorCallback = spy( + KeyguardUpdateMonitorCallback.class); + mKeyguardUpdateMonitor.registerCallback(keyguardUpdateMonitorCallback); + mKeyguardUpdateMonitor.handleSimStateChange(-1, 0, TelephonyManager.SIM_STATE_NOT_READY); + verify(keyguardUpdateMonitorCallback).onSimStateChanged(-1, 0, + TelephonyManager.SIM_STATE_NOT_READY); + } + @Test public void onAuthEnrollmentChangesCallbacksAreNotified() { KeyguardUpdateMonitorCallback callback = mock(KeyguardUpdateMonitorCallback.class);