2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FSys_SettingLocationProvider.cpp
19 * @brief This is the implementation for the _SettingLocationProvider class.
24 #include <FBaseSysLog.h>
26 #include "FSys_SettingInfo.h"
27 #include "FSys_SettingLocationProvider.h"
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
32 namespace Tizen { namespace System
35 static const wchar_t* _LOCATION_GPS = L"http://tizen.org/setting/location.gps";
36 static const wchar_t* _LOCATION_GPS_ADVANCED = L"http://tizen.org/setting/location.gps.advanced";
37 static const wchar_t* _LOCATION_WPS = L"http://tizen.org/setting/location.wps";
39 _SettingLocationProvider::_SettingLocationProvider()
41 int errorCode = vconf_notify_key_changed(VCONFKEY_LOCATION_ENABLED, SettingEventVConf, null);
44 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_LOCATION_ENABLED event listener");
47 errorCode = vconf_notify_key_changed(VCONFKEY_LOCATION_NETWORK_ENABLED, SettingEventVConf, null);
50 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_LOCATION_NETWORK_ENABLED event listener");
53 errorCode = vconf_notify_key_changed(VCONFKEY_LOCATION_AGPS_ENABLED, SettingEventVConf, null);
56 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_LOCATION_AGPS_ENABLED event listener");
61 _SettingLocationProvider::~_SettingLocationProvider()
63 int errorCode = vconf_ignore_key_changed(VCONFKEY_LOCATION_ENABLED, SettingEventVConf);
66 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_LOCATION_ENABLED event listener");
69 errorCode = vconf_ignore_key_changed(VCONFKEY_LOCATION_NETWORK_ENABLED, SettingEventVConf);
72 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_LOCATION_NETWORK_ENABLED event listener");
75 errorCode = vconf_ignore_key_changed(VCONFKEY_LOCATION_AGPS_ENABLED, SettingEventVConf);
78 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_LOCATION_AGPS_ENABLED event listener");
83 _SettingLocationProvider::GetValue(const String& key, bool& value)
85 result r = E_OBJ_NOT_FOUND;
88 if (key == _LOCATION_GPS)
91 errorCode = vconf_get_int(VCONFKEY_LOCATION_ENABLED, &gps_value);
93 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get the VCONFKEY_LOCATION_ENABLED vconf.");
103 else if (key == _LOCATION_GPS_ADVANCED)
106 errorCode = vconf_get_int(VCONFKEY_LOCATION_AGPS_ENABLED, &agps);
108 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL vconf.");
121 else if (key == _LOCATION_WPS)
124 errorCode = vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &wps_value);
126 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get the VCONFKEY_LOCATION_NETWORK_ENABLED");
141 _SettingLocationProvider::SetValueForPrivilegedKey(const String& key, bool value)
144 result r = E_OBJ_NOT_FOUND;
145 if(key == _LOCATION_GPS)
147 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support GPS feature.");
151 errorCode = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 1);
155 errorCode = vconf_set_int(VCONFKEY_LOCATION_ENABLED, 0);
157 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_LOCATION_ENABLED vconf");
159 else if(key == _LOCATION_WPS)
161 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support WPS feature.");
165 errorCode = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 1);
169 errorCode = vconf_set_int(VCONFKEY_LOCATION_NETWORK_ENABLED, 0);
171 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_LOCATION_NETWORK_ENABLED vconf");
173 else if(key == _LOCATION_GPS_ADVANCED)
175 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Advanced GPS feature.");
179 errorCode = vconf_set_int(VCONFKEY_LOCATION_AGPS_ENABLED, 1);
183 errorCode = vconf_set_int(VCONFKEY_LOCATION_AGPS_ENABLED, 0);
185 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_LOCATION_AGPS_ENABLED vconf");
191 _SettingLocationProvider::HasKey(const Tizen::Base::String& key)
193 if(key == _LOCATION_GPS || key == _LOCATION_WPS || key == _LOCATION_GPS_ADVANCED)
201 _SettingLocationProvider::SettingEventVConf(keynode_t* node, void* userData)
205 if (strcmp(VCONFKEY_LOCATION_ENABLED, vconf_keynode_get_name(node)) == 0)
207 settingKey.Append(_LOCATION_GPS);
209 else if (strcmp(VCONFKEY_LOCATION_NETWORK_ENABLED, vconf_keynode_get_name(node)) == 0)
211 settingKey.Append(_LOCATION_WPS);
213 else if (strcmp(VCONFKEY_LOCATION_AGPS_ENABLED, vconf_keynode_get_name(node)) == 0)
215 settingKey.Append(_LOCATION_GPS_ADVANCED);
221 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
222 SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
224 result r = pSettingInfo->AnnounceSettingEvent(settingKey);
225 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());