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

Commit ba018e07 authored by Eric Schwarzenbach's avatar Eric Schwarzenbach
Browse files

Update ServiceState with PhysicalChannelConfigs.

Updates the ServiceState cell bandwidths from PhysicalChannelConfig
indication. Uses the RatRatcheter to conditionally update the
ServiceState bandwidths iff the current PhysicalChannelConfigs have a
greater aggregate bandwidth than the current ServiceState bandwidths.
Ratchets the bandwidth list until cell change.

Bug: 72524533
Test: runtest frameworks-telephony
Change-Id: I46aaa0d4ab3660e79dab7d2dcf6105ca6575b973
Merged-In: I46aaa0d4ab3660e79dab7d2dcf6105ca6575b973
(cherry picked from commit 475cb714)
parent f675639d
Loading
Loading
Loading
Loading
+41 −6
Original line number Diff line number Diff line
@@ -22,11 +22,13 @@ import android.content.IntentFilter;
import android.os.PersistableBundle;
import android.os.UserHandle;
import android.telephony.CarrierConfigManager;
import android.telephony.ServiceState;
import android.telephony.Rlog;
import android.telephony.ServiceState;
import android.util.SparseArray;
import android.util.SparseIntArray;

import java.util.Arrays;

/**
 * This class loads configuration from CarrierConfig and uses it to determine
 * what RATs are within a ratcheting family.  For example all the HSPA/HSDPA/HSUPA RATs.
@@ -46,10 +48,31 @@ public class RatRatcheter {
    private final SparseArray<SparseIntArray> mRatFamilyMap = new SparseArray<>();

    private final Phone mPhone;

    private boolean mVoiceRatchetEnabled = true;
    private boolean mDataRatchetEnabled = true;

    /**
     * Updates the ServiceState with a new set of cell bandwidths IFF the new bandwidth list has a
     * higher aggregate bandwidth.
     *
     * @return Whether the bandwidths were updated.
     */
    public static boolean updateBandwidths(int[] bandwidths, ServiceState serviceState) {
        if (bandwidths == null) {
            return false;
        }

        int ssAggregateBandwidth = Arrays.stream(serviceState.getCellBandwidths()).sum();
        int newAggregateBandwidth = Arrays.stream(bandwidths).sum();

        if (newAggregateBandwidth > ssAggregateBandwidth) {
            serviceState.setCellBandwidths(bandwidths);
            return true;
        }

        return false;
    }

    /** Constructor */
    public RatRatcheter(Phone phone) {
        mPhone = phone;
@@ -61,7 +84,7 @@ public class RatRatcheter {
        resetRatFamilyMap();
    }

    public int ratchetRat(int oldRat, int newRat) {
    private int ratchetRat(int oldRat, int newRat) {
        synchronized (mRatFamilyMap) {
            final SparseIntArray oldFamily = mRatFamilyMap.get(oldRat);
            if (oldFamily == null) return newRat;
@@ -76,7 +99,11 @@ public class RatRatcheter {
        }
    }

    public void ratchetRat(ServiceState oldSS, ServiceState newSS, boolean locationChange) {
    /** Ratchets RATs and cell bandwidths if oldSS and newSS have the same RAT family. */
    public void ratchet(ServiceState oldSS, ServiceState newSS, boolean locationChange) {
        if (isSameRatFamily(oldSS, newSS)) {
            updateBandwidths(oldSS.getCellBandwidths(), newSS);
        }
        // temporarily disable rat ratchet on location change.
        if (locationChange) {
            mVoiceRatchetEnabled = false;
@@ -101,11 +128,19 @@ public class RatRatcheter {
            mVoiceRatchetEnabled = true;
        }

        boolean newUsingCA = oldSS.isUsingCarrierAggregation() ||
                newSS.isUsingCarrierAggregation();
        boolean newUsingCA = oldSS.isUsingCarrierAggregation()
                || newSS.isUsingCarrierAggregation()
                || newSS.getCellBandwidths().length > 1;
        newSS.setIsUsingCarrierAggregation(newUsingCA);
    }

    private boolean isSameRatFamily(ServiceState ss1, ServiceState ss2) {
        synchronized (mRatFamilyMap) {
            return mRatFamilyMap.get(ss1.getRilDataRadioTechnology())
                    == mRatFamilyMap.get(ss2.getRilDataRadioTechnology());
        }
    }

    private BroadcastReceiver mConfigChangedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
+16 −3
Original line number Diff line number Diff line
@@ -1431,6 +1431,11 @@ public class ServiceStateTracker extends Handler {
                                + list);
                    }
                    mPhone.notifyPhysicalChannelConfiguration(list);

                    // only notify if bandwidths changed
                    if (RatRatcheter.updateBandwidths(getBandwidthsFromConfigs(list), mSS)) {
                        mPhone.notifyServiceStateChanged(mSS);
                    }
                }
                break;

@@ -1440,6 +1445,13 @@ public class ServiceStateTracker extends Handler {
        }
    }

    private int[] getBandwidthsFromConfigs(List<PhysicalChannelConfig> list) {
        return list.stream()
                .map(PhysicalChannelConfig::getCellBandwidthDownlink)
                .mapToInt(Integer::intValue)
                .toArray();
    }

    protected boolean isSidsAllZeros() {
        if (mHomeSystemId != null) {
            for (int i=0; i < mHomeSystemId.length; i++) {
@@ -2645,11 +2657,12 @@ public class ServiceStateTracker extends Handler {

        boolean hasLocationChanged = !mNewCellLoc.equals(mCellLoc);

        // ratchet the new tech up through it's rat family but don't drop back down
        // ratchet the new tech up through its rat family but don't drop back down
        // until cell change or device is OOS
        boolean isDataInService = mNewSS.getDataRegState() == ServiceState.STATE_IN_SERVICE;
        if (isDataInService) {
            mRatRatcheter.ratchetRat(mSS, mNewSS, hasLocationChanged);

        if (!hasLocationChanged && isDataInService) {
            mRatRatcheter.ratchet(mSS, mNewSS, hasLocationChanged);
        }

        boolean hasRilVoiceRadioTechnologyChanged =
+71 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.telephony;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

import android.telephony.ServiceState;

import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;

/** Tests for RatRatcheter. */
public class RatRatcheterTest {

    private ServiceState mServiceState;

    @Before
    public void setUp() {
        mServiceState = new ServiceState();
    }

    @Test
    public void testUpdateBandwidthsSuccess() {
        int[] bandwidths = new int[] {1400, 5000};
        mServiceState.setCellBandwidths(new int[] {5000});

        boolean updated = RatRatcheter.updateBandwidths(bandwidths, mServiceState);

        assertTrue(updated);
        assertTrue(Arrays.equals(mServiceState.getCellBandwidths(), bandwidths));
    }

    @Test
    public void testUpdateBandwidthsFailure() {
        int[] originalBandwidths = {5000, 10000};
        int[] newBandwidths = {1400, 5000};
        mServiceState.setCellBandwidths(originalBandwidths);

        boolean updated = RatRatcheter.updateBandwidths(newBandwidths, mServiceState);

        assertFalse(updated);
        assertTrue(Arrays.equals(mServiceState.getCellBandwidths(), originalBandwidths));
    }

    @Test
    public void testUpdateBandwidthsNull() {
        int[] originalBandwidths = {5000, 10000};
        mServiceState.setCellBandwidths(originalBandwidths);

        boolean updated = RatRatcheter.updateBandwidths(null, mServiceState);

        assertFalse(updated);
        assertTrue(Arrays.equals(mServiceState.getCellBandwidths(), originalBandwidths));
    }
}