1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "napi_telephony_observer.h"
17 #include "event_listener_manager.h"
18 #include "telephony_callback_event_id.h"
19 #include "telephony_log_wrapper.h"
20 #include "update_infos.h"
21
22 namespace OHOS {
23 namespace Telephony {
OnCallStateUpdated(int32_t slotId,int32_t callState,const std::u16string & phoneNumber)24 void NapiTelephonyObserver::OnCallStateUpdated(int32_t slotId, int32_t callState, const std::u16string &phoneNumber)
25 {
26 TELEPHONY_LOGI("OnCallStateUpdated slotId = %{public}d, callState = %{public}d", slotId, callState);
27 std::unique_ptr<CallStateUpdateInfo> callStateInfo =
28 std::make_unique<CallStateUpdateInfo>(slotId, callState, phoneNumber);
29 if (callStateInfo == nullptr) {
30 TELEPHONY_LOGE("callStateInfo is nullptr!");
31 return;
32 }
33 EventListenerManager::SendEvent(ToUint32t(TelephonyCallbackEventId::EVENT_ON_CALL_STATE_UPDATE), callStateInfo);
34 }
35
OnSignalInfoUpdated(int32_t slotId,const std::vector<sptr<SignalInformation>> & signalInfoList)36 void NapiTelephonyObserver::OnSignalInfoUpdated(
37 int32_t slotId, const std::vector<sptr<SignalInformation>> &signalInfoList)
38 {
39 TELEPHONY_LOGI("OnSignalInfoUpdated slotId = %{public}d, signalInfoList.size = %{public}zu", slotId,
40 signalInfoList.size());
41 std::unique_ptr<SignalUpdateInfo> infoList = std::make_unique<SignalUpdateInfo>(slotId, signalInfoList);
42 if (infoList == nullptr) {
43 TELEPHONY_LOGE("SignalUpdateInfo is nullptr!");
44 return;
45 }
46 EventListenerManager::SendEvent(ToUint32t(TelephonyCallbackEventId::EVENT_ON_SIGNAL_INFO_UPDATE), infoList);
47 }
48
OnNetworkStateUpdated(int32_t slotId,const sptr<NetworkState> & networkState)49 void NapiTelephonyObserver::OnNetworkStateUpdated(int32_t slotId, const sptr<NetworkState> &networkState)
50 {
51 TELEPHONY_LOGI(
52 "OnNetworkStateUpdated slotId = %{public}d, networkState = %{public}d", slotId, networkState == nullptr);
53 std::unique_ptr<NetworkStateUpdateInfo> networkStateUpdateInfo =
54 std::make_unique<NetworkStateUpdateInfo>(slotId, networkState);
55 if (networkStateUpdateInfo == nullptr) {
56 TELEPHONY_LOGE("NetworkStateUpdateInfo is nullptr!");
57 return;
58 }
59 EventListenerManager::SendEvent(
60 ToUint32t(TelephonyCallbackEventId::EVENT_ON_NETWORK_STATE_UPDATE), networkStateUpdateInfo);
61 }
62
OnSimStateUpdated(int32_t slotId,CardType type,SimState state,LockReason reason)63 void NapiTelephonyObserver::OnSimStateUpdated(
64 int32_t slotId, CardType type, SimState state, LockReason reason)
65 {
66 TELEPHONY_LOGI("OnSimStateUpdated slotId = %{public}d, simState = %{public}d", slotId, state);
67 std::unique_ptr<SimStateUpdateInfo> simStateUpdateInfo =
68 std::make_unique<SimStateUpdateInfo>(slotId, type, state, reason);
69 if (simStateUpdateInfo == nullptr) {
70 TELEPHONY_LOGE("SimStateUpdateInfo is nullptr!");
71 return;
72 }
73 EventListenerManager::SendEvent(
74 ToUint32t(TelephonyCallbackEventId::EVENT_ON_SIM_STATE_UPDATE), simStateUpdateInfo);
75 }
76
OnCellInfoUpdated(int32_t slotId,const std::vector<sptr<CellInformation>> & vec)77 void NapiTelephonyObserver::OnCellInfoUpdated(int32_t slotId, const std::vector<sptr<CellInformation>> &vec)
78 {
79 TELEPHONY_LOGI("OnCellInfoUpdated slotId = %{public}d, cell info size = %{public}zu", slotId, vec.size());
80 std::unique_ptr<CellInfomationUpdate> cellInfo = std::make_unique<CellInfomationUpdate>(slotId, vec);
81 if (cellInfo == nullptr) {
82 TELEPHONY_LOGE("CellInfomationUpdate is nullptr!");
83 return;
84 }
85 EventListenerManager::SendEvent(ToUint32t(TelephonyCallbackEventId::EVENT_ON_CELL_INFOMATION_UPDATE), cellInfo);
86 }
87
OnCellularDataConnectStateUpdated(int32_t slotId,int32_t dataState,int32_t networkType)88 void NapiTelephonyObserver::OnCellularDataConnectStateUpdated(
89 int32_t slotId, int32_t dataState, int32_t networkType)
90 {
91 TELEPHONY_LOGD("OnCellularDataConnectStateUpdated slotId=%{public}d, dataState=%{public}d, networkType="
92 "%{public}d",
93 slotId, dataState, networkType);
94 std::unique_ptr<CellularDataConnectState> cellularDataConnectState =
95 std::make_unique<CellularDataConnectState>(slotId, dataState, networkType);
96 if (cellularDataConnectState == nullptr) {
97 TELEPHONY_LOGE("OnCellularDataConnectStateUpdated cellularDataConnectState is nullptr!");
98 return;
99 }
100 EventListenerManager::SendEvent(
101 ToUint32t(TelephonyCallbackEventId::EVENT_ON_CELLULAR_DATA_CONNECTION_UPDATE), cellularDataConnectState);
102 }
103
OnCellularDataFlowUpdated(int32_t slotId,int32_t dataFlowType)104 void NapiTelephonyObserver::OnCellularDataFlowUpdated(int32_t slotId, int32_t dataFlowType)
105 {
106 TELEPHONY_LOGI(
107 "OnCellularDataFlowUpdated slotId = %{public}d, dataFlowType = %{public}d", slotId, dataFlowType);
108 std::unique_ptr<CellularDataFlowUpdate> cellularDataFlowUpdateInfo =
109 std::make_unique<CellularDataFlowUpdate>(slotId, dataFlowType);
110 if (cellularDataFlowUpdateInfo == nullptr) {
111 TELEPHONY_LOGE("CellularDataFlowUpdate is nullptr!");
112 return;
113 }
114 EventListenerManager::SendEvent(
115 ToUint32t(TelephonyCallbackEventId::EVENT_ON_CELLULAR_DATA_FLOW_UPDATE), cellularDataFlowUpdateInfo);
116 }
117
OnCfuIndicatorUpdated(int32_t slotId,bool cfuResult)118 void NapiTelephonyObserver::OnCfuIndicatorUpdated(int32_t slotId, bool cfuResult)
119 {
120 TELEPHONY_LOGI("OnCfuIndicatorUpdated slotId = %{public}d, cfuResult = %{public}d", slotId, cfuResult);
121 std::unique_ptr<CfuIndicatorUpdate> cfuIndicatorUpdateInfo =
122 std::make_unique<CfuIndicatorUpdate>(slotId, cfuResult);
123 if (cfuIndicatorUpdateInfo == nullptr) {
124 TELEPHONY_LOGE("CfuIndicatorUpdate is nullptr!");
125 return;
126 }
127 EventListenerManager::SendEvent(
128 ToUint32t(TelephonyCallbackEventId::EVENT_ON_CFU_INDICATOR_UPDATE), cfuIndicatorUpdateInfo);
129 }
130
OnIccAccountUpdated()131 void NapiTelephonyObserver::OnIccAccountUpdated()
132 {
133 TELEPHONY_LOGI("OnIccAccountUpdated begin");
134 EventListenerManager::SendEvent(ToUint32t(TelephonyCallbackEventId::EVENT_ON_ICC_ACCOUNT_UPDATE));
135 }
136
OnVoiceMailMsgIndicatorUpdated(int32_t slotId,bool voiceMailMsgResult)137 void NapiTelephonyObserver::OnVoiceMailMsgIndicatorUpdated(int32_t slotId, bool voiceMailMsgResult)
138 {
139 TELEPHONY_LOGI("OnVoiceMailMsgIndicatorUpdated slotId = %{public}d, voiceMailMsgResult = %{public}d", slotId,
140 voiceMailMsgResult);
141 std::unique_ptr<VoiceMailMsgIndicatorUpdate> voiceMailMsgIndicatorUpdateInfo =
142 std::make_unique<VoiceMailMsgIndicatorUpdate>(slotId, voiceMailMsgResult);
143 if (voiceMailMsgIndicatorUpdateInfo == nullptr) {
144 TELEPHONY_LOGE("VoiceMailMsgIndicatorUpdate is nullptr!");
145 return;
146 }
147 EventListenerManager::SendEvent(
148 ToUint32t(TelephonyCallbackEventId::EVENT_ON_VOICE_MAIL_MSG_INDICATOR_UPDATE), voiceMailMsgIndicatorUpdateInfo);
149 }
150 } // namespace Telephony
151 } // namespace OHOS
152