From b55e1138d7bba3b7d09b2d7d0e8e38be11a49a9c Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Mon, 15 Apr 2024 10:17:09 +0800 Subject: [PATCH 1/2] RM007 Signed-off-by: mayunteng_1 --- frameworks/proxy/events/src/key_event.cpp | 1 + .../innerkits/event/include/key_event.h | 7 ++ service/BUILD.gn | 1 + .../src/display_event_monitor.cpp | 1 + service/event_handler/include/hos_key_event.h | 1 + .../src/key_event_value_transformation.cpp | 1 + .../key_command/include/key_command_handler.h | 3 +- .../key_command/include/stylus_key_handler.h | 49 ++++++++++ .../key_command/src/key_command_handler.cpp | 41 +++++++-- .../key_command/src/stylus_key_handler.cpp | 92 +++++++++++++++++++ 10 files changed, 187 insertions(+), 10 deletions(-) create mode 100644 service/key_command/include/stylus_key_handler.h create mode 100644 service/key_command/src/stylus_key_handler.cpp diff --git a/frameworks/proxy/events/src/key_event.cpp b/frameworks/proxy/events/src/key_event.cpp index e8d0a302ed..52aa30cdf6 100644 --- a/frameworks/proxy/events/src/key_event.cpp +++ b/frameworks/proxy/events/src/key_event.cpp @@ -781,6 +781,7 @@ const int32_t KeyEvent::KEYCODE_WLAN = 2844; const int32_t KeyEvent::KEYCODE_UWB = 2845; const int32_t KeyEvent::KEYCODE_WWAN_WIMAX = 2846; const int32_t KeyEvent::KEYCODE_RFKILL = 2847; +const int32_t KeyEvent::KEYCODE_STYLUS_SCREEN = 2849; const int32_t KeyEvent::KEYCODE_CHANNEL = 3001; const int32_t KeyEvent::KEYCODE_BTN_0 = 3100; const int32_t KeyEvent::KEYCODE_BTN_1 = 3101; diff --git a/interfaces/native/innerkits/event/include/key_event.h b/interfaces/native/innerkits/event/include/key_event.h index cf29996734..dff287f7eb 100644 --- a/interfaces/native/innerkits/event/include/key_event.h +++ b/interfaces/native/innerkits/event/include/key_event.h @@ -2837,6 +2837,13 @@ public: */ static const int32_t KEYCODE_LAUNCHER_MENU; + /** + * Stylus key + * + * @since 9 + */ + static const int32_t KEYCODE_STYLUS_SCREEN; + /** * Unknown key operation, which is usually used to indicate the initial invalid value. * diff --git a/service/BUILD.gn b/service/BUILD.gn index 19f389e2d9..1bd185f18f 100644 --- a/service/BUILD.gn +++ b/service/BUILD.gn @@ -147,6 +147,7 @@ ohos_shared_library("libmmi-server") { "key_command/src/key_command_handler.cpp", "key_command/src/setting_datashare.cpp", "key_command/src/setting_observer.cpp", + "key_command/src/stylus_key_handler.cpp", ] } } diff --git a/service/display_state_manager/src/display_event_monitor.cpp b/service/display_state_manager/src/display_event_monitor.cpp index 122d7525da..b3f04e3d64 100644 --- a/service/display_state_manager/src/display_event_monitor.cpp +++ b/service/display_state_manager/src/display_event_monitor.cpp @@ -47,6 +47,7 @@ public: } if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON) { MMI_HILOGD("display screen on"); + STYLUS_HANDLER->IsLaunchAbility(); if (FINGERSENSE_WRAPPER->enableFingersense_ != nullptr) { MMI_HILOGD("start enable fingersense"); FINGERSENSE_WRAPPER->enableFingersense_(); diff --git a/service/event_handler/include/hos_key_event.h b/service/event_handler/include/hos_key_event.h index bd13750046..b01b6ba5ed 100644 --- a/service/event_handler/include/hos_key_event.h +++ b/service/event_handler/include/hos_key_event.h @@ -1297,6 +1297,7 @@ enum HosKeyEventEnum { HOS_KEY_WWAN_WIMAX = 2846, HOS_KEY_RFKILL = 2847, HOS_KEY_F26 = 2848, + HOS_KEY_F27 = 2849, HOS_KEY_CHANNEL = 3001, HOS_KEY_BTN_0 = 3100, diff --git a/service/event_handler/src/key_event_value_transformation.cpp b/service/event_handler/src/key_event_value_transformation.cpp index 6f9bccec0e..f8bc301eb4 100644 --- a/service/event_handler/src/key_event_value_transformation.cpp +++ b/service/event_handler/src/key_event_value_transformation.cpp @@ -408,6 +408,7 @@ const std::multimap MAP_KEY_EVENT_VALUE_TR {247, {"KEY_RFKILL", 247, 2847, HOS_KEY_RFKILL}}, {248, {"KEY_MUTE", 248, 23, HOS_KEY_MUTE}}, {196, {"KEY_F26", 196, 2848, HOS_KEY_F26}}, + {197, {"KEY_F27", 197, 2849, HOS_KEY_F27}}, {363, {"KEY_CHANNEL", 363, 3001, HOS_KEY_CHANNEL}}, {256, {"KEY_BTN_0", 256, 3100, HOS_KEY_BTN_0}}, diff --git a/service/key_command/include/key_command_handler.h b/service/key_command/include/key_command_handler.h index 4bde15bc11..6090e2c016 100755 --- a/service/key_command/include/key_command_handler.h +++ b/service/key_command/include/key_command_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -173,6 +173,7 @@ private: bool HandleKeyDown(ShortcutKey &shortcutKey); bool HandleKeyCancel(ShortcutKey &shortcutKey); bool HandleEvent(const std::shared_ptr key); + bool PreHandleEvent(const std::shared_ptr key); bool HandleKeyUpCancel(const RepeatKey &item, const std::shared_ptr keyEvent); bool HandleRepeatKeyCount(const RepeatKey &item, const std::shared_ptr keyEvent); bool HandleRepeatKey(const RepeatKey& item, bool &isLaunchAbility, const std::shared_ptr keyEvent); diff --git a/service/key_command/include/stylus_key_handler.h b/service/key_command/include/stylus_key_handler.h new file mode 100644 index 0000000000..ec3ddeb215 --- /dev/null +++ b/service/key_command/include/stylus_key_handler.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef STYLUS_KEY_HANDLER_H +#define STYLUS_KEY_HANDLER_H + +#include "key_command_handler.h" +#include "key_event.h" + +#include "singleton.h" + +namespace OHOS { +namespace MMI { +struct StylusKey { + int32_t durationTimes { 0 }; + bool lastEventIsStylus { false }; + bool isLaunchAbility { false }; + Ability ability; +}; +class StylusKeyHandler final { + DECLARE_DELAYED_SINGLETON(StylusKeyHandler); + public: + DISALLOW_COPY_AND_MOVE(StylusKeyHandler); +#ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER + bool HandleStylusKey(const std::shared_ptr keyEvent); + void IsLaunchAbility(); + void SetLastEventState(bool state); + private: + void LaunchAbility(const Ability &ability); + private: + StylusKey stylusKey_; +#endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER +}; +#define STYLUS_HANDLER ::OHOS::DelayedSingleton::GetInstance() +} // namespace MMI +} // namespace OHOS +#endif // STYLUS_KEY_HANDLER_H \ No newline at end of file diff --git a/service/key_command/src/key_command_handler.cpp b/service/key_command/src/key_command_handler.cpp index 78dd30aaea..b1d32669be 100644 --- a/service/key_command/src/key_command_handler.cpp +++ b/service/key_command/src/key_command_handler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,25 +16,26 @@ #include "key_command_handler.h" #include "ability_manager_client.h" -#include "nap_process.h" #include "bytrace_adapter.h" #include "cJSON.h" #include "config_policy_utils.h" +#include "file_ex.h" +#include "setting_datashare.h" +#include "system_ability_definition.h" + #include "define_multimodal.h" #include "dfx_hisysevent.h" #include "error_multimodal.h" -#include "file_ex.h" #include "input_event_data_transformation.h" #include "input_event_handler.h" #include "mmi_log.h" +#include "multimodal_input_preferences_manager.h" +#include "nap_process.h" #include "net_packet.h" #include "proto.h" -#include "setting_datashare.h" -#include "system_ability_definition.h" +#include "stylus_key_handler.h" #include "timer_manager.h" #include "util_ex.h" -#include "nap_process.h" -#include "multimodal_input_preferences_manager.h" namespace OHOS { namespace MMI { @@ -814,6 +815,9 @@ void KeyCommandHandler::OnHandleTouchEvent(const std::shared_ptr t { CALL_DEBUG_ENTER; CHKPV(touchEvent); +#ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER + STYLUS_HANDLER->SetLastEventState(false); +#endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER if (!isParseConfig_) { if (!ParseConfig()) { MMI_HILOGE("Parse configFile failed"); @@ -1360,9 +1364,8 @@ std::shared_ptr KeyCommandHandler::CreateKeyEvent(int32_t keyCode, int return keyEvent; } -bool KeyCommandHandler::HandleEvent(const std::shared_ptr key) +bool KeyCommandHandler::PreHandleEvent(const std::shared_ptr key) { - CALL_DEBUG_ENTER; CHKPF(key); if (!IsEnableCombineKey(key)) { MMI_HILOGI("Combine key is taken over in key command"); @@ -1389,6 +1392,23 @@ bool KeyCommandHandler::HandleEvent(const std::shared_ptr key) isParseStatusConfig_ = true; } + return true; +} + +bool KeyCommandHandler::HandleEvent(const std::shared_ptr key) +{ + CALL_DEBUG_ENTER; + CHKPF(key); + if (!PreHandleEvent(key)) { + return false; + } + +#ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER + if (STYLUS_HANDLER->HandleStylusKey(keyEvent)) { + return true; + } +#endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER + bool isHandled = HandleShortKeys(key); isHandled = HandleSequences(key) || isHandled; if (isHandled) { @@ -1468,6 +1488,9 @@ bool KeyCommandHandler::OnHandleEvent(const std::shared_ptr pointe { CALL_DEBUG_ENTER; CHKPF(pointer); +#ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER + STYLUS_HANDLER->SetLastEventState(false); +#endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER if (!isParseConfig_) { if (!ParseConfig()) { MMI_HILOGE("Parse configFile failed"); diff --git a/service/key_command/src/stylus_key_handler.cpp b/service/key_command/src/stylus_key_handler.cpp new file mode 100644 index 0000000000..0463d8c794 --- /dev/null +++ b/service/key_command/src/stylus_key_handler.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stylus_key_handler.h" + +#include "ability_manager_client.h" +#include "error_multimodal.h" +#include "mmi_log.h" + +namespace OHOS { +namespace MMI { +namespace { +#ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "StylusKeyHandler" }; +#endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER +} // namespace +const std::string STYLUS_ABILITY_NAME = "HiNotePcMainAbility"; +const std::string STYLUS_BUNDLE_NAME = "com.huawei.hmos.hinote"; + +StylusKeyHandler::StylusKeyHandler() {} +StylusKeyHandler::~StylusKeyHandler() {} + +#ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER +bool StylusKeyHandler::HandleStylusKey(const std::shared_ptr keyEvent) +{ + CALL_DEBUG_ENTER; + CHKPF(keyEvent); + if (keyEvent->GetKeyCode() != KeyEvent::KEYCODE_STYLUS_SCREEN) { + stylusKey_.lastEventIsStylus = false; + return false; + } + if (stylusKey_.isLaunchAbility) { + stylusKey_.isLaunchAbility = false; + return true; + } + stylusKey_.lastEventIsStylus = true; + return false; +} + +void StylusKeyHandler::IsLaunchAbility() +{ + if (stylusKey_.lastEventIsStylus) { + stylusKey_.ability.abilityName = STYLUS_ABILITY_NAME; + stylusKey_.ability.bundleName = STYLUS_BUNDLE_NAME; + LaunchAbility(stylusKey_.ability); + stylusKey_.lastEventIsStylus = false; + stylusKey_.isLaunchAbility = true; + } +} + +void StylusKeyHandler::LaunchAbility(const Ability &ability) +{ + CALL_DEBUG_ENTER; + AAFwk::Want want; + want.SetElementName(ability.deviceId, ability.bundleName, ability.abilityName); + want.SetAction(ability.action); + want.SetUri(ability.uri); + want.SetType(ability.type); + for (const auto &entity : ability.entities) { + want.AddEntity(entity); + } + for (const auto &item : ability.params) { + want.SetParam(item.first, item.second); + } + + ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want); + if (err != ERR_OK) { + MMI_HILOGE("LaunchAbility failed, bundleName:%{public}s, err:%{public}d", ability.bundleName.c_str(), err); + } + MMI_HILOGD("End launch ability, bundleName:%{public}s", ability.bundleName.c_str()); +} + +void StylusKeyHandler::SetLastEventState(bool state) +{ + stylusKey_.lastEventIsStylus = state; +} + +#endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER +} // namespace AppExecFwk +} // namespace OHOS -- Gitee From 52937595766b3e0797c1c7ed2be7dfa4bda581aa Mon Sep 17 00:00:00 2001 From: mayunteng Date: Sat, 4 May 2024 05:40:32 +0000 Subject: [PATCH 2/2] update service/key_command/src/stylus_key_handler.cpp. Signed-off-by: mayunteng --- service/key_command/src/stylus_key_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/key_command/src/stylus_key_handler.cpp b/service/key_command/src/stylus_key_handler.cpp index 0463d8c794..6952971bfc 100644 --- a/service/key_command/src/stylus_key_handler.cpp +++ b/service/key_command/src/stylus_key_handler.cpp @@ -27,7 +27,7 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "Stylu #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER } // namespace const std::string STYLUS_ABILITY_NAME = "HiNotePcMainAbility"; -const std::string STYLUS_BUNDLE_NAME = "com.huawei.hmos.hinote"; +const std::string STYLUS_BUNDLE_NAME = "com.hmos.hinote"; StylusKeyHandler::StylusKeyHandler() {} StylusKeyHandler::~StylusKeyHandler() {} -- Gitee