• 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 #ifndef EVENT_LOG_HELPER_H
17 #define EVENT_LOG_HELPER_H
18 
19 #if !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
20 #include "parameters.h"
21 #endif // !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
22 
23 #include "key_event.h"
24 #include "mmi_log.h"
25 #include "pointer_event.h"
26 
27 #undef MMI_LOG_TAG
28 #define MMI_LOG_TAG "EventLogHelper"
29 
30 namespace OHOS {
31 namespace MMI {
32 static constexpr std::string_view InfoTrackingDict =
33         "Info-InputTracking-Dict: "
34         "AT-ActionTime, CL-CapsLock, DI-DisplayId, DPT-DispatchTimes, DT-DownTime, DX-DisplayX, DXP-DisplayXPos,"
35         " DY-DisplayY, DYP-DisplayYPos, ET-EventType, GU-GetUnicode, I-id, IP-IsPressed, IR-IsRepeat, SI-IsSimulate,"
36         " KA-KeyAction, KC-KeyCode, KIC-keyItemsCount, LA-LongAxis, NL-NumLock, OPI-OriginPointerId, PA-PointerAction,"
37         " PI-pointerId, P-Pressure, SA-ShortAxis, SL-ScrollLock, ST-SourceType, WI-WindowId, WXP-WindowXPos, "
38         "WYP-WindowYPos, PBS-PressedButtonsSize";
39 
40 static constexpr std::string_view DebugTrackingDict =
41         "Debug-InputTracking-Dict: "
42         "A-Action, AST-ActionStartTime, B-Buffer, BC-BufferCount, BI-ButtonId, BAV-BrakeAbsValue, F-Flag,"
43         " GAV-GenericAxisValue, HAV-HorizontalAxisValue, HXAV-Hat0xAbsValue, HYAV-Hat0yAbsValue, KI-KeyIntention,"
44         " ME-MarkEnabled, PAV-PinchAxisValue, PC-PointerCount, RZAV-RzAbsValue, SIT-SensorInputTime, "
45         "TAV-ThrottleAbsValue, TX-TiltX, TY-TiltY, VAV-VerticalAxisValue, W-Width, WX-WindowX, WY-WindowY,"
46         " XAV-XAbsValue, YAV-YAbsValue, ZAV-ZAbsValue, RAV-RotateAxisValue";
47 
48 constexpr int32_t NUMBER_KEY_BEGIN { 2000 };
49 constexpr int32_t NUMBER_KEY_END { 2011 };
50 constexpr int32_t AIPHABET_KEY_BEGIN { 2017 };
51 constexpr int32_t AIPHABET_KEY_END { 2044 };
52 constexpr int32_t SYMBOLIC_KEY_BEGIN { 2056 };
53 constexpr int32_t SYMBOLIC_KEY_END { 2066 };
54 constexpr int32_t KEYPAD_KEY_BEGIN { 2103 };
55 constexpr int32_t KEYPAD_KEY_END { 2122 };
56 constexpr int32_t BIN_KEY_BEGIN { 3100 };
57 constexpr int32_t BIN_KEY_END { 3109 };
58 
59 class EventLogHelper final {
60 public:
61     template<class T>
62     static void PrintEventData(std::shared_ptr<T> event, int32_t actionType, int32_t itemNum, const LogHeader &lh);
63 
64     template<class T> static void PrintEventData(std::shared_ptr<T> event, const LogHeader &lh);
65 
GetBetaUserType()66     static std::string GetBetaUserType()
67     {
68         std::call_once(betaFlag_, []() { SetBetaUserType(); });
69         if (userType_ == "beta") {
70             return "DEVICE_BETA_USER";
71         } else if (userType_ == "default") {
72             return "DEVICE_BETA_DEFAULT";
73         } else {
74             return "DEVICE_BETA_OTHER";
75         }
76     }
77 
IsBetaVersion()78     static bool IsBetaVersion()
79     {
80         return GetBetaUserType() == "DEVICE_BETA_USER";
81     }
82 
SetBetaUserType()83     static void SetBetaUserType()
84     {
85 #if !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
86         userType_ = OHOS::system::GetParameter("const.logsystem.versiontype", "default");
87 #endif // !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
88     }
89 
90 private:
91     static int32_t infoDictCount_;
92     static int32_t debugDictCount_;
93     static std::string userType_;
94     static std::once_flag betaFlag_;
95     static constexpr int32_t printRate_ = 50;
96 
IsEnterableKey(int32_t keyCode)97     static bool IsEnterableKey(int32_t keyCode)
98     {
99         if ((keyCode >= NUMBER_KEY_BEGIN && keyCode <= NUMBER_KEY_END) ||
100             (keyCode >= AIPHABET_KEY_BEGIN && keyCode <= AIPHABET_KEY_END) ||
101             (keyCode >= SYMBOLIC_KEY_BEGIN && keyCode <= SYMBOLIC_KEY_END) ||
102             (keyCode >= KEYPAD_KEY_BEGIN && keyCode <= KEYPAD_KEY_END) ||
103             (keyCode >= BIN_KEY_BEGIN && keyCode <= BIN_KEY_END)) {
104             return true;
105         }
106         return false;
107     }
108 
PrintInfoDict()109     static void PrintInfoDict()
110     {
111         if ((++infoDictCount_) % printRate_ == 0) {
112             infoDictCount_ = 0;
113             MMI_HILOGI("%{public}s", InfoTrackingDict.data());
114         }
115     }
116 
PrintDebugDict()117     static void PrintDebugDict()
118     {
119         if ((++debugDictCount_) % printRate_ == 0) {
120             debugDictCount_ = 0;
121             MMI_HILOGD("%{public}s", DebugTrackingDict.data());
122         }
123     }
124 
PrintInfoLog(const std::shared_ptr<KeyEvent> event,const LogHeader & lh)125     static void PrintInfoLog(const std::shared_ptr<KeyEvent> event, const LogHeader &lh)
126     {
127         PrintInfoDict();
128         std::vector<KeyEvent::KeyItem> eventItems{ event->GetKeyItems() };
129         std::string isSimulate = event->HasFlag(InputEvent::EVENT_FLAG_SIMULATE) ? "true" : "false";
130         std::string isRepeat = event->IsRepeat() ? "true" : "false";
131         if (!IsBetaVersion()) {
132             MMI_HILOG_HEADER(LOG_INFO, lh, "See InputTracking-Dict, I:%{public}d" ", ET:%{public}s,"
133                 "KA:%{public}s, KIC:%{public}zu, DI:%{public}d, IR:%{public}s, SI:%{public}s",
134                 event->GetId(), InputEvent::EventTypeToString(event->GetEventType()),
135                 KeyEvent::ActionToString(event->GetKeyAction()), eventItems.size(),
136                 event->GetTargetDisplayId(), isRepeat.c_str(), isSimulate.c_str());
137         } else {
138             if (event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE) || IsEnterableKey(event->GetKeyCode())) {
139                 MMI_HILOG_HEADER(LOG_INFO, lh, "See InputTracking-Dict, I:%{public}d, KC:%d, AT:%{public}" PRId64
140                     ", ET:%{public}s, KA:%{public}s, NL:%{public}d, CL:%d, SL:%d, KIC:%zu, "
141                     "DI:%{public}d, IR:%{public}s, SI:%{public}s",
142                     event->GetId(), event->GetKeyCode(), event->GetActionTime(),
143                     InputEvent::EventTypeToString(event->GetEventType()),
144                     KeyEvent::ActionToString(event->GetKeyAction()),
145                     event->GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY),
146                     event->GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY),
147                     event->GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY), eventItems.size(),
148                     event->GetTargetDisplayId(), isRepeat.c_str(), isSimulate.c_str());
149             } else {
150                 MMI_HILOG_HEADER(LOG_INFO, lh, "See InputTracking-Dict, I:%{public}d, KC:%{public}d,"
151                     "AT:%{public} " PRId64 " , ET:%{public}s, KA:%{public}s, NL:%{public}d, CL:%{public}d, "
152                     "SL:%{public}d, KIC:%{public}zu, DI:%{public}d, IR:%{public}s, SI:%{public}s",
153                     event->GetId(), event->GetKeyCode(), event->GetActionTime(),
154                     InputEvent::EventTypeToString(event->GetEventType()),
155                     KeyEvent::ActionToString(event->GetKeyAction()),
156                     event->GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY),
157                     event->GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY),
158                     event->GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY), eventItems.size(),
159                     event->GetTargetDisplayId(), isRepeat.c_str(), isSimulate.c_str());
160             }
161         }
162 
163         for (const auto &item : eventItems) {
164             if (!IsBetaVersion()) {
165                 MMI_HILOG_HEADER(LOG_INFO, lh, "DN:%{public}d" PRId64
166                 ", IP:%{public}d,", item.GetDeviceId(), item.IsPressed());
167             } else {
168                 if (event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
169                     MMI_HILOG_HEADER(LOG_INFO, lh, "DN:%{public}d, KC:%d, DT:%{public}" PRId64
170                     ", IP:%{public}d,", item.GetDeviceId(), item.GetKeyCode(), item.GetDownTime(), item.IsPressed());
171                 } else {
172                     MMI_HILOG_HEADER(LOG_INFO, lh, "DN:%{public}d, KC:%{public}d, DT:%{public}" PRId64
173                     ", IP:%{public}d,", item.GetDeviceId(), item.GetKeyCode(), item.GetDownTime(), item.IsPressed());
174                 }
175             }
176         }
177         std::vector<int32_t> pressedKeys = event->GetPressedKeys();
178         std::vector<int32_t>::const_iterator cItr = pressedKeys.cbegin();
179         if (cItr != pressedKeys.cend()) {
180             std::string tmpStr = "Pressed KC: [" + std::to_string(*(cItr++));
181             for (; cItr != pressedKeys.cend(); ++cItr) {
182                 tmpStr += ("," + std::to_string(*cItr));
183             }
184             if (IsBetaVersion()) {
185                 if (!event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
186                     MMI_HILOG_HEADER(LOG_INFO, lh, "%{public}s]", tmpStr.c_str());
187                 }
188             }
189         }
190     }
191 
Print(const std::shared_ptr<KeyEvent> event,const LogHeader & lh)192     static void Print(const std::shared_ptr<KeyEvent> event, const LogHeader &lh)
193     {
194         if (!HiLogIsLoggable(lh.domain, lh.func, LOG_DEBUG) && event->GetKeyCode() != KeyEvent::KEYCODE_POWER) {
195             return;
196         }
197         PrintDebugDict();
198         PrintInfoDict();
199         std::vector<KeyEvent::KeyItem> eventItems{ event->GetKeyItems() };
200         bool isJudgeMode = IsEnterableKey(event->GetKeyCode());
201         if (!IsBetaVersion()) {
202             MMI_HILOG_HEADER(LOG_DEBUG, lh, "KI:%{public}d, " "ET:%{public}s, F:%{public}d, KA:%{public}s, "
203                 "EN:%{public}d , KIC:%{public}zu",
204                 event->GetKeyIntention(), InputEvent::EventTypeToString(event->GetEventType()), event->GetFlag(),
205                 KeyEvent::ActionToString(event->GetKeyAction()), event->GetId(), eventItems.size());
206         } else {
207             if (event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE) || isJudgeMode) {
208                     MMI_HILOG_HEADER(LOG_DEBUG, lh, "KC:%d, KI:%{public}d, AT:%{public}" PRId64 ", AST:%{public}" PRId64
209                         ", ET:%{public}s, F:%{public}d, KA:%{public}s, NL:%{public}d, CL:%{public}d, SL:%{public}d"
210                         ", EN:%{public}d, KIC:%{public}zu",
211                         event->GetKeyCode(), event->GetKeyIntention(), event->GetActionTime(),
212                         event->GetActionStartTime(), InputEvent::EventTypeToString(event->GetEventType()),
213                         event->GetFlag(), KeyEvent::ActionToString(event->GetKeyAction()),
214                         event->GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY),
215                         event->GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY),
216                         event->GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY), event->GetId(), eventItems.size());
217             } else {
218                 MMI_HILOG_HEADER(LOG_DEBUG, lh, "KC:%{public}d, KI:%{public}d, AT:%{public}" PRId64 ","
219                     "AST:%{public}" PRId64 ", ET:%{public}s, F:%{public}d, KA:%{public}s, NL:%{public}d, "
220                     "CL:%{public}d, SL:%{public}d, EN:%{public}d, KIC:%{public}zu",
221                     event->GetKeyCode(), event->GetKeyIntention(), event->GetActionTime(), event->GetActionStartTime(),
222                     InputEvent::EventTypeToString(event->GetEventType()), event->GetFlag(),
223                     KeyEvent::ActionToString(event->GetKeyAction()),
224                     event->GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY),
225                     event->GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY),
226                     event->GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY), event->GetId(), eventItems.size());
227             }
228         }
229         for (const auto &item : eventItems) {
230             if (!IsBetaVersion()) {
231                 MMI_HILOG_HEADER(LOG_INFO, lh, "DN:%{public}d, IP:%{public}d",
232                     item.GetDeviceId(), item.IsPressed());
233             } else {
234                 if (event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
235                     MMI_HILOG_HEADER(LOG_INFO, lh, "DN:%{public}d, IP:%{public}d",
236                         item.GetDeviceId(), item.IsPressed());
237                 } else {
238                     MMI_HILOG_HEADER(LOG_INFO, lh, "DN:%{public}d, KC:%{public}d, DT:%{public}" PRId64 ","
239                         "IP:%{public}d, GU:%{public}d", item.GetDeviceId(), item.GetKeyCode(), item.GetDownTime(),
240                         item.IsPressed(), item.GetUnicode());
241                 }
242             }
243         }
244         std::vector<int32_t> pressedKeys = event->GetPressedKeys();
245         std::vector<int32_t>::const_iterator cItr = pressedKeys.cbegin();
246         if (cItr != pressedKeys.cend()) {
247             std::string tmpStr = "Pressed keyCode: [" + std::to_string(*(cItr++));
248             for (; cItr != pressedKeys.cend(); ++cItr) {
249                 tmpStr += ("," + std::to_string(*cItr));
250             }
251             if (IsBetaVersion()) {
252                 if (!isJudgeMode || !event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
253                         MMI_HILOG_HEADER(LOG_INFO, lh, "%{public}s]", tmpStr.c_str());
254                 }
255             }
256         }
257     }
258 
259     __attribute__((no_sanitize("cfi")))
PrintInfoLog(const std::shared_ptr<PointerEvent> event,const LogHeader & lh)260     static void PrintInfoLog(const std::shared_ptr<PointerEvent> event, const LogHeader &lh)
261     {
262         if (event->GetPointerAction() == PointerEvent::POINTER_ACTION_MOVE ||
263             event->GetPointerAction() == PointerEvent::POINTER_ACTION_PULL_MOVE ||
264             event->GetPointerAction() == PointerEvent::POINTER_ACTION_HOVER_MOVE ||
265             event->GetPointerAction() == PointerEvent::POINTER_ACTION_AXIS_UPDATE ||
266             event->GetPointerAction() == PointerEvent::POINTER_ACTION_SWIPE_UPDATE ||
267             event->GetPointerAction() == PointerEvent::POINTER_ACTION_ROTATE_UPDATE ||
268             event->GetPointerAction() == PointerEvent::POINTER_ACTION_FINGERPRINT_SLIDE) {
269             return;
270         }
271         PrintInfoDict();
272         std::vector<int32_t> pointerIds{ event->GetPointerIds() };
273         std::string isSimulate = event->HasFlag(InputEvent::EVENT_FLAG_SIMULATE) ? "true" : "false";
274         MMI_HILOGD("See InputTracking-Dict I:%{public}d, ET:%{public}s, AT:%{public}" PRId64
275             ", PA:%{public}s, ST:%{public}s, DI:%{public}d, WI:%{public}d, DPT:%{public}d"
276             ", SI:%{public}s, PBS:%{public}zu",
277             event->GetId(), InputEvent::EventTypeToString(event->GetEventType()), event->GetActionTime(),
278             event->DumpPointerAction(), event->DumpSourceType(), event->GetTargetDisplayId(),
279             event->GetTargetWindowId(), event->GetDispatchTimes(), isSimulate.c_str(),
280             event->GetPressedButtons().size());
281         for (const auto &pointerId : pointerIds) {
282             PointerEvent::PointerItem item;
283             if (!event->GetPointerItem(pointerId, item)) {
284                 MMI_HILOG_HEADER(LOG_ERROR, lh, "Invalid pointer:%{public}d", pointerId);
285                 return;
286             }
287             if (!IsBetaVersion()) {
288                 MMI_HILOG_HEADER(LOG_INFO, lh, "PI:%{public}d, IP:%{public}d, P:%{public}.2f, MF:%{public}d, "
289                     "WI:%{public}d, OPI:%{public}d, SI:%{public}s",
290                     pointerId, item.IsPressed(), item.GetPressure(), item.GetMoveFlag(), item.GetTargetWindowId(),
291                     item.GetOriginPointerId(), isSimulate.c_str());
292             } else {
293                 if (event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
294                     MMI_HILOG_HEADER(LOG_INFO, lh, "PI:%{public}d, DT:%{public}" PRId64 ", IP:%{public}d, DX:%d, DY:%d,"
295                         "P:%{public}.2f, MF:%{public}d, LA:%{public}d, SA:%{public}d, WI:%{public}d, "
296                         "DXP:%f, DYP:%f, WXP:%f, WYP:%f, OPI:%{public}d",
297                         pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(), item.GetDisplayY(),
298                         item.GetPressure(), item.GetMoveFlag(), item.GetLongAxis(), item.GetShortAxis(),
299                         item.GetTargetWindowId(), item.GetDisplayXPos(), item.GetDisplayYPos(), item.GetWindowXPos(),
300                         item.GetWindowYPos(), item.GetOriginPointerId());
301                 } else {
302                     MMI_HILOG_HEADER(LOG_INFO, lh, "PI:%{public}d, DT:%{public}" PRId64 ", IP:%{public}d, "
303                         "DX:%{public}d, DY:%{public}d, P:%{public}.2f, MF:%{public}d, LA:%{public}d, SA:%{public}d, "
304                         "WI:%{public}d, DXP:%{public}f, DYP:%{public}f, WXP:%{public}f, WYP:%{public}f, "
305                         "OPI:%{public}d, SI:%{public}s",
306                         pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(), item.GetDisplayY(),
307                         item.GetPressure(), item.GetMoveFlag(), item.GetLongAxis(), item.GetShortAxis(),
308                         item.GetTargetWindowId(), item.GetDisplayXPos(), item.GetDisplayYPos(), item.GetWindowXPos(),
309                         item.GetWindowYPos(), item.GetOriginPointerId(), isSimulate.c_str());
310                 }
311             }
312         }
313         std::vector<int32_t> pressedKeys = event->GetPressedKeys();
314         std::vector<int32_t>::const_iterator cItr = pressedKeys.cbegin();
315         if (cItr != pressedKeys.cend()) {
316             std::string tmpStr = "Pressed keyCode: [" + std::to_string(*(cItr++));
317             for (; cItr != pressedKeys.cend(); ++cItr) {
318                 tmpStr += ("," + std::to_string(*cItr));
319             }
320             if (IsBetaVersion()) {
321                 if (!event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
322                     MMI_HILOG_HEADER(LOG_INFO, lh, "%{public}s]", tmpStr.c_str());
323                 }
324             }
325         }
326     }
327 
Print(const std::shared_ptr<PointerEvent> event,const LogHeader & lh)328     static void Print(const std::shared_ptr<PointerEvent> event, const LogHeader &lh)
329     {
330         PrintDebugDict();
331         std::vector<int32_t> pointerIds{ event->GetPointerIds() };
332         std::string str;
333         std::vector<uint8_t> buffer = event->GetBuffer();
334         for (const auto &buff : buffer) {
335             str += std::to_string(buff);
336         }
337         if (!IsBetaVersion()) {
338             MMI_HILOG_HEADER(LOG_DEBUG, lh, "ET:%{public}s, SIT:%{public}" PRIu64 ", A:%{public}d, "
339                 ", F:%{public}d, PA:%{public}s, ST:%{public}s, BI:%{public}d, PI:%{public}d, PC:%{public}zu, "
340                 "EN:%{public}d, BC:%{public}zu, ME:%{public}d",
341                 InputEvent::EventTypeToString(event->GetEventType()),
342                 event->GetSensorInputTime(), event->GetAction(), event->GetFlag(),
343                 event->DumpPointerAction(), event->DumpSourceType(), event->GetButtonId(), event->GetPointerId(),
344                 pointerIds.size(), event->GetId(), buffer.size(), event->IsMarkEnabled());
345         } else {
346             MMI_HILOG_HEADER(LOG_DEBUG, lh, "ET:%{public}s, AT:%{public}" PRId64 ", SIT:%{public}" PRId64
347                 ",A:%{public}d, AST:%{public}" PRId64 ", F:%{public}d, PA:%{public}s, ST:%{public}s, BI:%{public}d, "
348                 "VAV:%{public}.5f, HAV:%{public}.5f, PAV:%{public}.5f, PAV:%{public}.5f, XAV:%{public}.5f,"
349                 "YAV:%{public}.5f, ZAV:%{public}.5f, RZAV:%{public}.5f, GAV:%{public}.5f, BAV:%{public}.5f, "
350                 "HXAV:%{public}.5f, HYAV:%{public}.5f, TAV:%{public}.5f,PI:%{public}d, PC:%{public}zu, EN:%{public}d, "
351                 "BC:%{public}zu, B:%{public}s, ME:%{public}d",
352                 InputEvent::EventTypeToString(event->GetEventType()), event->GetActionTime(),
353                 event->GetSensorInputTime(), event->GetAction(), event->GetActionStartTime(), event->GetFlag(),
354                 event->DumpPointerAction(), event->DumpSourceType(), event->GetButtonId(),
355                 event->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL),
356                 event->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL),
357                 event->GetAxisValue(PointerEvent::AXIS_TYPE_PINCH), event->GetAxisValue(PointerEvent::AXIS_TYPE_ROTATE),
358                 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_X), event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_Y),
359                 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_Z), event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_RZ),
360                 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_GAS),
361                 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_BRAKE),
362                 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_HAT0X),
363                 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_HAT0Y),
364                 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_THROTTLE), event->GetPointerId(), pointerIds.size(),
365                 event->GetId(), buffer.size(), str.c_str(), event->IsMarkEnabled());
366         }
367 
368         for (const auto &pointerId : pointerIds) {
369             PointerEvent::PointerItem item;
370             if (!event->GetPointerItem(pointerId, item)) {
371                 MMI_HILOG_HEADER(LOG_ERROR, lh, "Invalid pointer:%{public}d", pointerId);
372                 return;
373             }
374             if (!IsBetaVersion()) {
375                 MMI_HILOG_HEADER(LOG_DEBUG, lh,
376                     "PI:%{public}d, IP:%{public}d, P:%{public}.2f, MF:%{public}d, ToolType:%{public}d",
377                     pointerId, item.IsPressed(), item.GetPressure(), item.GetMoveFlag(), item.GetToolType());
378             } else {
379                 if (event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
380                     MMI_HILOG_HEADER(LOG_DEBUG, lh,"PI:%{public}d, DT:%{public}" PRId64 ", IP:%{public}d, DX:%d, DY:%d"
381                         ", WX:%d, WY:%d, W:%{public}d, H:%{public}d, TX:%.2f, TY:%.2f, TDX:%d, TDY:%d, ToolWX:%d, "
382                         "ToolWY:%d, ToolW:%{public}d, ToolH:%{public}d, P:%{public}.2f, MF:%{public}d, "
383                         "ToolType:%{public}d, LA:%{public}d, SA:%{public}d, RawDx:%d, RawDy:%d, RawDisplayX:%d, "
384                         "RawDisplayY:%d",
385                         pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(), item.GetDisplayY(),
386                         item.GetWindowX(), item.GetWindowY(), item.GetWidth(), item.GetHeight(), item.GetTiltX(),
387                         item.GetTiltY(), item.GetToolDisplayX(), item.GetToolDisplayY(), item.GetToolWindowX(),
388                         item.GetToolWindowY(), item.GetToolWidth(), item.GetToolHeight(), item.GetPressure(),
389                         item.GetMoveFlag(), item.GetToolType(), item.GetLongAxis(), item.GetShortAxis(),
390                         item.GetRawDx(), item.GetRawDy(), item.GetRawDisplayX(), item.GetRawDisplayY());
391                 } else {
392                     MMI_HILOG_HEADER(LOG_DEBUG, lh,"PI:%{public}d, DT:%{public}" PRId64 ", IP:%{public}d, "
393                         "DX:%{public}d, DY:%{public}d, WX:%{public}d, WY:%{public}d, W:%{public}d, H:%{public}d, "
394                         "TX:%{public}.2f, TY:%{public}.2f, TDX:%{public}d, TDY:%{public}d, ToolWX:%{public}d, "
395                         "ToolWY:%{public}d, ToolW:%{public}d, ToolH:%{public}d, P:%{public}.2f, MF:%{public}d, "
396                         "ToolType:%{public}d, LA:%{public}d, SA:%{public}d, RawDx:%{public}d, RawDy:%{public}d"
397                         "RawDisplayX:%{public}d, RawDisplayY:%{public}d",
398                         pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(), item.GetDisplayY(),
399                         item.GetWindowX(), item.GetWindowY(), item.GetWidth(), item.GetHeight(), item.GetTiltX(),
400                         item.GetTiltY(), item.GetToolDisplayX(), item.GetToolDisplayY(), item.GetToolWindowX(),
401                         item.GetToolWindowY(), item.GetToolWidth(), item.GetToolHeight(), item.GetPressure(),
402                         item.GetMoveFlag(), item.GetToolType(), item.GetLongAxis(), item.GetShortAxis(),
403                         item.GetRawDx(), item.GetRawDy(), item.GetRawDisplayX(), item.GetRawDisplayY());
404                 }
405             }
406             if (!IsBetaVersion()) {
407                 MMI_HILOG_HEADER(LOG_DEBUG, lh,
408                     "PI:%{public}d" ", IP:%{public}d, P:%{public}.2f, MF:%{public}d, ToolType:%{public}d",
409                     pointerId, item.IsPressed(), item.GetPressure(), item.GetMoveFlag(), item.GetToolType());
410             } else {
411                 if (event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
412                     MMI_HILOG_HEADER(LOG_DEBUG, lh,
413                         "PI:%{public}d, DT:%{public}" PRId64 ", IP:%{public}d, DX:%d, DY:%d, WX:%d, WY:%d, "
414                         "W:%{public}d, H:%{public}d, TX:%.2f, TY:%.2f, TDX:%d, TDY:%d, ToolWX:%d, ToolWY:%d, "
415                         "ToolW:%{public}d, ToolH:%{public}d, P:%{public}.2f, MF:%{public}d, "
416                         "ToolType:%{public}d, LA:%{public}d, SA:%{public}d, RawDx:%d, RawDy:%d, RawDisplayX:%d, "
417                         "RawDisplayY:%d",
418                         pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(),
419                         item.GetDisplayY(), item.GetWindowX(), item.GetWindowY(), item.GetWidth(), item.GetHeight(),
420                         item.GetTiltX(), item.GetTiltY(), item.GetToolDisplayX(), item.GetToolDisplayY(),
421                         item.GetToolWindowX(), item.GetToolWindowY(), item.GetToolWidth(), item.GetToolHeight(),
422                         item.GetPressure(), item.GetMoveFlag(), item.GetToolType(), item.GetLongAxis(),
423                         item.GetShortAxis(), item.GetRawDx(), item.GetRawDy(), item.GetRawDisplayX(),
424                         item.GetRawDisplayY());
425                 } else {
426                     MMI_HILOG_HEADER(LOG_DEBUG, lh,
427                         "PI:%{public}d, DT:%{public}" PRId64 ", IP:%{public}d, DX:%{public}d, DY:%{public}d, "
428                         "WX:%{public}d, WY:%{public}d, W:%{public}d, H:%{public}d, TX:%{public}.2f, TY:%{public}.2f, "
429                         "TDX:%{public}d, TDY:%{public}d, ToolWX:%{public}d, ToolWY:%{public}d, ToolW:%{public}d, "
430                         "ToolH:%{public}d, P:%{public}.2f, ToolType:%{public}d, LA:%{public}d, SA:%{public}d, "
431                         "RawDx:%{public}d, RawDy:%{public}d, RawDisplayX:%{public}d, RawDisplayY:%{public}d",
432                         pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(),
433                         item.GetDisplayY(), item.GetWindowX(), item.GetWindowY(), item.GetWidth(), item.GetHeight(),
434                         item.GetTiltX(), item.GetTiltY(), item.GetToolDisplayX(), item.GetToolDisplayY(),
435                         item.GetToolWindowX(), item.GetToolWindowY(), item.GetToolWidth(), item.GetToolHeight(),
436                         item.GetPressure(), item.GetToolType(), item.GetLongAxis(), item.GetShortAxis(),
437                         item.GetRawDx(), item.GetRawDy(), item.GetRawDisplayX(), item.GetRawDisplayY());
438                 }
439             }
440         }
441         std::vector<int32_t> pressedKeys = event->GetPressedKeys();
442         std::vector<int32_t>::const_iterator cItr = pressedKeys.cbegin();
443         if (cItr != pressedKeys.cend()) {
444             std::string tmpStr = "Pressed keyCode: [" + std::to_string(*(cItr++));
445             for (; cItr != pressedKeys.cend(); ++cItr) {
446                 tmpStr += (", " + std::to_string(*cItr));
447             }
448             if (IsBetaVersion()) {
449                 if (!event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
450                     MMI_HILOG_HEADER(LOG_DEBUG, lh, "%{public}s]", tmpStr.c_str());
451                 }
452             }
453         }
454     }
455 };
456 
PrintEventData(std::shared_ptr<T> event,int32_t actionType,int32_t itemNum,const LogHeader & lh)457 template <class T> void EventLogHelper::PrintEventData(std::shared_ptr<T> event, int32_t actionType, int32_t itemNum,
458                                                        const LogHeader &lh)
459 {
460     CHKPV(event);
461     PrintInfoLog(event, lh);
462     if (HiLogIsLoggable(lh.domain, lh.tag, LOG_DEBUG)) {
463         static int64_t nowTimeUSec = 0;
464         static int32_t dropped = 0;
465         if (event->GetAction() == EVENT_TYPE_POINTER) {
466             if ((actionType == POINTER_ACTION_MOVE) && (event->GetActionTime() - nowTimeUSec <= TIMEOUT)) {
467                 ++dropped;
468                 return;
469             }
470             if (actionType == POINTER_ACTION_UP && itemNum == FINAL_FINGER) {
471                 MMI_HILOG_HEADER(LOG_DEBUG, lh, "This touch process discards %{public}d high frequent events", dropped);
472                 dropped = 0;
473             }
474             nowTimeUSec = event->GetActionTime();
475         }
476         EventLogHelper::Print(event, lh);
477     }
478 }
479 
PrintEventData(std::shared_ptr<T> event,const LogHeader & lh)480 template <class T> void EventLogHelper::PrintEventData(std::shared_ptr<T> event, const LogHeader &lh)
481 {
482     CHKPV(event);
483     PrintInfoLog(event, lh);
484     if (HiLogIsLoggable(lh.domain, lh.tag, LOG_DEBUG) ||
485         (event->GetAction() == InputEvent::EVENT_TYPE_KEY)) {
486         EventLogHelper::Print(event, lh);
487     }
488 }
489 } // namespace MMI
490 } // namespace OHOS
491 #endif // EVENT_LOG_HELPER_H
492