system-cooperator : exchange direct sound play with feedback play 33/98333/1
authorGiyeol Ok <giyeol.ok@samsung.com>
Thu, 17 Nov 2016 05:57:34 +0000 (14:57 +0900)
committerGiyeol Ok <giyeol.ok@samsung.com>
Thu, 17 Nov 2016 06:00:45 +0000 (15:00 +0900)
feedback support sound play for charger connection
so we dont need direct sound play, and also feedback play need time delay until feedback deinit
so move feedback deinit into the timer expire logic

Signed-off-by: Giyeol Ok <giyeol.ok@samsung.com>
Change-Id: Ib16d785cf0e1f1609cbdca42442842381c328cae

system-cooperator/system-cooperator.c

index f0fdb873c7eee602ad112b1d6a6a018c6f42cea6..df4d77ae1e8d2a798f8f086ae5bdabf7f112a091 100755 (executable)
 #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"
@@ -36,9 +32,7 @@
 #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,
@@ -56,7 +50,8 @@ enum sound_status {
        MUTE,
 };
 
-static GMainLoop *loop = NULL;
+static guint noti_timer;
+static GMainLoop *loop;
 static int loop_type = LOOP_ERROR;
 
 static void quit_main_loop(ltype)
@@ -85,85 +80,37 @@ static int get_sound_state(void)
        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;
 }
 
@@ -171,7 +118,7 @@ static int app_create(int type)
 {
        switch (type) {
        case CHARGER_CONNECTION:
-               return play_battery_sound();
+               return play_notification(type, FEEDBACK_PATTERN_CHARGERCONN);
        default:
                _E("Unknown type(%d)", type);
                return -EINVAL;