• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 "call_manager_errors.h"
19 #include "telephony_errors.h"
20 #include "telephony_log_wrapper.h"
21 
22 namespace OHOS {
23 namespace Telephony {
24 // EVENT
25 static constexpr const char *CALL_DIAL_FAILED_EVENT = "CALL_DIAL_FAILED";
26 static constexpr const char *CALL_INCOMING_FAILED_EVENT = "CALL_INCOMING_FAILED";
27 static constexpr const char *CALL_ANSWER_FAILED_EVENT = "CALL_ANSWER_FAILED";
28 static constexpr const char *CALL_HANGUP_FAILED_EVENT = "CALL_HANGUP_FAILED";
29 static constexpr const char *INCOMING_CALL_EVENT = "INCOMING_CALL";
30 static constexpr const char *CALL_STATE_CHANGED_EVENT = "CALL_STATE";
31 
32 // KEY
33 static constexpr const char *MODULE_NAME_KEY = "MODULE";
34 static constexpr const char *SLOT_ID_KEY = "SLOT_ID";
35 static constexpr const char *INDEX_ID_KEY = "INDEX_ID";
36 static constexpr const char *STATE_KEY = "STATE";
37 static constexpr const char *CALL_ID_KEY = "CALL_ID";
38 static constexpr const char *CALL_TYPE_KEY = "CALL_TYPE";
39 static constexpr const char *VIDEO_STATE_KEY = "VIDEO_STATE";
40 static constexpr const char *ERROR_TYPE_KEY = "ERROR_TYPE";
41 static constexpr const char *ERROR_MSG_KEY = "ERROR_MSG";
42 
43 // VALUE
44 static constexpr const char *CALL_MANAGER_MODULE = "CALL_MANAGER";
45 static const int32_t CS_CALL_TYPE = 0;
46 static const int32_t IMS_CALL_TYPE = 1;
47 static const int32_t VOICE_TYPE = 0;
48 static const int32_t VIDEO_TYPE = 1;
49 
WriteCallStateBehaviorEvent(const int32_t slotId,const int32_t state,const int32_t index)50 void CallManagerHisysevent::WriteCallStateBehaviorEvent(const int32_t slotId, const int32_t state, const int32_t index)
51 {
52     HiWriteBehaviorEvent(CALL_STATE_CHANGED_EVENT, SLOT_ID_KEY, slotId, STATE_KEY, state, INDEX_ID_KEY, index);
53 }
54 
WriteIncomingCallBehaviorEvent(const int32_t slotId,int32_t callType,int32_t callMode)55 void CallManagerHisysevent::WriteIncomingCallBehaviorEvent(const int32_t slotId, int32_t callType, int32_t callMode)
56 {
57     int32_t type = 0;
58     if (callType == IMS_CALL_TYPE && callMode == VOICE_TYPE) {
59         type = static_cast<int32_t>(IncomingCallType::IMS_VOICE_INCOMING);
60     } else if (callType == IMS_CALL_TYPE && callMode == VIDEO_TYPE) {
61         type = static_cast<int32_t>(IncomingCallType::IMS_VIDEO_INCOMING);
62     } else if (callType == CS_CALL_TYPE && callMode == VOICE_TYPE) {
63         type = static_cast<int32_t>(IncomingCallType::CS_VOICE_INCOMING);
64     } else {
65         TELEPHONY_LOGE("WriteIncomingCallBehaviorEvent call incomming arges is out of range!");
66         return;
67     }
68     HiWriteBehaviorEvent(INCOMING_CALL_EVENT, SLOT_ID_KEY, slotId, CALL_TYPE_KEY, type);
69 }
70 
WriteIncomingCallFaultEvent(const int32_t slotId,const int32_t callType,const int32_t videoState,const int32_t errCode,const std::string & desc)71 void CallManagerHisysevent::WriteIncomingCallFaultEvent(const int32_t slotId, const int32_t callType,
72     const int32_t videoState, const int32_t errCode, const std::string &desc)
73 {
74     CallErrorCode value = CallErrorCode::CALL_ERROR_NONE;
75     if (ErrorCodeConversion(errCode, value)) {
76         HiWriteFaultEvent(CALL_INCOMING_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
77             CALL_TYPE_KEY, callType, VIDEO_STATE_KEY, videoState, ERROR_TYPE_KEY, static_cast<int32_t>(value),
78             ERROR_MSG_KEY, desc);
79     } else {
80         HiWriteFaultEvent(CALL_INCOMING_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
81             CALL_TYPE_KEY, callType, VIDEO_STATE_KEY, videoState, ERROR_TYPE_KEY, errCode, ERROR_MSG_KEY, desc);
82     }
83 }
84 
WriteDialCallFaultEvent(const int32_t slotId,const int32_t callType,const int32_t videoState,const int32_t errCode,const std::string & desc)85 void CallManagerHisysevent::WriteDialCallFaultEvent(const int32_t slotId, const int32_t callType,
86     const int32_t videoState, const int32_t errCode, const std::string &desc)
87 {
88     CallErrorCode value = CallErrorCode::CALL_ERROR_NONE;
89     if (ErrorCodeConversion(errCode, value)) {
90         HiWriteFaultEvent(CALL_DIAL_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
91             CALL_TYPE_KEY, callType, VIDEO_STATE_KEY, videoState, ERROR_TYPE_KEY, static_cast<int32_t>(value),
92             ERROR_MSG_KEY, desc);
93     } else {
94         HiWriteFaultEvent(CALL_DIAL_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
95             CALL_TYPE_KEY, callType, VIDEO_STATE_KEY, videoState, ERROR_TYPE_KEY, errCode, ERROR_MSG_KEY, desc);
96     }
97 }
98 
WriteAnswerCallFaultEvent(const int32_t slotId,const int32_t callId,const int32_t videoState,const int32_t errCode,const std::string & desc)99 void CallManagerHisysevent::WriteAnswerCallFaultEvent(const int32_t slotId, const int32_t callId,
100     const int32_t videoState, const int32_t errCode, const std::string &desc)
101 {
102     CallErrorCode value = CallErrorCode::CALL_ERROR_NONE;
103     if (ErrorCodeConversion(errCode, value)) {
104         HiWriteFaultEvent(CALL_ANSWER_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
105             CALL_ID_KEY, callId, VIDEO_STATE_KEY, videoState, ERROR_TYPE_KEY, static_cast<int32_t>(value),
106             ERROR_MSG_KEY, desc);
107     } else {
108         HiWriteFaultEvent(CALL_ANSWER_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
109             CALL_ID_KEY, callId, VIDEO_STATE_KEY, videoState, ERROR_TYPE_KEY, errCode, ERROR_MSG_KEY, desc);
110     }
111 }
112 
WriteHangUpFaultEvent(const int32_t slotId,const int32_t callId,const int32_t errCode,const std::string & desc)113 void CallManagerHisysevent::WriteHangUpFaultEvent(
114     const int32_t slotId, const int32_t callId, const int32_t errCode, const std::string &desc)
115 {
116     CallErrorCode value = CallErrorCode::CALL_ERROR_NONE;
117     if (ErrorCodeConversion(errCode, value)) {
118         HiWriteFaultEvent(CALL_HANGUP_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
119             CALL_ID_KEY, callId, ERROR_TYPE_KEY, static_cast<int32_t>(value), ERROR_MSG_KEY, desc);
120     } else {
121         HiWriteFaultEvent(CALL_HANGUP_FAILED_EVENT, MODULE_NAME_KEY, CALL_MANAGER_MODULE, SLOT_ID_KEY, slotId,
122             CALL_ID_KEY, callId, ERROR_TYPE_KEY, errCode, ERROR_MSG_KEY, desc);
123     }
124 }
125 
GetErrorDescription(const int32_t errCode,std::string & errordesc)126 void CallManagerHisysevent::GetErrorDescription(const int32_t errCode, std::string &errordesc)
127 {
128     switch (errCode) {
129         case CALL_ERR_PHONE_NUMBER_EMPTY:
130         case CALL_ERR_NUMBER_OUT_OF_RANGE:
131             errordesc = "NumberLegalityCheck failed";
132             break;
133         case CALL_ERR_UNKNOW_DIAL_TYPE:
134         case CALL_ERR_INVALID_SLOT_ID:
135         case CALL_ERR_UNKNOW_CALL_TYPE:
136         case CALL_ERR_INVALID_DIAL_SCENE:
137         case CALL_ERR_INVALID_VIDEO_STATE:
138             errordesc = "DialPolicy failed";
139             break;
140         case TELEPHONY_ERR_LOCAL_PTR_NULL:
141             errordesc = errordesc = "callRequestHandlerServicePtr_ or handler_ is nullptr";
142             break;
143         case CALL_ERR_SYSTEM_EVENT_HANDLE_FAILURE:
144             errordesc = "Send HANDLER_DIAL_CALL_REQUEST event failed";
145             break;
146         default:
147             break;
148     }
149 }
150 
ErrorCodeConversion(const int32_t errCode,CallErrorCode & eventValue)151 int32_t CallManagerHisysevent::ErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue)
152 {
153     if (CallDataErrorCodeConversion(errCode, eventValue) || CallInterfaceErrorCodeConversion(errCode, eventValue) ||
154         TelephonyErrorCodeConversion(errCode, eventValue)) {
155         TELEPHONY_LOGI("CallManagerHisysevent::ErrorCodeConversion in %{public}d out %{public}d", errCode, eventValue);
156         return true;
157     }
158     return false;
159 }
160 
TelephonyErrorCodeConversion(const int32_t errCode,CallErrorCode & eventValue)161 int32_t CallManagerHisysevent::TelephonyErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue)
162 {
163     switch (errCode) {
164         case static_cast<int32_t>(TELEPHONY_ERR_LOCAL_PTR_NULL):
165             eventValue = CallErrorCode::CALL_ERROR_CALL_LOCAL_PTR_NULL;
166             break;
167         case static_cast<int32_t>(TELEPHONY_ERR_ARGUMENT_INVALID):
168             eventValue = CallErrorCode::CALL_ERROR_ARGUMENT_INVALID;
169             break;
170         case static_cast<int32_t>(TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL):
171             eventValue = CallErrorCode::CALL_ERROR_IPC_CONNECT_STUB_FAIL;
172             break;
173         case static_cast<int32_t>(TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL):
174             eventValue = CallErrorCode::CALL_ERROR_IPC_WRITE_DESCRIPTOR_TOKEN_FAIL;
175             break;
176         case static_cast<int32_t>(TELEPHONY_ERR_WRITE_DATA_FAIL):
177             eventValue = CallErrorCode::CALL_ERROR_IPC_WRITE_DATA_FAIL;
178             break;
179         case static_cast<int32_t>(TELEPHONY_ERR_PERMISSION_ERR):
180             eventValue = CallErrorCode::CALL_ERROR_PERMISSION_ERR;
181             break;
182         case static_cast<int32_t>(TELEPHONY_ERR_MEMSET_FAIL):
183             eventValue = CallErrorCode::CALL_ERROR_MEMSET_FAIL;
184             break;
185         case static_cast<int32_t>(TELEPHONY_ERR_MEMCPY_FAIL):
186             eventValue = CallErrorCode::CALL_ERROR_MEMCPY_FAIL;
187             break;
188         default:
189             return false;
190     }
191 
192     return true;
193 }
194 
CallDataErrorCodeConversion(const int32_t errCode,CallErrorCode & eventValue)195 int32_t CallManagerHisysevent::CallDataErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue)
196 {
197     switch (errCode) {
198         case static_cast<int32_t>(CALL_ERR_INVALID_SLOT_ID):
199             eventValue = CallErrorCode::CALL_ERROR_INVALID_SLOT_ID;
200             break;
201         case static_cast<int32_t>(CALL_ERR_INVALID_CALLID):
202             eventValue = CallErrorCode::CALL_ERROR_INVALID_CALLID;
203             break;
204         case static_cast<int32_t>(CALL_ERR_PHONE_NUMBER_EMPTY):
205             eventValue = CallErrorCode::CALL_ERROR_PHONE_NUMBER_EMPTY;
206             break;
207         case static_cast<int32_t>(CALL_ERR_NUMBER_OUT_OF_RANGE):
208             eventValue = CallErrorCode::CALL_ERROR_NUMBER_OUT_OF_RANGE;
209             break;
210         case static_cast<int32_t>(CALL_ERR_UNSUPPORTED_NETWORK_TYPE):
211             eventValue = CallErrorCode::CALL_ERROR_UNSUPPORTED_NETWORK_TYPE;
212             break;
213         case static_cast<int32_t>(CALL_ERR_INVALID_DIAL_SCENE):
214             eventValue = CallErrorCode::CALL_ERROR_INVALID_DIAL_SCENE;
215             break;
216         case static_cast<int32_t>(CALL_ERR_INVALID_VIDEO_STATE):
217             eventValue = CallErrorCode::CALL_ERROR_INVALID_VIDEO_STATE;
218             break;
219         case static_cast<int32_t>(CALL_ERR_UNKNOW_DIAL_TYPE):
220             eventValue = CallErrorCode::CALL_ERROR_UNKNOW_DIAL_TYPE;
221             break;
222         case static_cast<int32_t>(CALL_ERR_UNKNOW_CALL_TYPE):
223             eventValue = CallErrorCode::CALL_ERROR_UNKNOW_CALL_TYPE;
224             break;
225         case static_cast<int32_t>(CALL_ERR_CALL_OBJECT_IS_NULL):
226             eventValue = CallErrorCode::CALL_ERROR_CALL_OBJECT_IS_NULL;
227             break;
228         default:
229             return false;
230     }
231     return true;
232 }
233 
CallInterfaceErrorCodeConversion(const int32_t errCode,CallErrorCode & eventValue)234 int32_t CallManagerHisysevent::CallInterfaceErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue)
235 {
236     switch (errCode) {
237         case static_cast<int32_t>(CALL_ERR_DIAL_IS_BUSY):
238             eventValue = CallErrorCode::CALL_ERROR_DIAL_IS_BUSY;
239             break;
240         case static_cast<int32_t>(CALL_ERR_ILLEGAL_CALL_OPERATION):
241             eventValue = CallErrorCode::CALL_ERROR_ILLEGAL_CALL_OPERATION;
242             break;
243         case static_cast<int32_t>(CALL_ERR_PHONE_CALLSTATE_NOTIFY_FAILED):
244             eventValue = CallErrorCode::CALL_ERROR_PHONE_CALLSTATE_NOTIFY_FAILED;
245             break;
246         case static_cast<int32_t>(CALL_ERR_SYSTEM_EVENT_HANDLE_FAILURE):
247             eventValue = CallErrorCode::CALL_ERROR_SYSTEM_EVENT_HANDLE_FAILURE;
248             break;
249         case static_cast<int32_t>(CALL_ERR_CALL_COUNTS_EXCEED_LIMIT):
250             eventValue = CallErrorCode::CALL_ERROR_CALL_COUNTS_EXCEED_LIMIT;
251             break;
252         case static_cast<int32_t>(CALL_ERR_GET_RADIO_STATE_FAILED):
253             eventValue = CallErrorCode::CALL_ERROR_GET_RADIO_STATE_FAILED;
254             break;
255         default:
256             return false;
257     }
258 
259     return true;
260 }
261 
SetDialStartTime()262 void CallManagerHisysevent::SetDialStartTime()
263 {
264     dialStartTime_ =
265         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
266             .count();
267 }
268 
SetIncomingStartTime()269 void CallManagerHisysevent::SetIncomingStartTime()
270 {
271     incomingStartTime_ =
272         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
273             .count();
274 }
275 
SetAnswerStartTime()276 void CallManagerHisysevent::SetAnswerStartTime()
277 {
278     answerStartTime_ =
279         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
280             .count();
281 }
282 
JudgingDialTimeOut(const int32_t slotId,const int32_t callType,const int32_t videoState)283 void CallManagerHisysevent::JudgingDialTimeOut(const int32_t slotId, const int32_t callType, const int32_t videoState)
284 {
285     int64_t dialEndTime =
286         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
287             .count();
288     if (dialEndTime - dialStartTime_ > NORMAL_DIAL_TIME) {
289         WriteDialCallFaultEvent(slotId, callType, videoState,
290             static_cast<int32_t>(CallErrorCode::CALL_ERROR_DIAL_TIME_OUT),
291             "dial time out " + std::to_string(dialEndTime - dialStartTime_));
292     }
293 }
294 
JudgingIncomingTimeOut(const int32_t slotId,const int32_t callType,const int32_t videoState)295 void CallManagerHisysevent::JudgingIncomingTimeOut(
296     const int32_t slotId, const int32_t callType, const int32_t videoState)
297 {
298     int64_t incomingEndTime =
299         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
300             .count();
301     if (incomingEndTime - incomingStartTime_ > NORMAL_INCOMING_TIME) {
302         WriteIncomingCallFaultEvent(slotId, callType, videoState,
303             static_cast<int32_t>(CallErrorCode::CALL_ERROR_INCOMING_TIME_OUT),
304             "incoming time out " + std::to_string(incomingEndTime - incomingStartTime_));
305     }
306 }
307 
JudgingAnswerTimeOut(const int32_t slotId,const int32_t callId,const int32_t videoState)308 void CallManagerHisysevent::JudgingAnswerTimeOut(const int32_t slotId, const int32_t callId, const int32_t videoState)
309 {
310     int64_t answerEndTime =
311         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
312             .count();
313     if (answerEndTime - answerStartTime_ > NORMAL_ANSWER_TIME) {
314         WriteAnswerCallFaultEvent(slotId, callId, videoState,
315             static_cast<int32_t>(CallErrorCode::CALL_ERROR_ANSWER_TIME_OUT),
316             "answer time out " + std::to_string(answerEndTime - answerStartTime_));
317     }
318 }
319 } // namespace Telephony
320 } // namespace OHOS
321