diff options
author | Meng Wang <mewan@google.com> | 2021-09-23 18:37:43 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-09-23 18:37:43 +0000 |
commit | d2cce22dda5dc1dc25806febfac0d683c21b2e86 (patch) | |
tree | ffb7e6ae2e264091a81cb5307f958af41cbd3ec5 | |
parent | 1073943589f631aee08cc9137f66a5fbcad8369f (diff) | |
parent | dd4c4cc35a7c20f388ddcc58edbbf6c494bef5fe (diff) | |
download | ImsServiceEntitlement-d2cce22dda5dc1dc25806febfac0d683c21b2e86.tar.gz |
Skip CARRIER_CONFIG_CHANGED broadcast if SIM not loaded. am: dd4c4cc35a
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/ImsServiceEntitlement/+/15890231
Change-Id: Id1c84fb707ec5b959e81aacd99c0c30631b80279
3 files changed, 36 insertions, 3 deletions
diff --git a/src/com/android/imsserviceentitlement/ImsEntitlementReceiver.java b/src/com/android/imsserviceentitlement/ImsEntitlementReceiver.java index dc78b0a..d1d3a97 100644 --- a/src/com/android/imsserviceentitlement/ImsEntitlementReceiver.java +++ b/src/com/android/imsserviceentitlement/ImsEntitlementReceiver.java @@ -16,6 +16,8 @@ package com.android.imsserviceentitlement; +import static android.telephony.TelephonyManager.SIM_STATE_LOADED; + import static com.android.imsserviceentitlement.entitlement.EntitlementConfiguration.ClientBehavior.NEEDS_TO_RESET; import static com.android.imsserviceentitlement.entitlement.EntitlementConfiguration.ClientBehavior.VALID_DURING_VALIDITY; import static com.android.imsserviceentitlement.entitlement.EntitlementConfiguration.ClientBehavior.VALID_WITHOUT_DURATION; @@ -68,6 +70,8 @@ public class ImsEntitlementReceiver extends BroadcastReceiver { SubscriptionManager.INVALID_SIM_SLOT_INDEX); Dependencies dependencies = createDependency(context, currentSubId); if (!dependencies.userManager.isSystemUser() + || !SubscriptionManager.isValidSubscriptionId(currentSubId) + || dependencies.telephonyUtils.getSimApplicationState() != SIM_STATE_LOADED || !TelephonyUtils.isImsProvisioningRequired(context, currentSubId)) { return; } @@ -89,9 +93,6 @@ public class ImsEntitlementReceiver extends BroadcastReceiver { private void handleCarrierConfigChanged( Context context, int currentSubId, int slotId, JobManager jobManager, PendingResult result) { - if (!SubscriptionManager.isValidSubscriptionId(currentSubId)) { - return; - } boolean shouldQuery = false; // Handle device boot up. diff --git a/src/com/android/imsserviceentitlement/utils/TelephonyUtils.java b/src/com/android/imsserviceentitlement/utils/TelephonyUtils.java index 2601fd8..e968c2f 100644 --- a/src/com/android/imsserviceentitlement/utils/TelephonyUtils.java +++ b/src/com/android/imsserviceentitlement/utils/TelephonyUtils.java @@ -98,6 +98,11 @@ public class TelephonyUtils { return mTelephonyManager.getSimSpecificCarrierId(); } + /** Returns SIM card application state. */ + public int getSimApplicationState() { + return mTelephonyManager.getSimApplicationState(); + } + /** * Returns {@code true} if the {@code subId} still point to a actived SIM; {@code false} * otherwise. diff --git a/tests/unittests/src/com/android/imsserviceentitlement/ImsEntitlementReceiverTest.java b/tests/unittests/src/com/android/imsserviceentitlement/ImsEntitlementReceiverTest.java index dbea9a1..444db10 100644 --- a/tests/unittests/src/com/android/imsserviceentitlement/ImsEntitlementReceiverTest.java +++ b/tests/unittests/src/com/android/imsserviceentitlement/ImsEntitlementReceiverTest.java @@ -16,6 +16,9 @@ package com.android.imsserviceentitlement; +import static android.telephony.TelephonyManager.SIM_STATE_LOADED; +import static android.telephony.TelephonyManager.SIM_STATE_PIN_REQUIRED; + import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.never; @@ -117,6 +120,7 @@ public class ImsEntitlementReceiverTest { new EntitlementConfiguration(mContext, SUB_ID).reset(); when(mMockUserManager.isSystemUser()).thenReturn(true); + when(mMockTelephonyUtils.getSimApplicationState()).thenReturn(SIM_STATE_LOADED); setLastSubId(LAST_SUB_ID, 0); setupCarrierConfig(); @@ -133,6 +137,29 @@ public class ImsEntitlementReceiverTest { } @Test + public void onReceive_simChanged_simPinLockedThenLoaded() { + // SIM PIN locked + when(mMockTelephonyUtils.getSimApplicationState()).thenReturn(SIM_STATE_PIN_REQUIRED); + + mReceiver.onReceive(mContext, getCarrierConfigChangedIntent(SUB_ID, /* slotId= */ 0)); + + // no-op + assertThat( + new EntitlementConfiguration(mContext, LAST_SUB_ID).getVoWifiStatus()).isEqualTo(1); + verify(mMockJobManager, never()).queryEntitlementStatusOnceNetworkReady(); + + // SIM LOADED + when(mMockTelephonyUtils.getSimApplicationState()).thenReturn(SIM_STATE_LOADED); + + mReceiver.onReceive(mContext, getCarrierConfigChangedIntent(SUB_ID, /* slotId= */ 0)); + + // configuration reset and entitlement query scheduled. + assertThat( + new EntitlementConfiguration(mContext, LAST_SUB_ID).getVoWifiStatus()).isEqualTo(2); + verify(mMockJobManager, times(1)).queryEntitlementStatusOnceNetworkReady(); + } + + @Test public void onReceive_theSameSim_dataNotReset() { mReceiver.onReceive( mContext, getCarrierConfigChangedIntent(LAST_SUB_ID, /* slotId= */ 0)); |