Add testcase for DisplayInfo Compatibility
Bug: 197521539
Test: atest com.android.internal.telephony.TelephonyRegistryTest
Change-Id: I03ba625bd7ea2d5b3c72db91bb874210c868e328
(cherry picked from commit 92edb30218208da04c94ba0df6803f5b669b3913)
diff --git a/tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java b/tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java
index 1d5bce6..d14bbd0 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.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 @@
assertEquals(phoneCapability, mPhoneCapability);
}
-
@Test @SmallTest
public void testActiveDataSubChanged() {
// mTelephonyRegistry.listen with notifyNow = true should trigger callback immediately.
@@ -616,9 +616,13 @@
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 @@
}
@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;