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