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_SettingApplicationProvider.cpp
19 * @brief This is the implementation for the _SettingApplicationProvider class.
21 #include <unique_ptr.h>
25 #include <FBase_StringConverter.h>
27 #include <FBaseString.h>
29 #include "FSys_SettingInfo.h"
30 #include "FSys_SettingApplicationProvider.h"
34 using namespace Tizen::App;
35 using namespace Tizen::Base;
37 namespace Tizen { namespace System
40 static const wchar_t* _APPLICATION_HOME = L"http://tizen.org/setting/application.home";
41 static const wchar_t* _APPLICATION_LOCK = L"http://tizen.org/setting/application.lock";
45 void operator()(char* pValue)
55 _SettingApplicationProvider::_SettingApplicationProvider()
57 int errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, SettingEventVConf, null);
60 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register event listen for home application change.");
62 errorCode = vconf_notify_key_changed(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, SettingEventVConf, null);
65 SysLogException(NID_SYS, E_SYSTEM, "It is failed to register event listen for lock application change.");
69 _SettingApplicationProvider::~_SettingApplicationProvider()
71 int errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, SettingEventVConf);
74 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister event listen for home application change.");
77 errorCode = vconf_ignore_key_changed(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, SettingEventVConf);
80 SysLogException(NID_SYS, E_SYSTEM, "It is failed to unregister event listen for lock application change.");
85 _SettingApplicationProvider::HasKey(const String& key)
87 if(key == _APPLICATION_HOME)
89 unique_ptr<char, charDeleter> pPackageName(vconf_get_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME));
91 if(pPackageName.get() != null)
96 else if(key == _APPLICATION_LOCK)
98 unique_ptr<char, charDeleter> pPackageName(vconf_get_str(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR));
100 if(pPackageName.get() != null)
109 _SettingApplicationProvider::GetValue(const String& key, String& value)
111 result r = E_OBJ_NOT_FOUND;
113 SysLog(NID_SYS, "Key[%ls] is required.", key.GetPointer());
114 if(key == _APPLICATION_HOME)
116 unique_ptr<char, charDeleter> pPackageName(vconf_get_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME));
117 SysLog(NID_SYS, "Value for Key[%ls] is %s.", key.GetPointer(), pPackageName.get());
118 SysTryReturnResult(NID_SYS, pPackageName != null, E_UNSUPPORTED_OPERATION, "It is failed to get package name of home application.");
120 value.Append(pPackageName.get());
123 else if(key == _APPLICATION_LOCK)
125 unique_ptr<char, charDeleter> pPackageName(vconf_get_str(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR));
126 SysLog(NID_SYS, "Value for Key[%ls] is %s.", key.GetPointer(), pPackageName.get());
127 SysTryReturnResult(NID_SYS, pPackageName != null, E_UNSUPPORTED_OPERATION, "It is failed to get package name of lock application.");
129 value.Append(pPackageName.get());
137 _SettingApplicationProvider::SetValueForPrivilegedKey(const String& key, String value)
139 result r = E_OBJ_NOT_FOUND;
143 if(key == _APPLICATION_HOME)
145 bool installed = _Aul::IsInstalled(value);
146 SysTryReturnResult(NID_SYS, installed == true, E_INVALID_ARG, "Specified application[%ls] is not installed.", value.GetPointer());
147 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support home application.");
150 unique_ptr<char []> pPackageName(_StringConverter::CopyToCharArrayN(value));
151 SysTryReturnResult(NID_SYS, pPackageName.get() != null, E_SYSTEM, "It is failed to get string of specified value[%ls].", value.GetPointer());
152 SysLog(NID_SYS, "Value for Key[%ls] is %s.", key.GetPointer(), pPackageName.get());
153 errorCode = vconf_set_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, pPackageName.get());
154 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set home application.");
156 else if(key == _APPLICATION_LOCK)
158 bool installed = _Aul::IsInstalled(value);
159 SysTryReturnResult(NID_SYS, installed == true, E_INVALID_ARG, "Specified application[%ls] is not installed.", value.GetPointer());
160 SysTryReturnResult(NID_SYS, HasKey(key) == true, E_UNSUPPORTED_OPERATION, "Current device does not support lock application.");
163 unique_ptr<char []> pPackageName(_StringConverter::CopyToCharArrayN(value));
164 SysTryReturnResult(NID_SYS, pPackageName.get() != null, E_SYSTEM, "It is failed to get string of specified value[%ls].", value.GetPointer());
165 SysLog(NID_SYS, "Value for Key[%ls] is %s.", key.GetPointer(), pPackageName.get());
166 errorCode = vconf_set_str(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, pPackageName.get());
167 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to set lock application.");
173 _SettingApplicationProvider::SettingEventVConf(keynode_t* node, void* userData)
177 _SettingInfo* pSettingInfo = _SettingInfo::GetInstance();
178 SysTryReturnVoidResult(NID_SYS, pSettingInfo != null, E_SYSTEM, "_SettingInfo is not ready.");
180 if(strcmp(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME, vconf_keynode_get_name(node)) == 0)
182 settingKey.Append(_APPLICATION_HOME);
184 else if(strcmp(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR, vconf_keynode_get_name(node)) == 0)
186 settingKey.Append(_APPLICATION_LOCK);
190 SysLogException(NID_SYS, E_SYSTEM, "There is no reserved key [%s].", vconf_keynode_get_name(node));
194 result r = pSettingInfo->AnnounceSettingEvent(settingKey);
195 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send the event[%ls].", settingKey.GetPointer());