451d424a11eb02dc6b105dbd608a0c19eafa3085
[platform/core/csapi/tizenfx.git] / test / Tizen.Tapitest / ModemPage.cs
1 using System;
2 using Xamarin.Forms;
3 using Tizen;
4 using Tizen.Tapi;
5 using System.Threading.Tasks;
6
7 namespace XamarinForTizen.Tizen
8 {
9     public class ModemPage : ContentPage
10     {
11         Modem modem = null;
12         public ModemPage()
13         {
14             try
15             {
16                 modem = new Modem(Globals.handleModem0);
17             }
18
19             catch(Exception ex)
20             {
21                 Log.Debug(Globals.LogTag, "Modem constructor throws exception = " + ex.ToString());
22             }
23
24             var processPowerCommandBtn = new Button
25             {
26                 Text = "ProcessPowerCommand",
27                 VerticalOptions = LayoutOptions.Start,
28                 HorizontalOptions = LayoutOptions.FillAndExpand
29             };
30             processPowerCommandBtn.Clicked += processPowerBtn_Clicked;
31
32             var flightModeBtn = new Button
33             {
34                 Text = "SetGetFlightMode",
35                 VerticalOptions = LayoutOptions.Start,
36                 HorizontalOptions = LayoutOptions.FillAndExpand
37             };
38             flightModeBtn.Clicked += FlightModeBtn_Clicked;
39
40             var miscMeVersionBtn = new Button
41             {
42                 Text = "GetMiscMeVersion_async_and_sync",
43                 VerticalOptions = LayoutOptions.Start,
44                 HorizontalOptions = LayoutOptions.FillAndExpand
45             };
46             miscMeVersionBtn.Clicked += MiscVersionBtn_Clicked;
47
48             var miscMeSnBtn = new Button
49             {
50                 Text = "GetMiscMeSn_async_and_sync",
51                 VerticalOptions = LayoutOptions.Start,
52                 HorizontalOptions = LayoutOptions.FillAndExpand
53             };
54             miscMeSnBtn.Clicked += MiscMeSnBtn_Clicked;
55
56             var miscMeImeiBtn = new Button
57             {
58                 Text = "GetMiscMeImei_async_and_sync",
59                 VerticalOptions = LayoutOptions.Start,
60                 HorizontalOptions = LayoutOptions.FillAndExpand
61             };
62             miscMeImeiBtn.Clicked += MiscMeImeiBtn_Clicked;
63
64             var checkPowerBtn = new Button
65             {
66                 Text = "CheckPowerStatus",
67                 VerticalOptions = LayoutOptions.Start,
68                 HorizontalOptions = LayoutOptions.FillAndExpand
69             };
70             checkPowerBtn.Clicked += CheckPowerBtn_Clicked;
71
72             var deviceInfoBtn = new Button
73             {
74                 Text = "GetDeviceInfo",
75                 VerticalOptions = LayoutOptions.Start,
76                 HorizontalOptions = LayoutOptions.FillAndExpand
77             };
78             deviceInfoBtn.Clicked += DeviceInfoBtn_Clicked;
79
80             Content = new StackLayout
81             {
82                 VerticalOptions = LayoutOptions.Center,
83                 Children = {
84                         processPowerCommandBtn, flightModeBtn, miscMeVersionBtn, miscMeSnBtn, miscMeImeiBtn, checkPowerBtn, deviceInfoBtn
85                     }
86             };
87         }
88
89         private async void DeviceInfoBtn_Clicked(object sender, EventArgs e)
90         {
91             try
92             {
93                 Log.Debug(Globals.LogTag, "GetDeviceInfo call start");
94                 MiscDeviceInfo info = await modem.GetDeviceInfo();
95                 if (info!= null)
96                 {
97                     Log.Debug(Globals.LogTag, "MiscDeviceInfo data is -- ");
98                     Log.Debug(Globals.LogTag, "DeviceName = " + info.DeviceName);
99                     Log.Debug(Globals.LogTag, "VendorName = " + info.VendorName);
100                 }
101                 Log.Debug(Globals.LogTag, "GetDeviceInfo call end");
102             }
103
104             catch (Exception ex)
105             {
106                 Log.Debug(Globals.LogTag, "Getdeviceinfo ,exception = " + ex.ToString());
107             }
108         }
109
110         private void CheckPowerBtn_Clicked(object sender, EventArgs e)
111         {
112             try
113             {
114                 Log.Debug(Globals.LogTag, "CheckPowerStatus call start");
115                 PhonePowerStatus status = modem.CheckPowerStatus();
116                 Log.Debug(Globals.LogTag, "power status = " + status);
117                 Log.Debug(Globals.LogTag, "CheckPowerStatus call end");
118             }
119
120             catch (Exception ex)
121             {
122                 Log.Debug(Globals.LogTag, "CheckPowerStatus ,exception = " + ex.ToString());
123             }
124         }
125
126         private async void MiscMeImeiBtn_Clicked(object sender, EventArgs e)
127         {
128             try
129             {
130                 Log.Debug(Globals.LogTag, "GetMiscMeImei async call start");
131                 string info = await modem.GetMiscMeImei();
132                 if (info != null)
133                 {
134                     Log.Debug(Globals.LogTag, "MiscImei number is -- " + info);
135                 }
136
137                 Log.Debug(Globals.LogTag, "GetMiscMeImei async call end");
138                 Log.Debug(Globals.LogTag, "GetMiscMeImei sync call start");
139                 string infosync = modem.MiscMeImeiSync;
140                 if (infosync != null)
141                 {
142                     Log.Debug(Globals.LogTag, "MiscImei number is -- " +infosync);
143                 }
144
145                 Log.Debug(Globals.LogTag, "GetMiscMeImei sync call end");
146             }
147
148             catch (Exception ex)
149             {
150                 Log.Debug(Globals.LogTag, "GetMiscMeImei ,exception = " + ex.ToString());
151             }
152         }
153
154         private async void MiscMeSnBtn_Clicked(object sender, EventArgs e)
155         {
156             try
157             {
158                 Log.Debug(Globals.LogTag, "GetMiscMeSn async call start");
159                 MiscSerialNumberInformation info = await modem.GetMiscMeSn();
160                 if (info != null)
161                 {
162                     Log.Debug(Globals.LogTag, "MiscSerialNumberInformation data is -- ");
163                     Log.Debug(Globals.LogTag, "Esn = " + info.Esn);
164                     Log.Debug(Globals.LogTag, "Imei = " + info.Imei);
165                     Log.Debug(Globals.LogTag, "ImeiSv = " + info.ImeiSv);
166                     Log.Debug(Globals.LogTag, "Meid = " + info.MeId);
167                 }
168
169                 Log.Debug(Globals.LogTag, "GetMiscMeSn async call end");
170                 Log.Debug(Globals.LogTag, "GetMiscMeSn sync call start");
171                 MiscSerialNumberInformation infosync = modem.MiscMeSnSync;
172                 if (infosync != null)
173                 {
174                     Log.Debug(Globals.LogTag, "MiscSerialNumberInformation data is -- ");
175                     Log.Debug(Globals.LogTag, "Esn = " + infosync.Esn);
176                     Log.Debug(Globals.LogTag, "Imei = " + infosync.Imei);
177                     Log.Debug(Globals.LogTag, "ImeiSv = " + infosync.ImeiSv);
178                     Log.Debug(Globals.LogTag, "Meid = " + infosync.MeId);
179                 }
180
181                 Log.Debug(Globals.LogTag, "GetMiscMeSn sync call end");
182             }
183
184             catch (Exception ex)
185             {
186                 Log.Debug(Globals.LogTag, "GetMiscMeSn ,exception = " + ex.ToString());
187             }
188         }
189
190         private async void FlightModeBtn_Clicked(object sender, EventArgs e)
191         {
192             try
193             {
194                 Log.Debug(Globals.LogTag, "Modem flightmode call start");
195                 await modem.SetFlightMode(PowerFlightModeRequest.Enter);
196                 Log.Debug(Globals.LogTag, "Modem flightmode set Enter success");
197                 bool isFlightMode = await modem.GetFlightMode();
198                 Log.Debug(Globals.LogTag, "Modem flightmode get success , flightmode = "+ isFlightMode);
199                 await modem.SetFlightMode(PowerFlightModeRequest.Leave);
200                 Log.Debug(Globals.LogTag, "Modem flightmode set Leave success");
201                 isFlightMode = await modem.GetFlightMode();
202                 Log.Debug(Globals.LogTag, "Modem flightmode get success , flightmode = " + isFlightMode);
203             }
204
205             catch (Exception ex)
206             {
207                 Log.Debug(Globals.LogTag, "Modem flightmode ,exception = " + ex.ToString());
208             }
209         }
210
211         private async void processPowerBtn_Clicked(object sender, EventArgs e)
212         {
213             TapiHandle handle = Globals.handleModem0;
214             try
215             {
216                 handle.NotificationChanged += Handle_NotiPowerStatusChanged;
217                 handle.RegisterNotiEvent(Notification.ModemPower);
218                 Log.Debug(Globals.LogTag, "Modem powercommand call start");
219                 await modem.ProcessPowerCommand(PhonePowerCommand.Off);
220                 Log.Debug(Globals.LogTag, "Modem powercommand call off success");
221             }
222
223             catch(Exception ex)
224             {
225                 Log.Debug(Globals.LogTag, "Modem processpower command ,exception = " + ex.ToString());
226             }
227
228             finally
229             {
230                 handle.DeregisterNotiEvent(Notification.ModemPower);
231                 handle.NotificationChanged -= Handle_NotiPowerStatusChanged;
232             }
233         }
234
235         private async void MiscVersionBtn_Clicked(object sender, EventArgs e)
236         {
237             try
238             {
239                 Log.Debug(Globals.LogTag, "GetMiscMeVersion async call start");
240                 MiscVersionInformation info = await modem.GetMiscMeVersion();
241                 if (info!=null)
242                 {
243                     Log.Debug(Globals.LogTag, "MiscVersionInformation data is -- ");
244                     Log.Debug(Globals.LogTag, "Version = " + info.VersionMask.ToString());
245                     Log.Debug(Globals.LogTag, "CalculationDate = " + info.CalculationDate);
246                     Log.Debug(Globals.LogTag, "Erinam = " + info.EriNam.ToString());
247                     Log.Debug(Globals.LogTag, "EriVersion = " + info.EriVersion);
248                     Log.Debug(Globals.LogTag, "Hwversion = " + info.HwVersion);
249                     Log.Debug(Globals.LogTag, "Swversion = " + info.SwVersion);
250                     Log.Debug(Globals.LogTag, "ModelId = " + info.ModelId);
251                     Log.Debug(Globals.LogTag, "Prlnam = " + info.PrlNam.ToString());
252                     Log.Debug(Globals.LogTag, "Prlversion = " + info.PrlVersion);
253                     Log.Debug(Globals.LogTag, "Productcode = " + info.ProductCode);
254                 }
255
256                 Log.Debug(Globals.LogTag, "GetMiscMeVersion async call end");
257                 Log.Debug(Globals.LogTag, "GetMiscMeVersion sync call start");
258                 MiscVersionInformation infosync = modem.MiscMeVersionSync;
259                 if (infosync != null)
260                 {
261                     Log.Debug(Globals.LogTag, "MiscVersionInformation data is -- ");
262                     Log.Debug(Globals.LogTag, "Version = " + infosync.VersionMask.ToString());
263                     Log.Debug(Globals.LogTag, "CalculationDate = " + infosync.CalculationDate);
264                     Log.Debug(Globals.LogTag, "Erinam = " + infosync.EriNam.ToString());
265                     Log.Debug(Globals.LogTag, "EriVersion = " + infosync.EriVersion);
266                     Log.Debug(Globals.LogTag, "Hwversion = " + infosync.HwVersion);
267                     Log.Debug(Globals.LogTag, "Swversion = " + infosync.SwVersion);
268                     Log.Debug(Globals.LogTag, "ModelId = " + infosync.ModelId);
269                     Log.Debug(Globals.LogTag, "Prlnam = " + infosync.PrlNam.ToString());
270                     Log.Debug(Globals.LogTag, "Prlversion = " + infosync.PrlVersion);
271                     Log.Debug(Globals.LogTag, "Productcode = " + infosync.ProductCode);
272                 }
273
274                 Log.Debug(Globals.LogTag, "GetMiscMeVersion sync call end");
275             }
276
277             catch(Exception ex)
278             {
279                 Log.Debug(Globals.LogTag, "GetMiscMeVersion ,exception = " + ex.ToString());
280             }
281         }
282
283         private void Handle_PropertyPowerStatusChanged(object sender, PropertyChangedEventArgs e)
284         {
285             Log.Debug(Globals.LogTag, "Handle_PropertyPowerStatusChanged event receive");
286             //Log.Debug(Globals.LogTag, "Handle_PropertyPowerStatusChanged event receive, status = " + e.Data + e.Property);
287         }
288
289         private void Handle_NotiPowerStatusChanged(object sender, NotificationChangedEventArgs e)
290         {
291             Log.Debug(Globals.LogTag, "Handle_NotiPowerStatusChanged event receive, status = " + e.Data + ", Notification Value = " +e.Id);
292         }
293     }
294 }