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
46 static const int _NUM_OF_GENERAL_PROVIDER = 6;
48 static const wchar_t* _DEVICE_NAME = L"device_name";
50 static const wchar_t* _MOTION_UI = L"motion.ui";
52 static const wchar_t* _CONTACT_ORDER_FIRSTNAME = L"contacts.order.firstname";
53 static const int _CONTACT_ORDER_FIRSTNAME_FIRSTLAST = 0;
54 static const int _CONTACT_ORDER_FIRSTNAME_LASTFIRST = 1;
56 static const wchar_t* _DEVELOPER_USBDEBUGGING = L"developer.usb_debugging";
58 static const wchar_t* _BATTERY_FORMAT_PERCENTAGE = L"battery.format.percentage";
60 static const wchar_t* _GRAPHICS_GPU_RENDERING = L"graphics.gpu.rendering";
61 static const char* _GRAPHICS_GPU_RENDERING_HW = "opengl_x11";
62 static const char* _GRAPHICS_GPU_RENDERING_SW = "software_x11";
66 void operator()(char* pValue)
76 _SettingGeneralProvider::_SettingGeneralProvider()
79 int errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR, SettingEventVConf, null);
82 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_DEVICE_NAME_STR event listener.");
85 errorCode = vconf_notify_key_changed(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, SettingEventVConf, null);
88 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER event listener.");
91 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, SettingEventVConf, null);
94 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL event listener.");
97 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL, SettingEventVConf, null);
100 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL event listener.");
103 errorCode = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, SettingEventSettingInfo, null);
106 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION event listener.");
108 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT, SettingEventVConf, null);
111 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT event listener.");
116 _SettingGeneralProvider::~_SettingGeneralProvider()
118 int errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR, SettingEventVConf);
121 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_SETAPPL_DEVICE_NAME_STR event listener.");
124 errorCode = vconf_ignore_key_changed(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, SettingEventVConf);
127 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER event listener.");
130 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, SettingEventVConf);
133 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL event listener.");
136 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL, SettingEventVConf);
139 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL event listener.");
142 errorCode = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION);
145 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION event listener.");
147 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT, SettingEventVConf);
150 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT event listener.");
155 _SettingGeneralProvider::GetValue(const String& key, bool& value)
158 result r = E_OBJ_NOT_FOUND;
160 SysLog(NID_SYS, "Key: %ls", key.GetPointer());
161 if (key == _MOTION_UI)
163 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
167 errorCode = vconf_get_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, &motion);
168 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get the VCONFKEY_SETAPPL_MOTION_ACTIVATION.");
172 else if (key == _CONTACT_ORDER_FIRSTNAME)
174 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support Contact ordering feature.");
177 int contactOrder = 0;
178 errorCode = vconf_get_int(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, &contactOrder);
179 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get the VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER.");
181 if (contactOrder == _CONTACT_ORDER_FIRSTNAME_FIRSTLAST)
185 else if (contactOrder == _CONTACT_ORDER_FIRSTNAME_LASTFIRST)
194 else if (key == _DEVELOPER_USBDEBUGGING)
196 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support USB debugging feature.");
200 errorCode = vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &usbMode);
201 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get the VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL.");
204 else if(key == _BATTERY_FORMAT_PERCENTAGE)
206 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support battery format feature.");
209 int batteryFormat = 0;
210 errorCode = vconf_get_bool(VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL, &batteryFormat);
211 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get the VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL.");
212 value = batteryFormat;
214 else if(key == _GRAPHICS_GPU_RENDERING)
216 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support GPU rendering feature.");
219 int gpu_rendering = 0;
220 errorCode = vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT, &gpu_rendering);
221 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get the VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT.");
222 value = (gpu_rendering == SETTING_RENDERING_ENGINE_HW);
228 _SettingGeneralProvider::SetValue(const String& key, const bool value)
231 result r = E_OBJ_NOT_FOUND;
232 SysLog(NID_SYS, "Key: %ls, %d", key.GetPointer(), value);
233 if(key == _MOTION_UI)
235 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
238 errorCode = vconf_set_bool(VCONFKEY_SETAPPL_MOTION_ACTIVATION, value);
239 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set the VCONFKEY_SETAPPL_MOTION_ACTIVATION.");
241 else if (key == _CONTACT_ORDER_FIRSTNAME)
243 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
246 int contactOrder = 0;
250 contactOrder = _CONTACT_ORDER_FIRSTNAME_FIRSTLAST;
254 contactOrder = _CONTACT_ORDER_FIRSTNAME_LASTFIRST;
256 errorCode = vconf_set_int(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, contactOrder);
257 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER vconf");
259 else if(key == _BATTERY_FORMAT_PERCENTAGE)
261 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support battery format feature.");
263 errorCode = vconf_set_bool(VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL, value);
264 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set the VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL.");
266 else if(key == _GRAPHICS_GPU_RENDERING)
268 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support GPU rendering feature.");
273 elm_config_preferred_engine_set(_GRAPHICS_GPU_RENDERING_HW);
274 errorCode = vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT, SETTING_RENDERING_ENGINE_HW);
278 elm_config_preferred_engine_set(_GRAPHICS_GPU_RENDERING_SW);
279 errorCode = vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT, SETTING_RENDERING_ENGINE_SW);
282 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get the VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT.");
288 _SettingGeneralProvider::SetValueForPrivilegedKey(const String& key, bool value)
290 result r = E_OBJ_NOT_FOUND;
291 if(key == _DEVELOPER_USBDEBUGGING)
293 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
296 int errorCode = vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, value);
297 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL vconf");
303 _SettingGeneralProvider::GetValue(const String& key, String& value)
305 result r = E_OBJ_NOT_FOUND;
306 if (key == _DEVICE_NAME)
308 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
311 unique_ptr<char, charDeleter> pDeviceName(vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR));
312 SysTryReturnResult(NID_SYS, pDeviceName.get() != null, E_SYSTEM, "It is failed to get device name.");
314 r = StringUtil::Utf8ToString(pDeviceName.get(), value);
315 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "[%s] StringUtil::Utf8ToString is failed", GetErrorMessage(r));
321 _SettingGeneralProvider::SetValue(const String& key, const String value)
324 result r = E_OBJ_NOT_FOUND;
326 if(key == _DEVICE_NAME)
328 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support vibrator feature.");
331 SysTryReturnResult(NID_SYS, value.GetLength() > 0 && value.GetLength() <= 128, E_INVALID_ARG, "Device name is too long")
332 unique_ptr<char []> deviceName(_StringConverter::CopyToCharArrayN(value));
333 SysTryReturnResult(NID_SYS, deviceName.get() != null, E_SYSTEM, "It is failed to convert String to string");
335 errorCode = vconf_set_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR, deviceName.get());
336 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_DEVICE_NAME_STR vconf");
342 _SettingGeneralProvider::HasKey(const Tizen::Base::String& key)
344 if(key == _DEVICE_NAME)
348 else if(key == _MOTION_UI)
352 else if(key == _CONTACT_ORDER_FIRSTNAME)
356 else if(key == _DEVELOPER_USBDEBUGGING)
364 else if(key == _GRAPHICS_GPU_RENDERING)
368 else if(key == _BATTERY_FORMAT_PERCENTAGE)
376 _SettingGeneralProvider::SettingEventSettingInfo(system_settings_key_e key, void* userData)
378 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
379 SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
382 if(key == SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION)
384 settingKey.Append(_MOTION_UI);
391 result r = pSettingInfo->AnnounceSettingEvent(settingKey);
392 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
396 _SettingGeneralProvider::SettingEventVConf(keynode_t* node, void* userData)
398 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
399 SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
402 if (strcmp(VCONFKEY_SETAPPL_DEVICE_NAME_STR, vconf_keynode_get_name(node)) == 0)
404 settingKey.Append(_DEVICE_NAME);
406 else if (strcmp(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, vconf_keynode_get_name(node)) == 0)
408 settingKey.Append(_CONTACT_ORDER_FIRSTNAME);
410 else if (strcmp(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, vconf_keynode_get_name(node)) == 0)
412 settingKey.Append(_DEVELOPER_USBDEBUGGING);
414 else if (strcmp(VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL, vconf_keynode_get_name(node)) == 0)
416 settingKey.Append(_BATTERY_FORMAT_PERCENTAGE);
418 else if (strcmp(VCONFKEY_SETAPPL_DEFAULT_RENDERING_ENGINE_TYPE_INT, vconf_keynode_get_name(node)) == 0)
420 settingKey.Append(_GRAPHICS_GPU_RENDERING);
426 result r = pSettingInfo->AnnounceSettingEvent(settingKey);
427 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());