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