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.
19 #include <dbus/dbus.h>
20 #include <dbus/dbus-glib.h>
21 #include <dbus/dbus-glib-lowlevel.h>
24 #include <notification.h>
26 #include "mobileap_agent.h"
28 //#define __ENABLE_UG_LAUNCH
29 #define MH_NOTI_APP_NAME "setting-mobileap-efl"
30 #define MH_AGENT_PKG_NAME "mobileap-agent"
32 static int connected_noti_id = 0;
33 static int timeout_noti_id = 0;
35 int _create_timeout_noti(const char *content, const char *title,
36 const char *icon_path)
39 notification_h noti = NULL;
40 notification_error_e ret = NOTIFICATION_ERROR_NONE;
42 if (timeout_noti_id) {
43 noti = notification_load(APPNAME, timeout_noti_id);
45 DBG("Notification can be deleted already\n");
47 ret = notification_delete(noti);
48 if (ret != NOTIFICATION_ERROR_NONE) {
49 ERR("Fail to notification_delete [%d]\n", ret);
51 ret = notification_free(noti);
52 if (ret != NOTIFICATION_ERROR_NONE)
53 ERR("Fail to notification_free [%d]\n", ret);
54 return MOBILE_AP_ERROR_INTERNAL;
57 ret = notification_free(noti);
58 if (ret != NOTIFICATION_ERROR_NONE) {
59 ERR("Fail to notification_free [%d]\n", ret);
60 return MOBILE_AP_ERROR_INTERNAL;
66 noti = notification_create(NOTIFICATION_TYPE_NOTI);
68 ERR("Fail to notification_create\n");
69 return MOBILE_AP_ERROR_INTERNAL;
72 ret = notification_set_property(noti,
73 #ifdef __ENABLE_UG_LAUNCH
74 NOTIFICATION_PROP_VOLATILE_DISPLAY);
76 NOTIFICATION_PROP_VOLATILE_DISPLAY |
77 NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
79 if (ret != NOTIFICATION_ERROR_NONE) {
80 ERR("Fail to notification_set_property [%d]\n", ret);
84 ret = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
85 if (ret != NOTIFICATION_ERROR_NONE) {
86 ERR("Fail to notification_set_image [%d]\n", ret);
90 ret = notification_set_image(noti,
91 NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
92 if (ret != NOTIFICATION_ERROR_NONE) {
93 ERR("Fail to notification_set_image [%d]\n", ret);
97 ret = notification_set_text(noti,
98 NOTIFICATION_TEXT_TYPE_TITLE,
100 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
101 if (ret != NOTIFICATION_ERROR_NONE) {
102 ERR("Fail to notification_set_text [%d]\n", ret);
106 ret = notification_set_text(noti,
107 NOTIFICATION_TEXT_TYPE_CONTENT,
109 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
110 if (ret != NOTIFICATION_ERROR_NONE) {
111 ERR("Fail to notification_set_text [%d]\n", ret);
115 ret = notification_set_pkgname(noti, APPNAME);
116 if (ret != NOTIFICATION_ERROR_NONE) {
117 ERR("Fail to notification_set_pkgname [%d]\n", ret);
120 #ifdef __ENABLE_UG_LAUNCH
121 ret = notification_set_application(noti, MH_NOTI_APP_NAME);
122 if (ret != NOTIFICATION_ERROR_NONE) {
123 ERR("Fail to notification_set_application [%d]\n", ret);
127 ret = notification_insert(noti, &timeout_noti_id);
128 if (ret != NOTIFICATION_ERROR_NONE) {
129 ERR("Fail to notification_insert [%d]\n", ret);
133 ret = notification_free(noti);
134 if (ret != NOTIFICATION_ERROR_NONE) {
135 ERR("Fail to notification_free [%d]\n", ret);
140 return MOBILE_AP_ERROR_NONE;
143 ret = notification_free(noti);
144 if (ret != NOTIFICATION_ERROR_NONE)
145 ERR("Fail to notification_free [%d]\n", ret);
147 return MOBILE_AP_ERROR_INTERNAL;
150 int _delete_timeout_noti(void)
152 notification_error_e ret = NOTIFICATION_ERROR_NONE;
153 notification_list_h noti_list = NULL;
154 notification_h noti = NULL;
156 ret = notification_get_detail_list(MH_AGENT_PKG_NAME,
157 NOTIFICATION_GROUP_ID_NONE,
158 NOTIFICATION_PRIV_ID_NONE,
161 if (ret != NOTIFICATION_ERROR_NONE) {
162 ERR("Fail to notification_get_detail_list\n");
163 return MOBILE_AP_ERROR_INTERNAL;
167 noti = notification_list_get_data(noti_list);
169 notification_delete(noti);
171 notification_free_list(noti_list);
174 return MOBILE_AP_ERROR_NONE;
177 int _create_connected_noti(const char *content, const char *title,
178 const char *icon_path)
181 notification_h noti = NULL;
182 notification_error_e ret = NOTIFICATION_ERROR_NONE;
184 noti = notification_create(NOTIFICATION_TYPE_ONGOING);
186 ERR("Fail to notification_create\n");
187 return MOBILE_AP_ERROR_INTERNAL;
190 ret = notification_set_property(noti,
191 NOTIFICATION_PROP_DISABLE_AUTO_DELETE |
192 #ifdef __ENABLE_UG_LAUNCH
193 NOTIFICATION_PROP_VOLATILE_DISPLAY);
195 NOTIFICATION_PROP_VOLATILE_DISPLAY |
196 NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
198 if (ret != NOTIFICATION_ERROR_NONE) {
199 ERR("Fail to notification_set_property [%d]\n", ret);
203 ret = notification_set_layout(noti, NOTIFICATION_LY_ONGOING_EVENT);
204 if (ret != NOTIFICATION_ERROR_NONE) {
205 ERR("Fail to notification_set_image [%d]\n", ret);
209 ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
210 if (ret != NOTIFICATION_ERROR_NONE) {
211 ERR("Fail to notification_set_image [%d]\n", ret);
215 ret = notification_set_text(noti,
216 NOTIFICATION_TEXT_TYPE_TITLE,
218 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
219 if (ret != NOTIFICATION_ERROR_NONE) {
220 ERR("Fail to notification_set_text [%d]\n", ret);
224 ret = notification_set_text(noti,
225 NOTIFICATION_TEXT_TYPE_CONTENT,
227 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
228 if (ret != NOTIFICATION_ERROR_NONE) {
229 ERR("Fail to notification_set_text [%d]\n", ret);
233 ret = notification_set_pkgname(noti, APPNAME);
234 if (ret != NOTIFICATION_ERROR_NONE) {
235 ERR("Fail to notification_set_pkgname [%d]\n", ret);
238 #ifdef __ENABLE_UG_LAUNCH
239 ret = notification_set_application(noti, MH_NOTI_APP_NAME);
240 if (ret != NOTIFICATION_ERROR_NONE) {
241 ERR("Fail to notification_set_application [%d]\n", ret);
245 ret = notification_insert(noti, &connected_noti_id);
246 if (ret != NOTIFICATION_ERROR_NONE) {
247 ERR("Fail to notification_insert [%d]\n", ret);
251 ret = notification_free(noti);
252 if (ret != NOTIFICATION_ERROR_NONE) {
253 ERR("Fail to notification_free [%d]\n", ret);
258 return MOBILE_AP_ERROR_NONE;
261 ret = notification_free(noti);
262 if (ret != NOTIFICATION_ERROR_NONE)
263 ERR("Fail to notification_free [%d]\n", ret);
264 return MOBILE_AP_ERROR_INTERNAL;
267 int _update_connected_noti(const char *content)
271 if (content == NULL) {
272 ERR("Invalid param\n");
273 return MOBILE_AP_ERROR_INVALID_PARAM;
276 notification_h noti = NULL;
277 notification_error_e ret = NOTIFICATION_ERROR_NONE;
279 noti = notification_load(APPNAME, connected_noti_id);
281 ERR("notification_load is failed\n");
282 return MOBILE_AP_ERROR_INTERNAL;
285 ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
286 content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
287 if (ret != NOTIFICATION_ERROR_NONE) {
288 ERR("Fail to notification_set_text [%d]\n", ret);
290 ret = notification_free(noti);
291 if (ret != NOTIFICATION_ERROR_NONE)
292 ERR("Fail to notification_free [%d]\n", ret);
293 return MOBILE_AP_ERROR_INTERNAL;
296 ret = notification_update(noti);
297 if (ret != NOTIFICATION_ERROR_NONE) {
298 ERR("Fail to notification_update [%d]\n", ret);
300 ret = notification_free(noti);
301 if (ret != NOTIFICATION_ERROR_NONE)
302 ERR("Fail to notification_free [%d]\n", ret);
303 return MOBILE_AP_ERROR_INTERNAL;
306 ret = notification_free(noti);
307 if (ret != NOTIFICATION_ERROR_NONE) {
308 ERR("Fail to notification_free [%d]\n", ret);
309 return MOBILE_AP_ERROR_INTERNAL;
313 return MOBILE_AP_ERROR_NONE;
316 int _delete_connected_noti(void)
319 notification_h noti = NULL;
320 notification_error_e ret;
322 noti = notification_load(APPNAME, connected_noti_id);
324 ERR("notification_load is failed\n");
325 connected_noti_id = 0;
326 return MOBILE_AP_ERROR_INTERNAL;
328 connected_noti_id = 0;
330 ret = notification_delete(noti);
331 if (ret != NOTIFICATION_ERROR_NONE) {
332 ERR("Fail to notification_delete [%d]\n", ret);
334 ret = notification_free(noti);
335 if (ret != NOTIFICATION_ERROR_NONE)
336 ERR("Fail to notification_free [%d]\n", ret);
337 return MOBILE_AP_ERROR_INTERNAL;
340 ret = notification_free(noti);
341 if (ret != NOTIFICATION_ERROR_NONE) {
342 ERR("Fail to notification_free [%d]\n", ret);
343 return MOBILE_AP_ERROR_INTERNAL;
347 return MOBILE_AP_ERROR_NONE;
350 int _create_status_noti(const char *content)
353 return MOBILE_AP_ERROR_INVALID_PARAM;
355 notification_error_e ret;
357 ret = notification_status_message_post(content);
358 if (ret != NOTIFICATION_ERROR_NONE) {
359 ERR("notification_status_message_post() is failed : %d\n", ret);
360 return MOBILE_AP_ERROR_INTERNAL;
363 return MOBILE_AP_ERROR_NONE;