blob: 258b172918440015291eda7817d907243f3b0750 [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
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 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
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
sandeepjs3bb50002022-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 Chin91997ac2021-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);
Tim Lin14830372022-04-08 22:54:48 +080062 EXPECT_EQ(std::cv_status::no_timeout, wait());
Sarah Chin91997ac2021-12-29 00:35:12 -080063 ALOGI("getHalDeviceCapabilities, rspInfo.error = %s\n",
64 toString(radioRsp_config->rspInfo.error).c_str());
65}
Sarah Chin52de0ad2022-01-28 01:02:16 -080066
67/*
68 * Test IRadioConfig.getSimSlotsStatus() for the response returned.
69 */
70TEST_P(RadioConfigTest, getSimSlotsStatus) {
71 serial = GetRandomSerialNumber();
72 ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial);
73 ASSERT_OK(res);
Tim Lin14830372022-04-08 22:54:48 +080074 EXPECT_EQ(std::cv_status::no_timeout, wait());
Sarah Chin52de0ad2022-01-28 01:02:16 -080075 ALOGI("getSimSlotsStatus, rspInfo.error = %s\n",
76 toString(radioRsp_config->rspInfo.error).c_str());
77}
78
79/*
80 * Test IRadioConfig.getPhoneCapability() for the response returned.
81 */
82TEST_P(RadioConfigTest, getPhoneCapability) {
83 serial = GetRandomSerialNumber();
84 ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial);
85 ASSERT_OK(res);
86 EXPECT_EQ(std::cv_status::no_timeout, wait());
87 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
88 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
89 ALOGI("getPhoneCapability, rspInfo.error = %s\n",
90 toString(radioRsp_config->rspInfo.error).c_str());
91
92 ASSERT_TRUE(CheckAnyOfErrors(
93 radioRsp_config->rspInfo.error,
94 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
95
96 if (radioRsp_config->rspInfo.error == RadioError ::NONE) {
97 // maxActiveData should be greater than or equal to maxActiveInternetData.
98 EXPECT_GE(radioRsp_config->phoneCap.maxActiveData,
99 radioRsp_config->phoneCap.maxActiveInternetData);
100 // maxActiveData and maxActiveInternetData should be 0 or positive numbers.
101 EXPECT_GE(radioRsp_config->phoneCap.maxActiveInternetData, 0);
102 }
103}
104
105/*
106 * Test IRadioConfig.setPreferredDataModem() for the response returned.
107 */
108TEST_P(RadioConfigTest, setPreferredDataModem) {
109 serial = GetRandomSerialNumber();
110 ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial);
111 ASSERT_OK(res);
112 EXPECT_EQ(std::cv_status::no_timeout, wait());
113 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
114 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
115 ALOGI("getPhoneCapability, rspInfo.error = %s\n",
116 toString(radioRsp_config->rspInfo.error).c_str());
117
118 ASSERT_TRUE(CheckAnyOfErrors(
119 radioRsp_config->rspInfo.error,
120 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
121
122 if (radioRsp_config->rspInfo.error != RadioError ::NONE) {
123 return;
124 }
125
126 if (radioRsp_config->phoneCap.logicalModemIds.size() == 0) {
127 return;
128 }
129
130 // We get phoneCapability. Send setPreferredDataModem command
131 serial = GetRandomSerialNumber();
132 uint8_t modemId = radioRsp_config->phoneCap.logicalModemIds[0];
133 res = radio_config->setPreferredDataModem(serial, modemId);
134
135 ASSERT_OK(res);
136 EXPECT_EQ(std::cv_status::no_timeout, wait());
137 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
138 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
139 ALOGI("setPreferredDataModem, rspInfo.error = %s\n",
140 toString(radioRsp_config->rspInfo.error).c_str());
141
142 ASSERT_TRUE(CheckAnyOfErrors(
143 radioRsp_config->rspInfo.error,
144 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
145}
146
147/*
148 * Test IRadioConfig.setPreferredDataModem() with invalid arguments.
149 */
150TEST_P(RadioConfigTest, setPreferredDataModem_invalidArgument) {
151 serial = GetRandomSerialNumber();
152 uint8_t modemId = -1;
153 ndk::ScopedAStatus res = radio_config->setPreferredDataModem(serial, modemId);
154
155 ASSERT_OK(res);
156 EXPECT_EQ(std::cv_status::no_timeout, wait());
157 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
158 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
159 ALOGI("setPreferredDataModem, rspInfo.error = %s\n",
160 toString(radioRsp_config->rspInfo.error).c_str());
161
162 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error,
163 {RadioError::INVALID_ARGUMENTS, RadioError::RADIO_NOT_AVAILABLE,
164 RadioError::INTERNAL_ERR}));
165}
sandeepjs3bb50002022-02-15 11:41:28 +0000166
167/*
168 * Test IRadioConfig.setSimSlotsMapping() for the response returned.
169 */
170TEST_P(RadioConfigTest, setSimSlotsMapping) {
Tim Lin1a55fff2022-04-07 01:25:37 +0800171 // get slot status and set SIM slots mapping based on the result.
172 updateSimSlotStatus();
173 if (radioRsp_config->rspInfo.error == RadioError::NONE) {
174 SlotPortMapping slotPortMapping;
175 // put invalid value at first and adjust by slotStatusResponse.
176 slotPortMapping.physicalSlotId = -1;
177 slotPortMapping.portId = -1;
178 std::vector<SlotPortMapping> slotPortMappingList = {slotPortMapping};
179 if (isDsDsEnabled()) {
180 slotPortMappingList.push_back(slotPortMapping);
181 } else if (isTsTsEnabled()) {
182 slotPortMappingList.push_back(slotPortMapping);
183 slotPortMappingList.push_back(slotPortMapping);
184 }
185 for (size_t i = 0; i < radioRsp_config->simSlotStatus.size(); i++) {
186 ASSERT_TRUE(radioRsp_config->simSlotStatus[i].portInfo.size() > 0);
187 for (size_t j = 0; j < radioRsp_config->simSlotStatus[i].portInfo.size(); j++) {
188 if (radioRsp_config->simSlotStatus[i].portInfo[j].portActive) {
189 int32_t logicalSlotId =
190 radioRsp_config->simSlotStatus[i].portInfo[j].logicalSlotId;
191 // logicalSlotId should be 0 or positive numbers if the port
192 // is active.
193 EXPECT_GE(logicalSlotId, 0);
194 // logicalSlotId should be less than the maximum number of
195 // supported SIM slots.
196 EXPECT_LT(logicalSlotId, slotPortMappingList.size());
197 if (logicalSlotId >= 0 && logicalSlotId < slotPortMappingList.size()) {
198 slotPortMappingList[logicalSlotId].physicalSlotId = i;
199 slotPortMappingList[logicalSlotId].portId = j;
200 }
201 }
202 }
203 }
Tim Linfd854fe2022-03-31 21:06:57 +0800204
Tim Lin1a55fff2022-04-07 01:25:37 +0800205 // set SIM slots mapping
206 for (size_t i = 0; i < slotPortMappingList.size(); i++) {
207 // physicalSlotId and portId should be 0 or positive numbers for the
208 // input of setSimSlotsMapping.
209 EXPECT_GE(slotPortMappingList[i].physicalSlotId, 0);
210 EXPECT_GE(slotPortMappingList[i].portId, 0);
211 }
212 serial = GetRandomSerialNumber();
213 ndk::ScopedAStatus res = radio_config->setSimSlotsMapping(serial, slotPortMappingList);
214 ASSERT_OK(res);
215 EXPECT_EQ(std::cv_status::no_timeout, wait());
216 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
217 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
218 ALOGI("setSimSlotsMapping, rspInfo.error = %s\n",
219 toString(radioRsp_config->rspInfo.error).c_str());
220 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error, {RadioError::NONE}));
221
222 // Give some time for modem to fully switch SIM configuration
223 sleep(MODEM_SET_SIM_SLOT_MAPPING_DELAY_IN_SECONDS);
224 }
sandeepjs3bb50002022-02-15 11:41:28 +0000225}
226
227/*
228 * Test IRadioConfig.getSimSlotStatus() for the response returned.
229 */
230
231TEST_P(RadioConfigTest, checkPortInfoExistsAndPortActive) {
232 serial = GetRandomSerialNumber();
233 ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial);
234 ASSERT_OK(res);
235 ALOGI("getSimSlotsStatus, rspInfo.error = %s\n",
236 toString(radioRsp_config->rspInfo.error).c_str());
237 EXPECT_EQ(std::cv_status::no_timeout, wait());
238 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
239 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
240 if (radioRsp_config->rspInfo.error == RadioError::NONE) {
Tim Lin118816d2022-04-12 21:24:03 +0800241 uint8_t simCount = 0;
sandeepjs3bb50002022-02-15 11:41:28 +0000242 // check if cardState is present, portInfo size should be more than 0
243 for (const SimSlotStatus& slotStatusResponse : radioRsp_config->simSlotStatus) {
244 if (slotStatusResponse.cardState == CardStatus::STATE_PRESENT) {
245 ASSERT_TRUE(slotStatusResponse.portInfo.size() > 0);
Tim Lin118816d2022-04-12 21:24:03 +0800246 for (const SimPortInfo& simPortInfo : slotStatusResponse.portInfo) {
247 if (simPortInfo.portActive) {
248 simCount++;
249 }
250 }
sandeepjs3bb50002022-02-15 11:41:28 +0000251 }
252 }
Tim Lin118816d2022-04-12 21:24:03 +0800253 if (isSsSsEnabled()) {
254 EXPECT_EQ(1, simCount);
255 } else if (isDsDsEnabled()) {
256 EXPECT_EQ(2, simCount);
257 } else if (isTsTsEnabled()) {
258 EXPECT_EQ(3, simCount);
259 }
sandeepjs3bb50002022-02-15 11:41:28 +0000260 }
261}