From: Igor Olshevskyi Date: Thu, 20 Apr 2017 06:13:06 +0000 (+0300) Subject: TizenRefApp-8412 [Call UI] Implement RssiStateSource X-Git-Tag: submit/tizen/20170630.111746~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f3ef966f192b2e5fa1f55c750d58a58fa583a4dd;p=profile%2Fwearable%2Fapps%2Fnative%2Fcall-ui.git TizenRefApp-8412 [Call UI] Implement RssiStateSource Change-Id: I8edf3a912ea3bc04697137036355e5453e376e76 --- diff --git a/inc/model/IndicatorState.h b/inc/model/IndicatorState.h index cd7ab13..baf6b60 100644 --- a/inc/model/IndicatorState.h +++ b/inc/model/IndicatorState.h @@ -27,6 +27,9 @@ namespace callui { ConnectionType getConnectionState(IndicatorState state); PacketDirection getPacketDirection(IndicatorState state); + RssiState getRssiState(IndicatorState state); + bool getRoamingState(IndicatorState state); + } #endif // __CALLUI_MODEL_INDICATOR_STATE_H__ diff --git a/inc/model/types.h b/inc/model/types.h index ed47e7d..867774a 100644 --- a/inc/model/types.h +++ b/inc/model/types.h @@ -111,6 +111,17 @@ namespace callui { INOUT }; + enum class RssiState { + NONE = 0, + LEVEL_0, + LEVEL_1, + LEVEL_2, + LEVEL_3, + LEVEL_4, + NO_SIGNAL, + FLIGHT_MODE + }; + enum class IndicatorProperty { NW_CONNECTION = 0, RSSI, diff --git a/src/model/Call.cpp b/src/model/Call.cpp index 6346ea4..d24fe62 100644 --- a/src/model/Call.cpp +++ b/src/model/Call.cpp @@ -25,6 +25,7 @@ #include "IndicatorStateProvider.h" #include "ConnectionStateSource.h" +#include "RssiStateSource.h" #include "common.h" @@ -141,13 +142,20 @@ namespace callui { LOG_RETURN(RES_FAIL, "IndicatorStateProvider::newInstance() failed!"); } - auto connectionStateSource = ConnectionStateSource::newInstance(); - if (!connectionStateSource) { + auto connStateSource = ConnectionStateSource::newInstance(); + if (!connStateSource) { LOG_RETURN(RES_FAIL, "ConnectionStateSource::newInstance() failed!"); } + FAIL_RETURN(m_indicatorStateProvider->setStateSource( + IndicatorProperty::NW_CONNECTION, connStateSource), + "setStateSource() failed!"); + auto rssiStateSource = RssiStateSource::newInstance(); + if (!rssiStateSource) { + LOG_RETURN(RES_FAIL, "ConnectionStateSource::newInstance() failed!"); + } FAIL_RETURN(m_indicatorStateProvider->setStateSource( - IndicatorProperty::NW_CONNECTION, connectionStateSource), + IndicatorProperty::RSSI, rssiStateSource), "setStateSource() failed!"); return RES_OK; diff --git a/src/model/ConnectionStateSource.cpp b/src/model/ConnectionStateSource.cpp index 6c77f1a..24e3ec0 100644 --- a/src/model/ConnectionStateSource.cpp +++ b/src/model/ConnectionStateSource.cpp @@ -71,16 +71,6 @@ namespace callui { return (state == VCONFKEY_WIFI_CONNECTED); } - bool ConnectionStateSource::isFlightMode() const - { - int status = false;; - if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &status) < 0) { - ELOG("Get Flight mode status failed!"); - return false; - } - return status; - } - bool ConnectionStateSource::isDnetConnected() const { int status = VCONFKEY_DNET_OFF; @@ -179,7 +169,7 @@ namespace callui { bool ConnectionStateSource::updateConnType() { - if (isFlightMode()) { + if (isFlightModeActive()) { return updateConnTypeBits(ConnectionType::NONE); } @@ -206,8 +196,6 @@ namespace callui { void ConnectionStateSource::onConnTypeChangedCb(keynode_t *node) { - ILOG(); - bool needNotify = updateConnType(); if (updatePacketDir()) { needNotify = true; @@ -260,10 +248,9 @@ namespace callui { bool ConnectionStateSource::updatePacketDir() { - ILOG(); PacketDirection direction = PacketDirection::NONE; - if (isFlightMode()) { + if (isFlightModeActive()) { return updatePacketDirBits(direction); } diff --git a/src/model/ConnectionStateSource.h b/src/model/ConnectionStateSource.h index 8627f50..ba6c749 100644 --- a/src/model/ConnectionStateSource.h +++ b/src/model/ConnectionStateSource.h @@ -46,7 +46,6 @@ namespace callui { void onPacketStateChangedCb(keynode_t *node); bool isWifiConnected() const; - bool isFlightMode() const; bool isDnetConnected() const; bool updateConnTypeBits(ConnectionType connType); diff --git a/src/model/RssiStateSource.cpp b/src/model/RssiStateSource.cpp new file mode 100644 index 0000000..58ae978 --- /dev/null +++ b/src/model/RssiStateSource.cpp @@ -0,0 +1,230 @@ +/* + * 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 "RssiStateSource.h" + +#include "common.h" + +namespace callui { + + using namespace ucl; + + RssiStateSource::Bits::Bits(): + value(0) + { + property = convertEnumValueToInt(IndicatorProperty::RSSI); + } + + RssiStateSource::Bits::Bits(const IndicatorState &state): + value(state.value) + { + } + + RssiStateSource::RssiStateSource() + { + } + + RssiStateSource::~RssiStateSource() + { + unsignSysStateCallbacks(); + } + + IIndicatorStateSourceSRef RssiStateSource::newInstance() + { + auto result = makeShared(); + FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!"); + return result; + } + + Result RssiStateSource::prepare() + { + FAIL_RETURN(signSysStateCallbacks(), "signSysStateCallbacks() failed!"); + + updateRssiState(); + updateRoamingState(); + + return RES_OK; + } + + bool RssiStateSource::isRoamingActive() const + { + int status = 0; + if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &status) != 0) { + ELOG("Get Flight mode status failed!"); + return false; + } + return (status == VCONFKEY_TELEPHONY_SVC_ROAM_ON); + } + + bool RssiStateSource::updateRssiStateBits(RssiState state) + { + int rssiStateInt = convertEnumValueToInt(state); + if (rssiStateInt != m_bits.rssiState) { + m_bits.rssiState = rssiStateInt; + return true; + } + return false; + } + + bool RssiStateSource::updateRoamingStateBits(bool state) + { + if (state != m_bits.isRoamingEnable) { + m_bits.rssiState = state; + return true; + } + return false; + } + + RssiState RssiStateSource::getCurRssiState() const + { + int status = 0; + if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &status) == 0) { + switch (status) { + case VCONFKEY_TELEPHONY_SVCTYPE_NONE : + case VCONFKEY_TELEPHONY_SVCTYPE_NOSVC : + case VCONFKEY_TELEPHONY_SVCTYPE_SEARCH : + return RssiState::NO_SIGNAL; + default : + break; + } + } else { + ELOG("Get telephony SVC type failed!"); + } + + status = 0; + if (vconf_get_int(VCONFKEY_TELEPHONY_RSSI, &status) == 0) { + switch (status) { + case VCONFKEY_TELEPHONY_RSSI_0: return RssiState::LEVEL_0; + case VCONFKEY_TELEPHONY_RSSI_1: return RssiState::LEVEL_1; + case VCONFKEY_TELEPHONY_RSSI_2: return RssiState::LEVEL_2; + case VCONFKEY_TELEPHONY_RSSI_3: return RssiState::LEVEL_3; + case VCONFKEY_TELEPHONY_RSSI_4: return RssiState::LEVEL_4; + default: + break; + } + } else { + ELOG("Get telephony RSSI level failed!"); + } + return RssiState::NONE; + } + + bool RssiStateSource::updateRssiState() + { + if (isFlightModeActive()) { + return updateRssiStateBits(RssiState::FLIGHT_MODE); + } + return updateRssiStateBits(getCurRssiState()); + } + + bool RssiStateSource::updateRoamingState() + { + return updateRoamingStateBits(isRoamingActive()); + } + + void RssiStateSource::onRssiChangedCb(keynode_t *node) + { + bool needNotify = updateRssiState(); + if (updateRoamingState()) { + needNotify = true; + } + + if (needNotify && m_handler) { + m_handler(); + } + } + + Result RssiStateSource::signSysStateCallbacks() + { + int res = vconf_notify_key_changed(VCONFKEY_TELEPHONY_SVC_ROAM, + CALLBACK_B(RssiStateSource::onRssiChangedCb), this); + if (res != 0) { + LOG_RETURN(RES_FAIL, "vconf_notify_key_changed() failed"); + } + + res = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, + CALLBACK_B(RssiStateSource::onRssiChangedCb), this); + if (res != 0) { + LOG_RETURN(RES_FAIL, "vconf_notify_key_changed() failed"); + } + + res = vconf_notify_key_changed(VCONFKEY_TELEPHONY_SVCTYPE, + CALLBACK_B(RssiStateSource::onRssiChangedCb), this); + if (res != 0) { + LOG_RETURN(RES_FAIL, "vconf_notify_key_changed() failed"); + } + + res = vconf_notify_key_changed(VCONFKEY_TELEPHONY_RSSI, + CALLBACK_B(RssiStateSource::onRssiChangedCb), this); + if (res != 0) { + LOG_RETURN(RES_FAIL, "vconf_notify_key_changed() failed"); + } + + res = vconf_notify_key_changed(VCONFKEY_TELEPHONY_ROAM_ICON_MODE, + CALLBACK_B(RssiStateSource::onRssiChangedCb), this); + if (res != 0) { + LOG_RETURN(RES_FAIL, "vconf_notify_key_changed() failed"); + } + + return RES_OK; + } + + void RssiStateSource::unsignSysStateCallbacks() + { + vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SVC_ROAM, + CALLBACK_B(RssiStateSource::onRssiChangedCb)); + vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, + CALLBACK_B(RssiStateSource::onRssiChangedCb)); + vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SVCTYPE, + CALLBACK_B(RssiStateSource::onRssiChangedCb)); + vconf_ignore_key_changed(VCONFKEY_TELEPHONY_RSSI, + CALLBACK_B(RssiStateSource::onRssiChangedCb)); + vconf_ignore_key_changed(VCONFKEY_TELEPHONY_ROAM_ICON_MODE, + CALLBACK_B(RssiStateSource::onRssiChangedCb)); + } + + IndicatorState RssiStateSource::getState() const + { + return {m_bits.value}; + } + + void RssiStateSource::setStateChangeHandler(StateChangeHandler handler) + { + m_handler = handler; + } + + RssiStateSource::Bits RssiStateSource::asBits(IndicatorState state) + { + Bits bits(state); + if (static_cast(bits.property) != IndicatorProperty::RSSI) { + ELOG("State of incorrect property type [%d]", bits.property); + return {}; + } + + return bits; + } + + RssiState getRssiState(IndicatorState state) + { + return static_cast( + RssiStateSource::asBits(state).rssiState); + } + + bool getRoamingState(IndicatorState state) + { + return RssiStateSource::asBits(state).isRoamingEnable; + } + +} diff --git a/src/model/RssiStateSource.h b/src/model/RssiStateSource.h new file mode 100644 index 0000000..58d1fda --- /dev/null +++ b/src/model/RssiStateSource.h @@ -0,0 +1,75 @@ +/* + * 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_RSSI_STATE_SOURCE_H__ +#define __CALLUI_MODEL_RSSI_STATE_SOURCE_H__ + +#include "IIndicatorStateSource.h" + +#include + +namespace callui { + + class RssiStateSource final : public IIndicatorStateSource { + public: + static IIndicatorStateSourceSRef newInstance(); + virtual ~RssiStateSource(); + + // IIndicatorStateSource + + virtual IndicatorState getState() const override final; + virtual void setStateChangeHandler(StateChangeHandler handler) override final; + + private: + friend class ucl::RefCountObj; + RssiStateSource(); + + ucl::Result prepare(); + ucl::Result signSysStateCallbacks(); + void unsignSysStateCallbacks(); + + bool isRoamingActive() const; + bool updateRssiStateBits(RssiState state); + bool updateRoamingStateBits(bool state); + RssiState getCurRssiState() const; + bool updateRssiState(); + bool updateRoamingState(); + + void onRssiChangedCb(keynode_t *node); + + private: + union Bits { + struct { + uint8_t property : 4; + uint8_t rssiState : 4; + uint8_t isRoamingEnable: 1; + }; + uint64_t value; + Bits(); + Bits(const IndicatorState &state); + }; + + public: + static Bits asBits(IndicatorState state); + + private: + Bits m_bits; + StateChangeHandler m_handler; + }; + +} + +#endif // __CALLUI_MODEL_RSSI_STATE_SOURCE_H__ diff --git a/src/model/helpers.h b/src/model/helpers.h index 2f11b91..d92e149 100644 --- a/src/model/helpers.h +++ b/src/model/helpers.h @@ -38,6 +38,8 @@ namespace callui { cm_call_answer_type_e convertCUICallAnswerType(CallAnswerType type); + bool isFlightModeActive(); + template constexpr auto convertEnumValueToInt(TYPE e) -> typename std::underlying_type::type { diff --git a/src/model/helpers.hpp b/src/model/helpers.hpp index a6485e1..42f7e10 100644 --- a/src/model/helpers.hpp +++ b/src/model/helpers.hpp @@ -15,6 +15,7 @@ */ #include +#include namespace callui { @@ -137,4 +138,14 @@ namespace callui { } } + inline bool isFlightModeActive() + { + int status = false;; + if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &status) != 0) { + ELOG("Get Flight mode status failed!"); + return false; + } + return status; + } + }