blob: 26845795ec3c1c24e8660ce6e8883cda8e9c4890 [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);
121 EXPECT_EQ(0, cardStatus.slotMap.portId);
122 }
Sarah Chinfc5603b2021-12-21 11:34:00 -0800123 }
124}
125
126/*
127 * Test IRadioSim.setCarrierInfoForImsiEncryption() for the response returned.
128 */
129TEST_P(RadioSimTest, setCarrierInfoForImsiEncryption) {
joonhunshind519aea2023-10-31 03:06:54 +0000130 if (telephony_flags::enforce_telephony_feature_mapping()) {
131 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
132 GTEST_SKIP() << "Skipping setCarrierInfoForImsiEncryption "
133 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
134 }
135 }
136
Sarah Chinfc5603b2021-12-21 11:34:00 -0800137 serial = GetRandomSerialNumber();
138 ImsiEncryptionInfo imsiInfo;
139 imsiInfo.mcc = "310";
140 imsiInfo.mnc = "004";
141 imsiInfo.carrierKey = (std::vector<uint8_t>){1, 2, 3, 4, 5, 6};
142 imsiInfo.keyIdentifier = "Test";
143 imsiInfo.expirationTime = 20180101;
144 imsiInfo.keyType = ImsiEncryptionInfo::PUBLIC_KEY_TYPE_EPDG;
145
146 radio_sim->setCarrierInfoForImsiEncryption(serial, imsiInfo);
147 EXPECT_EQ(std::cv_status::no_timeout, wait());
148 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
149 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
150
151 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
152 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
153 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
154 }
155}
156
157/*
158 * Test IRadioSim.getSimPhonebookRecords() for the response returned.
159 */
160TEST_P(RadioSimTest, getSimPhonebookRecords) {
joonhunshind519aea2023-10-31 03:06:54 +0000161 if (telephony_flags::enforce_telephony_feature_mapping()) {
162 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
163 GTEST_SKIP() << "Skipping getSimPhonebookRecords "
164 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
165 }
166 }
167
Sarah Chinfc5603b2021-12-21 11:34:00 -0800168 serial = GetRandomSerialNumber();
169 radio_sim->getSimPhonebookRecords(serial);
170 EXPECT_EQ(std::cv_status::no_timeout, wait());
171 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
172 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
173 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
174 ASSERT_TRUE(
175 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
176 {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE,
177 RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS,
178 RadioError::REQUEST_NOT_SUPPORTED},
179 CHECK_GENERAL_ERROR));
180 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
181 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
182 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
183 CHECK_GENERAL_ERROR));
184 }
185}
186
187/*
188 * Test IRadioSim.getSimPhonebookCapacity for the response returned.
189 */
190TEST_P(RadioSimTest, getSimPhonebookCapacity) {
joonhunshind519aea2023-10-31 03:06:54 +0000191 if (telephony_flags::enforce_telephony_feature_mapping()) {
192 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
193 GTEST_SKIP() << "Skipping getSimPhonebookCapacity "
194 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
195 }
196 }
197
Sarah Chinfc5603b2021-12-21 11:34:00 -0800198 serial = GetRandomSerialNumber();
199 radio_sim->getSimPhonebookCapacity(serial);
200 EXPECT_EQ(std::cv_status::no_timeout, wait());
201 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
202 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
203 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
204 ASSERT_TRUE(
205 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
206 {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE,
207 RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS,
208 RadioError::REQUEST_NOT_SUPPORTED},
209 CHECK_GENERAL_ERROR));
210 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
211 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
212 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
213 CHECK_GENERAL_ERROR));
214
215 PhonebookCapacity pbCapacity = radioRsp_sim->capacity;
216 if (pbCapacity.maxAdnRecords > 0) {
217 EXPECT_TRUE(pbCapacity.maxNameLen > 0 && pbCapacity.maxNumberLen > 0);
218 EXPECT_TRUE(pbCapacity.usedAdnRecords <= pbCapacity.maxAdnRecords);
219 }
220
221 if (pbCapacity.maxEmailRecords > 0) {
222 EXPECT_TRUE(pbCapacity.maxEmailLen > 0);
223 EXPECT_TRUE(pbCapacity.usedEmailRecords <= pbCapacity.maxEmailRecords);
224 }
225
226 if (pbCapacity.maxAdditionalNumberRecords > 0) {
227 EXPECT_TRUE(pbCapacity.maxAdditionalNumberLen > 0);
228 EXPECT_TRUE(pbCapacity.usedAdditionalNumberRecords <=
229 pbCapacity.maxAdditionalNumberRecords);
230 }
231 }
232}
233
234/*
235 * Test IRadioSim.updateSimPhonebookRecords() for the response returned.
236 */
237TEST_P(RadioSimTest, updateSimPhonebookRecords) {
joonhunshind519aea2023-10-31 03:06:54 +0000238 if (telephony_flags::enforce_telephony_feature_mapping()) {
239 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
240 GTEST_SKIP() << "Skipping updateSimPhonebookRecords "
241 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
242 }
243 }
244
Sarah Chinfc5603b2021-12-21 11:34:00 -0800245 serial = GetRandomSerialNumber();
246 radio_sim->getSimPhonebookCapacity(serial);
247 EXPECT_EQ(std::cv_status::no_timeout, wait());
248 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
249 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
250 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
251 ASSERT_TRUE(
252 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
253 {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE,
254 RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS,
255 RadioError::REQUEST_NOT_SUPPORTED},
256 CHECK_GENERAL_ERROR));
257 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
258 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
259 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
260 CHECK_GENERAL_ERROR));
261 PhonebookCapacity pbCapacity = radioRsp_sim->capacity;
262
263 serial = GetRandomSerialNumber();
264 radio_sim->getSimPhonebookRecords(serial);
265
266 EXPECT_EQ(std::cv_status::no_timeout, wait());
267 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
268 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
269 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
270 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED},
271 CHECK_GENERAL_ERROR));
272
273 if (pbCapacity.maxAdnRecords > 0 && pbCapacity.usedAdnRecords < pbCapacity.maxAdnRecords) {
274 // Add a phonebook record
275 PhonebookRecordInfo recordInfo;
276 recordInfo.recordId = 0;
277 recordInfo.name = "ABC";
278 recordInfo.number = "1234567890";
279 serial = GetRandomSerialNumber();
280 radio_sim->updateSimPhonebookRecords(serial, recordInfo);
281
282 EXPECT_EQ(std::cv_status::no_timeout, wait());
283 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
284 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
285 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
286 int index = radioRsp_sim->updatedRecordIndex;
287 EXPECT_TRUE(index > 0);
288
289 // Deleted a phonebook record
290 recordInfo.recordId = index;
291 recordInfo.name = "";
292 recordInfo.number = "";
293 serial = GetRandomSerialNumber();
294 radio_sim->updateSimPhonebookRecords(serial, recordInfo);
295
296 EXPECT_EQ(std::cv_status::no_timeout, wait());
297 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
298 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
299 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
300 }
301 }
302}
Sarah Chin912bdf32022-01-28 01:02:16 -0800303
304/*
305 * Test IRadioSim.enableUiccApplications() for the response returned.
306 * For SIM ABSENT case.
307 */
308TEST_P(RadioSimTest, togglingUiccApplicationsSimAbsent) {
joonhunshind519aea2023-10-31 03:06:54 +0000309 if (telephony_flags::enforce_telephony_feature_mapping()) {
310 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
311 GTEST_SKIP() << "Skipping togglingUiccApplicationsSimAbsent "
312 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
313 }
314 }
315
Sarah Chin912bdf32022-01-28 01:02:16 -0800316 // This test case only test SIM ABSENT case.
317 if (cardStatus.cardState != CardStatus::STATE_ABSENT) return;
318
319 // Disable Uicc applications.
320 serial = GetRandomSerialNumber();
321 radio_sim->enableUiccApplications(serial, false);
322 EXPECT_EQ(std::cv_status::no_timeout, wait());
323 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
324 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
325 // As SIM is absent, RadioError::SIM_ABSENT should be thrown.
326 EXPECT_EQ(RadioError::SIM_ABSENT, radioRsp_sim->rspInfo.error);
327
328 // Query Uicc application enablement.
329 serial = GetRandomSerialNumber();
330 radio_sim->areUiccApplicationsEnabled(serial);
331 EXPECT_EQ(std::cv_status::no_timeout, wait());
332 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
333 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
334 // As SIM is absent, RadioError::SIM_ABSENT should be thrown.
335 EXPECT_EQ(RadioError::SIM_ABSENT, radioRsp_sim->rspInfo.error);
336}
337
338/*
339 * Test IRadioSim.enableUiccApplications() for the response returned.
340 * For SIM PRESENT case.
341 */
342TEST_P(RadioSimTest, togglingUiccApplicationsSimPresent) {
joonhunshind519aea2023-10-31 03:06:54 +0000343 if (telephony_flags::enforce_telephony_feature_mapping()) {
344 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
345 GTEST_SKIP() << "Skipping togglingUiccApplicationsSimPresent "
346 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
347 }
348 }
349
Sarah Chin912bdf32022-01-28 01:02:16 -0800350 // This test case only test SIM ABSENT case.
351 if (cardStatus.cardState != CardStatus::STATE_PRESENT) return;
352 if (cardStatus.applications.size() == 0) return;
353
354 // Disable Uicc applications.
355 serial = GetRandomSerialNumber();
356 radio_sim->enableUiccApplications(serial, false);
357 EXPECT_EQ(std::cv_status::no_timeout, wait());
358 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
359 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
360 // As SIM is present, there shouldn't be error.
361 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
362
363 // Query Uicc application enablement.
364 serial = GetRandomSerialNumber();
365 radio_sim->areUiccApplicationsEnabled(serial);
366 EXPECT_EQ(std::cv_status::no_timeout, wait());
367 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
368 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
369 // As SIM is present, there shouldn't be error.
370 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
371 ASSERT_FALSE(radioRsp_sim->areUiccApplicationsEnabled);
372
373 // Enable Uicc applications.
374 serial = GetRandomSerialNumber();
375 radio_sim->enableUiccApplications(serial, true);
376 EXPECT_EQ(std::cv_status::no_timeout, wait());
377 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
378 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
379 // As SIM is present, there shouldn't be error.
380 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
381
382 // Query Uicc application enablement.
383 serial = GetRandomSerialNumber();
384 radio_sim->areUiccApplicationsEnabled(serial);
385 EXPECT_EQ(std::cv_status::no_timeout, wait());
386 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
387 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
388 // As SIM is present, there shouldn't be error.
389 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
390 ASSERT_TRUE(radioRsp_sim->areUiccApplicationsEnabled);
391}
392
393/*
394 * Test IRadioSim.areUiccApplicationsEnabled() for the response returned.
395 */
396TEST_P(RadioSimTest, areUiccApplicationsEnabled) {
joonhunshind519aea2023-10-31 03:06:54 +0000397 if (telephony_flags::enforce_telephony_feature_mapping()) {
398 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
399 GTEST_SKIP() << "Skipping areUiccApplicationsEnabled "
400 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
401 }
402 }
403
Sarah Chin912bdf32022-01-28 01:02:16 -0800404 // Disable Uicc applications.
405 serial = GetRandomSerialNumber();
406 radio_sim->areUiccApplicationsEnabled(serial);
407 EXPECT_EQ(std::cv_status::no_timeout, wait());
408 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
409 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
410
411 // If SIM is absent, RadioError::SIM_ABSENT should be thrown. Otherwise there shouldn't be any
412 // error.
413 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
414 EXPECT_EQ(RadioError::SIM_ABSENT, radioRsp_sim->rspInfo.error);
415 } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) {
416 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
417 }
418}
419
420/*
421 * Test IRadioSim.getAllowedCarriers() for the response returned.
422 */
423TEST_P(RadioSimTest, getAllowedCarriers) {
joonhunshind519aea2023-10-31 03:06:54 +0000424 if (telephony_flags::enforce_telephony_feature_mapping()) {
425 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
426 GTEST_SKIP() << "Skipping getAllowedCarriers "
427 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
428 }
429 }
430
Sarah Chin912bdf32022-01-28 01:02:16 -0800431 serial = GetRandomSerialNumber();
432
433 radio_sim->getAllowedCarriers(serial);
434 EXPECT_EQ(std::cv_status::no_timeout, wait());
435 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
436 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
437
438 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
439 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
440}
441
442/**
443 * Test IRadioSim.setAllowedCarriers() for the response returned.
444 */
445TEST_P(RadioSimTest, setAllowedCarriers) {
joonhunshind519aea2023-10-31 03:06:54 +0000446 if (telephony_flags::enforce_telephony_feature_mapping()) {
447 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
448 GTEST_SKIP() << "Skipping setAllowedCarriers "
449 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
450 }
451 }
452
Sarah Chin912bdf32022-01-28 01:02:16 -0800453 serial = GetRandomSerialNumber();
454 CarrierRestrictions carrierRestrictions;
455 memset(&carrierRestrictions, 0, sizeof(carrierRestrictions));
arunvoddu902ca982024-07-25 07:40:37 +0000456 int32_t aidl_version;
457 ndk::ScopedAStatus aidl_status = radio_sim->getInterfaceVersion(&aidl_version);
458 ASSERT_OK(aidl_status);
459
460 // Changes start
461
Sarah Chin912bdf32022-01-28 01:02:16 -0800462 SimLockMultiSimPolicy multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY;
arunvoddu902ca982024-07-25 07:40:37 +0000463 ALOGI("VTSAllowedCarriers Current AIDL version is %d ", aidl_version);
464 if (aidl_version <= 2) {
465 ALOGI("VTSAllowedCarriers If aidl_version is below 3 then , it will consider old AIDLs");
466 carrierRestrictions.allowedCarrierInfoList.resize(1);
467 if ((carrierRestrictions.allowedCarrierInfoList.size() > 0)) {
468 ALOGI("VTSAllowedCarriers If size of allowedCarrierInfoList is greater than 0");
469 }
470 carrierRestrictions.allowedCarriers.resize(1);
471 carrierRestrictions.excludedCarriers.resize(0);
472 carrierRestrictions.allowedCarriers[0].mcc = std::string("123");
473 carrierRestrictions.allowedCarriers[0].mnc = std::string("456");
474 carrierRestrictions.allowedCarriers[0].matchType = Carrier::MATCH_TYPE_ALL;
475 carrierRestrictions.allowedCarriers[0].matchData = std::string();
476 carrierRestrictions.allowedCarriersPrioritized = true;
477 multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY;
478 } else {
479 carrierRestrictions.allowedCarrierInfoList.resize(1);
480 carrierRestrictions.excludedCarrierInfoList.resize(0);
481 carrierRestrictions.allowedCarrierInfoList[0].mcc = std::string("321");
482 carrierRestrictions.allowedCarrierInfoList[0].mnc = std::string("654");
483 carrierRestrictions.allowedCarrierInfoList[0].spn = std::string("TestNetwork");
484 carrierRestrictions.allowedCarrierInfoList[0].gid1 = std::string("BAE000000000000");
485 carrierRestrictions.allowedCarrierInfoList[0].gid2 = std::string("AE0000000000000");
486 carrierRestrictions.allowedCarrierInfoList[0].imsiPrefix = std::string("9987");
487 carrierRestrictions.allowedCarriersPrioritized = true;
488 carrierRestrictions.status = CarrierRestrictions::CarrierRestrictionStatus::RESTRICTED;
489 multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY;
490 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800491
492 radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy);
493 EXPECT_EQ(std::cv_status::no_timeout, wait());
494 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
495 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
496
497 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
498 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
499
500 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
501 /* Verify the update of the SIM status. This might need some time */
502 if (cardStatus.cardState != CardStatus::STATE_ABSENT) {
503 updateSimCardStatus();
504 auto startTime = std::chrono::system_clock::now();
505 while (cardStatus.cardState != CardStatus::STATE_RESTRICTED &&
506 std::chrono::duration_cast<std::chrono::seconds>(
507 std::chrono::system_clock::now() - startTime)
508 .count() < 30) {
509 /* Set 2 seconds as interval to check card status */
510 sleep(2);
511 updateSimCardStatus();
512 }
Sarah Chin0623bdd2022-02-16 11:09:26 -0800513 // TODO: uncomment once CF fully supports setAllowedCarriers
514 // EXPECT_EQ(CardStatus::STATE_RESTRICTED, cardStatus.cardState);
Sarah Chin912bdf32022-01-28 01:02:16 -0800515 }
516
517 /* Verify that configuration was set correctly, retrieving it from the modem */
518 serial = GetRandomSerialNumber();
519
520 radio_sim->getAllowedCarriers(serial);
521 EXPECT_EQ(std::cv_status::no_timeout, wait());
522 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
523 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
524 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
525
arunvoddu902ca982024-07-25 07:40:37 +0000526 if (aidl_version <= 2) {
527 EXPECT_EQ(1, radioRsp_sim->carrierRestrictionsResp.allowedCarriers.size());
528 EXPECT_EQ(0, radioRsp_sim->carrierRestrictionsResp.excludedCarriers.size());
Sarah Chin912bdf32022-01-28 01:02:16 -0800529
arunvoddu902ca982024-07-25 07:40:37 +0000530 ASSERT_TRUE(std::string("123") ==
531 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mcc);
532 ASSERT_TRUE(std::string("456") ==
533 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mnc);
534 EXPECT_EQ(Carrier::MATCH_TYPE_ALL,
535 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].matchType);
536 ASSERT_TRUE(radioRsp_sim->carrierRestrictionsResp.allowedCarriersPrioritized);
537 EXPECT_EQ(SimLockMultiSimPolicy::NO_MULTISIM_POLICY, radioRsp_sim->multiSimPolicyResp);
538 } else {
539 EXPECT_EQ(1, radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList.size());
540 EXPECT_EQ(0, radioRsp_sim->carrierRestrictionsResp.excludedCarrierInfoList.size());
541 ASSERT_TRUE(std::string("321") ==
542 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].mcc);
543 ASSERT_TRUE(std::string("654") ==
544 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].mnc);
545 ASSERT_TRUE(std::string("BAE000000000000") ==
546 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].gid1);
547 ASSERT_TRUE(std::string("AE0000000000000") ==
548 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].gid2);
549 ASSERT_TRUE(std::string("9987") ==
550 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].imsiPrefix);
551 ASSERT_TRUE(radioRsp_sim->carrierRestrictionsResp.allowedCarriersPrioritized);
552 EXPECT_EQ(CarrierRestrictions::CarrierRestrictionStatus::RESTRICTED,
553 radioRsp_sim->carrierRestrictionsResp.status);
554 EXPECT_EQ(SimLockMultiSimPolicy::NO_MULTISIM_POLICY, radioRsp_sim->multiSimPolicyResp);
555 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800556 sleep(10);
557
558 /**
559 * Another test case of the API to cover to allow carrier.
560 * If the API is supported, this is also used to reset to no carrier restriction
561 * status for cardStatus.
562 */
563 memset(&carrierRestrictions, 0, sizeof(carrierRestrictions));
arunvoddu902ca982024-07-25 07:40:37 +0000564 if (aidl_version <= 2) {
565 carrierRestrictions.allowedCarriers.resize(0);
566 carrierRestrictions.excludedCarriers.resize(0);
567 carrierRestrictions.allowedCarriersPrioritized = false;
568 } else {
569 carrierRestrictions.allowedCarrierInfoList.resize(0);
570 carrierRestrictions.excludedCarrierInfoList.resize(0);
571 carrierRestrictions.allowedCarriersPrioritized = false;
572 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800573
574 serial = GetRandomSerialNumber();
575 radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy);
576 EXPECT_EQ(std::cv_status::no_timeout, wait());
577 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
578 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
579
580 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
581
582 if (cardStatus.cardState != CardStatus::STATE_ABSENT) {
583 /* Resetting back to no carrier restriction needs some time */
584 updateSimCardStatus();
585 auto startTime = std::chrono::system_clock::now();
586 while (cardStatus.cardState == CardStatus::STATE_RESTRICTED &&
587 std::chrono::duration_cast<std::chrono::seconds>(
588 std::chrono::system_clock::now() - startTime)
589 .count() < 10) {
590 /* Set 2 seconds as interval to check card status */
591 sleep(2);
592 updateSimCardStatus();
593 }
594 EXPECT_NE(CardStatus::STATE_RESTRICTED, cardStatus.cardState);
595 sleep(10);
596 }
597 }
598}
599
600/*
601 * Test IRadioSim.getIccCardStatus() for the response returned.
602 */
603TEST_P(RadioSimTest, getIccCardStatus) {
joonhunshind519aea2023-10-31 03:06:54 +0000604 if (telephony_flags::enforce_telephony_feature_mapping()) {
605 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
606 GTEST_SKIP() << "Skipping getIccCardStatus "
607 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
608 }
609 }
610
Sarah Chin912bdf32022-01-28 01:02:16 -0800611 EXPECT_LE(cardStatus.applications.size(), RadioConst::CARD_MAX_APPS);
612 EXPECT_LT(cardStatus.gsmUmtsSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
613 EXPECT_LT(cardStatus.cdmaSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
614 EXPECT_LT(cardStatus.imsSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
Sarah Chin912bdf32022-01-28 01:02:16 -0800615}
616
617/*
618 * Test IRadioSim.supplyIccPinForApp() for the response returned
619 */
620TEST_P(RadioSimTest, supplyIccPinForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000621 if (telephony_flags::enforce_telephony_feature_mapping()) {
622 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
623 GTEST_SKIP() << "Skipping supplyIccPinForApp "
624 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
625 }
626 }
627
Sarah Chin912bdf32022-01-28 01:02:16 -0800628 serial = GetRandomSerialNumber();
629
630 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
631 // 3GPP2 apps only
632 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
633 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
634 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
635 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
636 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
637 radio_sim->supplyIccPinForApp(serial, std::string("test1"),
638 cardStatus.applications[i].aidPtr);
639 EXPECT_EQ(std::cv_status::no_timeout, wait());
640 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
641 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
642 ASSERT_TRUE(CheckAnyOfErrors(
643 radioRsp_sim->rspInfo.error,
644 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
645 }
646 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800647}
648
649/*
650 * Test IRadioSim.supplyIccPukForApp() for the response returned.
651 */
652TEST_P(RadioSimTest, supplyIccPukForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000653 if (telephony_flags::enforce_telephony_feature_mapping()) {
654 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
655 GTEST_SKIP() << "Skipping supplyIccPukForApp "
656 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
657 }
658 }
659
Sarah Chin912bdf32022-01-28 01:02:16 -0800660 serial = GetRandomSerialNumber();
661
662 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
663 // 3GPP2 apps only
664 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
665 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
666 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
667 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
668 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
669 radio_sim->supplyIccPukForApp(serial, std::string("test1"), std::string("test2"),
670 cardStatus.applications[i].aidPtr);
671 EXPECT_EQ(std::cv_status::no_timeout, wait());
672 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
673 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
674 ASSERT_TRUE(CheckAnyOfErrors(
675 radioRsp_sim->rspInfo.error,
676 {RadioError::PASSWORD_INCORRECT, RadioError::INVALID_SIM_STATE}));
677 }
678 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800679}
680
681/*
682 * Test IRadioSim.supplyIccPin2ForApp() for the response returned.
683 */
684TEST_P(RadioSimTest, supplyIccPin2ForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000685 if (telephony_flags::enforce_telephony_feature_mapping()) {
686 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
687 GTEST_SKIP() << "Skipping supplyIccPin2ForApp "
688 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
689 }
690 }
691
Sarah Chin912bdf32022-01-28 01:02:16 -0800692 serial = GetRandomSerialNumber();
693
694 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
695 // 3GPP2 apps only
696 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
697 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
698 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
699 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
700 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
701 radio_sim->supplyIccPin2ForApp(serial, std::string("test1"),
702 cardStatus.applications[i].aidPtr);
703 EXPECT_EQ(std::cv_status::no_timeout, wait());
704 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
705 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
706 ASSERT_TRUE(
707 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
708 {RadioError::PASSWORD_INCORRECT,
709 RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_PUK2}));
710 }
711 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800712}
713
714/*
715 * Test IRadioSim.supplyIccPuk2ForApp() for the response returned.
716 */
717TEST_P(RadioSimTest, supplyIccPuk2ForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000718 if (telephony_flags::enforce_telephony_feature_mapping()) {
719 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
720 GTEST_SKIP() << "Skipping supplyIccPuk2ForApp "
721 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
722 }
723 }
724
Sarah Chin912bdf32022-01-28 01:02:16 -0800725 serial = GetRandomSerialNumber();
726
727 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
728 // 3GPP2 apps only
729 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
730 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
731 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
732 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
733 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
734 radio_sim->supplyIccPuk2ForApp(serial, std::string("test1"), std::string("test2"),
735 cardStatus.applications[i].aidPtr);
736 EXPECT_EQ(std::cv_status::no_timeout, wait());
737 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
738 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
739 ASSERT_TRUE(CheckAnyOfErrors(
740 radioRsp_sim->rspInfo.error,
741 {RadioError::PASSWORD_INCORRECT, RadioError::INVALID_SIM_STATE}));
742 }
743 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800744}
745
746/*
747 * Test IRadioSim.changeIccPinForApp() for the response returned.
748 */
749TEST_P(RadioSimTest, changeIccPinForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000750 if (telephony_flags::enforce_telephony_feature_mapping()) {
751 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
752 GTEST_SKIP() << "Skipping changeIccPinForApp "
753 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
754 }
755 }
756
Sarah Chin912bdf32022-01-28 01:02:16 -0800757 serial = GetRandomSerialNumber();
758
759 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
760 // 3GPP2 apps only
761 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
762 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
763 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
764 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
765 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
766 radio_sim->changeIccPinForApp(serial, std::string("test1"), std::string("test2"),
767 cardStatus.applications[i].aidPtr);
768 EXPECT_EQ(std::cv_status::no_timeout, wait());
769 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
770 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
771 ASSERT_TRUE(CheckAnyOfErrors(
772 radioRsp_sim->rspInfo.error,
773 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
774 }
775 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800776}
777
778/*
779 * Test IRadioSim.changeIccPin2ForApp() for the response returned.
780 */
781TEST_P(RadioSimTest, changeIccPin2ForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000782 if (telephony_flags::enforce_telephony_feature_mapping()) {
783 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
784 GTEST_SKIP() << "Skipping changeIccPin2ForApp "
785 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
786 }
787 }
788
Sarah Chin912bdf32022-01-28 01:02:16 -0800789 serial = GetRandomSerialNumber();
790
791 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
792 // 3GPP2 apps only
793 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
794 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
795 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
796 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
797 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
798 radio_sim->changeIccPin2ForApp(serial, std::string("test1"), std::string("test2"),
799 cardStatus.applications[i].aidPtr);
800 EXPECT_EQ(std::cv_status::no_timeout, wait());
801 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
802 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
803 ASSERT_TRUE(
804 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
805 {RadioError::PASSWORD_INCORRECT,
806 RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_PUK2}));
807 }
808 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800809}
810
811/*
Sarah Chin912bdf32022-01-28 01:02:16 -0800812 * Test IRadioSim.getImsiForApp() for the response returned.
813 */
Sarah Chinca421a62022-01-28 15:54:36 -0800814TEST_P(RadioSimTest, getImsiForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000815 if (telephony_flags::enforce_telephony_feature_mapping()) {
816 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
817 GTEST_SKIP() << "Skipping getImsiForApp "
818 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
819 }
820 }
821
Sarah Chin912bdf32022-01-28 01:02:16 -0800822 serial = GetRandomSerialNumber();
823
824 // Check success returned while getting imsi for 3GPP and 3GPP2 apps only
825 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
826 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
827 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
828 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
829 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
830 radio_sim->getImsiForApp(serial, cardStatus.applications[i].aidPtr);
831 EXPECT_EQ(std::cv_status::no_timeout, wait());
832 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
833 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
834 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE},
835 CHECK_GENERAL_ERROR));
836
837 // IMSI (MCC+MNC+MSIN) is at least 6 digits, but not more than 15
838 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
839 EXPECT_NE(radioRsp_sim->imsi, std::string());
840 EXPECT_GE((int)(radioRsp_sim->imsi).size(), 6);
841 EXPECT_LE((int)(radioRsp_sim->imsi).size(), 15);
842 }
843 }
844 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800845}
846
847/*
848 * Test IRadioSim.iccIoForApp() for the response returned.
849 */
850TEST_P(RadioSimTest, iccIoForApp) {
joonhunshind519aea2023-10-31 03:06:54 +0000851 if (telephony_flags::enforce_telephony_feature_mapping()) {
852 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
853 GTEST_SKIP() << "Skipping iccIoForApp "
854 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
855 }
856 }
857
Sarah Chin912bdf32022-01-28 01:02:16 -0800858 serial = GetRandomSerialNumber();
859
860 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
861 IccIo iccIo;
862 iccIo.command = 0xc0;
863 iccIo.fileId = 0x6f11;
864 iccIo.path = std::string("3F007FFF");
865 iccIo.p1 = 0;
866 iccIo.p2 = 0;
867 iccIo.p3 = 0;
868 iccIo.data = std::string();
869 iccIo.pin2 = std::string();
870 iccIo.aid = cardStatus.applications[i].aidPtr;
871
872 radio_sim->iccIoForApp(serial, iccIo);
873 EXPECT_EQ(std::cv_status::no_timeout, wait());
874 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
875 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
876 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800877}
878
879/*
880 * Test IRadioSim.iccTransmitApduBasicChannel() for the response returned.
881 */
882TEST_P(RadioSimTest, iccTransmitApduBasicChannel) {
joonhunshind519aea2023-10-31 03:06:54 +0000883 if (telephony_flags::enforce_telephony_feature_mapping()) {
884 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
885 GTEST_SKIP() << "Skipping iccTransmitApduBasicChannel "
886 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
887 }
888 }
889
Sarah Chin912bdf32022-01-28 01:02:16 -0800890 serial = GetRandomSerialNumber();
891 SimApdu msg;
892 memset(&msg, 0, sizeof(msg));
893 msg.data = std::string();
894
895 radio_sim->iccTransmitApduBasicChannel(serial, msg);
896 EXPECT_EQ(std::cv_status::no_timeout, wait());
897 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
898 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
Sarah Chin912bdf32022-01-28 01:02:16 -0800899}
900
901/*
902 * Test IRadioSim.iccOpenLogicalChannel() for the response returned.
903 */
904TEST_P(RadioSimTest, iccOpenLogicalChannel) {
joonhunshind519aea2023-10-31 03:06:54 +0000905 if (telephony_flags::enforce_telephony_feature_mapping()) {
906 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
907 GTEST_SKIP() << "Skipping iccOpenLogicalChannel "
908 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
909 }
910 }
911
Sarah Chin912bdf32022-01-28 01:02:16 -0800912 serial = GetRandomSerialNumber();
913 int p2 = 0x04;
914 // Specified in ISO 7816-4 clause 7.1.1 0x04 means that FCP template is requested.
915 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
916 radio_sim->iccOpenLogicalChannel(serial, cardStatus.applications[i].aidPtr, p2);
917 EXPECT_EQ(std::cv_status::no_timeout, wait());
918 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
919 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
920 }
Sarah Chin912bdf32022-01-28 01:02:16 -0800921}
922
923/*
924 * Test IRadioSim.iccCloseLogicalChannel() for the response returned.
925 */
926TEST_P(RadioSimTest, iccCloseLogicalChannel) {
joonhunshind519aea2023-10-31 03:06:54 +0000927 if (telephony_flags::enforce_telephony_feature_mapping()) {
928 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
929 GTEST_SKIP() << "Skipping iccCloseLogicalChannel "
930 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
931 }
932 }
933
Sarah Chin912bdf32022-01-28 01:02:16 -0800934 serial = GetRandomSerialNumber();
935 // Try closing invalid channel and check INVALID_ARGUMENTS returned as error
936 radio_sim->iccCloseLogicalChannel(serial, 0);
937 EXPECT_EQ(std::cv_status::no_timeout, wait());
938 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
939 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
940
941 EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp_sim->rspInfo.error);
Sarah Chin912bdf32022-01-28 01:02:16 -0800942}
943
944/*
Muralidhar Reddyc13d0d62023-01-18 18:45:14 +0000945 * Test IRadioSim.iccCloseLogicalChannelWithSessionInfo() for the response returned.
946 */
947TEST_P(RadioSimTest, iccCloseLogicalChannelWithSessionInfo) {
joonhunshind519aea2023-10-31 03:06:54 +0000948 if (telephony_flags::enforce_telephony_feature_mapping()) {
949 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
950 GTEST_SKIP() << "Skipping iccCloseLogicalChannelWithSessionInfo "
951 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
952 }
953 }
954
Muralidhar Reddyeb1c6172023-04-12 12:55:19 +0000955 int32_t aidl_version;
956 ndk::ScopedAStatus aidl_status = radio_sim->getInterfaceVersion(&aidl_version);
957 ASSERT_OK(aidl_status);
958 if (aidl_version < 2) {
959 ALOGI("Skipped the test since"
960 " iccCloseLogicalChannelWithSessionInfo is not supported on version < 2");
961 GTEST_SKIP();
962 }
Muralidhar Reddyc13d0d62023-01-18 18:45:14 +0000963 serial = GetRandomSerialNumber();
964 SessionInfo info;
965 memset(&info, 0, sizeof(info));
966 info.sessionId = 0;
967 info.isEs10 = false;
968
969 // Try closing invalid channel and check INVALID_ARGUMENTS returned as error
970 radio_sim->iccCloseLogicalChannelWithSessionInfo(serial, info);
971 EXPECT_EQ(std::cv_status::no_timeout, wait());
972 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
973 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
974
975 EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp_sim->rspInfo.error);
Muralidhar Reddyc13d0d62023-01-18 18:45:14 +0000976}
977
978/*
Sarah Chin912bdf32022-01-28 01:02:16 -0800979 * Test IRadioSim.iccTransmitApduLogicalChannel() for the response returned.
980 */
981TEST_P(RadioSimTest, iccTransmitApduLogicalChannel) {
joonhunshind519aea2023-10-31 03:06:54 +0000982 if (telephony_flags::enforce_telephony_feature_mapping()) {
983 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
984 GTEST_SKIP() << "Skipping iccTransmitApduLogicalChannel "
985 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
986 }
987 }
988
Sarah Chin912bdf32022-01-28 01:02:16 -0800989 serial = GetRandomSerialNumber();
990 SimApdu msg;
991 memset(&msg, 0, sizeof(msg));
992 msg.data = std::string();
993
994 radio_sim->iccTransmitApduLogicalChannel(serial, msg);
995 EXPECT_EQ(std::cv_status::no_timeout, wait());
996 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
997 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
Sarah Chin912bdf32022-01-28 01:02:16 -0800998}
999
1000/*
1001 * Test IRadioSim.requestIccSimAuthentication() for the response returned.
1002 */
1003TEST_P(RadioSimTest, requestIccSimAuthentication) {
joonhunshind519aea2023-10-31 03:06:54 +00001004 if (telephony_flags::enforce_telephony_feature_mapping()) {
1005 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1006 GTEST_SKIP() << "Skipping requestIccSimAuthentication "
1007 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1008 }
1009 }
1010
Sarah Chin912bdf32022-01-28 01:02:16 -08001011 serial = GetRandomSerialNumber();
1012
1013 // Pass wrong challenge string and check RadioError::INVALID_ARGUMENTS
1014 // or REQUEST_NOT_SUPPORTED returned as error.
1015 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
1016 radio_sim->requestIccSimAuthentication(serial, 0, std::string("test"),
1017 cardStatus.applications[i].aidPtr);
1018 EXPECT_EQ(std::cv_status::no_timeout, wait());
1019 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1020 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1021 ASSERT_TRUE(CheckAnyOfErrors(
1022 radioRsp_sim->rspInfo.error,
1023 {RadioError::INVALID_ARGUMENTS, RadioError::REQUEST_NOT_SUPPORTED}));
1024 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001025}
1026
1027/*
1028 * Test IRadioSim.getFacilityLockForApp() for the response returned.
1029 */
1030TEST_P(RadioSimTest, getFacilityLockForApp) {
joonhunshind519aea2023-10-31 03:06:54 +00001031 if (telephony_flags::enforce_telephony_feature_mapping()) {
1032 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1033 GTEST_SKIP() << "Skipping getFacilityLockForApp "
1034 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1035 }
1036 }
1037
Sarah Chin912bdf32022-01-28 01:02:16 -08001038 serial = GetRandomSerialNumber();
1039 std::string facility = "";
1040 std::string password = "";
1041 int32_t serviceClass = 1;
1042 std::string appId = "";
1043
1044 radio_sim->getFacilityLockForApp(serial, facility, password, serviceClass, appId);
1045
1046 EXPECT_EQ(std::cv_status::no_timeout, wait());
1047 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1048 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1049
1050 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1051 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
1052 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR},
1053 CHECK_GENERAL_ERROR));
1054 }
1055}
1056
1057/*
1058 * Test IRadioSim.setFacilityLockForApp() for the response returned.
1059 */
1060TEST_P(RadioSimTest, setFacilityLockForApp) {
joonhunshind519aea2023-10-31 03:06:54 +00001061 if (telephony_flags::enforce_telephony_feature_mapping()) {
1062 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1063 GTEST_SKIP() << "Skipping setFacilityLockForApp "
1064 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1065 }
1066 }
1067
Sarah Chin912bdf32022-01-28 01:02:16 -08001068 serial = GetRandomSerialNumber();
1069 std::string facility = "";
1070 bool lockState = false;
1071 std::string password = "";
1072 int32_t serviceClass = 1;
1073 std::string appId = "";
1074
1075 radio_sim->setFacilityLockForApp(serial, facility, lockState, password, serviceClass, appId);
1076
1077 EXPECT_EQ(std::cv_status::no_timeout, wait());
1078 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1079 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1080
1081 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1082 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
1083 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR},
1084 CHECK_GENERAL_ERROR));
1085 }
1086}
1087
1088/*
1089 * Test IRadioSim.getCdmaSubscription() for the response returned.
1090 */
1091TEST_P(RadioSimTest, getCdmaSubscription) {
joonhunshind519aea2023-10-31 03:06:54 +00001092 if (telephony_flags::enforce_telephony_feature_mapping()) {
1093 if (!deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
1094 GTEST_SKIP() << "Skipping getCdmaSubscription "
1095 "due to undefined FEATURE_TELEPHONY_CDMA";
1096 }
1097 }
1098
Sarah Chin912bdf32022-01-28 01:02:16 -08001099 serial = GetRandomSerialNumber();
1100
1101 radio_sim->getCdmaSubscription(serial);
1102 EXPECT_EQ(std::cv_status::no_timeout, wait());
1103 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1104 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1105
1106 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1107 ASSERT_TRUE(CheckAnyOfErrors(
1108 radioRsp_sim->rspInfo.error,
1109 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT}));
1110 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001111}
1112
1113/*
1114 * Test IRadioSim.getCdmaSubscriptionSource() for the response returned.
1115 */
1116TEST_P(RadioSimTest, getCdmaSubscriptionSource) {
joonhunshind519aea2023-10-31 03:06:54 +00001117 if (telephony_flags::enforce_telephony_feature_mapping()) {
1118 if (!deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
1119 GTEST_SKIP() << "Skipping getCdmaSubscriptionSource "
1120 "due to undefined FEATURE_TELEPHONY_CDMA";
1121 }
1122 }
1123
Sarah Chin912bdf32022-01-28 01:02:16 -08001124 serial = GetRandomSerialNumber();
1125
1126 radio_sim->getCdmaSubscriptionSource(serial);
1127 EXPECT_EQ(std::cv_status::no_timeout, wait());
1128 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1129 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1130
1131 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1132 ASSERT_TRUE(CheckAnyOfErrors(
1133 radioRsp_sim->rspInfo.error,
1134 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT}));
1135 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001136}
1137
1138/*
1139 * Test IRadioSim.setCdmaSubscriptionSource() for the response returned.
1140 */
1141TEST_P(RadioSimTest, setCdmaSubscriptionSource) {
joonhunshind519aea2023-10-31 03:06:54 +00001142 if (telephony_flags::enforce_telephony_feature_mapping()) {
1143 if (!deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
1144 GTEST_SKIP() << "Skipping setCdmaSubscriptionSource "
1145 "due to undefined FEATURE_TELEPHONY_CDMA";
1146 }
1147 }
1148
Sarah Chin912bdf32022-01-28 01:02:16 -08001149 serial = GetRandomSerialNumber();
1150
1151 radio_sim->setCdmaSubscriptionSource(serial, CdmaSubscriptionSource::RUIM_SIM);
1152 EXPECT_EQ(std::cv_status::no_timeout, wait());
1153 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1154 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1155
1156 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1157 ASSERT_TRUE(CheckAnyOfErrors(
1158 radioRsp_sim->rspInfo.error,
1159 {RadioError::NONE, RadioError::SIM_ABSENT, RadioError::SUBSCRIPTION_NOT_AVAILABLE},
1160 CHECK_GENERAL_ERROR));
1161 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001162}
1163
1164/*
1165 * Test IRadioSim.setUiccSubscription() for the response returned.
1166 */
1167TEST_P(RadioSimTest, setUiccSubscription) {
joonhunshind519aea2023-10-31 03:06:54 +00001168 if (telephony_flags::enforce_telephony_feature_mapping()) {
1169 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1170 GTEST_SKIP() << "Skipping setUiccSubscription "
1171 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1172 }
1173 }
1174
Sarah Chin912bdf32022-01-28 01:02:16 -08001175 serial = GetRandomSerialNumber();
1176 SelectUiccSub item;
1177 memset(&item, 0, sizeof(item));
1178
1179 radio_sim->setUiccSubscription(serial, item);
1180 EXPECT_EQ(std::cv_status::no_timeout, wait());
1181 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1182 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1183
1184 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1185 ASSERT_TRUE(
1186 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
1187 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
1188 RadioError::MODEM_ERR, RadioError::SUBSCRIPTION_NOT_SUPPORTED},
1189 CHECK_GENERAL_ERROR));
1190 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001191}
1192
1193/*
1194 * Test IRadioSim.sendEnvelope() for the response returned.
1195 */
1196TEST_P(RadioSimTest, sendEnvelope) {
joonhunshind519aea2023-10-31 03:06:54 +00001197 if (telephony_flags::enforce_telephony_feature_mapping()) {
1198 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1199 GTEST_SKIP() << "Skipping sendEnvelope "
1200 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1201 }
1202 }
1203
Sarah Chin912bdf32022-01-28 01:02:16 -08001204 serial = GetRandomSerialNumber();
1205
1206 // Test with sending empty string
1207 std::string content = "";
1208
1209 radio_sim->sendEnvelope(serial, content);
1210
1211 EXPECT_EQ(std::cv_status::no_timeout, wait());
1212 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1213 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1214
1215 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1216 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
1217 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
1218 RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
1219 CHECK_GENERAL_ERROR));
1220 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001221}
1222
1223/*
1224 * Test IRadioSim.sendTerminalResponseToSim() for the response returned.
1225 */
1226TEST_P(RadioSimTest, sendTerminalResponseToSim) {
joonhunshind519aea2023-10-31 03:06:54 +00001227 if (telephony_flags::enforce_telephony_feature_mapping()) {
1228 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1229 GTEST_SKIP() << "Skipping sendTerminalResponseToSim "
1230 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1231 }
1232 }
1233
Sarah Chin912bdf32022-01-28 01:02:16 -08001234 serial = GetRandomSerialNumber();
1235
1236 // Test with sending empty string
1237 std::string commandResponse = "";
1238
1239 radio_sim->sendTerminalResponseToSim(serial, commandResponse);
1240
1241 EXPECT_EQ(std::cv_status::no_timeout, wait());
1242 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1243 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1244
1245 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1246 ASSERT_TRUE(CheckAnyOfErrors(
1247 radioRsp_sim->rspInfo.error,
1248 {RadioError::NONE, RadioError::INVALID_ARGUMENTS, RadioError::SIM_ABSENT},
1249 CHECK_GENERAL_ERROR));
1250 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001251}
1252
1253/*
1254 * Test IRadioSim.reportStkServiceIsRunning() for the response returned.
1255 */
1256TEST_P(RadioSimTest, reportStkServiceIsRunning) {
joonhunshind519aea2023-10-31 03:06:54 +00001257 if (telephony_flags::enforce_telephony_feature_mapping()) {
1258 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1259 GTEST_SKIP() << "Skipping reportStkServiceIsRunning "
1260 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1261 }
1262 }
1263
Sarah Chin912bdf32022-01-28 01:02:16 -08001264 serial = GetRandomSerialNumber();
1265
1266 radio_sim->reportStkServiceIsRunning(serial);
1267
1268 EXPECT_EQ(std::cv_status::no_timeout, wait());
1269 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1270 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1271
1272 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1273 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE},
1274 CHECK_GENERAL_ERROR));
1275 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001276}
1277
1278/*
1279 * Test IRadioSim.sendEnvelopeWithStatus() for the response returned with empty
1280 * string.
1281 */
1282TEST_P(RadioSimTest, sendEnvelopeWithStatus) {
joonhunshind519aea2023-10-31 03:06:54 +00001283 if (telephony_flags::enforce_telephony_feature_mapping()) {
1284 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1285 GTEST_SKIP() << "Skipping sendEnvelopeWithStatus "
1286 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1287 }
1288 }
1289
Sarah Chin912bdf32022-01-28 01:02:16 -08001290 serial = GetRandomSerialNumber();
1291
1292 // Test with sending empty string
1293 std::string contents = "";
1294
1295 radio_sim->sendEnvelopeWithStatus(serial, contents);
1296
1297 EXPECT_EQ(std::cv_status::no_timeout, wait());
1298 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1299 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1300
1301 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1302 ASSERT_TRUE(CheckAnyOfErrors(
1303 radioRsp_sim->rspInfo.error,
1304 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
1305 CHECK_GENERAL_ERROR));
1306 }
Sarah Chin912bdf32022-01-28 01:02:16 -08001307}