}
if (g_session_interrupt_cb_table.user_cb == NULL) {
- ret = mm_sound_add_device_connected_callback(SOUND_DEVICE_ALL_MASK, (mm_sound_device_connected_cb)_device_connected_cb, NULL, &subs_id);
- if (ret)
+ if ((ret = mm_sound_add_device_connected_callback(SOUND_DEVICE_ALL_MASK, (mm_sound_device_connected_cb)_device_connected_cb, NULL, &subs_id))) {
+ ret = MM_ERROR_INVALID_ARGUMENT;
goto LEAVE;
- ret = mm_sound_focus_set_session_interrupt_callback((mm_sound_focus_session_interrupt_cb)_focus_session_interrupt_cb, NULL);
- if (ret) {
+ }
+ if ((ret = mm_sound_focus_set_session_interrupt_callback((mm_sound_focus_session_interrupt_cb)_focus_session_interrupt_cb, NULL))) {
if (mm_sound_remove_device_connected_callback(subs_id) != MM_ERROR_NONE)
LOGW("mm_sound_remove_device_connected_callback failed");
+ ret = MM_ERROR_INVALID_ARGUMENT;
goto LEAVE;
}
g_session_interrupt_cb_table.subs_id = subs_id;
goto LEAVE;
}
- ret = mm_sound_focus_unset_session_interrupt_callback();
- if (ret) {
+ if ((ret = mm_sound_focus_unset_session_interrupt_callback())) {
if (mm_sound_remove_device_connected_callback(g_session_interrupt_cb_table.subs_id) != MM_ERROR_NONE)
LOGW("mm_sound_remove_device_connected_callback failed");
+ ret = MM_ERROR_SOUND_INTERNAL;
goto LEAVE;
}
- ret = mm_sound_remove_device_connected_callback(g_session_interrupt_cb_table.subs_id);
- if (ret)
+ if ((ret = mm_sound_remove_device_connected_callback(g_session_interrupt_cb_table.subs_id))) {
+ ret = MM_ERROR_SOUND_INTERNAL;
goto LEAVE;
+ }
g_session_interrupt_cb_table.subs_id = 0;
g_session_interrupt_cb_table.user_cb = NULL;
if (!strncmp(stream_type, "media", SOUND_STREAM_TYPE_LEN) ||
!strncmp(stream_type, "radio", SOUND_STREAM_TYPE_LEN) ||
- !strncmp(stream_type, "system", SOUND_STREAM_TYPE_LEN) ||
!strncmp(stream_type, "voice-information", SOUND_STREAM_TYPE_LEN) ||
!strncmp(stream_type, "voice-recognition", SOUND_STREAM_TYPE_LEN) ||
!strncmp(stream_type, "loopback", SOUND_STREAM_TYPE_LEN) ||
*change_reason = SOUND_SESSION_INTERRUPTED_BY_CALL;
} else {
- LOGE("not supported stream_type(%s)", stream_type);
+ LOGE("not supported stream_type(%s) for session interrupted cb", stream_type);
return MM_ERROR_INVALID_ARGUMENT;
}
return;
}
-void _focus_session_interrupt_cb(mm_sound_focus_state_e state, const char *reason, bool is_wcb, void *user_data)
+void _focus_session_interrupt_cb(mm_sound_focus_state_e state, const char *reason, void *user_data)
{
sound_session_interrupted_code_e e;
- LOGE("session interrupted by [%s]", reason);
- if (g_session_interrupt_cb_table.user_cb) {
- if (is_wcb) {
- if (state == FOCUS_IS_RELEASED)
- e = SOUND_SESSION_INTERRUPTED_COMPLETED;
- else
- _convert_stream_type_to_interrupt_reason(reason, &e);
- } else {
- if (state == FOCUS_IS_ACQUIRED)
- e = SOUND_SESSION_INTERRUPTED_COMPLETED;
- else
- _convert_stream_type_to_interrupt_reason(reason, &e);
+ int ret = MM_ERROR_NONE;
+ int cur_session = -1;
+ int cur_session_option = -1;
+
+ if (!g_session_interrupt_cb_table.user_cb) {
+ LOGE("user_cb is null");
+ return;
+ }
+ if (_convert_stream_type_to_interrupt_reason(reason, &e)) {
+ LOGE("failed to session _convert_stream_type_to_interrupt_reason[%s]", reason);
+ return;
+ }
+
+ ret = mm_session_get_current_information(&cur_session, &cur_session_option);
+ if (ret == MM_ERROR_INVALID_HANDLE) {
+ cur_session = MM_SESSION_TYPE_MEDIA;
+ } else if (ret != MM_ERROR_NONE) {
+ LOGE("failed to mm_session_get_current_type()");
+ return;
+ }
+
+ if (state == FOCUS_IS_RELEASED) {
+ if (cur_session != MM_SESSION_TYPE_MEDIA &&
+ cur_session != MM_SESSION_TYPE_MEDIA_RECORD) {
+ LOGI("current session is not media, skip resumption");
+ return;
}
- g_session_interrupt_cb_table.user_cb(e, g_session_interrupt_cb_table.user_data);
+ if (e == SOUND_SESSION_INTERRUPTED_BY_MEDIA) {
+ /* check if this media session is resumable */
+ if (cur_session_option == -1 ||
+ !(cur_session_option & MM_SESSION_OPTION_RESUME_BY_SYSTEM_OR_MEDIA_PAUSED)) {
+ LOGI("current media session option is not resumable by media, skip resumption");
+ return;
+ }
+ }
+ e = SOUND_SESSION_INTERRUPTED_COMPLETED;
}
+ LOGE("session interrupted by [%s], interrupted code[%d], user_cb[%p]", reason, e, g_session_interrupt_cb_table.user_cb);
+ g_session_interrupt_cb_table.user_cb(e, g_session_interrupt_cb_table.user_data);
+
return;
}