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 #ifndef DFX_HISYSEVENT_H
17 #define DFX_HISYSEVENT_H
18 
19 #include <string>
20 
21 #include "hisysevent.h"
22 
23 #include "input_device_manager.h"
24 #include "key_event.h"
25 #include "mmi_log.h"
26 #include "pointer_event.h"
27 #include "uds_session.h"
28 
29 namespace OHOS {
30 namespace MMI {
31 class DfxHisysevent {
32 public:
33     struct DispCastTime {
34         uint32_t sampleCount;
35         uint32_t totalTimes;
36         uint32_t below10msTimes;
37         uint32_t below25msTimes;
38         uint32_t below50msTimes;
39         uint32_t above50msTimes;
40     };
41     struct ComboStartCastTime {
42         uint32_t totalTimes;
43         uint32_t below10msTimes;
44         uint32_t below30msTimes;
45         uint32_t below50msTimes;
46         uint32_t above50msTimes;
47     };
48     struct ClientConnectData {
49         int32_t pid { -1 };
50         int32_t uid { -1 };
51         int32_t moduleType { -1 };
52         std::string programName;
53         int32_t serverFd { -1 };
54     };
55 
56     enum TOUCHPAD_SETTING_CODE {
57         TOUCHPAD_SCROLL_SETTING = 1,
58         TOUCHPAD_SCROLL_DIR_SETTING,
59         TOUCHPAD_TAP_SETTING,
60         TOUCHPAD_SWIPE_SETTING,
61         TOUCHPAD_PINCH_SETTING,
62         TOUCHPAD_POINTER_SPEED_SETTING,
63         TOUCHPAD_RIGHT_CLICK_SETTING,
64         TOUCHPAD_ROTATE_SETTING
65     };
66 
67     static void OnDeviceConnect(int32_t id, OHOS::HiviewDFX::HiSysEvent::EventType type);
68     static void OnDeviceDisconnect(int32_t id, OHOS::HiviewDFX::HiSysEvent::EventType type);
69     static void OnClientConnect(const ClientConnectData &data, OHOS::HiviewDFX::HiSysEvent::EventType type);
70     static void OnClientDisconnect(const SessionPtr& secPtr, int32_t fd,
71         OHOS::HiviewDFX::HiSysEvent::EventType type);
72     static void OnUpdateTargetPointer(std::shared_ptr<PointerEvent> pointer, int32_t fd,
73         OHOS::HiviewDFX::HiSysEvent::EventType type);
74     static void OnUpdateTargetKey(std::shared_ptr<KeyEvent> key, int32_t fd,
75         OHOS::HiviewDFX::HiSysEvent::EventType type);
76     static void OnFocusWindowChanged(int32_t oldFocusWindowId, int32_t newFocusWindowId,
77         int32_t oldFocusWindowPid, int32_t newFocusWindowPid);
78     static void OnZorderWindowChanged(int32_t oldZorderFirstWindowId, int32_t newZorderFirstWindowId,
79         int32_t oldZorderFirstWindowPid, int32_t newZorderFirstWindowPid);
80     static void OnLidSwitchChanged(int32_t lidSwitch);
81     static void ApplicationBlockInput(const SessionPtr& sess);
82     static void CalcKeyDispTimes();
83     static void CalcPointerDispTimes();
84     static void CalcComboStartTimes(int32_t keyDownDuration);
85     static void ReportDispTimes();
86     static void ReportComboStartTimes();
87     static void ReportPowerInfo(std::shared_ptr<KeyEvent> key, OHOS::HiviewDFX::HiSysEvent::EventType type);
GetComboStartTime()88     static inline void GetComboStartTime()
89     {
90         comboStartTime_ = GetSysClockTime();
91     }
GetDispStartTime()92     static inline void GetDispStartTime()
93     {
94         dispatchStartTime_ = GetSysClockTime();
95     }
96     static void ReportTouchpadSettingState(TOUCHPAD_SETTING_CODE settingCode, bool flag);
97     static void ReportTouchpadSettingState(TOUCHPAD_SETTING_CODE settingCode, int32_t value);
98     static void StatisticTouchpadGesture(std::shared_ptr<PointerEvent> pointerEvent);
99     static void ReportKnuckleClickEvent();
100     static void ReportScreenCaptureGesture();
101     static void ReportSingleKnuckleDoubleClickEvent(int32_t intervalTime, int32_t distanceInterval);
102     static void ReportFailIfInvalidTime(const std::shared_ptr<PointerEvent> touchEvent, int32_t intervalTime);
103     static void ReportFailIfInvalidDistance(const std::shared_ptr<PointerEvent> touchEvent, float distance);
104 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR
105     static void ReportMagicCursorColorChange(std::string fill_Color, std::string stroke_Color);
106     static void ReportMagicCursorShapeChange(std::string fill_Code, OHOS::MMI::MOUSE_ICON mouse_Style);
107     static void ReportMagicCursorSizeChange(std::string fill_Code, std::string mouse_Size);
108     static void ReportMagicCursorFault(std::string error_Code, std::string error_Name);
109 #endif // OHOS_BUILD_ENABLE_MAGICCURSOR
110     static void ReportSmartShotSuccTimes();
111     static void ReportKnuckleGestureTrackLength(int32_t knuckleGestureTrackLength);
112     static void ReportKnuckleGestureTrackTime(const std::vector<int64_t> &gestureTimeStamps);
113     static void ReportKnuckleGestureFaildTimes();
114     static void ReportKnuckleDrawSSuccessTimes();
115     static void ReportKnuckleGestureFromFailToSuccessTime(int32_t intervalTime);
116     static void ReportKnuckleGestureFromSuccessToFailTime(int32_t intervalTime);
117     static void ReportScreenRecorderGesture(int32_t intervalTime);
118     static void ReportFailIfKnockTooFast();
119     static void ReportFailIfOneSuccTwoFail(const std::shared_ptr<PointerEvent> touchEvent);
120     static std::string GetTpVendorName();
121     static std::string GetAccVendorName();
122     static std::string GetLcdInfo();
123 
124 private:
125     static inline int64_t dispatchStartTime_ { 0 };
126     static inline int64_t comboStartTime_ { 0 };
127     static inline DispCastTime dispCastTime_ { 0 };
128     static inline ComboStartCastTime comboStartCastTime_ { 0 };
129 };
130 } // namespace MMI
131 } // namespace OHOS
132 #endif // BYTRACE_ADAPTER_H
133