Release 4.0.1.14150
[platform/core/csapi/tizenfx.git] / test / Tizen.CallManager.Test / MainPage.cs
1 using System;
2 using System.Threading.Tasks;
3 using System.Collections.Generic;
4 using System.Linq;
5 using Xamarin.Forms;
6 using Tizen;
7 using Tizen.CallManager;
8
9 namespace XamarinForTizen.Tizen
10 {
11     public class MainPage : ContentPage
12     {
13         public MainPage()
14         {
15             var initBtn = new Button
16             {
17                 Text = "Initialize",
18                 VerticalOptions = LayoutOptions.Start,
19                 HorizontalOptions = LayoutOptions.FillAndExpand
20             };
21             initBtn.Clicked += initBtn_Clicked;
22
23             var dialBtn = new Button
24             {
25                 Text = "Dial & end voice call",
26                 VerticalOptions = LayoutOptions.Start,
27                 HorizontalOptions = LayoutOptions.FillAndExpand
28             };
29             dialBtn.Clicked += dialBtn_Clicked;
30
31             var holdBtn = new Button
32             {
33                 Text = "Hold & unhold voice call",
34                 VerticalOptions = LayoutOptions.Start,
35                 HorizontalOptions = LayoutOptions.FillAndExpand
36             };
37             holdBtn.Clicked += holdBtn_Clicked;
38
39             var answerBtn = new Button
40             {
41                 Text = "Answer incoming call",
42                 VerticalOptions = LayoutOptions.Start,
43                 HorizontalOptions = LayoutOptions.FillAndExpand
44             };
45             answerBtn.Clicked += answerBtn_Clicked;
46
47             var alertBtn = new Button
48             {
49                 Text = "Start & Stop alert",
50                 VerticalOptions = LayoutOptions.Start,
51                 HorizontalOptions = LayoutOptions.FillAndExpand
52             };
53             alertBtn.Clicked += alertBtn_Clicked;
54
55             var rejectBtn = new Button
56             {
57                 Text = "Reject incoming call",
58                 VerticalOptions = LayoutOptions.Start,
59                 HorizontalOptions = LayoutOptions.FillAndExpand
60             };
61             rejectBtn.Clicked += rejectBtn_Clicked;
62
63             var swapBtn = new Button
64             {
65                 Text = "Swap call",
66                 VerticalOptions = LayoutOptions.Start,
67                 HorizontalOptions = LayoutOptions.FillAndExpand
68             };
69             swapBtn.Clicked += swapBtn_Clicked;
70
71             var joinBtn = new Button
72             {
73                 Text = "Join calls",
74                 VerticalOptions = LayoutOptions.Start,
75                 HorizontalOptions = LayoutOptions.FillAndExpand
76             };
77             joinBtn.Clicked += joinBtn_Clicked;
78
79             var splitBtn = new Button
80             {
81                 Text = "Split call",
82                 VerticalOptions = LayoutOptions.Start,
83                 HorizontalOptions = LayoutOptions.FillAndExpand
84             };
85             splitBtn.Clicked += splitBtn_Clicked;
86
87             var getAllCallListBtn = new Button
88             {
89                 Text = "Get all call list",
90                 VerticalOptions = LayoutOptions.Start,
91                 HorizontalOptions = LayoutOptions.FillAndExpand
92             };
93             getAllCallListBtn.Clicked += getAllCallListBtn_Clicked;
94
95             var getConfCallListBtn = new Button
96             {
97                 Text = "Get conf call list",
98                 VerticalOptions = LayoutOptions.Start,
99                 HorizontalOptions = LayoutOptions.FillAndExpand
100             };
101             getConfCallListBtn.Clicked += getConfCallListBtn_Clicked;
102
103             var getCallDataBtn = new Button
104             {
105                 Text = "Get all call data",
106                 VerticalOptions = LayoutOptions.Start,
107                 HorizontalOptions = LayoutOptions.FillAndExpand
108             };
109             getCallDataBtn.Clicked += getCallDataBtn_Clicked;
110
111             var statusBtn = new Button
112             {
113                 Text = "Get call status",
114                 VerticalOptions = LayoutOptions.Start,
115                 HorizontalOptions = LayoutOptions.FillAndExpand
116             };
117             statusBtn.Clicked += statusBtn_Clicked;
118
119             var deinitBtn = new Button
120             {
121                 Text = "Deinitialize",
122                 VerticalOptions = LayoutOptions.Start,
123                 HorizontalOptions = LayoutOptions.FillAndExpand
124             };
125             deinitBtn.Clicked += deinitBtn_Clicked;
126
127             Content = new StackLayout
128             {
129                 VerticalOptions = LayoutOptions.Center,
130                 Children = {
131                         initBtn, dialBtn, holdBtn, answerBtn, alertBtn, rejectBtn, swapBtn, joinBtn, splitBtn,
132                         getAllCallListBtn, getConfCallListBtn, getCallDataBtn, statusBtn, deinitBtn
133                     }
134             };
135         }
136
137         private void getCallDataBtn_Clicked(object sender, EventArgs e)
138         {
139             try
140             {
141                 if (Globals.cmHandle == null)
142                 {
143                     Log.Debug(Globals.LogTag, "Not initialized!!!!!");
144                     return;
145                 }
146
147                 Globals.cmHandle.GetAllCallData(out CallData incoming, out CallData active, out CallData held);
148                 if (incoming == null)
149                 {
150                     Log.Debug(Globals.LogTag, "No incoming call");
151                 }
152
153                 else
154                 {
155                     Log.Debug(Globals.LogTag, "Incoming call Id: " + incoming.Id);
156                     Log.Debug(Globals.LogTag, "Incoming call number: " + incoming.CallNumber);
157                 }
158
159                 if (active == null)
160                 {
161                     Log.Debug(Globals.LogTag, "No active calls");
162                 }
163
164                 else
165                 {
166                     Log.Debug(Globals.LogTag, "Active call Id: " + active.Id);
167                     Log.Debug(Globals.LogTag, "Active call number: " + active.CallNumber);
168                 }
169
170                 if (held == null)
171                 {
172                     Log.Debug(Globals.LogTag, "No held calls");
173                 }
174
175                 else
176                 {
177                     Log.Debug(Globals.LogTag, "Held call Id: " + held.Id);
178                     Log.Debug(Globals.LogTag, "Held call number: " + held.CallNumber);
179                 }
180             }
181
182             catch (Exception ex)
183             {
184                 Log.Debug(Globals.LogTag, "Get all call data exception: " + ex.ToString());
185             }
186         }
187
188         private void getConfCallListBtn_Clicked(object sender, EventArgs e)
189         {
190             try
191             {
192                 if (Globals.cmHandle == null)
193                 {
194                     Log.Debug(Globals.LogTag, "Not initialized!!!!!");
195                     return;
196                 }
197
198                 List<ConferenceCallData> confCallList = Globals.cmHandle.AllConferenceCalls.ToList();
199                 if (confCallList.Count == 0)
200                 {
201                     Log.Debug(Globals.LogTag, "Conf call list is empty");
202                     return;
203                 }
204
205                 for (int i = 0; i < confCallList.Count; i++)
206                 {
207                     Log.Debug(Globals.LogTag, "ID[" + i + "]: " + confCallList[i].Id);
208                     Log.Debug(Globals.LogTag, "Number[" + i + "]: " + confCallList[i].CallNumber);
209                     Log.Debug(Globals.LogTag, "PersonId[" + i + "]: " + confCallList[i].PersonId);
210                     Log.Debug(Globals.LogTag, "Mode[" + i + "]: " + confCallList[i].Mode);
211                 }
212             }
213
214             catch (Exception ex)
215             {
216                 Log.Debug(Globals.LogTag, "Get all conf call list exception: " + ex.ToString());
217             }
218         }
219
220         private void getAllCallListBtn_Clicked(object sender, EventArgs e)
221         {
222             try
223             {
224                 if (Globals.cmHandle == null)
225                 {
226                     Log.Debug(Globals.LogTag, "Not initialized!!!!!");
227                     return;
228                 }
229
230                 List<CallData> callDataList = Globals.cmHandle.AllCalls.ToList();
231                 if (callDataList.Count == 0)
232                 {
233                     Log.Debug(Globals.LogTag, "Call data list is empty");
234                     return;
235                 }
236
237                 for (int i = 0; i < callDataList.Count; i++)
238                 {
239                     Log.Debug(Globals.LogTag, "Call ID[" + i +"]: " + callDataList[i].Id);
240                     Log.Debug(Globals.LogTag, "Number[" + i + "]: " + callDataList[i].CallNumber);
241                     Log.Debug(Globals.LogTag, "Call direction[" + i + "]: " + callDataList[i].Direction);
242                     Log.Debug(Globals.LogTag, "Name[" + i + "]: " + callDataList[i].CallingName);
243                     Log.Debug(Globals.LogTag, "Call type[" + i + "]: " + callDataList[i].Type);
244                     Log.Debug(Globals.LogTag, "Call state[" + i + "]: " + callDataList[i].State);
245                     Log.Debug(Globals.LogTag, "Member count[" + i + "]: " + callDataList[i].MemberCount);
246                     Log.Debug(Globals.LogTag, "Is Ecc[" + i + "]: " + callDataList[i].IsEmergency);
247                     Log.Debug(Globals.LogTag, "Call domain[" + i + "]: " + callDataList[i].Domain);
248                     Log.Debug(Globals.LogTag, "Start time[" + i + "]: " + callDataList[i].StartTime);
249                 }
250             }
251
252             catch (Exception ex)
253             {
254                 Log.Debug(Globals.LogTag, "Get all call list exception: " + ex.ToString());
255             }
256         }
257
258         private void splitBtn_Clicked(object sender, EventArgs e)
259         {
260             try
261             {
262                 if (Globals.cmHandle == null)
263                 {
264                     Log.Debug(Globals.LogTag, "Not initialized!!!!!");
265                     return;
266                 }
267
268                 Globals.cmHandle.SplitCall(1);
269             }
270
271             catch (Exception ex)
272             {
273                 Log.Debug(Globals.LogTag, "Split call exception: " + ex.ToString());
274             }
275         }
276
277         private void joinBtn_Clicked(object sender, EventArgs e)
278         {
279             try
280             {
281                 if (Globals.cmHandle == null)
282                 {
283                     Log.Debug(Globals.LogTag, "Not initialized!!!!!");
284                     return;
285                 }
286
287                 Globals.cmHandle.JoinCall();
288             }
289
290             catch (Exception ex)
291             {
292                 Log.Debug(Globals.LogTag, "Join call exception: " + ex.ToString());
293             }
294         }
295
296         private void swapBtn_Clicked(object sender, EventArgs e)
297         {
298             try
299             {
300                 if (Globals.cmHandle == null)
301                 {
302                     Log.Debug(Globals.LogTag, "Not initialized!!!!!");
303                     return;
304                 }
305
306                 Globals.cmHandle.SwapCall();
307             }
308
309             catch (Exception ex)
310             {
311                 Log.Debug(Globals.LogTag, "Swap call exception: " + ex.ToString());
312             }
313         }
314
315         private void statusBtn_Clicked(object sender, EventArgs e)
316         {
317             try
318             {
319                 if (Globals.cmHandle == null)
320                 {
321                     Log.Debug(Globals.LogTag, "Not initialized!!!!!");
322                     return;
323                 }
324
325                 Log.Debug(Globals.LogTag, "Call status: " + Globals.cmHandle.CallStatus);
326             }
327
328             catch (Exception ex)
329             {
330                 Log.Debug(Globals.LogTag, "Get call status exception: " + ex.ToString());
331             }
332         }
333
334         private void rejectBtn_Clicked(object sender, EventArgs e)
335         {
336             try
337             {
338                 if (Globals.cmHandle == null)
339                 {
340                     Log.Debug(Globals.LogTag, "Not initialized!!!!!");
341                     return;
342                 }
343
344                 Globals.cmHandle.RejectCall();
345             }
346
347             catch (Exception ex)
348             {
349                 Log.Debug(Globals.LogTag, "Reject call exception: " + ex.ToString());
350             }
351         }
352
353         private async void alertBtn_Clicked(object sender, EventArgs e)
354         {
355             try
356             {
357                 if (Globals.cmHandle == null)
358                 {
359                     Log.Debug(Globals.LogTag, "Not initialized!!!!!");
360                     return;
361                 }
362
363                 Globals.cmHandle.CallStatusChanged += CmHandle_CallStatusChanged;
364                 Globals.cmHandle.StopAlert();
365                 await Task.Delay(5000);
366                 Globals.cmHandle.StartAlert();
367             }
368
369             catch (Exception ex)
370             {
371                 Log.Debug(Globals.LogTag, "Call alert exception: " + ex.ToString());
372             }
373         }
374
375         private void CmHandle_CallStatusChanged(object sender, CallStatusChangedEventArgs e)
376         {
377             Log.Debug(Globals.LogTag, "Call status changed: " + e.CallNumber + e.Status);
378         }
379
380         private void answerBtn_Clicked(object sender, EventArgs e)
381         {
382             try
383             {
384                 if (Globals.cmHandle == null)
385                 {
386                     Log.Debug(Globals.LogTag, "Not initialized!!!!!");
387                     return;
388                 }
389
390                 Globals.cmHandle.AnswerCall(CallAnswerType.Normal);
391             }
392
393             catch (Exception ex)
394             {
395                 Log.Debug(Globals.LogTag, "Answer call exception: " + ex.ToString());
396             }
397         }
398
399         private async void holdBtn_Clicked(object sender, EventArgs e)
400         {
401             try
402             {
403                 if (Globals.cmHandle == null)
404                 {
405                     Log.Debug(Globals.LogTag, "Not initialized!!!!!");
406                     return;
407                 }
408
409                 Globals.HoldTest = true;
410                 Globals.cmHandle.DialCall(Globals.Number, CallType.Voice, MultiSimSlot.Default);
411                 await Task.Delay(20000);
412                 Globals.cmHandle.HoldCall();
413                 await Task.Delay(8000);
414                 Globals.cmHandle.UnholdCall();
415                 await Task.Delay(8000);
416                 Globals.cmHandle.EndCall(1, CallReleaseType.AllActiveCalls);
417             }
418
419             catch (Exception ex)
420             {
421                 Log.Debug(Globals.LogTag, "Hold call exception: " + ex.ToString());
422             }
423         }
424
425         private async void dialBtn_Clicked(object sender, EventArgs e)
426         {
427             try
428             {
429                 if (Globals.cmHandle == null)
430                 {
431                     Log.Debug(Globals.LogTag, "Not initialized!!!!!");
432                     return;
433                 }
434
435                 Globals.cmHandle.DialCall(Globals.Number, CallType.Voice, MultiSimSlot.Default);
436                 await Task.Delay(20000);
437                 Globals.cmHandle.EndCall(1, CallReleaseType.AllCalls);
438             }
439
440             catch (Exception ex)
441             {
442                 Log.Debug(Globals.LogTag, "Dial call exception: " + ex.ToString());
443             }
444         }
445
446         private void deinitBtn_Clicked(object sender, EventArgs e)
447         {
448             try
449             {
450                 if (Globals.cmHandle == null)
451                 {
452                     Log.Debug(Globals.LogTag, "Not initialized!!!!!");
453                     return;
454                 }
455
456                 CallManager.DeinitCm(Globals.cmHandle);
457                 Globals.cmHandle = null;
458                 Log.Debug(Globals.LogTag, "Callmanager deinitialized successfully");
459             }
460
461             catch (Exception ex)
462             {
463                 Log.Debug(Globals.LogTag, "Callmanager deinit exception: " + ex.ToString());
464             }
465         }
466
467         private void initBtn_Clicked(object sender, EventArgs e)
468         {
469             try
470             {
471                 if (Globals.cmHandle != null)
472                 {
473                     Log.Debug(Globals.LogTag, "Already initialized!!!!!");
474                     return;
475                 }
476
477                 Globals.cmHandle = CallManager.InitCm();
478                 Globals.cmHandle.EnableRecovery("Tizen.CallManager.Test");
479                 Log.Debug(Globals.LogTag, "Callmanager initialization is successful");
480             }
481
482             catch(Exception ex)
483             {
484                 Log.Debug(Globals.LogTag, "Callmanager init exception: " + ex.ToString());
485             }
486         }
487
488         private async void CmHandle_CallEventChangedAsync(object sender, CallEventEventArgs e)
489         {
490             try
491             {
492                 Log.Debug(Globals.LogTag, "Call event changed handler, CallEvent: " + e.Event);
493                 if (e.EventData != null)
494                 {
495                     Log.Debug(Globals.LogTag, "Call ID: " + e.EventData.Id);
496                     Log.Debug(Globals.LogTag, "Sim slot: " + e.EventData.SimSlot);
497                     Log.Debug(Globals.LogTag, "Call end cause: " + e.EventData.EndCause);
498                 }
499
500                 if (Globals.DialTest && e.Event == CallEvent.Active)
501                 {
502                     Globals.DialTest = false;
503                     await Task.Delay(3000);
504                     Globals.cmHandle.EndCall(e.EventData.Id, CallReleaseType.ByCallHandle);
505                 }
506
507                 if (Globals.HoldTest && e.Event == CallEvent.Active)
508                 {
509                     await Task.Delay(3000);
510                     Globals.cmHandle.HoldCall();
511                 }
512
513                 if (Globals.HoldTest && e.Event == CallEvent.Held)
514                 {
515                     Globals.HoldTest = false;
516                     await Task.Delay(8000);
517                     Globals.cmHandle.UnholdCall();
518                     await Task.Delay(8000);
519                     Globals.cmHandle.EndCall(e.EventData.Id, CallReleaseType.AllActiveCalls);
520                 }
521             }
522
523             catch (Exception ex)
524             {
525                 Log.Debug(Globals.LogTag, "End call exception: " + ex.ToString());
526             }
527         }
528
529         ~MainPage()
530         {
531             if (Globals.cmHandle != null)
532             {
533                 CallManager.DeinitCm(Globals.cmHandle);
534                 Globals.cmHandle = null;
535             }
536         }
537     }
538 }