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 #ifndef CALL_MANAGER_HISYSEVENT_H
17 #define CALL_MANAGER_HISYSEVENT_H
18 
19 #include <string>
20 
21 #include "telephony_hisysevent.h"
22 
23 namespace OHOS {
24 namespace Telephony {
25 static const int64_t NORMAL_DIAL_TIME = 500;     // dial time (ms)
26 static const int64_t NORMAL_INCOMING_TIME = 100; // incoming time (ms)
27 static const int64_t NORMAL_ANSWER_TIME = 300;   // answer time (ms)
28 static constexpr const char DOMAIN_PHONE_UE[] = "PHONE_UE";
29 
30 enum class IncomingCallType {
31     IMS_VOICE_INCOMING = 0,
32     IMS_VIDEO_INCOMING,
33     CS_VOICE_INCOMING,
34 };
35 
36 class CallManagerHisysevent : public TelephonyHiSysEvent {
37 public:
38     static void WriteCallStateBehaviorEvent(const int32_t slotId, const int32_t state, const int32_t index);
39     static void WriteIncomingCallBehaviorEvent(const int32_t slotId, int32_t callType, int32_t callMode);
40     static void WriteIncomingNumIdentityBehaviorEvent(const int32_t markType);
41     static void WriteIncomingCallFaultEvent(const int32_t slotId, const int32_t callType, const int32_t videoState,
42         const int32_t errCode, const std::string &desc);
43     static void WriteDialCallFaultEvent(const int32_t slotId, const int32_t callType, const int32_t videoState,
44         const int32_t errCode, const std::string &desc);
45     static void WriteAnswerCallFaultEvent(const int32_t slotId, const int32_t callId, const int32_t videoState,
46         const int32_t errCode, const std::string &desc);
47     static void WriteHangUpFaultEvent(
48         const int32_t slotId, const int32_t callId, const int32_t errCode, const std::string &desc);
49     void GetErrorDescription(const int32_t errCode, std::string &errordesc);
50     void SetDialStartTime();
51     void SetIncomingStartTime();
52     void SetAnswerStartTime();
53     void JudgingDialTimeOut(const int32_t slotId, const int32_t callType, const int32_t videoState);
54     void JudgingIncomingTimeOut(const int32_t slotId, const int32_t callType, const int32_t videoState);
55     void JudgingAnswerTimeOut(const int32_t slotId, const int32_t callId, const int32_t videoState);
56 
57 public:
58     template<typename... Types>
HiWriteBehaviorEventPhoneUE(const std::string &eventName, Types... args)59     static void HiWriteBehaviorEventPhoneUE(const std::string &eventName, Types... args)
60     {
61         HiSysEventWrite(DOMAIN_PHONE_UE, eventName, EventType::BEHAVIOR, args...);
62     }
63 
64 private:
65     static int32_t ErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue);
66     static int32_t CallDataErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue);
67     static int32_t CallInterfaceErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue);
68     static int32_t TelephonyErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue);
69 
70 private:
71     int64_t dialStartTime_ = 0;
72     int64_t incomingStartTime_ = 0;
73     int64_t answerStartTime_ = 0;
74 };
75 } // namespace Telephony
76 } // namespace OHOS
77 
78 #endif // CALL_MANAGER_HISYSEVENT_H
79