#include <Ecore.h>
#include <glib.h>
#include <dlog.h>
-#include <wav_player.h>
-#include <sound_manager.h>
#include <vconf.h>
#include <feedback.h>
-#include <appcore-common.h>
-#include <recorder.h>
#undef LOG_TAG
#define LOG_TAG "SYSTEM_APPS"
#define _E(fmt, args...) SLOGE(fmt, ##args)
#define _I(fmt, args...) SLOGI(fmt, ##args)
-#define CHARGER_TIMEOUT 2000 /* Milliseconds */
-
-#define CHARGER_CONNECTION_PATH "/usr/share/feedback/sound/operation/operation.wav"
+#define NOTI_TIMEOUT 2000 /* Milliseconds */
enum service_type {
CHARGER_CONNECTION,
MUTE,
};
-static GMainLoop *loop = NULL;
+static guint noti_timer;
+static GMainLoop *loop;
static int loop_type = LOOP_ERROR;
static void quit_main_loop(ltype)
return MUTE;
}
-static bool get_call_state(void)
-{
- int state;
- if (vconf_get_int(VCONFKEY_CALL_STATE, &state) == 0
- && state != VCONFKEY_CALL_OFF)
- return true;
- return false;
-}
-
-static bool get_voice_recording_state(void)
-{
- recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
-
- if (recorder_get_device_state(RECORDER_TYPE_AUDIO, &state) == 0
- && (state == RECORDER_DEVICE_STATE_RECORDING))
- return true;
- return false;
-}
-
-static void play_completed(int id, void *data)
-{
- quit_main_loop(loop_type);
-}
-
static gboolean time_expired(gpointer data)
{
+ feedback_deinitialize();
quit_main_loop(loop_type);
return FALSE;
}
-static void play_notification_sound(void)
-{
- int ret;
- static bool session = false;
-
- if (access(CHARGER_CONNECTION_PATH, F_OK) != 0) {
- _E("The sound file does not exist (%d)", CHARGER_CONNECTION_PATH);
- return;
- }
-
- if (!session) {
- ret = sound_manager_set_session_type(SOUND_SESSION_TYPE_NOTIFICATION);
- if (ret != SOUND_MANAGER_ERROR_NONE) {
- _E("Failed to set session to play sound(%d)", ret);
- return;
- }
- }
-
- ret = wav_player_start(CHARGER_CONNECTION_PATH, SOUND_TYPE_NOTIFICATION, play_completed, NULL, NULL);
- if (ret != WAV_PLAYER_ERROR_NONE)
- _E("Failed to play sound file (%d, %s)", ret, CHARGER_CONNECTION_PATH);
-}
-
-static void play_feedback(int pattern)
+static void play_feedback(int type, int pattern)
{
feedback_initialize();
- feedback_play_type(FEEDBACK_TYPE_VIBRATION, pattern);
- feedback_deinitialize();
+ feedback_play_type(type, pattern);
}
-static int play_battery_sound(void)
+static int play_notification(int type, int pattern)
{
- int sound;
+ int sound_type;
- sound = get_sound_state();
- switch (sound) {
+ sound_type = get_sound_state();
+ switch (sound_type) {
case SOUND:
- if (!get_call_state() && !get_voice_recording_state()) {
- play_notification_sound();
- break;
- }
+ play_feedback(FEEDBACK_TYPE_SOUND, pattern);
+ break;
case VIBRATION:
- play_feedback(FEEDBACK_PATTERN_CHARGERCONN);
+ play_feedback(FEEDBACK_TYPE_VIBRATION, pattern);
break;
- case MUTE:
default:
break;
}
- g_timeout_add(CHARGER_TIMEOUT, time_expired, NULL);
+ if (noti_timer > 0)
+ g_source_remove(noti_timer);
+ noti_timer = g_timeout_add(NOTI_TIMEOUT, time_expired, NULL);
return 0;
}
{
switch (type) {
case CHARGER_CONNECTION:
- return play_battery_sound();
+ return play_notification(type, FEEDBACK_PATTERN_CHARGERCONN);
default:
_E("Unknown type(%d)", type);
return -EINVAL;