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