__mIsInit(false),
__mSubscribeId(0),
__mUseFocus(false),
- __mFocusType(FOCUS_NONE),
- __mState(FOCUS_IS_RELEASED),
+ __mAcquiredFocus(FOCUS_NONE),
__mReasonForChange(NULL),
__mAdditionalInfo(NULL) {
__mAudioInfo = audioInfo;
#ifndef DISABLE_SESSION_BACK_COMP
CAudioSessionHandler* pHandler = static_cast<CAudioSessionHandler*>(user_data);
- pHandler->__mFocusType = focus_type;
- pHandler->__mState = state;
+
+ if (state == FOCUS_IS_RELEASED)
+ pHandler->__mAcquiredFocus &= ~focus_type;
+ else if (state == FOCUS_IS_ACQUIRED)
+ pHandler->__mAcquiredFocus |= focus_type;
pHandler->__mReasonForChange = (char *)reason_for_change;
pHandler->__mAdditionalInfo = (char *)additional_info;
AUDIO_IO_LOGD("Focus watch callback unregistered successfully [id:%d]", __mId);
__mId = -1;
}
+ __mAcquiredFocus = FOCUS_NONE;
}
}
if (__mUseFocus && __isFocusRequired(__mMultimediaSession, __mOptions)) {
if (__mId >= 0) {
int ret = MM_ERROR_NONE;
+ int focus_type = 0;
+ if (__mAcquiredFocus == FOCUS_FOR_BOTH) {
+ AUDIO_IO_LOGW("Focus was already acquired, skip it...");
+ return;
+ }
+ focus_type |= (FOCUS_FOR_BOTH & ~__mAcquiredFocus);
if (__mMultimediaSession == MM_SESSION_TYPE_MEDIA)
- ret = mm_sound_acquire_focus_with_option(__mId, FOCUS_FOR_BOTH, 1, "audio-io acquire focus"); /* option: 1 for no-resume */
+ ret = mm_sound_acquire_focus_with_option(__mId, (mm_sound_focus_type_e)focus_type, 1, "audio-io acquire focus"); /* option: 1 for no-resume */
else
- ret = mm_sound_acquire_focus(__mId, FOCUS_FOR_BOTH, "audio-io acquire focus");
+ ret = mm_sound_acquire_focus(__mId, (mm_sound_focus_type_e)focus_type, "audio-io acquire focus");
if (ret != MM_ERROR_NONE) {
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_POLICY_BLOCKED, "Failed mm_sound_acquire_focus() err:0x%x", ret);
}
+ __mAcquiredFocus = FOCUS_FOR_BOTH;
AUDIO_IO_LOGD("Focus acquired successfully [id:%d]", __mId);
}
}
if (__mUseFocus && __isFocusRequired(__mMultimediaSession, __mOptions)) {
if (__mId >= 0) {
int ret = MM_ERROR_NONE;
+ if (__mAcquiredFocus == FOCUS_NONE) {
+ AUDIO_IO_LOGW("Focus was already released, skip it...");
+ return;
+ }
if (__mMultimediaSession == MM_SESSION_TYPE_MEDIA)
- ret = mm_sound_release_focus_with_option(__mId, FOCUS_FOR_BOTH, 1, "audio-io release focus"); /* option: 1 for no-resume */
+ ret = mm_sound_release_focus_with_option(__mId, (mm_sound_focus_type_e)__mAcquiredFocus, 1, "audio-io release focus"); /* option: 1 for no-resume */
else
- ret = mm_sound_release_focus(__mId, FOCUS_FOR_BOTH, "audio-io release focus");
+ ret = mm_sound_release_focus(__mId, (mm_sound_focus_type_e)__mAcquiredFocus, "audio-io release focus");
if (ret != MM_ERROR_NONE) {
THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed mm_sound_release_focus() err:0x%x", ret);
}
+ __mAcquiredFocus = FOCUS_NONE;
AUDIO_IO_LOGD("Focus released successfully [id:%d]", __mId);
}
}