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