Use the same type to compare values
[platform/framework/web/download-provider.git] / provider / download-provider-notification.c
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifdef SUPPORT_NOTIFICATION
18 #include <time.h>
19 #include <sys/time.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22
23 #include "download-provider.h"
24 #include "download-provider-notification.h"
25 #include "download-provider-db-defs.h"
26 #include "download-provider-db.h"
27 #include "download-provider-log.h"
28 #include "download-provider-client.h"
29 #include "download-provider-utils.h"
30
31 #include <bundle.h>
32 #include <bundle_internal.h>
33 #include <notification.h>
34
35 #include "notification_text_domain.h"
36 #include "notification_internal.h"
37 #include "notification_error.h"
38
39 #include <appsvc.h>
40
41 #include <vconf.h>
42 #include <locale.h>
43 #include <libintl.h>
44
45 #include <tzplatform_config.h>
46
47 #define __(s) dgettext(PKG_NAME, s)
48
49 #define DP_DOMAIN PKG_NAME
50 #define DP_LOCALEDIR LOCALE_DIR
51 #define DP_NOTIFICATION_NO_SUBJECT "Preparing to download..."
52
53 #define DP_NOTIFICATION_DRM_ICON_PATH IMAGE_DIR"/download_manager_icon_drm.png"
54 #define DP_NOTIFICATION_UNKNOWN_ICON_PATH IMAGE_DIR"/download_manager_icon_unknown.png"
55 #define DP_NOTIFICATION_EXCEL_ICON_PATH IMAGE_DIR"/download_manager_icon_xls.png"
56 #define DP_NOTIFICATION_HTML_ICON_PATH IMAGE_DIR"/download_manager_icon_html.png"
57 #define DP_NOTIFICATION_MUSIC_ICON_PATH IMAGE_DIR"/download_manager_icon_music.png"
58 #define DP_NOTIFICATION_PDF_ICON_PATH IMAGE_DIR"/download_manager_icon_pdf.png"
59 #define DP_NOTIFICATION_PPT_ICON_PATH IMAGE_DIR"/download_manager_icon_ppt.png"
60 #define DP_NOTIFICATION_TEXT_ICON_PATH IMAGE_DIR"/download_manager_icon_text.png"
61 #define DP_NOTIFICATION_WORD_ICON_PATH IMAGE_DIR"/download_manager_icon_word.png"
62 #define DP_NOTIFICATION_VIDEO_ICON_PATH IMAGE_DIR"/download_manager_icon_movie.png"
63 #define DP_NOTIFICATION_IMAGE_ICON_PATH IMAGE_DIR"/download_manager_icon_img.png"
64 #define DP_NOTIFICATION_FALSH_ICON_PATH IMAGE_DIR"/download_manager_icon_swf.png"
65 #define DP_NOTIFICATION_TPK_ICON_PATH IMAGE_DIR"/download_manager_icon_tpk.png"
66 #define DP_NOTIFICATION_VCAL_ICON_PATH IMAGE_DIR"/download_manager_icon_date.png"
67
68 // base path
69 #define QP_PRELOAD_NOTI_ICON_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "com.samsung.quickpanel/shared/res/noti_icons")
70
71 // each application path
72 #define QP_PRELOAD_COMMON_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "com.samsung.quickpanel/shared/res/noti_icons/Common")
73 #define DP_NOTIFICATION_COMPLETED_ICON_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "com.samsung.quickpanel/shared/res/noti_icons/Common/noti_download_complete.png")
74 #define DP_NOTIFICATION_FAILED_ICON_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "com.samsung.quickpanel/shared/res/noti_icons/Common/noti_download_failed.png")
75
76 #define DP_NOTIFICATION_ONGOING_ICON_PATH "reserved://quickpanel/ani/downloading"
77 #define DP_NOTIFICATION_DOWNLOADING_ICON_PATH "reserved://indicator/ani/downloading"
78 #define DP_NOTIFICATION_FAILED_INDICATOR_ICON_PATH IMAGE_DIR"/B03_Processing_download_failed.png"
79 #define DP_NOTIFICATION_COMPLETED_INDICATOR_ICON_PATH IMAGE_DIR"/B03_Processing_download_complete.png"
80
81 #define DP_MAX_ICONS_TABLE_COUNT 15
82
83 static char *file_icons_table[DP_MAX_ICONS_TABLE_COUNT] = {
84         //unknown file type
85         DP_NOTIFICATION_UNKNOWN_ICON_PATH,
86         //image
87         DP_NOTIFICATION_IMAGE_ICON_PATH,
88         //video
89         DP_NOTIFICATION_VIDEO_ICON_PATH,
90         // audio /music
91         DP_NOTIFICATION_MUSIC_ICON_PATH,
92         // PDF
93         DP_NOTIFICATION_PDF_ICON_PATH,
94         // word
95         DP_NOTIFICATION_WORD_ICON_PATH,
96         // ppt
97         DP_NOTIFICATION_PPT_ICON_PATH,
98         // excel
99         DP_NOTIFICATION_EXCEL_ICON_PATH,
100         // html
101         DP_NOTIFICATION_HTML_ICON_PATH,
102         // txt
103         DP_NOTIFICATION_TEXT_ICON_PATH,
104         // DRM
105         DP_NOTIFICATION_DRM_ICON_PATH,
106         DP_NOTIFICATION_DRM_ICON_PATH,
107         DP_NOTIFICATION_FALSH_ICON_PATH,
108         DP_NOTIFICATION_TPK_ICON_PATH,
109         DP_NOTIFICATION_VCAL_ICON_PATH,
110 };
111
112 static const char *__dp_noti_error_str(int err)
113 {
114         switch (err) {
115         case NOTIFICATION_ERROR_INVALID_PARAMETER:
116                 return "NOTIFICATION_ERROR_INVALID_PARAMETER";
117         case NOTIFICATION_ERROR_OUT_OF_MEMORY:
118                 return "NOTIFICATION_ERROR_OUT_OF_MEMORY";
119         case NOTIFICATION_ERROR_FROM_DB:
120                 return "NOTIFICATION_ERROR_FROM_DB";
121         case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
122                 return "NOTIFICATION_ERROR_ALREADY_EXIST_ID";
123         case NOTIFICATION_ERROR_FROM_DBUS:
124                 return "NOTIFICATION_ERROR_FROM_DBUS";
125         case NOTIFICATION_ERROR_NOT_EXIST_ID:
126                 return "NOTIFICATION_ERROR_NOT_EXIST_ID";
127         default:
128                 break;
129         }
130         return "Unknown error";
131 }
132
133 char *__dp_noti_get_sender(char *url)
134 {
135         char *temp = NULL;
136         char *found = NULL;
137         char *found1 = NULL;
138         char *sender = NULL;
139         char *credential_sender = NULL;
140
141         if (url == NULL)
142                 return NULL;
143
144         found = strstr(url, "://");
145         if (found != NULL)
146                 temp = found + 3;
147         else
148                 temp = url;
149
150         found = strchr(temp, '/');
151         if (found != NULL) {
152                 int len = 0;
153                 len = found - temp;
154                 sender = calloc(len + 1, sizeof(char));
155                 if (sender == NULL)
156                         return NULL;
157                 snprintf(sender, len + 1, "%s", temp);
158         } else {
159                 sender = dp_strdup(temp);
160                 if (sender == NULL)
161                         return NULL;
162         }
163
164         // For credential URL
165         found = strchr(sender, '@');
166         found1 = strchr(sender, ':');
167         if (found != NULL && found1 != NULL && found1 < found) {
168                 int len = 0;
169                 found = found + 1;
170                 len = strlen(found);
171                 credential_sender = calloc(len + 1, sizeof(char));
172                 if (credential_sender == NULL) {
173                         free(sender);
174                         return NULL;
175                 }
176                 snprintf(credential_sender, len + 1, "%s", found);
177                 free(sender);
178                 return credential_sender;
179         } else {
180                 return sender;
181         }
182 }
183
184 static char *__dp_noti_status(dp_state_type state)
185 {
186         char *message = NULL;
187         switch (state) {
188         case DP_STATE_COMPLETED:
189                 message = "IDS_DM_HEADER_DOWNLOAD_COMPLETE";
190                 break;
191         case DP_STATE_CANCELED:
192         case DP_STATE_FAILED:
193                 message = "IDS_DM_BODY_DOWNLOAD_FAILED_M_STATUS_ABB";
194                 break;
195         default:
196                 break;
197         }
198         return message;
199 }
200
201 void __lang_changed_cb(keynode_t *key, void* data)
202 {
203         char *str = NULL;
204         str = vconf_get_str(VCONFKEY_LANGSET);
205         if (str != NULL) {
206                 setlocale(LC_ALL, str);
207                 bindtextdomain(PKG_NAME, LOCALE_DIR);
208                 textdomain(PKG_NAME);
209         }
210         free(str);
211 }
212
213 void dp_notification_set_locale()
214 {
215         // move to notification.c
216         // locale
217         __lang_changed_cb(NULL, NULL);
218         if (vconf_notify_key_changed(VCONFKEY_LANGSET, __lang_changed_cb, NULL) != 0)
219                 TRACE_ERROR("Fail to set language changed vconf callback");
220 }
221
222 void dp_notification_clear_locale()
223 {
224         // move to notification.c
225         if (vconf_ignore_key_changed(VCONFKEY_LANGSET, __lang_changed_cb) != 0)
226                 TRACE_ERROR("Fail to unset language changed vconf callback");
227 }
228
229 void dp_notification_clear_ongoings()
230 {
231         int err = NOTIFICATION_ERROR_NONE;
232         err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_ONGOING);
233         if (err != NOTIFICATION_ERROR_NONE)
234                 TRACE_DEBUG("[FAIL] clear noti [%s]", __dp_noti_error_str(err));
235         return;
236 }
237
238 int dp_notification_ongoing_new(const char *url, const char *pkgname, const char *subject, unsigned char *raws_buffer, const int raws_length)
239 {
240         int err = NOTIFICATION_ERROR_NONE;
241         notification_h noti_handle = NULL;
242         noti_handle = notification_create(NOTIFICATION_TYPE_ONGOING);
243         if (noti_handle == NULL) {
244                 TRACE_ERROR("failed to create notification handle");
245                 return -1;
246         }
247
248         if (subject != NULL) {
249                 err = notification_set_text(noti_handle,
250                                 NOTIFICATION_TEXT_TYPE_TITLE, subject, NULL,
251                                 NOTIFICATION_VARIABLE_TYPE_NONE);
252         } else {
253                 err = notification_set_text(noti_handle,
254                                 NOTIFICATION_TEXT_TYPE_TITLE, DP_NOTIFICATION_NO_SUBJECT, NULL,
255                                 NOTIFICATION_VARIABLE_TYPE_NONE);
256         }
257         if (err != NOTIFICATION_ERROR_NONE)
258                 TRACE_ERROR("failed to set subject error:%s", __dp_noti_error_str(err));
259
260         if (url != NULL) {
261                 err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, url, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
262                 if (err != NOTIFICATION_ERROR_NONE)
263                         TRACE_ERROR("failed to set url error:%s", __dp_noti_error_str(err));
264         }
265
266
267
268         err = notification_set_image(noti_handle,
269                         NOTIFICATION_IMAGE_TYPE_ICON,
270                         DP_NOTIFICATION_ONGOING_ICON_PATH);
271         if (err != NOTIFICATION_ERROR_NONE)
272                 TRACE_ERROR("failed to set icon error:%s", __dp_noti_error_str(err));
273
274         if (raws_buffer != NULL && raws_length > 0) {
275                 bundle *b = NULL;
276                 b = bundle_decode_raw((bundle_raw *)raws_buffer, raws_length);
277                 if (b != NULL) {
278                         err = notification_set_execute_option(noti_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
279                 } else {
280                         b = bundle_create();
281                         if (b != NULL && pkgname != NULL) {
282                                 if (appsvc_set_pkgname(b, pkgname) != APPSVC_RET_OK)
283                                         TRACE_ERROR("failed to set set pkgname");
284                                 else
285                                         err = notification_set_execute_option(noti_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
286                         } else {
287                                 TRACE_ERROR("failed to create bundle");
288                         }
289                 }
290                 if (err != NOTIFICATION_ERROR_NONE)
291                         TRACE_ERROR("failed to set service error:%s", __dp_noti_error_str(err));
292
293                 if (b != NULL)
294                         bundle_free(b);
295         }
296
297         err = notification_set_property(noti_handle,
298                         NOTIFICATION_PROP_DISABLE_TICKERNOTI);
299         if (err != NOTIFICATION_ERROR_NONE) {
300                 TRACE_ERROR("failed to set property error:%s", __dp_noti_error_str(err));
301                 notification_free(noti_handle);
302                 return -1;
303         }
304         err = notification_set_image(noti_handle,
305                         NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR,
306                         DP_NOTIFICATION_DOWNLOADING_ICON_PATH);
307         if (err != NOTIFICATION_ERROR_NONE) {
308                 TRACE_ERROR("failed to set icon indicator error:%s", __dp_noti_error_str(err));
309                 notification_free(noti_handle);
310                 return -1;
311         }
312         err = notification_set_display_applist(noti_handle,
313                         NOTIFICATION_DISPLAY_APP_ALL);
314         if (err != NOTIFICATION_ERROR_NONE) {
315                 TRACE_ERROR("failed to set display app all error:%s", __dp_noti_error_str(err));
316                 notification_free(noti_handle);
317                 return -1;
318         }
319
320         int priv_id = 0;
321         err = notification_insert(noti_handle, &priv_id);
322         if (err != NOTIFICATION_ERROR_NONE) {
323                 TRACE_ERROR("failed to set priv_id error:%s", __dp_noti_error_str(err));
324                 notification_free(noti_handle);
325                 return -1;
326         }
327
328         //TRACE_DEBUG("m_noti_id [%d]", priv_id);
329         notification_free(noti_handle);
330
331         return priv_id; // store on memory for reuse it
332 }
333
334
335
336 int dp_notification_ongoing_update(const int noti_priv_id, const double received_size, const double file_size, const char *subject)
337 {
338         if (noti_priv_id > 0) {
339                 int err = NOTIFICATION_ERROR_NONE;
340                 if (file_size > 0)
341                         err = notification_update_progress(NULL, noti_priv_id, (received_size / file_size));
342                 else
343                         err = notification_update_size(NULL, noti_priv_id, received_size);
344                 if (err != NOTIFICATION_ERROR_NONE) {
345                         TRACE_ERROR("failed to update error:%s", __dp_noti_error_str(err));
346                         // return 0 because progress is called frequently
347                 }
348                 if (subject != NULL) {
349                         notification_h noti_handle = NULL;
350                         noti_handle = notification_load(NULL, noti_priv_id);
351                         if (noti_handle != NULL) {
352                                 err = notification_set_text(noti_handle,
353                                                 NOTIFICATION_TEXT_TYPE_TITLE, subject, NULL,
354                                                 NOTIFICATION_VARIABLE_TYPE_NONE);
355                                 err = notification_update(noti_handle);
356                                 if (err != NOTIFICATION_ERROR_NONE)
357                                         TRACE_ERROR("failed to update by priv_id:%d", noti_priv_id);
358                                 notification_free(noti_handle);
359                         } else {
360                                 TRACE_ERROR("failed to load handle by priv_id:%d", noti_priv_id);
361                                 return -1;
362                         }
363                 }
364         }
365         return 0;
366 }
367
368
369 int dp_notification_delete_ongoing(const int noti_priv_id)
370 {
371         int err = NOTIFICATION_ERROR_NONE;
372         err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_ONGOING, noti_priv_id);
373         if (err != NOTIFICATION_ERROR_NONE)
374                 TRACE_ERROR("failed to delete notification by priv_id:%d error:%s", noti_priv_id, __dp_noti_error_str(err));
375
376         return 0;
377 }
378
379 int dp_notification_delete(const int noti_priv_id)
380 {
381         int err = NOTIFICATION_ERROR_NONE;
382         err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, noti_priv_id);
383         if (err != NOTIFICATION_ERROR_NONE)
384                 TRACE_ERROR("failed to delete notification by priv_id:%d error:%s", noti_priv_id, __dp_noti_error_str(err));
385
386         return 0;
387 }
388
389
390 int dp_notification_new(void *dbhandle, const int download_id, const int state, int content_type, const char *pkgname)
391 {
392         int errorcode = DP_ERROR_NONE;
393         int err = NOTIFICATION_ERROR_NONE;
394
395         if (state != DP_STATE_COMPLETED &&
396                         state != DP_STATE_CANCELED &&
397                         state != DP_STATE_FAILED) {
398                 TRACE_ERROR("deny by invalid state:%d id:%d", state, download_id);
399                 return -1;
400         }
401
402
403         notification_h noti_handle = NULL;
404         noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
405         if (noti_handle == NULL) {
406                 TRACE_ERROR("failed to create notification handle");
407                 return -1;
408         }
409
410         err = notification_set_layout(noti_handle, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
411         if (err != NOTIFICATION_ERROR_NONE) {
412                 TRACE_ERROR("Fail to set notification layout [%d]", err);
413                 notification_free(noti_handle);
414                 return -1;
415         }
416
417         err = notification_set_text_domain(noti_handle, DP_DOMAIN, DP_LOCALEDIR);
418         if (err != NOTIFICATION_ERROR_NONE) {
419                 TRACE_ERROR("Fail to set text domain [%d]", err);
420                 notification_free(noti_handle);
421                 return -1;
422         }
423
424         char *string = NULL;
425         unsigned length = 0;
426         if (dp_db_get_property_string(dbhandle, download_id, DP_TABLE_NOTIFICATION, DP_DB_COL_NOTI_DESCRIPTION, (unsigned char **)&string, &length, &errorcode) < 0)
427                 TRACE_ERROR("failed to get description id:%d error:%s", download_id, dp_print_errorcode(errorcode));
428
429         if (string != NULL) {
430                 err = notification_set_text(noti_handle,
431                                 NOTIFICATION_TEXT_TYPE_CONTENT, string, NULL,
432                                 NOTIFICATION_VARIABLE_TYPE_NONE);
433                 free(string);
434                 if (err != NOTIFICATION_ERROR_NONE)
435                         TRACE_ERROR("failed to set state id:%d error:%s", download_id, __dp_noti_error_str(err));
436         } else {
437                 string = __dp_noti_status(state);
438                 err = notification_set_text(noti_handle,
439                                 NOTIFICATION_TEXT_TYPE_CONTENT, __(string), string,
440                                 NOTIFICATION_VARIABLE_TYPE_NONE);
441                 if (err != NOTIFICATION_ERROR_NONE)
442                         TRACE_ERROR("failed to set state id:%d error:%s", download_id, __dp_noti_error_str(err));
443         }
444
445         string = NULL;
446         if (dp_db_get_property_string(dbhandle, download_id, DP_TABLE_NOTIFICATION, DP_DB_COL_NOTI_SUBJECT, (unsigned char **)&string, &length, &errorcode) < 0)
447                 TRACE_ERROR("failed to get subject id:%d error:%s", download_id, dp_print_errorcode(errorcode));
448         err = NOTIFICATION_ERROR_NONE;
449         if (string == NULL && dp_db_get_property_string(dbhandle, download_id, DP_TABLE_DOWNLOAD, DP_DB_COL_CONTENT_NAME, (unsigned char **)&string, &length, &errorcode) < 0)
450                 TRACE_ERROR("failed to get content_name id:%d error:%s", download_id, dp_print_errorcode(errorcode));
451         if (string == NULL)
452                 string = dp_strdup(DP_NOTIFICATION_NO_SUBJECT);
453         if (string != NULL) {
454                 err = notification_set_text(noti_handle,
455                                 NOTIFICATION_TEXT_TYPE_TITLE, string, NULL,
456                                 NOTIFICATION_VARIABLE_TYPE_NONE);
457                 free(string);
458                 string = NULL;
459                 if (err != NOTIFICATION_ERROR_NONE)
460                         TRACE_ERROR("failed to set state id:%d error:%s", download_id, __dp_noti_error_str(err));
461         }
462         err = notification_set_time(noti_handle, time(NULL));
463         if (err != NOTIFICATION_ERROR_NONE)
464                 TRACE_ERROR("failed to set time id:%d error:%s", download_id, __dp_noti_error_str(err));
465
466         bundle *b = NULL;
467         bundle_raw *raws_buffer = NULL;
468         if (state == DP_STATE_COMPLETED) {
469                 if (dp_db_get_property_string(dbhandle, download_id, DP_TABLE_NOTIFICATION, DP_DB_COL_NOTI_RAW_COMPLETE, &raws_buffer, &length, &errorcode) < 0)
470                         TRACE_ERROR("failed to get bundle raws id:%d", download_id);
471
472                 if (raws_buffer != NULL) {
473                         b = bundle_decode_raw(raws_buffer, length);
474                         bundle_free_encoded_rawdata(&raws_buffer);
475                 }
476                 if (b != NULL) {
477                         err = notification_set_execute_option(noti_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
478                 } else {
479                         b = bundle_create();
480                         if (dp_db_get_property_string(dbhandle, download_id, DP_TABLE_DOWNLOAD, DP_DB_COL_SAVED_PATH, (unsigned char **)&string, &length, &errorcode) < 0)
481                                 TRACE_ERROR("failed to get saved_path id:%d error:%s", download_id, dp_print_errorcode(errorcode));
482
483                         if (b != NULL && string != NULL) {
484                                 if (appsvc_set_operation(b, APPSVC_OPERATION_VIEW) != APPSVC_RET_OK) {
485                                         TRACE_ERROR("failed to set service operation id:%d", download_id);
486                                 } else {
487                                         if (appsvc_set_uri(b, string) != APPSVC_RET_OK) {
488                                                 TRACE_ERROR("failed to set service uri id:%d", download_id);
489                                         } else {
490                                                 err = notification_set_execute_option(noti_handle,
491                                                                 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
492                                         }
493                                 }
494                         } else {
495                                 TRACE_SECURE_ERROR("failed to create bundle id:%d path:%s", download_id, string);
496                         }
497                         free(string);
498                         string = NULL;
499                 }
500                 if (err != NOTIFICATION_ERROR_NONE)
501                         TRACE_ERROR("failed to set service id:%d error:%s", download_id, __dp_noti_error_str(err));
502
503                 char *file_type_icon = DP_NOTIFICATION_UNKNOWN_ICON_PATH;
504                 if (content_type > 0 && content_type < DP_MAX_ICONS_TABLE_COUNT)
505                         file_type_icon = file_icons_table[content_type];
506
507                 err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, file_type_icon);
508                 if (err != NOTIFICATION_ERROR_NONE)
509                         TRACE_ERROR("failed to set icon id:%d error:%s", download_id, __dp_noti_error_str(err));
510
511                 err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR,
512                                 DP_NOTIFICATION_COMPLETED_INDICATOR_ICON_PATH);
513                 if (err != NOTIFICATION_ERROR_NONE)
514                         TRACE_ERROR("failed to set icon id:%d error:%s", download_id, __dp_noti_error_str(err));
515         } else if (state == DP_STATE_CANCELED || state == DP_STATE_FAILED) {
516
517                 if (dp_db_get_property_string(dbhandle, download_id, DP_TABLE_NOTIFICATION, DP_DB_COL_NOTI_RAW_FAIL, &raws_buffer, &length, &errorcode) < 0)
518                         TRACE_ERROR("failed to get bundle raws id:%d", download_id);
519
520                 if (raws_buffer != NULL) {
521                         b = bundle_decode_raw(raws_buffer, length);
522                         bundle_free_encoded_rawdata(&raws_buffer);
523                 }
524                 if (b != NULL) {
525                         err = notification_set_execute_option(noti_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
526                 } else {
527                         b = bundle_create();
528                         if (b != NULL && pkgname != NULL) {
529                                 if (appsvc_set_pkgname(b, pkgname) != APPSVC_RET_OK) {
530                                         TRACE_ERROR("failed to set set pkgname id:%d", download_id);
531                                 } else {
532                                         err = notification_set_execute_option(noti_handle,
533                                                         NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
534                                 }
535                         } else {
536                                 TRACE_ERROR("failed to create bundle id:%d", download_id);
537                         }
538                 }
539                 if (err != NOTIFICATION_ERROR_NONE)
540                         TRACE_ERROR("failed to set service id:%d error:%s", download_id, __dp_noti_error_str(err));
541
542                 err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON,
543                                 DP_NOTIFICATION_FAILED_ICON_PATH);
544                 if (err != NOTIFICATION_ERROR_NONE)
545                         TRACE_ERROR("failed to set icon id:%d error:%s", download_id, __dp_noti_error_str(err));
546
547                 err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR,
548                                 DP_NOTIFICATION_FAILED_INDICATOR_ICON_PATH);
549                 if (err != NOTIFICATION_ERROR_NONE)
550                         TRACE_ERROR("failed to set icon id:%d error:%s", download_id, __dp_noti_error_str(err));
551         }
552
553         if (b != NULL)
554                 bundle_free(b);
555
556         err = notification_set_property(noti_handle,
557                         NOTIFICATION_PROP_DISABLE_TICKERNOTI);
558         if (err != NOTIFICATION_ERROR_NONE)
559                 TRACE_ERROR("failed to set property id:%d error:%s", download_id, __dp_noti_error_str(err));
560
561         err = notification_set_display_applist(noti_handle,
562                         NOTIFICATION_DISPLAY_APP_ALL ^ NOTIFICATION_DISPLAY_APP_INDICATOR);
563         if (err != NOTIFICATION_ERROR_NONE)
564                 TRACE_ERROR("failed to set display app all id:%d error:%s", download_id, __dp_noti_error_str(err));
565
566         int priv_id = 0;
567         err = notification_insert(noti_handle, &priv_id);
568         if (err != NOTIFICATION_ERROR_NONE)
569                 TRACE_ERROR("failed to set priv_id id:%d error:%s", download_id, __dp_noti_error_str(err));
570
571         //TRACE_DEBUG("m_noti_id [%d]", priv_id);
572         notification_free(noti_handle);
573
574         return priv_id;
575 }
576 #else
577 void dp_notification_clear_ongoings()
578 {
579         return;
580 }
581 #endif