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)
92 if(File::IsFileExist(_COMMON_SERVICE_ENABLED) == false)
94 if(pSettingClient == null)
96 pSettingClient = _SettingClient::GetInstance();
103 if(pSettingClientEx == null)
105 pSettingClientEx = _SettingClientEx::GetInstance();
111 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, Tizen::Base::String& value)
113 result r = E_SUCCESS;
115 if (key == _FONT_SIZE || key == _FONT_TYPE || key == _FONTSIZE || key == _FONTTYPE)
117 String tizenKey(key);
118 if(tizenKey == _FONTSIZE)
120 tizenKey = _FONT_SIZE;
122 else if(tizenKey == _FONTTYPE)
124 tizenKey = _FONT_TYPE;
127 r = GetValueForFont(tizenKey, value);
131 if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat() == true)
133 if(value == _FONT_SIZE_GIANT || value == _FONT_SIZE_HUGE)
135 value = _FONT_SIZE_LARGE; //OSP not support giant or huge size of font.
143 if(common_mode == false)
145 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
146 r = pSettingClient->GetValue(key, value);
150 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
151 r = pSettingClientEx->GetValue(key, value);
158 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, int& value)
161 if(common_mode == false)
163 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
164 return pSettingClient->GetValue(key, value);
168 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
169 return pSettingClientEx->GetValue(key, value);
174 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, long long& value)
177 if(common_mode == false)
179 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
180 return pSettingClient->GetValue(key, value);
184 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
185 return pSettingClientEx->GetValue(key, value);
190 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, double& value)
193 if(common_mode == false)
195 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
196 return pSettingClient->GetValue(key, value);
200 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
201 return pSettingClientEx->GetValue(key, value);
206 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, bool& value)
209 if(common_mode == false)
211 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
212 return pSettingClient->GetValue(key, value);
216 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
217 return pSettingClientEx->GetValue(key, value);
222 _SettingInfoImpl::GetValue(const Tizen::Base::String& key, Tizen::Base::UuId& value)
225 if(common_mode == false)
227 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
228 return pSettingClient->GetValue(key, value);
232 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
233 return pSettingClientEx->GetValue(key, value);
238 _SettingInfoImpl::SetWallpaper(const Tizen::Base::String& filePath)
241 result r = E_SUCCESS;
243 if(common_mode == false)
245 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
246 r = pSettingClient->SetValue(_SETTING_SCREEN_WALLPAPER, filePath);
250 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
251 r = pSettingClientEx->SetValue(_SETTING_SCREEN_WALLPAPER, filePath);
254 if(r == E_INVALID_ARG)
255 r = E_FILE_NOT_FOUND;
256 else if(r == E_OBJ_NOT_FOUND)
258 else if(r == E_UNSUPPORTED_OPERATION)
265 _SettingInfoImpl::GetValueForPrivilegedKey(const String& key, bool& value)
269 if(common_mode == false)
271 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
272 return pSettingClient->GetValueForPrivilegedKey(key, value);
276 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
277 return pSettingClientEx->GetValueForPrivilegedKey(key, value);
282 _SettingInfoImpl::SetValue(const String& key, bool value)
285 if(common_mode == false)
287 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
288 return pSettingClient->SetValue(key, value);
292 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
293 return pSettingClientEx->SetValue(key, value);
298 _SettingInfoImpl::SetValue(const String& key, int value)
301 if(common_mode == false)
303 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
304 return pSettingClient->SetValue(key, value);
308 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
309 return pSettingClientEx->SetValue(key, value);
315 _SettingInfoImpl::SetValue(const String& key, String value)
317 result r = E_SUCCESS;
318 if (key == _FONT_SIZE || key == _FONT_TYPE)
320 r = SetValueForFont(key, value);
325 if(common_mode == false)
327 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
328 return pSettingClient->SetValue(key, value);
332 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
333 return pSettingClientEx->SetValue(key, value);
340 _SettingInfoImpl::SetValueForPrivilegedKey(const String& key, bool value)
343 if(common_mode == false)
345 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
346 return pSettingClient->SetValueForPrivilegedKey(key, value);
350 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
351 return pSettingClientEx->SetValueForPrivilegedKey(key, value);
356 _SettingInfoImpl::SetValueForPrivilegedKey(const String& key, String value)
359 if(common_mode == false)
361 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
362 return pSettingClient->SetValueForPrivilegedKey(key, value);
366 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
367 return pSettingClientEx->SetValueForPrivilegedKey(key, value);
372 _SettingInfoImpl::HasKey(const String& key)
375 if(common_mode == false)
377 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
378 return pSettingClient->HasKey(key);
382 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
383 return pSettingClientEx->HasKey(key);
387 _SettingInfoImpl::ResetToFactoryDefault(void)
390 if(common_mode == false)
392 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
393 return pSettingClient->ResetToFactoryDefault();
397 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
398 return pSettingClientEx->ResetToFactoryDefault();
403 _SettingInfoImpl::SetRingtone(const Tizen::Base::String& filePath)
405 result r = E_SUCCESS;
407 if(common_mode == false)
409 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
410 r = pSettingClient->SetValue(_SETTING_SOUND_RINGTONE, filePath);
414 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
415 r = pSettingClientEx->SetValue(_SETTING_SOUND_RINGTONE, filePath);
418 if(r == E_INVALID_ARG)
419 r = E_FILE_NOT_FOUND;
420 else if(r == E_OBJ_NOT_FOUND)
422 else if(r == E_UNSUPPORTED_OPERATION)
429 _SettingInfoImpl::SetVolume(const Tizen::Base::String& soundCategory, int level)
431 result r = E_SUCCESS;
434 if (soundCategory == _SETTING_SYSTEM_SOUND_VOLUME)
436 key = _SETTING_SOUND_SYSTEM_VOLUME;
438 else if (soundCategory == _SETTING_MEDIA_SOUND_VOLUME)
440 key = _SETTING_SOUND_MEDIA_VOLUME;
442 else if (soundCategory == _SETTING_RINGTONE_SOUND_VOLUME)
444 key = _SETTING_SOUND_RINGTONE_VOLUME;
446 else if (soundCategory == _SETTING_NOTIFICATION_SOUND_VOLUME)
448 key = _SETTING_SOUND_NOTIFICATION_VOLUME;
456 if(common_mode == false)
458 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
459 r = pSettingClient->SetValue(key, level);
463 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
464 r = pSettingClientEx->SetValue(key, level);
467 if (r == E_OBJ_NOT_FOUND)
471 else if(r == E_INVALID_ARG)
475 else if(r == E_UNSUPPORTED_OPERATION)
483 _SettingInfoImpl::AddSettingEventListener(ISettingEventListener& listener)
486 if(common_mode == false)
488 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
489 return pSettingClient->AddSettingEventListener(listener);
493 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
494 return pSettingClientEx->AddSettingEventListener(listener);
499 _SettingInfoImpl::RemoveSettingEventListener(ISettingEventListener& listener)
502 if(common_mode == false)
504 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
505 return pSettingClient->RemoveSettingEventListener(listener);
509 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
510 return pSettingClientEx->RemoveSettingEventListener(listener);
515 _SettingInfoImpl::AddSettingEventListenerForInternal(ISettingEventListener& listener)
518 if(common_mode == false)
520 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
521 return pSettingClient->AddSettingEventListenerForInternal(listener);
525 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
526 return pSettingClientEx->AddSettingEventListenerForInternal(listener);
531 _SettingInfoImpl::RemoveSettingEventListenerForInternal(ISettingEventListener& listener)
534 if(common_mode == false)
536 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
537 return pSettingClient->RemoveSettingEventListenerForInternal(listener);
541 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
542 return pSettingClientEx->RemoveSettingEventListenerForInternal(listener);
547 _SettingInfoImpl::SetSettingEventListener(ISettingEventListener* pListener)
550 if(common_mode == false)
552 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
553 return pSettingClient->SetSettingEventListener(pListener);
557 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
558 return pSettingClientEx->SetSettingEventListener(pListener);
563 _SettingInfoImpl::SetValueAsync(const Tizen::Base::String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
566 if(common_mode == false)
568 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
569 return pSettingClient->SetValueAsync(key, value, listener);
573 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
574 return pSettingClientEx->SetValueAsync(key, value, listener);
579 _SettingInfoImpl::SetValueAsyncForPrivilegedKey(const Tizen::Base::String& key, bool value, ISettingInfoSetValueAsyncResultListener* listener)
582 if(common_mode == false)
584 SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
585 return pSettingClient->SetValueAsyncForPrivilegedKey(key, value, listener);
589 SysTryReturnResult(NID_SYS, pSettingClientEx != null, E_SYSTEM, "It is failed to intialize setting manager");
590 return pSettingClientEx->SetValueAsyncForPrivilegedKey(key, value, listener);
595 _SettingInfoImpl::GetInstance(SettingInfo& settinginfo)
597 return settinginfo.__pSettingInfoImpl;
600 const _SettingInfoImpl*
601 _SettingInfoImpl::GetInstance(const SettingInfo& settinginfo)
603 return settinginfo.__pSettingInfoImpl;
607 _SettingInfoImpl::GetValueForFont(const Tizen::Base::String& key, Tizen::Base::String& value)
609 result r = E_OBJ_NOT_FOUND;
611 if (key == _FONT_SIZE)
615 res = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &fontSize);
617 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "It is failed to get font size.");
622 case _FONT_SIZE_GIANT_VCONF:
623 value.Append(_FONT_SIZE_GIANT);
625 case _FONT_SIZE_HUGE_VCONF:
626 value.Append(_FONT_SIZE_HUGE);
628 case _FONT_SIZE_LARGE_VCONF:
629 value.Append(_FONT_SIZE_LARGE);
631 case _FONT_SIZE_MEDIUM_VCONF:
632 value.Append(_FONT_SIZE_MEDIUM);
634 case _FONT_SIZE_SMALL_VCONF:
635 value.Append(_FONT_SIZE_SMALL);
643 else if (key == _FONT_TYPE)
646 char* pFontType = null;
648 res = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &pFontType);
649 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "Failed to get font type");
650 r = StringUtil::Utf8ToString(pFontType, value);
651 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::Utf8ToString failed", GetErrorMessage(r));
659 _SettingInfoImpl::SetValueForFont(const Tizen::Base::String& key, Tizen::Base::String value)
661 result r = E_OBJ_NOT_FOUND;
663 if(key == _FONT_SIZE)
667 String lowerValue = value;
668 lowerValue.ToLowerCase();
671 if (lowerValue == _FONT_SIZE_GIANT)
673 fontSize = _FONT_SIZE_GIANT_VCONF;
675 else if (lowerValue == _FONT_SIZE_HUGE)
677 fontSize = _FONT_SIZE_HUGE_VCONF;
679 else if (lowerValue == _FONT_SIZE_LARGE)
681 fontSize = _FONT_SIZE_LARGE_VCONF;
683 else if (lowerValue == _FONT_SIZE_MEDIUM)
685 fontSize = _FONT_SIZE_MEDIUM_VCONF;
687 else if (lowerValue == _FONT_SIZE_SMALL)
689 fontSize = _FONT_SIZE_SMALL_VCONF;
693 return E_INVALID_ARG;
695 res = system_settings_set_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, fontSize);
696 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "It is failed to set font size.");
698 else if(key == _FONT_TYPE)
703 unique_ptr<char[]> pFontType(_StringConverter::CopyToCharArrayN(value));
704 SysTryReturnResult(NID_SYS, pFontType.get() != null, E_SYSTEM, "It is failed to convert String to string.");
705 SysLog(NID_SYS, "Requested font type is %s.", pFontType.get());
706 res = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, pFontType.get());
707 SysTryReturnResult(NID_SYS, res != SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, "It is not valid font type.");
708 SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "It is failed to set font type.");