1 /*
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 <libradiocompat/RadioVoice.h>
18 
19 #include "commonStructs.h"
20 #include "debug.h"
21 #include "structs.h"
22 
23 #include "collections.h"
24 
25 #define RADIO_MODULE "Voice"
26 
27 namespace android::hardware::radio::compat {
28 
29 using ::ndk::ScopedAStatus;
30 namespace aidl = ::aidl::android::hardware::radio::voice;
31 constexpr auto ok = &ScopedAStatus::ok;
32 
respond()33 std::shared_ptr<aidl::IRadioVoiceResponse> RadioVoice::respond() {
34     return mCallbackManager->response().voiceCb();
35 }
36 
acceptCall(int32_t serial)37 ScopedAStatus RadioVoice::acceptCall(int32_t serial) {
38     LOG_CALL << serial;
39     mHal1_5->acceptCall(serial);
40     return ok();
41 }
42 
cancelPendingUssd(int32_t serial)43 ScopedAStatus RadioVoice::cancelPendingUssd(int32_t serial) {
44     LOG_CALL << serial;
45     mHal1_5->cancelPendingUssd(serial);
46     return ok();
47 }
48 
conference(int32_t serial)49 ScopedAStatus RadioVoice::conference(int32_t serial) {
50     LOG_CALL << serial;
51     mHal1_5->conference(serial);
52     return ok();
53 }
54 
dial(int32_t serial,const aidl::Dial & dialInfo)55 ScopedAStatus RadioVoice::dial(int32_t serial, const aidl::Dial& dialInfo) {
56     LOG_CALL << serial;
57     mHal1_5->dial(serial, toHidl(dialInfo));
58     return ok();
59 }
60 
emergencyDial(int32_t serial,const aidl::Dial & info,int32_t categories,const std::vector<std::string> & urns,aidl::EmergencyCallRouting routing,bool knownUserIntentEmerg,bool isTesting)61 ScopedAStatus RadioVoice::emergencyDial(  //
62         int32_t serial, const aidl::Dial& info, int32_t categories,
63         const std::vector<std::string>& urns, aidl::EmergencyCallRouting routing,
64         bool knownUserIntentEmerg, bool isTesting) {
65     LOG_CALL << serial;
66     if (mHal1_6) {
67         mHal1_6->emergencyDial_1_6(  //
68                 serial, toHidl(info), toHidlBitfield<V1_4::EmergencyServiceCategory>(categories),
69                 toHidl(urns), V1_4::EmergencyCallRouting(routing), knownUserIntentEmerg, isTesting);
70     } else {
71         mHal1_5->emergencyDial(  //
72                 serial, toHidl(info), toHidlBitfield<V1_4::EmergencyServiceCategory>(categories),
73                 toHidl(urns), V1_4::EmergencyCallRouting(routing), knownUserIntentEmerg, isTesting);
74     }
75     return ok();
76 }
77 
exitEmergencyCallbackMode(int32_t serial)78 ScopedAStatus RadioVoice::exitEmergencyCallbackMode(int32_t serial) {
79     LOG_CALL << serial;
80     mHal1_5->exitEmergencyCallbackMode(serial);
81     return ok();
82 }
83 
explicitCallTransfer(int32_t serial)84 ScopedAStatus RadioVoice::explicitCallTransfer(int32_t serial) {
85     LOG_CALL << serial;
86     mHal1_5->explicitCallTransfer(serial);
87     return ok();
88 }
89 
getCallForwardStatus(int32_t serial,const aidl::CallForwardInfo & callInfo)90 ScopedAStatus RadioVoice::getCallForwardStatus(int32_t serial,
91                                                const aidl::CallForwardInfo& callInfo) {
92     LOG_CALL << serial;
93     mHal1_5->getCallForwardStatus(serial, toHidl(callInfo));
94     return ok();
95 }
96 
getCallWaiting(int32_t serial,int32_t serviceClass)97 ScopedAStatus RadioVoice::getCallWaiting(int32_t serial, int32_t serviceClass) {
98     LOG_CALL << serial;
99     mHal1_5->getCallWaiting(serial, serviceClass);
100     return ok();
101 }
102 
getClip(int32_t serial)103 ScopedAStatus RadioVoice::getClip(int32_t serial) {
104     LOG_CALL << serial;
105     mHal1_5->getClip(serial);
106     return ok();
107 }
108 
getClir(int32_t serial)109 ScopedAStatus RadioVoice::getClir(int32_t serial) {
110     LOG_CALL << serial;
111     mHal1_5->getClir(serial);
112     return ok();
113 }
114 
getCurrentCalls(int32_t serial)115 ScopedAStatus RadioVoice::getCurrentCalls(int32_t serial) {
116     LOG_CALL << serial;
117     if (mHal1_6) {
118         mHal1_6->getCurrentCalls_1_6(serial);
119     } else {
120         mHal1_5->getCurrentCalls(serial);
121     }
122     return ok();
123 }
124 
getLastCallFailCause(int32_t serial)125 ScopedAStatus RadioVoice::getLastCallFailCause(int32_t serial) {
126     LOG_CALL << serial;
127     mHal1_5->getLastCallFailCause(serial);
128     return ok();
129 }
130 
getMute(int32_t serial)131 ScopedAStatus RadioVoice::getMute(int32_t serial) {
132     LOG_CALL << serial;
133     mHal1_5->getMute(serial);
134     return ok();
135 }
136 
getPreferredVoicePrivacy(int32_t serial)137 ScopedAStatus RadioVoice::getPreferredVoicePrivacy(int32_t serial) {
138     LOG_CALL << serial;
139     mHal1_5->getPreferredVoicePrivacy(serial);
140     return ok();
141 }
142 
getTtyMode(int32_t serial)143 ScopedAStatus RadioVoice::getTtyMode(int32_t serial) {
144     LOG_CALL << serial;
145     mHal1_5->getTTYMode(serial);
146     return ok();
147 }
148 
handleStkCallSetupRequestFromSim(int32_t serial,bool accept)149 ScopedAStatus RadioVoice::handleStkCallSetupRequestFromSim(int32_t serial, bool accept) {
150     LOG_CALL << serial;
151     mHal1_5->handleStkCallSetupRequestFromSim(serial, accept);
152     return ok();
153 }
154 
hangup(int32_t serial,int32_t gsmIndex)155 ScopedAStatus RadioVoice::hangup(int32_t serial, int32_t gsmIndex) {
156     LOG_CALL << serial;
157     mHal1_5->hangup(serial, gsmIndex);
158     return ok();
159 }
160 
hangupForegroundResumeBackground(int32_t serial)161 ScopedAStatus RadioVoice::hangupForegroundResumeBackground(int32_t serial) {
162     LOG_CALL << serial;
163     mHal1_5->hangupForegroundResumeBackground(serial);
164     return ok();
165 }
166 
hangupWaitingOrBackground(int32_t serial)167 ScopedAStatus RadioVoice::hangupWaitingOrBackground(int32_t serial) {
168     LOG_CALL << serial;
169     mHal1_5->hangupWaitingOrBackground(serial);
170     return ok();
171 }
172 
isVoNrEnabled(int32_t serial)173 ScopedAStatus RadioVoice::isVoNrEnabled(int32_t serial) {
174     LOG_CALL << serial;
175     respond()->isVoNrEnabledResponse(notSupported(serial), false);
176     return ok();
177 }
178 
rejectCall(int32_t serial)179 ScopedAStatus RadioVoice::rejectCall(int32_t serial) {
180     LOG_CALL << serial;
181     mHal1_5->rejectCall(serial);
182     return ok();
183 }
184 
responseAcknowledgement()185 ScopedAStatus RadioVoice::responseAcknowledgement() {
186     LOG_CALL;
187     mHal1_5->responseAcknowledgement();
188     return ok();
189 }
190 
sendBurstDtmf(int32_t serial,const std::string & dtmf,int32_t on,int32_t off)191 ScopedAStatus RadioVoice::sendBurstDtmf(int32_t serial, const std::string& dtmf, int32_t on,
192                                         int32_t off) {
193     LOG_CALL << serial;
194     mHal1_5->sendBurstDtmf(serial, dtmf, on, off);
195     return ok();
196 }
197 
sendCdmaFeatureCode(int32_t serial,const std::string & featureCode)198 ScopedAStatus RadioVoice::sendCdmaFeatureCode(int32_t serial, const std::string& featureCode) {
199     LOG_CALL << serial;
200     mHal1_5->sendCDMAFeatureCode(serial, featureCode);
201     return ok();
202 }
203 
sendDtmf(int32_t serial,const std::string & s)204 ScopedAStatus RadioVoice::sendDtmf(int32_t serial, const std::string& s) {
205     LOG_CALL << serial;
206     mHal1_5->sendDtmf(serial, s);
207     return ok();
208 }
209 
sendUssd(int32_t serial,const std::string & ussd)210 ScopedAStatus RadioVoice::sendUssd(int32_t serial, const std::string& ussd) {
211     LOG_CALL << serial << ' ' << ussd;
212     mHal1_5->sendUssd(serial, ussd);
213     return ok();
214 }
215 
separateConnection(int32_t serial,int32_t gsmIndex)216 ScopedAStatus RadioVoice::separateConnection(int32_t serial, int32_t gsmIndex) {
217     LOG_CALL << serial;
218     mHal1_5->separateConnection(serial, gsmIndex);
219     return ok();
220 }
221 
setCallForward(int32_t serial,const aidl::CallForwardInfo & callInfo)222 ScopedAStatus RadioVoice::setCallForward(int32_t serial, const aidl::CallForwardInfo& callInfo) {
223     LOG_CALL << serial;
224     mHal1_5->setCallForward(serial, toHidl(callInfo));
225     return ok();
226 }
227 
setCallWaiting(int32_t serial,bool enable,int32_t serviceClass)228 ScopedAStatus RadioVoice::setCallWaiting(int32_t serial, bool enable, int32_t serviceClass) {
229     LOG_CALL << serial;
230     mHal1_5->setCallWaiting(serial, enable, serviceClass);
231     return ok();
232 }
233 
setClir(int32_t serial,int32_t status)234 ScopedAStatus RadioVoice::setClir(int32_t serial, int32_t status) {
235     LOG_CALL << serial;
236     mHal1_5->setClir(serial, status);
237     return ok();
238 }
239 
setMute(int32_t serial,bool enable)240 ScopedAStatus RadioVoice::setMute(int32_t serial, bool enable) {
241     LOG_CALL << serial;
242     mHal1_5->setMute(serial, enable);
243     return ok();
244 }
245 
setPreferredVoicePrivacy(int32_t serial,bool enable)246 ScopedAStatus RadioVoice::setPreferredVoicePrivacy(int32_t serial, bool enable) {
247     LOG_CALL << serial;
248     mHal1_5->setPreferredVoicePrivacy(serial, enable);
249     return ok();
250 }
251 
setResponseFunctions(const std::shared_ptr<aidl::IRadioVoiceResponse> & response,const std::shared_ptr<aidl::IRadioVoiceIndication> & indication)252 ScopedAStatus RadioVoice::setResponseFunctions(
253         const std::shared_ptr<aidl::IRadioVoiceResponse>& response,
254         const std::shared_ptr<aidl::IRadioVoiceIndication>& indication) {
255     LOG_CALL << response << ' ' << indication;
256     mCallbackManager->setResponseFunctions(response, indication);
257     return ok();
258 }
259 
setTtyMode(int32_t serial,aidl::TtyMode mode)260 ScopedAStatus RadioVoice::setTtyMode(int32_t serial, aidl::TtyMode mode) {
261     LOG_CALL << serial;
262     mHal1_5->setTTYMode(serial, V1_0::TtyMode(mode));
263     return ok();
264 }
265 
setVoNrEnabled(int32_t serial,bool enable)266 ndk::ScopedAStatus RadioVoice::setVoNrEnabled(int32_t serial, [[maybe_unused]] bool enable) {
267     LOG_CALL << serial;
268     // Note: a workaround for older HALs could also be setting persist.radio.is_vonr_enabled_
269     respond()->setVoNrEnabledResponse(notSupported(serial));
270     return ok();
271 }
272 
startDtmf(int32_t serial,const std::string & s)273 ScopedAStatus RadioVoice::startDtmf(int32_t serial, const std::string& s) {
274     LOG_CALL << serial;
275     mHal1_5->startDtmf(serial, s);
276     return ok();
277 }
278 
stopDtmf(int32_t serial)279 ScopedAStatus RadioVoice::stopDtmf(int32_t serial) {
280     LOG_CALL << serial;
281     mHal1_5->stopDtmf(serial);
282     return ok();
283 }
284 
switchWaitingOrHoldingAndActive(int32_t serial)285 ScopedAStatus RadioVoice::switchWaitingOrHoldingAndActive(int32_t serial) {
286     LOG_CALL << serial;
287     mHal1_5->switchWaitingOrHoldingAndActive(serial);
288     return ok();
289 }
290 
291 }  // namespace android::hardware::radio::compat
292