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     }
36 }
37 
38 /*
39  * Test IRadio.setupDataCall() for the response returned.
40  */
TEST_F(RadioHidlTest,setupDataCall)41 TEST_F(RadioHidlTest, setupDataCall) {
42     serial = GetRandomSerialNumber();
43 
44     RadioTechnology radioTechnology = RadioTechnology::LTE;
45 
46     DataProfileInfo dataProfileInfo;
47     memset(&dataProfileInfo, 0, sizeof(dataProfileInfo));
48     dataProfileInfo.profileId = DataProfileId::IMS;
49     dataProfileInfo.apn = hidl_string("VZWIMS");
50     dataProfileInfo.protocol = hidl_string("IPV4V6");
51     dataProfileInfo.roamingProtocol = hidl_string("IPV6");
52     dataProfileInfo.authType = ApnAuthType::NO_PAP_NO_CHAP;
53     dataProfileInfo.user = "";
54     dataProfileInfo.password = "";
55     dataProfileInfo.type = DataProfileInfoType::THREE_GPP2;
56     dataProfileInfo.maxConnsTime = 300;
57     dataProfileInfo.maxConns = 20;
58     dataProfileInfo.waitTime = 0;
59     dataProfileInfo.enabled = true;
60     dataProfileInfo.supportedApnTypesBitmap = 320;
61     dataProfileInfo.bearerBitmap = 161543;
62     dataProfileInfo.mtu = 0;
63     dataProfileInfo.mvnoType = MvnoType::NONE;
64     dataProfileInfo.mvnoMatchData = hidl_string();
65 
66     bool modemCognitive = false;
67     bool roamingAllowed = false;
68     bool isRoaming = false;
69 
70     radio->setupDataCall(serial, radioTechnology, dataProfileInfo, modemCognitive, roamingAllowed,
71                          isRoaming);
72 
73     EXPECT_EQ(std::cv_status::no_timeout, wait(300));
74     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
75     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
76 
77     if (cardStatus.cardState == CardState::ABSENT) {
78         ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
79                                      {RadioError::NONE, RadioError::OP_NOT_ALLOWED_BEFORE_REG_TO_NW,
80                                       RadioError::OP_NOT_ALLOWED_DURING_VOICE_CALL,
81                                       RadioError::RADIO_NOT_AVAILABLE, RadioError::SIM_ABSENT},
82                                      CHECK_OEM_ERROR));
83     }
84 }
85 
86 /*
87  * Test IRadio.deactivateDataCall() for the response returned.
88  */
TEST_F(RadioHidlTest,deactivateDataCall)89 TEST_F(RadioHidlTest, deactivateDataCall) {
90     serial = GetRandomSerialNumber();
91     int cid = 1;
92     bool reasonRadioShutDown = false;
93 
94     radio->deactivateDataCall(serial, cid, reasonRadioShutDown);
95 
96     EXPECT_EQ(std::cv_status::no_timeout, wait());
97     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
98     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
99 
100     if (cardStatus.cardState == CardState::ABSENT) {
101         ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
102                                      {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
103                                       RadioError::SIM_ABSENT, RadioError::INVALID_CALL_ID},
104                                      CHECK_OEM_ERROR));
105     }
106 }
107 
108 /*
109  * Test IRadio.getDataCallList() for the response returned.
110  */
TEST_F(RadioHidlTest,getDataCallList)111 TEST_F(RadioHidlTest, getDataCallList) {
112     serial = GetRandomSerialNumber();
113 
114     radio->getDataCallList(serial);
115 
116     EXPECT_EQ(std::cv_status::no_timeout, wait());
117     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
118     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
119 
120     if (cardStatus.cardState == CardState::ABSENT) {
121         ASSERT_TRUE(CheckAnyOfErrors(
122             radioRsp->rspInfo.error,
123             {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::SIM_ABSENT}));
124     }
125 }
126 
127 /*
128  * Test IRadio.setInitialAttachApn() for the response returned.
129  */
TEST_F(RadioHidlTest,setInitialAttachApn)130 TEST_F(RadioHidlTest, setInitialAttachApn) {
131     serial = GetRandomSerialNumber();
132 
133     DataProfileInfo dataProfileInfo;
134     memset(&dataProfileInfo, 0, sizeof(dataProfileInfo));
135     dataProfileInfo.profileId = DataProfileId::IMS;
136     dataProfileInfo.apn = hidl_string("VZWIMS");
137     dataProfileInfo.protocol = hidl_string("IPV4V6");
138     dataProfileInfo.roamingProtocol = hidl_string("IPV6");
139     dataProfileInfo.authType = ApnAuthType::NO_PAP_NO_CHAP;
140     dataProfileInfo.user = "";
141     dataProfileInfo.password = "";
142     dataProfileInfo.type = DataProfileInfoType::THREE_GPP2;
143     dataProfileInfo.maxConnsTime = 300;
144     dataProfileInfo.maxConns = 20;
145     dataProfileInfo.waitTime = 0;
146     dataProfileInfo.enabled = true;
147     dataProfileInfo.supportedApnTypesBitmap = 320;
148     dataProfileInfo.bearerBitmap = 161543;
149     dataProfileInfo.mtu = 0;
150     dataProfileInfo.mvnoType = MvnoType::NONE;
151     dataProfileInfo.mvnoMatchData = hidl_string();
152 
153     bool modemCognitive = true;
154     bool isRoaming = false;
155 
156     radio->setInitialAttachApn(serial, dataProfileInfo, modemCognitive, isRoaming);
157 
158     EXPECT_EQ(std::cv_status::no_timeout, wait());
159     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
160     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
161 
162     if (cardStatus.cardState == CardState::ABSENT) {
163         ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
164                                      {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
165                                       RadioError::SUBSCRIPTION_NOT_AVAILABLE},
166                                      CHECK_OEM_ERROR));
167     }
168 }
169 
170 /*
171  * Test IRadio.setDataAllowed() for the response returned.
172  */
TEST_F(RadioHidlTest,setDataAllowed)173 TEST_F(RadioHidlTest, setDataAllowed) {
174     serial = GetRandomSerialNumber();
175     bool allow = true;
176 
177     radio->setDataAllowed(serial, allow);
178 
179     EXPECT_EQ(std::cv_status::no_timeout, wait());
180     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
181     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
182 
183     if (cardStatus.cardState == CardState::ABSENT) {
184         EXPECT_EQ(RadioError::NONE, radioRsp->rspInfo.error);
185     }
186 }
187 
188 /*
189  * Test IRadio.setDataProfile() for the response returned.
190  */
TEST_F(RadioHidlTest,setDataProfile)191 TEST_F(RadioHidlTest, setDataProfile) {
192     serial = GetRandomSerialNumber();
193 
194     // Create a dataProfileInfo
195     DataProfileInfo dataProfileInfo;
196     memset(&dataProfileInfo, 0, sizeof(dataProfileInfo));
197     dataProfileInfo.profileId = DataProfileId::IMS;
198     dataProfileInfo.apn = hidl_string("VZWIMS");
199     dataProfileInfo.protocol = hidl_string("IPV4V6");
200     dataProfileInfo.roamingProtocol = hidl_string("IPV6");
201     dataProfileInfo.authType = ApnAuthType::NO_PAP_NO_CHAP;
202     dataProfileInfo.user = "";
203     dataProfileInfo.password = "";
204     dataProfileInfo.type = DataProfileInfoType::THREE_GPP2;
205     dataProfileInfo.maxConnsTime = 300;
206     dataProfileInfo.maxConns = 20;
207     dataProfileInfo.waitTime = 0;
208     dataProfileInfo.enabled = true;
209     dataProfileInfo.supportedApnTypesBitmap = 320;
210     dataProfileInfo.bearerBitmap = 161543;
211     dataProfileInfo.mtu = 0;
212     dataProfileInfo.mvnoType = MvnoType::NONE;
213     dataProfileInfo.mvnoMatchData = hidl_string();
214 
215     // Create a dataProfileInfoList
216     android::hardware::hidl_vec<DataProfileInfo> dataProfileInfoList = {dataProfileInfo};
217 
218     bool isRoadming = false;
219 
220     radio->setDataProfile(serial, dataProfileInfoList, isRoadming);
221 
222     EXPECT_EQ(std::cv_status::no_timeout, wait());
223     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
224     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
225 
226     if (cardStatus.cardState == CardState::ABSENT) {
227         ASSERT_TRUE(CheckAnyOfErrors(radioRsp->rspInfo.error,
228                                      {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
229                                       RadioError::SIM_ABSENT, RadioError::REQUEST_NOT_SUPPORTED}));
230     }
231 }
232