From 2c4b6dfaae21b977c82d0f3dedf62f5871b86783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E4=B9=A6=E5=8C=85=E6=8C=87=E6=8C=A5=E5=AE=98?= Date: Thu, 26 Dec 2024 19:57:32 +0800 Subject: [PATCH 1/6] watch feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 红书包指挥官 --- .../js_scene_session_manager.cpp | 71 +++++++++++++++++++ .../js_scene_session_manager.h | 12 +++- .../include/scene_session_manager.h | 12 ++++ .../zidl/scene_session_manager_interface.h | 25 +++++++ .../zidl/scene_session_manager_proxy.h | 2 + .../include/zidl/scene_session_manager_stub.h | 2 + .../src/scene_session_manager.cpp | 36 ++++++++++ .../src/zidl/scene_session_manager_proxy.cpp | 62 ++++++++++++++++ .../src/zidl/scene_session_manager_stub.cpp | 39 ++++++++++ wm/include/window_adapter.h | 2 + wm/include/window_session_impl.h | 19 +++++ wm/src/window_adapter.cpp | 16 +++++ wm/src/window_scene_session_impl.cpp | 8 +++ wm/src/window_session_impl.cpp | 58 +++++++++++++++ .../include/zidl/window_manager_interface.h | 3 + 15 files changed, 366 insertions(+), 1 deletion(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index 90eba18998..d22479829a 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -69,6 +69,8 @@ const std::string CLOSE_TARGET_FLOAT_WINDOW_CB = "closeTargetFloatWindow"; const std::string ABILITY_MANAGER_COLLABORATOR_REGISTERED_CB = "abilityManagerCollaboratorRegistered"; const std::string START_PIP_FAILED_CB = "startPiPFailed"; const std::string NOTIFY_APP_USE_CONTROL_LIST_CB = "updateAppUseControl"; +const std::string WATCH_GESTURE_CONSUME_RESULT_CB = "watchGestureConsumeResult"; +const std::string WATCH_FOCUS_ACTIVE_CHANGE_CB = "watchFocusActiveChange"; const std::map ListenerFunctionTypeMap { {CREATE_SYSTEM_SESSION_CB, ListenerFunctionType::CREATE_SYSTEM_SESSION_CB}, @@ -85,6 +87,8 @@ const std::map ListenerFunctionTypeMap { {ABILITY_MANAGER_COLLABORATOR_REGISTERED_CB, ListenerFunctionType::ABILITY_MANAGER_COLLABORATOR_REGISTERED_CB}, {START_PIP_FAILED_CB, ListenerFunctionType::START_PIP_FAILED_CB}, {NOTIFY_APP_USE_CONTROL_LIST_CB, ListenerFunctionType::NOTIFY_APP_USE_CONTROL_LIST_CB}, + {WATCH_GESTURE_CONSUME_RESULT_CB, ListenerFunctionType::WATCH_GESTURE_CONSUME_RESULT_CB}, + {WATCH_FOCUS_ACTIVE_CHANGE_CB, ListenerFunctionType::WATCH_FOCUS_ACTIVE_CHANGE_CB}, }; } // namespace @@ -1317,6 +1321,12 @@ void JsSceneSessionManager::ProcessRegisterCallback(ListenerFunctionType listene case ListenerFunctionType::NOTIFY_APP_USE_CONTROL_LIST_CB: RegisterNotifyAppUseControlListCallback(); break; + case ListenerFunctionType::WATCH_GESTURE_CONSUME_RESULT_CB: + RegisterWatchGestureConsumeResultCallback(); + break; + case ListenerFunctionType::WATCH_FOCUS_ACTIVE_CHANGE_CB: + RegisterWatchFocusActiveChangeCallback(); + break; default: break; } @@ -3907,4 +3917,65 @@ void JsSceneSessionManager::OnNotifyAppUseControlList( napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }, __func__); } + +void JsSceneSessionManager::RegisterWatchGestureConsumeResultCallback() +{ + ProcessWatchGestureConsumeResultFunc func = [this](int32_t keyCode, bool isConsumed) { + WLOGFD("RegisterWatchGestureConsumeResultCallback called"); + this->OnWatchGestureConsumeResult(keyCode, isConsumed); + }; + SceneSessionManager::GetInstance().RegisterWatchGestureConsumeResultCallback(func); +} + +void JsSceneSessionManager::OnWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) +{ + TLOGD(WmsLogTag::WMS_EVENT, "in"); + taskScheduler_->PostMainThreadTask([this, keyCode, isConsumed, + jsCallBack = GetJSCallback(WATCH_GESTURE_CONSUME_RESULT_CB), env = env_] { + if (jsCallBack == nullptr) { + TLOGNE(WmsLogTag::WMS_EVENT, "jsCallBack is nullptr"); + return; + } + napi_value objValue = nullptr; + napi_create_object(env, &objValue); + if (objValue == nullptr) { + TLOGNE(WmsLogTag::WMS_EVENT, "jsCallBack is nullptr"); + return; + } + napi_set_named_property(env, objValue, "keyCode", CreateJsValue(env_, keyCode)); + napi_set_named_property(env, objValue, "isConsumed", CreateJsValue(env_, isConsumed)); + napi_value argv[] = {objValue}; + napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); + }, __func__); +} + +void JsSceneSessionManager::RegisterWatchFocusActiveChangeCallback() +{ + ProcessWatchFocusActiveChangeFunc func = [this](bool isActived) { + WLOGFD("RegisterWatchFocusActiveChangeCallback called"); + this->OnWatchFocusActiveChange(isActived); + }; + SceneSessionManager::GetInstance().RegisterWatchFocusActiveChangeCallback(func); +} + +void JsSceneSessionManager::OnWatchFocusActiveChange(bool isActived) +{ + TLOGD(WmsLogTag::WMS_EVENT, "in"); + taskScheduler_->PostMainThreadTask([this, isActived, + jsCallBack = GetJSCallback(WATCH_FOCUS_ACTIVE_CHANGE_CB), env = env_] { + if (jsCallBack == nullptr) { + TLOGNE(WmsLogTag::WMS_EVENT, "jsCallBack is nullptr"); + return; + } + napi_value objValue = nullptr; + napi_create_object(env, &objValue); + if (objValue == nullptr) { + TLOGNE(WmsLogTag::WMS_EVENT, "jsCallBack is nullptr"); + return; + } + napi_set_named_property(env, objValue, "isActived", CreateJsValue(env_, isActived)); + napi_value argv[] = {objValue}; + napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); + }, __func__); +} } // namespace OHOS::Rosen diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h index fc65835dc4..4c8310e99a 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h @@ -42,7 +42,9 @@ enum class ListenerFunctionType : uint32_t { CLOSE_TARGET_FLOAT_WINDOW_CB, ABILITY_MANAGER_COLLABORATOR_REGISTERED_CB, START_PIP_FAILED_CB, - NOTIFY_APP_USE_CONTROL_LIST_CB + NOTIFY_APP_USE_CONTROL_LIST_CB, + WATCH_GESTURE_CONSUME_RESULT_CB, + WATCH_FOCUS_ACTIVE_CHANGE_CB }; class JsSceneSessionManager final { @@ -253,6 +255,14 @@ private: void OnStartPiPFailed(); void ProcessStartPiPFailedRegister(); + /* + * Window Input Event + */ + void RegisterWatchGestureConsumeResultCallback(); + void OnWatchGestureConsumeResult(int32_t keyCode, bool isConsumed); + void RegisterWatchFocusActiveChangeCallback(); + void OnWatchFocusActiveChange(bool isActived); + napi_env env_; std::shared_mutex jsCbMapMutex_; std::map> jsCbMap_; diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 538b935937..141baf48d6 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -129,6 +129,8 @@ using NotifyStartPiPFailedFunc = std::function; using NotifyAppUseControlListFunc = std::function& controlList)>; using NotifyRootSceneAvoidAreaChangeFunc = std::function& avoidArea, AvoidAreaType type)>; +using ProcessWatchGestureConsumeResultFunc = std::function; +using ProcessWatchFocusActiveChangeFunc = std::function; class AppAnrListener : public IRemoteStub { public: @@ -198,6 +200,14 @@ public: void SetDumpUITreeFunc(const DumpUITreeFunc& func); const AppWindowSceneConfig& GetWindowSceneConfig() const; + /* + * Window Input Event + */ + void RegisterWatchGestureConsumeResultCallback(const ProcessWatchGestureConsumeResultFunc& func); + WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) override; + void RegisterWatchFocusActiveChangeCallback(const ProcessWatchFocusActiveChangeFunc& func); + WMError NotifyWatchFocusActiveChange(bool isActived) override; + /* * Window Rotate Animation */ @@ -854,6 +864,8 @@ private: DumpUITreeFunc dumpUITreeFunc_; ProcessVirtualPixelRatioChangeFunc processVirtualPixelRatioChangeFunc_ = nullptr; ProcessCloseTargetFloatWindowFunc closeTargetFloatWindowFunc_; + ProcessWatchGestureConsumeResultFunc onWatchGestureConsumeResultFunc_; + ProcessWatchFocusActiveChangeFunc onWatchFocusActiveChangeFunc_; AppWindowSceneConfig appWindowSceneConfig_; diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h index cc7f5af062..e7ae4e87cc 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h @@ -124,6 +124,8 @@ public: TRANS_ID_GET_GLOBAL_DRAG_RESIZE_TYPE, TRANS_ID_SET_APP_DRAG_RESIZE_TYPE, TRANS_ID_GET_APP_DRAG_RESIZE_TYPE, + TRANS_ID_WATCH_GESTURE_CONSUME_RESULT, + TRANS_ID_WATCH_FOCUS_ACTIVE_CHANGE, }; virtual WSError SetSessionLabel(const sptr& token, const std::string& label) = 0; @@ -170,6 +172,29 @@ public: return WSError::WS_OK; } + /** + * @brief Notify watch gesture event consumption results + * + * This function provides the ability for Notify watch gesture event consumption results + * + * @param keycode keypointe codes + * @param isConsumed consume result + * @return Returns WSError::WS_OK if called success, otherwise failed. + * @permission Make sure the caller has system permission. + */ + WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) override { return WMError::WM_OK; } + + /** + * @brief Notify watch focus active change + * + * This function provides the ability for Notify watch focus active change + * + * @param isActived focus status + * @return Returns WSError::WS_OK if called success, otherwise failed. + * @permission Make sure the caller has system permission. + */ + WMError NotifyWatchFocusActiveChange(bool isActived) override { return WMError::WM_OK; } + virtual WSError RegisterIAbilityManagerCollaborator(int32_t type, const sptr& impl) = 0; virtual WSError UnregisterIAbilityManagerCollaborator(int32_t type) = 0; diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h b/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h index 324d4c7737..bc94a2f837 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h @@ -98,6 +98,8 @@ public: WSError UnregisterIAbilityManagerCollaborator(int32_t type) override; WSError NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible) override; WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override; + WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) override; + WMError NotifyWatchFocusActiveChange(bool isActived) override; WMError GetParentMainWindowId(int32_t windowId, int32_t& mainWindowId) override; WMError GetVisibilityWindowInfo(std::vector>& infos) override; WSError ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId) override; diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_stub.h b/window_scene/session_manager/include/zidl/scene_session_manager_stub.h index 2e20d7c223..62c9ae24ce 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_stub.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_stub.h @@ -82,6 +82,8 @@ private: int HandleRaiseWindowToTop(MessageParcel& data, MessageParcel& reply); int HandleNotifyWindowExtensionVisibilityChange(MessageParcel& data, MessageParcel& reply); int HandleGetTopWindowId(MessageParcel& data, MessageParcel& reply); + int HandleWatchGestureConsumeResult(MessageParcel& data, MessageParcel& reply); + int HandleWatchFocusActiveChange(MessageParcel& data, MessageParcel& reply); int HandleGetParentMainWindowId(MessageParcel& data, MessageParcel& reply); int HandleUpdateSessionWindowVisibilityListener(MessageParcel& data, MessageParcel& reply); int HandleShiftAppWindowFocus(MessageParcel& data, MessageParcel& reply); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index c91023ba3e..0e39890529 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -3574,6 +3574,42 @@ void SceneSessionManager::SetOutsideDownEventListener(const ProcessOutsideDownEv outsideDownEventFunc_ = func; } +WMError SceneSessionManager::NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) +{ + TLOGD(WmsLogTag::WMS_EVENT, "keyCode:%{public}d isConsumed:%{public}d", keyCode, isConsumed); + if (onWatchGestureConsumeResultFunc_) { + onWatchGestureConsumeResultFunc_(keyCode, isConsumed); + } else { + TLOGE(WmsLogTag::WMS_EVENT, "onWatchGestureConsumeResultFunc is null"); + return WMError::WM_ERROR_INVALID_PARAM; + } + return WMError::WM_OK; +} + +void SceneSessionManager::RegisterWatchGestureConsumeResultCallback(const ProcessWatchGestureConsumeResultFunc& func) +{ + TLOGD(WmsLogTag::WMS_EVENT, "in"); + onWatchGestureConsumeResultFunc_ = func; +} + +WMError SceneSessionManager::NotifyWatchFocusActiveChange(bool isActived) +{ + TLOGD(WmsLogTag::WMS_EVENT, "isActived:%{public}d", isActived); + if (onWatchFocusActiveChangeFunc_) { + onWatchFocusActiveChangeFunc_(isActived); + } else { + TLOGE(WmsLogTag::WMS_EVENT, "onWatchFocusActiveChangeFunc is null"); + return WMError::WM_ERROR_INVALID_PARAM; + } + return WMError::WM_OK; +} + +void SceneSessionManager::RegisterWatchFocusActiveChangeCallback(const ProcessWatchFocusActiveChangeFunc& func) +{ + TLOGD(WmsLogTag::WMS_EVENT, "in"); + onWatchFocusActiveChangeFunc_ = func; +} + void SceneSessionManager::ClearSpecificSessionRemoteObjectMap(int32_t persistentId) { for (auto iter = remoteObjectMap_.begin(); iter != remoteObjectMap_.end(); ++iter) { diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp index dc01b248eb..cb903f4158 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp @@ -1737,6 +1737,68 @@ WMError SceneSessionManagerProxy::GetTopWindowId(uint32_t mainWinId, uint32_t& t return static_cast(ret); } +WMError SceneSessionManagerProxy::NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) +{ + TLOGD(WmsLogTag::WMS_EVENT, "keyCode:%{public}d isConsumed:%{public}d", keyCode, isConsumed); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("Write interface token failed."); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteInt32(keyCode)) { + WLOGFE("Write keyCode failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteBool(isConsumed)) { + WLOGFE("Write isConsumed failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFE("remote is null"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (remote->SendRequest(static_cast(SceneSessionManagerMessage::TRANS_ID_WATCH_GESTURE_CONSUME_RESULT), + data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WMError SceneSessionManagerProxy::NotifyWatchFocusActiveChange(bool isActived) +{ + TLOGD(WmsLogTag::WMS_EVENT, "isActived:%{public}d", isActived); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("Write interface token failed."); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteBool(isActived)) { + WLOGFE("Write isActived failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFE("remote is null"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (remote->SendRequest(static_cast(SceneSessionManagerMessage::TRANS_ID_WATCH_FOCUS_ACTIVE_CHANGE), + data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + WMError SceneSessionManagerProxy::GetParentMainWindowId(int32_t windowId, int32_t& mainWindowId) { MessageParcel data; diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp index 55abc118b6..465206e48f 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp @@ -195,6 +195,10 @@ int SceneSessionManagerStub::ProcessRemoteRequest(uint32_t code, MessageParcel& return HandleSetAppDragResizeType(data, reply); case static_cast(SceneSessionManagerMessage::TRANS_ID_GET_APP_DRAG_RESIZE_TYPE): return HandleGetAppDragResizeType(data, reply); + case static_cast(SceneSessionManagerMessage::TRANS_ID_WATCH_GESTURE_CONSUME_RESULT): + return HandleWatchGestureConsumeResult(data, reply); + case static_cast(SceneSessionManagerMessage::TRANS_ID_WATCH_FOCUS_ACTIVE_CHANGE): + return HandleWatchFocusActiveChange(data, reply); default: WLOGFE("Failed to find function handler!"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -1063,6 +1067,41 @@ int SceneSessionManagerStub::HandleGetParentMainWindowId(MessageParcel& data, Me return ERR_NONE; } +int SceneSessionManagerStub::HandleWatchGestureConsumeResult(MessageParcel& data, MessageParcel& reply) +{ + int32_t keyCode = 0; + if (!data.ReadInt32(keyCode)) { + TLOGE(WmsLogTag::WMS_EVENT, "read keyCode failed"); + return ERR_INVALID_DATA; + } + bool isConsumed = false; + if (!data.ReadBool(isConsumed)) { + TLOGE(WmsLogTag::WMS_EVENT, "read isConsumed failed"); + return ERR_INVALID_DATA; + } + TLOGD(WmsLogTag::WMS_EVENT, "keyCode:%{public}d isConsumed:%{public}d", keyCode, isConsumed); + WMError ret = NotifyWatchGestureConsumeResult(keyCode, isConsumed); + if (!reply.WriteInt32(static_cast(ret))) { + return ERR_INVALID_DATA; + } + return ERR_NONE; +} + +int SceneSessionManagerStub::HandleWatchFocusActiveChange(MessageParcel& data, MessageParcel& reply) +{ + bool isActived = false; + if (!data.ReadBool(isActived)) { + TLOGE(WmsLogTag::WMS_FOCUS, "read isActived failed"); + return ERR_INVALID_DATA; + } + TLOGD(WmsLogTag::WMS_EVENT, "isActived:%{public}d", isActived); + WMError ret = NotifyWatchFocusActiveChange(isActived); + if (!reply.WriteInt32(static_cast(ret))) { + return ERR_INVALID_DATA; + } + return ERR_NONE; +} + int SceneSessionManagerStub::HandleUpdateSessionWindowVisibilityListener(MessageParcel& data, MessageParcel& reply) { TLOGD(WmsLogTag::WMS_ATTRIBUTE, "Handled!"); diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 79eb2b08fe..0c2137536d 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -140,6 +140,8 @@ public: virtual WMError GetWindowIdsByCoordinate(DisplayId displayId, int32_t windowNumber, int32_t x, int32_t y, std::vector& windowIds); virtual WMError ReleaseForegroundSessionScreenLock(); + virtual WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed); + virtual WMError NotifyWatchFocusActiveChange(bool isActived); /* * PC Window */ diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index d78b475208..8c45f775e1 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -325,6 +325,14 @@ public: */ WSError NotifyDisplayIdChange(DisplayId displayId); + /* + * Window Input Event + */ + WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed); + WMError NotifyWatchFocusActiveChange(bool isActived); + void RegisterWatchFocusActiveChangeCallback(); + void NotifyResultToFloatWindow(const std::shared_ptr& keyEvent, bool isConsumed); + protected: WMError Connect(); bool IsWindowSessionInvalid() const; @@ -473,6 +481,12 @@ protected: float lastSystemDensity_ = UNDEFINED_DENSITY; WSError NotifySystemDensityChange(float density); + /* + * Window Input Event + */ + bool GetWatchGestureConsumed(); + void SetWatchGestureConsumed(bool isWatchGestureConsumed); + private: //Trans between colorGamut and colorSpace static ColorSpace GetColorSpaceFromSurfaceGamut(GraphicColorGamut colorGamut); @@ -640,6 +654,11 @@ private: * PC Window */ uint32_t targetAPIVersion_ = 0; + + /* + * Window Input Event + */ + bool isWatchGestureConsumed_ = false; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 9ddd4e6571..9e47b04710 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -1041,5 +1041,21 @@ WMError WindowAdapter::GetAppDragResizeType(const std::string& bundleName, DragR CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR); return wmsProxy->GetAppDragResizeType(bundleName, dragResizeType); } + +WMError WindowAdapter::NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) +{ + INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); + auto wmsProxy = GetWindowManagerServiceProxy(); + CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR); + return wmsProxy->NotifyWatchGestureConsumeResult(keyCode, isConsumed); +} + +WMError WindowAdapter::NotifyWatchFocusActiveChange(bool isActived) +{ + INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); + auto wmsProxy = GetWindowManagerServiceProxy(); + CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR); + return wmsProxy->NotifyWatchFocusActiveChange(isActived); +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index c5a261c6a0..4c924f529c 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -843,6 +843,14 @@ bool WindowSceneSessionImpl::PreNotifyKeyEvent(const std::shared_ptrProcessKeyEvent(keyEvent, true); } RefreshNoInteractionTimeoutMonitor(); + if ((keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_TAB || + keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ENTER) && + ret && keyEvent->GetKeyAction() == MMI::KeyEvent::KEY_ACTION_DOWN) { + TLOGD(WmsLogTag::WMS_INPUT_KEY_FLOW, "wid:%{public}d, keyCode:%{public}d, ret:%{public}d", + GetWindowId(), keyEvent->GetKeyCode(), ret); + SetWatchGestureConsumed(ret); + NotifyWatchGestureConsumeResult(keyEvent->GetKeyCode(), ret); + } return ret; } diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 86805fa74f..e411e7f5ef 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -1402,9 +1402,32 @@ WMError WindowSessionImpl::InitUIContent(const std::string& contentInfo, napi_en WLOGFI("Initialized, isUIExtensionSubWindow:%{public}d, isUIExtensionAbilityProcess:%{public}d", uiContent_->IsUIExtensionSubWindow(), uiContent_->IsUIExtensionAbilityProcess()); } + RegisterWatchFocusActiveChangeCallback(); return WMError::WM_OK; } +void WindowSessionImpl::RegisterWatchFocusActiveChangeCallback() +{ + if (uiContent_ == nullptr) { + TLOGE(WmsLogTag::WMS_EVENT, "uiContent is nullptr"); + return; + } + auto callback = [this](bool isFocusActive) { + NotifyWatchFocusActiveChange(isFocusActive); + }; + uiContent_->AddFocusActiveChangeCallback(callback); +} + +WMError WindowSessionImpl::NotifyWatchFocusActiveChange(bool isActived) +{ + TLOGD(WmsLogTag::WMS_LIFE, "isActived: %{public}d", isActived); + if (IsWindowSessionInvalid()) { + TLOGE(WmsLogTag::WMS_EVENT, "window is invalid!"); + return WMError::WM_ERROR_INVALID_WINDOW; + } + return SingletonContainer::Get().NotifyWatchFocusActiveChange(isActived); +} + WMError WindowSessionImpl::SetUIContentInner(const std::string& contentInfo, napi_env env, napi_value storage, WindowSetUIContentType setUIContentType, BackupAndRestoreType restoreType, AppExecFwk::Ability* ability) { @@ -3623,6 +3646,28 @@ WSError WindowSessionImpl::NotifyDisplayIdChange(DisplayId displayId) return WSError::WS_OK; } +WMError WindowSessionImpl::NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) +{ + TLOGD(WmsLogTag::WMS_EVENT, "keyCode:%{public}d, isConsumed:%{public}d", keyCode, isConsumed); + if (IsWindowSessionInvalid()) { + TLOGE(WmsLogTag::WMS_EVENT, "window is invalid!"); + return WMError::WM_ERROR_INVALID_WINDOW; + } + return SingletonContainer::Get().NotifyWatchGestureConsumeResult(keyCode, isConsumed); +} + +bool WindowSessionImpl::GetWatchGestureConsumed() +{ + return isWatchGestureConsumed_; +} + +void WindowSessionImpl::SetWatchGestureConsumed(bool isWatchGestureConsumed) +{ + TLOGD(WmsLogTag::WMS_EVENT, "wid:%{public}d, isWatchGestureConsumed:%{public}d", + GetPersistentId(), isWatchGestureConsumed); + isWatchGestureConsumed_ = isWatchGestureConsumed; +} + WSError WindowSessionImpl::NotifySystemDensityChange(float density) { std::lock_guard lock(systemDensityChangeListenerMutex_); @@ -3732,6 +3777,18 @@ bool WindowSessionImpl::FilterKeyEvent(const std::shared_ptr& key return false; } +void WindowSessionImpl::NotifyResultToFloatWindow(const std::shared_ptr& keyEvent, bool isConsumed) +{ + if ((keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_TAB || + keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ENTER) && !GetWatchGestureConsumed() && + keyEvent->GetKeyAction() == MMI::KeyEvent::KEY_ACTION_DOWN) { + TLOGD(WmsLogTag::WMS_INPUT_KEY_FLOW, "wid:%{public}d, keyCode:%{public}d, isConsumed:%{public}d", + GetWindowId(), keyEvent->GetKeyCode(), isConsumed); + NotifyWatchGestureConsumeResult(keyEvent->GetKeyCode(), isConsumed); + SetWatchGestureConsumed(false); + } +} + void WindowSessionImpl::DispatchKeyEventCallback(const std::shared_ptr& keyEvent, bool& isConsumed) { std::shared_ptr inputEventConsumer; @@ -3776,6 +3833,7 @@ void WindowSessionImpl::DispatchKeyEventCallback(const std::shared_ptrMarkProcessed(); } diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index a50e307010..b9425725a4 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -255,6 +255,9 @@ public: DragResizeType dragResizeType) { return WMError::WM_OK; } virtual WMError GetAppDragResizeType(const std::string& bundleName, DragResizeType& dragResizeType) { return WMError::WM_OK; } + virtual WMError NotifyWatchGestureConsumeResult(int32_t keyCode, + bool isConsumed) { return WMError::WM_OK; } + virtual WMError NotifyWatchFocusActiveChange(bool isActived) { return WMError::WM_OK; } }; } } -- Gitee From 17c86abbb7c228c3d8d4573af867630c8f47707d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E4=B9=A6=E5=8C=85=E6=8C=87=E6=8C=A5=E5=AE=98?= Date: Fri, 27 Dec 2024 15:31:59 +0800 Subject: [PATCH 2/6] fix review opinions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 红书包指挥官 --- .../js_scene_session_manager.cpp | 6 +++--- .../include/scene_session_manager.h | 8 ++++++-- .../src/zidl/scene_session_manager_proxy.cpp | 10 ++++++++-- wm/include/window_adapter.h | 1 + wm/src/window_scene_session_impl.cpp | 16 ++++++++-------- wm/src/window_session_impl.cpp | 2 +- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index d22479829a..9b71740904 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -88,7 +88,7 @@ const std::map ListenerFunctionTypeMap { {START_PIP_FAILED_CB, ListenerFunctionType::START_PIP_FAILED_CB}, {NOTIFY_APP_USE_CONTROL_LIST_CB, ListenerFunctionType::NOTIFY_APP_USE_CONTROL_LIST_CB}, {WATCH_GESTURE_CONSUME_RESULT_CB, ListenerFunctionType::WATCH_GESTURE_CONSUME_RESULT_CB}, - {WATCH_FOCUS_ACTIVE_CHANGE_CB, ListenerFunctionType::WATCH_FOCUS_ACTIVE_CHANGE_CB}, + {WATCH_FOCUS_ACTIVE_CHANGE_CB, ListenerFunctionType::WATCH_FOCUS_ACTIVE_CHANGE_CB}, }; } // namespace @@ -3944,7 +3944,7 @@ void JsSceneSessionManager::OnWatchGestureConsumeResult(int32_t keyCode, bool is } napi_set_named_property(env, objValue, "keyCode", CreateJsValue(env_, keyCode)); napi_set_named_property(env, objValue, "isConsumed", CreateJsValue(env_, isConsumed)); - napi_value argv[] = {objValue}; + napi_value argv[] = { objValue }; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }, __func__); } @@ -3974,7 +3974,7 @@ void JsSceneSessionManager::OnWatchFocusActiveChange(bool isActived) return; } napi_set_named_property(env, objValue, "isActived", CreateJsValue(env_, isActived)); - napi_value argv[] = {objValue}; + napi_value argv[] = { objValue }; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }, __func__); } diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 141baf48d6..cd6a72d19a 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -819,6 +819,12 @@ private: void UpdateGestureBackEnabled(int32_t persistentId); std::unordered_set gestureBackEnableWindowIdSet_; // ONLY Accessed on OS_sceneSession thread + /* + * Window Input Event + */ + ProcessWatchGestureConsumeResultFunc onWatchGestureConsumeResultFunc_; + ProcessWatchFocusActiveChangeFunc onWatchFocusActiveChangeFunc_; + sptr rootSceneSession_; std::weak_ptr rootSceneContextWeak_; mutable std::shared_mutex sceneSessionMapMutex_; @@ -864,8 +870,6 @@ private: DumpUITreeFunc dumpUITreeFunc_; ProcessVirtualPixelRatioChangeFunc processVirtualPixelRatioChangeFunc_ = nullptr; ProcessCloseTargetFloatWindowFunc closeTargetFloatWindowFunc_; - ProcessWatchGestureConsumeResultFunc onWatchGestureConsumeResultFunc_; - ProcessWatchFocusActiveChangeFunc onWatchFocusActiveChangeFunc_; AppWindowSceneConfig appWindowSceneConfig_; diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp index cb903f4158..1c40428211 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp @@ -1766,7 +1766,10 @@ WMError SceneSessionManagerProxy::NotifyWatchGestureConsumeResult(int32_t keyCod WLOGFE("SendRequest failed"); return WMError::WM_ERROR_IPC_FAILED; } - int32_t ret = reply.ReadInt32(); + int32_t ret = 0; + if (!reply.ReadInt32(ret)) { + return WMError::WM_ERROR_IPC_FAILED; + } return static_cast(ret); } @@ -1795,7 +1798,10 @@ WMError SceneSessionManagerProxy::NotifyWatchFocusActiveChange(bool isActived) WLOGFE("SendRequest failed"); return WMError::WM_ERROR_IPC_FAILED; } - int32_t ret = reply.ReadInt32(); + int32_t ret = 0; + if (!reply.ReadInt32(ret)) { + return WMError::WM_ERROR_IPC_FAILED; + } return static_cast(ret); } diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 0c2137536d..590277507b 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -142,6 +142,7 @@ public: virtual WMError ReleaseForegroundSessionScreenLock(); virtual WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed); virtual WMError NotifyWatchFocusActiveChange(bool isActived); + /* * PC Window */ diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index 4c924f529c..9696cac8ac 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -838,20 +838,20 @@ void WindowSceneSessionImpl::ConsumePointerEvent(const std::shared_ptr& keyEvent) { - bool ret = false; + bool isConsumed = false; if (auto uiContent = GetUIContentSharedPtr()) { - ret = uiContent->ProcessKeyEvent(keyEvent, true); + isConsumed = uiContent->ProcessKeyEvent(keyEvent, true); } RefreshNoInteractionTimeoutMonitor(); if ((keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_TAB || keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ENTER) && - ret && keyEvent->GetKeyAction() == MMI::KeyEvent::KEY_ACTION_DOWN) { - TLOGD(WmsLogTag::WMS_INPUT_KEY_FLOW, "wid:%{public}d, keyCode:%{public}d, ret:%{public}d", - GetWindowId(), keyEvent->GetKeyCode(), ret); - SetWatchGestureConsumed(ret); - NotifyWatchGestureConsumeResult(keyEvent->GetKeyCode(), ret); + isConsumed && keyEvent->GetKeyAction() == MMI::KeyEvent::KEY_ACTION_DOWN) { + TLOGD(WmsLogTag::WMS_INPUT_KEY_FLOW, "wid:%{public}d, keyCode:%{public}d, isConsumed:%{public}d", + GetWindowId(), keyEvent->GetKeyCode(), isConsumed); + SetWatchGestureConsumed(isConsumed); + NotifyWatchGestureConsumeResult(keyEvent->GetKeyCode(), isConsumed); } - return ret; + return isConsumed; } void WindowSceneSessionImpl::GetConfigurationFromAbilityInfo() diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index e411e7f5ef..8cc1444abc 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -1408,7 +1408,7 @@ WMError WindowSessionImpl::InitUIContent(const std::string& contentInfo, napi_en void WindowSessionImpl::RegisterWatchFocusActiveChangeCallback() { - if (uiContent_ == nullptr) { + if (GetUIContentSharedPtr() == nullptr) { TLOGE(WmsLogTag::WMS_EVENT, "uiContent is nullptr"); return; } -- Gitee From be176978299cc943b467c6d52c2f2bc4df74255e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E4=B9=A6=E5=8C=85=E6=8C=87=E6=8C=A5=E5=AE=98?= Date: Fri, 27 Dec 2024 21:17:09 +0800 Subject: [PATCH 3/6] fix review opinions again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 红书包指挥官 --- .../js_scene_session_manager.cpp | 29 +++++----- .../js_scene_session_manager.h | 2 +- .../include/scene_session_manager.h | 14 ++--- .../zidl/scene_session_manager_interface.h | 8 +-- .../zidl/scene_session_manager_proxy.h | 2 +- .../src/scene_session_manager.cpp | 14 ++--- .../src/zidl/scene_session_manager_proxy.cpp | 24 ++++---- .../src/zidl/scene_session_manager_stub.cpp | 10 ++-- .../unittest/scene_session_manager_test12.cpp | 57 +++++++++++++++++++ wm/include/window_adapter.h | 2 +- wm/include/window_session_impl.h | 2 +- wm/src/window_adapter.cpp | 4 +- wm/src/window_scene_session_impl.cpp | 2 +- wm/src/window_session_impl.cpp | 7 +-- .../unittest/window_session_impl_test3.cpp | 57 +++++++++++++++++++ .../include/zidl/window_manager_interface.h | 2 +- 16 files changed, 174 insertions(+), 62 deletions(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index 9b71740904..94e92bb8c6 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -3920,11 +3920,11 @@ void JsSceneSessionManager::OnNotifyAppUseControlList( void JsSceneSessionManager::RegisterWatchGestureConsumeResultCallback() { - ProcessWatchGestureConsumeResultFunc func = [this](int32_t keyCode, bool isConsumed) { - WLOGFD("RegisterWatchGestureConsumeResultCallback called"); - this->OnWatchGestureConsumeResult(keyCode, isConsumed); - }; - SceneSessionManager::GetInstance().RegisterWatchGestureConsumeResultCallback(func); + SceneSessionManager::GetInstance().RegisterWatchGestureConsumeResultCallback( + [this](int32_t keyCode, bool isConsumed) { + TLOGND(WmsLogTag::WMS_EVENT, "RegisterWatchGestureConsumeResultCallback called"); + this->OnWatchGestureConsumeResult(keyCode, isConsumed); + }); } void JsSceneSessionManager::OnWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) @@ -3942,8 +3942,8 @@ void JsSceneSessionManager::OnWatchGestureConsumeResult(int32_t keyCode, bool is TLOGNE(WmsLogTag::WMS_EVENT, "jsCallBack is nullptr"); return; } - napi_set_named_property(env, objValue, "keyCode", CreateJsValue(env_, keyCode)); - napi_set_named_property(env, objValue, "isConsumed", CreateJsValue(env_, isConsumed)); + napi_set_named_property(env, objValue, "keyCode", CreateJsValue(env, keyCode)); + napi_set_named_property(env, objValue, "isConsumed", CreateJsValue(env, isConsumed)); napi_value argv[] = { objValue }; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }, __func__); @@ -3951,17 +3951,16 @@ void JsSceneSessionManager::OnWatchGestureConsumeResult(int32_t keyCode, bool is void JsSceneSessionManager::RegisterWatchFocusActiveChangeCallback() { - ProcessWatchFocusActiveChangeFunc func = [this](bool isActived) { - WLOGFD("RegisterWatchFocusActiveChangeCallback called"); - this->OnWatchFocusActiveChange(isActived); - }; - SceneSessionManager::GetInstance().RegisterWatchFocusActiveChangeCallback(func); + SceneSessionManager::GetInstance().RegisterWatchFocusActiveChangeCallback([this](bool isActive) { + TLOGND(WmsLogTag::WMS_EVENT, "RegisterWatchFocusActiveChangeCallback called"); + this->OnWatchFocusActiveChange(isActive); + }); } -void JsSceneSessionManager::OnWatchFocusActiveChange(bool isActived) +void JsSceneSessionManager::OnWatchFocusActiveChange(bool isActive) { TLOGD(WmsLogTag::WMS_EVENT, "in"); - taskScheduler_->PostMainThreadTask([this, isActived, + taskScheduler_->PostMainThreadTask([this, isActive, jsCallBack = GetJSCallback(WATCH_FOCUS_ACTIVE_CHANGE_CB), env = env_] { if (jsCallBack == nullptr) { TLOGNE(WmsLogTag::WMS_EVENT, "jsCallBack is nullptr"); @@ -3973,7 +3972,7 @@ void JsSceneSessionManager::OnWatchFocusActiveChange(bool isActived) TLOGNE(WmsLogTag::WMS_EVENT, "jsCallBack is nullptr"); return; } - napi_set_named_property(env, objValue, "isActived", CreateJsValue(env_, isActived)); + napi_set_named_property(env, objValue, "isActive", CreateJsValue(env, isActive)); napi_value argv[] = { objValue }; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }, __func__); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h index 4c8310e99a..f81bfe9414 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h @@ -261,7 +261,7 @@ private: void RegisterWatchGestureConsumeResultCallback(); void OnWatchGestureConsumeResult(int32_t keyCode, bool isConsumed); void RegisterWatchFocusActiveChangeCallback(); - void OnWatchFocusActiveChange(bool isActived); + void OnWatchFocusActiveChange(bool isActive); napi_env env_; std::shared_mutex jsCbMapMutex_; diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index cd6a72d19a..9df08bd793 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -129,8 +129,8 @@ using NotifyStartPiPFailedFunc = std::function; using NotifyAppUseControlListFunc = std::function& controlList)>; using NotifyRootSceneAvoidAreaChangeFunc = std::function& avoidArea, AvoidAreaType type)>; -using ProcessWatchGestureConsumeResultFunc = std::function; -using ProcessWatchFocusActiveChangeFunc = std::function; +using NotifyWatchGestureConsumeResultFunc = std::function; +using NotifyWatchFocusActiveChangeFunc = std::function; class AppAnrListener : public IRemoteStub { public: @@ -203,10 +203,10 @@ public: /* * Window Input Event */ - void RegisterWatchGestureConsumeResultCallback(const ProcessWatchGestureConsumeResultFunc& func); + void RegisterWatchGestureConsumeResultCallback(NotifyWatchGestureConsumeResultFunc&& func); WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) override; - void RegisterWatchFocusActiveChangeCallback(const ProcessWatchFocusActiveChangeFunc& func); - WMError NotifyWatchFocusActiveChange(bool isActived) override; + void RegisterWatchFocusActiveChangeCallback(NotifyWatchFocusActiveChangeFunc&& func); + WMError NotifyWatchFocusActiveChange(bool isActive) override; /* * Window Rotate Animation @@ -822,8 +822,8 @@ private: /* * Window Input Event */ - ProcessWatchGestureConsumeResultFunc onWatchGestureConsumeResultFunc_; - ProcessWatchFocusActiveChangeFunc onWatchFocusActiveChangeFunc_; + NotifyWatchGestureConsumeResultFunc onWatchGestureConsumeResultFunc_; + NotifyWatchFocusActiveChangeFunc onWatchFocusActiveChangeFunc_; sptr rootSceneSession_; std::weak_ptr rootSceneContextWeak_; diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h index e7ae4e87cc..226f97dd4e 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h @@ -173,11 +173,11 @@ public: } /** - * @brief Notify watch gesture event consumption results + * @brief notifying watch gesture event consumption results * * This function provides the ability for Notify watch gesture event consumption results * - * @param keycode keypointe codes + * @param keycode keyEvent codes * @param isConsumed consume result * @return Returns WSError::WS_OK if called success, otherwise failed. * @permission Make sure the caller has system permission. @@ -185,7 +185,7 @@ public: WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) override { return WMError::WM_OK; } /** - * @brief Notify watch focus active change + * @brief notifying watch focus active change * * This function provides the ability for Notify watch focus active change * @@ -193,7 +193,7 @@ public: * @return Returns WSError::WS_OK if called success, otherwise failed. * @permission Make sure the caller has system permission. */ - WMError NotifyWatchFocusActiveChange(bool isActived) override { return WMError::WM_OK; } + WMError NotifyWatchFocusActiveChange(bool isActive) override { return WMError::WM_OK; } virtual WSError RegisterIAbilityManagerCollaborator(int32_t type, const sptr& impl) = 0; diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h b/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h index bc94a2f837..94fece2a82 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h @@ -99,7 +99,7 @@ public: WSError NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible) override; WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override; WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) override; - WMError NotifyWatchFocusActiveChange(bool isActived) override; + WMError NotifyWatchFocusActiveChange(bool isActive) override; WMError GetParentMainWindowId(int32_t windowId, int32_t& mainWindowId) override; WMError GetVisibilityWindowInfo(std::vector>& infos) override; WSError ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId) override; diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 0e39890529..d9d803267d 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -3586,17 +3586,17 @@ WMError SceneSessionManager::NotifyWatchGestureConsumeResult(int32_t keyCode, bo return WMError::WM_OK; } -void SceneSessionManager::RegisterWatchGestureConsumeResultCallback(const ProcessWatchGestureConsumeResultFunc& func) +void SceneSessionManager::RegisterWatchGestureConsumeResultCallback(NotifyWatchGestureConsumeResultFunc&& func) { TLOGD(WmsLogTag::WMS_EVENT, "in"); - onWatchGestureConsumeResultFunc_ = func; + onWatchGestureConsumeResultFunc_ = std::move(func); } -WMError SceneSessionManager::NotifyWatchFocusActiveChange(bool isActived) +WMError SceneSessionManager::NotifyWatchFocusActiveChange(bool isActive) { - TLOGD(WmsLogTag::WMS_EVENT, "isActived:%{public}d", isActived); + TLOGD(WmsLogTag::WMS_EVENT, "isActived:%{public}d", isActive); if (onWatchFocusActiveChangeFunc_) { - onWatchFocusActiveChangeFunc_(isActived); + onWatchFocusActiveChangeFunc_(isActive); } else { TLOGE(WmsLogTag::WMS_EVENT, "onWatchFocusActiveChangeFunc is null"); return WMError::WM_ERROR_INVALID_PARAM; @@ -3604,10 +3604,10 @@ WMError SceneSessionManager::NotifyWatchFocusActiveChange(bool isActived) return WMError::WM_OK; } -void SceneSessionManager::RegisterWatchFocusActiveChangeCallback(const ProcessWatchFocusActiveChangeFunc& func) +void SceneSessionManager::RegisterWatchFocusActiveChangeCallback(NotifyWatchFocusActiveChangeFunc&& func) { TLOGD(WmsLogTag::WMS_EVENT, "in"); - onWatchFocusActiveChangeFunc_ = func; + onWatchFocusActiveChangeFunc_ = std::move(func); } void SceneSessionManager::ClearSpecificSessionRemoteObjectMap(int32_t persistentId) diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp index 1c40428211..62fde3b471 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp @@ -1744,26 +1744,26 @@ WMError SceneSessionManagerProxy::NotifyWatchGestureConsumeResult(int32_t keyCod MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("Write interface token failed."); + TLOGE(WmsLogTag::WMS_EVENT, "Write interface token failed."); return WMError::WM_ERROR_IPC_FAILED; } if (!data.WriteInt32(keyCode)) { - WLOGFE("Write keyCode failed"); + TLOGE(WmsLogTag::WMS_EVENT, "Write keyCode failed"); return WMError::WM_ERROR_IPC_FAILED; } if (!data.WriteBool(isConsumed)) { - WLOGFE("Write isConsumed failed"); + TLOGE(WmsLogTag::WMS_EVENT, "Write isConsumed failed"); return WMError::WM_ERROR_IPC_FAILED; } sptr remote = Remote(); if (remote == nullptr) { - WLOGFE("remote is null"); + TLOGE(WmsLogTag::WMS_EVENT, "remote is null"); return WMError::WM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(SceneSessionManagerMessage::TRANS_ID_WATCH_GESTURE_CONSUME_RESULT), data, reply, option) != ERR_NONE) { - WLOGFE("SendRequest failed"); + TLOGE(WmsLogTag::WMS_EVENT, "SendRequest failed"); return WMError::WM_ERROR_IPC_FAILED; } int32_t ret = 0; @@ -1773,29 +1773,29 @@ WMError SceneSessionManagerProxy::NotifyWatchGestureConsumeResult(int32_t keyCod return static_cast(ret); } -WMError SceneSessionManagerProxy::NotifyWatchFocusActiveChange(bool isActived) +WMError SceneSessionManagerProxy::NotifyWatchFocusActiveChange(bool isActive) { - TLOGD(WmsLogTag::WMS_EVENT, "isActived:%{public}d", isActived); + TLOGD(WmsLogTag::WMS_EVENT, "isActive:%{public}d", isActive); MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("Write interface token failed."); + TLOGE(WmsLogTag::WMS_EVENT, "Write interface token failed."); return WMError::WM_ERROR_IPC_FAILED; } - if (!data.WriteBool(isActived)) { - WLOGFE("Write isActived failed"); + if (!data.WriteBool(isActive)) { + TLOGE(WmsLogTag::WMS_EVENT, "Write isActive failed"); return WMError::WM_ERROR_IPC_FAILED; } sptr remote = Remote(); if (remote == nullptr) { - WLOGFE("remote is null"); + TLOGE(WmsLogTag::WMS_EVENT, "remote is null"); return WMError::WM_ERROR_IPC_FAILED; } if (remote->SendRequest(static_cast(SceneSessionManagerMessage::TRANS_ID_WATCH_FOCUS_ACTIVE_CHANGE), data, reply, option) != ERR_NONE) { - WLOGFE("SendRequest failed"); + TLOGE(WmsLogTag::WMS_EVENT, "SendRequest failed"); return WMError::WM_ERROR_IPC_FAILED; } int32_t ret = 0; diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp index 465206e48f..a599318966 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp @@ -1089,13 +1089,13 @@ int SceneSessionManagerStub::HandleWatchGestureConsumeResult(MessageParcel& data int SceneSessionManagerStub::HandleWatchFocusActiveChange(MessageParcel& data, MessageParcel& reply) { - bool isActived = false; - if (!data.ReadBool(isActived)) { - TLOGE(WmsLogTag::WMS_FOCUS, "read isActived failed"); + bool isActive = false; + if (!data.ReadBool(isActive)) { + TLOGE(WmsLogTag::WMS_FOCUS, "read isActive failed"); return ERR_INVALID_DATA; } - TLOGD(WmsLogTag::WMS_EVENT, "isActived:%{public}d", isActived); - WMError ret = NotifyWatchFocusActiveChange(isActived); + TLOGD(WmsLogTag::WMS_EVENT, "isActive:%{public}d", isActive); + WMError ret = NotifyWatchFocusActiveChange(isActive); if (!reply.WriteInt32(static_cast(ret))) { return ERR_INVALID_DATA; } diff --git a/window_scene/test/unittest/scene_session_manager_test12.cpp b/window_scene/test/unittest/scene_session_manager_test12.cpp index b89fce48ff..1e88f6dafe 100644 --- a/window_scene/test/unittest/scene_session_manager_test12.cpp +++ b/window_scene/test/unittest/scene_session_manager_test12.cpp @@ -667,6 +667,63 @@ HWTEST_F(SceneSessionManagerTest12, IsKeyboardForeground, Function | SmallTest | property->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW); sceneSessionManager->IsKeyboardForeground(); } + +/** + * @tc.name: RegisterWatchGestureConsumeResultCallback + * @tc.desc: RegisterWatchGestureConsumeResultCallback + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, RegisterWatchGestureConsumeResultCallback, Function | SmallTest | Level3) +{ + NotifyWatchGestureConsumeResultFunc func = [](int32_t keyCode, bool isConsumed) {}; + ssm_->RegisterWatchGestureConsumeResultCallback(move(func)); + ASSERT_NE(ssm_->onWatchGestureConsumeResultFunc_, nullptr); +} + +/** + * @tc.name: RegisterWatchFocusActiveChangeCallback + * @tc.desc: RegisterWatchFocusActiveChangeCallback + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, RegisterWatchFocusActiveChangeCallback, Function | SmallTest | Level3) +{ + NotifyWatchFocusActiveChangeFunc func = [](bool isActive) {}; + ssm_->RegisterWatchFocusActiveChangeCallback(move(func)); + ASSERT_NE(ssm_->onWatchFocusActiveChangeFunc_, nullptr); +} + +/** + * @tc.name: NotifyWatchGestureConsumeResult + * @tc.desc: NotifyWatchGestureConsumeResult + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, NotifyWatchGestureConsumeResult, Function | SmallTest | Level3) +{ + int32_t keyCode = 2049; + bool isConsumed = true; + ssm_->onWatchGestureConsumeResultFunc_ = [](int32_t keyCode, bool isConsumed) {}; + auto ret = ssm_->NotifyWatchGestureConsumeResult(keyCode, isConsumed); + ASSERT_EQ(WMError::WM_OK, ret); + ssm_->onWatchGestureConsumeResultFunc_ = nullptr; + ret = ssm_->NotifyWatchGestureConsumeResult(keyCode, isConsumed); + ASSERT_NE(ret, WMError::WM_ERROR_INVALID_PARAM); +} + +/** + * @tc.name: NotifyWatchFocusActiveChange + * @tc.desc: NotifyWatchFocusActiveChange + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, NotifyWatchFocusActiveChange, Function | SmallTest | Level3) +{ + bool isActive = true; + ssm_->onWatchFocusActiveChangeFunc_ = [](bool isActive) {}; + auto ret = ssm_->NotifyWatchFocusActiveChange(isActive); + ASSERT_EQ(WMError::WM_OK, ret); + ssm_->onWatchFocusActiveChangeFunc_ = nullptr; + ret = ssm_->NotifyWatchFocusActiveChange(isActive); + ASSERT_NE(ret, WMError::WM_ERROR_INVALID_PARAM); +} } } // namespace Rosen } // namespace OHOS diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 590277507b..869677e8ff 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -141,7 +141,7 @@ public: int32_t x, int32_t y, std::vector& windowIds); virtual WMError ReleaseForegroundSessionScreenLock(); virtual WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed); - virtual WMError NotifyWatchFocusActiveChange(bool isActived); + virtual WMError NotifyWatchFocusActiveChange(bool isActive); /* * PC Window diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index 8c45f775e1..b024df3879 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -329,7 +329,7 @@ public: * Window Input Event */ WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed); - WMError NotifyWatchFocusActiveChange(bool isActived); + WMError NotifyWatchFocusActiveChange(bool isActive); void RegisterWatchFocusActiveChangeCallback(); void NotifyResultToFloatWindow(const std::shared_ptr& keyEvent, bool isConsumed); diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 9e47b04710..5497610736 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -1050,12 +1050,12 @@ WMError WindowAdapter::NotifyWatchGestureConsumeResult(int32_t keyCode, bool isC return wmsProxy->NotifyWatchGestureConsumeResult(keyCode, isConsumed); } -WMError WindowAdapter::NotifyWatchFocusActiveChange(bool isActived) +WMError WindowAdapter::NotifyWatchFocusActiveChange(bool isActive) { INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); auto wmsProxy = GetWindowManagerServiceProxy(); CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR); - return wmsProxy->NotifyWatchFocusActiveChange(isActived); + return wmsProxy->NotifyWatchFocusActiveChange(isActive); } } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index 9696cac8ac..c1b6a6d7f2 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -848,9 +848,9 @@ bool WindowSceneSessionImpl::PreNotifyKeyEvent(const std::shared_ptrGetKeyAction() == MMI::KeyEvent::KEY_ACTION_DOWN) { TLOGD(WmsLogTag::WMS_INPUT_KEY_FLOW, "wid:%{public}d, keyCode:%{public}d, isConsumed:%{public}d", GetWindowId(), keyEvent->GetKeyCode(), isConsumed); - SetWatchGestureConsumed(isConsumed); NotifyWatchGestureConsumeResult(keyEvent->GetKeyCode(), isConsumed); } + SetWatchGestureConsumed(isConsumed); return isConsumed; } diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 8cc1444abc..fe841b5111 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -1418,14 +1418,14 @@ void WindowSessionImpl::RegisterWatchFocusActiveChangeCallback() uiContent_->AddFocusActiveChangeCallback(callback); } -WMError WindowSessionImpl::NotifyWatchFocusActiveChange(bool isActived) +WMError WindowSessionImpl::NotifyWatchFocusActiveChange(bool isActive) { - TLOGD(WmsLogTag::WMS_LIFE, "isActived: %{public}d", isActived); + TLOGD(WmsLogTag::WMS_LIFE, "isActive: %{public}d", isActive); if (IsWindowSessionInvalid()) { TLOGE(WmsLogTag::WMS_EVENT, "window is invalid!"); return WMError::WM_ERROR_INVALID_WINDOW; } - return SingletonContainer::Get().NotifyWatchFocusActiveChange(isActived); + return SingletonContainer::Get().NotifyWatchFocusActiveChange(isActive); } WMError WindowSessionImpl::SetUIContentInner(const std::string& contentInfo, napi_env env, napi_value storage, @@ -3785,7 +3785,6 @@ void WindowSessionImpl::NotifyResultToFloatWindow(const std::shared_ptrGetKeyCode(), isConsumed); NotifyWatchGestureConsumeResult(keyEvent->GetKeyCode(), isConsumed); - SetWatchGestureConsumed(false); } } diff --git a/wm/test/unittest/window_session_impl_test3.cpp b/wm/test/unittest/window_session_impl_test3.cpp index 02c075e298..c1561ed7a1 100644 --- a/wm/test/unittest/window_session_impl_test3.cpp +++ b/wm/test/unittest/window_session_impl_test3.cpp @@ -914,6 +914,63 @@ HWTEST_F(WindowSessionImplTest3, GetAvoidAreaOption, Function | SmallTest | Leve WMError res = window->GetAvoidAreaOption(avoidAreaOption); ASSERT_EQ(res, WMError::WM_OK); } + +/** + * @tc.name: NotifyWatchGestureConsumeResult + * @tc.desc: NotifyWatchGestureConsumeResult test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest3, NotifyWatchGestureConsumeResult, Function | SmallTest | Level2) +{ + int32_t keyCode = 2054; + bool isConsumed = false; + ASSERT_NE(window_, nullptr); + WMError ret = window_->NotifyWatchGestureConsumeResult(keyCode, isConsumed); + ASSERT_EQ(ret, WMError::WM_OK); +} + +/** + * @tc.name: NotifyWatchFocusActiveChange + * @tc.desc: NotifyWatchFocusActiveChange test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest3, NotifyWatchFocusActiveChange, Function | SmallTest | Level2) +{ + bool isActive = false; + ASSERT_NE(window_, nullptr); + WMError ret = window_->NotifyWatchFocusActiveChange(isActive); + ASSERT_EQ(ret, WMError::WM_OK); +} + +/** + * @tc.name: SetWatchGestureConsumed + * @tc.desc: SetWatchGestureConsumed test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest3, SetWatchGestureConsumed, Function | SmallTest | Level2) +{ + bool isWatchGestureConsumed = false; + ASSERT_NE(window_, nullptr); + window_->SetWatchGestureConsumed(isWatchGestureConsumed); + ASSERT_EQ(window_->GetWatchGestureConsumed(), false); +} + +/** + * @tc.name: NotifyResultToFloatWindow + * @tc.desc: NotifyResultToFloatWindow test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest3, NotifyResultToFloatWindow, Function | SmallTest | Level2) +{ + std::shared_ptr keyEvent; + keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_TAB); + keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN); + bool isConsumed = false; + ASSERT_NE(window_, nullptr); + window_->SetWatchGestureConsumed(false); + window_->NotifyResultToFloatWindow(keyEvent, isConsumed); + ASSERT_EQ(window_->GetWatchGestureConsumed(), false); +} } } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index b9425725a4..8b4a1f28d3 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -257,7 +257,7 @@ public: DragResizeType& dragResizeType) { return WMError::WM_OK; } virtual WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) { return WMError::WM_OK; } - virtual WMError NotifyWatchFocusActiveChange(bool isActived) { return WMError::WM_OK; } + virtual WMError NotifyWatchFocusActiveChange(bool isActive) { return WMError::WM_OK; } }; } } -- Gitee From e056ddcc5016dcf62ee8d98f82babfd7ff6a321b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E4=B9=A6=E5=8C=85=E6=8C=87=E6=8C=A5=E5=AE=98?= Date: Sat, 28 Dec 2024 13:14:51 +0800 Subject: [PATCH 4/6] fix review opinions codes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 红书包指挥官 --- .../zidl/scene_session_manager_interface.h | 10 ++--- .../src/scene_session_manager.cpp | 2 +- .../unittest/scene_session_manager_test12.cpp | 4 +- wm/include/window_session_impl.h | 4 +- wm/src/window_scene_session_impl.cpp | 6 +-- wm/src/window_session_impl.cpp | 24 ++++++------ .../unittest/window_session_impl_test3.cpp | 37 +++---------------- 7 files changed, 29 insertions(+), 58 deletions(-) diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h index 226f97dd4e..94cd2cd881 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h @@ -173,9 +173,9 @@ public: } /** - * @brief notifying watch gesture event consumption results + * @brief notify watch gesture event consumption results * - * This function provides the ability for Notify watch gesture event consumption results + * This function provides the ability for notifying watch gesture event consumption results * * @param keycode keyEvent codes * @param isConsumed consume result @@ -185,11 +185,11 @@ public: WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) override { return WMError::WM_OK; } /** - * @brief notifying watch focus active change + * @brief notify watch focus active change * - * This function provides the ability for Notify watch focus active change + * This function provides the ability for notifying watch focus active change * - * @param isActived focus status + * @param isActive focus status * @return Returns WSError::WS_OK if called success, otherwise failed. * @permission Make sure the caller has system permission. */ diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index d9d803267d..05c8d9ff7f 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -3594,7 +3594,7 @@ void SceneSessionManager::RegisterWatchGestureConsumeResultCallback(NotifyWatchG WMError SceneSessionManager::NotifyWatchFocusActiveChange(bool isActive) { - TLOGD(WmsLogTag::WMS_EVENT, "isActived:%{public}d", isActive); + TLOGD(WmsLogTag::WMS_EVENT, "isActive:%{public}d", isActive); if (onWatchFocusActiveChangeFunc_) { onWatchFocusActiveChangeFunc_(isActive); } else { diff --git a/window_scene/test/unittest/scene_session_manager_test12.cpp b/window_scene/test/unittest/scene_session_manager_test12.cpp index 1e88f6dafe..a2ee862a42 100644 --- a/window_scene/test/unittest/scene_session_manager_test12.cpp +++ b/window_scene/test/unittest/scene_session_manager_test12.cpp @@ -676,7 +676,7 @@ HWTEST_F(SceneSessionManagerTest12, IsKeyboardForeground, Function | SmallTest | HWTEST_F(SceneSessionManagerTest12, RegisterWatchGestureConsumeResultCallback, Function | SmallTest | Level3) { NotifyWatchGestureConsumeResultFunc func = [](int32_t keyCode, bool isConsumed) {}; - ssm_->RegisterWatchGestureConsumeResultCallback(move(func)); + ssm_->RegisterWatchGestureConsumeResultCallback(std::move(func)); ASSERT_NE(ssm_->onWatchGestureConsumeResultFunc_, nullptr); } @@ -688,7 +688,7 @@ HWTEST_F(SceneSessionManagerTest12, RegisterWatchGestureConsumeResultCallback, F HWTEST_F(SceneSessionManagerTest12, RegisterWatchFocusActiveChangeCallback, Function | SmallTest | Level3) { NotifyWatchFocusActiveChangeFunc func = [](bool isActive) {}; - ssm_->RegisterWatchFocusActiveChangeCallback(move(func)); + ssm_->RegisterWatchFocusActiveChangeCallback(std::move(func)); ASSERT_NE(ssm_->onWatchFocusActiveChangeFunc_, nullptr); } diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index b024df3879..8c79d299bf 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -331,7 +331,7 @@ public: WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed); WMError NotifyWatchFocusActiveChange(bool isActive); void RegisterWatchFocusActiveChangeCallback(); - void NotifyResultToFloatWindow(const std::shared_ptr& keyEvent, bool isConsumed); + void NotifyConsumeResultToFloatWindow(const std::shared_ptr& keyEvent, bool isConsumed); protected: WMError Connect(); @@ -484,7 +484,7 @@ protected: /* * Window Input Event */ - bool GetWatchGestureConsumed(); + bool GetWatchGestureConsumed() const; void SetWatchGestureConsumed(bool isWatchGestureConsumed); private: diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index c1b6a6d7f2..4de2b6e837 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -844,9 +844,9 @@ bool WindowSceneSessionImpl::PreNotifyKeyEvent(const std::shared_ptrGetKeyCode() == MMI::KeyEvent::KEYCODE_TAB || - keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ENTER) && - isConsumed && keyEvent->GetKeyAction() == MMI::KeyEvent::KEY_ACTION_DOWN) { - TLOGD(WmsLogTag::WMS_INPUT_KEY_FLOW, "wid:%{public}d, keyCode:%{public}d, isConsumed:%{public}d", + keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ENTER) && isConsumed && + keyEvent->GetKeyAction() == MMI::KeyEvent::KEY_ACTION_DOWN) { + TLOGD(WmsLogTag::WMS_EVENT, "wid:%{public}d, keyCode:%{public}d, isConsumed:%{public}d", GetWindowId(), keyEvent->GetKeyCode(), isConsumed); NotifyWatchGestureConsumeResult(keyEvent->GetKeyCode(), isConsumed); } diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index fe841b5111..264fc74590 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -1408,21 +1408,19 @@ WMError WindowSessionImpl::InitUIContent(const std::string& contentInfo, napi_en void WindowSessionImpl::RegisterWatchFocusActiveChangeCallback() { - if (GetUIContentSharedPtr() == nullptr) { + if (auto uiContent = GetUIContentSharedPtr()) { + uiContent->AddFocusActiveChangeCallback([this](bool isFocusActive) { + NotifyWatchFocusActiveChange(isFocusActive); + }); + } else { TLOGE(WmsLogTag::WMS_EVENT, "uiContent is nullptr"); - return; } - auto callback = [this](bool isFocusActive) { - NotifyWatchFocusActiveChange(isFocusActive); - }; - uiContent_->AddFocusActiveChangeCallback(callback); } WMError WindowSessionImpl::NotifyWatchFocusActiveChange(bool isActive) { - TLOGD(WmsLogTag::WMS_LIFE, "isActive: %{public}d", isActive); + TLOGD(WmsLogTag::WMS_EVENT, "isActive:%{public}d", isActive); if (IsWindowSessionInvalid()) { - TLOGE(WmsLogTag::WMS_EVENT, "window is invalid!"); return WMError::WM_ERROR_INVALID_WINDOW; } return SingletonContainer::Get().NotifyWatchFocusActiveChange(isActive); @@ -3650,13 +3648,12 @@ WMError WindowSessionImpl::NotifyWatchGestureConsumeResult(int32_t keyCode, bool { TLOGD(WmsLogTag::WMS_EVENT, "keyCode:%{public}d, isConsumed:%{public}d", keyCode, isConsumed); if (IsWindowSessionInvalid()) { - TLOGE(WmsLogTag::WMS_EVENT, "window is invalid!"); return WMError::WM_ERROR_INVALID_WINDOW; } return SingletonContainer::Get().NotifyWatchGestureConsumeResult(keyCode, isConsumed); } -bool WindowSessionImpl::GetWatchGestureConsumed() +bool WindowSessionImpl::GetWatchGestureConsumed() const { return isWatchGestureConsumed_; } @@ -3777,12 +3774,13 @@ bool WindowSessionImpl::FilterKeyEvent(const std::shared_ptr& key return false; } -void WindowSessionImpl::NotifyResultToFloatWindow(const std::shared_ptr& keyEvent, bool isConsumed) +void WindowSessionImpl::NotifyConsumeResultToFloatWindow + (const std::shared_ptr& keyEvent, bool isConsumed) { if ((keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_TAB || keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ENTER) && !GetWatchGestureConsumed() && keyEvent->GetKeyAction() == MMI::KeyEvent::KEY_ACTION_DOWN) { - TLOGD(WmsLogTag::WMS_INPUT_KEY_FLOW, "wid:%{public}d, keyCode:%{public}d, isConsumed:%{public}d", + TLOGD(WmsLogTag::WMS_EVENT, "wid:%{public}d, keyCode:%{public}d, isConsumed:%{public}d", GetWindowId(), keyEvent->GetKeyCode(), isConsumed); NotifyWatchGestureConsumeResult(keyEvent->GetKeyCode(), isConsumed); } @@ -3832,7 +3830,7 @@ void WindowSessionImpl::DispatchKeyEventCallback(const std::shared_ptrMarkProcessed(); } diff --git a/wm/test/unittest/window_session_impl_test3.cpp b/wm/test/unittest/window_session_impl_test3.cpp index c1561ed7a1..479f7790fe 100644 --- a/wm/test/unittest/window_session_impl_test3.cpp +++ b/wm/test/unittest/window_session_impl_test3.cpp @@ -915,33 +915,6 @@ HWTEST_F(WindowSessionImplTest3, GetAvoidAreaOption, Function | SmallTest | Leve ASSERT_EQ(res, WMError::WM_OK); } -/** - * @tc.name: NotifyWatchGestureConsumeResult - * @tc.desc: NotifyWatchGestureConsumeResult test - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplTest3, NotifyWatchGestureConsumeResult, Function | SmallTest | Level2) -{ - int32_t keyCode = 2054; - bool isConsumed = false; - ASSERT_NE(window_, nullptr); - WMError ret = window_->NotifyWatchGestureConsumeResult(keyCode, isConsumed); - ASSERT_EQ(ret, WMError::WM_OK); -} - -/** - * @tc.name: NotifyWatchFocusActiveChange - * @tc.desc: NotifyWatchFocusActiveChange test - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplTest3, NotifyWatchFocusActiveChange, Function | SmallTest | Level2) -{ - bool isActive = false; - ASSERT_NE(window_, nullptr); - WMError ret = window_->NotifyWatchFocusActiveChange(isActive); - ASSERT_EQ(ret, WMError::WM_OK); -} - /** * @tc.name: SetWatchGestureConsumed * @tc.desc: SetWatchGestureConsumed test @@ -956,19 +929,19 @@ HWTEST_F(WindowSessionImplTest3, SetWatchGestureConsumed, Function | SmallTest | } /** - * @tc.name: NotifyResultToFloatWindow - * @tc.desc: NotifyResultToFloatWindow test + * @tc.name: NotifyConsumeResultToFloatWindow + * @tc.desc: NotifyConsumeResultToFloatWindow test * @tc.type: FUNC */ -HWTEST_F(WindowSessionImplTest3, NotifyResultToFloatWindow, Function | SmallTest | Level2) +HWTEST_F(WindowSessionImplTest3, NotifyConsumeResultToFloatWindow, Function | SmallTest | Level2) { std::shared_ptr keyEvent; keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_TAB); keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN); - bool isConsumed = false; ASSERT_NE(window_, nullptr); window_->SetWatchGestureConsumed(false); - window_->NotifyResultToFloatWindow(keyEvent, isConsumed); + bool isConsumed = false; + window_->NotifyConsumeResultToFloatWindow(keyEvent, isConsumed); ASSERT_EQ(window_->GetWatchGestureConsumed(), false); } } -- Gitee From 58a5958f6c8b3044c261ba452ff2b0a7e72fa2f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E4=B9=A6=E5=8C=85=E6=8C=87=E6=8C=A5=E5=AE=98?= Date: Sat, 28 Dec 2024 12:09:39 +0000 Subject: [PATCH 5/6] update wm/src/window_session_impl.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 红书包指挥官 --- wm/src/window_session_impl.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 5a61e13a95..eca41c60b7 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -3840,6 +3840,8 @@ void WindowSessionImpl::NotifyConsumeResultToFloatWindow GetWindowId(), keyEvent->GetKeyCode(), isConsumed); NotifyWatchGestureConsumeResult(keyEvent->GetKeyCode(), isConsumed); } +} + bool WindowSessionImpl::IsAxisEvent(int32_t action) { if (action != OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_BEGIN && -- Gitee From 24eaa4f8fd9549ba32e5b16e1940c7392051b594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=A2=E4=B9=A6=E5=8C=85=E6=8C=87=E6=8C=A5=E5=AE=98?= Date: Sat, 28 Dec 2024 12:10:53 +0000 Subject: [PATCH 6/6] update wm/test/unittest/window_session_impl_test3.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 红书包指挥官 --- wm/test/unittest/window_session_impl_test3.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wm/test/unittest/window_session_impl_test3.cpp b/wm/test/unittest/window_session_impl_test3.cpp index 546b13db26..456660e625 100644 --- a/wm/test/unittest/window_session_impl_test3.cpp +++ b/wm/test/unittest/window_session_impl_test3.cpp @@ -943,6 +943,9 @@ HWTEST_F(WindowSessionImplTest3, NotifyConsumeResultToFloatWindow, Function | Sm bool isConsumed = false; window_->NotifyConsumeResultToFloatWindow(keyEvent, isConsumed); ASSERT_EQ(window_->GetWatchGestureConsumed(), false); +} + +/* * @tc.name: IsSystemWindow * @tc.desc: IsSystemWindow * @tc.type: FUNC -- Gitee