[TCSACR-150] Add telephony privilege to use telephony API. (#299)
[platform/core/csapi/tizenfx.git] / test / Tizen.Tapitest / CommonPage.cs
1 using System;
2 using System.Collections.Generic;
3 using Xamarin.Forms;
4 using Tizen.Tapi;
5 using Tizen;
6 using System.Linq;
7
8 namespace XamarinForTizen.Tizen
9 {
10     public class CommonPage : ContentPage
11     {
12         List<string> cplist = new List<string>();
13         public CommonPage()
14         {
15             var cpNameBtn = new Button
16             {
17                 Text = "CPName",
18                 VerticalOptions = LayoutOptions.Start,
19                 HorizontalOptions = LayoutOptions.FillAndExpand
20             };
21             cpNameBtn.Clicked += cpNameBtn_Clicked;
22
23             var initBtn0 = new Button
24             {
25                 Text = "InitTapimodem0",
26                 VerticalOptions = LayoutOptions.Start,
27                 HorizontalOptions = LayoutOptions.FillAndExpand
28             };
29             initBtn0.Clicked += initBtn0_Clicked;
30
31             var initBtn1 = new Button
32             {
33                 Text = "InitTapimodem1",
34                 VerticalOptions = LayoutOptions.Start,
35                 HorizontalOptions = LayoutOptions.FillAndExpand
36             };
37             initBtn1.Clicked += initBtn1_Clicked;
38
39             var deinitBtn0 = new Button
40             {
41                 Text = "DeinitTapimodem0",
42                 VerticalOptions = LayoutOptions.Start,
43                 HorizontalOptions = LayoutOptions.FillAndExpand
44             };
45             deinitBtn0.Clicked += deinitBtn0_Clicked;
46
47             var deinitBtn1 = new Button
48             {
49                 Text = "DeinitTapimodem1",
50                 VerticalOptions = LayoutOptions.Start,
51                 HorizontalOptions = LayoutOptions.FillAndExpand
52             };
53             deinitBtn1.Clicked += deinitBtn1_Clicked;
54
55             var getIntPropBtn = new Button
56             {
57                 Text = "GetIntProperty",
58                 VerticalOptions = LayoutOptions.Start,
59                 HorizontalOptions = LayoutOptions.FillAndExpand
60             };
61             getIntPropBtn.Clicked += GetIntPropBtn_Clicked;
62
63             var getStrPropBtn = new Button
64             {
65                 Text = "GetStringProperty",
66                 VerticalOptions = LayoutOptions.Start,
67                 HorizontalOptions = LayoutOptions.FillAndExpand
68             };
69             getStrPropBtn.Clicked += GetStrPropBtn_Clicked;
70
71             var getReadyBtn = new Button
72             {
73                 Text = "GetReadyState",
74                 VerticalOptions = LayoutOptions.Start,
75                 HorizontalOptions = LayoutOptions.FillAndExpand
76             };
77             getReadyBtn.Clicked += GetReadyBtn_Clicked;
78
79             Content = new StackLayout
80             {
81                 VerticalOptions = LayoutOptions.Center,
82                 Children = {
83                         cpNameBtn, initBtn0, deinitBtn0, initBtn1, deinitBtn1, getIntPropBtn, getStrPropBtn, getReadyBtn
84                     }
85             };
86         }
87
88         private void GetReadyBtn_Clicked(object sender, EventArgs e)
89         {
90             //Get the state of Tapi
91             int s = TapiManager.State;
92             if (s == 0)
93                 Log.Debug(Globals.LogTag, "Tapi state, result = false");
94             else if (s == 1)
95                 Log.Debug(Globals.LogTag, "Tapi state, result = true");
96             else
97                 Log.Debug(Globals.LogTag, "Tapi state, result = " + s);
98         }
99
100         private async void GetStrPropBtn_Clicked(object sender, EventArgs e)
101         {
102             try
103             {
104                 var action = await DisplayActionSheet("Operation", "Cancel", null, "Network Name", "Network Spn Name", "Network Name Option");
105                 Log.Debug(Globals.LogTag, "Action: " + action);
106                 if (action != null)
107                 {
108                     Property p = Property.NetworkPlmn;
109                     if (action == "Network Name")
110                         p = Property.NetworkName;
111                     else if (action == "Network Spn Name")
112                         p = Property.NetworkSpnName;
113                     else if (action == "Network Name Option")
114                         p = Property.NetworkNameOption;
115                     if (Globals.handleModem0 != null)
116                     {
117                         string val = Globals.handleModem0.GetStringProperty(p);
118                         Log.Debug(Globals.LogTag, "String property result = " + val);
119                     }
120                     else if (Globals.handleModem1 != null)
121                     {
122                         string val = Globals.handleModem1.GetStringProperty(p);
123                         Log.Debug(Globals.LogTag, "String property result = " + val);
124                     }
125                 }
126             }
127
128             catch (Exception ex)
129             {
130                 Log.Debug(Globals.LogTag, "GetStringProperty tapi exception = " + ex.ToString());
131             }
132         }
133
134         private async void GetIntPropBtn_Clicked(object sender, EventArgs e)
135         {
136             try
137             {
138                 var action = await DisplayActionSheet("Operation", "Cancel", null, "Ps Type", "Power", "Dongle Status");
139                 Log.Debug(Globals.LogTag, "Action: " + action);
140                 if (action != null)
141                 {
142                     Property p = Property.NetworkPlmn;
143                     if (action == "Ps Type")
144                         p = Property.NetworkPsType;
145                     else if (action == "Power")
146                         p = Property.ModemPower;
147                     else if (action == "Dongle Status")
148                         p = Property.ModemDongleStatus;
149                     if (Globals.handleModem0 != null)
150                     {
151                         int val = Globals.handleModem0.GetIntProperty(p);
152                         Log.Debug(Globals.LogTag, "Int property result = " + val);
153                     }
154                     else if (Globals.handleModem1 != null)
155                     {
156                         int val = Globals.handleModem1.GetIntProperty(p);
157                         Log.Debug(Globals.LogTag, "Int property result = " + val);
158                     }
159                 }
160             }
161
162             catch (Exception ex)
163             {
164                 Log.Debug(Globals.LogTag, "GetIntProperty tapi exception = " + ex.ToString());
165             }
166         }
167
168         private void deinitBtn1_Clicked(object sender, EventArgs e)
169         {
170             try
171             {
172                 if (Globals.handleModem1 != null)
173                 {
174                     TapiManager.DeinitTapi(Globals.handleModem1);
175                     Log.Debug(Globals.LogTag, "Deinit tapi is successful");
176                 }
177                 else
178                     Log.Debug(Globals.LogTag, "TapiHandle is null");
179             }
180
181             catch (Exception ex)
182             {
183                 Log.Debug(Globals.LogTag, "inside deinit tapi exception = " + ex.ToString());
184             }
185         }
186
187         private void deinitBtn0_Clicked(object sender, EventArgs e)
188         {
189             try
190             {
191                 if (Globals.handleModem0 != null)
192                 {
193                     TapiManager.DeinitTapi(Globals.handleModem0);
194                     Log.Debug(Globals.LogTag, "Deinit tapi is successful");
195                 }
196                 else
197                     Log.Debug(Globals.LogTag, "TapiHandle is null");
198             }
199
200             catch (Exception ex)
201             {
202                 Log.Debug(Globals.LogTag, "inside deinit tapi exception = " + ex.ToString());
203             }
204         }
205
206         private void initBtn1_Clicked(object sender, EventArgs e)
207         {
208             try
209             {
210                 Globals.handleModem1 = TapiManager.InitTapi(cplist[1]);
211                 if (Globals.handleModem1 == null)
212                     Log.Debug(Globals.LogTag, "Init tapi is not successful and TapiHandle is null");
213                 else
214                     Log.Debug(Globals.LogTag, "Init tapi is successful");
215             }
216
217             catch (Exception ex)
218             {
219                 Log.Debug(Globals.LogTag, "inside init tapi exception = " + ex.ToString());
220             }
221         }
222
223         private void initBtn0_Clicked(object sender, EventArgs e)
224         {
225             try
226             {
227                 Globals.handleModem0 = TapiManager.InitTapi(cplist[0]);
228                 if (Globals.handleModem0 == null)
229                     Log.Debug(Globals.LogTag, "Init tapi is not successful and TapiHandle is null");
230                 else
231                     Log.Debug(Globals.LogTag, "Init tapi is successful");
232             }
233
234             catch (Exception ex)
235             {
236                 Log.Debug(Globals.LogTag, "inside init tapi exception = " + ex.ToString());
237             }
238         }
239
240         private void cpNameBtn_Clicked(object sender, EventArgs e)
241         {
242             try
243             {
244                 cplist = TapiManager.GetCpNames().ToList();
245                 if (cplist != null)
246                 {
247                     Log.Debug(Globals.LogTag, "inside common button clicked ");
248                     for (int i = 0; i < cplist.Count; i++)
249                         Log.Debug(Globals.LogTag, "Cp name = " + cplist[i]);
250                 }
251             }
252
253             catch (Exception ex)
254             {
255                 Log.Debug(Globals.LogTag, "Getcpnames throw exception = " + ex.ToString());
256             }
257         }
258     }
259 }