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

Commit f38bf26b authored by Ling Ma's avatar Ling Ma Committed by Android (Google) Code Review
Browse files

Merge "Add secondary timer for advance band" into main

parents a3eb7743 7dcb2b16
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -173,6 +173,8 @@ public class NetworkTypeController extends StateMachine {
    @NonNull private final Set<Integer> mAdditionalNrAdvancedBands = new HashSet<>();
    @NonNull private String mPrimaryTimerState;
    @NonNull private String mSecondaryTimerState;
    // TODO(b/316425811 remove the workaround)
    private int mNrAdvancedBandsSecondaryTimer;
    @NonNull private String mPreviousState;
    @LinkStatus private int mPhysicalLinkStatus;
    private boolean mIsPhysicalChannelConfig16Supported;
@@ -192,6 +194,8 @@ public class NetworkTypeController extends StateMachine {

    // Ratchet physical channel config fields to prevent 5G/5G+ flickering
    @NonNull private Set<Integer> mRatchetedNrBands = new HashSet<>();
    // TODO(b/316425811 remove the workaround)
    private boolean mLastShownNrDueToAdvancedBand = false;
    private int mRatchetedNrBandwidths = 0;
    private int mLastAnchorNrCellId = PhysicalChannelConfig.PHYSICAL_CELL_ID_UNKNOWN;
    private boolean mDoesPccListIndicateIdle = false;
@@ -362,6 +366,8 @@ public class NetworkTypeController extends StateMachine {
                    mNrPhysicalLinkStatusChangedCallback);
            mNrPhysicalLinkStatusChangedCallback = null;
        }
        mNrAdvancedBandsSecondaryTimer = config.getInt(
                CarrierConfigManager.KEY_NR_ADVANCED_BANDS_SECONDARY_TIMER_SECONDS_INT);
        String nrIconConfiguration = config.getString(
                CarrierConfigManager.KEY_5G_ICON_CONFIGURATION_STRING);
        String overrideTimerRule = config.getString(
@@ -659,6 +665,7 @@ public class NetworkTypeController extends StateMachine {
                    mIsSecondaryTimerActive = false;
                    mSecondaryTimerState = "";
                    updateTimers();
                    mLastShownNrDueToAdvancedBand = false;
                    updateOverrideNetworkType();
                    break;
                case EVENT_RADIO_OFF_OR_UNAVAILABLE:
@@ -1139,7 +1146,11 @@ public class NetworkTypeController extends StateMachine {

        @Override
        public boolean processMessage(Message msg) {
            if (DBG) log("NrConnectedAdvancedState: process " + getEventName(msg.what));
            mLastShownNrDueToAdvancedBand = isAdditionalNrAdvancedBand(mRatchetedNrBands);
            if (DBG) {
                log("NrConnectedAdvancedState: process " + getEventName(msg.what)
                        + ", been using advanced band is " + mLastShownNrDueToAdvancedBand);
            }
            updateTimers();
            AsyncResult ar;
            switch (msg.what) {
@@ -1325,6 +1336,10 @@ public class NetworkTypeController extends StateMachine {
        }
        if (!mIsDeviceIdleMode && rule != null && rule.getSecondaryTimer(currentName) > 0) {
            int duration = rule.getSecondaryTimer(currentName);
            if (mLastShownNrDueToAdvancedBand && mNrAdvancedBandsSecondaryTimer > 0) {
                duration = mNrAdvancedBandsSecondaryTimer;
                if (DBG) log("secondary timer adjusted by nr_advanced_bands_secondary_timer_long");
            }
            if (DBG) log(duration + "s secondary timer started for state: " + currentName);
            mSecondaryTimerState = currentName;
            mPreviousState = currentName;
@@ -1429,6 +1444,8 @@ public class NetworkTypeController extends StateMachine {
        mIsSecondaryTimerActive = false;
        mPrimaryTimerState = "";
        mSecondaryTimerState = "";

        mLastShownNrDueToAdvancedBand = false;
    }

    private boolean isTimerActiveForRrcIdle() {
+83 −0
Original line number Diff line number Diff line
@@ -1429,6 +1429,89 @@ public class NetworkTypeControllerTest extends TelephonyTest {
        assertFalse(mNetworkTypeController.areAnyTimersActive());
    }

    @Test
    public void testSecondaryTimerAdvanceBand() throws Exception {
        doReturn(true).when(mFeatureFlags).supportNrSaRrcIdle();
        doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(mServiceState).getNrState();
        doReturn(ServiceState.FREQUENCY_RANGE_HIGH).when(mServiceState).getNrFrequencyRange();
        ArrayList<PhysicalChannelConfig> physicalChannelConfigs = new ArrayList<>();
        // use advanced band
        physicalChannelConfigs.add(new PhysicalChannelConfig.Builder()
                .setPhysicalCellId(1)
                .setNetworkType(TelephonyManager.NETWORK_TYPE_NR)
                .setCellConnectionStatus(CellInfo.CONNECTION_PRIMARY_SERVING)
                .setBand(41)
                .build());
        doReturn(physicalChannelConfigs).when(mSST).getPhysicalChannelConfigList();
        mBundle.putIntArray(CarrierConfigManager.KEY_ADDITIONAL_NR_ADVANCED_BANDS_INT_ARRAY,
                new int[]{41});
        mBundle.putString(CarrierConfigManager.KEY_5G_ICON_DISPLAY_GRACE_PERIOD_STRING,
                "connected_mmwave,any,10");
        mBundle.putString(CarrierConfigManager.KEY_5G_ICON_DISPLAY_SECONDARY_GRACE_PERIOD_STRING,
                "connected_mmwave,any,5");
        mBundle.putInt(CarrierConfigManager.KEY_NR_ADVANCED_BANDS_SECONDARY_TIMER_SECONDS_INT,
                20);
        sendCarrierConfigChanged();

        assertEquals("connected_mmwave", getCurrentState().getName());
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED,
                mNetworkTypeController.getOverrideNetworkType());

        // lost the advance band, trigger 10 second connected_mmwave -> connected primary timer
        physicalChannelConfigs.clear();
        physicalChannelConfigs.add(new PhysicalChannelConfig.Builder()
                .setPhysicalCellId(1)
                .setNetworkType(TelephonyManager.NETWORK_TYPE_NR)
                .setCellConnectionStatus(CellInfo.CONNECTION_PRIMARY_SERVING)
                .build());
        mNetworkTypeController.sendMessage(11 /* EVENT_PHYSICAL_CHANNEL_CONFIGS_CHANGED */,
                new AsyncResult(null, physicalChannelConfigs, null));
        processAllMessages();

        assertEquals("connected", getCurrentState().getName());
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED,
                mNetworkTypeController.getOverrideNetworkType());
        assertTrue(mNetworkTypeController.areAnyTimersActive());

        // switch to connected_rrc_idle before primary timer expires
        physicalChannelConfigs.clear();
        mNetworkTypeController.sendMessage(11 /* EVENT_PHYSICAL_CHANNEL_CONFIGS_CHANGED */,
                new AsyncResult(null, physicalChannelConfigs, null));
        processAllMessages();

        assertEquals("connected_rrc_idle", getCurrentState().getName());
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED,
                mNetworkTypeController.getOverrideNetworkType());
        assertTrue(mNetworkTypeController.areAnyTimersActive());

        // primary timer expires
        moveTimeForward(10 * 1000);
        processAllMessages();

        // should trigger 20(not 5) seconds connected_mmwave -> connected_rrc_idle secondary timer
        assertEquals("connected_rrc_idle", getCurrentState().getName());
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED,
                mNetworkTypeController.getOverrideNetworkType());
        assertTrue(mNetworkTypeController.areAnyTimersActive());

        // 5 seconds passed during connected_mmwave -> connected_rrc_idle secondary timer
        moveTimeForward(5 * 1000);
        processAllMessages();
        assertEquals("connected_rrc_idle", getCurrentState().getName());
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED,
                mNetworkTypeController.getOverrideNetworkType());
        assertTrue(mNetworkTypeController.areAnyTimersActive());

        // secondary timer expired
        moveTimeForward(15 * 1000);
        processAllMessages();

        assertEquals("connected_rrc_idle", getCurrentState().getName());
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA,
                mNetworkTypeController.getOverrideNetworkType());
        assertFalse(mNetworkTypeController.areAnyTimersActive());
    }

    @Test
    public void testSecondaryTimerExpireNrIdle() throws Exception {
        doReturn(true).when(mFeatureFlags).supportNrSaRrcIdle();