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