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
17 #include <android/binder_manager.h>
18
19 #include "radio_config_utils.h"
20
21 #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
22
SetUp()23 void RadioConfigTest::SetUp() {
24 RadioServiceTest::SetUp();
25 std::string serviceName = GetParam();
26
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
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
updateSimSlotStatus()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
53 /*
54 * Test IRadioConfig.getHalDeviceCapabilities() for the response returned.
55 */
TEST_P(RadioConfigTest,getHalDeviceCapabilities)56 TEST_P(RadioConfigTest, getHalDeviceCapabilities) {
57 serial = GetRandomSerialNumber();
58 ndk::ScopedAStatus res = radio_config->getHalDeviceCapabilities(serial);
59 ASSERT_OK(res);
60 EXPECT_EQ(std::cv_status::no_timeout, wait());
61 ALOGI("getHalDeviceCapabilities, rspInfo.error = %s\n",
62 toString(radioRsp_config->rspInfo.error).c_str());
63 }
64
65 /*
66 * Test IRadioConfig.getSimSlotsStatus() for the response returned.
67 */
TEST_P(RadioConfigTest,getSimSlotsStatus)68 TEST_P(RadioConfigTest, getSimSlotsStatus) {
69 serial = GetRandomSerialNumber();
70 ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial);
71 ASSERT_OK(res);
72 EXPECT_EQ(std::cv_status::no_timeout, wait());
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 */
TEST_P(RadioConfigTest,getPhoneCapability)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 */
TEST_P(RadioConfigTest,setPreferredDataModem)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 */
TEST_P(RadioConfigTest,setPreferredDataModem_invalidArgument)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 }
164
165 /*
166 * Test IRadioConfig.setSimSlotsMapping() for the response returned.
167 */
TEST_P(RadioConfigTest,setSimSlotsMapping)168 TEST_P(RadioConfigTest, setSimSlotsMapping) {
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};
177 if (isDsDsEnabled() || isDsDaEnabled()) {
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 }
202
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 }
223 }
224
225 /*
226 * Test IRadioConfig.getSimSlotStatus() for the response returned.
227 */
228
TEST_P(RadioConfigTest,checkPortInfoExistsAndPortActive)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) {
239 uint8_t simCount = 0;
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);
244 for (const SimPortInfo& simPortInfo : slotStatusResponse.portInfo) {
245 if (simPortInfo.portActive) {
246 simCount++;
247 }
248 }
249 }
250 }
251 if (isSsSsEnabled()) {
252 EXPECT_EQ(1, simCount);
253 } else if (isDsDsEnabled() || isDsDaEnabled()) {
254 EXPECT_EQ(2, simCount);
255 } else if (isTsTsEnabled()) {
256 EXPECT_EQ(3, simCount);
257 }
258 }
259 }
260