TizenRefApp-8412 [Call UI] Implement RssiStateSource 37/126137/3
authorIgor Olshevskyi <i.olshevskyi@samsung.com>
Thu, 20 Apr 2017 06:13:06 +0000 (09:13 +0300)
committerIgor Olshevskyi <i.olshevskyi@samsung.com>
Thu, 20 Apr 2017 11:19:26 +0000 (14:19 +0300)
Change-Id: I8edf3a912ea3bc04697137036355e5453e376e76

inc/model/IndicatorState.h
inc/model/types.h
src/model/Call.cpp
src/model/ConnectionStateSource.cpp
src/model/ConnectionStateSource.h
src/model/RssiStateSource.cpp [new file with mode: 0644]
src/model/RssiStateSource.h [new file with mode: 0644]
src/model/helpers.h
src/model/helpers.hpp

index cd7ab138e4ab474063e471ca0c9f449e419db8c7..baf6b60d849b99747102bd5c8cdae414b628b6d7 100644 (file)
@@ -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__
index ed47e7d68cf67466c5933437235dbe02d93b2027..867774a256f10e88237164e24e30312b75a98c29 100644 (file)
@@ -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,
index 6346ea4fe1e2e8effdf04f54f0327f4f3f8a8bd9..d24fe62209a15ad87cf50b52ef3d56df37e421da 100644 (file)
@@ -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;
index 6c77f1a7e8d40c7dc6bb0d884ae1d0f408613524..24e3ec00987b2299e870e3c553102fa06e03e0e4 100644 (file)
@@ -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);
                }
 
index 8627f50730ba79b6c927f7af8bf80a2d2ce42224..ba6c7498a43e3dd21740670a9122f84755d25915 100644 (file)
@@ -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 (file)
index 0000000..58ae978
--- /dev/null
@@ -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<RssiStateSource>();
+               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<IndicatorProperty>(bits.property) != IndicatorProperty::RSSI) {
+                       ELOG("State of incorrect property type [%d]", bits.property);
+                       return {};
+               }
+
+               return bits;
+       }
+
+       RssiState getRssiState(IndicatorState state)
+       {
+               return static_cast<RssiState>(
+                               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 (file)
index 0000000..58d1fda
--- /dev/null
@@ -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 <vconf.h>
+
+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>;
+               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__
index 2f11b91d25f698e51622366a6487ff0942339d93..d92e1492282b9afbf8a6c825f190151829f61cab 100644 (file)
@@ -38,6 +38,8 @@ namespace callui {
 
        cm_call_answer_type_e convertCUICallAnswerType(CallAnswerType type);
 
+       bool isFlightModeActive();
+
        template<typename TYPE>
        constexpr auto convertEnumValueToInt(TYPE e) -> typename std::underlying_type<TYPE>::type
        {
index a6485e11022d4bcbd3ab6c9b5b809204582c70a0..42f7e10a2dad4ee969ef4128e590eda8e0163bae 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <call-manager.h>
+#include <vconf.h>
 
 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;
+       }
+
 }