TizenRefApp-8714 [Call UI] Implement DeviceStatePresenter 04/134604/1
authorIgor Olshevskyi <i.olshevskyi@samsung.com>
Thu, 15 Jun 2017 08:07:34 +0000 (11:07 +0300)
committerIgor Olshevskyi <i.olshevskyi@samsung.com>
Mon, 19 Jun 2017 10:27:03 +0000 (13:27 +0300)
Change-Id: Ia859df24fbf4cdee3e3237c428d3f43d7f2a3631

inc/presenters/DeviceStatePresenter.h [new file with mode: 0644]
inc/presenters/MainPage.h
inc/presenters/types.h
src/model/BluetoothVolume.cpp
src/presenters/DeviceStatePresenter.cpp [new file with mode: 0644]
src/presenters/MainPage.cpp
src/presenters/helpers.h
tizen-manifest.xml

diff --git a/inc/presenters/DeviceStatePresenter.h b/inc/presenters/DeviceStatePresenter.h
new file mode 100644 (file)
index 0000000..2cabe9c
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * 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_PRESENTERS_DEVICE_STATE_PRESENTER_H__
+#define __CALLUI_PRESENTERS_DEVICE_STATE_PRESENTER_H__
+
+#include "ucl/gui/Window.h"
+
+#include "types.h"
+
+namespace callui {
+
+       class DeviceStatePresenter final {
+       public:
+               class Builder {
+               public:
+                       Builder();
+                       Builder &setDisplayState(DisplayState state);
+                       Builder &setDisplayMode(DisplayMode mode);
+                       Builder &setCpuLockState(bool lockState);
+                       DeviceStatePresenterSRef build(
+                                       const ucl::WindowSRef &window) const;
+               private:
+                       DisplayState m_state;
+                       DisplayMode m_mode;
+                       bool m_lockState;
+               };
+
+       public:
+               ucl::Result setDisplayState(DisplayState state,
+                               bool forse = false);
+               ucl::Result setDisplayMode(DisplayMode mode);
+               ucl::Result setCpuLockState(bool lockState);
+
+       private:
+               friend class ucl::RefCountObj<DeviceStatePresenter>;
+               DeviceStatePresenter(ucl::RefCountObjBase &rc,
+                               const ucl::WindowSRef &window);
+               ~DeviceStatePresenter() = default;
+
+               ucl::Result prepare(DisplayState state,
+                               DisplayMode mode,
+                               bool lockState);
+
+       private:
+               ucl::WindowSRef m_window;
+               DisplayMode m_mode;
+               bool m_lockState;
+       };
+}
+
+#endif // __CALLUI_PRESENTERS_DEVICE_STATE_PRESENTER_H__
index 6f498684525313ca73d9a1754e27b59a5a046aaa..66b3f39907beffe37cf9c1b82c56609ef0a6203a 100644 (file)
@@ -77,6 +77,12 @@ namespace callui {
 
                bool detectMuteControlDisableState();
 
+               ucl::Result updateDeviceState(CallMode prevMode, CallMode curMode);
+
+               ucl::Result createWidget();
+               ucl::Result createIndicatorPresenter();
+               ucl::Result createDisplayPresenter();
+
                // Presenter
 
                virtual void onActivateBy(const DeactivatorInfo &info) final override;
@@ -95,6 +101,7 @@ namespace callui {
                ucl::LayoutSRef m_widget;
                ucl::LayoutSRef m_rmLy;
                ucl::StyledWidgetSRef m_bottomBtn;
+
                ICallSRef m_call;
                ICallManagerSRef m_cm;
                IndicatorSRef m_indicator;
@@ -102,7 +109,9 @@ namespace callui {
                AcceptRejectPresenterSRef m_acceptRejectPrs;
                RejectMsgPresenterSRef m_rmPrs;
                AccessoryPresenterSRef m_accessoryPrs;
-               MoreOptionsPresenterSRef m_moreOptions;
+               MoreOptionsPresenterSRef m_moreOptionsPrs;
+               DeviceStatePresenterSRef m_devicePrs;
+
                CallMode m_mode;
                Ecore_Timer *m_ecTimer;
                bool m_ecTimerBtnReq;
index dbccc849a1920f21113e6823bbce30e691e2f39f..297b4e00aea93be7ea41d199cfcbbbe164df8b2d 100644 (file)
@@ -44,6 +44,19 @@ namespace callui {
                SHOWN
        };
 
+       enum class DisplayState {
+               UNDEFINED,
+               ON,
+               OFF,
+               DIM
+       };
+
+       enum class DisplayMode {
+               UNDEFINED,
+               REGULAR,
+               TOP_PRIORITY
+       };
+
        UCL_DECLARE_REF_ALIASES(Page);
        UCL_DECLARE_REF_ALIASES(MainPage);
        UCL_DECLARE_REF_ALIASES(KeypadPage);
@@ -60,6 +73,8 @@ namespace callui {
        UCL_DECLARE_REF_ALIASES(AccessoryPresenter);
        UCL_DECLARE_REF_ALIASES(MoreOptionsPresenter);
 
+       UCL_DECLARE_REF_ALIASES(DeviceStatePresenter);
+
        using AcceptDialogHandler = ucl::WeakDelegate<bool(AcceptDialog &, AcceptDialogEvent)>;
        using RejectMsgStateHandler = ucl::WeakDelegate<void(RejectMsgState)>;
        using RejectMsgSelectHandler = ucl::WeakDelegate<void(const IRejectMsgSRef &rm)>;
index 633a84922137a9658f739d2373203fe56efdcfbd..33d22605e648f869bc4afa16035a140e416cc0c7 100644 (file)
@@ -103,14 +103,16 @@ namespace callui {
        {
                auto ret = bt_audio_initialize();
                if (ret != BT_ERROR_NONE) {
-                       LOG_RETURN(RES_FAIL, "bt_audio_initialize() failed");
+                       LOG_RETURN(RES_FAIL, "bt_audio_initialize() failed. [%d][%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");
+                       LOG_RETURN(RES_FAIL, "bt_ag_set_speaker_gain_changed_cb() failed. [%d][%s]",
+                                               ret, get_error_message(ret));
                }
 
                return RES_OK;
diff --git a/src/presenters/DeviceStatePresenter.cpp b/src/presenters/DeviceStatePresenter.cpp
new file mode 100644 (file)
index 0000000..c59bd1b
--- /dev/null
@@ -0,0 +1,198 @@
+/*
+ * 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 "presenters/DeviceStatePresenter.h"
+
+#include <device/power.h>
+#include <device/display.h>
+#include <efl_util.h>
+
+#include "common.h"
+
+namespace callui {
+
+       using namespace ucl;
+
+       // DeviceStatePresenter::Builder
+
+       DeviceStatePresenter::Builder::Builder():
+                       m_state(DisplayState::UNDEFINED),
+                       m_mode(DisplayMode::UNDEFINED),
+                       m_lockState(false)
+       {
+       }
+
+       DeviceStatePresenter::Builder &
+       DeviceStatePresenter::Builder::setDisplayState(DisplayState state)
+       {
+               m_state = state;
+               return *this;
+       }
+
+       DeviceStatePresenter::Builder &
+       DeviceStatePresenter::Builder::setDisplayMode(DisplayMode mode)
+       {
+               m_mode = mode;
+               return *this;
+       }
+
+       DeviceStatePresenter::Builder &
+       DeviceStatePresenter::Builder::setCpuLockState(bool lockState)
+       {
+               m_lockState = lockState;
+               return *this;
+       }
+
+       DeviceStatePresenterSRef
+       DeviceStatePresenter::Builder::build(const ucl::WindowSRef &window) const
+       {
+               auto result = makeShared<DeviceStatePresenter>(window);
+               FAIL_RETURN_VALUE(result->prepare(m_state,
+                               m_mode, m_lockState), {},
+                               "result->prepare() failed!");
+               return result;
+       }
+
+       // DeviceStatePresenter
+
+       DeviceStatePresenter::DeviceStatePresenter(RefCountObjBase &rc,
+                       const ucl::WindowSRef &window):
+                                       m_window(window),
+                                       m_mode(DisplayMode::UNDEFINED),
+                                       m_lockState(false)
+       {
+       }
+
+       Result DeviceStatePresenter::prepare(DisplayState state,
+                       DisplayMode mode,
+                       bool lockState)
+       {
+               if (state != DisplayState::UNDEFINED) {
+                       FAIL_RETURN(setDisplayState(state, true),
+                                       "setDisplayState() failed");
+               }
+
+               if (mode != DisplayMode::UNDEFINED) {
+                       FAIL_RETURN(setDisplayMode(mode),
+                                       "setDisplayMode() failed");
+               }
+
+               if (lockState) {
+                       FAIL_RETURN(setCpuLockState(lockState),
+                                       "setCpuLockState() failed");
+               }
+
+               return RES_OK;
+       }
+
+       Result DeviceStatePresenter::setDisplayState(DisplayState state, bool forse)
+       {
+               if (state == DisplayState::UNDEFINED) {
+                       LOG_RETURN(RES_FAIL, "State is undefined");
+               }
+
+               display_state_e dispState = DISPLAY_STATE_NORMAL;
+
+               if (!forse) {
+                       int res = device_display_get_state(&dispState);
+                       if (res != DEVICE_ERROR_NONE) {
+                               LOG_RETURN(RES_FAIL, "device_display_get_state() failed."
+                                               "res[%d] msg[%s]", res, get_error_message(res));
+                       }
+                       if ((state == DisplayState::ON
+                                       && dispState == DISPLAY_STATE_NORMAL)
+                                       || (state == DisplayState::DIM
+                                                       && dispState == DISPLAY_STATE_SCREEN_DIM)
+                                       || (state == DisplayState::OFF
+                                                       && dispState == DISPLAY_STATE_SCREEN_OFF)) {
+                               LOG_RETURN(RES_OK,
+                                               "Display state already set into needed state");
+                       }
+               }
+
+               switch (state) {
+               case DisplayState::ON:
+                       dispState = DISPLAY_STATE_NORMAL;
+                       break;
+               case DisplayState::DIM:
+                       dispState = DISPLAY_STATE_SCREEN_DIM;
+                       break;
+               case DisplayState::OFF:
+                       dispState = DISPLAY_STATE_SCREEN_OFF;
+                       break;
+               default:
+                       LOG_RETURN(RES_FAIL, "Undefined state");
+                       break;
+               }
+
+               int res = device_display_change_state(dispState);
+               if (res != DEVICE_ERROR_NONE) {
+                       LOG_RETURN(RES_FAIL, "device_display_change_state() failed."
+                                       "res[%d] msg[%s]", res, get_error_message(res));
+               }
+
+               return RES_OK;
+       }
+
+       Result DeviceStatePresenter::setDisplayMode(DisplayMode mode)
+       {
+               if (mode == DisplayMode::UNDEFINED) {
+                       LOG_RETURN(RES_FAIL, "Mode is undefined");
+               }
+
+               if (mode == m_mode) {
+                       LOG_RETURN(RES_OK, "Display mode already set");
+               }
+
+               m_mode = mode;
+
+               efl_util_screen_mode_e setScreenMode =
+                               (m_mode == DisplayMode::TOP_PRIORITY) ?
+                               EFL_UTIL_SCREEN_MODE_ALWAYS_ON :
+                               EFL_UTIL_SCREEN_MODE_DEFAULT;
+
+               int res = efl_util_set_window_screen_mode(*m_window, setScreenMode);
+               if (res != EFL_UTIL_ERROR_NONE) {
+                       LOG_RETURN(RES_FAIL, "Set window screen mode failed."
+                                       "res[%d] msg[%s]", res, get_error_message(res));
+               }
+
+               return RES_OK;
+       }
+
+       Result DeviceStatePresenter::setCpuLockState(bool lockState)
+       {
+               if (lockState == m_lockState) {
+                       LOG_RETURN(RES_OK, "Cpu lock state already set %s",
+                                       lockState ? "locked" : "unlocked");
+               }
+
+               m_lockState = lockState;
+
+               int res = m_lockState ?
+                               device_power_request_lock(POWER_LOCK_CPU, 0) :
+                               device_power_release_lock(POWER_LOCK_CPU);
+
+               if (res != DEVICE_ERROR_NONE) {
+                       LOG_RETURN(RES_FAIL, "Device power request %s failed.",
+                                       m_lockState ? "lock" : "unlock",
+                                       "res[%d] msg[%s]", res, get_error_message(res));
+               }
+
+               return RES_OK;
+       }
+
+}
index f81a420ad2d68e105f19e16c66cafda1042b8bf5..3504b7e4ca71a0d3229324814e09624fe6ac0cda 100644 (file)
@@ -35,6 +35,7 @@
 #include "presenters/RejectMsgPresenter.h"
 #include "presenters/AccessoryPresenter.h"
 #include "presenters/MoreOptionsPresenter.h"
+#include "presenters/DeviceStatePresenter.h"
 
 #include "resources.h"
 #include "common.h"
@@ -139,28 +140,14 @@ namespace callui {
 
        Result MainPage::prepare()
        {
-               DLOG();
                m_cm = m_call->getCallManager();
                if (!m_cm) {
                        LOG_RETURN(RES_FAIL, "Call manager is NULL!");
                }
 
-               m_widget = Layout::Builder().
-                               setTheme(impl::LAYOUT_MAIN_WIDGET).
-                               setIsOwner(true).
-                               build(getNaviframe());
-               if (!m_widget) {
-                       LOG_RETURN(RES_FAIL, "Layout::build() failed!");
-               }
-
-               m_indicator = Indicator::Builder().
-                               setIndicatorStateProvider(m_call->getIndicatorStateProvider()).
-                               build(*m_widget);
-               if (!m_indicator) {
-                       LOG_RETURN(RES_FAIL, "Indicator::build() failed!");
-               }
-
-               m_widget->setContent(m_indicator->getWidget().getEo(), impl::PART_SWL_INDICATOR);
+               FAIL_RETURN(createWidget(), "createWidget() failed!");
+               FAIL_RETURN(createIndicatorPresenter(), "createIndicatorPresenter() failed!");
+               FAIL_RETURN(createDisplayPresenter(), "createDisplayPresenter() failed!");
 
                auto win = m_widget->getWindow();
                if (!win) {
@@ -170,8 +157,7 @@ namespace callui {
                                MainPage::onPowerKeyUp, asWeak(*this)));
 
                return Page::prepare([this]() {
-                       return getNaviframe().
-                                       push(*m_widget);
+                       return getNaviframe().push(*m_widget);
                });
        }
 
@@ -411,7 +397,9 @@ namespace callui {
 
                stopEndCallTimer();
 
+               CallMode prevMode = m_mode;
                updateCallMode();
+
                if (m_mode == CallMode::UNDEFINED) {
                        requestExit();
                        return;
@@ -422,7 +410,7 @@ namespace callui {
 
                if (m_mode == CallMode::INCOMING) {
                        m_accessoryPrs.reset();
-                       m_moreOptions.reset();
+                       m_moreOptionsPrs.reset();
 
                        FAIL_RETURN_VOID(processIncomingCall(),
                                        "processIncomingCall() failed!");
@@ -433,7 +421,7 @@ namespace callui {
 
                        if (m_mode == CallMode::END) {
                                m_accessoryPrs.reset();
-                               m_moreOptions.reset();
+                               m_moreOptionsPrs.reset();
                                startEndCallTimer();
                        } else {
                                FAIL_RETURN_VOID(createAccessoryPresenter(),
@@ -442,19 +430,32 @@ namespace callui {
                                                "createMoreOptionsPresenter() failed");
                                FAIL_RETURN_VOID(createBottomBtn(impl::STYLE_BB_END_CALL),
                                                "createBottomBtn() failed");
-
-                               if (m_mode == CallMode::OUTGOING ||
-                                               (m_mode == CallMode::DURING &&
-                                                               (m_cm->getAvailableCalls() == CALL_FLAG_HELD))) {
-                                       m_accessoryPrs->setMuteControlDisabled(true);
-                               } else {
-                                       m_accessoryPrs->setMuteControlDisabled(false);
-                               }
                        }
                }
 
                FAIL_RETURN_VOID(createCallInfoPresenter(m_mode),
                                "createCallInfoPresenter() failed!");
+
+               FAIL_RETURN_VOID(updateDeviceState(prevMode, m_mode),
+                               "createCallInfoPresenter() failed!");
+       }
+
+       Result MainPage::updateDeviceState(CallMode prevMode, CallMode curMode)
+       {
+               if (curMode == CallMode::INCOMING && curMode != prevMode) {
+                       m_devicePrs->setDisplayState(DisplayState::ON);
+                       m_devicePrs->setDisplayMode(DisplayMode::TOP_PRIORITY);
+                       m_devicePrs->setCpuLockState(true);
+               } else if (prevMode == CallMode::INCOMING && prevMode != curMode) {
+                       m_devicePrs->setDisplayMode(DisplayMode::REGULAR);
+                       m_devicePrs->setCpuLockState(false);
+               }
+
+               if (curMode == CallMode::END) {
+                       m_devicePrs->setDisplayState(DisplayState::ON);
+               }
+
+               return RES_OK;
        }
 
        bool MainPage::detectMuteControlDisableState()
@@ -464,6 +465,54 @@ namespace callui {
                                                (m_cm->getAvailableCalls() == CALL_FLAG_HELD)));
        }
 
+       Result MainPage::createWidget()
+       {
+               m_widget = Layout::Builder().
+                               setTheme(impl::LAYOUT_MAIN_WIDGET).
+                               setIsOwner(true).
+                               build(getNaviframe());
+
+               if (!m_widget) {
+                       LOG_RETURN(RES_FAIL, "Layout::build() failed!");
+               }
+
+               return RES_OK;
+       }
+
+       Result MainPage::createIndicatorPresenter()
+       {
+               m_indicator = Indicator::Builder().
+                               setIndicatorStateProvider(
+                                               m_call->getIndicatorStateProvider()).
+                               build(*m_widget);
+
+               if (!m_indicator) {
+                       LOG_RETURN(RES_FAIL, "Indicator::build() failed!");
+               }
+
+               m_widget->setContent(m_indicator->getWidget().getEo(), impl::PART_SWL_INDICATOR);
+
+               return RES_OK;
+       }
+
+       Result MainPage::createDisplayPresenter()
+       {
+               auto win = m_widget->getWindow();
+               if (!win) {
+                       LOG_RETURN(RES_FAIL, "win is NULL!");
+               }
+
+               m_devicePrs = DeviceStatePresenter::Builder().
+                               setDisplayState(DisplayState::ON).
+                               build(asShared(win));
+
+               if (!m_devicePrs) {
+                       LOG_RETURN(RES_FAIL, "DisplayPresenter::build() failed!");
+               }
+
+               return RES_OK;
+       }
+
        Result MainPage::createAccessoryPresenter()
        {
                if (m_accessoryPrs) {
@@ -491,26 +540,26 @@ namespace callui {
 
        Result MainPage::createMoreOptionsPresenter()
        {
-               if (m_moreOptions) {
+               if (m_moreOptionsPrs) {
                        ILOG("Already exists. No need to create new one. Just update.");
-                       m_moreOptions->update();
+                       m_moreOptionsPrs->update();
                        return RES_OK;
                }
 
-               m_moreOptions = MoreOptionsPresenter::Builder().
+               m_moreOptionsPrs = MoreOptionsPresenter::Builder().
                                setCallManager(m_cm).
                                setSoundManager(m_call->getSoundManager()).
                                setNaviframe(asShared(getNaviframe())).
                                build(*m_widget);
 
-               if (!m_moreOptions) {
+               if (!m_moreOptionsPrs) {
                        LOG_RETURN(RES_FAIL,
                                        "MoreOptionsPresenter::build() failed!");
                }
 
-               m_widget->setContent(m_moreOptions->getWidget(),
+               m_widget->setContent(m_moreOptionsPrs->getWidget(),
                                impl::PART_SWL_MORE_OPTION);
-               addDeactivatorSource(m_moreOptions->getWidget());
+               addDeactivatorSource(m_moreOptionsPrs->getWidget());
 
                return RES_OK;
        }
@@ -540,11 +589,8 @@ namespace callui {
 
        void MainPage::RejectMsgStateCb(RejectMsgState state)
        {
-               if (state == RejectMsgState::HIDDEN) {
-                       show(*m_rmLy);
-               } else {
-                       hide(*m_rmLy);
-               }
+               (state == RejectMsgState::HIDDEN) ?
+                               show(*m_rmLy) : hide(*m_rmLy);
        }
 
        void MainPage::RejectMsgSelectCb(const IRejectMsgSRef &rm)
@@ -591,8 +637,7 @@ namespace callui {
                                build(*m_widget);
 
                if (!m_callInfoPrs) {
-                       LOG_RETURN(RES_FAIL,
-                                       "CallerInfo::build() failed!");
+                       LOG_RETURN(RES_FAIL, "CallerInfo::build() failed!");
                }
                m_widget->setContent(m_callInfoPrs->getWidget().getEo(),
                                impl::PART_SWL_CALL_INFO);
index 0504407aaa4a42b84eccf036bb474ad3e4c9df1c..cc46cf7bc6fc44d0efe3ab7cb186154938a0b3d3 100644 (file)
@@ -34,6 +34,7 @@ namespace callui {
        void tryUpdateCallDurationTime(
                        struct tm &curTime, struct tm &compTime,
                        ucl::EdjeWidget &widget, const ucl::EdjePart &part);
+
 }
 
 #endif // __CALLUI_PRESENTERS_HELPERS_H__
index 6a76d4d76749b1b7090ae10f3568258ab8e0fde8..c0e14d6e0f18ac4ce664622d7978ad8c44dce90e 100644 (file)
@@ -25,5 +25,6 @@
         <privilege>http://tizen.org/privilege/notification</privilege>
         <privilege>http://tizen.org/privilege/message.read</privilege>
         <privilege>http://tizen.org/privilege/callhistory.read</privilege>
+        <privilege>http://tizen.org/privilege/display</privilege>
     </privileges>
 </manifest>