blob: dbf0eb7ec3a65deb11b0c6c92d87c88083052de1 [file] [log] [blame]
Sarah Chinfc5603b2021-12-21 11:34:00 -08001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <aidl/android/hardware/radio/config/IRadioConfig.h>
18#include <android-base/logging.h>
19#include <android/binder_manager.h>
20#include <algorithm>
21
22#include "radio_data_utils.h"
23
24#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
25
26void RadioDataTest::SetUp() {
27 std::string serviceName = GetParam();
28
29 if (!isServiceValidForDeviceConfiguration(serviceName)) {
30 ALOGI("Skipped the test due to device configuration.");
31 GTEST_SKIP();
32 }
33
34 radio_data = IRadioData::fromBinder(
35 ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
36 ASSERT_NE(nullptr, radio_data.get());
37
38 radioRsp_data = ndk::SharedRefBase::make<RadioDataResponse>(*this);
39 ASSERT_NE(nullptr, radioRsp_data.get());
40
41 count_ = 0;
42
43 radioInd_data = ndk::SharedRefBase::make<RadioDataIndication>(*this);
44 ASSERT_NE(nullptr, radioInd_data.get());
45
46 radio_data->setResponseFunctions(radioRsp_data, radioInd_data);
47
48 // Assert IRadioConfig exists before testing
49 std::shared_ptr<aidl::android::hardware::radio::config::IRadioConfig> radioConfig =
50 aidl::android::hardware::radio::config::IRadioConfig::fromBinder(
51 ndk::SpAIBinder(AServiceManager_waitForService(
52 "android.hardware.radio.config.IRadioConfig/default")));
53 ASSERT_NE(nullptr, radioConfig.get());
54}
55
56ndk::ScopedAStatus RadioDataTest::getDataCallList() {
57 serial = GetRandomSerialNumber();
58 radio_data->getDataCallList(serial);
59 EXPECT_EQ(std::cv_status::no_timeout, wait());
60 return ndk::ScopedAStatus::ok();
61}
62
63/*
64 * Test IRadioData.setupDataCall() for the response returned.
65 */
66TEST_P(RadioDataTest, setupDataCall) {
67 serial = GetRandomSerialNumber();
68
69 AccessNetwork accessNetwork = AccessNetwork::EUTRAN;
70
71 DataProfileInfo dataProfileInfo;
72 memset(&dataProfileInfo, 0, sizeof(dataProfileInfo));
73 dataProfileInfo.profileId = DataProfileInfo::ID_DEFAULT;
74 dataProfileInfo.apn = std::string("internet");
75 dataProfileInfo.protocol = PdpProtocolType::IP;
76 dataProfileInfo.roamingProtocol = PdpProtocolType::IP;
77 dataProfileInfo.authType = ApnAuthType::NO_PAP_NO_CHAP;
78 dataProfileInfo.user = std::string("username");
79 dataProfileInfo.password = std::string("password");
80 dataProfileInfo.type = DataProfileInfo::TYPE_THREE_GPP;
81 dataProfileInfo.maxConnsTime = 300;
82 dataProfileInfo.maxConns = 20;
83 dataProfileInfo.waitTime = 0;
84 dataProfileInfo.enabled = true;
85 // TODO(b/210712359): 320 was the previous value; need to support bitmaps
86 dataProfileInfo.supportedApnTypesBitmap = ApnTypes::DEFAULT;
87 // TODO(b/210712359): 161543 was the previous value; need to support bitmaps
88 dataProfileInfo.bearerBitmap = RadioAccessFamily::LTE;
89 dataProfileInfo.mtuV4 = 0;
90 dataProfileInfo.mtuV6 = 0;
91 dataProfileInfo.preferred = true;
92 dataProfileInfo.persistent = false;
93
94 bool roamingAllowed = false;
95
96 std::vector<LinkAddress> addresses = {};
97 std::vector<std::string> dnses = {};
98
99 DataRequestReason reason = DataRequestReason::NORMAL;
100 SliceInfo sliceInfo;
101 bool matchAllRuleAllowed = true;
102
103 ndk::ScopedAStatus res =
104 radio_data->setupDataCall(serial, accessNetwork, dataProfileInfo, roamingAllowed,
105 reason, addresses, dnses, -1, sliceInfo, matchAllRuleAllowed);
106 ASSERT_OK(res);
107
108 EXPECT_EQ(std::cv_status::no_timeout, wait());
109 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_data->rspInfo.type);
110 EXPECT_EQ(serial, radioRsp_data->rspInfo.serial);
111 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
112 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error,
113 {RadioError::SIM_ABSENT, RadioError::RADIO_NOT_AVAILABLE,
114 RadioError::OP_NOT_ALLOWED_BEFORE_REG_TO_NW}));
115 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
116 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error,
117 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
118 RadioError::OP_NOT_ALLOWED_BEFORE_REG_TO_NW}));
119 }
120}
121
122/*
123 * Test IRadioData.setupDataCall() with osAppId for the response returned.
124 */
125TEST_P(RadioDataTest, setupDataCall_osAppId) {
126 serial = GetRandomSerialNumber();
127
128 AccessNetwork accessNetwork = AccessNetwork::EUTRAN;
129
130 TrafficDescriptor trafficDescriptor;
131 OsAppId osAppId;
132 std::string osAppIdString("osAppId");
133 // TODO(b/210712359): there should be a cleaner way to convert this
134 std::vector<unsigned char> output(osAppIdString.length());
135 std::transform(osAppIdString.begin(), osAppIdString.end(), output.begin(),
136 [](char c) { return static_cast<unsigned char>(c); });
137 osAppId.osAppId = output;
138 trafficDescriptor.osAppId = osAppId;
139
140 DataProfileInfo dataProfileInfo;
141 memset(&dataProfileInfo, 0, sizeof(dataProfileInfo));
142 dataProfileInfo.profileId = DataProfileInfo::ID_DEFAULT;
143 dataProfileInfo.apn = std::string("internet");
144 dataProfileInfo.protocol = PdpProtocolType::IP;
145 dataProfileInfo.roamingProtocol = PdpProtocolType::IP;
146 dataProfileInfo.authType = ApnAuthType::NO_PAP_NO_CHAP;
147 dataProfileInfo.user = std::string("username");
148 dataProfileInfo.password = std::string("password");
149 dataProfileInfo.type = DataProfileInfo::TYPE_THREE_GPP;
150 dataProfileInfo.maxConnsTime = 300;
151 dataProfileInfo.maxConns = 20;
152 dataProfileInfo.waitTime = 0;
153 dataProfileInfo.enabled = true;
154 // TODO(b/210712359): 320 was the previous value; need to support bitmaps
155 dataProfileInfo.supportedApnTypesBitmap = ApnTypes::DEFAULT;
156 // TODO(b/210712359): 161543 was the previous value; need to support bitmaps
157 dataProfileInfo.bearerBitmap = RadioAccessFamily::LTE;
158 dataProfileInfo.mtuV4 = 0;
159 dataProfileInfo.mtuV6 = 0;
160 dataProfileInfo.preferred = true;
161 dataProfileInfo.persistent = false;
162 dataProfileInfo.trafficDescriptor = trafficDescriptor;
163
164 bool roamingAllowed = false;
165
166 std::vector<LinkAddress> addresses = {};
167 std::vector<std::string> dnses = {};
168
169 DataRequestReason reason = DataRequestReason::NORMAL;
170 SliceInfo sliceInfo;
171 bool matchAllRuleAllowed = true;
172
173 ndk::ScopedAStatus res =
174 radio_data->setupDataCall(serial, accessNetwork, dataProfileInfo, roamingAllowed,
175 reason, addresses, dnses, -1, sliceInfo, matchAllRuleAllowed);
176 ASSERT_OK(res);
177
178 EXPECT_EQ(std::cv_status::no_timeout, wait());
179 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_data->rspInfo.type);
180 EXPECT_EQ(serial, radioRsp_data->rspInfo.serial);
181 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
182 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error,
183 {RadioError::SIM_ABSENT, RadioError::RADIO_NOT_AVAILABLE,
184 RadioError::OP_NOT_ALLOWED_BEFORE_REG_TO_NW}));
185 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
186 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error,
187 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
188 RadioError::OP_NOT_ALLOWED_BEFORE_REG_TO_NW}));
189 if (radioRsp_data->setupDataCallResult.trafficDescriptors.size() <= 0) {
190 return;
191 }
192 EXPECT_EQ(trafficDescriptor.osAppId.value().osAppId,
193 radioRsp_data->setupDataCallResult.trafficDescriptors[0].osAppId.value().osAppId);
194 }
195}
196
197/*
198 * Test IRadioData.getSlicingConfig() for the response returned.
199 */
200TEST_P(RadioDataTest, getSlicingConfig) {
201 serial = GetRandomSerialNumber();
202 radio_data->getSlicingConfig(serial);
203 EXPECT_EQ(std::cv_status::no_timeout, wait());
204 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_data->rspInfo.type);
205 EXPECT_EQ(serial, radioRsp_data->rspInfo.serial);
206 if (getRadioHalCapabilities()) {
207 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error,
208 {RadioError::REQUEST_NOT_SUPPORTED}));
209 } else {
210 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error,
211 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
212 RadioError::INTERNAL_ERR, RadioError::MODEM_ERR}));
213 }
214}
215
216/*
217 * Test IRadioData.setDataThrottling() for the response returned.
218 */
219TEST_P(RadioDataTest, setDataThrottling) {
220 serial = GetRandomSerialNumber();
221
222 ndk::ScopedAStatus res = radio_data->setDataThrottling(
223 serial, DataThrottlingAction::THROTTLE_SECONDARY_CARRIER, 60000);
224 ASSERT_OK(res);
225
226 EXPECT_EQ(std::cv_status::no_timeout, wait());
227 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_data->rspInfo.type);
228 EXPECT_EQ(serial, radioRsp_data->rspInfo.serial);
229 if (getRadioHalCapabilities()) {
230 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error,
231 {RadioError::REQUEST_NOT_SUPPORTED, RadioError::NONE}));
232 } else {
233 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error,
234 {RadioError::RADIO_NOT_AVAILABLE, RadioError::MODEM_ERR,
235 RadioError::NONE, RadioError::INVALID_ARGUMENTS}));
236 }
237
238 sleep(1);
239 serial = GetRandomSerialNumber();
240
241 res = radio_data->setDataThrottling(serial, DataThrottlingAction::THROTTLE_ANCHOR_CARRIER,
242 60000);
243 ASSERT_OK(res);
244 EXPECT_EQ(std::cv_status::no_timeout, wait());
245 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_data->rspInfo.type);
246 EXPECT_EQ(serial, radioRsp_data->rspInfo.serial);
247 if (getRadioHalCapabilities()) {
248 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error,
249 {RadioError::REQUEST_NOT_SUPPORTED, RadioError::NONE}));
250 } else {
251 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error,
252 {RadioError::RADIO_NOT_AVAILABLE, RadioError::MODEM_ERR,
253 RadioError::NONE, RadioError::INVALID_ARGUMENTS}));
254 }
255
256 sleep(1);
257 serial = GetRandomSerialNumber();
258
259 res = radio_data->setDataThrottling(serial, DataThrottlingAction::HOLD, 60000);
260 ASSERT_OK(res);
261
262 EXPECT_EQ(std::cv_status::no_timeout, wait());
263 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_data->rspInfo.type);
264 EXPECT_EQ(serial, radioRsp_data->rspInfo.serial);
265 if (getRadioHalCapabilities()) {
266 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error,
267 {RadioError::REQUEST_NOT_SUPPORTED, RadioError::NONE}));
268 } else {
269 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error,
270 {RadioError::RADIO_NOT_AVAILABLE, RadioError::MODEM_ERR,
271 RadioError::NONE, RadioError::INVALID_ARGUMENTS}));
272 }
273
274 sleep(1);
275 serial = GetRandomSerialNumber();
276
277 res = radio_data->setDataThrottling(serial, DataThrottlingAction::NO_DATA_THROTTLING, 60000);
278 ASSERT_OK(res);
279 EXPECT_EQ(std::cv_status::no_timeout, wait());
280 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_data->rspInfo.type);
281 EXPECT_EQ(serial, radioRsp_data->rspInfo.serial);
282 if (getRadioHalCapabilities()) {
283 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error,
284 {RadioError::REQUEST_NOT_SUPPORTED, RadioError::NONE}));
285 } else {
286 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error,
287 {RadioError::RADIO_NOT_AVAILABLE, RadioError::MODEM_ERR,
288 RadioError::NONE, RadioError::INVALID_ARGUMENTS}));
289 }
290
291 sleep(1);
292}