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 std::vector<KeyEvent::KeyItem> eventItems{ event->GetKeyItems() };
128 std::string isSimulate = event->HasFlag(InputEvent::EVENT_FLAG_SIMULATE) ? "true" : "false";
129 std::string isRepeat = event->IsRepeat() ? "true" : "false";
130 if (!IsBetaVersion()) {
131 MMI_HILOG_HEADER(LOG_INFO, lh, "See InputTracking-Dict, I:%{public}d" ", ET:%{public}s,"
132 "KA:%{public}s, KIC:%{public}zu, DI:%{public}d, IR:%{public}s, SI:%{public}s",
133 event->GetId(), InputEvent::EventTypeToString(event->GetEventType()),
134 KeyEvent::ActionToString(event->GetKeyAction()), eventItems.size(),
135 event->GetTargetDisplayId(), isRepeat.c_str(), isSimulate.c_str());
136 } else {
137 if (event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE) || IsEnterableKey(event->GetKeyCode())) {
138 MMI_HILOG_HEADER(LOG_INFO, lh, "See InputTracking-Dict, I:%{public}d,"
139 "KC:%{private}d, AT:%{public}" PRId64
140 ", ET:%{public}s, KA:%{public}s, NL:%{public}d, CL:%{public}d, SL:%{public}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:%{private}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:%{private}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:%{private}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 std::vector<KeyEvent::KeyItem> eventItems{ event->GetKeyItems() };
199 bool isJudgeMode = IsEnterableKey(event->GetKeyCode());
200 if (!IsBetaVersion()) {
201 MMI_HILOG_HEADER(LOG_DEBUG, lh, "KI:%{public}d, " "ET:%{public}s, F:%{public}d, KA:%{public}s, "
202 "EN:%{public}d , KIC:%{public}zu",
203 event->GetKeyIntention(), InputEvent::EventTypeToString(event->GetEventType()), event->GetFlag(),
204 KeyEvent::ActionToString(event->GetKeyAction()), event->GetId(), eventItems.size());
205 } else {
206 if (event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE) || isJudgeMode) {
207 MMI_HILOG_HEADER(LOG_DEBUG, lh, "KC:%{private}d, KI:%{public}d,"
208 "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:%{private}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:%{private}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, "%{private}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 std::vector<int32_t> pointerIds{ event->GetPointerIds() };
272 std::string isSimulate = event->HasFlag(InputEvent::EVENT_FLAG_SIMULATE) ? "true" : "false";
273 MMI_HILOGD("See InputTracking-Dict I:%{public}d, ET:%{public}s, AT:%{public}" PRId64
274 ", PA:%{public}s, ST:%{public}s, DI:%{public}d, WI:%{public}d, DPT:%{public}d"
275 ", SI:%{public}s, PBS:%{public}zu",
276 event->GetId(), InputEvent::EventTypeToString(event->GetEventType()), event->GetActionTime(),
277 event->DumpPointerAction(), event->DumpSourceType(), event->GetTargetDisplayId(),
278 event->GetTargetWindowId(), event->GetDispatchTimes(), isSimulate.c_str(),
279 event->GetPressedButtons().size());
280 for (const auto &pointerId : pointerIds) {
281 PointerEvent::PointerItem item;
282 if (!event->GetPointerItem(pointerId, item)) {
283 MMI_HILOG_HEADER(LOG_ERROR, lh, "Invalid pointer:%{public}d", pointerId);
284 return;
285 }
286 if (!IsBetaVersion()) {
287 MMI_HILOG_HEADER(LOG_INFO, lh, "PI:%{public}d, IP:%{public}d, P:%{public}.2f, MF:%{public}d, "
288 "WI:%{public}d, OPI:%{public}d, SI:%{public}s, T:%{public}d",
289 pointerId, item.IsPressed(), item.GetPressure(), item.GetMoveFlag(), item.GetTargetWindowId(),
290 item.GetOriginPointerId(), isSimulate.c_str(), item.GetTwist());
291 } else {
292 MMI_HILOG_HEADER(LOG_DEBUG, lh,"DX:%{private}d, DY:%{private}d, DXP:%{private}f, DYP:%{private}f,"
293 "WXP:%{private}f, WYP:%{private}f, IP:%{public}d, P:%{public}.2f, MF:%{public}d,"
294 "LA:%{public}d, SA:%{public}d, SI:%{public}s",
295 item.GetDisplayX(), item.GetDisplayY(), item.GetDisplayXPos(), item.GetDisplayYPos(),
296 item.GetWindowXPos(), item.GetWindowYPos(), item.IsPressed(), item.GetPressure(),
297 item.GetMoveFlag(), item.GetLongAxis(), item.GetShortAxis(), isSimulate.c_str());
298 MMI_HILOG_HEADER(LOG_INFO, lh, "%{public}d|%{public}d|%{public}d|%{public}d|%{public}" PRId64,
299 pointerId, item.GetTargetWindowId(), item.GetOriginPointerId(),
300 item.GetTwist(), item.GetDownTime());
301 }
302 }
303 std::vector<int32_t> pressedKeys = event->GetPressedKeys();
304 std::vector<int32_t>::const_iterator cItr = pressedKeys.cbegin();
305 if (cItr != pressedKeys.cend()) {
306 std::string tmpStr = "Pressed keyCode: [" + std::to_string(*(cItr++));
307 for (; cItr != pressedKeys.cend(); ++cItr) {
308 tmpStr += ("," + std::to_string(*cItr));
309 }
310 if (IsBetaVersion()) {
311 if (!event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
312 MMI_HILOG_HEADER(LOG_INFO, lh, "%{private}s]", tmpStr.c_str());
313 }
314 }
315 }
316 }
317
Print(const std::shared_ptr<PointerEvent> event,const LogHeader & lh)318 static void Print(const std::shared_ptr<PointerEvent> event, const LogHeader &lh)
319 {
320 PrintDebugDict();
321 std::vector<int32_t> pointerIds{ event->GetPointerIds() };
322 std::string str;
323 std::vector<uint8_t> buffer = event->GetBuffer();
324 for (const auto &buff : buffer) {
325 str += std::to_string(buff);
326 }
327 if (!IsBetaVersion()) {
328 MMI_HILOG_HEADER(LOG_DEBUG, lh, "ET:%{public}s, SIT:%{public}" PRIu64 ", A:%{public}d, "
329 ", F:%{public}d, PA:%{public}s, ST:%{public}s, BI:%{public}d, PI:%{public}d, PC:%{public}zu, "
330 "EN:%{public}d, BC:%{public}zu, ME:%{public}d",
331 InputEvent::EventTypeToString(event->GetEventType()),
332 event->GetSensorInputTime(), event->GetAction(), event->GetFlag(),
333 event->DumpPointerAction(), event->DumpSourceType(), event->GetButtonId(), event->GetPointerId(),
334 pointerIds.size(), event->GetId(), buffer.size(), event->IsMarkEnabled());
335 } else {
336 MMI_HILOG_HEADER(LOG_DEBUG, lh, "ET:%{public}s, AT:%{public}" PRId64 ", SIT:%{public}" PRId64
337 ",A:%{public}d, AST:%{public}" PRId64 ", F:%{public}d, PA:%{public}s, ST:%{public}s, BI:%{public}d, "
338 "VAV:%{public}.5f, HAV:%{public}.5f, PAV:%{public}.5f, PAV:%{public}.5f, XAV:%{public}.5f,"
339 "YAV:%{public}.5f, ZAV:%{public}.5f, RZAV:%{public}.5f, GAV:%{public}.5f, BAV:%{public}.5f, "
340 "HXAV:%{public}.5f, HYAV:%{public}.5f, TAV:%{public}.5f,PI:%{public}d, PC:%{public}zu, EN:%{public}d, "
341 "BC:%{public}zu, B:%{public}s, ME:%{public}d",
342 InputEvent::EventTypeToString(event->GetEventType()), event->GetActionTime(),
343 event->GetSensorInputTime(), event->GetAction(), event->GetActionStartTime(), event->GetFlag(),
344 event->DumpPointerAction(), event->DumpSourceType(), event->GetButtonId(),
345 event->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL),
346 event->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL),
347 event->GetAxisValue(PointerEvent::AXIS_TYPE_PINCH), event->GetAxisValue(PointerEvent::AXIS_TYPE_ROTATE),
348 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_X), event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_Y),
349 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_Z), event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_RZ),
350 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_GAS),
351 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_BRAKE),
352 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_HAT0X),
353 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_HAT0Y),
354 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_THROTTLE), event->GetPointerId(), pointerIds.size(),
355 event->GetId(), buffer.size(), str.c_str(), event->IsMarkEnabled());
356 }
357
358 for (const auto &pointerId : pointerIds) {
359 PointerEvent::PointerItem item;
360 if (!event->GetPointerItem(pointerId, item)) {
361 MMI_HILOG_HEADER(LOG_ERROR, lh, "Invalid pointer:%{public}d", pointerId);
362 return;
363 }
364 if (!IsBetaVersion()) {
365 MMI_HILOG_HEADER(LOG_DEBUG, lh,
366 "PI:%{public}d, IP:%{public}d, P:%{public}.2f, MF:%{public}d, ToolType:%{public}d, T:%{public}d",
367 pointerId, item.IsPressed(), item.GetPressure(), item.GetMoveFlag(), item.GetToolType(),
368 item.GetTwist());
369 } else {
370 if (event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
371 MMI_HILOG_HEADER(LOG_DEBUG, lh,"PI:%{public}d, DT:%{public}" PRId64 ", IP:%{public}d, DX:%d, DY:%d"
372 ", WX:%d, WY:%d, W:%{public}d, H:%{public}d, TX:%.2f, TY:%.2f, TDX:%d, TDY:%d, ToolWX:%d, "
373 "ToolWY:%d, ToolW:%{public}d, ToolH:%{public}d, P:%{public}.2f, MF:%{public}d, "
374 "ToolType:%{public}d, LA:%{public}d, SA:%{public}d, RawDx:%d, RawDy:%d, RawDisplayX:%d, "
375 "RawDisplayY:%d, T:%{public}d, DXP:%f, DYP:%f, WXP:%f, WYP:%f",
376 pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(), item.GetDisplayY(),
377 item.GetWindowX(), item.GetWindowY(), item.GetWidth(), item.GetHeight(), item.GetTiltX(),
378 item.GetTiltY(), item.GetToolDisplayX(), item.GetToolDisplayY(), item.GetToolWindowX(),
379 item.GetToolWindowY(), item.GetToolWidth(), item.GetToolHeight(), item.GetPressure(),
380 item.GetMoveFlag(), item.GetToolType(), item.GetLongAxis(), item.GetShortAxis(),
381 item.GetRawDx(), item.GetRawDy(), item.GetRawDisplayX(), item.GetRawDisplayY(),
382 item.GetTwist(), item.GetDisplayXPos(), item.GetDisplayYPos(),
383 item.GetWindowXPos(), item.GetWindowYPos());
384 } else {
385 MMI_HILOG_HEADER(LOG_DEBUG, lh,"PI:%{public}d, DT:%{public}" PRId64 ", IP:%{public}d, "
386 "DX:%{private}d, DY:%{private}d, WX:%{private}d, WY:%{private}d, W:%{public}d, H:%{public}d, "
387 "TX:%{private}.2f, TY:%{private}.2f, TDX:%{private}d, TDY:%{private}d, ToolWX:%{private}d, "
388 "ToolWY:%{private}d, ToolW:%{public}d, ToolH:%{public}d, P:%{public}.2f, MF:%{public}d, "
389 "ToolType:%{public}d, LA:%{public}d, SA:%{public}d, RawDx:%{private}d, RawDy:%{private}d"
390 ", RawDisplayX:%{private}d, RawDisplayY:%{private}d, T:%{public}d"
391 ", DXP:%{private}f, DYP:%{private}f, WXP:%{private}f, WYP:%{private}f",
392 pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(), item.GetDisplayY(),
393 item.GetWindowX(), item.GetWindowY(), item.GetWidth(), item.GetHeight(), item.GetTiltX(),
394 item.GetTiltY(), item.GetToolDisplayX(), item.GetToolDisplayY(), item.GetToolWindowX(),
395 item.GetToolWindowY(), item.GetToolWidth(), item.GetToolHeight(), item.GetPressure(),
396 item.GetMoveFlag(), item.GetToolType(), item.GetLongAxis(), item.GetShortAxis(),
397 item.GetRawDx(), item.GetRawDy(), item.GetRawDisplayX(), item.GetRawDisplayY(),
398 item.GetTwist(), item.GetDisplayXPos(), item.GetDisplayYPos(),
399 item.GetWindowXPos(), item.GetWindowYPos());
400 }
401 }
402 if (!IsBetaVersion()) {
403 MMI_HILOG_HEADER(LOG_DEBUG, lh,
404 "PI:%{public}d" ", IP:%{public}d, P:%{public}.2f, MF:%{public}d, ToolType:%{public}d, "
405 "T:%{public}d",
406 pointerId, item.IsPressed(), item.GetPressure(), item.GetMoveFlag(), item.GetToolType(),
407 item.GetTwist());
408 } else {
409 if (event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
410 MMI_HILOG_HEADER(LOG_DEBUG, lh,
411 "PI:%{public}d, DT:%{public}" PRId64 ", IP:%{public}d, DX:%d, DY:%d, WX:%d, WY:%d, "
412 "W:%{public}d, H:%{public}d, TX:%.2f, TY:%.2f, TDX:%d, TDY:%d, ToolWX:%d, ToolWY:%d, "
413 "ToolW:%{public}d, ToolH:%{public}d, P:%{public}.2f, MF:%{public}d, "
414 "ToolType:%{public}d, LA:%{public}d, SA:%{public}d, RawDx:%d, RawDy:%d, RawDisplayX:%d, "
415 "RawDisplayY:%d, T:%{public}d, DXP:%f, DYP:%f, WXP:%f, WYP:%f",
416 pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(),
417 item.GetDisplayY(), item.GetWindowX(), item.GetWindowY(), item.GetWidth(), item.GetHeight(),
418 item.GetTiltX(), item.GetTiltY(), item.GetToolDisplayX(), item.GetToolDisplayY(),
419 item.GetToolWindowX(), item.GetToolWindowY(), item.GetToolWidth(), item.GetToolHeight(),
420 item.GetPressure(), item.GetMoveFlag(), item.GetToolType(), item.GetLongAxis(),
421 item.GetShortAxis(), item.GetRawDx(), item.GetRawDy(), item.GetRawDisplayX(),
422 item.GetRawDisplayY(), item.GetTwist(), item.GetDisplayXPos(), item.GetDisplayYPos(),
423 item.GetWindowXPos(), item.GetWindowYPos());
424 } else {
425 MMI_HILOG_HEADER(LOG_DEBUG, lh,
426 "PI:%{public}d, DT:%{public}" PRId64 ", IP:%{public}d, DX:%{private}d, DY:%{private}d, "
427 "WX:%{private}d, WY:%{private}d, W:%{public}d, H:%{public}d, "
428 "TX:%{private}.2f, TY:%{private}.2f, TDX:%{private}d, TDY:%{private}d, "
429 "ToolWX:%{private}d, ToolWY:%{private}d, ToolW:%{public}d, ToolH:%{public}d, "
430 "P:%{public}.2f, ToolType:%{public}d, LA:%{public}d, SA:%{public}d, "
431 "RawDx:%{private}d, RawDy:%{private}d, RawDisplayX:%{private}d, RawDisplayY:%{private}d, "
432 "T:%{public}d, DXP:%{private}f, DYP:%{private}f, WXP:%{private}f, WYP:%{private}f",
433 pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(),
434 item.GetDisplayY(), item.GetWindowX(), item.GetWindowY(), item.GetWidth(), item.GetHeight(),
435 item.GetTiltX(), item.GetTiltY(), item.GetToolDisplayX(), item.GetToolDisplayY(),
436 item.GetToolWindowX(), item.GetToolWindowY(), item.GetToolWidth(), item.GetToolHeight(),
437 item.GetPressure(), item.GetToolType(), item.GetLongAxis(), item.GetShortAxis(),
438 item.GetRawDx(), item.GetRawDy(), item.GetRawDisplayX(), item.GetRawDisplayY(),
439 item.GetTwist(), item.GetDisplayXPos(), item.GetDisplayYPos(),
440 item.GetWindowXPos(), item.GetWindowYPos());
441 }
442 }
443 }
444 std::vector<int32_t> pressedKeys = event->GetPressedKeys();
445 std::vector<int32_t>::const_iterator cItr = pressedKeys.cbegin();
446 if (cItr != pressedKeys.cend()) {
447 std::string tmpStr = "Pressed keyCode: [" + std::to_string(*(cItr++));
448 for (; cItr != pressedKeys.cend(); ++cItr) {
449 tmpStr += (", " + std::to_string(*cItr));
450 }
451 if (IsBetaVersion()) {
452 if (!event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
453 MMI_HILOG_HEADER(LOG_DEBUG, lh, "%{private}s]", tmpStr.c_str());
454 }
455 }
456 }
457 }
458 };
459
PrintEventData(std::shared_ptr<T> event,int32_t actionType,int32_t itemNum,const LogHeader & lh)460 template <class T> void EventLogHelper::PrintEventData(std::shared_ptr<T> event, int32_t actionType, int32_t itemNum,
461 const LogHeader &lh)
462 {
463 CHKPV(event);
464 PrintInfoLog(event, lh);
465 if (HiLogIsLoggable(lh.domain, lh.tag, LOG_DEBUG)) {
466 static int64_t nowTimeUSec = 0;
467 static int32_t dropped = 0;
468 if (event->GetAction() == EVENT_TYPE_POINTER) {
469 if ((actionType == POINTER_ACTION_MOVE) && (event->GetActionTime() - nowTimeUSec <= TIMEOUT)) {
470 ++dropped;
471 return;
472 }
473 if (actionType == POINTER_ACTION_UP && itemNum == FINAL_FINGER) {
474 MMI_HILOG_HEADER(LOG_DEBUG, lh, "This touch process discards %{public}d high frequent events", dropped);
475 dropped = 0;
476 }
477 nowTimeUSec = event->GetActionTime();
478 }
479 EventLogHelper::Print(event, lh);
480 }
481 }
482
PrintEventData(std::shared_ptr<T> event,const LogHeader & lh)483 template <class T> void EventLogHelper::PrintEventData(std::shared_ptr<T> event, const LogHeader &lh)
484 {
485 CHKPV(event);
486 PrintInfoLog(event, lh);
487 if (HiLogIsLoggable(lh.domain, lh.tag, LOG_DEBUG) ||
488 (event->GetAction() == InputEvent::EVENT_TYPE_KEY)) {
489 EventLogHelper::Print(event, lh);
490 }
491 }
492 } // namespace MMI
493 } // namespace OHOS
494 #endif // EVENT_LOG_HELPER_H
495