From: Igor Olshevskyi Date: Fri, 13 Oct 2017 06:43:58 +0000 (+0300) Subject: TizenRefApp-9604 [Call UI] Prevent to set / get Volume level while SCO is not connected X-Git-Tag: submit/tizen_4.0/20171018.080056~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9098dc48852db96386b9b34160c847e543235740;p=profile%2Fwearable%2Fapps%2Fnative%2Fcall-ui.git TizenRefApp-9604 [Call UI] Prevent to set / get Volume level while SCO is not connected Change-Id: I71c8637f96866038a171d146e661ee8354010e4e --- diff --git a/call-ui/model/impl/BluetoothManager.cpp b/call-ui/model/impl/BluetoothManager.cpp index 25fa8e0..f5f39eb 100644 --- a/call-ui/model/impl/BluetoothManager.cpp +++ b/call-ui/model/impl/BluetoothManager.cpp @@ -36,7 +36,7 @@ namespace callui { namespace { namespace impl { "bt_ag_is_sco_opened() failed! " "res[%d] msg[%s]", res, get_error_message(res)); } - DLOG("BT SCO open state [%d]", isOpened); + DLOG("SCO state [%s]", isOpened ? "opened" : "closed"); return isOpened; } @@ -78,7 +78,8 @@ namespace callui { BluetoothManager::~BluetoothManager() { - unregisterAudioHandling(); + unregisterScoStateHandling(); + unregisterVolumeChangeHandling(); unregisterHeadsetConnectionHandling(); deinitializeBluetooth(); } @@ -88,8 +89,11 @@ namespace callui { FAIL_RETURN(initializeBluetooth(), "initializeBluetooth() failed!"); - FAIL_RETURN(registerAudioHandling(), - "registerAudioHandling() failed"); + FAIL_RETURN(registerVolumeChangeHandling(), + "registerVolumeChangeHandling() failed"); + + FAIL_RETURN(registerScoStateHandling(), + "registerScoStateHandling() failed"); FAIL_RETURN(registerHeadsetConnectionHandling(), "registerHeadsetConnectionHandling() failed!"); @@ -122,11 +126,15 @@ namespace callui { int BluetoothManager::getVolume() const { auto vol = 0; - auto res = bt_ag_get_speaker_gain(&vol); - if (res != BT_ERROR_NONE) { - LOG_RETURN_VALUE(RES_FAIL, -1, "bt_ag_get_speaker_gain() failed! " - "res[%d] msg[%s]", res, get_error_message(res)); + if (impl::isScoOpened() && impl::isCallCurrentSoundType()) { + auto res = bt_ag_get_speaker_gain(&vol); + if (res != BT_ERROR_NONE) { + LOG_RETURN_VALUE(RES_FAIL, -1, + "bt_ag_get_speaker_gain() failed! " + "res[%d] msg[%s]", res, get_error_message(res)); + } } + DLOG("BT Volume level [%d]", vol); return vol; } @@ -138,20 +146,24 @@ namespace callui { Result BluetoothManager::setVolume(int volume) { - auto res = bt_ag_notify_speaker_gain(volume); - if (res != BT_ERROR_NONE) { - LOG_RETURN(RES_FAIL, "bt_ag_notify_speaker_gain() failed! " - "res[%d] msg[%s]", res, get_error_message(res)); + if (impl::isScoOpened() && impl::isCallCurrentSoundType()) { + auto res = bt_ag_notify_speaker_gain(volume); + if (res != BT_ERROR_NONE) { + LOG_RETURN(RES_FAIL, "bt_ag_notify_speaker_gain() failed! " + "res[%d] msg[%s]", res, get_error_message(res)); + } + return RES_OK; } - return RES_OK; + + return RES_FAIL; } - void BluetoothManager::setVolumeStateHandler(NotiHandler handler) + void BluetoothManager::setVolumeChangeHandler(NotiHandler handler) { m_btVolumeHandler = std::move(handler); } - Result BluetoothManager::registerAudioHandling() + Result BluetoothManager::registerVolumeChangeHandling() { auto res = bt_audio_initialize(); if (res != BT_ERROR_NONE) { @@ -169,7 +181,7 @@ namespace callui { return RES_OK; } - void BluetoothManager::unregisterAudioHandling() + void BluetoothManager::unregisterVolumeChangeHandling() { bt_ag_unset_speaker_gain_changed_cb(); @@ -179,6 +191,22 @@ namespace callui { } } + Result BluetoothManager::registerScoStateHandling() + { + auto res = bt_ag_set_sco_state_changed_cb( + CALLBACK_B(BluetoothManager::onScoChanged), this); + if (res != BT_ERROR_NONE) { + LOG_RETURN(RES_FAIL, "bt_ag_set_sco_state_changed_cb() failed! ", + "res[%d] msg[%s]", res, get_error_message(res)); + } + return RES_OK; + } + + void BluetoothManager::unregisterScoStateHandling() + { + bt_ag_unset_sco_state_changed_cb(); + } + Result BluetoothManager::registerHeadsetConnectionHandling() { auto res = vconf_notify_key_changed(VCONFKEY_BT_DEVICE, @@ -192,15 +220,32 @@ namespace callui { void BluetoothManager::unregisterHeadsetConnectionHandling() { - vconf_ignore_key_changed( - VCONFKEY_BT_DEVICE, + vconf_ignore_key_changed(VCONFKEY_BT_DEVICE, CALLBACK_B(BluetoothManager::onHeadsetConnectionChanged)); } void BluetoothManager::onVolumeChanged(int volume) + { + DLOG(); + notifyVolumeChange(); + } + + void BluetoothManager::onScoChanged(int result, bool opened) + { + DLOG("Result [%d] SCO state [%s]", result, + opened ? "opened" : "close"); + + if (result == BT_ERROR_NONE && opened) { + notifyVolumeChange(); + } + } + + void BluetoothManager::notifyVolumeChange() { if (impl::isScoOpened() && impl::isCallCurrentSoundType()) { + DLOG("Try call volume change handler..."); if (const auto handler = m_btVolumeHandler.lock()) { + DLOG("Call volume change handler"); handler(); } } diff --git a/call-ui/model/impl/BluetoothManager.h b/call-ui/model/impl/BluetoothManager.h index 22e703d..e1b7f4f 100644 --- a/call-ui/model/impl/BluetoothManager.h +++ b/call-ui/model/impl/BluetoothManager.h @@ -59,10 +59,10 @@ namespace callui { ucl::Result setVolume(int volume); /** - * @brief Sets volume state change handler + * @brief Sets volume level change handler * @param[in] handler Volume state change handler */ - void setVolumeStateHandler(NotiHandler handler); + void setVolumeChangeHandler(NotiHandler handler); /** * @brief Checks whether headset device is connected @@ -85,10 +85,16 @@ namespace callui { ucl::Result initializeBluetooth(); void deinitializeBluetooth(); - ucl::Result registerAudioHandling(); - void unregisterAudioHandling(); + ucl::Result registerVolumeChangeHandling(); + void unregisterVolumeChangeHandling(); void onVolumeChanged(int volume); + ucl::Result registerScoStateHandling(); + void unregisterScoStateHandling(); + void onScoChanged(int result, bool opened); + + void notifyVolumeChange(); + ucl::Result registerHeadsetConnectionHandling(); void unregisterHeadsetConnectionHandling(); diff --git a/call-ui/model/impl/SoundManager.cpp b/call-ui/model/impl/SoundManager.cpp index 17c23cc..f243df8 100644 --- a/call-ui/model/impl/SoundManager.cpp +++ b/call-ui/model/impl/SoundManager.cpp @@ -99,7 +99,7 @@ namespace callui { } if (isBTSupported()) { - m_btManager->setVolumeStateHandler( + m_btManager->setVolumeChangeHandler( WEAK_DELEGATE_THIS(onBTHeadsetVolumeChanged)); m_btManager->setHeadsetConnectionChangeHandler(