Fix session interrupted callback in case of SOUND_SESSION_INTERRUPTED_BY_EARJACK_UNPLUG 21/127121/1 accepted/tizen_3.0_common accepted/tizen_3.0_ivi accepted/tizen_3.0_mobile accepted/tizen_3.0_tv accepted/tizen_3.0_wearable accepted/tizen/3.0/common/20170519.185839 accepted/tizen/3.0/ivi/20170519.065923 accepted/tizen/3.0/mobile/20170519.065902 accepted/tizen/3.0/tv/20170519.065910 accepted/tizen/3.0/wearable/20170519.065916 submit/tizen_3.0/20170517.035640
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 26 Apr 2017 07:58:28 +0000 (16:58 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 26 Apr 2017 07:58:28 +0000 (16:58 +0900)
Added to check pulseaudio stream information whether it invokes user callback or not.
The invoking condition complies with legacy session policy.

[Version] 0.3.113
[Profile] Common
[Issue Type] Backward compatibility

Change-Id: I10bd367ecbc6670a0b9b1dd220ba556d6cb2d846
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/capi-media-sound-manager.spec
src/sound_manager_private.c

index c8be3bbd76aee4e754b4e0b5f5bf4048eb2e109a..75b3f66b6b8c6e7d164948f888a59df55de39ece 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-sound-manager
 Summary:    Sound Manager library
-Version:    0.3.112
+Version:    0.3.113
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index ce8139ee2a8610d035f5215612aa6141bd7cedc2..c7c9b9f17d70c8ca9115e89d07da8f3ade4de1e6 100644 (file)
@@ -31,6 +31,7 @@
 #define PA_STREAM_MANAGER_METHOD_NAME_GET_CURRENT_VOLUME_TYPE   "GetCurrentVolumeType"
 #define PA_STREAM_MANAGER_METHOD_NAME_GET_CURRENT_MEDIA_ROUTING_PATH "GetCurrentMediaRoutingPath"
 #define PA_STREAM_MANAGER_METHOD_NAME_UPDATE_FOCUS_STATUS       "UpdateFocusStatus"
+#define PA_STREAM_MANAGER_METHOD_NAME_CHECK_STREAM_EXIST_BY_PID "CheckStreamExistByPid"
 #define VCONF_PATH_PREFIX_VOLUME                                "file/private/sound/volume/"
 #define VCONF_PATH_MAX                                          64
 
@@ -1248,6 +1249,58 @@ LEAVE:
        return;
 }
 
+static int _check_media_stream_exist_by_pid(unsigned int pid, const char *direction, bool *exist)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant *result = NULL;
+       GDBusConnection *conn = NULL;
+       GError *err = NULL;
+       const gchar *dbus_ret = NULL;
+
+       assert(exist);
+       assert(direction);
+
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (!conn) {
+               LOGE("g_bus_get_sync() error (%s)", err->message);
+               g_error_free(err);
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       result = g_dbus_connection_call_sync(conn,
+                                                       PA_BUS_NAME,
+                                                       PA_STREAM_MANAGER_OBJECT_PATH,
+                                                       PA_STREAM_MANAGER_INTERFACE,
+                                                       PA_STREAM_MANAGER_METHOD_NAME_CHECK_STREAM_EXIST_BY_PID,
+                                                       g_variant_new("(uss)", pid, "media", direction),
+                                                       G_VARIANT_TYPE("(s)"),
+                                                       G_DBUS_CALL_FLAGS_NONE,
+                                                       2000,
+                                                       NULL,
+                                                       &err);
+       if (!result) {
+               LOGE("g_dbus_connection_call_sync() for CHECK_STREAM_EXIST_BY_PID error (%s)", err->message);
+               g_error_free(err);
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto LEAVE;
+       }
+
+       g_variant_get(result, "(&s)", &dbus_ret);
+       LOGI("g_dbus_connection_call_sync() success, method return value is (%s)", dbus_ret);
+       if (!strncmp("STREAM_MANAGER_RETURN_OK", dbus_ret, strlen(dbus_ret)))
+               *exist = true;
+       else if (!strncmp("STREAM_MANAGER_RETURN_ERROR_NO_STREAM", dbus_ret, strlen(dbus_ret)))
+               *exist = false;
+       else
+               ret = MM_ERROR_SOUND_INTERNAL;
+
+       g_variant_unref(result);
+LEAVE:
+       g_object_unref(conn);
+
+       return ret;
+}
+
 void _focus_session_interrupt_cb(mm_sound_focus_state_e state, const char *reason, void *user_data)
 {
        sound_session_interrupted_code_e e;
@@ -1311,8 +1364,22 @@ void _device_connected_cb(sound_device_h device, bool is_connected, void *user_d
        case MM_SOUND_DEVICE_TYPE_MIRRORING:
        case MM_SOUND_DEVICE_TYPE_USB_AUDIO:
                if (!is_connected) {
-                       LOGI("sound device unplugged");
-                       g_session_interrupt_cb_table.user_cb(SOUND_SESSION_INTERRUPTED_BY_EARJACK_UNPLUG, g_session_interrupt_cb_table.user_data);
+                       bool stream_exist = false;
+                       LOGI("sound device(%d) is unplugged", type);
+                       if (!_check_media_stream_exist_by_pid(getpid(), "out", &stream_exist)) {
+                               if (stream_exist) {
+                                       LOGI("invoke user_cb(%p) for interrupted_by_earjack_unplug", g_session_interrupt_cb_table.user_cb);
+                                       g_session_interrupt_cb_table.user_cb(SOUND_SESSION_INTERRUPTED_BY_EARJACK_UNPLUG, g_session_interrupt_cb_table.user_data);
+                               }
+                               break;
+                       }
+                       if (!_check_media_stream_exist_by_pid(getpid(), "in", &stream_exist)) {
+                               if (stream_exist) {
+                                       LOGI("invoke user_cb(%p) for interrupted_by_earjack_unplug", g_session_interrupt_cb_table.user_cb);
+                                       g_session_interrupt_cb_table.user_cb(SOUND_SESSION_INTERRUPTED_BY_EARJACK_UNPLUG, g_session_interrupt_cb_table.user_data);
+                               }
+                               break;
+                       }
                }
                break;
        default: