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