Sarah Chin | d2a4119 | 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 | c9d3b7b | 2021-12-23 16:41:58 -0800 | [diff] [blame] | 17 | #include <aidl/android/hardware/radio/RadioAccessFamily.h> |
Sarah Chin | d2a4119 | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 18 | #include <aidl/android/hardware/radio/config/IRadioConfig.h> |
Sarah Chin | c9d3b7b | 2021-12-23 16:41:58 -0800 | [diff] [blame] | 19 | #include <aidl/android/hardware/radio/data/ApnTypes.h> |
Sarah Chin | d2a4119 | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 20 | #include <android-base/logging.h> |
| 21 | #include <android/binder_manager.h> |
Sarah Chin | d2a4119 | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 22 | |
| 23 | #include "radio_data_utils.h" |
| 24 | |
| 25 | #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk()) |
| 26 | |
| 27 | void RadioDataTest::SetUp() { |
| 28 | std::string serviceName = GetParam(); |
| 29 | |
| 30 | if (!isServiceValidForDeviceConfiguration(serviceName)) { |
| 31 | ALOGI("Skipped the test due to device configuration."); |
| 32 | GTEST_SKIP(); |
| 33 | } |
| 34 | |
| 35 | radio_data = IRadioData::fromBinder( |
| 36 | ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str()))); |
| 37 | ASSERT_NE(nullptr, radio_data.get()); |
| 38 | |
| 39 | radioRsp_data = ndk::SharedRefBase::make<RadioDataResponse>(*this); |
| 40 | ASSERT_NE(nullptr, radioRsp_data.get()); |
| 41 | |
| 42 | count_ = 0; |
| 43 | |
| 44 | radioInd_data = ndk::SharedRefBase::make<RadioDataIndication>(*this); |
| 45 | ASSERT_NE(nullptr, radioInd_data.get()); |
| 46 | |
| 47 | radio_data->setResponseFunctions(radioRsp_data, radioInd_data); |
| 48 | |
Sarah Chin | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame^] | 49 | // Assert IRadioSim exists and SIM is present before testing |
| 50 | radio_sim = sim::IRadioSim::fromBinder(ndk::SpAIBinder( |
| 51 | AServiceManager_waitForService("android.hardware.radio.sim.IRadioSim/slot1"))); |
| 52 | ASSERT_NE(nullptr, radio_sim.get()); |
| 53 | updateSimCardStatus(); |
| 54 | EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState); |
| 55 | |
Sarah Chin | d2a4119 | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 56 | // Assert IRadioConfig exists before testing |
Sarah Chin | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame^] | 57 | radio_config = config::IRadioConfig::fromBinder(ndk::SpAIBinder( |
| 58 | AServiceManager_waitForService("android.hardware.radio.config.IRadioConfig/default"))); |
| 59 | ASSERT_NE(nullptr, radio_config.get()); |
Sarah Chin | d2a4119 | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | ndk::ScopedAStatus RadioDataTest::getDataCallList() { |
| 63 | serial = GetRandomSerialNumber(); |
| 64 | radio_data->getDataCallList(serial); |
| 65 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 66 | return ndk::ScopedAStatus::ok(); |
| 67 | } |
| 68 | |
| 69 | /* |
| 70 | * Test IRadioData.setupDataCall() for the response returned. |
| 71 | */ |
| 72 | TEST_P(RadioDataTest, setupDataCall) { |
| 73 | serial = GetRandomSerialNumber(); |
| 74 | |
| 75 | AccessNetwork accessNetwork = AccessNetwork::EUTRAN; |
| 76 | |
| 77 | DataProfileInfo dataProfileInfo; |
| 78 | memset(&dataProfileInfo, 0, sizeof(dataProfileInfo)); |
| 79 | dataProfileInfo.profileId = DataProfileInfo::ID_DEFAULT; |
| 80 | dataProfileInfo.apn = std::string("internet"); |
| 81 | dataProfileInfo.protocol = PdpProtocolType::IP; |
| 82 | dataProfileInfo.roamingProtocol = PdpProtocolType::IP; |
| 83 | dataProfileInfo.authType = ApnAuthType::NO_PAP_NO_CHAP; |
| 84 | dataProfileInfo.user = std::string("username"); |
| 85 | dataProfileInfo.password = std::string("password"); |
| 86 | dataProfileInfo.type = DataProfileInfo::TYPE_THREE_GPP; |
| 87 | dataProfileInfo.maxConnsTime = 300; |
| 88 | dataProfileInfo.maxConns = 20; |
| 89 | dataProfileInfo.waitTime = 0; |
| 90 | dataProfileInfo.enabled = true; |
Sarah Chin | c9d3b7b | 2021-12-23 16:41:58 -0800 | [diff] [blame] | 91 | dataProfileInfo.supportedApnTypesBitmap = |
| 92 | static_cast<int32_t>(ApnTypes::IMS) | static_cast<int32_t>(ApnTypes::IA); |
| 93 | dataProfileInfo.bearerBitmap = static_cast<int32_t>(RadioAccessFamily::GPRS) | |
| 94 | static_cast<int32_t>(RadioAccessFamily::EDGE) | |
| 95 | static_cast<int32_t>(RadioAccessFamily::UMTS) | |
| 96 | static_cast<int32_t>(RadioAccessFamily::HSDPA) | |
| 97 | static_cast<int32_t>(RadioAccessFamily::HSUPA) | |
| 98 | static_cast<int32_t>(RadioAccessFamily::HSPA) | |
| 99 | static_cast<int32_t>(RadioAccessFamily::EHRPD) | |
| 100 | static_cast<int32_t>(RadioAccessFamily::LTE) | |
| 101 | static_cast<int32_t>(RadioAccessFamily::HSPAP) | |
| 102 | static_cast<int32_t>(RadioAccessFamily::IWLAN); |
Sarah Chin | d2a4119 | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 103 | dataProfileInfo.mtuV4 = 0; |
| 104 | dataProfileInfo.mtuV6 = 0; |
| 105 | dataProfileInfo.preferred = true; |
| 106 | dataProfileInfo.persistent = false; |
| 107 | |
| 108 | bool roamingAllowed = false; |
| 109 | |
| 110 | std::vector<LinkAddress> addresses = {}; |
| 111 | std::vector<std::string> dnses = {}; |
| 112 | |
| 113 | DataRequestReason reason = DataRequestReason::NORMAL; |
| 114 | SliceInfo sliceInfo; |
| 115 | bool matchAllRuleAllowed = true; |
| 116 | |
| 117 | ndk::ScopedAStatus res = |
| 118 | radio_data->setupDataCall(serial, accessNetwork, dataProfileInfo, roamingAllowed, |
| 119 | reason, addresses, dnses, -1, sliceInfo, matchAllRuleAllowed); |
| 120 | ASSERT_OK(res); |
| 121 | |
| 122 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 123 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_data->rspInfo.type); |
| 124 | EXPECT_EQ(serial, radioRsp_data->rspInfo.serial); |
| 125 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 126 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error, |
| 127 | {RadioError::SIM_ABSENT, RadioError::RADIO_NOT_AVAILABLE, |
| 128 | RadioError::OP_NOT_ALLOWED_BEFORE_REG_TO_NW})); |
| 129 | } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) { |
| 130 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error, |
| 131 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, |
| 132 | RadioError::OP_NOT_ALLOWED_BEFORE_REG_TO_NW})); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /* |
| 137 | * Test IRadioData.setupDataCall() with osAppId for the response returned. |
| 138 | */ |
| 139 | TEST_P(RadioDataTest, setupDataCall_osAppId) { |
| 140 | serial = GetRandomSerialNumber(); |
| 141 | |
| 142 | AccessNetwork accessNetwork = AccessNetwork::EUTRAN; |
| 143 | |
| 144 | TrafficDescriptor trafficDescriptor; |
| 145 | OsAppId osAppId; |
| 146 | std::string osAppIdString("osAppId"); |
Sarah Chin | c9d3b7b | 2021-12-23 16:41:58 -0800 | [diff] [blame] | 147 | std::vector<unsigned char> osAppIdVec(osAppIdString.begin(), osAppIdString.end()); |
| 148 | osAppId.osAppId = osAppIdVec; |
Sarah Chin | d2a4119 | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 149 | trafficDescriptor.osAppId = osAppId; |
| 150 | |
| 151 | DataProfileInfo dataProfileInfo; |
| 152 | memset(&dataProfileInfo, 0, sizeof(dataProfileInfo)); |
| 153 | dataProfileInfo.profileId = DataProfileInfo::ID_DEFAULT; |
| 154 | dataProfileInfo.apn = std::string("internet"); |
| 155 | dataProfileInfo.protocol = PdpProtocolType::IP; |
| 156 | dataProfileInfo.roamingProtocol = PdpProtocolType::IP; |
| 157 | dataProfileInfo.authType = ApnAuthType::NO_PAP_NO_CHAP; |
| 158 | dataProfileInfo.user = std::string("username"); |
| 159 | dataProfileInfo.password = std::string("password"); |
| 160 | dataProfileInfo.type = DataProfileInfo::TYPE_THREE_GPP; |
| 161 | dataProfileInfo.maxConnsTime = 300; |
| 162 | dataProfileInfo.maxConns = 20; |
| 163 | dataProfileInfo.waitTime = 0; |
| 164 | dataProfileInfo.enabled = true; |
Sarah Chin | c9d3b7b | 2021-12-23 16:41:58 -0800 | [diff] [blame] | 165 | dataProfileInfo.supportedApnTypesBitmap = |
| 166 | static_cast<int32_t>(ApnTypes::IMS) | static_cast<int32_t>(ApnTypes::IA); |
| 167 | dataProfileInfo.bearerBitmap = static_cast<int32_t>(RadioAccessFamily::GPRS) | |
| 168 | static_cast<int32_t>(RadioAccessFamily::EDGE) | |
| 169 | static_cast<int32_t>(RadioAccessFamily::UMTS) | |
| 170 | static_cast<int32_t>(RadioAccessFamily::HSDPA) | |
| 171 | static_cast<int32_t>(RadioAccessFamily::HSUPA) | |
| 172 | static_cast<int32_t>(RadioAccessFamily::HSPA) | |
| 173 | static_cast<int32_t>(RadioAccessFamily::EHRPD) | |
| 174 | static_cast<int32_t>(RadioAccessFamily::LTE) | |
| 175 | static_cast<int32_t>(RadioAccessFamily::HSPAP) | |
| 176 | static_cast<int32_t>(RadioAccessFamily::IWLAN); |
Sarah Chin | d2a4119 | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 177 | dataProfileInfo.mtuV4 = 0; |
| 178 | dataProfileInfo.mtuV6 = 0; |
| 179 | dataProfileInfo.preferred = true; |
| 180 | dataProfileInfo.persistent = false; |
| 181 | dataProfileInfo.trafficDescriptor = trafficDescriptor; |
| 182 | |
| 183 | bool roamingAllowed = false; |
| 184 | |
| 185 | std::vector<LinkAddress> addresses = {}; |
| 186 | std::vector<std::string> dnses = {}; |
| 187 | |
| 188 | DataRequestReason reason = DataRequestReason::NORMAL; |
| 189 | SliceInfo sliceInfo; |
| 190 | bool matchAllRuleAllowed = true; |
| 191 | |
| 192 | ndk::ScopedAStatus res = |
| 193 | radio_data->setupDataCall(serial, accessNetwork, dataProfileInfo, roamingAllowed, |
| 194 | reason, addresses, dnses, -1, sliceInfo, matchAllRuleAllowed); |
| 195 | ASSERT_OK(res); |
| 196 | |
| 197 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 198 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_data->rspInfo.type); |
| 199 | EXPECT_EQ(serial, radioRsp_data->rspInfo.serial); |
| 200 | if (cardStatus.cardState == CardStatus::STATE_ABSENT) { |
| 201 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error, |
| 202 | {RadioError::SIM_ABSENT, RadioError::RADIO_NOT_AVAILABLE, |
| 203 | RadioError::OP_NOT_ALLOWED_BEFORE_REG_TO_NW})); |
| 204 | } else if (cardStatus.cardState == CardStatus::STATE_PRESENT) { |
| 205 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error, |
| 206 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, |
| 207 | RadioError::OP_NOT_ALLOWED_BEFORE_REG_TO_NW})); |
| 208 | if (radioRsp_data->setupDataCallResult.trafficDescriptors.size() <= 0) { |
| 209 | return; |
| 210 | } |
| 211 | EXPECT_EQ(trafficDescriptor.osAppId.value().osAppId, |
| 212 | radioRsp_data->setupDataCallResult.trafficDescriptors[0].osAppId.value().osAppId); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | * Test IRadioData.getSlicingConfig() for the response returned. |
| 218 | */ |
| 219 | TEST_P(RadioDataTest, getSlicingConfig) { |
| 220 | serial = GetRandomSerialNumber(); |
| 221 | radio_data->getSlicingConfig(serial); |
| 222 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 223 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_data->rspInfo.type); |
| 224 | EXPECT_EQ(serial, radioRsp_data->rspInfo.serial); |
| 225 | if (getRadioHalCapabilities()) { |
| 226 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error, |
| 227 | {RadioError::REQUEST_NOT_SUPPORTED})); |
| 228 | } else { |
| 229 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error, |
| 230 | {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, |
| 231 | RadioError::INTERNAL_ERR, RadioError::MODEM_ERR})); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /* |
| 236 | * Test IRadioData.setDataThrottling() for the response returned. |
| 237 | */ |
| 238 | TEST_P(RadioDataTest, setDataThrottling) { |
| 239 | serial = GetRandomSerialNumber(); |
| 240 | |
| 241 | ndk::ScopedAStatus res = radio_data->setDataThrottling( |
| 242 | serial, DataThrottlingAction::THROTTLE_SECONDARY_CARRIER, 60000); |
| 243 | ASSERT_OK(res); |
| 244 | |
| 245 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 246 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_data->rspInfo.type); |
| 247 | EXPECT_EQ(serial, radioRsp_data->rspInfo.serial); |
| 248 | if (getRadioHalCapabilities()) { |
| 249 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error, |
| 250 | {RadioError::REQUEST_NOT_SUPPORTED, RadioError::NONE})); |
| 251 | } else { |
| 252 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error, |
| 253 | {RadioError::RADIO_NOT_AVAILABLE, RadioError::MODEM_ERR, |
| 254 | RadioError::NONE, RadioError::INVALID_ARGUMENTS})); |
| 255 | } |
| 256 | |
| 257 | sleep(1); |
| 258 | serial = GetRandomSerialNumber(); |
| 259 | |
| 260 | res = radio_data->setDataThrottling(serial, DataThrottlingAction::THROTTLE_ANCHOR_CARRIER, |
| 261 | 60000); |
| 262 | ASSERT_OK(res); |
| 263 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 264 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_data->rspInfo.type); |
| 265 | EXPECT_EQ(serial, radioRsp_data->rspInfo.serial); |
| 266 | if (getRadioHalCapabilities()) { |
| 267 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error, |
| 268 | {RadioError::REQUEST_NOT_SUPPORTED, RadioError::NONE})); |
| 269 | } else { |
| 270 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error, |
| 271 | {RadioError::RADIO_NOT_AVAILABLE, RadioError::MODEM_ERR, |
| 272 | RadioError::NONE, RadioError::INVALID_ARGUMENTS})); |
| 273 | } |
| 274 | |
| 275 | sleep(1); |
| 276 | serial = GetRandomSerialNumber(); |
| 277 | |
| 278 | res = radio_data->setDataThrottling(serial, DataThrottlingAction::HOLD, 60000); |
| 279 | ASSERT_OK(res); |
| 280 | |
| 281 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 282 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_data->rspInfo.type); |
| 283 | EXPECT_EQ(serial, radioRsp_data->rspInfo.serial); |
| 284 | if (getRadioHalCapabilities()) { |
| 285 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error, |
| 286 | {RadioError::REQUEST_NOT_SUPPORTED, RadioError::NONE})); |
| 287 | } else { |
| 288 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error, |
| 289 | {RadioError::RADIO_NOT_AVAILABLE, RadioError::MODEM_ERR, |
| 290 | RadioError::NONE, RadioError::INVALID_ARGUMENTS})); |
| 291 | } |
| 292 | |
| 293 | sleep(1); |
| 294 | serial = GetRandomSerialNumber(); |
| 295 | |
| 296 | res = radio_data->setDataThrottling(serial, DataThrottlingAction::NO_DATA_THROTTLING, 60000); |
| 297 | ASSERT_OK(res); |
| 298 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 299 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_data->rspInfo.type); |
| 300 | EXPECT_EQ(serial, radioRsp_data->rspInfo.serial); |
| 301 | if (getRadioHalCapabilities()) { |
| 302 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error, |
| 303 | {RadioError::REQUEST_NOT_SUPPORTED, RadioError::NONE})); |
| 304 | } else { |
| 305 | ASSERT_TRUE(CheckAnyOfErrors(radioRsp_data->rspInfo.error, |
| 306 | {RadioError::RADIO_NOT_AVAILABLE, RadioError::MODEM_ERR, |
| 307 | RadioError::NONE, RadioError::INVALID_ARGUMENTS})); |
| 308 | } |
| 309 | |
| 310 | sleep(1); |
| 311 | } |