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.h>
18 
19 using namespace ::android::hardware::radio::V1_0;
20 
21 /*
22  * Test IRadio.sendSms() for the response returned.
23  */
TEST_F(RadioHidlTest,sendSms)24 TEST_F(RadioHidlTest, sendSms) {
25     int serial = GetRandomSerialNumber();
26     GsmSmsMessage msg;
27     msg.smscPdu = "";
28     msg.pdu = "01000b916105770203f3000006d4f29c3e9b01";
29 
30     radio->sendSms(serial, msg);
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         ASSERT_TRUE(CheckGeneralError() ||
38                     radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
39                     radioRsp->rspInfo.error == RadioError::INVALID_STATE);
40         EXPECT_EQ(0, radioRsp->sendSmsResult.errorCode);
41     }
42 }
43 
44 /*
45  * Test IRadio.sendSMSExpectMore() for the response returned.
46  */
TEST_F(RadioHidlTest,sendSMSExpectMore)47 TEST_F(RadioHidlTest, sendSMSExpectMore) {
48     int serial = GetRandomSerialNumber();
49     GsmSmsMessage msg;
50     msg.smscPdu = "";
51     msg.pdu = "01000b916105770203f3000006d4f29c3e9b01";
52 
53     radio->sendSMSExpectMore(serial, msg);
54 
55     // TODO(shuoq): add more test for this API when inserted sim card is
56     // considered
57 
58     EXPECT_EQ(std::cv_status::no_timeout, wait());
59     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
60     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
61 
62     if (cardStatus.cardState == CardState::ABSENT) {
63         ASSERT_TRUE(CheckGeneralError() ||
64                     radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
65                     radioRsp->rspInfo.error == RadioError::INVALID_STATE);
66     }
67 }
68 
69 /*
70  * Test IRadio.acknowledgeLastIncomingGsmSms() for the response returned.
71  */
TEST_F(RadioHidlTest,acknowledgeLastIncomingGsmSms)72 TEST_F(RadioHidlTest, acknowledgeLastIncomingGsmSms) {
73     int serial = GetRandomSerialNumber();
74     bool success = true;
75 
76     radio->acknowledgeLastIncomingGsmSms(serial, success,
77                                          SmsAcknowledgeFailCause::MEMORY_CAPACITY_EXCEEDED);
78 
79     EXPECT_EQ(std::cv_status::no_timeout, wait());
80     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
81     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
82 
83     if (cardStatus.cardState == CardState::ABSENT) {
84         ASSERT_TRUE(CheckGeneralError() ||
85                     radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
86                     radioRsp->rspInfo.error == RadioError::INVALID_STATE);
87     }
88 }
89 
90 /*
91  * Test IRadio.acknowledgeIncomingGsmSmsWithPdu() for the response returned.
92  */
TEST_F(RadioHidlTest,acknowledgeIncomingGsmSmsWithPdu)93 TEST_F(RadioHidlTest, acknowledgeIncomingGsmSmsWithPdu) {
94     int serial = GetRandomSerialNumber();
95     bool success = true;
96     std::string ackPdu = "";
97 
98     radio->acknowledgeIncomingGsmSmsWithPdu(serial, success, ackPdu);
99 
100     EXPECT_EQ(std::cv_status::no_timeout, wait());
101     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
102     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
103 
104     if (cardStatus.cardState == CardState::ABSENT) {
105         // TODO(shuoq): Will add error check when we know the expected error from QC
106     }
107 }
108 
109 /*
110  * Test IRadio.sendCdmaSms() for the response returned.
111  */
TEST_F(RadioHidlTest,sendCdmaSms)112 TEST_F(RadioHidlTest, sendCdmaSms) {
113     int serial = GetRandomSerialNumber();
114 
115     // Create a CdmaSmsAddress
116     CdmaSmsAddress cdmaSmsAddress;
117     cdmaSmsAddress.digitMode = CdmaSmsDigitMode::FOUR_BIT;
118     cdmaSmsAddress.numberMode = CdmaSmsNumberMode::NOT_DATA_NETWORK;
119     cdmaSmsAddress.numberType = CdmaSmsNumberType::UNKNOWN;
120     cdmaSmsAddress.numberPlan = CdmaSmsNumberPlan::UNKNOWN;
121     cdmaSmsAddress.digits = (std::vector<uint8_t>){11, 1, 6, 5, 10, 7, 7, 2, 10, 3, 10, 3};
122 
123     // Create a CdmaSmsSubAddress
124     CdmaSmsSubaddress cdmaSmsSubaddress;
125     cdmaSmsSubaddress.subaddressType = CdmaSmsSubaddressType::NSAP;
126     cdmaSmsSubaddress.odd = false;
127     cdmaSmsSubaddress.digits = (std::vector<uint8_t>){};
128 
129     // Create a CdmaSmsMessage
130     android::hardware::radio::V1_0::CdmaSmsMessage cdmaSmsMessage;
131     cdmaSmsMessage.teleserviceId = 4098;
132     cdmaSmsMessage.isServicePresent = false;
133     cdmaSmsMessage.serviceCategory = 0;
134     cdmaSmsMessage.address = cdmaSmsAddress;
135     cdmaSmsMessage.subAddress = cdmaSmsSubaddress;
136     cdmaSmsMessage.bearerData =
137         (std::vector<uint8_t>){15, 0, 3, 32, 3, 16, 1, 8, 16, 53, 76, 68, 6, 51, 106, 0};
138 
139     radio->sendCdmaSms(serial, cdmaSmsMessage);
140 
141     EXPECT_EQ(std::cv_status::no_timeout, wait());
142     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
143     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
144 
145     if (cardStatus.cardState == CardState::ABSENT) {
146         ASSERT_TRUE(CheckGeneralError() ||
147                     radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
148                     radioRsp->rspInfo.error == RadioError::INVALID_STATE);
149     }
150 }
151 
152 /*
153  * Test IRadio.acknowledgeLastIncomingCdmaSms() for the response returned.
154  */
TEST_F(RadioHidlTest,acknowledgeLastIncomingCdmaSms)155 TEST_F(RadioHidlTest, acknowledgeLastIncomingCdmaSms) {
156     int serial = GetRandomSerialNumber();
157 
158     // Create a CdmaSmsAck
159     CdmaSmsAck cdmaSmsAck;
160     cdmaSmsAck.errorClass = CdmaSmsErrorClass::NO_ERROR;
161     cdmaSmsAck.smsCauseCode = 1;
162 
163     radio->acknowledgeLastIncomingCdmaSms(serial, cdmaSmsAck);
164 
165     EXPECT_EQ(std::cv_status::no_timeout, wait());
166     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
167     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
168 
169     if (cardStatus.cardState == CardState::ABSENT) {
170         ASSERT_TRUE(CheckGeneralError() ||
171                     radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
172                     radioRsp->rspInfo.error == RadioError::NO_SMS_TO_ACK);
173     }
174 }
175 
176 /*
177  * Test IRadio.sendImsSms() for the response returned.
178  */
TEST_F(RadioHidlTest,sendImsSms)179 TEST_F(RadioHidlTest, sendImsSms) {
180     int serial = GetRandomSerialNumber();
181 
182     // Create a CdmaSmsAddress
183     CdmaSmsAddress cdmaSmsAddress;
184     cdmaSmsAddress.digitMode = CdmaSmsDigitMode::FOUR_BIT;
185     cdmaSmsAddress.numberMode = CdmaSmsNumberMode::NOT_DATA_NETWORK;
186     cdmaSmsAddress.numberType = CdmaSmsNumberType::UNKNOWN;
187     cdmaSmsAddress.numberPlan = CdmaSmsNumberPlan::UNKNOWN;
188     cdmaSmsAddress.digits = (std::vector<uint8_t>){11, 1, 6, 5, 10, 7, 7, 2, 10, 3, 10, 3};
189 
190     // Create a CdmaSmsSubAddress
191     CdmaSmsSubaddress cdmaSmsSubaddress;
192     cdmaSmsSubaddress.subaddressType = CdmaSmsSubaddressType::NSAP;
193     cdmaSmsSubaddress.odd = false;
194     cdmaSmsSubaddress.digits = (std::vector<uint8_t>){};
195 
196     // Create a CdmaSmsMessage
197     CdmaSmsMessage cdmaSmsMessage;
198     cdmaSmsMessage.teleserviceId = 4098;
199     cdmaSmsMessage.isServicePresent = false;
200     cdmaSmsMessage.serviceCategory = 0;
201     cdmaSmsMessage.address = cdmaSmsAddress;
202     cdmaSmsMessage.subAddress = cdmaSmsSubaddress;
203     cdmaSmsMessage.bearerData =
204         (std::vector<uint8_t>){15, 0, 3, 32, 3, 16, 1, 8, 16, 53, 76, 68, 6, 51, 106, 0};
205 
206     // Creata an ImsSmsMessage
207     ImsSmsMessage msg;
208     msg.tech = RadioTechnologyFamily::THREE_GPP2;
209     msg.retry = false;
210     msg.messageRef = 0;
211     msg.cdmaMessage = (std::vector<CdmaSmsMessage>){cdmaSmsMessage};
212     msg.gsmMessage = (std::vector<GsmSmsMessage>){};
213 
214     radio->sendImsSms(serial, msg);
215 
216     EXPECT_EQ(std::cv_status::no_timeout, wait());
217     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
218     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
219 
220     if (cardStatus.cardState == CardState::ABSENT) {
221         ASSERT_TRUE(CheckGeneralError() ||
222                     radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS);
223     }
224 }
225 
226 /*
227  * Test IRadio.getSmscAddress() for the response returned.
228  */
TEST_F(RadioHidlTest,getSmscAddress)229 TEST_F(RadioHidlTest, getSmscAddress) {
230     int serial = GetRandomSerialNumber();
231 
232     radio->getSmscAddress(serial);
233 
234     EXPECT_EQ(std::cv_status::no_timeout, wait());
235     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
236     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
237 
238     if (cardStatus.cardState == CardState::ABSENT) {
239         ASSERT_TRUE(CheckGeneralError() || radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
240                     radioRsp->rspInfo.error == RadioError::INVALID_MODEM_STATE);
241     }
242 }
243 
244 /*
245  * Test IRadio.setSmscAddress() for the response returned.
246  */
TEST_F(RadioHidlTest,setSmscAddress)247 TEST_F(RadioHidlTest, setSmscAddress) {
248     int serial = GetRandomSerialNumber();
249     hidl_string address = hidl_string("smscAddress");
250 
251     radio->setSmscAddress(serial, address);
252 
253     EXPECT_EQ(std::cv_status::no_timeout, wait());
254     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
255     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
256 
257     if (cardStatus.cardState == CardState::ABSENT) {
258         ASSERT_TRUE(CheckGeneralError() ||
259                     radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
260                     radioRsp->rspInfo.error == RadioError::INVALID_SMS_FORMAT);
261     }
262 }
263 
264 /*
265  * Test IRadio.writeSmsToSim() for the response returned.
266  */
TEST_F(RadioHidlTest,writeSmsToSim)267 TEST_F(RadioHidlTest, writeSmsToSim) {
268     int serial = GetRandomSerialNumber();
269     SmsWriteArgs smsWriteArgs;
270     smsWriteArgs.status = SmsWriteArgsStatus::REC_UNREAD;
271     smsWriteArgs.smsc = "";
272     smsWriteArgs.pdu = "01000b916105770203f3000006d4f29c3e9b01";
273 
274     radio->writeSmsToSim(serial, smsWriteArgs);
275 
276     EXPECT_EQ(std::cv_status::no_timeout, wait());
277     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
278     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
279 
280     if (cardStatus.cardState == CardState::ABSENT) {
281         ASSERT_TRUE(CheckGeneralError() ||
282                     radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
283                     radioRsp->rspInfo.error == RadioError::NONE ||
284                     radioRsp->rspInfo.error == RadioError::MODEM_ERR ||
285                     radioRsp->rspInfo.error == RadioError::ENCODING_ERR ||
286                     radioRsp->rspInfo.error == RadioError::NO_RESOURCES ||
287                     radioRsp->rspInfo.error == RadioError::NETWORK_NOT_READY ||
288                     radioRsp->rspInfo.error == RadioError::INVALID_SMSC_ADDRESS);
289     }
290 }
291 
292 /*
293  * Test IRadio.deleteSmsOnSim() for the response returned.
294  */
TEST_F(RadioHidlTest,deleteSmsOnSim)295 TEST_F(RadioHidlTest, deleteSmsOnSim) {
296     int serial = GetRandomSerialNumber();
297     int index = 1;
298 
299     radio->deleteSmsOnSim(serial, index);
300 
301     EXPECT_EQ(std::cv_status::no_timeout, wait());
302     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
303     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
304 
305     if (cardStatus.cardState == CardState::ABSENT) {
306         ASSERT_TRUE(CheckGeneralError() ||
307                     radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
308                     radioRsp->rspInfo.error == RadioError::NONE ||
309                     radioRsp->rspInfo.error == RadioError::MODEM_ERR ||
310                     radioRsp->rspInfo.error == RadioError::NO_SUCH_ENTRY ||
311                     radioRsp->rspInfo.error == RadioError::INVALID_MODEM_STATE);
312     }
313 }
314 
315 /*
316  * Test IRadio.writeSmsToRuim() for the response returned.
317  */
TEST_F(RadioHidlTest,writeSmsToRuim)318 TEST_F(RadioHidlTest, writeSmsToRuim) {
319     int serial = GetRandomSerialNumber();
320 
321     // Create a CdmaSmsAddress
322     CdmaSmsAddress cdmaSmsAddress;
323     cdmaSmsAddress.digitMode = CdmaSmsDigitMode::FOUR_BIT;
324     cdmaSmsAddress.numberMode = CdmaSmsNumberMode::NOT_DATA_NETWORK;
325     cdmaSmsAddress.numberType = CdmaSmsNumberType::UNKNOWN;
326     cdmaSmsAddress.numberPlan = CdmaSmsNumberPlan::UNKNOWN;
327     cdmaSmsAddress.digits = (std::vector<uint8_t>){11, 1, 6, 5, 10, 7, 7, 2, 10, 3, 10, 3};
328 
329     // Create a CdmaSmsSubAddress
330     CdmaSmsSubaddress cdmaSmsSubaddress;
331     cdmaSmsSubaddress.subaddressType = CdmaSmsSubaddressType::NSAP;
332     cdmaSmsSubaddress.odd = false;
333     cdmaSmsSubaddress.digits = (std::vector<uint8_t>){};
334 
335     // Create a CdmaSmsMessage
336     CdmaSmsMessage cdmaSmsMessage;
337     cdmaSmsMessage.teleserviceId = 4098;
338     cdmaSmsMessage.isServicePresent = false;
339     cdmaSmsMessage.serviceCategory = 0;
340     cdmaSmsMessage.address = cdmaSmsAddress;
341     cdmaSmsMessage.subAddress = cdmaSmsSubaddress;
342     cdmaSmsMessage.bearerData =
343         (std::vector<uint8_t>){15, 0, 3, 32, 3, 16, 1, 8, 16, 53, 76, 68, 6, 51, 106, 0};
344 
345     // Create a CdmaSmsWriteArgs
346     CdmaSmsWriteArgs cdmaSmsWriteArgs;
347     cdmaSmsWriteArgs.status = CdmaSmsWriteArgsStatus::REC_UNREAD;
348     cdmaSmsWriteArgs.message = cdmaSmsMessage;
349 
350     radio->writeSmsToRuim(serial, cdmaSmsWriteArgs);
351 
352     EXPECT_EQ(std::cv_status::no_timeout, wait());
353     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
354     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
355 
356     if (cardStatus.cardState == CardState::ABSENT) {
357         ASSERT_TRUE(CheckGeneralError() ||
358                     radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
359                     radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
360                     radioRsp->rspInfo.error == RadioError::INVALID_SMS_FORMAT ||
361                     radioRsp->rspInfo.error == RadioError::NONE ||
362                     radioRsp->rspInfo.error == RadioError::MODEM_ERR ||
363                     radioRsp->rspInfo.error == RadioError::NO_SUCH_ENTRY ||
364                     radioRsp->rspInfo.error == RadioError::INVALID_SMSC_ADDRESS);
365     }
366 }
367 
368 /*
369  * Test IRadio.deleteSmsOnRuim() for the response returned.
370  */
TEST_F(RadioHidlTest,deleteSmsOnRuim)371 TEST_F(RadioHidlTest, deleteSmsOnRuim) {
372     int serial = GetRandomSerialNumber();
373     int index = 1;
374 
375     // Create a CdmaSmsAddress
376     CdmaSmsAddress cdmaSmsAddress;
377     cdmaSmsAddress.digitMode = CdmaSmsDigitMode::FOUR_BIT;
378     cdmaSmsAddress.numberMode = CdmaSmsNumberMode::NOT_DATA_NETWORK;
379     cdmaSmsAddress.numberType = CdmaSmsNumberType::UNKNOWN;
380     cdmaSmsAddress.numberPlan = CdmaSmsNumberPlan::UNKNOWN;
381     cdmaSmsAddress.digits = (std::vector<uint8_t>){11, 1, 6, 5, 10, 7, 7, 2, 10, 3, 10, 3};
382 
383     // Create a CdmaSmsSubAddress
384     CdmaSmsSubaddress cdmaSmsSubaddress;
385     cdmaSmsSubaddress.subaddressType = CdmaSmsSubaddressType::NSAP;
386     cdmaSmsSubaddress.odd = false;
387     cdmaSmsSubaddress.digits = (std::vector<uint8_t>){};
388 
389     // Create a CdmaSmsMessage
390     CdmaSmsMessage cdmaSmsMessage;
391     cdmaSmsMessage.teleserviceId = 4098;
392     cdmaSmsMessage.isServicePresent = false;
393     cdmaSmsMessage.serviceCategory = 0;
394     cdmaSmsMessage.address = cdmaSmsAddress;
395     cdmaSmsMessage.subAddress = cdmaSmsSubaddress;
396     cdmaSmsMessage.bearerData =
397         (std::vector<uint8_t>){15, 0, 3, 32, 3, 16, 1, 8, 16, 53, 76, 68, 6, 51, 106, 0};
398 
399     // Create a CdmaSmsWriteArgs
400     CdmaSmsWriteArgs cdmaSmsWriteArgs;
401     cdmaSmsWriteArgs.status = CdmaSmsWriteArgsStatus::REC_UNREAD;
402     cdmaSmsWriteArgs.message = cdmaSmsMessage;
403 
404     radio->deleteSmsOnRuim(serial, index);
405 
406     EXPECT_EQ(std::cv_status::no_timeout, wait());
407     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
408     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
409 
410     if (cardStatus.cardState == CardState::ABSENT) {
411         ASSERT_TRUE(CheckGeneralError() ||
412                     radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
413                     radioRsp->rspInfo.error == RadioError::NONE ||
414                     radioRsp->rspInfo.error == RadioError::MODEM_ERR ||
415                     radioRsp->rspInfo.error == RadioError::NO_SUCH_ENTRY ||
416                     radioRsp->rspInfo.error == RadioError::INVALID_MODEM_STATE);
417     }
418 }
419 
420 /*
421  * Test IRadio.reportSmsMemoryStatus() for the response returned.
422  */
TEST_F(RadioHidlTest,reportSmsMemoryStatus)423 TEST_F(RadioHidlTest, reportSmsMemoryStatus) {
424     int serial = GetRandomSerialNumber();
425     bool available = true;
426 
427     radio->reportSmsMemoryStatus(serial, available);
428 
429     EXPECT_EQ(std::cv_status::no_timeout, wait());
430     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
431     EXPECT_EQ(serial, radioRsp->rspInfo.serial);
432 
433     if (cardStatus.cardState == CardState::ABSENT) {
434         ASSERT_TRUE(CheckGeneralError() ||
435                     radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
436                     radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
437                     radioRsp->rspInfo.error == RadioError::MODEM_ERR);
438     }
439 }
440