blob: 83c4de0090ffc72468275e9a1dbc9492f4dc8620 [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);
62 ALOGI("getHalDeviceCapabilities, rspInfo.error = %s\n",
63 toString(radioRsp_config->rspInfo.error).c_str());
64}
Sarah Chin52de0ad2022-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}
sandeepjs3bb50002022-02-15 11:41:28 +0000164
165/*
166 * Test IRadioConfig.setSimSlotsMapping() for the response returned.
167 */
168TEST_P(RadioConfigTest, setSimSlotsMapping) {
169 serial = GetRandomSerialNumber();
170 SlotPortMapping slotPortMapping;
171 slotPortMapping.physicalSlotId = 0;
172 slotPortMapping.portId = 0;
173 std::vector<SlotPortMapping> slotPortMappingList = {slotPortMapping};
174 ndk::ScopedAStatus res = radio_config->setSimSlotsMapping(serial, slotPortMappingList);
175 ASSERT_OK(res);
176 EXPECT_EQ(std::cv_status::no_timeout, wait());
177 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
178 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
179 ALOGI("setSimSlotsMapping, rspInfo.error = %s\n",
180 toString(radioRsp_config->rspInfo.error).c_str());
181 ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error, {RadioError::NONE}));
182}
183
184/*
185 * Test IRadioConfig.getSimSlotStatus() for the response returned.
186 */
187
188TEST_P(RadioConfigTest, checkPortInfoExistsAndPortActive) {
189 serial = GetRandomSerialNumber();
190 ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial);
191 ASSERT_OK(res);
192 ALOGI("getSimSlotsStatus, rspInfo.error = %s\n",
193 toString(radioRsp_config->rspInfo.error).c_str());
194 EXPECT_EQ(std::cv_status::no_timeout, wait());
195 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
196 EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
197 if (radioRsp_config->rspInfo.error == RadioError::NONE) {
198 // check if cardState is present, portInfo size should be more than 0
199 for (const SimSlotStatus& slotStatusResponse : radioRsp_config->simSlotStatus) {
200 if (slotStatusResponse.cardState == CardStatus::STATE_PRESENT) {
201 ASSERT_TRUE(slotStatusResponse.portInfo.size() > 0);
202 ASSERT_TRUE(slotStatusResponse.portInfo[0].portActive);
203 }
204 }
205 }
206}