blob: a124907ad00f22f109969003b49cdb1e116b7bf8 [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
27 if (!isServiceValidForDeviceConfiguration(serviceName)) {
28 ALOGI("Skipped the test due to device configuration.");
29 GTEST_SKIP();
30 }
31
32 radio_config = IRadioConfig::fromBinder(
33 ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
34 ASSERT_NE(nullptr, radio_config.get());
35
36 radioRsp_config = ndk::SharedRefBase::make<RadioConfigResponse>(*this);
37 ASSERT_NE(nullptr, radioRsp_config.get());
38
39 count_ = 0;
40
41 radioInd_config = ndk::SharedRefBase::make<RadioConfigIndication>(*this);
42 ASSERT_NE(nullptr, radioInd_config.get());
43
44 radio_config->setResponseFunctions(radioRsp_config, radioInd_config);
45}
46
sandeepjs5561b4b2022-02-15 11:41:28 +000047void RadioConfigTest::updateSimSlotStatus() {
48 serial = GetRandomSerialNumber();
49 radio_config->getSimSlotsStatus(serial);
50 EXPECT_EQ(std::cv_status::no_timeout, wait());
51 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
52 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
53 EXPECT_EQ(RadioError::NONE, radioRsp_config->rspInfo.error);
54 // assuming only 1 slot
55 for (const SimSlotStatus& slotStatusResponse : radioRsp_config->simSlotStatus) {
56 slotStatus = slotStatusResponse;
57 }
58}
59
Sarah Chinc83bce42021-12-29 00:35:12 -080060/*
61 * Test IRadioConfig.getHalDeviceCapabilities() for the response returned.
62 */
63TEST_P(RadioConfigTest, getHalDeviceCapabilities) {
64 serial = GetRandomSerialNumber();
65 ndk::ScopedAStatus res = radio_config->getHalDeviceCapabilities(serial);
66 ASSERT_OK(res);
67 ALOGI("getHalDeviceCapabilities, rspInfo.error = %s\n",
68 toString(radioRsp_config->rspInfo.error).c_str());
69}
Sarah Chin912bdf32022-01-28 01:02:16 -080070
71/*
72 * Test IRadioConfig.getSimSlotsStatus() for the response returned.
73 */
74TEST_P(RadioConfigTest, getSimSlotsStatus) {
75 serial = GetRandomSerialNumber();
76 ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial);
77 ASSERT_OK(res);
78 ALOGI("getSimSlotsStatus, rspInfo.error = %s\n",
79 toString(radioRsp_config->rspInfo.error).c_str());
80}
81
82/*
83 * Test IRadioConfig.getPhoneCapability() for the response returned.
84 */
85TEST_P(RadioConfigTest, getPhoneCapability) {
86 serial = GetRandomSerialNumber();
87 ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial);
88 ASSERT_OK(res);
89 EXPECT_EQ(std::cv_status::no_timeout, wait());
90 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
91 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
92 ALOGI("getPhoneCapability, rspInfo.error = %s\n",
93 toString(radioRsp_config->rspInfo.error).c_str());
94
95 ASSERT_TRUE(CheckAnyOfErrors(
96 radioRsp_config->rspInfo.error,
97 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
98
99 if (radioRsp_config->rspInfo.error == RadioError ::NONE) {
100 // maxActiveData should be greater than or equal to maxActiveInternetData.
101 EXPECT_GE(radioRsp_config->phoneCap.maxActiveData,
102 radioRsp_config->phoneCap.maxActiveInternetData);
103 // maxActiveData and maxActiveInternetData should be 0 or positive numbers.
104 EXPECT_GE(radioRsp_config->phoneCap.maxActiveInternetData, 0);
105 }
106}
107
108/*
109 * Test IRadioConfig.setPreferredDataModem() for the response returned.
110 */
111TEST_P(RadioConfigTest, setPreferredDataModem) {
112 serial = GetRandomSerialNumber();
113 ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial);
114 ASSERT_OK(res);
115 EXPECT_EQ(std::cv_status::no_timeout, wait());
116 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
117 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
118 ALOGI("getPhoneCapability, rspInfo.error = %s\n",
119 toString(radioRsp_config->rspInfo.error).c_str());
120
121 ASSERT_TRUE(CheckAnyOfErrors(
122 radioRsp_config->rspInfo.error,
123 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
124
125 if (radioRsp_config->rspInfo.error != RadioError ::NONE) {
126 return;
127 }
128
129 if (radioRsp_config->phoneCap.logicalModemIds.size() == 0) {
130 return;
131 }
132
133 // We get phoneCapability. Send setPreferredDataModem command
134 serial = GetRandomSerialNumber();
135 uint8_t modemId = radioRsp_config->phoneCap.logicalModemIds[0];
136 res = radio_config->setPreferredDataModem(serial, modemId);
137
138 ASSERT_OK(res);
139 EXPECT_EQ(std::cv_status::no_timeout, wait());
140 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
141 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
142 ALOGI("setPreferredDataModem, rspInfo.error = %s\n",
143 toString(radioRsp_config->rspInfo.error).c_str());
144
145 ASSERT_TRUE(CheckAnyOfErrors(
146 radioRsp_config->rspInfo.error,
147 {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
148}
149
150/*
151 * Test IRadioConfig.setPreferredDataModem() with invalid arguments.
152 */
153TEST_P(RadioConfigTest, setPreferredDataModem_invalidArgument) {
154 serial = GetRandomSerialNumber();
155 uint8_t modemId = -1;
156 ndk::ScopedAStatus res = radio_config->setPreferredDataModem(serial, modemId);
157
158 ASSERT_OK(res);
159 EXPECT_EQ(std::cv_status::no_timeout, wait());
160 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
161 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
162 ALOGI("setPreferredDataModem, rspInfo.error = %s\n",
163 toString(radioRsp_config->rspInfo.error).c_str());
164
165 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error,
166 {RadioError::INVALID_ARGUMENTS, RadioError::RADIO_NOT_AVAILABLE,
167 RadioError::INTERNAL_ERR}));
168}
sandeepjs5561b4b2022-02-15 11:41:28 +0000169
170/*
171 * Test IRadioConfig.setSimSlotsMapping() for the response returned.
172 */
173TEST_P(RadioConfigTest, setSimSlotsMapping) {
174 serial = GetRandomSerialNumber();
175 SlotPortMapping slotPortMapping;
176 slotPortMapping.physicalSlotId = 0;
177 slotPortMapping.portId = 0;
178 std::vector<SlotPortMapping> slotPortMappingList = {slotPortMapping};
179 ndk::ScopedAStatus res = radio_config->setSimSlotsMapping(serial, slotPortMappingList);
180 ASSERT_OK(res);
181 EXPECT_EQ(std::cv_status::no_timeout, wait());
182 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
183 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
184 ALOGI("setSimSlotsMapping, rspInfo.error = %s\n",
185 toString(radioRsp_config->rspInfo.error).c_str());
186 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error, {RadioError::NONE}));
187}
188
189/*
190 * Test IRadioConfig.getSimSlotStatus() for the response returned.
191 */
192
193TEST_P(RadioConfigTest, checkPortInfoExistsAndPortActive) {
194 serial = GetRandomSerialNumber();
195 ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial);
196 ASSERT_OK(res);
197 ALOGI("getSimSlotsStatus, rspInfo.error = %s\n",
198 toString(radioRsp_config->rspInfo.error).c_str());
199 EXPECT_EQ(std::cv_status::no_timeout, wait());
200 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
201 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
202 if (radioRsp_config->rspInfo.error == RadioError::NONE) {
203 // check if cardState is present, portInfo size should be more than 0
204 for (const SimSlotStatus& slotStatusResponse : radioRsp_config->simSlotStatus) {
205 if (slotStatusResponse.cardState == CardStatus::STATE_PRESENT) {
206 ASSERT_TRUE(slotStatusResponse.portInfo.size() > 0);
207 ASSERT_TRUE(slotStatusResponse.portInfo[0].portActive);
208 }
209 }
210 }
211}