• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ffrt.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      * GetVideoCallWaiting
238      *
239      * @brief Gets whether the call waiting service of the current account is enabled
240      * @param slotId[in], The slot id
241      * @param enabled
242      * @return Returns 0 on success, others on failure.
243      */
244     int GetVideoCallWaiting(int32_t slotId, bool &enabled);
245 
246     /**
247      * SetCallRestriction
248      *
249      * @brief Set the call restriction function for the current account
250      * @param info[in], Call restriction information
251      * @param slotId[in], The slot id
252      * @return Returns 0 on success, others on failure.
253      */
254     int SetCallRestriction(const CallRestrictionInfo &info, int32_t slotId);
255 
256     /**
257      * GetCallRestriction
258      *
259      * @brief Gets the call restriction information of the specified account
260      * @param facType[in], Call Restriction type
261      * @param slotId[in], The slot id
262      * @return Returns 0 on success, others on failure.
263      */
264     int GetCallRestriction(CallRestrictionType facType, int32_t slotId);
265 
266     /**
267      * SetCallRestrictionPassword
268      *
269      * @brief Set the call restriction password of the specified account
270      * @param slotId[in] the slot id
271      * @param fac[in] indicate the call restriction type, just like all incoming, all outgoing .etc
272      * @param oldPassword[in] indicate the call restriction old password
273      * @param newPassword[in] indicate the call restriction new password
274      * @return Returns 0 on success, others on failure.
275      */
276     int32_t SetCallRestrictionPassword(
277         int32_t slotId, CallRestrictionType fac, const char *oldPassword, const char *newPassword);
278 
279     /**
280      * SetCallPreferenceMode
281      *
282      * @brief Setting the Call Type
283      * @param slotId[in], The slot id
284      * @param mode[in], Preference Mode
285      * @return Returns 0 on success, others on failure.
286      */
287     int SetCallPreferenceMode(int32_t slotId, int32_t mode);
288 
289     /**
290      * StartRtt
291      *
292      * @brief Enable and send RTT information
293      * @param callInfo[in], Call information.
294      * @param msg[in], RTT information
295      * @return Returns 0 on success, others on failure.
296      */
297     int StartRtt(const CellularCallInfo &callInfo, std::u16string &msg);
298 
299     /**
300      * StopRtt
301      *
302      * @brief Close the RTT
303      * @param callInfo[in], Call information.
304      * @return Returns 0 on success, others on failure.
305      */
306     int StopRtt(const CellularCallInfo &callInfo);
307 
308     /**
309      * RegisterCallBack
310      *
311      * @brief Register callback
312      * @param callback[in], callback function pointer
313      * @return Returns 0 on success, others on failure.
314      */
315     int RegisterCallBack(const sptr<ICallStatusCallback> &callback);
316 
317     /**
318      * @brief UnRegister callback
319      * @return Returns 0 on success, others on failure.
320      */
321     int32_t UnRegisterCallBack();
322 
323     /**
324      * ControlCamera
325      *
326      * @brief Open or close camera
327      * @param slotId[in] the slot id
328      * @param index[in] the index of call
329      * @param cameraId[in] the id of camera
330      * @param callingUid[in] the Uid of call
331      * @param callingPid[in] the Pid of call
332      * @return Returns 0 on success, others on failure.
333      */
334     int32_t ControlCamera(
335         int32_t slotId, int32_t index, std::string &cameraId, int32_t callingUid, int32_t callingPid);
336 
337     /**
338      * SetPreviewWindow
339      *
340      * @brief Set the location and size of the preview window for videos captured by the local camera.
341      * @param slotId[in] the slot id
342      * @param index[in] the index of call
343      * @param surfaceId[in], Window information
344      * @param surface[in], Window information
345      * @return Returns 0 on success, others on failure.
346      */
347     int32_t SetPreviewWindow(int32_t slotId, int32_t index, std::string &surfaceId, sptr<Surface> surface);
348 
349     /**
350      * SetDisplayWindow
351      *
352      * @brief Sets the location and size of the remote video window.
353      * @param slotId[in] the slot id
354      * @param index[in] the index of call
355      * @param surfaceId[in], Window information
356      * @param surface[in], Window information
357      * @return Returns 0 on success, others on failure.
358      */
359     int32_t SetDisplayWindow(int32_t slotId, int32_t index, std::string &surfaceId, sptr<Surface> surface);
360 
361     /**
362      * SetCameraZoom
363      *
364      * @brief Sets the local camera zoom scale
365      * @param zoomRatio[in], Camera scale
366      * @return Returns 0 on success, others on failure.
367      */
368     int32_t SetCameraZoom(float zoomRatio);
369 
370     /**
371      * SetPausePicture
372      *
373      * @brief APP sets the screen of the remote video freeze immediately.
374      * If the APP does not call this interface when making a video call,
375      * the last frame before the remote video freeze is displayed by default
376      * @param slotId[in] the slot id
377      * @param index[in] the index of call
378      * @param path[in], Local Picture address
379      * @return Returns 0 on success, others on failure.
380      */
381     int32_t SetPausePicture(int32_t slotId, int32_t index, std::string &path);
382 
383     /**
384      * SetDeviceDirection
385      *
386      * @brief Set the rotation Angle of the local device. The default value is 0
387      * @param slotId[in] the slot id
388      * @param index[in] the index of call
389      * @param rotation[in], Rotation Angle
390      * @return Returns 0 on success, others on failure.
391      */
392     int32_t SetDeviceDirection(int32_t slotId, int32_t index, int32_t rotation);
393 
394     /**
395      * SetImsSwitchStatus
396      *
397      * @brief Setting Ims Switch
398      * @param slotId[in], The slot id
399      * @param active[in],  On or off
400      * @return Returns 0 on success, others on failure.
401      */
402     int32_t SetImsSwitchStatus(int32_t slotId, bool active);
403 
404     /**
405      * GetImsSwitchStatus
406      *
407      * @brief Getting Ims Switch
408      * @param slotId[in], The slot id
409      * @param enabled[out], The result of enable or not
410      * @return Returns 0 on success, others on failure.
411      */
412     int32_t GetImsSwitchStatus(int32_t slotId, bool &enabled);
413 
414     /**
415      * GetCarrierVtConfig
416      *
417      * @brief Getting Carrier Vt Config
418      * @param slotId[in], The slot id
419      * @param enabled[out], The result of enable or not
420      * @return Returns 0 on success, others on failure.
421      */
422     int32_t GetCarrierVtConfig(int32_t slotId, bool &enabled);
423 
424     /**
425      * SetVoNRState
426      *
427      * @brief Setting VoNR Switch
428      * @param slotId[in], The slot id
429      * @param state[in],  On or off
430      * @return Returns 0 on success, others on failure.
431      */
432     int32_t SetVoNRState(int32_t slotId, int32_t state);
433 
434     /**
435      * GetVoNRState
436      *
437      * @brief Getting VoNR Switch
438      * @param slotId[in], The slot id
439      * @param state[out], The result of ON or OFF
440      * @return Returns 0 on success, others on failure.
441      */
442     int32_t GetVoNRState(int32_t slotId, int32_t &state);
443 
444     /**
445      * SendUpdateCallMediaModeRequest
446      *
447      * @brief send update call media request
448      * @param callInfo[in], Call information.
449      * @param mode[in], Calling patterns
450      * @return Returns 0 on success, others on failure.
451      */
452     int32_t SendUpdateCallMediaModeRequest(const CellularCallInfo &callInfo, ImsCallMode mode);
453 
454     /**
455      * SendUpdateCallMediaModeResponse
456      *
457      * @brief send update call media response
458      * @param callInfo[in], Call information.
459      * @param mode[in], Calling patterns
460      * @return Returns 0 on success, others on failure.
461      */
462     int32_t SendUpdateCallMediaModeResponse(const CellularCallInfo &callInfo, ImsCallMode mode);
463 
464     /**
465      * Set Ims Config
466      *
467      * @param ImsConfigItem
468      * @param value
469      * @param slotId
470      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
471      */
472     int32_t SetImsConfig(ImsConfigItem item, const std::string &value, int32_t slotId);
473 
474     /**
475      * Set Ims Config
476      *
477      * @param ImsConfigItem
478      * @param value
479      * @param slotId
480      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
481      */
482     int32_t SetImsConfig(ImsConfigItem item, int32_t value, int32_t slotId);
483 
484     /**
485      * Get Ims Config
486      *
487      * @param ImsConfigItem
488      * @param slotId
489      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
490      */
491     int32_t GetImsConfig(ImsConfigItem item, int32_t slotId);
492 
493     /**
494      * Set Ims Feature Value
495      *
496      * @param FeatureType
497      * @param value
498      * @param slotId
499      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
500      */
501     int32_t SetImsFeatureValue(FeatureType type, int32_t value, int32_t slotId);
502 
503     /**
504      * Get Ims Feature Value
505      *
506      * @param FeatureType
507      * @param slotId
508      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
509      */
510     int32_t GetImsFeatureValue(FeatureType type, int32_t slotId);
511 
512     /**
513      * InviteToConference interface
514      *
515      * @param numberList
516      * @param slotId
517      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
518      */
519     int32_t InviteToConference(const std::vector<std::string> &numberList, int32_t slotId);
520 
521     /**
522      * SetMute
523      *
524      * @param mute
525      * @param slotId
526      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
527      */
528     int32_t SetMute(int32_t mute, int32_t slotId);
529 
530     /**
531      * CloseUnFinishedUssd
532      *
533      * @brief Close Unfinished Ussd function for the current account
534      * @param slotId[in], The slot id
535      * @return Returns 0 on success, others on failure.
536      */
537     int CloseUnFinishedUssd(int32_t slotId);
538 
539     /**
540      * Is Connect cellular call service Object
541      *
542      * @return result for Connect cellular call service
543      */
544     bool IsConnect() const;
545 
546     /**
547      * CancelCallUpgrade
548      *
549      * @brief cancel call upgrade
550      * @param slotId[in] the slot id
551      * @param index[in] the index of call
552      * @return Returns 0 on success, others on failure.
553      */
554     int32_t CancelCallUpgrade(int32_t slotId, int32_t index);
555 
556     /**
557      * RequestCameraCapabilities
558      *
559      * @brief request camera capabilities
560      * @param slotId[in] the slot id
561      * @param index[in] the index of call
562      * @return Returns 0 on success, others on failure.
563      */
564     int32_t RequestCameraCapabilities(int32_t slotId, int32_t index);
565 
566     /**
567      * @brief send ussd response to modem
568      *
569      * @param slotId[in] the slot id
570      * @param content[in] the content need send to modem
571      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
572      */
573     int32_t SendUssdResponse(int32_t slotId, const std::string &content);
574 
575     /**
576      * @brief is mmi code
577      *
578      * @param slotId[in] the slot id
579      * @param number[in] the phone number
580      * @return Returns true on phone number is mmi code, else return false.
581      */
582     bool IsMmiCode(int32_t slotId, std::string &number);
583 
584 private:
585     int32_t ConnectService();
586     int32_t RegisterCallBackFun();
587     void DisconnectService();
588     int32_t ReConnectService();
589     void OnDeath();
590     void Clean();
591     void NotifyDeath();
592     int32_t ClearAllCalls();
593 
594 private:
595     class SystemAbilityListener : public SystemAbilityStatusChangeStub {
596     public:
597         SystemAbilityListener() = default;
598         ~SystemAbilityListener() = default;
599         void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
600         void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
601     };
602 
603 private:
604     int32_t systemAbilityId_;
605     sptr<ICallStatusCallback> cellularCallCallbackPtr_;
606     sptr<CellularCallInterface> cellularCallInterfacePtr_;
607     sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
608     bool connectState_;
609     ffrt::shared_mutex clientLock_;
610 };
611 } // namespace Telephony
612 } // namespace OHOS
613 
614 #endif
615