• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 "call_manager_hisysevent.h"
17 
18 #include "app_mgr_interface.h"
19 #include "bundle_mgr_interface.h"
20 #include "bundle_mgr_proxy.h"
21 #include "iservice_registry.h"
22 
23 #include "call_control_manager.h"
24 #include "call_manager_errors.h"
25 #include "telephony_errors.h"
26 #include "telephony_log_wrapper.h"
27 #include "voip_call.h"
28 
29 namespace OHOS {
30 namespace Telephony {
31 // EVENT
32 static constexpr const char *CALL_DIAL_FAILED_EVENT = "CALL_DIAL_FAILED";
33 static constexpr const char *CALL_INCOMING_FAILED_EVENT = "CALL_INCOMING_FAILED";
34 static constexpr const char *CALL_ANSWER_FAILED_EVENT = "CALL_ANSWER_FAILED";
35 static constexpr const char *CALL_HANGUP_FAILED_EVENT = "CALL_HANGUP_FAILED";
36 static constexpr const char *INCOMING_CALL_EVENT = "INCOMING_CALL";
37 static constexpr const char *CALL_STATE_CHANGED_EVENT = "CALL_STATE";
38 static constexpr const char *CALL_INCOMING_NUM_IDENTITY_EVENT = "CALL_INCOMING_NUM_IDENTITY";
39 
40 // KEY
41 static constexpr const char *MODULE_NAME_KEY = "MODULE";
42 static constexpr const char *SLOT_ID_KEY = "SLOT_ID";
43 static constexpr const char *INDEX_ID_KEY = "INDEX_ID";
44 static constexpr const char *STATE_KEY = "STATE";
45 static constexpr const char *CALL_ID_KEY = "CALL_ID";
46 static constexpr const char *CALL_TYPE_KEY = "CALL_TYPE";
47 static constexpr const char *VIDEO_STATE_KEY = "VIDEO_STATE";
48 static constexpr const char *ERROR_TYPE_KEY = "ERROR_TYPE";
49 static constexpr const char *ERROR_MSG_KEY = "ERROR_MSG";
50 static constexpr const char *MARK_TYPE_KEY = "MARK_TYPE";
51 static constexpr const char *IS_BLOCK = "IS_BLOCK";
52 static constexpr const char *BLOCK_REASON = "BLOCK_REASON";
53 
54 // VALUE
55 static constexpr const char *CALL_MANAGER_MODULE = "CALL_MANAGER";
56 static const int32_t CS_CALL_TYPE = 0;
57 static const int32_t IMS_CALL_TYPE = 1;
58 static const int32_t SATELLITE_CALL_TYPE = 5;
59 static const int32_t VOICE_TYPE = 0;
60 static const int32_t VIDEO_TYPE = 1;
61 using namespace OHOS::AppExecFwk;
WriteCallStateBehaviorEvent(const int32_t slotId,const int32_t state,const int32_t index)62 void CallManagerHisysevent::WriteCallStateBehaviorEvent(const int32_t slotId, const int32_t state, const int32_t index)
63 {
64     HiWriteBehaviorEvent(CALL_STATE_CHANGED_EVENT, SLOT_ID_KEY, slotId, STATE_KEY, state, INDEX_ID_KEY, index);
65 }
66 
WriteIncomingCallBehaviorEvent(const int32_t slotId,int32_t callType,int32_t callMode)67 void CallManagerHisysevent::WriteIncomingCallBehaviorEvent(const int32_t slotId, int32_t callType, int32_t callMode)
68 {
69     int32_t type = 0;
70     if (callType == IMS_CALL_TYPE && callMode == VOICE_TYPE) {
71         type = static_cast<int32_t>(IncomingCallType::IMS_VOICE_INCOMING);
72     } else if (callType == IMS_CALL_TYPE && callMode == VIDEO_TYPE) {
73         type = static_cast<int32_t>(IncomingCallType::IMS_VIDEO_INCOMING);
74     } else if ((callType == CS_CALL_TYPE || callType == SATELLITE_CALL_TYPE) && callMode == VOICE_TYPE) {
75         type = static_cast<int32_t>(IncomingCallType::CS_VOICE_INCOMING);
76     } else {
77         TELEPHONY_LOGE("WriteIncomingCallBehaviorEvent call incomming arges is out of range!");
78         return;
79     }
80     HiWriteBehaviorEvent(INCOMING_CALL_EVENT, SLOT_ID_KEY, slotId, CALL_TYPE_KEY, type);
81 }
82 
WriteIncomingNumIdentityBehaviorEvent(const int32_t markType,const bool isBlock,const int32_t blockReason)83 void CallManagerHisysevent::WriteIncomingNumIdentityBehaviorEvent(const int32_t markType, const bool isBlock,
84     const int32_t blockReason)
85 {
86     TELEPHONY_LOGI("WriteIncomingNumIdentityBehaviorEvent markType: %{public}d, isBlock: %{public}d, "
87         "blockReason: %{public}d", markType, isBlock, blockReason);
88     HiWriteBehaviorEventPhoneUE(CALL_INCOMING_NUM_IDENTITY_EVENT, PNAMEID_KEY, "callmanager", PVERSIONID_KEY, "",
89         MARK_TYPE_KEY, markType, IS_BLOCK, isBlock, BLOCK_REASON, blockReason);
90 }
91 
WriteIncomingCallFaultEvent(const int32_t slotId,const int32_t callType,const int32_t videoState,const int32_t errCode,const std::string & desc)92 void CallManagerHisysevent::WriteIncomingCallFaultEvent(const int32_t slotId, const int32_t callType,
93     const int32_t videoState, const int32_t errCode, const std::string &desc)
94 {
95     CallErrorCode value = CallErrorCode::CALL_ERROR_NONE;
96     if (ErrorCodeConversion(errCode, value)) {
97         HiWriteFaultEvent(CALL_INCOMING_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
98             CALL_TYPE_KEY, callType, VIDEO_STATE_KEY, videoState, ERROR_TYPE_KEY, static_cast<int32_t>(value),
99             ERROR_MSG_KEY, desc);
100     } else {
101         HiWriteFaultEvent(CALL_INCOMING_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
102             CALL_TYPE_KEY, callType, VIDEO_STATE_KEY, videoState, ERROR_TYPE_KEY, errCode, ERROR_MSG_KEY, desc);
103     }
104 }
105 
WriteDialCallFaultEvent(const int32_t slotId,const int32_t callType,const int32_t videoState,const int32_t errCode,const std::string & desc)106 void CallManagerHisysevent::WriteDialCallFaultEvent(const int32_t slotId, const int32_t callType,
107     const int32_t videoState, const int32_t errCode, const std::string &desc)
108 {
109     CallErrorCode value = CallErrorCode::CALL_ERROR_NONE;
110     if (ErrorCodeConversion(errCode, value)) {
111         HiWriteFaultEvent(CALL_DIAL_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
112             CALL_TYPE_KEY, callType, VIDEO_STATE_KEY, videoState, ERROR_TYPE_KEY, static_cast<int32_t>(value),
113             ERROR_MSG_KEY, desc);
114     } else {
115         HiWriteFaultEvent(CALL_DIAL_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
116             CALL_TYPE_KEY, callType, VIDEO_STATE_KEY, videoState, ERROR_TYPE_KEY, errCode, ERROR_MSG_KEY, desc);
117     }
118 }
119 
WriteAnswerCallFaultEvent(const int32_t slotId,const int32_t callId,const int32_t videoState,const int32_t errCode,const std::string & desc)120 void CallManagerHisysevent::WriteAnswerCallFaultEvent(const int32_t slotId, const int32_t callId,
121     const int32_t videoState, const int32_t errCode, const std::string &desc)
122 {
123     CallErrorCode value = CallErrorCode::CALL_ERROR_NONE;
124     if (ErrorCodeConversion(errCode, value)) {
125         HiWriteFaultEvent(CALL_ANSWER_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
126             CALL_ID_KEY, callId, VIDEO_STATE_KEY, videoState, ERROR_TYPE_KEY, static_cast<int32_t>(value),
127             ERROR_MSG_KEY, desc);
128     } else {
129         HiWriteFaultEvent(CALL_ANSWER_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
130             CALL_ID_KEY, callId, VIDEO_STATE_KEY, videoState, ERROR_TYPE_KEY, errCode, ERROR_MSG_KEY, desc);
131     }
132 }
133 
WriteHangUpFaultEvent(const int32_t slotId,const int32_t callId,const int32_t errCode,const std::string & desc)134 void CallManagerHisysevent::WriteHangUpFaultEvent(
135     const int32_t slotId, const int32_t callId, const int32_t errCode, const std::string &desc)
136 {
137     CallErrorCode value = CallErrorCode::CALL_ERROR_NONE;
138     if (ErrorCodeConversion(errCode, value)) {
139         HiWriteFaultEvent(CALL_HANGUP_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
140             CALL_ID_KEY, callId, ERROR_TYPE_KEY, static_cast<int32_t>(value), ERROR_MSG_KEY, desc);
141     } else {
142         HiWriteFaultEvent(CALL_HANGUP_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
143             CALL_ID_KEY, callId, ERROR_TYPE_KEY, errCode, ERROR_MSG_KEY, desc);
144     }
145 }
146 
GetErrorDescription(const int32_t errCode,std::string & errordesc)147 void CallManagerHisysevent::GetErrorDescription(const int32_t errCode, std::string &errordesc)
148 {
149     switch (errCode) {
150         case CALL_ERR_PHONE_NUMBER_EMPTY:
151         case CALL_ERR_NUMBER_OUT_OF_RANGE:
152             errordesc = "NumberLegalityCheck failed";
153             break;
154         case CALL_ERR_UNKNOW_DIAL_TYPE:
155         case CALL_ERR_INVALID_SLOT_ID:
156         case CALL_ERR_UNKNOW_CALL_TYPE:
157         case CALL_ERR_INVALID_DIAL_SCENE:
158         case CALL_ERR_INVALID_VIDEO_STATE:
159             errordesc = "DialPolicy failed";
160             break;
161         case TELEPHONY_ERR_LOCAL_PTR_NULL:
162             errordesc = errordesc = "CallRequestHandlerPtr_ or handler_ is nullptr";
163             break;
164         case CALL_ERR_SYSTEM_EVENT_HANDLE_FAILURE:
165             errordesc = "Send HANDLER_DIAL_CALL_REQUEST event failed";
166             break;
167         default:
168             break;
169     }
170 }
171 
ErrorCodeConversion(const int32_t errCode,CallErrorCode & eventValue)172 int32_t CallManagerHisysevent::ErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue)
173 {
174     if (CallDataErrorCodeConversion(errCode, eventValue) || CallInterfaceErrorCodeConversion(errCode, eventValue) ||
175         TelephonyErrorCodeConversion(errCode, eventValue)) {
176         TELEPHONY_LOGI("CallManagerHisysevent::ErrorCodeConversion in %{public}d out %{public}d", errCode, eventValue);
177         return true;
178     }
179     return false;
180 }
181 
TelephonyErrorCodeConversion(const int32_t errCode,CallErrorCode & eventValue)182 int32_t CallManagerHisysevent::TelephonyErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue)
183 {
184     switch (errCode) {
185         case static_cast<int32_t>(TELEPHONY_ERR_LOCAL_PTR_NULL):
186             eventValue = CallErrorCode::CALL_ERROR_CALL_LOCAL_PTR_NULL;
187             break;
188         case static_cast<int32_t>(TELEPHONY_ERR_ARGUMENT_INVALID):
189             eventValue = CallErrorCode::CALL_ERROR_ARGUMENT_INVALID;
190             break;
191         case static_cast<int32_t>(TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL):
192             eventValue = CallErrorCode::CALL_ERROR_IPC_CONNECT_STUB_FAIL;
193             break;
194         case static_cast<int32_t>(TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL):
195             eventValue = CallErrorCode::CALL_ERROR_IPC_WRITE_DESCRIPTOR_TOKEN_FAIL;
196             break;
197         case static_cast<int32_t>(TELEPHONY_ERR_WRITE_DATA_FAIL):
198             eventValue = CallErrorCode::CALL_ERROR_IPC_WRITE_DATA_FAIL;
199             break;
200         case static_cast<int32_t>(TELEPHONY_ERR_PERMISSION_ERR):
201             eventValue = CallErrorCode::CALL_ERROR_PERMISSION_ERR;
202             break;
203         case static_cast<int32_t>(TELEPHONY_ERR_MEMSET_FAIL):
204             eventValue = CallErrorCode::CALL_ERROR_MEMSET_FAIL;
205             break;
206         case static_cast<int32_t>(TELEPHONY_ERR_MEMCPY_FAIL):
207             eventValue = CallErrorCode::CALL_ERROR_MEMCPY_FAIL;
208             break;
209         default:
210             return false;
211     }
212 
213     return true;
214 }
215 
CallDataErrorCodeConversion(const int32_t errCode,CallErrorCode & eventValue)216 int32_t CallManagerHisysevent::CallDataErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue)
217 {
218     switch (errCode) {
219         case static_cast<int32_t>(CALL_ERR_INVALID_SLOT_ID):
220             eventValue = CallErrorCode::CALL_ERROR_INVALID_SLOT_ID;
221             break;
222         case static_cast<int32_t>(CALL_ERR_INVALID_CALLID):
223             eventValue = CallErrorCode::CALL_ERROR_INVALID_CALLID;
224             break;
225         case static_cast<int32_t>(CALL_ERR_PHONE_NUMBER_EMPTY):
226             eventValue = CallErrorCode::CALL_ERROR_PHONE_NUMBER_EMPTY;
227             break;
228         case static_cast<int32_t>(CALL_ERR_NUMBER_OUT_OF_RANGE):
229             eventValue = CallErrorCode::CALL_ERROR_NUMBER_OUT_OF_RANGE;
230             break;
231         case static_cast<int32_t>(CALL_ERR_UNSUPPORTED_NETWORK_TYPE):
232             eventValue = CallErrorCode::CALL_ERROR_UNSUPPORTED_NETWORK_TYPE;
233             break;
234         case static_cast<int32_t>(CALL_ERR_INVALID_DIAL_SCENE):
235             eventValue = CallErrorCode::CALL_ERROR_INVALID_DIAL_SCENE;
236             break;
237         case static_cast<int32_t>(CALL_ERR_INVALID_VIDEO_STATE):
238             eventValue = CallErrorCode::CALL_ERROR_INVALID_VIDEO_STATE;
239             break;
240         case static_cast<int32_t>(CALL_ERR_UNKNOW_DIAL_TYPE):
241             eventValue = CallErrorCode::CALL_ERROR_UNKNOW_DIAL_TYPE;
242             break;
243         case static_cast<int32_t>(CALL_ERR_UNKNOW_CALL_TYPE):
244             eventValue = CallErrorCode::CALL_ERROR_UNKNOW_CALL_TYPE;
245             break;
246         case static_cast<int32_t>(CALL_ERR_CALL_OBJECT_IS_NULL):
247             eventValue = CallErrorCode::CALL_ERROR_CALL_OBJECT_IS_NULL;
248             break;
249         default:
250             return false;
251     }
252     return true;
253 }
254 
CallInterfaceErrorCodeConversion(const int32_t errCode,CallErrorCode & eventValue)255 int32_t CallManagerHisysevent::CallInterfaceErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue)
256 {
257     switch (errCode) {
258         case static_cast<int32_t>(CALL_ERR_DIAL_IS_BUSY):
259             eventValue = CallErrorCode::CALL_ERROR_DIAL_IS_BUSY;
260             break;
261         case static_cast<int32_t>(CALL_ERR_ILLEGAL_CALL_OPERATION):
262             eventValue = CallErrorCode::CALL_ERROR_ILLEGAL_CALL_OPERATION;
263             break;
264         case static_cast<int32_t>(CALL_ERR_PHONE_CALLSTATE_NOTIFY_FAILED):
265             eventValue = CallErrorCode::CALL_ERROR_PHONE_CALLSTATE_NOTIFY_FAILED;
266             break;
267         case static_cast<int32_t>(CALL_ERR_SYSTEM_EVENT_HANDLE_FAILURE):
268             eventValue = CallErrorCode::CALL_ERROR_SYSTEM_EVENT_HANDLE_FAILURE;
269             break;
270         case static_cast<int32_t>(CALL_ERR_CALL_COUNTS_EXCEED_LIMIT):
271             eventValue = CallErrorCode::CALL_ERROR_CALL_COUNTS_EXCEED_LIMIT;
272             break;
273         case static_cast<int32_t>(CALL_ERR_GET_RADIO_STATE_FAILED):
274             eventValue = CallErrorCode::CALL_ERROR_GET_RADIO_STATE_FAILED;
275             break;
276         default:
277             return false;
278     }
279 
280     return true;
281 }
282 
SetDialStartTime()283 void CallManagerHisysevent::SetDialStartTime()
284 {
285     dialStartTime_ =
286         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
287             .count();
288 }
289 
SetIncomingStartTime()290 void CallManagerHisysevent::SetIncomingStartTime()
291 {
292     incomingStartTime_ =
293         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
294             .count();
295 }
296 
SetAnswerStartTime()297 void CallManagerHisysevent::SetAnswerStartTime()
298 {
299     answerStartTime_ =
300         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
301             .count();
302 }
303 
JudgingDialTimeOut(const int32_t slotId,const int32_t callType,const int32_t videoState)304 void CallManagerHisysevent::JudgingDialTimeOut(const int32_t slotId, const int32_t callType, const int32_t videoState)
305 {
306     int64_t dialEndTime =
307         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
308             .count();
309     if (dialEndTime - dialStartTime_ > NORMAL_DIAL_TIME) {
310         WriteDialCallFaultEvent(slotId, callType, videoState,
311             static_cast<int32_t>(CallErrorCode::CALL_ERROR_DIAL_TIME_OUT),
312             "dial time out " + std::to_string(dialEndTime - dialStartTime_));
313     }
314 }
315 
JudgingIncomingTimeOut(const int32_t slotId,const int32_t callType,const int32_t videoState)316 void CallManagerHisysevent::JudgingIncomingTimeOut(
317     const int32_t slotId, const int32_t callType, const int32_t videoState)
318 {
319     int64_t incomingEndTime =
320         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
321             .count();
322     if (incomingEndTime - incomingStartTime_ > NORMAL_INCOMING_TIME) {
323         WriteIncomingCallFaultEvent(slotId, callType, videoState,
324             static_cast<int32_t>(CallErrorCode::CALL_ERROR_INCOMING_TIME_OUT),
325             "incoming time out " + std::to_string(incomingEndTime - incomingStartTime_));
326     }
327 }
328 
JudgingAnswerTimeOut(const int32_t slotId,const int32_t callId,const int32_t videoState)329 void CallManagerHisysevent::JudgingAnswerTimeOut(const int32_t slotId, const int32_t callId, const int32_t videoState)
330 {
331     int64_t answerEndTime =
332         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
333             .count();
334     if (answerEndTime - answerStartTime_ > NORMAL_ANSWER_TIME) {
335         WriteAnswerCallFaultEvent(slotId, callId, videoState,
336             static_cast<int32_t>(CallErrorCode::CALL_ERROR_ANSWER_TIME_OUT),
337             "answer time out " + std::to_string(answerEndTime - answerStartTime_));
338     }
339 }
340 
WriteVoipCallStatisticalEvent(const std::string & voipCallId,const std::string & bundleName,const int32_t & uid,const std::string statisticalField)341 void CallManagerHisysevent::WriteVoipCallStatisticalEvent(const std::string &voipCallId, const std::string &bundleName,
342     const int32_t &uid, const std::string statisticalField)
343 {
344     ffrt::submit([voipCallId, bundleName, uid, statisticalField]() {
345         int32_t appIndex = -1;
346         GetAppIndexByBundleName(bundleName, uid, appIndex);
347         HiSysEventWrite(DOMAIN_NAME, "VOIP_CALL_STATISTICS", EventType::STATISTIC, CALL_ID_KEY, voipCallId,
348             "BUNDLE_NAME", bundleName, "STATISTICAL_FIELD", statisticalField, "APP_INDEX", appIndex);
349     });
350 }
WriteVoipCallStatisticalEvent(const int32_t & callId,const std::string statisticalField)351 void CallManagerHisysevent::WriteVoipCallStatisticalEvent(const int32_t &callId, const std::string statisticalField)
352 {
353     auto call = CallControlManager::GetOneCallObject(callId);
354     if (call == nullptr || call->GetCallType() != CallType::TYPE_VOIP) {
355         return;
356     }
357 
358     sptr<VoIPCall> voipCall = reinterpret_cast<VoIPCall *>(call.GetRefPtr());
359     WriteVoipCallStatisticalEvent(voipCall->GetVoipCallId(), voipCall->GetVoipBundleName(), voipCall->GetVoipUid(),
360         statisticalField);
361 }
GetAppIndexByBundleName(std::string bundleName,int32_t uid,int32_t & appIndex)362 void CallManagerHisysevent::GetAppIndexByBundleName(std::string bundleName, int32_t uid, int32_t &appIndex)
363 {
364     sptr<ISystemAbilityManager> systemAbilityManager =
365         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
366     if (systemAbilityManager == nullptr) {
367         TELEPHONY_LOGE("system ability manager is nullptr");
368         return;
369     }
370     sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
371     if (remoteObject == nullptr) {
372         TELEPHONY_LOGE("Get system ability failed");
373         return;
374     }
375     sptr<IBundleMgr> bundleMgr = iface_cast<IBundleMgr>(remoteObject);
376     bundleMgr->GetNameAndIndexForUid(uid, bundleName, appIndex);
377 }
378 
379 } // namespace Telephony
380 } // namespace OHOS
381