blob: f7251367c31f7b2524b4dc445dbc67a39b3f136a [file] [log] [blame]
Sarah Chin91997ac2021-12-29 00:35:12 -08001/*
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 Chin91997ac2021-12-29 00:35:12 -080017#include <android/binder_manager.h>
18
19#include "radio_config_utils.h"
20
21#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
22
23void RadioConfigTest::SetUp() {
Sarah China1efe7a2023-05-02 21:11:41 -070024 RadioServiceTest::SetUp();
Sarah Chin91997ac2021-12-29 00:35:12 -080025 std::string serviceName = GetParam();
26
Sarah Chin91997ac2021-12-29 00:35:12 -080027 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 Chin91997ac2021-12-29 00:35:12 -080034 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
sandeepjs3bb50002022-02-15 11:41:28 +000040void 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 Chin91997ac2021-12-29 00:35:12 -080053/*
54 * Test IRadioConfig.getHalDeviceCapabilities() for the response returned.
55 */
56TEST_P(RadioConfigTest, getHalDeviceCapabilities) {
joonhunshind519aea2023-10-31 03:06:54 +000057 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 Chin91997ac2021-12-29 00:35:12 -080064 serial = GetRandomSerialNumber();
65 ndk::ScopedAStatus res = radio_config->getHalDeviceCapabilities(serial);
66 ASSERT_OK(res);
Tim Lin14830372022-04-08 22:54:48 +080067 EXPECT_EQ(std::cv_status::no_timeout, wait());
Sarah Chin91997ac2021-12-29 00:35:12 -080068 ALOGI("getHalDeviceCapabilities, rspInfo.error = %s\n",
69 toString(radioRsp_config->rspInfo.error).c_str());
70}
Sarah Chin52de0ad2022-01-28 01:02:16 -080071
72/*
73 * Test IRadioConfig.getSimSlotsStatus() for the response returned.
74 */
75TEST_P(RadioConfigTest, getSimSlotsStatus) {
joonhunshind519aea2023-10-31 03:06:54 +000076 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 Chin52de0ad2022-01-28 01:02:16 -080083 serial = GetRandomSerialNumber();
84 ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial);
85 ASSERT_OK(res);
Tim Lin14830372022-04-08 22:54:48 +080086 EXPECT_EQ(std::cv_status::no_timeout, wait());
Sarah Chin52de0ad2022-01-28 01:02:16 -080087 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 */
94TEST_P(RadioConfigTest, getPhoneCapability) {
joonhunshind519aea2023-10-31 03:06:54 +000095 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 Chin52de0ad2022-01-28 01:02:16 -0800102 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/*
Grant Menke37cc14d2023-11-29 19:28:28 -0800125 * Test IRadioConfig.getSimultaneousCallingSupport() for the response returned.
126 */
127TEST_P(RadioConfigTest, getSimultaneousCallingSupport) {
128 if (telephony_flags::enforce_telephony_feature_mapping()) {
129 if (!deviceSupportsFeature(FEATURE_TELEPHONY)) {
130 GTEST_SKIP() << "Skipping getSimultaneousCallingSupport "
131 "due to undefined FEATURE_TELEPHONY";
132 }
133 }
134
135 int32_t aidl_version;
136 ndk::ScopedAStatus aidl_status = radio_config->getInterfaceVersion(&aidl_version);
137 ASSERT_OK(aidl_status);
138 if (aidl_version < 3) {
139 ALOGI("Skipped the test since"
140 " getSimultaneousCallingSupport is not supported on version < 3.");
141 GTEST_SKIP();
142 }
143
144 serial = GetRandomSerialNumber();
145 ndk::ScopedAStatus res = radio_config->getSimultaneousCallingSupport(serial);
146 ASSERT_OK(res);
147 EXPECT_EQ(std::cv_status::no_timeout, wait());
148 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
149 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
150 ALOGI("getSimultaneousCallingSupport, rspInfo.error = %s\n",
151 toString(radioRsp_config->rspInfo.error).c_str());
152
153 ASSERT_TRUE(CheckAnyOfErrors(
154 radioRsp_config->rspInfo.error,
155 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR,
156 RadioError::MODEM_ERR, RadioError::REQUEST_NOT_SUPPORTED}));
157}
158
159/*
Sarah Chin52de0ad2022-01-28 01:02:16 -0800160 * Test IRadioConfig.setPreferredDataModem() for the response returned.
161 */
162TEST_P(RadioConfigTest, setPreferredDataModem) {
joonhunshind519aea2023-10-31 03:06:54 +0000163 if (telephony_flags::enforce_telephony_feature_mapping()) {
164 if (!deviceSupportsFeature(FEATURE_TELEPHONY_DATA)) {
165 GTEST_SKIP() << "Skipping setPreferredDataModem "
166 "due to undefined FEATURE_TELEPHONY_DATA";
167 }
168 }
169
Sarah Chin52de0ad2022-01-28 01:02:16 -0800170 serial = GetRandomSerialNumber();
171 ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial);
172 ASSERT_OK(res);
173 EXPECT_EQ(std::cv_status::no_timeout, wait());
174 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
175 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
176 ALOGI("getPhoneCapability, rspInfo.error = %s\n",
177 toString(radioRsp_config->rspInfo.error).c_str());
178
179 ASSERT_TRUE(CheckAnyOfErrors(
180 radioRsp_config->rspInfo.error,
181 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
182
183 if (radioRsp_config->rspInfo.error != RadioError ::NONE) {
184 return;
185 }
186
187 if (radioRsp_config->phoneCap.logicalModemIds.size() == 0) {
188 return;
189 }
190
191 // We get phoneCapability. Send setPreferredDataModem command
192 serial = GetRandomSerialNumber();
193 uint8_t modemId = radioRsp_config->phoneCap.logicalModemIds[0];
194 res = radio_config->setPreferredDataModem(serial, modemId);
195
196 ASSERT_OK(res);
197 EXPECT_EQ(std::cv_status::no_timeout, wait());
198 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
199 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
200 ALOGI("setPreferredDataModem, rspInfo.error = %s\n",
201 toString(radioRsp_config->rspInfo.error).c_str());
202
203 ASSERT_TRUE(CheckAnyOfErrors(
204 radioRsp_config->rspInfo.error,
205 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
206}
207
208/*
209 * Test IRadioConfig.setPreferredDataModem() with invalid arguments.
210 */
211TEST_P(RadioConfigTest, setPreferredDataModem_invalidArgument) {
joonhunshind519aea2023-10-31 03:06:54 +0000212 if (telephony_flags::enforce_telephony_feature_mapping()) {
213 if (!deviceSupportsFeature(FEATURE_TELEPHONY_DATA)) {
214 GTEST_SKIP() << "Skipping setPreferredDataModem_invalidArgument "
215 "due to undefined FEATURE_TELEPHONY_DATA";
216 }
217 }
218
Sarah Chin52de0ad2022-01-28 01:02:16 -0800219 serial = GetRandomSerialNumber();
220 uint8_t modemId = -1;
221 ndk::ScopedAStatus res = radio_config->setPreferredDataModem(serial, modemId);
222
223 ASSERT_OK(res);
224 EXPECT_EQ(std::cv_status::no_timeout, wait());
225 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
226 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
227 ALOGI("setPreferredDataModem, rspInfo.error = %s\n",
228 toString(radioRsp_config->rspInfo.error).c_str());
229
230 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error,
231 {RadioError::INVALID_ARGUMENTS, RadioError::RADIO_NOT_AVAILABLE,
232 RadioError::INTERNAL_ERR}));
233}
sandeepjs3bb50002022-02-15 11:41:28 +0000234
235/*
236 * Test IRadioConfig.setSimSlotsMapping() for the response returned.
237 */
238TEST_P(RadioConfigTest, setSimSlotsMapping) {
joonhunshind519aea2023-10-31 03:06:54 +0000239 if (telephony_flags::enforce_telephony_feature_mapping()) {
240 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
241 GTEST_SKIP() << "Skipping setSimSlotsMapping "
242 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
243 }
244 }
245
Tim Lin1a55fff2022-04-07 01:25:37 +0800246 // get slot status and set SIM slots mapping based on the result.
247 updateSimSlotStatus();
248 if (radioRsp_config->rspInfo.error == RadioError::NONE) {
249 SlotPortMapping slotPortMapping;
250 // put invalid value at first and adjust by slotStatusResponse.
251 slotPortMapping.physicalSlotId = -1;
252 slotPortMapping.portId = -1;
253 std::vector<SlotPortMapping> slotPortMappingList = {slotPortMapping};
Zhang Yuan29100822022-10-20 16:39:19 +0800254 if (isDsDsEnabled() || isDsDaEnabled()) {
Tim Lin1a55fff2022-04-07 01:25:37 +0800255 slotPortMappingList.push_back(slotPortMapping);
256 } else if (isTsTsEnabled()) {
257 slotPortMappingList.push_back(slotPortMapping);
258 slotPortMappingList.push_back(slotPortMapping);
259 }
260 for (size_t i = 0; i < radioRsp_config->simSlotStatus.size(); i++) {
261 ASSERT_TRUE(radioRsp_config->simSlotStatus[i].portInfo.size() > 0);
262 for (size_t j = 0; j < radioRsp_config->simSlotStatus[i].portInfo.size(); j++) {
263 if (radioRsp_config->simSlotStatus[i].portInfo[j].portActive) {
264 int32_t logicalSlotId =
265 radioRsp_config->simSlotStatus[i].portInfo[j].logicalSlotId;
266 // logicalSlotId should be 0 or positive numbers if the port
267 // is active.
268 EXPECT_GE(logicalSlotId, 0);
269 // logicalSlotId should be less than the maximum number of
270 // supported SIM slots.
271 EXPECT_LT(logicalSlotId, slotPortMappingList.size());
272 if (logicalSlotId >= 0 && logicalSlotId < slotPortMappingList.size()) {
273 slotPortMappingList[logicalSlotId].physicalSlotId = i;
274 slotPortMappingList[logicalSlotId].portId = j;
275 }
276 }
277 }
278 }
Tim Linfd854fe2022-03-31 21:06:57 +0800279
Tim Lin1a55fff2022-04-07 01:25:37 +0800280 // set SIM slots mapping
281 for (size_t i = 0; i < slotPortMappingList.size(); i++) {
282 // physicalSlotId and portId should be 0 or positive numbers for the
283 // input of setSimSlotsMapping.
284 EXPECT_GE(slotPortMappingList[i].physicalSlotId, 0);
285 EXPECT_GE(slotPortMappingList[i].portId, 0);
286 }
287 serial = GetRandomSerialNumber();
288 ndk::ScopedAStatus res = radio_config->setSimSlotsMapping(serial, slotPortMappingList);
289 ASSERT_OK(res);
290 EXPECT_EQ(std::cv_status::no_timeout, wait());
291 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
292 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
293 ALOGI("setSimSlotsMapping, rspInfo.error = %s\n",
294 toString(radioRsp_config->rspInfo.error).c_str());
295 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error, {RadioError::NONE}));
296
297 // Give some time for modem to fully switch SIM configuration
298 sleep(MODEM_SET_SIM_SLOT_MAPPING_DELAY_IN_SECONDS);
299 }
sandeepjs3bb50002022-02-15 11:41:28 +0000300}
301
302/*
303 * Test IRadioConfig.getSimSlotStatus() for the response returned.
304 */
305
306TEST_P(RadioConfigTest, checkPortInfoExistsAndPortActive) {
joonhunshind519aea2023-10-31 03:06:54 +0000307 if (telephony_flags::enforce_telephony_feature_mapping()) {
308 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
309 GTEST_SKIP() << "Skipping checkPortInfoExistsAndPortActive "
310 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
311 }
312 }
313
sandeepjs3bb50002022-02-15 11:41:28 +0000314 serial = GetRandomSerialNumber();
315 ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial);
316 ASSERT_OK(res);
317 ALOGI("getSimSlotsStatus, rspInfo.error = %s\n",
318 toString(radioRsp_config->rspInfo.error).c_str());
319 EXPECT_EQ(std::cv_status::no_timeout, wait());
320 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
321 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
322 if (radioRsp_config->rspInfo.error == RadioError::NONE) {
Tim Lin118816d2022-04-12 21:24:03 +0800323 uint8_t simCount = 0;
sandeepjs3bb50002022-02-15 11:41:28 +0000324 // check if cardState is present, portInfo size should be more than 0
325 for (const SimSlotStatus& slotStatusResponse : radioRsp_config->simSlotStatus) {
326 if (slotStatusResponse.cardState == CardStatus::STATE_PRESENT) {
327 ASSERT_TRUE(slotStatusResponse.portInfo.size() > 0);
Tim Lin118816d2022-04-12 21:24:03 +0800328 for (const SimPortInfo& simPortInfo : slotStatusResponse.portInfo) {
329 if (simPortInfo.portActive) {
330 simCount++;
331 }
332 }
sandeepjs3bb50002022-02-15 11:41:28 +0000333 }
334 }
Tim Lin118816d2022-04-12 21:24:03 +0800335 if (isSsSsEnabled()) {
336 EXPECT_EQ(1, simCount);
Zhang Yuan29100822022-10-20 16:39:19 +0800337 } else if (isDsDsEnabled() || isDsDaEnabled()) {
Tim Lin118816d2022-04-12 21:24:03 +0800338 EXPECT_EQ(2, simCount);
339 } else if (isTsTsEnabled()) {
340 EXPECT_EQ(3, simCount);
341 }
sandeepjs3bb50002022-02-15 11:41:28 +0000342 }
343}