From 983178198cfe50650bb7d7f23d5af02afaa3ce8e Mon Sep 17 00:00:00 2001 From: Igor Olshevskyi Date: Wed, 21 Jun 2017 08:42:38 +0300 Subject: [PATCH] TizenRefApp-8725 [Call UI] Add possibility to launch Bluetooth Headset settings application Change-Id: I2dce006283baa9e3ca586a91305753e654a9b80c --- src/common.h | 2 + src/helpers.h | 36 ++++++++++ src/helpers.hpp | 87 +++++++++++++++++++++++++ src/model/BluetoothVolume.cpp | 27 +++++--- src/presenters/MoreOptionsPresenter.cpp | 20 +++++- 5 files changed, 161 insertions(+), 11 deletions(-) create mode 100644 src/helpers.h create mode 100644 src/helpers.hpp diff --git a/src/common.h b/src/common.h index 8d05486..1d8b345 100644 --- a/src/common.h +++ b/src/common.h @@ -28,6 +28,8 @@ #include "ucl/gui/stdTheme.h" #include "ucl/gui/helpers.h" +#include "helpers.h" + #undef UCL_LOG_TAG #define UCL_LOG_TAG "CALLUI" diff --git a/src/helpers.h b/src/helpers.h new file mode 100644 index 0000000..4bb49d6 --- /dev/null +++ b/src/helpers.h @@ -0,0 +1,36 @@ +/* + * 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_HELPERS_H__ +#define __CALLUI_HELPERS_H__ + +#include "types.h" + +namespace callui { namespace util { + + template + ucl::Result get(GETTER &&getter, V &result, ARGS &&...args); + + template + ucl::Result getNz(GETTER &&getter, V &result, ARGS &&...args); + + template + ucl::Result call(FUNC &&func, ARGS &&...args); +}} + +#include "helpers.hpp" + +#endif // __CALLUI_HELPERS_H__ diff --git a/src/helpers.hpp b/src/helpers.hpp new file mode 100644 index 0000000..d44e8e0 --- /dev/null +++ b/src/helpers.hpp @@ -0,0 +1,87 @@ +/* + * 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 "ucl/util/helpers.h" +#include "ucl/util/logging.h" + +namespace callui { namespace util { namespace himpl { + + template + inline ucl::Result get(GETTER &&getter, bool optional, + std::string &result, ARGS &&...args) + { + char *value = nullptr; + const int ret = getter(std::forward(args)..., &value); + if ((ret != 0) || (!optional && ucl::isEmpty(value))) { + UCL_ELOG("get() failed: %d", ret); + return ucl::RES_FAIL; + } + + if (value) { + result = value; + free(value); + } else { + result.clear(); + } + + return ucl::RES_OK; + } + + template + inline ucl::Result get(GETTER &&getter, bool optional, + V &result, ARGS &&...args) + { + typename std::remove_pointer::type value = {}; + + const int ret = getter(std::forward(args)..., &value); + if ((ret != 0) || (!optional && !value)) { + UCL_ELOG("get() failed: %d", ret); + return ucl::RES_FAIL; + } + + result = value; + + return ucl::RES_OK; + } +}}} + +namespace callui { namespace util { + + template + inline ucl::Result get(GETTER &&getter, V &result, ARGS &&...args) + { + return himpl::get(std::forward(getter), true, + result, std::forward(args)...); + } + + template + inline ucl::Result getNz(GETTER &&getter, V &result, ARGS &&...args) + { + return himpl::get(std::forward(getter), false, + result, std::forward(args)...); + } + + template + inline ucl::Result call(FUNC &&func, ARGS &&...args) + { + const int ret = func(std::forward(args)...); + if (ret != 0) { + UCL_ELOG("func() failed: %d", ret); + return ucl::RES_FAIL; + } + return ucl::RES_OK; + } +}} diff --git a/src/model/BluetoothVolume.cpp b/src/model/BluetoothVolume.cpp index 33d2260..6fcd6dd 100644 --- a/src/model/BluetoothVolume.cpp +++ b/src/model/BluetoothVolume.cpp @@ -57,8 +57,11 @@ namespace callui { Result BluetoothVolume::prepare() { - if (BT_ERROR_NONE != bt_initialize()) { - LOG_RETURN(RES_FAIL, "BT initialize failed"); + auto ret = bt_initialize(); + if (ret != BT_ERROR_NONE) { + LOG_RETURN(RES_FAIL, "BT initialize failed. " + "ret[%d] msg[%s]", ret, get_error_message(ret)); + } m_btInitialized = true; @@ -73,7 +76,8 @@ namespace callui { 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!"); + LOG_RETURN_VALUE(RES_FAIL, -1, "bt_ag_get_speaker_gain() failed. " + "ret[%d] msg[%s]", ret, get_error_message(ret)); } DLOG("BT Volume level [%d]", vol); return vol; @@ -88,7 +92,8 @@ namespace callui { { auto ret = bt_ag_notify_speaker_gain(volume); if (ret != BT_ERROR_NONE) { - LOG_RETURN(RES_FAIL, "bt_ag_notify_speaker_gain() failed!"); + LOG_RETURN(RES_FAIL, "bt_ag_notify_speaker_gain() failed! " + "ret[%d] msg[%s]", ret, get_error_message(ret)); } return RES_OK; } @@ -103,16 +108,16 @@ namespace callui { { auto ret = bt_audio_initialize(); if (ret != BT_ERROR_NONE) { - LOG_RETURN(RES_FAIL, "bt_audio_initialize() failed. [%d][%s]", - ret, get_error_message(ret)); + LOG_RETURN(RES_FAIL, "bt_audio_initialize() failed. ", + "ret[%d] msg[%s]", ret, get_error_message(ret)); } 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. [%d][%s]", - ret, get_error_message(ret)); + LOG_RETURN(RES_FAIL, "bt_ag_set_speaker_gain_changed_cb() failed. " + "ret[%d] msg[%s]", ret, get_error_message(ret)); } return RES_OK; @@ -133,13 +138,15 @@ namespace callui { 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"); + LOG_RETURN_VOID(RES_FAIL, "sound_manager_get_current_sound_type() failed. " + "ret[%d] msg[%s]", ret, get_error_message(ret)); } 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"); + LOG_RETURN_VOID(RES_FAIL, "sound_manager_get_current_sound_type() failed. " + "ret[%d] msg[%s]", ret, get_error_message(ret)); } if (isSCOOpened && soundType == SOUND_TYPE_CALL) { diff --git a/src/presenters/MoreOptionsPresenter.cpp b/src/presenters/MoreOptionsPresenter.cpp index e1d4e65..75e7b39 100644 --- a/src/presenters/MoreOptionsPresenter.cpp +++ b/src/presenters/MoreOptionsPresenter.cpp @@ -19,6 +19,7 @@ #include #include "ucl/gui/Layout.h" +#include "ucl/appfw/types.h" #include "model/ICallManager.h" #include "model/IHeldCall.h" @@ -535,7 +536,24 @@ namespace callui { Result MoreOptionsPresenter::launchBluetoothSettings() { - LOG_RETURN(RES_FAIL, "Not implemented"); + AutoAppCtrl appCtrl; + + FAIL_RETURN(util::getNz(app_control_create, appCtrl), + "app_control_create() failed!"); + + FAIL_RETURN(util::call(app_control_set_app_id, + appCtrl, "org.tizen.bluetooth"), + "app_control_set_app_id() failed!"); + + FAIL_RETURN(util::call(app_control_add_extra_data, + appCtrl, "launch-type", "call"), + "app_control_add_extra_data() failed!"); + + FAIL_RETURN(util::call(app_control_send_launch_request, + appCtrl, nullptr, nullptr), + "app_control_send_launch_request() failed!"); + + return RES_OK; } void MoreOptionsPresenter::unsetPanelContent(const EdjePart &part) -- 2.34.1