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