nativeinfologctrl - native platform info log on/off script
[platform/framework/native/appfw.git] / src / server / system / setting / providers / FSys_SettingNetworkProvider.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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 /**
18  * @file        FSys_SettingNetworkProvider.cpp
19  * @brief       This is the implementation for the _SettingNetworkProvider class.
20  */
21
22 #include <unistd.h>
23 #include <unique_ptr.h>
24 #include <dlfcn.h>
25 #include <sim.h>
26 #include <system_info.h>
27 #include <bluetooth.h>
28
29 #include <FBase_StringConverter.h>
30
31 #include <FApp.h>
32 #include <FBase.h>
33 #include <FBaseSysLog.h>
34
35 #include "FSys_SystemInfo.h"
36 #include "FSys_SettingNetworkProvider.h"
37
38 using namespace std;
39
40 using namespace Tizen::App;
41 using namespace Tizen::Base;
42 using namespace Tizen::Base;
43 using namespace Utility;
44
45 namespace Tizen { namespace System
46 {
47 //Network Telephony
48 static const wchar_t* _NETWORK_FLIGHTMODE = L"http://tizen.org/setting/network.flight_mode";
49 static const wchar_t* _NETWORK_TELEPHONY_PACKETSERVICE = L"http://tizen.org/setting/network.telephony.packet_service";
50 static const wchar_t* _NETWORK_TELEPHONY_ROAMING = L"http://tizen.org/setting/network.telephony.roaming";
51
52 //Network Wi-Fi
53 static const wchar_t* _NETWORK_WIFI = L"http://tizen.org/setting/network.wifi";
54 static const wchar_t* _NETWORK_WIFI_NOTIFICATION = L"http://tizen.org/setting/network.wifi.notification";
55 static const wchar_t* _NETWORK_WIFI_TETHERING = L"http://tizen.org/setting/network.wifi.tethering";
56 static const wchar_t* _NETWORK_WIFI_TETHERING_HIDE = L"http://tizen.org/setting/network.wifi.tethering.hide";
57 static const wchar_t* _NETWORK_WIFI_TETHERING_SECURITY = L"http://tizen.org/setting/network.wifi.tethering.security";
58 //static const wchar_t* _NETWORK_WIFI_TETHERING_SECURITY_PASSWORD = L"http://tizen.org/setting/network.wifi.tethering.security.password";
59 static const wchar_t* _USB_TETHERING = L"http://tizen.org/setting/usb.tethering"; //Especially, USB tethering is covered by this provider.
60 static const wchar_t* _NETWORK_WIFI_DIRECT = L"http://tizen.org/setting/network.wifi.direct";
61
62 //Network Bluetooth
63 static const wchar_t* _NETWORK_BLUETOOTH = L"http://tizen.org/setting/network.bluetooth";
64 static const wchar_t* _NETWORK_BLUETOOTH_TETHERING = L"http://tizen.org/setting/network.bluetooth.tethering";
65
66 static const wchar_t* _SYSTEM_NETWORK_BLUETOOTH = L"http://tizen.org/feature/network.bluetooth";
67
68 struct charDeleter
69 {
70         void operator()(char* pValue)
71         {
72                 if(pValue != null)
73                 {
74                         free(pValue);
75                         pValue = null;
76                 }
77         }
78 };
79
80 _SettingNetworkProvider::_SettingNetworkProvider()
81         : __tapiHandle(null)
82         , __pWifiDllHandle(null)
83         , __pBluetoothDllHandle(null)
84         , __tetheringHandle(null)
85         , __stateOfFlightMode(0)
86         , __stateOfWifi(0)
87         , __stateOfWifiDirect(0)
88         , __stateOfBluetooth(0)
89         , __flightModeEnabled(false)
90         , __networkBluetoothEnabled(false)
91         , __wifiInit(false)
92         , __wifiDirectInit(false)
93         , __pWifiListener(null)
94         , __pWifiDirectListener(null)
95         , __pFlightModeListener(null)
96         , __pBluetoothListener(null)
97 {
98         int errorCode = bt_initialize();
99         if(errorCode != 0)
100         {
101                 //For multiple usage, deinitialize should not be called when it terminated.
102                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to initialize bluetooth.");
103         }
104
105         errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED, SettingEventRuntimeInfo, null);
106         if(errorCode != 0)
107         {
108                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register flight mode event listener");
109         }
110
111         errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_PACKET_DATA_ENABLED, SettingEventRuntimeInfo, null);
112         if(errorCode != 0)
113         {
114                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register packet data event listener");
115         }
116
117         errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED, SettingEventRuntimeInfo, null);
118         if(errorCode != 0)
119         {
120                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register roaming event listener");
121         }
122
123         errorCode = vconf_notify_key_changed(VCONFKEY_WIFI_STATE, SettingEventVConf, null);
124         if(errorCode != 0)
125         {
126                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_WIFI_STATE listener");
127         }
128
129         errorCode = tethering_create(&__tetheringHandle);
130         if(errorCode != 0)
131         {
132                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to create tethering handle");
133         }
134         else
135         {
136                 errorCode = tethering_set_enabled_cb(__tetheringHandle, TETHERING_TYPE_USB, SettingEventTetheringEnabled, null);
137                 if(errorCode != 0)
138                 {
139                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_USB listener");
140                 }
141
142                 errorCode = tethering_set_enabled_cb(__tetheringHandle, TETHERING_TYPE_WIFI, SettingEventTetheringEnabled, null);
143                 if(errorCode != 0)
144                 {
145                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_WIFI listener");
146                 }
147
148                 errorCode = tethering_set_enabled_cb(__tetheringHandle, TETHERING_TYPE_BT, SettingEventTetheringEnabled, null);
149                 if(errorCode != 0)
150                 {
151                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_BT listener");
152                 }
153
154                 errorCode = tethering_set_disabled_cb(__tetheringHandle, TETHERING_TYPE_USB, SettingEventTetheringDisabled, null);
155                 if(errorCode != 0)
156                 {
157                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_USB listener");
158                 }
159
160                 errorCode = tethering_set_disabled_cb(__tetheringHandle, TETHERING_TYPE_WIFI, SettingEventTetheringDisabled, null);
161                 if(errorCode != 0)
162                 {
163                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_WIFI listener");
164                 }
165
166                 errorCode = tethering_set_disabled_cb(__tetheringHandle, TETHERING_TYPE_BT, SettingEventTetheringDisabled, null);
167                 if(errorCode != 0)
168                 {
169                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_BT listener");
170                 }
171         }
172
173         errorCode = vconf_notify_key_changed(VCONFKEY_WIFI_DIRECT_STATE, SettingEventVConf, null);
174         if(errorCode != 0)
175         {
176                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_WIFI_DIRECT_STATE listener");
177         }
178
179         errorCode = vconf_notify_key_changed(VCONFKEY_BT_STATUS, SettingEventVConf, null);
180         if(errorCode != 0)
181         {
182                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_BT_STATUS listener");
183         }
184
185         errorCode = vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_SECURITY, SettingEventVConf, null);
186         if(errorCode != 0)
187         {
188                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_MOBILE_HOTSPOT_SECURITY listener");
189         }
190
191         errorCode = vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_HIDE, SettingEventVConf, null);
192         if(errorCode != 0)
193         {
194                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_MOBILE_HOTSPOT_HIDE listener");
195         }
196
197         errorCode = vconf_notify_key_changed(VCONFKEY_WIFI_ENABLE_QS, SettingEventVConf, null);
198         if(errorCode != 0)
199         {
200                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_WIFI_ENABLE_QS listener");
201         }
202
203         errorCode = bt_adapter_set_state_changed_cb(SettingEventBluetooth, (void*)this);
204         if(errorCode != 0)
205         {
206                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register bluetooth listener");
207         }
208
209         if(__wifiInit == false)
210         {
211                 SysLog(NID_SYS, "wifi init is started");
212                 errorCode = wifi_initialize();
213                 SysLog(NID_SYS, "wifi init result is %d", errorCode);
214                 __wifiInit = true;
215         }
216 }
217
218
219 _SettingNetworkProvider::~_SettingNetworkProvider()
220 {
221         int errorCode = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED);
222         if(errorCode != 0)
223         {
224                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister flight mode event listener");
225         }
226
227         errorCode = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_PACKET_DATA_ENABLED);
228         if(errorCode != 0)
229         {
230                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister packet data event listener");
231         }
232
233         errorCode = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED);
234         if(errorCode != 0)
235         {
236                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister roaming event listener");
237         }
238
239         errorCode = vconf_ignore_key_changed(VCONFKEY_WIFI_STATE, SettingEventVConf);
240         if(errorCode != 0)
241         {
242                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_WIFI_STATE listener");
243         }
244
245         if(__tetheringHandle != null)
246         {
247                 errorCode = tethering_unset_enabled_cb(__tetheringHandle, TETHERING_TYPE_USB);
248                 if(errorCode != 0)
249                 {
250                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_USB listener");
251                 }
252
253                 errorCode = tethering_unset_enabled_cb(__tetheringHandle, TETHERING_TYPE_WIFI);
254                 if(errorCode != 0)
255                 {
256                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_WIFI listener");
257                 }
258
259                 errorCode = tethering_unset_enabled_cb(__tetheringHandle, TETHERING_TYPE_BT);
260                 if(errorCode != 0)
261                 {
262                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_BT listener");
263                 }
264
265                 errorCode = tethering_unset_disabled_cb(__tetheringHandle, TETHERING_TYPE_USB);
266                 if(errorCode != 0)
267                 {
268                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_USB listener");
269                 }
270
271                 errorCode = tethering_unset_disabled_cb(__tetheringHandle, TETHERING_TYPE_WIFI);
272                 if(errorCode != 0)
273                 {
274                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_WIFI listener");
275                 }
276
277                 errorCode = tethering_unset_disabled_cb(__tetheringHandle, TETHERING_TYPE_BT);
278                 if(errorCode != 0)
279                 {
280                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_BT listener");
281                 }
282
283                 tethering_destroy(__tetheringHandle);
284                 __tetheringHandle = null;
285         }
286
287         errorCode = vconf_ignore_key_changed(VCONFKEY_WIFI_DIRECT_STATE, SettingEventVConf);
288         if(errorCode != 0)
289         {
290                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_WIFI_DIRECT_STATE listener");
291         }
292         errorCode = vconf_ignore_key_changed(VCONFKEY_BT_STATUS, SettingEventVConf);
293         if(errorCode != 0)
294         {
295                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_BT_STATUS listener");
296         }
297
298         errorCode = vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_SECURITY, SettingEventVConf);
299         if(errorCode != 0)
300         {
301                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_MOBILE_HOTSPOT_SECURITY listener");
302         }
303
304         errorCode = vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_HIDE, SettingEventVConf);
305         if(errorCode != 0)
306         {
307                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_MOBILE_HOTSPOT_HIDE listener");
308         }
309
310         errorCode = vconf_ignore_key_changed(VCONFKEY_WIFI_ENABLE_QS, SettingEventVConf);
311         if(errorCode != 0)
312         {
313                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_WIFI_ENABLE_QS listener");
314         }
315
316         errorCode = bt_adapter_unset_state_changed_cb();
317         if(errorCode != 0)
318         {
319                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister bluetooth listener");
320         }
321
322         errorCode = bt_deinitialize();
323         if(errorCode != 0)
324         {
325                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to deinitialize bluetooth.");
326         }
327
328         if(__wifiDirectInit == true)
329         {
330                 errorCode = wifi_direct_unset_device_state_changed_cb();
331                 if(errorCode == WIFI_DIRECT_ERROR_NONE)
332                 {
333                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister Wi-Fi direct callback.");
334                 }
335
336                 errorCode = wifi_direct_deinitialize();
337                 if(errorCode == WIFI_DIRECT_ERROR_NONE)
338                 {
339                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to deinitialize Wi-Fi direct.");
340                 }
341                 SysLog(NID_SYS, "Wifi direct de-init result is %d.", errorCode);
342                 __wifiDirectInit = false;
343         }
344
345         if(__wifiInit == true)
346         {
347                 errorCode = wifi_deinitialize();
348                 if(errorCode == WIFI_ERROR_NONE)
349                 {
350                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to deinitialize Wi-Fi.");
351                 }
352                 SysLog(NID_SYS, "Wifi de-init result is %d.", errorCode);
353                 __wifiInit = false;
354         }
355         SysLog(NID_SYS, "Network Provider is terminated properly.");
356 }
357
358 result
359 _SettingNetworkProvider::GetValue(const String& key, bool& value)
360 {
361         int errorCode = 0;
362         result r = E_OBJ_NOT_FOUND;
363
364         if(key == _NETWORK_FLIGHTMODE)
365         {
366                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support flightmode feature.");
367                 bool flightModeEnabled = false;
368                 r = E_SUCCESS;
369                 errorCode = runtime_info_get_value_bool(RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED, &flightModeEnabled);
370                 SysTryReturnResult(NID_SYS, errorCode == RUNTIME_INFO_ERROR_NONE, E_SYSTEM, "It is failed to get the RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED");
371                 value = flightModeEnabled;
372         }
373         else if(key == _NETWORK_TELEPHONY_PACKETSERVICE)
374         {
375                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Telephony packet service feature.");
376                 bool packetServiceAllowed = false;
377                 r = E_SUCCESS;
378                 errorCode = runtime_info_get_value_bool(RUNTIME_INFO_KEY_PACKET_DATA_ENABLED, &packetServiceAllowed);
379                 SysTryReturnResult(NID_SYS, errorCode == RUNTIME_INFO_ERROR_NONE, E_SYSTEM, "It is failed to get the RUNTIME_INFO_KEY_PACKET_DATA_ENABLED");
380                 value = packetServiceAllowed;
381         }
382         else if(key == _NETWORK_TELEPHONY_ROAMING)
383         {
384                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Telephony roaming feature.");
385                 bool dataRoamingEnabled = false;
386                 r = E_SUCCESS;
387                 errorCode = runtime_info_get_value_bool(RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED, &dataRoamingEnabled);
388                 SysTryReturnResult(NID_SYS, errorCode == RUNTIME_INFO_ERROR_NONE, E_SYSTEM, "It is failed to get the RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED");
389                 value = dataRoamingEnabled;
390         }
391         else if (key == _NETWORK_WIFI)
392         {
393                 r = E_SUCCESS;
394                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
395
396                 bool wifiState = false;
397                 errorCode = wifi_is_activated(&wifiState);
398                 SysTryReturnResult(NID_SYS, errorCode == WIFI_ERROR_NONE, E_SYSTEM, "It is failed to get from wifi_is_activated.");
399                 value = wifiState;
400         }
401         else if (key == _NETWORK_WIFI_NOTIFICATION)
402         {
403                 int wifiQSState = 0;
404                 r = E_SUCCESS;
405                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
406
407                 errorCode = vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &wifiQSState);
408                 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_WIFI_ENABLE_QS vconf.");
409
410                 if(wifiQSState == VCONFKEY_WIFI_QS_DISABLE)
411                 {
412                         value = false;
413                 }
414                 else
415                 {
416                         value = true;
417                 }
418         }
419         else if (key == _NETWORK_WIFI_TETHERING)
420         {
421                 r = E_SUCCESS;
422                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
423                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_SYSTEM, "It is failed to get tethering handle.");
424
425                 value = tethering_is_enabled(__tetheringHandle, TETHERING_TYPE_WIFI);
426         }
427         else if (key == _NETWORK_WIFI_TETHERING_HIDE)
428         {
429                 r = E_SUCCESS;
430                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
431                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_SYSTEM, "It is failed to get tethering handle.");
432
433                 errorCode = tethering_wifi_get_ssid_visibility(__tetheringHandle, &value);
434                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to get wifi tethering visibility state");
435         }
436         else if (key == _NETWORK_WIFI_TETHERING_SECURITY)
437         {
438                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
439                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_SYSTEM, "It is failed to get tethering handle.");
440
441                 r = E_SUCCESS;
442                 tethering_wifi_security_type_e securityType;
443                 errorCode = tethering_wifi_get_security_type(__tetheringHandle, &securityType);
444                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to get wifi tethering securiy state");
445                 if(securityType == TETHERING_WIFI_SECURITY_TYPE_NONE)
446                 {
447                         value = false;
448                 }
449                 else
450                 {
451                         value = true;
452                 }
453         }
454         else if (key == _USB_TETHERING)
455         {
456                 r = E_SUCCESS;
457                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support USB tethering feature.");
458                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_SYSTEM, "It is failed to get tethering handle.");
459
460                 value = tethering_is_enabled(__tetheringHandle, TETHERING_TYPE_USB);
461         }
462         else if (key == _NETWORK_WIFI_DIRECT)
463         {
464                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi direct feature.");
465                 r = E_SUCCESS;
466
467                 int isActivated = 0;
468                 errorCode = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &isActivated);
469                 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_WIFI_ENABLE_QS vconf.");
470
471                 if(isActivated == 1)
472                 {
473                         value = true;
474                 }
475                 else
476                 {
477                         value = false;
478                 }
479         }
480         else if (key == _NETWORK_BLUETOOTH)
481         {
482                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Bluetooth feature.");
483                 r = E_SUCCESS;
484                 int bluetoothStatus = VCONFKEY_BT_STATUS_OFF;
485                 errorCode = vconf_get_int(VCONFKEY_BT_STATUS, &bluetoothStatus);
486                 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to read bluetooth status.");
487
488                 if(bluetoothStatus == VCONFKEY_BT_STATUS_OFF)
489                 {
490                         value = false;
491                 }
492                 else
493                 {
494                         value = true;
495                 }
496         }
497         else if (key == _NETWORK_BLUETOOTH_TETHERING)
498         {
499                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Bluetooth tethering feature.");
500                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_SYSTEM, "It is failed to get tethering handle.");
501
502                 r = E_SUCCESS;
503                 value  = tethering_is_enabled(__tetheringHandle, TETHERING_TYPE_BT);
504         }
505         return r;
506 }
507
508 result
509 _SettingNetworkProvider::SetValue(const String& key, const bool value)
510 {
511         int errorCode = 0;
512         result r = E_OBJ_NOT_FOUND;
513
514         if(key == _NETWORK_WIFI_NOTIFICATION)
515         {
516                 int currentValue = 0;
517                 r = E_SUCCESS;
518                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
519                 errorCode = vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &currentValue);
520                 SysTryReturnResult(NID_SYS, errorCode != -1, E_UNSUPPORTED_OPERATION, "This device does not support %ls key.", key.GetPointer());
521
522                 if(value == true)
523                 {
524                         errorCode = vconf_set_int(VCONFKEY_WIFI_ENABLE_QS, VCONFKEY_WIFI_QS_ENABLE);
525                 }
526                 else
527                 {
528                         errorCode = vconf_set_int(VCONFKEY_WIFI_ENABLE_QS, VCONFKEY_WIFI_QS_DISABLE);
529                 }
530                 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_WIFI_ENABLE_QS vconf.");
531         }
532         else if(key == _NETWORK_WIFI_TETHERING)
533         {
534                 bool state = false;
535                 r = E_SUCCESS;
536                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
537                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_SYSTEM, "It is failed to get tethering handle.");
538
539                 r = GetValue(_NETWORK_WIFI, state);
540                 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get the WIFI state");
541                 SysTryReturnResult(NID_SYS, state == true, E_INVALID_STATE, "WIFI is not activated");
542
543                 if(value == true)
544                 {
545                         errorCode = tethering_enable(__tetheringHandle, TETHERING_TYPE_WIFI);
546                 }
547                 else
548                 {
549                         errorCode = tethering_disable(__tetheringHandle, TETHERING_TYPE_WIFI);
550                 }
551                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change tethering option.");
552         }
553         else if(key == _NETWORK_WIFI_TETHERING_HIDE)
554         {
555                 r = E_SUCCESS;
556                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
557                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_SYSTEM, "It is failed to get tethering handle.");
558
559                 bool currentState = false;
560                 errorCode = tethering_wifi_get_ssid_visibility(__tetheringHandle, &currentState);
561                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to current wifi tethering visibility setting");
562
563                 if(value == true && currentState == false)
564                 {
565                         errorCode = tethering_wifi_set_ssid_visibility(__tetheringHandle, true);
566                 }
567                 else if(value == false && currentState == true)
568                 {
569                         errorCode = tethering_wifi_set_ssid_visibility(__tetheringHandle, false);
570                 }
571                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change wifi tethering visibility setting");
572         }
573         else if(key == _NETWORK_WIFI_TETHERING_SECURITY)
574         {
575                 r = E_SUCCESS;
576                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
577                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_SYSTEM, "It is failed to get tethering handle.");
578
579                 tethering_wifi_security_type_e securityType;
580
581                 errorCode = tethering_wifi_get_security_type(__tetheringHandle, &securityType);
582                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to get wifi tethering securiy state");
583
584                 if(value == true && securityType == TETHERING_WIFI_SECURITY_TYPE_NONE)
585                 {
586                         errorCode = tethering_wifi_set_security_type(__tetheringHandle, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK);
587                 }
588                 else if(value == false && securityType == TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK)
589                 {
590                         errorCode = tethering_wifi_set_security_type(__tetheringHandle, TETHERING_WIFI_SECURITY_TYPE_NONE);
591                 }
592                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change wifi tethering visibility setting");
593         }
594         else if(key == _USB_TETHERING)
595         {
596                 r = E_SUCCESS;
597                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support tethering feature.");
598                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_SYSTEM, "It is failed to get tethering handle.");
599
600                 if(value == true)
601                 {
602                         errorCode = tethering_enable(__tetheringHandle, TETHERING_TYPE_USB);
603                 }
604                 else
605                 {
606                         errorCode = tethering_disable(__tetheringHandle, TETHERING_TYPE_USB);
607                 }
608                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change tethering option");
609         }
610         else if(key == _NETWORK_BLUETOOTH_TETHERING)
611         {
612                 r = E_SUCCESS;
613                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support tethering feature.");
614                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_SYSTEM, "It is failed to get tethering handle.");
615
616                 bool state = false;
617                 r = GetValue(_NETWORK_BLUETOOTH, state);
618                 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get the Bluetooth state");
619                 SysTryReturnResult(NID_SYS, state == true, E_INVALID_STATE, "Bluetooth is not activated");
620
621                 if(value == true)
622                 {
623                         errorCode = tethering_enable(__tetheringHandle, TETHERING_TYPE_BT);
624                 }
625                 else
626                 {
627                         errorCode = tethering_disable(__tetheringHandle, TETHERING_TYPE_BT);
628                 }
629                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change tethering option");
630         }
631         return r;
632 }
633
634 result
635 _SettingNetworkProvider::SetValueAsync(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
636 {
637         int ret = 0;
638         result r = E_OBJ_NOT_FOUND;
639
640         if(key == _NETWORK_BLUETOOTH)
641         {
642                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Bluetooth feature.");
643                 SysTryReturnResult(NID_SYS, __stateOfBluetooth == 0, E_IN_PROGRESS, "Bluetooth is under changing procedure.");
644                 r = E_SUCCESS;
645                 __stateOfBluetooth = 1;
646                 __pBluetoothListener = listener;
647
648                 SysLog(NID_SYS, "Required bluetooth value is %d.", value);
649                 if(value == true)
650                 {
651                         ret = bt_adapter_enable();
652                 }
653                 else
654                 {
655                         ret = bt_adapter_disable();
656                 }
657
658                 SysLog(NID_SYS, "bt_adapter returns %d.", ret);
659
660                 switch(ret)
661                 {
662                 case BT_ERROR_NONE:
663                         SysLog(NID_SYS, "It is OK to change the bluetooth mode.");
664                         break;
665
666                 case BT_ERROR_ALREADY_DONE:
667                         SysLog(NID_SYS, "Bluetooth is already changed.");
668                         SettingEventBluetooth(BT_ERROR_NONE, BT_ADAPTER_ENABLED, (void*)this);
669                         break;
670                 case BT_ERROR_NOT_ENABLED:
671                         SysLog(NID_SYS, "Bluetooth is not enabled.");
672                         SettingEventBluetooth(BT_ERROR_NONE, BT_ADAPTER_ENABLED, (void*)this);
673                         break;
674
675                 case BT_ERROR_NOW_IN_PROGRESS:
676                         SysLog(NID_SYS, "Currently, Bluetooth change is in progress.");
677                         __stateOfBluetooth = 0;
678                         r = E_IN_PROGRESS;
679                         break;
680
681                 case BT_ERROR_NOT_INITIALIZED:
682                 default:
683                         SysLog(NID_SYS, "There is an unknown error when changing the bluetooth mode.");
684                         __stateOfBluetooth = 0;
685                         r = E_SYSTEM;
686                         break;
687                 }
688         }
689         return r;
690 }
691
692 result
693 _SettingNetworkProvider::SetValueForPrivilegedKey(const String& key, bool value)
694 {
695         int errorCode = 0;
696         result r = E_OBJ_NOT_FOUND;
697         if(key == _NETWORK_TELEPHONY_PACKETSERVICE)
698         {
699                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support telephony packet service feature.");
700                 r = E_SUCCESS;
701                 errorCode = vconf_set_bool(VCONFKEY_3G_ENABLE, value);
702                 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_3G_ENABLE vconf.");
703         }
704         else if(key == _NETWORK_TELEPHONY_ROAMING)
705         {
706                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support telephony roaming feature.");
707                 r = E_SUCCESS;
708                 errorCode = vconf_set_bool(VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, value);
709                 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL vconf.");
710         }
711         return r;
712 }
713
714 result
715 _SettingNetworkProvider::SetValueAsyncForPrivilegedKey(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
716 {
717         int errorCode = 0;
718         result r = E_OBJ_NOT_FOUND;
719
720         if(key == _NETWORK_FLIGHTMODE)
721         {
722                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support flightmode feature.");
723                 r = E_SUCCESS;
724
725                 SysTryReturnResult(NID_SYS, __stateOfFlightMode == 0, E_IN_PROGRESS, "Flightmode is under changing procedure.");
726                 __stateOfFlightMode = 1;
727
728                 bool supported = false;
729                 int ret = system_info_get_platform_bool("tizen.org/feature/network.telephony", &supported);
730                 SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
731
732                 __pFlightModeListener = listener;
733                 if(supported == true)
734                 {
735                         if(__tapiHandle ==  null)
736                         {
737                                 __tapiHandle = tel_init(null);
738                                 if(__tapiHandle == null)
739                                 {
740                                         __stateOfFlightMode = 0;
741                                 }
742                                 SysTryReturnResult(NID_SYS, __tapiHandle != null, E_SYSTEM, "Tapi is not ready.");
743                         }
744                         errorCode = tel_set_flight_mode(__tapiHandle,
745                                         value ? TAPI_POWER_FLIGHT_MODE_ENTER : TAPI_POWER_FLIGHT_MODE_LEAVE,
746                                         SettingEventFlightMode, (void*)this);
747
748                         if(errorCode != 0)
749                         {
750                                 __stateOfFlightMode = 0;
751                         }
752                         SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on Network Flight mode(%d).", errorCode);
753                 }
754                 else
755                 {
756                         FlightModeEnabler((void*)this);
757                 }
758         }
759         else if(key == _NETWORK_WIFI)
760         {
761                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
762                 SysTryReturnResult(NID_SYS, __stateOfWifi == 0 && __stateOfWifiDirect == 0, E_IN_PROGRESS, "Wifi processing is under way.");
763                 r = E_SUCCESS;
764
765                 __stateOfWifi = 1;
766                 SysLog(NID_SYS, "It creates thread for wifi enable[%d].", value);
767
768                 bool wifiEnabled = false;
769                 __pWifiListener = listener;
770                 errorCode = wifi_is_activated(&wifiEnabled);
771                 if(errorCode != WIFI_ERROR_NONE)
772                 {
773                         __stateOfWifi = 0;
774                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to get current status of WIFI.");
775                         return E_SYSTEM;
776                 }
777
778                 if(value == wifiEnabled) //Wi-Fi is already changed.
779                 {
780                         SysLog(NID_SYS, "It is try to use dummy thread");
781                         r = WifiDummy((void*)this);
782                         SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to set Wi-Fi state.");
783                         return r;
784                 }
785
786                 if(value == true)
787                 {
788                         errorCode = wifi_activate(SettingWifiActivateCallBack, (void*) this);
789                 }
790                 else
791                 {
792                         errorCode = wifi_deactivate(SettingWifiActivateCallBack, (void*) this);
793                 }
794
795                 if(errorCode != WIFI_ERROR_NONE)
796                 {
797                         __stateOfWifi = 0;
798                         return E_SYSTEM;
799                 }
800         }
801         else if(key == _NETWORK_WIFI_DIRECT)
802         {
803                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
804                 SysTryReturnResult(NID_SYS, __stateOfWifi == 0 && __stateOfWifiDirect == 0, E_IN_PROGRESS, "Wifi processing is under way.");
805                 r = E_SUCCESS;
806
807                 __stateOfWifiDirect = 1;
808                 SysLog(NID_SYS, "It creates thread for wifi direct enable[%d].", value);
809
810
811                 __pWifiDirectListener = listener;
812                 if(__wifiDirectInit == false)
813                 {
814                         SysLog(NID_SYS, "wifi direct init is started");
815                         errorCode = wifi_direct_initialize();
816                         SysLog(NID_SYS, "wifi direct init result is %d", errorCode);
817                         SysTryReturnResult(NID_SYS, errorCode == WIFI_DIRECT_ERROR_NONE, E_SYSTEM, "It is failed to init wifi direct.");
818                         errorCode = wifi_direct_set_device_state_changed_cb(SettingWifiDirectStateChangedCallBack, (void*) this);
819                         SysTryReturnResult(NID_SYS, errorCode == WIFI_DIRECT_ERROR_NONE, E_SYSTEM, "It is failed to register wifi direct result callback.");
820                         __wifiDirectInit = true;
821                 }
822
823
824                 wifi_direct_state_e wifi_direct_state;
825                 errorCode = wifi_direct_get_state(&wifi_direct_state);
826                 if(errorCode != WIFI_DIRECT_ERROR_NONE)
827                 {
828                         __stateOfWifiDirect = 0;
829                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to get current status of WIFI direct.");
830                         return E_SYSTEM;
831                 }
832
833                 if((value == false && wifi_direct_state == WIFI_DIRECT_STATE_DEACTIVATED)
834                         || (value == true && wifi_direct_state != WIFI_DIRECT_STATE_DEACTIVATED))
835                 {
836                         SysLog(NID_SYS, "Required state is already applied.");
837                         WifiDirectDummy((void*)this);
838                         return E_SUCCESS;
839                 }
840
841                 if(value == true)
842                 {
843                         errorCode = wifi_direct_activate();
844                 }
845                 else
846                 {
847                         errorCode = wifi_direct_deactivate();
848                 }
849                 SysLog(NID_SYS, "wifi_direct_activate result is %d. value is %d.", errorCode, value);
850
851                 if(errorCode < 0)
852                 {
853                         return E_SYSTEM;
854                 }
855         }
856         return r;
857 }
858
859 result
860 _SettingNetworkProvider::WifiDummy(void* data)
861 {
862         result r = E_SUCCESS;
863         String settingKey(_NETWORK_WIFI);
864         _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
865         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
866         SysTryReturnResult(NID_SYS, (pSettingInfo != null && pProvider != null), E_SYSTEM, "There is no values of args.");
867
868         SysTryCatch(NID_SYS, pProvider->__stateOfWifi == 1, r = E_SYSTEM, E_SYSTEM, "There is invalid state.");
869
870         if(pProvider->__pWifiListener != null)
871         {
872                 pProvider->__pWifiListener->OnResultReceivedForSetValueAsync(settingKey, E_SUCCESS);
873         }
874         r = pSettingInfo->AnnounceSettingEvent(settingKey);
875         SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
876
877 CATCH:
878         pProvider->__stateOfWifi = 0;
879         return r;
880 }
881
882 result
883 _SettingNetworkProvider::WifiDirectDummy(void* data)
884 {
885         result r = E_SUCCESS;
886         String settingKey(_NETWORK_WIFI_DIRECT);
887         _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
888         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
889         SysTryReturnResult(NID_SYS, (pSettingInfo != null && pProvider != null), E_SYSTEM, "There is no values of args.");
890         SysTryCatch(NID_SYS, pProvider->__stateOfWifiDirect  == 1, E_SYSTEM, E_SYSTEM, "There is invalid state.");
891
892         if(pProvider->__pWifiDirectListener != null)
893         {
894                 pProvider->__pWifiDirectListener->OnResultReceivedForSetValueAsync(settingKey, E_SUCCESS);
895         }
896         r = pSettingInfo->AnnounceSettingEvent(settingKey);
897         SysTryCatch(NID_SYS, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
898
899 CATCH:
900         pProvider->__stateOfWifiDirect = 0;
901         return r;
902 }
903
904 void
905 _SettingNetworkProvider::SettingWifiActivateCallBack(wifi_error_e errorCode, void* data)
906 {
907         String settingKey(_NETWORK_WIFI);
908
909         _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
910         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
911         SysTryReturnVoidResult(NID_SYS, (pSettingInfo != null && pProvider != null), E_SYSTEM, "There is no values of args.");
912         SysTryCatch(NID_SYS, pProvider->__stateOfWifi == 1, E_SYSTEM, E_SYSTEM, "Wi-Fi processing is under way.");
913
914         switch(errorCode)
915         {
916                 case WIFI_ERROR_INVALID_PARAMETER:
917                 SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by invalid param.");
918                 break;
919                 case WIFI_ERROR_OUT_OF_MEMORY:
920                 SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by out of memory.");
921                 break;
922                 case WIFI_ERROR_INVALID_OPERATION:
923                 SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by invalid operation.");
924                 break;
925                 case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
926                 SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by family not supported.");
927                 break;
928                 case WIFI_ERROR_OPERATION_FAILED:
929                 SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by operation failed.");
930                 break;
931                 case WIFI_ERROR_NO_CONNECTION:
932                 SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by no connection.");
933                 break;
934                 case WIFI_ERROR_ALREADY_EXISTS:
935                 SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by already exist.");
936                 break;
937                 case WIFI_ERROR_OPERATION_ABORTED:
938                 SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by operation aborted.");
939                 break;
940                 case WIFI_ERROR_DHCP_FAILED:
941                 SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by DHCP fail.");
942                 break;
943                 case WIFI_ERROR_INVALID_KEY:
944                 SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by invalid key.");
945                 break;
946                 case WIFI_ERROR_NO_REPLY:
947                 SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by no reply.");
948                 break;
949                 case WIFI_ERROR_SECURITY_RESTRICTED:
950                 SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by security restricted.");
951                 break;
952                 case WIFI_ERROR_NOW_IN_PROGRESS:
953                 SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is under way.");
954                 break;
955                 case WIFI_ERROR_NONE:
956                 SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is work properly");
957                 break;
958         }
959
960         if(pProvider->__pWifiListener != null)
961         {
962                 SysLog(NID_SYS, "Wi-Fi result is forwarded.");
963                 pProvider->__pWifiListener->OnResultReceivedForSetValueAsync(settingKey, E_SUCCESS);
964         }
965         else
966         {
967                 SysLog(NID_SYS, "There is no listener.");
968         }
969 CATCH:
970         pProvider->__stateOfWifi = 0;
971 }
972
973 void
974 _SettingNetworkProvider::SettingWifiDirectStateChangedCallBack(wifi_direct_error_e errorCode, wifi_direct_device_state_e deviceState, void* data)
975 {
976         result r = E_SUCCESS;
977         String settingKey(_NETWORK_WIFI_DIRECT);
978
979         _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
980         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
981         SysTryReturnVoidResult(NID_SYS, (pSettingInfo != null && pProvider != null), E_SYSTEM, "There is no values of args.");
982
983         SysTryCatch(NID_SYS, pProvider->__stateOfWifiDirect == 1 , E_SYSTEM, E_SYSTEM, "There is invalid state.");
984
985         if(errorCode != WIFI_DIRECT_ERROR_NONE)
986         {
987                 r = E_SYSTEM;
988         }
989
990         if(pProvider->__pWifiDirectListener != null)
991         {
992                 pProvider->__pWifiDirectListener->OnResultReceivedForSetValueAsync(settingKey, r);
993         }
994
995 CATCH:
996         pProvider->__stateOfWifiDirect = 0;
997 }
998
999 result
1000 _SettingNetworkProvider::GetValue(const String& key, String& value)
1001 {
1002         int errorCode = 0;
1003         result r = E_OBJ_NOT_FOUND;
1004
1005 /*
1006         if (key == _NETWORK_WIFI_TETHERING_SECURITY_PASSWORD)
1007         {
1008                 r = E_SUCCESS;
1009                 unique_ptr<char> password(null);
1010                 char* pTemp = null;
1011                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
1012                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_SYSTEM, "It is failed to get tethering handle.");
1013
1014                 errorCode = tethering_wifi_get_passphrase(__tetheringHandle, &pTemp);
1015                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE && pTemp != null, E_SYSTEM, "It is failed to get password");
1016
1017                 password.reset(pTemp);
1018
1019                 value.Clear();
1020                 value.Append(password.get());
1021         }
1022 */
1023         return r;
1024 }
1025
1026 result
1027 _SettingNetworkProvider::SetValue(const String& key, const String value)
1028 {
1029         int errorCode = 0;
1030         result r = E_OBJ_NOT_FOUND;
1031 /*
1032         if(key ==_NETWORK_WIFI_TETHERING_SECURITY_PASSWORD)
1033         {
1034                 r = E_SUCCESS;
1035                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
1036                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_SYSTEM, "It is failed to get tethering handle.");
1037
1038                 unique_ptr<char []> password(_StringConverter::CopyToCharArrayN(value));
1039                 SysTryReturnResult(NID_SYS, password != null, E_SYSTEM, "It is failed to convert String to string");
1040                 errorCode = tethering_wifi_set_passphrase(__tetheringHandle, password.get());
1041                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to set password");
1042         }
1043 */
1044         return r;
1045 }
1046
1047 bool
1048 _SettingNetworkProvider::HasKey(const String& key)
1049 {
1050         bool wifi_supported = false;
1051         bool wifi_direct_supported = false;
1052         bool bluetooth_supported = false;
1053         bool telephony_supported = false;
1054
1055         int ret = system_info_get_platform_bool("tizen.org/feature/network.wifi", &wifi_supported);
1056         SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
1057
1058         ret = system_info_get_platform_bool("tizen.org/feature/network.wifi.direct", &wifi_direct_supported);
1059         SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
1060
1061         ret = system_info_get_platform_bool("tizen.org/feature/network.bluetooth", &bluetooth_supported);
1062         SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
1063
1064         ret = system_info_get_platform_bool("tizen.org/feature/network.telephony", &telephony_supported);
1065         SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
1066
1067         if(key == _NETWORK_FLIGHTMODE)
1068         {
1069                 return true;
1070         }
1071         else if(key == _NETWORK_TELEPHONY_PACKETSERVICE || key == _NETWORK_TELEPHONY_ROAMING)
1072         {
1073                 if(telephony_supported == true)
1074                 {
1075                         return true;
1076                 }
1077         }
1078         else if(key == _NETWORK_WIFI || key == _NETWORK_WIFI_NOTIFICATION)
1079         {
1080                 if(wifi_supported == true)
1081                 {
1082                         return true;
1083                 }
1084         }
1085         else if(key == _NETWORK_WIFI_DIRECT)
1086         {
1087                 if(wifi_direct_supported == true)
1088                 {
1089                         return true;
1090                 }
1091         }
1092         else if(key == _NETWORK_WIFI_TETHERING || key ==  _NETWORK_WIFI_TETHERING_HIDE
1093                 || key == _NETWORK_WIFI_TETHERING_SECURITY /*|| key == _NETWORK_WIFI_TETHERING_SECURITY_PASSWORD*/ || key == _USB_TETHERING)
1094         {
1095                 bool isSupported = false;
1096                 int errorCode = system_info_get_value_bool(SYSTEM_INFO_KEY_TETHERING_SUPPORTED, &isSupported);
1097
1098                 if(errorCode == SYSTEM_INFO_ERROR_NONE && isSupported == true)
1099                 {
1100                         return true;
1101                 }
1102         }
1103         else if(key == _NETWORK_BLUETOOTH)
1104         {
1105                 if(bluetooth_supported == true)
1106                 {
1107                         return true;
1108                 }
1109         }
1110         else if(key == _NETWORK_BLUETOOTH_TETHERING)
1111         {
1112                 if(__tetheringHandle != null && bluetooth_supported == true)
1113                 {
1114                         return true;
1115                 }
1116         }
1117         return false;
1118 }
1119
1120 void
1121 _SettingNetworkProvider::SettingEventRuntimeInfo(runtime_info_key_e key, void* userData)
1122 {
1123         String settingKey;
1124
1125         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
1126         SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "SettingInfo is not ready.");
1127
1128         if(key == RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED)
1129         {
1130                 settingKey.Append(_NETWORK_FLIGHTMODE);
1131         }
1132         else if(key == RUNTIME_INFO_KEY_PACKET_DATA_ENABLED)
1133         {
1134                 settingKey.Append(_NETWORK_TELEPHONY_PACKETSERVICE);
1135         }
1136         else if(key == RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED)
1137         {
1138                 settingKey.Append(_NETWORK_TELEPHONY_ROAMING);
1139         }
1140         else
1141         {
1142                 SysLogException(NID_SYS, E_SYSTEM, "It is not supported key.");
1143                 return;
1144         }
1145
1146         result r = pSettingInfo->AnnounceSettingEvent(settingKey);
1147         SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
1148 }
1149
1150 void
1151 _SettingNetworkProvider::SettingEventVConf(keynode_t* node, void* userData)
1152 {
1153         result r = E_SUCCESS;
1154         String settingKey;
1155         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
1156         SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
1157
1158         if (strcmp(VCONFKEY_WIFI_STATE, vconf_keynode_get_name(node)) == 0)
1159         {
1160                 int state = VCONFKEY_WIFI_OFF;
1161                 int errorCode = 0;
1162                 errorCode = vconf_get_int(VCONFKEY_WIFI_STATE, &state);
1163
1164                 if(errorCode == 0 && (state == VCONFKEY_WIFI_OFF || state == VCONFKEY_WIFI_UNCONNECTED))
1165                 {
1166                         settingKey.Append(_NETWORK_WIFI);
1167                         r = pSettingInfo->AnnounceSettingEvent(settingKey);
1168                         SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
1169                 }
1170                 return;
1171         }
1172         else if (strcmp(VCONFKEY_WIFI_ENABLE_QS, vconf_keynode_get_name(node)) == 0)
1173         {
1174                 settingKey.Append(_NETWORK_WIFI_NOTIFICATION);
1175         }
1176         else if (strcmp(VCONFKEY_WIFI_DIRECT_STATE, vconf_keynode_get_name(node)) == 0)
1177         {
1178                 int state = VCONFKEY_WIFI_DIRECT_DEACTIVATED;
1179                 int errorCode = 0;
1180                 errorCode = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &state);
1181                 SysLog(NID_SYS, "Wi-Fi Direct state is changed. %d", state);
1182                 if(errorCode == 0 && (state == VCONFKEY_WIFI_DIRECT_DEACTIVATED || state == VCONFKEY_WIFI_DIRECT_ACTIVATED))
1183                 {
1184                         settingKey.Append(_NETWORK_WIFI_DIRECT);
1185                         r = pSettingInfo->AnnounceSettingEvent(settingKey);
1186                         SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
1187                 }
1188                 return;
1189         }
1190         else if (strcmp(VCONFKEY_BT_STATUS, vconf_keynode_get_name(node)) == 0)
1191         {
1192                 settingKey.Append(_NETWORK_BLUETOOTH);
1193         }
1194         else if (strcmp(VCONFKEY_MOBILE_HOTSPOT_SECURITY, vconf_keynode_get_name(node)) == 0)
1195         {
1196                 settingKey.Append(_NETWORK_WIFI_TETHERING_SECURITY);
1197         }
1198         else if (strcmp(VCONFKEY_MOBILE_HOTSPOT_HIDE, vconf_keynode_get_name(node)) == 0)
1199         {
1200                 settingKey.Append(_NETWORK_WIFI_TETHERING_HIDE);
1201         }
1202         else
1203         {
1204                 SysLogException(NID_SYS, E_SYSTEM, "It is not supported key.");
1205                 return;
1206         }
1207
1208         r = pSettingInfo->AnnounceSettingEvent(settingKey);
1209         SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
1210 }
1211
1212 void
1213 _SettingNetworkProvider::SettingEventTetheringEnabled(tethering_error_e err, tethering_type_e type, bool is_requested, void* data)
1214 {
1215         String settingKey;
1216         SysLog(NID_SYS, "Tethering Endabled Event is occured.");
1217
1218         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
1219         SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
1220
1221         switch(type)
1222         {
1223         case TETHERING_TYPE_USB:
1224                 settingKey.Append(_USB_TETHERING);
1225                 break;
1226         case TETHERING_TYPE_WIFI:
1227                 settingKey.Append(_NETWORK_WIFI_TETHERING);
1228                 break;
1229         case TETHERING_TYPE_BT:
1230                 settingKey.Append(_NETWORK_BLUETOOTH_TETHERING);
1231                 break;
1232         default:
1233                 return;
1234         }
1235
1236         result r = pSettingInfo->AnnounceSettingEvent(settingKey);
1237         SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
1238 }
1239
1240 void
1241 _SettingNetworkProvider::SettingEventTetheringDisabled(tethering_error_e err, tethering_type_e type, tethering_disabled_cause_e cause,void* data)
1242 {
1243         SysLog(NID_SYS, "Tethering Disabled Event is occured.");
1244         SettingEventTetheringEnabled(err, type, false, null);
1245 }
1246
1247 void
1248 _SettingNetworkProvider::SettingEventFlightMode(TapiHandle* handle, int res, void* data, void* user_data)
1249 {
1250         String settingKey(_NETWORK_FLIGHTMODE);
1251         int errorCode = 0;
1252         result r = E_SUCCESS;
1253         SysLog(NID_SYS, "Flightmode response is handle:%x, res:%d, date:%x, user_data:%x", handle, res, data, user_data);
1254
1255         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
1256         SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "SettingInfo is not ready.");
1257         _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)user_data;
1258         SysTryReturnVoidResult(NID_SYS, pProvider != null, E_SYSTEM, "There is invalid provider.");
1259         SysTryCatch(NID_SYS, pProvider->__stateOfFlightMode == 1, E_SYSTEM, E_SYSTEM, "Current state of flight mode is not valid.");
1260
1261         switch (res)
1262         {
1263         case TAPI_POWER_FLIGHT_MODE_RESP_ON:
1264                 SysLog(NID_SYS, "It successes to change flight mode on");
1265
1266                 errorCode = vconf_set_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, true);
1267                 if (errorCode != 0)
1268                 {
1269                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to set on VCONFKEY_TELEPHONY_FLIGHT_MODE vconf.");
1270                         r = E_SYSTEM;
1271                 }
1272                 break;
1273         case TAPI_POWER_FLIGHT_MODE_RESP_OFF:
1274                 SysLog(NID_SYS, "It successes to change flight mode off");
1275
1276                 errorCode = vconf_set_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, false);
1277                 if (errorCode != 0)
1278                 {
1279                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to set on VCONFKEY_TELEPHONY_FLIGHT_MODE vconf.");
1280                         r = E_SYSTEM;
1281                 }
1282                 break;
1283         case TAPI_POWER_FLIGHT_MODE_RESP_FAIL:
1284         default:
1285                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to change flight mode");
1286                 r = E_SYSTEM;
1287         }
1288
1289         if(pProvider->__pFlightModeListener != null)
1290         {
1291                 pProvider->__pFlightModeListener->OnResultReceivedForSetValueAsync(settingKey, r);
1292         }
1293
1294 CATCH:
1295         pProvider->__stateOfFlightMode = 0;
1296 }
1297
1298 result
1299 _SettingNetworkProvider::FlightModeEnabler(void* data)
1300 {
1301         result r = E_SUCCESS;
1302         int errorCode = 0;
1303         String settingKey(_NETWORK_FLIGHTMODE);
1304
1305         _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
1306         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
1307         SysTryReturnResult(NID_SYS, pProvider != null && pSettingInfo != null, E_SYSTEM, "Provider or SettingInfo is not ready.");
1308         SysTryCatch(NID_SYS, pProvider->__stateOfFlightMode == 1, E_SYSTEM, E_SYSTEM, "Current state of flight mode is not valid.");
1309
1310         errorCode = vconf_set_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, pProvider->__flightModeEnabled);
1311         if (errorCode != 0)
1312         {
1313                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to set on VCONFKEY_TELEPHONY_FLIGHT_MODE vconf.");
1314                 r = E_SYSTEM;
1315         }
1316
1317
1318         if(pProvider->__pFlightModeListener != null)
1319         {
1320                 pProvider->__pFlightModeListener->OnResultReceivedForSetValueAsync(settingKey, r);
1321         }
1322
1323 CATCH:
1324         pProvider->__stateOfFlightMode = 0;
1325         return r;
1326 }
1327
1328 void
1329 _SettingNetworkProvider::SettingEventBluetooth(int res, bt_adapter_state_e adapter_state, void* user_data)
1330 {
1331         String settingKey(_NETWORK_BLUETOOTH);
1332         result r = E_SUCCESS;
1333         SysLog(NID_SYS, "Bluetooth callback is invoked. result:%d, adapter_state:%d, user_data:%x", res, adapter_state, user_data);
1334
1335         _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)user_data;
1336         SysTryReturnVoidResult(NID_SYS, pProvider != null, E_SYSTEM, "There is no values of args.");
1337         SysTryCatch(NID_SYS, pProvider->__stateOfBluetooth == 1, E_SYSTEM, E_SYSTEM, "Bluetooth processing is under way.");
1338
1339         if(res == BT_ERROR_NONE)
1340         {
1341                 r = E_SUCCESS;
1342         }
1343         else
1344         {
1345                 r = E_SYSTEM;
1346         }
1347
1348         if(pProvider->__pBluetoothListener != null && pProvider->__stateOfBluetooth == 1)
1349         {
1350                 pProvider->__pBluetoothListener->OnResultReceivedForSetValueAsync(settingKey, r);
1351         }
1352
1353         if(r == E_SUCCESS)
1354         {
1355                 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
1356                 SysTryCatch(NID_SYS, pSettingInfo != null, E_SYSTEM, E_SYSTEM, "_SettingInfo is not ready.");
1357
1358                 result r = pSettingInfo->AnnounceSettingEvent(settingKey);
1359                 SysTryCatch(NID_SYS, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
1360         }
1361
1362 CATCH:
1363         pProvider->__stateOfBluetooth = 0;
1364 }
1365
1366 }}