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