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_SettingInfoImpl.cpp
19 * @brief This is the implementation file for _SysSettingInfoImpl class.
21 #include <unique_ptr.h>
22 #include <system/system_settings.h>
24 #include <FBaseColArrayList.h>
25 #include <FBaseSysLog.h>
26 #include <FBaseUtilStringUtil.h>
29 #include <FApp_AppInfo.h>
30 #include <FBase_StringConverter.h>
31 #include <FBase_NativeError.h>
32 #include <FSys_SettingInfoImpl.h>
34 #include "FSys_SettingClient.h"
35 #include "FSys_SettingClientEx.h"
39 using namespace Tizen::App;
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42 using namespace Tizen::Io;
43 using namespace Tizen::Base::Utility;
45 namespace Tizen { namespace System
48 static const int _SYSTEM_RESPONSE_DATA = 2;
51 static const wchar_t* _SETTING_SCREEN_WALLPAPER = L"http://tizen.org/setting/screen.wallpaper";
52 static const wchar_t* _SETTING_SYSTEM_SOUND_VOLUME = L"SystemSoundVolume";
53 static const wchar_t* _SETTING_SOUND_SYSTEM_VOLUME= L"http://tizen.org/setting/sound.system.volume";
54 static const wchar_t* _SETTING_MEDIA_SOUND_VOLUME = L"MediaSoundVolume";
55 static const wchar_t* _SETTING_SOUND_MEDIA_VOLUME = L"http://tizen.org/setting/sound.media.volume";
56 static const wchar_t* _SETTING_RINGTONE_SOUND_VOLUME = L"RingtoneSoundVolume";
57 static const wchar_t* _SETTING_SOUND_RINGTONE = L"http://tizen.org/setting/sound.ringtone";
58 static const wchar_t* _SETTING_SOUND_RINGTONE_VOLUME = L"http://tizen.org/setting/sound.ringtone.volume";
59 static const wchar_t* _SETTING_NOTIFICATION_SOUND_VOLUME = L"NotificationSoundVolume";
60 static const wchar_t* _SETTING_SOUND_NOTIFICATION_VOLUME = L"http://tizen.org/setting/sound.notification.volume";
63 static const wchar_t* _FONT_SIZE = L"http://tizen.org/setting/font.size";
64 static const wchar_t* _FONTSIZE = L"FontSize";
65 static const wchar_t* _FONT_TYPE = L"http://tizen.org/setting/font.type";
66 static const wchar_t* _FONTTYPE = L"FontType";
68 static const wchar_t* _FONT_SIZE_GIANT = L"giant";
69 static const wchar_t* _FONT_SIZE_HUGE = L"huge";
70 static const wchar_t* _FONT_SIZE_LARGE = L"large";
71 static const wchar_t* _FONT_SIZE_MEDIUM = L"medium";
72 static const wchar_t* _FONT_SIZE_SMALL = L"small";
74 static const int _FONT_SIZE_GIANT_VCONF = 4;
75 static const int _FONT_SIZE_HUGE_VCONF = 3;
76 static const int _FONT_SIZE_LARGE_VCONF = 2;
77 static const int _FONT_SIZE_MEDIUM_VCONF = 1;
78 static const int _FONT_SIZE_SMALL_VCONF = 0;
81 static _SettingClient* pSettingClient = null;
82 static _SettingClientEx* pSettingClientEx = null;
84 static const wchar_t* _COMMON_SERVICE_ENABLED = L"/opt/usr/etc/setting_common";
85 static bool common_mode = false;
87 _SettingInfoImpl::InitSettingClient(void)
89 if(pSettingClient == null && pSettingClientEx == null)
91 if(File::IsFileExist(_COMMON_SERVICE_ENABLED) == false)
93 if(pSettingClient == null)
95 pSettingClient = _SettingClient::GetInstance();
101 if(pSettingClientEx == null)
103 pSettingClientEx = _SettingClientEx::GetInstance();
109 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, Tizen::Base::String& value)
111 result r = E_SUCCESS;
113 if (key == _FONT_SIZE || key == _FONT_TYPE || key == _FONTSIZE || key == _FONTTYPE)
115 String tizenKey(key);
116 if(tizenKey == _FONTSIZE)
118 tizenKey = _FONT_SIZE;
120 else if(tizenKey == _FONTTYPE)
122 tizenKey = _FONT_TYPE;
125 r = GetValueForFont(tizenKey, value);
129 if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat() == true)
131 if(value == _FONT_SIZE_GIANT || value == _FONT_SIZE_HUGE)
133 value = _FONT_SIZE_LARGE; //OSP not support giant or huge size of font.
141 if(common_mode == false)
143 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
144 r = pSettingClient->GetValue(key, value);
148 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
149 r = pSettingClientEx->GetValue(key, value);
156 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, int& value)
159 if(common_mode == false)
161 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
162 return pSettingClient->GetValue(key, value);
166 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
167 return pSettingClientEx->GetValue(key, value);
172 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, long long& value)
175 if(common_mode == false)
177 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
178 return pSettingClient->GetValue(key, value);
182 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
183 return pSettingClientEx->GetValue(key, value);
188 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, double& value)
191 if(common_mode == false)
193 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
194 return pSettingClient->GetValue(key, value);
198 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
199 return pSettingClientEx->GetValue(key, value);
204 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, bool& value)
207 if(common_mode == false)
209 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
210 return pSettingClient->GetValue(key, value);
214 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
215 return pSettingClientEx->GetValue(key, value);
220 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, Tizen::Base::UuId& value)
223 if(common_mode == false)
225 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
226 return pSettingClient->GetValue(key, value);
230 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
231 return pSettingClientEx->GetValue(key, value);
236 _SettingInfoImpl::SetWallpaper(const Tizen::Base::String& filePath)
239 result r = E_SUCCESS;
241 if(common_mode == false)
243 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
244 r = pSettingClient->SetValue(_SETTING_SCREEN_WALLPAPER, filePath);
248 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
249 r = pSettingClientEx->SetValue(_SETTING_SCREEN_WALLPAPER, filePath);
252 if(r == E_INVALID_ARG)
253 r = E_FILE_NOT_FOUND;
254 else if(r == E_OBJ_NOT_FOUND)
256 else if(r == E_UNSUPPORTED_OPERATION)
263 _SettingInfoImpl::GetValueForPrivilegedKey(const String& key, bool& value)
267 if(common_mode == false)
269 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
270 return pSettingClient->GetValueForPrivilegedKey(key, value);
274 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
275 return pSettingClientEx->GetValueForPrivilegedKey(key, value);
280 _SettingInfoImpl::SetValue(const String& key, bool value)
283 if(common_mode == false)
285 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
286 return pSettingClient->SetValue(key, value);
290 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
291 return pSettingClientEx->SetValue(key, value);
296 _SettingInfoImpl::SetValue(const String& key, int value)
299 if(common_mode == false)
301 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
302 return pSettingClient->SetValue(key, value);
306 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
307 return pSettingClientEx->SetValue(key, value);
313 _SettingInfoImpl::SetValue(const String& key, String value)
315 result r = E_SUCCESS;
316 if (key == _FONT_SIZE || key == _FONT_TYPE)
318 r = SetValueForFont(key, value);
323 if(common_mode == false)
325 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
326 return pSettingClient->SetValue(key, value);
330 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
331 return pSettingClientEx->SetValue(key, value);
338 _SettingInfoImpl::SetValueForPrivilegedKey(const String& key, bool value)
341 if(common_mode == false)
343 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
344 return pSettingClient->SetValueForPrivilegedKey(key, value);
348 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
349 return pSettingClientEx->SetValueForPrivilegedKey(key, value);
354 _SettingInfoImpl::SetValueForPrivilegedKey(const String& key, String value)
357 if(common_mode == false)
359 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
360 return pSettingClient->SetValueForPrivilegedKey(key, value);
364 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
365 return pSettingClientEx->SetValueForPrivilegedKey(key, value);
370 _SettingInfoImpl::HasKey(const String& key)
373 if(common_mode == false)
375 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
376 return pSettingClient->HasKey(key);
380 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
381 return pSettingClientEx->HasKey(key);
385 _SettingInfoImpl::ResetToFactoryDefault(void)
388 if(common_mode == false)
390 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
391 return pSettingClient->ResetToFactoryDefault();
395 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
396 return pSettingClientEx->ResetToFactoryDefault();
401 _SettingInfoImpl::SetRingtone(const Tizen::Base::String& filePath)
403 result r = E_SUCCESS;
405 if(common_mode == false)
407 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
408 r = pSettingClient->SetValue(_SETTING_SOUND_RINGTONE, filePath);
412 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
413 r = pSettingClientEx->SetValue(_SETTING_SOUND_RINGTONE, filePath);
416 if(r == E_INVALID_ARG)
417 r = E_FILE_NOT_FOUND;
418 else if(r == E_OBJ_NOT_FOUND)
420 else if(r == E_UNSUPPORTED_OPERATION)
427 _SettingInfoImpl::SetVolume(const Tizen::Base::String& soundCategory, int level)
429 result r = E_SUCCESS;
432 if (soundCategory == _SETTING_SYSTEM_SOUND_VOLUME)
434 key = _SETTING_SOUND_SYSTEM_VOLUME;
436 else if (soundCategory == _SETTING_MEDIA_SOUND_VOLUME)
438 key = _SETTING_SOUND_MEDIA_VOLUME;
440 else if (soundCategory == _SETTING_RINGTONE_SOUND_VOLUME)
442 key = _SETTING_SOUND_RINGTONE_VOLUME;
444 else if (soundCategory == _SETTING_NOTIFICATION_SOUND_VOLUME)
446 key = _SETTING_SOUND_NOTIFICATION_VOLUME;
454 if(common_mode == false)
456 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
457 r = pSettingClient->SetValue(key, level);
461 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
462 r = pSettingClientEx->SetValue(key, level);
465 if (r == E_OBJ_NOT_FOUND)
469 else if(r == E_INVALID_ARG)
473 else if(r == E_UNSUPPORTED_OPERATION)
481 _SettingInfoImpl::AddSettingEventListener(ISettingEventListener& listener)
484 if(common_mode == false)
486 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
487 return pSettingClient->AddSettingEventListener(listener);
491 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
492 return pSettingClientEx->AddSettingEventListener(listener);
497 _SettingInfoImpl::RemoveSettingEventListener(ISettingEventListener& listener)
500 if(common_mode == false)
502 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
503 return pSettingClient->RemoveSettingEventListener(listener);
507 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
508 return pSettingClientEx->RemoveSettingEventListener(listener);
513 _SettingInfoImpl::AddSettingEventListenerForInternal(ISettingEventListener& listener)
516 if(common_mode == false)
518 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
519 return pSettingClient->AddSettingEventListenerForInternal(listener);
523 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
524 return pSettingClientEx->AddSettingEventListenerForInternal(listener);
529 _SettingInfoImpl::RemoveSettingEventListenerForInternal(ISettingEventListener& listener)
532 if(common_mode == false)
534 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
535 return pSettingClient->RemoveSettingEventListenerForInternal(listener);
539 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
540 return pSettingClientEx->RemoveSettingEventListenerForInternal(listener);
545 _SettingInfoImpl::SetSettingEventListener(ISettingEventListener* pListener)
548 if(common_mode == false)
550 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
551 return pSettingClient->SetSettingEventListener(pListener);
555 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
556 return pSettingClientEx->SetSettingEventListener(pListener);
561 _SettingInfoImpl::SetValueAsync(const Tizen::Base::String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
564 if(common_mode == false)
566 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
567 return pSettingClient->SetValueAsync(key, value, listener);
571 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
572 return pSettingClientEx->SetValueAsync(key, value, listener);
577 _SettingInfoImpl::SetValueAsyncForPrivilegedKey(const Tizen::Base::String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
580 if(common_mode == false)
582 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
583 return pSettingClient->SetValueAsyncForPrivilegedKey(key, value, listener);
587 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
588 return pSettingClientEx->SetValueAsyncForPrivilegedKey(key, value, listener);
593 _SettingInfoImpl::GetInstance(SettingInfo& settinginfo)
595 return settinginfo.__pSettingInfoImpl;
598 const _SettingInfoImpl*
599 _SettingInfoImpl::GetInstance(const SettingInfo& settinginfo)
601 return settinginfo.__pSettingInfoImpl;
605 _SettingInfoImpl::GetValueForFont(const Tizen::Base::String& key, Tizen::Base::String& value)
607 result r = E_OBJ_NOT_FOUND;
609 if (key == _FONT_SIZE)
613 res = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &fontSize);
615 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "It is failed to get font size.");
620 case _FONT_SIZE_GIANT_VCONF:
621 value.Append(_FONT_SIZE_GIANT);
623 case _FONT_SIZE_HUGE_VCONF:
624 value.Append(_FONT_SIZE_HUGE);
626 case _FONT_SIZE_LARGE_VCONF:
627 value.Append(_FONT_SIZE_LARGE);
629 case _FONT_SIZE_MEDIUM_VCONF:
630 value.Append(_FONT_SIZE_MEDIUM);
632 case _FONT_SIZE_SMALL_VCONF:
633 value.Append(_FONT_SIZE_SMALL);
641 else if (key == _FONT_TYPE)
644 char* pFontType = null;
646 res = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &pFontType);
647 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "Failed to get font type");
648 r = StringUtil::Utf8ToString(pFontType, value);
649 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::Utf8ToString failed", GetErrorMessage(r));
657 _SettingInfoImpl::SetValueForFont(const Tizen::Base::String& key, Tizen::Base::String value)
659 result r = E_OBJ_NOT_FOUND;
661 if(key == _FONT_SIZE)
665 String lowerValue = value;
666 lowerValue.ToLowerCase();
669 if (lowerValue == _FONT_SIZE_GIANT)
671 fontSize = _FONT_SIZE_GIANT_VCONF;
673 else if (lowerValue == _FONT_SIZE_HUGE)
675 fontSize = _FONT_SIZE_HUGE_VCONF;
677 else if (lowerValue == _FONT_SIZE_LARGE)
679 fontSize = _FONT_SIZE_LARGE_VCONF;
681 else if (lowerValue == _FONT_SIZE_MEDIUM)
683 fontSize = _FONT_SIZE_MEDIUM_VCONF;
685 else if (lowerValue == _FONT_SIZE_SMALL)
687 fontSize = _FONT_SIZE_SMALL_VCONF;
691 return E_INVALID_ARG;
693 res = system_settings_set_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, fontSize);
694 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "It is failed to set font size.");
696 else if(key == _FONT_TYPE)
701 unique_ptr<char[]> pFontType(_StringConverter::CopyToCharArrayN(value));
702 SysTryReturnResult(NID_SYS, pFontType.get() != null, E_SYSTEM, "It is failed to convert String to string.");
703 SysLog(NID_SYS, "Requested font type is %s.", pFontType.get());
704 res = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, pFontType.get());
705 SysTryReturnResult(NID_SYS, res != SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, "It is not valid font type.");
706 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "It is failed to set font type.");