[Tapitest] Added test code for Ss and framework fixes.
[platform/core/csapi/tizenfx.git] / test / Tizen.Tapitest / SsPage.cs
1 using System;
2 using Xamarin.Forms;
3 using Tizen;
4 using Tizen.Tapi;
5 using System.Collections.Generic;
6 using System.Linq;
7
8 namespace XamarinForTizen.Tizen
9 {
10     public class SsPage : ContentPage
11     {
12         Ss ss = null;
13         public SsPage()
14         {
15             try
16             {
17                 ss = new Ss(Globals.handleModem0);
18             }
19
20             catch (Exception ex)
21             {
22                 Log.Debug(Globals.LogTag, "Ss constructor throws exception = " + ex.ToString());
23             }
24
25             var setCfBtn = new Button
26             {
27                 Text = "Set SS call forward",
28                 VerticalOptions = LayoutOptions.Start,
29                 HorizontalOptions = LayoutOptions.FillAndExpand
30             };
31             setCfBtn.Clicked += setCfBtn_Clicked;
32
33             var getCfBtn = new Button
34             {
35                 Text = "Get SS call forward status",
36                 VerticalOptions = LayoutOptions.Start,
37                 HorizontalOptions = LayoutOptions.FillAndExpand
38             };
39             getCfBtn.Clicked += getCfBtn_Clicked;
40
41             var setcwBtn = new Button
42             {
43                 Text = "Set SS call waiting",
44                 VerticalOptions = LayoutOptions.Start,
45                 HorizontalOptions = LayoutOptions.FillAndExpand
46             };
47             setcwBtn.Clicked += setcwBtn_Clicked;
48
49             var getcwBtn = new Button
50             {
51                 Text = "Get SS call waiting status",
52                 VerticalOptions = LayoutOptions.Start,
53                 HorizontalOptions = LayoutOptions.FillAndExpand
54             };
55             getcwBtn.Clicked += getcwBtn_Clicked;
56
57             var setCliBtn = new Button
58             {
59                 Text = "Set SS CLI status",
60                 VerticalOptions = LayoutOptions.Start,
61                 HorizontalOptions = LayoutOptions.FillAndExpand
62             };
63             setCliBtn.Clicked += setCliBtn_Clicked;
64
65             var getCliBtn = new Button
66             {
67                 Text = "Get SS CLI status",
68                 VerticalOptions = LayoutOptions.Start,
69                 HorizontalOptions = LayoutOptions.FillAndExpand
70             };
71             getCliBtn.Clicked += getCliBtn_Clicked;
72
73             var setBarringBtn = new Button
74             {
75                 Text = "Set SS barring",
76                 VerticalOptions = LayoutOptions.Start,
77                 HorizontalOptions = LayoutOptions.FillAndExpand
78             };
79             setBarringBtn.Clicked += setBarringBtn_Clicked;
80
81             var getBarringBtn = new Button
82             {
83                 Text = "Get SS barring status",
84                 VerticalOptions = LayoutOptions.Start,
85                 HorizontalOptions = LayoutOptions.FillAndExpand
86             };
87             getBarringBtn.Clicked += getBarringBtn_Clicked;
88
89             var changeBarringPwBtn = new Button
90             {
91                 Text = "Change SS barring password",
92                 VerticalOptions = LayoutOptions.Start,
93                 HorizontalOptions = LayoutOptions.FillAndExpand
94             };
95             changeBarringPwBtn.Clicked += changeBarringPwBtn_Clicked;
96
97             var sendUssdBtn = new Button
98             {
99                 Text = "Ss send USSD request",
100                 VerticalOptions = LayoutOptions.Start,
101                 HorizontalOptions = LayoutOptions.FillAndExpand
102             };
103             sendUssdBtn.Clicked += sendUssdBtn_Clicked;
104
105             Content = new StackLayout
106             {
107                 VerticalOptions = LayoutOptions.Center,
108                 Children = {
109                         setCfBtn, getCfBtn, setcwBtn, getcwBtn, setCliBtn, getCliBtn, setBarringBtn, getBarringBtn,
110                         changeBarringPwBtn, sendUssdBtn
111                     }
112             };
113         }
114
115         private async void sendUssdBtn_Clicked(object sender, EventArgs e)
116         {
117             try
118             {
119                 Log.Debug(Globals.LogTag, "Ss send ussd request start");
120                 SsUssdMsgInfo info = new SsUssdMsgInfo();
121                 info.Type = SsUssdType.UserInit;
122                 info.UssdString = "*123#";
123                 info.Length = info.UssdString.Length;
124                 SsUssdResponse resp = await ss.SsSendUssdRequest(info);
125                 Log.Debug(Globals.LogTag, "Type: " + resp.Type);
126                 Log.Debug(Globals.LogTag, "String: " + resp.UssdString);
127                 Log.Debug(Globals.LogTag, "Ss send ussd request success");
128             }
129
130             catch (Exception ex)
131             {
132                 Log.Debug(Globals.LogTag, "Ss send ussd request exception: " + ex.ToString());
133             }
134         }
135
136         private async void changeBarringPwBtn_Clicked(object sender, EventArgs e)
137         {
138             try
139             {
140                 Log.Debug(Globals.LogTag, "Ss change barring password start");
141                 bool b = await ss.SsChangeBarringPassword("1111", "'1234", "1234");
142                 if (b)
143                 {
144                     Log.Debug(Globals.LogTag, "Ss barring password changed successfully");
145                 }
146             }
147
148             catch (Exception ex)
149             {
150                 Log.Debug(Globals.LogTag, "Ss change barring password exception: " + ex.ToString());
151             }
152         }
153
154         private async void getBarringBtn_Clicked(object sender, EventArgs e)
155         {
156             try
157             {
158                 Log.Debug(Globals.LogTag, "Ss get barring status start");
159                 SsBarringResponse resp = await ss.SsGetBarringStatus(SsClass.AllTele, SsBarringType.Aob);
160                 Log.Debug(Globals.LogTag, "Record number: " + resp.RecordNumber);
161                 List<SsBarringRecord> rec = resp.Record.ToList();
162                 for (int i = 0; i < resp.RecordNumber; i++)
163                 {
164                     Log.Debug(Globals.LogTag, "[" + i + "] Class: " + rec[i].Class);
165                     Log.Debug(Globals.LogTag, "[" + i + "] Type: " + rec[i].BarringType);
166                     Log.Debug(Globals.LogTag, "[" + i + "] Status: " + rec[i].Status);
167                 }
168
169                 Log.Debug(Globals.LogTag, "Ss get barring status success");
170             }
171
172             catch (Exception ex)
173             {
174                 Log.Debug(Globals.LogTag, "Ss set barring exception: " + ex.ToString());
175             }
176         }
177
178         private async void setBarringBtn_Clicked(object sender, EventArgs e)
179         {
180             TapiHandle handle = Globals.handleModem0;
181             try
182             {
183                 Log.Debug(Globals.LogTag, "Ss set barring start");
184                 handle.RegisterNotiEvent(Notification.SsNotifyBarring);
185                 handle.NotificationChanged += Handle_Barring_NotiEvent;
186                 SsBarringInfo info = new SsBarringInfo(SsClass.Voice, SsBarringMode.Activate, SsBarringType.Aob, "0000");
187                 SsBarringResponse resp = await ss.SsSetBarring(info);
188                 Log.Debug(Globals.LogTag, "Record number: " + resp.RecordNumber);
189                 List<SsBarringRecord> rec = resp.Record.ToList();
190                 for (int i = 0; i < resp.RecordNumber; i++)
191                 {
192                     Log.Debug(Globals.LogTag, "[" + i + "] Class: " + rec[i].Class);
193                     Log.Debug(Globals.LogTag, "[" + i + "] Type: " + rec[i].BarringType);
194                     Log.Debug(Globals.LogTag, "[" + i + "] Status: " + rec[i].Status);
195                 }
196
197                 Log.Debug(Globals.LogTag, "Ss set barring success");
198             }
199
200             catch (Exception ex)
201             {
202                 Log.Debug(Globals.LogTag, "Ss set barring exception: " + ex.ToString());
203             }
204
205             finally
206             {
207                 handle.DeregisterNotiEvent(Notification.SsNotifyBarring);
208                 handle.NotificationChanged -= Handle_Barring_NotiEvent;
209             }
210         }
211
212         private void Handle_Barring_NotiEvent(object sender, NotificationChangedEventArgs e)
213         {
214             Log.Debug(Globals.LogTag, "Ss barring noti event received");
215             SsBarringResponse resp = (SsBarringResponse)e.Data;
216             Log.Debug(Globals.LogTag, "Record number: " + resp.RecordNumber);
217             List<SsBarringRecord> rec = resp.Record.ToList();
218             for (int i = 0; i < resp.RecordNumber; i++)
219             {
220                 Log.Debug(Globals.LogTag, "[" + i + "] Class: " + rec[i].Class);
221                 Log.Debug(Globals.LogTag, "[" + i + "] Type: " + rec[i].BarringType);
222                 Log.Debug(Globals.LogTag, "[" + i + "] Status: " + rec[i].Status);
223             }
224         }
225
226         private async void getCliBtn_Clicked(object sender, EventArgs e)
227         {
228             try
229             {
230                 Log.Debug(Globals.LogTag, "Ss get CLI status start");
231                 SsCliResponse resp = await ss.SsGetCliStatus(SsCliType.Clip);
232                 Log.Debug(Globals.LogTag, "Type: " + resp.Type);
233                 Log.Debug(Globals.LogTag, "Status: " + resp.Status);
234                 Log.Debug(Globals.LogTag, "Ss get CLI status success");
235             }
236
237             catch (Exception ex)
238             {
239                 Log.Debug(Globals.LogTag, "Ss get CLI status exception: " + ex.ToString());
240             }
241         }
242
243         private async void setCliBtn_Clicked(object sender, EventArgs e)
244         {
245             try
246             {
247                 Log.Debug(Globals.LogTag, "Ss set CLI start");
248                 bool b = await ss.SsSetCliStatus(SsCliType.Clip, SsCliStatus.Activated);
249                 if (b)
250                 {
251                     Log.Debug(Globals.LogTag, "Ss set CLI status is success");
252                 }
253             }
254
255             catch (Exception ex)
256             {
257                 Log.Debug(Globals.LogTag, "Ss set CLI exception: " + ex.ToString());
258             }
259         }
260
261         private async void getcwBtn_Clicked(object sender, EventArgs e)
262         {
263             try
264             {
265                 Log.Debug(Globals.LogTag, "Ss get call waiting start");
266                 SsWaitingResponse resp = await ss.SsGetWaitingInfo(SsClass.Voice);
267                 Log.Debug(Globals.LogTag, "Record number: " + resp.RecordNumber);
268                 List<SsWaitingRecord> rec = resp.Record.ToList();
269                 for (int i = 0; i < resp.RecordNumber; i++)
270                 {
271                     Log.Debug(Globals.LogTag, "[" + i + "] Class: " + rec[i].Class);
272                     Log.Debug(Globals.LogTag, "[" + i + "] Status: " + rec[i].Status);
273                 }
274
275                 Log.Debug(Globals.LogTag, "Ss get call waiting success");
276             }
277
278             catch (Exception ex)
279             {
280                 Log.Debug(Globals.LogTag, "Ss get call waiting exception: " + ex.ToString());
281             }
282         }
283
284         private async void setcwBtn_Clicked(object sender, EventArgs e)
285         {
286             TapiHandle handle = Globals.handleModem0;
287             try
288             {
289                 Log.Debug(Globals.LogTag, "Ss set call waiting start");
290                 handle.RegisterNotiEvent(Notification.SsNotifyWaiting);
291                 handle.NotificationChanged += Handle_CallWaitingNoti;
292                 SsWaitingInfo info = new SsWaitingInfo(SsClass.Voice, SsCallWaitingMode.Activate);
293                 SsWaitingResponse resp = await ss.SsSetWaitingInfo(info);
294                 Log.Debug(Globals.LogTag, "Record number: " + resp.RecordNumber);
295                 List<SsWaitingRecord> rec = resp.Record.ToList();
296                 for (int i = 0; i < resp.RecordNumber; i++)
297                 {
298                     Log.Debug(Globals.LogTag, "[" + i + "] Class: " + rec[i].Class);
299                     Log.Debug(Globals.LogTag, "[" + i + "] Status: " + rec[i].Status);
300                 }
301
302                 Log.Debug(Globals.LogTag, "Ss set call waiting success");
303             }
304
305             catch (Exception ex)
306             {
307                 Log.Debug(Globals.LogTag, "Ss set call waiting exception: " + ex.ToString());
308             }
309
310             finally
311             {
312                 handle.DeregisterNotiEvent(Notification.SsNotifyWaiting);
313                 handle.NotificationChanged -= Handle_CallWaitingNoti;
314             }
315         }
316
317         private void Handle_CallWaitingNoti(object sender, NotificationChangedEventArgs e)
318         {
319             Log.Debug(Globals.LogTag, "Ss call waiting noti event is received");
320             SsWaitingResponse resp = (SsWaitingResponse)e.Data;
321             Log.Debug(Globals.LogTag, "Record number: " + resp.RecordNumber);
322             List<SsWaitingRecord> rec = resp.Record.ToList();
323             for (int i = 0; i < resp.RecordNumber; i++)
324             {
325                 Log.Debug(Globals.LogTag, "[" + i + "] Class: " + rec[i].Class);
326                 Log.Debug(Globals.LogTag, "[" + i + "] Status: " + rec[i].Status);
327             }
328         }
329
330         private async void getCfBtn_Clicked(object sender, EventArgs e)
331         {
332             try
333             {
334                 Log.Debug(Globals.LogTag, "Ss get call forward start");
335                 SsForwardResponse resp = await ss.SsGetForwardStatus(SsClass.Voice, SsForwardCondition.NotReachable);
336                 Log.Debug(Globals.LogTag, "Record num: " + resp.RecordNumber);
337                 List<SsForwardRecord> rec = resp.Record.ToList();
338                 for (int i = 0; i < resp.RecordNumber; i++)
339                 {
340                     Log.Debug(Globals.LogTag, "[" + i + "] Class: " + rec[i].Class);
341                     Log.Debug(Globals.LogTag, "[" + i + "] Status: " + rec[i].Status);
342                     Log.Debug(Globals.LogTag, "[" + i + "] ForwardCondition: " + rec[i].ForwardCondition);
343                     Log.Debug(Globals.LogTag, "[" + i + "] IsFwNumPresent: " + rec[i].IsForwardingNumberPresent);
344                     Log.Debug(Globals.LogTag, "[" + i + "] NoReplyTime:: " + rec[i].NoReplyTime);
345                     Log.Debug(Globals.LogTag, "[" + i + "] Ton: " + rec[i].Ton);
346                     Log.Debug(Globals.LogTag, "[" + i + "] Npi: " + rec[i].Npi);
347                     Log.Debug(Globals.LogTag, "[" + i + "] Number: " + rec[i].ForwardingNumber);
348                 }
349
350                 Log.Debug(Globals.LogTag, "Ss get call forward success");
351             }
352
353             catch (Exception ex)
354             {
355                 Log.Debug(Globals.LogTag, "Ss get call forward exception: " + ex.ToString());
356             }
357         }
358
359         private async void setCfBtn_Clicked(object sender, EventArgs e)
360         {
361             TapiHandle handle = Globals.handleModem0;
362             try
363             {
364                 Log.Debug(Globals.LogTag, "Ss set call forward start");
365                 handle.RegisterNotiEvent(Notification.SsNotifyForwarding);
366                 handle.NotificationChanged += Handle_CallForwardNotiEvent;
367                 SsForwardInfo cfInfo = new SsForwardInfo(SsClass.Voice, SsForwardMode.Enable, SsForwardCondition.NotReachable, SsNoReplyTime.Time5Secs, SsForwardTypeOfNumber.National, SsForwardNumberingPlanIdentity.National, "9589874552");
368                 SsForwardResponse resp = await ss.SsSetForwardInfo(cfInfo);
369                 Log.Debug(Globals.LogTag, "Record num: " + resp.RecordNumber);
370                 List<SsForwardRecord> rec = resp.Record.ToList();
371                 for (int i = 0; i < resp.RecordNumber; i++)
372                 {
373                     Log.Debug(Globals.LogTag, "[" + i + "] Class: " + rec[i].Class);
374                     Log.Debug(Globals.LogTag, "[" + i + "] Status: " + rec[i].Status);
375                     Log.Debug(Globals.LogTag, "[" + i + "] ForwardCondition: " + rec[i].ForwardCondition);
376                     Log.Debug(Globals.LogTag, "[" + i + "] IsFwNumPresent: " + rec[i].IsForwardingNumberPresent);
377                     Log.Debug(Globals.LogTag, "[" + i + "] NoReplyTime:: " + rec[i].NoReplyTime);
378                     Log.Debug(Globals.LogTag, "[" + i + "] Ton: " + rec[i].Ton);
379                     Log.Debug(Globals.LogTag, "[" + i + "] Npi: " + rec[i].Npi);
380                     Log.Debug(Globals.LogTag, "[" + i + "] Number: " + rec[i].ForwardingNumber);
381                 }
382
383                 Log.Debug(Globals.LogTag, "Ss set call forward success");
384             }
385
386             catch(Exception ex)
387             {
388                 Log.Debug(Globals.LogTag, "Ss set call forward exception: " + ex.ToString());
389             }
390
391             finally
392             {
393                 handle.DeregisterNotiEvent(Notification.SsNotifyForwarding);
394                 handle.NotificationChanged -= Handle_CallForwardNotiEvent;
395             }
396         }
397
398         private void Handle_CallForwardNotiEvent(object sender, NotificationChangedEventArgs e)
399         {
400             Log.Debug(Globals.LogTag, "Call forward noti event received");
401             SsForwardResponse resp = (SsForwardResponse)e.Data;
402             Log.Debug(Globals.LogTag, "Record number: " + resp.RecordNumber);
403             List<SsForwardRecord> rec = resp.Record.ToList();
404             for (int i = 0; i < resp.RecordNumber; i++)
405             {
406                 Log.Debug(Globals.LogTag, "[" + i + "] Class: " + rec[i].Class);
407                 Log.Debug(Globals.LogTag, "[" + i + "] Status: " + rec[i].Status);
408                 Log.Debug(Globals.LogTag, "[" + i + "] ForwardCondition: " + rec[i].ForwardCondition);
409                 Log.Debug(Globals.LogTag, "[" + i + "] IsFwNumPresent: " + rec[i].IsForwardingNumberPresent);
410                 Log.Debug(Globals.LogTag, "[" + i + "] NoReplyTime:: " + rec[i].NoReplyTime);
411                 Log.Debug(Globals.LogTag, "[" + i + "] Ton: " + rec[i].Ton);
412                 Log.Debug(Globals.LogTag, "[" + i + "] Npi: " + rec[i].Npi);
413                 Log.Debug(Globals.LogTag, "[" + i + "] Number: " + rec[i].ForwardingNumber);
414             }
415         }
416
417         ~SsPage()
418         {
419         }
420     }
421 }