diff --git a/interfaces/innerkits/native/include/power_state_machine_info.h b/interfaces/innerkits/native/include/power_state_machine_info.h index 720cf8c513616002114b56456ef35e8c7325c1e2..184b525ab6ea5361660b8d792ba9db00830cd187 100644 --- a/interfaces/innerkits/native/include/power_state_machine_info.h +++ b/interfaces/innerkits/native/include/power_state_machine_info.h @@ -102,7 +102,10 @@ enum class WakeupDeviceType : uint32_t { WAKEUP_DEVICE_WAKE_MOTION = 7, WAKEUP_DEVICE_HDMI = 8, WAKEUP_DEVICE_LID = 9, - WAKEUP_DEVICE_MAX = WAKEUP_DEVICE_LID, + WAKEUP_DEVICE_DOUBLE_CLICK = 10, + WAKEUP_DEVICE_KEYBOARD = 11, + WAKEUP_DEVICE_MOUSE = 12, + WAKEUP_DEVICE_MAX = WAKEUP_DEVICE_MOUSE, }; // SuspendDeviceType list diff --git a/services/native/include/power_mgr_service.h b/services/native/include/power_mgr_service.h index 062a3933e3e2c27715c3b2ff87fc8b50f4e30920..0a7f4fd3b32dd5b8473eaac8169c8b9af0adfb8d 100644 --- a/services/native/include/power_mgr_service.h +++ b/services/native/include/power_mgr_service.h @@ -81,7 +81,7 @@ public: void HandleShutdownRequest(); void HandleKeyEvent(int32_t keyCode); - void HandlePointEvent(); + void HandlePointEvent(int32_t type); void KeyMonitorInit(); std::shared_ptr GetHandler() const { diff --git a/services/native/src/power_mgr_service.cpp b/services/native/src/power_mgr_service.cpp index c1821760bb85fb3e2c9882e0b694b5bf0ed10729..26c1fd36051cb777a3263d3978f92493a1b0b1e2 100644 --- a/services/native/src/power_mgr_service.cpp +++ b/services/native/src/power_mgr_service.cpp @@ -130,7 +130,11 @@ class InputCallback : public IInputEventConsumer { void InputCallback::OnInputEvent(std::shared_ptr keyEvent) const { POWER_HILOGE(MODULE_SERVICE, "OnInputEvent keyEvent"); - // Do noting. It's done by AddMonitor callback + auto pms = DelayedSpSingleton::GetInstance(); + if (pms == nullptr) { + return; + } + pms->HandleKeyEvent(keyEvent->GetKeyCode()); } void InputCallback::OnInputEvent(std::shared_ptr pointerEvent) const @@ -140,7 +144,8 @@ void InputCallback::OnInputEvent(std::shared_ptr pointerEvent) con if (pms == nullptr) { return; } - pms->HandlePointEvent(); + int32_t type = pointerEvent->GetSourceType(); + pms->HandlePointEvent(type); } void InputCallback::OnInputEvent(std::shared_ptr axisEvent) const @@ -150,7 +155,6 @@ void InputCallback::OnInputEvent(std::shared_ptr axisEvent) const if (pms == nullptr) { return; } - pms->HandlePointEvent(); } void PowerMgrService::KeyMonitorInit() @@ -166,9 +170,10 @@ void PowerMgrService::KeyMonitorInit() int32_t id = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [this](std::shared_ptr keyEvent) { POWER_HILOGI(MODULE_SERVICE, "Receive long press powerkey"); - handler_->RemoveEvent(PowermsEventHandler::SHUTDOWN_REQUEST_MSG); + handler_->SendEvent(PowermsEventHandler::SHUTDOWN_REQUEST_MSG); }); if (id < 0) { + POWER_HILOGI(MODULE_SERVICE, "SubscribeKeyEvent failed: %{public}d", id); handler_->SendEvent(PowermsEventHandler::INIT_KEY_MONITOR_MSG, 0, INIT_KEY_MONITOR_DELAY); return; } @@ -199,6 +204,18 @@ void PowerMgrService::KeyMonitorInit() this->HandlePowerKeyUp(); }); + keyOption.reset(); + keyOption = std::make_shared(); + keyOption->SetPreKeys(preKeys); + keyOption->SetFinalKey(OHOS::MMI::KeyEvent::KEYCODE_F1); + keyOption->SetFinalKeyDown(true); + keyOption->SetFinalKeyDownDuration(0); + id = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, + [this](std::shared_ptr keyEvent) { + POWER_HILOGI(MODULE_SERVICE, "Receive double click"); + this->HandleKeyEvent(keyEvent->GetKeyCode()); + }); + InputManager::GetInstance()->AddMonitor([this](std::shared_ptr event) { this->HandleKeyEvent(event->GetKeyCode()); }); @@ -263,21 +280,33 @@ void PowerMgrService::HandleKeyEvent(int32_t keyCode) if (IsScreenOn()) { this->RefreshActivity(now, UserActivityType::USER_ACTIVITY_TYPE_BUTTON, false); } else { - if (keyCode >= KeyEvent::KEYCODE_0 + if (keyCode == KeyEvent::KEYCODE_F1) { + POWER_HILOGI(MODULE_SERVICE, "wakeup by double click"); + std::string reason = "double click"; + reason.append(std::to_string(keyCode)); + this->WakeupDevice(now, WakeupDeviceType::WAKEUP_DEVICE_DOUBLE_CLICK, reason); + } else if (keyCode >= KeyEvent::KEYCODE_0 && keyCode <= KeyEvent::KEYCODE_NUMPAD_RIGHT_PAREN) { POWER_HILOGI(MODULE_SERVICE, "wakeup by keyboard"); std::string reason = "keyboard:"; reason.append(std::to_string(keyCode)); - this->WakeupDevice(now, WakeupDeviceType::WAKEUP_DEVICE_POWER_BUTTON, reason); + this->WakeupDevice(now, WakeupDeviceType::WAKEUP_DEVICE_KEYBOARD, reason); } } } -void PowerMgrService::HandlePointEvent() +void PowerMgrService::HandlePointEvent(int32_t type) { - POWER_HILOGI(MODULE_SERVICE, "HandlePointEvent"); + POWER_HILOGI(MODULE_SERVICE, "HandlePointEvent: %{public}d", type); int64_t now = static_cast(time(0)); - this->RefreshActivity(now, UserActivityType::USER_ACTIVITY_TYPE_TOUCH, false); + if (this->IsScreenOn()) { + this->RefreshActivity(now, UserActivityType::USER_ACTIVITY_TYPE_TOUCH, false); + } else { + if (type == PointerEvent::SOURCE_TYPE_MOUSE) { + std::string reason = "mouse click"; + this->WakeupDevice(now, WakeupDeviceType::WAKEUP_DEVICE_MOUSE, reason); + } + } } void PowerMgrService::HandlePowerKeyTimeout()