blob: d90658893bd0c49f7cfcd628f4c4f1d973806a01 [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 China1efe7a2023-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);
114 EXPECT_EQ(0, cardStatus.slotMap.portId);
115 }
Sarah Chinfc5603b2021-12-21 11:34:00 -0800116 }
117}
118
119/*
120 * Test IRadioSim.setCarrierInfoForImsiEncryption() for the response returned.
121 */
122TEST_P(RadioSimTest, setCarrierInfoForImsiEncryption) {
123 serial = GetRandomSerialNumber();
124 ImsiEncryptionInfo imsiInfo;
125 imsiInfo.mcc = "310";
126 imsiInfo.mnc = "004";
127 imsiInfo.carrierKey = (std::vector<uint8_t>){1, 2, 3, 4, 5, 6};
128 imsiInfo.keyIdentifier = "Test";
129 imsiInfo.expirationTime = 20180101;
130 imsiInfo.keyType = ImsiEncryptionInfo::PUBLIC_KEY_TYPE_EPDG;
131
132 radio_sim->setCarrierInfoForImsiEncryption(serial, imsiInfo);
133 EXPECT_EQ(std::cv_status::no_timeout, wait());
134 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
135 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
136
137 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
138 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
139 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
140 }
141}
142
143/*
144 * Test IRadioSim.getSimPhonebookRecords() for the response returned.
145 */
146TEST_P(RadioSimTest, getSimPhonebookRecords) {
147 serial = GetRandomSerialNumber();
148 radio_sim->getSimPhonebookRecords(serial);
149 EXPECT_EQ(std::cv_status::no_timeout, wait());
150 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
151 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
152 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
153 ASSERT_TRUE(
154 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
155 {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE,
156 RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS,
157 RadioError::REQUEST_NOT_SUPPORTED},
158 CHECK_GENERAL_ERROR));
159 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
160 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
161 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
162 CHECK_GENERAL_ERROR));
163 }
164}
165
166/*
167 * Test IRadioSim.getSimPhonebookCapacity for the response returned.
168 */
169TEST_P(RadioSimTest, getSimPhonebookCapacity) {
170 serial = GetRandomSerialNumber();
171 radio_sim->getSimPhonebookCapacity(serial);
172 EXPECT_EQ(std::cv_status::no_timeout, wait());
173 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
174 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
175 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
176 ASSERT_TRUE(
177 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
178 {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE,
179 RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS,
180 RadioError::REQUEST_NOT_SUPPORTED},
181 CHECK_GENERAL_ERROR));
182 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
183 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
184 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
185 CHECK_GENERAL_ERROR));
186
187 PhonebookCapacity pbCapacity = radioRsp_sim->capacity;
188 if (pbCapacity.maxAdnRecords > 0) {
189 EXPECT_TRUE(pbCapacity.maxNameLen > 0 && pbCapacity.maxNumberLen > 0);
190 EXPECT_TRUE(pbCapacity.usedAdnRecords <= pbCapacity.maxAdnRecords);
191 }
192
193 if (pbCapacity.maxEmailRecords > 0) {
194 EXPECT_TRUE(pbCapacity.maxEmailLen > 0);
195 EXPECT_TRUE(pbCapacity.usedEmailRecords <= pbCapacity.maxEmailRecords);
196 }
197
198 if (pbCapacity.maxAdditionalNumberRecords > 0) {
199 EXPECT_TRUE(pbCapacity.maxAdditionalNumberLen > 0);
200 EXPECT_TRUE(pbCapacity.usedAdditionalNumberRecords <=
201 pbCapacity.maxAdditionalNumberRecords);
202 }
203 }
204}
205
206/*
207 * Test IRadioSim.updateSimPhonebookRecords() for the response returned.
208 */
209TEST_P(RadioSimTest, updateSimPhonebookRecords) {
210 serial = GetRandomSerialNumber();
211 radio_sim->getSimPhonebookCapacity(serial);
212 EXPECT_EQ(std::cv_status::no_timeout, wait());
213 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
214 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
215 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
216 ASSERT_TRUE(
217 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
218 {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE,
219 RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS,
220 RadioError::REQUEST_NOT_SUPPORTED},
221 CHECK_GENERAL_ERROR));
222 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
223 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
224 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
225 CHECK_GENERAL_ERROR));
226 PhonebookCapacity pbCapacity = radioRsp_sim->capacity;
227
228 serial = GetRandomSerialNumber();
229 radio_sim->getSimPhonebookRecords(serial);
230
231 EXPECT_EQ(std::cv_status::no_timeout, wait());
232 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
233 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
234 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
235 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
236 CHECK_GENERAL_ERROR));
237
238 if (pbCapacity.maxAdnRecords > 0 && pbCapacity.usedAdnRecords < pbCapacity.maxAdnRecords) {
239 // Add a phonebook record
240 PhonebookRecordInfo recordInfo;
241 recordInfo.recordId = 0;
242 recordInfo.name = "ABC";
243 recordInfo.number = "1234567890";
244 serial = GetRandomSerialNumber();
245 radio_sim->updateSimPhonebookRecords(serial, recordInfo);
246
247 EXPECT_EQ(std::cv_status::no_timeout, wait());
248 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
249 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
250 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
251 int index = radioRsp_sim->updatedRecordIndex;
252 EXPECT_TRUE(index > 0);
253
254 // Deleted a phonebook record
255 recordInfo.recordId = index;
256 recordInfo.name = "";
257 recordInfo.number = "";
258 serial = GetRandomSerialNumber();
259 radio_sim->updateSimPhonebookRecords(serial, recordInfo);
260
261 EXPECT_EQ(std::cv_status::no_timeout, wait());
262 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
263 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
264 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
265 }
266 }
267}
Sarah Chin912bdf32022-01-28 01:02:16 -0800268
269/*
270 * Test IRadioSim.enableUiccApplications() for the response returned.
271 * For SIM ABSENT case.
272 */
273TEST_P(RadioSimTest, togglingUiccApplicationsSimAbsent) {
274 // This test case only test SIM ABSENT case.
275 if (cardStatus.cardState != CardStatus::STATE_ABSENT) return;
276
277 // Disable Uicc applications.
278 serial = GetRandomSerialNumber();
279 radio_sim->enableUiccApplications(serial, false);
280 EXPECT_EQ(std::cv_status::no_timeout, wait());
281 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
282 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
283 // As SIM is absent, RadioError::SIM_ABSENT should be thrown.
284 EXPECT_EQ(RadioError::SIM_ABSENT, radioRsp_sim->rspInfo.error);
285
286 // Query Uicc application enablement.
287 serial = GetRandomSerialNumber();
288 radio_sim->areUiccApplicationsEnabled(serial);
289 EXPECT_EQ(std::cv_status::no_timeout, wait());
290 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
291 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
292 // As SIM is absent, RadioError::SIM_ABSENT should be thrown.
293 EXPECT_EQ(RadioError::SIM_ABSENT, radioRsp_sim->rspInfo.error);
294}
295
296/*
297 * Test IRadioSim.enableUiccApplications() for the response returned.
298 * For SIM PRESENT case.
299 */
300TEST_P(RadioSimTest, togglingUiccApplicationsSimPresent) {
301 // This test case only test SIM ABSENT case.
302 if (cardStatus.cardState != CardStatus::STATE_PRESENT) return;
303 if (cardStatus.applications.size() == 0) return;
304
305 // Disable Uicc applications.
306 serial = GetRandomSerialNumber();
307 radio_sim->enableUiccApplications(serial, false);
308 EXPECT_EQ(std::cv_status::no_timeout, wait());
309 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
310 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
311 // As SIM is present, there shouldn't be error.
312 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
313
314 // Query Uicc application enablement.
315 serial = GetRandomSerialNumber();
316 radio_sim->areUiccApplicationsEnabled(serial);
317 EXPECT_EQ(std::cv_status::no_timeout, wait());
318 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
319 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
320 // As SIM is present, there shouldn't be error.
321 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
322 ASSERT_FALSE(radioRsp_sim->areUiccApplicationsEnabled);
323
324 // Enable Uicc applications.
325 serial = GetRandomSerialNumber();
326 radio_sim->enableUiccApplications(serial, true);
327 EXPECT_EQ(std::cv_status::no_timeout, wait());
328 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
329 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
330 // As SIM is present, there shouldn't be error.
331 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
332
333 // Query Uicc application enablement.
334 serial = GetRandomSerialNumber();
335 radio_sim->areUiccApplicationsEnabled(serial);
336 EXPECT_EQ(std::cv_status::no_timeout, wait());
337 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
338 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
339 // As SIM is present, there shouldn't be error.
340 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
341 ASSERT_TRUE(radioRsp_sim->areUiccApplicationsEnabled);
342}
343
344/*
345 * Test IRadioSim.areUiccApplicationsEnabled() for the response returned.
346 */
347TEST_P(RadioSimTest, areUiccApplicationsEnabled) {
348 // Disable Uicc applications.
349 serial = GetRandomSerialNumber();
350 radio_sim->areUiccApplicationsEnabled(serial);
351 EXPECT_EQ(std::cv_status::no_timeout, wait());
352 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
353 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
354
355 // If SIM is absent, RadioError::SIM_ABSENT should be thrown. Otherwise there shouldn't be any
356 // error.
357 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
358 EXPECT_EQ(RadioError::SIM_ABSENT, radioRsp_sim->rspInfo.error);
359 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
360 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
361 }
362}
363
364/*
365 * Test IRadioSim.getAllowedCarriers() for the response returned.
366 */
367TEST_P(RadioSimTest, getAllowedCarriers) {
368 serial = GetRandomSerialNumber();
369
370 radio_sim->getAllowedCarriers(serial);
371 EXPECT_EQ(std::cv_status::no_timeout, wait());
372 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
373 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
374
375 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
376 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
377}
378
379/**
380 * Test IRadioSim.setAllowedCarriers() for the response returned.
381 */
382TEST_P(RadioSimTest, setAllowedCarriers) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800383 serial = GetRandomSerialNumber();
384 CarrierRestrictions carrierRestrictions;
385 memset(&carrierRestrictions, 0, sizeof(carrierRestrictions));
386 carrierRestrictions.allowedCarriers.resize(1);
387 carrierRestrictions.excludedCarriers.resize(0);
388 carrierRestrictions.allowedCarriers[0].mcc = std::string("123");
389 carrierRestrictions.allowedCarriers[0].mnc = std::string("456");
390 carrierRestrictions.allowedCarriers[0].matchType = Carrier::MATCH_TYPE_ALL;
391 carrierRestrictions.allowedCarriers[0].matchData = std::string();
Sarah Chin912bdf32022-01-28 01:02:16 -0800392 carrierRestrictions.allowedCarriersPrioritized = true;
393 SimLockMultiSimPolicy multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY;
394
395 radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy);
396 EXPECT_EQ(std::cv_status::no_timeout, wait());
397 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
398 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
399
400 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
401 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
402
403 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
404 /* Verify the update of the SIM status. This might need some time */
405 if (cardStatus.cardState != CardStatus::STATE_ABSENT) {
406 updateSimCardStatus();
407 auto startTime = std::chrono::system_clock::now();
408 while (cardStatus.cardState != CardStatus::STATE_RESTRICTED &&
409 std::chrono::duration_cast<std::chrono::seconds>(
410 std::chrono::system_clock::now() - startTime)
411 .count() < 30) {
412 /* Set 2 seconds as interval to check card status */
413 sleep(2);
414 updateSimCardStatus();
415 }
Sarah Chin0623bdd2022-02-16 11:09:26 -0800416 // TODO: uncomment once CF fully supports setAllowedCarriers
417 // EXPECT_EQ(CardStatus::STATE_RESTRICTED, cardStatus.cardState);
Sarah Chin912bdf32022-01-28 01:02:16 -0800418 }
419
420 /* Verify that configuration was set correctly, retrieving it from the modem */
421 serial = GetRandomSerialNumber();
422
423 radio_sim->getAllowedCarriers(serial);
424 EXPECT_EQ(std::cv_status::no_timeout, wait());
425 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
426 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
427 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
428
429 EXPECT_EQ(1, radioRsp_sim->carrierRestrictionsResp.allowedCarriers.size());
430 EXPECT_EQ(0, radioRsp_sim->carrierRestrictionsResp.excludedCarriers.size());
431 ASSERT_TRUE(std::string("123") ==
432 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mcc);
433 ASSERT_TRUE(std::string("456") ==
434 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mnc);
435 EXPECT_EQ(Carrier::MATCH_TYPE_ALL,
436 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].matchType);
437 ASSERT_TRUE(radioRsp_sim->carrierRestrictionsResp.allowedCarriersPrioritized);
438 EXPECT_EQ(SimLockMultiSimPolicy::NO_MULTISIM_POLICY, radioRsp_sim->multiSimPolicyResp);
439
440 sleep(10);
441
442 /**
443 * Another test case of the API to cover to allow carrier.
444 * If the API is supported, this is also used to reset to no carrier restriction
445 * status for cardStatus.
446 */
447 memset(&carrierRestrictions, 0, sizeof(carrierRestrictions));
448 carrierRestrictions.allowedCarriers.resize(0);
449 carrierRestrictions.excludedCarriers.resize(0);
450 carrierRestrictions.allowedCarriersPrioritized = false;
451
452 serial = GetRandomSerialNumber();
453 radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy);
454 EXPECT_EQ(std::cv_status::no_timeout, wait());
455 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
456 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
457
458 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
459
460 if (cardStatus.cardState != CardStatus::STATE_ABSENT) {
461 /* Resetting back to no carrier restriction needs some time */
462 updateSimCardStatus();
463 auto startTime = std::chrono::system_clock::now();
464 while (cardStatus.cardState == CardStatus::STATE_RESTRICTED &&
465 std::chrono::duration_cast<std::chrono::seconds>(
466 std::chrono::system_clock::now() - startTime)
467 .count() < 10) {
468 /* Set 2 seconds as interval to check card status */
469 sleep(2);
470 updateSimCardStatus();
471 }
472 EXPECT_NE(CardStatus::STATE_RESTRICTED, cardStatus.cardState);
473 sleep(10);
474 }
475 }
476}
477
478/*
479 * Test IRadioSim.getIccCardStatus() for the response returned.
480 */
481TEST_P(RadioSimTest, getIccCardStatus) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800482 EXPECT_LE(cardStatus.applications.size(), RadioConst::CARD_MAX_APPS);
483 EXPECT_LT(cardStatus.gsmUmtsSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
484 EXPECT_LT(cardStatus.cdmaSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
485 EXPECT_LT(cardStatus.imsSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
Sarah Chin912bdf32022-01-28 01:02:16 -0800486}
487
488/*
489 * Test IRadioSim.supplyIccPinForApp() for the response returned
490 */
491TEST_P(RadioSimTest, supplyIccPinForApp) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800492 serial = GetRandomSerialNumber();
493
494 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
495 // 3GPP2 apps only
496 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
497 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
498 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
499 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
500 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
501 radio_sim->supplyIccPinForApp(serial, std::string("test1"),
502 cardStatus.applications[i].aidPtr);
503 EXPECT_EQ(std::cv_status::no_timeout, wait());
504 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
505 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
506 ASSERT_TRUE(CheckAnyOfErrors(
507 radioRsp_sim->rspInfo.error,
508 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
509 }
510 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800511}
512
513/*
514 * Test IRadioSim.supplyIccPukForApp() for the response returned.
515 */
516TEST_P(RadioSimTest, supplyIccPukForApp) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800517 serial = GetRandomSerialNumber();
518
519 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
520 // 3GPP2 apps only
521 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
522 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
523 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
524 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
525 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
526 radio_sim->supplyIccPukForApp(serial, std::string("test1"), std::string("test2"),
527 cardStatus.applications[i].aidPtr);
528 EXPECT_EQ(std::cv_status::no_timeout, wait());
529 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
530 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
531 ASSERT_TRUE(CheckAnyOfErrors(
532 radioRsp_sim->rspInfo.error,
533 {RadioError::PASSWORD_INCORRECT, RadioError::INVALID_SIM_STATE}));
534 }
535 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800536}
537
538/*
539 * Test IRadioSim.supplyIccPin2ForApp() for the response returned.
540 */
541TEST_P(RadioSimTest, supplyIccPin2ForApp) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800542 serial = GetRandomSerialNumber();
543
544 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
545 // 3GPP2 apps only
546 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
547 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
548 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
549 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
550 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
551 radio_sim->supplyIccPin2ForApp(serial, std::string("test1"),
552 cardStatus.applications[i].aidPtr);
553 EXPECT_EQ(std::cv_status::no_timeout, wait());
554 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
555 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
556 ASSERT_TRUE(
557 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
558 {RadioError::PASSWORD_INCORRECT,
559 RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_PUK2}));
560 }
561 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800562}
563
564/*
565 * Test IRadioSim.supplyIccPuk2ForApp() for the response returned.
566 */
567TEST_P(RadioSimTest, supplyIccPuk2ForApp) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800568 serial = GetRandomSerialNumber();
569
570 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
571 // 3GPP2 apps only
572 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
573 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
574 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
575 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
576 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
577 radio_sim->supplyIccPuk2ForApp(serial, std::string("test1"), std::string("test2"),
578 cardStatus.applications[i].aidPtr);
579 EXPECT_EQ(std::cv_status::no_timeout, wait());
580 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
581 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
582 ASSERT_TRUE(CheckAnyOfErrors(
583 radioRsp_sim->rspInfo.error,
584 {RadioError::PASSWORD_INCORRECT, RadioError::INVALID_SIM_STATE}));
585 }
586 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800587}
588
589/*
590 * Test IRadioSim.changeIccPinForApp() for the response returned.
591 */
592TEST_P(RadioSimTest, changeIccPinForApp) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800593 serial = GetRandomSerialNumber();
594
595 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
596 // 3GPP2 apps only
597 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
598 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
599 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
600 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
601 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
602 radio_sim->changeIccPinForApp(serial, std::string("test1"), std::string("test2"),
603 cardStatus.applications[i].aidPtr);
604 EXPECT_EQ(std::cv_status::no_timeout, wait());
605 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
606 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
607 ASSERT_TRUE(CheckAnyOfErrors(
608 radioRsp_sim->rspInfo.error,
609 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
610 }
611 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800612}
613
614/*
615 * Test IRadioSim.changeIccPin2ForApp() for the response returned.
616 */
617TEST_P(RadioSimTest, changeIccPin2ForApp) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800618 serial = GetRandomSerialNumber();
619
620 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
621 // 3GPP2 apps only
622 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
623 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
624 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
625 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
626 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
627 radio_sim->changeIccPin2ForApp(serial, std::string("test1"), std::string("test2"),
628 cardStatus.applications[i].aidPtr);
629 EXPECT_EQ(std::cv_status::no_timeout, wait());
630 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
631 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
632 ASSERT_TRUE(
633 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
634 {RadioError::PASSWORD_INCORRECT,
635 RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_PUK2}));
636 }
637 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800638}
639
640/*
Sarah Chin912bdf32022-01-28 01:02:16 -0800641 * Test IRadioSim.getImsiForApp() for the response returned.
642 */
Sarah Chinca421a62022-01-28 15:54:36 -0800643TEST_P(RadioSimTest, getImsiForApp) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800644 serial = GetRandomSerialNumber();
645
646 // Check success returned while getting imsi for 3GPP and 3GPP2 apps only
647 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
648 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
649 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
650 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
651 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
652 radio_sim->getImsiForApp(serial, cardStatus.applications[i].aidPtr);
653 EXPECT_EQ(std::cv_status::no_timeout, wait());
654 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
655 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
656 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE},
657 CHECK_GENERAL_ERROR));
658
659 // IMSI (MCC+MNC+MSIN) is at least 6 digits, but not more than 15
660 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
661 EXPECT_NE(radioRsp_sim->imsi, std::string());
662 EXPECT_GE((int)(radioRsp_sim->imsi).size(), 6);
663 EXPECT_LE((int)(radioRsp_sim->imsi).size(), 15);
664 }
665 }
666 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800667}
668
669/*
670 * Test IRadioSim.iccIoForApp() for the response returned.
671 */
672TEST_P(RadioSimTest, iccIoForApp) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800673 serial = GetRandomSerialNumber();
674
675 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
676 IccIo iccIo;
677 iccIo.command = 0xc0;
678 iccIo.fileId = 0x6f11;
679 iccIo.path = std::string("3F007FFF");
680 iccIo.p1 = 0;
681 iccIo.p2 = 0;
682 iccIo.p3 = 0;
683 iccIo.data = std::string();
684 iccIo.pin2 = std::string();
685 iccIo.aid = cardStatus.applications[i].aidPtr;
686
687 radio_sim->iccIoForApp(serial, iccIo);
688 EXPECT_EQ(std::cv_status::no_timeout, wait());
689 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
690 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
691 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800692}
693
694/*
695 * Test IRadioSim.iccTransmitApduBasicChannel() for the response returned.
696 */
697TEST_P(RadioSimTest, iccTransmitApduBasicChannel) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800698 serial = GetRandomSerialNumber();
699 SimApdu msg;
700 memset(&msg, 0, sizeof(msg));
701 msg.data = std::string();
702
703 radio_sim->iccTransmitApduBasicChannel(serial, msg);
704 EXPECT_EQ(std::cv_status::no_timeout, wait());
705 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
706 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
Sarah Chin912bdf32022-01-28 01:02:16 -0800707}
708
709/*
710 * Test IRadioSim.iccOpenLogicalChannel() for the response returned.
711 */
712TEST_P(RadioSimTest, iccOpenLogicalChannel) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800713 serial = GetRandomSerialNumber();
714 int p2 = 0x04;
715 // Specified in ISO 7816-4 clause 7.1.1 0x04 means that FCP template is requested.
716 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
717 radio_sim->iccOpenLogicalChannel(serial, cardStatus.applications[i].aidPtr, p2);
718 EXPECT_EQ(std::cv_status::no_timeout, wait());
719 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
720 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
721 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800722}
723
724/*
725 * Test IRadioSim.iccCloseLogicalChannel() for the response returned.
726 */
727TEST_P(RadioSimTest, iccCloseLogicalChannel) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800728 serial = GetRandomSerialNumber();
729 // Try closing invalid channel and check INVALID_ARGUMENTS returned as error
730 radio_sim->iccCloseLogicalChannel(serial, 0);
731 EXPECT_EQ(std::cv_status::no_timeout, wait());
732 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
733 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
734
735 EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp_sim->rspInfo.error);
Sarah Chin912bdf32022-01-28 01:02:16 -0800736}
737
738/*
Muralidhar Reddyc13d0d62023-01-18 18:45:14 +0000739 * Test IRadioSim.iccCloseLogicalChannelWithSessionInfo() for the response returned.
740 */
741TEST_P(RadioSimTest, iccCloseLogicalChannelWithSessionInfo) {
Muralidhar Reddyeb1c6172023-04-12 12:55:19 +0000742 int32_t aidl_version;
743 ndk::ScopedAStatus aidl_status = radio_sim->getInterfaceVersion(&aidl_version);
744 ASSERT_OK(aidl_status);
745 if (aidl_version < 2) {
746 ALOGI("Skipped the test since"
747 " iccCloseLogicalChannelWithSessionInfo is not supported on version < 2");
748 GTEST_SKIP();
749 }
Muralidhar Reddyc13d0d62023-01-18 18:45:14 +0000750 serial = GetRandomSerialNumber();
751 SessionInfo info;
752 memset(&info, 0, sizeof(info));
753 info.sessionId = 0;
754 info.isEs10 = false;
755
756 // Try closing invalid channel and check INVALID_ARGUMENTS returned as error
757 radio_sim->iccCloseLogicalChannelWithSessionInfo(serial, info);
758 EXPECT_EQ(std::cv_status::no_timeout, wait());
759 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
760 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
761
762 EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp_sim->rspInfo.error);
Muralidhar Reddyc13d0d62023-01-18 18:45:14 +0000763}
764
765/*
Sarah Chin912bdf32022-01-28 01:02:16 -0800766 * Test IRadioSim.iccTransmitApduLogicalChannel() for the response returned.
767 */
768TEST_P(RadioSimTest, iccTransmitApduLogicalChannel) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800769 serial = GetRandomSerialNumber();
770 SimApdu msg;
771 memset(&msg, 0, sizeof(msg));
772 msg.data = std::string();
773
774 radio_sim->iccTransmitApduLogicalChannel(serial, msg);
775 EXPECT_EQ(std::cv_status::no_timeout, wait());
776 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
777 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
Sarah Chin912bdf32022-01-28 01:02:16 -0800778}
779
780/*
781 * Test IRadioSim.requestIccSimAuthentication() for the response returned.
782 */
783TEST_P(RadioSimTest, requestIccSimAuthentication) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800784 serial = GetRandomSerialNumber();
785
786 // Pass wrong challenge string and check RadioError::INVALID_ARGUMENTS
787 // or REQUEST_NOT_SUPPORTED returned as error.
788 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
789 radio_sim->requestIccSimAuthentication(serial, 0, std::string("test"),
790 cardStatus.applications[i].aidPtr);
791 EXPECT_EQ(std::cv_status::no_timeout, wait());
792 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
793 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
794 ASSERT_TRUE(CheckAnyOfErrors(
795 radioRsp_sim->rspInfo.error,
796 {RadioError::INVALID_ARGUMENTS, RadioError::REQUEST_NOT_SUPPORTED}));
797 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800798}
799
800/*
801 * Test IRadioSim.getFacilityLockForApp() for the response returned.
802 */
803TEST_P(RadioSimTest, getFacilityLockForApp) {
804 serial = GetRandomSerialNumber();
805 std::string facility = "";
806 std::string password = "";
807 int32_t serviceClass = 1;
808 std::string appId = "";
809
810 radio_sim->getFacilityLockForApp(serial, facility, password, serviceClass, appId);
811
812 EXPECT_EQ(std::cv_status::no_timeout, wait());
813 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
814 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
815
816 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
817 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
818 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR},
819 CHECK_GENERAL_ERROR));
820 }
821}
822
823/*
824 * Test IRadioSim.setFacilityLockForApp() for the response returned.
825 */
826TEST_P(RadioSimTest, setFacilityLockForApp) {
827 serial = GetRandomSerialNumber();
828 std::string facility = "";
829 bool lockState = false;
830 std::string password = "";
831 int32_t serviceClass = 1;
832 std::string appId = "";
833
834 radio_sim->setFacilityLockForApp(serial, facility, lockState, 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.getCdmaSubscription() for the response returned.
849 */
850TEST_P(RadioSimTest, getCdmaSubscription) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800851 serial = GetRandomSerialNumber();
852
853 radio_sim->getCdmaSubscription(serial);
854 EXPECT_EQ(std::cv_status::no_timeout, wait());
855 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
856 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
857
858 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
859 ASSERT_TRUE(CheckAnyOfErrors(
860 radioRsp_sim->rspInfo.error,
861 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT}));
862 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800863}
864
865/*
866 * Test IRadioSim.getCdmaSubscriptionSource() for the response returned.
867 */
868TEST_P(RadioSimTest, getCdmaSubscriptionSource) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800869 serial = GetRandomSerialNumber();
870
871 radio_sim->getCdmaSubscriptionSource(serial);
872 EXPECT_EQ(std::cv_status::no_timeout, wait());
873 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
874 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
875
876 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
877 ASSERT_TRUE(CheckAnyOfErrors(
878 radioRsp_sim->rspInfo.error,
879 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT}));
880 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800881}
882
883/*
884 * Test IRadioSim.setCdmaSubscriptionSource() for the response returned.
885 */
886TEST_P(RadioSimTest, setCdmaSubscriptionSource) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800887 serial = GetRandomSerialNumber();
888
889 radio_sim->setCdmaSubscriptionSource(serial, CdmaSubscriptionSource::RUIM_SIM);
890 EXPECT_EQ(std::cv_status::no_timeout, wait());
891 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
892 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
893
894 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
895 ASSERT_TRUE(CheckAnyOfErrors(
896 radioRsp_sim->rspInfo.error,
897 {RadioError::NONE, RadioError::SIM_ABSENT, RadioError::SUBSCRIPTION_NOT_AVAILABLE},
898 CHECK_GENERAL_ERROR));
899 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800900}
901
902/*
903 * Test IRadioSim.setUiccSubscription() for the response returned.
904 */
905TEST_P(RadioSimTest, setUiccSubscription) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800906 serial = GetRandomSerialNumber();
907 SelectUiccSub item;
908 memset(&item, 0, sizeof(item));
909
910 radio_sim->setUiccSubscription(serial, item);
911 EXPECT_EQ(std::cv_status::no_timeout, wait());
912 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
913 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
914
915 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
916 ASSERT_TRUE(
917 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
918 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
919 RadioError::MODEM_ERR, RadioError::SUBSCRIPTION_NOT_SUPPORTED},
920 CHECK_GENERAL_ERROR));
921 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800922}
923
924/*
925 * Test IRadioSim.sendEnvelope() for the response returned.
926 */
927TEST_P(RadioSimTest, sendEnvelope) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800928 serial = GetRandomSerialNumber();
929
930 // Test with sending empty string
931 std::string content = "";
932
933 radio_sim->sendEnvelope(serial, content);
934
935 EXPECT_EQ(std::cv_status::no_timeout, wait());
936 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
937 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
938
939 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
940 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
941 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
942 RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
943 CHECK_GENERAL_ERROR));
944 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800945}
946
947/*
948 * Test IRadioSim.sendTerminalResponseToSim() for the response returned.
949 */
950TEST_P(RadioSimTest, sendTerminalResponseToSim) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800951 serial = GetRandomSerialNumber();
952
953 // Test with sending empty string
954 std::string commandResponse = "";
955
956 radio_sim->sendTerminalResponseToSim(serial, commandResponse);
957
958 EXPECT_EQ(std::cv_status::no_timeout, wait());
959 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
960 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
961
962 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
963 ASSERT_TRUE(CheckAnyOfErrors(
964 radioRsp_sim->rspInfo.error,
965 {RadioError::NONE, RadioError::INVALID_ARGUMENTS, RadioError::SIM_ABSENT},
966 CHECK_GENERAL_ERROR));
967 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800968}
969
970/*
971 * Test IRadioSim.reportStkServiceIsRunning() for the response returned.
972 */
973TEST_P(RadioSimTest, reportStkServiceIsRunning) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800974 serial = GetRandomSerialNumber();
975
976 radio_sim->reportStkServiceIsRunning(serial);
977
978 EXPECT_EQ(std::cv_status::no_timeout, wait());
979 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
980 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
981
982 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
983 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE},
984 CHECK_GENERAL_ERROR));
985 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800986}
987
988/*
989 * Test IRadioSim.sendEnvelopeWithStatus() for the response returned with empty
990 * string.
991 */
992TEST_P(RadioSimTest, sendEnvelopeWithStatus) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800993 serial = GetRandomSerialNumber();
994
995 // Test with sending empty string
996 std::string contents = "";
997
998 radio_sim->sendEnvelopeWithStatus(serial, contents);
999
1000 EXPECT_EQ(std::cv_status::no_timeout, wait());
1001 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1002 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1003
1004 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1005 ASSERT_TRUE(CheckAnyOfErrors(
1006 radioRsp_sim->rspInfo.error,
1007 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
1008 CHECK_GENERAL_ERROR));
1009 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001010}