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 | bb35a43 | 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) { |
| 57 | serial = GetRandomSerialNumber(); |
| 58 | ndk::ScopedAStatus res = radio_config->getHalDeviceCapabilities(serial); |
| 59 | ASSERT_OK(res); |
Tim Lin | 1483037 | 2022-04-08 22:54:48 +0800 | [diff] [blame] | 60 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
Sarah Chin | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame] | 61 | ALOGI("getHalDeviceCapabilities, rspInfo.error = %s\n", |
| 62 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 63 | } |
Sarah Chin | 52de0ad | 2022-01-28 01:02:16 -0800 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * Test IRadioConfig.getSimSlotsStatus() for the response returned. |
| 67 | */ |
| 68 | TEST_P(RadioConfigTest, getSimSlotsStatus) { |
| 69 | serial = GetRandomSerialNumber(); |
| 70 | ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial); |
| 71 | ASSERT_OK(res); |
Tim Lin | 1483037 | 2022-04-08 22:54:48 +0800 | [diff] [blame] | 72 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
Sarah Chin | 52de0ad | 2022-01-28 01:02:16 -0800 | [diff] [blame] | 73 | ALOGI("getSimSlotsStatus, rspInfo.error = %s\n", |
| 74 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 75 | } |
| 76 | |
| 77 | /* |
| 78 | * Test IRadioConfig.getPhoneCapability() for the response returned. |
| 79 | */ |
| 80 | TEST_P(RadioConfigTest, getPhoneCapability) { |
| 81 | serial = GetRandomSerialNumber(); |
| 82 | ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial); |
| 83 | ASSERT_OK(res); |
| 84 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 85 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 86 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 87 | ALOGI("getPhoneCapability, rspInfo.error = %s\n", |
| 88 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 89 | |
| 90 | ASSERT_TRUE(CheckAnyOfErrors( |
| 91 | radioRsp_config->rspInfo.error, |
| 92 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR})); |
| 93 | |
| 94 | if (radioRsp_config->rspInfo.error == RadioError ::NONE) { |
| 95 | // maxActiveData should be greater than or equal to maxActiveInternetData. |
| 96 | EXPECT_GE(radioRsp_config->phoneCap.maxActiveData, |
| 97 | radioRsp_config->phoneCap.maxActiveInternetData); |
| 98 | // maxActiveData and maxActiveInternetData should be 0 or positive numbers. |
| 99 | EXPECT_GE(radioRsp_config->phoneCap.maxActiveInternetData, 0); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * Test IRadioConfig.setPreferredDataModem() for the response returned. |
| 105 | */ |
| 106 | TEST_P(RadioConfigTest, setPreferredDataModem) { |
| 107 | serial = GetRandomSerialNumber(); |
| 108 | ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial); |
| 109 | ASSERT_OK(res); |
| 110 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 111 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 112 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 113 | ALOGI("getPhoneCapability, rspInfo.error = %s\n", |
| 114 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 115 | |
| 116 | ASSERT_TRUE(CheckAnyOfErrors( |
| 117 | radioRsp_config->rspInfo.error, |
| 118 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR})); |
| 119 | |
| 120 | if (radioRsp_config->rspInfo.error != RadioError ::NONE) { |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | if (radioRsp_config->phoneCap.logicalModemIds.size() == 0) { |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | // We get phoneCapability. Send setPreferredDataModem command |
| 129 | serial = GetRandomSerialNumber(); |
| 130 | uint8_t modemId = radioRsp_config->phoneCap.logicalModemIds[0]; |
| 131 | res = radio_config->setPreferredDataModem(serial, modemId); |
| 132 | |
| 133 | ASSERT_OK(res); |
| 134 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 135 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 136 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 137 | ALOGI("setPreferredDataModem, rspInfo.error = %s\n", |
| 138 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 139 | |
| 140 | ASSERT_TRUE(CheckAnyOfErrors( |
| 141 | radioRsp_config->rspInfo.error, |
| 142 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR})); |
| 143 | } |
| 144 | |
| 145 | /* |
| 146 | * Test IRadioConfig.setPreferredDataModem() with invalid arguments. |
| 147 | */ |
| 148 | TEST_P(RadioConfigTest, setPreferredDataModem_invalidArgument) { |
| 149 | serial = GetRandomSerialNumber(); |
| 150 | uint8_t modemId = -1; |
| 151 | ndk::ScopedAStatus res = radio_config->setPreferredDataModem(serial, modemId); |
| 152 | |
| 153 | ASSERT_OK(res); |
| 154 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 155 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 156 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 157 | ALOGI("setPreferredDataModem, rspInfo.error = %s\n", |
| 158 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 159 | |
| 160 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error, |
| 161 | {RadioError::INVALID_ARGUMENTS, RadioError::RADIO_NOT_AVAILABLE, |
| 162 | RadioError::INTERNAL_ERR})); |
| 163 | } |
sandeepjs | 3bb5000 | 2022-02-15 11:41:28 +0000 | [diff] [blame] | 164 | |
| 165 | /* |
| 166 | * Test IRadioConfig.setSimSlotsMapping() for the response returned. |
| 167 | */ |
| 168 | TEST_P(RadioConfigTest, setSimSlotsMapping) { |
Tim Lin | 1a55fff | 2022-04-07 01:25:37 +0800 | [diff] [blame] | 169 | // get slot status and set SIM slots mapping based on the result. |
| 170 | updateSimSlotStatus(); |
| 171 | if (radioRsp_config->rspInfo.error == RadioError::NONE) { |
| 172 | SlotPortMapping slotPortMapping; |
| 173 | // put invalid value at first and adjust by slotStatusResponse. |
| 174 | slotPortMapping.physicalSlotId = -1; |
| 175 | slotPortMapping.portId = -1; |
| 176 | std::vector<SlotPortMapping> slotPortMappingList = {slotPortMapping}; |
Zhang Yuan | 2910082 | 2022-10-20 16:39:19 +0800 | [diff] [blame] | 177 | if (isDsDsEnabled() || isDsDaEnabled()) { |
Tim Lin | 1a55fff | 2022-04-07 01:25:37 +0800 | [diff] [blame] | 178 | slotPortMappingList.push_back(slotPortMapping); |
| 179 | } else if (isTsTsEnabled()) { |
| 180 | slotPortMappingList.push_back(slotPortMapping); |
| 181 | slotPortMappingList.push_back(slotPortMapping); |
| 182 | } |
| 183 | for (size_t i = 0; i < radioRsp_config->simSlotStatus.size(); i++) { |
| 184 | ASSERT_TRUE(radioRsp_config->simSlotStatus[i].portInfo.size() > 0); |
| 185 | for (size_t j = 0; j < radioRsp_config->simSlotStatus[i].portInfo.size(); j++) { |
| 186 | if (radioRsp_config->simSlotStatus[i].portInfo[j].portActive) { |
| 187 | int32_t logicalSlotId = |
| 188 | radioRsp_config->simSlotStatus[i].portInfo[j].logicalSlotId; |
| 189 | // logicalSlotId should be 0 or positive numbers if the port |
| 190 | // is active. |
| 191 | EXPECT_GE(logicalSlotId, 0); |
| 192 | // logicalSlotId should be less than the maximum number of |
| 193 | // supported SIM slots. |
| 194 | EXPECT_LT(logicalSlotId, slotPortMappingList.size()); |
| 195 | if (logicalSlotId >= 0 && logicalSlotId < slotPortMappingList.size()) { |
| 196 | slotPortMappingList[logicalSlotId].physicalSlotId = i; |
| 197 | slotPortMappingList[logicalSlotId].portId = j; |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | } |
Tim Lin | fd854fe | 2022-03-31 21:06:57 +0800 | [diff] [blame] | 202 | |
Tim Lin | 1a55fff | 2022-04-07 01:25:37 +0800 | [diff] [blame] | 203 | // set SIM slots mapping |
| 204 | for (size_t i = 0; i < slotPortMappingList.size(); i++) { |
| 205 | // physicalSlotId and portId should be 0 or positive numbers for the |
| 206 | // input of setSimSlotsMapping. |
| 207 | EXPECT_GE(slotPortMappingList[i].physicalSlotId, 0); |
| 208 | EXPECT_GE(slotPortMappingList[i].portId, 0); |
| 209 | } |
| 210 | serial = GetRandomSerialNumber(); |
| 211 | ndk::ScopedAStatus res = radio_config->setSimSlotsMapping(serial, slotPortMappingList); |
| 212 | ASSERT_OK(res); |
| 213 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 214 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 215 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 216 | ALOGI("setSimSlotsMapping, rspInfo.error = %s\n", |
| 217 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 218 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error, {RadioError::NONE})); |
| 219 | |
| 220 | // Give some time for modem to fully switch SIM configuration |
| 221 | sleep(MODEM_SET_SIM_SLOT_MAPPING_DELAY_IN_SECONDS); |
| 222 | } |
sandeepjs | 3bb5000 | 2022-02-15 11:41:28 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /* |
| 226 | * Test IRadioConfig.getSimSlotStatus() for the response returned. |
| 227 | */ |
| 228 | |
| 229 | TEST_P(RadioConfigTest, checkPortInfoExistsAndPortActive) { |
| 230 | serial = GetRandomSerialNumber(); |
| 231 | ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial); |
| 232 | ASSERT_OK(res); |
| 233 | ALOGI("getSimSlotsStatus, rspInfo.error = %s\n", |
| 234 | toString(radioRsp_config->rspInfo.error).c_str()); |
| 235 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 236 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type); |
| 237 | EXPECT_EQ(serial, radioRsp_config->rspInfo.serial); |
| 238 | if (radioRsp_config->rspInfo.error == RadioError::NONE) { |
Tim Lin | 118816d | 2022-04-12 21:24:03 +0800 | [diff] [blame] | 239 | uint8_t simCount = 0; |
sandeepjs | 3bb5000 | 2022-02-15 11:41:28 +0000 | [diff] [blame] | 240 | // check if cardState is present, portInfo size should be more than 0 |
| 241 | for (const SimSlotStatus& slotStatusResponse : radioRsp_config->simSlotStatus) { |
| 242 | if (slotStatusResponse.cardState == CardStatus::STATE_PRESENT) { |
| 243 | ASSERT_TRUE(slotStatusResponse.portInfo.size() > 0); |
Tim Lin | 118816d | 2022-04-12 21:24:03 +0800 | [diff] [blame] | 244 | for (const SimPortInfo& simPortInfo : slotStatusResponse.portInfo) { |
| 245 | if (simPortInfo.portActive) { |
| 246 | simCount++; |
| 247 | } |
| 248 | } |
sandeepjs | 3bb5000 | 2022-02-15 11:41:28 +0000 | [diff] [blame] | 249 | } |
| 250 | } |
Tim Lin | 118816d | 2022-04-12 21:24:03 +0800 | [diff] [blame] | 251 | if (isSsSsEnabled()) { |
| 252 | EXPECT_EQ(1, simCount); |
Zhang Yuan | 2910082 | 2022-10-20 16:39:19 +0800 | [diff] [blame] | 253 | } else if (isDsDsEnabled() || isDsDaEnabled()) { |
Tim Lin | 118816d | 2022-04-12 21:24:03 +0800 | [diff] [blame] | 254 | EXPECT_EQ(2, simCount); |
| 255 | } else if (isTsTsEnabled()) { |
| 256 | EXPECT_EQ(3, simCount); |
| 257 | } |
sandeepjs | 3bb5000 | 2022-02-15 11:41:28 +0000 | [diff] [blame] | 258 | } |
| 259 | } |