diff --git a/frameworks/napi/input_consumer/include/js_register_module.h b/frameworks/napi/input_consumer/include/js_register_module.h index 147dab007f974980f06ae7e365ee0d9a57bc7d23..4f842f42bc399211680a2a096f88cbe0d86d98d1 100644 --- a/frameworks/napi/input_consumer/include/js_register_module.h +++ b/frameworks/napi/input_consumer/include/js_register_module.h @@ -54,6 +54,16 @@ struct KeyEventMonitorInfo { napi_ref callback[1] {}; int32_t subscribeId { 0 }; std::shared_ptr keyOption { nullptr }; + bool valid { true }; + std::mutex refLock; + void SetValid(bool flag) { + std::lock_guard lock(refLock); + valid = flag; + } + bool IsValid() { + std::lock_guard lock(refLock); + return valid; + } }; typedef std::map> Callbacks; diff --git a/frameworks/napi/input_consumer/src/js_register_module.cpp b/frameworks/napi/input_consumer/src/js_register_module.cpp index 9daef7ac04ae888f04463a8545b2748fa1a1e360..30cca26281948c93cf7b37357519904ee0ee7496 100644 --- a/frameworks/napi/input_consumer/src/js_register_module.cpp +++ b/frameworks/napi/input_consumer/src/js_register_module.cpp @@ -238,11 +238,22 @@ static napi_value JsOn(napi_env env, napi_callback_info info) CALL_DEBUG_ENTER; size_t argc = 3; napi_value argv[3] = { 0 }; - CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + napi_value thisArg = nullptr; + CHKRP(napi_get_cb_info(env, info, &argc, argv, &thisArg, nullptr), GET_CB_INFO); if (argc < 3) { THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "parameter number error"); return nullptr; } + if (thisArg == nullptr) { + MMI_HILOGE("%{public}s, This argument is nullptr.", __func__); + return nullptr; + } + napi_valuetype valueOfThis = napi_undefined; + CHKRP(napi_typeof(env, thisArg, &valueOfThis), TYPEOF); + if (valueOfThis == napi_undefined) { + MMI_HILOGE("%{public}s, Wrong value of this.", __func__); + return nullptr; + } KeyEventMonitorInfo *event = new (std::nothrow) KeyEventMonitorInfo { .env = env, .asyncWork = nullptr, @@ -282,6 +293,14 @@ static napi_value JsOn(napi_env env, napi_callback_info info) MMI_HILOGE("AddEventCallback failed"); return nullptr; } + std::shared_ptr* cbInfo = new std::shared_ptr(event); + napi_wrap(env, thisArg, (void*)cbInfo, [](napi_env env, void* data, void* hint) { + std::shared_ptr* cbInfo = static_cast*>(data); + if (cbInfo != nullptr && *cbInfo != nullptr) { + (*cbInfo)->SetValid(false); + delete cbInfo; + } + }, nullptr, nullptr); return nullptr; } diff --git a/frameworks/napi/input_consumer/src/js_register_util.cpp b/frameworks/napi/input_consumer/src/js_register_util.cpp index d13d7ca269bcb54a0c96c49b0b9cda0acab04680..75bd32a1baf7a9a151be32ea956ea4622725aa9c 100644 --- a/frameworks/napi/input_consumer/src/js_register_util.cpp +++ b/frameworks/napi/input_consumer/src/js_register_util.cpp @@ -311,6 +311,10 @@ void EmitAsyncCallbackWork(KeyEventMonitorInfo *reportEvent) { CALL_DEBUG_ENTER; CHKPV(reportEvent); + if (!reportEvent->IsValid()) { + MMI_HILOGE("%{public}s, module exported object is invalid.", __func__); + return; + } uv_loop_s *loop = nullptr; CHKRV(napi_get_uv_event_loop(reportEvent->env, &loop), GET_UV_EVENT_LOOP); uv_work_t *work = new (std::nothrow) uv_work_t; diff --git a/frameworks/proxy/event_handler/include/anr_handler.h b/frameworks/proxy/event_handler/include/anr_handler.h index 27029e419951e51498f1f036f79b2444cbfa0510..db999191e42954023ddc9f25c94777124559b312 100644 --- a/frameworks/proxy/event_handler/include/anr_handler.h +++ b/frameworks/proxy/event_handler/include/anr_handler.h @@ -31,6 +31,7 @@ public: void SetLastProcessedEventId(int32_t eventType, int32_t eventId, uint64_t actionTime); void MarkProcessed(int32_t eventType); + void ResetAnrArray(); std::mutex anrMtx_; private: @@ -50,4 +51,4 @@ private: #define ANRHdl ::OHOS::DelayedSingleton::GetInstance() } // namespace MMI } // namespace OHOS -#endif // ANR_HANDLER_H \ No newline at end of file +#endif // ANR_HANDLER_H diff --git a/frameworks/proxy/event_handler/src/anr_handler.cpp b/frameworks/proxy/event_handler/src/anr_handler.cpp index 4c6a94de4ebaddd8aa578cbe30c10111112a988c..ee1163130d12d96598f7c8ccb844fd7720b36385 100644 --- a/frameworks/proxy/event_handler/src/anr_handler.cpp +++ b/frameworks/proxy/event_handler/src/anr_handler.cpp @@ -123,5 +123,13 @@ void ANRHandler::SendEvent(int32_t eventType, int64_t delayTime) MMI_HILOGE("Send dispatch event failed"); } } + +void ANRHandler::ResetAnrArray() { + for(int i = 0; i < ANR_EVENT_TYPE_NUM; i++) { + event_[i].sendStatus = false; + event_[i].lastEventId = -1; + event_[i].lastReportId = -1; + } +} } // namespace MMI -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/frameworks/proxy/event_handler/src/client_msg_handler.cpp b/frameworks/proxy/event_handler/src/client_msg_handler.cpp index 97a74d5a9bd4e009800fcdd6cf3dc494ad398a54..39f605ba92bd8d01c3f6b7c1934dbb4866442264 100644 --- a/frameworks/proxy/event_handler/src/client_msg_handler.cpp +++ b/frameworks/proxy/event_handler/src/client_msg_handler.cpp @@ -182,12 +182,21 @@ int32_t ClientMsgHandler::OnSubscribeKeyEventCallback(const UDSClient &client, N MMI_HILOGE("Packet read fd failed"); return PACKET_READ_FAIL; } - MMI_HILOGD("Subscribe:%{public}d,Fd:%{public}d,KeyEvent:%{public}d," + if (keyEvent->GetKeyCode() == KEYCODE_POWER) { + MMI_HILOGI("Subscribe:%{public}d,Fd:%{public}d,KeyEvent:%{public}d," "KeyCode:%{public}d,ActionTime:%{public}" PRId64 ",ActionStartTime:%{public}" PRId64 "," "Action:%{public}d,KeyAction:%{public}d,EventType:%{public}d,Flag:%{public}u", subscribeId, fd, keyEvent->GetId(), keyEvent->GetKeyCode(), keyEvent->GetActionTime(), keyEvent->GetActionStartTime(), keyEvent->GetAction(), keyEvent->GetKeyAction(), keyEvent->GetEventType(), keyEvent->GetFlag()); + } else { + MMI_HILOGD("Subscribe:%{public}d,Fd:%{public}d,KeyEvent:%{public}d," + "KeyCode:%{public}d,ActionTime:%{public}" PRId64 ",ActionStartTime:%{public}" PRId64 "," + "Action:%{public}d,KeyAction:%{public}d,EventType:%{public}d,Flag:%{public}u", + subscribeId, fd, keyEvent->GetId(), keyEvent->GetKeyCode(), keyEvent->GetActionTime(), + keyEvent->GetActionStartTime(), keyEvent->GetAction(), keyEvent->GetKeyAction(), + keyEvent->GetEventType(), keyEvent->GetFlag()); + } BytraceAdapter::StartBytrace(keyEvent, BytraceAdapter::TRACE_START, BytraceAdapter::KEY_SUBSCRIBE_EVENT); return KeyEventInputSubscribeMgr.OnSubscribeKeyEventCallback(keyEvent, subscribeId); } diff --git a/frameworks/proxy/events/include/event_log_helper.h b/frameworks/proxy/events/include/event_log_helper.h index ab27d0318fc115e4f85b8a9735b924e5e0bb06bc..ee5221ee503f3a8f486081b84fff8376f239c7d9 100644 --- a/frameworks/proxy/events/include/event_log_helper.h +++ b/frameworks/proxy/events/include/event_log_helper.h @@ -38,7 +38,7 @@ private: static void Print(const std::shared_ptr event) { std::vector eventItems { event->GetKeyItems() }; - MMI_HILOGD("KeyCode:%{public}d,KeyIntention:%{public}d,ActionTime:%{public}" PRId64 ",ActionStartTime:%{public}" PRId64 + MMI_HILOGI("KeyCode:%{public}d,KeyIntention:%{public}d,ActionTime:%{public}" PRId64 ",ActionStartTime:%{public}" PRId64 ",EventType:%{public}s,Flag:%{public}d,KeyAction:%{public}s,NumLock:%{public}d," "CapsLock:%{public}d,ScrollLock:%{public}d,EventNumber:%{public}d,keyItemsCount:%{public}zu", event->GetKeyCode(), event->GetKeyIntention(), event->GetActionTime(), event->GetActionStartTime(), @@ -48,7 +48,7 @@ private: event->GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY), event->GetId(), eventItems.size()); for (const auto &item : eventItems) { - MMI_HILOGD("DeviceNumber:%{public}d,KeyCode:%{public}d,DownTime:%{public}" PRId64 ",IsPressed:%{public}d," + MMI_HILOGI("DeviceNumber:%{public}d,KeyCode:%{public}d,DownTime:%{public}" PRId64 ",IsPressed:%{public}d," "GetUnicode:%{public}d", item.GetDeviceId(), item.GetKeyCode(), item.GetDownTime(), item.IsPressed(), item.GetUnicode()); } @@ -59,7 +59,7 @@ private: for (; cItr != pressedKeys.cend(); ++cItr) { tmpStr += ("," + std::to_string(*cItr)); } - MMI_HILOGD("%{public}s]", tmpStr.c_str()); + MMI_HILOGI("%{public}s]", tmpStr.c_str()); } } @@ -153,7 +153,8 @@ template void EventLogHelper::PrintEventData(std::shared_ptr event) { CHKPV(event); - if (HiLogIsLoggable(OHOS::MMI::MMI_LOG_DOMAIN, LABEL.tag, LOG_DEBUG)) { + if (HiLogIsLoggable(OHOS::MMI::MMI_LOG_DOMAIN, LABEL.tag, LOG_DEBUG) || + (event->GetAction() == EVENT_TYPE_KEY && event->GetKeyCode() == KEYCODE_POWER)){ EventLogHelper::Print(event); } } diff --git a/frameworks/proxy/module_loader/src/mmi_client.cpp b/frameworks/proxy/module_loader/src/mmi_client.cpp index 2dc50988252cd211e4f23ebb67ea2fcc72927a18..d28f723898c16ee0a270ad8c8c622051ee8ceb15 100755 --- a/frameworks/proxy/module_loader/src/mmi_client.cpp +++ b/frameworks/proxy/module_loader/src/mmi_client.cpp @@ -17,9 +17,11 @@ #include #include +#include "anr_handler.h" #include "mmi_log.h" #include "proto.h" #include "util.h" +#include "anr_handler.h" #include "input_manager_impl.h" #include "mmi_fd_listener.h" @@ -223,6 +225,7 @@ void MMIClient::OnDisconnected() MMI_HILOGI("Disconnected from server, fd:%{public}d", fd_); isConnected_ = false; isListening_ = false; + ANRHdl->ResetAnrArray(); if (funDisconnected_) { funDisconnected_(*this); } diff --git a/service/event_dispatch/include/event_dispatch_handler.h b/service/event_dispatch/include/event_dispatch_handler.h index c79ad2ab2d67c44f6315933e694a32193d7018ae..b6e53142fda4edeae1d067423b2d47e6c1d1f8d6 100644 --- a/service/event_dispatch/include/event_dispatch_handler.h +++ b/service/event_dispatch/include/event_dispatch_handler.h @@ -63,6 +63,8 @@ private: std::mutex lock_; std::vector dinputSimulateEvent_; #endif // OHOS_BUILD_ENABLE_COOPERATE + int32_t eventTime_ { 0 }; + int32_t currentTime_ { 0 }; }; } // namespace MMI } // namespace OHOS diff --git a/service/event_dispatch/src/event_dispatch_handler.cpp b/service/event_dispatch/src/event_dispatch_handler.cpp index 250794d45e45ee01c67754e68b4158508912f2ae..82514cadc8cbbf524f556a11fc44bd16b7e1058c 100644 --- a/service/event_dispatch/src/event_dispatch_handler.cpp +++ b/service/event_dispatch/src/event_dispatch_handler.cpp @@ -41,6 +41,7 @@ namespace { #if defined(OHOS_BUILD_ENABLE_KEYBOARD) || defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "EventDispatchHandler" }; #endif // OHOS_BUILD_ENABLE_KEYBOARD || OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH +constexpr int32_t INTERVAL_TIME = 3000; // log time interval is 3 seconds. } // namespace EventDispatchHandler::EventDispatchHandler() @@ -83,7 +84,9 @@ void EventDispatchHandler::HandlePointerEventInner(const std::shared_ptrGetClientFd(point); - if (fd < 0) { + currentTime_ = point->GetActionTime(); + if (fd < 0 && currentTime_ - eventTime_ > INTERVAL_TIME) { + eventTime_ = currentTime_; MMI_HILOGE("The fd less than 0, fd:%{public}d", fd); DfxHisysevent::OnUpdateTargetPointer(point, fd, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT); return; @@ -136,7 +139,9 @@ int32_t EventDispatchHandler::DispatchKeyEventPid(UDSServer& udsServer, std::sha CALL_DEBUG_ENTER; CHKPR(key, PARAM_INPUT_INVALID); auto fd = WinMgr->UpdateTarget(key); - if (fd < 0) { + currentTime_ = point->GetActionTime(); + if (fd < 0 && currentTime_ - eventTime_ > INTERVAL_TIME) { + eventTime_ = currentTime_; MMI_HILOGE("Invalid fd, fd:%{public}d", fd); DfxHisysevent::OnUpdateTargetKey(key, fd, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT); return RET_ERR;