aboutsummaryrefslogtreecommitdiff
path: root/tests/telephonytests/src/com/android/internal/telephony/RatRatcheterTest.java
blob: b0cc83ee163fd2726fb60b7b9680e0b43d0d9d91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * 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.os.PersistableBundle;
import android.telephony.AccessNetworkConstants;
import android.telephony.CarrierConfigManager;
import android.telephony.LteVopsSupportInfo;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;

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

import java.util.Arrays;

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

    private ServiceState mServiceState;
    private PersistableBundle mBundle;

    @Before
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
        mServiceState = new ServiceState();
    }

    @After
    public void tearDown() throws Exception {
        super.tearDown();
    }

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

    private NetworkRegistrationInfo createNetworkRegistrationInfo(
            int domain, int accessNetworkTechnology, boolean isUsingCarrierAggregation) {

        LteVopsSupportInfo lteVopsSupportInfo =
                new LteVopsSupportInfo(LteVopsSupportInfo.LTE_STATUS_SUPPORTED,
                        LteVopsSupportInfo.LTE_STATUS_NOT_SUPPORTED);

        return new NetworkRegistrationInfo(
                domain,  // domain
                AccessNetworkConstants.TRANSPORT_TYPE_WWAN,  // transportType
                0,  // registrationState
                accessNetworkTechnology,  // accessNetworkTechnology
                0,  // rejectCause
                false,  // emergencyOnly
                null,  // availableServices
                null,  // cellIdentity
                null,  // rplmn
                0,  // maxDataCalls
                false,  // isDcNrRestricted
                false,  // isNrAvailable
                false,  // isEndcAvailable
                lteVopsSupportInfo,  // lteVopsSupportInfo
                isUsingCarrierAggregation);  // isUsingCarrierAggregation
    }

    private void setNetworkRegistrationInfo(ServiceState ss, int accessNetworkTechnology) {

        NetworkRegistrationInfo nri1;
        NetworkRegistrationInfo nri2;

        boolean isUsingCarrierAggregation = false;

        if (accessNetworkTechnology == TelephonyManager.NETWORK_TYPE_LTE_CA) {
            isUsingCarrierAggregation = true;
        }

        nri1 = createNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS,
                accessNetworkTechnology, isUsingCarrierAggregation);
        nri2 = createNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_CS,
                accessNetworkTechnology, isUsingCarrierAggregation);

        ss.addNetworkRegistrationInfo(nri1);
        ss.addNetworkRegistrationInfo(nri2);
    }

    @Test
    public void testRatchetIsFamily() {
        ServiceState oldSS = new ServiceState();
        ServiceState newSS = new ServiceState();

        mBundle = mContextFixture.getCarrierConfigBundle();
        mBundle.putStringArray(CarrierConfigManager.KEY_RATCHET_RAT_FAMILIES,
                new String[]{"14,19"});

        setNetworkRegistrationInfo(oldSS, TelephonyManager.NETWORK_TYPE_LTE_CA);
        setNetworkRegistrationInfo(newSS, TelephonyManager.NETWORK_TYPE_LTE);

        RatRatcheter ratRatcheter = new RatRatcheter(mPhone);
        ratRatcheter.ratchet(oldSS, newSS, false);

        assertTrue(newSS.isUsingCarrierAggregation());
    }

    @Test
    public void testRatchetIsNotFamily() {
        ServiceState oldSS = new ServiceState();
        ServiceState newSS = new ServiceState();

        mBundle = mContextFixture.getCarrierConfigBundle();
        mBundle.putStringArray(CarrierConfigManager.KEY_RATCHET_RAT_FAMILIES, new String[]{});

        setNetworkRegistrationInfo(oldSS, TelephonyManager.NETWORK_TYPE_LTE_CA);
        setNetworkRegistrationInfo(newSS, TelephonyManager.NETWORK_TYPE_LTE);

        RatRatcheter ratRatcheter = new RatRatcheter(mPhone);
        ratRatcheter.ratchet(oldSS, newSS, false);

        assertFalse(newSS.isUsingCarrierAggregation());
    }
}