blob: 3454f33b540dd5d71bd117a0304e274bd936c3b1 [file] [log] [blame]
Sarah Chinfc5603b2021-12-21 11:34:00 -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 <aidl/android/hardware/radio/config/IRadioConfig.h>
18#include <android-base/logging.h>
19#include <android/binder_manager.h>
20
21#include "radio_modem_utils.h"
22
23#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
24
25void RadioModemTest::SetUp() {
26 std::string serviceName = GetParam();
27
28 if (!isServiceValidForDeviceConfiguration(serviceName)) {
29 ALOGI("Skipped the test due to device configuration.");
30 GTEST_SKIP();
31 }
32
33 radio_modem = IRadioModem::fromBinder(
34 ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
35 ASSERT_NE(nullptr, radio_modem.get());
36
37 radioRsp_modem = ndk::SharedRefBase::make<RadioModemResponse>(*this);
38 ASSERT_NE(nullptr, radioRsp_modem.get());
39
40 count_ = 0;
41
42 radioInd_modem = ndk::SharedRefBase::make<RadioModemIndication>(*this);
43 ASSERT_NE(nullptr, radioInd_modem.get());
44
45 radio_modem->setResponseFunctions(radioRsp_modem, radioInd_modem);
46
Sarah Chinc83bce42021-12-29 00:35:12 -080047 // Assert IRadioSim exists and SIM is present before testing
48 radio_sim = sim::IRadioSim::fromBinder(ndk::SpAIBinder(
49 AServiceManager_waitForService("android.hardware.radio.sim.IRadioSim/slot1")));
50 ASSERT_NE(nullptr, radio_sim.get());
51 updateSimCardStatus();
52 EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState);
53
Sarah Chinfc5603b2021-12-21 11:34:00 -080054 // Assert IRadioConfig exists before testing
Sarah Chinc83bce42021-12-29 00:35:12 -080055 radio_config = config::IRadioConfig::fromBinder(ndk::SpAIBinder(
56 AServiceManager_waitForService("android.hardware.radio.config.IRadioConfig/default")));
57 ASSERT_NE(nullptr, radio_config.get());
Sarah Chinfc5603b2021-12-21 11:34:00 -080058}
59
60/*
61 * Test IRadioModem.setRadioPower() for the response returned.
62 */
63TEST_P(RadioModemTest, setRadioPower_emergencyCall_cancelled) {
64 // Set radio power to off.
65 serial = GetRandomSerialNumber();
66 radio_modem->setRadioPower(serial, false, false, false);
67 EXPECT_EQ(std::cv_status::no_timeout, wait());
68 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
69 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
70 EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error);
71
72 // Set radio power to on with forEmergencyCall being true. This should put modem to only scan
73 // emergency call bands.
74 serial = GetRandomSerialNumber();
75 radio_modem->setRadioPower(serial, true, true, true);
76 EXPECT_EQ(std::cv_status::no_timeout, wait());
77 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
78 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
79 EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error);
80
81 // Set radio power to on with forEmergencyCall being false. This should put modem in regular
82 // operation modem.
83 serial = GetRandomSerialNumber();
84 radio_modem->setRadioPower(serial, true, false, false);
85 EXPECT_EQ(std::cv_status::no_timeout, wait());
86 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
87 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
88 EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error);
89}
Sarah Chin912bdf32022-01-28 01:02:16 -080090
91/*
92 * Test IRadioModem.enableModem() for the response returned.
93 */
94TEST_P(RadioModemTest, enableModem) {
95 serial = GetRandomSerialNumber();
96
97 if (isSsSsEnabled()) {
98 ALOGI("enableModem, no need to test in single SIM mode");
99 return;
100 }
101
102 bool responseToggle = radioRsp_modem->enableModemResponseToggle;
103 ndk::ScopedAStatus res = radio_modem->enableModem(serial, true);
104 ASSERT_OK(res);
105 EXPECT_EQ(std::cv_status::no_timeout, wait());
106 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
107 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
108 ALOGI("getModemStackStatus, rspInfo.error = %s\n",
109 toString(radioRsp_modem->rspInfo.error).c_str());
110 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error,
111 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
112 RadioError::MODEM_ERR, RadioError::INVALID_STATE}));
113
114 // checking if getModemStackStatus returns true, as modem was enabled above
115 if (RadioError::NONE == radioRsp_modem->rspInfo.error) {
116 // wait until modem enabling is finished
117 while (responseToggle == radioRsp_modem->enableModemResponseToggle) {
118 sleep(1);
119 }
120 ndk::ScopedAStatus resEnabled = radio_modem->getModemStackStatus(serial);
121 ASSERT_OK(resEnabled);
122 EXPECT_EQ(std::cv_status::no_timeout, wait());
123 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
124 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
125 ALOGI("getModemStackStatus, rspInfo.error = %s\n",
126 toString(radioRsp_modem->rspInfo.error).c_str());
127 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error,
128 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE,
129 RadioError::MODEM_ERR, RadioError::INVALID_STATE}));
130 // verify that enableModem did set isEnabled correctly
131 EXPECT_EQ(true, radioRsp_modem->isModemEnabled);
132 }
133}
134
135/*
136 * Test IRadioModem.getModemStackStatus() for the response returned.
137 */
138TEST_P(RadioModemTest, getModemStackStatus) {
139 serial = GetRandomSerialNumber();
140
141 ndk::ScopedAStatus res = radio_modem->getModemStackStatus(serial);
142 ASSERT_OK(res);
143 EXPECT_EQ(std::cv_status::no_timeout, wait());
144 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
145 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
146 ALOGI("getModemStackStatus, rspInfo.error = %s\n",
147 toString(radioRsp_modem->rspInfo.error).c_str());
148 ASSERT_TRUE(CheckAnyOfErrors(
149 radioRsp_modem->rspInfo.error,
150 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::MODEM_ERR}));
151}
152
153/*
154 * Test IRadioModem.getBasebandVersion() for the response returned.
155 */
156TEST_P(RadioModemTest, getBasebandVersion) {
157 LOG(DEBUG) << "getBasebandVersion";
158 serial = GetRandomSerialNumber();
159
160 radio_modem->getBasebandVersion(serial);
161 EXPECT_EQ(std::cv_status::no_timeout, wait());
162 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
163 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
164
165 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
166 EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error);
167 }
168 LOG(DEBUG) << "getBasebandVersion finished";
169}
170
171/*
172 * Test IRadioModem.getDeviceIdentity() for the response returned.
173 */
174TEST_P(RadioModemTest, getDeviceIdentity) {
175 LOG(DEBUG) << "getDeviceIdentity";
176 serial = GetRandomSerialNumber();
177
178 radio_modem->getDeviceIdentity(serial);
179 EXPECT_EQ(std::cv_status::no_timeout, wait());
180 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
181 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
182
183 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
184 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error,
185 {RadioError::NONE, RadioError::EMPTY_RECORD}));
186 }
187 LOG(DEBUG) << "getDeviceIdentity finished";
188}
189
190/*
arunvoddud9bbd442022-11-15 08:39:26 +0000191 * Test IRadioModem.getImei() for the response returned.
192 */
193TEST_P(RadioModemTest, getImei) {
Muralidhar Reddyeb1c6172023-04-12 12:55:19 +0000194 int32_t aidl_version;
195 ndk::ScopedAStatus aidl_status = radio_modem->getInterfaceVersion(&aidl_version);
196 ASSERT_OK(aidl_status);
197 if (aidl_version < 2) {
198 ALOGI("Skipped the test since getImei is not supported on version < 2");
199 GTEST_SKIP();
200 }
arunvoddud9bbd442022-11-15 08:39:26 +0000201 LOG(DEBUG) << "getImei";
202 serial = GetRandomSerialNumber();
203
204 radio_modem->getImei(serial);
205 EXPECT_EQ(std::cv_status::no_timeout, wait());
206 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
207 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
208
209 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
210 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error,
211 {RadioError::NONE, RadioError::EMPTY_RECORD}));
212 }
213 LOG(DEBUG) << "getImei finished";
214}
215
216/*
Sarah Chin912bdf32022-01-28 01:02:16 -0800217 * Test IRadioModem.nvReadItem() for the response returned.
218 */
219TEST_P(RadioModemTest, nvReadItem) {
220 LOG(DEBUG) << "nvReadItem";
221 serial = GetRandomSerialNumber();
222
223 radio_modem->nvReadItem(serial, NvItem::LTE_BAND_ENABLE_25);
224 EXPECT_EQ(std::cv_status::no_timeout, wait());
225 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
226 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
227
228 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
229 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, {RadioError::NONE},
230 CHECK_GENERAL_ERROR));
231 }
232 LOG(DEBUG) << "nvReadItem finished";
233}
234
235/*
236 * Test IRadioModem.nvWriteItem() for the response returned.
237 */
238TEST_P(RadioModemTest, nvWriteItem) {
239 LOG(DEBUG) << "nvWriteItem";
240 serial = GetRandomSerialNumber();
241 NvWriteItem item;
242 memset(&item, 0, sizeof(item));
243 item.value = std::string();
244
245 radio_modem->nvWriteItem(serial, item);
246 EXPECT_EQ(std::cv_status::no_timeout, wait());
247 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
248 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
249
250 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
251 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, {RadioError::NONE},
252 CHECK_GENERAL_ERROR));
253 }
254 LOG(DEBUG) << "nvWriteItem finished";
255}
256
257/*
258 * Test IRadioModem.nvWriteCdmaPrl() for the response returned.
259 */
260TEST_P(RadioModemTest, nvWriteCdmaPrl) {
261 LOG(DEBUG) << "nvWriteCdmaPrl";
262 serial = GetRandomSerialNumber();
263 std::vector<uint8_t> prl = {1, 2, 3, 4, 5};
264
265 radio_modem->nvWriteCdmaPrl(serial, std::vector<uint8_t>(prl));
266 EXPECT_EQ(std::cv_status::no_timeout, wait());
267 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
268 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
269
270 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
271 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, {RadioError::NONE},
272 CHECK_GENERAL_ERROR));
273 }
274 LOG(DEBUG) << "nvWriteCdmaPrl finished";
275}
276
277/*
278 * Test IRadioModem.nvResetConfig() for the response returned.
279 */
280TEST_P(RadioModemTest, nvResetConfig) {
281 LOG(DEBUG) << "nvResetConfig";
282 serial = GetRandomSerialNumber();
283
284 radio_modem->nvResetConfig(serial, ResetNvType::FACTORY_RESET);
285 EXPECT_EQ(std::cv_status::no_timeout, wait());
286 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
287 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
288
289 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
290 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error,
291 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
292 }
293 LOG(DEBUG) << "nvResetConfig finished";
294}
295
296/*
297 * Test IRadioModem.getHardwareConfig() for the response returned.
298 */
299TEST_P(RadioModemTest, getHardwareConfig) {
300 LOG(DEBUG) << "getHardwareConfig";
301 serial = GetRandomSerialNumber();
302
303 radio_modem->getHardwareConfig(serial);
304 EXPECT_EQ(std::cv_status::no_timeout, wait());
305 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
306 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
307
308 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
309 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, {RadioError::NONE},
310 CHECK_GENERAL_ERROR));
311 }
312 LOG(DEBUG) << "getHardwareConfig finished";
313}
314
315/*
316 * The following test is disabled due to b/64734869
317 *
318 * Test IRadioModem.requestShutdown() for the response returned.
319 */
320TEST_P(RadioModemTest, DISABLED_requestShutdown) {
321 serial = GetRandomSerialNumber();
322
323 radio_modem->requestShutdown(serial);
324 EXPECT_EQ(std::cv_status::no_timeout, wait());
325 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
326 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
327
328 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
329 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error, {RadioError::NONE},
330 CHECK_GENERAL_ERROR));
331 }
332}
333
334/*
335 * Test IRadioModem.getRadioCapability() for the response returned.
336 */
337TEST_P(RadioModemTest, getRadioCapability) {
338 LOG(DEBUG) << "getRadioCapability";
339 serial = GetRandomSerialNumber();
340
341 radio_modem->getRadioCapability(serial);
342 EXPECT_EQ(std::cv_status::no_timeout, wait());
343 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
344 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
345
346 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
347 EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error);
348 }
349 LOG(DEBUG) << "getRadioCapability finished";
350}
351
352/*
353 * Test IRadioModem.setRadioCapability() for the response returned.
354 */
355TEST_P(RadioModemTest, setRadioCapability) {
356 LOG(DEBUG) << "setRadioCapability";
357 serial = GetRandomSerialNumber();
358 RadioCapability rc;
359 memset(&rc, 0, sizeof(rc));
360 rc.logicalModemUuid = std::string();
361
362 radio_modem->setRadioCapability(serial, rc);
363 EXPECT_EQ(std::cv_status::no_timeout, wait());
364 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
365 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
366
367 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
368 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error,
369 {RadioError::INVALID_ARGUMENTS, RadioError::INVALID_STATE},
370 CHECK_GENERAL_ERROR));
371 }
372 LOG(DEBUG) << "setRadioCapability finished";
373}
374
375/*
376 * Test IRadioModem.getModemActivityInfo() for the response returned.
377 */
378TEST_P(RadioModemTest, getModemActivityInfo) {
379 LOG(DEBUG) << "getModemActivityInfo";
380 serial = GetRandomSerialNumber();
381
382 radio_modem->getModemActivityInfo(serial);
383 EXPECT_EQ(std::cv_status::no_timeout, wait());
384 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
385 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
386
387 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
388 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error,
389 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
390 }
391 LOG(DEBUG) << "getModemActivityInfo finished";
392}
393
394/*
395 * Test IRadioModem.sendDeviceState() for the response returned.
396 */
397TEST_P(RadioModemTest, sendDeviceState) {
398 LOG(DEBUG) << "sendDeviceState";
399 serial = GetRandomSerialNumber();
400
401 radio_modem->sendDeviceState(serial, DeviceStateType::POWER_SAVE_MODE, true);
402 EXPECT_EQ(std::cv_status::no_timeout, wait());
403 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type);
404 EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial);
405
406 std::cout << static_cast<int>(radioRsp_modem->rspInfo.error) << std::endl;
407
408 if (cardStatus.cardState == CardStatus::STATE_ABSENT) {
409 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_modem->rspInfo.error,
410 {RadioError::NONE, RadioError::REQUEST_NOT_SUPPORTED}));
411 }
412 LOG(DEBUG) << "sendDeviceState finished";
413}