blob: f65714229cae6d21bdb5248b524feb5d751b5785 [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) {
Muralidhar Reddyeb1c6172023-04-12 12:55:19 +0000768 int32_t aidl_version;
769 ndk::ScopedAStatus aidl_status = radio_sim->getInterfaceVersion(&aidl_version);
770 ASSERT_OK(aidl_status);
771 if (aidl_version < 2) {
772 ALOGI("Skipped the test since"
773 " iccCloseLogicalChannelWithSessionInfo is not supported on version < 2");
774 GTEST_SKIP();
775 }
Muralidhar Reddyc13d0d62023-01-18 18:45:14 +0000776 LOG(DEBUG) << "iccCloseLogicalChannelWithSessionInfo";
777 serial = GetRandomSerialNumber();
778 SessionInfo info;
779 memset(&info, 0, sizeof(info));
780 info.sessionId = 0;
781 info.isEs10 = false;
782
783 // Try closing invalid channel and check INVALID_ARGUMENTS returned as error
784 radio_sim->iccCloseLogicalChannelWithSessionInfo(serial, info);
785 EXPECT_EQ(std::cv_status::no_timeout, wait());
786 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
787 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
788
789 EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp_sim->rspInfo.error);
790 LOG(DEBUG) << "iccCloseLogicalChannelWithSessionInfo finished";
791}
792
793/*
Sarah Chin912bdf32022-01-28 01:02:16 -0800794 * Test IRadioSim.iccTransmitApduLogicalChannel() for the response returned.
795 */
796TEST_P(RadioSimTest, iccTransmitApduLogicalChannel) {
797 LOG(DEBUG) << "iccTransmitApduLogicalChannel";
798 serial = GetRandomSerialNumber();
799 SimApdu msg;
800 memset(&msg, 0, sizeof(msg));
801 msg.data = std::string();
802
803 radio_sim->iccTransmitApduLogicalChannel(serial, msg);
804 EXPECT_EQ(std::cv_status::no_timeout, wait());
805 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
806 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
Sarah Chin912bdf32022-01-28 01:02:16 -0800807 LOG(DEBUG) << "iccTransmitApduLogicalChannel finished";
808}
809
810/*
811 * Test IRadioSim.requestIccSimAuthentication() for the response returned.
812 */
813TEST_P(RadioSimTest, requestIccSimAuthentication) {
814 LOG(DEBUG) << "requestIccSimAuthentication";
815 serial = GetRandomSerialNumber();
816
817 // Pass wrong challenge string and check RadioError::INVALID_ARGUMENTS
818 // or REQUEST_NOT_SUPPORTED returned as error.
819 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
820 radio_sim->requestIccSimAuthentication(serial, 0, std::string("test"),
821 cardStatus.applications[i].aidPtr);
822 EXPECT_EQ(std::cv_status::no_timeout, wait());
823 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
824 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
825 ASSERT_TRUE(CheckAnyOfErrors(
826 radioRsp_sim->rspInfo.error,
827 {RadioError::INVALID_ARGUMENTS, RadioError::REQUEST_NOT_SUPPORTED}));
828 }
829 LOG(DEBUG) << "requestIccSimAuthentication finished";
830}
831
832/*
833 * Test IRadioSim.getFacilityLockForApp() for the response returned.
834 */
835TEST_P(RadioSimTest, getFacilityLockForApp) {
836 serial = GetRandomSerialNumber();
837 std::string facility = "";
838 std::string password = "";
839 int32_t serviceClass = 1;
840 std::string appId = "";
841
842 radio_sim->getFacilityLockForApp(serial, facility, password, serviceClass, appId);
843
844 EXPECT_EQ(std::cv_status::no_timeout, wait());
845 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
846 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
847
848 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
849 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
850 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR},
851 CHECK_GENERAL_ERROR));
852 }
853}
854
855/*
856 * Test IRadioSim.setFacilityLockForApp() for the response returned.
857 */
858TEST_P(RadioSimTest, setFacilityLockForApp) {
859 serial = GetRandomSerialNumber();
860 std::string facility = "";
861 bool lockState = false;
862 std::string password = "";
863 int32_t serviceClass = 1;
864 std::string appId = "";
865
866 radio_sim->setFacilityLockForApp(serial, facility, lockState, password, serviceClass, appId);
867
868 EXPECT_EQ(std::cv_status::no_timeout, wait());
869 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
870 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
871
872 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
873 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
874 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR},
875 CHECK_GENERAL_ERROR));
876 }
877}
878
879/*
880 * Test IRadioSim.getCdmaSubscription() for the response returned.
881 */
882TEST_P(RadioSimTest, getCdmaSubscription) {
883 LOG(DEBUG) << "getCdmaSubscription";
884 serial = GetRandomSerialNumber();
885
886 radio_sim->getCdmaSubscription(serial);
887 EXPECT_EQ(std::cv_status::no_timeout, wait());
888 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
889 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
890
891 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
892 ASSERT_TRUE(CheckAnyOfErrors(
893 radioRsp_sim->rspInfo.error,
894 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT}));
895 }
896 LOG(DEBUG) << "getCdmaSubscription finished";
897}
898
899/*
900 * Test IRadioSim.getCdmaSubscriptionSource() for the response returned.
901 */
902TEST_P(RadioSimTest, getCdmaSubscriptionSource) {
903 LOG(DEBUG) << "getCdmaSubscriptionSource";
904 serial = GetRandomSerialNumber();
905
906 radio_sim->getCdmaSubscriptionSource(serial);
907 EXPECT_EQ(std::cv_status::no_timeout, wait());
908 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
909 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
910
911 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
912 ASSERT_TRUE(CheckAnyOfErrors(
913 radioRsp_sim->rspInfo.error,
914 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT}));
915 }
916 LOG(DEBUG) << "getCdmaSubscriptionSource finished";
917}
918
919/*
920 * Test IRadioSim.setCdmaSubscriptionSource() for the response returned.
921 */
922TEST_P(RadioSimTest, setCdmaSubscriptionSource) {
923 LOG(DEBUG) << "setCdmaSubscriptionSource";
924 serial = GetRandomSerialNumber();
925
926 radio_sim->setCdmaSubscriptionSource(serial, CdmaSubscriptionSource::RUIM_SIM);
927 EXPECT_EQ(std::cv_status::no_timeout, wait());
928 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
929 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
930
931 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
932 ASSERT_TRUE(CheckAnyOfErrors(
933 radioRsp_sim->rspInfo.error,
934 {RadioError::NONE, RadioError::SIM_ABSENT, RadioError::SUBSCRIPTION_NOT_AVAILABLE},
935 CHECK_GENERAL_ERROR));
936 }
937 LOG(DEBUG) << "setCdmaSubscriptionSource finished";
938}
939
940/*
941 * Test IRadioSim.setUiccSubscription() for the response returned.
942 */
943TEST_P(RadioSimTest, setUiccSubscription) {
944 LOG(DEBUG) << "setUiccSubscription";
945 serial = GetRandomSerialNumber();
946 SelectUiccSub item;
947 memset(&item, 0, sizeof(item));
948
949 radio_sim->setUiccSubscription(serial, item);
950 EXPECT_EQ(std::cv_status::no_timeout, wait());
951 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
952 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
953
954 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
955 ASSERT_TRUE(
956 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
957 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
958 RadioError::MODEM_ERR, RadioError::SUBSCRIPTION_NOT_SUPPORTED},
959 CHECK_GENERAL_ERROR));
960 }
961 LOG(DEBUG) << "setUiccSubscription finished";
962}
963
964/*
965 * Test IRadioSim.sendEnvelope() for the response returned.
966 */
967TEST_P(RadioSimTest, sendEnvelope) {
968 LOG(DEBUG) << "sendEnvelope";
969 serial = GetRandomSerialNumber();
970
971 // Test with sending empty string
972 std::string content = "";
973
974 radio_sim->sendEnvelope(serial, content);
975
976 EXPECT_EQ(std::cv_status::no_timeout, wait());
977 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
978 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
979
980 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
981 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
982 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
983 RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
984 CHECK_GENERAL_ERROR));
985 }
986 LOG(DEBUG) << "sendEnvelope finished";
987}
988
989/*
990 * Test IRadioSim.sendTerminalResponseToSim() for the response returned.
991 */
992TEST_P(RadioSimTest, sendTerminalResponseToSim) {
993 LOG(DEBUG) << "sendTerminalResponseToSim";
994 serial = GetRandomSerialNumber();
995
996 // Test with sending empty string
997 std::string commandResponse = "";
998
999 radio_sim->sendTerminalResponseToSim(serial, commandResponse);
1000
1001 EXPECT_EQ(std::cv_status::no_timeout, wait());
1002 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1003 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1004
1005 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1006 ASSERT_TRUE(CheckAnyOfErrors(
1007 radioRsp_sim->rspInfo.error,
1008 {RadioError::NONE, RadioError::INVALID_ARGUMENTS, RadioError::SIM_ABSENT},
1009 CHECK_GENERAL_ERROR));
1010 }
1011 LOG(DEBUG) << "sendTerminalResponseToSim finished";
1012}
1013
1014/*
1015 * Test IRadioSim.reportStkServiceIsRunning() for the response returned.
1016 */
1017TEST_P(RadioSimTest, reportStkServiceIsRunning) {
1018 LOG(DEBUG) << "reportStkServiceIsRunning";
1019 serial = GetRandomSerialNumber();
1020
1021 radio_sim->reportStkServiceIsRunning(serial);
1022
1023 EXPECT_EQ(std::cv_status::no_timeout, wait());
1024 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1025 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1026
1027 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1028 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE},
1029 CHECK_GENERAL_ERROR));
1030 }
1031 LOG(DEBUG) << "reportStkServiceIsRunning finished";
1032}
1033
1034/*
1035 * Test IRadioSim.sendEnvelopeWithStatus() for the response returned with empty
1036 * string.
1037 */
1038TEST_P(RadioSimTest, sendEnvelopeWithStatus) {
1039 LOG(DEBUG) << "sendEnvelopeWithStatus";
1040 serial = GetRandomSerialNumber();
1041
1042 // Test with sending empty string
1043 std::string contents = "";
1044
1045 radio_sim->sendEnvelopeWithStatus(serial, contents);
1046
1047 EXPECT_EQ(std::cv_status::no_timeout, wait());
1048 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1049 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1050
1051 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1052 ASSERT_TRUE(CheckAnyOfErrors(
1053 radioRsp_sim->rspInfo.error,
1054 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
1055 CHECK_GENERAL_ERROR));
1056 }
1057 LOG(DEBUG) << "sendEnvelopeWithStatus finished";
1058}