blob: 7a0bedd3eef1355dda2d627f12ff13f930d3601a [file] [log] [blame]
Sarah Chind2a41192021-12-21 11:34:00 -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 <aidl/android/hardware/radio/config/IRadioConfig.h>
Sarah Chinc9d3b7b2021-12-23 16:41:58 -080018#include <aidl/android/hardware/radio/voice/EmergencyServiceCategory.h>
Sarah Chind2a41192021-12-21 11:34:00 -080019#include <android-base/logging.h>
20#include <android/binder_manager.h>
21
22#include "radio_voice_utils.h"
23
24#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
25
26void RadioVoiceTest::SetUp() {
27 std::string serviceName = GetParam();
28
29 if (!isServiceValidForDeviceConfiguration(serviceName)) {
30 ALOGI("Skipped the test due to device configuration.");
31 GTEST_SKIP();
32 }
33
34 radio_voice = IRadioVoice::fromBinder(
35 ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
36 ASSERT_NE(nullptr, radio_voice.get());
37
38 radioRsp_voice = ndk::SharedRefBase::make<RadioVoiceResponse>(*this);
39 ASSERT_NE(nullptr, radioRsp_voice.get());
40
41 count_ = 0;
42
43 radioInd_voice = ndk::SharedRefBase::make<RadioVoiceIndication>(*this);
44 ASSERT_NE(nullptr, radioInd_voice.get());
45
46 radio_voice->setResponseFunctions(radioRsp_voice, radioInd_voice);
47
48 // Assert IRadioConfig exists before testing
49 std::shared_ptr<aidl::android::hardware::radio::config::IRadioConfig> radioConfig =
50 aidl::android::hardware::radio::config::IRadioConfig::fromBinder(
51 ndk::SpAIBinder(AServiceManager_waitForService(
52 "android.hardware.radio.config.IRadioConfig/default")));
53 ASSERT_NE(nullptr, radioConfig.get());
54}
55
56ndk::ScopedAStatus RadioVoiceTest::clearPotentialEstablishedCalls() {
57 // Get the current call Id to hangup the established emergency call.
58 serial = GetRandomSerialNumber();
59 radio_voice->getCurrentCalls(serial);
60 EXPECT_EQ(std::cv_status::no_timeout, wait());
61
62 // Hang up to disconnect the established call channels.
63 for (const Call& call : radioRsp_voice->currentCalls) {
64 serial = GetRandomSerialNumber();
65 radio_voice->hangup(serial, call.index);
66 ALOGI("Hang up to disconnect the established call channel: %d", call.index);
67 EXPECT_EQ(std::cv_status::no_timeout, wait());
68 // Give some time for modem to disconnect the established call channel.
69 sleep(MODEM_EMERGENCY_CALL_DISCONNECT_TIME);
70 }
71
72 // Verify there are no more current calls.
73 serial = GetRandomSerialNumber();
74 radio_voice->getCurrentCalls(serial);
75 EXPECT_EQ(std::cv_status::no_timeout, wait());
76 EXPECT_EQ(0, radioRsp_voice->currentCalls.size());
77 return ndk::ScopedAStatus::ok();
78}
79
80/*
81 * Test IRadioVoice.emergencyDial() for the response returned.
82 */
83TEST_P(RadioVoiceTest, emergencyDial) {
84 if (!deviceSupportsFeature(FEATURE_VOICE_CALL)) {
85 ALOGI("Skipping emergencyDial because voice call is not supported in device");
86 return;
87 } else if (!deviceSupportsFeature(FEATURE_TELEPHONY_GSM) &&
88 !deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
89 ALOGI("Skipping emergencyDial because gsm/cdma radio is not supported in device");
90 return;
91 } else {
92 ALOGI("Running emergencyDial because voice call is supported in device");
93 }
94
95 serial = GetRandomSerialNumber();
96
97 Dial dialInfo;
98 dialInfo.address = std::string("911");
Sarah Chinc9d3b7b2021-12-23 16:41:58 -080099 int32_t categories = static_cast<int32_t>(EmergencyServiceCategory::UNSPECIFIED);
Sarah Chind2a41192021-12-21 11:34:00 -0800100 std::vector<std::string> urns = {""};
101 EmergencyCallRouting routing = EmergencyCallRouting::UNKNOWN;
102
103 ndk::ScopedAStatus res =
104 radio_voice->emergencyDial(serial, dialInfo, categories, urns, routing, true, true);
105 ASSERT_OK(res);
106 EXPECT_EQ(std::cv_status::no_timeout, wait());
107 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_voice->rspInfo.type);
108 EXPECT_EQ(serial, radioRsp_voice->rspInfo.serial);
109
110 ALOGI("emergencyDial, rspInfo.error = %s\n", toString(radioRsp_voice->rspInfo.error).c_str());
111
112 RadioError rspEmergencyDial = radioRsp_voice->rspInfo.error;
113 // In DSDS or TSTS, we only check the result if the current slot is IN_SERVICE
114 // or Emergency_Only.
115 if (isDsDsEnabled() || isTsTsEnabled()) {
116 // TODO(b/210712359): maybe create a local RadioNetwork instance
117 /**
118 serial = GetRandomSerialNumber();
119 radio_v1_6->getVoiceRegistrationState(serial);
120 EXPECT_EQ(std::cv_status::no_timeout, wait());
121 if (isVoiceEmergencyOnly(radioRsp_v1_6->voiceRegResp.regState) ||
122 isVoiceInService(radioRsp_v1_6->voiceRegResp.regState)) {
123 EXPECT_EQ(RadioError::NONE, rspEmergencyDial);
124 }
125 **/
126 } else {
127 EXPECT_EQ(RadioError::NONE, rspEmergencyDial);
128 }
129
130 // Give some time for modem to establish the emergency call channel.
131 sleep(MODEM_EMERGENCY_CALL_ESTABLISH_TIME);
132
133 // Disconnect all the potential established calls to prevent them affecting other tests.
134 clearPotentialEstablishedCalls();
135}
136
137/*
138 * Test IRadioVoice.emergencyDial() with specified service and its response returned.
139 */
140TEST_P(RadioVoiceTest, emergencyDial_withServices) {
141 if (!deviceSupportsFeature(FEATURE_VOICE_CALL)) {
142 ALOGI("Skipping emergencyDial because voice call is not supported in device");
143 return;
144 } else if (!deviceSupportsFeature(FEATURE_TELEPHONY_GSM) &&
145 !deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
146 ALOGI("Skipping emergencyDial because gsm/cdma radio is not supported in device");
147 return;
148 } else {
149 ALOGI("Running emergencyDial because voice call is supported in device");
150 }
151
152 serial = GetRandomSerialNumber();
153
154 Dial dialInfo;
155 dialInfo.address = std::string("911");
Sarah Chinc9d3b7b2021-12-23 16:41:58 -0800156 int32_t categories = static_cast<int32_t>(EmergencyServiceCategory::AMBULANCE);
Sarah Chind2a41192021-12-21 11:34:00 -0800157 std::vector<std::string> urns = {"urn:service:sos.ambulance"};
158 EmergencyCallRouting routing = EmergencyCallRouting::UNKNOWN;
159
160 ndk::ScopedAStatus res =
161 radio_voice->emergencyDial(serial, dialInfo, categories, urns, routing, true, true);
162 ASSERT_OK(res);
163 EXPECT_EQ(std::cv_status::no_timeout, wait());
164 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_voice->rspInfo.type);
165 EXPECT_EQ(serial, radioRsp_voice->rspInfo.serial);
166
167 ALOGI("emergencyDial_withServices, rspInfo.error = %s\n",
168 toString(radioRsp_voice->rspInfo.error).c_str());
169 RadioError rspEmergencyDial = radioRsp_voice->rspInfo.error;
170
171 // In DSDS or TSTS, we only check the result if the current slot is IN_SERVICE
172 // or Emergency_Only.
173 if (isDsDsEnabled() || isTsTsEnabled()) {
174 // TODO(b/210712359): maybe create a local RadioNetwork instance
175 /**
176 serial = GetRandomSerialNumber();
177 radio_v1_6->getVoiceRegistrationState_1_6(serial);
178 EXPECT_EQ(std::cv_status::no_timeout, wait());
179 if (isVoiceEmergencyOnly(radioRsp_v1_6->voiceRegResp.regState) ||
180 isVoiceInService(radioRsp_v1_6->voiceRegResp.regState)) {
181 EXPECT_EQ(RadioError::NONE, rspEmergencyDial);
182 }
183 **/
184 } else {
185 EXPECT_EQ(RadioError::NONE, rspEmergencyDial);
186 }
187 // Give some time for modem to establish the emergency call channel.
188 sleep(MODEM_EMERGENCY_CALL_ESTABLISH_TIME);
189
190 // Disconnect all the potential established calls to prevent them affecting other tests.
191 clearPotentialEstablishedCalls();
192}
193
194/*
195 * Test IRadioVoice.emergencyDial() with known emergency call routing and its response returned.
196 */
197TEST_P(RadioVoiceTest, emergencyDial_withEmergencyRouting) {
198 if (!deviceSupportsFeature(FEATURE_VOICE_CALL)) {
199 ALOGI("Skipping emergencyDial because voice call is not supported in device");
200 return;
201 } else if (!deviceSupportsFeature(FEATURE_TELEPHONY_GSM) &&
202 !deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
203 ALOGI("Skipping emergencyDial because gsm/cdma radio is not supported in device");
204 return;
205 } else {
206 ALOGI("Running emergencyDial because voice call is supported in device");
207 }
208
209 serial = GetRandomSerialNumber();
210
211 Dial dialInfo;
212 dialInfo.address = std::string("911");
Sarah Chinc9d3b7b2021-12-23 16:41:58 -0800213 int32_t categories = static_cast<int32_t>(EmergencyServiceCategory::UNSPECIFIED);
Sarah Chind2a41192021-12-21 11:34:00 -0800214 std::vector<std::string> urns = {""};
215 EmergencyCallRouting routing = EmergencyCallRouting::EMERGENCY;
216
217 ndk::ScopedAStatus res =
218 radio_voice->emergencyDial(serial, dialInfo, categories, urns, routing, true, true);
219 ASSERT_OK(res);
220 EXPECT_EQ(std::cv_status::no_timeout, wait());
221 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_voice->rspInfo.type);
222 EXPECT_EQ(serial, radioRsp_voice->rspInfo.serial);
223
224 ALOGI("emergencyDial_withEmergencyRouting, rspInfo.error = %s\n",
225 toString(radioRsp_voice->rspInfo.error).c_str());
226 RadioError rspEmergencyDial = radioRsp_voice->rspInfo.error;
227
228 // In DSDS or TSTS, we only check the result if the current slot is IN_SERVICE
229 // or Emergency_Only.
230 if (isDsDsEnabled() || isTsTsEnabled()) {
231 // TODO(b/210712359): maybe create a local RadioNetwork instance
232 /**
233 serial = GetRandomSerialNumber();
234 radio_v1_6->getVoiceRegistrationState_1_6(serial);
235 EXPECT_EQ(std::cv_status::no_timeout, wait());
236 if (isVoiceEmergencyOnly(radioRsp_v1_6->voiceRegResp.regState) ||
237 isVoiceInService(radioRsp_v1_6->voiceRegResp.regState)) {
238 EXPECT_EQ(RadioError::NONE, rspEmergencyDial);
239 }
240 **/
241 } else {
242 EXPECT_EQ(RadioError::NONE, rspEmergencyDial);
243 }
244
245 // Give some time for modem to establish the emergency call channel.
246 sleep(MODEM_EMERGENCY_CALL_ESTABLISH_TIME);
247
248 // Disconnect all the potential established calls to prevent them affecting other tests.
249 clearPotentialEstablishedCalls();
250}
251
252/*
253 * Test IRadioVoice.getCurrentCalls() for the response returned.
254 */
255TEST_P(RadioVoiceTest, getCurrentCalls) {
256 serial = GetRandomSerialNumber();
257 radio_voice->getCurrentCalls(serial);
258 EXPECT_EQ(std::cv_status::no_timeout, wait());
259 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_voice->rspInfo.type);
260 EXPECT_EQ(serial, radioRsp_voice->rspInfo.serial);
261 EXPECT_EQ(RadioError::NONE, radioRsp_voice->rspInfo.error);
262}