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 CELLULAR_CALL_CONNECTION_H
17 #define CELLULAR_CALL_CONNECTION_H
18 
19 #include <mutex>
20 
21 #include "call_status_callback.h"
22 #include "cellular_call_interface.h"
23 #include "i_call_status_callback.h"
24 #include "if_system_ability_manager.h"
25 #include "refbase.h"
26 #include "rwlock.h"
27 #include "singleton.h"
28 #include "surface.h"
29 #include "system_ability_status_change_stub.h"
30 
31 namespace OHOS {
32 namespace Telephony {
33 class CellularCallConnection : public std::enable_shared_from_this<CellularCallConnection> {
34     DECLARE_DELAYED_SINGLETON(CellularCallConnection)
35 
36 public:
37     void Init(int32_t systemAbilityId);
38     void UnInit();
39 
40     /**
41      * Dial
42      *
43      * @brief Make a phone call
44      * @param callInfo[in], Call information.
45      * @return Returns callId when the value is greater than zero, others on failure.
46      */
47     int Dial(const CellularCallInfo &callInfo);
48 
49     /**
50      * HangUp
51      *
52      * @brief Hang up the phone
53      * @param callInfo[in], Call information.
54      * @param CallSupplementType
55      * @return Returns 0 on success, others on failure.
56      */
57     int HangUp(const CellularCallInfo &callInfo, CallSupplementType type);
58 
59     /**
60      * Reject
61      *
62      * @brief Reject a phone call
63      * @param callInfo[in], Call information.
64      * @return Returns 0 on success, others on failure.
65      */
66     int Reject(const CellularCallInfo &callInfo);
67 
68     /**
69      * Answer
70      *
71      * @brief Answer a phone call
72      * @param callInfo[in], Call information.
73      * @return Returns 0 on success, others on failure.
74      */
75     int Answer(const CellularCallInfo &callInfo);
76 
77     /**
78      * HoldCall
79      *
80      * @brief Park a phone call
81      * @param callInfo[in], Call information.
82      * @return Returns 0 on success, others on failure.
83      */
84     int HoldCall(const CellularCallInfo &callInfo);
85 
86     /**
87      * UnHoldCall
88      *
89      * @brief Activate a phone call
90      * @param callInfo[in], Call information.
91      * @return Returns 0 on success, others on failure.
92      */
93     int UnHoldCall(const CellularCallInfo &callInfo);
94 
95     /**
96      * SwitchCall
97      *
98      * @brief Switch the phone
99      * @param callInfo[in], Call information.
100      * @return Returns 0 on success, others on failure.
101      */
102     int SwitchCall(const CellularCallInfo &callInfo);
103 
104     /**
105      * IsEmergencyPhoneNumber
106      *
107      * @brief Is it an emergency call
108      * @param number[in], Phone number to be formatted
109      * @param slotId[in], The slot id
110      * @param enabled[out] true is emergency phonenumber, other is not
111      * @return Returns 0 on success, others on failure.
112      */
113     int IsEmergencyPhoneNumber(const std::string &phoneNum, int32_t slotId, bool &enabled);
114 
115     /**
116      * CombineConference
117      *
118      * @brief Merge calls to form a conference
119      * @param callInfo[in], Call information.
120      * @return Returns 0 on success, others on failure.
121      */
122     int CombineConference(const CellularCallInfo &callInfo);
123 
124     /**
125      * SeparateConference
126      *
127      * @brief Separates a specified call from a conference call
128      * @param callInfo[in], Call information.
129      * @return Returns 0 on success, others on failure.
130      */
131     int SeparateConference(const CellularCallInfo &callInfo);
132 
133     /**
134      * KickOutFromConference
135      *
136      * @brief Hangup a specified call from a conference call
137      * @param callInfo[in], Call information.
138      * @return Returns 0 on success, others on failure.
139      */
140     int KickOutFromConference(const CellularCallInfo &callInfo);
141 
142     /**
143      * StartDtmf
144      *
145      * @brief Enable and send DTMF
146      * @param cDTMFCode[in], Characters sent
147      * @param callInfo[in], Call information.
148      * @return Returns 0 on success, others on failure.
149      */
150     int StartDtmf(char cDTMFCode, const CellularCallInfo &callInfo);
151 
152     /**
153      * StopDtmf
154      *
155      * @brief Stop the DTMF
156      * @param callInfo[in], Call information.
157      * @return Returns 0 on success, others on failure.
158      */
159     int StopDtmf(const CellularCallInfo &callInfo);
160 
161     int PostDialProceed(const CellularCallInfo &callInfo, const bool proceed);
162 
163     /**
164      * SendDtmf
165      *
166      * @brief Sending DTMF
167      * @param cDTMFCode[in], Characters sent
168      * @param phoneNum[in], Phone number corresponding to the call
169      * @return Returns 0 on success, others on failure.
170      */
171     int SendDtmf(char cDTMFCode, const std::string &phoneNum);
172 
173     /**
174      * SendDtmfString
175      *
176      * @brief Send a string of DTMFS
177      * @param dtmfCodeStr[in], Characters sent
178      * @param phoneNum[in], Phone number corresponding to the call
179      * @param phoneNetType[in].
180      * @param switchOn[in].
181      * @param switchOff[in].
182      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
183      */
184     int SendDtmfString(const std::string &dtmfCodeStr, const std::string &phoneNum, PhoneNetType phoneNetType,
185         int32_t switchOn, int32_t switchOff);
186 
187     /**
188      * SetCallTransferInfo
189      *
190      * @brief Set the call transfer function for the current account
191      * @param info[in], Call Transfer Information
192      * @param slotId[in], The slot id
193      * @return Returns 0 on success, others on failure.
194      */
195     int SetCallTransferInfo(const CallTransferInfo &info, int32_t slotId);
196 
197     /**
198      * CanSetCallTransferTime
199      *
200      * @brief confirm whether IMS can set call transfer time.
201      * @param slotId[in], The slot id
202      * @param result[out], The result of can set or not
203      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
204      */
205     int CanSetCallTransferTime(int32_t slotId, bool &result);
206 
207     /**
208      * GetCallTransferInfo
209      *
210      * @brief Gets the call transfer information of the current account
211      * @param type[in], Call Transfer Type
212      * @param slotId[in], The slot id
213      * @return Returns 0 on success, others on failure.
214      */
215     int GetCallTransferInfo(CallTransferType type, int32_t slotId);
216 
217     /**
218      * SetCallWaiting
219      *
220      * @brief Set the call waiting function for the current account
221      * @param activate[in], Activation of switch
222      * @param slotId[in], The slot id
223      * @return Returns 0 on success, others on failure.
224      */
225     int SetCallWaiting(bool activate, int32_t slotId);
226 
227     /**
228      * GetCallWaiting
229      *
230      * @brief Gets whether the call waiting service of the current account is enabled
231      * @param slotId[in], The slot id
232      * @return Returns 0 on success, others on failure.
233      */
234     int GetCallWaiting(int32_t slotId);
235 
236     /**
237      * SetCallRestriction
238      *
239      * @brief Set the call restriction function for the current account
240      * @param info[in], Call restriction information
241      * @param slotId[in], The slot id
242      * @return Returns 0 on success, others on failure.
243      */
244     int SetCallRestriction(const CallRestrictionInfo &info, int32_t slotId);
245 
246     /**
247      * GetCallRestriction
248      *
249      * @brief Gets the call restriction information of the specified account
250      * @param facType[in], Call Restriction type
251      * @param slotId[in], The slot id
252      * @return Returns 0 on success, others on failure.
253      */
254     int GetCallRestriction(CallRestrictionType facType, int32_t slotId);
255 
256     /**
257      * SetCallRestrictionPassword
258      *
259      * @brief Set the call restriction password of the specified account
260      * @param slotId[in] the slot id
261      * @param fac[in] indicate the call restriction type, just like all incoming, all outgoing .etc
262      * @param oldPassword[in] indicate the call restriction old password
263      * @param newPassword[in] indicate the call restriction new password
264      * @return Returns 0 on success, others on failure.
265      */
266     int32_t SetCallRestrictionPassword(
267         int32_t slotId, CallRestrictionType fac, const char *oldPassword, const char *newPassword);
268 
269     /**
270      * SetCallPreferenceMode
271      *
272      * @brief Setting the Call Type
273      * @param slotId[in], The slot id
274      * @param mode[in], Preference Mode
275      * @return Returns 0 on success, others on failure.
276      */
277     int SetCallPreferenceMode(int32_t slotId, int32_t mode);
278 
279     /**
280      * StartRtt
281      *
282      * @brief Enable and send RTT information
283      * @param callInfo[in], Call information.
284      * @param msg[in], RTT information
285      * @return Returns 0 on success, others on failure.
286      */
287     int StartRtt(const CellularCallInfo &callInfo, std::u16string &msg);
288 
289     /**
290      * StopRtt
291      *
292      * @brief Close the RTT
293      * @param callInfo[in], Call information.
294      * @return Returns 0 on success, others on failure.
295      */
296     int StopRtt(const CellularCallInfo &callInfo);
297 
298     /**
299      * RegisterCallBack
300      *
301      * @brief Register callback
302      * @param callback[in], callback function pointer
303      * @return Returns 0 on success, others on failure.
304      */
305     int RegisterCallBack(const sptr<ICallStatusCallback> &callback);
306 
307     /**
308      * @brief UnRegister callback
309      * @return Returns 0 on success, others on failure.
310      */
311     int32_t UnRegisterCallBack();
312 
313     /**
314      * ControlCamera
315      *
316      * @brief Open or close camera
317      * @param slotId[in] the slot id
318      * @param index[in] the index of call
319      * @param cameraId[in] the id of camera
320      * @param callingUid[in] the Uid of call
321      * @param callingPid[in] the Pid of call
322      * @return Returns 0 on success, others on failure.
323      */
324     int32_t ControlCamera(
325         int32_t slotId, int32_t index, std::string &cameraId, int32_t callingUid, int32_t callingPid);
326 
327     /**
328      * SetPreviewWindow
329      *
330      * @brief Set the location and size of the preview window for videos captured by the local camera.
331      * @param slotId[in] the slot id
332      * @param index[in] the index of call
333      * @param surfaceId[in], Window information
334      * @param surface[in], Window information
335      * @return Returns 0 on success, others on failure.
336      */
337     int32_t SetPreviewWindow(int32_t slotId, int32_t index, std::string &surfaceId, sptr<Surface> surface);
338 
339     /**
340      * SetDisplayWindow
341      *
342      * @brief Sets the location and size of the remote video window.
343      * @param slotId[in] the slot id
344      * @param index[in] the index of call
345      * @param surfaceId[in], Window information
346      * @param surface[in], Window information
347      * @return Returns 0 on success, others on failure.
348      */
349     int32_t SetDisplayWindow(int32_t slotId, int32_t index, std::string &surfaceId, sptr<Surface> surface);
350 
351     /**
352      * SetCameraZoom
353      *
354      * @brief Sets the local camera zoom scale
355      * @param zoomRatio[in], Camera scale
356      * @return Returns 0 on success, others on failure.
357      */
358     int32_t SetCameraZoom(float zoomRatio);
359 
360     /**
361      * SetPausePicture
362      *
363      * @brief APP sets the screen of the remote video freeze immediately.
364      * If the APP does not call this interface when making a video call,
365      * the last frame before the remote video freeze is displayed by default
366      * @param slotId[in] the slot id
367      * @param index[in] the index of call
368      * @param path[in], Local Picture address
369      * @return Returns 0 on success, others on failure.
370      */
371     int32_t SetPausePicture(int32_t slotId, int32_t index, std::string &path);
372 
373     /**
374      * SetDeviceDirection
375      *
376      * @brief Set the rotation Angle of the local device. The default value is 0
377      * @param slotId[in] the slot id
378      * @param index[in] the index of call
379      * @param rotation[in], Rotation Angle
380      * @return Returns 0 on success, others on failure.
381      */
382     int32_t SetDeviceDirection(int32_t slotId, int32_t index, int32_t rotation);
383 
384     /**
385      * SetImsSwitchStatus
386      *
387      * @brief Setting Ims Switch
388      * @param slotId[in], The slot id
389      * @param active[in],  On or off
390      * @return Returns 0 on success, others on failure.
391      */
392     int32_t SetImsSwitchStatus(int32_t slotId, bool active);
393 
394     /**
395      * GetImsSwitchStatus
396      *
397      * @brief Getting Ims Switch
398      * @param slotId[in], The slot id
399      * @param enabled[out], The result of enable or not
400      * @return Returns 0 on success, others on failure.
401      */
402     int32_t GetImsSwitchStatus(int32_t slotId, bool &enabled);
403 
404     /**
405      * SetVoNRState
406      *
407      * @brief Setting VoNR Switch
408      * @param slotId[in], The slot id
409      * @param state[in],  On or off
410      * @return Returns 0 on success, others on failure.
411      */
412     int32_t SetVoNRState(int32_t slotId, int32_t state);
413 
414     /**
415      * GetVoNRState
416      *
417      * @brief Getting VoNR Switch
418      * @param slotId[in], The slot id
419      * @param state[out], The result of ON or OFF
420      * @return Returns 0 on success, others on failure.
421      */
422     int32_t GetVoNRState(int32_t slotId, int32_t &state);
423 
424     /**
425      * SendUpdateCallMediaModeRequest
426      *
427      * @brief send update call media request
428      * @param callInfo[in], Call information.
429      * @param mode[in], Calling patterns
430      * @return Returns 0 on success, others on failure.
431      */
432     int32_t SendUpdateCallMediaModeRequest(const CellularCallInfo &callInfo, ImsCallMode mode);
433 
434     /**
435      * SendUpdateCallMediaModeResponse
436      *
437      * @brief send update call media response
438      * @param callInfo[in], Call information.
439      * @param mode[in], Calling patterns
440      * @return Returns 0 on success, others on failure.
441      */
442     int32_t SendUpdateCallMediaModeResponse(const CellularCallInfo &callInfo, ImsCallMode mode);
443 
444     /**
445      * Set Ims Config
446      *
447      * @param ImsConfigItem
448      * @param value
449      * @param slotId
450      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
451      */
452     int32_t SetImsConfig(ImsConfigItem item, const std::string &value, int32_t slotId);
453 
454     /**
455      * Set Ims Config
456      *
457      * @param ImsConfigItem
458      * @param value
459      * @param slotId
460      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
461      */
462     int32_t SetImsConfig(ImsConfigItem item, int32_t value, int32_t slotId);
463 
464     /**
465      * Get Ims Config
466      *
467      * @param ImsConfigItem
468      * @param slotId
469      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
470      */
471     int32_t GetImsConfig(ImsConfigItem item, int32_t slotId);
472 
473     /**
474      * Set Ims Feature Value
475      *
476      * @param FeatureType
477      * @param value
478      * @param slotId
479      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
480      */
481     int32_t SetImsFeatureValue(FeatureType type, int32_t value, int32_t slotId);
482 
483     /**
484      * Get Ims Feature Value
485      *
486      * @param FeatureType
487      * @param slotId
488      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
489      */
490     int32_t GetImsFeatureValue(FeatureType type, int32_t slotId);
491 
492     /**
493      * InviteToConference interface
494      *
495      * @param numberList
496      * @param slotId
497      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
498      */
499     int32_t InviteToConference(const std::vector<std::string> &numberList, int32_t slotId);
500 
501     /**
502      * SetMute
503      *
504      * @param mute
505      * @param slotId
506      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
507      */
508     int32_t SetMute(int32_t mute, int32_t slotId);
509 
510     /**
511      * CloseUnFinishedUssd
512      *
513      * @brief Close Unfinished Ussd function for the current account
514      * @param slotId[in], The slot id
515      * @return Returns 0 on success, others on failure.
516      */
517     int CloseUnFinishedUssd(int32_t slotId);
518 
519     /**
520      * Is Connect cellular call service Object
521      *
522      * @return result for Connect cellular call service
523      */
524     bool IsConnect() const;
525 
526     /**
527      * CancelCallUpgrade
528      *
529      * @brief cancel call upgrade
530      * @param slotId[in] the slot id
531      * @param index[in] the index of call
532      * @return Returns 0 on success, others on failure.
533      */
534     int32_t CancelCallUpgrade(int32_t slotId, int32_t index);
535 
536     /**
537      * RequestCameraCapabilities
538      *
539      * @brief request camera capabilities
540      * @param slotId[in] the slot id
541      * @param index[in] the index of call
542      * @return Returns 0 on success, others on failure.
543      */
544     int32_t RequestCameraCapabilities(int32_t slotId, int32_t index);
545 
546 private:
547     int32_t ConnectService();
548     int32_t RegisterCallBackFun();
549     void DisconnectService();
550     int32_t ReConnectService();
551     void OnDeath();
552     void Clean();
553     void NotifyDeath();
554     int32_t ClearAllCalls();
555 
556 private:
557     class SystemAbilityListener : public SystemAbilityStatusChangeStub {
558     public:
559         SystemAbilityListener() = default;
560         ~SystemAbilityListener() = default;
561         void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
562         void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
563     };
564 
565 private:
566     int32_t systemAbilityId_;
567     sptr<ICallStatusCallback> cellularCallCallbackPtr_;
568     sptr<CellularCallInterface> cellularCallInterfacePtr_;
569     sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
570     bool connectState_;
571     Utils::RWLock rwClientLock_;
572 };
573 } // namespace Telephony
574 } // namespace OHOS
575 
576 #endif
577