Sarah Chin | 91997ac | 2021-12-29 00:35:12 -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 | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 17 | #include <android/binder_manager.h> |
| 18 | |
| 19 | #include "radio_config_utils.h" |
| 20 | |
| 21 | #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk()) |
| 22 | |
| 23 | void RadioConfigTest::SetUp() { |
Sarah Chin | a1efe7a | 2023-05-02 21:11:41 -0700 | [diff] [blame] | 24 | RadioServiceTest::SetUp(); |
Sarah Chin | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 25 | std::string serviceName = GetParam(); |
| 26 | |
Sarah Chin | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 27 | radio_config = IRadioConfig::fromBinder( |
| 28 | ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str()))); |
| 29 | ASSERT_NE(nullptr, radio_config.get()); |
| 30 | |
| 31 | radioRsp_config = ndk::SharedRefBase::make<RadioConfigResponse>(*this); |
| 32 | ASSERT_NE(nullptr, radioRsp_config.get()); |
| 33 | |
Sarah Chin | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 34 | radioInd_config = ndk::SharedRefBase::make<RadioConfigIndication>(*this); |
| 35 | ASSERT_NE(nullptr, radioInd_config.get()); |
| 36 | |
| 37 | radio_config->setResponseFunctions(radioRsp_config, radioInd_config); |
| 38 | } |
| 39 | |
sandeepjs | 3bb5000 | 2022-02-15 11:41:28 +0000 | [diff] [blame] | 40 | void RadioConfigTest::updateSimSlotStatus() { |
| 41 | serial = GetRandomSerialNumber(); |
| 42 | radio_config->getSimSlotsStatus(serial); |
| 43 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 44 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 45 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 46 | EXPECT_EQ(RadioError::NONE, radioRsp_config->rspInfo.error); |
| 47 | // assuming only 1 slot |
| 48 | for (const SimSlotStatus& slotStatusResponse : radioRsp_config->simSlotStatus) { |
| 49 | slotStatus = slotStatusResponse; |
| 50 | } |
| 51 | } |
| 52 | |
Sarah Chin | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 53 | /* |
| 54 | * Test IRadioConfig.getHalDeviceCapabilities() for the response returned. |
| 55 | */ |
| 56 | TEST_P(RadioConfigTest, getHalDeviceCapabilities) { |
joonhunshin | d519aea | 2023-10-31 03:06:54 +0000 | [diff] [blame] | 57 | if (telephony_flags::enforce_telephony_feature_mapping()) { |
| 58 | if (!deviceSupportsFeature(FEATURE_TELEPHONY)) { |
| 59 | GTEST_SKIP() << "Skipping getHalDeviceCapabilities " |
| 60 | "due to undefined FEATURE_TELEPHONY"; |
| 61 | } |
| 62 | } |
| 63 | |
Sarah Chin | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 64 | serial = GetRandomSerialNumber(); |
| 65 | ndk::ScopedAStatus res = radio_config->getHalDeviceCapabilities(serial); |
| 66 | ASSERT_OK(res); |
Tim Lin | 1483037 | 2022-04-08 22:54:48 +0800 | [diff] [blame] | 67 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
Sarah Chin | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 68 | ALOGI("getHalDeviceCapabilities, rspInfo.error = %s\n", |
| 69 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 70 | } |
Sarah Chin | 52de0ad | 2022-01-28 01:02:16 -0800 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * Test IRadioConfig.getSimSlotsStatus() for the response returned. |
| 74 | */ |
| 75 | TEST_P(RadioConfigTest, getSimSlotsStatus) { |
joonhunshin | d519aea | 2023-10-31 03:06:54 +0000 | [diff] [blame] | 76 | if (telephony_flags::enforce_telephony_feature_mapping()) { |
| 77 | if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) { |
| 78 | GTEST_SKIP() << "Skipping getSimSlotsStatus " |
| 79 | "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION"; |
| 80 | } |
| 81 | } |
| 82 | |
Sarah Chin | 52de0ad | 2022-01-28 01:02:16 -0800 | [diff] [blame] | 83 | serial = GetRandomSerialNumber(); |
| 84 | ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial); |
| 85 | ASSERT_OK(res); |
Tim Lin | 1483037 | 2022-04-08 22:54:48 +0800 | [diff] [blame] | 86 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
Sarah Chin | 52de0ad | 2022-01-28 01:02:16 -0800 | [diff] [blame] | 87 | ALOGI("getSimSlotsStatus, rspInfo.error = %s\n", |
| 88 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * Test IRadioConfig.getPhoneCapability() for the response returned. |
| 93 | */ |
| 94 | TEST_P(RadioConfigTest, getPhoneCapability) { |
joonhunshin | d519aea | 2023-10-31 03:06:54 +0000 | [diff] [blame] | 95 | if (telephony_flags::enforce_telephony_feature_mapping()) { |
| 96 | if (!deviceSupportsFeature(FEATURE_TELEPHONY)) { |
| 97 | GTEST_SKIP() << "Skipping getPhoneCapability " |
| 98 | "due to undefined FEATURE_TELEPHONY"; |
| 99 | } |
| 100 | } |
| 101 | |
Sarah Chin | 52de0ad | 2022-01-28 01:02:16 -0800 | [diff] [blame] | 102 | serial = GetRandomSerialNumber(); |
| 103 | ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial); |
| 104 | ASSERT_OK(res); |
| 105 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 106 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 107 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 108 | ALOGI("getPhoneCapability, rspInfo.error = %s\n", |
| 109 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 110 | |
| 111 | ASSERT_TRUE(CheckAnyOfErrors( |
| 112 | radioRsp_config->rspInfo.error, |
| 113 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR})); |
| 114 | |
| 115 | if (radioRsp_config->rspInfo.error == RadioError ::NONE) { |
| 116 | // maxActiveData should be greater than or equal to maxActiveInternetData. |
| 117 | EXPECT_GE(radioRsp_config->phoneCap.maxActiveData, |
| 118 | radioRsp_config->phoneCap.maxActiveInternetData); |
| 119 | // maxActiveData and maxActiveInternetData should be 0 or positive numbers. |
| 120 | EXPECT_GE(radioRsp_config->phoneCap.maxActiveInternetData, 0); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /* |
| 125 | * Test IRadioConfig.setPreferredDataModem() for the response returned. |
| 126 | */ |
| 127 | TEST_P(RadioConfigTest, setPreferredDataModem) { |
joonhunshin | d519aea | 2023-10-31 03:06:54 +0000 | [diff] [blame] | 128 | if (telephony_flags::enforce_telephony_feature_mapping()) { |
| 129 | if (!deviceSupportsFeature(FEATURE_TELEPHONY_DATA)) { |
| 130 | GTEST_SKIP() << "Skipping setPreferredDataModem " |
| 131 | "due to undefined FEATURE_TELEPHONY_DATA"; |
| 132 | } |
| 133 | } |
| 134 | |
Sarah Chin | 52de0ad | 2022-01-28 01:02:16 -0800 | [diff] [blame] | 135 | serial = GetRandomSerialNumber(); |
| 136 | ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial); |
| 137 | ASSERT_OK(res); |
| 138 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 139 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 140 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 141 | ALOGI("getPhoneCapability, rspInfo.error = %s\n", |
| 142 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 143 | |
| 144 | ASSERT_TRUE(CheckAnyOfErrors( |
| 145 | radioRsp_config->rspInfo.error, |
| 146 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR})); |
| 147 | |
| 148 | if (radioRsp_config->rspInfo.error != RadioError ::NONE) { |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | if (radioRsp_config->phoneCap.logicalModemIds.size() == 0) { |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | // We get phoneCapability. Send setPreferredDataModem command |
| 157 | serial = GetRandomSerialNumber(); |
| 158 | uint8_t modemId = radioRsp_config->phoneCap.logicalModemIds[0]; |
| 159 | res = radio_config->setPreferredDataModem(serial, modemId); |
| 160 | |
| 161 | ASSERT_OK(res); |
| 162 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 163 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 164 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 165 | ALOGI("setPreferredDataModem, rspInfo.error = %s\n", |
| 166 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 167 | |
| 168 | ASSERT_TRUE(CheckAnyOfErrors( |
| 169 | radioRsp_config->rspInfo.error, |
| 170 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR})); |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Test IRadioConfig.setPreferredDataModem() with invalid arguments. |
| 175 | */ |
| 176 | TEST_P(RadioConfigTest, setPreferredDataModem_invalidArgument) { |
joonhunshin | d519aea | 2023-10-31 03:06:54 +0000 | [diff] [blame] | 177 | if (telephony_flags::enforce_telephony_feature_mapping()) { |
| 178 | if (!deviceSupportsFeature(FEATURE_TELEPHONY_DATA)) { |
| 179 | GTEST_SKIP() << "Skipping setPreferredDataModem_invalidArgument " |
| 180 | "due to undefined FEATURE_TELEPHONY_DATA"; |
| 181 | } |
| 182 | } |
| 183 | |
Sarah Chin | 52de0ad | 2022-01-28 01:02:16 -0800 | [diff] [blame] | 184 | serial = GetRandomSerialNumber(); |
| 185 | uint8_t modemId = -1; |
| 186 | ndk::ScopedAStatus res = radio_config->setPreferredDataModem(serial, modemId); |
| 187 | |
| 188 | ASSERT_OK(res); |
| 189 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 190 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 191 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 192 | ALOGI("setPreferredDataModem, rspInfo.error = %s\n", |
| 193 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 194 | |
| 195 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error, |
| 196 | {RadioError::INVALID_ARGUMENTS, RadioError::RADIO_NOT_AVAILABLE, |
| 197 | RadioError::INTERNAL_ERR})); |
| 198 | } |
sandeepjs | 3bb5000 | 2022-02-15 11:41:28 +0000 | [diff] [blame] | 199 | |
| 200 | /* |
| 201 | * Test IRadioConfig.setSimSlotsMapping() for the response returned. |
| 202 | */ |
| 203 | TEST_P(RadioConfigTest, setSimSlotsMapping) { |
joonhunshin | d519aea | 2023-10-31 03:06:54 +0000 | [diff] [blame] | 204 | if (telephony_flags::enforce_telephony_feature_mapping()) { |
| 205 | if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) { |
| 206 | GTEST_SKIP() << "Skipping setSimSlotsMapping " |
| 207 | "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION"; |
| 208 | } |
| 209 | } |
| 210 | |
Tim Lin | 1a55fff | 2022-04-07 01:25:37 +0800 | [diff] [blame] | 211 | // get slot status and set SIM slots mapping based on the result. |
| 212 | updateSimSlotStatus(); |
| 213 | if (radioRsp_config->rspInfo.error == RadioError::NONE) { |
| 214 | SlotPortMapping slotPortMapping; |
| 215 | // put invalid value at first and adjust by slotStatusResponse. |
| 216 | slotPortMapping.physicalSlotId = -1; |
| 217 | slotPortMapping.portId = -1; |
| 218 | std::vector<SlotPortMapping> slotPortMappingList = {slotPortMapping}; |
Zhang Yuan | 2910082 | 2022-10-20 16:39:19 +0800 | [diff] [blame] | 219 | if (isDsDsEnabled() || isDsDaEnabled()) { |
Tim Lin | 1a55fff | 2022-04-07 01:25:37 +0800 | [diff] [blame] | 220 | slotPortMappingList.push_back(slotPortMapping); |
| 221 | } else if (isTsTsEnabled()) { |
| 222 | slotPortMappingList.push_back(slotPortMapping); |
| 223 | slotPortMappingList.push_back(slotPortMapping); |
| 224 | } |
| 225 | for (size_t i = 0; i < radioRsp_config->simSlotStatus.size(); i++) { |
| 226 | ASSERT_TRUE(radioRsp_config->simSlotStatus[i].portInfo.size() > 0); |
| 227 | for (size_t j = 0; j < radioRsp_config->simSlotStatus[i].portInfo.size(); j++) { |
| 228 | if (radioRsp_config->simSlotStatus[i].portInfo[j].portActive) { |
| 229 | int32_t logicalSlotId = |
| 230 | radioRsp_config->simSlotStatus[i].portInfo[j].logicalSlotId; |
| 231 | // logicalSlotId should be 0 or positive numbers if the port |
| 232 | // is active. |
| 233 | EXPECT_GE(logicalSlotId, 0); |
| 234 | // logicalSlotId should be less than the maximum number of |
| 235 | // supported SIM slots. |
| 236 | EXPECT_LT(logicalSlotId, slotPortMappingList.size()); |
| 237 | if (logicalSlotId >= 0 && logicalSlotId < slotPortMappingList.size()) { |
| 238 | slotPortMappingList[logicalSlotId].physicalSlotId = i; |
sandeepjs | 7529611 | 2024-05-21 18:08:44 +0000 | [diff] [blame^] | 239 | if (radioRsp_config->simSlotStatus[i].supportedMepMode == |
| 240 | MultipleEnabledProfilesMode::MEP_A1 || |
| 241 | radioRsp_config->simSlotStatus[i].supportedMepMode == |
| 242 | MultipleEnabledProfilesMode::MEP_A2) { |
| 243 | slotPortMappingList[logicalSlotId].portId = j + 1; |
| 244 | } else { |
| 245 | slotPortMappingList[logicalSlotId].portId = j; |
| 246 | } |
Tim Lin | 1a55fff | 2022-04-07 01:25:37 +0800 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | } |
| 250 | } |
Tim Lin | fd854fe | 2022-03-31 21:06:57 +0800 | [diff] [blame] | 251 | |
Tim Lin | 1a55fff | 2022-04-07 01:25:37 +0800 | [diff] [blame] | 252 | // set SIM slots mapping |
| 253 | for (size_t i = 0; i < slotPortMappingList.size(); i++) { |
| 254 | // physicalSlotId and portId should be 0 or positive numbers for the |
| 255 | // input of setSimSlotsMapping. |
| 256 | EXPECT_GE(slotPortMappingList[i].physicalSlotId, 0); |
| 257 | EXPECT_GE(slotPortMappingList[i].portId, 0); |
| 258 | } |
| 259 | serial = GetRandomSerialNumber(); |
| 260 | ndk::ScopedAStatus res = radio_config->setSimSlotsMapping(serial, slotPortMappingList); |
| 261 | ASSERT_OK(res); |
| 262 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 263 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 264 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 265 | ALOGI("setSimSlotsMapping, rspInfo.error = %s\n", |
| 266 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 267 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error, {RadioError::NONE})); |
| 268 | |
| 269 | // Give some time for modem to fully switch SIM configuration |
| 270 | sleep(MODEM_SET_SIM_SLOT_MAPPING_DELAY_IN_SECONDS); |
| 271 | } |
sandeepjs | 3bb5000 | 2022-02-15 11:41:28 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* |
| 275 | * Test IRadioConfig.getSimSlotStatus() for the response returned. |
| 276 | */ |
| 277 | |
| 278 | TEST_P(RadioConfigTest, checkPortInfoExistsAndPortActive) { |
joonhunshin | d519aea | 2023-10-31 03:06:54 +0000 | [diff] [blame] | 279 | if (telephony_flags::enforce_telephony_feature_mapping()) { |
| 280 | if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) { |
| 281 | GTEST_SKIP() << "Skipping checkPortInfoExistsAndPortActive " |
| 282 | "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION"; |
| 283 | } |
| 284 | } |
| 285 | |
sandeepjs | 3bb5000 | 2022-02-15 11:41:28 +0000 | [diff] [blame] | 286 | serial = GetRandomSerialNumber(); |
| 287 | ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial); |
| 288 | ASSERT_OK(res); |
| 289 | ALOGI("getSimSlotsStatus, rspInfo.error = %s\n", |
| 290 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 291 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 292 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 293 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 294 | if (radioRsp_config->rspInfo.error == RadioError::NONE) { |
Tim Lin | 118816d | 2022-04-12 21:24:03 +0800 | [diff] [blame] | 295 | uint8_t simCount = 0; |
sandeepjs | 3bb5000 | 2022-02-15 11:41:28 +0000 | [diff] [blame] | 296 | // check if cardState is present, portInfo size should be more than 0 |
| 297 | for (const SimSlotStatus& slotStatusResponse : radioRsp_config->simSlotStatus) { |
| 298 | if (slotStatusResponse.cardState == CardStatus::STATE_PRESENT) { |
| 299 | ASSERT_TRUE(slotStatusResponse.portInfo.size() > 0); |
Tim Lin | 118816d | 2022-04-12 21:24:03 +0800 | [diff] [blame] | 300 | for (const SimPortInfo& simPortInfo : slotStatusResponse.portInfo) { |
| 301 | if (simPortInfo.portActive) { |
| 302 | simCount++; |
| 303 | } |
| 304 | } |
sandeepjs | 3bb5000 | 2022-02-15 11:41:28 +0000 | [diff] [blame] | 305 | } |
| 306 | } |
Tim Lin | 118816d | 2022-04-12 21:24:03 +0800 | [diff] [blame] | 307 | if (isSsSsEnabled()) { |
| 308 | EXPECT_EQ(1, simCount); |
Zhang Yuan | 2910082 | 2022-10-20 16:39:19 +0800 | [diff] [blame] | 309 | } else if (isDsDsEnabled() || isDsDaEnabled()) { |
Tim Lin | 118816d | 2022-04-12 21:24:03 +0800 | [diff] [blame] | 310 | EXPECT_EQ(2, simCount); |
| 311 | } else if (isTsTsEnabled()) { |
| 312 | EXPECT_EQ(3, simCount); |
| 313 | } |
sandeepjs | 3bb5000 | 2022-02-15 11:41:28 +0000 | [diff] [blame] | 314 | } |
| 315 | } |