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 package com.android.internal.telephony;
18 
19 import static android.telephony.TelephonyManager.HAL_SERVICE_VOICE;
20 
21 import android.hardware.radio.RadioError;
22 import android.hardware.radio.RadioResponseInfo;
23 import android.hardware.radio.voice.IRadioVoiceResponse;
24 
25 import java.util.ArrayList;
26 import java.util.Collections;
27 
28 /**
29  * Interface declaring response functions to solicited radio requests for SIM APIs.
30  */
31 public class VoiceResponse extends IRadioVoiceResponse.Stub {
32     private final RIL mRil;
33 
VoiceResponse(RIL ril)34     public VoiceResponse(RIL ril) {
35         mRil = ril;
36     }
37 
38     /**
39      * Acknowledge the receipt of radio request sent to the vendor. This must be sent only for
40      * radio request which take long time to respond.
41      * For more details, refer https://source.android.com/devices/tech/connect/ril.html
42      * @param serial Serial no. of the request whose acknowledgement is sent.
43      */
acknowledgeRequest(int serial)44     public void acknowledgeRequest(int serial) {
45         mRil.processRequestAck(serial);
46     }
47 
48     /**
49      * @param responseInfo Response info struct containing response type, serial no. and error
50      */
acceptCallResponse(RadioResponseInfo responseInfo)51     public void acceptCallResponse(RadioResponseInfo responseInfo) {
52         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
53     }
54 
55     /**
56      * @param responseInfo Response info struct containing response type, serial no. and error
57      */
cancelPendingUssdResponse(RadioResponseInfo responseInfo)58     public void cancelPendingUssdResponse(RadioResponseInfo responseInfo) {
59         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
60     }
61 
62     /**
63      * @param responseInfo Response info struct containing response type, serial no. and error
64      */
conferenceResponse(RadioResponseInfo responseInfo)65     public void conferenceResponse(RadioResponseInfo responseInfo) {
66         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
67     }
68 
69     /**
70      * @param responseInfo Response info struct containing response type, serial no. and error
71      */
dialResponse(RadioResponseInfo responseInfo)72     public void dialResponse(RadioResponseInfo responseInfo) {
73         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
74     }
75 
76     /**
77      * @param responseInfo Response info struct containing response type, serial no. and error
78      */
emergencyDialResponse(RadioResponseInfo responseInfo)79     public void emergencyDialResponse(RadioResponseInfo responseInfo) {
80         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
81     }
82 
83     /**
84      * @param responseInfo Response info struct containing response type, serial no. and error
85      */
exitEmergencyCallbackModeResponse(RadioResponseInfo responseInfo)86     public void exitEmergencyCallbackModeResponse(RadioResponseInfo responseInfo) {
87         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
88     }
89 
90     /**
91      * @param responseInfo Response info struct containing response type, serial no. and error
92      */
explicitCallTransferResponse(RadioResponseInfo responseInfo)93     public void explicitCallTransferResponse(RadioResponseInfo responseInfo) {
94         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
95     }
96 
97     /**
98      * @param responseInfo Response info struct containing response type, serial no. and error
99      * @param callForwardInfos points to a vector of CallForwardInfo, one for
100      *        each distinct registered phone number.
101      */
getCallForwardStatusResponse(RadioResponseInfo responseInfo, android.hardware.radio.voice.CallForwardInfo[] callForwardInfos)102     public void getCallForwardStatusResponse(RadioResponseInfo responseInfo,
103             android.hardware.radio.voice.CallForwardInfo[] callForwardInfos) {
104         RILRequest rr = mRil.processResponse(HAL_SERVICE_VOICE, responseInfo);
105         if (rr != null) {
106             CallForwardInfo[] ret = new CallForwardInfo[callForwardInfos.length];
107             for (int i = 0; i < callForwardInfos.length; i++) {
108                 ret[i] = new CallForwardInfo();
109                 ret[i].status = callForwardInfos[i].status;
110                 ret[i].reason = callForwardInfos[i].reason;
111                 ret[i].serviceClass = callForwardInfos[i].serviceClass;
112                 ret[i].toa = callForwardInfos[i].toa;
113                 ret[i].number = callForwardInfos[i].number;
114                 ret[i].timeSeconds = callForwardInfos[i].timeSeconds;
115             }
116             if (responseInfo.error == RadioError.NONE) {
117                 RadioResponse.sendMessageResponse(rr.mResult, ret);
118             }
119             mRil.processResponseDone(rr, responseInfo, ret);
120         }
121     }
122 
123     /**
124      * @param responseInfo Response info struct containing response type, serial no. and error
125      * @param enable If current call waiting state is disabled, enable = false else true
126      * @param serviceClass If enable, then callWaitingResp[1] must follow, with the TS 27.007
127      *        service class bit vector of services for which call waiting is enabled.
128      *        For example, if callWaitingResp[0] is 1 and callWaitingResp[1] is 3, then call waiting
129      *        is enabled for data and voice and disabled for everything else.
130      */
getCallWaitingResponse(RadioResponseInfo responseInfo, boolean enable, int serviceClass)131     public void getCallWaitingResponse(RadioResponseInfo responseInfo, boolean enable,
132             int serviceClass) {
133         RadioResponse.responseInts(
134                 HAL_SERVICE_VOICE, mRil, responseInfo, enable ? 1 : 0, serviceClass);
135     }
136 
137     /**
138      * @param responseInfo Response info struct containing response type, serial no. and error
139      * @param status indicates CLIP status
140      */
getClipResponse(RadioResponseInfo responseInfo, int status)141     public void getClipResponse(RadioResponseInfo responseInfo, int status) {
142         RadioResponse.responseInts(HAL_SERVICE_VOICE, mRil, responseInfo, status);
143     }
144 
145     /**
146      * @param responseInfo Response info struct containing response type, serial no. and error
147      * @param n is "n" parameter from TS 27.007 7.7
148      * @param m is "m" parameter from TS 27.007 7.7
149      */
getClirResponse(RadioResponseInfo responseInfo, int n, int m)150     public void getClirResponse(RadioResponseInfo responseInfo, int n, int m) {
151         RadioResponse.responseInts(HAL_SERVICE_VOICE, mRil, responseInfo, n, m);
152     }
153 
154     /**
155      * @param responseInfo Response info struct containing response type, serial no. and error
156      * @param calls Current call list
157      */
getCurrentCallsResponse(RadioResponseInfo responseInfo, android.hardware.radio.voice.Call[] calls)158     public void getCurrentCallsResponse(RadioResponseInfo responseInfo,
159             android.hardware.radio.voice.Call[] calls) {
160         RILRequest rr = mRil.processResponse(HAL_SERVICE_VOICE, responseInfo);
161 
162         if (rr != null) {
163             int num = calls.length;
164             ArrayList<DriverCall> dcCalls = new ArrayList<>(num);
165             DriverCall dc;
166             for (int i = 0; i < num; i++) {
167                 dc = RILUtils.convertToDriverCall(calls[i]);
168                 dcCalls.add(dc);
169                 if (dc.isVoicePrivacy) {
170                     mRil.mVoicePrivacyOnRegistrants.notifyRegistrants();
171                     mRil.riljLog("InCall VoicePrivacy is enabled");
172                 } else {
173                     mRil.mVoicePrivacyOffRegistrants.notifyRegistrants();
174                     mRil.riljLog("InCall VoicePrivacy is disabled");
175                 }
176             }
177 
178             Collections.sort(dcCalls);
179             if ((num == 0) && mRil.mTestingEmergencyCall.getAndSet(false)) {
180                 if (mRil.mEmergencyCallbackModeRegistrant != null) {
181                     mRil.riljLog("responseCurrentCalls: call ended, testing emergency call,"
182                             + " notify ECM Registrants");
183                     mRil.mEmergencyCallbackModeRegistrant.notifyRegistrant();
184                 }
185             }
186 
187             if (responseInfo.error == RadioError.NONE) {
188                 RadioResponse.sendMessageResponse(rr.mResult, dcCalls);
189             }
190             mRil.processResponseDone(rr, responseInfo, dcCalls);
191         }
192     }
193 
194     /**
195      * @param responseInfo Response info struct containing response type, serial no. and error
196      * @param fcInfo Contains LastCallFailCause and vendor cause code. GSM failure reasons
197      *        are mapped to cause codes defined in TS 24.008 Annex H where possible. CDMA failure
198      *        reasons are derived from the possible call failure scenarios described in the
199      *        "CDMA IS-2000 Release A (C.S0005-A v6.0)" standard.
200      */
getLastCallFailCauseResponse(RadioResponseInfo responseInfo, android.hardware.radio.voice.LastCallFailCauseInfo fcInfo)201     public void getLastCallFailCauseResponse(RadioResponseInfo responseInfo,
202             android.hardware.radio.voice.LastCallFailCauseInfo fcInfo) {
203         RILRequest rr = mRil.processResponse(HAL_SERVICE_VOICE, responseInfo);
204 
205         if (rr != null) {
206             LastCallFailCause ret = new LastCallFailCause();
207             ret.causeCode = fcInfo.causeCode;
208             ret.vendorCause = fcInfo.vendorCause;
209             if (responseInfo.error == RadioError.NONE) {
210                 RadioResponse.sendMessageResponse(rr.mResult, ret);
211             }
212             mRil.processResponseDone(rr, responseInfo, ret);
213         }
214     }
215 
216     /**
217      * @param responseInfo Response info struct containing response type, serial no. and error
218      * @param enable true for "mute enabled" and false for "mute disabled"
219      */
getMuteResponse(RadioResponseInfo responseInfo, boolean enable)220     public void getMuteResponse(RadioResponseInfo responseInfo, boolean enable) {
221         RadioResponse.responseInts(HAL_SERVICE_VOICE, mRil, responseInfo, enable ? 1 : 0);
222     }
223 
224     /**
225      * @param responseInfo Response info struct containing response type, serial no. and error
226      * @param enable false for Standard Privacy Mode (Public Long Code Mask)
227      *        true for Enhanced Privacy Mode (Private Long Code Mask)
228      */
getPreferredVoicePrivacyResponse(RadioResponseInfo responseInfo, boolean enable)229     public void getPreferredVoicePrivacyResponse(RadioResponseInfo responseInfo, boolean enable) {
230         RadioResponse.responseInts(HAL_SERVICE_VOICE, mRil, responseInfo, enable ? 1 : 0);
231     }
232 
233     /**
234      * @param responseInfo Response info struct containing response type, serial no. and error
235      * @param mode TTY mode
236      */
getTtyModeResponse(RadioResponseInfo responseInfo, int mode)237     public void getTtyModeResponse(RadioResponseInfo responseInfo, int mode) {
238         RadioResponse.responseInts(HAL_SERVICE_VOICE, mRil, responseInfo, mode);
239     }
240 
241     /**
242      * @param responseInfo Response info struct containing response type, serial no. and error
243      */
handleStkCallSetupRequestFromSimResponse(RadioResponseInfo responseInfo)244     public void handleStkCallSetupRequestFromSimResponse(RadioResponseInfo responseInfo) {
245         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
246     }
247 
248     /**
249      * @param responseInfo Response info struct containing response type, serial no. and error
250      */
hangupConnectionResponse(RadioResponseInfo responseInfo)251     public void hangupConnectionResponse(RadioResponseInfo responseInfo) {
252         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
253     }
254 
255     /**
256      * @param responseInfo Response info struct containing response type, serial no. and error
257      */
hangupForegroundResumeBackgroundResponse(RadioResponseInfo responseInfo)258     public void hangupForegroundResumeBackgroundResponse(RadioResponseInfo responseInfo) {
259         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
260     }
261 
262     /**
263      * @param responseInfo Response info struct containing response type, serial no. and error
264      */
hangupWaitingOrBackgroundResponse(RadioResponseInfo responseInfo)265     public void hangupWaitingOrBackgroundResponse(RadioResponseInfo responseInfo) {
266         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
267     }
268 
269     /**
270      * @param responseInfo Response info struct containing response type, serial no. and error
271      * @param enable true for "vonr enabled" and false for "vonr disabled"
272      */
isVoNrEnabledResponse(RadioResponseInfo responseInfo, boolean enable)273     public void isVoNrEnabledResponse(RadioResponseInfo responseInfo, boolean enable) {
274         RILRequest rr = mRil.processResponse(HAL_SERVICE_VOICE, responseInfo);
275 
276         if (rr != null) {
277             if (responseInfo.error == RadioError.NONE) {
278                 RadioResponse.sendMessageResponse(rr.mResult, enable);
279             }
280             mRil.processResponseDone(rr, responseInfo, enable);
281         }
282     }
283 
284     /**
285      * @param responseInfo Response info struct containing response type, serial no. and error
286      */
rejectCallResponse(RadioResponseInfo responseInfo)287     public void rejectCallResponse(RadioResponseInfo responseInfo) {
288         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
289     }
290 
291     /**
292      * @param responseInfo Response info struct containing response type, serial no. and error
293      */
sendBurstDtmfResponse(RadioResponseInfo responseInfo)294     public void sendBurstDtmfResponse(RadioResponseInfo responseInfo) {
295         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
296     }
297 
298     /**
299      * @param responseInfo Response info struct containing response type, serial no. and error
300      */
sendCdmaFeatureCodeResponse(RadioResponseInfo responseInfo)301     public void sendCdmaFeatureCodeResponse(RadioResponseInfo responseInfo) {
302         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
303     }
304 
305     /**
306      * @param responseInfo Response info struct containing response type, serial no. and error
307      */
sendDtmfResponse(RadioResponseInfo responseInfo)308     public void sendDtmfResponse(RadioResponseInfo responseInfo) {
309         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
310     }
311 
312     /**
313      * @param responseInfo Response info struct containing response type, serial no. and error
314      */
sendUssdResponse(RadioResponseInfo responseInfo)315     public void sendUssdResponse(RadioResponseInfo responseInfo) {
316         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
317     }
318 
319     /**
320      * @param responseInfo Response info struct containing response type, serial no. and error
321      */
separateConnectionResponse(RadioResponseInfo responseInfo)322     public void separateConnectionResponse(RadioResponseInfo responseInfo) {
323         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
324     }
325 
326     /**
327      * @param responseInfo Response info struct containing response type, serial no. and error
328      */
setCallForwardResponse(RadioResponseInfo responseInfo)329     public void setCallForwardResponse(RadioResponseInfo responseInfo) {
330         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
331     }
332 
333     /**
334      * @param responseInfo Response info struct containing response type, serial no. and error
335      */
setCallWaitingResponse(RadioResponseInfo responseInfo)336     public void setCallWaitingResponse(RadioResponseInfo responseInfo) {
337         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
338     }
339 
340     /**
341      * @param responseInfo Response info struct containing response type, serial no. and error
342      */
setClirResponse(RadioResponseInfo responseInfo)343     public void setClirResponse(RadioResponseInfo responseInfo) {
344         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
345     }
346 
347     /**
348      * @param responseInfo Response info struct containing response type, serial no. and error
349      */
setMuteResponse(RadioResponseInfo responseInfo)350     public void setMuteResponse(RadioResponseInfo responseInfo) {
351         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
352     }
353 
354     /**
355      * @param responseInfo Response info struct containing response type, serial no. and error
356      */
setPreferredVoicePrivacyResponse(RadioResponseInfo responseInfo)357     public void setPreferredVoicePrivacyResponse(RadioResponseInfo responseInfo) {
358         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
359     }
360 
361     /**
362      * @param responseInfo Response info struct containing response type, serial no. and error
363      */
setTtyModeResponse(RadioResponseInfo responseInfo)364     public void setTtyModeResponse(RadioResponseInfo responseInfo) {
365         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
366     }
367 
368     /**
369      * @param responseInfo Response info struct containing response type, serial no. and error
370      */
setVoNrEnabledResponse(RadioResponseInfo responseInfo)371     public void setVoNrEnabledResponse(RadioResponseInfo responseInfo) {
372         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
373     }
374 
375     /**
376      * @param responseInfo Response info struct containing response type, serial no. and error
377      */
startDtmfResponse(RadioResponseInfo responseInfo)378     public void startDtmfResponse(RadioResponseInfo responseInfo) {
379         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
380     }
381 
382     /**
383      * @param responseInfo Response info struct containing response type, serial no. and error
384      */
stopDtmfResponse(RadioResponseInfo responseInfo)385     public void stopDtmfResponse(RadioResponseInfo responseInfo) {
386         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
387     }
388 
389     /**
390      * @param responseInfo Response info struct containing response type, serial no. and error
391      */
switchWaitingOrHoldingAndActiveResponse(RadioResponseInfo responseInfo)392     public void switchWaitingOrHoldingAndActiveResponse(RadioResponseInfo responseInfo) {
393         RadioResponse.responseVoid(HAL_SERVICE_VOICE, mRil, responseInfo);
394     }
395 
396     @Override
getInterfaceHash()397     public String getInterfaceHash() {
398         return IRadioVoiceResponse.HASH;
399     }
400 
401     @Override
getInterfaceVersion()402     public int getInterfaceVersion() {
403         return IRadioVoiceResponse.VERSION;
404     }
405 }
406