blob: 62a18f1fb7d356a18efcf56b710bdfddd63e788c [file] [log] [blame]
Hunsuk Choi9d4f38c2021-12-16 21:50:04 +00001/*
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_ims_utils.h"
22
23#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
24
25void RadioImsTest::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 count_ = 0;
41
42 radioInd_ims = ndk::SharedRefBase::make<RadioImsIndication>(*this);
43 ASSERT_NE(nullptr, radioInd_ims.get());
44
45 radio_ims->setResponseFunctions(radioRsp_ims, radioInd_ims);
46
47 // Assert IRadioConfig exists before testing
48 radio_config = config::IRadioConfig::fromBinder(ndk::SpAIBinder(
49 AServiceManager_waitForService("android.hardware.radio.config.IRadioConfig/default")));
50 ASSERT_NE(nullptr, radio_config.get());
51}
52
53/*
54 * Test IRadioIms.setSrvccCallInfo() for the response returned.
55 */
56TEST_P(RadioImsTest, setSrvccCallInfo) {
57 if (!deviceSupportsFeature(FEATURE_TELEPHONY_IMS)) {
58 ALOGI("Skipping setSrvccCallInfo because ims is not supported in device");
59 return;
60 } else {
61 ALOGI("Running setSrvccCallInfo because ims is supported in device");
62 }
63
64 serial = GetRandomSerialNumber();
65
66 SrvccCall srvccCall;
67
68 ndk::ScopedAStatus res =
69 radio_ims->setSrvccCallInfo(serial, { srvccCall });
70 ASSERT_OK(res);
71 EXPECT_EQ(std::cv_status::no_timeout, wait());
72 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_ims->rspInfo.type);
73 EXPECT_EQ(serial, radioRsp_ims->rspInfo.serial);
74
75 ALOGI("setSrvccCallInfo, rspInfo.error = %s\n",
76 toString(radioRsp_ims->rspInfo.error).c_str());
77
78 verifyError(radioRsp_ims->rspInfo.error);
79}
80
81/*
82 * Test IRadioIms.updateImsRegistrationInfo() for the response returned.
83 */
84TEST_P(RadioImsTest, updateImsRegistrationInfo) {
85 if (!deviceSupportsFeature(FEATURE_TELEPHONY_IMS)) {
86 ALOGI("Skipping updateImsRegistrationInfo because ims is not supported in device");
87 return;
88 } else {
89 ALOGI("Running updateImsRegistrationInfo because ims is supported in device");
90 }
91
92 serial = GetRandomSerialNumber();
93
94 ImsRegistration regInfo;
95 regInfo.state = ImsRegistration::State::NOT_REGISTERED;
96 regInfo.ipcan = ImsRegistration::ImsAccessNetwork::NONE;
97 regInfo.reason = ImsRegistration::FailureReason::NONE;
98 regInfo.features = ImsRegistration::FEATURE_NONE;
99
100 ndk::ScopedAStatus res =
101 radio_ims->updateImsRegistrationInfo(serial, regInfo);
102 ASSERT_OK(res);
103 EXPECT_EQ(std::cv_status::no_timeout, wait());
104 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_ims->rspInfo.type);
105 EXPECT_EQ(serial, radioRsp_ims->rspInfo.serial);
106
107 ALOGI("updateImsRegistrationInfo, rspInfo.error = %s\n",
108 toString(radioRsp_ims->rspInfo.error).c_str());
109
110 verifyError(radioRsp_ims->rspInfo.error);
111}
112
113/*
114 * Test IRadioIms.notifyImsTraffic() for the response returned.
115 */
116TEST_P(RadioImsTest, notifyImsTraffic) {
117 if (!deviceSupportsFeature(FEATURE_TELEPHONY_IMS)) {
118 ALOGI("Skipping notifyImsTraffic because ims is not supported in device");
119 return;
120 } else {
121 ALOGI("Running notifyImsTraffic because ims is supported in device");
122 }
123
124 serial = GetRandomSerialNumber();
125
126 ndk::ScopedAStatus res =
127 radio_ims->notifyImsTraffic(serial, 1, ImsTrafficType::REGISTRATION, false);
128 ASSERT_OK(res);
129 EXPECT_EQ(std::cv_status::no_timeout, wait());
130 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_ims->rspInfo.type);
131 EXPECT_EQ(serial, radioRsp_ims->rspInfo.serial);
132
133 ALOGI("notifyImsTraffic, rspInfo.error = %s\n",
134 toString(radioRsp_ims->rspInfo.error).c_str());
135
136 verifyError(radioRsp_ims->rspInfo.error);
137}
138
139/*
140 * Test IRadioIms.performAcbCheck() for the response returned.
141 */
142TEST_P(RadioImsTest, performAcbCheck) {
143 if (!deviceSupportsFeature(FEATURE_TELEPHONY_IMS)) {
144 ALOGI("Skipping performAcbCheck because ims is not supported in device");
145 return;
146 } else {
147 ALOGI("Running performAcbCheck because ims is supported in device");
148 }
149
150 serial = GetRandomSerialNumber();
151
152 ndk::ScopedAStatus res =
153 radio_ims->performAcbCheck(serial, 1, ImsTrafficType::REGISTRATION);
154 ASSERT_OK(res);
155 EXPECT_EQ(std::cv_status::no_timeout, wait());
156 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_ims->rspInfo.type);
157 EXPECT_EQ(serial, radioRsp_ims->rspInfo.serial);
158
159 ALOGI("performAcbCheck, rspInfo.error = %s\n",
160 toString(radioRsp_ims->rspInfo.error).c_str());
161
162 verifyError(radioRsp_ims->rspInfo.error);
163}
164
165void RadioImsTest::verifyError(RadioError resp) {
166 switch (resp) {
167 case RadioError::NONE:
168 case RadioError::RADIO_NOT_AVAILABLE:
169 case RadioError::INVALID_STATE:
170 case RadioError::NO_MEMORY:
171 case RadioError::SYSTEM_ERR:
172 case RadioError::MODEM_ERR:
173 case RadioError::INTERNAL_ERR:
174 case RadioError::INVALID_ARGUMENTS:
175 case RadioError::REQUEST_NOT_SUPPORTED:
176 case RadioError::NO_RESOURCES:
177 SUCCEED();
178 break;
179 default:
180 FAIL();
181 break;
182 }
183}