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