Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f9abde3 authored by Rambo Wang's avatar Rambo Wang Committed by Automerger Merge Worker
Browse files

Merge "Add UT for PhysicalChannelConfigChangedListener" am: 358394b2 am: 1f29315b

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/1645786

Change-Id: Ib22de84f9159be5d180619a1fea945cf697582d0
parents 204fee93 1f29315b
Loading
Loading
Loading
Loading
+41 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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);
@@ -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() {
@@ -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.
     */