blob: 717f3f0be92710653826488e88a4c4b5748b90b7 [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
Sarah Chin91997ac2021-12-29 00:35:12 -080048 // Assert IRadioSim exists and SIM is present before testing
49 radio_sim = sim::IRadioSim::fromBinder(ndk::SpAIBinder(
50 AServiceManager_waitForService("android.hardware.radio.sim.IRadioSim/slot1")));
51 ASSERT_NE(nullptr, radio_sim.get());
52 updateSimCardStatus();
53 EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState);
54
Sarah Chind2a41192021-12-21 11:34:00 -080055 // Assert IRadioConfig exists before testing
Sarah Chin91997ac2021-12-29 00:35:12 -080056 radio_config = config::IRadioConfig::fromBinder(ndk::SpAIBinder(
57 AServiceManager_waitForService("android.hardware.radio.config.IRadioConfig/default")));
58 ASSERT_NE(nullptr, radio_config.get());
59
60 if (isDsDsEnabled() || isTsTsEnabled()) {
61 radio_network = IRadioNetwork::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService(
62 "android.hardware.radio.network.IRadioNetwork/slot1")));
63 ASSERT_NE(nullptr, radio_network.get());
64 radioRsp_network = ndk::SharedRefBase::make<RadioNetworkResponse>(*this);
65 radioInd_network = ndk::SharedRefBase::make<RadioNetworkIndication>(*this);
66 radio_network->setResponseFunctions(radioRsp_network, radioInd_network);
67 }
Sarah Chind2a41192021-12-21 11:34:00 -080068}
69
70ndk::ScopedAStatus RadioVoiceTest::clearPotentialEstablishedCalls() {
71 // Get the current call Id to hangup the established emergency call.
72 serial = GetRandomSerialNumber();
73 radio_voice->getCurrentCalls(serial);
74 EXPECT_EQ(std::cv_status::no_timeout, wait());
75
76 // Hang up to disconnect the established call channels.
77 for (const Call& call : radioRsp_voice->currentCalls) {
78 serial = GetRandomSerialNumber();
79 radio_voice->hangup(serial, call.index);
80 ALOGI("Hang up to disconnect the established call channel: %d", call.index);
81 EXPECT_EQ(std::cv_status::no_timeout, wait());
82 // Give some time for modem to disconnect the established call channel.
83 sleep(MODEM_EMERGENCY_CALL_DISCONNECT_TIME);
84 }
85
86 // Verify there are no more current calls.
87 serial = GetRandomSerialNumber();
88 radio_voice->getCurrentCalls(serial);
89 EXPECT_EQ(std::cv_status::no_timeout, wait());
90 EXPECT_EQ(0, radioRsp_voice->currentCalls.size());
91 return ndk::ScopedAStatus::ok();
92}
93
94/*
95 * Test IRadioVoice.emergencyDial() for the response returned.
96 */
97TEST_P(RadioVoiceTest, emergencyDial) {
98 if (!deviceSupportsFeature(FEATURE_VOICE_CALL)) {
99 ALOGI("Skipping emergencyDial because voice call is not supported in device");
100 return;
101 } else if (!deviceSupportsFeature(FEATURE_TELEPHONY_GSM) &&
102 !deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
103 ALOGI("Skipping emergencyDial because gsm/cdma radio is not supported in device");
104 return;
105 } else {
106 ALOGI("Running emergencyDial because voice call is supported in device");
107 }
108
109 serial = GetRandomSerialNumber();
110
111 Dial dialInfo;
112 dialInfo.address = std::string("911");
Sarah Chinc9d3b7b2021-12-23 16:41:58 -0800113 int32_t categories = static_cast<int32_t>(EmergencyServiceCategory::UNSPECIFIED);
Sarah Chind2a41192021-12-21 11:34:00 -0800114 std::vector<std::string> urns = {""};
115 EmergencyCallRouting routing = EmergencyCallRouting::UNKNOWN;
116
117 ndk::ScopedAStatus res =
118 radio_voice->emergencyDial(serial, dialInfo, categories, urns, routing, true, true);
119 ASSERT_OK(res);
120 EXPECT_EQ(std::cv_status::no_timeout, wait());
121 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_voice->rspInfo.type);
122 EXPECT_EQ(serial, radioRsp_voice->rspInfo.serial);
123
124 ALOGI("emergencyDial, rspInfo.error = %s\n", toString(radioRsp_voice->rspInfo.error).c_str());
125
126 RadioError rspEmergencyDial = radioRsp_voice->rspInfo.error;
127 // In DSDS or TSTS, we only check the result if the current slot is IN_SERVICE
128 // or Emergency_Only.
129 if (isDsDsEnabled() || isTsTsEnabled()) {
Sarah Chind2a41192021-12-21 11:34:00 -0800130 serial = GetRandomSerialNumber();
Sarah Chin91997ac2021-12-29 00:35:12 -0800131 radio_network->getVoiceRegistrationState(serial);
Sarah Chind2a41192021-12-21 11:34:00 -0800132 EXPECT_EQ(std::cv_status::no_timeout, wait());
Sarah Chin91997ac2021-12-29 00:35:12 -0800133 if (isVoiceEmergencyOnly(radioRsp_network->voiceRegResp.regState) ||
134 isVoiceInService(radioRsp_network->voiceRegResp.regState)) {
Sarah Chind2a41192021-12-21 11:34:00 -0800135 EXPECT_EQ(RadioError::NONE, rspEmergencyDial);
136 }
Sarah Chind2a41192021-12-21 11:34:00 -0800137 } else {
138 EXPECT_EQ(RadioError::NONE, rspEmergencyDial);
139 }
140
141 // Give some time for modem to establish the emergency call channel.
142 sleep(MODEM_EMERGENCY_CALL_ESTABLISH_TIME);
143
144 // Disconnect all the potential established calls to prevent them affecting other tests.
145 clearPotentialEstablishedCalls();
146}
147
148/*
149 * Test IRadioVoice.emergencyDial() with specified service and its response returned.
150 */
151TEST_P(RadioVoiceTest, emergencyDial_withServices) {
152 if (!deviceSupportsFeature(FEATURE_VOICE_CALL)) {
153 ALOGI("Skipping emergencyDial because voice call is not supported in device");
154 return;
155 } else if (!deviceSupportsFeature(FEATURE_TELEPHONY_GSM) &&
156 !deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
157 ALOGI("Skipping emergencyDial because gsm/cdma radio is not supported in device");
158 return;
159 } else {
160 ALOGI("Running emergencyDial because voice call is supported in device");
161 }
162
163 serial = GetRandomSerialNumber();
164
165 Dial dialInfo;
166 dialInfo.address = std::string("911");
Sarah Chinc9d3b7b2021-12-23 16:41:58 -0800167 int32_t categories = static_cast<int32_t>(EmergencyServiceCategory::AMBULANCE);
Sarah Chind2a41192021-12-21 11:34:00 -0800168 std::vector<std::string> urns = {"urn:service:sos.ambulance"};
169 EmergencyCallRouting routing = EmergencyCallRouting::UNKNOWN;
170
171 ndk::ScopedAStatus res =
172 radio_voice->emergencyDial(serial, dialInfo, categories, urns, routing, true, true);
173 ASSERT_OK(res);
174 EXPECT_EQ(std::cv_status::no_timeout, wait());
175 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_voice->rspInfo.type);
176 EXPECT_EQ(serial, radioRsp_voice->rspInfo.serial);
177
178 ALOGI("emergencyDial_withServices, rspInfo.error = %s\n",
179 toString(radioRsp_voice->rspInfo.error).c_str());
180 RadioError rspEmergencyDial = radioRsp_voice->rspInfo.error;
181
182 // In DSDS or TSTS, we only check the result if the current slot is IN_SERVICE
183 // or Emergency_Only.
184 if (isDsDsEnabled() || isTsTsEnabled()) {
Sarah Chind2a41192021-12-21 11:34:00 -0800185 serial = GetRandomSerialNumber();
Sarah Chin91997ac2021-12-29 00:35:12 -0800186 radio_network->getVoiceRegistrationState(serial);
Sarah Chind2a41192021-12-21 11:34:00 -0800187 EXPECT_EQ(std::cv_status::no_timeout, wait());
Sarah Chin91997ac2021-12-29 00:35:12 -0800188 if (isVoiceEmergencyOnly(radioRsp_network->voiceRegResp.regState) ||
189 isVoiceInService(radioRsp_network->voiceRegResp.regState)) {
Sarah Chind2a41192021-12-21 11:34:00 -0800190 EXPECT_EQ(RadioError::NONE, rspEmergencyDial);
191 }
Sarah Chind2a41192021-12-21 11:34:00 -0800192 } else {
193 EXPECT_EQ(RadioError::NONE, rspEmergencyDial);
194 }
195 // Give some time for modem to establish the emergency call channel.
196 sleep(MODEM_EMERGENCY_CALL_ESTABLISH_TIME);
197
198 // Disconnect all the potential established calls to prevent them affecting other tests.
199 clearPotentialEstablishedCalls();
200}
201
202/*
203 * Test IRadioVoice.emergencyDial() with known emergency call routing and its response returned.
204 */
205TEST_P(RadioVoiceTest, emergencyDial_withEmergencyRouting) {
206 if (!deviceSupportsFeature(FEATURE_VOICE_CALL)) {
207 ALOGI("Skipping emergencyDial because voice call is not supported in device");
208 return;
209 } else if (!deviceSupportsFeature(FEATURE_TELEPHONY_GSM) &&
210 !deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) {
211 ALOGI("Skipping emergencyDial because gsm/cdma radio is not supported in device");
212 return;
213 } else {
214 ALOGI("Running emergencyDial because voice call is supported in device");
215 }
216
217 serial = GetRandomSerialNumber();
218
219 Dial dialInfo;
220 dialInfo.address = std::string("911");
Sarah Chinc9d3b7b2021-12-23 16:41:58 -0800221 int32_t categories = static_cast<int32_t>(EmergencyServiceCategory::UNSPECIFIED);
Sarah Chind2a41192021-12-21 11:34:00 -0800222 std::vector<std::string> urns = {""};
223 EmergencyCallRouting routing = EmergencyCallRouting::EMERGENCY;
224
225 ndk::ScopedAStatus res =
226 radio_voice->emergencyDial(serial, dialInfo, categories, urns, routing, true, true);
227 ASSERT_OK(res);
228 EXPECT_EQ(std::cv_status::no_timeout, wait());
229 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_voice->rspInfo.type);
230 EXPECT_EQ(serial, radioRsp_voice->rspInfo.serial);
231
232 ALOGI("emergencyDial_withEmergencyRouting, rspInfo.error = %s\n",
233 toString(radioRsp_voice->rspInfo.error).c_str());
234 RadioError rspEmergencyDial = radioRsp_voice->rspInfo.error;
235
236 // In DSDS or TSTS, we only check the result if the current slot is IN_SERVICE
237 // or Emergency_Only.
238 if (isDsDsEnabled() || isTsTsEnabled()) {
Sarah Chind2a41192021-12-21 11:34:00 -0800239 serial = GetRandomSerialNumber();
Sarah Chin91997ac2021-12-29 00:35:12 -0800240 radio_network->getVoiceRegistrationState(serial);
Sarah Chind2a41192021-12-21 11:34:00 -0800241 EXPECT_EQ(std::cv_status::no_timeout, wait());
Sarah Chin91997ac2021-12-29 00:35:12 -0800242 if (isVoiceEmergencyOnly(radioRsp_network->voiceRegResp.regState) ||
243 isVoiceInService(radioRsp_network->voiceRegResp.regState)) {
Sarah Chind2a41192021-12-21 11:34:00 -0800244 EXPECT_EQ(RadioError::NONE, rspEmergencyDial);
245 }
Sarah Chind2a41192021-12-21 11:34:00 -0800246 } else {
247 EXPECT_EQ(RadioError::NONE, rspEmergencyDial);
248 }
249
250 // Give some time for modem to establish the emergency call channel.
251 sleep(MODEM_EMERGENCY_CALL_ESTABLISH_TIME);
252
253 // Disconnect all the potential established calls to prevent them affecting other tests.
254 clearPotentialEstablishedCalls();
255}
256
257/*
258 * Test IRadioVoice.getCurrentCalls() for the response returned.
259 */
260TEST_P(RadioVoiceTest, getCurrentCalls) {
261 serial = GetRandomSerialNumber();
262 radio_voice->getCurrentCalls(serial);
263 EXPECT_EQ(std::cv_status::no_timeout, wait());
264 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_voice->rspInfo.type);
265 EXPECT_EQ(serial, radioRsp_voice->rspInfo.serial);
266 EXPECT_EQ(RadioError::NONE, radioRsp_voice->rspInfo.error);
267}