Loading tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java +41 −1 Original line number Diff line number Diff line Loading @@ -15,6 +15,8 @@ */ package com.android.internal.telephony; import static android.telephony.PhysicalChannelConfig.PHYSICAL_CELL_ID_UNKNOWN; import static android.telephony.ServiceState.FREQUENCY_RANGE_LOW; import static android.telephony.SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED; import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; import static android.telephony.TelephonyManager.ACTION_MULTI_SIM_CONFIG_CHANGED; Loading @@ -23,6 +25,7 @@ import static android.telephony.TelephonyManager.RADIO_POWER_ON; import static android.telephony.TelephonyManager.RADIO_POWER_UNAVAILABLE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doReturn; Loading @@ -36,6 +39,7 @@ import android.telephony.AccessNetworkConstants; import android.telephony.Annotation; import android.telephony.LinkCapacityEstimate; import android.telephony.PhoneCapability; import android.telephony.PhysicalChannelConfig; import android.telephony.PreciseDataConnectionState; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; Loading @@ -47,6 +51,8 @@ import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import androidx.annotation.NonNull; import com.android.server.TelephonyRegistry; import org.junit.After; Loading Loading @@ -76,6 +82,7 @@ public class TelephonyRegistryTest extends TelephonyTest { private TelephonyDisplayInfo mTelephonyDisplayInfo; private int mSrvccState = -1; private int mRadioPowerState = RADIO_POWER_UNAVAILABLE; private List<PhysicalChannelConfig> mPhysicalChannelConfigs; // All events contribute to TelephonyRegistry#isPhoneStatePermissionRequired private static final Set<Integer> READ_PHONE_STATE_EVENTS; Loading Loading @@ -141,7 +148,8 @@ public class TelephonyRegistryTest extends TelephonyTest { TelephonyCallback.RadioPowerStateListener, TelephonyCallback.PreciseDataConnectionStateListener, TelephonyCallback.DisplayInfoListener, TelephonyCallback.LinkCapacityEstimateChangedListener { TelephonyCallback.LinkCapacityEstimateChangedListener, TelephonyCallback.PhysicalChannelConfigListener { // This class isn't mockable to get invocation counts because the IBinder is null and // crashes the TelephonyRegistry. Make a cheesy verify(times()) alternative. public AtomicInteger invocationCount = new AtomicInteger(0); Loading Loading @@ -181,6 +189,11 @@ public class TelephonyRegistryTest extends TelephonyTest { List<LinkCapacityEstimate> linkCapacityEstimateList) { mLinkCapacityEstimateList = linkCapacityEstimateList; } @Override public void onPhysicalChannelConfigChanged(@NonNull List<PhysicalChannelConfig> configs) { mPhysicalChannelConfigs = configs; } } private void addTelephonyRegistryService() { Loading Loading @@ -421,6 +434,33 @@ public class TelephonyRegistryTest extends TelephonyTest { assertEquals(4, mTelephonyCallback.invocationCount.get()); } @Test public void testPhysicalChannelConfigChanged() { // Return a slotIndex / phoneId of 0 for all sub ids given. doReturn(mMockSubInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt()); doReturn(0/*slotIndex*/).when(mMockSubInfo).getSimSlotIndex(); final int subId = 1; int[] events = {TelephonyCallback.EVENT_PHYSICAL_CHANNEL_CONFIG_CHANGED}; // Construct PhysicalChannelConfig with minimum fields set (The default value for // frequencyRange and band fields throw IAE) PhysicalChannelConfig config = new PhysicalChannelConfig.Builder() .setFrequencyRange(FREQUENCY_RANGE_LOW) .setBand(1) .setPhysicalCellId(2) .build(); List<PhysicalChannelConfig> configs = new ArrayList<>(1); configs.add(config); mTelephonyRegistry.notifyPhysicalChannelConfigForSubscriber(subId, configs); mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertNotNull(mPhysicalChannelConfigs); assertEquals(PHYSICAL_CELL_ID_UNKNOWN, mPhysicalChannelConfigs.get(0).getPhysicalCellId()); } /** * Test listen to events that require READ_PHONE_STATE permission. */ Loading Loading
tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java +41 −1 Original line number Diff line number Diff line Loading @@ -15,6 +15,8 @@ */ package com.android.internal.telephony; import static android.telephony.PhysicalChannelConfig.PHYSICAL_CELL_ID_UNKNOWN; import static android.telephony.ServiceState.FREQUENCY_RANGE_LOW; import static android.telephony.SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED; import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; import static android.telephony.TelephonyManager.ACTION_MULTI_SIM_CONFIG_CHANGED; Loading @@ -23,6 +25,7 @@ import static android.telephony.TelephonyManager.RADIO_POWER_ON; import static android.telephony.TelephonyManager.RADIO_POWER_UNAVAILABLE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doReturn; Loading @@ -36,6 +39,7 @@ import android.telephony.AccessNetworkConstants; import android.telephony.Annotation; import android.telephony.LinkCapacityEstimate; import android.telephony.PhoneCapability; import android.telephony.PhysicalChannelConfig; import android.telephony.PreciseDataConnectionState; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; Loading @@ -47,6 +51,8 @@ import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import androidx.annotation.NonNull; import com.android.server.TelephonyRegistry; import org.junit.After; Loading Loading @@ -76,6 +82,7 @@ public class TelephonyRegistryTest extends TelephonyTest { private TelephonyDisplayInfo mTelephonyDisplayInfo; private int mSrvccState = -1; private int mRadioPowerState = RADIO_POWER_UNAVAILABLE; private List<PhysicalChannelConfig> mPhysicalChannelConfigs; // All events contribute to TelephonyRegistry#isPhoneStatePermissionRequired private static final Set<Integer> READ_PHONE_STATE_EVENTS; Loading Loading @@ -141,7 +148,8 @@ public class TelephonyRegistryTest extends TelephonyTest { TelephonyCallback.RadioPowerStateListener, TelephonyCallback.PreciseDataConnectionStateListener, TelephonyCallback.DisplayInfoListener, TelephonyCallback.LinkCapacityEstimateChangedListener { TelephonyCallback.LinkCapacityEstimateChangedListener, TelephonyCallback.PhysicalChannelConfigListener { // This class isn't mockable to get invocation counts because the IBinder is null and // crashes the TelephonyRegistry. Make a cheesy verify(times()) alternative. public AtomicInteger invocationCount = new AtomicInteger(0); Loading Loading @@ -181,6 +189,11 @@ public class TelephonyRegistryTest extends TelephonyTest { List<LinkCapacityEstimate> linkCapacityEstimateList) { mLinkCapacityEstimateList = linkCapacityEstimateList; } @Override public void onPhysicalChannelConfigChanged(@NonNull List<PhysicalChannelConfig> configs) { mPhysicalChannelConfigs = configs; } } private void addTelephonyRegistryService() { Loading Loading @@ -421,6 +434,33 @@ public class TelephonyRegistryTest extends TelephonyTest { assertEquals(4, mTelephonyCallback.invocationCount.get()); } @Test public void testPhysicalChannelConfigChanged() { // Return a slotIndex / phoneId of 0 for all sub ids given. doReturn(mMockSubInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt()); doReturn(0/*slotIndex*/).when(mMockSubInfo).getSimSlotIndex(); final int subId = 1; int[] events = {TelephonyCallback.EVENT_PHYSICAL_CHANNEL_CONFIG_CHANGED}; // Construct PhysicalChannelConfig with minimum fields set (The default value for // frequencyRange and band fields throw IAE) PhysicalChannelConfig config = new PhysicalChannelConfig.Builder() .setFrequencyRange(FREQUENCY_RANGE_LOW) .setBand(1) .setPhysicalCellId(2) .build(); List<PhysicalChannelConfig> configs = new ArrayList<>(1); configs.add(config); mTelephonyRegistry.notifyPhysicalChannelConfigForSubscriber(subId, configs); mTelephonyRegistry.listenWithEventList(subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mTelephonyCallback.callback, events, true); processAllMessages(); assertNotNull(mPhysicalChannelConfigs); assertEquals(PHYSICAL_CELL_ID_UNKNOWN, mPhysicalChannelConfigs.get(0).getPhysicalCellId()); } /** * Test listen to events that require READ_PHONE_STATE permission. */ Loading