blob: 6ffe2c55111aa53ffaf186833ef8122cef480783 [file] [log] [blame]
Sarah Chinfc5603b2021-12-21 11:34:00 -08001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Sarah Chin912bdf32022-01-28 01:02:16 -080017#include <aidl/android/hardware/radio/RadioConst.h>
Sarah Chinfc5603b2021-12-21 11:34:00 -080018#include <aidl/android/hardware/radio/config/IRadioConfig.h>
Sarah Chinfc5603b2021-12-21 11:34:00 -080019#include <android/binder_manager.h>
20
21#include "radio_sim_utils.h"
22
23#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
24
25void RadioSimTest::SetUp() {
Sarah China1efe7a2023-05-02 21:11:41 -070026 RadioServiceTest::SetUp();
Sarah Chinfc5603b2021-12-21 11:34:00 -080027 std::string serviceName = GetParam();
28
29 if (!isServiceValidForDeviceConfiguration(serviceName)) {
30 ALOGI("Skipped the test due to device configuration.");
31 GTEST_SKIP();
32 }
33
34 radio_sim = IRadioSim::fromBinder(
35 ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
36 ASSERT_NE(nullptr, radio_sim.get());
37
38 radioRsp_sim = ndk::SharedRefBase::make<RadioSimResponse>(*this);
39 ASSERT_NE(nullptr, radioRsp_sim.get());
40
Sarah Chinfc5603b2021-12-21 11:34:00 -080041 radioInd_sim = ndk::SharedRefBase::make<RadioSimIndication>(*this);
42 ASSERT_NE(nullptr, radioInd_sim.get());
43
44 radio_sim->setResponseFunctions(radioRsp_sim, radioInd_sim);
Sarah Chinc83bce42021-12-29 00:35:12 -080045 // Assert SIM is present before testing
46 updateSimCardStatus();
47 EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState);
Sarah Chinfc5603b2021-12-21 11:34:00 -080048
49 // Assert IRadioConfig exists before testing
Sarah Chinc83bce42021-12-29 00:35:12 -080050 radio_config = config::IRadioConfig::fromBinder(ndk::SpAIBinder(
51 AServiceManager_waitForService("android.hardware.radio.config.IRadioConfig/default")));
52 ASSERT_NE(nullptr, radio_config.get());
Sarah Chinfc5603b2021-12-21 11:34:00 -080053}
54
Sarah Chinc83bce42021-12-29 00:35:12 -080055void RadioSimTest::updateSimCardStatus() {
Sarah Chinfc5603b2021-12-21 11:34:00 -080056 serial = GetRandomSerialNumber();
57 radio_sim->getIccCardStatus(serial);
58 EXPECT_EQ(std::cv_status::no_timeout, wait());
Sarah Chinc83bce42021-12-29 00:35:12 -080059 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
60 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
61 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
Sarah Chinfc5603b2021-12-21 11:34:00 -080062}
63
64/*
65 * Test IRadioSim.setSimCardPower() for the response returned.
66 */
67TEST_P(RadioSimTest, setSimCardPower) {
joonhunshind519aea2023-10-31 03:06:54 +000068 if (telephony_flags::enforce_telephony_feature_mapping()) {
69 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
70 GTEST_SKIP() << "Skipping setSimCardPower "
71 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
72 }
73 }
74
Sarah Chinfc5603b2021-12-21 11:34:00 -080075 /* Test setSimCardPower power down */
76 serial = GetRandomSerialNumber();
77 radio_sim->setSimCardPower(serial, CardPowerState::POWER_DOWN);
78 EXPECT_EQ(std::cv_status::no_timeout, wait());
79 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
80 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
81 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
82 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
83 RadioError::RADIO_NOT_AVAILABLE, RadioError::SIM_ERR}));
84
85 // setSimCardPower does not return until the request is handled, and should not trigger
86 // CardStatus::STATE_ABSENT when turning off power
87 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
88 /* Wait some time for setting sim power down and then verify it */
89 updateSimCardStatus();
90 // We cannot assert the consistency of CardState here due to b/203031664
91 // EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState);
92 // applications should be an empty vector of AppStatus
93 EXPECT_EQ(0, cardStatus.applications.size());
94 }
95
96 // Give some time for modem to fully power down the SIM card
97 sleep(MODEM_SET_SIM_POWER_DELAY_IN_SECONDS);
98
99 /* Test setSimCardPower power up */
100 serial = GetRandomSerialNumber();
101 radio_sim->setSimCardPower(serial, CardPowerState::POWER_UP);
102 EXPECT_EQ(std::cv_status::no_timeout, wait());
103 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
104 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
105 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
106 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
107 RadioError::RADIO_NOT_AVAILABLE, RadioError::SIM_ERR}));
108
109 // Give some time for modem to fully power up the SIM card
110 sleep(MODEM_SET_SIM_POWER_DELAY_IN_SECONDS);
111
112 // setSimCardPower does not return until the request is handled. Just verify that we still
113 // have CardStatus::STATE_PRESENT after turning the power back on
114 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
115 updateSimCardStatus();
Tim Lin8a6a1d32022-03-31 21:06:57 +0800116 updateSimSlotStatus(cardStatus.slotMap.physicalSlotId);
Sarah Chinfc5603b2021-12-21 11:34:00 -0800117 EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState);
sandeepjs5561b4b2022-02-15 11:41:28 +0000118 EXPECT_EQ(CardStatus::STATE_PRESENT, slotStatus.cardState);
119 if (CardStatus::STATE_PRESENT == slotStatus.cardState) {
120 ASSERT_TRUE(slotStatus.portInfo[0].portActive);
sandeepjs2be3b9a2024-07-11 14:57:08 +0000121 if (cardStatus.supportedMepMode == aidl::android::hardware::radio::config::
122 MultipleEnabledProfilesMode::MEP_A1 ||
123 cardStatus.supportedMepMode == aidl::android::hardware::radio::config::
124 MultipleEnabledProfilesMode::MEP_A2) {
125 EXPECT_EQ(1, cardStatus.slotMap.portId);
126 } else {
127 EXPECT_EQ(0, cardStatus.slotMap.portId);
128 }
sandeepjs5561b4b2022-02-15 11:41:28 +0000129 }
Sarah Chinfc5603b2021-12-21 11:34:00 -0800130 }
131}
132
133/*
134 * Test IRadioSim.setCarrierInfoForImsiEncryption() for the response returned.
135 */
136TEST_P(RadioSimTest, setCarrierInfoForImsiEncryption) {
joonhunshind519aea2023-10-31 03:06:54 +0000137 if (telephony_flags::enforce_telephony_feature_mapping()) {
138 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
139 GTEST_SKIP() << "Skipping setCarrierInfoForImsiEncryption "
140 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
141 }
142 }
143
Sarah Chinfc5603b2021-12-21 11:34:00 -0800144 serial = GetRandomSerialNumber();
145 ImsiEncryptionInfo imsiInfo;
146 imsiInfo.mcc = "310";
147 imsiInfo.mnc = "004";
148 imsiInfo.carrierKey = (std::vector<uint8_t>){1, 2, 3, 4, 5, 6};
149 imsiInfo.keyIdentifier = "Test";
150 imsiInfo.expirationTime = 20180101;
151 imsiInfo.keyType = ImsiEncryptionInfo::PUBLIC_KEY_TYPE_EPDG;
152
153 radio_sim->setCarrierInfoForImsiEncryption(serial, imsiInfo);
154 EXPECT_EQ(std::cv_status::no_timeout, wait());
155 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
156 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
157
158 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
159 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
160 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
161 }
162}
163
164/*
165 * Test IRadioSim.getSimPhonebookRecords() for the response returned.
166 */
167TEST_P(RadioSimTest, getSimPhonebookRecords) {
joonhunshind519aea2023-10-31 03:06:54 +0000168 if (telephony_flags::enforce_telephony_feature_mapping()) {
169 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
170 GTEST_SKIP() << "Skipping getSimPhonebookRecords "
171 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
172 }
173 }
174
Sarah Chinfc5603b2021-12-21 11:34:00 -0800175 serial = GetRandomSerialNumber();
176 radio_sim->getSimPhonebookRecords(serial);
177 EXPECT_EQ(std::cv_status::no_timeout, wait());
178 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
179 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
180 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
181 ASSERT_TRUE(
182 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
183 {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE,
184 RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS,
185 RadioError::REQUEST_NOT_SUPPORTED},
186 CHECK_GENERAL_ERROR));
187 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
188 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
189 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
190 CHECK_GENERAL_ERROR));
191 }
192}
193
194/*
195 * Test IRadioSim.getSimPhonebookCapacity for the response returned.
196 */
197TEST_P(RadioSimTest, getSimPhonebookCapacity) {
joonhunshind519aea2023-10-31 03:06:54 +0000198 if (telephony_flags::enforce_telephony_feature_mapping()) {
199 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
200 GTEST_SKIP() << "Skipping getSimPhonebookCapacity "
201 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
202 }
203 }
204
Sarah Chinfc5603b2021-12-21 11:34:00 -0800205 serial = GetRandomSerialNumber();
206 radio_sim->getSimPhonebookCapacity(serial);
207 EXPECT_EQ(std::cv_status::no_timeout, wait());
208 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
209 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
210 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
211 ASSERT_TRUE(
212 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
213 {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE,
214 RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS,
215 RadioError::REQUEST_NOT_SUPPORTED},
216 CHECK_GENERAL_ERROR));
217 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
218 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
219 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
220 CHECK_GENERAL_ERROR));
221
222 PhonebookCapacity pbCapacity = radioRsp_sim->capacity;
223 if (pbCapacity.maxAdnRecords > 0) {
224 EXPECT_TRUE(pbCapacity.maxNameLen > 0 && pbCapacity.maxNumberLen > 0);
225 EXPECT_TRUE(pbCapacity.usedAdnRecords <= pbCapacity.maxAdnRecords);
226 }
227
228 if (pbCapacity.maxEmailRecords > 0) {
229 EXPECT_TRUE(pbCapacity.maxEmailLen > 0);
230 EXPECT_TRUE(pbCapacity.usedEmailRecords <= pbCapacity.maxEmailRecords);
231 }
232
233 if (pbCapacity.maxAdditionalNumberRecords > 0) {
234 EXPECT_TRUE(pbCapacity.maxAdditionalNumberLen > 0);
235 EXPECT_TRUE(pbCapacity.usedAdditionalNumberRecords <=
236 pbCapacity.maxAdditionalNumberRecords);
237 }
238 }
239}
240
241/*
242 * Test IRadioSim.updateSimPhonebookRecords() for the response returned.
243 */
244TEST_P(RadioSimTest, updateSimPhonebookRecords) {
joonhunshind519aea2023-10-31 03:06:54 +0000245 if (telephony_flags::enforce_telephony_feature_mapping()) {
246 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
247 GTEST_SKIP() << "Skipping updateSimPhonebookRecords "
248 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
249 }
250 }
251
Sarah Chinfc5603b2021-12-21 11:34:00 -0800252 serial = GetRandomSerialNumber();
253 radio_sim->getSimPhonebookCapacity(serial);
254 EXPECT_EQ(std::cv_status::no_timeout, wait());
255 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
256 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
257 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
258 ASSERT_TRUE(
259 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
260 {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE,
261 RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS,
262 RadioError::REQUEST_NOT_SUPPORTED},
263 CHECK_GENERAL_ERROR));
264 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
265 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
266 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
267 CHECK_GENERAL_ERROR));
268 PhonebookCapacity pbCapacity = radioRsp_sim->capacity;
269
270 serial = GetRandomSerialNumber();
271 radio_sim->getSimPhonebookRecords(serial);
272
273 EXPECT_EQ(std::cv_status::no_timeout, wait());
274 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
275 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
276 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
277 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
278 CHECK_GENERAL_ERROR));
279
280 if (pbCapacity.maxAdnRecords > 0 && pbCapacity.usedAdnRecords < pbCapacity.maxAdnRecords) {
281 // Add a phonebook record
282 PhonebookRecordInfo recordInfo;
283 recordInfo.recordId = 0;
284 recordInfo.name = "ABC";
285 recordInfo.number = "1234567890";
286 serial = GetRandomSerialNumber();
287 radio_sim->updateSimPhonebookRecords(serial, recordInfo);
288
289 EXPECT_EQ(std::cv_status::no_timeout, wait());
290 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
291 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
292 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
293 int index = radioRsp_sim->updatedRecordIndex;
294 EXPECT_TRUE(index > 0);
295
296 // Deleted a phonebook record
297 recordInfo.recordId = index;
298 recordInfo.name = "";
299 recordInfo.number = "";
300 serial = GetRandomSerialNumber();
301 radio_sim->updateSimPhonebookRecords(serial, recordInfo);
302
303 EXPECT_EQ(std::cv_status::no_timeout, wait());
304 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
305 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
306 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
307 }
308 }
309}
Sarah Chin912bdf32022-01-28 01:02:16 -0800310
311/*
312 * Test IRadioSim.enableUiccApplications() for the response returned.
313 * For SIM ABSENT case.
314 */
315TEST_P(RadioSimTest, togglingUiccApplicationsSimAbsent) {
joonhunshind519aea2023-10-31 03:06:54 +0000316 if (telephony_flags::enforce_telephony_feature_mapping()) {
317 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
318 GTEST_SKIP() << "Skipping togglingUiccApplicationsSimAbsent "
319 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
320 }
321 }
322
Sarah Chin912bdf32022-01-28 01:02:16 -0800323 // This test case only test SIM ABSENT case.
324 if (cardStatus.cardState != CardStatus::STATE_ABSENT) return;
325
326 // Disable Uicc applications.
327 serial = GetRandomSerialNumber();
328 radio_sim->enableUiccApplications(serial, false);
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 absent, RadioError::SIM_ABSENT should be thrown.
333 EXPECT_EQ(RadioError::SIM_ABSENT, 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 absent, RadioError::SIM_ABSENT should be thrown.
342 EXPECT_EQ(RadioError::SIM_ABSENT, radioRsp_sim->rspInfo.error);
343}
344
345/*
346 * Test IRadioSim.enableUiccApplications() for the response returned.
347 * For SIM PRESENT case.
348 */
349TEST_P(RadioSimTest, togglingUiccApplicationsSimPresent) {
joonhunshind519aea2023-10-31 03:06:54 +0000350 if (telephony_flags::enforce_telephony_feature_mapping()) {
351 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
352 GTEST_SKIP() << "Skipping togglingUiccApplicationsSimPresent "
353 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
354 }
355 }
356
Sarah Chin912bdf32022-01-28 01:02:16 -0800357 // This test case only test SIM ABSENT case.
358 if (cardStatus.cardState != CardStatus::STATE_PRESENT) return;
359 if (cardStatus.applications.size() == 0) return;
360
361 // Disable Uicc applications.
362 serial = GetRandomSerialNumber();
363 radio_sim->enableUiccApplications(serial, false);
364 EXPECT_EQ(std::cv_status::no_timeout, wait());
365 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
366 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
367 // As SIM is present, there shouldn't be error.
368 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
369
370 // Query Uicc application enablement.
371 serial = GetRandomSerialNumber();
372 radio_sim->areUiccApplicationsEnabled(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 // As SIM is present, there shouldn't be error.
377 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
378 ASSERT_FALSE(radioRsp_sim->areUiccApplicationsEnabled);
379
380 // Enable Uicc applications.
381 serial = GetRandomSerialNumber();
382 radio_sim->enableUiccApplications(serial, true);
383 EXPECT_EQ(std::cv_status::no_timeout, wait());
384 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
385 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
386 // As SIM is present, there shouldn't be error.
387 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
388
389 // Query Uicc application enablement.
390 serial = GetRandomSerialNumber();
391 radio_sim->areUiccApplicationsEnabled(serial);
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 // As SIM is present, there shouldn't be error.
396 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
397 ASSERT_TRUE(radioRsp_sim->areUiccApplicationsEnabled);
398}
399
400/*
401 * Test IRadioSim.areUiccApplicationsEnabled() for the response returned.
402 */
403TEST_P(RadioSimTest, areUiccApplicationsEnabled) {
joonhunshind519aea2023-10-31 03:06:54 +0000404 if (telephony_flags::enforce_telephony_feature_mapping()) {
405 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
406 GTEST_SKIP() << "Skipping areUiccApplicationsEnabled "
407 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
408 }
409 }
410
Sarah Chin912bdf32022-01-28 01:02:16 -0800411 // Disable Uicc applications.
412 serial = GetRandomSerialNumber();
413 radio_sim->areUiccApplicationsEnabled(serial);
414 EXPECT_EQ(std::cv_status::no_timeout, wait());
415 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
416 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
417
418 // If SIM is absent, RadioError::SIM_ABSENT should be thrown. Otherwise there shouldn't be any
419 // error.
420 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
421 EXPECT_EQ(RadioError::SIM_ABSENT, radioRsp_sim->rspInfo.error);
422 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
423 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
424 }
425}
426
427/*
428 * Test IRadioSim.getAllowedCarriers() for the response returned.
429 */
430TEST_P(RadioSimTest, getAllowedCarriers) {
joonhunshind519aea2023-10-31 03:06:54 +0000431 if (telephony_flags::enforce_telephony_feature_mapping()) {
432 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
433 GTEST_SKIP() << "Skipping getAllowedCarriers "
434 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
435 }
436 }
437
Sarah Chin912bdf32022-01-28 01:02:16 -0800438 serial = GetRandomSerialNumber();
439
440 radio_sim->getAllowedCarriers(serial);
441 EXPECT_EQ(std::cv_status::no_timeout, wait());
442 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
443 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
444
445 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
446 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
447}
448
449/**
450 * Test IRadioSim.setAllowedCarriers() for the response returned.
451 */
452TEST_P(RadioSimTest, setAllowedCarriers) {
joonhunshind519aea2023-10-31 03:06:54 +0000453 if (telephony_flags::enforce_telephony_feature_mapping()) {
454 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
455 GTEST_SKIP() << "Skipping setAllowedCarriers "
456 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
457 }
458 }
459
Sarah Chin912bdf32022-01-28 01:02:16 -0800460 serial = GetRandomSerialNumber();
461 CarrierRestrictions carrierRestrictions;
462 memset(&carrierRestrictions, 0, sizeof(carrierRestrictions));
arunvoddu902ca982024-07-25 07:40:37 +0000463 int32_t aidl_version;
464 ndk::ScopedAStatus aidl_status = radio_sim->getInterfaceVersion(&aidl_version);
465 ASSERT_OK(aidl_status);
466
467 // Changes start
468
Sarah Chin912bdf32022-01-28 01:02:16 -0800469 SimLockMultiSimPolicy multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY;
arunvoddu902ca982024-07-25 07:40:37 +0000470 ALOGI("VTSAllowedCarriers Current AIDL version is %d ", aidl_version);
471 if (aidl_version <= 2) {
472 ALOGI("VTSAllowedCarriers If aidl_version is below 3 then , it will consider old AIDLs");
473 carrierRestrictions.allowedCarrierInfoList.resize(1);
474 if ((carrierRestrictions.allowedCarrierInfoList.size() > 0)) {
475 ALOGI("VTSAllowedCarriers If size of allowedCarrierInfoList is greater than 0");
476 }
477 carrierRestrictions.allowedCarriers.resize(1);
478 carrierRestrictions.excludedCarriers.resize(0);
479 carrierRestrictions.allowedCarriers[0].mcc = std::string("123");
480 carrierRestrictions.allowedCarriers[0].mnc = std::string("456");
481 carrierRestrictions.allowedCarriers[0].matchType = Carrier::MATCH_TYPE_ALL;
482 carrierRestrictions.allowedCarriers[0].matchData = std::string();
483 carrierRestrictions.allowedCarriersPrioritized = true;
484 multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY;
485 } else {
486 carrierRestrictions.allowedCarrierInfoList.resize(1);
487 carrierRestrictions.excludedCarrierInfoList.resize(0);
488 carrierRestrictions.allowedCarrierInfoList[0].mcc = std::string("321");
489 carrierRestrictions.allowedCarrierInfoList[0].mnc = std::string("654");
490 carrierRestrictions.allowedCarrierInfoList[0].spn = std::string("TestNetwork");
491 carrierRestrictions.allowedCarrierInfoList[0].gid1 = std::string("BAE000000000000");
492 carrierRestrictions.allowedCarrierInfoList[0].gid2 = std::string("AE0000000000000");
493 carrierRestrictions.allowedCarrierInfoList[0].imsiPrefix = std::string("9987");
494 carrierRestrictions.allowedCarriersPrioritized = true;
495 carrierRestrictions.status = CarrierRestrictions::CarrierRestrictionStatus::RESTRICTED;
496 multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY;
497 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800498
499 radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy);
500 EXPECT_EQ(std::cv_status::no_timeout, wait());
501 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
502 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
503
504 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
505 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
506
507 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
508 /* Verify the update of the SIM status. This might need some time */
509 if (cardStatus.cardState != CardStatus::STATE_ABSENT) {
510 updateSimCardStatus();
511 auto startTime = std::chrono::system_clock::now();
512 while (cardStatus.cardState != CardStatus::STATE_RESTRICTED &&
513 std::chrono::duration_cast<std::chrono::seconds>(
514 std::chrono::system_clock::now() - startTime)
515 .count() < 30) {
516 /* Set 2 seconds as interval to check card status */
517 sleep(2);
518 updateSimCardStatus();
519 }
Sarah Chin0623bdd2022-02-16 11:09:26 -0800520 // TODO: uncomment once CF fully supports setAllowedCarriers
521 // EXPECT_EQ(CardStatus::STATE_RESTRICTED, cardStatus.cardState);
Sarah Chin912bdf32022-01-28 01:02:16 -0800522 }
523
524 /* Verify that configuration was set correctly, retrieving it from the modem */
525 serial = GetRandomSerialNumber();
526
527 radio_sim->getAllowedCarriers(serial);
528 EXPECT_EQ(std::cv_status::no_timeout, wait());
529 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
530 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
531 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
532
arunvoddu902ca982024-07-25 07:40:37 +0000533 if (aidl_version <= 2) {
Tomasz Wasilczyk4feb1b22024-07-25 10:57:19 -0700534 ASSERT_EQ(1, radioRsp_sim->carrierRestrictionsResp.allowedCarriers.size());
arunvoddu902ca982024-07-25 07:40:37 +0000535 EXPECT_EQ(0, radioRsp_sim->carrierRestrictionsResp.excludedCarriers.size());
Sarah Chin912bdf32022-01-28 01:02:16 -0800536
arunvoddu902ca982024-07-25 07:40:37 +0000537 ASSERT_TRUE(std::string("123") ==
538 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mcc);
539 ASSERT_TRUE(std::string("456") ==
540 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mnc);
541 EXPECT_EQ(Carrier::MATCH_TYPE_ALL,
542 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].matchType);
543 ASSERT_TRUE(radioRsp_sim->carrierRestrictionsResp.allowedCarriersPrioritized);
544 EXPECT_EQ(SimLockMultiSimPolicy::NO_MULTISIM_POLICY, radioRsp_sim->multiSimPolicyResp);
545 } else {
Tomasz Wasilczyk4feb1b22024-07-25 10:57:19 -0700546 ASSERT_EQ(1, radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList.size());
arunvoddu902ca982024-07-25 07:40:37 +0000547 EXPECT_EQ(0, radioRsp_sim->carrierRestrictionsResp.excludedCarrierInfoList.size());
548 ASSERT_TRUE(std::string("321") ==
549 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].mcc);
550 ASSERT_TRUE(std::string("654") ==
551 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].mnc);
552 ASSERT_TRUE(std::string("BAE000000000000") ==
553 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].gid1);
554 ASSERT_TRUE(std::string("AE0000000000000") ==
555 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].gid2);
556 ASSERT_TRUE(std::string("9987") ==
557 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].imsiPrefix);
558 ASSERT_TRUE(radioRsp_sim->carrierRestrictionsResp.allowedCarriersPrioritized);
559 EXPECT_EQ(CarrierRestrictions::CarrierRestrictionStatus::RESTRICTED,
560 radioRsp_sim->carrierRestrictionsResp.status);
561 EXPECT_EQ(SimLockMultiSimPolicy::NO_MULTISIM_POLICY, radioRsp_sim->multiSimPolicyResp);
562 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800563 sleep(10);
564
565 /**
566 * Another test case of the API to cover to allow carrier.
567 * If the API is supported, this is also used to reset to no carrier restriction
568 * status for cardStatus.
569 */
570 memset(&carrierRestrictions, 0, sizeof(carrierRestrictions));
arunvoddu902ca982024-07-25 07:40:37 +0000571 if (aidl_version <= 2) {
572 carrierRestrictions.allowedCarriers.resize(0);
573 carrierRestrictions.excludedCarriers.resize(0);
574 carrierRestrictions.allowedCarriersPrioritized = false;
575 } else {
576 carrierRestrictions.allowedCarrierInfoList.resize(0);
577 carrierRestrictions.excludedCarrierInfoList.resize(0);
578 carrierRestrictions.allowedCarriersPrioritized = false;
579 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800580
581 serial = GetRandomSerialNumber();
582 radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy);
583 EXPECT_EQ(std::cv_status::no_timeout, wait());
584 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
585 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
586
587 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
588
589 if (cardStatus.cardState != CardStatus::STATE_ABSENT) {
590 /* Resetting back to no carrier restriction needs some time */
591 updateSimCardStatus();
592 auto startTime = std::chrono::system_clock::now();
593 while (cardStatus.cardState == CardStatus::STATE_RESTRICTED &&
594 std::chrono::duration_cast<std::chrono::seconds>(
595 std::chrono::system_clock::now() - startTime)
596 .count() < 10) {
597 /* Set 2 seconds as interval to check card status */
598 sleep(2);
599 updateSimCardStatus();
600 }
601 EXPECT_NE(CardStatus::STATE_RESTRICTED, cardStatus.cardState);
602 sleep(10);
603 }
604 }
605}
606
607/*
608 * Test IRadioSim.getIccCardStatus() for the response returned.
609 */
610TEST_P(RadioSimTest, getIccCardStatus) {
joonhunshind519aea2023-10-31 03:06:54 +0000611 if (telephony_flags::enforce_telephony_feature_mapping()) {
612 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
613 GTEST_SKIP() << "Skipping getIccCardStatus "
614 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
615 }
616 }
617
Sarah Chin912bdf32022-01-28 01:02:16 -0800618 EXPECT_LE(cardStatus.applications.size(), RadioConst::CARD_MAX_APPS);
619 EXPECT_LT(cardStatus.gsmUmtsSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
620 EXPECT_LT(cardStatus.cdmaSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
621 EXPECT_LT(cardStatus.imsSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
Sarah Chin912bdf32022-01-28 01:02:16 -0800622}
623
624/*
625 * Test IRadioSim.supplyIccPinForApp() for the response returned
626 */
627TEST_P(RadioSimTest, supplyIccPinForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000628 if (telephony_flags::enforce_telephony_feature_mapping()) {
629 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
630 GTEST_SKIP() << "Skipping supplyIccPinForApp "
631 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
632 }
633 }
634
Sarah Chin912bdf32022-01-28 01:02:16 -0800635 serial = GetRandomSerialNumber();
636
637 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
638 // 3GPP2 apps only
639 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
640 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
641 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
642 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
643 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
644 radio_sim->supplyIccPinForApp(serial, std::string("test1"),
645 cardStatus.applications[i].aidPtr);
646 EXPECT_EQ(std::cv_status::no_timeout, wait());
647 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
648 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
649 ASSERT_TRUE(CheckAnyOfErrors(
650 radioRsp_sim->rspInfo.error,
651 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
652 }
653 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800654}
655
656/*
657 * Test IRadioSim.supplyIccPukForApp() for the response returned.
658 */
659TEST_P(RadioSimTest, supplyIccPukForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000660 if (telephony_flags::enforce_telephony_feature_mapping()) {
661 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
662 GTEST_SKIP() << "Skipping supplyIccPukForApp "
663 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
664 }
665 }
666
Sarah Chin912bdf32022-01-28 01:02:16 -0800667 serial = GetRandomSerialNumber();
668
669 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
670 // 3GPP2 apps only
671 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
672 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
673 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
674 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
675 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
676 radio_sim->supplyIccPukForApp(serial, std::string("test1"), std::string("test2"),
677 cardStatus.applications[i].aidPtr);
678 EXPECT_EQ(std::cv_status::no_timeout, wait());
679 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
680 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
681 ASSERT_TRUE(CheckAnyOfErrors(
682 radioRsp_sim->rspInfo.error,
683 {RadioError::PASSWORD_INCORRECT, RadioError::INVALID_SIM_STATE}));
684 }
685 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800686}
687
688/*
689 * Test IRadioSim.supplyIccPin2ForApp() for the response returned.
690 */
691TEST_P(RadioSimTest, supplyIccPin2ForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000692 if (telephony_flags::enforce_telephony_feature_mapping()) {
693 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
694 GTEST_SKIP() << "Skipping supplyIccPin2ForApp "
695 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
696 }
697 }
698
Sarah Chin912bdf32022-01-28 01:02:16 -0800699 serial = GetRandomSerialNumber();
700
701 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
702 // 3GPP2 apps only
703 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
704 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
705 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
706 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
707 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
708 radio_sim->supplyIccPin2ForApp(serial, std::string("test1"),
709 cardStatus.applications[i].aidPtr);
710 EXPECT_EQ(std::cv_status::no_timeout, wait());
711 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
712 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
713 ASSERT_TRUE(
714 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
715 {RadioError::PASSWORD_INCORRECT,
716 RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_PUK2}));
717 }
718 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800719}
720
721/*
722 * Test IRadioSim.supplyIccPuk2ForApp() for the response returned.
723 */
724TEST_P(RadioSimTest, supplyIccPuk2ForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000725 if (telephony_flags::enforce_telephony_feature_mapping()) {
726 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
727 GTEST_SKIP() << "Skipping supplyIccPuk2ForApp "
728 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
729 }
730 }
731
Sarah Chin912bdf32022-01-28 01:02:16 -0800732 serial = GetRandomSerialNumber();
733
734 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
735 // 3GPP2 apps only
736 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
737 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
738 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
739 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
740 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
741 radio_sim->supplyIccPuk2ForApp(serial, std::string("test1"), std::string("test2"),
742 cardStatus.applications[i].aidPtr);
743 EXPECT_EQ(std::cv_status::no_timeout, wait());
744 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
745 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
746 ASSERT_TRUE(CheckAnyOfErrors(
747 radioRsp_sim->rspInfo.error,
748 {RadioError::PASSWORD_INCORRECT, RadioError::INVALID_SIM_STATE}));
749 }
750 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800751}
752
753/*
754 * Test IRadioSim.changeIccPinForApp() for the response returned.
755 */
756TEST_P(RadioSimTest, changeIccPinForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000757 if (telephony_flags::enforce_telephony_feature_mapping()) {
758 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
759 GTEST_SKIP() << "Skipping changeIccPinForApp "
760 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
761 }
762 }
763
Sarah Chin912bdf32022-01-28 01:02:16 -0800764 serial = GetRandomSerialNumber();
765
766 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
767 // 3GPP2 apps only
768 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
769 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
770 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
771 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
772 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
773 radio_sim->changeIccPinForApp(serial, std::string("test1"), std::string("test2"),
774 cardStatus.applications[i].aidPtr);
775 EXPECT_EQ(std::cv_status::no_timeout, wait());
776 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
777 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
778 ASSERT_TRUE(CheckAnyOfErrors(
779 radioRsp_sim->rspInfo.error,
780 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
781 }
782 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800783}
784
785/*
786 * Test IRadioSim.changeIccPin2ForApp() for the response returned.
787 */
788TEST_P(RadioSimTest, changeIccPin2ForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000789 if (telephony_flags::enforce_telephony_feature_mapping()) {
790 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
791 GTEST_SKIP() << "Skipping changeIccPin2ForApp "
792 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
793 }
794 }
795
Sarah Chin912bdf32022-01-28 01:02:16 -0800796 serial = GetRandomSerialNumber();
797
798 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
799 // 3GPP2 apps only
800 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
801 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
802 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
803 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
804 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
805 radio_sim->changeIccPin2ForApp(serial, std::string("test1"), std::string("test2"),
806 cardStatus.applications[i].aidPtr);
807 EXPECT_EQ(std::cv_status::no_timeout, wait());
808 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
809 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
810 ASSERT_TRUE(
811 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
812 {RadioError::PASSWORD_INCORRECT,
813 RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_PUK2}));
814 }
815 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800816}
817
818/*
Sarah Chin912bdf32022-01-28 01:02:16 -0800819 * Test IRadioSim.getImsiForApp() for the response returned.
820 */
Sarah Chinca421a62022-01-28 15:54:36 -0800821TEST_P(RadioSimTest, getImsiForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000822 if (telephony_flags::enforce_telephony_feature_mapping()) {
823 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
824 GTEST_SKIP() << "Skipping getImsiForApp "
825 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
826 }
827 }
828
Sarah Chin912bdf32022-01-28 01:02:16 -0800829 serial = GetRandomSerialNumber();
830
831 // Check success returned while getting imsi for 3GPP and 3GPP2 apps only
832 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
833 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
834 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
835 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
836 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
837 radio_sim->getImsiForApp(serial, cardStatus.applications[i].aidPtr);
838 EXPECT_EQ(std::cv_status::no_timeout, wait());
839 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
840 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
841 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE},
842 CHECK_GENERAL_ERROR));
843
844 // IMSI (MCC+MNC+MSIN) is at least 6 digits, but not more than 15
845 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
846 EXPECT_NE(radioRsp_sim->imsi, std::string());
847 EXPECT_GE((int)(radioRsp_sim->imsi).size(), 6);
848 EXPECT_LE((int)(radioRsp_sim->imsi).size(), 15);
849 }
850 }
851 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800852}
853
854/*
855 * Test IRadioSim.iccIoForApp() for the response returned.
856 */
857TEST_P(RadioSimTest, iccIoForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000858 if (telephony_flags::enforce_telephony_feature_mapping()) {
859 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
860 GTEST_SKIP() << "Skipping iccIoForApp "
861 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
862 }
863 }
864
Sarah Chin912bdf32022-01-28 01:02:16 -0800865 serial = GetRandomSerialNumber();
866
867 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
868 IccIo iccIo;
869 iccIo.command = 0xc0;
870 iccIo.fileId = 0x6f11;
871 iccIo.path = std::string("3F007FFF");
872 iccIo.p1 = 0;
873 iccIo.p2 = 0;
874 iccIo.p3 = 0;
875 iccIo.data = std::string();
876 iccIo.pin2 = std::string();
877 iccIo.aid = cardStatus.applications[i].aidPtr;
878
879 radio_sim->iccIoForApp(serial, iccIo);
880 EXPECT_EQ(std::cv_status::no_timeout, wait());
881 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
882 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
883 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800884}
885
886/*
887 * Test IRadioSim.iccTransmitApduBasicChannel() for the response returned.
888 */
889TEST_P(RadioSimTest, iccTransmitApduBasicChannel) {
joonhunshind519aea2023-10-31 03:06:54 +0000890 if (telephony_flags::enforce_telephony_feature_mapping()) {
891 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
892 GTEST_SKIP() << "Skipping iccTransmitApduBasicChannel "
893 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
894 }
895 }
896
Sarah Chin912bdf32022-01-28 01:02:16 -0800897 serial = GetRandomSerialNumber();
898 SimApdu msg;
899 memset(&msg, 0, sizeof(msg));
900 msg.data = std::string();
901
902 radio_sim->iccTransmitApduBasicChannel(serial, msg);
903 EXPECT_EQ(std::cv_status::no_timeout, wait());
904 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
905 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
Sarah Chin912bdf32022-01-28 01:02:16 -0800906}
907
908/*
909 * Test IRadioSim.iccOpenLogicalChannel() for the response returned.
910 */
911TEST_P(RadioSimTest, iccOpenLogicalChannel) {
joonhunshind519aea2023-10-31 03:06:54 +0000912 if (telephony_flags::enforce_telephony_feature_mapping()) {
913 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
914 GTEST_SKIP() << "Skipping iccOpenLogicalChannel "
915 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
916 }
917 }
918
Sarah Chin912bdf32022-01-28 01:02:16 -0800919 serial = GetRandomSerialNumber();
920 int p2 = 0x04;
921 // Specified in ISO 7816-4 clause 7.1.1 0x04 means that FCP template is requested.
922 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
923 radio_sim->iccOpenLogicalChannel(serial, cardStatus.applications[i].aidPtr, p2);
924 EXPECT_EQ(std::cv_status::no_timeout, wait());
925 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
926 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
927 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800928}
929
930/*
931 * Test IRadioSim.iccCloseLogicalChannel() for the response returned.
932 */
933TEST_P(RadioSimTest, iccCloseLogicalChannel) {
joonhunshind519aea2023-10-31 03:06:54 +0000934 if (telephony_flags::enforce_telephony_feature_mapping()) {
935 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
936 GTEST_SKIP() << "Skipping iccCloseLogicalChannel "
937 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
938 }
939 }
940
Sarah Chin912bdf32022-01-28 01:02:16 -0800941 serial = GetRandomSerialNumber();
942 // Try closing invalid channel and check INVALID_ARGUMENTS returned as error
943 radio_sim->iccCloseLogicalChannel(serial, 0);
944 EXPECT_EQ(std::cv_status::no_timeout, wait());
945 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
946 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
947
948 EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp_sim->rspInfo.error);
Sarah Chin912bdf32022-01-28 01:02:16 -0800949}
950
951/*
Muralidhar Reddyc13d0d62023-01-18 18:45:14 +0000952 * Test IRadioSim.iccCloseLogicalChannelWithSessionInfo() for the response returned.
953 */
954TEST_P(RadioSimTest, iccCloseLogicalChannelWithSessionInfo) {
joonhunshind519aea2023-10-31 03:06:54 +0000955 if (telephony_flags::enforce_telephony_feature_mapping()) {
956 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
957 GTEST_SKIP() << "Skipping iccCloseLogicalChannelWithSessionInfo "
958 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
959 }
960 }
961
Muralidhar Reddyeb1c6172023-04-12 12:55:19 +0000962 int32_t aidl_version;
963 ndk::ScopedAStatus aidl_status = radio_sim->getInterfaceVersion(&aidl_version);
964 ASSERT_OK(aidl_status);
965 if (aidl_version < 2) {
966 ALOGI("Skipped the test since"
967 " iccCloseLogicalChannelWithSessionInfo is not supported on version < 2");
968 GTEST_SKIP();
969 }
Muralidhar Reddyc13d0d62023-01-18 18:45:14 +0000970 serial = GetRandomSerialNumber();
971 SessionInfo info;
972 memset(&info, 0, sizeof(info));
973 info.sessionId = 0;
974 info.isEs10 = false;
975
976 // Try closing invalid channel and check INVALID_ARGUMENTS returned as error
977 radio_sim->iccCloseLogicalChannelWithSessionInfo(serial, info);
978 EXPECT_EQ(std::cv_status::no_timeout, wait());
979 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
980 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
981
982 EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp_sim->rspInfo.error);
Muralidhar Reddyc13d0d62023-01-18 18:45:14 +0000983}
984
985/*
Sarah Chin912bdf32022-01-28 01:02:16 -0800986 * Test IRadioSim.iccTransmitApduLogicalChannel() for the response returned.
987 */
988TEST_P(RadioSimTest, iccTransmitApduLogicalChannel) {
joonhunshind519aea2023-10-31 03:06:54 +0000989 if (telephony_flags::enforce_telephony_feature_mapping()) {
990 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
991 GTEST_SKIP() << "Skipping iccTransmitApduLogicalChannel "
992 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
993 }
994 }
995
Sarah Chin912bdf32022-01-28 01:02:16 -0800996 serial = GetRandomSerialNumber();
997 SimApdu msg;
998 memset(&msg, 0, sizeof(msg));
999 msg.data = std::string();
1000
1001 radio_sim->iccTransmitApduLogicalChannel(serial, msg);
1002 EXPECT_EQ(std::cv_status::no_timeout, wait());
1003 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1004 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
Sarah Chin912bdf32022-01-28 01:02:16 -08001005}
1006
1007/*
1008 * Test IRadioSim.requestIccSimAuthentication() for the response returned.
1009 */
1010TEST_P(RadioSimTest, requestIccSimAuthentication) {
joonhunshind519aea2023-10-31 03:06:54 +00001011 if (telephony_flags::enforce_telephony_feature_mapping()) {
1012 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1013 GTEST_SKIP() << "Skipping requestIccSimAuthentication "
1014 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1015 }
1016 }
1017
Sarah Chin912bdf32022-01-28 01:02:16 -08001018 serial = GetRandomSerialNumber();
1019
1020 // Pass wrong challenge string and check RadioError::INVALID_ARGUMENTS
1021 // or REQUEST_NOT_SUPPORTED returned as error.
1022 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
1023 radio_sim->requestIccSimAuthentication(serial, 0, std::string("test"),
1024 cardStatus.applications[i].aidPtr);
1025 EXPECT_EQ(std::cv_status::no_timeout, wait());
1026 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1027 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1028 ASSERT_TRUE(CheckAnyOfErrors(
1029 radioRsp_sim->rspInfo.error,
1030 {RadioError::INVALID_ARGUMENTS, RadioError::REQUEST_NOT_SUPPORTED}));
1031 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001032}
1033
1034/*
1035 * Test IRadioSim.getFacilityLockForApp() for the response returned.
1036 */
1037TEST_P(RadioSimTest, getFacilityLockForApp) {
joonhunshind519aea2023-10-31 03:06:54 +00001038 if (telephony_flags::enforce_telephony_feature_mapping()) {
1039 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1040 GTEST_SKIP() << "Skipping getFacilityLockForApp "
1041 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1042 }
1043 }
1044
Sarah Chin912bdf32022-01-28 01:02:16 -08001045 serial = GetRandomSerialNumber();
1046 std::string facility = "";
1047 std::string password = "";
1048 int32_t serviceClass = 1;
1049 std::string appId = "";
1050
1051 radio_sim->getFacilityLockForApp(serial, facility, password, serviceClass, appId);
1052
1053 EXPECT_EQ(std::cv_status::no_timeout, wait());
1054 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1055 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1056
1057 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1058 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
1059 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR},
1060 CHECK_GENERAL_ERROR));
1061 }
1062}
1063
1064/*
1065 * Test IRadioSim.setFacilityLockForApp() for the response returned.
1066 */
1067TEST_P(RadioSimTest, setFacilityLockForApp) {
joonhunshind519aea2023-10-31 03:06:54 +00001068 if (telephony_flags::enforce_telephony_feature_mapping()) {
1069 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1070 GTEST_SKIP() << "Skipping setFacilityLockForApp "
1071 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1072 }
1073 }
1074
Sarah Chin912bdf32022-01-28 01:02:16 -08001075 serial = GetRandomSerialNumber();
1076 std::string facility = "";
1077 bool lockState = false;
1078 std::string password = "";
1079 int32_t serviceClass = 1;
1080 std::string appId = "";
1081
1082 radio_sim->setFacilityLockForApp(serial, facility, lockState, password, serviceClass, appId);
1083
1084 EXPECT_EQ(std::cv_status::no_timeout, wait());
1085 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1086 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1087
1088 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1089 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
1090 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR},
1091 CHECK_GENERAL_ERROR));
1092 }
1093}
1094
1095/*
1096 * Test IRadioSim.getCdmaSubscription() for the response returned.
1097 */
1098TEST_P(RadioSimTest, getCdmaSubscription) {
joonhunshind519aea2023-10-31 03:06:54 +00001099 if (telephony_flags::enforce_telephony_feature_mapping()) {
1100 if (!deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
1101 GTEST_SKIP() << "Skipping getCdmaSubscription "
1102 "due to undefined FEATURE_TELEPHONY_CDMA";
1103 }
1104 }
1105
Sarah Chin912bdf32022-01-28 01:02:16 -08001106 serial = GetRandomSerialNumber();
1107
1108 radio_sim->getCdmaSubscription(serial);
1109 EXPECT_EQ(std::cv_status::no_timeout, wait());
1110 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1111 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1112
1113 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1114 ASSERT_TRUE(CheckAnyOfErrors(
1115 radioRsp_sim->rspInfo.error,
1116 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT}));
1117 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001118}
1119
1120/*
1121 * Test IRadioSim.getCdmaSubscriptionSource() for the response returned.
1122 */
1123TEST_P(RadioSimTest, getCdmaSubscriptionSource) {
joonhunshind519aea2023-10-31 03:06:54 +00001124 if (telephony_flags::enforce_telephony_feature_mapping()) {
1125 if (!deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
1126 GTEST_SKIP() << "Skipping getCdmaSubscriptionSource "
1127 "due to undefined FEATURE_TELEPHONY_CDMA";
1128 }
1129 }
1130
Sarah Chin912bdf32022-01-28 01:02:16 -08001131 serial = GetRandomSerialNumber();
1132
1133 radio_sim->getCdmaSubscriptionSource(serial);
1134 EXPECT_EQ(std::cv_status::no_timeout, wait());
1135 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1136 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1137
1138 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1139 ASSERT_TRUE(CheckAnyOfErrors(
1140 radioRsp_sim->rspInfo.error,
1141 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT}));
1142 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001143}
1144
1145/*
1146 * Test IRadioSim.setCdmaSubscriptionSource() for the response returned.
1147 */
1148TEST_P(RadioSimTest, setCdmaSubscriptionSource) {
joonhunshind519aea2023-10-31 03:06:54 +00001149 if (telephony_flags::enforce_telephony_feature_mapping()) {
1150 if (!deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
1151 GTEST_SKIP() << "Skipping setCdmaSubscriptionSource "
1152 "due to undefined FEATURE_TELEPHONY_CDMA";
1153 }
1154 }
1155
Sarah Chin912bdf32022-01-28 01:02:16 -08001156 serial = GetRandomSerialNumber();
1157
1158 radio_sim->setCdmaSubscriptionSource(serial, CdmaSubscriptionSource::RUIM_SIM);
1159 EXPECT_EQ(std::cv_status::no_timeout, wait());
1160 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1161 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1162
1163 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1164 ASSERT_TRUE(CheckAnyOfErrors(
1165 radioRsp_sim->rspInfo.error,
1166 {RadioError::NONE, RadioError::SIM_ABSENT, RadioError::SUBSCRIPTION_NOT_AVAILABLE},
1167 CHECK_GENERAL_ERROR));
1168 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001169}
1170
1171/*
1172 * Test IRadioSim.setUiccSubscription() for the response returned.
1173 */
1174TEST_P(RadioSimTest, setUiccSubscription) {
joonhunshind519aea2023-10-31 03:06:54 +00001175 if (telephony_flags::enforce_telephony_feature_mapping()) {
1176 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1177 GTEST_SKIP() << "Skipping setUiccSubscription "
1178 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1179 }
1180 }
1181
Sarah Chin912bdf32022-01-28 01:02:16 -08001182 serial = GetRandomSerialNumber();
1183 SelectUiccSub item;
1184 memset(&item, 0, sizeof(item));
1185
1186 radio_sim->setUiccSubscription(serial, item);
1187 EXPECT_EQ(std::cv_status::no_timeout, wait());
1188 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1189 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1190
1191 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1192 ASSERT_TRUE(
1193 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
1194 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
1195 RadioError::MODEM_ERR, RadioError::SUBSCRIPTION_NOT_SUPPORTED},
1196 CHECK_GENERAL_ERROR));
1197 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001198}
1199
1200/*
1201 * Test IRadioSim.sendEnvelope() for the response returned.
1202 */
1203TEST_P(RadioSimTest, sendEnvelope) {
joonhunshind519aea2023-10-31 03:06:54 +00001204 if (telephony_flags::enforce_telephony_feature_mapping()) {
1205 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1206 GTEST_SKIP() << "Skipping sendEnvelope "
1207 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1208 }
1209 }
1210
Sarah Chin912bdf32022-01-28 01:02:16 -08001211 serial = GetRandomSerialNumber();
1212
1213 // Test with sending empty string
1214 std::string content = "";
1215
1216 radio_sim->sendEnvelope(serial, content);
1217
1218 EXPECT_EQ(std::cv_status::no_timeout, wait());
1219 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1220 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1221
1222 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1223 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
1224 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
1225 RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
1226 CHECK_GENERAL_ERROR));
1227 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001228}
1229
1230/*
1231 * Test IRadioSim.sendTerminalResponseToSim() for the response returned.
1232 */
1233TEST_P(RadioSimTest, sendTerminalResponseToSim) {
joonhunshind519aea2023-10-31 03:06:54 +00001234 if (telephony_flags::enforce_telephony_feature_mapping()) {
1235 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1236 GTEST_SKIP() << "Skipping sendTerminalResponseToSim "
1237 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1238 }
1239 }
1240
Sarah Chin912bdf32022-01-28 01:02:16 -08001241 serial = GetRandomSerialNumber();
1242
1243 // Test with sending empty string
1244 std::string commandResponse = "";
1245
1246 radio_sim->sendTerminalResponseToSim(serial, commandResponse);
1247
1248 EXPECT_EQ(std::cv_status::no_timeout, wait());
1249 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1250 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1251
1252 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1253 ASSERT_TRUE(CheckAnyOfErrors(
1254 radioRsp_sim->rspInfo.error,
1255 {RadioError::NONE, RadioError::INVALID_ARGUMENTS, RadioError::SIM_ABSENT},
1256 CHECK_GENERAL_ERROR));
1257 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001258}
1259
1260/*
1261 * Test IRadioSim.reportStkServiceIsRunning() for the response returned.
1262 */
1263TEST_P(RadioSimTest, reportStkServiceIsRunning) {
joonhunshind519aea2023-10-31 03:06:54 +00001264 if (telephony_flags::enforce_telephony_feature_mapping()) {
1265 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1266 GTEST_SKIP() << "Skipping reportStkServiceIsRunning "
1267 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1268 }
1269 }
1270
Sarah Chin912bdf32022-01-28 01:02:16 -08001271 serial = GetRandomSerialNumber();
1272
1273 radio_sim->reportStkServiceIsRunning(serial);
1274
1275 EXPECT_EQ(std::cv_status::no_timeout, wait());
1276 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1277 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1278
1279 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1280 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE},
1281 CHECK_GENERAL_ERROR));
1282 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001283}
1284
1285/*
1286 * Test IRadioSim.sendEnvelopeWithStatus() for the response returned with empty
1287 * string.
1288 */
1289TEST_P(RadioSimTest, sendEnvelopeWithStatus) {
joonhunshind519aea2023-10-31 03:06:54 +00001290 if (telephony_flags::enforce_telephony_feature_mapping()) {
1291 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1292 GTEST_SKIP() << "Skipping sendEnvelopeWithStatus "
1293 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1294 }
1295 }
1296
Sarah Chin912bdf32022-01-28 01:02:16 -08001297 serial = GetRandomSerialNumber();
1298
1299 // Test with sending empty string
1300 std::string contents = "";
1301
1302 radio_sim->sendEnvelopeWithStatus(serial, contents);
1303
1304 EXPECT_EQ(std::cv_status::no_timeout, wait());
1305 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1306 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1307
1308 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1309 ASSERT_TRUE(CheckAnyOfErrors(
1310 radioRsp_sim->rspInfo.error,
1311 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
1312 CHECK_GENERAL_ERROR));
1313 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001314}