1 /*
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
17 #include <aidl/android/hardware/radio/RadioConst.h>
18 #include <aidl/android/hardware/radio/config/IRadioConfig.h>
19 #include <android/binder_manager.h>
20
21 #include "radio_sim_utils.h"
22
23 #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
24
SetUp()25 void RadioSimTest::SetUp() {
26 RadioServiceTest::SetUp();
27 std::string serviceName = GetParam();
28
29 if (!isServiceValidForDeviceConfiguration(serviceName)) {
30 ALOGI("Skipped the test due to device configuration.");
31 GTEST_SKIP();
32 }
33
34 radio_sim = IRadioSim::fromBinder(
35 ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
36 ASSERT_NE(nullptr, radio_sim.get());
37
38 radioRsp_sim = ndk::SharedRefBase::make<RadioSimResponse>(*this);
39 ASSERT_NE(nullptr, radioRsp_sim.get());
40
41 radioInd_sim = ndk::SharedRefBase::make<RadioSimIndication>(*this);
42 ASSERT_NE(nullptr, radioInd_sim.get());
43
44 radio_sim->setResponseFunctions(radioRsp_sim, radioInd_sim);
45 // Assert SIM is present before testing
46 updateSimCardStatus();
47 EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState);
48
49 // Assert IRadioConfig exists before testing
50 radio_config = config::IRadioConfig::fromBinder(ndk::SpAIBinder(
51 AServiceManager_waitForService("android.hardware.radio.config.IRadioConfig/default")));
52 ASSERT_NE(nullptr, radio_config.get());
53 }
54
updateSimCardStatus()55 void RadioSimTest::updateSimCardStatus() {
56 serial = GetRandomSerialNumber();
57 radio_sim->getIccCardStatus(serial);
58 EXPECT_EQ(std::cv_status::no_timeout, wait());
59 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);
62 }
63
64 /*
65 * Test IRadioSim.setSimCardPower() for the response returned.
66 */
TEST_P(RadioSimTest,setSimCardPower)67 TEST_P(RadioSimTest, setSimCardPower) {
68 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
75 /* 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();
116 updateSimSlotStatus(cardStatus.slotMap.physicalSlotId);
117 EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState);
118 EXPECT_EQ(CardStatus::STATE_PRESENT, slotStatus.cardState);
119 if (CardStatus::STATE_PRESENT == slotStatus.cardState) {
120 ASSERT_TRUE(slotStatus.portInfo[0].portActive);
121 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 }
129 }
130 }
131 }
132
133 /*
134 * Test IRadioSim.setCarrierInfoForImsiEncryption() for the response returned.
135 */
TEST_P(RadioSimTest,setCarrierInfoForImsiEncryption)136 TEST_P(RadioSimTest, setCarrierInfoForImsiEncryption) {
137 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
144 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 */
TEST_P(RadioSimTest,getSimPhonebookRecords)167 TEST_P(RadioSimTest, getSimPhonebookRecords) {
168 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
175 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 */
TEST_P(RadioSimTest,getSimPhonebookCapacity)197 TEST_P(RadioSimTest, getSimPhonebookCapacity) {
198 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
205 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 */
TEST_P(RadioSimTest,updateSimPhonebookRecords)244 TEST_P(RadioSimTest, updateSimPhonebookRecords) {
245 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
252 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 }
310
311 /*
312 * Test IRadioSim.enableUiccApplications() for the response returned.
313 * For SIM ABSENT case.
314 */
TEST_P(RadioSimTest,togglingUiccApplicationsSimAbsent)315 TEST_P(RadioSimTest, togglingUiccApplicationsSimAbsent) {
316 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
323 // 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 */
TEST_P(RadioSimTest,togglingUiccApplicationsSimPresent)349 TEST_P(RadioSimTest, togglingUiccApplicationsSimPresent) {
350 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
357 // 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 */
TEST_P(RadioSimTest,areUiccApplicationsEnabled)403 TEST_P(RadioSimTest, areUiccApplicationsEnabled) {
404 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
411 // 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 */
TEST_P(RadioSimTest,getAllowedCarriers)430 TEST_P(RadioSimTest, getAllowedCarriers) {
431 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
438 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 */
TEST_P(RadioSimTest,setAllowedCarriers)452 TEST_P(RadioSimTest, setAllowedCarriers) {
453 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
460 serial = GetRandomSerialNumber();
461 CarrierRestrictions carrierRestrictions;
462 memset(&carrierRestrictions, 0, sizeof(carrierRestrictions));
463 int32_t aidl_version;
464 ndk::ScopedAStatus aidl_status = radio_sim->getInterfaceVersion(&aidl_version);
465 ASSERT_OK(aidl_status);
466
467 // Changes start
468
469 SimLockMultiSimPolicy multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY;
470 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 // TODO(b/365568518): change mcc/mnc to something else once CF fully supports
489 // setAllowedCarriers
490 carrierRestrictions.allowedCarrierInfoList[0].mcc = std::string("123");
491 carrierRestrictions.allowedCarrierInfoList[0].mnc = std::string("456");
492 carrierRestrictions.allowedCarrierInfoList[0].spn = std::string("TestNetwork");
493 carrierRestrictions.allowedCarrierInfoList[0].gid1 = std::string("BAE000000000000");
494 carrierRestrictions.allowedCarrierInfoList[0].gid2 = std::string("AE0000000000000");
495 carrierRestrictions.allowedCarrierInfoList[0].imsiPrefix = std::string("9987");
496 carrierRestrictions.allowedCarriersPrioritized = true;
497 carrierRestrictions.status = CarrierRestrictions::CarrierRestrictionStatus::RESTRICTED;
498 multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY;
499 }
500
501 radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy);
502 EXPECT_EQ(std::cv_status::no_timeout, wait());
503 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
504 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
505
506 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
507 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
508
509 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
510 /* Verify the update of the SIM status. This might need some time */
511 if (cardStatus.cardState != CardStatus::STATE_ABSENT) {
512 updateSimCardStatus();
513 auto startTime = std::chrono::system_clock::now();
514 while (cardStatus.cardState != CardStatus::STATE_RESTRICTED &&
515 std::chrono::duration_cast<std::chrono::seconds>(
516 std::chrono::system_clock::now() - startTime)
517 .count() < 30) {
518 /* Set 2 seconds as interval to check card status */
519 sleep(2);
520 updateSimCardStatus();
521 }
522 // TODO(b/365568518): uncomment once CF fully supports setAllowedCarriers
523 // EXPECT_EQ(CardStatus::STATE_RESTRICTED, cardStatus.cardState);
524 }
525
526 /* Verify that configuration was set correctly, retrieving it from the modem */
527 serial = GetRandomSerialNumber();
528
529 radio_sim->getAllowedCarriers(serial);
530 EXPECT_EQ(std::cv_status::no_timeout, wait());
531 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
532 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
533 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
534
535 if (aidl_version <= 2) {
536 ASSERT_EQ(1, radioRsp_sim->carrierRestrictionsResp.allowedCarriers.size());
537 EXPECT_EQ(0, radioRsp_sim->carrierRestrictionsResp.excludedCarriers.size());
538
539 ASSERT_TRUE(std::string("123") ==
540 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mcc);
541 ASSERT_TRUE(std::string("456") ==
542 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mnc);
543 EXPECT_EQ(Carrier::MATCH_TYPE_ALL,
544 radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].matchType);
545 ASSERT_TRUE(radioRsp_sim->carrierRestrictionsResp.allowedCarriersPrioritized);
546 EXPECT_EQ(SimLockMultiSimPolicy::NO_MULTISIM_POLICY, radioRsp_sim->multiSimPolicyResp);
547 } else {
548 ASSERT_EQ(1, radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList.size());
549 EXPECT_EQ(0, radioRsp_sim->carrierRestrictionsResp.excludedCarrierInfoList.size());
550 ASSERT_EQ(std::string("123"),
551 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].mcc);
552 ASSERT_EQ(std::string("456"),
553 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].mnc);
554 #if 0 // TODO(b/365568518): enable once CF fully supports setAllowedCarriers
555 ASSERT_EQ(std::string("BAE000000000000"),
556 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].gid1);
557 ASSERT_EQ(std::string("AE0000000000000"),
558 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].gid2);
559 ASSERT_EQ(std::string("9987"),
560 radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].imsiPrefix);
561 EXPECT_EQ(CarrierRestrictions::CarrierRestrictionStatus::RESTRICTED,
562 radioRsp_sim->carrierRestrictionsResp.status);
563 #endif
564 ASSERT_TRUE(radioRsp_sim->carrierRestrictionsResp.allowedCarriersPrioritized);
565 EXPECT_EQ(SimLockMultiSimPolicy::NO_MULTISIM_POLICY, radioRsp_sim->multiSimPolicyResp);
566 }
567 sleep(10);
568
569 /**
570 * Another test case of the API to cover to allow carrier.
571 * If the API is supported, this is also used to reset to no carrier restriction
572 * status for cardStatus.
573 */
574 memset(&carrierRestrictions, 0, sizeof(carrierRestrictions));
575 if (aidl_version <= 2) {
576 carrierRestrictions.allowedCarriers.resize(0);
577 carrierRestrictions.excludedCarriers.resize(0);
578 carrierRestrictions.allowedCarriersPrioritized = false;
579 } else {
580 carrierRestrictions.allowedCarrierInfoList.resize(0);
581 carrierRestrictions.excludedCarrierInfoList.resize(0);
582 carrierRestrictions.allowedCarriersPrioritized = false;
583 }
584
585 serial = GetRandomSerialNumber();
586 radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy);
587 EXPECT_EQ(std::cv_status::no_timeout, wait());
588 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
589 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
590
591 EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error);
592
593 if (cardStatus.cardState != CardStatus::STATE_ABSENT) {
594 /* Resetting back to no carrier restriction needs some time */
595 updateSimCardStatus();
596 auto startTime = std::chrono::system_clock::now();
597 while (cardStatus.cardState == CardStatus::STATE_RESTRICTED &&
598 std::chrono::duration_cast<std::chrono::seconds>(
599 std::chrono::system_clock::now() - startTime)
600 .count() < 10) {
601 /* Set 2 seconds as interval to check card status */
602 sleep(2);
603 updateSimCardStatus();
604 }
605 EXPECT_NE(CardStatus::STATE_RESTRICTED, cardStatus.cardState);
606 sleep(10);
607 }
608 }
609 }
610
611 /*
612 * Test IRadioSim.getIccCardStatus() for the response returned.
613 */
TEST_P(RadioSimTest,getIccCardStatus)614 TEST_P(RadioSimTest, getIccCardStatus) {
615 if (telephony_flags::enforce_telephony_feature_mapping()) {
616 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
617 GTEST_SKIP() << "Skipping getIccCardStatus "
618 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
619 }
620 }
621
622 EXPECT_LE(cardStatus.applications.size(), RadioConst::CARD_MAX_APPS);
623 EXPECT_LT(cardStatus.gsmUmtsSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
624 EXPECT_LT(cardStatus.cdmaSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
625 EXPECT_LT(cardStatus.imsSubscriptionAppIndex, RadioConst::CARD_MAX_APPS);
626 }
627
628 /*
629 * Test IRadioSim.supplyIccPinForApp() for the response returned
630 */
TEST_P(RadioSimTest,supplyIccPinForApp)631 TEST_P(RadioSimTest, supplyIccPinForApp) {
632 if (telephony_flags::enforce_telephony_feature_mapping()) {
633 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
634 GTEST_SKIP() << "Skipping supplyIccPinForApp "
635 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
636 }
637 }
638
639 serial = GetRandomSerialNumber();
640
641 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
642 // 3GPP2 apps only
643 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
644 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
645 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
646 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
647 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
648 radio_sim->supplyIccPinForApp(serial, std::string("test1"),
649 cardStatus.applications[i].aidPtr);
650 EXPECT_EQ(std::cv_status::no_timeout, wait());
651 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
652 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
653 ASSERT_TRUE(CheckAnyOfErrors(
654 radioRsp_sim->rspInfo.error,
655 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
656 }
657 }
658 }
659
660 /*
661 * Test IRadioSim.supplyIccPukForApp() for the response returned.
662 */
TEST_P(RadioSimTest,supplyIccPukForApp)663 TEST_P(RadioSimTest, supplyIccPukForApp) {
664 if (telephony_flags::enforce_telephony_feature_mapping()) {
665 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
666 GTEST_SKIP() << "Skipping supplyIccPukForApp "
667 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
668 }
669 }
670
671 serial = GetRandomSerialNumber();
672
673 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
674 // 3GPP2 apps only
675 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
676 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
677 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
678 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
679 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
680 radio_sim->supplyIccPukForApp(serial, std::string("test1"), std::string("test2"),
681 cardStatus.applications[i].aidPtr);
682 EXPECT_EQ(std::cv_status::no_timeout, wait());
683 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
684 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
685 ASSERT_TRUE(CheckAnyOfErrors(
686 radioRsp_sim->rspInfo.error,
687 {RadioError::PASSWORD_INCORRECT, RadioError::INVALID_SIM_STATE}));
688 }
689 }
690 }
691
692 /*
693 * Test IRadioSim.supplyIccPin2ForApp() for the response returned.
694 */
TEST_P(RadioSimTest,supplyIccPin2ForApp)695 TEST_P(RadioSimTest, supplyIccPin2ForApp) {
696 if (telephony_flags::enforce_telephony_feature_mapping()) {
697 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
698 GTEST_SKIP() << "Skipping supplyIccPin2ForApp "
699 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
700 }
701 }
702
703 serial = GetRandomSerialNumber();
704
705 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
706 // 3GPP2 apps only
707 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
708 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
709 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
710 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
711 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
712 radio_sim->supplyIccPin2ForApp(serial, std::string("test1"),
713 cardStatus.applications[i].aidPtr);
714 EXPECT_EQ(std::cv_status::no_timeout, wait());
715 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
716 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
717 ASSERT_TRUE(
718 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
719 {RadioError::PASSWORD_INCORRECT,
720 RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_PUK2}));
721 }
722 }
723 }
724
725 /*
726 * Test IRadioSim.supplyIccPuk2ForApp() for the response returned.
727 */
TEST_P(RadioSimTest,supplyIccPuk2ForApp)728 TEST_P(RadioSimTest, supplyIccPuk2ForApp) {
729 if (telephony_flags::enforce_telephony_feature_mapping()) {
730 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
731 GTEST_SKIP() << "Skipping supplyIccPuk2ForApp "
732 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
733 }
734 }
735
736 serial = GetRandomSerialNumber();
737
738 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
739 // 3GPP2 apps only
740 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
741 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
742 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
743 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
744 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
745 radio_sim->supplyIccPuk2ForApp(serial, std::string("test1"), std::string("test2"),
746 cardStatus.applications[i].aidPtr);
747 EXPECT_EQ(std::cv_status::no_timeout, wait());
748 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
749 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
750 ASSERT_TRUE(CheckAnyOfErrors(
751 radioRsp_sim->rspInfo.error,
752 {RadioError::PASSWORD_INCORRECT, RadioError::INVALID_SIM_STATE}));
753 }
754 }
755 }
756
757 /*
758 * Test IRadioSim.changeIccPinForApp() for the response returned.
759 */
TEST_P(RadioSimTest,changeIccPinForApp)760 TEST_P(RadioSimTest, changeIccPinForApp) {
761 if (telephony_flags::enforce_telephony_feature_mapping()) {
762 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
763 GTEST_SKIP() << "Skipping changeIccPinForApp "
764 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
765 }
766 }
767
768 serial = GetRandomSerialNumber();
769
770 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
771 // 3GPP2 apps only
772 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
773 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
774 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
775 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
776 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
777 radio_sim->changeIccPinForApp(serial, std::string("test1"), std::string("test2"),
778 cardStatus.applications[i].aidPtr);
779 EXPECT_EQ(std::cv_status::no_timeout, wait());
780 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
781 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
782 ASSERT_TRUE(CheckAnyOfErrors(
783 radioRsp_sim->rspInfo.error,
784 {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED}));
785 }
786 }
787 }
788
789 /*
790 * Test IRadioSim.changeIccPin2ForApp() for the response returned.
791 */
TEST_P(RadioSimTest,changeIccPin2ForApp)792 TEST_P(RadioSimTest, changeIccPin2ForApp) {
793 if (telephony_flags::enforce_telephony_feature_mapping()) {
794 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
795 GTEST_SKIP() << "Skipping changeIccPin2ForApp "
796 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
797 }
798 }
799
800 serial = GetRandomSerialNumber();
801
802 // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and
803 // 3GPP2 apps only
804 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
805 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
806 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
807 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
808 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
809 radio_sim->changeIccPin2ForApp(serial, std::string("test1"), std::string("test2"),
810 cardStatus.applications[i].aidPtr);
811 EXPECT_EQ(std::cv_status::no_timeout, wait());
812 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
813 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
814 ASSERT_TRUE(
815 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
816 {RadioError::PASSWORD_INCORRECT,
817 RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_PUK2}));
818 }
819 }
820 }
821
822 /*
823 * Test IRadioSim.getImsiForApp() for the response returned.
824 */
TEST_P(RadioSimTest,getImsiForApp)825 TEST_P(RadioSimTest, getImsiForApp) {
826 if (telephony_flags::enforce_telephony_feature_mapping()) {
827 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
828 GTEST_SKIP() << "Skipping getImsiForApp "
829 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
830 }
831 }
832
833 serial = GetRandomSerialNumber();
834
835 // Check success returned while getting imsi for 3GPP and 3GPP2 apps only
836 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
837 if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM ||
838 cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM ||
839 cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM ||
840 cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) {
841 radio_sim->getImsiForApp(serial, cardStatus.applications[i].aidPtr);
842 EXPECT_EQ(std::cv_status::no_timeout, wait());
843 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
844 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
845 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE},
846 CHECK_GENERAL_ERROR));
847
848 // IMSI (MCC+MNC+MSIN) is at least 6 digits, but not more than 15
849 if (radioRsp_sim->rspInfo.error == RadioError::NONE) {
850 EXPECT_NE(radioRsp_sim->imsi, std::string());
851 EXPECT_GE((int)(radioRsp_sim->imsi).size(), 6);
852 EXPECT_LE((int)(radioRsp_sim->imsi).size(), 15);
853 }
854 }
855 }
856 }
857
858 /*
859 * Test IRadioSim.iccIoForApp() for the response returned.
860 */
TEST_P(RadioSimTest,iccIoForApp)861 TEST_P(RadioSimTest, iccIoForApp) {
862 if (telephony_flags::enforce_telephony_feature_mapping()) {
863 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
864 GTEST_SKIP() << "Skipping iccIoForApp "
865 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
866 }
867 }
868
869 serial = GetRandomSerialNumber();
870
871 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
872 IccIo iccIo;
873 iccIo.command = 0xc0;
874 iccIo.fileId = 0x6f11;
875 iccIo.path = std::string("3F007FFF");
876 iccIo.p1 = 0;
877 iccIo.p2 = 0;
878 iccIo.p3 = 0;
879 iccIo.data = std::string();
880 iccIo.pin2 = std::string();
881 iccIo.aid = cardStatus.applications[i].aidPtr;
882
883 radio_sim->iccIoForApp(serial, iccIo);
884 EXPECT_EQ(std::cv_status::no_timeout, wait());
885 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
886 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
887 }
888 }
889
890 /*
891 * Test IRadioSim.iccTransmitApduBasicChannel() for the response returned.
892 */
TEST_P(RadioSimTest,iccTransmitApduBasicChannel)893 TEST_P(RadioSimTest, iccTransmitApduBasicChannel) {
894 if (telephony_flags::enforce_telephony_feature_mapping()) {
895 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
896 GTEST_SKIP() << "Skipping iccTransmitApduBasicChannel "
897 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
898 }
899 }
900
901 serial = GetRandomSerialNumber();
902 SimApdu msg;
903 memset(&msg, 0, sizeof(msg));
904 msg.data = std::string();
905
906 radio_sim->iccTransmitApduBasicChannel(serial, msg);
907 EXPECT_EQ(std::cv_status::no_timeout, wait());
908 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
909 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
910 }
911
912 /*
913 * Test IRadioSim.iccOpenLogicalChannel() for the response returned.
914 */
TEST_P(RadioSimTest,iccOpenLogicalChannel)915 TEST_P(RadioSimTest, iccOpenLogicalChannel) {
916 if (telephony_flags::enforce_telephony_feature_mapping()) {
917 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
918 GTEST_SKIP() << "Skipping iccOpenLogicalChannel "
919 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
920 }
921 }
922
923 serial = GetRandomSerialNumber();
924 int p2 = 0x04;
925 // Specified in ISO 7816-4 clause 7.1.1 0x04 means that FCP template is requested.
926 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
927 radio_sim->iccOpenLogicalChannel(serial, cardStatus.applications[i].aidPtr, p2);
928 EXPECT_EQ(std::cv_status::no_timeout, wait());
929 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
930 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
931 }
932 }
933
934 /*
935 * Test IRadioSim.iccCloseLogicalChannel() for the response returned.
936 */
TEST_P(RadioSimTest,iccCloseLogicalChannel)937 TEST_P(RadioSimTest, iccCloseLogicalChannel) {
938 if (telephony_flags::enforce_telephony_feature_mapping()) {
939 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
940 GTEST_SKIP() << "Skipping iccCloseLogicalChannel "
941 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
942 }
943 }
944
945 serial = GetRandomSerialNumber();
946 // Try closing invalid channel and check INVALID_ARGUMENTS returned as error
947 radio_sim->iccCloseLogicalChannel(serial, 0);
948 EXPECT_EQ(std::cv_status::no_timeout, wait());
949 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
950 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
951
952 EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp_sim->rspInfo.error);
953 }
954
955 /*
956 * Test IRadioSim.iccCloseLogicalChannelWithSessionInfo() for the response returned.
957 */
TEST_P(RadioSimTest,iccCloseLogicalChannelWithSessionInfo)958 TEST_P(RadioSimTest, iccCloseLogicalChannelWithSessionInfo) {
959 if (telephony_flags::enforce_telephony_feature_mapping()) {
960 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
961 GTEST_SKIP() << "Skipping iccCloseLogicalChannelWithSessionInfo "
962 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
963 }
964 }
965
966 int32_t aidl_version;
967 ndk::ScopedAStatus aidl_status = radio_sim->getInterfaceVersion(&aidl_version);
968 ASSERT_OK(aidl_status);
969 if (aidl_version < 2) {
970 ALOGI("Skipped the test since"
971 " iccCloseLogicalChannelWithSessionInfo is not supported on version < 2");
972 GTEST_SKIP();
973 }
974 serial = GetRandomSerialNumber();
975 SessionInfo info;
976 memset(&info, 0, sizeof(info));
977 info.sessionId = 0;
978 info.isEs10 = false;
979
980 // Try closing invalid channel and check INVALID_ARGUMENTS returned as error
981 radio_sim->iccCloseLogicalChannelWithSessionInfo(serial, info);
982 EXPECT_EQ(std::cv_status::no_timeout, wait());
983 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
984 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
985
986 EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp_sim->rspInfo.error);
987 }
988
989 /*
990 * Test IRadioSim.iccTransmitApduLogicalChannel() for the response returned.
991 */
TEST_P(RadioSimTest,iccTransmitApduLogicalChannel)992 TEST_P(RadioSimTest, iccTransmitApduLogicalChannel) {
993 if (telephony_flags::enforce_telephony_feature_mapping()) {
994 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
995 GTEST_SKIP() << "Skipping iccTransmitApduLogicalChannel "
996 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
997 }
998 }
999
1000 serial = GetRandomSerialNumber();
1001 SimApdu msg;
1002 memset(&msg, 0, sizeof(msg));
1003 msg.data = std::string();
1004
1005 radio_sim->iccTransmitApduLogicalChannel(serial, msg);
1006 EXPECT_EQ(std::cv_status::no_timeout, wait());
1007 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1008 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1009 }
1010
1011 /*
1012 * Test IRadioSim.requestIccSimAuthentication() for the response returned.
1013 */
TEST_P(RadioSimTest,requestIccSimAuthentication)1014 TEST_P(RadioSimTest, requestIccSimAuthentication) {
1015 if (telephony_flags::enforce_telephony_feature_mapping()) {
1016 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1017 GTEST_SKIP() << "Skipping requestIccSimAuthentication "
1018 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1019 }
1020 }
1021
1022 serial = GetRandomSerialNumber();
1023
1024 // Pass wrong challenge string and check RadioError::INVALID_ARGUMENTS
1025 // or REQUEST_NOT_SUPPORTED returned as error.
1026 for (int i = 0; i < (int)cardStatus.applications.size(); i++) {
1027 radio_sim->requestIccSimAuthentication(serial, 0, std::string("test"),
1028 cardStatus.applications[i].aidPtr);
1029 EXPECT_EQ(std::cv_status::no_timeout, wait());
1030 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1031 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1032 ASSERT_TRUE(CheckAnyOfErrors(
1033 radioRsp_sim->rspInfo.error,
1034 {RadioError::INVALID_ARGUMENTS, RadioError::REQUEST_NOT_SUPPORTED}));
1035 }
1036 }
1037
1038 /*
1039 * Test IRadioSim.getFacilityLockForApp() for the response returned.
1040 */
TEST_P(RadioSimTest,getFacilityLockForApp)1041 TEST_P(RadioSimTest, getFacilityLockForApp) {
1042 if (telephony_flags::enforce_telephony_feature_mapping()) {
1043 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1044 GTEST_SKIP() << "Skipping getFacilityLockForApp "
1045 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1046 }
1047 }
1048
1049 serial = GetRandomSerialNumber();
1050 std::string facility = "";
1051 std::string password = "";
1052 int32_t serviceClass = 1;
1053 std::string appId = "";
1054
1055 radio_sim->getFacilityLockForApp(serial, facility, password, serviceClass, appId);
1056
1057 EXPECT_EQ(std::cv_status::no_timeout, wait());
1058 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1059 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1060
1061 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1062 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
1063 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR},
1064 CHECK_GENERAL_ERROR));
1065 }
1066 }
1067
1068 /*
1069 * Test IRadioSim.setFacilityLockForApp() for the response returned.
1070 */
TEST_P(RadioSimTest,setFacilityLockForApp)1071 TEST_P(RadioSimTest, setFacilityLockForApp) {
1072 if (telephony_flags::enforce_telephony_feature_mapping()) {
1073 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1074 GTEST_SKIP() << "Skipping setFacilityLockForApp "
1075 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1076 }
1077 }
1078
1079 serial = GetRandomSerialNumber();
1080 std::string facility = "";
1081 bool lockState = false;
1082 std::string password = "";
1083 int32_t serviceClass = 1;
1084 std::string appId = "";
1085
1086 radio_sim->setFacilityLockForApp(serial, facility, lockState, password, serviceClass, appId);
1087
1088 EXPECT_EQ(std::cv_status::no_timeout, wait());
1089 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1090 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1091
1092 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1093 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
1094 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR},
1095 CHECK_GENERAL_ERROR));
1096 }
1097 }
1098
1099 /*
1100 * Test IRadioSim.getCdmaSubscription() for the response returned.
1101 */
TEST_P(RadioSimTest,getCdmaSubscription)1102 TEST_P(RadioSimTest, getCdmaSubscription) {
1103 if (telephony_flags::enforce_telephony_feature_mapping()) {
1104 if (!deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
1105 GTEST_SKIP() << "Skipping getCdmaSubscription "
1106 "due to undefined FEATURE_TELEPHONY_CDMA";
1107 }
1108 }
1109
1110 serial = GetRandomSerialNumber();
1111
1112 radio_sim->getCdmaSubscription(serial);
1113 EXPECT_EQ(std::cv_status::no_timeout, wait());
1114 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1115 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1116
1117 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1118 ASSERT_TRUE(CheckAnyOfErrors(
1119 radioRsp_sim->rspInfo.error,
1120 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT}));
1121 }
1122 }
1123
1124 /*
1125 * Test IRadioSim.getCdmaSubscriptionSource() for the response returned.
1126 */
TEST_P(RadioSimTest,getCdmaSubscriptionSource)1127 TEST_P(RadioSimTest, getCdmaSubscriptionSource) {
1128 if (telephony_flags::enforce_telephony_feature_mapping()) {
1129 if (!deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
1130 GTEST_SKIP() << "Skipping getCdmaSubscriptionSource "
1131 "due to undefined FEATURE_TELEPHONY_CDMA";
1132 }
1133 }
1134
1135 serial = GetRandomSerialNumber();
1136
1137 radio_sim->getCdmaSubscriptionSource(serial);
1138 EXPECT_EQ(std::cv_status::no_timeout, wait());
1139 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1140 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1141
1142 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1143 ASSERT_TRUE(CheckAnyOfErrors(
1144 radioRsp_sim->rspInfo.error,
1145 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT}));
1146 }
1147 }
1148
1149 /*
1150 * Test IRadioSim.setCdmaSubscriptionSource() for the response returned.
1151 */
TEST_P(RadioSimTest,setCdmaSubscriptionSource)1152 TEST_P(RadioSimTest, setCdmaSubscriptionSource) {
1153 if (telephony_flags::enforce_telephony_feature_mapping()) {
1154 if (!deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
1155 GTEST_SKIP() << "Skipping setCdmaSubscriptionSource "
1156 "due to undefined FEATURE_TELEPHONY_CDMA";
1157 }
1158 }
1159
1160 serial = GetRandomSerialNumber();
1161
1162 radio_sim->setCdmaSubscriptionSource(serial, CdmaSubscriptionSource::RUIM_SIM);
1163 EXPECT_EQ(std::cv_status::no_timeout, wait());
1164 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1165 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1166
1167 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1168 ASSERT_TRUE(CheckAnyOfErrors(
1169 radioRsp_sim->rspInfo.error,
1170 {RadioError::NONE, RadioError::SIM_ABSENT, RadioError::SUBSCRIPTION_NOT_AVAILABLE},
1171 CHECK_GENERAL_ERROR));
1172 }
1173 }
1174
1175 /*
1176 * Test IRadioSim.setUiccSubscription() for the response returned.
1177 */
TEST_P(RadioSimTest,setUiccSubscription)1178 TEST_P(RadioSimTest, setUiccSubscription) {
1179 if (telephony_flags::enforce_telephony_feature_mapping()) {
1180 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1181 GTEST_SKIP() << "Skipping setUiccSubscription "
1182 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1183 }
1184 }
1185
1186 serial = GetRandomSerialNumber();
1187 SelectUiccSub item;
1188 memset(&item, 0, sizeof(item));
1189
1190 radio_sim->setUiccSubscription(serial, item);
1191 EXPECT_EQ(std::cv_status::no_timeout, wait());
1192 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1193 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1194
1195 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1196 ASSERT_TRUE(
1197 CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
1198 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
1199 RadioError::MODEM_ERR, RadioError::SUBSCRIPTION_NOT_SUPPORTED},
1200 CHECK_GENERAL_ERROR));
1201 }
1202 }
1203
1204 /*
1205 * Test IRadioSim.sendEnvelope() for the response returned.
1206 */
TEST_P(RadioSimTest,sendEnvelope)1207 TEST_P(RadioSimTest, sendEnvelope) {
1208 if (telephony_flags::enforce_telephony_feature_mapping()) {
1209 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1210 GTEST_SKIP() << "Skipping sendEnvelope "
1211 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1212 }
1213 }
1214
1215 serial = GetRandomSerialNumber();
1216
1217 // Test with sending empty string
1218 std::string content = "";
1219
1220 radio_sim->sendEnvelope(serial, content);
1221
1222 EXPECT_EQ(std::cv_status::no_timeout, wait());
1223 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1224 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1225
1226 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1227 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error,
1228 {RadioError::NONE, RadioError::INVALID_ARGUMENTS,
1229 RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
1230 CHECK_GENERAL_ERROR));
1231 }
1232 }
1233
1234 /*
1235 * Test IRadioSim.sendTerminalResponseToSim() for the response returned.
1236 */
TEST_P(RadioSimTest,sendTerminalResponseToSim)1237 TEST_P(RadioSimTest, sendTerminalResponseToSim) {
1238 if (telephony_flags::enforce_telephony_feature_mapping()) {
1239 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1240 GTEST_SKIP() << "Skipping sendTerminalResponseToSim "
1241 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1242 }
1243 }
1244
1245 serial = GetRandomSerialNumber();
1246
1247 // Test with sending empty string
1248 std::string commandResponse = "";
1249
1250 radio_sim->sendTerminalResponseToSim(serial, commandResponse);
1251
1252 EXPECT_EQ(std::cv_status::no_timeout, wait());
1253 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1254 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1255
1256 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1257 ASSERT_TRUE(CheckAnyOfErrors(
1258 radioRsp_sim->rspInfo.error,
1259 {RadioError::NONE, RadioError::INVALID_ARGUMENTS, RadioError::SIM_ABSENT},
1260 CHECK_GENERAL_ERROR));
1261 }
1262 }
1263
1264 /*
1265 * Test IRadioSim.reportStkServiceIsRunning() for the response returned.
1266 */
TEST_P(RadioSimTest,reportStkServiceIsRunning)1267 TEST_P(RadioSimTest, reportStkServiceIsRunning) {
1268 if (telephony_flags::enforce_telephony_feature_mapping()) {
1269 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1270 GTEST_SKIP() << "Skipping reportStkServiceIsRunning "
1271 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1272 }
1273 }
1274
1275 serial = GetRandomSerialNumber();
1276
1277 radio_sim->reportStkServiceIsRunning(serial);
1278
1279 EXPECT_EQ(std::cv_status::no_timeout, wait());
1280 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1281 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1282
1283 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1284 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE},
1285 CHECK_GENERAL_ERROR));
1286 }
1287 }
1288
1289 /*
1290 * Test IRadioSim.sendEnvelopeWithStatus() for the response returned with empty
1291 * string.
1292 */
TEST_P(RadioSimTest,sendEnvelopeWithStatus)1293 TEST_P(RadioSimTest, sendEnvelopeWithStatus) {
1294 if (telephony_flags::enforce_telephony_feature_mapping()) {
1295 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
1296 GTEST_SKIP() << "Skipping sendEnvelopeWithStatus "
1297 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
1298 }
1299 }
1300
1301 serial = GetRandomSerialNumber();
1302
1303 // Test with sending empty string
1304 std::string contents = "";
1305
1306 radio_sim->sendEnvelopeWithStatus(serial, contents);
1307
1308 EXPECT_EQ(std::cv_status::no_timeout, wait());
1309 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type);
1310 EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial);
1311
1312 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
1313 ASSERT_TRUE(CheckAnyOfErrors(
1314 radioRsp_sim->rspInfo.error,
1315 {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR, RadioError::SIM_ABSENT},
1316 CHECK_GENERAL_ERROR));
1317 }
1318 }
1319