diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-10-06 22:26:58 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-10-06 22:26:58 +0000 |
commit | a6afbf73ee9ed4ae0101a6ff16333b6f9420190c (patch) | |
tree | 5cb8b3c3ff020911e605ce98546aeef87a331e5e | |
parent | 7b52ecd05444d604cf38732ec2b3a90bd3c252e7 (diff) | |
parent | e9bf1b3372a95bc67327fd29bd91b74bc5c080b0 (diff) | |
download | telephony-android12-mainline-statsd-release.tar.gz |
Snap for 7799923 from e9bf1b3372a95bc67327fd29bd91b74bc5c080b0 to mainline-os-statsd-releaseandroid-mainline-12.0.0_r58android12-mainline-statsd-release
Change-Id: I829b03723f79d9b431d3620f16be99038944dc41
4 files changed, 124 insertions, 5 deletions
diff --git a/src/java/com/android/internal/telephony/uicc/UiccController.java b/src/java/com/android/internal/telephony/uicc/UiccController.java index 36cad5f442..fb64b6a3cc 100644 --- a/src/java/com/android/internal/telephony/uicc/UiccController.java +++ b/src/java/com/android/internal/telephony/uicc/UiccController.java @@ -1103,12 +1103,16 @@ public class UiccController extends Handler { options.toBundle()); } - private boolean slotStatusChanged(ArrayList<IccSlotStatus> slotStatusList) { + /** + * Check if slot status has changed from the last received one + */ + @VisibleForTesting + public boolean slotStatusChanged(ArrayList<IccSlotStatus> slotStatusList) { if (sLastSlotStatus == null || sLastSlotStatus.size() != slotStatusList.size()) { return true; } - for (IccSlotStatus iccSlotStatus : slotStatusList) { - if (!sLastSlotStatus.contains(iccSlotStatus)) { + for (int i = 0; i < slotStatusList.size(); i++) { + if (!sLastSlotStatus.get(i).equals(slotStatusList.get(i))) { return true; } } diff --git a/tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java b/tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java index f04e69f321..14f5aa14cf 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java +++ b/tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java @@ -424,6 +424,12 @@ public class ContextFixture implements TestFixture<Context> { } @Override + public void sendBroadcast(Intent intent, String receiverPermission, Bundle initialExtras) { + logd("sendBroadcast called for " + intent.getAction()); + sendBroadcast(intent); + } + + @Override public void sendOrderedBroadcast(Intent intent, String receiverPermission) { logd("sendOrderedBroadcast called for " + intent.getAction()); sendBroadcast(intent); diff --git a/tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java b/tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java index 1d5bce64db..d14bbd0801 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java @@ -30,6 +30,7 @@ import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -273,7 +274,6 @@ public class TelephonyRegistryTest extends TelephonyTest { assertEquals(phoneCapability, mPhoneCapability); } - @Test @SmallTest public void testActiveDataSubChanged() { // mTelephonyRegistry.listen with notifyNow = true should trigger callback immediately. @@ -616,9 +616,13 @@ public class TelephonyRegistryTest extends TelephonyTest { int[] events = {TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED}; mTelephonyRegistry.listenWithEventList(2, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); + when(mMockConfigurationProvider.isDisplayInfoNrAdvancedSupported( + anyString(), any())).thenReturn(true); + TelephonyDisplayInfo displayInfo = new TelephonyDisplayInfo( + TelephonyManager.NETWORK_TYPE_LTE, + TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED); // Notify with invalid subId on default phone. Should NOT trigger callback. - TelephonyDisplayInfo displayInfo = new TelephonyDisplayInfo(0, 0); mTelephonyRegistry.notifyDisplayInfoChanged(0, INVALID_SUBSCRIPTION_ID, displayInfo); processAllMessages(); assertEquals(null, mTelephonyDisplayInfo); @@ -630,6 +634,82 @@ public class TelephonyRegistryTest extends TelephonyTest { } @Test + public void testDisplayInfoCompatibility() { + mContext.sendBroadcast(new Intent(ACTION_DEFAULT_SUBSCRIPTION_CHANGED) + .putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, 12) + .putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, 0)); + processAllMessages(); + int[] events = {TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED}; + mTelephonyRegistry.listenWithEventList(2, mContext.getOpPackageName(), + mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); + when(mMockConfigurationProvider.isDisplayInfoNrAdvancedSupported( + anyString(), any())).thenReturn(false); + TelephonyDisplayInfo displayInfo = new TelephonyDisplayInfo( + TelephonyManager.NETWORK_TYPE_LTE, + TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED); + TelephonyDisplayInfo expectDisplayInfo = new TelephonyDisplayInfo( + TelephonyManager.NETWORK_TYPE_LTE, + TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE); + + // Notify with invalid subId on default phone. Should NOT trigger callback. + mTelephonyRegistry.notifyDisplayInfoChanged(0, INVALID_SUBSCRIPTION_ID, displayInfo); + processAllMessages(); + assertEquals(null, mTelephonyDisplayInfo); + + // Notify with the matching subId on default phone. Should trigger callback. + mTelephonyRegistry.notifyDisplayInfoChanged(0, 2, displayInfo); + processAllMessages(); + assertEquals(expectDisplayInfo, mTelephonyDisplayInfo); + } + + @Test + public void testDisplayInfoCompatibility_moreCallingPackages() { + mContext.sendBroadcast(new Intent(ACTION_DEFAULT_SUBSCRIPTION_CHANGED) + .putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, 12) + .putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, 0)); + processAllMessages(); + int[] events = {TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED}; + TelephonyDisplayInfo displayInfo = new TelephonyDisplayInfo( + TelephonyManager.NETWORK_TYPE_LTE, + TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED); + TelephonyDisplayInfo expectDisplayInfo = new TelephonyDisplayInfo( + TelephonyManager.NETWORK_TYPE_LTE, + TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE); + TelephonyCallback telephonyCallback2 = new TelephonyCallbackWrapper() { + @Override + public void onDisplayInfoChanged(TelephonyDisplayInfo displayInfoNotify) { + assertEquals(displayInfo, displayInfoNotify); + } + }; + Executor mSimpleExecutor2 = new Executor() { + @Override + public void execute(Runnable r) { + r.run(); + } + }; + telephonyCallback2.init(mSimpleExecutor2); + mTelephonyRegistry.listenWithEventList(2, "pkg1", + mContext.getAttributionTag(), mTelephonyCallback.callback, events, false); + mTelephonyRegistry.listenWithEventList(2, "pkg2", + mContext.getAttributionTag(), telephonyCallback2.callback, events, false); + when(mMockConfigurationProvider.isDisplayInfoNrAdvancedSupported( + eq("pkg1"), any())).thenReturn(false); + when(mMockConfigurationProvider.isDisplayInfoNrAdvancedSupported( + eq("pkg2"), any())).thenReturn(true); + + + // Notify with invalid subId on default phone. Should NOT trigger callback. + mTelephonyRegistry.notifyDisplayInfoChanged(0, INVALID_SUBSCRIPTION_ID, displayInfo); + processAllMessages(); + assertEquals(null, mTelephonyDisplayInfo); + + // Notify with the matching subId on default phone. Should trigger callback. + mTelephonyRegistry.notifyDisplayInfoChanged(0, 2, displayInfo); + processAllMessages(); + assertEquals(expectDisplayInfo, mTelephonyDisplayInfo); + } + + @Test public void testNotifyCellLocationForSubscriberByUserSwitched() throws RemoteException { final int phoneId = 0; final int subId = 1; diff --git a/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccControllerTest.java index c9fccafecf..a00e110f5a 100644 --- a/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccControllerTest.java +++ b/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccControllerTest.java @@ -18,6 +18,7 @@ package com.android.internal.telephony.uicc; import static junit.framework.Assert.fail; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -634,4 +635,32 @@ public class UiccControllerTest extends TelephonyTest { assertEquals(mUiccControllerUT.convertToPublicCardId(knownEidFromApdu), mUiccControllerUT.getCardIdForDefaultEuicc()); } + + @Test + public void testSlotStatusChanged() { + // simulate slot status loaded so that the UiccController sets the last slot status + IccSlotStatus iss1 = new IccSlotStatus(); + iss1.setSlotState(1 /* active */); + iss1.eid = "eid1"; + IccSlotStatus iss2 = new IccSlotStatus(); + iss2.setSlotState(1 /* active */); + iss2.eid = "eid2"; + ArrayList<IccSlotStatus> status = new ArrayList<IccSlotStatus>(); + status.add(iss1); + status.add(iss2); + AsyncResult ar = new AsyncResult(null, status, null); + Message msg = Message.obtain(mUiccControllerUT, EVENT_GET_SLOT_STATUS_DONE, ar); + mUiccControllerUT.handleMessage(msg); + processAllMessages(); + + assertFalse(mUiccControllerUT.slotStatusChanged(status)); + + // change the order of the IccSlotStatus in the list + status = new ArrayList<>(); + status.add(iss2); + status.add(iss1); + + // status should be treated different from last status + assertTrue(mUiccControllerUT.slotStatusChanged(status)); + } } |