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