Release 4.0.0-preview1-00258
[platform/core/csapi/tizenfx.git] / src / Tizen.CallManager / Tizen.CallManager / CmClientHandle.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Collections.Generic;
19 using System.Runtime.InteropServices;
20 using System.Linq;
21
22 namespace Tizen.CallManager
23 {
24     /// <summary>
25     /// A class which manages call manager events, properties and functions.
26     /// </summary>
27     public class CmClientHandle
28     {
29         internal IntPtr _handle = IntPtr.Zero;
30         private event EventHandler<CallStatusChangedEventArgs> _callStatusChanged;
31         private event EventHandler<CallMuteStatusChangedEventArgs> _callMuteStatusChanged;
32         private event EventHandler<CallEventEventArgs> _callEvent;
33         private event EventHandler<DialStatusEventArgs> _dialStatusChanged;
34         private event EventHandler<AudioStatusChangedEventArgs> _audioStateChanged;
35         private event EventHandler<DtmfIndicationEventArgs> _dtmfIndication;
36         private event EventHandler<EventArgs> _goForeGround;
37         private event EventHandler<VoiceRecordStatusEventArgs> _voiceRecordStatusChanged;
38
39         private Interop.CallManager.CallStatusChangedCallback _callStatusChangedCb;
40         private Interop.CallManager.CallMuteStatusChangedCallback _callMuteStatusChangedCb;
41         private Interop.CallManager.CallEventNotificationCallback _callEventCb;
42         private Interop.CallManager.DialStatusChangedCallback _dialStatusChangedCb;
43         private Interop.CallManager.AudioStateChangedCallback _audioStateChangedCb;
44         private Interop.CallManager.DtmfIndicationChangedCallback _dtmfIndicationChangedCb;
45         private Interop.CallManager.GoForegroundCallback _goForeGroundCb;
46         private Interop.CallManager.VoiceRecordStatusChangedCallback _voiceRecordStatusChangedCb;
47
48         internal CmClientHandle(IntPtr handle)
49         {
50             _handle = handle;
51         }
52
53         /// <summary>
54         /// This event is raised when call status changes.
55         /// </summary>
56         public event EventHandler<CallStatusChangedEventArgs> CallStatusChanged
57         {
58             add
59             {
60                 if (_callStatusChanged == null)
61                 {
62                     RegisterCallStatusChangedEvent();
63                 }
64
65                 _callStatusChanged += value;
66             }
67
68             remove
69             {
70                 _callStatusChanged -= value;
71                 if (_callStatusChanged == null)
72                 {
73                     UnregisterCallStatusChangedEvent();
74                 }
75             }
76         }
77
78         /// <summary>
79         /// This event is raised when the mute status changes.
80         /// </summary>
81         public event EventHandler<CallMuteStatusChangedEventArgs> CallMuteStatusChanged
82         {
83             add
84             {
85                 if (_callMuteStatusChanged == null)
86                 {
87                     RegisterCallMuteStatusChangedEvent();
88                 }
89
90                 _callMuteStatusChanged += value;
91             }
92
93             remove
94             {
95                 _callMuteStatusChanged -= value;
96                 if (_callMuteStatusChanged == null)
97                 {
98                     UnregisterCallMuteStatusChangedEvent();
99                 }
100             }
101         }
102
103         /// <summary>
104         /// This event is raised when call events change.
105         /// </summary>
106         public event EventHandler<CallEventEventArgs> CallEvent
107         {
108             add
109             {
110                 if (_callEvent == null)
111                 {
112                     RegisterCallEventNotification();
113                 }
114
115                 _callEvent += value;
116             }
117
118             remove
119             {
120                 _callEvent -= value;
121                 if (_callEvent == null)
122                 {
123                     UnregisterCallEventNotification();
124                 }
125             }
126         }
127
128         /// <summary>
129         /// This event is raised when dial status changes.
130         /// </summary>
131         public event EventHandler<DialStatusEventArgs> DialStatusChanged
132         {
133             add
134             {
135                 if (_dialStatusChanged == null)
136                 {
137                     RegisterDialStatusEvent();
138                 }
139
140                 _dialStatusChanged += value;
141             }
142
143             remove
144             {
145                 _dialStatusChanged -= value;
146                 if (_dialStatusChanged == null)
147                 {
148                     UnregisterDialStatusEvent();
149                 }
150             }
151         }
152
153         /// <summary>
154         /// This event is raised when audio status changes.
155         /// </summary>
156         public event EventHandler<AudioStatusChangedEventArgs> AudioStateChanged
157         {
158             add
159             {
160                 if (_audioStateChanged == null)
161                 {
162                     RegisterAudioStateChangedEvent();
163                 }
164
165                 _audioStateChanged += value;
166             }
167
168             remove
169             {
170                 _audioStateChanged -= value;
171                 if (_audioStateChanged == null)
172                 {
173                     UnregisterAudioStateChangedEvent();
174                 }
175             }
176         }
177
178         /// <summary>
179         /// This event is raised during DTMF indication.
180         /// </summary>
181         public event EventHandler<DtmfIndicationEventArgs> DtmfIndication
182         {
183             add
184             {
185                 if (_dtmfIndication == null)
186                 {
187                     RegisterDtmfIndicationEvent();
188                 }
189
190                 _dtmfIndication += value;
191             }
192
193             remove
194             {
195                 _dtmfIndication -= value;
196                 if (_dtmfIndication == null)
197                 {
198                     UnregisterDtmfIndicationEvent();
199                 }
200             }
201         }
202
203         /// <summary>
204         /// This event is raised when call comes to foreground.
205         /// </summary>
206         public event EventHandler<EventArgs> GoForeground
207         {
208             add
209             {
210                 if (_goForeGround == null)
211                 {
212                     RegisterGoForegroundEvent();
213                 }
214
215                 _goForeGround += value;
216             }
217
218             remove
219             {
220                 _goForeGround -= value;
221                 if (_goForeGround == null)
222                 {
223                     UnregisterGoForegroundEvent();
224                 }
225             }
226         }
227
228         /// <summary>
229         /// This event is raised when voice record status is changed.
230         /// </summary>
231         public event EventHandler<VoiceRecordStatusEventArgs> VoiceRecordStatusChanged
232         {
233             add
234             {
235                 if (_voiceRecordStatusChanged == null)
236                 {
237                     RegisterVoiceRecordStatusEvent();
238                 }
239
240                 _voiceRecordStatusChanged += value;
241             }
242
243             remove
244             {
245                 _voiceRecordStatusChanged -= value;
246                 if (_voiceRecordStatusChanged == null)
247                 {
248                     UnregisterVoiceRecordStatusEvent();
249                 }
250             }
251         }
252
253         private void RegisterCallStatusChangedEvent()
254         {
255             _callStatusChangedCb = (CallStatus status, IntPtr number, IntPtr userData) =>
256             {
257                 _callStatusChanged?.Invoke(null, new CallStatusChangedEventArgs(status, Marshal.PtrToStringAnsi(number)));
258             };
259             int ret = Interop.CallManager.SetCallStatusCallback(_handle, _callStatusChangedCb, IntPtr.Zero);
260             if (ret != (int)CmError.None)
261             {
262                 Log.Error(CmUtility.LogTag, "Failed to set call status changed callback, Error: " + (CmError)ret);
263                 CmUtility.ThrowCmException(ret, _handle);
264             }
265         }
266
267         private void UnregisterCallStatusChangedEvent()
268         {
269             int ret = Interop.CallManager.UnsetCallstatusCallback(_handle);
270             if (ret != (int)CmError.None)
271             {
272                 Log.Error(CmUtility.LogTag, "Failed to unset call status changed callback, Error: " + (CmError)ret);
273                 CmUtility.ThrowCmException(ret, _handle);
274             }
275         }
276
277         private void RegisterCallMuteStatusChangedEvent()
278         {
279             _callMuteStatusChangedCb = (CallMuteStatus muteStatus, IntPtr userData) =>
280             {
281                 _callMuteStatusChanged?.Invoke(null, new CallMuteStatusChangedEventArgs(muteStatus));
282             };
283             int ret = Interop.CallManager.SetCallMuteStatusCallback(_handle, _callMuteStatusChangedCb, IntPtr.Zero);
284             if (ret != (int)CmError.None)
285             {
286                 Log.Error(CmUtility.LogTag, "Failed to set call mute status changed callback, Error: " + (CmError)ret);
287                 CmUtility.ThrowCmException(ret, _handle);
288             }
289         }
290
291         private void UnregisterCallMuteStatusChangedEvent()
292         {
293             int ret = Interop.CallManager.UnsetCallMuteStatusCallback(_handle);
294             if (ret != (int)CmError.None)
295             {
296                 Log.Error(CmUtility.LogTag, "Failed to unset call mute status changed callback, Error: " + (CmError)ret);
297                 CmUtility.ThrowCmException(ret, _handle);
298             }
299         }
300
301         private void RegisterCallEventNotification()
302         {
303             _callEventCb = (CallEvent callEvent, IntPtr eventData, IntPtr userData) =>
304             {
305                 _callEvent?.Invoke(null, new CallEventEventArgs(callEvent, CmUtility.GetCallEventData(callEvent, eventData)));
306             };
307             int ret = Interop.CallManager.SetCallEventCb(_handle, _callEventCb, IntPtr.Zero);
308             if (ret != (int)CmError.None)
309             {
310                 Log.Error(CmUtility.LogTag, "Failed to set call event notification callback, Error: " + (CmError)ret);
311                 CmUtility.ThrowCmException(ret, _handle);
312             }
313         }
314
315         private void UnregisterCallEventNotification()
316         {
317             int ret = Interop.CallManager.UnsetCallEventCb(_handle);
318             if (ret != (int)CmError.None)
319             {
320                 Log.Error(CmUtility.LogTag, "Failed to unset call event notification callback, Error: " + (CmError)ret);
321                 CmUtility.ThrowCmException(ret, _handle);
322             }
323         }
324
325         private void RegisterDialStatusEvent()
326         {
327             _dialStatusChangedCb = (DialStatus status, IntPtr userData) =>
328             {
329                 _dialStatusChanged?.Invoke(null, new DialStatusEventArgs(status));
330             };
331             int ret = Interop.CallManager.SetDialStatusCb(_handle, _dialStatusChangedCb, IntPtr.Zero);
332             if (ret != (int)CmError.None)
333             {
334                 Log.Error(CmUtility.LogTag, "Failed to set dial status changed callback, Error: " + (CmError)ret);
335                 CmUtility.ThrowCmException(ret, _handle);
336             }
337         }
338
339         private void UnregisterDialStatusEvent()
340         {
341             int ret = Interop.CallManager.UnsetDialStatusCb(_handle);
342             if (ret != (int)CmError.None)
343             {
344                 Log.Error(CmUtility.LogTag, "Failed to unset dial status changed callback, Error: " + (CmError)ret);
345                 CmUtility.ThrowCmException(ret, _handle);
346             }
347         }
348
349         private void RegisterAudioStateChangedEvent()
350         {
351             _audioStateChangedCb = (AudioState state, IntPtr userData) =>
352             {
353                 _audioStateChanged?.Invoke(null, new AudioStatusChangedEventArgs(state));
354             };
355             int ret = Interop.CallManager.SetAudioStateChangedCb(_handle, _audioStateChangedCb, IntPtr.Zero);
356             if (ret != (int)CmError.None)
357             {
358                 Log.Error(CmUtility.LogTag, "Failed to set audio state changed callback, Error: " + (CmError)ret);
359                 CmUtility.ThrowCmException(ret, _handle);
360             }
361         }
362
363         private void UnregisterAudioStateChangedEvent()
364         {
365             int ret = Interop.CallManager.UnsetAudioStateChangedCb(_handle);
366             if (ret != (int)CmError.None)
367             {
368                 Log.Error(CmUtility.LogTag, "Failed to unset audio state changed callback, Error: " + (CmError)ret);
369                 CmUtility.ThrowCmException(ret, _handle);
370             }
371         }
372
373         private void RegisterDtmfIndicationEvent()
374         {
375             _dtmfIndicationChangedCb = (DtmfIndication indiType, string number, IntPtr userData) =>
376             {
377                 _dtmfIndication?.Invoke(null, new DtmfIndicationEventArgs(indiType, number));
378             };
379             int ret = Interop.CallManager.SetDtmfIndicationCb(_handle, _dtmfIndicationChangedCb, IntPtr.Zero);
380             if (ret != (int)CmError.None)
381             {
382                 Log.Error(CmUtility.LogTag, "Failed to set DTMF indication changed callback, Error: " + (CmError)ret);
383                 CmUtility.ThrowCmException(ret, _handle);
384             }
385         }
386
387         private void UnregisterDtmfIndicationEvent()
388         {
389             int ret = Interop.CallManager.UnsetDtmfIndicationCb(_handle);
390             if (ret != (int)CmError.None)
391             {
392                 Log.Error(CmUtility.LogTag, "Failed to unset DTMF indication changed callback, Error: " + (CmError)ret);
393                 CmUtility.ThrowCmException(ret, _handle);
394             }
395         }
396
397         private void RegisterGoForegroundEvent()
398         {
399             _goForeGroundCb = (IntPtr userData) =>
400             {
401                 _goForeGround?.Invoke(null, EventArgs.Empty);
402             };
403             int ret = Interop.CallManager.SetForegroundCb(_handle, _goForeGroundCb, IntPtr.Zero);
404             if (ret != (int)CmError.None)
405             {
406                 Log.Error(CmUtility.LogTag, "Failed to set go foreground callback, Error: " + (CmError)ret);
407                 CmUtility.ThrowCmException(ret, _handle);
408             }
409         }
410
411         private void UnregisterGoForegroundEvent()
412         {
413             int ret = Interop.CallManager.UnsetForegroundCb(_handle);
414             if (ret != (int)CmError.None)
415             {
416                 Log.Error(CmUtility.LogTag, "Failed to unset go foreground callback, Error: " + (CmError)ret);
417                 CmUtility.ThrowCmException(ret, _handle);
418             }
419         }
420
421         private void RegisterVoiceRecordStatusEvent()
422         {
423             _voiceRecordStatusChangedCb = (VrStatus vrStatus, VrStatusExtraType extraType, IntPtr userData) =>
424             {
425                 _voiceRecordStatusChanged?.Invoke(null, new VoiceRecordStatusEventArgs(vrStatus, extraType));
426             };
427             int ret = Interop.CallManager.SetVoiceRecordStatusCb(_handle, _voiceRecordStatusChangedCb, IntPtr.Zero);
428             if (ret != (int)CmError.None)
429             {
430                 Log.Error(CmUtility.LogTag, "Failed to set voice record status changed callback, Error: " + (CmError)ret);
431                 CmUtility.ThrowCmException(ret, _handle);
432             }
433         }
434
435         private void UnregisterVoiceRecordStatusEvent()
436         {
437             int ret = Interop.CallManager.UnsetVoiceRecordStatusCb(_handle);
438             if (ret != (int)CmError.None)
439             {
440                 Log.Error(CmUtility.LogTag, "Failed to unset voice record status changed callback, Error: " + (CmError)ret);
441                 CmUtility.ThrowCmException(ret, _handle);
442             }
443         }
444
445         public CallStatus CallStatus
446         {
447             get
448             {
449                 int ret = Interop.CallManager.GetStatus(_handle, out CallStatus status);
450                 if (ret != (int)CmError.None)
451                 {
452                     Log.Error(CmUtility.LogTag, "Failed to get call status, Error: " + (CmError)ret);
453                     return default(CallStatus);
454                 }
455
456                 return status;
457             }
458         }
459
460         /// <summary>
461         /// Gets the mute status.
462         /// </summary>
463         public CallMuteStatus CallMuteStatus
464         {
465             get
466             {
467                 int ret = Interop.CallManager.GetMuteStatus(_handle, out CallMuteStatus status);
468                 if (ret != (int)CmError.None)
469                 {
470                     Log.Error(CmUtility.LogTag, "Failed to get call mute status, Error: " + (CmError)ret);
471                     return default(CallMuteStatus);
472                 }
473
474                 return status;
475             }
476         }
477
478         /// <summary>
479         /// Gets the audio state.
480         /// </summary>
481         public AudioState AudioState
482         {
483             get
484             {
485                 int ret = Interop.CallManager.GetAudioState(_handle, out AudioState state);
486                 if (ret != (int)CmError.None)
487                 {
488                     Log.Error(CmUtility.LogTag, "Failed to get audio state, Error: " + (CmError)ret);
489                     return default(AudioState);
490                 }
491
492                 return state;
493             }
494         }
495
496         /// <summary>
497         /// Gets the list of call data.
498         /// </summary>
499         public IEnumerable<CallData> AllCalls
500         {
501             get
502             {
503                 int ret = Interop.CallManager.GetAllCallList(_handle, out IntPtr list);
504                 if (ret != (int)CmError.None)
505                 {
506                     Log.Error(CmUtility.LogTag, "Failed to get all call list, Error: " + (CmError)ret);
507                     return null;
508                 }
509
510                 int length = Interop.GsList.GetLength(list);
511                 if (length == 0)
512                 {
513                     Log.Debug(CmUtility.LogTag, "Call list is empty");
514                     return Enumerable.Empty<CallData>();
515                 }
516
517                 List<CallData> callList = new List<CallData>();
518                 IntPtr callData = IntPtr.Zero;
519                 for (int index = 0; index < length; index++)
520                 {
521                     callData = Interop.GsList.GetDataByIndex(list, index);
522                     if (callData != IntPtr.Zero)
523                     {
524                         callList.Add(CmUtility.GetCallData(callData));
525                     }
526                 }
527
528                 return callList;
529             }
530         }
531
532         /// <summary>
533         /// Gets the list of conference call data.
534         /// </summary>
535         public IEnumerable<ConferenceCallData> AllConferenceCalls
536         {
537             get
538             {
539                 int ret = Interop.CallManager.GetConferenceCallList(_handle, out IntPtr list);
540                 if (ret != (int)CmError.None)
541                 {
542                     Log.Error(CmUtility.LogTag, "Failed to get conference call list, Error: " + (CmError)ret);
543                     return null;
544                 }
545
546                 int length = Interop.GsList.GetLength(list);
547                 if (length == 0)
548                 {
549                     Log.Debug(CmUtility.LogTag, "Conf call list is empty");
550                     return Enumerable.Empty<ConferenceCallData>();
551                 }
552                 List<ConferenceCallData> confList = new List<ConferenceCallData>();
553                 IntPtr confData = IntPtr.Zero;
554                 for (int index = 0; index < length; index++)
555                 {
556                     confData = Interop.GsList.GetDataByIndex(list, index);
557                     if (confData != IntPtr.Zero)
558                     {
559                         confList.Add(CmUtility.GetConfCallData(confData));
560                     }
561                 }
562
563                 return confList;
564             }
565         }
566
567         /// <summary>
568         /// Rejects the incoming call.
569         /// </summary>
570         /// <privlevel>partner</privlevel>
571         /// <privilege>http://developer.samsung.com/tizen/privilege/call.reject</privilege>
572         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
573         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
574         public void RejectCall()
575         {
576             int ret = Interop.CallManager.RejectCall(_handle);
577             if (ret != (int)CmError.None)
578             {
579                 Log.Error(CmUtility.LogTag, "Failed to reject call, Error: " + (CmError)ret);
580                 CmUtility.ThrowCmException(ret, _handle, "http://developer.samsung.com/tizen/privilege/call.reject");
581             }
582         }
583
584         /// <summary>
585         /// Starts incoming call alert ringtone.
586         /// </summary>
587         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
588         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
589         public void StartAlert()
590         {
591             int ret = Interop.CallManager.StartAlert(_handle);
592             if (ret != (int)CmError.None)
593             {
594                 Log.Error(CmUtility.LogTag, "Failed to start incoming call alert, Error: " + (CmError)ret);
595                 CmUtility.ThrowCmException(ret, _handle);
596             }
597         }
598
599         /// <summary>
600         /// Stops incoming call alert ringtone.
601         /// </summary>
602         /// <privlevel>partner</privlevel>
603         /// <privilege>http://developer.samsung.com/tizen/privilege/call.reject</privilege>
604         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
605         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
606         public void StopAlert()
607         {
608             int ret = Interop.CallManager.StopAlert(_handle);
609             if (ret != (int)CmError.None)
610             {
611                 Log.Error(CmUtility.LogTag, "Failed to stop incoming call alert, Error: " + (CmError)ret);
612                 CmUtility.ThrowCmException(ret, _handle, "http://developer.samsung.com/tizen/privilege/call.reject");
613             }
614         }
615
616         /// <summary>
617         /// Enables call recovery.
618         /// </summary>
619         /// <param name="appId">App ID to be recovered.</param>
620         /// <exception cref="ArgumentNullException">Thrown appId is passed as null.</exception>
621         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
622         public void EnableRecovery(string appId)
623         {
624             if (appId == null)
625             {
626                 throw new ArgumentNullException("App ID is null");
627             }
628
629             int ret = Interop.CallManager.EnableRecovery(_handle, appId);
630             if (ret != (int)CmError.None)
631             {
632                 Log.Error(CmUtility.LogTag, "Failed to enable recovery, Error: " + (CmError)ret);
633                 CmUtility.ThrowCmException(ret, _handle);
634             }
635         }
636
637         /// <summary>
638         /// Dials a call.
639         /// </summary>
640         /// <param name="number">Calling number to be dialed.</param>
641         /// <param name="type">Type of the call to be dialed.</param>
642         /// <param name="slot">Multi sim slot type in which the call is dialed.</param>
643         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
644         /// <exception cref="ArgumentNullException">Thrown number is passed as null.</exception>
645         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
646         public void DialCall(string number, CallType type, MultiSimSlot slot)
647         {
648             if (number == null)
649             {
650                 throw new ArgumentNullException("Calling number is null");
651             }
652
653             int ret = Interop.CallManager.DialCall(_handle, number, type, slot);
654             if (ret != (int)CmError.None)
655             {
656                 Log.Error(CmUtility.LogTag, "Failed to dial call, Error: " + (CmError)ret);
657                 CmUtility.ThrowCmException(ret, _handle);
658             }
659         }
660
661         /// <summary>
662         /// Swaps the calls.
663         /// </summary>
664         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
665         public void SwapCall()
666         {
667             int ret = Interop.CallManager.SwapCall(_handle);
668             if (ret != (int)CmError.None)
669             {
670                 Log.Error(CmUtility.LogTag, "Failed to swap call, Error: " + (CmError)ret);
671                 CmUtility.ThrowCmException(ret, _handle);
672             }
673         }
674
675         /// <summary>
676         /// Joins a call with another.
677         /// </summary>
678         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
679         public void JoinCall()
680         {
681             int ret = Interop.CallManager.JoinCall(_handle);
682             if (ret != (int)CmError.None)
683             {
684                 Log.Error(CmUtility.LogTag, "Failed to join call, Error: " + (CmError)ret);
685                 CmUtility.ThrowCmException(ret, _handle);
686             }
687         }
688
689         /// <summary>
690         /// Splits a call.
691         /// </summary>
692         /// <param name="id">Call id to be splitted.</param>
693         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
694         public void SplitCall(uint id)
695         {
696             int ret = Interop.CallManager.SplitCall(_handle, id);
697             if (ret != (int)CmError.None)
698             {
699                 Log.Error(CmUtility.LogTag, "Failed to split call, Error: " + (CmError)ret);
700                 CmUtility.ThrowCmException(ret, _handle);
701             }
702         }
703
704         /// <summary>
705         /// Transfers a call.
706         /// </summary>
707         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
708         public void TransferCall()
709         {
710             int ret = Interop.CallManager.TransferCall(_handle);
711             if (ret != (int)CmError.None)
712             {
713                 Log.Error(CmUtility.LogTag, "Failed to transfer call, Error: " + (CmError)ret);
714                 CmUtility.ThrowCmException(ret, _handle);
715             }
716         }
717
718         /// <summary>
719         /// Accepts MT ViLTE call as VoLTE.
720         /// </summary>
721         /// <param name="answerType">Call answer type.</param>
722         /// <param name="type">Call type.</param>
723         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
724         public void AnswerCallEx(CallAnswerType answerType, CallType type)
725         {
726             int ret = Interop.CallManager.AnswerCallEx(_handle, answerType, type);
727             if (ret != (int)CmError.None)
728             {
729                 Log.Error(CmUtility.LogTag, "Failed to answer call, Error: " + (CmError)ret);
730                 CmUtility.ThrowCmException(ret, _handle);
731             }
732         }
733
734         /// <summary>
735         /// Answers an incoming call.
736         /// </summary>
737         /// <param name="answerType">Call answer type.</param>
738         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
739         public void AnswerCall(CallAnswerType answerType)
740         {
741             int ret = Interop.CallManager.AnswerCall(_handle, answerType);
742             if (ret != (int)CmError.None)
743             {
744                 Log.Error(CmUtility.LogTag, "Failed to answer call, Error: " + (CmError)ret);
745                 CmUtility.ThrowCmException(ret, _handle);
746             }
747         }
748
749         /// <summary>
750         /// Upgrades a call.
751         /// </summary>
752         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
753         public void UpgradeCall()
754         {
755             int ret = Interop.CallManager.UpgradeCall(_handle);
756             if (ret != (int)CmError.None)
757             {
758                 Log.Error(CmUtility.LogTag, "Failed to upgrade call, Error: " + (CmError)ret);
759                 CmUtility.ThrowCmException(ret, _handle);
760             }
761         }
762
763         /// <summary>
764         /// Downgrades a call.
765         /// </summary>
766         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
767         public void DowngradeCall()
768         {
769             int ret = Interop.CallManager.DowngradeCall(_handle);
770             if (ret != (int)CmError.None)
771             {
772                 Log.Error(CmUtility.LogTag, "Failed to downgrade call, Error: " + (CmError)ret);
773                 CmUtility.ThrowCmException(ret, _handle);
774             }
775         }
776
777         /// <summary>
778         /// Confirms upgrade call request.
779         /// </summary>
780         /// <param name="response">Upgrade response type.</param>
781         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
782         public void ConfirmUpgradeCall(CallUpgradeResponseType response)
783         {
784             int ret = Interop.CallManager.ConfirmUpgradeCall(_handle, response);
785             if (ret != (int)CmError.None)
786             {
787                 Log.Error(CmUtility.LogTag, "Failed to confirm upgrade call, Error: " + (CmError)ret);
788                 CmUtility.ThrowCmException(ret, _handle);
789             }
790         }
791
792         /// <summary>
793         /// Sets the speaker on/off.
794         /// </summary>
795         /// <param name="status">Status of the speaker to be set.</param>
796         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
797         public void ManageSpeaker(FeatureStatus status)
798         {
799             int ret = -1;
800             if (status == FeatureStatus.Off)
801             {
802                 ret = Interop.CallManager.SpeakerOff(_handle);
803             }
804
805             else if (status == FeatureStatus.On)
806             {
807                 ret = Interop.CallManager.SpeakerOn(_handle);
808             }
809
810             if (ret != (int)CmError.None)
811             {
812                 Log.Error(CmUtility.LogTag, "Failed to manage speaker, Error: " + (CmError)ret);
813                 CmUtility.ThrowCmException(ret, _handle);
814             }
815         }
816
817         /// <summary>
818         /// Sets the bluetooth feature on/off.
819         /// </summary>
820         /// <param name="status">Status of the bluetooth to be set.</param>
821         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
822         public void ManageBluetooth(FeatureStatus status)
823         {
824             int ret = -1;
825             if (status == FeatureStatus.Off)
826             {
827                 ret = Interop.CallManager.BluetoothOff(_handle);
828             }
829
830             else if (status == FeatureStatus.On)
831             {
832                 ret = Interop.CallManager.BluetoothOn(_handle);
833             }
834
835             if (ret != (int)CmError.None)
836             {
837                 Log.Error(CmUtility.LogTag, "Failed to manage bluetooth, Error: " + (CmError)ret);
838                 CmUtility.ThrowCmException(ret, _handle);
839             }
840         }
841
842         /// <summary>
843         /// Sets extra volume if needed.
844         /// </summary>
845         /// <param name="isExtraVolume">Boolean value to indicate if the call is set to have extra volume.</param>
846         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
847         public void SetExtraVolume(bool isExtraVolume)
848         {
849             int ret = Interop.CallManager.SetExtraVolume(_handle, isExtraVolume);
850             if (ret != (int)CmError.None)
851             {
852                 Log.Error(CmUtility.LogTag, "Failed to set extra volume, Error: " + (CmError)ret);
853                 CmUtility.ThrowCmException(ret, _handle);
854             }
855         }
856
857         /// <summary>
858         /// Sets the noise reduction feature during call.
859         /// </summary>
860         /// <param name="isNoiceReduction">Boolean value to indicate whether the call needs noise reduction.</param>
861         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
862         public void SetNoiseReduction(bool isNoiceReduction)
863         {
864             int ret = Interop.CallManager.SetNoiseReduction(_handle, isNoiceReduction);
865             if (ret != (int)CmError.None)
866             {
867                 Log.Error(CmUtility.LogTag, "Failed to set noise reduction, Error: " + (CmError)ret);
868                 CmUtility.ThrowCmException(ret, _handle);
869             }
870         }
871
872         /// <summary>
873         /// Sets the mute state of the call.
874         /// </summary>
875         /// <param name="isMuteState">Mute state to be set.</param>
876         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
877         public void SetMuteState(bool isMuteState)
878         {
879             int ret = Interop.CallManager.SetMuteState(_handle, isMuteState);
880             if (ret != (int)CmError.None)
881             {
882                 Log.Error(CmUtility.LogTag, "Failed to set mute state, Error: " + (CmError)ret);
883                 CmUtility.ThrowCmException(ret, _handle);
884             }
885         }
886
887         /// <summary>
888         /// Starts sending signal through DTMF digit.
889         /// </summary>
890         /// <param name="dtmfDigit">DTMF digit to be pressed on the phone.</param>
891         /// <exception cref="ArgumentException">Thrown when method failed due to invalid parameter.</exception>
892         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
893         public void StartDtmf(byte dtmfDigit)
894         {
895             int ret = Interop.CallManager.StartDtmf(_handle, dtmfDigit);
896             if (ret != (int)CmError.None)
897             {
898                 Log.Error(CmUtility.LogTag, "Failed to start DTMF, Error: " + (CmError)ret);
899                 CmUtility.ThrowCmException(ret, _handle);
900             }
901         }
902
903         /// <summary>
904         /// Stops sending DTMF signal.
905         /// </summary>
906         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
907         public void StopDtmf()
908         {
909             int ret = Interop.CallManager.StopDtmf(_handle);
910             if (ret != (int)CmError.None)
911             {
912                 Log.Error(CmUtility.LogTag, "Failed to stop DTMF, Error: " + (CmError)ret);
913                 CmUtility.ThrowCmException(ret, _handle);
914             }
915         }
916
917         /// <summary>
918         /// Sends signal through DTMF digits.
919         /// </summary>
920         /// <param name="dtmfDigits">DTMF digits.</param>
921         /// <exception cref="ArgumentNullException">Thrown when dtmfDigits is passed as null.</exception>
922         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
923         public void BurstDtmf(string dtmfDigits)
924         {
925             if (dtmfDigits == null)
926             {
927                 throw new ArgumentNullException("DTMF digits is null");
928             }
929
930             int ret = Interop.CallManager.BurstDtmf(_handle, dtmfDigits);
931             if (ret != (int)CmError.None)
932             {
933                 Log.Error(CmUtility.LogTag, "Failed to burst DTMF, Error: " + (CmError)ret);
934                 CmUtility.ThrowCmException(ret, _handle);
935             }
936         }
937
938         /// <summary>
939         /// Sends DTMF response.
940         /// </summary>
941         /// <param name="response">DTMF response type.</param>
942         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
943         public void SendDtmfResponse(DtmfResponseType response)
944         {
945             int ret = Interop.CallManager.SendDtmfResponse(_handle, response);
946             if (ret != (int)CmError.None)
947             {
948                 Log.Error(CmUtility.LogTag, "Failed to send DTMF response, Error: " + (CmError)ret);
949                 CmUtility.ThrowCmException(ret, _handle);
950             }
951         }
952
953         /// <summary>
954         /// Activates call manager UI.
955         /// </summary>
956         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
957         public void ActivateUi()
958         {
959             int ret = Interop.CallManager.ActivateUi(_handle);
960             if (ret != (int)CmError.None)
961             {
962                 Log.Error(CmUtility.LogTag, "Failed to activate UI, Error: " + (CmError)ret);
963                 CmUtility.ThrowCmException(ret, _handle);
964             }
965         }
966
967         /// <summary>
968         /// Sets device LCD time out.
969         /// </summary>
970         /// <param name="timeout">LCD timeout to be set.</param>
971         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
972         public void SetLcdTimeout(LcdTimeOut timeout)
973         {
974             int ret = Interop.CallManager.SetLcdTimeOut(_handle, timeout);
975             if (ret != (int)CmError.None)
976             {
977                 Log.Error(CmUtility.LogTag, "Failed to set LCD timeout, Error: " + (CmError)ret);
978                 CmUtility.ThrowCmException(ret, _handle);
979             }
980         }
981
982         /// <summary>
983         /// Starts voice recording.
984         /// </summary>
985         /// <param name="number">Call number.</param>
986         /// <exception cref="ArgumentNullException">Thrown when number is passed as null.</exception>
987         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
988         public void StartVoiceRecord(string number)
989         {
990             if (number == null)
991             {
992                 throw new ArgumentNullException("Call number is null");
993             }
994
995             int ret = Interop.CallManager.StartVoiceRecord(_handle, number);
996             if (ret != (int)CmError.None)
997             {
998                 Log.Error(CmUtility.LogTag, "Failed to start voice record, Error: " + (CmError)ret);
999                 CmUtility.ThrowCmException(ret, _handle);
1000             }
1001         }
1002
1003         /// <summary>
1004         /// Stops voice record.
1005         /// </summary>
1006         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
1007         public void StopVoiceRecord()
1008         {
1009             int ret = Interop.CallManager.StopVoiceRecord(_handle);
1010             if (ret != (int)CmError.None)
1011             {
1012                 Log.Error(CmUtility.LogTag, "Failed to stop voice record, Error: " + (CmError)ret);
1013                 CmUtility.ThrowCmException(ret, _handle);
1014             }
1015         }
1016
1017         /// <summary>
1018         /// Gets all current call data.
1019         /// </summary>
1020         /// <param name="incoming">Incoming calldata instance to be filled.</param>
1021         /// <param name="active">Active calldata instance to be filled.</param>
1022         /// <param name="held">Held calldata instance to be filled.</param>
1023         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
1024         public void GetAllCallData(out CallData incoming, out CallData active, out CallData held)
1025         {
1026             int ret = Interop.CallManager.GetAllCallData(_handle, out IntPtr incomingCall, out IntPtr activeCall, out IntPtr heldCall);
1027             if (ret != (int)CmError.None)
1028             {
1029                 Log.Error(CmUtility.LogTag, "Failed to get all call data, Error: " + (CmError)ret);
1030                 CmUtility.ThrowCmException(ret, _handle);
1031             }
1032
1033             incoming = CmUtility.GetCallData(incomingCall);
1034             active = CmUtility.GetCallData(activeCall);
1035             held = CmUtility.GetCallData(heldCall);
1036         }
1037
1038         /// <summary>
1039         /// Holds the active call.
1040         /// </summary>
1041         /// <privlevel>platform</privlevel>
1042         /// <privilege>http://developer.samsung.com/tizen/privilege/call.admin</privilege>
1043         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1044         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
1045         public void HoldCall()
1046         {
1047             int ret = Interop.CallManager.HoldCall(_handle);
1048             if (ret != (int)CmError.None)
1049             {
1050                 Log.Error(CmUtility.LogTag, "Failed to hold call, Error: " + (CmError)ret);
1051                 CmUtility.ThrowCmException(ret, _handle, "http://developer.samsung.com/tizen/privilege/call.admin");
1052             }
1053         }
1054
1055         /// <summary>
1056         /// Unholds the active call.
1057         /// </summary>
1058         /// <privlevel>platform</privlevel>
1059         /// <privilege>http://developer.samsung.com/tizen/privilege/call.admin</privilege>
1060         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1061         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
1062         public void UnholdCall()
1063         {
1064             int ret = Interop.CallManager.UnholdCall(_handle);
1065             if (ret != (int)CmError.None)
1066             {
1067                 Log.Error(CmUtility.LogTag, "Failed to unhold call, Error: " + (CmError)ret);
1068                 CmUtility.ThrowCmException(ret, _handle, "http://developer.samsung.com/tizen/privilege/call.admin");
1069             }
1070         }
1071
1072         /// <summary>
1073         /// Ends ongoing call.
1074         /// </summary>
1075         /// <param name="id">ID of the call which is to be ended.</param>
1076         /// <param name="type">Call release type.</param>
1077         /// <privlevel>platform</privlevel>
1078         /// <privilege>http://developer.samsung.com/tizen/privilege/call.admin</privilege>
1079         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1080         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
1081         public void EndCall(uint id, CallReleaseType type)
1082         {
1083             int ret = Interop.CallManager.EndCall(_handle, id, type);
1084             if (ret != (int)CmError.None)
1085             {
1086                 Log.Error(CmUtility.LogTag, "Failed to end call, Error: " + (CmError)ret);
1087                 CmUtility.ThrowCmException(ret, _handle, "http://developer.samsung.com/tizen/privilege/call.admin");
1088             }
1089         }
1090     }
1091 }