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