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:%{public}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, "%{public}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(), event->GetActionStartTime(),
220 InputEvent::EventTypeToString(event->GetEventType()), event->GetFlag(),
221 KeyEvent::ActionToString(event->GetKeyAction()),
222 event->GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY),
223 event->GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY),
224 event->GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY), event->GetId(), eventItems.size());
225 }
226 }
227 for (const auto &item : eventItems) {
228 if (!IsBetaVersion()) {
229 MMI_HILOG_HEADER(LOG_INFO, lh, "DN:%{public}d, IP:%{public}d",
230 item.GetDeviceId(), item.IsPressed());
231 } else {
232 if (event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
233 MMI_HILOG_HEADER(LOG_INFO, lh, "DN:%{public}d, IP:%{public}d",
234 item.GetDeviceId(), item.IsPressed());
235 } else {
236 MMI_HILOG_HEADER(LOG_INFO, lh, "DN:%{public}d, KC:%{public}d, DT:%{public}" PRId64 ","
237 "IP:%{public}d, GU:%{public}d", item.GetDeviceId(), item.GetKeyCode(), item.GetDownTime(),
238 item.IsPressed(), item.GetUnicode());
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, MF:%{public}d, "
287 "WI:%{public}d, OPI:%{public}d, SI:%{public}s",
288 pointerId, item.IsPressed(), item.GetPressure(), item.GetMoveFlag(), 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, MF:%{public}d, LA:%{public}d, SA:%{public}d, WI:%{public}d, "
294 "DXP:%f, DYP:%f, WXP:%f, WYP:%f, OPI:%{public}d",
295 pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(), item.GetDisplayY(),
296 item.GetPressure(), item.GetMoveFlag(), item.GetLongAxis(), item.GetShortAxis(),
297 item.GetTargetWindowId(), item.GetDisplayXPos(), item.GetDisplayYPos(), item.GetWindowXPos(),
298 item.GetWindowYPos(), item.GetOriginPointerId());
299 } else {
300 MMI_HILOG_HEADER(LOG_INFO, lh, "PI:%{public}d, DT:%{public}" PRId64 ", IP:%{public}d, "
301 "DX:%{public}d, DY:%{public}d, P:%{public}.2f, MF:%{public}d, LA:%{public}d, SA:%{public}d, "
302 "WI:%{public}d, DXP:%{public}f, DYP:%{public}f, WXP:%{public}f, WYP:%{public}f, "
303 "OPI:%{public}d, SI:%{public}s",
304 pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(), item.GetDisplayY(),
305 item.GetPressure(), item.GetMoveFlag(), item.GetLongAxis(), item.GetShortAxis(),
306 item.GetTargetWindowId(), item.GetDisplayXPos(), item.GetDisplayYPos(), item.GetWindowXPos(),
307 item.GetWindowYPos(), item.GetOriginPointerId(), isSimulate.c_str());
308 }
309 }
310 }
311 std::vector<int32_t> pressedKeys = event->GetPressedKeys();
312 std::vector<int32_t>::const_iterator cItr = pressedKeys.cbegin();
313 if (cItr != pressedKeys.cend()) {
314 std::string tmpStr = "Pressed keyCode: [" + std::to_string(*(cItr++));
315 for (; cItr != pressedKeys.cend(); ++cItr) {
316 tmpStr += ("," + std::to_string(*cItr));
317 }
318 if (IsBetaVersion()) {
319 if (!event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
320 MMI_HILOG_HEADER(LOG_INFO, lh, "%{public}s]", tmpStr.c_str());
321 }
322 }
323 }
324 }
325
Print(const std::shared_ptr<PointerEvent> event, const LogHeader &lh)326 static void Print(const std::shared_ptr<PointerEvent> event, const LogHeader &lh)
327 {
328 PrintDebugDict();
329 std::vector<int32_t> pointerIds{ event->GetPointerIds() };
330 std::string str;
331 std::vector<uint8_t> buffer = event->GetBuffer();
332 for (const auto &buff : buffer) {
333 str += std::to_string(buff);
334 }
335 if (!IsBetaVersion()) {
336 MMI_HILOG_HEADER(LOG_DEBUG, lh, "ET:%{public}s, SIT:%{public}" PRIu64 ", A:%{public}d, "
337 ", F:%{public}d, PA:%{public}s, ST:%{public}s, BI:%{public}d, PI:%{public}d, PC:%{public}zu, "
338 "EN:%{public}d, BC:%{public}zu, ME:%{public}d",
339 InputEvent::EventTypeToString(event->GetEventType()),
340 event->GetSensorInputTime(), event->GetAction(), event->GetFlag(),
341 event->DumpPointerAction(), event->DumpSourceType(), event->GetButtonId(), event->GetPointerId(),
342 pointerIds.size(), event->GetId(), buffer.size(), event->IsMarkEnabled());
343 } else {
344 MMI_HILOG_HEADER(LOG_DEBUG, lh, "ET:%{public}s, AT:%{public}" PRId64 ", SIT:%{public}" PRId64
345 ",A:%{public}d, AST:%{public}" PRId64 ", F:%{public}d, PA:%{public}s, ST:%{public}s, BI:%{public}d, "
346 "VAV:%{public}.5f, HAV:%{public}.5f, PAV:%{public}.5f, PAV:%{public}.5f, XAV:%{public}.5f,"
347 "YAV:%{public}.5f, ZAV:%{public}.5f, RZAV:%{public}.5f, GAV:%{public}.5f, BAV:%{public}.5f, "
348 "HXAV:%{public}.5f, HYAV:%{public}.5f, TAV:%{public}.5f,PI:%{public}d, PC:%{public}zu, EN:%{public}d, "
349 "BC:%{public}zu, B:%{public}s, ME:%{public}d",
350 InputEvent::EventTypeToString(event->GetEventType()), event->GetActionTime(),
351 event->GetSensorInputTime(), event->GetAction(), event->GetActionStartTime(), event->GetFlag(),
352 event->DumpPointerAction(), event->DumpSourceType(), event->GetButtonId(),
353 event->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL),
354 event->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL),
355 event->GetAxisValue(PointerEvent::AXIS_TYPE_PINCH), event->GetAxisValue(PointerEvent::AXIS_TYPE_ROTATE),
356 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_X), event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_Y),
357 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_Z), event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_RZ),
358 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_GAS),
359 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_BRAKE),
360 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_HAT0X),
361 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_HAT0Y),
362 event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_THROTTLE), event->GetPointerId(), pointerIds.size(),
363 event->GetId(), buffer.size(), str.c_str(), event->IsMarkEnabled());
364 }
365
366 for (const auto &pointerId : pointerIds) {
367 PointerEvent::PointerItem item;
368 if (!event->GetPointerItem(pointerId, item)) {
369 MMI_HILOG_HEADER(LOG_ERROR, lh, "Invalid pointer:%{public}d", pointerId);
370 return;
371 }
372 if (!IsBetaVersion()) {
373 MMI_HILOG_HEADER(LOG_DEBUG, lh,
374 "PI:%{public}d, IP:%{public}d, P:%{public}.2f, MF:%{public}d, ToolType:%{public}d",
375 pointerId, item.IsPressed(), item.GetPressure(), item.GetMoveFlag(), item.GetToolType());
376 } else {
377 if (event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
378 MMI_HILOG_HEADER(LOG_DEBUG, lh,"PI:%{public}d, DT:%{public}" PRId64 ", IP:%{public}d, DX:%d, DY:%d"
379 ", WX:%d, WY:%d, W:%{public}d, H:%{public}d, TX:%.2f, TY:%.2f, TDX:%d, TDY:%d, ToolWX:%d, "
380 "ToolWY:%d, ToolW:%{public}d, ToolH:%{public}d, P:%{public}.2f, MF:%{public}d, "
381 "ToolType:%{public}d, LA:%{public}d, SA:%{public}d, RawDx:%d, RawDy:%d, RawDisplayX:%d, "
382 "RawDisplayY:%d",
383 pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(), item.GetDisplayY(),
384 item.GetWindowX(), item.GetWindowY(), item.GetWidth(), item.GetHeight(), item.GetTiltX(),
385 item.GetTiltY(), item.GetToolDisplayX(), item.GetToolDisplayY(), item.GetToolWindowX(),
386 item.GetToolWindowY(), item.GetToolWidth(), item.GetToolHeight(), item.GetPressure(),
387 item.GetMoveFlag(), item.GetToolType(), item.GetLongAxis(), item.GetShortAxis(),
388 item.GetRawDx(), item.GetRawDy(), item.GetRawDisplayX(), item.GetRawDisplayY());
389 } else {
390 MMI_HILOG_HEADER(LOG_DEBUG, lh,"PI:%{public}d, DT:%{public}" PRId64 ", IP:%{public}d, "
391 "DX:%{public}d, DY:%{public}d, WX:%{public}d, WY:%{public}d, W:%{public}d, H:%{public}d, "
392 "TX:%{public}.2f, TY:%{public}.2f, TDX:%{public}d, TDY:%{public}d, ToolWX:%{public}d, "
393 "ToolWY:%{public}d, ToolW:%{public}d, ToolH:%{public}d, P:%{public}.2f, MF:%{public}d, "
394 "ToolType:%{public}d, LA:%{public}d, SA:%{public}d, RawDx:%{public}d, RawDy:%{public}d"
395 "RawDisplayX:%{public}d, RawDisplayY:%{public}d",
396 pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(), item.GetDisplayY(),
397 item.GetWindowX(), item.GetWindowY(), item.GetWidth(), item.GetHeight(), item.GetTiltX(),
398 item.GetTiltY(), item.GetToolDisplayX(), item.GetToolDisplayY(), item.GetToolWindowX(),
399 item.GetToolWindowY(), item.GetToolWidth(), item.GetToolHeight(), item.GetPressure(),
400 item.GetMoveFlag(), item.GetToolType(), item.GetLongAxis(), item.GetShortAxis(),
401 item.GetRawDx(), item.GetRawDy(), item.GetRawDisplayX(), item.GetRawDisplayY());
402 }
403 }
404 if (!IsBetaVersion()) {
405 MMI_HILOG_HEADER(LOG_DEBUG, lh,
406 "PI:%{public}d" ", IP:%{public}d, P:%{public}.2f, MF:%{public}d, ToolType:%{public}d",
407 pointerId, item.IsPressed(), item.GetPressure(), item.GetMoveFlag(), item.GetToolType());
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",
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());
423 } else {
424 MMI_HILOG_HEADER(LOG_DEBUG, lh,
425 "PI:%{public}d, DT:%{public}" PRId64 ", IP:%{public}d, DX:%{public}d, DY:%{public}d, "
426 "WX:%{public}d, WY:%{public}d, W:%{public}d, H:%{public}d, TX:%{public}.2f, TY:%{public}.2f, "
427 "TDX:%{public}d, TDY:%{public}d, ToolWX:%{public}d, ToolWY:%{public}d, ToolW:%{public}d, "
428 "ToolH:%{public}d, P:%{public}.2f, ToolType:%{public}d, LA:%{public}d, SA:%{public}d, "
429 "RawDx:%{public}d, RawDy:%{public}d, RawDisplayX:%{public}d, RawDisplayY:%{public}d",
430 pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(),
431 item.GetDisplayY(), item.GetWindowX(), item.GetWindowY(), item.GetWidth(), item.GetHeight(),
432 item.GetTiltX(), item.GetTiltY(), item.GetToolDisplayX(), item.GetToolDisplayY(),
433 item.GetToolWindowX(), item.GetToolWindowY(), item.GetToolWidth(), item.GetToolHeight(),
434 item.GetPressure(), item.GetToolType(), item.GetLongAxis(), item.GetShortAxis(),
435 item.GetRawDx(), item.GetRawDy(), item.GetRawDisplayX(), item.GetRawDisplayY());
436 }
437 }
438 }
439 std::vector<int32_t> pressedKeys = event->GetPressedKeys();
440 std::vector<int32_t>::const_iterator cItr = pressedKeys.cbegin();
441 if (cItr != pressedKeys.cend()) {
442 std::string tmpStr = "Pressed keyCode: [" + std::to_string(*(cItr++));
443 for (; cItr != pressedKeys.cend(); ++cItr) {
444 tmpStr += (", " + std::to_string(*cItr));
445 }
446 if (IsBetaVersion()) {
447 if (!event->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) {
448 MMI_HILOG_HEADER(LOG_DEBUG, lh, "%{public}s]", tmpStr.c_str());
449 }
450 }
451 }
452 }
453 };
454
PrintEventData(std::shared_ptr<T> event, int32_t actionType, int32_t itemNum, const LogHeader &lh)455 template <class T> void EventLogHelper::PrintEventData(std::shared_ptr<T> event, int32_t actionType, int32_t itemNum,
456 const LogHeader &lh)
457 {
458 CHKPV(event);
459 PrintInfoLog(event, lh);
460 if (HiLogIsLoggable(lh.domain, lh.tag, LOG_DEBUG)) {
461 static int64_t nowTimeUSec = 0;
462 static int32_t dropped = 0;
463 if (event->GetAction() == EVENT_TYPE_POINTER) {
464 if ((actionType == POINTER_ACTION_MOVE) && (event->GetActionTime() - nowTimeUSec <= TIMEOUT)) {
465 ++dropped;
466 return;
467 }
468 if (actionType == POINTER_ACTION_UP && itemNum == FINAL_FINGER) {
469 MMI_HILOG_HEADER(LOG_DEBUG, lh, "This touch process discards %{public}d high frequent events", dropped);
470 dropped = 0;
471 }
472 nowTimeUSec = event->GetActionTime();
473 }
474 EventLogHelper::Print(event, lh);
475 }
476 }
477
PrintEventData(std::shared_ptr<T> event, const LogHeader &lh)478 template <class T> void EventLogHelper::PrintEventData(std::shared_ptr<T> event, const LogHeader &lh)
479 {
480 CHKPV(event);
481 PrintInfoLog(event, lh);
482 if (HiLogIsLoggable(lh.domain, lh.tag, LOG_DEBUG) ||
483 (event->GetAction() == InputEvent::EVENT_TYPE_KEY)) {
484 EventLogHelper::Print(event, lh);
485 }
486 }
487 } // namespace MMI
488 } // namespace OHOS
489 #endif // EVENT_LOG_HELPER_H
490