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

Commit 1cfc399a authored by Zoey Chen's avatar Zoey Chen Committed by Gerrit Code Review
Browse files

Merge "[PhysicalChannelConfig] Add new testcases and Rename 1. the setRat...

Merge "[PhysicalChannelConfig] Add new testcases and Rename     1. the setRat to setNetworkType     2. PhysicalChannelConfiguration to PhysicalChannelConfig"
parents 6873b4b8 79f932f9
Loading
Loading
Loading
Loading
+47 −2
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ import android.hardware.radio.V1_0.StkCcUnsolSsResult;
import android.hardware.radio.V1_0.SuppSvcNotification;
import android.hardware.radio.V1_2.CellConnectionStatus;
import android.hardware.radio.V1_6.IRadioIndication;
import android.hardware.radio.V1_6.PhysicalChannelConfig.Band;
import android.os.AsyncResult;
import android.os.RemoteException;
import android.sysprop.TelephonyProperties;
@@ -1175,7 +1176,7 @@ public class RadioIndication extends IRadioIndication.Stub {
                builder.setFrequencyRange(config.rfInfo.range());
                break;
            case android.hardware.radio.V1_4.RadioFrequencyInfo.hidl_discriminator.channelNumber:
                builder.setChannelNumber(config.rfInfo.channelNumber());
                builder.setDownlinkChannelNumber(config.rfInfo.channelNumber());
                break;
            default:
                mRil.riljLoge("Unsupported frequency type " + config.rfInfo.getDiscriminator());
@@ -1196,6 +1197,35 @@ public class RadioIndication extends IRadioIndication.Stub {
        }
    }

    /**
     * Set the band from the physical channel config.
     *
     * @param builder the builder of {@link PhysicalChannelConfig}.
     * @param config physical channel config from ril.
     */
    public void setBandToBuilder(PhysicalChannelConfig.Builder builder,
            android.hardware.radio.V1_6.PhysicalChannelConfig config) {

        android.hardware.radio.V1_6.PhysicalChannelConfig.Band band = config.band;

        switch (band.getDiscriminator()) {
            case Band.hidl_discriminator.geranBand:
                builder.setBand(band.geranBand());
                break;
            case Band.hidl_discriminator.utranBand:
                builder.setBand(band.utranBand());
                break;
            case Band.hidl_discriminator.eutranBand:
                builder.setBand(band.eutranBand());
                break;
            case Band.hidl_discriminator.ngranBand:
                builder.setBand(band.ngranBand());
                break;
            default:
                mRil.riljLoge("Unsupported band type " + band.getDiscriminator());
        }
    }

    private void physicalChannelConfigsIndication(List<? extends Object> configs) {
        List<PhysicalChannelConfig> response = new ArrayList<>(configs.size());
        for (Object obj : configs) {
@@ -1216,7 +1246,22 @@ public class RadioIndication extends IRadioIndication.Stub {
                response.add(builder.setCellConnectionStatus(
                        convertConnectionStatusFromCellConnectionStatus(config.base.status))
                        .setCellBandwidthDownlinkKhz(config.base.cellBandwidthDownlink)
                        .setRat(ServiceState.rilRadioTechnologyToNetworkType(config.rat))
                        .setNetworkType(ServiceState.rilRadioTechnologyToNetworkType(config.rat))
                        .setPhysicalCellId(config.physicalCellId)
                        .setContextIds(config.contextIds.stream().mapToInt(x -> x).toArray())
                        .build());
            } else if (obj instanceof android.hardware.radio.V1_6.PhysicalChannelConfig) {
                android.hardware.radio.V1_6.PhysicalChannelConfig config =
                        (android.hardware.radio.V1_6.PhysicalChannelConfig) obj;
                PhysicalChannelConfig.Builder builder = new PhysicalChannelConfig.Builder();
                setBandToBuilder(builder, config);
                response.add(builder.setCellConnectionStatus(
                        convertConnectionStatusFromCellConnectionStatus(config.status))
                        .setDownlinkChannelNumber(config.downlinkChannelNumber)
                        .setUplinkChannelNumber(config.uplinkChannelNumber)
                        .setCellBandwidthDownlinkKhz(config.cellBandwidthDownlink)
                        .setCellBandwidthUplinkKhz(config.cellBandwidthUplink)
                        .setNetworkType(ServiceState.rilRadioTechnologyToNetworkType(config.rat))
                        .setPhysicalCellId(config.physicalCellId)
                        .setContextIds(config.contextIds.stream().mapToInt(x -> x).toArray())
                        .build());
+1 −1
Original line number Diff line number Diff line
@@ -1775,7 +1775,7 @@ public class ServiceStateTracker extends Handler {

    private int[] getBandwidthsFromConfigs(List<PhysicalChannelConfig> list) {
        return list.stream()
                .map(PhysicalChannelConfig::getCellBandwidthDownlink)
                .map(PhysicalChannelConfig::getCellBandwidthDownlinkKhz)
                .mapToInt(Integer::intValue)
                .toArray();
    }
+119 −25
Original line number Diff line number Diff line
@@ -17,63 +17,157 @@ package com.android.internal.telephony;

import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.fail;

import android.os.Parcel;
import android.telephony.AccessNetworkConstants;
import android.telephony.PhysicalChannelConfig;
import android.telephony.PhysicalChannelConfig.Builder;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;

import org.junit.Test;

/** Unit test for {@link android.telephony.PhysicalChannelConfig}. */
public class PhysicalChannelConfigTest {

    private static final int RAT = ServiceState.RIL_RADIO_TECHNOLOGY_LTE;
    private static final int NETWORK_TYPE_NR = TelephonyManager.NETWORK_TYPE_NR;
    private static final int NETWORK_TYPE_LTE = TelephonyManager.NETWORK_TYPE_LTE;
    private static final int NETWORK_TYPE_UMTS = TelephonyManager.NETWORK_TYPE_UMTS;
    private static final int NETWORK_TYPE_GSM = TelephonyManager.NETWORK_TYPE_GSM;
    private static final int CONNECTION_STATUS = PhysicalChannelConfig.CONNECTION_PRIMARY_SERVING;
    private static final int CELL_BANDWIDTH = 12345;
    private static final int FREQUENCY_RANGE = 1;
    private static final int CHANNEL_NUMBER = 1234;
    private static final int[] CONTEXT_IDS = new int[] {123, 555, 1, 0};
    private static final int PHYSICAL_CELL_ID = 502;
    private static final int BAND = 1;
    public static final int INVALID_FREQUENCY = -1;

    @Test
    public void testBuilder() {
        PhysicalChannelConfig config = new Builder()
                .setRat(RAT)
    private PhysicalChannelConfig mPhysicalChannelConfig;

    private void setUpPhysicalChannelConfig(int networkType, int band, int downlinkChannelNumber,
            int uplinkChannelNumber, int frequencyRange) {
        mPhysicalChannelConfig = new Builder()
                .setCellConnectionStatus(CONNECTION_STATUS)
                .setCellBandwidthDownlinkKhz(CELL_BANDWIDTH)
                .setFrequencyRange(FREQUENCY_RANGE)
                .setChannelNumber(CHANNEL_NUMBER)
                .setCellBandwidthUplinkKhz(CELL_BANDWIDTH)
                .setContextIds(CONTEXT_IDS)
                .setPhysicalCellId(PHYSICAL_CELL_ID)
                .setNetworkType(networkType)
                .setFrequencyRange(frequencyRange)
                .setDownlinkChannelNumber(downlinkChannelNumber)
                .setUplinkChannelNumber(uplinkChannelNumber)
                .setBand(band)
                .build();
    }

    @Test
    public void testDownlinkFrequencyForNrArfcn(){
        setUpPhysicalChannelConfig(NETWORK_TYPE_NR, AccessNetworkConstants.NgranBands.BAND_1,
                CHANNEL_NUMBER, CHANNEL_NUMBER, ServiceState.FREQUENCY_RANGE_MID);

        // 3GPP TS 38.104 Table 5.4.2.1-1, {@link AccessNetworkUtils#getFrequencyFromNrArfcn}.
        // Formula of NR-ARFCN convert to actual frequency:
        // Actual frequency(kHz) = (RANGE_OFFSET + GLOBAL_KHZ * (ARFCN - ARFCN_OFFSET))
        assertThat(mPhysicalChannelConfig.getDownlinkFrequencyKhz()).isEqualTo(6170);
    }

    @Test
    public void testDownlinkandUplinkFrequencyForEarfcn(){
        setUpPhysicalChannelConfig(NETWORK_TYPE_LTE, AccessNetworkConstants.EutranBand.BAND_3,
                CHANNEL_NUMBER, 19500, ServiceState.FREQUENCY_RANGE_MID);

        assertThat(config.getNetworkType()).isEqualTo(RAT);
        assertThat(config.getConnectionStatus()).isEqualTo(CONNECTION_STATUS);
        assertThat(config.getCellBandwidthDownlink()).isEqualTo(CELL_BANDWIDTH);
        assertThat(config.getFrequencyRange()).isEqualTo(FREQUENCY_RANGE);
        assertThat(config.getChannelNumber()).isEqualTo(CHANNEL_NUMBER);
        assertThat(config.getContextIds()).isEqualTo(CONTEXT_IDS);
        assertThat(config.getPhysicalCellId()).isEqualTo(PHYSICAL_CELL_ID);
        // 3GPP TS 36.101 Table 5.7.3-1, {@link AccessNetworkUtils#getFrequencyFromEarfcn}.
        // Formula of E-UTRA ARFCN convert to actual frequency:
        // Actual frequency(kHz) = (DOWNLINK_LOW + 0.1 * (ARFCN - DOWNLINK_OFFSET)) * FREQUENCY_KHZ
        // Actual frequency(kHz) = (UPLINK_LOW + 0.1 * (ARFCN - UPLINK_OFFSET)) * FREQUENCY_KHZ
        assertThat(mPhysicalChannelConfig.getDownlinkFrequencyKhz()).isEqualTo(1808400);
        assertThat(mPhysicalChannelConfig.getUplinkFrequencyKhz()).isEqualTo(1740000);
    }

    @Test
    public void testDownlinkandUplinkFrequencyForUarfcn(){
        setUpPhysicalChannelConfig(NETWORK_TYPE_UMTS, AccessNetworkConstants.UtranBand.BAND_3,
                CHANNEL_NUMBER, 940, ServiceState.FREQUENCY_RANGE_MID);

        // 3GPP TS 25.101, {@link AccessNetworkUtils#getFrequencyFromUarfcn}.
        // Formula of UTRA ARFCN convert to actual frequency:
        // For general bands:
        // Downlink actual frequency(kHz) = (DOWNLINK_OFFSET + 0.2 * ARFCN) * FREQUENCY_KHZ
        // Uplink actual frequency(kHz) = (UPLINK_OFFSET + 0.2 * ARFCN) * FREQUENCY_KHZ
        assertThat(mPhysicalChannelConfig.getDownlinkFrequencyKhz()).isEqualTo(1821800);
        assertThat(mPhysicalChannelConfig.getUplinkFrequencyKhz()).isEqualTo(1713000);
    }

    @Test
    public void testDownlinkFrequencyForArfcn(){
        setUpPhysicalChannelConfig(NETWORK_TYPE_GSM, AccessNetworkConstants.GeranBand.BAND_450,
                270, 270, ServiceState.FREQUENCY_RANGE_LOW);

        // 3GPP TS 45.005 Table 2-1 Dynamically mapped ARFCN
        // Formula of Geran ARFCN convert to actual frequency:
        // Uplink actual frequency(kHz) =
        //       (UPLINK_FREQUENCY_FIRST + 0.2 * (ARFCN - ARFCN_RANGE_FIRST)) * FREQUENCY_KHZ
        // Downlink actual frequency(kHz) = Uplink actual frequency + 10
        assertThat(mPhysicalChannelConfig.getDownlinkFrequencyKhz()).isEqualTo(452810);
    }

    @Test
    public void testDownlinkandUplinkFrequencyForEarfcnWithIncorrectRange() {
        setUpPhysicalChannelConfig(NETWORK_TYPE_LTE, AccessNetworkConstants.EutranBand.BAND_3,
                900, 900, ServiceState.FREQUENCY_RANGE_MID);

        assertThat(mPhysicalChannelConfig.getDownlinkFrequencyKhz()).isEqualTo(INVALID_FREQUENCY);
    }

    @Test
    public void testFrequencyRangeWithoutBand() {
        try {
            setUpPhysicalChannelConfig(NETWORK_TYPE_UMTS, 0, CHANNEL_NUMBER, CHANNEL_NUMBER,
                    ServiceState.FREQUENCY_RANGE_UNKNOWN);
            fail("Frequency range: 0 is invalid.");
        } catch (IllegalArgumentException e) {
        }
    }

    @Test
    public void testFrequencyRangeForNrArfcn() {
        setUpPhysicalChannelConfig(NETWORK_TYPE_NR, AccessNetworkConstants.NgranBands.BAND_79,
                4500, 4500, ServiceState.FREQUENCY_RANGE_HIGH);

        assertThat(mPhysicalChannelConfig.getFrequencyRange()).isEqualTo(
                ServiceState.FREQUENCY_RANGE_HIGH);
    }

    @Test
    public void testBuilder() {
        setUpPhysicalChannelConfig(NETWORK_TYPE_LTE, BAND, CHANNEL_NUMBER, CHANNEL_NUMBER,
                FREQUENCY_RANGE);

        assertThat(mPhysicalChannelConfig.getNetworkType()).isEqualTo(NETWORK_TYPE_LTE);
        assertThat(mPhysicalChannelConfig.getConnectionStatus()).isEqualTo(CONNECTION_STATUS);
        assertThat(mPhysicalChannelConfig.getCellBandwidthDownlinkKhz()).isEqualTo(CELL_BANDWIDTH);
        assertThat(mPhysicalChannelConfig.getCellBandwidthUplinkKhz()).isEqualTo(CELL_BANDWIDTH);
        assertThat(mPhysicalChannelConfig.getFrequencyRange()).isEqualTo(FREQUENCY_RANGE);
        assertThat(mPhysicalChannelConfig.getChannelNumber()).isEqualTo(CHANNEL_NUMBER);
        assertThat(mPhysicalChannelConfig.getContextIds()).isEqualTo(CONTEXT_IDS);
        assertThat(mPhysicalChannelConfig.getPhysicalCellId()).isEqualTo(PHYSICAL_CELL_ID);
        assertThat(mPhysicalChannelConfig.getDownlinkChannelNumber()).isEqualTo(CHANNEL_NUMBER);
        assertThat(mPhysicalChannelConfig.getUplinkChannelNumber()).isEqualTo(CHANNEL_NUMBER);
    }

    @Test
    public void testParcel() {
        PhysicalChannelConfig config = new Builder()
                .setRat(RAT)
                .setCellConnectionStatus(CONNECTION_STATUS)
                .setCellBandwidthDownlinkKhz(CELL_BANDWIDTH)
                .setFrequencyRange(FREQUENCY_RANGE)
                .setChannelNumber(CHANNEL_NUMBER)
                .setContextIds(CONTEXT_IDS)
                .setPhysicalCellId(PHYSICAL_CELL_ID)
                .build();
        setUpPhysicalChannelConfig(NETWORK_TYPE_LTE, BAND, CHANNEL_NUMBER, CHANNEL_NUMBER,
                ServiceState.FREQUENCY_RANGE_MID);

        Parcel parcel = Parcel.obtain();
        config.writeToParcel(parcel, 0 /* flags */);
        mPhysicalChannelConfig.writeToParcel(parcel, 0 /* flags */);
        parcel.setDataPosition(0);

        PhysicalChannelConfig fromParcel = PhysicalChannelConfig.CREATOR.createFromParcel(parcel);

        assertThat(fromParcel).isEqualTo(config);
        assertThat(fromParcel).isEqualTo(mPhysicalChannelConfig);
    }
}