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_SettingGeneralProvider.cpp
19 * @brief This is the implementation for the _SettingGeneralProvider class.
21 #include <unique_ptr.h>
24 #include <Elementary.h>
26 #include <runtime_info.h>
28 #include <FBase_StringConverter.h>
32 #include <FBaseSysLog.h>
34 #include "FSys_SettingInfo.h"
35 #include "FSys_SettingGeneralProvider.h"
39 using namespace Tizen::App;
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Utility;
43 namespace Tizen { namespace System
45 static const wchar_t* _DEVICE_NAME = L"http://tizen.org/setting/device_name";
47 static const wchar_t* _MOTION_UI = L"http://tizen.org/setting/motion.ui";
49 static const wchar_t* _CONTACT_ORDER_FIRSTNAME = L"http://tizen.org/setting/contacts.order.firstname";
50 static const int _CONTACT_ORDER_FIRSTNAME_FIRSTLAST = 0;
51 static const int _CONTACT_ORDER_FIRSTNAME_LASTFIRST = 1;
53 static const wchar_t* _DEVELOPER_USBDEBUGGING = L"http://tizen.org/setting/developer.usb_debugging";
55 static const wchar_t* _BATTERY_FORMAT_PERCENTAGE = L"http://tizen.org/setting/battery.format.percentage";
57 static const wchar_t* _GRAPHICS_GPU_RENDERING = L"http://tizen.org/setting/graphics.gpu.rendering";
58 static const char* _GRAPHICS_GPU_RENDERING_HW = "opengl_x11";
59 static const char* _GRAPHICS_GPU_RENDERING_SW = "software_x11";
63 void operator()(char* pValue)
73 _SettingGeneralProvider::_SettingGeneralProvider()
76 int errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR, SettingEventVConf, null);
79 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_DEVICE_NAME_STR event listener.");
82 errorCode = vconf_notify_key_changed(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, SettingEventVConf, null);
85 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER event listener.");
88 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, SettingEventVConf, null);
91 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL event listener.");
94 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL, SettingEventVConf, null);
97 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL event listener.");
100 errorCode = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, SettingEventSettingInfo, null);
103 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION event listener.");
105 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT, SettingEventVConf, null);
108 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT event listener.");
113 _SettingGeneralProvider::~_SettingGeneralProvider()
115 int errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR, SettingEventVConf);
118 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_SETAPPL_DEVICE_NAME_STR event listener.");
121 errorCode = vconf_ignore_key_changed(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, SettingEventVConf);
124 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER event listener.");
127 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, SettingEventVConf);
130 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL event listener.");
133 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL, SettingEventVConf);
136 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL event listener.");
139 errorCode = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION);
142 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION event listener.");
144 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT, SettingEventVConf);
147 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT event listener.");
152 _SettingGeneralProvider::GetValue(const String& key, bool& value)
155 result r = E_OBJ_NOT_FOUND;
157 SysLog(NID_SYS, "Key: %ls", key.GetPointer());
158 if (key == _MOTION_UI)
160 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
164 errorCode = vconf_get_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, &motion);
165 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get the VCONFKEY_SETAPPL_MOTION_ACTIVATION.");
169 else if (key == _CONTACT_ORDER_FIRSTNAME)
171 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Contact ordering feature.");
174 int contactOrder = 0;
175 errorCode = vconf_get_int(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, &contactOrder);
176 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get the VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER.");
178 if (contactOrder == _CONTACT_ORDER_FIRSTNAME_FIRSTLAST)
182 else if (contactOrder == _CONTACT_ORDER_FIRSTNAME_LASTFIRST)
191 else if (key == _DEVELOPER_USBDEBUGGING)
193 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support USB debugging feature.");
197 errorCode = vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &usbMode);
198 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get the VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL.");
201 else if(key == _BATTERY_FORMAT_PERCENTAGE)
203 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support battery format feature.");
206 int batteryFormat = 0;
207 errorCode = vconf_get_bool(VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL, &batteryFormat);
208 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get the VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL.");
209 value = batteryFormat;
211 else if(key == _GRAPHICS_GPU_RENDERING)
213 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support GPU rendering feature.");
216 int gpu_rendering = 0;
217 errorCode = vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT, &gpu_rendering);
218 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get the VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT.");
219 value = (gpu_rendering == SETTING_RENDERING_ENGINE_HW);
225 _SettingGeneralProvider::SetValue(const String& key, const bool value)
228 result r = E_OBJ_NOT_FOUND;
229 SysLog(NID_SYS, "Key: %ls, %d", key.GetPointer(), value);
230 if(key == _MOTION_UI)
232 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
235 errorCode = vconf_set_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, value);
236 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set the VCONFKEY_SETAPPL_MOTION_ACTIVATION.");
238 else if (key == _CONTACT_ORDER_FIRSTNAME)
240 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
243 int contactOrder = 0;
247 contactOrder = _CONTACT_ORDER_FIRSTNAME_FIRSTLAST;
251 contactOrder = _CONTACT_ORDER_FIRSTNAME_LASTFIRST;
253 errorCode = vconf_set_int(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, contactOrder);
254 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER vconf");
256 else if(key == _BATTERY_FORMAT_PERCENTAGE)
258 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support battery format feature.");
260 errorCode = vconf_set_bool(VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL, value);
261 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set the VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL.");
263 else if(key == _GRAPHICS_GPU_RENDERING)
265 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support GPU rendering feature.");
270 elm_config_preferred_engine_set(_GRAPHICS_GPU_RENDERING_HW);
271 errorCode = vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT, SETTING_RENDERING_ENGINE_HW);
275 elm_config_preferred_engine_set(_GRAPHICS_GPU_RENDERING_SW);
276 errorCode = vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT, SETTING_RENDERING_ENGINE_SW);
279 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get the VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT.");
285 _SettingGeneralProvider::SetValueForPrivilegedKey(const String& key, bool value)
287 result r = E_OBJ_NOT_FOUND;
288 if(key == _DEVELOPER_USBDEBUGGING)
290 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
293 int errorCode = vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, value);
294 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL vconf");
300 _SettingGeneralProvider::GetValue(const String& key, String& value)
302 result r = E_OBJ_NOT_FOUND;
303 if (key == _DEVICE_NAME)
305 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
308 unique_ptr<char, charDeleter> pDeviceName(vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR));
309 SysTryReturnResult(NID_SYS, pDeviceName.get() != null, E_SYSTEM, "It is failed to get device name.");
311 r = StringUtil::Utf8ToString(pDeviceName.get(), value);
312 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "[%s] StringUtil::Utf8ToString is failed", GetErrorMessage(r));
318 _SettingGeneralProvider::SetValue(const String& key, const String value)
321 result r = E_OBJ_NOT_FOUND;
323 if(key == _DEVICE_NAME)
325 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
328 SysTryReturnResult(NID_SYS, value.GetLength() > 0 && value.GetLength() <= 128, E_INVALID_ARG, "Device name is too long")
329 unique_ptr<char []> deviceName(_StringConverter::CopyToCharArrayN(value));
330 SysTryReturnResult(NID_SYS, deviceName.get() != null, E_SYSTEM, "It is failed to convert String to string");
332 errorCode = vconf_set_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR, deviceName.get());
333 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_DEVICE_NAME_STR vconf");
339 _SettingGeneralProvider::HasKey(const Tizen::Base::String& key)
341 if(key == _DEVICE_NAME)
345 else if(key == _MOTION_UI)
349 else if(key == _CONTACT_ORDER_FIRSTNAME)
353 else if(key == _DEVELOPER_USBDEBUGGING)
361 else if(key == _GRAPHICS_GPU_RENDERING)
365 else if(key == _BATTERY_FORMAT_PERCENTAGE)
373 _SettingGeneralProvider::SettingEventSettingInfo(system_settings_key_e key, void* userData)
375 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
376 SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
378 SysLog(NID_SYS, "SettingEvent callback is called");
380 if(key == SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION)
382 settingKey.Append(_MOTION_UI);
389 result r = pSettingInfo->AnnounceSettingEvent(settingKey);
390 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
394 _SettingGeneralProvider::SettingEventVConf(keynode_t* node, void* userData)
396 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
397 SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
400 if (strcmp(VCONFKEY_SETAPPL_DEVICE_NAME_STR, vconf_keynode_get_name(node)) == 0)
402 settingKey.Append(_DEVICE_NAME);
404 else if (strcmp(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, vconf_keynode_get_name(node)) == 0)
406 settingKey.Append(_CONTACT_ORDER_FIRSTNAME);
408 else if (strcmp(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, vconf_keynode_get_name(node)) == 0)
410 settingKey.Append(_DEVELOPER_USBDEBUGGING);
412 else if (strcmp(VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL, vconf_keynode_get_name(node)) == 0)
414 settingKey.Append(_BATTERY_FORMAT_PERCENTAGE);
416 else if (strcmp(VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT, vconf_keynode_get_name(node)) == 0)
418 settingKey.Append(_GRAPHICS_GPU_RENDERING);
424 result r = pSettingInfo->AnnounceSettingEvent(settingKey);
425 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());