2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include <Commons/Exception.h>
19 #include <CommonsJavaScript/Converter.h>
20 #include <CommonsJavaScript/PrivateObject.h>
21 #include "SystemSetting.h"
23 #include <arpa/inet.h>
25 #include <system_settings.h>
27 using namespace WrtDeviceApis::CommonsJavaScript;
28 using namespace WrtDeviceApis::Commons;
31 namespace SystemSetting {
34 static const std::string ERR_SYSTEM_SETTINGS_INVALID_PARAMETER = "Invalid parameter";
35 static const std::string ERR_SYSTEM_SETTINGS_OUT_OF_MEMORY = "Out of memory";
36 static const std::string ERR_SYSTEM_SETTINGS_IO_ERROR = "Internal I/O error";
37 static const std::string ERR_SYSTEM_SETTINGS_PERMISSION_DENIED = "Permission denied";
38 static const std::string ERR_SYSTEM_SETTINGS_UNKNOWN = "Unknown error";
41 const std::string& getSystemSettingsErrorMessage(int errorCode)
44 case SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER:
45 return ERR_SYSTEM_SETTINGS_INVALID_PARAMETER;
46 case SYSTEM_SETTINGS_ERROR_OUT_OF_MEMORY:
47 return ERR_SYSTEM_SETTINGS_OUT_OF_MEMORY;
48 case SYSTEM_SETTINGS_ERROR_IO_ERROR:
49 return ERR_SYSTEM_SETTINGS_IO_ERROR;
50 case SYSTEM_SETTINGS_ERROR_PERMISSION_DENIED:
51 return ERR_SYSTEM_SETTINGS_PERMISSION_DENIED;
53 return ERR_SYSTEM_SETTINGS_UNKNOWN;
57 std::string SystemSetting::getSystemSettingsLogMessage(const int errorCode, const std::string &hint)
60 ss << "Failed " << hint << " : " << getSystemSettingsErrorMessage(errorCode) << ", " << errorCode;
64 SystemSetting::SystemSetting()
68 SystemSetting::~SystemSetting()
72 void SystemSetting::setWallpaper(const EventSetWallpaperPtr &event)
75 EventRequestReceiver<EventSetWallpaper>::PostRequest(event);
78 void SystemSetting::setRingtone(const EventSetRingtonePtr &event)
81 EventRequestReceiver<EventSetRingtone>::PostRequest(event);
84 void SystemSetting::setProperty(const EventSetSettingPtr &event)
87 EventRequestReceiver<EventSetSetting>::PostRequest(event);
90 void SystemSetting::getProperty(const EventGetSettingPtr &event)
93 EventRequestReceiver<EventGetSetting>::PostRequest(event);
96 std::string SystemSetting::getProperty(const SettingType settingType)
99 int ret = SYSTEM_SETTINGS_ERROR_NONE;
102 std::string gettingValue;
104 if (settingType == HOME_SCREEN)
107 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &value);
108 LOGD("result : %d value: %s", ret, value);
110 else if (settingType == LOCK_SCREEN)
113 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, &value);
114 LOGD("result : %d value: %s", ret, value);
115 }else if (settingType == INCOMMING_CALL)
118 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &value);
119 LOGD("result : %d value: %s", ret, value);
121 else if (settingType == NOTIFICATION_EMAIL)
124 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, &value);
125 LOGD("result : %d value: %s", ret, value);
128 if (ret == SYSTEM_SETTINGS_ERROR_NONE)
131 gettingValue = value;
136 LOGE("err : %d", ret);
137 throwSystemSettingsException(ret, "system_settings_get_value_string()");
141 void SystemSetting::OnRequestReceived(const EventSetWallpaperPtr &event)
144 int ret = SYSTEM_SETTINGS_ERROR_NONE;
146 std::string wallpaperUri = event->getWallpaperURI();
147 std::string wallpaperType = event->getWallpaperType();
149 if (strcmp(wallpaperType.c_str(), "HOME_SCREEN") == 0)
151 LOGD("home screen : %s", wallpaperUri.c_str());
152 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, wallpaperUri.c_str());
154 else if (strcmp(wallpaperType.c_str(), "LOCK_SCREEN") == 0)
156 LOGD("lock screen : %s", wallpaperUri.c_str());
157 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, wallpaperUri.c_str());
160 if (ret == SYSTEM_SETTINGS_ERROR_NONE)
163 event->setExceptionCode(ExceptionCodes::None);
167 LOGW("%s", getSystemSettingsLogMessage(ret, "system_settings_set_value_string()").c_str());
168 event->setExceptionCode(ExceptionCodes::PlatformException);
173 void SystemSetting::OnRequestReceived(const EventSetRingtonePtr &event)
176 int ret = SYSTEM_SETTINGS_ERROR_NONE;
178 std::string ringtoneUri = event->getRingtoneURI();
179 std::string ringtoneType = event->getRingtoneType();
181 if (strcmp(ringtoneType.c_str(), "INCOMING_CALL") == 0)
183 LOGD("call : %s", ringtoneUri.c_str());
184 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, ringtoneUri.c_str());
186 else if (strcmp(ringtoneType.c_str(), "NOTIFICATION_EMAIL") == 0)
188 // TODO need manage-api
189 LOGD("email : %s", ringtoneUri.c_str());
190 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, ringtoneUri.c_str());
193 if (ret == SYSTEM_SETTINGS_ERROR_NONE)
196 event->setExceptionCode(ExceptionCodes::None);
200 LOGW("%s", getSystemSettingsLogMessage(ret, "system_settings_set_value_string()").c_str());
201 event->setExceptionCode(ExceptionCodes::PlatformException);
206 void SystemSetting::OnRequestReceived(const EventSetSettingPtr &event)
209 int ret = SYSTEM_SETTINGS_ERROR_NONE;
211 std::string settingValue = event->getSettingValue();
212 SettingType settingType = event->getSettingType();
214 if (settingType == HOME_SCREEN)
216 LOGD("home screen : %s", settingValue.c_str());
217 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, settingValue.c_str());
218 LOGD("result : %d", ret);
220 else if (settingType == LOCK_SCREEN)
222 LOGD("lock screen : %s", settingValue.c_str());
223 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, settingValue.c_str());
224 LOGD("result : %d", ret);
225 }else if (settingType == INCOMMING_CALL)
227 LOGD("call : %s", settingValue.c_str());
228 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, settingValue.c_str());
229 LOGD("result : %d", ret);
231 else if (settingType == NOTIFICATION_EMAIL)
233 LOGD("email : %s", settingValue.c_str());
234 ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, settingValue.c_str());
235 LOGD("result : %d", ret);
238 if (ret == SYSTEM_SETTINGS_ERROR_NONE)
241 event->setExceptionCode(ExceptionCodes::None);
245 LOGW("%s", getSystemSettingsLogMessage(ret, "system_settings_set_value_string()").c_str());
246 event->setExceptionCode(ExceptionCodes::PlatformException);
251 void SystemSetting::OnRequestReceived(const EventGetSettingPtr &event)
254 int ret = SYSTEM_SETTINGS_ERROR_NONE;
256 std::string settingValue;
257 SettingType settingType = event->getSettingType();
260 if (settingType == HOME_SCREEN)
263 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &value);
264 LOGD("result : %d", ret);
266 else if (settingType == LOCK_SCREEN)
269 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, &value);
270 LOGD("result : %d", ret);
271 }else if (settingType == INCOMMING_CALL)
274 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &value);
275 LOGD("result : %d", ret);
277 else if (settingType == NOTIFICATION_EMAIL)
280 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, &value);
281 LOGD("result : %d", ret);
284 if (ret == SYSTEM_SETTINGS_ERROR_NONE)
287 event->setExceptionCode(ExceptionCodes::None);
288 settingValue = value;
289 event->setSettingValue(settingValue);
293 LOGW("%s", getSystemSettingsLogMessage(ret, "system_settings_get_value_string()").c_str());
294 event->setExceptionCode(ExceptionCodes::PlatformException);