• 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 <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.
91             // Only test for 64 bit here. TODO: remove this limit after b/113181277 being fixed.
92             int mccSize = hidl_mcc.size();
93             EXPECT_TRUE(mccSize == 0 || mccSize == 3);
94             if (mccSize > 0) {
95                 int mcc = stoi(hidl_mcc);
96                 EXPECT_TRUE(mcc >= 0 && mcc <= 999);
97             }
98 
99             int mncSize = hidl_mnc.size();
100             EXPECT_TRUE(mncSize == 0 || mncSize == 2 || mncSize == 3);
101             if (mncSize > 0) {
102                 int mnc = stoi(hidl_mnc);
103                 EXPECT_TRUE(mnc >= 0 && mnc <= 999);
104             }
105         }
106     }
107     LOG(DEBUG) << "getDataRegistrationState finished";
108 }
109 
110 /*
111  * Test IRadio.setupDataCall() for the response returned.
112  */
TEST_P(RadioHidlTest,setupDataCall)113 TEST_P(RadioHidlTest, setupDataCall) {
114     LOG(DEBUG) << "setupDataCall";
115     serial = GetRandomSerialNumber();
116 
117     RadioTechnology radioTechnology = RadioTechnology::LTE;
118 
119     DataProfileInfo dataProfileInfo;
120     memset(&dataProfileInfo, 0, sizeof(dataProfileInfo));
121     dataProfileInfo.profileId = DataProfileId::IMS;
122     dataProfileInfo.apn = hidl_string("VZWIMS");
123     dataProfileInfo.protocol = hidl_string("IPV4V6");
124     dataProfileInfo.roamingProtocol = hidl_string("IPV6");
125     dataProfileInfo.authType = ApnAuthType::NO_PAP_NO_CHAP;
126     dataProfileInfo.user = "";
127     dataProfileInfo.password = "";
128     dataProfileInfo.type = DataProfileInfoType::THREE_GPP2;
129     dataProfileInfo.maxConnsTime = 300;
130     dataProfileInfo.maxConns = 20;
131     dataProfileInfo.waitTime = 0;
132     dataProfileInfo.enabled = true;
133     dataProfileInfo.supportedApnTypesBitmap = 320;
134     dataProfileInfo.bearerBitmap = 161543;
135     dataProfileInfo.mtu = 0;
136     dataProfileInfo.mvnoType = MvnoType::NONE;
137     dataProfileInfo.mvnoMatchData = hidl_string();
138 
139     bool modemCognitive = false;
140     bool roamingAllowed = false;
141     bool isRoaming = false;
142 
143     radio->setupDataCall(serial, radioTechnology, dataProfileInfo, modemCognitive, roamingAllowed,
144                          isRoaming);
145 
146     EXPECT_EQ(std::cv_status::no_timeout, wait(300));
147     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
148     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
149 
150     // setupDataCall is deprecated on radio::V1_2 with setupDataCall_1_2
151     SKIP_TEST_IF_REQUEST_NOT_SUPPORTED_WITH_HAL_VERSION_AT_LEAST(1_2);
152 
153     if (cardStatus.cardState == CardState::ABSENT) {
154         ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
155                                      {RadioError::NONE, RadioError::OP_NOT_ALLOWED_BEFORE_REG_TO_NW,
156                                       RadioError::OP_NOT_ALLOWED_DURING_VOICE_CALL,
157                                       RadioError::RADIO_NOT_AVAILABLE, RadioError::SIM_ABSENT},
158                                      CHECK_OEM_ERROR));
159     }
160     LOG(DEBUG) << "setupDataCall finished";
161 }
162 
163 /*
164  * Test IRadio.deactivateDataCall() for the response returned.
165  */
TEST_P(RadioHidlTest,deactivateDataCall)166 TEST_P(RadioHidlTest, deactivateDataCall) {
167     LOG(DEBUG) << "deactivateDataCall";
168     serial = GetRandomSerialNumber();
169     int cid = 1;
170     bool reasonRadioShutDown = false;
171 
172     radio->deactivateDataCall(serial, cid, reasonRadioShutDown);
173 
174     EXPECT_EQ(std::cv_status::no_timeout, wait());
175     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
176     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
177 
178     // deactivateDataCall is deprecated on radio::V1_2 with deactiveDataCall_1_2
179     SKIP_TEST_IF_REQUEST_NOT_SUPPORTED_WITH_HAL_VERSION_AT_LEAST(1_2);
180 
181     if (cardStatus.cardState == CardState::ABSENT) {
182         ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
183                                      {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
184                                       RadioError::SIM_ABSENT, RadioError::INVALID_CALL_ID},
185                                      CHECK_OEM_ERROR));
186     }
187     LOG(DEBUG) << "deactivateDataCall finished";
188 }
189 
190 /*
191  * Test IRadio.getDataCallList() for the response returned.
192  */
TEST_P(RadioHidlTest,getDataCallList)193 TEST_P(RadioHidlTest, getDataCallList) {
194     LOG(DEBUG) << "getDataCallList";
195     serial = GetRandomSerialNumber();
196 
197     radio->getDataCallList(serial);
198 
199     EXPECT_EQ(std::cv_status::no_timeout, wait());
200     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
201     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
202 
203     if (cardStatus.cardState == CardState::ABSENT) {
204         ASSERT_TRUE(CheckAnyOfErrors(
205             radioRsp->rspInfo.error,
206             {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::SIM_ABSENT}));
207     }
208     LOG(DEBUG) << "getDataCallList finished";
209 }
210 
211 /*
212  * Test IRadio.setInitialAttachApn() for the response returned.
213  */
TEST_P(RadioHidlTest,setInitialAttachApn)214 TEST_P(RadioHidlTest, setInitialAttachApn) {
215     LOG(DEBUG) << "setInitialAttachApn";
216     serial = GetRandomSerialNumber();
217 
218     DataProfileInfo dataProfileInfo;
219     memset(&dataProfileInfo, 0, sizeof(dataProfileInfo));
220     dataProfileInfo.profileId = DataProfileId::IMS;
221     dataProfileInfo.apn = hidl_string("VZWIMS");
222     dataProfileInfo.protocol = hidl_string("IPV4V6");
223     dataProfileInfo.roamingProtocol = hidl_string("IPV6");
224     dataProfileInfo.authType = ApnAuthType::NO_PAP_NO_CHAP;
225     dataProfileInfo.user = "";
226     dataProfileInfo.password = "";
227     dataProfileInfo.type = DataProfileInfoType::THREE_GPP2;
228     dataProfileInfo.maxConnsTime = 300;
229     dataProfileInfo.maxConns = 20;
230     dataProfileInfo.waitTime = 0;
231     dataProfileInfo.enabled = true;
232     dataProfileInfo.supportedApnTypesBitmap = 320;
233     dataProfileInfo.bearerBitmap = 161543;
234     dataProfileInfo.mtu = 0;
235     dataProfileInfo.mvnoType = MvnoType::NONE;
236     dataProfileInfo.mvnoMatchData = hidl_string();
237 
238     bool modemCognitive = true;
239     bool isRoaming = false;
240 
241     radio->setInitialAttachApn(serial, dataProfileInfo, modemCognitive, isRoaming);
242 
243     EXPECT_EQ(std::cv_status::no_timeout, wait());
244     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
245     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
246 
247     if (cardStatus.cardState == CardState::ABSENT) {
248         ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
249                                      {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
250                                       RadioError::SUBSCRIPTION_NOT_AVAILABLE},
251                                      CHECK_OEM_ERROR));
252     }
253     LOG(DEBUG) << "setInitialAttachApn finished";
254 }
255 
256 /*
257  * Test IRadio.setDataAllowed() for the response returned.
258  */
TEST_P(RadioHidlTest,setDataAllowed)259 TEST_P(RadioHidlTest, setDataAllowed) {
260     LOG(DEBUG) << "setDataAllowed";
261     serial = GetRandomSerialNumber();
262     bool allow = true;
263 
264     radio->setDataAllowed(serial, allow);
265 
266     EXPECT_EQ(std::cv_status::no_timeout, wait());
267     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
268     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
269 
270     if (cardStatus.cardState == CardState::ABSENT) {
271         EXPECT_EQ(RadioError::NONE, radioRsp->rspInfo.error);
272     }
273     LOG(DEBUG) << "setDataAllowed finished";
274 }
275 
276 /*
277  * Test IRadio.setDataProfile() for the response returned.
278  */
TEST_P(RadioHidlTest,setDataProfile)279 TEST_P(RadioHidlTest, setDataProfile) {
280     LOG(DEBUG) << "setDataProfile";
281     serial = GetRandomSerialNumber();
282 
283     // Create a dataProfileInfo
284     DataProfileInfo dataProfileInfo;
285     memset(&dataProfileInfo, 0, sizeof(dataProfileInfo));
286     dataProfileInfo.profileId = DataProfileId::IMS;
287     dataProfileInfo.apn = hidl_string("VZWIMS");
288     dataProfileInfo.protocol = hidl_string("IPV4V6");
289     dataProfileInfo.roamingProtocol = hidl_string("IPV6");
290     dataProfileInfo.authType = ApnAuthType::NO_PAP_NO_CHAP;
291     dataProfileInfo.user = "";
292     dataProfileInfo.password = "";
293     dataProfileInfo.type = DataProfileInfoType::THREE_GPP2;
294     dataProfileInfo.maxConnsTime = 300;
295     dataProfileInfo.maxConns = 20;
296     dataProfileInfo.waitTime = 0;
297     dataProfileInfo.enabled = true;
298     dataProfileInfo.supportedApnTypesBitmap = 320;
299     dataProfileInfo.bearerBitmap = 161543;
300     dataProfileInfo.mtu = 0;
301     dataProfileInfo.mvnoType = MvnoType::NONE;
302     dataProfileInfo.mvnoMatchData = hidl_string();
303 
304     // Create a dataProfileInfoList
305     android::hardware::hidl_vec<DataProfileInfo> dataProfileInfoList = {dataProfileInfo};
306 
307     bool isRoadming = false;
308 
309     radio->setDataProfile(serial, dataProfileInfoList, isRoadming);
310 
311     EXPECT_EQ(std::cv_status::no_timeout, wait());
312     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
313     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
314 
315     if (cardStatus.cardState == CardState::ABSENT) {
316         ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
317                                      {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
318                                       RadioError::SIM_ABSENT, RadioError::REQUEST_NOT_SUPPORTED}));
319     }
320     LOG(DEBUG) << "setDataProfile finished";
321 }
322