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

Commit 71e4788b authored by Eric Schwarzenbach's avatar Eric Schwarzenbach Committed by android-build-merger
Browse files

Merge "Update ServiceState with PhysicalChannelConfigs."

am: 0853406b

Change-Id: I1c41c447ddac840e7bf5fd77e58d08059a2d34df
parents 34f2dd59 0853406b
Loading
Loading
Loading
Loading
+42 −6
Original line number Diff line number Diff line
@@ -22,12 +22,12 @@ 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.ArrayList;
import java.util.Arrays;

/**
 * This class loads configuration from CarrierConfig and uses it to determine
@@ -49,6 +49,28 @@ public class RatRatcheter {

    private final Phone mPhone;

    /**
     * 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;
@@ -60,7 +82,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;
@@ -75,19 +97,33 @@ public class RatRatcheter {
        }
    }

    public void ratchetRat(ServiceState oldSS, ServiceState newSS) {
    /** Ratchets RATs and cell bandwidths if oldSS and newSS have the same RAT family. */
    public void ratchet(ServiceState oldSS, ServiceState newSS) {
        int newVoiceRat = ratchetRat(oldSS.getRilVoiceRadioTechnology(),
                newSS.getRilVoiceRadioTechnology());
        int newDataRat = ratchetRat(oldSS.getRilDataRadioTechnology(),
                newSS.getRilDataRadioTechnology());
        boolean newUsingCA = oldSS.isUsingCarrierAggregation() ||
                newSS.isUsingCarrierAggregation();

        if (isSameRatFamily(oldSS, newSS)) {
            updateBandwidths(oldSS.getCellBandwidths(), newSS);
        }

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

        newSS.setRilVoiceRadioTechnology(newVoiceRat);
        newSS.setRilDataRadioTechnology(newDataRat);
        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) {
+14 −2
Original line number Diff line number Diff line
@@ -1430,6 +1430,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;

@@ -1439,6 +1444,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++) {
@@ -2628,11 +2640,11 @@ 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 (!hasLocationChanged && isDataInService) {
            mRatRatcheter.ratchetRat(mSS, mNewSS);
            mRatRatcheter.ratchet(mSS, mNewSS);
        }

        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));
    }
}