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