#include "IndicatorStateProvider.h"
#include "ConnectionStateSource.h"
+#include "RssiStateSource.h"
#include "common.h"
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;
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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__