+//
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file FSys_SettingNetworkProvider.cpp
+ * @brief This is the implementation for the _SettingNetworkProvider class.
+ */
+
+#include <unistd.h>
+#include <unique_ptr.h>
+#include <dlfcn.h>
+#include <sim.h>
+#include <system_info.h>
+#include <bluetooth.h>
+
+#include <FBase_StringConverter.h>
+
+#include <FApp.h>
+#include <FBase.h>
+#include <FBaseSysLog.h>
+
+#include "FSys_SystemInfo.h"
+#include "FSys_SettingNetworkProvider.h"
+
+using namespace std;
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base;
+using namespace Utility;
+
+namespace Tizen { namespace System
+{
+//Network Telephony
+static const wchar_t* _NETWORK_FLIGHTMODE = L"http://tizen.org/setting/network.flight_mode";
+static const wchar_t* _NETWORK_TELEPHONY_PACKETSERVICE = L"http://tizen.org/setting/network.telephony.packet_service";
+static const wchar_t* _NETWORK_TELEPHONY_ROAMING = L"http://tizen.org/setting/network.telephony.roaming";
+static const wchar_t* _SYSTEM_TELEPHONY = L"http://tizen.org/feature/network.telephony";
+
+//Network Wi-Fi
+static const wchar_t* _NETWORK_WIFI = L"http://tizen.org/setting/network.wifi";
+static const wchar_t* _NETWORK_WIFI_NOTIFICATION = L"http://tizen.org/setting/network.wifi.notification";
+static const wchar_t* _NETWORK_WIFI_TETHERING = L"http://tizen.org/setting/network.wifi.tethering";
+static const wchar_t* _NETWORK_WIFI_TETHERING_HIDE = L"http://tizen.org/setting/network.wifi.tethering.hide";
+static const wchar_t* _NETWORK_WIFI_TETHERING_SECURITY = L"http://tizen.org/setting/network.wifi.tethering.security";
+static const wchar_t* _NETWORK_WIFI_TETHERING_SECURITY_PASSWORD = L"http://tizen.org/setting/network.wifi.tethering.security.password";
+static const wchar_t* _USB_TETHERING = L"http://tizen.org/setting/usb.tethering"; //Especially, USB tethering is covered by this provider.
+static const wchar_t* _NETWORK_WIFI_DIRECT = L"http://tizen.org/setting/network.wifi.direct";
+
+static const wchar_t* _SYSTEM_NETWORK_WIFI_DIRECT = L"http://tizen.org/feature/network.wifi.direct";
+static const wchar_t* _SYSTEM_NETWORK_WIFI = L"http://tizen.org/feature/network.wifi";
+
+//Network Bluetooth
+static const wchar_t* _NETWORK_BLUETOOTH = L"http://tizen.org/setting/network.bluetooth";
+static const wchar_t* _NETWORK_BLUETOOTH_TETHERING = L"http://tizen.org/setting/network.bluetooth.tethering";
+
+static const wchar_t* _SYSTEM_NETWORK_BLUETOOTH = L"http://tizen.org/feature/network.bluetooth";
+
+static const wchar_t* _NETWORK_RESULT_SUCCESS = L"osp.system.result.success";
+static const wchar_t* _NETWORK_RESULT_SYSTEM = L"osp.system.result.system";
+
+struct charDeleter
+{
+ void operator()(char* pValue)
+ {
+ if(pValue != null)
+ {
+ free(pValue);
+ pValue = null;
+ }
+ }
+};
+
+_SettingNetworkProvider::_SettingNetworkProvider()
+ : __tapiHandle(null)
+ , __pWifiDllHandle(null)
+ , __pBluetoothDllHandle(null)
+ , __stateOfFlightMode(0)
+ , __stateOfWifi(0)
+ , __stateOfWifiDirect(0)
+ , __stateOfBluetooth(0)
+ , __flightModeEnabled(false)
+ , __networkBluetoothEnabled(false)
+ , __wifiInit(false)
+ , __wifiDirectInit(false)
+ , __pWifiListener(null)
+ , __pWifiDirectListener(null)
+ , __pFlightModeListener(null)
+ , __pBluetoothListener(null)
+{
+ int errorCode = bt_initialize();
+ if(errorCode != 0)
+ {
+ //For multiple usage, deinitialize should not be called when it terminated.
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to initialize bluetooth.");
+ }
+
+ errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED, SettingEventRuntimeInfo, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register flight mode event listener");
+ }
+
+ errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_PACKET_DATA_ENABLED, SettingEventRuntimeInfo, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register packet data event listener");
+ }
+
+ errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED, SettingEventRuntimeInfo, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register roaming event listener");
+ }
+
+ errorCode = vconf_notify_key_changed(VCONFKEY_WIFI_STATE, SettingEventVConf, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_WIFI_STATE listener");
+ }
+
+ errorCode = tethering_create(&__tetheringHandle);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to create tethering handle");
+ }
+
+ errorCode = tethering_set_enabled_cb(__tetheringHandle, TETHERING_TYPE_USB, SettingEventTetheringEnabled, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_USB listener");
+ }
+
+ errorCode = tethering_set_enabled_cb(__tetheringHandle, TETHERING_TYPE_WIFI, SettingEventTetheringEnabled, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_WIFI listener");
+ }
+
+ errorCode = tethering_set_enabled_cb(__tetheringHandle, TETHERING_TYPE_BT, SettingEventTetheringEnabled, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_BT listener");
+ }
+
+ errorCode = tethering_set_disabled_cb(__tetheringHandle, TETHERING_TYPE_USB, SettingEventTetheringDisabled, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_USB listener");
+ }
+
+ errorCode = tethering_set_disabled_cb(__tetheringHandle, TETHERING_TYPE_WIFI, SettingEventTetheringDisabled, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_WIFI listener");
+ }
+
+ errorCode = tethering_set_disabled_cb(__tetheringHandle, TETHERING_TYPE_BT, SettingEventTetheringDisabled, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register TETHERING_TYPE_BT listener");
+ }
+
+ errorCode = vconf_notify_key_changed(VCONFKEY_WIFI_DIRECT_STATE, SettingEventVConf, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_WIFI_DIRECT_STATE listener");
+ }
+
+ errorCode = vconf_notify_key_changed(VCONFKEY_BT_STATUS, SettingEventVConf, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_BT_STATUS listener");
+ }
+
+ errorCode = vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_SECURITY, SettingEventVConf, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_MOBILE_HOTSPOT_SECURITY listener");
+ }
+
+ errorCode = vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_HIDE, SettingEventVConf, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_MOBILE_HOTSPOT_HIDE listener");
+ }
+
+ errorCode = vconf_notify_key_changed(VCONFKEY_WIFI_ENABLE_QS, SettingEventVConf, null);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_WIFI_ENABLE_QS listener");
+ }
+
+ errorCode = bt_adapter_set_state_changed_cb(SettingEventBluetooth, (void*)this);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to register bluetooth listener");
+ }
+
+ if(__wifiInit == false)
+ {
+ SysLog(NID_SYS, "wifi init is started");
+ errorCode = wifi_initialize();
+ SysLog(NID_SYS, "wifi init result is %d", errorCode);
+ __wifiInit = true;
+ }
+}
+
+
+_SettingNetworkProvider::~_SettingNetworkProvider()
+{
+ int errorCode = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister flight mode event listener");
+ }
+
+ errorCode = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_PACKET_DATA_ENABLED);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister packet data event listener");
+ }
+
+ errorCode = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister roaming event listener");
+ }
+
+ errorCode = vconf_ignore_key_changed(VCONFKEY_WIFI_STATE, SettingEventVConf);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_WIFI_STATE listener");
+ }
+
+ errorCode = tethering_unset_enabled_cb(__tetheringHandle, TETHERING_TYPE_USB);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_USB listener");
+ }
+
+ errorCode = tethering_unset_enabled_cb(__tetheringHandle, TETHERING_TYPE_WIFI);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_WIFI listener");
+ }
+
+ errorCode = tethering_unset_enabled_cb(__tetheringHandle, TETHERING_TYPE_BT);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_BT listener");
+ }
+
+ errorCode = tethering_unset_disabled_cb(__tetheringHandle, TETHERING_TYPE_USB);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_USB listener");
+ }
+
+ errorCode = tethering_unset_disabled_cb(__tetheringHandle, TETHERING_TYPE_WIFI);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_WIFI listener");
+ }
+
+ errorCode = tethering_unset_disabled_cb(__tetheringHandle, TETHERING_TYPE_BT);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister TETHERING_TYPE_BT listener");
+ }
+
+ tethering_destroy(__tetheringHandle);
+ __tetheringHandle = null;
+
+ errorCode = vconf_ignore_key_changed(VCONFKEY_WIFI_DIRECT_STATE, SettingEventVConf);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_WIFI_DIRECT_STATE listener");
+ }
+ errorCode = vconf_ignore_key_changed(VCONFKEY_BT_STATUS, SettingEventVConf);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_BT_STATUS listener");
+ }
+
+ errorCode = vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_SECURITY, SettingEventVConf);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_MOBILE_HOTSPOT_SECURITY listener");
+ }
+
+ errorCode = vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_HIDE, SettingEventVConf);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_MOBILE_HOTSPOT_HIDE listener");
+ }
+
+ errorCode = vconf_ignore_key_changed(VCONFKEY_WIFI_ENABLE_QS, SettingEventVConf);
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_WIFI_ENABLE_QS listener");
+ }
+
+ errorCode = bt_adapter_unset_state_changed_cb();
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister bluetooth listener");
+ }
+
+ errorCode = bt_deinitialize();
+ if(errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to deinitialize bluetooth.");
+ }
+
+ if(__wifiDirectInit == true)
+ {
+ errorCode = wifi_direct_unset_device_state_changed_cb();
+ if(errorCode == WIFI_DIRECT_ERROR_NONE)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister Wi-Fi direct callback.");
+ }
+
+ errorCode = wifi_direct_deinitialize();
+ if(errorCode == WIFI_DIRECT_ERROR_NONE)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to deinitialize Wi-Fi direct.");
+ }
+ SysLog(NID_SYS, "Wifi direct de-init result is %d.", errorCode);
+ __wifiDirectInit = false;
+ }
+
+ if(__wifiInit == true)
+ {
+ errorCode = wifi_deinitialize();
+ if(errorCode == WIFI_ERROR_NONE)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to deinitialize Wi-Fi.");
+ }
+ SysLog(NID_SYS, "Wifi de-init result is %d.", errorCode);
+ __wifiInit = false;
+ }
+ SysLog(NID_SYS, "Network Provider is terminated properly.");
+}
+
+result
+_SettingNetworkProvider::GetValue(const String& key, bool& value)
+{
+ int errorCode = 0;
+ result r = E_OBJ_NOT_FOUND;
+
+ if(key == _NETWORK_FLIGHTMODE)
+ {
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support flightmode feature.");
+ bool flightModeEnabled = false;
+ r = E_SUCCESS;
+ errorCode = runtime_info_get_value_bool(RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED, &flightModeEnabled);
+ SysTryReturnResult(NID_SYS, errorCode == RUNTIME_INFO_ERROR_NONE, E_SYSTEM, "It is failed to get the RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED");
+ value = flightModeEnabled;
+ }
+ else if(key == _NETWORK_TELEPHONY_PACKETSERVICE)
+ {
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Telephony packet service feature.");
+ bool packetServiceAllowed = false;
+ r = E_SUCCESS;
+ errorCode = runtime_info_get_value_bool(RUNTIME_INFO_KEY_PACKET_DATA_ENABLED, &packetServiceAllowed);
+ SysTryReturnResult(NID_SYS, errorCode == RUNTIME_INFO_ERROR_NONE, E_SYSTEM, "It is failed to get the RUNTIME_INFO_KEY_PACKET_DATA_ENABLED");
+ value = packetServiceAllowed;
+ }
+ else if(key == _NETWORK_TELEPHONY_ROAMING)
+ {
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Telephony roaming feature.");
+ bool dataRoamingEnabled = false;
+ r = E_SUCCESS;
+ errorCode = runtime_info_get_value_bool(RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED, &dataRoamingEnabled);
+ SysTryReturnResult(NID_SYS, errorCode == RUNTIME_INFO_ERROR_NONE, E_SYSTEM, "It is failed to get the RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED");
+ value = dataRoamingEnabled;
+ }
+ else if (key == _NETWORK_WIFI)
+ {
+ r = E_SUCCESS;
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
+
+ bool wifiState = false;
+ errorCode = wifi_is_activated(&wifiState);
+ SysTryReturnResult(NID_SYS, errorCode == WIFI_ERROR_NONE, E_SYSTEM, "It is failed to get from wifi_is_activated.");
+ value = wifiState;
+ }
+ else if (key == _NETWORK_WIFI_NOTIFICATION)
+ {
+ int wifiQSState = 0;
+ r = E_SUCCESS;
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
+
+ errorCode = vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &wifiQSState);
+ SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_WIFI_ENABLE_QS vconf.");
+
+ if(wifiQSState == VCONFKEY_WIFI_QS_DISABLE)
+ {
+ value = false;
+ }
+ else
+ {
+ value = true;
+ }
+ }
+ else if (key == _NETWORK_WIFI_TETHERING)
+ {
+ r = E_SUCCESS;
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
+ value = tethering_is_enabled(__tetheringHandle, TETHERING_TYPE_WIFI);
+ }
+ else if (key == _NETWORK_WIFI_TETHERING_HIDE)
+ {
+ r = E_SUCCESS;
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
+ errorCode = tethering_wifi_get_ssid_visibility(__tetheringHandle, &value);
+ SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to get wifi tethering visibility state");
+ }
+ else if (key == _NETWORK_WIFI_TETHERING_SECURITY)
+ {
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
+ r = E_SUCCESS;
+ tethering_wifi_security_type_e securityType;
+ errorCode = tethering_wifi_get_security_type(__tetheringHandle, &securityType);
+ SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to get wifi tethering securiy state");
+ if(securityType == TETHERING_WIFI_SECURITY_TYPE_NONE)
+ {
+ value = false;
+ }
+ else
+ {
+ value = true;
+ }
+ }
+ else if (key == _USB_TETHERING)
+ {
+ r = E_SUCCESS;
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support USB tethering feature.");
+ value = tethering_is_enabled(__tetheringHandle, TETHERING_TYPE_USB);
+ }
+ else if (key == _NETWORK_WIFI_DIRECT)
+ {
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi direct feature.");
+ r = E_SUCCESS;
+
+ int isActivated = 0;
+ errorCode = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &isActivated);
+ SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_WIFI_ENABLE_QS vconf.");
+
+ if(isActivated == 1)
+ {
+ value = true;
+ }
+ else
+ {
+ value = false;
+ }
+ }
+ else if (key == _NETWORK_BLUETOOTH)
+ {
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Bluetooth feature.");
+ r = E_SUCCESS;
+ int bluetoothStatus = VCONFKEY_BT_STATUS_OFF;
+ errorCode = vconf_get_int(VCONFKEY_BT_STATUS, &bluetoothStatus);
+ SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to read bluetooth status.");
+
+ if(bluetoothStatus == VCONFKEY_BT_STATUS_OFF)
+ {
+ value = false;
+ }
+ else
+ {
+ value = true;
+ }
+ }
+ else if (key == _NETWORK_BLUETOOTH_TETHERING)
+ {
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Bluetooth tethering feature.");
+ r = E_SUCCESS;
+ value = tethering_is_enabled(__tetheringHandle, TETHERING_TYPE_BT);
+ }
+ return r;
+}
+
+result
+_SettingNetworkProvider::SetValue(const String& key, const bool value)
+{
+ int errorCode = 0;
+ result r = E_OBJ_NOT_FOUND;
+
+ if(key == _NETWORK_WIFI_NOTIFICATION)
+ {
+ int currentValue = 0;
+ r = E_SUCCESS;
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
+ errorCode = vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, ¤tValue);
+ SysTryReturnResult(NID_SYS, errorCode != -1, E_UNSUPPORTED_OPERATION, "This device does not support %ls key.", key.GetPointer());
+
+ if(value == true)
+ {
+ errorCode = vconf_set_int(VCONFKEY_WIFI_ENABLE_QS, VCONFKEY_WIFI_QS_ENABLE);
+ }
+ else
+ {
+ errorCode = vconf_set_int(VCONFKEY_WIFI_ENABLE_QS, VCONFKEY_WIFI_QS_DISABLE);
+ }
+ SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_WIFI_ENABLE_QS vconf.");
+ }
+ else if(key == _NETWORK_WIFI_TETHERING)
+ {
+ bool state = false;
+ r = E_SUCCESS;
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
+ SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_UNSUPPORTED_OPERATION, "Current device does not support tethering feature.");
+ r = GetValue(_NETWORK_WIFI, state);
+ SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get the WIFI state");
+ SysTryReturnResult(NID_SYS, state == true, E_INVALID_STATE, "WIFI is not activated");
+
+ if(value == true)
+ {
+ errorCode = tethering_enable(__tetheringHandle, TETHERING_TYPE_WIFI);
+ }
+ else
+ {
+ errorCode = tethering_disable(__tetheringHandle, TETHERING_TYPE_WIFI);
+ }
+ SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change tethering option.");
+ }
+ else if(key == _NETWORK_WIFI_TETHERING_HIDE)
+ {
+ r = E_SUCCESS;
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
+
+ bool currentState = false;
+ SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_UNSUPPORTED_OPERATION, "Current device does not support tethering feature.");
+ errorCode = tethering_wifi_get_ssid_visibility(__tetheringHandle, ¤tState);
+ SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to current wifi tethering visibility setting");
+
+ if(value == true && currentState == false)
+ {
+ errorCode = tethering_wifi_set_ssid_visibility(__tetheringHandle, true);
+ }
+ else if(value == false && currentState == true)
+ {
+ errorCode = tethering_wifi_set_ssid_visibility(__tetheringHandle, false);
+ }
+ SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change wifi tethering visibility setting");
+ }
+ else if(key == _NETWORK_WIFI_TETHERING_SECURITY)
+ {
+ r = E_SUCCESS;
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
+
+ tethering_wifi_security_type_e securityType;
+ SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_UNSUPPORTED_OPERATION, "Current device does not support tethering feature.");
+
+ errorCode = tethering_wifi_get_security_type(__tetheringHandle, &securityType);
+ SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to get wifi tethering securiy state");
+
+ if(value == true && securityType == TETHERING_WIFI_SECURITY_TYPE_NONE)
+ {
+ errorCode = tethering_wifi_set_security_type(__tetheringHandle, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK);
+ }
+ else if(value == false && securityType == TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK)
+ {
+ errorCode = tethering_wifi_set_security_type(__tetheringHandle, TETHERING_WIFI_SECURITY_TYPE_NONE);
+ }
+ SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change wifi tethering visibility setting");
+ }
+ else if(key == _USB_TETHERING)
+ {
+ r = E_SUCCESS;
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support tethering feature.");
+
+ if(value == true)
+ {
+ errorCode = tethering_enable(__tetheringHandle, TETHERING_TYPE_USB);
+ }
+ else
+ {
+ errorCode = tethering_disable(__tetheringHandle, TETHERING_TYPE_USB);
+ }
+ SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change tethering option");
+ }
+ else if(key == _NETWORK_BLUETOOTH_TETHERING)
+ {
+ r = E_SUCCESS;
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support tethering feature.");
+
+ bool state = false;
+ r = GetValue(_NETWORK_BLUETOOTH, state);
+ SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get the Bluetooth state");
+ SysTryReturnResult(NID_SYS, state == true, E_INVALID_STATE, "Bluetooth is not activated");
+
+ if(value == true)
+ {
+ errorCode = tethering_enable(__tetheringHandle, TETHERING_TYPE_BT);
+ }
+ else
+ {
+ errorCode = tethering_disable(__tetheringHandle, TETHERING_TYPE_BT);
+ }
+ SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to change tethering option");
+ }
+ return r;
+}
+
+result
+_SettingNetworkProvider::SetValueAsync(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
+{
+ int ret = 0;
+ result r = E_OBJ_NOT_FOUND;
+
+ if(key == _NETWORK_BLUETOOTH)
+ {
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Bluetooth feature.");
+ SysTryReturnResult(NID_SYS, __stateOfBluetooth == 0, E_IN_PROGRESS, "Bluetooth is under changing procedure.");
+ r = E_SUCCESS;
+ __stateOfBluetooth = 1;
+ __pBluetoothListener = listener;
+
+ if(value == true)
+ {
+ ret = bt_adapter_enable();
+ }
+ else
+ {
+ ret = bt_adapter_disable();
+ }
+
+ SysLog(NID_SYS, "bt_adapter returns %d.", ret);
+
+ switch(ret)
+ {
+ case BT_ERROR_NONE:
+ SysLog(NID_SYS, "It is OK to change the bluetooth mode.");
+ break;
+
+ case BT_ERROR_ALREADY_DONE:
+ case BT_ERROR_NOT_ENABLED:
+ SysLog(NID_SYS, "Bluetooth is already enabled.");
+ SettingEventBluetooth(BT_ERROR_NONE, BT_ADAPTER_ENABLED, (void*)this);
+ break;
+
+ case BT_ERROR_NOW_IN_PROGRESS:
+ SysLog(NID_SYS, "Currently, Bluetooth change is in progress.");
+ __stateOfBluetooth = 0;
+ r = E_IN_PROGRESS;
+ break;
+
+ case BT_ERROR_NOT_INITIALIZED:
+ default:
+ SysLog(NID_SYS, "There is an unknown error when changing the bluetooth mode.");
+ __stateOfBluetooth = 0;
+ r = E_SYSTEM;
+ break;
+ }
+ }
+ return r;
+}
+
+result
+_SettingNetworkProvider::SetValueForPrivilegedKey(const String& key, bool value)
+{
+ int errorCode = 0;
+ result r = E_OBJ_NOT_FOUND;
+ if(key == _NETWORK_TELEPHONY_PACKETSERVICE)
+ {
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support telephony packet service feature.");
+ r = E_SUCCESS;
+ errorCode = vconf_set_bool(VCONFKEY_3G_ENABLE, value);
+ SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_3G_ENABLE vconf.");
+ }
+ else if(key == _NETWORK_TELEPHONY_ROAMING)
+ {
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support telephony roaming feature.");
+ r = E_SUCCESS;
+ errorCode = vconf_set_bool(VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, value);
+ SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL vconf.");
+ }
+ return r;
+}
+
+result
+_SettingNetworkProvider::SetValueAsyncForPrivilegedKey(const String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
+{
+ int errorCode = 0;
+ result r = E_OBJ_NOT_FOUND;
+
+ if(key == _NETWORK_FLIGHTMODE)
+ {
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support flightmode feature.");
+ r = E_SUCCESS;
+
+ SysTryReturnResult(NID_SYS, __stateOfFlightMode == 0, E_IN_PROGRESS, "Flightmode is under changing procedure.");
+ __stateOfFlightMode = 1;
+
+ bool supported = false;
+ int ret = system_info_get_platform_bool("tizen.org/feature/network.telephony", &supported);
+ SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
+
+ __pFlightModeListener = listener;
+ if(supported == true)
+ {
+ if(__tapiHandle == null)
+ {
+ __tapiHandle = tel_init(null);
+ if(__tapiHandle == null)
+ {
+ __stateOfFlightMode = 0;
+ }
+ SysTryReturnResult(NID_SYS, __tapiHandle != null, E_SYSTEM, "Tapi is not ready.");
+ }
+ errorCode = tel_set_flight_mode(__tapiHandle,
+ value ? TAPI_POWER_FLIGHT_MODE_ENTER : TAPI_POWER_FLIGHT_MODE_LEAVE,
+ SettingEventFlightMode, (void*)this);
+
+ if(errorCode != 0)
+ {
+ __stateOfFlightMode = 0;
+ }
+ SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on Network Flight mode(%d).", errorCode);
+ }
+ else
+ {
+ FlightModeEnabler((void*)this);
+ }
+ }
+ else if(key == _NETWORK_WIFI)
+ {
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
+ SysTryReturnResult(NID_SYS, __stateOfWifi == 0 && __stateOfWifiDirect == 0, E_IN_PROGRESS, "Wifi processing is under way.");
+ r = E_SUCCESS;
+
+ __stateOfWifi = 1;
+ SysLog(NID_SYS, "It creates thread for wifi enable[%d].", value);
+
+ bool wifiEnabled = false;
+ __pWifiListener = listener;
+ errorCode = wifi_is_activated(&wifiEnabled);
+ if(errorCode != WIFI_ERROR_NONE)
+ {
+ __stateOfWifi = 0;
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to get current status of WIFI.");
+ return E_SYSTEM;
+ }
+
+ if(value == wifiEnabled) //Wi-Fi is already changed.
+ {
+ SysLog(NID_SYS, "It is try to use dummy thread");
+ r = WifiDummy((void*)this);
+ SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to set Wi-Fi state.");
+ return r;
+ }
+
+ if(value == true)
+ {
+ errorCode = wifi_activate(SettingWifiActivateCallBack, (void*) this);
+ }
+ else
+ {
+ errorCode = wifi_deactivate(SettingWifiActivateCallBack, (void*) this);
+ }
+
+ if(errorCode != WIFI_ERROR_NONE)
+ {
+ __stateOfWifi = 0;
+ return E_SYSTEM;
+ }
+ }
+ else if(key == _NETWORK_WIFI_DIRECT)
+ {
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi feature.");
+ SysTryReturnResult(NID_SYS, __stateOfWifi == 0 && __stateOfWifiDirect == 0, E_IN_PROGRESS, "Wifi processing is under way.");
+ r = E_SUCCESS;
+
+ __stateOfWifiDirect = 1;
+ SysLog(NID_SYS, "It creates thread for wifi direct enable[%d].", value);
+
+
+ __pWifiDirectListener = listener;
+ if(__wifiDirectInit == false)
+ {
+ SysLog(NID_SYS, "wifi direct init is started");
+ errorCode = wifi_direct_initialize();
+ SysLog(NID_SYS, "wifi direct init result is %d", errorCode);
+ SysTryReturnResult(NID_SYS, errorCode == WIFI_DIRECT_ERROR_NONE, E_SYSTEM, "It is failed to init wifi direct.");
+ errorCode = wifi_direct_set_device_state_changed_cb(SettingWifiDirectStateChangedCallBack, (void*) this);
+ SysTryReturnResult(NID_SYS, errorCode == WIFI_DIRECT_ERROR_NONE, E_SYSTEM, "It is failed to register wifi direct result callback.");
+ __wifiDirectInit = true;
+ }
+
+
+ wifi_direct_state_e wifi_direct_state;
+ errorCode = wifi_direct_get_state(&wifi_direct_state);
+ if(errorCode != WIFI_DIRECT_ERROR_NONE)
+ {
+ __stateOfWifiDirect = 0;
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to get current status of WIFI direct.");
+ return E_SYSTEM;
+ }
+
+ if((value == false && wifi_direct_state == WIFI_DIRECT_STATE_DEACTIVATED)
+ || (value == true && wifi_direct_state != WIFI_DIRECT_STATE_DEACTIVATED))
+ {
+ SysLog(NID_SYS, "Required state is already applied.");
+ WifiDirectDummy((void*)this);
+ return E_SUCCESS;
+ }
+
+ if(value == true)
+ {
+ errorCode = wifi_direct_activate();
+ }
+ else
+ {
+ errorCode = wifi_direct_deactivate();
+ }
+ SysLog(NID_SYS, "wifi_direct_activate result is %d. value is %d.", errorCode, value);
+
+ if(errorCode < 0)
+ {
+ return E_SYSTEM;
+ }
+ }
+ return r;
+}
+
+result
+_SettingNetworkProvider::WifiDummy(void* data)
+{
+ result r = E_SUCCESS;
+ String settingKey(_NETWORK_WIFI);
+ _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
+ _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
+ SysTryReturnResult(NID_SYS, (pSettingInfo != null && pProvider != null), E_SYSTEM, "There is no values of args.");
+
+ SysTryCatch(NID_SYS, pProvider->__stateOfWifi == 1, r = E_SYSTEM, E_SYSTEM, "There is invalid state.");
+
+ if(pProvider->__pWifiListener != null)
+ {
+ pProvider->__pWifiListener->OnResultReceivedForSetValueAsync(settingKey, E_SUCCESS);
+ }
+ r = pSettingInfo->AnnounceSettingEvent(settingKey);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
+
+CATCH:
+ pProvider->__stateOfWifi = 0;
+ return r;
+}
+
+result
+_SettingNetworkProvider::WifiDirectDummy(void* data)
+{
+ result r = E_SUCCESS;
+ String settingKey(_NETWORK_WIFI_DIRECT);
+ _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
+ _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
+ SysTryReturnResult(NID_SYS, (pSettingInfo != null && pProvider != null), E_SYSTEM, "There is no values of args.");
+ SysTryCatch(NID_SYS, pProvider->__stateOfWifiDirect == 1, E_SYSTEM, E_SYSTEM, "There is invalid state.");
+
+ if(pProvider->__pWifiDirectListener != null)
+ {
+ pProvider->__pWifiDirectListener->OnResultReceivedForSetValueAsync(settingKey, E_SUCCESS);
+ }
+ r = pSettingInfo->AnnounceSettingEvent(settingKey);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
+
+CATCH:
+ pProvider->__stateOfWifiDirect = 0;
+ return r;
+}
+
+void
+_SettingNetworkProvider::SettingWifiActivateCallBack(wifi_error_e errorCode, void* data)
+{
+ String settingKey(_NETWORK_WIFI);
+
+ _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
+ _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
+ SysTryReturnVoidResult(NID_SYS, (pSettingInfo != null && pProvider != null), E_SYSTEM, "There is no values of args.");
+ SysTryCatch(NID_SYS, pProvider->__stateOfWifi == 1, E_SYSTEM, E_SYSTEM, "Wi-Fi processing is under way.");
+
+ if(errorCode != WIFI_ERROR_NONE)
+ {
+ switch(errorCode)
+ {
+ case WIFI_ERROR_INVALID_PARAMETER:
+ SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by invalid param.");
+ break;
+ case WIFI_ERROR_OUT_OF_MEMORY:
+ SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by out of memory.");
+ break;
+ case WIFI_ERROR_INVALID_OPERATION:
+ SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by invalid operation.");
+ break;
+ case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
+ SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by family not supported.");
+ break;
+ case WIFI_ERROR_OPERATION_FAILED:
+ SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by operation failed.");
+ break;
+ case WIFI_ERROR_NO_CONNECTION:
+ SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by no connection.");
+ break;
+ case WIFI_ERROR_ALREADY_EXISTS:
+ SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by already exist.");
+ break;
+ case WIFI_ERROR_OPERATION_ABORTED:
+ SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by operation aborted.");
+ break;
+ case WIFI_ERROR_DHCP_FAILED:
+ SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by DHCP fail.");
+ break;
+ case WIFI_ERROR_INVALID_KEY:
+ SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by invalid key.");
+ break;
+ case WIFI_ERROR_NO_REPLY:
+ SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by no reply.");
+ break;
+ case WIFI_ERROR_SECURITY_RESTRICTED:
+ SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is failed by security restricted.");
+ break;
+ case WIFI_ERROR_NOW_IN_PROGRESS:
+ SysLogException(NID_SYS, E_SYSTEM, "Wifi change request is under way.");
+ break;
+ }
+ }
+
+ if(pProvider->__pWifiDirectListener != null)
+ {
+ pProvider->__pWifiDirectListener->OnResultReceivedForSetValueAsync(settingKey, E_SUCCESS);
+ }
+CATCH:
+ pProvider->__stateOfWifi = 0;
+}
+
+void
+_SettingNetworkProvider::SettingWifiDirectStateChangedCallBack(wifi_direct_error_e errorCode, wifi_direct_device_state_e deviceState, void* data)
+{
+ result r = E_SUCCESS;
+ String settingKey(_NETWORK_WIFI_DIRECT);
+ String returnValue = _NETWORK_RESULT_SUCCESS;
+
+ _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
+ _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
+ SysTryReturnVoidResult(NID_SYS, (pSettingInfo != null && pProvider != null), E_SYSTEM, "There is no values of args.");
+
+ SysTryCatch(NID_SYS, pProvider->__stateOfWifiDirect == 1 , E_SYSTEM, E_SYSTEM, "There is invalid state.");
+
+ if(errorCode != WIFI_DIRECT_ERROR_NONE)
+ {
+ r = E_SYSTEM;
+ }
+
+ if(pProvider->__pWifiDirectListener != null)
+ {
+ pProvider->__pWifiDirectListener->OnResultReceivedForSetValueAsync(settingKey, r);
+ }
+
+CATCH:
+ pProvider->__stateOfWifiDirect = 0;
+}
+
+result
+_SettingNetworkProvider::GetValue(const String& key, String& value)
+{
+ int errorCode = 0;
+ result r = E_OBJ_NOT_FOUND;
+
+ if (key == _NETWORK_WIFI_TETHERING_SECURITY_PASSWORD)
+ {
+ r = E_SUCCESS;
+ unique_ptr<char> password(null);
+ char* pTemp = null;
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
+
+ SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_UNSUPPORTED_OPERATION, "Current device does not support tethering feature.");
+ errorCode = tethering_wifi_get_passphrase(__tetheringHandle, &pTemp);
+ SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE && pTemp != null, E_SYSTEM, "It is failed to get password");
+
+ password.reset(pTemp);
+
+ value.Clear();
+ value.Append(password.get());
+ }
+ return r;
+}
+
+result
+_SettingNetworkProvider::SetValue(const String& key, const String value)
+{
+ int errorCode = 0;
+ result r = E_OBJ_NOT_FOUND;
+
+ if(key ==_NETWORK_WIFI_TETHERING_SECURITY_PASSWORD)
+ {
+ r = E_SUCCESS;
+ SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Wi-Fi tethering feature.");
+
+ SysTryReturnResult(NID_SYS, __tetheringHandle != null, E_UNSUPPORTED_OPERATION, "Current device does not support tethering feature.");
+ unique_ptr<char []> password(_StringConverter::CopyToCharArrayN(value));
+ SysTryReturnResult(NID_SYS, password != null, E_SYSTEM, "It is failed to convert String to string");
+ errorCode = tethering_wifi_set_passphrase(__tetheringHandle, password.get());
+ SysTryReturnResult(NID_SYS, errorCode == TETHERING_ERROR_NONE, E_SYSTEM, "It is failed to set password");
+ }
+ return r;
+}
+
+bool
+_SettingNetworkProvider::HasKey(const String& key)
+{
+ bool wifi_supported = false;
+ bool wifi_direct_supported = false;
+ bool bluetooth_supported = false;
+ bool telephony_supported = false;
+
+ int ret = system_info_get_platform_bool("tizen.org/feature/network.wifi", &wifi_supported);
+ SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
+
+ ret = system_info_get_platform_bool("tizen.org/feature/network.wifi.direct", &wifi_direct_supported);
+ SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
+
+ ret = system_info_get_platform_bool("tizen.org/feature/network.bluetooth", &bluetooth_supported);
+ SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
+
+ ret = system_info_get_platform_bool("tizen.org/feature/network.telephony", &telephony_supported);
+ SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to get system information from configration file.");
+
+ if(key == _NETWORK_FLIGHTMODE)
+ {
+ return true;
+ }
+ else if(key == _NETWORK_TELEPHONY_PACKETSERVICE || key == _NETWORK_TELEPHONY_ROAMING)
+ {
+ if(telephony_supported == true)
+ {
+ return true;
+ }
+ }
+ else if(key == _NETWORK_WIFI || key == _NETWORK_WIFI_NOTIFICATION)
+ {
+ if(wifi_supported == true)
+ {
+ return true;
+ }
+ }
+ else if(key == _NETWORK_WIFI_DIRECT)
+ {
+ if(wifi_direct_supported == true)
+ {
+ return true;
+ }
+ }
+ else if(key == _NETWORK_WIFI_TETHERING || key == _NETWORK_WIFI_TETHERING_HIDE
+ || key == _NETWORK_WIFI_TETHERING_SECURITY || key == _NETWORK_WIFI_TETHERING_SECURITY_PASSWORD || key == _USB_TETHERING)
+ {
+ bool isSupported = false;
+ int errorCode = system_info_get_value_bool(SYSTEM_INFO_KEY_TETHERING_SUPPORTED, &isSupported);
+ if(errorCode == SYSTEM_INFO_ERROR_NONE && isSupported == true)
+ {
+ return true;
+ }
+ }
+ else if(key == _NETWORK_BLUETOOTH)
+ {
+ if(bluetooth_supported == true)
+ {
+ return true;
+ }
+ }
+ else if(key == _NETWORK_BLUETOOTH_TETHERING)
+ {
+ if(__tetheringHandle != null && bluetooth_supported == true)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+void
+_SettingNetworkProvider::SettingEventRuntimeInfo(runtime_info_key_e key, void* userData)
+{
+ String settingKey;
+
+ _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
+ SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "SettingInfo is not ready.");
+
+ if(key == RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED)
+ {
+ settingKey.Append(_NETWORK_FLIGHTMODE);
+ }
+ else if(key == RUNTIME_INFO_KEY_PACKET_DATA_ENABLED)
+ {
+ settingKey.Append(_NETWORK_TELEPHONY_PACKETSERVICE);
+ }
+ else if(key == RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED)
+ {
+ settingKey.Append(_NETWORK_TELEPHONY_ROAMING);
+ }
+ else
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is not supported key.");
+ return;
+ }
+
+ result r = pSettingInfo->AnnounceSettingEvent(settingKey);
+ SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
+}
+
+void
+_SettingNetworkProvider::SettingEventVConf(keynode_t* node, void* userData)
+{
+ result r = E_SUCCESS;
+ String settingKey;
+ _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
+ SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
+
+ if (strcmp(VCONFKEY_WIFI_STATE, vconf_keynode_get_name(node)) == 0)
+ {
+ int state = VCONFKEY_WIFI_OFF;
+ int errorCode = 0;
+ errorCode = vconf_get_int(VCONFKEY_WIFI_STATE, &state);
+
+ if(errorCode == 0 && (state == VCONFKEY_WIFI_OFF || state == VCONFKEY_WIFI_UNCONNECTED))
+ {
+ settingKey.Append(_NETWORK_WIFI);
+ r = pSettingInfo->AnnounceSettingEvent(settingKey);
+ SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
+ }
+ return;
+ }
+ else if (strcmp(VCONFKEY_WIFI_ENABLE_QS, vconf_keynode_get_name(node)) == 0)
+ {
+ settingKey.Append(_NETWORK_WIFI_NOTIFICATION);
+ }
+ else if (strcmp(VCONFKEY_WIFI_DIRECT_STATE, vconf_keynode_get_name(node)) == 0)
+ {
+ int state = VCONFKEY_WIFI_DIRECT_DEACTIVATED;
+ int errorCode = 0;
+ errorCode = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &state);
+ SysLog(NID_SYS, "Wi-Fi Direct state is changed. %d", state);
+ if(errorCode == 0 && (state == VCONFKEY_WIFI_DIRECT_DEACTIVATED || state == VCONFKEY_WIFI_DIRECT_ACTIVATED))
+ {
+ settingKey.Append(_NETWORK_WIFI_DIRECT);
+ r = pSettingInfo->AnnounceSettingEvent(settingKey);
+ SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
+ }
+ return;
+ }
+ else if (strcmp(VCONFKEY_BT_STATUS, vconf_keynode_get_name(node)) == 0)
+ {
+ settingKey.Append(_NETWORK_BLUETOOTH);
+ }
+ else if (strcmp(VCONFKEY_MOBILE_HOTSPOT_SECURITY, vconf_keynode_get_name(node)) == 0)
+ {
+ settingKey.Append(_NETWORK_WIFI_TETHERING_SECURITY);
+ }
+ else if (strcmp(VCONFKEY_MOBILE_HOTSPOT_HIDE, vconf_keynode_get_name(node)) == 0)
+ {
+ settingKey.Append(_NETWORK_WIFI_TETHERING_HIDE);
+ }
+ else
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is not supported key.");
+ return;
+ }
+
+ r = pSettingInfo->AnnounceSettingEvent(settingKey);
+ SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
+}
+
+void
+_SettingNetworkProvider::SettingEventTetheringEnabled(tethering_error_e err, tethering_type_e type, bool is_requested, void* data)
+{
+ String settingKey;
+ SysLog(NID_SYS, "Tethering Endabled Event is occured.");
+
+ _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
+ SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
+
+ switch(type)
+ {
+ case TETHERING_TYPE_USB:
+ settingKey.Append(_USB_TETHERING);
+ break;
+ case TETHERING_TYPE_WIFI:
+ settingKey.Append(_NETWORK_WIFI_TETHERING);
+ break;
+ case TETHERING_TYPE_BT:
+ settingKey.Append(_NETWORK_BLUETOOTH_TETHERING);
+ break;
+ default:
+ return;
+ }
+
+ result r = pSettingInfo->AnnounceSettingEvent(settingKey);
+ SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
+}
+
+void
+_SettingNetworkProvider::SettingEventTetheringDisabled(tethering_error_e err, tethering_type_e type, tethering_disabled_cause_e cause,void* data)
+{
+ SysLog(NID_SYS, "Tethering Disabled Event is occured.");
+ SettingEventTetheringEnabled(err, type, false, null);
+}
+
+void
+_SettingNetworkProvider::SettingEventFlightMode(TapiHandle* handle, int res, void* data, void* user_data)
+{
+ String settingKey(_NETWORK_FLIGHTMODE);
+ int errorCode = 0;
+ result r = E_SUCCESS;
+ SysLog(NID_SYS, "Flightmode response is handle:%x, res:%d, date:%x, user_data:%x", handle, res, data, user_data);
+
+ _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
+ SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "SettingInfo is not ready.");
+ _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)user_data;
+ SysTryReturnVoidResult(NID_SYS, pProvider != null, E_SYSTEM, "There is invalid provider.");
+ SysTryCatch(NID_SYS, pProvider->__stateOfFlightMode == 1, E_SYSTEM, E_SYSTEM, "Current state of flight mode is not valid.");
+
+ switch (res)
+ {
+ case TAPI_POWER_FLIGHT_MODE_RESP_ON:
+ SysLog(NID_SYS, "It successes to change flight mode on");
+
+ errorCode = vconf_set_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, true);
+ if (errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to set on VCONFKEY_TELEPHONY_FLIGHT_MODE vconf.");
+ r = E_SYSTEM;
+ }
+ break;
+ case TAPI_POWER_FLIGHT_MODE_RESP_OFF:
+ SysLog(NID_SYS, "It successes to change flight mode off");
+
+ errorCode = vconf_set_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, false);
+ if (errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to set on VCONFKEY_TELEPHONY_FLIGHT_MODE vconf.");
+ r = E_SYSTEM;
+ }
+ break;
+ case TAPI_POWER_FLIGHT_MODE_RESP_FAIL:
+ default:
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to change flight mode");
+ r = E_SYSTEM;
+ }
+
+ if(pProvider->__pFlightModeListener != null)
+ {
+ pProvider->__pFlightModeListener->OnResultReceivedForSetValueAsync(settingKey, r);
+ }
+
+CATCH:
+ pProvider->__stateOfFlightMode = 0;
+}
+
+result
+_SettingNetworkProvider::FlightModeEnabler(void* data)
+{
+ result r = E_SUCCESS;
+ int errorCode = 0;
+ String settingKey(_NETWORK_FLIGHTMODE);
+
+ _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)data;
+ _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
+ SysTryReturnResult(NID_SYS, pProvider != null && pSettingInfo != null, E_SYSTEM, "Provider or SettingInfo is not ready.");
+ SysTryCatch(NID_SYS, pProvider->__stateOfFlightMode == 1, E_SYSTEM, E_SYSTEM, "Current state of flight mode is not valid.");
+
+ errorCode = vconf_set_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, pProvider->__flightModeEnabled);
+ if (errorCode != 0)
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to set on VCONFKEY_TELEPHONY_FLIGHT_MODE vconf.");
+ r = E_SYSTEM;
+ }
+
+
+ if(pProvider->__pFlightModeListener != null)
+ {
+ pProvider->__pFlightModeListener->OnResultReceivedForSetValueAsync(settingKey, r);
+ }
+
+CATCH:
+ pProvider->__stateOfFlightMode = 0;
+ return r;
+}
+
+void
+_SettingNetworkProvider::SettingEventBluetooth(int res, bt_adapter_state_e adapter_state, void* user_data)
+{
+ String settingKey(_NETWORK_BLUETOOTH);
+ result r = E_SUCCESS;
+ SysLog(NID_SYS, "Bluetooth callback is invoked. result:%d, adapter_state:%d, user_data:%x", res, adapter_state, user_data);
+
+ _SettingNetworkProvider* pProvider = (_SettingNetworkProvider*)user_data;
+ SysTryReturnVoidResult(NID_SYS, pProvider != null, E_SYSTEM, "There is no values of args.");
+ SysTryCatch(NID_SYS, pProvider->__stateOfBluetooth == 1, E_SYSTEM, E_SYSTEM, "Bluetooth processing is under way.");
+
+ if(res == BT_ERROR_NONE)
+ {
+ r = E_SUCCESS;
+ }
+ else
+ {
+ r = E_SYSTEM;
+ }
+
+ if(pProvider->__pBluetoothListener != null && pProvider->__stateOfBluetooth == 1)
+ {
+ pProvider->__pBluetoothListener->OnResultReceivedForSetValueAsync(settingKey, r);
+ }
+
+ if(r == E_SUCCESS)
+ {
+ _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
+ SysTryCatch(NID_SYS, pSettingInfo != null, E_SYSTEM, E_SYSTEM, "_SettingInfo is not ready.");
+
+ result r = pSettingInfo->AnnounceSettingEvent(settingKey);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
+ }
+
+CATCH:
+ pProvider->__stateOfBluetooth = 0;
+}
+
+}}