4 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include "MsgHelper.h"
24 #include "MsgGconfWrapper.h"
25 #include "MsgSettingTypes.h"
26 #include "MsgSoundPlayer.h"
30 /*==================================================================================================
32 ==================================================================================================*/
33 static bool g_bRepeat = false;
34 static alarm_id_t g_alarmId = 0;
37 /*==================================================================================================
38 FUNCTION IMPLEMENTATION
39 ==================================================================================================*/
42 void MsgSoundPlayStart(bool isEmergency)
52 MSG_DEBUG("Failed to fork");
57 MSG_DEBUG("Child Process - Run helper app for Sound");
60 execl("/usr/bin/msg-helper", MSG_EMERGENCY_SOUND_START, NULL);
62 execl("/usr/bin/msg-helper", MSG_NORMAL_SOUND_START, NULL);
64 MSG_DEBUG("Faild to run helper app for Sound");
68 else if (childpid != 0)
70 MSG_DEBUG("Parent Process - Mms Plugin Storage.");
73 if (g_bRepeat == false)
74 g_bRepeat = MsgSoundSetRepeatAlarm();
79 void MsgSoundPlayStop()
89 MSG_DEBUG("Failed to fork");
94 MSG_DEBUG("Child Process - Run helper app for Sound");
96 execl("/usr/bin/msg-helper", MSG_SOUND_STOP, NULL);
98 MSG_DEBUG("Faild to run helper app for Sound");
102 else if (childpid != 0)
104 MSG_DEBUG("Parent Process - Mms Plugin Storage.");
111 bool MsgSoundSetRepeatAlarm()
115 int nRepeatValue = 0;
116 long nRepeatTime = 0;
118 nRepeatValue = MsgSettingGetInt(MSG_ALERT_TONE);
120 switch (nRepeatValue)
122 case MSG_ALERT_TONE_ONCE:
126 case MSG_ALERT_TONE_2MINS:
130 case MSG_ALERT_TONE_5MINS:
134 case MSG_ALERT_TONE_10MINS:
139 MSG_DEBUG("Invalid Repetition time");
143 MSG_DEBUG("nRepeatTime = %d", nRepeatTime);
147 bRet = MsgSoundCreateRepeatAlarm(nRepeatTime);
154 bool MsgSoundCreateRepeatAlarm(int RepeatTime)
159 struct tm current_tm;
163 localtime_r(¤t_time, ¤t_tm);
167 retval = alarmmgr_init("msg-service-tools");
171 MSG_FATAL("alarmmgr_init() error [%d]", retval);
175 alarm_info_t* alarm_info;
176 alarm_date_t target_time;
178 alarm_info = alarmmgr_create_alarm();
180 target_time.year = 0;
181 target_time.month = 0;
184 if (current_tm.tm_min+RepeatTime < 60)
186 target_time.hour = current_tm.tm_hour;
187 target_time.min = current_tm.tm_min+RepeatTime;
191 if (current_tm.tm_hour < 12)
193 target_time.hour = current_tm.tm_hour+1;
197 target_time.hour = (current_tm.tm_hour+1)%12;
200 target_time.min = (current_tm.tm_min+RepeatTime)%60;
203 target_time.sec = current_tm.tm_sec;
205 retval = alarmmgr_set_time(alarm_info, target_time);
206 MSG_DEBUG("alarmmgr_set_time return = [%d]", retval);
207 retval = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, 0);
208 MSG_DEBUG("alarmmgr_set_repeat_mode return = [%d]", retval);
209 retval = alarmmgr_set_type(alarm_info, ALARM_TYPE_VOLATILE);
210 MSG_DEBUG("alarmmgr_set_type return = [%d]", retval);
211 retval = alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &g_alarmId);
212 MSG_DEBUG("alarmmgr_add_alarm_with_localtime return = [%d]", retval);
214 retval = alarmmgr_set_cb(MsgSoundRepeatAlarmCB, (void *)alarm_info);
218 MSG_DEBUG("alarmmgr_set_cb() error [%d]", retval);
222 MSG_DEBUG("Repeat Alarm Time : [%d-%d-%d %d:%d:%d]",
223 target_time.year,target_time.month,target_time.day,
224 target_time.hour, target_time.min, target_time.sec);
232 int MsgSoundRepeatAlarmCB(int TimerId, void *pUserParam)
236 alarm_info_t *alarm_info = (alarm_info_t *)pUserParam;
240 if (MsgSoundGetUnreadMsgCnt() <= 0) {
241 MSG_DEBUG("no unread msg");
243 MsgSoundPlayStart(false);
246 if (alarmmgr_free_alarm(alarm_info) != ALARMMGR_RESULT_SUCCESS)
247 MSG_DEBUG("alarmmgr_free_alarm is failed");
255 int MsgSoundGetUnreadMsgCnt()
260 unreadCnt = MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE);
263 unreadCnt += MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE);
265 MSG_DEBUG("unread count : [%d]", unreadCnt);
270 void MsgSoundInitRepeatAlarm()
274 int nRepeatValue = 0;
275 long nRepeatTime = 0;
279 if (MsgSoundGetUnreadMsgCnt() <= 0) {
280 MSG_DEBUG("no unread msg");
284 nRepeatValue = MsgSettingGetInt(MSG_ALERT_TONE);
286 switch (nRepeatValue)
288 case MSG_ALERT_TONE_ONCE:
292 case MSG_ALERT_TONE_2MINS:
296 case MSG_ALERT_TONE_5MINS:
300 case MSG_ALERT_TONE_10MINS:
305 MSG_DEBUG("Invalid Repetition time");
309 MSG_DEBUG("nRepeatTime = %d", nRepeatTime);
312 MsgSoundPlayStart(false);