blob: 2309f9ef7e270611f5f0b55fc4c3056cdc3b3bca [file] [log] [blame]
Sarah Chinc83bce42021-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
17#include <android-base/logging.h>
18#include <android/binder_manager.h>
19
20#include "radio_config_utils.h"
21
22#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
23
24void RadioConfigTest::SetUp() {
25 std::string serviceName = GetParam();
26
Sarah Chinc83bce42021-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
34 count_ = 0;
35
36 radioInd_config = ndk::SharedRefBase::make<RadioConfigIndication>(*this);
37 ASSERT_NE(nullptr, radioInd_config.get());
38
39 radio_config->setResponseFunctions(radioRsp_config, radioInd_config);
40}
41
sandeepjs5561b4b2022-02-15 11:41:28 +000042void RadioConfigTest::updateSimSlotStatus() {
43 serial = GetRandomSerialNumber();
44 radio_config->getSimSlotsStatus(serial);
45 EXPECT_EQ(std::cv_status::no_timeout, wait());
46 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
47 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
48 EXPECT_EQ(RadioError::NONE, radioRsp_config->rspInfo.error);
49 // assuming only 1 slot
50 for (const SimSlotStatus& slotStatusResponse : radioRsp_config->simSlotStatus) {
51 slotStatus = slotStatusResponse;
52 }
53}
54
Sarah Chinc83bce42021-12-29 00:35:12 -080055/*
56 * Test IRadioConfig.getHalDeviceCapabilities() for the response returned.
57 */
58TEST_P(RadioConfigTest, getHalDeviceCapabilities) {
59 serial = GetRandomSerialNumber();
60 ndk::ScopedAStatus res = radio_config->getHalDeviceCapabilities(serial);
61 ASSERT_OK(res);
62 ALOGI("getHalDeviceCapabilities, rspInfo.error = %s\n",
63 toString(radioRsp_config->rspInfo.error).c_str());
64}
Sarah Chin912bdf32022-01-28 01:02:16 -080065
66/*
67 * Test IRadioConfig.getSimSlotsStatus() for the response returned.
68 */
69TEST_P(RadioConfigTest, getSimSlotsStatus) {
70 serial = GetRandomSerialNumber();
71 ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial);
72 ASSERT_OK(res);
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 */
80TEST_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 */
106TEST_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 */
148TEST_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}
sandeepjs5561b4b2022-02-15 11:41:28 +0000164
165/*
166 * Test IRadioConfig.setSimSlotsMapping() for the response returned.
167 */
168TEST_P(RadioConfigTest, setSimSlotsMapping) {
Tim Linc19a0bb2022-04-07 01:25:37 +0800169 // 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()) {
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 }
Tim Lin8a6a1d32022-03-31 21:06:57 +0800202
Tim Linc19a0bb2022-04-07 01:25:37 +0800203 // 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 }
sandeepjs5561b4b2022-02-15 11:41:28 +0000223}
224
225/*
226 * Test IRadioConfig.getSimSlotStatus() for the response returned.
227 */
228
229TEST_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 // check if cardState is present, portInfo size should be more than 0
240 for (const SimSlotStatus& slotStatusResponse : radioRsp_config->simSlotStatus) {
241 if (slotStatusResponse.cardState == CardStatus::STATE_PRESENT) {
242 ASSERT_TRUE(slotStatusResponse.portInfo.size() > 0);
243 ASSERT_TRUE(slotStatusResponse.portInfo[0].portActive);
244 }
245 }
246 }
247}