Fix tethering failure
[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         if(errorCode != WIFI_ERROR_NONE)
919         {
920                 switch(errorCode)
921                 {
922                         case WIFI_ERROR_INVALID_PARAMETER:
923                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by invalid param.");
924                         break;
925                         case WIFI_ERROR_OUT_OF_MEMORY:
926                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by out of memory.");
927                         break;
928                         case WIFI_ERROR_INVALID_OPERATION:
929                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by invalid operation.");
930                         break;
931                         case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
932                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by family not supported.");
933                         break;
934                         case WIFI_ERROR_OPERATION_FAILED:
935                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by operation failed.");
936                         break;
937                         case WIFI_ERROR_NO_CONNECTION:
938                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by no connection.");
939                         break;
940                         case WIFI_ERROR_ALREADY_EXISTS:
941                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by already exist.");
942                         break;
943                         case WIFI_ERROR_OPERATION_ABORTED:
944                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by operation aborted.");
945                         break;
946                         case WIFI_ERROR_DHCP_FAILED:
947                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by DHCP fail.");
948                         break;
949                         case WIFI_ERROR_INVALID_KEY:
950                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by invalid key.");
951                         break;
952                         case WIFI_ERROR_NO_REPLY:
953                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by no reply.");
954                         break;
955                         case WIFI_ERROR_SECURITY_RESTRICTED:
956                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by security restricted.");
957                         break;
958                         case WIFI_ERROR_NOW_IN_PROGRESS:
959                         SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is under way.");
960                         break;
961                 }
962         }
963
964         if(pProvider->__pWifiDirectListener != null)
965         {
966                 pProvider->__pWifiDirectListener->OnResultReceivedForSetValueAsync(settingKey, E_SUCCESS);
967         }
968 CATCH:
969         pProvider->__stateOfWifi = 0;
970 }
971
972 void
973 _SettingNetworkProvider::SettingWifiDirectStateChangedCallBack(wifi_direct_error_e errorCode, wifi_direct_device_state_e deviceState, void* data)
974 {
975         result r = E_SUCCESS;
976         String settingKey(_NETWORK_WIFI_DIRECT);
977
978         _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
979         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
980         SysTryReturnVoidResult(NID_SYS, (pSettingInfo != null && pProvider != null), E_SYSTEM, "There is no values of args.");
981
982         SysTryCatch(NID_SYS, pProvider->__stateOfWifiDirect == 1 , E_SYSTEM, E_SYSTEM, "There is invalid state.");
983
984         if(errorCode != WIFI_DIRECT_ERROR_NONE)
985         {
986                 r = E_SYSTEM;
987         }
988
989         if(pProvider->__pWifiDirectListener != null)
990         {
991                 pProvider->__pWifiDirectListener->OnResultReceivedForSetValueAsync(settingKey, r);
992         }
993
994 CATCH:
995         pProvider->__stateOfWifiDirect = 0;
996 }
997
998 result
999 _SettingNetworkProvider::GetValue(const String& key, String& value)
1000 {
1001         int errorCode = 0;
1002         result r = E_OBJ_NOT_FOUND;
1003
1004         if (key == _NETWORK_WIFI_TETHERING_SECURITY_PASSWORD)
1005         {
1006                 r = E_SUCCESS;
1007                 unique_ptr<char> password(null);
1008                 char* pTemp = null;
1009                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
1010                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_SYSTEM, "It is failed to get tethering handle.");
1011
1012                 errorCode = tethering_wifi_get_passphrase(__tetheringHandle, &pTemp);
1013                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE && pTemp != null, E_SYSTEM, "It is failed to get password");
1014
1015                 password.reset(pTemp);
1016
1017                 value.Clear();
1018                 value.Append(password.get());
1019         }
1020         return r;
1021 }
1022
1023 result
1024 _SettingNetworkProvider::SetValue(const String& key, const String value)
1025 {
1026         int errorCode = 0;
1027         result r = E_OBJ_NOT_FOUND;
1028
1029         if(key ==_NETWORK_WIFI_TETHERING_SECURITY_PASSWORD)
1030         {
1031                 r = E_SUCCESS;
1032                 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
1033                 SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_SYSTEM, "It is failed to get tethering handle.");
1034
1035                 unique_ptr<char []> password(_StringConverter::CopyToCharArrayN(value));
1036                 SysTryReturnResult(NID_SYS, password != null, E_SYSTEM, "It is failed to convert String to string");
1037                 errorCode = tethering_wifi_set_passphrase(__tetheringHandle, password.get());
1038                 SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to set password");
1039         }
1040         return r;
1041 }
1042
1043 bool
1044 _SettingNetworkProvider::HasKey(const String& key)
1045 {
1046         bool wifi_supported = false;
1047         bool wifi_direct_supported = false;
1048         bool bluetooth_supported = false;
1049         bool telephony_supported = false;
1050
1051         int ret = system_info_get_platform_bool("tizen.org/feature/network.wifi", &wifi_supported);
1052         SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
1053
1054         ret = system_info_get_platform_bool("tizen.org/feature/network.wifi.direct", &wifi_direct_supported);
1055         SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
1056
1057         ret = system_info_get_platform_bool("tizen.org/feature/network.bluetooth", &bluetooth_supported);
1058         SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
1059
1060         ret = system_info_get_platform_bool("tizen.org/feature/network.telephony", &telephony_supported);
1061         SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
1062
1063         if(key == _NETWORK_FLIGHTMODE)
1064         {
1065                 return true;
1066         }
1067         else if(key == _NETWORK_TELEPHONY_PACKETSERVICE || key == _NETWORK_TELEPHONY_ROAMING)
1068         {
1069                 if(telephony_supported == true)
1070                 {
1071                         return true;
1072                 }
1073         }
1074         else if(key == _NETWORK_WIFI || key == _NETWORK_WIFI_NOTIFICATION)
1075         {
1076                 if(wifi_supported == true)
1077                 {
1078                         return true;
1079                 }
1080         }
1081         else if(key == _NETWORK_WIFI_DIRECT)
1082         {
1083                 if(wifi_direct_supported == true)
1084                 {
1085                         return true;
1086                 }
1087         }
1088         else if(key == _NETWORK_WIFI_TETHERING || key ==  _NETWORK_WIFI_TETHERING_HIDE
1089                 || key == _NETWORK_WIFI_TETHERING_SECURITY || key == _NETWORK_WIFI_TETHERING_SECURITY_PASSWORD || key == _USB_TETHERING)
1090         {
1091                 bool isSupported = false;
1092                 int errorCode = system_info_get_value_bool(SYSTEM_INFO_KEY_TETHERING_SUPPORTED, &isSupported);
1093
1094                 if(errorCode == SYSTEM_INFO_ERROR_NONE && isSupported == true)
1095                 {
1096                         return true;
1097                 }
1098         }
1099         else if(key == _NETWORK_BLUETOOTH)
1100         {
1101                 if(bluetooth_supported == true)
1102                 {
1103                         return true;
1104                 }
1105         }
1106         else if(key == _NETWORK_BLUETOOTH_TETHERING)
1107         {
1108                 if(__tetheringHandle != null && bluetooth_supported == true)
1109                 {
1110                         return true;
1111                 }
1112         }
1113         return false;
1114 }
1115
1116 void
1117 _SettingNetworkProvider::SettingEventRuntimeInfo(runtime_info_key_e key, void* userData)
1118 {
1119         String settingKey;
1120
1121         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
1122         SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "SettingInfo is not ready.");
1123
1124         if(key == RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED)
1125         {
1126                 settingKey.Append(_NETWORK_FLIGHTMODE);
1127         }
1128         else if(key == RUNTIME_INFO_KEY_PACKET_DATA_ENABLED)
1129         {
1130                 settingKey.Append(_NETWORK_TELEPHONY_PACKETSERVICE);
1131         }
1132         else if(key == RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED)
1133         {
1134                 settingKey.Append(_NETWORK_TELEPHONY_ROAMING);
1135         }
1136         else
1137         {
1138                 SysLogException(NID_SYS, E_SYSTEM, "It is not supported key.");
1139                 return;
1140         }
1141
1142         result r = pSettingInfo->AnnounceSettingEvent(settingKey);
1143         SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
1144 }
1145
1146 void
1147 _SettingNetworkProvider::SettingEventVConf(keynode_t* node, void* userData)
1148 {
1149         result r = E_SUCCESS;
1150         String settingKey;
1151         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
1152         SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
1153
1154         if (strcmp(VCONFKEY_WIFI_STATE, vconf_keynode_get_name(node)) == 0)
1155         {
1156                 int state = VCONFKEY_WIFI_OFF;
1157                 int errorCode = 0;
1158                 errorCode = vconf_get_int(VCONFKEY_WIFI_STATE, &state);
1159
1160                 if(errorCode == 0 && (state == VCONFKEY_WIFI_OFF || state == VCONFKEY_WIFI_UNCONNECTED))
1161                 {
1162                         settingKey.Append(_NETWORK_WIFI);
1163                         r = pSettingInfo->AnnounceSettingEvent(settingKey);
1164                         SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
1165                 }
1166                 return;
1167         }
1168         else if (strcmp(VCONFKEY_WIFI_ENABLE_QS, vconf_keynode_get_name(node)) == 0)
1169         {
1170                 settingKey.Append(_NETWORK_WIFI_NOTIFICATION);
1171         }
1172         else if (strcmp(VCONFKEY_WIFI_DIRECT_STATE, vconf_keynode_get_name(node)) == 0)
1173         {
1174                 int state = VCONFKEY_WIFI_DIRECT_DEACTIVATED;
1175                 int errorCode = 0;
1176                 errorCode = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &state);
1177                 SysLog(NID_SYS, "Wi-Fi Direct state is changed. %d", state);
1178                 if(errorCode == 0 && (state == VCONFKEY_WIFI_DIRECT_DEACTIVATED || state == VCONFKEY_WIFI_DIRECT_ACTIVATED))
1179                 {
1180                         settingKey.Append(_NETWORK_WIFI_DIRECT);
1181                         r = pSettingInfo->AnnounceSettingEvent(settingKey);
1182                         SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
1183                 }
1184                 return;
1185         }
1186         else if (strcmp(VCONFKEY_BT_STATUS, vconf_keynode_get_name(node)) == 0)
1187         {
1188                 settingKey.Append(_NETWORK_BLUETOOTH);
1189         }
1190         else if (strcmp(VCONFKEY_MOBILE_HOTSPOT_SECURITY, vconf_keynode_get_name(node)) == 0)
1191         {
1192                 settingKey.Append(_NETWORK_WIFI_TETHERING_SECURITY);
1193         }
1194         else if (strcmp(VCONFKEY_MOBILE_HOTSPOT_HIDE, vconf_keynode_get_name(node)) == 0)
1195         {
1196                 settingKey.Append(_NETWORK_WIFI_TETHERING_HIDE);
1197         }
1198         else
1199         {
1200                 SysLogException(NID_SYS, E_SYSTEM, "It is not supported key.");
1201                 return;
1202         }
1203
1204         r = pSettingInfo->AnnounceSettingEvent(settingKey);
1205         SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
1206 }
1207
1208 void
1209 _SettingNetworkProvider::SettingEventTetheringEnabled(tethering_error_e err, tethering_type_e type, bool is_requested, void* data)
1210 {
1211         String settingKey;
1212         SysLog(NID_SYS, "Tethering Endabled Event is occured.");
1213
1214         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
1215         SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
1216
1217         switch(type)
1218         {
1219         case TETHERING_TYPE_USB:
1220                 settingKey.Append(_USB_TETHERING);
1221                 break;
1222         case TETHERING_TYPE_WIFI:
1223                 settingKey.Append(_NETWORK_WIFI_TETHERING);
1224                 break;
1225         case TETHERING_TYPE_BT:
1226                 settingKey.Append(_NETWORK_BLUETOOTH_TETHERING);
1227                 break;
1228         default:
1229                 return;
1230         }
1231
1232         result r = pSettingInfo->AnnounceSettingEvent(settingKey);
1233         SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
1234 }
1235
1236 void
1237 _SettingNetworkProvider::SettingEventTetheringDisabled(tethering_error_e err, tethering_type_e type, tethering_disabled_cause_e cause,void* data)
1238 {
1239         SysLog(NID_SYS, "Tethering Disabled Event is occured.");
1240         SettingEventTetheringEnabled(err, type, false, null);
1241 }
1242
1243 void
1244 _SettingNetworkProvider::SettingEventFlightMode(TapiHandle* handle, int res, void* data, void* user_data)
1245 {
1246         String settingKey(_NETWORK_FLIGHTMODE);
1247         int errorCode = 0;
1248         result r = E_SUCCESS;
1249         SysLog(NID_SYS, "Flightmode response is handle:%x, res:%d, date:%x, user_data:%x", handle, res, data, user_data);
1250
1251         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
1252         SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "SettingInfo is not ready.");
1253         _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)user_data;
1254         SysTryReturnVoidResult(NID_SYS, pProvider != null, E_SYSTEM, "There is invalid provider.");
1255         SysTryCatch(NID_SYS, pProvider->__stateOfFlightMode == 1, E_SYSTEM, E_SYSTEM, "Current state of flight mode is not valid.");
1256
1257         switch (res)
1258         {
1259         case TAPI_POWER_FLIGHT_MODE_RESP_ON:
1260                 SysLog(NID_SYS, "It successes to change flight mode on");
1261
1262                 errorCode = vconf_set_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, true);
1263                 if (errorCode != 0)
1264                 {
1265                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to set on VCONFKEY_TELEPHONY_FLIGHT_MODE vconf.");
1266                         r = E_SYSTEM;
1267                 }
1268                 break;
1269         case TAPI_POWER_FLIGHT_MODE_RESP_OFF:
1270                 SysLog(NID_SYS, "It successes to change flight mode off");
1271
1272                 errorCode = vconf_set_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, false);
1273                 if (errorCode != 0)
1274                 {
1275                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to set on VCONFKEY_TELEPHONY_FLIGHT_MODE vconf.");
1276                         r = E_SYSTEM;
1277                 }
1278                 break;
1279         case TAPI_POWER_FLIGHT_MODE_RESP_FAIL:
1280         default:
1281                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to change flight mode");
1282                 r = E_SYSTEM;
1283         }
1284
1285         if(pProvider->__pFlightModeListener != null)
1286         {
1287                 pProvider->__pFlightModeListener->OnResultReceivedForSetValueAsync(settingKey, r);
1288         }
1289
1290 CATCH:
1291         pProvider->__stateOfFlightMode = 0;
1292 }
1293
1294 result
1295 _SettingNetworkProvider::FlightModeEnabler(void* data)
1296 {
1297         result r = E_SUCCESS;
1298         int errorCode = 0;
1299         String settingKey(_NETWORK_FLIGHTMODE);
1300
1301         _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
1302         _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
1303         SysTryReturnResult(NID_SYS, pProvider != null && pSettingInfo != null, E_SYSTEM, "Provider or SettingInfo is not ready.");
1304         SysTryCatch(NID_SYS, pProvider->__stateOfFlightMode == 1, E_SYSTEM, E_SYSTEM, "Current state of flight mode is not valid.");
1305
1306         errorCode = vconf_set_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, pProvider->__flightModeEnabled);
1307         if (errorCode != 0)
1308         {
1309                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to set on VCONFKEY_TELEPHONY_FLIGHT_MODE vconf.");
1310                 r = E_SYSTEM;
1311         }
1312
1313
1314         if(pProvider->__pFlightModeListener != null)
1315         {
1316                 pProvider->__pFlightModeListener->OnResultReceivedForSetValueAsync(settingKey, r);
1317         }
1318
1319 CATCH:
1320         pProvider->__stateOfFlightMode = 0;
1321         return r;
1322 }
1323
1324 void
1325 _SettingNetworkProvider::SettingEventBluetooth(int res, bt_adapter_state_e adapter_state, void* user_data)
1326 {
1327         String settingKey(_NETWORK_BLUETOOTH);
1328         result r = E_SUCCESS;
1329         SysLog(NID_SYS, "Bluetooth callback is invoked. result:%d, adapter_state:%d, user_data:%x", res, adapter_state, user_data);
1330
1331         _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)user_data;
1332         SysTryReturnVoidResult(NID_SYS, pProvider != null, E_SYSTEM, "There is no values of args.");
1333         SysTryCatch(NID_SYS, pProvider->__stateOfBluetooth == 1, E_SYSTEM, E_SYSTEM, "Bluetooth processing is under way.");
1334
1335         if(res == BT_ERROR_NONE)
1336         {
1337                 r = E_SUCCESS;
1338         }
1339         else
1340         {
1341                 r = E_SYSTEM;
1342         }
1343
1344         if(pProvider->__pBluetoothListener != null && pProvider->__stateOfBluetooth == 1)
1345         {
1346                 pProvider->__pBluetoothListener->OnResultReceivedForSetValueAsync(settingKey, r);
1347         }
1348
1349         if(r == E_SUCCESS)
1350         {
1351                 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
1352                 SysTryCatch(NID_SYS, pSettingInfo != null, E_SYSTEM, E_SYSTEM, "_SettingInfo is not ready.");
1353
1354                 result r = pSettingInfo->AnnounceSettingEvent(settingKey);
1355                 SysTryCatch(NID_SYS, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
1356         }
1357
1358 CATCH:
1359         pProvider->__stateOfBluetooth = 0;
1360 }
1361
1362 }}