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