TizenRefApp-9604 [Call UI] Prevent to set / get Volume level while SCO is not connected 47/155447/1
authorIgor Olshevskyi <i.olshevskyi@samsung.com>
Fri, 13 Oct 2017 06:43:58 +0000 (09:43 +0300)
committerIgor Olshevskyi <i.olshevskyi@samsung.com>
Fri, 13 Oct 2017 06:47:46 +0000 (09:47 +0300)
Change-Id: I71c8637f96866038a171d146e661ee8354010e4e

call-ui/model/impl/BluetoothManager.cpp
call-ui/model/impl/BluetoothManager.h
call-ui/model/impl/SoundManager.cpp

index 25fa8e002f3ff82ca1af81c20a665d51fd4cbaef..f5f39eb14a5fe0402ac5725bdcb21b6214a4d9be 100644 (file)
@@ -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();
                        }
                }
index 22e703d5c9cd9cd6b0efe5a78c76e30f08a0b101..e1b7f4f6170d98196723ccd821d364e38f0839a8 100644 (file)
@@ -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();
 
index 17c23ccf1f3c9fee438eb5532c8cd49d99083aa2..f243df894d0760247a3836978d86c540388ccd48 100644 (file)
@@ -99,7 +99,7 @@ namespace callui {
                }
 
                if (isBTSupported()) {
-                       m_btManager->setVolumeStateHandler(
+                       m_btManager->setVolumeChangeHandler(
                                        WEAK_DELEGATE_THIS(onBTHeadsetVolumeChanged));
 
                        m_btManager->setHeadsetConnectionChangeHandler(