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_SettingScreenProvider.cpp
19 * @brief This is the implementation for the _SettingScreenProvider class.
22 #include <unique_ptr.h>
28 #include <FBaseSysLog.h>
30 #include <FBase_StringConverter.h>
32 #include "FSys_SettingInfo.h"
33 #include "FSys_SettingScreenProvider.h"
37 using namespace Tizen::App;
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Utility;
40 using namespace Tizen::Io;
42 namespace Tizen { namespace System
45 static const wchar_t* _SCREEN_WALLPAPER = L"http://tizen.org/setting/screen.wallpaper";
46 static const wchar_t* _SCREEN_WALLPAPER_LOCK = L"http://tizen.org/setting/screen.wallpaper.lock";
47 static const wchar_t* _SCREEN_BRIGHTNESS = L"http://tizen.org/setting/screen.brightness";
48 static const wchar_t* _SCREEN_BRIGHTNESS_AUTO = L"http://tizen.org/setting/screen.brightness.auto";
49 static const wchar_t* _SCREEN_BACKLIGHT_TIME = L"http://tizen.org/setting/screen.backlight.time";
50 static const wchar_t* _SCREEN_ROTATION_AUTO = L"http://tizen.org/setting/screen.rotation.auto";
51 static const wchar_t* _SCREEN_MODE = L"http://tizen.org/setting/screen.mode";
53 static const wchar_t* _SCREEN_MODE_DYNAMIC = L"Dynamic";
54 static const wchar_t* _SCREEN_MODE_STANDARD = L"Standard";
55 static const wchar_t* _SCREEN_MODE_NATURAL = L"Natural";
56 static const wchar_t* _SCREEN_MODE_MOVIE = L"Movie";
57 static const char* _SCREEN_MODE_VCONFKEY = VCONFKEY_SETAPPL_PREFIX"/screenmode/selected_name";
61 void operator()(char* pValue)
71 _SettingScreenProvider::_SettingScreenProvider()
73 int errorCode = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, SettingEventSettingInfo, null);
76 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register wallpaper event listener");
79 errorCode = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, SettingEventSettingInfo, null);
82 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register lock wallpaper event listener");
85 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, SettingEventVConf, null);
88 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_LCD_BRIGHTNESS event listener");
91 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SettingEventVConf, null);
94 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT event listener");
97 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, SettingEventVConf, null);
100 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL event listener");
103 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, SettingEventVConf, null);
106 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL event listener");
109 errorCode = vconf_notify_key_changed(_SCREEN_MODE_VCONFKEY, SettingEventVConf, null);
112 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register _SCREEN_MODE_VCONFKEY event listener");
117 _SettingScreenProvider::~_SettingScreenProvider()
119 int errorCode = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN);
122 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister wallpaper event listener");
125 errorCode = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN);
128 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister lock wallpaper event listener");
131 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, SettingEventVConf);
134 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_SETAPPL_LCD_BRIGHTNESS event listener");
137 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SettingEventVConf);
140 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT event listener");
143 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, SettingEventVConf);
146 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL event listener");
149 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, SettingEventVConf);
152 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL event listener");
155 errorCode = vconf_ignore_key_changed(_SCREEN_MODE_VCONFKEY, SettingEventVConf);
158 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister _SCREEN_MODE_VCONFKEY event listener");
163 _SettingScreenProvider::GetValue(const String& key, bool& value)
166 result r = E_OBJ_NOT_FOUND;
167 if (key == _SCREEN_BRIGHTNESS_AUTO)
169 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support brightness auto control feature.");
171 int brightnessAuto = 0;
172 errorCode = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &brightnessAuto);
173 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on SETAPPL_BRIGHTNESS_AUTOMATIC_INT vconf");
175 if(brightnessAuto == 0)
184 else if (key == _SCREEN_ROTATION_AUTO)
186 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support auto ratation feature.");
188 int autoRotate = false;
189 errorCode = vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &autoRotate);
190 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL vconf");
204 _SettingScreenProvider::SetValue(const String& key, const bool value)
207 result r = E_OBJ_NOT_FOUND;
209 if(key == _SCREEN_BRIGHTNESS_AUTO)
211 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support brightness auto control feature.");
215 errorCode = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_ON);
219 errorCode = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_OFF);
221 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on SETAPPL_BRIGHTNESS_AUTOMATIC_INT vconf");
223 else if(key == _SCREEN_ROTATION_AUTO)
225 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support auto ratation feature.");
227 errorCode = vconf_set_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, value);
228 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL vconf");
234 _SettingScreenProvider::GetValue(const String& key, int& value)
237 result r = E_OBJ_NOT_FOUND;
238 if (key == _SCREEN_BRIGHTNESS)
240 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support brightness feature.");
243 errorCode = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness);
244 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_SETAPPL_LCD_BRIGHTNESS vconf");
247 else if (key == _SCREEN_BACKLIGHT_TIME)
249 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support screen backlight time feature.");
252 errorCode = vconf_get_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, &timeout);
253 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get on VCONFKEY_SETAPPL_TIMEOUT_NORMAL vconf");
260 _SettingScreenProvider::SetValue(const String& key, const int value)
263 result r = E_OBJ_NOT_FOUND;
265 if(key == _SCREEN_BRIGHTNESS)
267 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support brightness feature.");
269 SysTryReturnResult(NID_SYS, value > 0 && value <= 100, E_INVALID_ARG, "Out of range");
271 errorCode = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, value);
272 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_LCD_BRIGHTNESS vconf");
274 errorCode = device_set_brightness_to_settings(0, value);
277 SysLog(NID_SYS, "It is failed to update screen brightness.");
280 else if(key == _SCREEN_BACKLIGHT_TIME)
282 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support screen backlight time feature.");
284 SysTryReturnResult(NID_SYS, value == 15 || value == 30 || value == 60 || value == 120 || value == 300 || value == 600, E_INVALID_ARG, "Out of range");
286 errorCode = vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, value);
287 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set on VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL vconf");
293 _SettingScreenProvider::GetValue(const String& key, String& value)
296 result r = E_SUCCESS;
298 if(key == _SCREEN_WALLPAPER)
300 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support wallpaper feature.");
302 char* pWallpaper = null;
303 errorCode = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &pWallpaper);
304 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to get wallpaper of home screen");
306 r = StringUtil::Utf8ToString(pWallpaper, value);
307 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "[%s] StringUtil::Utf8ToString failed", GetErrorMessage(r));
311 else if (key == _SCREEN_WALLPAPER_LOCK)
313 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support wallpaper feature.");
315 unique_ptr<char, charDeleter> pWallpaper(null);
318 errorCode = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, &pTemp);
319 SysTryReturnResult(NID_SYS, errorCode == 0 && pTemp != null, E_SYSTEM, "It is failed to get wallpaper of lock screen");
321 pWallpaper.reset(pTemp);
323 r = StringUtil::Utf8ToString(pWallpaper.get(), value);
324 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "[%s] StringUtil::Utf8ToString failed", GetErrorMessage(r));
326 else if (key == _SCREEN_MODE)
328 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support screen mode feature.");
330 unique_ptr<char, charDeleter> curmode(vconf_get_str(_SCREEN_MODE_VCONFKEY));
332 value.Append(curmode.get());
338 _SettingScreenProvider::SetValue(const String& key, const String value)
341 result r = E_SUCCESS;
343 if(key == _SCREEN_WALLPAPER)
345 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support wallpaper feature.");
347 SysTryReturnResult(NID_SYS, File::IsFileExist(value) == true, E_INVALID_ARG, "The entry for the specified wallpaper file or the file path cannot be found");
348 unique_ptr<char []> pFilePath(_StringConverter::CopyToCharArrayN(value));
350 SysTryReturnResult(NID_SYS, pFilePath.get() != null, E_SYSTEM, "It is failed to convert type of filePath");
352 errorCode = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, pFilePath.get());
353 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set wallpaper of home screen");
355 else if(key == _SCREEN_WALLPAPER_LOCK)
357 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support wallpaper feature.");
359 SysTryReturnResult(NID_SYS, File::IsFileExist(value) == true, E_INVALID_ARG, "The entry for the specified wallpaper lock file or the file path cannot be found");
360 unique_ptr<char []> pFilePath(_StringConverter::CopyToCharArrayN(value));
361 SysTryReturnResult(NID_SYS, pFilePath.get() != null, E_SYSTEM, "It is failed to convert type of filePath");
363 errorCode = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, pFilePath.get());
364 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set wallpaper of home screen");
366 else if(key == _SCREEN_MODE)
368 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support screen mode feature.");
370 SysTryReturnResult(NID_SYS, value == _SCREEN_MODE_DYNAMIC || value == _SCREEN_MODE_STANDARD || value == _SCREEN_MODE_NATURAL || value == _SCREEN_MODE_MOVIE, E_INVALID_ARG, "designated value(%ls) is invalid", value.GetPointer());
371 unique_ptr<char []> screenMode(_StringConverter::CopyToCharArrayN(value));
372 errorCode = vconf_set_str(_SCREEN_MODE_VCONFKEY, screenMode.get());
374 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to change screen mode.");
380 _SettingScreenProvider::HasKey(const Tizen::Base::String& key)
383 if(key == _SCREEN_WALLPAPER || key == _SCREEN_WALLPAPER_LOCK)
387 else if(key == _SCREEN_BRIGHTNESS || key ==_SCREEN_BRIGHTNESS_AUTO)
391 else if(key == _SCREEN_BACKLIGHT_TIME)
395 else if(key == _SCREEN_ROTATION_AUTO)
399 else if(key == _SCREEN_MODE)
407 _SettingScreenProvider::SettingEventVConf(keynode_t* node, void* userData)
411 if (strcmp(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, vconf_keynode_get_name(node)) == 0)
413 settingKey.Append(_SCREEN_BRIGHTNESS);
415 else if (strcmp(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, vconf_keynode_get_name(node)) == 0)
417 settingKey.Append(_SCREEN_BRIGHTNESS_AUTO);
419 else if (strcmp(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, vconf_keynode_get_name(node)) == 0)
421 settingKey.Append(_SCREEN_BACKLIGHT_TIME);
423 else if (strcmp(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, vconf_keynode_get_name(node)) == 0)
425 settingKey.Append(_SCREEN_ROTATION_AUTO);
427 else if (strcmp(_SCREEN_MODE_VCONFKEY, vconf_keynode_get_name(node)) == 0)
429 settingKey.Append(_SCREEN_MODE);
435 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
436 SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
438 result r = pSettingInfo->AnnounceSettingEvent(settingKey);
439 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());
443 _SettingScreenProvider::SettingEventSettingInfo(system_settings_key_e key, void* userData)
447 if(key == SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN)
449 settingKey.Append(_SCREEN_WALLPAPER);
451 else if(key == SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN)
453 settingKey.Append(_SCREEN_WALLPAPER_LOCK);
459 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
460 SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
462 result r = pSettingInfo->AnnounceSettingEvent(settingKey);
463 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());