[cleanup] revise file location
[platform/core/connectivity/bluetooth-share.git] / app / bt-share-notification.c
1 /*
2  * bluetooth-share
3  *
4  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *              http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <applog.h>
21 #include <notification.h>
22 #include <notification_list.h>
23 #include <notification_text_domain.h>
24 #include <notification_internal.h>
25 #include <appsvc.h>
26 #include <vconf.h>
27
28 #include "bt-share-common.h"
29 #include "bt-share-notification.h"
30 #include "bt-share-main.h"
31 #include "bt-share-ipc.h"
32 #include "obex-event-handler.h"
33 #include "bluetooth-share-api.h"
34 #include "bt-share-resource.h"
35
36 #define BT_PRIV_ID_STR_LEN 12
37
38 extern GSList *bt_rcv_noti_info_list;
39 extern GSList *bt_snd_noti_info_list;
40
41 void _bt_insert_instant_notification(bt_notification_type_e type)
42 {
43         FN_START;
44         notification_h noti = NULL;
45         notification_error_e ret = NOTIFICATION_ERROR_NONE;
46         char *title = NULL;
47         char *icon_path = NULL;
48
49         DBG("Create notification type : %d", type);
50
51         switch (type) {
52         case BT_SENDING_NOTI: {
53                 title = BT_STR_SENDING_FILES;
54                 icon_path = BT_ICON_NOTIFICATION_SENT_INDICATOR;
55                 break;
56         }
57
58         case BT_RECEIVING_NOTI: {
59                 title = BT_STR_RECEIVING_FILES;
60                 icon_path = BT_ICON_NOTIFICATION_RECEIVED_INDICATOR;
61                 break;
62         }
63
64         case BT_SENT_NOTI: {
65                 title = BT_STR_FILES_SENT;
66                 icon_path = BT_ICON_NOTIFICATION_SENT_INDICATOR;
67                 break;
68         }
69
70         case BT_SENT_FAILED_NOTI: {
71                 title = BT_STR_SENDING_FILES_FAILED;
72                 icon_path = BT_ICON_NOTIFICATION_SENT_INDICATOR;
73                 break;
74         }
75
76         case BT_RECEIVED_NOTI: {
77                 title = BT_STR_FILES_RECEIVED;
78                 icon_path = BT_ICON_NOTIFICATION_RECEIVED_INDICATOR;
79                 break;
80         }
81
82         case BT_RECEIVED_FAILED_NOTI: {
83                 title = BT_STR_RECEIVING_FILES_FAILED;
84                 icon_path = BT_ICON_NOTIFICATION_RECEIVED_INDICATOR;
85                 break;
86         }
87
88         default:
89                 return;
90         }
91
92         noti = notification_create(NOTIFICATION_TYPE_NOTI);
93         retm_if(!noti, "Fail to notification_create");
94
95         if (title) {
96                 ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
97                                         NULL, title,
98                                         NOTIFICATION_VARIABLE_TYPE_NONE);
99                 warn_if(ret != NOTIFICATION_ERROR_NONE,
100                                 "Fail to notification_set_text [%d]", ret);
101         }
102
103         if (icon_path) {
104                 ret = notification_set_image(noti,
105                                 NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, icon_path);
106                 warn_if(ret != NOTIFICATION_ERROR_NONE,
107                         "Fail to notification_set_image [%d]", ret);
108         }
109
110         ret  = notification_set_display_applist(noti,
111                         NOTIFICATION_DISPLAY_APP_TICKER);
112         warn_if(ret != NOTIFICATION_ERROR_NONE,
113                 "Fail to notification_set_display_applist [%d]", ret);
114
115         ret = notification_post(noti);
116         warn_if(ret != NOTIFICATION_ERROR_NONE,
117                         "Fail to notification_insert [%d]", ret);
118
119         if (noti)
120                 notification_free(noti);
121         FN_END;
122 }
123
124 notification_h _bt_insert_notification(bt_appdata_t *ad,
125                         bt_notification_type_e type, char *dev_name,
126                         char *address, char *db_sid)
127 {
128         notification_h noti = NULL;
129         notification_error_e ret = NOTIFICATION_ERROR_NONE;
130         notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
131         char *title = NULL;
132         char *content = NULL;
133         char *icon_path = NULL;
134         char *indicator_icon_path = NULL;
135         char *app_id = NULL;
136         int noti_id = 0;
137         int flag = -1;
138         int success = 0;
139         int fail = 0;
140         bool include_name_param = false;
141
142         DBG("Create notification type : %d", type);
143
144         if (type == BT_SENT_NOTI) {
145                 success = ad->send_data.tr_success;
146                 fail = ad->send_data.tr_fail;
147
148                 if (success == 0) {
149                         title = "IDS_BT_MBODY_SENDING_FAILED";
150                 } else {
151                         title = "IDS_WIFI_BODY_FILES_SENT_TO_PS_M_STATUS";
152                         include_name_param = true;
153                 }
154
155                 if (success == 0 && fail > 0)
156                         content = "IDS_BT_SBODY_PD_FAILED_ABB";
157                 else if (fail == 0 && success > 0)
158                         content = "IDS_BT_SBODY_PD_SUCCEEDED_ABB";
159                 else
160                         content = "IDS_BT_SBODY_P1SD_SUCCEEDED_P2SD_FAILED_ABB2";
161
162                 icon_path = BT_ICON_NOTIFICATION_SENT;
163                 indicator_icon_path = BT_ICON_NOTIFICATION_SENT_INDICATOR;
164                 flag = NOTIFICATION_PROP_DISABLE_AUTO_DELETE;
165                 app_id = NOTI_OPC_APP_ID;
166                 noti_type = NOTIFICATION_TYPE_NOTI;
167         } else if (type == BT_RECEIVED_NOTI) {
168                 success = ad->recv_data.tr_success;
169                 fail = ad->recv_data.tr_fail;
170
171                 if (success == 0 && fail > 0) {
172                         content = "IDS_BT_SBODY_PD_FAILED_ABB";
173                         title = "IDS_BT_MBODY_RECEIVING_FAILED";
174                 } else if (fail == 0 && success > 0) {
175                         title = "IDS_WIFI_MBODY_FILES_RECEIVED_FROM_PS";
176                         content = "IDS_BT_SBODY_PD_SUCCEEDED_ABB";
177                         include_name_param = true;
178                 } else {
179                         title = "IDS_WIFI_MBODY_FILES_RECEIVED_FROM_PS";
180                         content = "IDS_BT_SBODY_P1SD_SUCCEEDED_P2SD_FAILED_ABB2";
181                         include_name_param = true;
182                 }
183                 icon_path = BT_ICON_NOTIFICATION_RECEIVED;
184                 indicator_icon_path = BT_ICON_NOTIFICATION_RECEIVED_INDICATOR;
185                 flag = NOTIFICATION_PROP_DISABLE_AUTO_DELETE;
186                 app_id = NOTI_OPS_APP_ID;
187                 noti_type = NOTIFICATION_TYPE_NOTI;
188         } else if (type == BT_SENDING_NOTI) {
189                 title = "IDS_BT_SBODY_PREPARING_TO_SEND_FILES_ING_ABB";
190                 icon_path = BT_ICON_NOTIFICATION_SENDING;
191                 indicator_icon_path = BT_ICON_NOTIFICATION_SENDING_INDICATOR;
192                 flag = NOTIFICATION_PROP_DISABLE_TICKERNOTI;
193                 noti_type = NOTIFICATION_TYPE_ONGOING;
194         } else if (type == BT_RECEIVING_NOTI) {
195                 title = "IDS_BT_SBODY_PREPARING_TO_RECEIVE_FILES_ING_ABB";
196                 icon_path = BT_ICON_NOTIFICATION_RECEIVING;
197                 indicator_icon_path = BT_ICON_NOTIFICATION_RECEIVING_INDICATOR;
198                 flag = NOTIFICATION_PROP_DISABLE_TICKERNOTI;
199                 noti_type = NOTIFICATION_TYPE_ONGOING;
200         }
201
202         noti = notification_create(noti_type);
203         if (!noti) {
204                 ERR("Fail to notification_create");
205                 return NULL;
206         }
207
208         notification_set_text_domain(noti, BT_COMMON_PKG, BT_COMMON_RES);
209
210         if (title) {
211                 if (include_name_param == true) {
212                         ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
213                                 NULL, title,
214                                 NOTIFICATION_VARIABLE_TYPE_STRING, dev_name,
215                                 NOTIFICATION_VARIABLE_TYPE_NONE);
216                 } else {
217                         ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
218                                 NULL, title,
219                                 NOTIFICATION_VARIABLE_TYPE_NONE);
220                 }
221                 warn_if(ret != NOTIFICATION_ERROR_NONE,
222                         "Fail to notification_set_text [%d]", ret);
223         }
224
225         if (content) {
226                 DBG("success : %d, fail : %d", success, fail);
227                 if (success > 0 && fail > 0) {
228                         ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
229                                                 NULL, content,
230                                                 NOTIFICATION_VARIABLE_TYPE_INT, success,
231                                                 NOTIFICATION_VARIABLE_TYPE_INT, fail,
232                                                 NOTIFICATION_VARIABLE_TYPE_NONE);
233                 } else {
234                         ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
235                                                 NULL, content,
236                                                 NOTIFICATION_VARIABLE_TYPE_INT, (success > 0) ? success : fail,
237                                                 NOTIFICATION_VARIABLE_TYPE_NONE);
238                 }
239
240                 warn_if(ret != NOTIFICATION_ERROR_NONE,
241                         "Fail to notification_set_text [%d]", ret);
242         }
243
244         if (icon_path) {
245                 ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
246                 warn_if(ret != NOTIFICATION_ERROR_NONE,
247                         "Fail to notification_set_image [%d]", ret);
248         }
249
250         if (indicator_icon_path) {
251                 ret = notification_set_image(noti,
252                                 NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, indicator_icon_path);
253                 warn_if(ret != NOTIFICATION_ERROR_NONE,
254                         "Fail to notification_set_image [%d]", ret);
255         }
256
257         if (flag != -1) {
258                 ret = notification_set_property(noti, flag);
259                 warn_if(ret != NOTIFICATION_ERROR_NONE,
260                         "Fail to notification_set_property [%d]", ret);
261
262                 if (type == BT_SENDING_NOTI || type == BT_RECEIVING_NOTI) {
263                         ret = notification_set_property(noti,
264                                         NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
265                         warn_if(ret != NOTIFICATION_ERROR_NONE,
266                                 "Fail to set property for DISABLE_APP_LAUNCH [%d]", ret);
267                 }
268         }
269
270         if (app_id) {
271                 ret = notification_set_pkgname(noti, app_id);
272                 warn_if(ret != NOTIFICATION_ERROR_NONE,
273                         "Fail to notification_set_pkgname [%d]", ret);
274         }
275
276         ret = notification_set_display_applist(noti,
277                         NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR);
278         warn_if(ret != NOTIFICATION_ERROR_NONE,
279                 "Fail to notification_set_display_applist [%d]", ret);
280
281         if (type == BT_SENT_NOTI) {
282                 _bt_set_notification_app_launch(noti, dev_name, address, db_sid,
283                                 CREATE_TR_LIST, NOTI_TR_TYPE_OUT, NULL, 0, NULL, 0);
284         } else if (type == BT_RECEIVED_NOTI) {
285                 _bt_set_notification_app_launch(noti, dev_name, address, db_sid,
286                                 CREATE_TR_LIST, NOTI_TR_TYPE_IN, NULL, 0, NULL, 0);
287         }
288
289         ret = notification_insert(noti, &noti_id);
290         warn_if(ret != NOTIFICATION_ERROR_NONE,
291                 "Fail to notification_insert [%d]", ret);
292
293         if (type == BT_SENT_NOTI)
294                 ad->send_noti_id = noti_id;
295         else if (type == BT_RECEIVED_NOTI)
296                 ad->receive_noti_id = noti_id;
297
298         INFO("Insert %s type: %d ", (type == BT_SENT_NOTI ||
299                         type == BT_RECEIVED_NOTI) ? "Notification" : "Ongoing", type);
300
301         return noti;
302 }
303
304 int _bt_update_notification(bt_appdata_t *ad,
305                 notification_h noti, char *title, char *content, char *dev_name,
306                 char *icon_path, char *opc_count)
307 {
308         retvm_if(!noti, BT_SHARE_FAIL, "noti is NULL");
309
310         INFO("Update noti : %p", noti);
311         notification_error_e ret = NOTIFICATION_ERROR_NONE;
312         int success = 0;
313         int fail = 0;
314         int flags = -1;
315
316         if (ad->send_noti == noti) {
317                 success = ad->send_data.tr_success;
318                 fail = ad->send_data.tr_fail;
319         } else if (ad->receive_noti == noti) {
320                 success = ad->recv_data.tr_success;
321                 fail = ad->recv_data.tr_fail;
322         }
323
324         if (ad->send_noti == noti || ad->receive_noti == noti) {
325                 if (success == 0 && fail > 0)
326                         content = "IDS_BT_SBODY_PD_FAILED_ABB";
327                 else if (fail == 0 && success > 0)
328                         content = "IDS_BT_SBODY_PD_SUCCEEDED_ABB";
329                 else
330                         content = "IDS_BT_SBODY_P1SD_SUCCEEDED_P2SD_FAILED_ABB2";
331         }
332
333         if (title) {
334                 ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
335                                         NULL, title,
336                                         NOTIFICATION_VARIABLE_TYPE_NONE);
337                 warn_if(ret != NOTIFICATION_ERROR_NONE,
338                         "Fail to notification_set_text [%d]", ret);
339         }
340
341         if (content) {
342                 if (noti == ad->send_noti || noti == ad->receive_noti) {
343                         if (success > 0 && fail > 0) {
344                                 ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
345                                                 NULL, content,
346                                                 NOTIFICATION_VARIABLE_TYPE_INT, success,
347                                                 NOTIFICATION_VARIABLE_TYPE_INT, fail,
348                                                 NOTIFICATION_VARIABLE_TYPE_NONE);
349                         } else {
350                                 ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
351                                                                 NULL, content,
352                                                                 NOTIFICATION_VARIABLE_TYPE_INT, (success > 0) ? success : fail,
353                                                                 NOTIFICATION_VARIABLE_TYPE_NONE);
354                         }
355                 } else {
356                         if (dev_name) {
357                                 ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
358                                                         NULL, content,
359                                                         NOTIFICATION_VARIABLE_TYPE_STRING, dev_name,
360                                                         NOTIFICATION_VARIABLE_TYPE_NONE);
361                         } else {
362                                 ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
363                                                         NULL, content, NOTIFICATION_VARIABLE_TYPE_NONE);
364                         }
365                 }
366
367                 warn_if(ret != NOTIFICATION_ERROR_NONE,
368                         "Fail to notification_set_text [%d]", ret);
369         }
370
371         if (opc_count) {
372                 ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT,
373                                         NULL, opc_count, NOTIFICATION_VARIABLE_TYPE_NONE);
374                 warn_if(ret != NOTIFICATION_ERROR_NONE,
375                         "Fail to notification_set_text [%d]", ret);
376         }
377
378         if (icon_path) {
379                 ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
380                                 icon_path);
381                 warn_if(ret != NOTIFICATION_ERROR_NONE,
382                         "Fail to notification_set_image [%d]", ret);
383         }
384
385         ret  = notification_get_property(noti, &flags);
386         if (ret == NOTIFICATION_ERROR_NONE) {
387                 if (flags & NOTIFICATION_PROP_DISABLE_APP_LAUNCH) {
388                         ret = notification_set_property(noti,
389                                         flags ^ NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
390                         warn_if(ret != NOTIFICATION_ERROR_NONE,
391                                         "Failed to set app launch property");
392                 }
393         } else {
394                 ERR("failed to get the property: [%d]", ret);
395         }
396
397         ret = notification_update(noti);
398         warn_if(ret != NOTIFICATION_ERROR_NONE,
399                         "Fail to notification_update [%d]", ret);
400
401         return ret;
402 }
403
404 int _bt_update_notification_progress(notification_h not,
405                                 int id, int val)
406 {
407         notification_error_e ret = NOTIFICATION_ERROR_NONE;
408
409         ret = notification_update_progress(not, id, (double)val / 100);
410         warn_if(ret != NOTIFICATION_ERROR_NONE,
411                 "Fail to notification_update_progress [%d]\n", ret);
412
413         return ret;
414 }
415
416 int _bt_get_notification_priv_id(notification_h noti)
417 {
418         int group_id = 0;
419         int priv_id = 0;
420         notification_error_e ret = NOTIFICATION_ERROR_NONE;
421
422         ret = notification_get_id(noti, &group_id, &priv_id);
423         warn_if(ret != NOTIFICATION_ERROR_NONE,
424                 "Fail to notification_get_id [%d]", ret);
425
426         return priv_id;
427 }
428
429 int _bt_delete_notification(notification_h noti)
430 {
431         retv_if(!noti, BT_SHARE_FAIL);
432         notification_error_e ret = NOTIFICATION_ERROR_NONE;
433
434         INFO("Delete noti : %p", noti);
435
436         /* In case daemon, give full path */
437         ret = notification_delete(noti);
438         warn_if(ret != NOTIFICATION_ERROR_NONE,
439                 "Fail to notification_delete [%d]", ret);
440
441         return ret;
442 }
443
444 int _bt_set_notification_app_launch(notification_h noti,
445                 char *device_name,
446                 char *device_addr,
447                 char *db_sid,
448                 bt_notification_launch_type_e launch_type,
449                 const char *transfer_type,
450                 const char *filename,
451                 unsigned long size,
452                 const char *progress_cnt,
453                 int transfer_id)
454 {
455         FN_START;
456         retv_if(!noti, BT_SHARE_FAIL);
457         retv_if(!transfer_type, BT_SHARE_FAIL);
458         retv_if(launch_type != CREATE_PROGRESS && launch_type != CREATE_TR_LIST,
459                         BT_SHARE_FAIL);
460
461         notification_error_e ret = NOTIFICATION_ERROR_NONE;
462         bundle *b = NULL;
463         b = bundle_create();
464         retv_if(!b, BT_SHARE_FAIL);
465
466         appsvc_set_pkgname(b, UI_PACKAGE);
467         appsvc_add_data(b, "device_name", device_name);
468         appsvc_add_data(b, "device_addr", device_addr);
469         appsvc_add_data(b, "transfer_type", transfer_type);
470         appsvc_add_data(b, "db_sid", db_sid);
471
472         if (launch_type == CREATE_PROGRESS) {
473                 if (!filename) {
474                         bundle_free(b);
475                         return BT_SHARE_FAIL;
476                 }
477
478                 char priv_id_str[BT_PRIV_ID_STR_LEN] = {0, };
479                 char size_str[BT_PRIV_ID_STR_LEN] = {0, };
480                 snprintf(priv_id_str, BT_PRIV_ID_STR_LEN, "%d", transfer_id);
481                 snprintf(size_str, BT_PRIV_ID_STR_LEN, "%lu", size);
482
483                 appsvc_add_data(b, "launch-type", "ongoing");
484                 appsvc_add_data(b, "filename", filename);
485                 appsvc_add_data(b, "size", size_str);
486                 appsvc_add_data(b, "transfer_id", priv_id_str);
487                 if (g_strcmp0(transfer_type, NOTI_TR_TYPE_OUT) == 0) {
488                         if (!progress_cnt) {
489                                 bundle_free(b);
490                                 return BT_SHARE_FAIL;
491                         }
492                         appsvc_add_data(b, "progress_cnt", progress_cnt);
493                 }
494         } else {
495                 char priv_id_str[BT_PRIV_ID_STR_LEN] = {0, };
496                 snprintf(priv_id_str, BT_PRIV_ID_STR_LEN, "%d", transfer_id);
497
498                 appsvc_add_data(b, "launch-type", "transfer_list");
499                 appsvc_add_data(b, "transfer_id", priv_id_str);
500                 appsvc_add_data(b, "filename", filename);
501         }
502
503         ret = notification_set_execute_option(noti,
504                                         NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
505                                         NULL, NULL, b);
506         warn_if(ret != NOTIFICATION_ERROR_NONE,
507                 "Fail to notification_set_execute_option [%d]\n", ret);
508
509         bundle_free(b);
510         FN_END;
511         return ret;
512 }
513
514 #if 0
515 gboolean _bt_update_notification_status(bt_appdata_t *ad)
516 {
517         retv_if(ad == NULL, FALSE);
518
519         notification_h noti = NULL;
520         notification_list_h list_head = NULL;
521         notification_list_h list_traverse = NULL;
522         gboolean is_noti_existed = FALSE;
523         gboolean send_noti = FALSE;
524         gboolean receive_noti = FALSE;
525         sqlite3 *db = NULL;
526         char *app_id = NULL;
527         int group_id = 0;
528         int priv_id = 0;
529         int ret = 0;
530
531         /* When bt-share is launched, need to update notification status  */
532         notification_get_list(NOTIFICATION_TYPE_NOTI, -1, &list_head);
533         list_traverse = list_head;
534
535         while (list_traverse != NULL) {
536                 noti = notification_list_get_data(list_traverse);
537                 notification_get_pkgname(noti, &app_id);
538
539                 if (g_strcmp0(app_id, NOTI_OPS_APP_ID) == 0) {
540                         ret = notification_clone(noti, &ad->receive_noti);
541                         warn_if(ret != NOTIFICATION_ERROR_NONE,
542                                         "Fail to clone notificatoin");
543
544                         ret = notification_get_id(noti, &group_id, &priv_id);
545                         warn_if(ret != NOTIFICATION_ERROR_NONE,
546                                         "Fail to get notification id");
547
548                         ad->receive_noti_id = priv_id;
549                         receive_noti = TRUE;
550                 } else if (g_strcmp0(app_id, NOTI_OPC_APP_ID) == 0) {
551                         ret = notification_clone(noti, &ad->send_noti);
552                         warn_if(ret != NOTIFICATION_ERROR_NONE,
553                                         "Unable to clone notificatoin");
554
555                         ret = notification_get_id(noti, &group_id, &priv_id);
556                         warn_if(ret != NOTIFICATION_ERROR_NONE,
557                                 "Fail to get notification id");
558
559                         ad->send_noti_id = priv_id;
560                         send_noti = TRUE;
561                 }
562
563                 if (receive_noti || send_noti) {
564                         time_t ret_time;
565                         /* Set notication insert_time */
566                         notification_get_insert_time(noti, &ret_time);
567                         notification_set_time(noti, ret_time);
568                         notification_update(noti);
569                         is_noti_existed = TRUE;
570                         send_noti = FALSE;
571                         receive_noti = FALSE;
572                 }
573
574                 list_traverse = notification_list_get_next(list_traverse);
575         }
576
577         if (list_head != NULL) {
578                 notification_free_list(list_head);
579                 list_head = NULL;
580         }
581
582         /* If notification item is removed durning BT off, need to remove DB */
583         db = bt_share_open_db();
584         retv_if(!db, is_noti_existed);
585
586         if (!receive_noti)
587                 bt_share_remove_all_tr_data(db, BT_DB_INBOUND);
588         if (!send_noti)
589                 bt_share_remove_all_tr_data(db, BT_DB_OUTBOUND);
590         bt_share_close_db(db);
591
592         return is_noti_existed;
593 }
594 #endif
595
596 /* LCOV_EXCL_START */
597 static void __bt_notification_changed_cb(void *data, notification_type_e type,
598                 notification_op *op_list, int num_op)
599 {
600         FN_START;
601         retm_if(data == NULL, "Invalid data");
602         retm_if(op_list == NULL, "Invalid op_list");
603
604         bt_appdata_t *ad = (bt_appdata_t *)data;
605         sqlite3 *db = NULL;
606         int i;
607
608         ret_if(type != NOTIFICATION_TYPE_NOTI ||
609                 (op_list->type != NOTIFICATION_OP_DELETE &&
610                 op_list->type != NOTIFICATION_OP_DELETE_ALL));
611
612         DBG("Notifications Changed: %d", num_op);
613         DBG("Currently Received NotiID: %d", ad->receive_noti_id);
614         db = bt_share_open_db();
615         for (i = 0; i < num_op; i++, op_list++) {
616                 DBG("TYPE:%d PRIV_ID:%d", op_list->type, op_list->priv_id);
617
618                 if (op_list->priv_id == ad->receive_noti_id) {
619                         ad->receive_noti = NULL;
620                         ad->receive_noti_id = 0;
621                 }
622
623                 if (bt_share_check_noti_id(db, BT_DB_OUTBOUND, op_list->priv_id)
624                                                 == BT_SHARE_ERR_NONE) {
625                         DBG("Delete Entries from OUTBOUND for NotiID %d", op_list->priv_id);
626                         ad->send_noti = NULL;
627                         ad->send_noti_id = 0;
628                         ad->send_data.tr_fail = 0;
629                         ad->send_data.tr_success = 0;
630                         _bt_remove_temporary_files_by_noti_id(db, op_list->priv_id);
631                         bt_share_remove_tr_data_by_notification(db,
632                                         BT_DB_OUTBOUND, op_list->priv_id);
633                 }
634                 if (bt_share_check_noti_id(db, BT_DB_INBOUND, op_list->priv_id)
635                                                 == BT_SHARE_ERR_NONE) {
636                         DBG("Delete Entries from INBOUND for NotiID %d", op_list->priv_id);
637                         ad->receive_noti = NULL;
638                         ad->receive_noti_id = 0;
639                         ad->recv_data.tr_fail = 0;
640                         ad->recv_data.tr_success = 0;
641                         bt_share_remove_tr_data_by_notification(db,
642                                         BT_DB_INBOUND, op_list->priv_id);
643                 }
644         }
645         bt_share_close_db(db);
646
647         DBG("SEND: Success[%d] Fail[%d] ||||| RECEIVE: Success[%d] Fail[%d]",
648                         ad->send_data.tr_success, ad->send_data.tr_fail,
649                         ad->recv_data.tr_success, ad->recv_data.tr_fail);
650         FN_END;
651
652 }
653 /* LCOV_EXCL_STOP */
654
655 void _bt_register_notification_cb(bt_appdata_t *ad)
656 {
657         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
658
659         noti_err = notification_register_detailed_changed_cb(
660                         __bt_notification_changed_cb, ad);
661         warn_if(noti_err != NOTIFICATION_ERROR_NONE,
662                         "notification_resister_changed_cb failed [%d]\n", noti_err);
663 }
664
665 void _bt_unregister_notification_cb(bt_appdata_t *ad)
666 {
667         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
668
669         noti_err = notification_unregister_detailed_changed_cb(
670                         __bt_notification_changed_cb, NULL);
671         warn_if(noti_err != NOTIFICATION_ERROR_NONE,
672                         "notification_unresister_changed_cb failed [%d]\n", noti_err);
673 }