blob: 44be258039a913b58a0f77a062b70fece760de54 [file] [log] [blame]
Sarah Chinfc5603b2021-12-21 11:34:00 -08001/*
2 * Copyright (C) 2021 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
Sarah Chin912bdf32022-01-28 01:02:16 -080017#include <aidl/android/hardware/radio/RadioConst.h>
Sarah Chinfc5603b2021-12-21 11:34:00 -080018#include <aidl/android/hardware/radio/config/IRadioConfig.h>
19#include <android-base/logging.h>
20#include <android/binder_manager.h>
21
22#include "radio_sim_utils.h"
23
24#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
25
26void RadioSimTest::SetUp() {
27 std::string serviceName = GetParam();
28
29 if (!isServiceValidForDeviceConfiguration(serviceName)) {
30 ALOGI("Skipped the test due to device configuration.");
31 GTEST_SKIP();
32 }
33
34 radio_sim = IRadioSim::fromBinder(
35 ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
36 ASSERT_NE(nullptr, radio_sim.get());
37
38 radioRsp_sim = ndk::SharedRefBase::make<RadioSimResponse>(*this);
39 ASSERT_NE(nullptr, radioRsp_sim.get());
40
41 count_ = 0;
42
43 radioInd_sim = ndk::SharedRefBase::make<RadioSimIndication>(*this);
44 ASSERT_NE(nullptr, radioInd_sim.get());
45
46 radio_sim->setResponseFunctions(radioRsp_sim, radioInd_sim);
Sarah Chinc83bce42021-12-29 00:35:12 -080047 // Assert SIM is present before testing
48 updateSimCardStatus();
49 EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState);
Sarah Chinfc5603b2021-12-21 11:34:00 -080050
51 // Assert IRadioConfig exists before testing
Sarah Chinc83bce42021-12-29 00:35:12 -080052 radio_config = config::IRadioConfig::fromBinder(ndk::SpAIBinder(
53 AServiceManager_waitForService("android.hardware.radio.config.IRadioConfig/default")));
54 ASSERT_NE(nullptr, radio_config.get());
Sarah Chinfc5603b2021-12-21 11:34:00 -080055}
56
Sarah Chinc83bce42021-12-29 00:35:12 -080057void RadioSimTest::updateSimCardStatus() {
Sarah Chinfc5603b2021-12-21 11:34:00 -080058 serial = GetRandomSerialNumber();
59 radio_sim->getIccCardStatus(serial);
60 EXPECT_EQ(std::cv_status::no_timeout, wait());
Sarah Chinc83bce42021-12-29 00:35:12 -080061 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
62 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
63 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
Sarah Chinfc5603b2021-12-21 11:34:00 -080064}
65
66/*
67 * Test IRadioSim.setSimCardPower() for the response returned.
68 */
69TEST_P(RadioSimTest, setSimCardPower) {
70 /* Test setSimCardPower power down */
71 serial = GetRandomSerialNumber();
72 radio_sim->setSimCardPower(serial, CardPowerState::POWER_DOWN);
73 EXPECT_EQ(std::cv_status::no_timeout, wait());
74 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
75 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
76 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
77 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
78 RadioError::RADIO_NOT_AVAILABLE, RadioError::SIM_ERR}));
79
80 // setSimCardPower does not return until the request is handled, and should not trigger
81 // CardStatus::STATE_ABSENT when turning off power
82 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
83 /* Wait some time for setting sim power down and then verify it */
84 updateSimCardStatus();
85 // We cannot assert the consistency of CardState here due to b/203031664
86 // EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState);
87 // applications should be an empty vector of AppStatus
88 EXPECT_EQ(0, cardStatus.applications.size());
89 }
90
91 // Give some time for modem to fully power down the SIM card
92 sleep(MODEM_SET_SIM_POWER_DELAY_IN_SECONDS);
93
94 /* Test setSimCardPower power up */
95 serial = GetRandomSerialNumber();
96 radio_sim->setSimCardPower(serial, CardPowerState::POWER_UP);
97 EXPECT_EQ(std::cv_status::no_timeout, wait());
98 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
99 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
100 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
101 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
102 RadioError::RADIO_NOT_AVAILABLE, RadioError::SIM_ERR}));
103
104 // Give some time for modem to fully power up the SIM card
105 sleep(MODEM_SET_SIM_POWER_DELAY_IN_SECONDS);
106
107 // setSimCardPower does not return until the request is handled. Just verify that we still
108 // have CardStatus::STATE_PRESENT after turning the power back on
109 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
110 updateSimCardStatus();
Tim Lin8a6a1d32022-03-31 21:06:57 +0800111 updateSimSlotStatus(cardStatus.slotMap.physicalSlotId);
Sarah Chinfc5603b2021-12-21 11:34:00 -0800112 EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState);
sandeepjs5561b4b2022-02-15 11:41:28 +0000113 EXPECT_EQ(CardStatus::STATE_PRESENT, slotStatus.cardState);
114 if (CardStatus::STATE_PRESENT == slotStatus.cardState) {
115 ASSERT_TRUE(slotStatus.portInfo[0].portActive);
116 EXPECT_EQ(0, cardStatus.slotMap.portId);
117 }
Sarah Chinfc5603b2021-12-21 11:34:00 -0800118 }
119}
120
121/*
122 * Test IRadioSim.setCarrierInfoForImsiEncryption() for the response returned.
123 */
124TEST_P(RadioSimTest, setCarrierInfoForImsiEncryption) {
125 serial = GetRandomSerialNumber();
126 ImsiEncryptionInfo imsiInfo;
127 imsiInfo.mcc = "310";
128 imsiInfo.mnc = "004";
129 imsiInfo.carrierKey = (std::vector<uint8_t>){1, 2, 3, 4, 5, 6};
130 imsiInfo.keyIdentifier = "Test";
131 imsiInfo.expirationTime = 20180101;
132 imsiInfo.keyType = ImsiEncryptionInfo::PUBLIC_KEY_TYPE_EPDG;
133
134 radio_sim->setCarrierInfoForImsiEncryption(serial, imsiInfo);
135 EXPECT_EQ(std::cv_status::no_timeout, wait());
136 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
137 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
138
139 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
140 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
141 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
142 }
143}
144
145/*
146 * Test IRadioSim.getSimPhonebookRecords() for the response returned.
147 */
148TEST_P(RadioSimTest, getSimPhonebookRecords) {
149 serial = GetRandomSerialNumber();
150 radio_sim->getSimPhonebookRecords(serial);
151 EXPECT_EQ(std::cv_status::no_timeout, wait());
152 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
153 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
154 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
155 ASSERT_TRUE(
156 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
157 {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE,
158 RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS,
159 RadioError::REQUEST_NOT_SUPPORTED},
160 CHECK_GENERAL_ERROR));
161 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
162 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
163 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
164 CHECK_GENERAL_ERROR));
165 }
166}
167
168/*
169 * Test IRadioSim.getSimPhonebookCapacity for the response returned.
170 */
171TEST_P(RadioSimTest, getSimPhonebookCapacity) {
172 serial = GetRandomSerialNumber();
173 radio_sim->getSimPhonebookCapacity(serial);
174 EXPECT_EQ(std::cv_status::no_timeout, wait());
175 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
176 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
177 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
178 ASSERT_TRUE(
179 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
180 {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE,
181 RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS,
182 RadioError::REQUEST_NOT_SUPPORTED},
183 CHECK_GENERAL_ERROR));
184 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
185 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
186 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
187 CHECK_GENERAL_ERROR));
188
189 PhonebookCapacity pbCapacity = radioRsp_sim->capacity;
190 if (pbCapacity.maxAdnRecords > 0) {
191 EXPECT_TRUE(pbCapacity.maxNameLen > 0 && pbCapacity.maxNumberLen > 0);
192 EXPECT_TRUE(pbCapacity.usedAdnRecords <= pbCapacity.maxAdnRecords);
193 }
194
195 if (pbCapacity.maxEmailRecords > 0) {
196 EXPECT_TRUE(pbCapacity.maxEmailLen > 0);
197 EXPECT_TRUE(pbCapacity.usedEmailRecords <= pbCapacity.maxEmailRecords);
198 }
199
200 if (pbCapacity.maxAdditionalNumberRecords > 0) {
201 EXPECT_TRUE(pbCapacity.maxAdditionalNumberLen > 0);
202 EXPECT_TRUE(pbCapacity.usedAdditionalNumberRecords <=
203 pbCapacity.maxAdditionalNumberRecords);
204 }
205 }
206}
207
208/*
209 * Test IRadioSim.updateSimPhonebookRecords() for the response returned.
210 */
211TEST_P(RadioSimTest, updateSimPhonebookRecords) {
212 serial = GetRandomSerialNumber();
213 radio_sim->getSimPhonebookCapacity(serial);
214 EXPECT_EQ(std::cv_status::no_timeout, wait());
215 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
216 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
217 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
218 ASSERT_TRUE(
219 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
220 {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE,
221 RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS,
222 RadioError::REQUEST_NOT_SUPPORTED},
223 CHECK_GENERAL_ERROR));
224 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
225 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
226 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
227 CHECK_GENERAL_ERROR));
228 PhonebookCapacity pbCapacity = radioRsp_sim->capacity;
229
230 serial = GetRandomSerialNumber();
231 radio_sim->getSimPhonebookRecords(serial);
232
233 EXPECT_EQ(std::cv_status::no_timeout, wait());
234 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
235 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
236 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
237 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
238 CHECK_GENERAL_ERROR));
239
240 if (pbCapacity.maxAdnRecords > 0 && pbCapacity.usedAdnRecords < pbCapacity.maxAdnRecords) {
241 // Add a phonebook record
242 PhonebookRecordInfo recordInfo;
243 recordInfo.recordId = 0;
244 recordInfo.name = "ABC";
245 recordInfo.number = "1234567890";
246 serial = GetRandomSerialNumber();
247 radio_sim->updateSimPhonebookRecords(serial, recordInfo);
248
249 EXPECT_EQ(std::cv_status::no_timeout, wait());
250 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
251 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
252 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
253 int index = radioRsp_sim->updatedRecordIndex;
254 EXPECT_TRUE(index > 0);
255
256 // Deleted a phonebook record
257 recordInfo.recordId = index;
258 recordInfo.name = "";
259 recordInfo.number = "";
260 serial = GetRandomSerialNumber();
261 radio_sim->updateSimPhonebookRecords(serial, recordInfo);
262
263 EXPECT_EQ(std::cv_status::no_timeout, wait());
264 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
265 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
266 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
267 }
268 }
269}
Sarah Chin912bdf32022-01-28 01:02:16 -0800270
271/*
272 * Test IRadioSim.enableUiccApplications() for the response returned.
273 * For SIM ABSENT case.
274 */
275TEST_P(RadioSimTest, togglingUiccApplicationsSimAbsent) {
276 // This test case only test SIM ABSENT case.
277 if (cardStatus.cardState != CardStatus::STATE_ABSENT) return;
278
279 // Disable Uicc applications.
280 serial = GetRandomSerialNumber();
281 radio_sim->enableUiccApplications(serial, false);
282 EXPECT_EQ(std::cv_status::no_timeout, wait());
283 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
284 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
285 // As SIM is absent, RadioError::SIM_ABSENT should be thrown.
286 EXPECT_EQ(RadioError::SIM_ABSENT, radioRsp_sim->rspInfo.error);
287
288 // Query Uicc application enablement.
289 serial = GetRandomSerialNumber();
290 radio_sim->areUiccApplicationsEnabled(serial);
291 EXPECT_EQ(std::cv_status::no_timeout, wait());
292 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
293 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
294 // As SIM is absent, RadioError::SIM_ABSENT should be thrown.
295 EXPECT_EQ(RadioError::SIM_ABSENT, radioRsp_sim->rspInfo.error);
296}
297
298/*
299 * Test IRadioSim.enableUiccApplications() for the response returned.
300 * For SIM PRESENT case.
301 */
302TEST_P(RadioSimTest, togglingUiccApplicationsSimPresent) {
303 // This test case only test SIM ABSENT case.
304 if (cardStatus.cardState != CardStatus::STATE_PRESENT) return;
305 if (cardStatus.applications.size() == 0) return;
306
307 // Disable Uicc applications.
308 serial = GetRandomSerialNumber();
309 radio_sim->enableUiccApplications(serial, false);
310 EXPECT_EQ(std::cv_status::no_timeout, wait());
311 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
312 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
313 // As SIM is present, there shouldn't be error.
314 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
315
316 // Query Uicc application enablement.
317 serial = GetRandomSerialNumber();
318 radio_sim->areUiccApplicationsEnabled(serial);
319 EXPECT_EQ(std::cv_status::no_timeout, wait());
320 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
321 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
322 // As SIM is present, there shouldn't be error.
323 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
324 ASSERT_FALSE(radioRsp_sim->areUiccApplicationsEnabled);
325
326 // Enable Uicc applications.
327 serial = GetRandomSerialNumber();
328 radio_sim->enableUiccApplications(serial, true);
329 EXPECT_EQ(std::cv_status::no_timeout, wait());
330 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
331 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
332 // As SIM is present, there shouldn't be error.
333 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
334
335 // Query Uicc application enablement.
336 serial = GetRandomSerialNumber();
337 radio_sim->areUiccApplicationsEnabled(serial);
338 EXPECT_EQ(std::cv_status::no_timeout, wait());
339 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
340 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
341 // As SIM is present, there shouldn't be error.
342 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
343 ASSERT_TRUE(radioRsp_sim->areUiccApplicationsEnabled);
344}
345
346/*
347 * Test IRadioSim.areUiccApplicationsEnabled() for the response returned.
348 */
349TEST_P(RadioSimTest, areUiccApplicationsEnabled) {
350 // Disable Uicc applications.
351 serial = GetRandomSerialNumber();
352 radio_sim->areUiccApplicationsEnabled(serial);
353 EXPECT_EQ(std::cv_status::no_timeout, wait());
354 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
355 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
356
357 // If SIM is absent, RadioError::SIM_ABSENT should be thrown. Otherwise there shouldn't be any
358 // error.
359 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
360 EXPECT_EQ(RadioError::SIM_ABSENT, radioRsp_sim->rspInfo.error);
361 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
362 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
363 }
364}
365
366/*
367 * Test IRadioSim.getAllowedCarriers() for the response returned.
368 */
369TEST_P(RadioSimTest, getAllowedCarriers) {
370 serial = GetRandomSerialNumber();
371
372 radio_sim->getAllowedCarriers(serial);
373 EXPECT_EQ(std::cv_status::no_timeout, wait());
374 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
375 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
376
377 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
378 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
379}
380
381/**
382 * Test IRadioSim.setAllowedCarriers() for the response returned.
383 */
384TEST_P(RadioSimTest, setAllowedCarriers) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800385 serial = GetRandomSerialNumber();
386 CarrierRestrictions carrierRestrictions;
387 memset(&carrierRestrictions, 0, sizeof(carrierRestrictions));
388 carrierRestrictions.allowedCarriers.resize(1);
389 carrierRestrictions.excludedCarriers.resize(0);
390 carrierRestrictions.allowedCarriers[0].mcc = std::string("123");
391 carrierRestrictions.allowedCarriers[0].mnc = std::string("456");
392 carrierRestrictions.allowedCarriers[0].matchType = Carrier::MATCH_TYPE_ALL;
393 carrierRestrictions.allowedCarriers[0].matchData = std::string();
Sarah Chin912bdf32022-01-28 01:02:16 -0800394 carrierRestrictions.allowedCarriersPrioritized = true;
395 SimLockMultiSimPolicy multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY;
396
397 radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy);
398 EXPECT_EQ(std::cv_status::no_timeout, wait());
399 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
400 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
401
402 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
403 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
404
405 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
406 /* Verify the update of the SIM status. This might need some time */
407 if (cardStatus.cardState != CardStatus::STATE_ABSENT) {
408 updateSimCardStatus();
409 auto startTime = std::chrono::system_clock::now();
410 while (cardStatus.cardState != CardStatus::STATE_RESTRICTED &&
411 std::chrono::duration_cast<std::chrono::seconds>(
412 std::chrono::system_clock::now() - startTime)
413 .count() < 30) {
414 /* Set 2 seconds as interval to check card status */
415 sleep(2);
416 updateSimCardStatus();
417 }
Sarah Chin0623bdd2022-02-16 11:09:26 -0800418 // TODO: uncomment once CF fully supports setAllowedCarriers
419 // EXPECT_EQ(CardStatus::STATE_RESTRICTED, cardStatus.cardState);
Sarah Chin912bdf32022-01-28 01:02:16 -0800420 }
421
422 /* Verify that configuration was set correctly, retrieving it from the modem */
423 serial = GetRandomSerialNumber();
424
425 radio_sim->getAllowedCarriers(serial);
426 EXPECT_EQ(std::cv_status::no_timeout, wait());
427 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
428 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
429 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
430
431 EXPECT_EQ(1, radioRsp_sim->carrierRestrictionsResp.allowedCarriers.size());
432 EXPECT_EQ(0, radioRsp_sim->carrierRestrictionsResp.excludedCarriers.size());
433 ASSERT_TRUE(std::string("123") ==
434 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mcc);
435 ASSERT_TRUE(std::string("456") ==
436 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mnc);
437 EXPECT_EQ(Carrier::MATCH_TYPE_ALL,
438 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].matchType);
439 ASSERT_TRUE(radioRsp_sim->carrierRestrictionsResp.allowedCarriersPrioritized);
440 EXPECT_EQ(SimLockMultiSimPolicy::NO_MULTISIM_POLICY, radioRsp_sim->multiSimPolicyResp);
441
442 sleep(10);
443
444 /**
445 * Another test case of the API to cover to allow carrier.
446 * If the API is supported, this is also used to reset to no carrier restriction
447 * status for cardStatus.
448 */
449 memset(&carrierRestrictions, 0, sizeof(carrierRestrictions));
450 carrierRestrictions.allowedCarriers.resize(0);
451 carrierRestrictions.excludedCarriers.resize(0);
452 carrierRestrictions.allowedCarriersPrioritized = false;
453
454 serial = GetRandomSerialNumber();
455 radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy);
456 EXPECT_EQ(std::cv_status::no_timeout, wait());
457 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
458 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
459
460 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
461
462 if (cardStatus.cardState != CardStatus::STATE_ABSENT) {
463 /* Resetting back to no carrier restriction needs some time */
464 updateSimCardStatus();
465 auto startTime = std::chrono::system_clock::now();
466 while (cardStatus.cardState == CardStatus::STATE_RESTRICTED &&
467 std::chrono::duration_cast<std::chrono::seconds>(
468 std::chrono::system_clock::now() - startTime)
469 .count() < 10) {
470 /* Set 2 seconds as interval to check card status */
471 sleep(2);
472 updateSimCardStatus();
473 }
474 EXPECT_NE(CardStatus::STATE_RESTRICTED, cardStatus.cardState);
475 sleep(10);
476 }
477 }
478}
479
480/*
481 * Test IRadioSim.getIccCardStatus() for the response returned.
482 */
483TEST_P(RadioSimTest, getIccCardStatus) {
484 LOG(DEBUG) << "getIccCardStatus";
485 EXPECT_LE(cardStatus.applications.size(), RadioConst::CARD_MAX_APPS);
486 EXPECT_LT(cardStatus.gsmUmtsSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
487 EXPECT_LT(cardStatus.cdmaSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
488 EXPECT_LT(cardStatus.imsSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
489 LOG(DEBUG) << "getIccCardStatus finished";
490}
491
492/*
493 * Test IRadioSim.supplyIccPinForApp() for the response returned
494 */
495TEST_P(RadioSimTest, supplyIccPinForApp) {
496 LOG(DEBUG) << "supplyIccPinForApp";
497 serial = GetRandomSerialNumber();
498
499 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
500 // 3GPP2 apps only
501 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
502 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
503 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
504 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
505 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
506 radio_sim->supplyIccPinForApp(serial, std::string("test1"),
507 cardStatus.applications[i].aidPtr);
508 EXPECT_EQ(std::cv_status::no_timeout, wait());
509 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
510 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
511 ASSERT_TRUE(CheckAnyOfErrors(
512 radioRsp_sim->rspInfo.error,
513 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
514 }
515 }
516 LOG(DEBUG) << "supplyIccPinForApp finished";
517}
518
519/*
520 * Test IRadioSim.supplyIccPukForApp() for the response returned.
521 */
522TEST_P(RadioSimTest, supplyIccPukForApp) {
523 LOG(DEBUG) << "supplyIccPukForApp";
524 serial = GetRandomSerialNumber();
525
526 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
527 // 3GPP2 apps only
528 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
529 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
530 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
531 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
532 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
533 radio_sim->supplyIccPukForApp(serial, std::string("test1"), std::string("test2"),
534 cardStatus.applications[i].aidPtr);
535 EXPECT_EQ(std::cv_status::no_timeout, wait());
536 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
537 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
538 ASSERT_TRUE(CheckAnyOfErrors(
539 radioRsp_sim->rspInfo.error,
540 {RadioError::PASSWORD_INCORRECT, RadioError::INVALID_SIM_STATE}));
541 }
542 }
543 LOG(DEBUG) << "supplyIccPukForApp finished";
544}
545
546/*
547 * Test IRadioSim.supplyIccPin2ForApp() for the response returned.
548 */
549TEST_P(RadioSimTest, supplyIccPin2ForApp) {
550 LOG(DEBUG) << "supplyIccPin2ForApp";
551 serial = GetRandomSerialNumber();
552
553 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
554 // 3GPP2 apps only
555 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
556 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
557 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
558 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
559 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
560 radio_sim->supplyIccPin2ForApp(serial, std::string("test1"),
561 cardStatus.applications[i].aidPtr);
562 EXPECT_EQ(std::cv_status::no_timeout, wait());
563 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
564 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
565 ASSERT_TRUE(
566 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
567 {RadioError::PASSWORD_INCORRECT,
568 RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_PUK2}));
569 }
570 }
571 LOG(DEBUG) << "supplyIccPin2ForApp finished";
572}
573
574/*
575 * Test IRadioSim.supplyIccPuk2ForApp() for the response returned.
576 */
577TEST_P(RadioSimTest, supplyIccPuk2ForApp) {
578 LOG(DEBUG) << "supplyIccPuk2ForApp";
579 serial = GetRandomSerialNumber();
580
581 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
582 // 3GPP2 apps only
583 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
584 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
585 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
586 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
587 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
588 radio_sim->supplyIccPuk2ForApp(serial, std::string("test1"), std::string("test2"),
589 cardStatus.applications[i].aidPtr);
590 EXPECT_EQ(std::cv_status::no_timeout, wait());
591 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
592 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
593 ASSERT_TRUE(CheckAnyOfErrors(
594 radioRsp_sim->rspInfo.error,
595 {RadioError::PASSWORD_INCORRECT, RadioError::INVALID_SIM_STATE}));
596 }
597 }
598 LOG(DEBUG) << "supplyIccPuk2ForApp finished";
599}
600
601/*
602 * Test IRadioSim.changeIccPinForApp() for the response returned.
603 */
604TEST_P(RadioSimTest, changeIccPinForApp) {
605 LOG(DEBUG) << "changeIccPinForApp";
606 serial = GetRandomSerialNumber();
607
608 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
609 // 3GPP2 apps only
610 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
611 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
612 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
613 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
614 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
615 radio_sim->changeIccPinForApp(serial, std::string("test1"), std::string("test2"),
616 cardStatus.applications[i].aidPtr);
617 EXPECT_EQ(std::cv_status::no_timeout, wait());
618 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
619 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
620 ASSERT_TRUE(CheckAnyOfErrors(
621 radioRsp_sim->rspInfo.error,
622 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
623 }
624 }
625 LOG(DEBUG) << "changeIccPinForApp finished";
626}
627
628/*
629 * Test IRadioSim.changeIccPin2ForApp() for the response returned.
630 */
631TEST_P(RadioSimTest, changeIccPin2ForApp) {
632 LOG(DEBUG) << "changeIccPin2ForApp";
633 serial = GetRandomSerialNumber();
634
635 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
636 // 3GPP2 apps only
637 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
638 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
639 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
640 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
641 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
642 radio_sim->changeIccPin2ForApp(serial, std::string("test1"), std::string("test2"),
643 cardStatus.applications[i].aidPtr);
644 EXPECT_EQ(std::cv_status::no_timeout, wait());
645 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
646 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
647 ASSERT_TRUE(
648 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
649 {RadioError::PASSWORD_INCORRECT,
650 RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_PUK2}));
651 }
652 }
653 LOG(DEBUG) << "changeIccPin2ForApp finished";
654}
655
656/*
Sarah Chin912bdf32022-01-28 01:02:16 -0800657 * Test IRadioSim.getImsiForApp() for the response returned.
658 */
Sarah Chinca421a62022-01-28 15:54:36 -0800659TEST_P(RadioSimTest, getImsiForApp) {
660 LOG(DEBUG) << "getImsiForApp";
Sarah Chin912bdf32022-01-28 01:02:16 -0800661 serial = GetRandomSerialNumber();
662
663 // Check success returned while getting imsi for 3GPP and 3GPP2 apps only
664 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
665 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
666 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
667 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
668 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
669 radio_sim->getImsiForApp(serial, cardStatus.applications[i].aidPtr);
670 EXPECT_EQ(std::cv_status::no_timeout, wait());
671 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
672 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
673 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE},
674 CHECK_GENERAL_ERROR));
675
676 // IMSI (MCC+MNC+MSIN) is at least 6 digits, but not more than 15
677 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
678 EXPECT_NE(radioRsp_sim->imsi, std::string());
679 EXPECT_GE((int)(radioRsp_sim->imsi).size(), 6);
680 EXPECT_LE((int)(radioRsp_sim->imsi).size(), 15);
681 }
682 }
683 }
Sarah Chinca421a62022-01-28 15:54:36 -0800684 LOG(DEBUG) << "getImsiForApp finished";
Sarah Chin912bdf32022-01-28 01:02:16 -0800685}
686
687/*
688 * Test IRadioSim.iccIoForApp() for the response returned.
689 */
690TEST_P(RadioSimTest, iccIoForApp) {
691 LOG(DEBUG) << "iccIoForApp";
692 serial = GetRandomSerialNumber();
693
694 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
695 IccIo iccIo;
696 iccIo.command = 0xc0;
697 iccIo.fileId = 0x6f11;
698 iccIo.path = std::string("3F007FFF");
699 iccIo.p1 = 0;
700 iccIo.p2 = 0;
701 iccIo.p3 = 0;
702 iccIo.data = std::string();
703 iccIo.pin2 = std::string();
704 iccIo.aid = cardStatus.applications[i].aidPtr;
705
706 radio_sim->iccIoForApp(serial, iccIo);
707 EXPECT_EQ(std::cv_status::no_timeout, wait());
708 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
709 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
710 }
711 LOG(DEBUG) << "iccIoForApp finished";
712}
713
714/*
715 * Test IRadioSim.iccTransmitApduBasicChannel() for the response returned.
716 */
717TEST_P(RadioSimTest, iccTransmitApduBasicChannel) {
718 LOG(DEBUG) << "iccTransmitApduBasicChannel";
719 serial = GetRandomSerialNumber();
720 SimApdu msg;
721 memset(&msg, 0, sizeof(msg));
722 msg.data = std::string();
723
724 radio_sim->iccTransmitApduBasicChannel(serial, msg);
725 EXPECT_EQ(std::cv_status::no_timeout, wait());
726 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
727 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
Sarah Chin912bdf32022-01-28 01:02:16 -0800728 LOG(DEBUG) << "iccTransmitApduBasicChannel finished";
729}
730
731/*
732 * Test IRadioSim.iccOpenLogicalChannel() for the response returned.
733 */
734TEST_P(RadioSimTest, iccOpenLogicalChannel) {
735 LOG(DEBUG) << "iccOpenLogicalChannel";
736 serial = GetRandomSerialNumber();
737 int p2 = 0x04;
738 // Specified in ISO 7816-4 clause 7.1.1 0x04 means that FCP template is requested.
739 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
740 radio_sim->iccOpenLogicalChannel(serial, cardStatus.applications[i].aidPtr, p2);
741 EXPECT_EQ(std::cv_status::no_timeout, wait());
742 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
743 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
744 }
745 LOG(DEBUG) << "iccOpenLogicalChannel finished";
746}
747
748/*
749 * Test IRadioSim.iccCloseLogicalChannel() for the response returned.
750 */
751TEST_P(RadioSimTest, iccCloseLogicalChannel) {
752 LOG(DEBUG) << "iccCloseLogicalChannel";
753 serial = GetRandomSerialNumber();
754 // Try closing invalid channel and check INVALID_ARGUMENTS returned as error
755 radio_sim->iccCloseLogicalChannel(serial, 0);
756 EXPECT_EQ(std::cv_status::no_timeout, wait());
757 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
758 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
759
760 EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp_sim->rspInfo.error);
761 LOG(DEBUG) << "iccCloseLogicalChannel finished";
762}
763
764/*
Muralidhar Reddyc13d0d62023-01-18 18:45:14 +0000765 * Test IRadioSim.iccCloseLogicalChannelWithSessionInfo() for the response returned.
766 */
767TEST_P(RadioSimTest, iccCloseLogicalChannelWithSessionInfo) {
768 LOG(DEBUG) << "iccCloseLogicalChannelWithSessionInfo";
769 serial = GetRandomSerialNumber();
770 SessionInfo info;
771 memset(&info, 0, sizeof(info));
772 info.sessionId = 0;
773 info.isEs10 = false;
774
775 // Try closing invalid channel and check INVALID_ARGUMENTS returned as error
776 radio_sim->iccCloseLogicalChannelWithSessionInfo(serial, info);
777 EXPECT_EQ(std::cv_status::no_timeout, wait());
778 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
779 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
780
781 EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp_sim->rspInfo.error);
782 LOG(DEBUG) << "iccCloseLogicalChannelWithSessionInfo finished";
783}
784
785/*
Sarah Chin912bdf32022-01-28 01:02:16 -0800786 * Test IRadioSim.iccTransmitApduLogicalChannel() for the response returned.
787 */
788TEST_P(RadioSimTest, iccTransmitApduLogicalChannel) {
789 LOG(DEBUG) << "iccTransmitApduLogicalChannel";
790 serial = GetRandomSerialNumber();
791 SimApdu msg;
792 memset(&msg, 0, sizeof(msg));
793 msg.data = std::string();
794
795 radio_sim->iccTransmitApduLogicalChannel(serial, msg);
796 EXPECT_EQ(std::cv_status::no_timeout, wait());
797 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
798 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
Sarah Chin912bdf32022-01-28 01:02:16 -0800799 LOG(DEBUG) << "iccTransmitApduLogicalChannel finished";
800}
801
802/*
803 * Test IRadioSim.requestIccSimAuthentication() for the response returned.
804 */
805TEST_P(RadioSimTest, requestIccSimAuthentication) {
806 LOG(DEBUG) << "requestIccSimAuthentication";
807 serial = GetRandomSerialNumber();
808
809 // Pass wrong challenge string and check RadioError::INVALID_ARGUMENTS
810 // or REQUEST_NOT_SUPPORTED returned as error.
811 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
812 radio_sim->requestIccSimAuthentication(serial, 0, std::string("test"),
813 cardStatus.applications[i].aidPtr);
814 EXPECT_EQ(std::cv_status::no_timeout, wait());
815 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
816 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
817 ASSERT_TRUE(CheckAnyOfErrors(
818 radioRsp_sim->rspInfo.error,
819 {RadioError::INVALID_ARGUMENTS, RadioError::REQUEST_NOT_SUPPORTED}));
820 }
821 LOG(DEBUG) << "requestIccSimAuthentication finished";
822}
823
824/*
825 * Test IRadioSim.getFacilityLockForApp() for the response returned.
826 */
827TEST_P(RadioSimTest, getFacilityLockForApp) {
828 serial = GetRandomSerialNumber();
829 std::string facility = "";
830 std::string password = "";
831 int32_t serviceClass = 1;
832 std::string appId = "";
833
834 radio_sim->getFacilityLockForApp(serial, facility, password, serviceClass, appId);
835
836 EXPECT_EQ(std::cv_status::no_timeout, wait());
837 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
838 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
839
840 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
841 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
842 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR},
843 CHECK_GENERAL_ERROR));
844 }
845}
846
847/*
848 * Test IRadioSim.setFacilityLockForApp() for the response returned.
849 */
850TEST_P(RadioSimTest, setFacilityLockForApp) {
851 serial = GetRandomSerialNumber();
852 std::string facility = "";
853 bool lockState = false;
854 std::string password = "";
855 int32_t serviceClass = 1;
856 std::string appId = "";
857
858 radio_sim->setFacilityLockForApp(serial, facility, lockState, password, serviceClass, appId);
859
860 EXPECT_EQ(std::cv_status::no_timeout, wait());
861 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
862 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
863
864 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
865 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
866 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR},
867 CHECK_GENERAL_ERROR));
868 }
869}
870
871/*
872 * Test IRadioSim.getCdmaSubscription() for the response returned.
873 */
874TEST_P(RadioSimTest, getCdmaSubscription) {
875 LOG(DEBUG) << "getCdmaSubscription";
876 serial = GetRandomSerialNumber();
877
878 radio_sim->getCdmaSubscription(serial);
879 EXPECT_EQ(std::cv_status::no_timeout, wait());
880 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
881 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
882
883 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
884 ASSERT_TRUE(CheckAnyOfErrors(
885 radioRsp_sim->rspInfo.error,
886 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT}));
887 }
888 LOG(DEBUG) << "getCdmaSubscription finished";
889}
890
891/*
892 * Test IRadioSim.getCdmaSubscriptionSource() for the response returned.
893 */
894TEST_P(RadioSimTest, getCdmaSubscriptionSource) {
895 LOG(DEBUG) << "getCdmaSubscriptionSource";
896 serial = GetRandomSerialNumber();
897
898 radio_sim->getCdmaSubscriptionSource(serial);
899 EXPECT_EQ(std::cv_status::no_timeout, wait());
900 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
901 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
902
903 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
904 ASSERT_TRUE(CheckAnyOfErrors(
905 radioRsp_sim->rspInfo.error,
906 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT}));
907 }
908 LOG(DEBUG) << "getCdmaSubscriptionSource finished";
909}
910
911/*
912 * Test IRadioSim.setCdmaSubscriptionSource() for the response returned.
913 */
914TEST_P(RadioSimTest, setCdmaSubscriptionSource) {
915 LOG(DEBUG) << "setCdmaSubscriptionSource";
916 serial = GetRandomSerialNumber();
917
918 radio_sim->setCdmaSubscriptionSource(serial, CdmaSubscriptionSource::RUIM_SIM);
919 EXPECT_EQ(std::cv_status::no_timeout, wait());
920 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
921 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
922
923 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
924 ASSERT_TRUE(CheckAnyOfErrors(
925 radioRsp_sim->rspInfo.error,
926 {RadioError::NONE, RadioError::SIM_ABSENT, RadioError::SUBSCRIPTION_NOT_AVAILABLE},
927 CHECK_GENERAL_ERROR));
928 }
929 LOG(DEBUG) << "setCdmaSubscriptionSource finished";
930}
931
932/*
933 * Test IRadioSim.setUiccSubscription() for the response returned.
934 */
935TEST_P(RadioSimTest, setUiccSubscription) {
936 LOG(DEBUG) << "setUiccSubscription";
937 serial = GetRandomSerialNumber();
938 SelectUiccSub item;
939 memset(&item, 0, sizeof(item));
940
941 radio_sim->setUiccSubscription(serial, item);
942 EXPECT_EQ(std::cv_status::no_timeout, wait());
943 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
944 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
945
946 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
947 ASSERT_TRUE(
948 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
949 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
950 RadioError::MODEM_ERR, RadioError::SUBSCRIPTION_NOT_SUPPORTED},
951 CHECK_GENERAL_ERROR));
952 }
953 LOG(DEBUG) << "setUiccSubscription finished";
954}
955
956/*
957 * Test IRadioSim.sendEnvelope() for the response returned.
958 */
959TEST_P(RadioSimTest, sendEnvelope) {
960 LOG(DEBUG) << "sendEnvelope";
961 serial = GetRandomSerialNumber();
962
963 // Test with sending empty string
964 std::string content = "";
965
966 radio_sim->sendEnvelope(serial, content);
967
968 EXPECT_EQ(std::cv_status::no_timeout, wait());
969 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
970 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
971
972 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
973 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
974 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
975 RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
976 CHECK_GENERAL_ERROR));
977 }
978 LOG(DEBUG) << "sendEnvelope finished";
979}
980
981/*
982 * Test IRadioSim.sendTerminalResponseToSim() for the response returned.
983 */
984TEST_P(RadioSimTest, sendTerminalResponseToSim) {
985 LOG(DEBUG) << "sendTerminalResponseToSim";
986 serial = GetRandomSerialNumber();
987
988 // Test with sending empty string
989 std::string commandResponse = "";
990
991 radio_sim->sendTerminalResponseToSim(serial, commandResponse);
992
993 EXPECT_EQ(std::cv_status::no_timeout, wait());
994 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
995 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
996
997 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
998 ASSERT_TRUE(CheckAnyOfErrors(
999 radioRsp_sim->rspInfo.error,
1000 {RadioError::NONE, RadioError::INVALID_ARGUMENTS, RadioError::SIM_ABSENT},
1001 CHECK_GENERAL_ERROR));
1002 }
1003 LOG(DEBUG) << "sendTerminalResponseToSim finished";
1004}
1005
1006/*
1007 * Test IRadioSim.reportStkServiceIsRunning() for the response returned.
1008 */
1009TEST_P(RadioSimTest, reportStkServiceIsRunning) {
1010 LOG(DEBUG) << "reportStkServiceIsRunning";
1011 serial = GetRandomSerialNumber();
1012
1013 radio_sim->reportStkServiceIsRunning(serial);
1014
1015 EXPECT_EQ(std::cv_status::no_timeout, wait());
1016 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1017 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1018
1019 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1020 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE},
1021 CHECK_GENERAL_ERROR));
1022 }
1023 LOG(DEBUG) << "reportStkServiceIsRunning finished";
1024}
1025
1026/*
1027 * Test IRadioSim.sendEnvelopeWithStatus() for the response returned with empty
1028 * string.
1029 */
1030TEST_P(RadioSimTest, sendEnvelopeWithStatus) {
1031 LOG(DEBUG) << "sendEnvelopeWithStatus";
1032 serial = GetRandomSerialNumber();
1033
1034 // Test with sending empty string
1035 std::string contents = "";
1036
1037 radio_sim->sendEnvelopeWithStatus(serial, contents);
1038
1039 EXPECT_EQ(std::cv_status::no_timeout, wait());
1040 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1041 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1042
1043 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1044 ASSERT_TRUE(CheckAnyOfErrors(
1045 radioRsp_sim->rspInfo.error,
1046 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
1047 CHECK_GENERAL_ERROR));
1048 }
1049 LOG(DEBUG) << "sendEnvelopeWithStatus finished";
1050}