blob: d8c0142ccd7516395326c5bbde72c8f34beba0c8 [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/*
125 * Test IRadioConfig.setPreferredDataModem() for the response returned.
126 */
127TEST_P(RadioConfigTest, setPreferredDataModem) {
joonhunshind519aea2023-10-31 03:06:54 +0000128 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 Chin52de0ad2022-01-28 01:02:16 -0800135 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 */
176TEST_P(RadioConfigTest, setPreferredDataModem_invalidArgument) {
joonhunshind519aea2023-10-31 03:06:54 +0000177 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 Chin52de0ad2022-01-28 01:02:16 -0800184 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}
sandeepjs3bb50002022-02-15 11:41:28 +0000199
200/*
201 * Test IRadioConfig.setSimSlotsMapping() for the response returned.
202 */
203TEST_P(RadioConfigTest, setSimSlotsMapping) {
joonhunshind519aea2023-10-31 03:06:54 +0000204 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 Lin1a55fff2022-04-07 01:25:37 +0800211 // 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 Yuan29100822022-10-20 16:39:19 +0800219 if (isDsDsEnabled() || isDsDaEnabled()) {
Tim Lin1a55fff2022-04-07 01:25:37 +0800220 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;
239 slotPortMappingList[logicalSlotId].portId = j;
240 }
241 }
242 }
243 }
Tim Linfd854fe2022-03-31 21:06:57 +0800244
Tim Lin1a55fff2022-04-07 01:25:37 +0800245 // set SIM slots mapping
246 for (size_t i = 0; i < slotPortMappingList.size(); i++) {
247 // physicalSlotId and portId should be 0 or positive numbers for the
248 // input of setSimSlotsMapping.
249 EXPECT_GE(slotPortMappingList[i].physicalSlotId, 0);
250 EXPECT_GE(slotPortMappingList[i].portId, 0);
251 }
252 serial = GetRandomSerialNumber();
253 ndk::ScopedAStatus res = radio_config->setSimSlotsMapping(serial, slotPortMappingList);
254 ASSERT_OK(res);
255 EXPECT_EQ(std::cv_status::no_timeout, wait());
256 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
257 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
258 ALOGI("setSimSlotsMapping, rspInfo.error = %s\n",
259 toString(radioRsp_config->rspInfo.error).c_str());
260 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error, {RadioError::NONE}));
261
262 // Give some time for modem to fully switch SIM configuration
263 sleep(MODEM_SET_SIM_SLOT_MAPPING_DELAY_IN_SECONDS);
264 }
sandeepjs3bb50002022-02-15 11:41:28 +0000265}
266
267/*
268 * Test IRadioConfig.getSimSlotStatus() for the response returned.
269 */
270
271TEST_P(RadioConfigTest, checkPortInfoExistsAndPortActive) {
joonhunshind519aea2023-10-31 03:06:54 +0000272 if (telephony_flags::enforce_telephony_feature_mapping()) {
273 if (!deviceSupportsFeature(FEATURE_TELEPHONY_SUBSCRIPTION)) {
274 GTEST_SKIP() << "Skipping checkPortInfoExistsAndPortActive "
275 "due to undefined FEATURE_TELEPHONY_SUBSCRIPTION";
276 }
277 }
278
sandeepjs3bb50002022-02-15 11:41:28 +0000279 serial = GetRandomSerialNumber();
280 ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial);
281 ASSERT_OK(res);
282 ALOGI("getSimSlotsStatus, rspInfo.error = %s\n",
283 toString(radioRsp_config->rspInfo.error).c_str());
284 EXPECT_EQ(std::cv_status::no_timeout, wait());
285 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
286 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
287 if (radioRsp_config->rspInfo.error == RadioError::NONE) {
Tim Lin118816d2022-04-12 21:24:03 +0800288 uint8_t simCount = 0;
sandeepjs3bb50002022-02-15 11:41:28 +0000289 // check if cardState is present, portInfo size should be more than 0
290 for (const SimSlotStatus& slotStatusResponse : radioRsp_config->simSlotStatus) {
291 if (slotStatusResponse.cardState == CardStatus::STATE_PRESENT) {
292 ASSERT_TRUE(slotStatusResponse.portInfo.size() > 0);
Tim Lin118816d2022-04-12 21:24:03 +0800293 for (const SimPortInfo& simPortInfo : slotStatusResponse.portInfo) {
294 if (simPortInfo.portActive) {
295 simCount++;
296 }
297 }
sandeepjs3bb50002022-02-15 11:41:28 +0000298 }
299 }
Tim Lin118816d2022-04-12 21:24:03 +0800300 if (isSsSsEnabled()) {
301 EXPECT_EQ(1, simCount);
Zhang Yuan29100822022-10-20 16:39:19 +0800302 } else if (isDsDsEnabled() || isDsDaEnabled()) {
Tim Lin118816d2022-04-12 21:24:03 +0800303 EXPECT_EQ(2, simCount);
304 } else if (isTsTsEnabled()) {
305 EXPECT_EQ(3, simCount);
306 }
sandeepjs3bb50002022-02-15 11:41:28 +0000307 }
308}