1 /*
2 * Copyright (C) 2022 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_ims_utils.h"
21
22 #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
23
SetUp()24 void RadioImsTest::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_ims = IRadioIms::fromBinder(
34 ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
35 ASSERT_NE(nullptr, radio_ims.get());
36
37 radioRsp_ims = ndk::SharedRefBase::make<RadioImsResponse>(*this);
38 ASSERT_NE(nullptr, radioRsp_ims.get());
39
40 radioInd_ims = ndk::SharedRefBase::make<RadioImsIndication>(*this);
41 ASSERT_NE(nullptr, radioInd_ims.get());
42
43 radio_ims->setResponseFunctions(radioRsp_ims, radioInd_ims);
44
45 // Assert IRadioConfig exists before testing
46 radio_config = config::IRadioConfig::fromBinder(ndk::SpAIBinder(
47 AServiceManager_waitForService("android.hardware.radio.config.IRadioConfig/default")));
48 ASSERT_NE(nullptr, radio_config.get());
49 }
50
51 /*
52 * Test IRadioIms.setSrvccCallInfo() for the response returned.
53 */
TEST_P(RadioImsTest,setSrvccCallInfo)54 TEST_P(RadioImsTest, setSrvccCallInfo) {
55 if (!deviceSupportsFeature(FEATURE_TELEPHONY_IMS)) {
56 ALOGI("Skipping setSrvccCallInfo because ims is not supported in device");
57 return;
58 } else {
59 ALOGI("Running setSrvccCallInfo because ims is supported in device");
60 }
61
62 serial = GetRandomSerialNumber();
63
64 SrvccCall srvccCall;
65
66 ndk::ScopedAStatus res =
67 radio_ims->setSrvccCallInfo(serial, { srvccCall });
68 ASSERT_OK(res);
69 EXPECT_EQ(std::cv_status::no_timeout, wait());
70 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_ims->rspInfo.type);
71 EXPECT_EQ(serial, radioRsp_ims->rspInfo.serial);
72
73 ALOGI("setSrvccCallInfo, rspInfo.error = %s\n",
74 toString(radioRsp_ims->rspInfo.error).c_str());
75
76 verifyError(radioRsp_ims->rspInfo.error);
77 }
78
79 /*
80 * Test IRadioIms.updateImsRegistrationInfo() for the response returned.
81 */
TEST_P(RadioImsTest,updateImsRegistrationInfo)82 TEST_P(RadioImsTest, updateImsRegistrationInfo) {
83 if (!deviceSupportsFeature(FEATURE_TELEPHONY_IMS)) {
84 ALOGI("Skipping updateImsRegistrationInfo because ims is not supported in device");
85 return;
86 } else {
87 ALOGI("Running updateImsRegistrationInfo because ims is supported in device");
88 }
89
90 serial = GetRandomSerialNumber();
91
92 ImsRegistration regInfo;
93 regInfo.regState = ImsRegistrationState::NOT_REGISTERED;
94 regInfo.accessNetworkType = AccessNetwork::EUTRAN;
95 regInfo.suggestedAction = SuggestedAction::NONE;
96 regInfo.capabilities = ImsRegistration::IMS_MMTEL_CAPABILITY_NONE;
97
98 ndk::ScopedAStatus res =
99 radio_ims->updateImsRegistrationInfo(serial, regInfo);
100 ASSERT_OK(res);
101 EXPECT_EQ(std::cv_status::no_timeout, wait());
102 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_ims->rspInfo.type);
103 EXPECT_EQ(serial, radioRsp_ims->rspInfo.serial);
104
105 ALOGI("updateImsRegistrationInfo, rspInfo.error = %s\n",
106 toString(radioRsp_ims->rspInfo.error).c_str());
107
108 verifyError(radioRsp_ims->rspInfo.error);
109 }
110
111 /*
112 * Test IRadioIms.startImsTraffic() for the response returned.
113 */
TEST_P(RadioImsTest,startImsTraffic)114 TEST_P(RadioImsTest, startImsTraffic) {
115 if (!deviceSupportsFeature(FEATURE_TELEPHONY_IMS)) {
116 ALOGI("Skipping startImsTraffic because ims is not supported in device");
117 return;
118 } else {
119 ALOGI("Running startImsTraffic because ims is supported in device");
120 }
121
122 serial = GetRandomSerialNumber();
123
124 ndk::ScopedAStatus res =
125 radio_ims->startImsTraffic(serial, 1,
126 ImsTrafficType::REGISTRATION, AccessNetwork::EUTRAN, ImsCall::Direction::OUTGOING);
127 ASSERT_OK(res);
128 EXPECT_EQ(std::cv_status::no_timeout, wait());
129 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_ims->rspInfo.type);
130 EXPECT_EQ(serial, radioRsp_ims->rspInfo.serial);
131
132 ALOGI("startImsTraffic, rspInfo.error = %s\n",
133 toString(radioRsp_ims->rspInfo.error).c_str());
134
135 verifyError(radioRsp_ims->rspInfo.error);
136 }
137
138 /*
139 * Test IRadioIms.stopImsTraffic() for the response returned.
140 */
TEST_P(RadioImsTest,stopImsTraffic)141 TEST_P(RadioImsTest, stopImsTraffic) {
142 if (!deviceSupportsFeature(FEATURE_TELEPHONY_IMS)) {
143 ALOGI("Skipping stopImsTraffic because ims is not supported in device");
144 return;
145 } else {
146 ALOGI("Running stopImsTraffic because ims is supported in device");
147 }
148
149 serial = GetRandomSerialNumber();
150
151 ndk::ScopedAStatus res = radio_ims->stopImsTraffic(serial, 2);
152 ASSERT_OK(res);
153 EXPECT_EQ(std::cv_status::no_timeout, wait());
154 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_ims->rspInfo.type);
155 EXPECT_EQ(serial, radioRsp_ims->rspInfo.serial);
156
157 ALOGI("stopImsTraffic, rspInfo.error = %s\n",
158 toString(radioRsp_ims->rspInfo.error).c_str());
159
160 verifyError(radioRsp_ims->rspInfo.error);
161 }
162
163 /*
164 * Test IRadioIms.triggerEpsFallback() for the response returned.
165 */
TEST_P(RadioImsTest,triggerEpsFallback)166 TEST_P(RadioImsTest, triggerEpsFallback) {
167 if (!deviceSupportsFeature(FEATURE_TELEPHONY_IMS)) {
168 ALOGI("Skipping triggerEpsFallback because ims is not supported in device");
169 return;
170 } else {
171 ALOGI("Running triggerEpsFallback because ims is supported in device");
172 }
173
174 serial = GetRandomSerialNumber();
175
176 ndk::ScopedAStatus res =
177 radio_ims->triggerEpsFallback(serial, EpsFallbackReason::NO_NETWORK_TRIGGER);
178 ASSERT_OK(res);
179 EXPECT_EQ(std::cv_status::no_timeout, wait());
180 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_ims->rspInfo.type);
181 EXPECT_EQ(serial, radioRsp_ims->rspInfo.serial);
182
183 ALOGI("triggerEpsFallback, rspInfo.error = %s\n",
184 toString(radioRsp_ims->rspInfo.error).c_str());
185
186 verifyError(radioRsp_ims->rspInfo.error);
187 }
188
189 /*
190 * Test IRadioIms.sendAnbrQuery() for the response returned.
191 */
TEST_P(RadioImsTest,sendAnbrQuery)192 TEST_P(RadioImsTest, sendAnbrQuery) {
193 if (!deviceSupportsFeature(FEATURE_TELEPHONY_IMS)) {
194 ALOGI("Skipping sendAnbrQuery because ims is not supported in device");
195 return;
196 } else {
197 ALOGI("Running sendAnbrQuery because ims is supported in device");
198 }
199
200 serial = GetRandomSerialNumber();
201
202 ndk::ScopedAStatus res =
203 radio_ims->sendAnbrQuery(serial, ImsStreamType::AUDIO, ImsStreamDirection::UPLINK, 13200);
204 ASSERT_OK(res);
205 EXPECT_EQ(std::cv_status::no_timeout, wait());
206 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_ims->rspInfo.type);
207 EXPECT_EQ(serial, radioRsp_ims->rspInfo.serial);
208
209 ALOGI("sendAnbrQuery, rspInfo.error = %s\n",
210 toString(radioRsp_ims->rspInfo.error).c_str());
211
212 verifyError(radioRsp_ims->rspInfo.error);
213 }
214
215 /*
216 * Test IRadioIms.updateImsCallStatus() for the response returned.
217 */
TEST_P(RadioImsTest,updateImsCallStatus)218 TEST_P(RadioImsTest, updateImsCallStatus) {
219 if (!deviceSupportsFeature(FEATURE_TELEPHONY_IMS)) {
220 ALOGI("Skipping updateImsCallStatus because ims is not supported in device");
221 return;
222 } else {
223 ALOGI("Running updateImsCallStatus because ims is supported in device");
224 }
225
226 serial = GetRandomSerialNumber();
227
228 ImsCall imsCall;
229
230 ndk::ScopedAStatus res =
231 radio_ims->updateImsCallStatus(serial, { imsCall });
232 ASSERT_OK(res);
233 EXPECT_EQ(std::cv_status::no_timeout, wait());
234 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_ims->rspInfo.type);
235 EXPECT_EQ(serial, radioRsp_ims->rspInfo.serial);
236
237 ALOGI("updateImsCallStatus, rspInfo.error = %s\n",
238 toString(radioRsp_ims->rspInfo.error).c_str());
239
240 verifyError(radioRsp_ims->rspInfo.error);
241 }
242
verifyError(RadioError resp)243 void RadioImsTest::verifyError(RadioError resp) {
244 switch (resp) {
245 case RadioError::NONE:
246 case RadioError::RADIO_NOT_AVAILABLE:
247 case RadioError::INVALID_STATE:
248 case RadioError::NO_MEMORY:
249 case RadioError::SYSTEM_ERR:
250 case RadioError::MODEM_ERR:
251 case RadioError::INTERNAL_ERR:
252 case RadioError::INVALID_ARGUMENTS:
253 case RadioError::NO_RESOURCES:
254 SUCCEED();
255 break;
256 default:
257 FAIL();
258 break;
259 }
260 }
261