Fix system-server for settings
[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 struct charDeleter
73 {
74         void operator()(char* pValue)
75         {
76                 if(pValue != null)
77                 {
78                         free(pValue);
79                         pValue = null;
80                 }
81         }
82 };
83
84 _SettingNetworkProvider::_SettingNetworkProvider()
85         : __tapiHandle(null)
86         , __pWifiDllHandle(null)
87         , __pBluetoothDllHandle(null)
88         , __stateOfFlightMode(0)
89         , __stateOfWifi(0)
90         , __stateOfWifiDirect(0)
91         , __stateOfBluetooth(0)
92         , __flightModeEnabled(false)
93         , __networkBluetoothEnabled(false)
94         , __wifiInit(false)
95         , __wifiDirectInit(false)
96         , __pWifiListener(null)
97         , __pWifiDirectListener(null)
98         , __pFlightModeListener(null)
99         , __pBluetoothListener(null)
100 {
101         int errorCode = bt_initialize();
102         if(errorCode != 0)
103         {
104                 //For multiple usage, deinitialize should not be called when it terminated.
105                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to initialize bluetooth.");
106         }
107
108         errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED, SettingEventRuntimeInfo, null);
109         if(errorCode != 0)
110         {
111                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register flight mode event listener");
112         }
113
114         errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_PACKET_DATA_ENABLED, SettingEventRuntimeInfo, null);
115         if(errorCode != 0)
116         {
117                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register packet data event listener");
118         }
119
120         errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED, SettingEventRuntimeInfo, null);
121         if(errorCode != 0)
122         {
123                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register roaming event listener");
124         }
125
126         errorCode = vconf_notify_key_changed(VCONFKEY_WIFI_STATE, SettingEventVConf, null);
127         if(errorCode != 0)
128         {
129                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_WIFI_STATE listener");
130         }
131
132         errorCode = tethering_create(&__tetheringHandle);
133         if(errorCode != 0)
134         {
135                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to create tethering handle");
136         }
137
138         errorCode = tethering_set_enabled_cb(__tetheringHandle, TETHERING_TYPE_USB, SettingEventTetheringEnabled, null);
139         if(errorCode != 0)
140         {
141                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_USB listener");
142         }
143
144         errorCode = tethering_set_enabled_cb(__tetheringHandle, TETHERING_TYPE_WIFI, SettingEventTetheringEnabled, null);
145         if(errorCode != 0)
146         {
147                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_WIFI listener");
148         }
149
150         errorCode = tethering_set_enabled_cb(__tetheringHandle, TETHERING_TYPE_BT, SettingEventTetheringEnabled, null);
151         if(errorCode != 0)
152         {
153                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_BT listener");
154         }
155
156         errorCode = tethering_set_disabled_cb(__tetheringHandle, TETHERING_TYPE_USB, SettingEventTetheringDisabled, null);
157         if(errorCode != 0)
158         {
159                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_USB listener");
160         }
161
162         errorCode = tethering_set_disabled_cb(__tetheringHandle, TETHERING_TYPE_WIFI, SettingEventTetheringDisabled, null);
163         if(errorCode != 0)
164         {
165                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_WIFI listener");
166         }
167
168         errorCode = tethering_set_disabled_cb(__tetheringHandle, TETHERING_TYPE_BT, SettingEventTetheringDisabled, null);
169         if(errorCode != 0)
170         {
171                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_BT listener");
172         }
173
174         errorCode = vconf_notify_key_changed(VCONFKEY_WIFI_DIRECT_STATE, SettingEventVConf, null);
175         if(errorCode != 0)
176         {
177                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_WIFI_DIRECT_STATE listener");
178         }
179
180         errorCode = vconf_notify_key_changed(VCONFKEY_BT_STATUS, SettingEventVConf, null);
181         if(errorCode != 0)
182         {
183                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_BT_STATUS listener");
184         }
185
186         errorCode = vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_SECURITY, SettingEventVConf, null);
187         if(errorCode != 0)
188         {
189                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_MOBILE_HOTSPOT_SECURITY listener");
190         }
191
192         errorCode = vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_HIDE, SettingEventVConf, null);
193         if(errorCode != 0)
194         {
195                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_MOBILE_HOTSPOT_HIDE listener");
196         }
197
198         errorCode = vconf_notify_key_changed(VCONFKEY_WIFI_ENABLE_QS, SettingEventVConf, null);
199         if(errorCode != 0)
200         {
201                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_WIFI_ENABLE_QS listener");
202         }
203
204         errorCode = bt_adapter_set_state_changed_cb(SettingEventBluetooth, (void*)this);
205         if(errorCode != 0)
206         {
207                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register bluetooth listener");
208         }
209
210         if(__wifiInit == false)
211         {
212                 SysLog(NID_SYS, "wifi init is started");
213                 errorCode = wifi_initialize();
214                 SysLog(NID_SYS, "wifi init result is %d", errorCode);
215                 __wifiInit = true;
216         }
217 }
218
219
220 _SettingNetworkProvider::~_SettingNetworkProvider()
221 {
222         int errorCode = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED);
223         if(errorCode != 0)
224         {
225                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister flight mode event listener");
226         }
227
228         errorCode = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_PACKET_DATA_ENABLED);
229         if(errorCode != 0)
230         {
231                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister packet data event listener");
232         }
233
234         errorCode = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED);
235         if(errorCode != 0)
236         {
237                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister roaming event listener");
238         }
239
240         errorCode = vconf_ignore_key_changed(VCONFKEY_WIFI_STATE, SettingEventVConf);
241         if(errorCode != 0)
242         {
243                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_WIFI_STATE listener");
244         }
245
246         errorCode = tethering_unset_enabled_cb(__tetheringHandle, TETHERING_TYPE_USB);
247         if(errorCode != 0)
248         {
249                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_USB listener");
250         }
251
252         errorCode = tethering_unset_enabled_cb(__tetheringHandle, TETHERING_TYPE_WIFI);
253         if(errorCode != 0)
254         {
255                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_WIFI listener");
256         }
257
258         errorCode = tethering_unset_enabled_cb(__tetheringHandle, TETHERING_TYPE_BT);
259         if(errorCode != 0)
260         {
261                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_BT listener");
262         }
263
264         errorCode = tethering_unset_disabled_cb(__tetheringHandle, TETHERING_TYPE_USB);
265         if(errorCode != 0)
266         {
267                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_USB listener");
268         }
269
270         errorCode = tethering_unset_disabled_cb(__tetheringHandle, TETHERING_TYPE_WIFI);
271         if(errorCode != 0)
272         {
273                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_WIFI listener");
274         }
275
276         errorCode = tethering_unset_disabled_cb(__tetheringHandle, TETHERING_TYPE_BT);
277         if(errorCode != 0)
278         {
279                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_BT listener");
280         }
281
282         tethering_destroy(__tetheringHandle);
283         __tetheringHandle = null;
284
285         errorCode = vconf_ignore_key_changed(VCONFKEY_WIFI_DIRECT_STATE, SettingEventVConf);
286         if(errorCode != 0)
287         {
288                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_WIFI_DIRECT_STATE listener");
289         }
290         errorCode = vconf_ignore_key_changed(VCONFKEY_BT_STATUS, SettingEventVConf);
291         if(errorCode != 0)
292         {
293                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_BT_STATUS listener");
294         }
295
296         errorCode = vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_SECURITY, SettingEventVConf);
297         if(errorCode != 0)
298         {
299                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_MOBILE_HOTSPOT_SECURITY listener");
300         }
301
302         errorCode = vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_HIDE, SettingEventVConf);
303         if(errorCode != 0)
304         {
305                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_MOBILE_HOTSPOT_HIDE listener");
306         }
307
308         errorCode = vconf_ignore_key_changed(VCONFKEY_WIFI_ENABLE_QS, SettingEventVConf);
309         if(errorCode != 0)
310         {
311                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_WIFI_ENABLE_QS listener");
312         }
313
314         errorCode = bt_adapter_unset_state_changed_cb();
315         if(errorCode != 0)
316         {
317                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister bluetooth listener");
318         }
319
320         errorCode = bt_deinitialize();
321         if(errorCode != 0)
322         {
323                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to deinitialize bluetooth.");
324         }
325
326         if(__wifiDirectInit == true)
327         {
328                 errorCode = wifi_direct_unset_device_state_changed_cb();
329                 if(errorCode == WIFI_DIRECT_ERROR_NONE)
330                 {
331                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister Wi-Fi direct callback.");
332                 }
333
334                 errorCode = wifi_direct_deinitialize();
335                 if(errorCode == WIFI_DIRECT_ERROR_NONE)
336                 {
337                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to deinitialize Wi-Fi direct.");
338                 }
339                 SysLog(NID_SYS, "Wifi direct de-init result is %d.", errorCode);
340                 __wifiDirectInit = false;
341         }
342
343         if(__wifiInit == true)
344         {
345                 errorCode = wifi_deinitialize();
346                 if(errorCode == WIFI_ERROR_NONE)
347                 {
348                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to deinitialize Wi-Fi.");
349                 }
350                 SysLog(NID_SYS, "Wifi de-init result is %d.", errorCode);
351                 __wifiInit = false;
352         }
353         SysLog(NID_SYS, "Network Provider is terminated properly.");
354 }
355
356 result
357 _SettingNetworkProvider::GetValue(const String& key, bool& value)
358 {
359         int errorCode = 0;
360         result r = E_OBJ_NOT_FOUND;
361
362         if(key == _NETWORK_FLIGHTMODE)
363         {
364                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support flightmode feature.");
365                 bool flightModeEnabled = false;
366                 r = E_SUCCESS;
367                 errorCode = runtime_info_get_value_bool(RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED, &flightModeEnabled);
368                 SysTryReturnResult(NID_SYS, errorCode == RUNTIME_INFO_ERROR_NONE, E_SYSTEM, "It is failed to get the RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED");
369                 value = flightModeEnabled;
370         }
371         else if(key == _NETWORK_TELEPHONY_PACKETSERVICE)
372         {
373                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Telephony packet service feature.");
374                 bool packetServiceAllowed = false;
375                 r = E_SUCCESS;
376                 errorCode = runtime_info_get_value_bool(RUNTIME_INFO_KEY_PACKET_DATA_ENABLED, &packetServiceAllowed);
377                 SysTryReturnResult(NID_SYS, errorCode == RUNTIME_INFO_ERROR_NONE, E_SYSTEM, "It is failed to get the RUNTIME_INFO_KEY_PACKET_DATA_ENABLED");
378                 value = packetServiceAllowed;
379         }
380         else if(key == _NETWORK_TELEPHONY_ROAMING)
381         {
382                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Telephony roaming feature.");
383                 bool dataRoamingEnabled = false;
384                 r = E_SUCCESS;
385                 errorCode = runtime_info_get_value_bool(RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED, &dataRoamingEnabled);
386                 SysTryReturnResult(NID_SYS, errorCode == RUNTIME_INFO_ERROR_NONE, E_SYSTEM, "It is failed to get the RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED");
387                 value = dataRoamingEnabled;
388         }
389         else if (key == _NETWORK_WIFI)
390         {
391                 r = E_SUCCESS;
392                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
393
394                 bool wifiState = false;
395                 errorCode = wifi_is_activated(&wifiState);
396                 SysTryReturnResult(NID_SYS, errorCode == WIFI_ERROR_NONE, E_SYSTEM, "It is failed to get from wifi_is_activated.");
397                 value = wifiState;
398         }
399         else if (key == _NETWORK_WIFI_NOTIFICATION)
400         {
401                 int wifiQSState = 0;
402                 r = E_SUCCESS;
403                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
404
405                 errorCode = vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &wifiQSState);
406                 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_WIFI_ENABLE_QS vconf.");
407
408                 if(wifiQSState == VCONFKEY_WIFI_QS_DISABLE)
409                 {
410                         value = false;
411                 }
412                 else
413                 {
414                         value = true;
415                 }
416         }
417         else if (key == _NETWORK_WIFI_TETHERING)
418         {
419                 r = E_SUCCESS;
420                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
421                 value = tethering_is_enabled(__tetheringHandle, TETHERING_TYPE_WIFI);
422         }
423         else if (key == _NETWORK_WIFI_TETHERING_HIDE)
424         {
425                 r = E_SUCCESS;
426                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
427                 errorCode = tethering_wifi_get_ssid_visibility(__tetheringHandle, &value);
428                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to get wifi tethering visibility state");
429         }
430         else if (key == _NETWORK_WIFI_TETHERING_SECURITY)
431         {
432                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
433                 r = E_SUCCESS;
434                 tethering_wifi_security_type_e securityType;
435                 errorCode = tethering_wifi_get_security_type(__tetheringHandle, &securityType);
436                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to get wifi tethering securiy state");
437                 if(securityType == TETHERING_WIFI_SECURITY_TYPE_NONE)
438                 {
439                         value = false;
440                 }
441                 else
442                 {
443                         value = true;
444                 }
445         }
446         else if (key == _USB_TETHERING)
447         {
448                 r = E_SUCCESS;
449                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support USB tethering feature.");
450                 value = tethering_is_enabled(__tetheringHandle, TETHERING_TYPE_USB);
451         }
452         else if (key == _NETWORK_WIFI_DIRECT)
453         {
454                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi direct feature.");
455                 r = E_SUCCESS;
456
457                 int isActivated = 0;
458                 errorCode = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &isActivated);
459                 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_WIFI_ENABLE_QS vconf.");
460
461                 if(isActivated == 1)
462                 {
463                         value = true;
464                 }
465                 else
466                 {
467                         value = false;
468                 }
469         }
470         else if (key == _NETWORK_BLUETOOTH)
471         {
472                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Bluetooth feature.");
473                 r = E_SUCCESS;
474                 int bluetoothStatus = VCONFKEY_BT_STATUS_OFF;
475                 errorCode = vconf_get_int(VCONFKEY_BT_STATUS, &bluetoothStatus);
476                 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to read bluetooth status.");
477
478                 if(bluetoothStatus == VCONFKEY_BT_STATUS_OFF)
479                 {
480                         value = false;
481                 }
482                 else
483                 {
484                         value = true;
485                 }
486         }
487         else if (key == _NETWORK_BLUETOOTH_TETHERING)
488         {
489                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Bluetooth tethering feature.");
490                 r = E_SUCCESS;
491                 value  = tethering_is_enabled(__tetheringHandle, TETHERING_TYPE_BT);
492         }
493         return r;
494 }
495
496 result
497 _SettingNetworkProvider::SetValue(const String& key, const bool value)
498 {
499         int errorCode = 0;
500         result r = E_OBJ_NOT_FOUND;
501
502         if(key == _NETWORK_WIFI_NOTIFICATION)
503         {
504                 int currentValue = 0;
505                 r = E_SUCCESS;
506                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
507                 errorCode = vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &currentValue);
508                 SysTryReturnResult(NID_SYS, errorCode != -1, E_UNSUPPORTED_OPERATION, "This device does not support %ls key.", key.GetPointer());
509
510                 if(value == true)
511                 {
512                         errorCode = vconf_set_int(VCONFKEY_WIFI_ENABLE_QS, VCONFKEY_WIFI_QS_ENABLE);
513                 }
514                 else
515                 {
516                         errorCode = vconf_set_int(VCONFKEY_WIFI_ENABLE_QS, VCONFKEY_WIFI_QS_DISABLE);
517                 }
518                 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_WIFI_ENABLE_QS vconf.");
519         }
520         else if(key == _NETWORK_WIFI_TETHERING)
521         {
522                 bool state = false;
523                 r = E_SUCCESS;
524                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
525                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_UNSUPPORTED_OPERATION, "Current device does not support tethering feature.");
526                 r = GetValue(_NETWORK_WIFI, state);
527                 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get the WIFI state");
528                 SysTryReturnResult(NID_SYS, state == true, E_INVALID_STATE, "WIFI is not activated");
529
530                 if(value == true)
531                 {
532                         errorCode = tethering_enable(__tetheringHandle, TETHERING_TYPE_WIFI);
533                 }
534                 else
535                 {
536                         errorCode = tethering_disable(__tetheringHandle, TETHERING_TYPE_WIFI);
537                 }
538                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change tethering option.");
539         }
540         else if(key == _NETWORK_WIFI_TETHERING_HIDE)
541         {
542                 r = E_SUCCESS;
543                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
544
545                 bool currentState = false;
546                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_UNSUPPORTED_OPERATION, "Current device does not support tethering feature.");
547                 errorCode = tethering_wifi_get_ssid_visibility(__tetheringHandle, &currentState);
548                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to current wifi tethering visibility setting");
549
550                 if(value == true && currentState == false)
551                 {
552                         errorCode = tethering_wifi_set_ssid_visibility(__tetheringHandle, true);
553                 }
554                 else if(value == false && currentState == true)
555                 {
556                         errorCode = tethering_wifi_set_ssid_visibility(__tetheringHandle, false);
557                 }
558                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change wifi tethering visibility setting");
559         }
560         else if(key == _NETWORK_WIFI_TETHERING_SECURITY)
561         {
562                 r = E_SUCCESS;
563                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
564
565                 tethering_wifi_security_type_e securityType;
566                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_UNSUPPORTED_OPERATION, "Current device does not support tethering feature.");
567
568                 errorCode = tethering_wifi_get_security_type(__tetheringHandle, &securityType);
569                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to get wifi tethering securiy state");
570
571                 if(value == true && securityType == TETHERING_WIFI_SECURITY_TYPE_NONE)
572                 {
573                         errorCode = tethering_wifi_set_security_type(__tetheringHandle, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK);
574                 }
575                 else if(value == false && securityType == TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK)
576                 {
577                         errorCode = tethering_wifi_set_security_type(__tetheringHandle, TETHERING_WIFI_SECURITY_TYPE_NONE);
578                 }
579                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change wifi tethering visibility setting");
580         }
581         else if(key == _USB_TETHERING)
582         {
583                 r = E_SUCCESS;
584                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support tethering feature.");
585
586                 if(value == true)
587                 {
588                         errorCode = tethering_enable(__tetheringHandle, TETHERING_TYPE_USB);
589                 }
590                 else
591                 {
592                         errorCode = tethering_disable(__tetheringHandle, TETHERING_TYPE_USB);
593                 }
594                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change tethering option");
595         }
596         else if(key == _NETWORK_BLUETOOTH_TETHERING)
597         {
598                 r = E_SUCCESS;
599                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support tethering feature.");
600
601                 bool state = false;
602                 r = GetValue(_NETWORK_BLUETOOTH, state);
603                 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get the Bluetooth state");
604                 SysTryReturnResult(NID_SYS, state == true, E_INVALID_STATE, "Bluetooth is not activated");
605
606                 if(value == true)
607                 {
608                         errorCode = tethering_enable(__tetheringHandle, TETHERING_TYPE_BT);
609                 }
610                 else
611                 {
612                         errorCode = tethering_disable(__tetheringHandle, TETHERING_TYPE_BT);
613                 }
614                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change tethering option");
615         }
616         return r;
617 }
618
619 result
620 _SettingNetworkProvider::SetValueAsync(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
621 {
622         int ret = 0;
623         result r = E_OBJ_NOT_FOUND;
624
625         if(key == _NETWORK_BLUETOOTH)
626         {
627                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Bluetooth feature.");
628                 SysTryReturnResult(NID_SYS, __stateOfBluetooth == 0, E_IN_PROGRESS, "Bluetooth is under changing procedure.");
629                 r = E_SUCCESS;
630                 __stateOfBluetooth = 1;
631                 __pBluetoothListener = listener;
632
633                 SysLog(NID_SYS, "Required bluetooth value is %d.", value);
634                 if(value == true)
635                 {
636                         ret = bt_adapter_enable();
637                 }
638                 else
639                 {
640                         ret = bt_adapter_disable();
641                 }
642
643                 SysLog(NID_SYS, "bt_adapter returns %d.", ret);
644
645                 switch(ret)
646                 {
647                 case BT_ERROR_NONE:
648                         SysLog(NID_SYS, "It is OK to change the bluetooth mode.");
649                         break;
650
651                 case BT_ERROR_ALREADY_DONE:
652                         SysLog(NID_SYS, "Bluetooth is already changed.");
653                         SettingEventBluetooth(BT_ERROR_NONE, BT_ADAPTER_ENABLED, (void*)this);
654                         break;
655                 case BT_ERROR_NOT_ENABLED:
656                         SysLog(NID_SYS, "Bluetooth is not enabled.");
657                         SettingEventBluetooth(BT_ERROR_NONE, BT_ADAPTER_ENABLED, (void*)this);
658                         break;
659
660                 case BT_ERROR_NOW_IN_PROGRESS:
661                         SysLog(NID_SYS, "Currently, Bluetooth change is in progress.");
662                         __stateOfBluetooth = 0;
663                         r = E_IN_PROGRESS;
664                         break;
665
666                 case BT_ERROR_NOT_INITIALIZED:
667                 default:
668                         SysLog(NID_SYS, "There is an unknown error when changing the bluetooth mode.");
669                         __stateOfBluetooth = 0;
670                         r = E_SYSTEM;
671                         break;
672                 }
673         }
674         return r;
675 }
676
677 result
678 _SettingNetworkProvider::SetValueForPrivilegedKey(const String& key, bool value)
679 {
680         int errorCode = 0;
681         result r = E_OBJ_NOT_FOUND;
682         if(key == _NETWORK_TELEPHONY_PACKETSERVICE)
683         {
684                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support telephony packet service feature.");
685                 r = E_SUCCESS;
686                 errorCode = vconf_set_bool(VCONFKEY_3G_ENABLE, value);
687                 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_3G_ENABLE vconf.");
688         }
689         else if(key == _NETWORK_TELEPHONY_ROAMING)
690         {
691                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support telephony roaming feature.");
692                 r = E_SUCCESS;
693                 errorCode = vconf_set_bool(VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, value);
694                 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL vconf.");
695         }
696         return r;
697 }
698
699 result
700 _SettingNetworkProvider::SetValueAsyncForPrivilegedKey(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
701 {
702         int errorCode = 0;
703         result r = E_OBJ_NOT_FOUND;
704
705         if(key == _NETWORK_FLIGHTMODE)
706         {
707                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support flightmode feature.");
708                 r = E_SUCCESS;
709
710                 SysTryReturnResult(NID_SYS, __stateOfFlightMode == 0, E_IN_PROGRESS, "Flightmode is under changing procedure.");
711                 __stateOfFlightMode = 1;
712
713                 bool supported = false;
714                 int ret = system_info_get_platform_bool("tizen.org/feature/network.telephony", &supported);
715                 SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
716
717                 __pFlightModeListener = listener;
718                 if(supported == true)
719                 {
720                         if(__tapiHandle ==  null)
721                         {
722                                 __tapiHandle = tel_init(null);
723                                 if(__tapiHandle == null)
724                                 {
725                                         __stateOfFlightMode = 0;
726                                 }
727                                 SysTryReturnResult(NID_SYS, __tapiHandle != null, E_SYSTEM, "Tapi is not ready.");
728                         }
729                         errorCode = tel_set_flight_mode(__tapiHandle,
730                                         value ? TAPI_POWER_FLIGHT_MODE_ENTER : TAPI_POWER_FLIGHT_MODE_LEAVE,
731                                         SettingEventFlightMode, (void*)this);
732
733                         if(errorCode != 0)
734                         {
735                                 __stateOfFlightMode = 0;
736                         }
737                         SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on Network Flight mode(%d).", errorCode);
738                 }
739                 else
740                 {
741                         FlightModeEnabler((void*)this);
742                 }
743         }
744         else if(key == _NETWORK_WIFI)
745         {
746                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
747                 SysTryReturnResult(NID_SYS, __stateOfWifi == 0 && __stateOfWifiDirect == 0, E_IN_PROGRESS, "Wifi processing is under way.");
748                 r = E_SUCCESS;
749
750                 __stateOfWifi = 1;
751                 SysLog(NID_SYS, "It creates thread for wifi enable[%d].", value);
752
753                 bool wifiEnabled = false;
754                 __pWifiListener = listener;
755                 errorCode = wifi_is_activated(&wifiEnabled);
756                 if(errorCode != WIFI_ERROR_NONE)
757                 {
758                         __stateOfWifi = 0;
759                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to get current status of WIFI.");
760                         return E_SYSTEM;
761                 }
762
763                 if(value == wifiEnabled) //Wi-Fi is already changed.
764                 {
765                         SysLog(NID_SYS, "It is try to use dummy thread");
766                         r = WifiDummy((void*)this);
767                         SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to set Wi-Fi state.");
768                         return r;
769                 }
770
771                 if(value == true)
772                 {
773                         errorCode = wifi_activate(SettingWifiActivateCallBack, (void*) this);
774                 }
775                 else
776                 {
777                         errorCode = wifi_deactivate(SettingWifiActivateCallBack, (void*) this);
778                 }
779
780                 if(errorCode != WIFI_ERROR_NONE)
781                 {
782                         __stateOfWifi = 0;
783                         return E_SYSTEM;
784                 }
785         }
786         else if(key == _NETWORK_WIFI_DIRECT)
787         {
788                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
789                 SysTryReturnResult(NID_SYS, __stateOfWifi == 0 && __stateOfWifiDirect == 0, E_IN_PROGRESS, "Wifi processing is under way.");
790                 r = E_SUCCESS;
791
792                 __stateOfWifiDirect = 1;
793                 SysLog(NID_SYS, "It creates thread for wifi direct enable[%d].", value);
794
795
796                 __pWifiDirectListener = listener;
797                 if(__wifiDirectInit == false)
798                 {
799                         SysLog(NID_SYS, "wifi direct init is started");
800                         errorCode = wifi_direct_initialize();
801                         SysLog(NID_SYS, "wifi direct init result is %d", errorCode);
802                         SysTryReturnResult(NID_SYS, errorCode == WIFI_DIRECT_ERROR_NONE, E_SYSTEM, "It is failed to init wifi direct.");
803                         errorCode = wifi_direct_set_device_state_changed_cb(SettingWifiDirectStateChangedCallBack, (void*) this);
804                         SysTryReturnResult(NID_SYS, errorCode == WIFI_DIRECT_ERROR_NONE, E_SYSTEM, "It is failed to register wifi direct result callback.");
805                         __wifiDirectInit = true;
806                 }
807
808
809                 wifi_direct_state_e wifi_direct_state;
810                 errorCode = wifi_direct_get_state(&wifi_direct_state);
811                 if(errorCode != WIFI_DIRECT_ERROR_NONE)
812                 {
813                         __stateOfWifiDirect = 0;
814                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to get current status of WIFI direct.");
815                         return E_SYSTEM;
816                 }
817
818                 if((value == false && wifi_direct_state == WIFI_DIRECT_STATE_DEACTIVATED)
819                         || (value == true && wifi_direct_state != WIFI_DIRECT_STATE_DEACTIVATED))
820                 {
821                         SysLog(NID_SYS, "Required state is already applied.");
822                         WifiDirectDummy((void*)this);
823                         return E_SUCCESS;
824                 }
825
826                 if(value == true)
827                 {
828                         errorCode = wifi_direct_activate();
829                 }
830                 else
831                 {
832                         errorCode = wifi_direct_deactivate();
833                 }
834                 SysLog(NID_SYS, "wifi_direct_activate result is %d. value is %d.", errorCode, value);
835
836                 if(errorCode < 0)
837                 {
838                         return E_SYSTEM;
839                 }
840         }
841         return r;
842 }
843
844 result
845 _SettingNetworkProvider::WifiDummy(void* data)
846 {
847         result r = E_SUCCESS;
848         String settingKey(_NETWORK_WIFI);
849         _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
850         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
851         SysTryReturnResult(NID_SYS, (pSettingInfo != null && pProvider != null), E_SYSTEM, "There is no values of args.");
852
853         SysTryCatch(NID_SYS, pProvider->__stateOfWifi == 1, r = E_SYSTEM, E_SYSTEM, "There is invalid state.");
854
855         if(pProvider->__pWifiListener != null)
856         {
857                 pProvider->__pWifiListener->OnResultReceivedForSetValueAsync(settingKey, E_SUCCESS);
858         }
859         r = pSettingInfo->AnnounceSettingEvent(settingKey);
860         SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
861
862 CATCH:
863         pProvider->__stateOfWifi = 0;
864         return r;
865 }
866
867 result
868 _SettingNetworkProvider::WifiDirectDummy(void* data)
869 {
870         result r = E_SUCCESS;
871         String settingKey(_NETWORK_WIFI_DIRECT);
872         _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
873         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
874         SysTryReturnResult(NID_SYS, (pSettingInfo != null && pProvider != null), E_SYSTEM, "There is no values of args.");
875         SysTryCatch(NID_SYS, pProvider->__stateOfWifiDirect  == 1, E_SYSTEM, E_SYSTEM, "There is invalid state.");
876
877         if(pProvider->__pWifiDirectListener != null)
878         {
879                 pProvider->__pWifiDirectListener->OnResultReceivedForSetValueAsync(settingKey, E_SUCCESS);
880         }
881         r = pSettingInfo->AnnounceSettingEvent(settingKey);
882         SysTryCatch(NID_SYS, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
883
884 CATCH:
885         pProvider->__stateOfWifiDirect = 0;
886         return r;
887 }
888
889 void
890 _SettingNetworkProvider::SettingWifiActivateCallBack(wifi_error_e errorCode, void* data)
891 {
892         String settingKey(_NETWORK_WIFI);
893
894         _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
895         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
896         SysTryReturnVoidResult(NID_SYS, (pSettingInfo != null && pProvider != null), E_SYSTEM, "There is no values of args.");
897         SysTryCatch(NID_SYS, pProvider->__stateOfWifi == 1, E_SYSTEM, E_SYSTEM, "Wi-Fi processing is under way.");
898
899         if(errorCode != WIFI_ERROR_NONE)
900         {
901                 switch(errorCode)
902                 {
903                         case WIFI_ERROR_INVALID_PARAMETER:
904                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by invalid param.");
905                         break;
906                         case WIFI_ERROR_OUT_OF_MEMORY:
907                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by out of memory.");
908                         break;
909                         case WIFI_ERROR_INVALID_OPERATION:
910                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by invalid operation.");
911                         break;
912                         case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
913                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by family not supported.");
914                         break;
915                         case WIFI_ERROR_OPERATION_FAILED:
916                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by operation failed.");
917                         break;
918                         case WIFI_ERROR_NO_CONNECTION:
919                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by no connection.");
920                         break;
921                         case WIFI_ERROR_ALREADY_EXISTS:
922                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by already exist.");
923                         break;
924                         case WIFI_ERROR_OPERATION_ABORTED:
925                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by operation aborted.");
926                         break;
927                         case WIFI_ERROR_DHCP_FAILED:
928                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by DHCP fail.");
929                         break;
930                         case WIFI_ERROR_INVALID_KEY:
931                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by invalid key.");
932                         break;
933                         case WIFI_ERROR_NO_REPLY:
934                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by no reply.");
935                         break;
936                         case WIFI_ERROR_SECURITY_RESTRICTED:
937                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by security restricted.");
938                         break;
939                         case WIFI_ERROR_NOW_IN_PROGRESS:
940                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is under way.");
941                         break;
942                 }
943         }
944
945         if(pProvider->__pWifiDirectListener != null)
946         {
947                 pProvider->__pWifiDirectListener->OnResultReceivedForSetValueAsync(settingKey, E_SUCCESS);
948         }
949 CATCH:
950         pProvider->__stateOfWifi = 0;
951 }
952
953 void
954 _SettingNetworkProvider::SettingWifiDirectStateChangedCallBack(wifi_direct_error_e errorCode, wifi_direct_device_state_e deviceState, void* data)
955 {
956         result r = E_SUCCESS;
957         String settingKey(_NETWORK_WIFI_DIRECT);
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 }}