blob: e82235c2b6200fe7b16f1093a01e48fa32430688 [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) {
Sarah Chin912bdf32022-01-28 01:02:16 -0800379 serial = GetRandomSerialNumber();
380 CarrierRestrictions carrierRestrictions;
381 memset(&carrierRestrictions, 0, sizeof(carrierRestrictions));
382 carrierRestrictions.allowedCarriers.resize(1);
383 carrierRestrictions.excludedCarriers.resize(0);
384 carrierRestrictions.allowedCarriers[0].mcc = std::string("123");
385 carrierRestrictions.allowedCarriers[0].mnc = std::string("456");
386 carrierRestrictions.allowedCarriers[0].matchType = Carrier::MATCH_TYPE_ALL;
387 carrierRestrictions.allowedCarriers[0].matchData = std::string();
Sarah Chin912bdf32022-01-28 01:02:16 -0800388 carrierRestrictions.allowedCarriersPrioritized = true;
389 SimLockMultiSimPolicy multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY;
390
391 radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy);
392 EXPECT_EQ(std::cv_status::no_timeout, wait());
393 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
394 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
395
396 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
397 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
398
399 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
400 /* Verify the update of the SIM status. This might need some time */
401 if (cardStatus.cardState != CardStatus::STATE_ABSENT) {
402 updateSimCardStatus();
403 auto startTime = std::chrono::system_clock::now();
404 while (cardStatus.cardState != CardStatus::STATE_RESTRICTED &&
405 std::chrono::duration_cast<std::chrono::seconds>(
406 std::chrono::system_clock::now() - startTime)
407 .count() < 30) {
408 /* Set 2 seconds as interval to check card status */
409 sleep(2);
410 updateSimCardStatus();
411 }
Sarah Chin0623bdd2022-02-16 11:09:26 -0800412 // TODO: uncomment once CF fully supports setAllowedCarriers
413 // EXPECT_EQ(CardStatus::STATE_RESTRICTED, cardStatus.cardState);
Sarah Chin912bdf32022-01-28 01:02:16 -0800414 }
415
416 /* Verify that configuration was set correctly, retrieving it from the modem */
417 serial = GetRandomSerialNumber();
418
419 radio_sim->getAllowedCarriers(serial);
420 EXPECT_EQ(std::cv_status::no_timeout, wait());
421 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
422 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
423 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
424
425 EXPECT_EQ(1, radioRsp_sim->carrierRestrictionsResp.allowedCarriers.size());
426 EXPECT_EQ(0, radioRsp_sim->carrierRestrictionsResp.excludedCarriers.size());
427 ASSERT_TRUE(std::string("123") ==
428 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mcc);
429 ASSERT_TRUE(std::string("456") ==
430 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mnc);
431 EXPECT_EQ(Carrier::MATCH_TYPE_ALL,
432 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].matchType);
433 ASSERT_TRUE(radioRsp_sim->carrierRestrictionsResp.allowedCarriersPrioritized);
434 EXPECT_EQ(SimLockMultiSimPolicy::NO_MULTISIM_POLICY, radioRsp_sim->multiSimPolicyResp);
435
436 sleep(10);
437
438 /**
439 * Another test case of the API to cover to allow carrier.
440 * If the API is supported, this is also used to reset to no carrier restriction
441 * status for cardStatus.
442 */
443 memset(&carrierRestrictions, 0, sizeof(carrierRestrictions));
444 carrierRestrictions.allowedCarriers.resize(0);
445 carrierRestrictions.excludedCarriers.resize(0);
446 carrierRestrictions.allowedCarriersPrioritized = false;
447
448 serial = GetRandomSerialNumber();
449 radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy);
450 EXPECT_EQ(std::cv_status::no_timeout, wait());
451 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
452 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
453
454 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
455
456 if (cardStatus.cardState != CardStatus::STATE_ABSENT) {
457 /* Resetting back to no carrier restriction needs some time */
458 updateSimCardStatus();
459 auto startTime = std::chrono::system_clock::now();
460 while (cardStatus.cardState == CardStatus::STATE_RESTRICTED &&
461 std::chrono::duration_cast<std::chrono::seconds>(
462 std::chrono::system_clock::now() - startTime)
463 .count() < 10) {
464 /* Set 2 seconds as interval to check card status */
465 sleep(2);
466 updateSimCardStatus();
467 }
468 EXPECT_NE(CardStatus::STATE_RESTRICTED, cardStatus.cardState);
469 sleep(10);
470 }
471 }
472}
473
474/*
475 * Test IRadioSim.getIccCardStatus() for the response returned.
476 */
477TEST_P(RadioSimTest, getIccCardStatus) {
478 LOG(DEBUG) << "getIccCardStatus";
479 EXPECT_LE(cardStatus.applications.size(), RadioConst::CARD_MAX_APPS);
480 EXPECT_LT(cardStatus.gsmUmtsSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
481 EXPECT_LT(cardStatus.cdmaSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
482 EXPECT_LT(cardStatus.imsSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
483 LOG(DEBUG) << "getIccCardStatus finished";
484}
485
486/*
487 * Test IRadioSim.supplyIccPinForApp() for the response returned
488 */
489TEST_P(RadioSimTest, supplyIccPinForApp) {
490 LOG(DEBUG) << "supplyIccPinForApp";
491 serial = GetRandomSerialNumber();
492
493 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
494 // 3GPP2 apps only
495 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
496 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
497 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
498 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
499 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
500 radio_sim->supplyIccPinForApp(serial, std::string("test1"),
501 cardStatus.applications[i].aidPtr);
502 EXPECT_EQ(std::cv_status::no_timeout, wait());
503 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
504 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
505 ASSERT_TRUE(CheckAnyOfErrors(
506 radioRsp_sim->rspInfo.error,
507 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
508 }
509 }
510 LOG(DEBUG) << "supplyIccPinForApp finished";
511}
512
513/*
514 * Test IRadioSim.supplyIccPukForApp() for the response returned.
515 */
516TEST_P(RadioSimTest, supplyIccPukForApp) {
517 LOG(DEBUG) << "supplyIccPukForApp";
518 serial = GetRandomSerialNumber();
519
520 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
521 // 3GPP2 apps only
522 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
523 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
524 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
525 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
526 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
527 radio_sim->supplyIccPukForApp(serial, std::string("test1"), std::string("test2"),
528 cardStatus.applications[i].aidPtr);
529 EXPECT_EQ(std::cv_status::no_timeout, wait());
530 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
531 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
532 ASSERT_TRUE(CheckAnyOfErrors(
533 radioRsp_sim->rspInfo.error,
534 {RadioError::PASSWORD_INCORRECT, RadioError::INVALID_SIM_STATE}));
535 }
536 }
537 LOG(DEBUG) << "supplyIccPukForApp finished";
538}
539
540/*
541 * Test IRadioSim.supplyIccPin2ForApp() for the response returned.
542 */
543TEST_P(RadioSimTest, supplyIccPin2ForApp) {
544 LOG(DEBUG) << "supplyIccPin2ForApp";
545 serial = GetRandomSerialNumber();
546
547 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
548 // 3GPP2 apps only
549 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
550 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
551 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
552 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
553 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
554 radio_sim->supplyIccPin2ForApp(serial, std::string("test1"),
555 cardStatus.applications[i].aidPtr);
556 EXPECT_EQ(std::cv_status::no_timeout, wait());
557 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
558 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
559 ASSERT_TRUE(
560 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
561 {RadioError::PASSWORD_INCORRECT,
562 RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_PUK2}));
563 }
564 }
565 LOG(DEBUG) << "supplyIccPin2ForApp finished";
566}
567
568/*
569 * Test IRadioSim.supplyIccPuk2ForApp() for the response returned.
570 */
571TEST_P(RadioSimTest, supplyIccPuk2ForApp) {
572 LOG(DEBUG) << "supplyIccPuk2ForApp";
573 serial = GetRandomSerialNumber();
574
575 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
576 // 3GPP2 apps only
577 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
578 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
579 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
580 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
581 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
582 radio_sim->supplyIccPuk2ForApp(serial, std::string("test1"), std::string("test2"),
583 cardStatus.applications[i].aidPtr);
584 EXPECT_EQ(std::cv_status::no_timeout, wait());
585 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
586 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
587 ASSERT_TRUE(CheckAnyOfErrors(
588 radioRsp_sim->rspInfo.error,
589 {RadioError::PASSWORD_INCORRECT, RadioError::INVALID_SIM_STATE}));
590 }
591 }
592 LOG(DEBUG) << "supplyIccPuk2ForApp finished";
593}
594
595/*
596 * Test IRadioSim.changeIccPinForApp() for the response returned.
597 */
598TEST_P(RadioSimTest, changeIccPinForApp) {
599 LOG(DEBUG) << "changeIccPinForApp";
600 serial = GetRandomSerialNumber();
601
602 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
603 // 3GPP2 apps only
604 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
605 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
606 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
607 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
608 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
609 radio_sim->changeIccPinForApp(serial, std::string("test1"), std::string("test2"),
610 cardStatus.applications[i].aidPtr);
611 EXPECT_EQ(std::cv_status::no_timeout, wait());
612 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
613 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
614 ASSERT_TRUE(CheckAnyOfErrors(
615 radioRsp_sim->rspInfo.error,
616 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
617 }
618 }
619 LOG(DEBUG) << "changeIccPinForApp finished";
620}
621
622/*
623 * Test IRadioSim.changeIccPin2ForApp() for the response returned.
624 */
625TEST_P(RadioSimTest, changeIccPin2ForApp) {
626 LOG(DEBUG) << "changeIccPin2ForApp";
627 serial = GetRandomSerialNumber();
628
629 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
630 // 3GPP2 apps only
631 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
632 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
633 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
634 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
635 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
636 radio_sim->changeIccPin2ForApp(serial, std::string("test1"), std::string("test2"),
637 cardStatus.applications[i].aidPtr);
638 EXPECT_EQ(std::cv_status::no_timeout, wait());
639 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
640 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
641 ASSERT_TRUE(
642 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
643 {RadioError::PASSWORD_INCORRECT,
644 RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_PUK2}));
645 }
646 }
647 LOG(DEBUG) << "changeIccPin2ForApp finished";
648}
649
650/*
Sarah Chin912bdf32022-01-28 01:02:16 -0800651 * Test IRadioSim.getImsiForApp() for the response returned.
652 */
Sarah Chinca421a62022-01-28 15:54:36 -0800653TEST_P(RadioSimTest, getImsiForApp) {
654 LOG(DEBUG) << "getImsiForApp";
Sarah Chin912bdf32022-01-28 01:02:16 -0800655 serial = GetRandomSerialNumber();
656
657 // Check success returned while getting imsi for 3GPP and 3GPP2 apps only
658 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
659 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
660 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
661 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
662 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
663 radio_sim->getImsiForApp(serial, cardStatus.applications[i].aidPtr);
664 EXPECT_EQ(std::cv_status::no_timeout, wait());
665 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
666 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
667 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE},
668 CHECK_GENERAL_ERROR));
669
670 // IMSI (MCC+MNC+MSIN) is at least 6 digits, but not more than 15
671 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
672 EXPECT_NE(radioRsp_sim->imsi, std::string());
673 EXPECT_GE((int)(radioRsp_sim->imsi).size(), 6);
674 EXPECT_LE((int)(radioRsp_sim->imsi).size(), 15);
675 }
676 }
677 }
Sarah Chinca421a62022-01-28 15:54:36 -0800678 LOG(DEBUG) << "getImsiForApp finished";
Sarah Chin912bdf32022-01-28 01:02:16 -0800679}
680
681/*
682 * Test IRadioSim.iccIoForApp() for the response returned.
683 */
684TEST_P(RadioSimTest, iccIoForApp) {
685 LOG(DEBUG) << "iccIoForApp";
686 serial = GetRandomSerialNumber();
687
688 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
689 IccIo iccIo;
690 iccIo.command = 0xc0;
691 iccIo.fileId = 0x6f11;
692 iccIo.path = std::string("3F007FFF");
693 iccIo.p1 = 0;
694 iccIo.p2 = 0;
695 iccIo.p3 = 0;
696 iccIo.data = std::string();
697 iccIo.pin2 = std::string();
698 iccIo.aid = cardStatus.applications[i].aidPtr;
699
700 radio_sim->iccIoForApp(serial, iccIo);
701 EXPECT_EQ(std::cv_status::no_timeout, wait());
702 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
703 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
704 }
705 LOG(DEBUG) << "iccIoForApp finished";
706}
707
708/*
709 * Test IRadioSim.iccTransmitApduBasicChannel() for the response returned.
710 */
711TEST_P(RadioSimTest, iccTransmitApduBasicChannel) {
712 LOG(DEBUG) << "iccTransmitApduBasicChannel";
713 serial = GetRandomSerialNumber();
714 SimApdu msg;
715 memset(&msg, 0, sizeof(msg));
716 msg.data = std::string();
717
718 radio_sim->iccTransmitApduBasicChannel(serial, msg);
719 EXPECT_EQ(std::cv_status::no_timeout, wait());
720 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
721 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
Sarah Chin912bdf32022-01-28 01:02:16 -0800722 LOG(DEBUG) << "iccTransmitApduBasicChannel finished";
723}
724
725/*
726 * Test IRadioSim.iccOpenLogicalChannel() for the response returned.
727 */
728TEST_P(RadioSimTest, iccOpenLogicalChannel) {
729 LOG(DEBUG) << "iccOpenLogicalChannel";
730 serial = GetRandomSerialNumber();
731 int p2 = 0x04;
732 // Specified in ISO 7816-4 clause 7.1.1 0x04 means that FCP template is requested.
733 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
734 radio_sim->iccOpenLogicalChannel(serial, cardStatus.applications[i].aidPtr, p2);
735 EXPECT_EQ(std::cv_status::no_timeout, wait());
736 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
737 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
738 }
739 LOG(DEBUG) << "iccOpenLogicalChannel finished";
740}
741
742/*
743 * Test IRadioSim.iccCloseLogicalChannel() for the response returned.
744 */
745TEST_P(RadioSimTest, iccCloseLogicalChannel) {
746 LOG(DEBUG) << "iccCloseLogicalChannel";
747 serial = GetRandomSerialNumber();
748 // Try closing invalid channel and check INVALID_ARGUMENTS returned as error
749 radio_sim->iccCloseLogicalChannel(serial, 0);
750 EXPECT_EQ(std::cv_status::no_timeout, wait());
751 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
752 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
753
754 EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp_sim->rspInfo.error);
755 LOG(DEBUG) << "iccCloseLogicalChannel finished";
756}
757
758/*
759 * Test IRadioSim.iccTransmitApduLogicalChannel() for the response returned.
760 */
761TEST_P(RadioSimTest, iccTransmitApduLogicalChannel) {
762 LOG(DEBUG) << "iccTransmitApduLogicalChannel";
763 serial = GetRandomSerialNumber();
764 SimApdu msg;
765 memset(&msg, 0, sizeof(msg));
766 msg.data = std::string();
767
768 radio_sim->iccTransmitApduLogicalChannel(serial, msg);
769 EXPECT_EQ(std::cv_status::no_timeout, wait());
770 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
771 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
Sarah Chin912bdf32022-01-28 01:02:16 -0800772 LOG(DEBUG) << "iccTransmitApduLogicalChannel finished";
773}
774
775/*
776 * Test IRadioSim.requestIccSimAuthentication() for the response returned.
777 */
778TEST_P(RadioSimTest, requestIccSimAuthentication) {
779 LOG(DEBUG) << "requestIccSimAuthentication";
780 serial = GetRandomSerialNumber();
781
782 // Pass wrong challenge string and check RadioError::INVALID_ARGUMENTS
783 // or REQUEST_NOT_SUPPORTED returned as error.
784 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
785 radio_sim->requestIccSimAuthentication(serial, 0, std::string("test"),
786 cardStatus.applications[i].aidPtr);
787 EXPECT_EQ(std::cv_status::no_timeout, wait());
788 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
789 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
790 ASSERT_TRUE(CheckAnyOfErrors(
791 radioRsp_sim->rspInfo.error,
792 {RadioError::INVALID_ARGUMENTS, RadioError::REQUEST_NOT_SUPPORTED}));
793 }
794 LOG(DEBUG) << "requestIccSimAuthentication finished";
795}
796
797/*
798 * Test IRadioSim.getFacilityLockForApp() for the response returned.
799 */
800TEST_P(RadioSimTest, getFacilityLockForApp) {
801 serial = GetRandomSerialNumber();
802 std::string facility = "";
803 std::string password = "";
804 int32_t serviceClass = 1;
805 std::string appId = "";
806
807 radio_sim->getFacilityLockForApp(serial, facility, password, serviceClass, appId);
808
809 EXPECT_EQ(std::cv_status::no_timeout, wait());
810 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
811 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
812
813 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
814 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
815 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR},
816 CHECK_GENERAL_ERROR));
817 }
818}
819
820/*
821 * Test IRadioSim.setFacilityLockForApp() for the response returned.
822 */
823TEST_P(RadioSimTest, setFacilityLockForApp) {
824 serial = GetRandomSerialNumber();
825 std::string facility = "";
826 bool lockState = false;
827 std::string password = "";
828 int32_t serviceClass = 1;
829 std::string appId = "";
830
831 radio_sim->setFacilityLockForApp(serial, facility, lockState, password, serviceClass, appId);
832
833 EXPECT_EQ(std::cv_status::no_timeout, wait());
834 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
835 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
836
837 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
838 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
839 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR},
840 CHECK_GENERAL_ERROR));
841 }
842}
843
844/*
845 * Test IRadioSim.getCdmaSubscription() for the response returned.
846 */
847TEST_P(RadioSimTest, getCdmaSubscription) {
848 LOG(DEBUG) << "getCdmaSubscription";
849 serial = GetRandomSerialNumber();
850
851 radio_sim->getCdmaSubscription(serial);
852 EXPECT_EQ(std::cv_status::no_timeout, wait());
853 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
854 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
855
856 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
857 ASSERT_TRUE(CheckAnyOfErrors(
858 radioRsp_sim->rspInfo.error,
859 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT}));
860 }
861 LOG(DEBUG) << "getCdmaSubscription finished";
862}
863
864/*
865 * Test IRadioSim.getCdmaSubscriptionSource() for the response returned.
866 */
867TEST_P(RadioSimTest, getCdmaSubscriptionSource) {
868 LOG(DEBUG) << "getCdmaSubscriptionSource";
869 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 }
881 LOG(DEBUG) << "getCdmaSubscriptionSource finished";
882}
883
884/*
885 * Test IRadioSim.setCdmaSubscriptionSource() for the response returned.
886 */
887TEST_P(RadioSimTest, setCdmaSubscriptionSource) {
888 LOG(DEBUG) << "setCdmaSubscriptionSource";
889 serial = GetRandomSerialNumber();
890
891 radio_sim->setCdmaSubscriptionSource(serial, CdmaSubscriptionSource::RUIM_SIM);
892 EXPECT_EQ(std::cv_status::no_timeout, wait());
893 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
894 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
895
896 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
897 ASSERT_TRUE(CheckAnyOfErrors(
898 radioRsp_sim->rspInfo.error,
899 {RadioError::NONE, RadioError::SIM_ABSENT, RadioError::SUBSCRIPTION_NOT_AVAILABLE},
900 CHECK_GENERAL_ERROR));
901 }
902 LOG(DEBUG) << "setCdmaSubscriptionSource finished";
903}
904
905/*
906 * Test IRadioSim.setUiccSubscription() for the response returned.
907 */
908TEST_P(RadioSimTest, setUiccSubscription) {
909 LOG(DEBUG) << "setUiccSubscription";
910 serial = GetRandomSerialNumber();
911 SelectUiccSub item;
912 memset(&item, 0, sizeof(item));
913
914 radio_sim->setUiccSubscription(serial, item);
915 EXPECT_EQ(std::cv_status::no_timeout, wait());
916 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
917 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
918
919 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
920 ASSERT_TRUE(
921 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
922 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
923 RadioError::MODEM_ERR, RadioError::SUBSCRIPTION_NOT_SUPPORTED},
924 CHECK_GENERAL_ERROR));
925 }
926 LOG(DEBUG) << "setUiccSubscription finished";
927}
928
929/*
930 * Test IRadioSim.sendEnvelope() for the response returned.
931 */
932TEST_P(RadioSimTest, sendEnvelope) {
933 LOG(DEBUG) << "sendEnvelope";
934 serial = GetRandomSerialNumber();
935
936 // Test with sending empty string
937 std::string content = "";
938
939 radio_sim->sendEnvelope(serial, content);
940
941 EXPECT_EQ(std::cv_status::no_timeout, wait());
942 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
943 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
944
945 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
946 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
947 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
948 RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
949 CHECK_GENERAL_ERROR));
950 }
951 LOG(DEBUG) << "sendEnvelope finished";
952}
953
954/*
955 * Test IRadioSim.sendTerminalResponseToSim() for the response returned.
956 */
957TEST_P(RadioSimTest, sendTerminalResponseToSim) {
958 LOG(DEBUG) << "sendTerminalResponseToSim";
959 serial = GetRandomSerialNumber();
960
961 // Test with sending empty string
962 std::string commandResponse = "";
963
964 radio_sim->sendTerminalResponseToSim(serial, commandResponse);
965
966 EXPECT_EQ(std::cv_status::no_timeout, wait());
967 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
968 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
969
970 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
971 ASSERT_TRUE(CheckAnyOfErrors(
972 radioRsp_sim->rspInfo.error,
973 {RadioError::NONE, RadioError::INVALID_ARGUMENTS, RadioError::SIM_ABSENT},
974 CHECK_GENERAL_ERROR));
975 }
976 LOG(DEBUG) << "sendTerminalResponseToSim finished";
977}
978
979/*
980 * Test IRadioSim.reportStkServiceIsRunning() for the response returned.
981 */
982TEST_P(RadioSimTest, reportStkServiceIsRunning) {
983 LOG(DEBUG) << "reportStkServiceIsRunning";
984 serial = GetRandomSerialNumber();
985
986 radio_sim->reportStkServiceIsRunning(serial);
987
988 EXPECT_EQ(std::cv_status::no_timeout, wait());
989 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
990 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
991
992 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
993 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE},
994 CHECK_GENERAL_ERROR));
995 }
996 LOG(DEBUG) << "reportStkServiceIsRunning finished";
997}
998
999/*
1000 * Test IRadioSim.sendEnvelopeWithStatus() for the response returned with empty
1001 * string.
1002 */
1003TEST_P(RadioSimTest, sendEnvelopeWithStatus) {
1004 LOG(DEBUG) << "sendEnvelopeWithStatus";
1005 serial = GetRandomSerialNumber();
1006
1007 // Test with sending empty string
1008 std::string contents = "";
1009
1010 radio_sim->sendEnvelopeWithStatus(serial, contents);
1011
1012 EXPECT_EQ(std::cv_status::no_timeout, wait());
1013 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1014 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1015
1016 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1017 ASSERT_TRUE(CheckAnyOfErrors(
1018 radioRsp_sim->rspInfo.error,
1019 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
1020 CHECK_GENERAL_ERROR));
1021 }
1022 LOG(DEBUG) << "sendEnvelopeWithStatus finished";
1023}