/* * Copyright (C) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * 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 "napi_telephony_observer.h" #include "event_listener_manager.h" #include "telephony_callback_event_id.h" #include "telephony_log_wrapper.h" #include "update_infos.h" namespace OHOS { namespace Telephony { void NapiTelephonyObserver::OnCallStateUpdated(int32_t slotId, int32_t callState, const std::u16string &phoneNumber) { TELEPHONY_LOGI("OnCallStateUpdated slotId = %{public}d, callState = %{public}d", slotId, callState); std::unique_ptr callStateInfo = std::make_unique(slotId, callState, phoneNumber); if (callStateInfo == nullptr) { TELEPHONY_LOGE("callStateInfo is nullptr!"); return; } EventListenerManager::SendEvent(ToUint32t(TelephonyCallbackEventId::EVENT_ON_CALL_STATE_UPDATE), callStateInfo); } void NapiTelephonyObserver::OnSignalInfoUpdated( int32_t slotId, const std::vector> &signalInfoList) { TELEPHONY_LOGI("OnSignalInfoUpdated slotId = %{public}d, signalInfoList.size = %{public}zu", slotId, signalInfoList.size()); std::unique_ptr infoList = std::make_unique(slotId, signalInfoList); if (infoList == nullptr) { TELEPHONY_LOGE("SignalUpdateInfo is nullptr!"); return; } EventListenerManager::SendEvent(ToUint32t(TelephonyCallbackEventId::EVENT_ON_SIGNAL_INFO_UPDATE), infoList); } void NapiTelephonyObserver::OnNetworkStateUpdated(int32_t slotId, const sptr &networkState) { TELEPHONY_LOGI( "OnNetworkStateUpdated slotId = %{public}d, networkState = %{public}d", slotId, networkState == nullptr); std::unique_ptr networkStateUpdateInfo = std::make_unique(slotId, networkState); if (networkStateUpdateInfo == nullptr) { TELEPHONY_LOGE("NetworkStateUpdateInfo is nullptr!"); return; } EventListenerManager::SendEvent( ToUint32t(TelephonyCallbackEventId::EVENT_ON_NETWORK_STATE_UPDATE), networkStateUpdateInfo); } void NapiTelephonyObserver::OnSimStateUpdated( int32_t slotId, CardType type, SimState state, LockReason reason) { TELEPHONY_LOGI("OnSimStateUpdated slotId = %{public}d, simState = %{public}d", slotId, state); std::unique_ptr simStateUpdateInfo = std::make_unique(slotId, type, state, reason); if (simStateUpdateInfo == nullptr) { TELEPHONY_LOGE("SimStateUpdateInfo is nullptr!"); return; } EventListenerManager::SendEvent( ToUint32t(TelephonyCallbackEventId::EVENT_ON_SIM_STATE_UPDATE), simStateUpdateInfo); } void NapiTelephonyObserver::OnCellInfoUpdated(int32_t slotId, const std::vector> &vec) { TELEPHONY_LOGI("OnCellInfoUpdated slotId = %{public}d, cell info size = %{public}zu", slotId, vec.size()); std::unique_ptr cellInfo = std::make_unique(slotId, vec); if (cellInfo == nullptr) { TELEPHONY_LOGE("CellInfomationUpdate is nullptr!"); return; } EventListenerManager::SendEvent(ToUint32t(TelephonyCallbackEventId::EVENT_ON_CELL_INFOMATION_UPDATE), cellInfo); } void NapiTelephonyObserver::OnCellularDataConnectStateUpdated( int32_t slotId, int32_t dataState, int32_t networkType) { TELEPHONY_LOGD("OnCellularDataConnectStateUpdated slotId=%{public}d, dataState=%{public}d, networkType=" "%{public}d", slotId, dataState, networkType); std::unique_ptr cellularDataConnectState = std::make_unique(slotId, dataState, networkType); if (cellularDataConnectState == nullptr) { TELEPHONY_LOGE("OnCellularDataConnectStateUpdated cellularDataConnectState is nullptr!"); return; } EventListenerManager::SendEvent( ToUint32t(TelephonyCallbackEventId::EVENT_ON_CELLULAR_DATA_CONNECTION_UPDATE), cellularDataConnectState); } void NapiTelephonyObserver::OnCellularDataFlowUpdated(int32_t slotId, int32_t dataFlowType) { TELEPHONY_LOGI( "OnCellularDataFlowUpdated slotId = %{public}d, dataFlowType = %{public}d", slotId, dataFlowType); std::unique_ptr cellularDataFlowUpdateInfo = std::make_unique(slotId, dataFlowType); if (cellularDataFlowUpdateInfo == nullptr) { TELEPHONY_LOGE("CellularDataFlowUpdate is nullptr!"); return; } EventListenerManager::SendEvent( ToUint32t(TelephonyCallbackEventId::EVENT_ON_CELLULAR_DATA_FLOW_UPDATE), cellularDataFlowUpdateInfo); } void NapiTelephonyObserver::OnCfuIndicatorUpdated(int32_t slotId, bool cfuResult) { TELEPHONY_LOGI("OnCfuIndicatorUpdated slotId = %{public}d, cfuResult = %{public}d", slotId, cfuResult); std::unique_ptr cfuIndicatorUpdateInfo = std::make_unique(slotId, cfuResult); if (cfuIndicatorUpdateInfo == nullptr) { TELEPHONY_LOGE("CfuIndicatorUpdate is nullptr!"); return; } EventListenerManager::SendEvent( ToUint32t(TelephonyCallbackEventId::EVENT_ON_CFU_INDICATOR_UPDATE), cfuIndicatorUpdateInfo); } void NapiTelephonyObserver::OnIccAccountUpdated() { TELEPHONY_LOGI("OnIccAccountUpdated begin"); EventListenerManager::SendEvent(ToUint32t(TelephonyCallbackEventId::EVENT_ON_ICC_ACCOUNT_UPDATE)); } void NapiTelephonyObserver::OnVoiceMailMsgIndicatorUpdated(int32_t slotId, bool voiceMailMsgResult) { TELEPHONY_LOGI("OnVoiceMailMsgIndicatorUpdated slotId = %{public}d, voiceMailMsgResult = %{public}d", slotId, voiceMailMsgResult); std::unique_ptr voiceMailMsgIndicatorUpdateInfo = std::make_unique(slotId, voiceMailMsgResult); if (voiceMailMsgIndicatorUpdateInfo == nullptr) { TELEPHONY_LOGE("VoiceMailMsgIndicatorUpdate is nullptr!"); return; } EventListenerManager::SendEvent( ToUint32t(TelephonyCallbackEventId::EVENT_ON_VOICE_MAIL_MSG_INDICATOR_UPDATE), voiceMailMsgIndicatorUpdateInfo); } } // namespace Telephony } // namespace OHOS