2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
19 * @file FApp_NotificationManagerService.cpp
20 * @brief This is the implementation for the _NotificationManagerService class.
23 #include <unique_ptr.h>
25 #include <FShellNotificationManager.h>
26 #include <FShellNotificationRequest.h>
28 #include <FBaseSysLog.h>
29 #include <FBaseInternalTypes.h>
30 #include <FBase_StringConverter.h>
31 #include <FApp_AppArg.h>
32 #include "FApp_AppInfo.h"
34 #include "FApp_NotificationManagerService.h"
35 #include "FAppPkg_PackageManagerImpl.h"
37 using namespace Tizen::App;
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Collection;
40 using namespace Tizen::Io;
41 using namespace Tizen::Shell;
43 extern "C" int service_create_request(bundle *data, service_h *service);
44 extern "C" int service_to_bundle(service_h service, bundle** data);
50 ConvertNotificationResult(int error)
54 case NOTIFICATION_ERROR_NONE:
56 case NOTIFICATION_ERROR_INVALID_DATA:
58 case NOTIFICATION_ERROR_NO_MEMORY:
59 return E_OUT_OF_MEMORY;
60 case NOTIFICATION_ERROR_FROM_DB:
62 case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
64 case NOTIFICATION_ERROR_NOT_EXIST_ID:
74 static int length = (_AppInfo::GetApiVersion() < _API_VERSION_2_1) ? 127 : MAX_NOTIFICATION_MESSAGE_LENGTH;
81 namespace Tizen { namespace App {
83 _NotificationManagerService::_NotificationManagerService()
88 _NotificationManagerService::~_NotificationManagerService()
93 _NotificationManagerService::Construct(void)
99 _NotificationManagerService::NotifyMessage(const AppId& appId,const NotificationRequest& notiMessage, bool isOngoing)
101 result r = E_SUCCESS;
104 notification_h core = NULL;
105 char* pTitleText = NULL;
106 char* pIconPath = NULL;
107 char* pSoundPath = NULL;
109 bundle* service_data = NULL;
110 service_h svc = NULL;
114 const String& messageText = notiMessage.GetAlertText();
115 const String& launchArguments = notiMessage.GetAppMessage();
116 const String& titleText = notiMessage.GetTitleText();
117 const String& iconPath = notiMessage.GetIconFilePath();
118 const String& soundPath = notiMessage.GetSoundFilePath();
120 bool isAppInstalled = _Aul::IsInstalled(appId);
121 SysTryReturnResult(NID_APP, isAppInstalled == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
123 std::unique_ptr<char[]> buffer(_StringConverter::CopyToCharArrayN(appId));
125 if (isOngoing || !messageText.IsEmpty())
127 SysTryReturnResult(NID_APP,
128 messageText.GetLength() <= GetMessageLength(), E_INVALID_ARG,
129 "MessageText is greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
133 core = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
134 SysTryReturnResult(NID_APP, core!= NULL , E_SYSTEM, "Notification creation failed ");
138 core = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
139 SysTryReturnResult(NID_APP, core!= NULL , E_SYSTEM, "Notification creation failed ");
142 pMsg = _StringConverter::CopyToCharArrayN(messageText);
143 notification_set_text(core, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
146 if (!titleText.IsEmpty())
148 pTitleText = _StringConverter::CopyToCharArrayN(titleText);
149 r = ConvertNotificationResult(notification_set_text(core, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
150 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
154 app_manager_get_app_name(buffer.get(), &pTitleText);
155 r = ConvertNotificationResult(notification_set_text(core, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE));
156 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set Title Text failed.", GetErrorMessage(r));
158 if (!iconPath.IsEmpty())
160 pIconPath = _StringConverter::CopyToCharArrayN(iconPath);
161 r = ConvertNotificationResult(notification_set_image(core, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath));
162 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set icon path failed.", GetErrorMessage(r));
166 app_manager_get_app_icon_path(buffer.get(), &pIconPath);
167 r = ConvertNotificationResult(notification_set_image(core, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath));
168 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set icon path failed.", GetErrorMessage(r));
170 if (!soundPath.IsEmpty())
172 pSoundPath = _StringConverter::CopyToCharArrayN(soundPath);
173 r = ConvertNotificationResult(notification_set_sound(core, NOTIFICATION_SOUND_TYPE_USER_DATA, pSoundPath));
174 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification Set sound failed.", GetErrorMessage(r));
177 r = arg.Construct(launchArguments);
178 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
180 kb = arg.GetBundle();
181 service_create_request(kb, &svc);
182 service_set_app_id(svc, buffer.get());
184 if (service_to_bundle(svc, &service_data) == SERVICE_ERROR_NONE)
186 notification_set_property(core, 0);
187 notification_set_execute_option(core, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
188 SysLog(NID_APP, "Sending notification[%ls] for package %s.", messageText.GetPointer(), buffer.get());
193 OngoingActivityType activityType = notiMessage.GetOngoingActivityType();
194 progress = notiMessage.GetOngoingActivityProgress();
196 switch (activityType)
198 case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
199 r = ConvertNotificationResult(notification_insert(core,NULL));
200 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
202 r = ConvertNotificationResult(notification_update_progress(core, NOTIFICATION_PRIV_ID_NONE, progress/100.));
203 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
205 case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
206 notification_insert(core,NULL);
207 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
209 r = ConvertNotificationResult(notification_update_size(core,NOTIFICATION_PRIV_ID_NONE, progress));
210 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
212 case ONGOING_ACTIVITY_TYPE_TEXT:
213 r = ConvertNotificationResult(notification_insert(core,NULL));
214 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
217 r = E_OPERATION_FAILED;
218 //ui_notification_set_content() is done already
224 r = ConvertNotificationResult(notification_insert(core,NULL));
225 SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
231 SysTryReturnResult(NID_APP, 0, E_INVALID_ARG, "MessageText is Empty");
234 if (notiMessage.GetBadgeNumber() >= 0)
236 notification_set_badge(NULL, NOTIFICATION_GROUP_ID_NONE, notiMessage.GetBadgeNumber());
247 notification_free(core);
249 service_destroy(svc);
254 _NotificationManagerService::RemoveNotification(const AppId& appId, bool isOngoing)
257 bool b = _Aul::IsInstalled(appId);
258 SysTryReturnResult(NID_APP, b == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
260 std::unique_ptr<char[]> pAppid(_StringConverter::CopyToCharArrayN(appId));
264 retCode = notification_delete_all_by_type(pAppid.get(), NOTIFICATION_TYPE_ONGOING);
268 retCode = notification_delete_all_by_type(pAppid.get(), NOTIFICATION_TYPE_NOTI);
271 result r = E_SUCCESS;
275 case NOTIFICATION_ERROR_NONE:
279 case NOTIFICATION_ERROR_INVALID_DATA:
288 SysLog(NID_APP, "[%s] Finished.", GetErrorMessage(r));
291 }} //namespace Tizen { namespace App {