1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef CALL_MANAGER_SERVICE_PROXY_H
17 #define CALL_MANAGER_SERVICE_PROXY_H
18 
19 #include <cfloat>
20 #include <cstdio>
21 #include <string>
22 #include <vector>
23 
24 #include "iremote_broker.h"
25 #include "iremote_proxy.h"
26 #include "pac_map.h"
27 
28 #include "call_ability_callback_ipc_interface_code.h"
29 #include "call_manager_inner_type.h"
30 #include "call_manager_service_ipc_interface_code.h"
31 #include "i_call_manager_service.h"
32 #include "telephony_log_wrapper.h"
33 
34 namespace OHOS {
35 namespace Telephony {
36 class CallManagerServiceProxy : public IRemoteProxy<ICallManagerService> {
37 public:
38     /**
39      * CallManagerServiceProxy
40      *
41      * @param impl
42      */
43     explicit CallManagerServiceProxy(const sptr<IRemoteObject> &impl);
44     virtual ~CallManagerServiceProxy() = default;
45 
46     /**
47      * RegisterCallBack
48      *
49      * @brief Register callback
50      * @param callback[in], callback function pointer
51      * @return Returns 0 on success, others on failure.
52      */
53     int32_t RegisterCallBack(const sptr<ICallAbilityCallback> &callback) override;
54 
55     /**
56      * UnRegisterCallBack
57      *
58      * @brief unregister callback
59      * @return Returns 0 on success, others on failure.
60      */
61     int32_t UnRegisterCallBack() override;
62 
63     /**
64      * ObserverOnCallDetailsChange
65      *
66      * @brief execute when observe OnCallDetailsChange
67      * @return Returns 0 on success, others on failure.
68      */
69     int32_t ObserverOnCallDetailsChange() override;
70 
71     /**
72      * DialCall
73      *
74      * @brief Dial a phone call
75      * @param number[in], dial param.
76      * @param extras[in], extras date.
77      * @return Returns callId when the value is greater than zero, others on failure.
78      */
79     int32_t DialCall(std::u16string number, AppExecFwk::PacMap &extras) override;
80 
81     /**
82      * MakeCall
83      *
84      * @brief Make a phone call
85      * @param number[in], call param.
86      * @return Returns 0 on success, others on failure.
87      */
88     int32_t MakeCall(std::string number) override;
89 
90     /**
91      * AnswerCall
92      *
93      * @brief Answer a phone call
94      * @param callId[in], call id
95      * @param videoState[in], 0: audio, 1: video
96      * @return Returns 0 on success, others on failure.
97      */
98     int32_t AnswerCall(int32_t callId, int32_t videoState) override;
99 
100     /**
101      * RejectCall
102      *
103      * @brief Reject a phone call
104      * @param callId[in], call id
105      * @param rejectWithMessage[in], Whether to enter the reason for rejection,true:yes false:no
106      * @param textMessage[in], The reason you reject the call
107      * @return Returns 0 on success, others on failure.
108      */
109     int32_t RejectCall(int32_t callId, bool rejectWithMessage, std::u16string textMessage) override;
110 
111     /**
112      * HangUpCall
113      *
114      * @brief Hang up the phone
115      * @param callId[in], call id
116      * @return Returns 0 on success, others on failure.
117      */
118     int32_t HangUpCall(int32_t callId) override;
119 
120     /**
121      * GetCallState
122      *
123      * @brief Obtain the call status of the device
124      * @return Returns call state.
125      */
126     int32_t GetCallState() override;
127 
128     /**
129      * HoldCall
130      *
131      * @brief Park a phone call
132      * @param callId[in], call id
133      * @return Returns 0 on success, others on failure.
134      */
135     int32_t HoldCall(int32_t callId) override;
136 
137     /**
138      * UnHoldCall
139      *
140      * @brief Activate a phone call
141      * @param callId[in], call id
142      * @return Returns 0 on success, others on failure.
143      */
144     int32_t UnHoldCall(int32_t callId) override;
145 
146     /**
147      * SwitchCall
148      *
149      * @brief Switch the phone
150      * @param callId[in], call id
151      * @return Returns 0 on success, others on failure.
152      */
153     int32_t SwitchCall(int32_t callId) override;
154 
155     /**
156      * HasCall
157      *
158      * @brief Is there Call
159      * @return Returns true on has call, others on there is no call.
160      */
161     bool HasCall() override;
162 
163     /**
164      * IsNewCallAllowed
165      *
166      * @brief Can I initiate a call
167      * @param enabled[out], whether allow new calls
168      * @return Returns interface processing results.
169      */
170     int32_t IsNewCallAllowed(bool &enabled) override;
171 
172     /**
173      * SetMuted
174      *
175      * @brief Mute the Microphone
176      * @param isMute[in], mute state
177      * @return Returns 0 on success, others on failure.
178      */
179     int32_t SetMuted(bool isMute) override;
180 
181     /**
182      * MuteRinger
183      *
184      * @brief Call mute
185      * @return Returns 0 on success, others on failure.
186      */
187     int32_t MuteRinger() override;
188 
189     /**
190      * SetAudioDevice
191      *
192      * @brief Setting the Audio Channel
193      * @param audioDevice[in], contain audioDeviceType and address
194      * @return Returns 0 on success, others on failure.
195      */
196     int32_t SetAudioDevice(const AudioDevice &audioDevice) override;
197 
198     /**
199      * IsRinging
200      *
201      * @brief Whether the ringing
202      * @param enabled[out], true on ringing, false on there is no ringing
203      * @return Returns interface processing results.
204      */
205     int32_t IsRinging(bool &enabled) override;
206 
207     /**
208      * IsInEmergencyCall
209      *
210      * @brief Is there an emergency call
211      * @param enabled[out], true on emergency call, false on no emergency call
212      * @return Returns interface processing results.
213      */
214     int32_t IsInEmergencyCall(bool &enabled) override;
215 
216     /**
217      * StartDtmf
218      *
219      * @brief Enable and send DTMF
220      * @param callId[in], call id
221      * @param str[in], Characters sent
222      * @return Returns 0 on success, others on failure.
223      */
224     int32_t StartDtmf(int32_t callId, char str) override;
225 
226     /**
227      * StopDtmf
228      *
229      * @brief Stop the DTMF
230      * @param callId[in], call id
231      * @return Returns 0 on success, others on failure.
232      */
233     int32_t StopDtmf(int32_t callId) override;
234 
235     int32_t PostDialProceed(int32_t callId, bool proceed) override;
236 
237     /**
238      * GetCallWaiting
239      *
240      * @brief Gets whether the call waiting service of the current account is enabled
241      * @param slotId[in], The slot id
242      * @return Returns 0 on success, others on failure.
243      */
244     int32_t GetCallWaiting(int32_t slotId) override;
245 
246     /**
247      * SetCallWaiting
248      *
249      * @brief Set the call waiting function for the current account
250      * @param slotId[in], The slot id
251      * @param activate[in], Activation of switch
252      * @return Returns 0 on success, others on failure.
253      */
254     int32_t SetCallWaiting(int32_t slotId, bool activate) override;
255 
256     /**
257      * GetCallRestriction
258      *
259      * @brief Gets the call restriction information of the specified account
260      * @param slotId[in], The slot id
261      * @param type[in], Call Restriction type
262      * @return Returns 0 on success, others on failure.
263      */
264     int32_t GetCallRestriction(int32_t slotId, CallRestrictionType type) override;
265 
266     /**
267      * SetCallRestriction
268      *
269      * @brief Set the call restriction function for the current account
270      * @param slotId[in], The slot id
271      * @param info[in], Call restriction information
272      * @return Returns 0 on success, others on failure.
273      */
274     int32_t SetCallRestriction(int32_t slotId, CallRestrictionInfo &info) override;
275 
276     /**
277      * SetCallRestrictionPassword
278      *
279      * @brief Set the call restriction password function for the current account
280      * @param slotId[in], The slot id
281      * @param fac[in], Call restriction type
282      * @param oldPassword[in], Old password of call restriction type
283      * @param newPassword[in], New password of call restriction type
284      * @return Returns 0 on success, others on failure.
285      */
286     int32_t SetCallRestrictionPassword(
287         int32_t slotId, CallRestrictionType fac, const char *oldPassword, const char *newPassword) override;
288 
289     /**
290      * GetCallTransferInfo
291      *
292      * @brief Gets the call transfer information of the current account
293      * @param slotId[in], The slot id
294      * @param type[in], Call Transfer Type
295      * @return Returns 0 on success, others on failure.
296      */
297     int32_t GetCallTransferInfo(int32_t slotId, CallTransferType type) override;
298 
299     /**
300      * SetCallTransferInfo
301      *
302      * @brief Set the call transfer function for the current account
303      * @param slotId[in], The slot id
304      * @param info[in], Call Transfer Information
305      * @return Returns 0 on success, others on failure.
306      */
307     int32_t SetCallTransferInfo(int32_t slotId, CallTransferInfo &info) override;
308 
309     /**
310      * CanSetCallTransferTime
311      *
312      * @brief confirm whether IMS can set call transfer time.
313      * @param slotId[in], The slot id
314      * @param result[out], The result of can set or not
315      * @return Returns true on can set, others on can not set.
316      */
317     int32_t CanSetCallTransferTime(int32_t slotId, bool &result) override;
318 
319     /**
320      * CombineConference
321      *
322      * @brief Merge calls to form a conference
323      * @param callId[in], call id
324      * @return Returns 0 on success, others on failure.
325      */
326     int32_t CombineConference(int32_t mainCallId) override;
327 
328     /**
329      * SeparateConference
330      *
331      * @brief Separates a specified call from a conference call
332      * @param callId[in], call id
333      * @return Returns 0 on success, others on failure.
334      */
335     int32_t SeparateConference(int32_t callId) override;
336 
337     /**
338      * KickOutFromConference
339      *
340      * @brief Hangup a specified call from a conference call
341      * @param callId[in], call id
342      * @return Returns 0 on success, others on failure.
343      */
344     int32_t KickOutFromConference(int32_t callId) override;
345 
346     /**
347      * JoinConference
348      *
349      * @brief Bring someone into a meeting
350      * @param callId[in], The call id
351      * @param numberList[in], List of calls to join the conference
352      * @return Returns 0 on success, others on failure.
353      */
354     int32_t JoinConference(int32_t callId, std::vector<std::u16string> &numberList) override;
355 
356     /**
357      * SetCallPreferenceMode
358      *
359      * @brief Setting the Call Type
360      * @param slotId[in], The slot id
361      * @param mode[in], Preference Mode
362      * @return Returns 0 on success, others on failure.
363      */
364     int32_t SetCallPreferenceMode(int32_t slotId, int32_t mode) override;
365 
366     /**
367      * ControlCamera
368      *
369      * @brief Open or close camera
370      * @param callId[in], The call id
371      * @param cameraId[in], The camera id
372      * @return Returns 0 on success, others on failure.
373      */
374     int32_t ControlCamera(int32_t callId, std::u16string &cameraId) override;
375 
376     /**
377      * SetPreviewWindow
378      *
379      * @brief Set the location and size of the preview window for videos captured by the local camera.
380      * @param callId[in], The call id
381      * @param surfaceId[in], Window information
382      * @param surface[in], Window information
383      * @return Returns 0 on success, others on failure.
384      */
385     int32_t SetPreviewWindow(int32_t callId, std::string &surfaceId, sptr<Surface> surface) override;
386 
387     /**
388      * SetDisplayWindow
389      *
390      * @brief Sets the location and size of the remote video window.
391      * @param callId[in], The call id
392      * @param surfaceId[in], Window information
393      * @param surface[in], Window information
394      * @return Returns 0 on success, others on failure.
395      */
396     int32_t SetDisplayWindow(int32_t callId, std::string &surfaceId, sptr<Surface> surface) override;
397 
398     /**
399      * SetCameraZoom
400      *
401      * @brief Sets the local camera zoom scale
402      * @param zoomRatio[in], Camera scale
403      * @return Returns 0 on success, others on failure.
404      */
405     int32_t SetCameraZoom(float zoomRatio) override;
406 
407     /**
408      * SetPausePicture
409      *
410      * @brief APP sets the screen of the remote video freeze immediately.
411      * If the APP does not call this interface when making a video call,
412      * the last frame before the remote video freeze is displayed by default
413      * @param callId[in], The call id
414      * @param path[in], Local Picture address
415      * @return Returns 0 on success, others on failure.
416      */
417     int32_t SetPausePicture(int32_t callId, std::u16string &path) override;
418 
419     /**
420      * SetDeviceDirection
421      *
422      * @brief Set the rotation Angle of the local device. The default value is 0
423      * @param callId[in], The call id
424      * @param rotation[in], Rotation Angle
425      * @return Returns 0 on success, others on failure.
426      */
427     int32_t SetDeviceDirection(int32_t callId, int32_t rotation) override;
428 
429     /**
430      * IsEmergencyPhoneNumber
431      *
432      * @brief Is it an emergency call
433      * @param number[in], Phone number to be formatted
434      * @param slotId[in], The slot id
435      * @param enabled[out] result of is it an emergency call
436      * @return Returns 0 on success, others on failure.
437      */
438     int32_t IsEmergencyPhoneNumber(std::u16string &number, int32_t slotId, bool &enabled) override;
439 
440     /**
441      * FormatPhoneNumber
442      *
443      * @brief Formatting a phone number
444      * @param number[in], Phone number to be formatted
445      * @param countryCode[in], Country code of the phone number
446      * @param formatNumber[out] Formatting a phone number
447      * @return Returns 0 on success, others on failure.
448      */
449     int32_t FormatPhoneNumber(
450         std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber) override;
451 
452     /**
453      * FormatPhoneNumberToE164
454      *
455      * @brief Formatting a phone number
456      * @param number[in]. Phone number to be formatted
457      * @param countryCode[in], Country code of the phone number
458      * @param formatNumber[out] Formatting a phone number
459      * @return Returns 0 on success, others on failure.
460      */
461     int32_t FormatPhoneNumberToE164(
462         std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber) override;
463 
464     /**
465      * GetMainCallId
466      *
467      * @brief Obtain the ID of the primary call in a conference
468      * @param callId[in], Id of a call in a conference
469      * @return Returns main call id, -1 on not call id.
470      */
471     int32_t GetMainCallId(int32_t callId, int32_t &mainCallId) override;
472 
473     /**
474      * GetSubCallIdList
475      *
476      * @brief Obtain the list of neutron call ids
477      * @param callId[in], Id of a call in a conference
478      * @param callIdList[out], the list of neutron call ids
479      * @return Returns 0 on success, others on failure.
480      */
481     int32_t GetSubCallIdList(int32_t callId, std::vector<std::u16string> &callIdList) override;
482 
483     /**
484      * GetCallIdListForConference
485      *
486      * @brief Obtain the callId list of all calls in a conference
487      * @param callId[in], Id of a call in a conference
488      * @param callIdList[out], the callId list of all calls in a conference
489      * @return Returns 0 on success, others on failure.
490      */
491     int32_t GetCallIdListForConference(int32_t callId, std::vector<std::u16string> &callIdList) override;
492 
493     /**
494      * GetImsConfig
495      *
496      * @brief Obtain the IMS service configuration
497      * @param slotId[in], The slot id
498      * @param item[in]
499      * @return Returns 0 on success, others on failure.
500      */
501     int32_t GetImsConfig(int32_t slotId, ImsConfigItem item) override;
502 
503     /**
504      * SetImsConfig
505      *
506      * @brief Example Set the IMS service configuration
507      * @param slotId[in], The slot id
508      * @param item[in]
509      * @return Returns 0 on success, others on failure.
510      */
511     int32_t SetImsConfig(int32_t slotId, ImsConfigItem item, std::u16string &value) override;
512 
513     /**
514      * GetImsFeatureValue
515      *
516      * @brief Gets the value of the IMS function item of the specified network type
517      * @param slotId[in], The slot id
518      * @param info[in], FeatureType
519      * @return Returns 0 on success, others on failure.
520      */
521     int32_t GetImsFeatureValue(int32_t slotId, FeatureType type) override;
522 
523     /**
524      * SetImsFeatureValue
525      *
526      * @brief Set the value of the IMS function item of the specified network type
527      * @param slotId[in], The slot id
528      * @param info[in], FeatureType
529      * @param value[in]
530      * @return Returns 0 on success, others on failure.
531      */
532     int32_t SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value) override;
533 
534     /**
535      * UpdateImsCallMode
536      *
537      * @brief Setting the Call Mode
538      * @param callId[in], The call id
539      * @param mode[in], Calling patterns
540      * @return Returns 0 on success, others on failure.
541      */
542     int32_t UpdateImsCallMode(int32_t callId, ImsCallMode mode) override;
543 
544     /**
545      * EnableImsSwitch
546      *
547      * @brief Start VoLte
548      * @param slotId[in], The slot id
549      * @return Returns 0 on success, others on failure.
550      */
551     int32_t EnableImsSwitch(int32_t slotId) override;
552 
553     /**
554      * DisableImsSwitch
555      *
556      * @brief Stop VoLte
557      * @param slotId[in], The slot id
558      * @return Returns 0 on success, others on failure.
559      */
560     int32_t DisableImsSwitch(int32_t slotId) override;
561 
562     /**
563      * IsImsSwitchEnabled
564      *
565      * @brief Whether to enable VoLte
566      * @param slotId[in], The slot id
567      * @param enabled[out], The result of enable or not
568      * @return Returns 0 on success, others on failure.
569      */
570     int32_t IsImsSwitchEnabled(int32_t slotId, bool &enabled) override;
571 
572     /**
573      * SetVoNRState
574      *
575      * @brief Set VoNR State
576      * @param slotId[in], The slot id
577      * @param state[in], The state of VoNR
578      * @return Returns 0 on success, others on failure.
579      */
580     int32_t SetVoNRState(int32_t slotId, int32_t state) override;
581 
582     /**
583      * GetVoNRState
584      *
585      * @brief Get VoNR State
586      * @param slotId[in], The slot id
587      * @param state[out], The result of VoNR state ON or OFF
588      * @return Returns 0 on success, others on failure.
589      */
590     int32_t GetVoNRState(int32_t slotId, int32_t &state) override;
591 
592     /**
593      * StartRtt
594      *
595      * @brief Enable and send RTT information
596      * @param callId[in], The call id
597      * @param msg[in], RTT information
598      * @return Returns 0 on success, others on failure.
599      */
600     int32_t StartRtt(int32_t callId, std::u16string &msg) override;
601 
602     /**
603      * StopRtt
604      *
605      * @brief Close the RTT
606      * @param callId[in], The call id
607      * @return Returns 0 on success, others on failure.
608      */
609     int32_t StopRtt(int32_t callId) override;
610 
611     /**
612      * ReportOttCallDetailsInfo
613      *
614      * @brief report ott call details info
615      * @param ottVec[in], ott call status detail info list
616      * @return Returns 0 on success, others on failure.
617      */
618     int32_t ReportOttCallDetailsInfo(std::vector<OttCallDetailsInfo> &ottVec) override;
619 
620     /**
621      * ReportOttCallEventInfo
622      *
623      * @brief report ott call event info
624      * @param eventInfo[in], ott call event detail info
625      * @return Returns 0 on success, others on failure.
626      */
627     int32_t ReportOttCallEventInfo(OttCallEventInfo &eventInfo) override;
628 
629     /**
630      * CloseUnFinishedUssd
631      *
632      * @brief Close Unfinished ussd function for the current account
633      * @param slotId[in], The slot id
634      * @return Returns 0 on success, others on failure.
635      */
636     int32_t CloseUnFinishedUssd(int32_t slotId) override;
637 
638     /**
639      * Handle special code from dialer.
640      *
641      * @param specialCode[in], special code
642      * @return Returns 0 on success, others on failure.
643      */
644     int32_t InputDialerSpecialCode(const std::string &specialCode) override;
645 
646     /**
647      * Remove missed incoming call notification.
648      *
649      * @return Returns 0 on success, others on failure.
650      */
651     int32_t RemoveMissedIncomingCallNotification() override;
652 
653     /**
654      * SetVoIPCallState
655      *
656      * @brief Set VoIP Call State
657      * @param state[in], The state of VoIP Call
658      * @return Returns 0 on success, others on failure.
659      */
660     int32_t SetVoIPCallState(int32_t state) override;
661 
662     /**
663      * GetVoNRState
664      *
665      * @brief Get VoIP Call State
666      * @param state[out], The VoIP Call state
667      * @return Returns 0 on success, others on failure.
668      */
669     int32_t GetVoIPCallState(int32_t &state) override;
670 
671     /**
672      * GetProxyObjectPtr
673      *
674      * @brief get callManager proxy object ptr
675      * @param proxyType[in], proxy type
676      * @return Returns nullptr on failure, others on success.
677      */
678     sptr<IRemoteObject> GetProxyObjectPtr(CallManagerProxyType proxyType) override;
679 
680     /**
681      * ReportAudioDeviceInfo
682      *
683      * @brief report audio device info
684      * @return Returns 0 on success, others on failure.
685      */
686     int32_t ReportAudioDeviceInfo() override;
687 
688     /**
689      * CancelCallUpgrade
690      *
691      * @brief cancel upgrade to video call
692      * @param callId[in], The call id
693      *
694      * @return Returns 0 on success, others on failure.
695      */
696     int32_t CancelCallUpgrade(int32_t callId) override;
697 
698     /**
699      * RequestCameraCapabilities
700      *
701      * @brief request camera capabilities
702      * @param callId[in], The call id
703      *
704      * @return Returns 0 on success, others on failure.
705      */
706     int32_t RequestCameraCapabilities(int32_t callId) override;
707 
708     /**
709      * RegisterVoipCallManagerCallback
710      *
711      * @brief notify voip register callstatus call back
712      * @return Returns 0 on success, others on failure.
713      */
714     int32_t RegisterVoipCallManagerCallback() override;
715 
716     /**
717      * @brief notify voip unregister callstatus callback
718      *
719      * @return Returns 0 on success, others on failure.
720      */
721     int32_t UnRegisterVoipCallManagerCallback() override;
722 
723     /**
724      * SendCallUiEvent
725      *
726      * @brief send call ui event
727      * @return Returns 0 on success, others on failure.
728      */
729     int32_t SendCallUiEvent(int32_t callId, std::string &eventName) override;
730 
731 private:
732     int32_t SendRequest(CallManagerInterfaceCode code);
733     int32_t SendRequest(CallManagerInterfaceCode code, MessageParcel &dataParcel, MessageParcel &replyParcel);
734 
735 private:
736     static inline BrokerDelegator<CallManagerServiceProxy> delegator_;
737 };
738 } // namespace Telephony
739 } // namespace OHOS
740 
741 #endif // CALL_MANAGER_SERVICE_PROXY_H
742