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