apply Tizen 3.0 Message UX Guide
[platform/core/messaging/msg-service.git] / externals / MsgNotificationWrapper.cpp
1 /*
2  * Copyright (c) 2014 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
18 #include "MsgDebug.h"
19 #include "MsgUtilFunction.h"
20 #include "MsgGconfWrapper.h"
21 #include "MsgNotificationWrapper.h"
22 #include "MsgDevicedWrapper.h"
23 #include "MsgSqliteWrapper.h"
24
25 extern "C"
26 {
27 #ifndef MSG_WEARABLE_PROFILE
28 #include <bundle.h>
29 #endif /* MSG_WEARABLE_PROFILE */
30 }
31
32 /*======================================================================================*/
33 /*                                                              FUNCTION IMPLEMENTATION                                                                 */
34 /*======================================================================================*/
35
36
37 msg_error_t MsgInsertNotification(MSG_MESSAGE_INFO_S *msg_info)
38 {
39         MSG_BEGIN();
40
41         msg_error_t err = MSG_SUCCESS;
42
43 #ifndef MSG_WEARABLE_PROFILE
44
45         msg_notification_type_t noti_type;
46
47         switch (msg_info->msgType.subType) {
48 #ifdef MSG_NOTI_INTEGRATION
49         case MSG_NORMAL_SMS:
50         case MSG_CB_SMS: {
51                 if (msg_info->msgType.classType == MSG_CLASS_0) {
52                         noti_type = MSG_NOTI_TYPE_CLASS0;
53                 } else {
54                         noti_type = MSG_NOTI_TYPE_NORMAL;
55                 }
56                 break;
57         }
58 #else
59         case MSG_NORMAL_SMS: {
60                 if (msg_info->msgType.classType == MSG_CLASS_0) {
61                         noti_type = MSG_NOTI_TYPE_CLASS0;
62                 } else if (msg_info->msgType.classType == MSG_CLASS_2) {
63                         noti_type = MSG_NOTI_TYPE_SIM;
64                 } else {
65                         noti_type = MSG_NOTI_TYPE_NORMAL;
66                 }
67                 break;
68         }
69         case MSG_CB_SMS:
70                 noti_type = MSG_NOTI_TYPE_CB;
71                 break;
72 #endif
73         case MSG_MWI_FAX_SMS:
74         case MSG_MWI_EMAIL_SMS:
75         case MSG_MWI_OTHER_SMS:
76                 noti_type = MSG_NOTI_TYPE_MWI;
77                 break;
78         case MSG_MWI_VOICE_SMS:
79                 noti_type = MSG_NOTI_TYPE_VOICE_1;
80                 break;
81         case MSG_MWI_VOICE2_SMS:
82                 noti_type = MSG_NOTI_TYPE_VOICE_2;
83                 break;
84         case MSG_STATUS_REPORT_SMS:
85                 noti_type = MSG_NOTI_TYPE_SMS_DELIVERY_REPORT;
86                 break;
87         case MSG_DELIVERYIND_MMS:
88                 noti_type = MSG_NOTI_TYPE_MMS_DELIVERY_REPORT;
89                 break;
90         case MSG_READORGIND_MMS:
91                 noti_type = MSG_NOTI_TYPE_MMS_READ_REPORT;
92                 break;
93         case MSG_READRECIND_MMS:
94         case MSG_READREPLY_MMS:
95                 noti_type = MSG_NOTI_TYPE_MMS_READ_REPORT_SENT;
96                 break;
97         default:
98 #ifdef MSG_NOTI_INTEGRATION
99                 noti_type = MSG_NOTI_TYPE_NORMAL;
100 #else
101                 if (msg_info->msgType.classType == MSG_CLASS_2) {
102                         noti_type = MSG_NOTI_TYPE_SIM;
103                 } else {
104                         noti_type = MSG_NOTI_TYPE_NORMAL;
105                 }
106 #endif
107                 break;
108         }
109
110         MSG_DEBUG("Notification type = [%d]", noti_type);
111
112         switch (noti_type) {
113         case MSG_NOTI_TYPE_NORMAL:
114         case MSG_NOTI_TYPE_SIM:
115         case MSG_NOTI_TYPE_CB:
116                 err = MsgRefreshNotification(noti_type, true, MSG_ACTIVE_NOTI_TYPE_ACTIVE);
117                 break;
118         case MSG_NOTI_TYPE_SMS_DELIVERY_REPORT:
119         case MSG_NOTI_TYPE_MMS_DELIVERY_REPORT:
120         case MSG_NOTI_TYPE_MMS_READ_REPORT:
121                 err = MsgAddReportNotification(noti_type, msg_info);
122                 break;
123         case MSG_NOTI_TYPE_VOICE_1:
124         case MSG_NOTI_TYPE_VOICE_2:
125         case MSG_NOTI_TYPE_MWI:
126         case MSG_NOTI_TYPE_CLASS0:
127         case MSG_NOTI_TYPE_MMS_READ_REPORT_SENT:
128                 err = MsgAddNotification(noti_type, msg_info);
129                 break;
130         default:
131                 MSG_DEBUG("No matching type [%d]");
132                 break;
133         }
134
135 #endif /* MSG_WEARABLE_PROFILE */
136
137         MSG_END();
138
139         return err;
140 }
141
142 msg_error_t MsgInsertOnlyActiveNotification(msg_notification_type_t noti_type, MSG_MESSAGE_INFO_S *msg_info)
143 {
144         MSG_BEGIN();
145
146         msg_error_t err = MSG_SUCCESS;
147
148 #ifndef MSG_WEARABLE_PROFILE
149         bundle *bundle_data = bundle_create();
150
151         bundle_add_str(bundle_data, "cmd", "insert_only_active_noti");
152         if (noti_type == MSG_NOTI_TYPE_NORMAL)
153                 bundle_add_str(bundle_data, "type", "normal");
154         else if (noti_type == MSG_NOTI_TYPE_CLASS0)
155                 bundle_add_str(bundle_data, "type", "class0");
156
157         err = msg_launch_app(MSG_MGR_APP_ID, bundle_data);
158
159         bundle_free(bundle_data);
160 #endif /* MSG_WEARABLE_PROFILE */
161         MSG_END();
162         return err;
163 }
164
165
166 msg_error_t MsgDeleteReportNotification(const char *addr)
167 {
168         MSG_BEGIN();
169
170         msg_error_t err = MSG_SUCCESS;
171
172 #ifndef MSG_WEARABLE_PROFILE
173         bundle *bundle_data = bundle_create();
174
175         bundle_add_str(bundle_data, "cmd", "del_report_noti");
176         bundle_add_str(bundle_data, "address", addr);
177
178         err = msg_launch_app(MSG_MGR_APP_ID, bundle_data);
179
180         bundle_free(bundle_data);
181 #endif /* MSG_WEARABLE_PROFILE */
182         MSG_END();
183
184         return err;
185 }
186
187 msg_error_t MsgIsSentReadReportNotificationExist(int threadId, int *msgId)
188 {
189         MSG_BEGIN();
190
191         msg_error_t err = MSG_SUCCESS;
192
193 #ifndef MSG_WEARABLE_PROFILE
194         char sqlQuery[MAX_QUERY_LEN+1];
195         int readReportSentMsgId = 0;
196
197         if (MsgSettingGetInt(VCONFKEY_MESSAGE_READ_REPORT_SENT_MSG_ID, &readReportSentMsgId) != MSG_SUCCESS)
198                 MSG_INFO("MsgSettingGetInt() is failed");
199
200         MsgDbHandler *dbHandle = getDbHandle();
201
202         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE CONV_ID = %d AND MSG_ID = %d;",
203                         MSGFW_MESSAGE_TABLE_NAME,  threadId, readReportSentMsgId);
204
205         if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
206                 return MSG_ERR_DB_PREPARE;
207
208         if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
209                 dbHandle->finalizeQuery();
210                 MSG_DEBUG("MsgId[%d] is in ThreadId[%d]", readReportSentMsgId, threadId);
211                 *msgId = readReportSentMsgId;
212                 return err;
213         }
214
215         dbHandle->finalizeQuery();
216
217         MSG_DEBUG("MsgId[%d] is not in ThreadId[%d]", readReportSentMsgId, threadId);
218
219         err = MSG_ERR_UNKNOWN;
220 #endif /* MSG_WEARABLE_PROFILE */
221         MSG_END();
222         return err;
223 }
224
225 msg_error_t MsgDeleteSentReadReportNotification(int msgId)
226 {
227         MSG_BEGIN();
228
229         msg_error_t err = MSG_SUCCESS;
230
231 #ifndef MSG_WEARABLE_PROFILE
232         int readReportSentMsgId = 0;
233
234         if (MsgSettingGetInt(VCONFKEY_MESSAGE_READ_REPORT_SENT_MSG_ID, &readReportSentMsgId) != MSG_SUCCESS)
235                 MSG_INFO("MsgSettingGetInt() is failed");
236
237         if (readReportSentMsgId != msgId) {
238                 MSG_ERR("Invalid read report sent notification msgId, noti msgId[%d], requested msgId[%d]", readReportSentMsgId, msgId);
239                 return MSG_ERR_UNKNOWN;
240         }
241
242         bundle *bundle_data = bundle_create();
243
244         bundle_add_str(bundle_data, "cmd", "del_sent_read_report_noti");
245
246         err = msg_launch_app(MSG_MGR_APP_ID, bundle_data);
247
248         bundle_free(bundle_data);
249
250 #endif /* MSG_WEARABLE_PROFILE */
251         MSG_END();
252         return err;
253 }
254
255 msg_error_t MsgAddReportNotification(msg_notification_type_t noti_type, MSG_MESSAGE_INFO_S *msg_info)
256 {
257         msg_error_t err = MSG_SUCCESS;
258
259 #ifndef MSG_WEARABLE_PROFILE
260         bundle *bundle_data = bundle_create();
261
262         bundle_add_str(bundle_data, "cmd", "add_report_noti");
263         switch (noti_type) {
264         case MSG_NOTI_TYPE_SMS_DELIVERY_REPORT:
265                 bundle_add_str(bundle_data, "type", "sms_delivery");
266                 break;
267         case MSG_NOTI_TYPE_MMS_DELIVERY_REPORT:
268                 bundle_add_str(bundle_data, "type", "mms_delivery");
269                 break;
270         case MSG_NOTI_TYPE_MMS_READ_REPORT:
271                 bundle_add_str(bundle_data, "type", "mms_read");
272                 break;
273         default:
274                 break;
275         }
276
277         char *msg_id = g_strdup_printf("%d", msg_info->msgId);
278         if (msg_id) {
279                 bundle_add_str(bundle_data, "msg_id", msg_id);
280                 g_free(msg_id);
281         }
282
283         err = msg_launch_app(MSG_MGR_APP_ID, bundle_data);
284
285         bundle_free(bundle_data);
286 #endif /* MSG_WEARABLE_PROFILE */
287         return err;
288 }
289
290
291 msg_error_t MsgRefreshNotification(msg_notification_type_t noti_type, bool bFeedback, msg_active_notification_type_t active_type)
292 {
293         msg_error_t err = MSG_SUCCESS;
294
295 #ifndef MSG_WEARABLE_PROFILE
296         bundle *bundle_data = bundle_create();
297
298         bundle_add_str(bundle_data, "cmd", "refresh_noti");
299         switch (noti_type) {
300         case MSG_NOTI_TYPE_NORMAL:
301                 bundle_add_str(bundle_data, "type", "normal");
302                 break;
303         case MSG_NOTI_TYPE_CB:
304                 bundle_add_str(bundle_data, "type", "cb");
305                 break;
306         case MSG_NOTI_TYPE_SIM:
307                 bundle_add_str(bundle_data, "type", "sim");
308                 break;
309         case MSG_NOTI_TYPE_FAILED:
310                 bundle_add_str(bundle_data, "type", "failed");
311                 break;
312         default:
313                 break;
314         }
315
316         switch (active_type) {
317         case MSG_ACTIVE_NOTI_TYPE_NONE:
318                 bundle_add_str(bundle_data, "active_type", "none");
319                 break;
320         case MSG_ACTIVE_NOTI_TYPE_ACTIVE:
321                 bundle_add_str(bundle_data, "active_type", "active");
322                 break;
323         case MSG_ACTIVE_NOTI_TYPE_INSTANT:
324                 bundle_add_str(bundle_data, "active_type", "instant");
325                 break;
326         default:
327                 break;
328         }
329
330         if (bFeedback)
331                 bundle_add_str(bundle_data, "feedback", "true");
332         else
333                 bundle_add_str(bundle_data, "feedback", "false");
334
335         err = msg_launch_app(MSG_MGR_APP_ID, bundle_data);
336
337         bundle_free(bundle_data);
338 #endif /* MSG_WEARABLE_PROFILE */
339         return err;
340 }
341
342
343 msg_error_t MsgAddNotification(msg_notification_type_t noti_type, MSG_MESSAGE_INFO_S *msg_info)
344 {
345         msg_error_t err = MSG_SUCCESS;
346
347 #ifndef MSG_WEARABLE_PROFILE
348         bundle *bundle_data = bundle_create();
349
350         bundle_add_str(bundle_data, "cmd", "add_noti");
351         switch (noti_type) {
352         case MSG_NOTI_TYPE_VOICE_1:
353                 bundle_add_str(bundle_data, "type", "voice1");
354                 break;
355         case MSG_NOTI_TYPE_VOICE_2:
356                 bundle_add_str(bundle_data, "type", "voice2");
357                 break;
358         case MSG_NOTI_TYPE_MWI:
359                 bundle_add_str(bundle_data, "type", "mwi");
360                 break;
361         case MSG_NOTI_TYPE_CLASS0:
362                 bundle_add_str(bundle_data, "type", "class0");
363                 break;
364         case MSG_NOTI_TYPE_MMS_READ_REPORT_SENT:
365                 bundle_add_str(bundle_data, "type", "read_report_sent");
366                 break;
367         default:
368                 break;
369         }
370
371         char *msg_id = g_strdup_printf("%d", msg_info->msgId);
372         if (msg_id) {
373                 bundle_add_str(bundle_data, "msg_id", msg_id);
374                 g_free(msg_id);
375         }
376
377         err = msg_launch_app(MSG_MGR_APP_ID, bundle_data);
378
379         bundle_free(bundle_data);
380 #endif /* MSG_WEARABLE_PROFILE */
381         return err;
382 }
383
384
385 void MsgRefreshAllNotification(bool bWithSimNoti, bool bFeedback, msg_active_notification_type_t active_type)
386 {
387         MSG_BEGIN();
388
389 #ifndef MSG_WEARABLE_PROFILE
390         msg_error_t err = MSG_SUCCESS;
391
392 /*      MsgDeleteNotification(MSG_NOTI_TYPE_SIM); */
393
394 #ifdef MSG_NOTI_INTEGRATION
395         err = MsgRefreshNotification(MSG_NOTI_TYPE_NORMAL, bFeedback, active_type);
396         if (err != MSG_SUCCESS)
397                 MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_NORMAL, err);
398 #else
399         err = MsgRefreshNotification(MSG_NOTI_TYPE_NORMAL, bFeedback, active_type);
400         if (err != MSG_SUCCESS)
401                 MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_NORMAL, err);
402
403         err = MsgRefreshNotification(MSG_NOTI_TYPE_CB, bFeedback, active_type);
404         if (err != MSG_SUCCESS)
405                 MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_CB, err);
406
407         if (bWithSimNoti) {
408                 err = MsgRefreshNotification(MSG_NOTI_TYPE_SIM, bFeedback, active_type);
409                 if (err != MSG_SUCCESS)
410                         MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_SIM, err);
411         }
412 #endif
413
414         err = MsgRefreshNotification(MSG_NOTI_TYPE_FAILED, bFeedback, active_type);
415         if (err != MSG_SUCCESS)
416                 MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_FAILED, err);
417
418 #endif /* MSG_WEARABLE_PROFILE */
419         MSG_END();
420 }
421
422
423 msg_error_t MsgDeleteNoti(msg_notification_type_t noti_type, int simIndex)
424 {
425 #ifndef MSG_WEARABLE_PROFILE
426         bundle *bundle_data = bundle_create();
427
428         bundle_add_str(bundle_data, "cmd", "del_noti");
429         switch (noti_type) {
430         case MSG_NOTI_TYPE_ALL:
431                 bundle_add_str(bundle_data, "type", "all");
432                 break;
433         case MSG_NOTI_TYPE_NORMAL:
434                 bundle_add_str(bundle_data, "type", "normal");
435                 break;
436         case MSG_NOTI_TYPE_SIM:
437                 bundle_add_str(bundle_data, "type", "sim");
438                 break;
439         case MSG_NOTI_TYPE_VOICE_1:
440                 bundle_add_str(bundle_data, "type", "voice1");
441                 break;
442         case MSG_NOTI_TYPE_VOICE_2:
443                 bundle_add_str(bundle_data, "type", "voice2");
444                 break;
445         default:
446                 break;
447         }
448
449         char *sim_index = g_strdup_printf("%d", simIndex);
450         if (sim_index) {
451                 bundle_add_str(bundle_data, "sim_index", sim_index);
452                 g_free(sim_index);
453         }
454
455         msg_launch_app(MSG_MGR_APP_ID, bundle_data);
456
457         bundle_free(bundle_data);
458 #endif /* MSG_WEARABLE_PROFILE */
459         return MSG_SUCCESS;
460 }
461
462
463 void MsgSoundPlayStart(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_SOUND_TYPE_T soundType)
464 {
465         MSG_BEGIN();
466 #ifndef MSG_WEARABLE_PROFILE
467         bundle *bundle_data = bundle_create();
468
469         bundle_add_str(bundle_data, "cmd", "sound_play_start");
470         switch (soundType) {
471         case MSG_SOUND_PLAY_DEFAULT:
472                 bundle_add_str(bundle_data, "type", "default");
473                 break;
474         case MSG_SOUND_PLAY_USER:
475                 bundle_add_str(bundle_data, "type", "user");
476                 break;
477         case MSG_SOUND_PLAY_EMERGENCY:
478                 bundle_add_str(bundle_data, "type", "emergency");
479                 break;
480         case MSG_SOUND_PLAY_VOICEMAIL:
481                 bundle_add_str(bundle_data, "type", "voicemail");
482                 break;
483         default:
484                 break;
485         }
486
487         if (pAddrInfo && pAddrInfo->addressVal[0] != '\0')
488                 bundle_add_str(bundle_data, "address", pAddrInfo->addressVal);
489
490         msg_launch_app(MSG_MGR_APP_ID, bundle_data);
491
492         bundle_free(bundle_data);
493 #endif /* MSG_WEARABLE_PROFILE */
494         MSG_END();
495 }
496
497
498 msg_error_t MsgInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg, bool bPlayFeedback, int msgId)
499 {
500         msg_error_t err = MSG_SUCCESS;
501 #ifndef MSG_WEARABLE_PROFILE
502         MSG_DEBUG("pTickerMsg=[%s], pLocaleTickerMsg=[%s]", pTickerMsg, pLocaleTickerMsg);
503         MSG_DEBUG("play feedback=[%d], msgId=[%d]", bPlayFeedback, msgId);
504
505         bundle *bundle_data = bundle_create();
506
507         bundle_add_str(bundle_data, "cmd", "insert_ticker");
508         bundle_add_str(bundle_data, "ticker_msg", pTickerMsg);
509         bundle_add_str(bundle_data, "locale_ticker_msg", pLocaleTickerMsg);
510
511         if (bPlayFeedback)
512                 bundle_add_str(bundle_data, "feedback", "true");
513         else
514                 bundle_add_str(bundle_data, "feedback", "false");
515
516         char *msg_id = g_strdup_printf("%d", msgId);
517         if (msg_id) {
518                 bundle_add_str(bundle_data, "msg_id", msg_id);
519                 g_free(msg_id);
520         }
521
522         err = msg_launch_app(MSG_MGR_APP_ID, bundle_data);
523
524         bundle_free(bundle_data);
525 #endif /* MSG_WEARABLE_PROFILE */
526         return err;
527 }
528
529
530 void MsgBootMsgMgr()
531 {
532         bundle *bundle_data = bundle_create();
533
534         bundle_add_str(bundle_data, "cmd", "on_boot");
535
536         msg_launch_app(MSG_MGR_APP_ID, bundle_data);
537
538         bundle_free(bundle_data);
539 }