Sarah Chin | fc5603b | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 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 | |
Sarah Chin | 912bdf3 | 2022-01-28 01:02:16 -0800 | [diff] [blame] | 17 | #include <aidl/android/hardware/radio/RadioConst.h> |
Sarah Chin | fc5603b | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 18 | #include <aidl/android/hardware/radio/config/IRadioConfig.h> |
| 19 | #include <android-base/logging.h> |
| 20 | #include <android/binder_manager.h> |
| 21 | |
| 22 | #include "radio_sim_utils.h" |
| 23 | |
| 24 | #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk()) |
| 25 | |
| 26 | void RadioSimTest::SetUp() { |
| 27 | std::string serviceName = GetParam(); |
| 28 | |
| 29 | if (!isServiceValidForDeviceConfiguration(serviceName)) { |
| 30 | ALOGI("Skipped the test due to device configuration."); |
| 31 | GTEST_SKIP(); |
| 32 | } |
| 33 | |
| 34 | radio_sim = IRadioSim::fromBinder( |
| 35 | ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str()))); |
| 36 | ASSERT_NE(nullptr, radio_sim.get()); |
| 37 | |
| 38 | radioRsp_sim = ndk::SharedRefBase::make<RadioSimResponse>(*this); |
| 39 | ASSERT_NE(nullptr, radioRsp_sim.get()); |
| 40 | |
| 41 | count_ = 0; |
| 42 | |
| 43 | radioInd_sim = ndk::SharedRefBase::make<RadioSimIndication>(*this); |
| 44 | ASSERT_NE(nullptr, radioInd_sim.get()); |
| 45 | |
| 46 | radio_sim->setResponseFunctions(radioRsp_sim, radioInd_sim); |
Sarah Chin | c83bce4 | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 47 | // Assert SIM is present before testing |
| 48 | updateSimCardStatus(); |
| 49 | EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState); |
Sarah Chin | fc5603b | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 50 | |
| 51 | // Assert IRadioConfig exists before testing |
Sarah Chin | c83bce4 | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 52 | radio_config = config::IRadioConfig::fromBinder(ndk::SpAIBinder( |
| 53 | AServiceManager_waitForService("android.hardware.radio.config.IRadioConfig/default"))); |
| 54 | ASSERT_NE(nullptr, radio_config.get()); |
Sarah Chin | fc5603b | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Sarah Chin | c83bce4 | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 57 | void RadioSimTest::updateSimCardStatus() { |
Sarah Chin | fc5603b | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 58 | serial = GetRandomSerialNumber(); |
| 59 | radio_sim->getIccCardStatus(serial); |
| 60 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
Sarah Chin | c83bce4 | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 61 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 62 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 63 | EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error); |
Sarah Chin | fc5603b | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /* |
| 67 | * Test IRadioSim.setSimCardPower() for the response returned. |
| 68 | */ |
| 69 | TEST_P(RadioSimTest, setSimCardPower) { |
| 70 | /* Test setSimCardPower power down */ |
| 71 | serial = GetRandomSerialNumber(); |
| 72 | radio_sim->setSimCardPower(serial, CardPowerState::POWER_DOWN); |
| 73 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 74 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 75 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 76 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 77 | {RadioError::NONE, RadioError::INVALID_ARGUMENTS, |
| 78 | RadioError::RADIO_NOT_AVAILABLE, RadioError::SIM_ERR})); |
| 79 | |
| 80 | // setSimCardPower does not return until the request is handled, and should not trigger |
| 81 | // CardStatus::STATE_ABSENT when turning off power |
| 82 | if (radioRsp_sim->rspInfo.error == RadioError::NONE) { |
| 83 | /* Wait some time for setting sim power down and then verify it */ |
| 84 | updateSimCardStatus(); |
| 85 | // We cannot assert the consistency of CardState here due to b/203031664 |
| 86 | // EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState); |
| 87 | // applications should be an empty vector of AppStatus |
| 88 | EXPECT_EQ(0, cardStatus.applications.size()); |
| 89 | } |
| 90 | |
| 91 | // Give some time for modem to fully power down the SIM card |
| 92 | sleep(MODEM_SET_SIM_POWER_DELAY_IN_SECONDS); |
| 93 | |
| 94 | /* Test setSimCardPower power up */ |
| 95 | serial = GetRandomSerialNumber(); |
| 96 | radio_sim->setSimCardPower(serial, CardPowerState::POWER_UP); |
| 97 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 98 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 99 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 100 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 101 | {RadioError::NONE, RadioError::INVALID_ARGUMENTS, |
| 102 | RadioError::RADIO_NOT_AVAILABLE, RadioError::SIM_ERR})); |
| 103 | |
| 104 | // Give some time for modem to fully power up the SIM card |
| 105 | sleep(MODEM_SET_SIM_POWER_DELAY_IN_SECONDS); |
| 106 | |
| 107 | // setSimCardPower does not return until the request is handled. Just verify that we still |
| 108 | // have CardStatus::STATE_PRESENT after turning the power back on |
| 109 | if (radioRsp_sim->rspInfo.error == RadioError::NONE) { |
| 110 | updateSimCardStatus(); |
| 111 | EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /* |
| 116 | * Test IRadioSim.setCarrierInfoForImsiEncryption() for the response returned. |
| 117 | */ |
| 118 | TEST_P(RadioSimTest, setCarrierInfoForImsiEncryption) { |
| 119 | serial = GetRandomSerialNumber(); |
| 120 | ImsiEncryptionInfo imsiInfo; |
| 121 | imsiInfo.mcc = "310"; |
| 122 | imsiInfo.mnc = "004"; |
| 123 | imsiInfo.carrierKey = (std::vector<uint8_t>){1, 2, 3, 4, 5, 6}; |
| 124 | imsiInfo.keyIdentifier = "Test"; |
| 125 | imsiInfo.expirationTime = 20180101; |
| 126 | imsiInfo.keyType = ImsiEncryptionInfo::PUBLIC_KEY_TYPE_EPDG; |
| 127 | |
| 128 | radio_sim->setCarrierInfoForImsiEncryption(serial, imsiInfo); |
| 129 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 130 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 131 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 132 | |
| 133 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 134 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 135 | {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED})); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /* |
| 140 | * Test IRadioSim.getSimPhonebookRecords() for the response returned. |
| 141 | */ |
| 142 | TEST_P(RadioSimTest, getSimPhonebookRecords) { |
| 143 | serial = GetRandomSerialNumber(); |
| 144 | radio_sim->getSimPhonebookRecords(serial); |
| 145 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 146 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 147 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 148 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 149 | ASSERT_TRUE( |
| 150 | CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 151 | {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE, |
| 152 | RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS, |
| 153 | RadioError::REQUEST_NOT_SUPPORTED}, |
| 154 | CHECK_GENERAL_ERROR)); |
| 155 | } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) { |
| 156 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 157 | {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}, |
| 158 | CHECK_GENERAL_ERROR)); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * Test IRadioSim.getSimPhonebookCapacity for the response returned. |
| 164 | */ |
| 165 | TEST_P(RadioSimTest, getSimPhonebookCapacity) { |
| 166 | serial = GetRandomSerialNumber(); |
| 167 | radio_sim->getSimPhonebookCapacity(serial); |
| 168 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 169 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 170 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 171 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 172 | ASSERT_TRUE( |
| 173 | CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 174 | {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE, |
| 175 | RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS, |
| 176 | RadioError::REQUEST_NOT_SUPPORTED}, |
| 177 | CHECK_GENERAL_ERROR)); |
| 178 | } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) { |
| 179 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 180 | {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}, |
| 181 | CHECK_GENERAL_ERROR)); |
| 182 | |
| 183 | PhonebookCapacity pbCapacity = radioRsp_sim->capacity; |
| 184 | if (pbCapacity.maxAdnRecords > 0) { |
| 185 | EXPECT_TRUE(pbCapacity.maxNameLen > 0 && pbCapacity.maxNumberLen > 0); |
| 186 | EXPECT_TRUE(pbCapacity.usedAdnRecords <= pbCapacity.maxAdnRecords); |
| 187 | } |
| 188 | |
| 189 | if (pbCapacity.maxEmailRecords > 0) { |
| 190 | EXPECT_TRUE(pbCapacity.maxEmailLen > 0); |
| 191 | EXPECT_TRUE(pbCapacity.usedEmailRecords <= pbCapacity.maxEmailRecords); |
| 192 | } |
| 193 | |
| 194 | if (pbCapacity.maxAdditionalNumberRecords > 0) { |
| 195 | EXPECT_TRUE(pbCapacity.maxAdditionalNumberLen > 0); |
| 196 | EXPECT_TRUE(pbCapacity.usedAdditionalNumberRecords <= |
| 197 | pbCapacity.maxAdditionalNumberRecords); |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | /* |
| 203 | * Test IRadioSim.updateSimPhonebookRecords() for the response returned. |
| 204 | */ |
| 205 | TEST_P(RadioSimTest, updateSimPhonebookRecords) { |
| 206 | serial = GetRandomSerialNumber(); |
| 207 | radio_sim->getSimPhonebookCapacity(serial); |
| 208 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 209 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 210 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 211 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 212 | ASSERT_TRUE( |
| 213 | CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 214 | {RadioError::INVALID_SIM_STATE, RadioError::RADIO_NOT_AVAILABLE, |
| 215 | RadioError::MODEM_ERR, RadioError::INVALID_ARGUMENTS, |
| 216 | RadioError::REQUEST_NOT_SUPPORTED}, |
| 217 | CHECK_GENERAL_ERROR)); |
| 218 | } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) { |
| 219 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 220 | {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}, |
| 221 | CHECK_GENERAL_ERROR)); |
| 222 | PhonebookCapacity pbCapacity = radioRsp_sim->capacity; |
| 223 | |
| 224 | serial = GetRandomSerialNumber(); |
| 225 | radio_sim->getSimPhonebookRecords(serial); |
| 226 | |
| 227 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 228 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 229 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 230 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 231 | {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}, |
| 232 | CHECK_GENERAL_ERROR)); |
| 233 | |
| 234 | if (pbCapacity.maxAdnRecords > 0 && pbCapacity.usedAdnRecords < pbCapacity.maxAdnRecords) { |
| 235 | // Add a phonebook record |
| 236 | PhonebookRecordInfo recordInfo; |
| 237 | recordInfo.recordId = 0; |
| 238 | recordInfo.name = "ABC"; |
| 239 | recordInfo.number = "1234567890"; |
| 240 | serial = GetRandomSerialNumber(); |
| 241 | radio_sim->updateSimPhonebookRecords(serial, recordInfo); |
| 242 | |
| 243 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 244 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 245 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 246 | EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error); |
| 247 | int index = radioRsp_sim->updatedRecordIndex; |
| 248 | EXPECT_TRUE(index > 0); |
| 249 | |
| 250 | // Deleted a phonebook record |
| 251 | recordInfo.recordId = index; |
| 252 | recordInfo.name = ""; |
| 253 | recordInfo.number = ""; |
| 254 | serial = GetRandomSerialNumber(); |
| 255 | radio_sim->updateSimPhonebookRecords(serial, recordInfo); |
| 256 | |
| 257 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 258 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 259 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 260 | EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error); |
| 261 | } |
| 262 | } |
| 263 | } |
Sarah Chin | 912bdf3 | 2022-01-28 01:02:16 -0800 | [diff] [blame] | 264 | |
| 265 | /* |
| 266 | * Test IRadioSim.enableUiccApplications() for the response returned. |
| 267 | * For SIM ABSENT case. |
| 268 | */ |
| 269 | TEST_P(RadioSimTest, togglingUiccApplicationsSimAbsent) { |
| 270 | // This test case only test SIM ABSENT case. |
| 271 | if (cardStatus.cardState != CardStatus::STATE_ABSENT) return; |
| 272 | |
| 273 | // Disable Uicc applications. |
| 274 | serial = GetRandomSerialNumber(); |
| 275 | radio_sim->enableUiccApplications(serial, false); |
| 276 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 277 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 278 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 279 | // As SIM is absent, RadioError::SIM_ABSENT should be thrown. |
| 280 | EXPECT_EQ(RadioError::SIM_ABSENT, radioRsp_sim->rspInfo.error); |
| 281 | |
| 282 | // Query Uicc application enablement. |
| 283 | serial = GetRandomSerialNumber(); |
| 284 | radio_sim->areUiccApplicationsEnabled(serial); |
| 285 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 286 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 287 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 288 | // As SIM is absent, RadioError::SIM_ABSENT should be thrown. |
| 289 | EXPECT_EQ(RadioError::SIM_ABSENT, radioRsp_sim->rspInfo.error); |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | * Test IRadioSim.enableUiccApplications() for the response returned. |
| 294 | * For SIM PRESENT case. |
| 295 | */ |
| 296 | TEST_P(RadioSimTest, togglingUiccApplicationsSimPresent) { |
| 297 | // This test case only test SIM ABSENT case. |
| 298 | if (cardStatus.cardState != CardStatus::STATE_PRESENT) return; |
| 299 | if (cardStatus.applications.size() == 0) return; |
| 300 | |
| 301 | // Disable Uicc applications. |
| 302 | serial = GetRandomSerialNumber(); |
| 303 | radio_sim->enableUiccApplications(serial, false); |
| 304 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 305 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 306 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 307 | // As SIM is present, there shouldn't be error. |
| 308 | EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error); |
| 309 | |
| 310 | // Query Uicc application enablement. |
| 311 | serial = GetRandomSerialNumber(); |
| 312 | radio_sim->areUiccApplicationsEnabled(serial); |
| 313 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 314 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 315 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 316 | // As SIM is present, there shouldn't be error. |
| 317 | EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error); |
| 318 | ASSERT_FALSE(radioRsp_sim->areUiccApplicationsEnabled); |
| 319 | |
| 320 | // Enable Uicc applications. |
| 321 | serial = GetRandomSerialNumber(); |
| 322 | radio_sim->enableUiccApplications(serial, true); |
| 323 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 324 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 325 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 326 | // As SIM is present, there shouldn't be error. |
| 327 | EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error); |
| 328 | |
| 329 | // Query Uicc application enablement. |
| 330 | serial = GetRandomSerialNumber(); |
| 331 | radio_sim->areUiccApplicationsEnabled(serial); |
| 332 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 333 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 334 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 335 | // As SIM is present, there shouldn't be error. |
| 336 | EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error); |
| 337 | ASSERT_TRUE(radioRsp_sim->areUiccApplicationsEnabled); |
| 338 | } |
| 339 | |
| 340 | /* |
| 341 | * Test IRadioSim.areUiccApplicationsEnabled() for the response returned. |
| 342 | */ |
| 343 | TEST_P(RadioSimTest, areUiccApplicationsEnabled) { |
| 344 | // Disable Uicc applications. |
| 345 | serial = GetRandomSerialNumber(); |
| 346 | radio_sim->areUiccApplicationsEnabled(serial); |
| 347 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 348 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 349 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 350 | |
| 351 | // If SIM is absent, RadioError::SIM_ABSENT should be thrown. Otherwise there shouldn't be any |
| 352 | // error. |
| 353 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 354 | EXPECT_EQ(RadioError::SIM_ABSENT, radioRsp_sim->rspInfo.error); |
| 355 | } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) { |
| 356 | EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | /* |
| 361 | * Test IRadioSim.getAllowedCarriers() for the response returned. |
| 362 | */ |
| 363 | TEST_P(RadioSimTest, getAllowedCarriers) { |
| 364 | serial = GetRandomSerialNumber(); |
| 365 | |
| 366 | radio_sim->getAllowedCarriers(serial); |
| 367 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 368 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 369 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 370 | |
| 371 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 372 | {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED})); |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Test IRadioSim.setAllowedCarriers() for the response returned. |
| 377 | */ |
| 378 | TEST_P(RadioSimTest, setAllowedCarriers) { |
| 379 | // TODO (b/210712359): remove once shim supports 1.4 or alternative is found |
| 380 | GTEST_SKIP(); |
| 381 | serial = GetRandomSerialNumber(); |
| 382 | CarrierRestrictions carrierRestrictions; |
| 383 | memset(&carrierRestrictions, 0, sizeof(carrierRestrictions)); |
| 384 | carrierRestrictions.allowedCarriers.resize(1); |
| 385 | carrierRestrictions.excludedCarriers.resize(0); |
| 386 | carrierRestrictions.allowedCarriers[0].mcc = std::string("123"); |
| 387 | carrierRestrictions.allowedCarriers[0].mnc = std::string("456"); |
| 388 | carrierRestrictions.allowedCarriers[0].matchType = Carrier::MATCH_TYPE_ALL; |
| 389 | carrierRestrictions.allowedCarriers[0].matchData = std::string(); |
| 390 | carrierRestrictions.priority = true; |
| 391 | carrierRestrictions.allowedCarriersPrioritized = true; |
| 392 | SimLockMultiSimPolicy multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY; |
| 393 | |
| 394 | radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy); |
| 395 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 396 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 397 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 398 | |
| 399 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 400 | {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED})); |
| 401 | |
| 402 | if (radioRsp_sim->rspInfo.error == RadioError::NONE) { |
| 403 | /* Verify the update of the SIM status. This might need some time */ |
| 404 | if (cardStatus.cardState != CardStatus::STATE_ABSENT) { |
| 405 | updateSimCardStatus(); |
| 406 | auto startTime = std::chrono::system_clock::now(); |
| 407 | while (cardStatus.cardState != CardStatus::STATE_RESTRICTED && |
| 408 | std::chrono::duration_cast<std::chrono::seconds>( |
| 409 | std::chrono::system_clock::now() - startTime) |
| 410 | .count() < 30) { |
| 411 | /* Set 2 seconds as interval to check card status */ |
| 412 | sleep(2); |
| 413 | updateSimCardStatus(); |
| 414 | } |
| 415 | EXPECT_EQ(CardStatus::STATE_RESTRICTED, cardStatus.cardState); |
| 416 | } |
| 417 | |
| 418 | /* Verify that configuration was set correctly, retrieving it from the modem */ |
| 419 | serial = GetRandomSerialNumber(); |
| 420 | |
| 421 | radio_sim->getAllowedCarriers(serial); |
| 422 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 423 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 424 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 425 | EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error); |
| 426 | |
| 427 | EXPECT_EQ(1, radioRsp_sim->carrierRestrictionsResp.allowedCarriers.size()); |
| 428 | EXPECT_EQ(0, radioRsp_sim->carrierRestrictionsResp.excludedCarriers.size()); |
| 429 | ASSERT_TRUE(std::string("123") == |
| 430 | radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mcc); |
| 431 | ASSERT_TRUE(std::string("456") == |
| 432 | radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mnc); |
| 433 | EXPECT_EQ(Carrier::MATCH_TYPE_ALL, |
| 434 | radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].matchType); |
| 435 | ASSERT_TRUE(radioRsp_sim->carrierRestrictionsResp.allowedCarriersPrioritized); |
| 436 | EXPECT_EQ(SimLockMultiSimPolicy::NO_MULTISIM_POLICY, radioRsp_sim->multiSimPolicyResp); |
| 437 | |
| 438 | sleep(10); |
| 439 | |
| 440 | /** |
| 441 | * Another test case of the API to cover to allow carrier. |
| 442 | * If the API is supported, this is also used to reset to no carrier restriction |
| 443 | * status for cardStatus. |
| 444 | */ |
| 445 | memset(&carrierRestrictions, 0, sizeof(carrierRestrictions)); |
| 446 | carrierRestrictions.allowedCarriers.resize(0); |
| 447 | carrierRestrictions.excludedCarriers.resize(0); |
| 448 | carrierRestrictions.allowedCarriersPrioritized = false; |
| 449 | |
| 450 | serial = GetRandomSerialNumber(); |
| 451 | radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy); |
| 452 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 453 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 454 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 455 | |
| 456 | EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error); |
| 457 | |
| 458 | if (cardStatus.cardState != CardStatus::STATE_ABSENT) { |
| 459 | /* Resetting back to no carrier restriction needs some time */ |
| 460 | updateSimCardStatus(); |
| 461 | auto startTime = std::chrono::system_clock::now(); |
| 462 | while (cardStatus.cardState == CardStatus::STATE_RESTRICTED && |
| 463 | std::chrono::duration_cast<std::chrono::seconds>( |
| 464 | std::chrono::system_clock::now() - startTime) |
| 465 | .count() < 10) { |
| 466 | /* Set 2 seconds as interval to check card status */ |
| 467 | sleep(2); |
| 468 | updateSimCardStatus(); |
| 469 | } |
| 470 | EXPECT_NE(CardStatus::STATE_RESTRICTED, cardStatus.cardState); |
| 471 | sleep(10); |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | /* |
| 477 | * Test IRadioSim.getIccCardStatus() for the response returned. |
| 478 | */ |
| 479 | TEST_P(RadioSimTest, getIccCardStatus) { |
| 480 | LOG(DEBUG) << "getIccCardStatus"; |
| 481 | EXPECT_LE(cardStatus.applications.size(), RadioConst::CARD_MAX_APPS); |
| 482 | EXPECT_LT(cardStatus.gsmUmtsSubscriptionAppIndex, RadioConst::CARD_MAX_APPS); |
| 483 | EXPECT_LT(cardStatus.cdmaSubscriptionAppIndex, RadioConst::CARD_MAX_APPS); |
| 484 | EXPECT_LT(cardStatus.imsSubscriptionAppIndex, RadioConst::CARD_MAX_APPS); |
| 485 | LOG(DEBUG) << "getIccCardStatus finished"; |
| 486 | } |
| 487 | |
| 488 | /* |
| 489 | * Test IRadioSim.supplyIccPinForApp() for the response returned |
| 490 | */ |
| 491 | TEST_P(RadioSimTest, supplyIccPinForApp) { |
| 492 | LOG(DEBUG) << "supplyIccPinForApp"; |
| 493 | serial = GetRandomSerialNumber(); |
| 494 | |
| 495 | // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and |
| 496 | // 3GPP2 apps only |
| 497 | for (int i = 0; i < (int)cardStatus.applications.size(); i++) { |
| 498 | if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM || |
| 499 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM || |
| 500 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM || |
| 501 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) { |
| 502 | radio_sim->supplyIccPinForApp(serial, std::string("test1"), |
| 503 | cardStatus.applications[i].aidPtr); |
| 504 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 505 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 506 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 507 | ASSERT_TRUE(CheckAnyOfErrors( |
| 508 | radioRsp_sim->rspInfo.error, |
| 509 | {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED})); |
| 510 | } |
| 511 | } |
| 512 | LOG(DEBUG) << "supplyIccPinForApp finished"; |
| 513 | } |
| 514 | |
| 515 | /* |
| 516 | * Test IRadioSim.supplyIccPukForApp() for the response returned. |
| 517 | */ |
| 518 | TEST_P(RadioSimTest, supplyIccPukForApp) { |
| 519 | LOG(DEBUG) << "supplyIccPukForApp"; |
| 520 | serial = GetRandomSerialNumber(); |
| 521 | |
| 522 | // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and |
| 523 | // 3GPP2 apps only |
| 524 | for (int i = 0; i < (int)cardStatus.applications.size(); i++) { |
| 525 | if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM || |
| 526 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM || |
| 527 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM || |
| 528 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) { |
| 529 | radio_sim->supplyIccPukForApp(serial, std::string("test1"), std::string("test2"), |
| 530 | cardStatus.applications[i].aidPtr); |
| 531 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 532 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 533 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 534 | ASSERT_TRUE(CheckAnyOfErrors( |
| 535 | radioRsp_sim->rspInfo.error, |
| 536 | {RadioError::PASSWORD_INCORRECT, RadioError::INVALID_SIM_STATE})); |
| 537 | } |
| 538 | } |
| 539 | LOG(DEBUG) << "supplyIccPukForApp finished"; |
| 540 | } |
| 541 | |
| 542 | /* |
| 543 | * Test IRadioSim.supplyIccPin2ForApp() for the response returned. |
| 544 | */ |
| 545 | TEST_P(RadioSimTest, supplyIccPin2ForApp) { |
| 546 | LOG(DEBUG) << "supplyIccPin2ForApp"; |
| 547 | serial = GetRandomSerialNumber(); |
| 548 | |
| 549 | // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and |
| 550 | // 3GPP2 apps only |
| 551 | for (int i = 0; i < (int)cardStatus.applications.size(); i++) { |
| 552 | if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM || |
| 553 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM || |
| 554 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM || |
| 555 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) { |
| 556 | radio_sim->supplyIccPin2ForApp(serial, std::string("test1"), |
| 557 | cardStatus.applications[i].aidPtr); |
| 558 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 559 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 560 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 561 | ASSERT_TRUE( |
| 562 | CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 563 | {RadioError::PASSWORD_INCORRECT, |
| 564 | RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_PUK2})); |
| 565 | } |
| 566 | } |
| 567 | LOG(DEBUG) << "supplyIccPin2ForApp finished"; |
| 568 | } |
| 569 | |
| 570 | /* |
| 571 | * Test IRadioSim.supplyIccPuk2ForApp() for the response returned. |
| 572 | */ |
| 573 | TEST_P(RadioSimTest, supplyIccPuk2ForApp) { |
| 574 | LOG(DEBUG) << "supplyIccPuk2ForApp"; |
| 575 | serial = GetRandomSerialNumber(); |
| 576 | |
| 577 | // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and |
| 578 | // 3GPP2 apps only |
| 579 | for (int i = 0; i < (int)cardStatus.applications.size(); i++) { |
| 580 | if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM || |
| 581 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM || |
| 582 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM || |
| 583 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) { |
| 584 | radio_sim->supplyIccPuk2ForApp(serial, std::string("test1"), std::string("test2"), |
| 585 | cardStatus.applications[i].aidPtr); |
| 586 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 587 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 588 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 589 | ASSERT_TRUE(CheckAnyOfErrors( |
| 590 | radioRsp_sim->rspInfo.error, |
| 591 | {RadioError::PASSWORD_INCORRECT, RadioError::INVALID_SIM_STATE})); |
| 592 | } |
| 593 | } |
| 594 | LOG(DEBUG) << "supplyIccPuk2ForApp finished"; |
| 595 | } |
| 596 | |
| 597 | /* |
| 598 | * Test IRadioSim.changeIccPinForApp() for the response returned. |
| 599 | */ |
| 600 | TEST_P(RadioSimTest, changeIccPinForApp) { |
| 601 | LOG(DEBUG) << "changeIccPinForApp"; |
| 602 | serial = GetRandomSerialNumber(); |
| 603 | |
| 604 | // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and |
| 605 | // 3GPP2 apps only |
| 606 | for (int i = 0; i < (int)cardStatus.applications.size(); i++) { |
| 607 | if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM || |
| 608 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM || |
| 609 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM || |
| 610 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) { |
| 611 | radio_sim->changeIccPinForApp(serial, std::string("test1"), std::string("test2"), |
| 612 | cardStatus.applications[i].aidPtr); |
| 613 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 614 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 615 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 616 | ASSERT_TRUE(CheckAnyOfErrors( |
| 617 | radioRsp_sim->rspInfo.error, |
| 618 | {RadioError::PASSWORD_INCORRECT, RadioError::REQUEST_NOT_SUPPORTED})); |
| 619 | } |
| 620 | } |
| 621 | LOG(DEBUG) << "changeIccPinForApp finished"; |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | * Test IRadioSim.changeIccPin2ForApp() for the response returned. |
| 626 | */ |
| 627 | TEST_P(RadioSimTest, changeIccPin2ForApp) { |
| 628 | LOG(DEBUG) << "changeIccPin2ForApp"; |
| 629 | serial = GetRandomSerialNumber(); |
| 630 | |
| 631 | // Pass wrong password and check PASSWORD_INCORRECT returned for 3GPP and |
| 632 | // 3GPP2 apps only |
| 633 | for (int i = 0; i < (int)cardStatus.applications.size(); i++) { |
| 634 | if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM || |
| 635 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM || |
| 636 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM || |
| 637 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) { |
| 638 | radio_sim->changeIccPin2ForApp(serial, std::string("test1"), std::string("test2"), |
| 639 | cardStatus.applications[i].aidPtr); |
| 640 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 641 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 642 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 643 | ASSERT_TRUE( |
| 644 | CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 645 | {RadioError::PASSWORD_INCORRECT, |
| 646 | RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_PUK2})); |
| 647 | } |
| 648 | } |
| 649 | LOG(DEBUG) << "changeIccPin2ForApp finished"; |
| 650 | } |
| 651 | |
| 652 | /* |
| 653 | * The following test is disabled due to b/109889468 |
| 654 | * |
| 655 | * Test IRadioSim.getImsiForApp() for the response returned. |
| 656 | */ |
| 657 | TEST_P(RadioSimTest, DISABLED_getImsiForApp) { |
| 658 | LOG(DEBUG) << "DISABLED_getImsiForApp"; |
| 659 | serial = GetRandomSerialNumber(); |
| 660 | |
| 661 | // Check success returned while getting imsi for 3GPP and 3GPP2 apps only |
| 662 | for (int i = 0; i < (int)cardStatus.applications.size(); i++) { |
| 663 | if (cardStatus.applications[i].appType == AppStatus::APP_TYPE_SIM || |
| 664 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_USIM || |
| 665 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_RUIM || |
| 666 | cardStatus.applications[i].appType == AppStatus::APP_TYPE_CSIM) { |
| 667 | radio_sim->getImsiForApp(serial, cardStatus.applications[i].aidPtr); |
| 668 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 669 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 670 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 671 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE}, |
| 672 | CHECK_GENERAL_ERROR)); |
| 673 | |
| 674 | // IMSI (MCC+MNC+MSIN) is at least 6 digits, but not more than 15 |
| 675 | if (radioRsp_sim->rspInfo.error == RadioError::NONE) { |
| 676 | EXPECT_NE(radioRsp_sim->imsi, std::string()); |
| 677 | EXPECT_GE((int)(radioRsp_sim->imsi).size(), 6); |
| 678 | EXPECT_LE((int)(radioRsp_sim->imsi).size(), 15); |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | LOG(DEBUG) << "DISABLED_getImsiForApp finished"; |
| 683 | } |
| 684 | |
| 685 | /* |
| 686 | * Test IRadioSim.iccIoForApp() for the response returned. |
| 687 | */ |
| 688 | TEST_P(RadioSimTest, iccIoForApp) { |
| 689 | LOG(DEBUG) << "iccIoForApp"; |
| 690 | serial = GetRandomSerialNumber(); |
| 691 | |
| 692 | for (int i = 0; i < (int)cardStatus.applications.size(); i++) { |
| 693 | IccIo iccIo; |
| 694 | iccIo.command = 0xc0; |
| 695 | iccIo.fileId = 0x6f11; |
| 696 | iccIo.path = std::string("3F007FFF"); |
| 697 | iccIo.p1 = 0; |
| 698 | iccIo.p2 = 0; |
| 699 | iccIo.p3 = 0; |
| 700 | iccIo.data = std::string(); |
| 701 | iccIo.pin2 = std::string(); |
| 702 | iccIo.aid = cardStatus.applications[i].aidPtr; |
| 703 | |
| 704 | radio_sim->iccIoForApp(serial, iccIo); |
| 705 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 706 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 707 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 708 | } |
| 709 | LOG(DEBUG) << "iccIoForApp finished"; |
| 710 | } |
| 711 | |
| 712 | /* |
| 713 | * Test IRadioSim.iccTransmitApduBasicChannel() for the response returned. |
| 714 | */ |
| 715 | TEST_P(RadioSimTest, iccTransmitApduBasicChannel) { |
| 716 | LOG(DEBUG) << "iccTransmitApduBasicChannel"; |
| 717 | serial = GetRandomSerialNumber(); |
| 718 | SimApdu msg; |
| 719 | memset(&msg, 0, sizeof(msg)); |
| 720 | msg.data = std::string(); |
| 721 | |
| 722 | radio_sim->iccTransmitApduBasicChannel(serial, msg); |
| 723 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 724 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 725 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 726 | |
| 727 | // TODO(sanketpadawe): Add test for error code |
| 728 | LOG(DEBUG) << "iccTransmitApduBasicChannel finished"; |
| 729 | } |
| 730 | |
| 731 | /* |
| 732 | * Test IRadioSim.iccOpenLogicalChannel() for the response returned. |
| 733 | */ |
| 734 | TEST_P(RadioSimTest, iccOpenLogicalChannel) { |
| 735 | LOG(DEBUG) << "iccOpenLogicalChannel"; |
| 736 | serial = GetRandomSerialNumber(); |
| 737 | int p2 = 0x04; |
| 738 | // Specified in ISO 7816-4 clause 7.1.1 0x04 means that FCP template is requested. |
| 739 | for (int i = 0; i < (int)cardStatus.applications.size(); i++) { |
| 740 | radio_sim->iccOpenLogicalChannel(serial, cardStatus.applications[i].aidPtr, p2); |
| 741 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 742 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 743 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 744 | } |
| 745 | LOG(DEBUG) << "iccOpenLogicalChannel finished"; |
| 746 | } |
| 747 | |
| 748 | /* |
| 749 | * Test IRadioSim.iccCloseLogicalChannel() for the response returned. |
| 750 | */ |
| 751 | TEST_P(RadioSimTest, iccCloseLogicalChannel) { |
| 752 | LOG(DEBUG) << "iccCloseLogicalChannel"; |
| 753 | serial = GetRandomSerialNumber(); |
| 754 | // Try closing invalid channel and check INVALID_ARGUMENTS returned as error |
| 755 | radio_sim->iccCloseLogicalChannel(serial, 0); |
| 756 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 757 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 758 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 759 | |
| 760 | EXPECT_EQ(RadioError::INVALID_ARGUMENTS, radioRsp_sim->rspInfo.error); |
| 761 | LOG(DEBUG) << "iccCloseLogicalChannel finished"; |
| 762 | } |
| 763 | |
| 764 | /* |
| 765 | * Test IRadioSim.iccTransmitApduLogicalChannel() for the response returned. |
| 766 | */ |
| 767 | TEST_P(RadioSimTest, iccTransmitApduLogicalChannel) { |
| 768 | LOG(DEBUG) << "iccTransmitApduLogicalChannel"; |
| 769 | serial = GetRandomSerialNumber(); |
| 770 | SimApdu msg; |
| 771 | memset(&msg, 0, sizeof(msg)); |
| 772 | msg.data = std::string(); |
| 773 | |
| 774 | radio_sim->iccTransmitApduLogicalChannel(serial, msg); |
| 775 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 776 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 777 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 778 | |
| 779 | // TODO(sanketpadawe): Add test for error code |
| 780 | LOG(DEBUG) << "iccTransmitApduLogicalChannel finished"; |
| 781 | } |
| 782 | |
| 783 | /* |
| 784 | * Test IRadioSim.requestIccSimAuthentication() for the response returned. |
| 785 | */ |
| 786 | TEST_P(RadioSimTest, requestIccSimAuthentication) { |
| 787 | LOG(DEBUG) << "requestIccSimAuthentication"; |
| 788 | serial = GetRandomSerialNumber(); |
| 789 | |
| 790 | // Pass wrong challenge string and check RadioError::INVALID_ARGUMENTS |
| 791 | // or REQUEST_NOT_SUPPORTED returned as error. |
| 792 | for (int i = 0; i < (int)cardStatus.applications.size(); i++) { |
| 793 | radio_sim->requestIccSimAuthentication(serial, 0, std::string("test"), |
| 794 | cardStatus.applications[i].aidPtr); |
| 795 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 796 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 797 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 798 | ASSERT_TRUE(CheckAnyOfErrors( |
| 799 | radioRsp_sim->rspInfo.error, |
| 800 | {RadioError::INVALID_ARGUMENTS, RadioError::REQUEST_NOT_SUPPORTED})); |
| 801 | } |
| 802 | LOG(DEBUG) << "requestIccSimAuthentication finished"; |
| 803 | } |
| 804 | |
| 805 | /* |
| 806 | * Test IRadioSim.getFacilityLockForApp() for the response returned. |
| 807 | */ |
| 808 | TEST_P(RadioSimTest, getFacilityLockForApp) { |
| 809 | serial = GetRandomSerialNumber(); |
| 810 | std::string facility = ""; |
| 811 | std::string password = ""; |
| 812 | int32_t serviceClass = 1; |
| 813 | std::string appId = ""; |
| 814 | |
| 815 | radio_sim->getFacilityLockForApp(serial, facility, password, serviceClass, appId); |
| 816 | |
| 817 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 818 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 819 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 820 | |
| 821 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 822 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 823 | {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR}, |
| 824 | CHECK_GENERAL_ERROR)); |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | /* |
| 829 | * Test IRadioSim.setFacilityLockForApp() for the response returned. |
| 830 | */ |
| 831 | TEST_P(RadioSimTest, setFacilityLockForApp) { |
| 832 | serial = GetRandomSerialNumber(); |
| 833 | std::string facility = ""; |
| 834 | bool lockState = false; |
| 835 | std::string password = ""; |
| 836 | int32_t serviceClass = 1; |
| 837 | std::string appId = ""; |
| 838 | |
| 839 | radio_sim->setFacilityLockForApp(serial, facility, lockState, password, serviceClass, appId); |
| 840 | |
| 841 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 842 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 843 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 844 | |
| 845 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 846 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 847 | {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR}, |
| 848 | CHECK_GENERAL_ERROR)); |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | /* |
| 853 | * Test IRadioSim.getCdmaSubscription() for the response returned. |
| 854 | */ |
| 855 | TEST_P(RadioSimTest, getCdmaSubscription) { |
| 856 | LOG(DEBUG) << "getCdmaSubscription"; |
| 857 | serial = GetRandomSerialNumber(); |
| 858 | |
| 859 | radio_sim->getCdmaSubscription(serial); |
| 860 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 861 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 862 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 863 | |
| 864 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 865 | ASSERT_TRUE(CheckAnyOfErrors( |
| 866 | radioRsp_sim->rspInfo.error, |
| 867 | {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT})); |
| 868 | } |
| 869 | LOG(DEBUG) << "getCdmaSubscription finished"; |
| 870 | } |
| 871 | |
| 872 | /* |
| 873 | * Test IRadioSim.getCdmaSubscriptionSource() for the response returned. |
| 874 | */ |
| 875 | TEST_P(RadioSimTest, getCdmaSubscriptionSource) { |
| 876 | LOG(DEBUG) << "getCdmaSubscriptionSource"; |
| 877 | serial = GetRandomSerialNumber(); |
| 878 | |
| 879 | radio_sim->getCdmaSubscriptionSource(serial); |
| 880 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 881 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 882 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 883 | |
| 884 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 885 | ASSERT_TRUE(CheckAnyOfErrors( |
| 886 | radioRsp_sim->rspInfo.error, |
| 887 | {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED, RadioError::SIM_ABSENT})); |
| 888 | } |
| 889 | LOG(DEBUG) << "getCdmaSubscriptionSource finished"; |
| 890 | } |
| 891 | |
| 892 | /* |
| 893 | * Test IRadioSim.setCdmaSubscriptionSource() for the response returned. |
| 894 | */ |
| 895 | TEST_P(RadioSimTest, setCdmaSubscriptionSource) { |
| 896 | LOG(DEBUG) << "setCdmaSubscriptionSource"; |
| 897 | serial = GetRandomSerialNumber(); |
| 898 | |
| 899 | radio_sim->setCdmaSubscriptionSource(serial, CdmaSubscriptionSource::RUIM_SIM); |
| 900 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 901 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 902 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 903 | |
| 904 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 905 | ASSERT_TRUE(CheckAnyOfErrors( |
| 906 | radioRsp_sim->rspInfo.error, |
| 907 | {RadioError::NONE, RadioError::SIM_ABSENT, RadioError::SUBSCRIPTION_NOT_AVAILABLE}, |
| 908 | CHECK_GENERAL_ERROR)); |
| 909 | } |
| 910 | LOG(DEBUG) << "setCdmaSubscriptionSource finished"; |
| 911 | } |
| 912 | |
| 913 | /* |
| 914 | * Test IRadioSim.setUiccSubscription() for the response returned. |
| 915 | */ |
| 916 | TEST_P(RadioSimTest, setUiccSubscription) { |
| 917 | LOG(DEBUG) << "setUiccSubscription"; |
| 918 | serial = GetRandomSerialNumber(); |
| 919 | SelectUiccSub item; |
| 920 | memset(&item, 0, sizeof(item)); |
| 921 | |
| 922 | radio_sim->setUiccSubscription(serial, item); |
| 923 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 924 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 925 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 926 | |
| 927 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 928 | ASSERT_TRUE( |
| 929 | CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 930 | {RadioError::NONE, RadioError::INVALID_ARGUMENTS, |
| 931 | RadioError::MODEM_ERR, RadioError::SUBSCRIPTION_NOT_SUPPORTED}, |
| 932 | CHECK_GENERAL_ERROR)); |
| 933 | } |
| 934 | LOG(DEBUG) << "setUiccSubscription finished"; |
| 935 | } |
| 936 | |
| 937 | /* |
| 938 | * Test IRadioSim.sendEnvelope() for the response returned. |
| 939 | */ |
| 940 | TEST_P(RadioSimTest, sendEnvelope) { |
| 941 | LOG(DEBUG) << "sendEnvelope"; |
| 942 | serial = GetRandomSerialNumber(); |
| 943 | |
| 944 | // Test with sending empty string |
| 945 | std::string content = ""; |
| 946 | |
| 947 | radio_sim->sendEnvelope(serial, content); |
| 948 | |
| 949 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 950 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 951 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 952 | |
| 953 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 954 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, |
| 955 | {RadioError::NONE, RadioError::INVALID_ARGUMENTS, |
| 956 | RadioError::MODEM_ERR, RadioError::SIM_ABSENT}, |
| 957 | CHECK_GENERAL_ERROR)); |
| 958 | } |
| 959 | LOG(DEBUG) << "sendEnvelope finished"; |
| 960 | } |
| 961 | |
| 962 | /* |
| 963 | * Test IRadioSim.sendTerminalResponseToSim() for the response returned. |
| 964 | */ |
| 965 | TEST_P(RadioSimTest, sendTerminalResponseToSim) { |
| 966 | LOG(DEBUG) << "sendTerminalResponseToSim"; |
| 967 | serial = GetRandomSerialNumber(); |
| 968 | |
| 969 | // Test with sending empty string |
| 970 | std::string commandResponse = ""; |
| 971 | |
| 972 | radio_sim->sendTerminalResponseToSim(serial, commandResponse); |
| 973 | |
| 974 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 975 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 976 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 977 | |
| 978 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 979 | ASSERT_TRUE(CheckAnyOfErrors( |
| 980 | radioRsp_sim->rspInfo.error, |
| 981 | {RadioError::NONE, RadioError::INVALID_ARGUMENTS, RadioError::SIM_ABSENT}, |
| 982 | CHECK_GENERAL_ERROR)); |
| 983 | } |
| 984 | LOG(DEBUG) << "sendTerminalResponseToSim finished"; |
| 985 | } |
| 986 | |
| 987 | /* |
| 988 | * Test IRadioSim.reportStkServiceIsRunning() for the response returned. |
| 989 | */ |
| 990 | TEST_P(RadioSimTest, reportStkServiceIsRunning) { |
| 991 | LOG(DEBUG) << "reportStkServiceIsRunning"; |
| 992 | serial = GetRandomSerialNumber(); |
| 993 | |
| 994 | radio_sim->reportStkServiceIsRunning(serial); |
| 995 | |
| 996 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 997 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 998 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 999 | |
| 1000 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 1001 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_sim->rspInfo.error, {RadioError::NONE}, |
| 1002 | CHECK_GENERAL_ERROR)); |
| 1003 | } |
| 1004 | LOG(DEBUG) << "reportStkServiceIsRunning finished"; |
| 1005 | } |
| 1006 | |
| 1007 | /* |
| 1008 | * Test IRadioSim.sendEnvelopeWithStatus() for the response returned with empty |
| 1009 | * string. |
| 1010 | */ |
| 1011 | TEST_P(RadioSimTest, sendEnvelopeWithStatus) { |
| 1012 | LOG(DEBUG) << "sendEnvelopeWithStatus"; |
| 1013 | serial = GetRandomSerialNumber(); |
| 1014 | |
| 1015 | // Test with sending empty string |
| 1016 | std::string contents = ""; |
| 1017 | |
| 1018 | radio_sim->sendEnvelopeWithStatus(serial, contents); |
| 1019 | |
| 1020 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 1021 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_sim->rspInfo.type); |
| 1022 | EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); |
| 1023 | |
| 1024 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 1025 | ASSERT_TRUE(CheckAnyOfErrors( |
| 1026 | radioRsp_sim->rspInfo.error, |
| 1027 | {RadioError::INVALID_ARGUMENTS, RadioError::MODEM_ERR, RadioError::SIM_ABSENT}, |
| 1028 | CHECK_GENERAL_ERROR)); |
| 1029 | } |
| 1030 | LOG(DEBUG) << "sendEnvelopeWithStatus finished"; |
| 1031 | } |