1 /*
2 * Copyright (C) 2017 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 <android-base/logging.h>
18 #include <android/hardware/radio/1.2/IRadio.h>
19 #include <gtest/gtest.h>
20 #include <radio_hidl_hal_utils_v1_0.h>
21
22 using namespace ::android::hardware::radio::V1_0;
23
24 /*
25 * Test IRadio.getDataRegistrationState() for the response returned.
26 */
TEST_P(RadioHidlTest,getDataRegistrationState)27 TEST_P(RadioHidlTest, getDataRegistrationState) {
28 LOG(DEBUG) << "getDataRegistrationState";
29 serial = GetRandomSerialNumber();
30
31 radio->getDataRegistrationState(serial);
32
33 EXPECT_EQ(std::cv_status::no_timeout, wait());
34 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
35 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
36
37 if (cardStatus.cardState == CardState::ABSENT) {
38 EXPECT_EQ(RadioError::NONE, radioRsp->rspInfo.error);
39 } else if (cardStatus.cardState == CardState::PRESENT) {
40 ASSERT_TRUE(CheckAnyOfErrors(
41 radioRsp->rspInfo.error,
42 {RadioError::NONE, RadioError::NOT_PROVISIONED, RadioError::CANCELLED}));
43
44 // Check the mcc [0, 999] and mnc [0, 999].
45 string hidl_mcc;
46 string hidl_mnc;
47 bool checkMccMnc = true;
48 int totalIdentitySizeExpected = 1;
49 CellIdentity cellIdentities = radioRsp->dataRegResp.cellIdentity;
50 CellInfoType cellInfoType = cellIdentities.cellInfoType;
51
52 if (cellInfoType == CellInfoType::NONE) {
53 // All the fields are 0
54 totalIdentitySizeExpected = 0;
55 checkMccMnc = false;
56 } else if (cellInfoType == CellInfoType::GSM) {
57 EXPECT_EQ(1, cellIdentities.cellIdentityGsm.size());
58 CellIdentityGsm cig = cellIdentities.cellIdentityGsm[0];
59 hidl_mcc = cig.mcc;
60 hidl_mnc = cig.mnc;
61 } else if (cellInfoType == CellInfoType::LTE) {
62 EXPECT_EQ(1, cellIdentities.cellIdentityLte.size());
63 CellIdentityLte cil = cellIdentities.cellIdentityLte[0];
64 hidl_mcc = cil.mcc;
65 hidl_mnc = cil.mnc;
66 } else if (cellInfoType == CellInfoType::WCDMA) {
67 EXPECT_EQ(1, cellIdentities.cellIdentityWcdma.size());
68 CellIdentityWcdma ciw = cellIdentities.cellIdentityWcdma[0];
69 hidl_mcc = ciw.mcc;
70 hidl_mnc = ciw.mnc;
71 } else if (cellInfoType == CellInfoType::TD_SCDMA) {
72 EXPECT_EQ(1, cellIdentities.cellIdentityTdscdma.size());
73 CellIdentityTdscdma cit = cellIdentities.cellIdentityTdscdma[0];
74 hidl_mcc = cit.mcc;
75 hidl_mnc = cit.mnc;
76 } else if (cellInfoType == CellInfoType::CDMA) {
77 // CellIndentityCdma has no mcc and mnc.
78 EXPECT_EQ(CellInfoType::CDMA, cellInfoType);
79 EXPECT_EQ(1, cellIdentities.cellIdentityCdma.size());
80 checkMccMnc = false;
81 } else {
82 // This test can be skipped for newer networks if a new RAT (e.g. 5g) that was not
83 // supported in this version is added to the response from a modem that supports a new
84 // version of this interface.
85 GTEST_SKIP() << "Exempt from 1.0 test: camped on a new network:" << (int)cellInfoType;
86 }
87
88 // Check only one CellIdentity is size 1, and others must be 0.
89 EXPECT_EQ(totalIdentitySizeExpected, cellIdentities.cellIdentityGsm.size() +
90 cellIdentities.cellIdentityCdma.size() +
91 cellIdentities.cellIdentityLte.size() +
92 cellIdentities.cellIdentityWcdma.size() +
93 cellIdentities.cellIdentityTdscdma.size());
94
95 if (checkMccMnc) {
96 // 32 bit system gets result: "\xff\xff\xff..." from RIL, which is not testable.
97 // Only test for 64 bit here. TODO: remove this limit after b/113181277 being fixed.
98 int mccSize = hidl_mcc.size();
99 EXPECT_TRUE(mccSize == 0 || mccSize == 3);
100 if (mccSize > 0) {
101 int mcc = stoi(hidl_mcc);
102 EXPECT_TRUE(mcc >= 0 && mcc <= 999);
103 }
104
105 int mncSize = hidl_mnc.size();
106 EXPECT_TRUE(mncSize == 0 || mncSize == 2 || mncSize == 3);
107 if (mncSize > 0) {
108 int mnc = stoi(hidl_mnc);
109 EXPECT_TRUE(mnc >= 0 && mnc <= 999);
110 }
111 }
112 }
113 LOG(DEBUG) << "getDataRegistrationState finished";
114 }
115
116 /*
117 * Test IRadio.setupDataCall() for the response returned.
118 */
TEST_P(RadioHidlTest,setupDataCall)119 TEST_P(RadioHidlTest, setupDataCall) {
120 LOG(DEBUG) << "setupDataCall";
121 serial = GetRandomSerialNumber();
122
123 RadioTechnology radioTechnology = RadioTechnology::LTE;
124
125 DataProfileInfo dataProfileInfo;
126 memset(&dataProfileInfo, 0, sizeof(dataProfileInfo));
127 dataProfileInfo.profileId = DataProfileId::IMS;
128 dataProfileInfo.apn = hidl_string("VZWIMS");
129 dataProfileInfo.protocol = hidl_string("IPV4V6");
130 dataProfileInfo.roamingProtocol = hidl_string("IPV6");
131 dataProfileInfo.authType = ApnAuthType::NO_PAP_NO_CHAP;
132 dataProfileInfo.user = "";
133 dataProfileInfo.password = "";
134 dataProfileInfo.type = DataProfileInfoType::THREE_GPP2;
135 dataProfileInfo.maxConnsTime = 300;
136 dataProfileInfo.maxConns = 20;
137 dataProfileInfo.waitTime = 0;
138 dataProfileInfo.enabled = true;
139 dataProfileInfo.supportedApnTypesBitmap = 320;
140 dataProfileInfo.bearerBitmap = 161543;
141 dataProfileInfo.mtu = 0;
142 dataProfileInfo.mvnoType = MvnoType::NONE;
143 dataProfileInfo.mvnoMatchData = hidl_string();
144
145 bool modemCognitive = false;
146 bool roamingAllowed = false;
147 bool isRoaming = false;
148
149 radio->setupDataCall(serial, radioTechnology, dataProfileInfo, modemCognitive, roamingAllowed,
150 isRoaming);
151
152 EXPECT_EQ(std::cv_status::no_timeout, wait(300));
153 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
154 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
155
156 // setupDataCall is deprecated on radio::V1_2 with setupDataCall_1_2
157 SKIP_TEST_IF_REQUEST_NOT_SUPPORTED_WITH_HAL_VERSION_AT_LEAST(1_2);
158
159 if (cardStatus.cardState == CardState::ABSENT) {
160 ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
161 {RadioError::NONE, RadioError::OP_NOT_ALLOWED_BEFORE_REG_TO_NW,
162 RadioError::OP_NOT_ALLOWED_DURING_VOICE_CALL,
163 RadioError::RADIO_NOT_AVAILABLE, RadioError::SIM_ABSENT},
164 CHECK_OEM_ERROR));
165 }
166 LOG(DEBUG) << "setupDataCall finished";
167 }
168
169 /*
170 * Test IRadio.deactivateDataCall() for the response returned.
171 */
TEST_P(RadioHidlTest,deactivateDataCall)172 TEST_P(RadioHidlTest, deactivateDataCall) {
173 LOG(DEBUG) << "deactivateDataCall";
174 serial = GetRandomSerialNumber();
175 int cid = 1;
176 bool reasonRadioShutDown = false;
177
178 radio->deactivateDataCall(serial, cid, reasonRadioShutDown);
179
180 EXPECT_EQ(std::cv_status::no_timeout, wait());
181 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
182 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
183
184 // deactivateDataCall is deprecated on radio::V1_2 with deactiveDataCall_1_2
185 SKIP_TEST_IF_REQUEST_NOT_SUPPORTED_WITH_HAL_VERSION_AT_LEAST(1_2);
186
187 if (cardStatus.cardState == CardState::ABSENT) {
188 ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
189 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
190 RadioError::SIM_ABSENT, RadioError::INVALID_CALL_ID},
191 CHECK_OEM_ERROR));
192 }
193 LOG(DEBUG) << "deactivateDataCall finished";
194 }
195
196 /*
197 * Test IRadio.getDataCallList() for the response returned.
198 */
TEST_P(RadioHidlTest,getDataCallList)199 TEST_P(RadioHidlTest, getDataCallList) {
200 LOG(DEBUG) << "getDataCallList";
201 serial = GetRandomSerialNumber();
202
203 radio->getDataCallList(serial);
204
205 EXPECT_EQ(std::cv_status::no_timeout, wait());
206 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
207 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
208
209 if (cardStatus.cardState == CardState::ABSENT) {
210 ASSERT_TRUE(CheckAnyOfErrors(
211 radioRsp->rspInfo.error,
212 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::SIM_ABSENT}));
213 }
214 LOG(DEBUG) << "getDataCallList finished";
215 }
216
217 /*
218 * Test IRadio.setInitialAttachApn() for the response returned.
219 */
TEST_P(RadioHidlTest,setInitialAttachApn)220 TEST_P(RadioHidlTest, setInitialAttachApn) {
221 LOG(DEBUG) << "setInitialAttachApn";
222 serial = GetRandomSerialNumber();
223
224 DataProfileInfo dataProfileInfo;
225 memset(&dataProfileInfo, 0, sizeof(dataProfileInfo));
226 dataProfileInfo.profileId = DataProfileId::IMS;
227 dataProfileInfo.apn = hidl_string("VZWIMS");
228 dataProfileInfo.protocol = hidl_string("IPV4V6");
229 dataProfileInfo.roamingProtocol = hidl_string("IPV6");
230 dataProfileInfo.authType = ApnAuthType::NO_PAP_NO_CHAP;
231 dataProfileInfo.user = "";
232 dataProfileInfo.password = "";
233 dataProfileInfo.type = DataProfileInfoType::THREE_GPP2;
234 dataProfileInfo.maxConnsTime = 300;
235 dataProfileInfo.maxConns = 20;
236 dataProfileInfo.waitTime = 0;
237 dataProfileInfo.enabled = true;
238 dataProfileInfo.supportedApnTypesBitmap = 320;
239 dataProfileInfo.bearerBitmap = 161543;
240 dataProfileInfo.mtu = 0;
241 dataProfileInfo.mvnoType = MvnoType::NONE;
242 dataProfileInfo.mvnoMatchData = hidl_string();
243
244 bool modemCognitive = true;
245 bool isRoaming = false;
246
247 radio->setInitialAttachApn(serial, dataProfileInfo, modemCognitive, isRoaming);
248
249 EXPECT_EQ(std::cv_status::no_timeout, wait());
250 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
251 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
252
253 if (cardStatus.cardState == CardState::ABSENT) {
254 ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
255 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
256 RadioError::SUBSCRIPTION_NOT_AVAILABLE},
257 CHECK_OEM_ERROR));
258 }
259 LOG(DEBUG) << "setInitialAttachApn finished";
260 }
261
262 /*
263 * Test IRadio.setDataAllowed() for the response returned.
264 */
TEST_P(RadioHidlTest,setDataAllowed)265 TEST_P(RadioHidlTest, setDataAllowed) {
266 LOG(DEBUG) << "setDataAllowed";
267 serial = GetRandomSerialNumber();
268 bool allow = true;
269
270 radio->setDataAllowed(serial, allow);
271
272 EXPECT_EQ(std::cv_status::no_timeout, wait());
273 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
274 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
275
276 if (cardStatus.cardState == CardState::ABSENT) {
277 EXPECT_EQ(RadioError::NONE, radioRsp->rspInfo.error);
278 }
279 LOG(DEBUG) << "setDataAllowed finished";
280 }
281
282 /*
283 * Test IRadio.setDataProfile() for the response returned.
284 */
TEST_P(RadioHidlTest,setDataProfile)285 TEST_P(RadioHidlTest, setDataProfile) {
286 LOG(DEBUG) << "setDataProfile";
287 serial = GetRandomSerialNumber();
288
289 // Create a dataProfileInfo
290 DataProfileInfo dataProfileInfo;
291 memset(&dataProfileInfo, 0, sizeof(dataProfileInfo));
292 dataProfileInfo.profileId = DataProfileId::IMS;
293 dataProfileInfo.apn = hidl_string("VZWIMS");
294 dataProfileInfo.protocol = hidl_string("IPV4V6");
295 dataProfileInfo.roamingProtocol = hidl_string("IPV6");
296 dataProfileInfo.authType = ApnAuthType::NO_PAP_NO_CHAP;
297 dataProfileInfo.user = "";
298 dataProfileInfo.password = "";
299 dataProfileInfo.type = DataProfileInfoType::THREE_GPP2;
300 dataProfileInfo.maxConnsTime = 300;
301 dataProfileInfo.maxConns = 20;
302 dataProfileInfo.waitTime = 0;
303 dataProfileInfo.enabled = true;
304 dataProfileInfo.supportedApnTypesBitmap = 320;
305 dataProfileInfo.bearerBitmap = 161543;
306 dataProfileInfo.mtu = 0;
307 dataProfileInfo.mvnoType = MvnoType::NONE;
308 dataProfileInfo.mvnoMatchData = hidl_string();
309
310 // Create a dataProfileInfoList
311 android::hardware::hidl_vec<DataProfileInfo> dataProfileInfoList = {dataProfileInfo};
312
313 bool isRoadming = false;
314
315 radio->setDataProfile(serial, dataProfileInfoList, isRoadming);
316
317 EXPECT_EQ(std::cv_status::no_timeout, wait());
318 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
319 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
320
321 if (cardStatus.cardState == CardState::ABSENT) {
322 ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
323 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
324 RadioError::SIM_ABSENT, RadioError::REQUEST_NOT_SUPPORTED}));
325 }
326 LOG(DEBUG) << "setDataProfile finished";
327 }
328