TizenRefApp-8644 [Call UI] Implement headset connection check logic 96/133496/1
authorIgor Olshevskyi <i.olshevskyi@samsung.com>
Wed, 7 Jun 2017 05:58:40 +0000 (08:58 +0300)
committerIgor Olshevskyi <i.olshevskyi@samsung.com>
Mon, 12 Jun 2017 11:15:28 +0000 (14:15 +0300)
Change-Id: Ibfc6adfe53c70e2c43139c3a5b83d6e6effb9a61

15 files changed:
inc/model/ISoundManager.h
inc/presenters/MoreOptionsPresenter.h
inc/types.h
src/model/BluetoothManager.cpp [deleted file]
src/model/BluetoothManager.h [deleted file]
src/model/BluetoothVolume.cpp [new file with mode: 0644]
src/model/BluetoothVolume.h [new file with mode: 0644]
src/model/Call.cpp
src/model/Call.h
src/model/SoundManager.cpp
src/model/SoundManager.h
src/model/implTypes.h
src/presenters/MainPage.cpp
src/presenters/MoreOptionsPresenter.cpp
src/presenters/RejectMsgPresenter.cpp

index 8114ae26807955ec2f7dd036e0d0566fa823e52f..a95b18f397471ee8d14d4212262a4a2d659fd3ca 100644 (file)
@@ -39,6 +39,7 @@ namespace callui {
                virtual int getMaxVolume() const = 0;
                virtual int getVolume() const = 0;
                virtual ucl::Result setVolume(int value) = 0;
+               virtual bool isBluetoothSupported() const = 0;
        };
 }
 
index c3b748f64fb6b2ab23523fc98a36905e80d6bedd..2955e52a09cf91ad35232792d2f0eefc439a77f4 100644 (file)
@@ -31,20 +31,23 @@ namespace callui {
                class Builder {
                public:
                        Builder();
-                       ~Builder();
                        Builder &setCallManager(const ICallManagerSRef &cm);
+                       Builder &setSoundManager(const ISoundManagerSRef &sm);
                        MoreOptionsPresenterSRef build(ucl::ElmWidget &parent) const;
                private:
                        ICallManagerSRef m_cm;
+                       ISoundManagerSRef m_sm;
                };
 
        public:
                ucl::Widget &getWidget();
-               ucl::Result update();
+               void update();
 
        private:
                friend class ucl::RefCountObj<MoreOptionsPresenter>;
-               MoreOptionsPresenter(ucl::RefCountObjBase &rc, const ICallManagerSRef &cm);
+               MoreOptionsPresenter(ucl::RefCountObjBase &rc,
+                               const ICallManagerSRef &cm,
+                               const ISoundManagerSRef &sm);
                virtual ~MoreOptionsPresenter();
 
                ucl::Result prepare(ucl::ElmWidget &parent);
@@ -57,13 +60,13 @@ namespace callui {
                                const ucl::TString &txt,
                                const ucl::WidgetEventHandler &handler);
 
-               ucl::Result updateSlots();
-               ucl::Result updateTopSlot();
-               ucl::Result updateLeftSlot();
-               ucl::Result updateRightSlot();
-               ucl::Result updateBottomSlot();
+               void updateSlots();
+               void updateTopSlot();
+               void updateLeftSlot();
+               void updateRightSlot();
+               void updateBottomSlot();
 
-               ucl::Result updateStatusText();
+               void updateStatusText();
                void updateStatusFontSize();
 
                void onSwapBtnClick(ucl::Widget &sender, void *eventInfo);
@@ -82,6 +85,13 @@ namespace callui {
                void stopCallDurationTimer();
                Eina_Bool onCallDurationTimerCb();
 
+               ucl::Result launchBluetoothSettings();
+
+               void onAudioStateChanged(AudioStateType state);
+
+               void unsetPanelContent(const ucl::EdjePart &part);
+               void setPanelContent(ucl::StyledWidgetSRef &widget, const ucl::EdjePart &part);
+
        private:
                ucl::LayoutSRef m_widget;
                ucl::StyledWidgetSRef m_panel;
@@ -94,6 +104,7 @@ namespace callui {
                ucl::StyledWidgetSRef m_btnGear;
 
                ICallManagerSRef m_cm;
+               ISoundManagerSRef m_sm;
                ICallInfoWCRef m_info;
 
                Ecore_Timer *m_timer;
index fcccaaa58efd1f1b2ee44535f62bf7f1cd33424b..890fc083df487dfda10e7a60d70c0328060d57fc 100644 (file)
@@ -31,7 +31,8 @@ namespace callui {
                RES_PERMISSION_DENIED   = ucl::_RES_BEGIN - 1,
                RES_NOT_REGISTERED      = ucl::_RES_BEGIN - 2,
                RES_ALREADY_REGISTERED  = ucl::_RES_BEGIN - 3,
-               RES_OPERATION_FAILED    = ucl::_RES_BEGIN - 4
+               RES_OPERATION_FAILED    = ucl::_RES_BEGIN - 4,
+               RES_NOT_CONNECTED       = ucl::_RES_BEGIN - 5
        };
 }
 
diff --git a/src/model/BluetoothManager.cpp b/src/model/BluetoothManager.cpp
deleted file mode 100644 (file)
index 7ef9959..0000000
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright 2017 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "BluetoothManager.h"
-
-#include <bluetooth.h>
-#include <bluetooth_internal.h>
-#include <bluetooth_extension.h>
-#include <sound_manager.h>
-
-#include "common.h"
-
-namespace callui { namespace { namespace impl {
-
-       using namespace ucl;
-
-       constexpr auto BT_VOLUME_MAX = 15;
-
-}}}
-
-namespace callui {
-
-       using namespace ucl;
-
-       BluetoothManagerSRef BluetoothManager::newInstance()
-       {
-               auto result = makeShared<BluetoothManager>();
-               FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!");
-               return result;
-       }
-
-       BluetoothManager::BluetoothManager():
-               m_btInitialized(false),
-               m_btAudioInitialized(false)
-       {
-       }
-
-       BluetoothManager::~BluetoothManager()
-       {
-               unregisterAudioHandling();
-
-               bt_deinitialize();
-       }
-
-       Result BluetoothManager::prepare()
-       {
-               if (BT_ERROR_NONE != bt_initialize()) {
-                       LOG_RETURN(RES_FAIL, "BT initialize failed");
-               }
-               m_btInitialized = true;
-
-               FAIL_RETURN(registerAudioHandling(),
-                               "registerAudioHandling() failed");
-
-               return RES_OK;
-       }
-
-       int BluetoothManager::getVolume() const
-       {
-               auto vol = 0;
-               auto ret = bt_ag_get_speaker_gain(&vol);
-               if (ret != BT_ERROR_NONE) {
-                       LOG_RETURN_VALUE(RES_FAIL, -1, "bt_ag_get_speaker_gain() failed!");
-               }
-               DLOG("BT Volume level [%d]", vol);
-               return vol;
-       }
-
-       int BluetoothManager::getMaxVolume() const
-       {
-               return impl::BT_VOLUME_MAX;
-       }
-
-       Result BluetoothManager::setVolume(int volume)
-       {
-               auto ret = bt_ag_notify_speaker_gain(volume);
-               if (ret != BT_ERROR_NONE) {
-                       LOG_RETURN(RES_FAIL, "bt_ag_notify_speaker_gain() failed!");
-               }
-               return RES_OK;
-       }
-
-       void BluetoothManager::setVolumeStateHandler(
-                       const BluetoothVolumeHandler &handler)
-       {
-               m_handler = handler;
-       }
-
-       Result BluetoothManager::registerAudioHandling()
-       {
-               auto ret = bt_audio_initialize();
-               if (ret != BT_ERROR_NONE) {
-                       LOG_RETURN(RES_FAIL, "bt_audio_initialize() failed");
-               }
-               m_btAudioInitialized = true;
-
-               ret = bt_ag_set_speaker_gain_changed_cb(
-                               CALLBACK_B(BluetoothManager::onVolumeChanged), this);
-               if (ret != BT_ERROR_NONE) {
-                       LOG_RETURN(RES_FAIL, "bt_ag_set_speaker_gain_changed_cb() failed");
-               }
-
-               return RES_OK;
-       }
-
-       void BluetoothManager::unregisterAudioHandling()
-       {
-               bt_ag_unset_speaker_gain_changed_cb();
-
-               if (m_btAudioInitialized) {
-                       bt_audio_deinitialize();
-                       m_btAudioInitialized = false;
-               }
-       }
-
-       void BluetoothManager::onVolumeChanged(int volume)
-       {
-               sound_type_e soundType = SOUND_TYPE_SYSTEM;
-               auto ret = sound_manager_get_current_sound_type(&soundType);
-               if (ret != SOUND_MANAGER_ERROR_NONE) {
-                       LOG_RETURN_VOID(RES_FAIL, "sound_manager_get_current_sound_type() failed");
-               }
-
-               bool isSCOOpened = false;
-               ret = bt_ag_is_sco_opened(&isSCOOpened);
-               if (ret != BT_ERROR_NONE) {
-                       LOG_RETURN_VOID(RES_FAIL, "sound_manager_get_current_sound_type() failed");
-               }
-
-               if (isSCOOpened && soundType == SOUND_TYPE_CALL) {
-                       if (m_handler) {
-                               m_handler(volume);
-                       }
-               }
-       }
-
-}
diff --git a/src/model/BluetoothManager.h b/src/model/BluetoothManager.h
deleted file mode 100644 (file)
index 06478b0..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2017 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __CALLUI_MODEL_BLUETOOTH_MANAGER_H__
-#define __CALLUI_MODEL_BLUETOOTH_MANAGER_H__
-
-#include "implTypes.h"
-
-namespace callui {
-
-       class BluetoothManager final {
-       public:
-               static BluetoothManagerSRef newInstance();
-               virtual ~BluetoothManager();
-
-               int getVolume() const;
-               int getMaxVolume() const;
-               ucl::Result setVolume(int volume);
-
-               void setVolumeStateHandler(const BluetoothVolumeHandler &handler);
-
-       private:
-               friend class ucl::RefCountObj<BluetoothManager>;
-               BluetoothManager();
-
-               ucl::Result prepare();
-
-               ucl::Result registerAudioHandling();
-               void unregisterAudioHandling();
-               void onVolumeChanged(int volume);
-
-       private:
-               BluetoothVolumeHandler m_handler;
-               bool m_btInitialized;
-               bool m_btAudioInitialized;
-       };
-
-}
-
-#endif // __CALLUI_MODEL_BLUETOOTH_MANAGER_H__
diff --git a/src/model/BluetoothVolume.cpp b/src/model/BluetoothVolume.cpp
new file mode 100644 (file)
index 0000000..633a849
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "BluetoothVolume.h"
+
+#include <bluetooth.h>
+#include <bluetooth_internal.h>
+#include <bluetooth_extension.h>
+#include <sound_manager.h>
+
+#include "common.h"
+
+namespace callui { namespace { namespace impl {
+
+       using namespace ucl;
+
+       constexpr auto BT_VOLUME_MAX = 15;
+
+}}}
+
+namespace callui {
+
+       using namespace ucl;
+
+       BluetoothVolumeSRef BluetoothVolume::newInstance()
+       {
+               auto result = makeShared<BluetoothVolume>();
+               FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!");
+               return result;
+       }
+
+       BluetoothVolume::BluetoothVolume():
+               m_btInitialized(false),
+               m_btAudioInitialized(false)
+       {
+       }
+
+       BluetoothVolume::~BluetoothVolume()
+       {
+               unregisterAudioHandling();
+
+               bt_deinitialize();
+       }
+
+       Result BluetoothVolume::prepare()
+       {
+               if (BT_ERROR_NONE != bt_initialize()) {
+                       LOG_RETURN(RES_FAIL, "BT initialize failed");
+               }
+               m_btInitialized = true;
+
+               FAIL_RETURN(registerAudioHandling(),
+                               "registerAudioHandling() failed");
+
+               return RES_OK;
+       }
+
+       int BluetoothVolume::getVolume() const
+       {
+               auto vol = 0;
+               auto ret = bt_ag_get_speaker_gain(&vol);
+               if (ret != BT_ERROR_NONE) {
+                       LOG_RETURN_VALUE(RES_FAIL, -1, "bt_ag_get_speaker_gain() failed!");
+               }
+               DLOG("BT Volume level [%d]", vol);
+               return vol;
+       }
+
+       int BluetoothVolume::getMaxVolume() const
+       {
+               return impl::BT_VOLUME_MAX;
+       }
+
+       Result BluetoothVolume::setVolume(int volume)
+       {
+               auto ret = bt_ag_notify_speaker_gain(volume);
+               if (ret != BT_ERROR_NONE) {
+                       LOG_RETURN(RES_FAIL, "bt_ag_notify_speaker_gain() failed!");
+               }
+               return RES_OK;
+       }
+
+       void BluetoothVolume::setVolumeStateHandler(
+                       const BluetoothVolumeHandler &handler)
+       {
+               m_handler = handler;
+       }
+
+       Result BluetoothVolume::registerAudioHandling()
+       {
+               auto ret = bt_audio_initialize();
+               if (ret != BT_ERROR_NONE) {
+                       LOG_RETURN(RES_FAIL, "bt_audio_initialize() failed");
+               }
+               m_btAudioInitialized = true;
+
+               ret = bt_ag_set_speaker_gain_changed_cb(
+                               CALLBACK_B(BluetoothVolume::onVolumeChanged), this);
+               if (ret != BT_ERROR_NONE) {
+                       LOG_RETURN(RES_FAIL, "bt_ag_set_speaker_gain_changed_cb() failed");
+               }
+
+               return RES_OK;
+       }
+
+       void BluetoothVolume::unregisterAudioHandling()
+       {
+               bt_ag_unset_speaker_gain_changed_cb();
+
+               if (m_btAudioInitialized) {
+                       bt_audio_deinitialize();
+                       m_btAudioInitialized = false;
+               }
+       }
+
+       void BluetoothVolume::onVolumeChanged(int volume)
+       {
+               sound_type_e soundType = SOUND_TYPE_SYSTEM;
+               auto ret = sound_manager_get_current_sound_type(&soundType);
+               if (ret != SOUND_MANAGER_ERROR_NONE) {
+                       LOG_RETURN_VOID(RES_FAIL, "sound_manager_get_current_sound_type() failed");
+               }
+
+               bool isSCOOpened = false;
+               ret = bt_ag_is_sco_opened(&isSCOOpened);
+               if (ret != BT_ERROR_NONE) {
+                       LOG_RETURN_VOID(RES_FAIL, "sound_manager_get_current_sound_type() failed");
+               }
+
+               if (isSCOOpened && soundType == SOUND_TYPE_CALL) {
+                       if (m_handler) {
+                               m_handler(volume);
+                       }
+               }
+       }
+}
diff --git a/src/model/BluetoothVolume.h b/src/model/BluetoothVolume.h
new file mode 100644 (file)
index 0000000..95e6d7a
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CALLUI_MODEL_BLUETOOTH_VOLUME_H__
+#define __CALLUI_MODEL_BLUETOOTH_VOLUME_H__
+
+#include "implTypes.h"
+
+namespace callui {
+
+       class BluetoothVolume final {
+       public:
+               static BluetoothVolumeSRef newInstance();
+
+               int getVolume() const;
+               int getMaxVolume() const;
+               ucl::Result setVolume(int volume);
+
+               void setVolumeStateHandler(const BluetoothVolumeHandler &handler);
+
+       private:
+               friend class ucl::RefCountObj<BluetoothVolume>;
+               BluetoothVolume();
+               ~BluetoothVolume();
+
+               ucl::Result prepare();
+
+               ucl::Result registerAudioHandling();
+               void unregisterAudioHandling();
+               void onVolumeChanged(int volume);
+
+       private:
+               BluetoothVolumeHandler m_handler;
+               bool m_btInitialized;
+               bool m_btAudioInitialized;
+       };
+
+}
+
+#endif // __CALLUI_MODEL_BLUETOOTH_MANAGER_H__
index 7d54f7bd0dfbbda64c240e01b1c55d3cab31a34f..a54f03aa13854f128b040157ff3e8d0f55a9bc24 100644 (file)
@@ -34,7 +34,6 @@
 #include "BatteryStateSource.h"
 #include "SimSlotStateSource.h"
 #include "HdVoiceStateSource.h"
-#include "BluetoothManager.h"
 
 #include "common.h"
 
@@ -128,11 +127,6 @@ namespace callui {
 
        Result Call::prepare()
        {
-               m_btManager = BluetoothManager::newInstance();
-               if (!m_btManager) {
-                       ELOG("BluetoothManager::newInstance() failed!");
-               }
-
                auto callClient = CallClient::newInstance();
                if (!callClient) {
                        LOG_RETURN(RES_FAIL, "Client::newInstance() failed!");
@@ -143,7 +137,7 @@ namespace callui {
                        LOG_RETURN(RES_FAIL, "CallManager::newInstance() failed!");
                }
 
-               m_soundManager = SoundManager::newInstance(callClient, m_btManager);
+               m_soundManager = SoundManager::newInstance(callClient);
                if (!m_soundManager) {
                        LOG_RETURN(RES_FAIL, "SoundManage::newInstance() failed!");
                }
index 08429c09356000a2925142998d9598fafaf4ab06..ff5a4061e6613b2d0958927c364825eb17ea1065 100644 (file)
@@ -67,7 +67,6 @@ namespace callui {
        private:
                CallManagerSRef m_callManager;
                SoundManagerSRef m_soundManager;
-               BluetoothManagerSRef m_btManager;
                ICallListenerWRef m_listener;
                SimSlotStateSourceSRef m_simSlotStSrc;
                HdVoiceStateSourceSRef m_hdCallStSrc;
index b7bc96f039881bdd7e873692bd9d57558e9fc606..491ea9ace885fa92bee7d6293487f78de9388434 100644 (file)
 
 #include "SoundManager.h"
 
+#include "BluetoothVolume.h"
 #include "CallClient.h"
-#include "BluetoothManager.h"
-
 #include "common.h"
 
+namespace callui { namespace { namespace impl {
+
+       using namespace ucl;
+
+       Result getBTVolumeDeviceCount(int &deviceCount)
+       {
+               Result res = RES_FAIL;
+               int count = 0;
+
+               sound_device_list_h deviceList = nullptr;
+               auto ret = sound_manager_get_device_list(SOUND_DEVICE_ALL_MASK, &deviceList);
+               if (ret != SOUND_MANAGER_ERROR_NONE) {
+                       LOG_RETURN(RES_FAIL, "sound_manager_get_device_list() failed. [%d][%s]",
+                                       ret, get_error_message(ret));
+               }
+
+               sound_device_type_e searchType = SOUND_DEVICE_BLUETOOTH_VOICE;
+               sound_device_h device;
+               sound_device_type_e type;
+
+               while (true) {
+                       device = nullptr;
+                       ret = sound_manager_get_next_device(deviceList, &device);
+                       if (ret == SOUND_MANAGER_ERROR_NO_DATA) {
+                               res = RES_OK;
+                               LOG_BREAK(res, "No more device to check");
+                       } else if (ret != SOUND_MANAGER_ERROR_NONE) {
+                               LOG_BREAK(res, "sound_manager_get_next_device() failed. [%d][%s]",
+                                               ret, get_error_message(ret));
+                       }
+                       if (!device) {
+                               LOG_BREAK(res, "device is NULL");
+                       }
+                       sound_manager_get_device_type(device, &type);
+                       if (searchType == type) {
+                               DLOG("Bluetooth voice device found");
+                               count++;
+                       }
+               }
+               sound_manager_free_device_list(deviceList);
+               deviceCount = count;
+
+               return res;
+       }
+}}}
+
 namespace callui {
 
        using namespace ucl;
 
        SoundManager::SoundManager(RefCountObjBase &rc,
-                       const CallClientSRef &client,
-                       const BluetoothManagerSRef &btManager):
+                       const CallClientSRef &client):
                                        RefCountAware(&rc),
                                m_client(client),
-                               m_btManager(btManager),
                                m_deviceVolumeCbID(-1)
        {
        }
@@ -44,10 +87,9 @@ namespace callui {
                cm_unset_mute_status_cb(*m_client);
        }
 
-       SoundManagerSRef SoundManager::newInstance(const CallClientSRef &client,
-                       const BluetoothManagerSRef &btManager)
+       SoundManagerSRef SoundManager::newInstance(const CallClientSRef &client)
        {
-               auto result = makeShared<SoundManager>(client, btManager);
+               auto result = makeShared<SoundManager>(client);
                FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!");
                return result;
        }
@@ -68,6 +110,11 @@ namespace callui {
 
        Result SoundManager::prepare()
        {
+               m_btVolume = BluetoothVolume::newInstance();
+               if (!m_btVolume) {
+                       ELOG("BluetoothVolume::newInstance() failed!");
+               }
+
                Result res = convertCMResult(cm_set_audio_state_changed_cb(*m_client,
                                CALLBACK_B(SoundManager::audioStateChangedCb), this));
                FAIL_RETURN(res, "cm_set_audio_state_changed_cb() failed!");
@@ -76,8 +123,8 @@ namespace callui {
                                CALLBACK_B(SoundManager::muteStateChangedCb), this));
                FAIL_RETURN(res, "cm_set_mute_status_cb() failed!");
 
-               FAIL_RETURN(registerVolumeCallbacks(),
-                               "registerVolumeCallbacks() failed!");
+               res = registerVolumeCallbacks();
+               FAIL_RETURN(res, "registerVolumeCallbacks() failed!");
 
                return res;
        }
@@ -93,8 +140,8 @@ namespace callui {
                                        "sound_manager_add_volume_changed_cb() failed");
                }
 
-               if (m_btManager) {
-                       m_btManager->setVolumeStateHandler(
+               if (isBluetoothSupported()) {
+                       m_btVolume->setVolumeStateHandler(
                                        WEAK_DELEGATE(SoundManager::onBluetoothVolumeChanged,
                                        asWeak(*this)));
                }
@@ -113,6 +160,17 @@ namespace callui {
 
        Result SoundManager::setBluetoothState(bool isEnable)
        {
+               if (!isBluetoothSupported()) {
+                       LOG_RETURN(RES_NOT_SUPPORTED, "Bluetooth not supported");
+               }
+
+               int count = 0;
+               FAIL_RETURN(impl::getBTVolumeDeviceCount(count), "getBTVolumeDeviceCount() failed");
+
+               if (count == 0) {
+                       LOG_RETURN(RES_NOT_CONNECTED, "Bluetooth headset device not connected");
+               }
+
                if (isEnable) {
                        return convertCMResult(cm_bluetooth_on(*m_client));
                } else {
@@ -190,10 +248,10 @@ namespace callui {
        {
                int maxVol = 0;
                if (getAudioState() == AudioStateType::BT) {
-                       if (m_btManager) {
-                               maxVol = m_btManager->getMaxVolume();
+                       if (isBluetoothSupported()) {
+                               maxVol = m_btVolume->getMaxVolume();
                        } else {
-                               ELOG("BT is not set");
+                               ELOG("BT is not supported");
                        }
                } else {
                        auto ret = sound_manager_get_max_volume(SOUND_TYPE_CALL, &maxVol);
@@ -210,10 +268,10 @@ namespace callui {
        {
                int vol = 0;
                if (getAudioState() == AudioStateType::BT) {
-                       if (m_btManager) {
-                               vol = m_btManager->getVolume();
+                       if (isBluetoothSupported()) {
+                               vol = m_btVolume->getVolume();
                        } else {
-                               ELOG("BT is not set");
+                               ELOG("BT is not supported");
                        }
                } else {
                        auto ret = sound_manager_get_volume(SOUND_TYPE_CALL, &vol);
@@ -229,10 +287,10 @@ namespace callui {
        Result SoundManager::setVolume(int value)
        {
                if (getAudioState() == AudioStateType::BT) {
-                       if (m_btManager) {
-                               return m_btManager->setVolume(value);
+                       if (isBluetoothSupported()) {
+                               return m_btVolume->setVolume(value);
                        } else {
-                               LOG_RETURN(RES_FAIL, "BT is not set");
+                               LOG_RETURN(RES_FAIL, "BT is not supported");
                        }
                } else {
                        auto ret = sound_manager_set_volume(SOUND_TYPE_CALL, value);
@@ -244,6 +302,10 @@ namespace callui {
                return RES_OK;
        }
 
+       bool SoundManager::isBluetoothSupported() const
+       {
+               return (m_btVolume != nullptr);
+       }
 
        void SoundManager::onDeviceVolumeChanged(sound_type_e type, unsigned int volume)
        {
index 2e1766aa4e5bddf28cd1faf21689ec6e20fbe408..c8f6901edf2cba38d6bf92951011df8c3d4d85f3 100644 (file)
@@ -30,8 +30,7 @@ namespace callui {
                public ucl::RefCountAware,
                public ISoundManager {
        public:
-               static SoundManagerSRef newInstance(const CallClientSRef &client,
-                               const BluetoothManagerSRef &btManager);
+               static SoundManagerSRef newInstance(const CallClientSRef &client);
                virtual ~SoundManager();
 
                // ISoundManager
@@ -52,12 +51,12 @@ namespace callui {
                virtual int getMaxVolume() const override final;
                virtual int getVolume() const override final;
                virtual ucl::Result setVolume(int value) override final;
+               virtual bool isBluetoothSupported() const override final;
 
        private:
                friend class ucl::RefCountObj<SoundManager>;
                SoundManager(ucl::RefCountObjBase &rc,
-                               const CallClientSRef &client,
-                               const BluetoothManagerSRef &btManager);
+                               const CallClientSRef &client);
 
                ucl::Result prepare();
                ucl::Result registerVolumeCallbacks();
@@ -70,7 +69,7 @@ namespace callui {
 
        private:
                CallClientSRef m_client;
-               BluetoothManagerSRef m_btManager;
+               BluetoothVolumeSRef m_btVolume;
                AudioStateEvent m_audioStateEvent;
                MuteStateEvent m_muteStateEvent;
                VolumeLevelEvent m_volumeLevelEvent;
index ad3e1efc8413232c11f9cf5eaaa8ad1bd762d39f..a26c7a83146df95346d3ae16ad2e37aadde792ce 100644 (file)
@@ -67,7 +67,7 @@ namespace callui {
        UCL_DECLARE_REF_ALIASES(SimSlotStateSource);
        UCL_DECLARE_REF_ALIASES(HdVoiceStateSource);
 
-       UCL_DECLARE_REF_ALIASES(BluetoothManager);
+       UCL_DECLARE_REF_ALIASES(BluetoothVolume);
 
        using AudioStateEvent = ucl::Event<AudioStateHandler>;
        using MuteStateEvent = ucl::Event<MuteStateHandler>;
index 85262b5242308d0fcea6c2f52b5e134658693bfc..ef15cb9a64bcf5c36ebd9e182a6810d1c0d6696f 100644 (file)
@@ -494,11 +494,13 @@ namespace callui {
        {
                if (m_moreOptions) {
                        ILOG("Already exists. No need to create new one. Just update.");
-                       return m_moreOptions->update();
+                       m_moreOptions->update();
+                       return RES_OK;
                }
 
                m_moreOptions = MoreOptionsPresenter::Builder().
                                setCallManager(m_cm).
+                               setSoundManager(m_call->getSoundManager()).
                                build(*m_widget);
 
                if (!m_moreOptions) {
index 556433bb5045122635cd1a19286ebf0ed1a8f846..a0b236e8004aae3775366b90f8dc009ea655a253 100644 (file)
 
 #include "presenters/MoreOptionsPresenter.h"
 
+#include <app_control.h>
+
 #include "ucl/gui/Layout.h"
 
 #include "model/ICallManager.h"
 #include "model/IHeldCall.h"
 #include "model/IActiveCall.h"
 #include "model/ICallInfo.h"
+#include "model/ISoundManager.h"
 
 #include "resources.h"
 #include "common.h"
@@ -69,23 +72,28 @@ namespace callui {
        {
        }
 
-       MoreOptionsPresenter::Builder::~Builder()
+       MoreOptionsPresenter::Builder &
+       MoreOptionsPresenter::Builder::setCallManager(const ICallManagerSRef &cm)
        {
+               m_cm = cm;
+               return *this;
        }
 
-       MoreOptionsPresenter::Builder &MoreOptionsPresenter::Builder::setCallManager(const ICallManagerSRef &cm)
+       MoreOptionsPresenter::Builder &
+       MoreOptionsPresenter::Builder::setSoundManager(const ISoundManagerSRef &sm)
        {
-               m_cm = cm;
+               m_sm = sm;
                return *this;
        }
 
-       MoreOptionsPresenterSRef MoreOptionsPresenter::Builder::build(ElmWidget &parent) const
+       MoreOptionsPresenterSRef
+       MoreOptionsPresenter::Builder::build(ElmWidget &parent) const
        {
-               if (!m_cm) {
-                       LOG_RETURN_VALUE(RES_FAIL, {}, "Call Manager is not set");
+               if (!m_cm || !m_sm) {
+                       LOG_RETURN_VALUE(RES_FAIL, {}, "Main params are not set");
                }
 
-               auto result = makeShared<MoreOptionsPresenter>(m_cm);
+               auto result = makeShared<MoreOptionsPresenter>(m_cm, m_sm);
                FAIL_RETURN_VALUE(result->prepare(parent), {},
                                "result->prepare() failed!");
 
@@ -94,9 +102,12 @@ namespace callui {
 
        // MoreOptionsPresenter
 
-       MoreOptionsPresenter::MoreOptionsPresenter(RefCountObjBase &rc, const ICallManagerSRef &cm):
+       MoreOptionsPresenter::MoreOptionsPresenter(RefCountObjBase &rc,
+                       const ICallManagerSRef &cm,
+                       const ISoundManagerSRef &sm):
                        Presenter(rc),
                        m_cm(cm),
+                       m_sm(sm),
                        m_timer(nullptr)
        {
        }
@@ -111,6 +122,9 @@ namespace callui {
 
                        sendActivateBy(*m_widget, this);
                }
+
+               m_sm->removeAudioStateHandler(DELEGATE(
+                               MoreOptionsPresenter::onAudioStateChanged, this));
        }
 
        Result MoreOptionsPresenter::prepare(ElmWidget &parent)
@@ -125,13 +139,21 @@ namespace callui {
 
                FAIL_RETURN(createButtons(), "createButtons() failed!");
 
-               FAIL_RETURN(update(), "update() failed!");
+               m_sm->addAudioStateHandler(DELEGATE(
+                               MoreOptionsPresenter::onAudioStateChanged, this));
+
+               update();
 
                addDeactivatorException(this);
 
                return RES_OK;
        }
 
+       void MoreOptionsPresenter::onAudioStateChanged(AudioStateType state)
+       {
+               updateLeftSlot();
+       }
+
        Result MoreOptionsPresenter::createWidget(ElmWidget &parent)
        {
                m_widget = Layout::Builder().
@@ -183,81 +205,60 @@ namespace callui {
                return RES_OK;
        }
 
-       Result MoreOptionsPresenter::updateSlots()
+       void MoreOptionsPresenter::updateSlots()
        {
-               FAIL_RETURN(updateTopSlot(), "updateTopSlot() failed");
-               FAIL_RETURN(updateLeftSlot(), "updateLeftSlot() failed");
-               FAIL_RETURN(updateRightSlot(), "updateRightSlot() failed");
-               FAIL_RETURN(updateBottomSlot(), "updateBottomSlot() failed");
-
-               return RES_OK;
+               updateTopSlot();
+               updateLeftSlot();
+               updateRightSlot();
+               updateBottomSlot();
        }
 
-       Result MoreOptionsPresenter::updateTopSlot()
+       void MoreOptionsPresenter::updateTopSlot()
        {
                auto active = m_cm->getActiveCall();
                auto held = m_cm->getHeldCall();
 
-               auto *eo = m_panelLy->unsetContent(impl::PART_SWL_PANEL_LY_TOP);
-               if (eo) {
-                       hide(*asWidget(eo));
-               }
+               unsetPanelContent(impl::PART_SWL_PANEL_LY_TOP);
 
                if (active) {
                        if (held) {
-                               m_panelLy->setContent(*m_btnSwap, impl::PART_SWL_PANEL_LY_TOP);
-                               show(*m_btnSwap);
+                               setPanelContent(m_btnSwap, impl::PART_SWL_PANEL_LY_TOP);
                        }
                } else if (held) {
-                       m_panelLy->setContent(*m_btnUnhold, impl::PART_SWL_PANEL_LY_TOP);
-                       show(*m_btnUnhold);
+                       setPanelContent(m_btnUnhold, impl::PART_SWL_PANEL_LY_TOP);
                } else {
-                       LOG_RETURN(RES_FAIL, "Undefined state");
+                       LOG_RETURN_VOID(RES_FAIL, "Undefined state");
                }
-
-               return RES_OK;
        }
 
-       Result MoreOptionsPresenter::updateLeftSlot()
+       void MoreOptionsPresenter::updateLeftSlot()
        {
-               auto *eo = m_panelLy->unsetContent(impl::PART_SWL_PANEL_LY_LEFT);
-               if (eo) {
-                       hide(*asWidget(eo));
-               }
-
-               m_panelLy->setContent(*m_btnHeadset, impl::PART_SWL_PANEL_LY_LEFT);
-               show(*m_btnHeadset);
-               disable(*m_btnHeadset);
+               unsetPanelContent(impl::PART_SWL_PANEL_LY_LEFT);
 
-               return RES_OK;
+               if (m_sm->getAudioState() != AudioStateType::BT) {
+                       setPanelContent(m_btnHeadset, impl::PART_SWL_PANEL_LY_LEFT);
+                       if (!m_sm->isBluetoothSupported()) {
+                               disable(*m_btnHeadset);
+                       }
+               } else {
+                       setPanelContent(m_btnGear, impl::PART_SWL_PANEL_LY_LEFT);
+               }
        }
 
-       Result MoreOptionsPresenter::updateRightSlot()
+       void MoreOptionsPresenter::updateRightSlot()
        {
-               auto *eo = m_panelLy->unsetContent(impl::PART_SWL_PANEL_LY_RIGHT);
-               if (eo) {
-                       hide(*asWidget(eo));
+               if (!m_panelLy->getContent(impl::PART_SWL_PANEL_LY_RIGHT)) {
+                       setPanelContent(m_btnPhone, impl::PART_SWL_PANEL_LY_RIGHT);
+                       disable(*m_btnPhone);
                }
-
-               m_panelLy->setContent(*m_btnPhone, impl::PART_SWL_PANEL_LY_RIGHT);
-               show(*m_btnPhone);
-               disable(*m_btnPhone);
-
-               return RES_OK;
        }
 
-       Result MoreOptionsPresenter::updateBottomSlot()
+       void MoreOptionsPresenter::updateBottomSlot()
        {
-               auto *eo = m_panelLy->unsetContent(impl::PART_SWL_PANEL_LY_BOTTOM);
-               if (eo) {
-                       hide(*asWidget(eo));
+               if (!m_panelLy->getContent(impl::PART_SWL_PANEL_LY_BOTTOM)) {
+                       setPanelContent(m_btnKeypad, impl::PART_SWL_PANEL_LY_BOTTOM);
+                       disable(*m_btnKeypad);
                }
-
-               m_panelLy->setContent(*m_btnKeypad, impl::PART_SWL_PANEL_LY_BOTTOM);
-               show(*m_btnKeypad);
-               disable(*m_btnKeypad);
-
-               return RES_OK;
        }
 
        Result MoreOptionsPresenter::createButtons()
@@ -333,7 +334,15 @@ namespace callui {
 
        void MoreOptionsPresenter::onHeadsetBtnClick(Widget &sender, void *eventInfo)
        {
-               ELOG("Not implemented");
+               auto res = m_sm->setBluetoothState(true);
+
+               if (res == RES_NOT_CONNECTED) {
+                       FAIL_RETURN_VOID(launchBluetoothSettings(),
+                                       "launchBluetoothSettings() failed");
+               } else {
+                       FAIL_RETURN_VOID(res,
+                                       "setBluetoothState() failed");
+               }
        }
 
        void MoreOptionsPresenter::onPhoneBtnClick(Widget &sender, void *eventInfo)
@@ -348,7 +357,7 @@ namespace callui {
 
        void MoreOptionsPresenter::onGearBtnClick(Widget &sender, void *eventInfo)
        {
-               ELOG("Not implemented");
+               FAIL_RETURN_VOID(m_sm->setBluetoothState(false),"setBluetoothState() failed");
        }
 
        StyledWidgetSRef MoreOptionsPresenter::createButton(
@@ -376,13 +385,10 @@ namespace callui {
                return *m_widget;
        }
 
-       Result MoreOptionsPresenter::update()
+       void MoreOptionsPresenter::update()
        {
-               FAIL_RETURN(updateSlots(), "updateSlots() failed!");
-
-               FAIL_RETURN(updateStatusText(), "updateStatusText() failed!");
-
-               return RES_OK;
+               updateSlots();
+               updateStatusText();
        }
 
        void MoreOptionsPresenter::onActivate(Evas_Object *obj, const char *emission, const char *source)
@@ -412,7 +418,7 @@ namespace callui {
                }
        }
 
-       Result MoreOptionsPresenter::updateStatusText()
+       void MoreOptionsPresenter::updateStatusText()
        {
                m_panelLy->setText("", impl::PART_TXT_STATUS);
 
@@ -426,23 +432,21 @@ namespace callui {
                        if (active->isDialingMode()) {
                                m_panelLy->setText(STR_DIALING_CALL, impl::PART_TXT_STATUS);
                                m_panelLy->emit(impl::SIGNAL_STATUS_TXT_BIG);
-                               return RES_OK;
+                               return;
                        }
                        m_info = active->getInfo();
                        if (!m_info) {
-                               LOG_RETURN(RES_FAIL, "Call Info is NULL");
+                               LOG_RETURN_VOID(RES_FAIL, "Call Info is NULL");
                        }
                        m_duration = m_info->getDuration();
                        setCallDuration(m_duration, *m_panelLy, impl::PART_TXT_STATUS);
                        updateStatusFontSize();
 
-                       FAIL_RETURN(startCallDurationTimer(), "startTimer() failed!");
+                       FAIL_RETURN_VOID(startCallDurationTimer(), "startTimer() failed!");
 
                } else {
-                       LOG_RETURN(RES_FAIL, "Undefined state");
+                       LOG_RETURN_VOID(RES_FAIL, "Undefined state");
                }
-
-               return RES_OK;
        }
 
        void MoreOptionsPresenter::updateStatusFontSize()
@@ -494,4 +498,23 @@ namespace callui {
                        m_timer = nullptr;
                }
        }
+
+       Result MoreOptionsPresenter::launchBluetoothSettings()
+       {
+               LOG_RETURN(RES_FAIL, "Not implemented");
+       }
+
+       void MoreOptionsPresenter::unsetPanelContent(const EdjePart &part)
+       {
+               auto *eo = m_panelLy->unsetContent(part);
+               if (eo) {
+                       hide(*asWidget(eo));
+               }
+       }
+
+       void MoreOptionsPresenter::setPanelContent(StyledWidgetSRef &widget, const EdjePart &part)
+       {
+               m_panelLy->setContent(*widget, part);
+               show(*widget);
+       }
 }
index 1395274275fccd0ca23240d2a1b110fd6379fa8c..637b4eee85ae3c5ad1ad7ee195f5b8ce3e8cf709 100644 (file)
@@ -169,7 +169,6 @@ namespace callui {
                                "createGenlist() failed!");
 
                addDeactivatorException(this);
-
                deactivateBy(m_widget.get());
 
                return RES_OK;
@@ -308,6 +307,7 @@ namespace callui {
                        LOG_RETURN(RES_FAIL, "elm_genlist_add() failed!");
                }
                eext_circle_object_genlist_scroller_policy_set(m_circleEo, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+               deactivateRotary();
 
                FAIL_RETURN(fillGenlist(), "fillGenlist() failed!");