54d27208e6909ef0e31a451b9b52faf5ddd35128
[platform/core/messaging/msg-service.git] / externals / MsgSoundPlayer.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 #include <wait.h>
18
19 #include "MsgCallStatusManager.h"
20 #include "MsgDebug.h"
21 #include "MsgCppTypes.h"
22 #include "MsgGconfWrapper.h"
23 #include "MsgSettingTypes.h"
24 #include "MsgDrmWrapper.h"
25 #include "MsgSensorWrapper.h"
26 #include "MsgUtilFile.h"
27 #include "MsgStorageTypes.h"
28 #include "MsgContact.h"
29 #include "MsgAlarm.h"
30 #include "MsgNotificationWrapper.h"
31 #include "MsgSoundPlayer.h"
32
33 #ifndef MSG_WEARABLE_PROFILE
34
35 #ifdef _USE_MM_FW_
36 #include <mm_error.h>
37 #include <mm_player.h>
38 #include <mm_session_private.h>
39 #include <mm_sound.h>
40 #endif
41
42 #include <feedback.h>
43 #include <feedback-internal.h>
44
45 /*==================================================================================================
46                                     DEFINES
47 ==================================================================================================*/
48 #define MAX_SOUND_FILE_LEN 1024
49
50 #define DEFAULT_ALERT_FILE              "/opt/usr/share/settings/Alerts/Whistle.ogg"
51
52 #define HAPTIC_TEST_ITERATION 1
53 #define MSG_VIBRATION_INTERVAL 3000
54 #define MSG_SOUND_TIMEOUT 5500
55
56
57 /*==================================================================================================
58                                      VARIABLES
59 ==================================================================================================*/
60 #ifdef _USE_MM_FW_
61 MMHandleType hPlayerHandle = 0;
62 #endif
63
64 pthread_mutex_t muMmPlay = PTHREAD_MUTEX_INITIALIZER;
65
66 #endif /* MSG_WEARABLE_PROFILE */
67
68 /*==================================================================================================
69                                      IMPLEMENTATION OF Functions
70 ==================================================================================================*/
71 void MsgSoundRepeatAlarmCB(int alarmId)
72 {
73         MSG_BEGIN();
74
75 #ifndef MSG_WEARABLE_PROFILE
76
77         MsgSoundPlayer::instance()->MsgSoundInitRepeatAlarm();
78
79 #endif /* MSG_WEARABLE_PROFILE */
80
81         MSG_END();
82         return;
83 }
84
85
86 void MsgSensorCBStop()
87 {
88         MSG_BEGIN();
89
90 #ifndef MSG_WEARABLE_PROFILE
91
92 #if 0
93         MsgSoundPlayer::instance()->MsgSoundPlayStop();
94 #else
95         MsgDeleteNotification(MSG_NOTI_TYPE_ALL, -1);
96
97         MsgRefreshNotification(MSG_NOTI_TYPE_ALL, false, MSG_ACTIVE_NOTI_TYPE_NONE);
98
99 #ifndef MSG_NOTI_INTEGRATION
100         MsgRefreshNotification(MSG_NOTI_TYPE_SIM, false, MSG_ACTIVE_NOTI_TYPE_NONE);
101 #endif
102
103 #endif
104
105 #endif /* MSG_WEARABLE_PROFILE */
106
107         MSG_END();
108 }
109
110 /*
111 static gboolean MsgSoundMelodyTimeout(gpointer data)
112 {
113         MSG_BEGIN();
114
115         MsgSoundPlayer::instance()->MsgSoundPlayStop();
116
117         MSG_END();
118
119         return FALSE;
120 }
121 */
122
123 #if 0
124 static int MsgSoundPlayCallback(int message, void *param, void *user_param)
125 {
126 #ifdef _USE_MM_FW_
127 #ifndef MSG_WEARABLE_PROFILE
128         switch (message) {
129         case MM_MESSAGE_BEGIN_OF_STREAM:
130                 MSG_DEBUG("Play is started.");
131                 break;
132         case MM_MESSAGE_END_OF_STREAM:
133         case MM_MESSAGE_STATE_INTERRUPTED:
134                 MSG_DEBUG("EOS or Interrupted.");
135                 MsgSoundPlayer::instance()->MsgSoundPlayStop();
136                 break;
137         case MM_MESSAGE_FILE_NOT_SUPPORTED:
138         case MM_MESSAGE_FILE_NOT_FOUND:
139         case MM_MESSAGE_DRM_NOT_AUTHORIZED:
140         case MM_MESSAGE_ERROR:
141                 MSG_DEBUG("message [%d] & play with default", message);
142                 MsgSoundPlayer::instance()->MsgSoundPlayStart(NULL, MSG_SOUND_PLAY_DEFAULT);
143                 break;
144         default:
145                 MSG_DEBUG("message [%d]", message);
146                 break;
147         }
148 #endif /* MSG_WEARABLE_PROFILE */
149 #endif
150         return 1;
151 }
152 #endif
153
154 /*==================================================================================================
155                                      IMPLEMENTATION OF MsgSoundPlayer - Member Functions
156 ==================================================================================================*/
157 MsgSoundPlayer* MsgSoundPlayer::pInstance = NULL;
158
159
160 MsgSoundPlayer::MsgSoundPlayer()
161 {
162 #ifdef _USE_MM_FW_
163 #ifndef MSG_WEARABLE_PROFILE
164         bPlaying = false;
165         bVibrating = false;
166         bFeedbackInit = false;
167         g_alarmId = 0;
168
169         defaultRingtonePath = NULL;
170
171         defaultRingtonePath = MsgSettingGetString(VCONFKEY_SETAPPL_NOTI_RINGTONE_DEFAULT_PATH_STR);
172
173         if (defaultRingtonePath == NULL || MsgGetFileSize(defaultRingtonePath) < 1) {
174                 defaultRingtonePath = (char *)DEFAULT_ALERT_FILE;
175         }
176
177         MSG_DEBUG("defaultRingtonePath [%s]", defaultRingtonePath);
178
179         if (MsgSensorConnect() == MSG_SUCCESS) {
180                 if (MsgRegSensorCB(&MsgSensorCBStop) != MSG_SUCCESS) {
181                         MSG_DEBUG("Fail to MsgRegSensorCB.");
182                         MsgSensorDisconnect();
183                 }
184         } else {
185                 MSG_DEBUG("Fail to MsgSensorConnect.");
186         }
187 #endif /* MSG_WEARABLE_PROFILE */
188 #endif
189 }
190
191
192 MsgSoundPlayer::~MsgSoundPlayer()
193 {
194 }
195
196
197 MsgSoundPlayer* MsgSoundPlayer::instance()
198 {
199         if (!pInstance) {
200                 MSG_DEBUG("pInstance is NULL. Now creating instance.");
201                 pInstance = new MsgSoundPlayer();
202         }
203
204         return pInstance;
205 }
206
207
208 void MsgSoundPlayer::MsgGetRingtonePath(char *userRingtonePath, char **msg_tone_file_path_p)
209 {
210 #ifndef MSG_WEARABLE_PROFILE
211         MSG_RINGTONE_TYPE_T ringtoneType = (MSG_RINGTONE_TYPE_T)MsgSettingGetInt(MSG_SETTING_RINGTONE_TYPE);
212
213         MSG_DEBUG("Ringtone type = [%d]", ringtoneType);
214
215         if (ringtoneType == MSG_RINGTONE_TYPE_SILENT) {
216                 *msg_tone_file_path_p = NULL;
217                 return;
218         }
219
220         char *tmpFilePath = NULL;
221         *msg_tone_file_path_p = new char[MSG_FILEPATH_LEN_MAX+1];
222
223         char *msg_tone_file_path = *msg_tone_file_path_p;
224
225         bool bUserRingtone = userRingtonePath && userRingtonePath[0] != '\0';
226         if (bUserRingtone) {
227                 tmpFilePath = userRingtonePath;
228         } else {
229                 if (ringtoneType == MSG_RINGTONE_TYPE_DEFAULT) {
230                         tmpFilePath = MsgSettingGetString(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR);
231                 } else {
232                         tmpFilePath = MsgSettingGetString(MSG_SETTING_RINGTONE_PATH);
233                 }
234         }
235
236         memset(msg_tone_file_path, 0x00, sizeof(char)*(MSG_FILEPATH_LEN_MAX+1));
237
238         if ((tmpFilePath == NULL || MsgGetFileSize(tmpFilePath) < 1) || /* wrong ringtone file path */
239                         (MsgDrmIsDrmFile(tmpFilePath) && !MsgDrmCheckRingtone(tmpFilePath))) { /* check DRM */
240                 if (tmpFilePath && (strcmp(tmpFilePath, "silent") == 0)) {
241                         MSG_DEBUG("Set ringtone to NONE(Silent)");
242                         msg_tone_file_path = NULL;
243                 } else {
244                         MSG_DEBUG("Set ringtone to defaultRingtonePath.");
245                         strncpy(msg_tone_file_path, defaultRingtonePath, MSG_FILEPATH_LEN_MAX);
246                 }
247         } else {
248                 MSG_DEBUG("Set ringtone to tmpFilePath.");
249                 snprintf(msg_tone_file_path, MSG_FILEPATH_LEN_MAX, "%s", tmpFilePath);
250         }
251
252         if (tmpFilePath && !bUserRingtone) {
253                 free(tmpFilePath);
254                 tmpFilePath = NULL;
255         }
256 #endif /* MSG_WEARABLE_PROFILE */
257 }
258
259 #ifndef MSG_WEARABLE_PROFILE
260 void MsgSoundPlayer::MsgGetPlayStatus(bool bOnCall, bool bSound, bool bVibration, bool bMsgSound, bool bMsgVibration, bool *bPlaySound, bool *bPlayVibration)
261 {
262         MSG_BEGIN();
263
264         /* samsung basic concept : feedback should follow profile setting.
265          * And if notification setting exist in msg app, then apply it prior to profile when profile either sound or vibration.
266          * But, Play sound when profile is vibration during call, if device does not support haptic */
267         if (bSound || bVibration) {
268                 bool bHantic_device = false;
269 #ifdef FEATURE_HAPTIC_ENABLE
270                 bHantic_device = true;
271 #endif
272                 if (bHantic_device || (bOnCall == false)) {
273                         if (bSound) {
274                                 if (bMsgSound) {
275                                         MSG_DEBUG("Play sound.");
276                                         *bPlaySound = true;
277                                 }
278
279                                 if (bMsgVibration) {
280                                         MSG_DEBUG("Play vibration.");
281                                         *bPlayVibration = true;
282                                 }
283                         } else {
284                                 if (bMsgVibration) {
285                                         MSG_DEBUG("Play vibration.");
286                                         *bPlayVibration = true;
287                                 }
288                         }
289                 } else { /* during call */
290                         if (bMsgSound || bMsgVibration) {
291                                 MSG_DEBUG("Play sound.");
292                                 *bPlaySound = true;
293                         }
294                 }
295         }
296 }
297 #endif /* MSG_WEARABLE_PROFILE */
298
299 void MsgSoundPlayer::MsgGetPlayStatus(bool bVoiceMail, bool *bPlaySound, bool *bPlayVibration, bool *bOnCall)
300 {
301         MSG_BEGIN();
302
303 #ifndef MSG_WEARABLE_PROFILE
304
305         if (!bPlaySound || !bPlayVibration || !bOnCall) {
306                 MSG_DEBUG("IN parameter is NULL.");
307                 return;
308         }
309
310         *bPlaySound = false;
311         *bPlayVibration = false;
312         *bOnCall = false;
313
314         /* Global setting */
315         bool bSoundOn = false; /* sound setting on notification panel */
316         bool bVibrationOn = false; /* vibration setting on notification panel */
317
318         MsgSettingGetBool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &bSoundOn);
319         MsgSettingGetBool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &bVibrationOn);
320
321         /* Alert setting */
322 #if 0   /* not used value */
323         bool bNotiVibrationOn = false; /* alert vibration */
324         MsgSettingGetBool(VCONFKEY_SETAPPL_VIBRATE_WHEN_NOTIFICATION_BOOL, &bNotiVibrationOn);
325 #endif
326
327         bool bMsgSettingNoti = true; /* Alert for message notification */
328         bool bMsgSettingVibration = false; /* vibration for message notification */
329
330         MSG_RINGTONE_TYPE_T ringtoneType = MSG_RINGTONE_TYPE_DEFAULT; /*sound type for message notification */
331         bool bMsgSettingSound = true;
332
333         MsgSettingGetBool(MSG_SETTING_VIBRATION, &bMsgSettingVibration);
334         MsgSettingGetBool(MSG_SETTING_NOTIFICATION, &bMsgSettingNoti);
335         ringtoneType = (MSG_RINGTONE_TYPE_T)MsgSettingGetInt(MSG_SETTING_RINGTONE_TYPE);
336         if (ringtoneType == MSG_RINGTONE_TYPE_SILENT)
337                 bMsgSettingSound = false;
338
339         MSG_SEC_DEBUG("Sound status : Sound mode[%d], Manner mode[%d]", bSoundOn, bVibrationOn);
340         MSG_SEC_DEBUG("Msg Setting : Noti Alert[%d], vibration[%d], sound[%d], ringtoneType[%d]", bMsgSettingNoti, bMsgSettingVibration, bMsgSettingSound, ringtoneType);
341
342         int callStatus = 0;
343 /*      int alertOnCall = 0; */
344
345         callStatus = MsgGetCallStatus();
346         MSG_DEBUG("Call Status [%d]", callStatus);
347
348         /* Check call status */
349         if (callStatus > 0 && callStatus < 3) {
350                 /* 1. On Call */
351                 *bOnCall = true; /* set call status; */
352         } else {
353                 /* 2. Call is not active */
354
355                 MSG_DEBUG("Call is not active.");
356                 int voiceRecording = MsgSettingGetInt(VCONFKEY_RECORDER_STATE);
357
358                 if (bVoiceMail) {       /* 2-1. Voice message */
359                         if (bMsgSettingNoti) {
360                                 MsgGetPlayStatus(false, bSoundOn, bVibrationOn, bMsgSettingSound, bMsgSettingVibration, bPlaySound, bPlayVibration);
361
362                         } else {
363                                 MSG_DEBUG("It doesn't play sound/vibration - voice message.");
364                         }
365                 } else {        /* 2-1. Normal message */
366                         if (bMsgSettingNoti) {
367                                 if (voiceRecording != VCONFKEY_RECORDER_STATE_RECORDING) {
368                                         MsgGetPlayStatus(false, bSoundOn, bVibrationOn, bMsgSettingSound, bMsgSettingVibration, bPlaySound, bPlayVibration);
369                                 } else {
370                                         MSG_DEBUG("It doesn't play sound/vibration.");
371                                 }
372                         } else {
373                                 MSG_DEBUG("It doesn't play sound/vibration.");
374                         }
375                 }
376         }
377
378 #endif /* MSG_WEARABLE_PROFILE */
379
380         MSG_END();
381 }
382
383
384 void MsgSoundPlayer::MsgSoundPlayStart(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_SOUND_TYPE_T soundType)
385 {
386         MSG_BEGIN();
387 #ifdef _USE_MM_FW_
388 #ifndef MSG_WEARABLE_PROFILE
389
390         MSG_DEBUG("soundType [%d]", soundType);
391
392         /* check camera state */
393         int cameraState = 0;    /* camera recording state */
394         cameraState = MsgSettingGetInt(VCONFKEY_CAMERA_STATE);
395         MSG_SEC_DEBUG("Camera state [%d]", cameraState);
396
397         if (cameraState == VCONFKEY_CAMERA_STATE_RECORDING) {
398                 MSG_END();
399                 return;
400         }
401
402 /* contacts-service is not used for gear */
403 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
404         /* get contact information */
405         MSG_CONTACT_INFO_S contactInfo;
406         memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
407
408         if (pAddrInfo) {
409                 /* Get Contact Info */
410                 if (MsgGetContactInfo(pAddrInfo, &contactInfo) != MSG_SUCCESS) {
411                         MSG_DEBUG("MsgGetContactInfo() fail.");
412                 }
413         }
414 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
415         /* get ringtone file path */
416         char *msg_tone_file_path = NULL;
417         unique_ptr<char*, void(*)(char**)> buf(&msg_tone_file_path, unique_ptr_deleter);
418
419         if (soundType == MSG_SOUND_PLAY_EMERGENCY) {
420                 msg_tone_file_path = new char[MAX_SOUND_FILE_LEN+1];
421                 memset(msg_tone_file_path, 0x00, sizeof(char)*(MAX_SOUND_FILE_LEN+1));
422         } else if (soundType == MSG_SOUND_PLAY_DEFAULT) {
423                 msg_tone_file_path = new char[MAX_SOUND_FILE_LEN+1];
424                 memset(msg_tone_file_path, 0x00, sizeof(char)*(MAX_SOUND_FILE_LEN+1));
425                 strncpy(msg_tone_file_path, DEFAULT_ALERT_FILE, MAX_SOUND_FILE_LEN);
426         }
427 /* contacts-service is not used for gear */
428 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
429         else {
430                 MsgGetRingtonePath(contactInfo.alerttonePath, &msg_tone_file_path);
431         }
432 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
433         MSG_SEC_DEBUG("soundType [%d], Sound File [%s]", soundType, msg_tone_file_path);
434
435         /* get sound play status */
436         bool bPlaySound = false;
437         bool bPlayVibration = false;
438         bool bVoiceMsg = (soundType == MSG_SOUND_PLAY_VOICEMAIL)?true:false;
439         bool bOnCall = false;
440
441         MsgGetPlayStatus(bVoiceMsg, &bPlaySound, &bPlayVibration, &bOnCall);
442
443         MSG_SEC_DEBUG("sound=[%d], vibration=[%d], voice_msg?[%d], on_call?[%d]",
444                         bPlaySound, bPlayVibration, bVoiceMsg, bOnCall);
445
446         /* play sound */
447         if (bPlaySound) {
448                 int err = MM_ERROR_NONE;
449
450                 if (soundType == MSG_SOUND_PLAY_EMERGENCY)
451                         err = mm_session_init(MM_SESSION_TYPE_EMERGENCY);
452                 else
453                         err = mm_session_init(MM_SESSION_TYPE_NOTIFY);
454
455                 if (err != MM_ERROR_NONE)
456                         MSG_DEBUG("MM Session Init Failed");
457                 else
458                         MSG_DEBUG("MM Session Init Success : %d", err);
459
460
461                 MsgSoundPlayMelody(msg_tone_file_path);
462
463                 err = mm_session_finish();
464
465                 if (err != MM_ERROR_NONE)
466                         MSG_DEBUG("MM Session Finish Failed.");
467                 else
468                         MSG_DEBUG("MM Session Finish Success : %d", err);
469         }
470
471 /* contacts-service is not used for gear */
472 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
473         /* play vibration */
474         if (bPlayVibration) {
475                 MsgSoundPlayVibration(contactInfo.vibrationPath);
476         }
477 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
478
479         /* For repeatition. */
480 /*      MsgSoundSetRepeatAlarm(); */
481
482 #endif /* MSG_WEARABLE_PROFILE */
483 #endif
484         MSG_END();
485 }
486
487
488 void MsgSoundPlayer::MsgSoundPlayStop()
489 {
490         MSG_BEGIN();
491 #ifdef _USE_MM_FW_
492 #ifndef MSG_WEARABLE_PROFILE
493
494         pthread_mutex_lock(&muMmPlay);
495
496         if (bPlaying == true && hPlayerHandle != 0) {
497                 MSG_DEBUG("stopping the player.");
498                 /* Stop playing media contents */
499                 int err = mm_player_stop(hPlayerHandle);
500
501                 if (err != MM_ERROR_NONE)
502                         MSG_DEBUG("stopping the player handle failed");
503         }
504
505         if (hPlayerHandle != 0) {
506                 MSG_DEBUG("destroy the player.");
507
508                 /* Uninitializing the player module */
509                 mm_player_unrealize(hPlayerHandle);
510
511                 /* Destroying the player handle */
512                 mm_player_destroy(hPlayerHandle);
513         }
514
515         hPlayerHandle = 0;
516         bPlaying = false;
517
518         pthread_mutex_unlock(&muMmPlay);
519
520 #endif /* MSG_WEARABLE_PROFILE */
521 #endif
522         MSG_END();
523 }
524
525
526 void MsgSoundPlayer::MsgSoundPlayMelody(char *pMsgToneFilePath)
527 {
528 #ifndef MSG_WEARABLE_PROFILE
529 #ifdef _USE_MM_FW_
530         int err = MM_ERROR_NONE;
531
532         if (!pMsgToneFilePath) {
533                 MSG_DEBUG("Ringtone path is NULL");
534                 return;
535         }
536
537         pthread_mutex_lock(&muMmPlay);
538
539         if (hPlayerHandle != 0) {
540                 mm_player_unrealize(hPlayerHandle);
541                 mm_player_destroy(hPlayerHandle);
542                 hPlayerHandle = 0;
543         }
544
545         err = mm_player_create(&hPlayerHandle);
546
547         pthread_mutex_unlock(&muMmPlay);
548
549         if (err != MM_ERROR_NONE) {
550                 MSG_DEBUG("creating the player handle failed");
551                 return;
552         }
553
554         /* Setting the call back function msg_callback */
555         mm_player_set_message_callback(hPlayerHandle, MsgSoundPlayCallback, NULL);
556
557         do {
558                 /* Setting fade in/out, Volume */
559                 err = mm_player_set_attribute(hPlayerHandle, NULL,
560                                 "sound_volume_type", MM_SOUND_VOLUME_TYPE_NOTIFICATION,
561                                 "profile_uri", pMsgToneFilePath, strlen(pMsgToneFilePath),
562                                 "sound_priority", 2,
563                                 NULL);
564
565                 if (err != MM_ERROR_NONE)
566                         MSG_DEBUG("error setting the profile attr [%d]", err);
567
568                 err = mm_player_realize(hPlayerHandle);
569
570                 if (err != MM_ERROR_NONE) {
571                         MSG_DEBUG("mm_player_realize() error : [%d]", err);
572                         if (pMsgToneFilePath != defaultRingtonePath) {
573                                 pMsgToneFilePath = defaultRingtonePath;
574                         } else {
575                                 return;
576                         }
577                 }
578         } while (err != MM_ERROR_NONE);
579
580
581         pthread_mutex_lock(&muMmPlay);
582         MSG_DEBUG("mm_player_start with [%s]", pMsgToneFilePath);
583         err = mm_player_start(hPlayerHandle);
584
585         if (err != MM_ERROR_NONE) {
586                 MSG_DEBUG("mm_player_start, FAIL [%x]", err);
587         } else {
588                 /* Add Timer to stop playing after 5 sec. */
589                 /*
590                 int g_contact_timer = -1;
591                 g_contact_timer = g_timeout_add(MSG_SOUND_TIMEOUT, (GSourceFunc)MsgSoundMelodyTimeout, NULL);
592                 */
593
594                 bPlaying = true;
595         }
596         pthread_mutex_unlock(&muMmPlay);
597
598 #endif /* MSG_WEARABLE_PROFILE */
599 #endif
600 }
601
602
603 void MsgSoundPlayer::MsgSoundPlayVibration(char *vibrationPath)
604 {
605         MSG_BEGIN();
606
607 #ifndef MSG_WEARABLE_PROFILE
608
609         int ret = 0;
610
611         if (!bFeedbackInit) {
612                 int ret = feedback_initialize();
613
614                 if (ret != FEEDBACK_ERROR_NONE) {
615                         MSG_DEBUG("Fail to feedback_initialize : [%d]", ret);
616                         bFeedbackInit = false;
617                         return;
618                 } else {
619                         MSG_DEBUG("Success to feedback_initialize.");
620                         bFeedbackInit = true;
621                 }
622         }
623
624         if (vibrationPath && strlen(vibrationPath)) {
625                 MSG_DEBUG("vibrationPath: [%s]", vibrationPath);
626                 ret = feedback_set_resource_path(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE, vibrationPath);
627                 if (ret != FEEDBACK_ERROR_NONE)
628                         MSG_DEBUG("Fail to feedback_set_resource_path");
629                 ret = feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE);
630
631                 if (ret != FEEDBACK_ERROR_NONE)
632                         MSG_DEBUG("Fail to feedback_play_type");
633         } else {
634                 ret = feedback_set_resource_path(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE, NULL);
635                 if (ret != FEEDBACK_ERROR_NONE)
636                         MSG_DEBUG("Fail to feedback_set_resource_path");
637
638                 ret = feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE);
639                 if (ret != FEEDBACK_ERROR_NONE)
640                         MSG_DEBUG("Fail to feedback_play_type");
641         }
642
643 #endif /* MSG_WEARABLE_PROFILE */
644
645         MSG_END();
646 }
647
648 void MsgSoundPlayer::MsgSoundPlayDtmf()
649 {
650         MSG_BEGIN();
651 #ifdef _USE_MM_FW_
652 #ifndef MSG_WEARABLE_PROFILE
653
654         int ret = 0;
655         int hToneHandle = 0;
656
657         ret = mm_sound_play_tone(MM_SOUND_TONE_PROP_BEEP2, VOLUME_TYPE_SYSTEM, 1.0, 300, &hToneHandle);
658
659         if (ret < 0) {
660                 MSG_DEBUG("play tone failed.");
661         } else {
662                 MSG_DEBUG("play tone success.");
663         }
664
665 #endif /* MSG_WEARABLE_PROFILE */
666 #endif
667         MSG_END();
668 }
669
670
671 void MsgSoundPlayer::MsgSoundSetRepeatAlarm()
672 {
673 #ifndef MSG_WEARABLE_PROFILE
674
675         int nRepeatValue = 0;
676         long    nRepeatTime = 0;
677
678         nRepeatValue = MsgSettingGetInt(MSG_ALERT_REP_TYPE);
679
680         switch (nRepeatValue) {
681         case MSG_ALERT_TONE_ONCE:
682                 nRepeatTime = 0;
683                 break;
684
685         case MSG_ALERT_TONE_2MINS:
686                 nRepeatTime = 2;
687                 break;
688
689         case MSG_ALERT_TONE_5MINS:
690                 nRepeatTime = 5;
691                 break;
692
693         case MSG_ALERT_TONE_10MINS:
694                 nRepeatTime = 10;
695                 break;
696
697         default:
698                 MSG_DEBUG("Invalid Repetition time");
699                 break;
700         }
701
702         MSG_DEBUG("nRepeatTime = %d", nRepeatTime);
703
704         if (nRepeatTime > 0) {
705                 if (g_alarmId > 0) {
706                         if (MsgAlarmRemove(g_alarmId) != MSG_SUCCESS)
707                                 MSG_FATAL("MsgAlarmRemove fail.");
708
709                         g_alarmId = 0;
710                 }
711                 MsgSoundCreateRepeatAlarm(nRepeatTime);
712         }
713
714 #endif /* MSG_WEARABLE_PROFILE */
715 }
716
717
718 void MsgSoundPlayer::MsgSoundCreateRepeatAlarm(int RepeatTime)
719 {
720         MSG_BEGIN();
721
722 #ifndef MSG_WEARABLE_PROFILE
723
724         int alarmId = 0;
725         time_t tmp_time;
726         struct tm repeat_tm;
727
728         time(&tmp_time);
729
730         tmp_time += (RepeatTime*60);
731         tzset();
732         localtime_r(&tmp_time, &repeat_tm);
733
734         if (MsgAlarmRegistration(&repeat_tm, MsgSoundRepeatAlarmCB, &alarmId) != MSG_SUCCESS) {
735                 MSG_DEBUG("MsgAlarmRegistration fail.");
736                 return;
737         }
738
739         g_alarmId = alarmId;
740         MSG_DEBUG("Set g_alarmId to [%d]", alarmId);
741
742         MSG_END();
743
744 #endif /* MSG_WEARABLE_PROFILE */
745 }
746
747
748 int MsgSoundPlayer::MsgSoundGetUnreadMsgCnt()
749 {
750         int unreadCnt = 0;
751
752 #ifndef MSG_WEARABLE_PROFILE
753
754         /* Get SMS Count */
755         unreadCnt = MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE);
756
757         /* Get MMS Count */
758         unreadCnt += MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE);
759
760         MSG_DEBUG("unread count : [%d]", unreadCnt);
761
762 #endif /* MSG_WEARABLE_PROFILE */
763
764         return unreadCnt;
765 }
766
767 void MsgSoundPlayer::MsgSoundInitRepeatAlarm()
768 {
769         MSG_BEGIN();
770
771 #ifndef MSG_WEARABLE_PROFILE
772
773         int nRepeatValue = 0;
774         long    nRepeatTime = 0;
775
776         g_alarmId = 0;
777
778         if (MsgSoundGetUnreadMsgCnt() <= 0) {
779                 MSG_DEBUG("no unread msg");
780                 return;
781         }
782
783         nRepeatValue = MsgSettingGetInt(MSG_ALERT_REP_TYPE);
784
785         switch (nRepeatValue) {
786         case MSG_ALERT_TONE_ONCE:
787                 nRepeatTime = 0;
788                 break;
789
790         case MSG_ALERT_TONE_2MINS:
791                 nRepeatTime = 2;
792                 break;
793
794         case MSG_ALERT_TONE_5MINS:
795                 nRepeatTime = 5;
796                 break;
797
798         case MSG_ALERT_TONE_10MINS:
799                 nRepeatTime = 10;
800                 break;
801
802         default:
803                 MSG_DEBUG("Invalid Repetition time");
804                 break;
805         }
806
807         MSG_DEBUG("nRepeatTime = %d", nRepeatTime);
808
809         if (nRepeatTime > 0)
810                 MsgSoundPlayStart(NULL, MSG_SOUND_PLAY_USER);
811
812 #endif /* MSG_WEARABLE_PROFILE */
813
814         MSG_END();
815 }