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 // phoneUE const
30 static constexpr const char *KEY_CALL_MANAGER = "callmanager";
31 static constexpr const char *CALL_DIAL_IN_SUPER_PRIVACY = "CALL_DIAL_IN_SUPER_PRIVACY";
32 static constexpr const char *CALL_ANSWER_IN_SUPER_PRIVACY = "CALL_ANSWER_IN_SUPER_PRIVACY";
33 static constexpr const char *CALL_REJECT_IN_SUPER_PRIVACY = "CALL_REJECT_IN_SUPER_PRIVACY";
34 static constexpr const char *CALL_DIAL_CLOSE_SUPER_PRIVACY = "CALL_DIAL_CLOSE_SUPER_PRIVACY";
35 static constexpr const char *CALL_INCOMING_REJECT_BY_SYSTEM = "CALL_INCOMING_REJECT_BY_SYSTEM";
36 // KEY
37 static constexpr const char *PNAMEID_KEY = "PNAMEID";
38 static constexpr const char *PVERSIONID_KEY = "PVERSIONID";
39 static constexpr const char *ACTION_TYPE = "ACTION_TYPE";
40 // VALUE
41 static constexpr const int64_t REJECT_BY_OOBE = 0;
42 static constexpr const int64_t REJECT_BY_NUM_BLOCK = 1;
43 static constexpr const int64_t REJECT_IN_FOCUSMODE = 2;
44 
45 enum class IncomingCallType {
46     IMS_VOICE_INCOMING = 0,
47     IMS_VIDEO_INCOMING,
48     CS_VOICE_INCOMING,
49 };
50 
51 class CallManagerHisysevent : public TelephonyHiSysEvent {
52 public:
53     static void WriteCallStateBehaviorEvent(const int32_t slotId, const int32_t state, const int32_t index);
54     static void WriteIncomingCallBehaviorEvent(const int32_t slotId, int32_t callType, int32_t callMode);
55     static void WriteIncomingNumIdentityBehaviorEvent(const int32_t markType, const bool isBlock,
56         const int32_t blockReason);
57     static void WriteIncomingCallFaultEvent(const int32_t slotId, const int32_t callType, const int32_t videoState,
58         const int32_t errCode, const std::string &desc);
59     static void WriteDialCallFaultEvent(const int32_t slotId, const int32_t callType, const int32_t videoState,
60         const int32_t errCode, const std::string &desc);
61     static void WriteAnswerCallFaultEvent(const int32_t slotId, const int32_t callId, const int32_t videoState,
62         const int32_t errCode, const std::string &desc);
63     static void WriteHangUpFaultEvent(
64         const int32_t slotId, const int32_t callId, const int32_t errCode, const std::string &desc);
65     void GetErrorDescription(const int32_t errCode, std::string &errordesc);
66     void SetDialStartTime();
67     void SetIncomingStartTime();
68     void SetAnswerStartTime();
69     void JudgingDialTimeOut(const int32_t slotId, const int32_t callType, const int32_t videoState);
70     void JudgingIncomingTimeOut(const int32_t slotId, const int32_t callType, const int32_t videoState);
71     void JudgingAnswerTimeOut(const int32_t slotId, const int32_t callId, const int32_t videoState);
72 
73 public:
74     template<typename... Types>
HiWriteBehaviorEventPhoneUE(const std::string & eventName,Types...args)75     static void HiWriteBehaviorEventPhoneUE(const std::string &eventName, Types... args)
76     {
77         HiSysEventWrite(DOMAIN_PHONE_UE, eventName, EventType::BEHAVIOR, args...);
78     }
79 
80 private:
81     static int32_t ErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue);
82     static int32_t CallDataErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue);
83     static int32_t CallInterfaceErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue);
84     static int32_t TelephonyErrorCodeConversion(const int32_t errCode, CallErrorCode &eventValue);
85 
86 private:
87     int64_t dialStartTime_ = 0;
88     int64_t incomingStartTime_ = 0;
89     int64_t answerStartTime_ = 0;
90 };
91 } // namespace Telephony
92 } // namespace OHOS
93 
94 #endif // CALL_MANAGER_HISYSEVENT_H
95