From 16d37024a363111f0c6e816fd81bc2e15ed0ce20 Mon Sep 17 00:00:00 2001 From: w00574628 Date: Sat, 30 Mar 2024 12:31:46 +0800 Subject: [PATCH] Keyboard Session Refactor Signed-off-by: wulehui --- .../scenesessionmanager_fuzzer.cpp | 7 - .../common/include/window_session_property.h | 8 +- .../common/src/window_session_property.cpp | 17 +- .../src/intention_event_manager.cpp | 2 +- .../js_root_scene_session.cpp | 2 +- .../js_scene_session_manager.cpp | 18 +- .../js_scene_session_manager.h | 4 +- window_scene/session/BUILD.gn | 1 + .../session/host/include/keyboard_session.h | 67 +++ .../session/host/include/scene_session.h | 7 - window_scene/session/host/include/session.h | 9 - .../session/host/include/system_session.h | 10 - .../host/include/zidl/session_interface.h | 6 +- .../include/zidl/session_ipc_interface_code.h | 2 + .../session/host/include/zidl/session_proxy.h | 3 +- .../session/host/include/zidl/session_stub.h | 2 + .../session/host/src/keyboard_session.cpp | 414 ++++++++++++++++++ .../session/host/src/scene_session.cpp | 10 - window_scene/session/host/src/session.cpp | 10 - .../session/host/src/system_session.cpp | 73 +-- .../session/host/src/zidl/session_proxy.cpp | 45 ++ .../session/host/src/zidl/session_stub.cpp | 24 + .../include/scene_session_manager.h | 29 +- .../zidl/scene_session_manager_interface.h | 1 - .../zidl/scene_session_manager_proxy.h | 1 - .../include/zidl/scene_session_manager_stub.h | 1 - .../src/scene_input_manager.cpp | 6 +- .../src/scene_session_manager.cpp | 397 +++-------------- .../src/zidl/scene_session_manager_proxy.cpp | 29 -- .../src/zidl/scene_session_manager_stub.cpp | 13 - .../scene_session_manager_stub_test.cpp | 18 - .../unittest/scene_session_manager_test.cpp | 69 +-- .../test/unittest/scene_session_test.cpp | 20 +- window_scene/test/unittest/session_test.cpp | 15 - .../unittest/window_session_property_test.cpp | 8 +- wm/include/window_scene_session_impl.h | 2 +- wm/include/window_session_impl.h | 1 - wm/src/window_extension_session_impl.cpp | 3 +- wm/src/window_scene_session_impl.cpp | 22 +- wm/src/window_session_impl.cpp | 18 +- 40 files changed, 720 insertions(+), 674 deletions(-) create mode 100644 window_scene/session/host/include/keyboard_session.h create mode 100644 window_scene/session/host/src/keyboard_session.cpp diff --git a/test/fuzztest/window_scene/scenesessionmanager_fuzzer/scenesessionmanager_fuzzer.cpp b/test/fuzztest/window_scene/scenesessionmanager_fuzzer/scenesessionmanager_fuzzer.cpp index 5205d3d5b4..04ac0901cf 100644 --- a/test/fuzztest/window_scene/scenesessionmanager_fuzzer/scenesessionmanager_fuzzer.cpp +++ b/test/fuzztest/window_scene/scenesessionmanager_fuzzer/scenesessionmanager_fuzzer.cpp @@ -180,8 +180,6 @@ void IPCSpecificInterfaceFuzzTest2(sptr proxy, MessageParcel& sen sendData, reply, option); proxy->SendRequest(static_cast(SSMMessage::TRANS_ID_SET_SESSION_CONTINUE_STATE), sendData, reply, option); - proxy->SendRequest(static_cast(SSMMessage::TRANS_ID_SET_SESSION_GRAVITY), - sendData, reply, option); proxy->SendRequest(static_cast(SSMMessage::TRANS_ID_CLEAR_SESSION), sendData, reply, option); proxy->SendRequest(static_cast(SSMMessage::TRANS_ID_CLEAR_ALL_SESSIONS), @@ -313,11 +311,6 @@ void ProxyInterfaceFuzzTestPart3(const uint8_t* data, size_t size) proxy->NotifyDumpInfoResult(info); int32_t persistentId = source.GetObject(); - SessionGravity gravity = source.GetObject(); - uint32_t percent = source.GetObject(); - proxy->SetSessionGravity(persistentId, gravity, percent); - - persistentId = source.GetObject(); proxy->ClearSession(persistentId); proxy->ClearAllSessions(); diff --git a/window_scene/common/include/window_session_property.h b/window_scene/common/include/window_session_property.h index bb21c93ecb..8374e5e13b 100755 --- a/window_scene/common/include/window_session_property.h +++ b/window_scene/common/include/window_session_property.h @@ -64,7 +64,7 @@ public: void SetWindowMode(WindowMode mode); void SetWindowLimits(const WindowLimits& windowLimits); void SetSystemBarProperty(WindowType type, const SystemBarProperty& property); - void SetSessionGravity(SessionGravity gravity_, uint32_t percent); + void SetKeyboardSessionGravity(SessionGravity gravity_, uint32_t percent); void SetDecorEnable(bool isDecorEnable); void SetAnimationFlag(uint32_t animationFlag); void SetTransform(const Transform& trans); @@ -77,7 +77,7 @@ public: void SetTouchHotAreas(const std::vector& rects); void KeepKeyboardOnFocus(bool keepKeyboardFlag); void SetIsNeedUpdateWindowMode(bool isNeedUpdateWindowMode); - void SetCallingWindow(uint32_t windowId); + void SetCallingSessionId(uint32_t sessionId); void SetPiPTemplateInfo(const PiPTemplateInfo& pipTemplateInfo); void SetExtensionFlag(bool isExtensionFlag); void SetWindowMask(const sptr& windowMask); @@ -121,7 +121,7 @@ public: bool IsFloatingWindowAppType() const; void GetTouchHotAreas(std::vector& rects) const; bool GetKeepKeyboardFlag() const; - uint32_t GetCallingWindow() const; + uint32_t GetCallingSessionId() const; PiPTemplateInfo GetPiPTemplateInfo() const; bool GetExtensionFlag() const; sptr GetWindowMask() const; @@ -200,7 +200,7 @@ private: bool hideNonSystemFloatingWindows_ = false; bool forceHide_ = false; bool keepKeyboardFlag_ = false; - uint32_t callingWindowId_ = INVALID_WINDOW_ID; + uint32_t callingSessionId_ = INVALID_SESSION_ID; double textFieldPositionY_ = 0.0; double textFieldHeight_ = 0.0; diff --git a/window_scene/common/src/window_session_property.cpp b/window_scene/common/src/window_session_property.cpp index 440e26923c..e4ed88af21 100755 --- a/window_scene/common/src/window_session_property.cpp +++ b/window_scene/common/src/window_session_property.cpp @@ -353,7 +353,7 @@ void WindowSessionProperty::SetWindowState(WindowState state) windowState_ = state; } -void WindowSessionProperty::SetSessionGravity(SessionGravity gravity, uint32_t percent) +void WindowSessionProperty::SetKeyboardSessionGravity(SessionGravity gravity, uint32_t percent) { sessionGravity_ = gravity; sessionGravitySizePercent_ = percent; @@ -423,14 +423,14 @@ bool WindowSessionProperty::GetKeepKeyboardFlag() const return keepKeyboardFlag_; } -void WindowSessionProperty::SetCallingWindow(uint32_t windowId) +void WindowSessionProperty::SetCallingSessionId(uint32_t sessionId) { - callingWindowId_ = windowId; + callingSessionId_ = sessionId; } -uint32_t WindowSessionProperty::GetCallingWindow() const +uint32_t WindowSessionProperty::GetCallingSessionId() const { - return callingWindowId_; + return callingSessionId_; } void WindowSessionProperty::SetPiPTemplateInfo(const PiPTemplateInfo& pipTemplateInfo) @@ -628,7 +628,7 @@ bool WindowSessionProperty::Marshalling(Parcel& parcel) const parcel.WriteUint32(static_cast(sessionGravity_)) && parcel.WriteUint32(sessionGravitySizePercent_) && parcel.WriteDouble(textFieldPositionY_) && parcel.WriteDouble(textFieldHeight_) && parcel.WriteUint32(static_cast(windowState_)) && - parcel.WriteBool(isNeedUpdateWindowMode_) && parcel.WriteUint32(callingWindowId_) && + parcel.WriteBool(isNeedUpdateWindowMode_) && parcel.WriteUint32(callingSessionId_) && parcel.WriteBool(isLayoutFullScreen_) && parcel.WriteBool(isExtensionFlag_) && MarshallingWindowMask(parcel); @@ -677,12 +677,12 @@ WindowSessionProperty* WindowSessionProperty::Unmarshalling(Parcel& parcel) property->SetFloatingWindowAppType(parcel.ReadBool()); UnmarshallingTouchHotAreas(parcel, property); property->SetSystemCalling(parcel.ReadBool()); - property->SetSessionGravity(static_cast(parcel.ReadUint32()), parcel.ReadUint32()); + property->SetKeyboardSessionGravity(static_cast(parcel.ReadUint32()), parcel.ReadUint32()); property->SetTextFieldPositionY(parcel.ReadDouble()); property->SetTextFieldHeight(parcel.ReadDouble()); property->SetWindowState(static_cast(parcel.ReadUint32())); property->SetIsNeedUpdateWindowMode(parcel.ReadBool()); - property->SetCallingWindow(parcel.ReadUint32()); + property->SetCallingSessionId(parcel.ReadUint32()); property->SetIsLayoutFullScreen(parcel.ReadBool()); property->SetExtensionFlag(parcel.ReadBool()); UnmarshallingWindowMask(parcel, property); @@ -727,6 +727,7 @@ void WindowSessionProperty::CopyFrom(const sptr& property textFieldPositionY_ = property->textFieldPositionY_; textFieldHeight_ = property->textFieldHeight_; isNeedUpdateWindowMode_ = property->isNeedUpdateWindowMode_; + callingSessionId_ = property->callingSessionId_; isLayoutFullScreen_ = property->isLayoutFullScreen_; windowMask_ = property->windowMask_; isShaped_ = property->isShaped_; diff --git a/window_scene/intention_event/src/intention_event_manager.cpp b/window_scene/intention_event/src/intention_event_manager.cpp index de32969594..46a0fa78e7 100644 --- a/window_scene/intention_event/src/intention_event_manager.cpp +++ b/window_scene/intention_event/src/intention_event_manager.cpp @@ -262,7 +262,7 @@ void IntentionEventManager::InputEventListener::OnInputEvent(std::shared_ptrMarkProcessed(); return; } - auto focusedSessionId = SceneSessionManager::GetInstance().GetFocusedSession(); + auto focusedSessionId = SceneSessionManager::GetInstance().GetFocusedSessionId(); if (focusedSessionId == INVALID_SESSION_ID) { TLOGE(WmsLogTag::WMS_EVENT, "focusedSessionId is invalid"); keyEvent->MarkProcessed(); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_root_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_root_scene_session.cpp index 163683720b..ea28143e89 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_root_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_root_scene_session.cpp @@ -254,7 +254,7 @@ void JsRootSceneSession::PendingSessionActivation(SessionInfo& info) TLOGI(WmsLogTag::WMS_LIFE, "[NAPI]session: %{public}d isNeedBackToOther: %{public}d", sceneSession->GetPersistentId(), isNeedBackToOther); if (isNeedBackToOther) { - int32_t realCallerSessionId = SceneSessionManager::GetInstance().GetFocusedSession(); + int32_t realCallerSessionId = SceneSessionManager::GetInstance().GetFocusedSessionId(); if (realCallerSessionId == sceneSession->GetPersistentId()) { TLOGI(WmsLogTag::WMS_LIFE, "[NAPI]caller is self, need back to self caller."); auto scnSession = SceneSessionManager::GetInstance().GetSceneSession(realCallerSessionId); 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 8538c63d92..9d7f7d0555 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 @@ -148,7 +148,7 @@ JsSceneSessionManager::JsSceneSessionManager(napi_env env) : env_(env) { START_UI_ABILITY_ERROR, &JsSceneSessionManager::ProcessStartUIAbilityErrorRegister}, { GESTURE_NAVIGATION_ENABLED_CHANGE_CB, &JsSceneSessionManager::ProcessGestureNavigationEnabledChangeListener }, - { CALLING_WINDOW_ID_CHANGE_CB, &JsSceneSessionManager::ProcessCallingWindowIdChangeRegister}, + { CALLING_WINDOW_ID_CHANGE_CB, &JsSceneSessionManager::ProcessCallingSessionIdChangeRegister}, }; taskScheduler_ = std::make_shared(env); } @@ -322,9 +322,9 @@ void JsSceneSessionManager::OnShiftFocus(int32_t persistentId) taskScheduler_->PostMainThreadTask(task, "OnShiftFocus, PID:" + std::to_string(persistentId)); } -void JsSceneSessionManager::OnCallingWindowIdChange(const uint32_t windowId) +void JsSceneSessionManager::OnCallingSessionIdChange(uint32_t windowId) { - TLOGD(WmsLogTag::WMS_KEYBOARD, "[NAPI]OnCallingWindowIdChange"); + TLOGD(WmsLogTag::WMS_KEYBOARD, "[NAPI]OnCallingSessionIdChange"); auto iter = jsCbMap_.find(CALLING_WINDOW_ID_CHANGE_CB); if (iter == jsCbMap_.end()) { return; @@ -334,7 +334,7 @@ void JsSceneSessionManager::OnCallingWindowIdChange(const uint32_t windowId) napi_value argv[] = { CreateJsValue(env, windowId) }; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }; - taskScheduler_->PostMainThreadTask(task, "OnCallingWindowIdChange, windowId:" + std::to_string(windowId)); + taskScheduler_->PostMainThreadTask(task, "OnCallingSessionIdChange, windowId:" + std::to_string(windowId)); } void JsSceneSessionManager::ProcessCreateSystemSessionRegister() @@ -420,13 +420,13 @@ void JsSceneSessionManager::ProcessShiftFocus() SceneSessionManager::GetInstance().SetSCBUnfocusedListener(unfocusedCallback); } -void JsSceneSessionManager::ProcessCallingWindowIdChangeRegister() +void JsSceneSessionManager::ProcessCallingSessionIdChangeRegister() { - ProcessCallingWindowIdChangeFunc func = [this](uint32_t callingWindowId) { - WLOGFD("ProcessCallingWindowIdChangeRegister called, callingWindowId: %{public}d", callingWindowId); - this->OnCallingWindowIdChange(callingWindowId); + ProcessCallingSessionIdChangeFunc func = [this](uint32_t callingSessionId) { + WLOGFD("ProcessCallingSessionIdChangeRegister called, callingSessionId: %{public}d", callingSessionId); + this->OnCallingSessionIdChange(callingSessionId); }; - SceneSessionManager::GetInstance().SetCallingWindowIdChangeListenser(func); + SceneSessionManager::GetInstance().SetCallingSessionIdSessionListenser(func); } napi_value JsSceneSessionManager::RegisterCallback(napi_env env, napi_callback_info info) 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 0409c14b47..478e26d207 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 @@ -123,7 +123,7 @@ private: void OnOutsideDownEvent(int32_t x, int32_t y); void OnStartUIAbilityError(const uint32_t errorCode); void OnShiftFocus(int32_t persistentId); - void OnCallingWindowIdChange(const uint32_t callingWindowId); + void OnCallingSessionIdChange(uint32_t callingSessionId); void ProcessCreateSystemSessionRegister(); void ProcessRecoverSceneSessionRegister(); void ProcessStatusBarEnabledChangeListener(); @@ -131,7 +131,7 @@ private: void ProcessStartUIAbilityErrorRegister(); void ProcessOutsideDownEvent(); void ProcessShiftFocus(); - void ProcessCallingWindowIdChangeRegister(); + void ProcessCallingSessionIdChangeRegister(); bool IsCallbackRegistered(napi_env env, const std::string& type, napi_value jsListenerObject); void RegisterDumpRootSceneElementInfoListener(); void RegisterVirtualPixelRatioChangeListener(); diff --git a/window_scene/session/BUILD.gn b/window_scene/session/BUILD.gn index 94b7b27f1e..ad7a784e5e 100755 --- a/window_scene/session/BUILD.gn +++ b/window_scene/session/BUILD.gn @@ -48,6 +48,7 @@ ohos_shared_library("scene_session") { "container/src/zidl/window_event_channel_proxy.cpp", "container/src/zidl/window_event_channel_stub.cpp", "host/src/extension_session.cpp", + "host/src/keyboard_session.cpp", "host/src/main_session.cpp", "host/src/move_drag_controller.cpp", "host/src/root_scene_session.cpp", diff --git a/window_scene/session/host/include/keyboard_session.h b/window_scene/session/host/include/keyboard_session.h new file mode 100644 index 0000000000..caeada85df --- /dev/null +++ b/window_scene/session/host/include/keyboard_session.h @@ -0,0 +1,67 @@ +/* + * 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 OHOS_ROSEN_WINDOW_SCENE_KEYBOARD_SESSION_H +#define OHOS_ROSEN_WINDOW_SCENE_KEYBOARD_SESSION_H + +#include "session/host/include/system_session.h" + +namespace OHOS::Rosen { +using OnGetSceneSessionCallback = std::function(uint32_t callingSessionId)>; +using OnGetFocusedSessionIdCallback = std::function; +using OnCallingSessionIdChangeCallback = std::function; + +class KeyboardSession : public SystemSession { +public: + // callback for notify SceneSessionManager + struct KeyboardSessionCallback : public RefBase { + OnGetSceneSessionCallback onGetSceneSession_; + OnGetFocusedSessionIdCallback onGetFocusedSessionId_; + OnCallingSessionIdChangeCallback onCallingSessionIdChange_; + }; + KeyboardSession(const SessionInfo& info, const sptr& specificCallback, + const sptr& keyboardCallback); + ~KeyboardSession(); + + WSError Show(sptr property) override; + WSError Hide() override; + WSError Disconnect(bool isFromClient = false) override; + WSError NotifyClientToUpdateRect(std::shared_ptr rsTransaction) override; + +private: + sptr GetSceneSession(uint32_t persistendId); + int32_t GetFocusedSessionId(); + + WSError SetKeyboardSessionGravity(SessionGravity gravity, uint32_t percent) override; + void SetCallingSessionId(uint32_t callingSessionId) override; + sptr GetCallingSession(); + + bool IsStatusBarVisible(const sptr& session); + int32_t GetStatusBarHeight(); + void NotifyOccupiedAreaChangeInfo(const sptr& callingSession, const WSRect& rect, + const WSRect& occupiedArea); + void RaiseCallingSession(bool isKeyboardUpdated = false); + void RestoreCallingSession(); + void UseFocusIdIfCallingSessionIdInvalid(); + void OnKeyboardSessionShown(); + void UpdateCallingSessionIdAndPosition(uint32_t callingSessionId); + void RelayoutKeyBoard(); + + sptr keyboardCallback_ = nullptr; + WSRect callingSessionRestoringRect_ = {0, 0, 0, 0}; + WSRect callingSessionRaisedRect_ = {0, 0, 0, 0}; +}; +} // namespace OHOS::Rosen +#endif // OHOS_ROSEN_WINDOW_SCENE_KEYBOARD_SESSION_H \ No newline at end of file diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index b5a2b7bcc1..661420e605 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -147,7 +147,6 @@ public: std::vector GetTouchHotAreas() const override; void SetFloatingScale(float floatingScale) override; WSError RaiseAboveTarget(int32_t subWindowId) override; - WSError SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) override; WSError UpdatePiPRect(const Rect& rect, SizeChangeReason reason) override; void NotifyPiPWindowPrepareClose() override; void SetScale(float scaleX, float scaleY, float pivotX, float pivotY) override; @@ -238,8 +237,6 @@ public: void SetSessionState(SessionState state) override; void UpdateSessionState(SessionState state) override; - double textFieldPositionY_ = 0.0; - double textFieldHeight_ = 0.0; std::shared_ptr keepScreenLock_; static const wptr GetEnterWindow(); @@ -248,10 +245,6 @@ public: static std::map windowDragHotAreaMap_; WSError UpdateRectChangeListenerRegistered(bool isRegister) override; - WSRect callingWindowRestoringRect_ = {0, 0, 0, 0}; - WSRect callingWindowNewRect_ = {0, 0, 0, 0}; - bool needUpdateSessionRect_ = false; - protected: void NotifyIsCustomAnimationPlaying(bool isPlaying); void SetMoveDragCallback(); diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index 2610b194e2..19649fd473 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -66,9 +66,6 @@ using NotifySessionExceptionFunc = std::function; using NotifyPendingSessionToForegroundFunc = std::function; using NotifyPendingSessionToBackgroundForDelegatorFunc = std::function; -using NotifyCallingSessionUpdateRectFunc = std::function; -using NotifyCallingSessionForegroundFunc = std::function; -using NotifyCallingSessionBackgroundFunc = std::function; using NotifyRaiseToTopForPointDownFunc = std::function; using NotifyUIRequestFocusFunc = std::function; using NotifyUILostFocusFunc = std::function; @@ -323,12 +320,6 @@ public: float GetPivotX() const; float GetPivotY() const; - virtual void SetNotifyCallingSessionUpdateRectFunc(const NotifyCallingSessionUpdateRectFunc& func) { return; }; - virtual void NotifyCallingSessionUpdateRect() { return; }; - virtual void SetNotifyCallingSessionForegroundFunc(const NotifyCallingSessionForegroundFunc& func) { return; }; - virtual void NotifyCallingSessionForeground() { return; }; - virtual void SetNotifyCallingSessionBackgroundFunc(const NotifyCallingSessionBackgroundFunc& func) { return; }; - virtual void NotifyCallingSessionBackground() { return; }; void SetRaiseToAppTopForPointDownFunc(const NotifyRaiseToTopForPointDownFunc& func); void NotifyScreenshot(); void RemoveLifeCycleTask(const LifeCycleTaskType &taskType); diff --git a/window_scene/session/host/include/system_session.h b/window_scene/session/host/include/system_session.h index 2950392fbb..c5a5d6a18a 100644 --- a/window_scene/session/host/include/system_session.h +++ b/window_scene/session/host/include/system_session.h @@ -32,12 +32,6 @@ public: WSError Disconnect(bool isFromClient = false) override; WSError ProcessPointDownSession(int32_t posX, int32_t posY) override; - void SetNotifyCallingSessionUpdateRectFunc(const NotifyCallingSessionUpdateRectFunc& func) override; - void NotifyCallingSessionUpdateRect() override; - void SetNotifyCallingSessionForegroundFunc(const NotifyCallingSessionForegroundFunc& func) override; - void NotifyCallingSessionForeground() override; - void SetNotifyCallingSessionBackgroundFunc(const NotifyCallingSessionBackgroundFunc& func) override; - void NotifyCallingSessionBackground() override; WSError TransferKeyEvent(const std::shared_ptr& keyEvent) override; WSError ProcessBackEvent() override; @@ -49,10 +43,6 @@ protected: private: void UpdateCameraFloatWindowStatus(bool isShowing); bool NeedSystemPermission(WindowType type); - - NotifyCallingSessionUpdateRectFunc notifyCallingSessionUpdateRectFunc_; - NotifyCallingSessionForegroundFunc notifyCallingSessionForegroundFunc_; - NotifyCallingSessionBackgroundFunc notifyCallingSessionBackgroundFunc_; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SYSTEM_SESSION_H diff --git a/window_scene/session/host/include/zidl/session_interface.h b/window_scene/session/host/include/zidl/session_interface.h index 743e9bd3d4..d6cfb9d90c 100644 --- a/window_scene/session/host/include/zidl/session_interface.h +++ b/window_scene/session/host/include/zidl/session_interface.h @@ -67,7 +67,6 @@ public: bool isShow) { return WSError::WS_OK; } virtual WSError NotifySessionException( const sptr abilitySessionInfo, bool needRemoveSession = false) { return WSError::WS_OK; } - virtual WSError SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) { return WSError::WS_OK; } // extension session virtual WSError TransferAbilityResult(uint32_t resultCode, const AAFwk::Want& want) { return WSError::WS_OK; } @@ -99,6 +98,11 @@ public: { return WSError::WS_OK; } + virtual WSError SetKeyboardSessionGravity(SessionGravity gravity, uint32_t percent) + { + return WSError::WS_OK; + } + virtual void SetCallingSessionId(uint32_t callingSessionId) {}; }; } // namespace OHOS::Rosen diff --git a/window_scene/session/host/include/zidl/session_ipc_interface_code.h b/window_scene/session/host/include/zidl/session_ipc_interface_code.h index ecf2f16c96..31a3c78579 100644 --- a/window_scene/session/host/include/zidl/session_ipc_interface_code.h +++ b/window_scene/session/host/include/zidl/session_ipc_interface_code.h @@ -52,6 +52,8 @@ enum class SessionInterfaceCode { TRANS_ID_SEND_POINTEREVENT_FOR_MOVE_DRAG, TRANS_ID_SET_LANDSCAPE_MULTI_WINDOW, TRANS_ID_UPDATE_RECTCHANGE_LISTENER_REGISTERED, + TRANS_ID_SET_KEYBOARD_SESSION_GRAVITY, + TRANS_ID_SET_CALLING_SESSION_ID, // Extension TRANS_ID_TRANSFER_ABILITY_RESULT = 500, diff --git a/window_scene/session/host/include/zidl/session_proxy.h b/window_scene/session/host/include/zidl/session_proxy.h index ae77f4ada8..2f579ab709 100644 --- a/window_scene/session/host/include/zidl/session_proxy.h +++ b/window_scene/session/host/include/zidl/session_proxy.h @@ -76,7 +76,8 @@ public: WSError ProcessPointDownSession(int32_t posX, int32_t posY) override; WSError SendPointEventForMoveDrag(const std::shared_ptr& pointerEvent) override; WSError UpdateRectChangeListenerRegistered(bool isRegister) override; - + WSError SetKeyboardSessionGravity(SessionGravity gravity, uint32_t percent) override; + void SetCallingSessionId(uint32_t callingSessionId) override; private: static inline BrokerDelegator delegator_; }; diff --git a/window_scene/session/host/include/zidl/session_stub.h b/window_scene/session/host/include/zidl/session_stub.h index 8b8e3772a4..080f5431f9 100644 --- a/window_scene/session/host/include/zidl/session_stub.h +++ b/window_scene/session/host/include/zidl/session_stub.h @@ -66,6 +66,8 @@ private: int HandleSendPointerEvenForMoveDrag(MessageParcel& data, MessageParcel& reply); int HandleSetLandscapeMultiWindow(MessageParcel& data, MessageParcel& reply); int HandleUpdateRectChangeListenerRegistered(MessageParcel& data, MessageParcel& reply); + int HandleSetKeyboardSessionGravity(MessageParcel& data, MessageParcel& reply); + int HandleSetCallingSessionId(MessageParcel& data, MessageParcel& reply); // extension extension int HandleTransferAbilityResult(MessageParcel& data, MessageParcel& reply); diff --git a/window_scene/session/host/src/keyboard_session.cpp b/window_scene/session/host/src/keyboard_session.cpp new file mode 100644 index 0000000000..5ab399978e --- /dev/null +++ b/window_scene/session/host/src/keyboard_session.cpp @@ -0,0 +1,414 @@ +/* + * 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 "session/host/include/keyboard_session.h" +#include "session/host/include/session.h" +#include "common/include/session_permission.h" +#include "display_manager.h" +#include "screen_session_manager/include/screen_session_manager_client.h" +#include "session_helper.h" +#include "window_helper.h" +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { + +KeyboardSession::KeyboardSession(const SessionInfo& info, const sptr& specificCallback, + const sptr& keyboardCallback) + : SystemSession(info, specificCallback) +{ + keyboardCallback_ = keyboardCallback; + TLOGI(WmsLogTag::WMS_KEYBOARD, "Create KeyboardSession"); +} + +KeyboardSession::~KeyboardSession() +{ + TLOGI(WmsLogTag::WMS_KEYBOARD, "~KeyboardSession"); +} + +WSError KeyboardSession::Show(sptr property) +{ + auto task = [weakThis = wptr(this), property]() { + auto session = weakThis.promote(); + if (!session) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Session is null, show keyboard failed"); + return WSError::WS_ERROR_DESTROYED_OBJECT; + } + + TLOGI(WmsLogTag::WMS_KEYBOARD, "Show keyboard session, id: %{public}d", session->GetPersistentId()); + auto ret = session->SceneSession::Foreground(property); + session->OnKeyboardSessionShown(); + return ret; + }; + PostTask(task, "Show"); + return WSError::WS_OK; +} + +WSError KeyboardSession::Hide() +{ + auto task = [weakThis = wptr(this)]() { + auto session = weakThis.promote(); + if (!session) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "session is null, hide keyboard failed!"); + return WSError::WS_ERROR_DESTROYED_OBJECT; + } + + TLOGI(WmsLogTag::WMS_KEYBOARD, "Hide keyboard session, set callingSessionId to 0, id: %{public}d", + session->GetPersistentId()); + auto ret = session->SetActive(false); + if (ret != WSError::WS_OK) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Set session active state failed, ret: %{public}d", ret); + return ret; + } + ret = session->SceneSession::Background(); + session->RestoreCallingSession(); + TLOGI(WmsLogTag::WMS_KEYBOARD, "The soft keyboard is hidden, set the callingSessionId to 0."); + if (session->GetSessionProperty()) { + session->GetSessionProperty()->SetCallingSessionId(INVALID_WINDOW_ID); + } + return ret; + }; + PostTask(task, "Hide"); + return WSError::WS_OK; +} + +WSError KeyboardSession::Disconnect(bool isFromClient) +{ + auto task = [weakThis = wptr(this), isFromClient]() { + auto session = weakThis.promote(); + if (!session) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "session is null, disconnect keyboard session failed!"); + return WSError::WS_ERROR_DESTROYED_OBJECT; + } + TLOGI(WmsLogTag::WMS_KEYBOARD, "Disconnect keyboard session, id: %{public}d, isFromClient: %{public}d", + session->GetPersistentId(), isFromClient); + session->SceneSession::Disconnect(isFromClient); + session->RestoreCallingSession(); + if (session->GetSessionProperty()) { + session->GetSessionProperty()->SetCallingSessionId(INVALID_WINDOW_ID); + } + return WSError::WS_OK; + }; + PostTask(task, "Disconnect"); + return WSError::WS_OK; +} + +WSError KeyboardSession::NotifyClientToUpdateRect(std::shared_ptr rsTransaction) +{ + auto task = [weakThis = wptr(this), rsTransaction]() { + auto session = weakThis.promote(); + WSError ret = session->NotifyClientToUpdateRectTask(weakThis, rsTransaction); + if (ret != WSError::WS_OK) { + return ret; + } + session->RaiseCallingSession(true); + if (session->specificCallback_ != nullptr && session->specificCallback_->onUpdateAvoidArea_ != nullptr) { + session->specificCallback_->onUpdateAvoidArea_(session->GetPersistentId()); + } + if (session->reason_ != SizeChangeReason::DRAG) { + session->reason_ = SizeChangeReason::UNDEFINED; + session->isDirty_ = false; + } + return ret; + }; + PostTask(task, "NotifyClientToUpdateRect"); + return WSError::WS_OK; +} + +WSError KeyboardSession::SetKeyboardSessionGravity(SessionGravity gravity, uint32_t percent) +{ + auto task = [weakThis = wptr(this), gravity, percent]() -> WSError { + auto session = weakThis.promote(); + if (!session) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "keyboard session is null"); + return WSError::WS_ERROR_DESTROYED_OBJECT; + } + TLOGI(WmsLogTag::WMS_KEYBOARD, "persistentId: %{public}d, gravity: %{public}d, percent: %{public}d", + session->GetPersistentId(), gravity, percent); + + if (session->GetSessionProperty()) { + session->GetSessionProperty()->SetKeyboardSessionGravity(gravity, percent); + } + session->RelayoutKeyBoard(); + if (gravity == SessionGravity::SESSION_GRAVITY_FLOAT) { + session->SetWindowAnimationFlag(false); + if (session->IsSessionForeground()) { + session->RestoreCallingSession(); + } + } else { + session->SetWindowAnimationFlag(true); + if (session->IsSessionForeground()) { + session->RaiseCallingSession(); + } + } + return WSError::WS_OK; + }; + PostTask(task, "SetKeyboardSessionGravity"); + return WSError::WS_OK; +} + +void KeyboardSession::SetCallingSessionId(uint32_t callingSessionId) +{ + TLOGI(WmsLogTag::WMS_KEYBOARD, "Calling session id: %{public}d", callingSessionId); + UpdateCallingSessionIdAndPosition(callingSessionId); + if (keyboardCallback_ == nullptr || keyboardCallback_->onCallingSessionIdChange_ == nullptr || + GetSessionProperty() == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "KeyboardCallback_ or sessionProperty is null, callingSessionId: %{public}d", + callingSessionId); + return; + } + keyboardCallback_->onCallingSessionIdChange_(GetSessionProperty()->GetCallingSessionId()); +} + +sptr KeyboardSession::GetSceneSession(uint32_t persistendId) +{ + if (keyboardCallback_ == nullptr || keyboardCallback_->onGetSceneSession_ == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Get scene session failed, persistendId: %{public}d", persistendId); + return nullptr; + } + return keyboardCallback_->onGetSceneSession_(persistendId); +} + +int32_t KeyboardSession::GetFocusedSessionId() +{ + if (keyboardCallback_ == nullptr || keyboardCallback_->onGetFocusedSessionId_ == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "keyboardCallback_ is nullptr, get focusedSessionId failed!"); + return INVALID_WINDOW_ID; + } + return keyboardCallback_->onGetFocusedSessionId_(); +} + +bool KeyboardSession::IsStatusBarVisible(const sptr& statusBarSession) +{ + if (statusBarSession == nullptr) { + return false; + } + if (statusBarSession->IsVisible()) { + TLOGD(WmsLogTag::WMS_KEYBOARD, "Status Bar is at foreground, id: %{public}d", + statusBarSession->GetPersistentId()); + return true; + } + TLOGD(WmsLogTag::WMS_KEYBOARD, "Status Bar is at background, id: %{public}d", statusBarSession->GetPersistentId()); + return false; +} + +int32_t KeyboardSession::GetStatusBarHeight() +{ + int32_t statusBarHeight = 0; + int32_t height = 0; + if (specificCallback_ == nullptr || specificCallback_->onGetSceneSessionVectorByType_ == nullptr || + GetSessionProperty() == nullptr) { + return statusBarHeight; + } + + std::vector> statusBarVector = specificCallback_->onGetSceneSessionVectorByType_( + WindowType::WINDOW_TYPE_STATUS_BAR, GetSessionProperty()->GetDisplayId()); + for (const auto& statusBar : statusBarVector) { + if (statusBar == nullptr || !IsStatusBarVisible(statusBar)) { + continue; + } + height = statusBar->GetSessionRect().height_; + statusBarHeight = (statusBarHeight > height) ? statusBarHeight : height; + } + TLOGI(WmsLogTag::WMS_KEYBOARD, "Status Bar height: %{public}d", statusBarHeight); + return statusBarHeight; +} + +void KeyboardSession::NotifyOccupiedAreaChangeInfo(const sptr& callingSession, const WSRect& rect, + const WSRect& occupiedArea) +{ + // if keyboard will occupy calling, notify calling window the occupied area and safe height + const WSRect& safeRect = SessionHelper::GetOverlap(occupiedArea, rect, 0, 0); + const WSRect& lastSafeRect = callingSession->GetLastSafeRect(); + TLOGI(WmsLogTag::WMS_KEYBOARD, "lastSafeRect: %{public}s, safeRect: %{public}s", + lastSafeRect.ToString().c_str(), safeRect.ToString().c_str()); + if (lastSafeRect == safeRect) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "lastSafeRect is same to safeRect"); + return; + } + callingSession->SetLastSafeRect(safeRect); + double textFieldPositionY = 0.0; + double textFieldHeight = 0.0; + if (GetSessionProperty() != nullptr) { + textFieldPositionY = GetSessionProperty()->GetTextFieldPositionY(); + textFieldHeight = GetSessionProperty()->GetTextFieldHeight(); + } + sptr info = new OccupiedAreaChangeInfo(OccupiedAreaType::TYPE_INPUT, + SessionHelper::TransferToRect(safeRect), safeRect.height_, textFieldPositionY, textFieldHeight); + TLOGI(WmsLogTag::WMS_KEYBOARD, "OccupiedAreaChangeInfo rect: %{public}s, textFieldPositionY_: %{public}f" + ", textFieldHeight_: %{public}f", occupiedArea.ToString().c_str(), textFieldPositionY, textFieldHeight); + callingSession->NotifyOccupiedAreaChangeInfo(info); +} + +sptr KeyboardSession::GetCallingSession() +{ + sptr callingSession = nullptr; + if (GetSessionProperty() != nullptr) { + callingSession = GetSceneSession(GetSessionProperty()->GetCallingSessionId()); + } + + return callingSession; +} + +void KeyboardSession::RaiseCallingSession(bool isKeyboardUpdated) +{ + sptr callingSession = GetCallingSession(); + if (callingSession == nullptr) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "Calling session is nullptr"); + return; + } + SessionGravity gravity = SessionGravity::SESSION_GRAVITY_DEFAULT; + uint32_t percent = 0; + GetSessionProperty()->GetSessionGravity(gravity, percent); + if (gravity == SessionGravity::SESSION_GRAVITY_FLOAT) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "No need to raise calling session, gravity: %{public}d", gravity); + return; + } + + WSRect callingSessionRect = callingSession->GetSessionRect(); + bool isCallingSessionFloating = (callingSession->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING); + if (isKeyboardUpdated && isCallingSessionFloating) { + callingSessionRect = callingSessionRestoringRect_; + } + const WSRect& keyboardSessionRect = (GetSessionRect().height_ != 0) ? GetSessionRect() : GetSessionRequestRect(); + TLOGI(WmsLogTag::WMS_KEYBOARD, "keyboardSessionRect: %{public}s, callingSessionRect: %{public}s" + ", isCallingSessionFloating: %{public}d, isKeyboardUpdated: %{public}d", keyboardSessionRect.ToString().c_str(), + callingSessionRect.ToString().c_str(), isCallingSessionFloating, isKeyboardUpdated); + if (SessionHelper::IsEmptyRect(SessionHelper::GetOverlap(keyboardSessionRect, callingSessionRect, 0, 0))) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "There is no overlap area"); + return; + } + + if (!isKeyboardUpdated) { + callingSessionRestoringRect_ = callingSessionRect; + } + + WSRect newRect = callingSessionRect; + int32_t statusHeight = GetStatusBarHeight(); + if (isCallingSessionFloating && callingSessionRect.posY_ > statusHeight) { + // calculate new rect of calling window + newRect.posY_ = std::max(keyboardSessionRect.posY_ - static_cast(newRect.height_), statusHeight); + NotifyOccupiedAreaChangeInfo(callingSession, newRect, keyboardSessionRect); + callingSession->UpdateSessionRect(newRect, SizeChangeReason::UNDEFINED); + callingSessionRaisedRect_ = callingSession->GetSessionRect(); + } else { + NotifyOccupiedAreaChangeInfo(callingSession, newRect, keyboardSessionRect); + } +} + +void KeyboardSession::RestoreCallingSession() +{ + sptr callingSession = GetCallingSession(); + if (callingSession == nullptr) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "Calling session is nullptr"); + return; + } + + TLOGI(WmsLogTag::WMS_KEYBOARD, "Calling session, RestoringRect_: %{public}s, RaisedRect_: %{public}s" + ", curRect_: %{public}s, sessionMode: %{public}d", callingSessionRestoringRect_.ToString().c_str(), + callingSessionRaisedRect_.ToString().c_str(), callingSession->GetSessionRect().ToString().c_str(), + callingSession->GetWindowMode()); + WSRect overlapRect = { 0, 0, 0, 0 }; + NotifyOccupiedAreaChangeInfo(callingSession, callingSessionRestoringRect_, overlapRect); + if (!SessionHelper::IsEmptyRect(callingSessionRestoringRect_) && + callingSession->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING && + callingSession->GetSessionRect() == callingSessionRaisedRect_) { + callingSession->UpdateSessionRect(callingSessionRestoringRect_, SizeChangeReason::UNDEFINED); + } + callingSessionRestoringRect_ = { 0, 0, 0, 0 }; + callingSessionRaisedRect_ = { 0, 0, 0, 0 }; +} + +// Use focused session id when calling session id is invalid. +void KeyboardSession::UseFocusIdIfCallingSessionIdInvalid() +{ + if (GetCallingSession() != nullptr) { + return; + } + uint32_t focusedSessionId = GetFocusedSessionId(); + if (GetSceneSession(focusedSessionId) == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Focused session is null, id: %{public}d", focusedSessionId); + } else { + TLOGI(WmsLogTag::WMS_KEYBOARD, "Using focusedSession id: %{public}d", focusedSessionId); + GetSessionProperty()->SetCallingSessionId(focusedSessionId); + } +} + +void KeyboardSession::OnKeyboardSessionShown() +{ + if (GetSessionProperty() == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Keyboard session property is nullptr, raise calling session failed."); + return; + } + UseFocusIdIfCallingSessionIdInvalid(); + TLOGI(WmsLogTag::WMS_KEYBOARD, "Raise keyboard session, persistentId: %{public}d, callingSessionId: %{public}d", + GetPersistentId(), GetSessionProperty()->GetCallingSessionId()); + RaiseCallingSession(); +} + +void KeyboardSession::UpdateCallingSessionIdAndPosition(uint32_t callingSessionId) +{ + if (GetSessionProperty() == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Session property is nullptr."); + return; + } + uint32_t curSessionId = GetSessionProperty()->GetCallingSessionId(); + // When calling window id changes, restore the old calling session, raise the new calling session. + if (curSessionId != INVALID_WINDOW_ID && callingSessionId != curSessionId) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "CallingSession curId: %{public}d, newId: %{public}d", + curSessionId, callingSessionId); + RestoreCallingSession(); + + GetSessionProperty()->SetCallingSessionId(callingSessionId); + UseFocusIdIfCallingSessionIdInvalid(); + RaiseCallingSession(); + } else { + GetSessionProperty()->SetCallingSessionId(callingSessionId); + } +} + +void KeyboardSession::RelayoutKeyBoard() +{ + if (GetSessionProperty() == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Session property is nullptr, relayout keyboard failed"); + return; + } + SessionGravity gravity = SessionGravity::SESSION_GRAVITY_DEFAULT; + uint32_t percent = 0; + GetSessionProperty()->GetSessionGravity(gravity, percent); + TLOGI(WmsLogTag::WMS_KEYBOARD, "Gravity: %{public}d, percent: %{public}d", gravity, percent); + if (gravity == SessionGravity::SESSION_GRAVITY_FLOAT) { + return; + } + auto displayId = GetSessionProperty()->GetDisplayId(); + auto screenSession = ScreenSessionManagerClient::GetInstance().GetScreenSession(displayId); + uint32_t screenWidth = screenSession->GetScreenProperty().GetBounds().rect_.width_; + uint32_t screenHeight = screenSession->GetScreenProperty().GetBounds().rect_.height_; + + auto requestRect = GetSessionProperty()->GetRequestRect(); + if (gravity == SessionGravity::SESSION_GRAVITY_BOTTOM) { + requestRect.width_ = static_cast(screenWidth); + requestRect.posX_ = 0; + if (percent != 0) { + // 100: for calc percent. + requestRect.height_ = static_cast(screenHeight) * percent / 100u; + } + } + requestRect.posY_ = screenHeight - static_cast(requestRect.height_); + GetSessionProperty()->SetRequestRect(requestRect); + TLOGI(WmsLogTag::WMS_KEYBOARD, "Id: %{public}d, rect: %{public}s", GetPersistentId(), + SessionHelper::TransferToWSRect(requestRect).ToString().c_str()); + UpdateSessionRect(SessionHelper::TransferToWSRect(requestRect), SizeChangeReason::UNDEFINED); +} +} // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index f0f8ed72a7..4e2cbf6c09 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -134,9 +134,6 @@ WSError SceneSession::Foreground(sptr property) session->GetSessionProperty()->SetDecorEnable(property->IsDecorEnable()); } - if (property) { - weakThis->SetTextFieldAvoidInfo(property->GetTextFieldPositionY(), property->GetTextFieldHeight()); - } auto ret = session->Session::Foreground(property); if (ret != WSError::WS_OK) { return ret; @@ -2287,13 +2284,6 @@ void SceneSession::NotifySessionBackground(uint32_t reason, bool withAnimation, return sessionStage_->NotifySessionBackground(reason, withAnimation, isFromInnerkits); } -WSError SceneSession::SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) -{ - textFieldPositionY_ = textFieldPositionY; - textFieldHeight_ = textFieldHeight; - return WSError::WS_OK; -} - WSError SceneSession::UpdatePiPRect(const Rect& rect, SizeChangeReason reason) { if (!WindowHelper::IsPipWindow(GetWindowType())) { diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 6bc6b06ae9..22783f2b11 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -852,9 +852,6 @@ WSError Session::Foreground(sptr property) SetSessionState(SessionState::STATE_BACKGROUND); } - if (GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { - NotifyCallingSessionForeground(); - } NotifyForeground(); return WSError::WS_OK; } @@ -935,13 +932,6 @@ WSError Session::Background() return WSError::WS_ERROR_INVALID_SESSION; } UpdateSessionState(SessionState::STATE_BACKGROUND); - if (GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { - NotifyCallingSessionBackground(); - if (property_) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "When the soft keyboard is hidden, set the callingWindowId to 0."); - property_->SetCallingWindow(INVALID_WINDOW_ID); - } - } NotifyBackground(); DelayedSingleton::GetInstance()->OnBackground(persistentId_); return WSError::WS_OK; diff --git a/window_scene/session/host/src/system_session.cpp b/window_scene/session/host/src/system_session.cpp index e534f34ea9..9203e9c168 100644 --- a/window_scene/session/host/src/system_session.cpp +++ b/window_scene/session/host/src/system_session.cpp @@ -85,14 +85,9 @@ WSError SystemSession::Show(sptr property) WSError SystemSession::Hide() { auto type = GetWindowType(); - if (WindowHelper::IsSystemWindow(type) && NeedSystemPermission(type)) { - if (type == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT || - type == WindowType::WINDOW_TYPE_INPUT_METHOD_STATUS_BAR) { - if (!SessionPermission::IsStartedByInputMethod()) { - TLOGE(WmsLogTag::WMS_LIFE, "Hide permission denied, keyboard is not hidden by current input method"); - return WSError::WS_ERROR_INVALID_PERMISSION; - } - } else if (!SessionPermission::IsSystemCalling()) { + if (NeedSystemPermission(type)) { + // Do not need to verify the permission to hide the input method status bar. + if (!SessionPermission::IsSystemCalling() && type != WindowType::WINDOW_TYPE_INPUT_METHOD_STATUS_BAR) { TLOGE(WmsLogTag::WMS_LIFE, "Hide permission denied id: %{public}d type:%{public}u", GetPersistentId(), type); return WSError::WS_ERROR_INVALID_PERMISSION; @@ -166,9 +161,6 @@ WSError SystemSession::Disconnect(bool isFromClient) } TLOGI(WmsLogTag::WMS_LIFE, "Disconnect session, id: %{public}d", session->GetPersistentId()); session->SceneSession::Disconnect(isFromClient); - if (session->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { - session->NotifyCallingSessionBackground(); - } session->UpdateCameraFloatWindowStatus(false); return WSError::WS_OK; }; @@ -195,45 +187,6 @@ WSError SystemSession::ProcessPointDownSession(int32_t posX, int32_t posY) return SceneSession::ProcessPointDownSession(posX, posY); } -void SystemSession::SetNotifyCallingSessionUpdateRectFunc(const NotifyCallingSessionUpdateRectFunc& func) -{ - notifyCallingSessionUpdateRectFunc_ = func; -} - -void SystemSession::SetNotifyCallingSessionForegroundFunc(const NotifyCallingSessionForegroundFunc& func) -{ - notifyCallingSessionForegroundFunc_ = func; -} - -void SystemSession::SetNotifyCallingSessionBackgroundFunc(const NotifyCallingSessionBackgroundFunc& func) -{ - notifyCallingSessionBackgroundFunc_ = func; -} - -void SystemSession::NotifyCallingSessionUpdateRect() -{ - if ((GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) && notifyCallingSessionUpdateRectFunc_) { - WLOGFI("Notify calling window that input method update rect"); - notifyCallingSessionUpdateRectFunc_(persistentId_); - } -} - -void SystemSession::NotifyCallingSessionForeground() -{ - if ((GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) && notifyCallingSessionForegroundFunc_) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "Notify calling window that input method shown"); - notifyCallingSessionForegroundFunc_(persistentId_); - } -} - -void SystemSession::NotifyCallingSessionBackground() -{ - if ((GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) && notifyCallingSessionBackgroundFunc_) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "Notify calling window that input method hide"); - notifyCallingSessionBackgroundFunc_(); - } -} - WSError SystemSession::TransferKeyEvent(const std::shared_ptr& keyEvent) { if (!IsSessionValid()) { @@ -278,17 +231,15 @@ WSError SystemSession::NotifyClientToUpdateRect(std::shared_ptr r auto task = [weakThis = wptr(this), rsTransaction]() { auto session = weakThis.promote(); WSError ret = session->NotifyClientToUpdateRectTask(weakThis, rsTransaction); - if (ret == WSError::WS_OK) { - if (session->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { - session->NotifyCallingSessionUpdateRect(); - } - if (session->specificCallback_ != nullptr && session->specificCallback_->onUpdateAvoidArea_ != nullptr) { - session->specificCallback_->onUpdateAvoidArea_(session->GetPersistentId()); - } - if (session->reason_ != SizeChangeReason::DRAG) { - session->reason_ = SizeChangeReason::UNDEFINED; - session->isDirty_ = false; - } + if (ret != WSError::WS_OK) { + return ret; + } + if (session->specificCallback_ != nullptr && session->specificCallback_->onUpdateAvoidArea_ != nullptr) { + session->specificCallback_->onUpdateAvoidArea_(session->GetPersistentId()); + } + if (session->reason_ != SizeChangeReason::DRAG) { + session->reason_ = SizeChangeReason::UNDEFINED; + session->isDirty_ = false; } return ret; }; diff --git a/window_scene/session/host/src/zidl/session_proxy.cpp b/window_scene/session/host/src/zidl/session_proxy.cpp index f53a89e6f6..24dc77cd40 100644 --- a/window_scene/session/host/src/zidl/session_proxy.cpp +++ b/window_scene/session/host/src/zidl/session_proxy.cpp @@ -1097,4 +1097,49 @@ WSError SessionProxy::UpdateRectChangeListenerRegistered(bool isRegister) int32_t ret = reply.ReadInt32(); return static_cast(ret); } + +WSError SessionProxy::SetKeyboardSessionGravity(SessionGravity gravity, uint32_t percent) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + if (!data.WriteUint32(static_cast(gravity))) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Write gravity failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + if (!data.WriteUint32(percent)) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Write percent failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(static_cast(SessionInterfaceCode::TRANS_ID_SET_KEYBOARD_SESSION_GRAVITY), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + return static_cast(reply.ReadInt32()); +} + +void SessionProxy::SetCallingSessionId(const uint32_t callingSessionId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "writeInterfaceToken failed"); + return; + } + if (!data.WriteUint32(callingSessionId)) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Write callingSessionId failed."); + return; + } + if (Remote()->SendRequest(static_cast(SessionInterfaceCode::TRANS_ID_SET_CALLING_SESSION_ID), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest failed"); + return; + } +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/zidl/session_stub.cpp b/window_scene/session/host/src/zidl/session_stub.cpp index 0f7569885b..6065b17b4f 100644 --- a/window_scene/session/host/src/zidl/session_stub.cpp +++ b/window_scene/session/host/src/zidl/session_stub.cpp @@ -97,6 +97,10 @@ const std::map SessionStub::stubFuncMap_ { &SessionStub::HandleProcessPointDownSession), std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_SEND_POINTEREVENT_FOR_MOVE_DRAG), &SessionStub::HandleSendPointerEvenForMoveDrag), + std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_SET_KEYBOARD_SESSION_GRAVITY), + &SessionStub::HandleSetKeyboardSessionGravity), + std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_SET_CALLING_SESSION_ID), + &SessionStub::HandleSetCallingSessionId), std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_TRANSFER_ABILITY_RESULT), &SessionStub::HandleTransferAbilityResult), @@ -624,4 +628,24 @@ int SessionStub::HandleUpdateRectChangeListenerRegistered(MessageParcel& data, M reply.WriteUint32(static_cast(errCode)); return ERR_NONE; } + +int SessionStub::HandleSetKeyboardSessionGravity(MessageParcel &data, MessageParcel &reply) +{ + TLOGD(WmsLogTag::WMS_KEYBOARD, "run HandleSetKeyboardSessionGravity!"); + SessionGravity gravity = static_cast(data.ReadUint32()); + uint32_t percent = data.ReadUint32(); + WSError ret = SetKeyboardSessionGravity(gravity, percent); + reply.WriteInt32(static_cast(ret)); + return ERR_NONE; +} + +int SessionStub::HandleSetCallingSessionId(MessageParcel& data, MessageParcel& reply) +{ + TLOGD(WmsLogTag::WMS_KEYBOARD, "run HandleSetCallingSessionId!"); + uint32_t callingSessionId = data.ReadUint32(); + + SetCallingSessionId(callingSessionId); + reply.WriteInt32(static_cast(WSError::WS_OK)); + return ERR_NONE; +} } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index ce995e235c..805dfec878 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -31,6 +31,7 @@ #include "scene_session_converter.h" #include "scb_session_handler.h" #include "session/host/include/root_scene_session.h" +#include "session/host/include/keyboard_session.h" #include "session_manager/include/zidl/scene_session_manager_stub.h" #include "wm_single_instance.h" #include "window_scene_config.h" @@ -78,7 +79,7 @@ using CmpFunc = std::function>& lhs, std::pair>& rhs)>; using ProcessStartUIAbilityErrorFunc = std::function; using NotifySCBAfterUpdateFocusFunc = std::function; -using ProcessCallingWindowIdChangeFunc = std::function; +using ProcessCallingSessionIdChangeFunc = std::function; using FlushWindowInfoTask = std::function; using ProcessVirtualPixelRatioChangeFunc = std::function; @@ -147,7 +148,7 @@ public: void SetShiftFocusListener(const ProcessShiftFocusFunc& func); void SetSCBFocusedListener(const NotifySCBAfterUpdateFocusFunc& func); void SetSCBUnfocusedListener(const NotifySCBAfterUpdateFocusFunc& func); - void SetCallingWindowIdChangeListenser(const ProcessCallingWindowIdChangeFunc& func); + void SetCallingSessionIdSessionListenser(const ProcessCallingSessionIdChangeFunc& func); const AppWindowSceneConfig& GetWindowSceneConfig() const; WSError ProcessBackEvent(); WSError BindDialogSessionTarget(uint64_t persistentId, sptr targetToken) override; @@ -158,8 +159,8 @@ public: WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) override; - WSError SetFocusedSession(int32_t persistentId); - int32_t GetFocusedSession() const; + WSError SetFocusedSessionId(int32_t persistentId); + int32_t GetFocusedSessionId() const; WSError GetAllSessionDumpInfo(std::string& info); WSError GetSpecifiedSessionDumpInfo(std::string& dumpInfo, const std::vector& params, const std::string& strId); @@ -179,7 +180,6 @@ public: void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; void NotifyCompleteFirstFrameDrawing(int32_t persistentId); void NotifySessionMovedToFront(int32_t persistentId); - WSError SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent) override; WSError SetSessionLabel(const sptr &token, const std::string &label) override; WSError SetSessionIcon(const sptr &token, const std::shared_ptr &icon) override; WSError IsValidSessionIds(const std::vector &sessionIds, std::vector &results) override; @@ -227,8 +227,6 @@ public: WMError GetAccessibilityWindowInfo(std::vector>& infos) override; WSError SetWindowFlags(const sptr& sceneSession, const sptr& property); - void NotifyOccupiedAreaChangeInfo(const sptr sceneSession, - const WSRect& rect, const WSRect& occupiedArea); void OnScreenshot(DisplayId displayId); void NotifyDumpInfoResult(const std::vector& info) override; void SetVirtualPixelRatioChangeListener(const ProcessVirtualPixelRatioChangeFunc& func); @@ -322,6 +320,7 @@ private: std::tuple> CreateCurve(const WindowSceneConfig::ConfigItem& curveConfig); void LoadKeyboardAnimation(const WindowSceneConfig::ConfigItem& item, KeyboardSceneAnimationConfig& config); sptr CreateSpecificSessionCallback(); + sptr CreateKeyboardSessionCallback(); void FillSessionInfo(sptr& sceneSession); std::shared_ptr QueryAbilityInfoFromBMS(const int32_t uId, const std::string& bundleName, const std::string& abilityName, const std::string& moduleName); @@ -346,12 +345,6 @@ private: void RegisterRequestFocusStatusNotifyManagerFunc(sptr& sceneSession); void RegisterGetStateFromManagerFunc(sptr& sceneSession); - void UpdateCallingWindowIdAndPosition(const sptr& property, - const sptr& sceneSession); - void RelayoutKeyBoard(sptr sceneSession); - void RestoreCallingSessionSizeIfNeed(); - void ResizeSoftInputCallingSessionIfNeed(const sptr& sceneSession, bool isInputUpdated = false); - sptr SetAbilitySessionInfo(const sptr& scnSession); WSError DestroyDialogWithMainWindow(const sptr& scnSession); sptr FindMainWindowWithToken(sptr targetToken); @@ -366,7 +359,6 @@ private: void UpdateNormalSessionAvoidArea(const int32_t& persistentId, sptr& sceneSession, bool& needUpdate); void UpdateAvoidArea(const int32_t& persistentId); void NotifyMMIWindowPidChange(int32_t windowId, bool startMoving); - int32_t GetStatusBarHeight(uint64_t displayId); sptr GetBundleManager(); std::shared_ptr GetResourceManager(const AppExecFwk::AbilityInfo& abilityInfo); @@ -408,11 +400,6 @@ private: void WindowLayerInfoChangeCallback(std::shared_ptr occlusiontionData); sptr SelectSesssionFromMap(const uint64_t& surfaceId); void WindowDestroyNotifyVisibility(const sptr& sceneSession); - void RegisterInputMethodUpdateFunc(const sptr& sceneSession); - void OnInputMethodUpdate(const int32_t& persistentId); - void RegisterInputMethodShownFunc(const sptr& sceneSession); - void OnInputMethodShown(const int32_t& persistentId); - void RegisterInputMethodHideFunc(const sptr& sceneSession); void RegisterSessionExceptionFunc(const sptr& sceneSession); void RegisterSessionSnapshotFunc(const sptr& sceneSession); void NotifySessionForCallback(const sptr& scnSession, const bool needRemoveSession); @@ -465,7 +452,7 @@ private: ProcessShiftFocusFunc shiftFocusFunc_; NotifySCBAfterUpdateFocusFunc notifySCBAfterFocusedFunc_; NotifySCBAfterUpdateFocusFunc notifySCBAfterUnfocusedFunc_; - ProcessCallingWindowIdChangeFunc callingWindowIdChangeFunc_; + ProcessCallingSessionIdChangeFunc callingSessionIdChangeFunc_; ProcessStartUIAbilityErrorFunc startUIAbilityErrorFunc_; ProcessVirtualPixelRatioChangeFunc processVirtualPixelRatioChangeFunc_ = nullptr; AppWindowSceneConfig appWindowSceneConfig_; @@ -518,7 +505,6 @@ private: std::bind(&SceneSessionManager::DestroySpecificSession, this, std::placeholders::_1)); sptr extensionDeath_ = new AgentDeathRecipient( std::bind(&SceneSessionManager::DestroyExtensionSession, this, std::placeholders::_1)); - sptr callingSession_ = nullptr; WSError ClearSession(sptr sceneSession); bool IsSessionClearable(sptr scnSession); @@ -569,6 +555,7 @@ private: void HandleCastScreenDisConnection(const sptr sceneSession); void ProcessSplitFloating(); void NotifyRSSWindowModeTypeUpdate(bool inSplit, bool inFloating); + bool IsKeyboardForeground(); }; } // namespace OHOS::Rosen 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 572f62ad7b..9aa06355a9 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 @@ -55,7 +55,6 @@ public: TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT, TRANS_ID_BIND_DIALOG_TARGET, TRANS_ID_GET_FOCUS_SESSION_INFO, - TRANS_ID_SET_SESSION_GRAVITY, TRANS_ID_SET_SESSION_LABEL, TRANS_ID_SET_SESSION_ICON, TRANS_ID_IS_VALID_SESSION_IDS, 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 bbc87d99f1..fa5d42c133 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 @@ -48,7 +48,6 @@ public: const sptr& windowManagerAgent) override; WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) override; - WSError SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent) override; WMError SetGestureNavigaionEnabled(bool enable) override; void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; WSError SetSessionLabel(const sptr &token, const std::string &label) 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 1e629e3f39..6f5e4be6bd 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 @@ -55,7 +55,6 @@ private: int HandleGetFocusSessionToken(MessageParcel &data, MessageParcel &reply); int HandleGetFocusSessionElement(MessageParcel& data, MessageParcel& reply); int HandleSetGestureNavigationEnabled(MessageParcel &data, MessageParcel &reply); - int HandleSetSessionGravity(MessageParcel &data, MessageParcel &reply); int HandleCheckWindowId(MessageParcel &data, MessageParcel &reply); int HandleRegisterSessionListener(MessageParcel& data, MessageParcel& reply); diff --git a/window_scene/session_manager/src/scene_input_manager.cpp b/window_scene/session_manager/src/scene_input_manager.cpp index d7526c59ec..a3038f2c0f 100644 --- a/window_scene/session_manager/src/scene_input_manager.cpp +++ b/window_scene/session_manager/src/scene_input_manager.cpp @@ -254,7 +254,7 @@ void SceneInputManager::FlushFullInfoToMMI(const std::vector& return; } - int32_t focusId = Rosen::SceneSessionManager::GetInstance().GetFocusedSession(); + int32_t focusId = Rosen::SceneSessionManager::GetInstance().GetFocusedSessionId(); MMI::DisplayGroupInfo displayGroupInfo = { .width = mainScreenWidth, .height = mainScreenHeight, @@ -308,7 +308,7 @@ void SceneInputManager::FlushChangeInfoToMMI(const std::mapUpdateWindowInfo(windowGroup); } @@ -317,7 +317,7 @@ void SceneInputManager::FlushChangeInfoToMMI(const std::map& displayInfos, const std::vector& windowInfoList) { - int32_t focusId = Rosen::SceneSessionManager::GetInstance().GetFocusedSession(); + int32_t focusId = Rosen::SceneSessionManager::GetInstance().GetFocusedSessionId(); if (focusId != lastFocusId_) { lastFocusId_ = focusId; return true; diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 925e1bc69f..4f0c54282c 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -940,6 +940,21 @@ sptr SceneSessionManager::CreateSpecificS return specificCb; } +sptr SceneSessionManager::CreateKeyboardSessionCallback() +{ + sptr keyboardCb = + new (std::nothrow)KeyboardSession::KeyboardSessionCallback(); + if (keyboardCb == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "KeyboardSessionCallback is nullptr"); + return keyboardCb; + } + keyboardCb->onGetSceneSession_ = std::bind(&SceneSessionManager::GetSceneSession, this, std::placeholders::_1); + keyboardCb->onGetFocusedSessionId_ = std::bind(&SceneSessionManager::GetFocusedSessionId, this); + keyboardCb->onCallingSessionIdChange_ = callingSessionIdChangeFunc_; + + return keyboardCb; +} + WMError SceneSessionManager::CheckWindowId(int32_t windowId, int32_t &pid) { auto task = [this, windowId, &pid]() -> WMError { @@ -976,6 +991,10 @@ sptr SceneSessionManager::CreateSceneSession(const SessionInfo& se } else if (property != nullptr && SessionHelper::IsSubWindow(property->GetWindowType())) { sceneSession = new (std::nothrow) SubSession(sessionInfo, specificCb); TLOGI(WmsLogTag::WMS_SUB, "Create SubSession, type: %{public}d", property->GetWindowType()); + } else if (property != nullptr && property->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { + sptr keyboardCb = CreateKeyboardSessionCallback(); + sceneSession = new (std::nothrow) KeyboardSession(sessionInfo, specificCb, keyboardCb); + TLOGI(WmsLogTag::WMS_KEYBOARD, "Create KeyboardSession, type: %{public}d", property->GetWindowType()); } else if (property != nullptr && SessionHelper::IsSystemWindow(property->GetWindowType())) { sceneSession = new (std::nothrow) SystemSession(sessionInfo, specificCb); TLOGI(WmsLogTag::WMS_SYSTEM, "Create SystemSession, type: %{public}d", property->GetWindowType()); @@ -1086,9 +1105,6 @@ void SceneSessionManager::PerformRegisterInRequestSceneSession(sptr& sess } } -void SceneSessionManager::RegisterInputMethodUpdateFunc(const sptr& sceneSession) -{ - if (sceneSession == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "session is nullptr"); - return; - } - NotifyCallingSessionForegroundFunc onInputMethodUpdate = [this](int32_t persistentId) { - this->OnInputMethodUpdate(persistentId); - }; - sceneSession->SetNotifyCallingSessionUpdateRectFunc(onInputMethodUpdate); - TLOGD(WmsLogTag::WMS_KEYBOARD, "RegisterInputMethodUpdateFunc success"); -} - -void SceneSessionManager::OnInputMethodUpdate(const int32_t& persistentId) -{ - auto scnSession = GetSceneSession(persistentId); - if (scnSession == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "Input method is null"); - return; - } - TLOGD(WmsLogTag::WMS_KEYBOARD, "persistentId: %{public}d, windowType: %{public}d", - persistentId, scnSession->GetWindowType()); - ResizeSoftInputCallingSessionIfNeed(scnSession, true); -} - -void SceneSessionManager::RegisterInputMethodShownFunc(const sptr& sceneSession) -{ - if (sceneSession == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "session is nullptr"); - return; - } - NotifyCallingSessionForegroundFunc onInputMethodShown = [this](int32_t persistentId) { - this->OnInputMethodShown(persistentId); - }; - sceneSession->SetNotifyCallingSessionForegroundFunc(onInputMethodShown); - TLOGD(WmsLogTag::WMS_KEYBOARD, "RegisterInputMethodShownFunc success"); -} - -void SceneSessionManager::OnInputMethodShown(const int32_t& persistentId) -{ - auto scnSession = GetSceneSession(persistentId); - if (scnSession == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "scnSession is null, persistentId: %{public}d", persistentId); - return; - } - - TLOGD(WmsLogTag::WMS_KEYBOARD, "persistentId: %{public}d, windowType: %{public}d", - persistentId, scnSession->GetWindowType()); - uint32_t callingWindowId = INVALID_WINDOW_ID; - if (scnSession->GetSessionProperty() != nullptr) { - callingWindowId = scnSession->GetSessionProperty()->GetCallingWindow(); - TLOGI(WmsLogTag::WMS_KEYBOARD, "Calling window id: %{public}d", callingWindowId); - callingSession_ = GetSceneSession(callingWindowId); - } - if (callingSession_ == nullptr) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "CallingSession is null, using focusedSession: %{public}d", focusedSessionId_); - callingSession_ = GetSceneSession(focusedSessionId_); - if (callingSession_ == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "Calling session obtained through focusedSessionId_ is null"); - return; - } - } - callingSession_->SetTextFieldAvoidInfo(scnSession->textFieldPositionY_, scnSession->textFieldHeight_); - ResizeSoftInputCallingSessionIfNeed(scnSession); -} - -void SceneSessionManager::RegisterInputMethodHideFunc(const sptr& sceneSession) -{ - if (sceneSession == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "session is nullptr"); - return; - } - NotifyCallingSessionBackgroundFunc onInputMethodHide = [this]() { - this->RestoreCallingSessionSizeIfNeed(); - this->callingSession_ = nullptr; - }; - sceneSession->SetNotifyCallingSessionBackgroundFunc(onInputMethodHide); - TLOGD(WmsLogTag::WMS_KEYBOARD, "RegisterInputMethodHideFunc success"); -} - sptr SceneSessionManager::SetAbilitySessionInfo(const sptr& scnSession) { sptr abilitySessionInfo = new (std::nothrow) AAFwk::SessionInfo(); @@ -1304,6 +1240,21 @@ std::future SceneSessionManager::RequestSceneSessionActivation( return future; } +bool SceneSessionManager::IsKeyboardForeground() +{ + bool isKeyboardForeground = false; + std::shared_lock lock(sceneSessionMapMutex_); + for (const auto &item : sceneSessionMap_) { + auto sceneSession = item.second; + if (sceneSession != nullptr && sceneSession->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { + isKeyboardForeground = sceneSession->IsSessionForeground(); + break; + } + } + + return isKeyboardForeground; +} + void SceneSessionManager::RequestInputMethodCloseKeyboard(const int32_t persistentId) { auto sceneSession = GetSceneSession(persistentId); @@ -1312,7 +1263,7 @@ void SceneSessionManager::RequestInputMethodCloseKeyboard(const int32_t persiste return; } // Hide keyboard when app is cold started, if keyboard is showing and screen is unlocked. - if (!sceneSession->IsSessionValid() && callingSession_ != nullptr && + if (!sceneSession->IsSessionValid() && IsKeyboardForeground() && !sceneSession->GetStateFromManager(ManagerState::MANAGER_STATE_SCREEN_LOCKED)) { sceneSession->RequestHideKeyboard(true); } @@ -1929,8 +1880,8 @@ WSError SceneSessionManager::RecoverAndConnectSpecificSession(const sptrGetWindowName().c_str(), info.windowMode, - info.windowType_, info.persistentId_, property->GetWindowState(), property->GetCallingWindow()); + "callingSessionId = %{public}" PRIu32, property->GetWindowName().c_str(), info.windowMode, + info.windowType_, info.persistentId_, property->GetWindowState(), property->GetCallingSessionId()); ClosePipWindowIfExist(type); sptr sceneSession = RequestSceneSession(info, property); @@ -2235,15 +2186,10 @@ void SceneSessionManager::OnOutsideDownEvent(int32_t x, int32_t y) void SceneSessionManager::NotifySessionTouchOutside(int32_t persistentId) { auto task = [this, persistentId]() { - int32_t callingSessionId = persistentId; - auto sceneSession = GetSceneSession(persistentId); - if (callingSession_ != nullptr && sceneSession != nullptr && - sceneSession->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { - callingSessionId = callingSession_->GetPersistentId(); - } + int32_t callingSessionId = INVALID_SESSION_ID; std::shared_lock lock(sceneSessionMapMutex_); for (const auto &item : sceneSessionMap_) { - sceneSession = item.second; + auto sceneSession = item.second; if (sceneSession == nullptr) { continue; } @@ -2258,6 +2204,12 @@ void SceneSessionManager::NotifySessionTouchOutside(int32_t persistentId) WLOGFD("id: %{public}d is not in touchOutsideListenerNodes, don't notify.", sessionId); continue; } + if (sceneSession->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT && + sceneSession->GetSessionProperty() != nullptr) { + callingSessionId = sceneSession->GetSessionProperty()->GetCallingSessionId(); + TLOGI(WmsLogTag::WMS_KEYBOARD, "persistentId: %{public}d, callingSessionId: %{public}d", + persistentId, callingSessionId); + } if (sessionId == callingSessionId || sessionId == persistentId) { WLOGFD("No need to notify touch window, id: %{public}d", sessionId); continue; @@ -2807,10 +2759,6 @@ WMError SceneSessionManager::HandleUpdateProperty(const sptrGetSystemCalling()) { WLOGFE("update decor enable permission denied!"); @@ -2838,7 +2786,10 @@ WMError SceneSessionManager::HandleUpdateProperty(const sptrSetTextFieldAvoidInfo(property->GetTextFieldPositionY(), property->GetTextFieldHeight()); + if (sceneSession->GetSessionProperty() != nullptr) { + sceneSession->GetSessionProperty()->SetTextFieldPositionY(property->GetTextFieldPositionY()); + sceneSession->GetSessionProperty()->SetTextFieldHeight(property->GetTextFieldHeight()); + } break; } case WSPropertyChangeAction::ACTION_UPDATE_WINDOW_MASK: { @@ -3114,7 +3065,7 @@ WMError SceneSessionManager::SetGestureNavigaionEnabled(bool enable) return taskScheduler_->PostSyncTask(task, "SetGestureNavigaionEnabled"); } -WSError SceneSessionManager::SetFocusedSession(int32_t persistentId) +WSError SceneSessionManager::SetFocusedSessionId(int32_t persistentId) { if (focusedSessionId_ == persistentId) { WLOGI("Focus scene not change, id: %{public}d", focusedSessionId_); @@ -3125,7 +3076,7 @@ WSError SceneSessionManager::SetFocusedSession(int32_t persistentId) return WSError::WS_OK; } -int32_t SceneSessionManager::GetFocusedSession() const +int32_t SceneSessionManager::GetFocusedSessionId() const { return focusedSessionId_; } @@ -3446,7 +3397,7 @@ WSError SceneSessionManager::GetAllSessionDumpInfo(std::string& dumpInfo) DumpSessionInfo(session, oss); count++; } - oss << "Focus window: " << GetFocusedSession() << std::endl; + oss << "Focus window: " << GetFocusedSessionId() << std::endl; oss << "Total window num: " << sceneSessionMapCopy.size() << std::endl; DumpAllAppSessionInfo(oss, sceneSessionMapCopy); dumpInfo.append(oss.str()); @@ -3905,10 +3856,10 @@ void SceneSessionManager::SetSCBUnfocusedListener(const NotifySCBAfterUpdateFocu notifySCBAfterUnfocusedFunc_ = func; } -void SceneSessionManager::SetCallingWindowIdChangeListenser(const ProcessCallingWindowIdChangeFunc& func) +void SceneSessionManager::SetCallingSessionIdSessionListenser(const ProcessCallingSessionIdChangeFunc& func) { - WLOGFD("SetCallingWindowIdChangeListenser"); - callingWindowIdChangeFunc_ = func; + WLOGFD("SetCallingSessionIdSessionListenser"); + callingSessionIdChangeFunc_ = func; } void SceneSessionManager::SetStartUIAbilityErrorListener(const ProcessStartUIAbilityErrorFunc& func) @@ -3952,7 +3903,7 @@ void SceneSessionManager::UpdateFocusStatus(sptr& sceneSession, bo { if (sceneSession == nullptr) { if (isFocused) { - SetFocusedSession(INVALID_SESSION_ID); + SetFocusedSessionId(INVALID_SESSION_ID); } return; } @@ -3960,7 +3911,7 @@ void SceneSessionManager::UpdateFocusStatus(sptr& sceneSession, bo sceneSession->GetWindowNameAllType().c_str(), sceneSession->GetPersistentId(), isFocused); // set focused if (isFocused) { - SetFocusedSession(sceneSession->GetPersistentId()); + SetFocusedSessionId(sceneSession->GetPersistentId()); } sceneSession->UpdateFocus(isFocused); if ((isFocused && !needBlockNotifyFocusStatusUntilForeground_) || (!isFocused && !needBlockNotifyUnfocusStatus_)) { @@ -4064,11 +4015,11 @@ WSError SceneSessionManager::UpdateFocus(int32_t persistentId, bool isFocused) sceneSession->GetWindowName().c_str(), persistentId, static_cast(isFocused)); // focusId change if (isFocused) { - SetFocusedSession(persistentId); + SetFocusedSessionId(persistentId); UpdateBrightness(focusedSessionId_); FocusIDChange(persistentId, sceneSession); - } else if (persistentId == GetFocusedSession()) { - SetFocusedSession(INVALID_SESSION_ID); + } else if (persistentId == GetFocusedSessionId()) { + SetFocusedSessionId(INVALID_SESSION_ID); } // notify window manager sptr focusChangeInfo = new FocusChangeInfo( @@ -5345,232 +5296,6 @@ void SceneSessionManager::StartWindowInfoReportLoop() isReportTaskStart_ = true; } -int32_t SceneSessionManager::GetStatusBarHeight(uint64_t displayId) -{ - int32_t statusBarHeight = 0; - int32_t height = 0; - std::vector> statusBarVector = GetSceneSessionVectorByType( - WindowType::WINDOW_TYPE_STATUS_BAR, displayId); - for (auto& statusBar : statusBarVector) { - if (statusBar == nullptr || !IsSessionVisible(statusBar)) { - continue; - } - height = statusBar->GetSessionRect().height_; - statusBarHeight = (statusBarHeight > height) ? statusBarHeight : height; - } - - return statusBarHeight; -} - -void SceneSessionManager::ResizeSoftInputCallingSessionIfNeed( - const sptr& sceneSession, bool isInputUpdated) -{ - if (callingSession_ == nullptr) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "calling session is nullptr"); - return; - } - if (!sceneSession->GetSessionProperty()) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "scene session property is nullptr"); - return; - } - SessionGravity gravity; - uint32_t percent = 0; - sceneSession->GetSessionProperty()->GetSessionGravity(gravity, percent); - if (gravity != SessionGravity::SESSION_GRAVITY_BOTTOM && gravity != SessionGravity::SESSION_GRAVITY_DEFAULT) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "No need to raise calling window, gravity: %{public}d", gravity); - return; - } - - bool isCallingSessionFloating = callingSession_->GetSessionProperty() && - callingSession_->GetSessionProperty()->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING; - - const WSRect& softInputSessionRect = (sceneSession->GetSessionRect().height_ != 0) ? - sceneSession->GetSessionRect() : sceneSession->GetSessionRequestRect(); - WSRect callingSessionRect; - if (isInputUpdated && isCallingSessionFloating) { - callingSessionRect = callingSession_->callingWindowRestoringRect_; - } else { - callingSessionRect = callingSession_->GetSessionRect(); - } - TLOGI(WmsLogTag::WMS_KEYBOARD, "softInputSessionRect: %{public}s, callingSessionRect: %{public}s", - softInputSessionRect.ToString().c_str(), callingSessionRect.ToString().c_str()); - if (SessionHelper::IsEmptyRect(SessionHelper::GetOverlap(softInputSessionRect, callingSessionRect, 0, 0))) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "There is no overlap area"); - return; - } - - WSRect newRect = callingSessionRect; - int32_t statusHeight = GetStatusBarHeight(sceneSession->GetSessionProperty()->GetDisplayId()); - if (isCallingSessionFloating && callingSessionRect.posY_ > statusHeight) { - // calculate new rect of calling window - newRect.posY_ = softInputSessionRect.posY_ - static_cast(newRect.height_); - newRect.posY_ = std::max(newRect.posY_, statusHeight); - } - - if (!isInputUpdated) { - callingSession_->callingWindowRestoringRect_ = callingSessionRect; - } - NotifyOccupiedAreaChangeInfo(sceneSession, newRect, softInputSessionRect); - if (isCallingSessionFloating && callingSessionRect.posY_ > statusHeight) { - callingSession_->needUpdateSessionRect_ = true; - callingSession_->UpdateSessionRect(newRect, SizeChangeReason::UNDEFINED); - callingSession_->callingWindowNewRect_ = callingSession_->GetSessionRect(); - } -} - -void SceneSessionManager::NotifyOccupiedAreaChangeInfo(const sptr sceneSession, - const WSRect& rect, const WSRect& occupiedArea) -{ - // if keyboard will occupy calling, notify calling window the occupied area and safe height - const WSRect& safeRect = SessionHelper::GetOverlap(occupiedArea, rect, 0, 0); - const WSRect& lastSafeRect = callingSession_->GetLastSafeRect(); - if (lastSafeRect == safeRect) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "NotifyOccupiedAreaChangeInfo lastSafeRect is same to safeRect"); - return; - } - callingSession_->SetLastSafeRect(safeRect); - sptr info = new OccupiedAreaChangeInfo(OccupiedAreaType::TYPE_INPUT, - SessionHelper::TransferToRect(safeRect), safeRect.height_, - sceneSession->textFieldPositionY_, sceneSession->textFieldHeight_); - TLOGI(WmsLogTag::WMS_KEYBOARD, "OccupiedAreaChangeInfo rect: %{public}s", occupiedArea.ToString().c_str()); - callingSession_->NotifyOccupiedAreaChangeInfo(info); -} - -void SceneSessionManager::RestoreCallingSessionSizeIfNeed() -{ - TLOGD(WmsLogTag::WMS_KEYBOARD, "RestoreCallingSessionSizeIfNeed"); - if (callingSession_ == nullptr) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "Calling session is nullptr"); - return; - } - - WSRect overlapRect = { 0, 0, 0, 0 }; - NotifyOccupiedAreaChangeInfo(callingSession_, callingSession_->callingWindowRestoringRect_, overlapRect); - if (!SessionHelper::IsEmptyRect(callingSession_->callingWindowRestoringRect_)) { - if (callingSession_->needUpdateSessionRect_ && callingSession_->GetSessionProperty() && - callingSession_->GetSessionProperty()->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING && - callingSession_->GetSessionRect() == callingSession_->callingWindowNewRect_) { - callingSession_->UpdateSessionRect(callingSession_->callingWindowRestoringRect_, - SizeChangeReason::UNDEFINED); - } - } - callingSession_->needUpdateSessionRect_ = false; - callingSession_->callingWindowRestoringRect_ = { 0, 0, 0, 0 }; - callingSession_->callingWindowNewRect_ = {0, 0, 0, 0}; -} - -WSError SceneSessionManager::SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent) -{ - auto task = [this, persistentId, gravity, percent]() -> WSError { - bool isKeyboardForeground = true; - auto sceneSession = GetSceneSession(persistentId); - if (!sceneSession) { - WLOGFE("scene session is nullptr"); - return WSError::WS_ERROR_NULLPTR; - } - TLOGI(WmsLogTag::WMS_KEYBOARD, "persistentId: %{public}d, windowType: %{public}d, gravity: %{public}d", - persistentId, sceneSession->GetWindowType(), gravity); - if (sceneSession->GetWindowType() != WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "scene session is not input method"); - return WSError::WS_ERROR_INVALID_TYPE; - } - sceneSession->GetSessionProperty()->SetSessionGravity(gravity, percent); - RelayoutKeyBoard(sceneSession); - if (sceneSession->GetSessionState() != SessionState::STATE_FOREGROUND && - sceneSession->GetSessionState() != SessionState::STATE_ACTIVE) { - isKeyboardForeground = false; - TLOGI(WmsLogTag::WMS_KEYBOARD, "Keyboard is not foreground, not need to adjust or restore callingWindow"); - } - if (gravity == SessionGravity::SESSION_GRAVITY_FLOAT) { - TLOGD(WmsLogTag::WMS_KEYBOARD, "input method is float mode"); - sceneSession->SetWindowAnimationFlag(false); - if (isKeyboardForeground) { - RestoreCallingSessionSizeIfNeed(); - } - } else { - TLOGD(WmsLogTag::WMS_KEYBOARD, "input method is bottom mode"); - sceneSession->SetWindowAnimationFlag(true); - if (isKeyboardForeground) { - ResizeSoftInputCallingSessionIfNeed(sceneSession); - } - } - return WSError::WS_OK; - }; - taskScheduler_->PostAsyncTask(task, "SetSessionGravity" + std::to_string(persistentId)); - return WSError::WS_OK; -} - -void SceneSessionManager::RelayoutKeyBoard(sptr sceneSession) -{ - if (sceneSession == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "sceneSession is nullptr"); - return; - } - SessionGravity gravity; - uint32_t percent = 0; - sceneSession->GetSessionProperty()->GetSessionGravity(gravity, percent); - if (sceneSession->GetWindowType() != WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT || - gravity == SessionGravity::SESSION_GRAVITY_FLOAT) { - return; - } - - auto defaultDisplayInfo = DisplayManager::GetInstance().GetDefaultDisplay(); - if (defaultDisplayInfo == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "screenSession is null"); - return; - } - - auto requestRect = sceneSession->GetSessionProperty()->GetRequestRect(); - if (gravity == SessionGravity::SESSION_GRAVITY_BOTTOM) { - requestRect.width_ = static_cast(defaultDisplayInfo->GetWidth()); - requestRect.posX_ = 0; - if (percent != 0) { - requestRect.height_ = - static_cast(defaultDisplayInfo->GetHeight()) * percent / 100u; // 100: for calc percent. - } - } - requestRect.posY_ = defaultDisplayInfo->GetHeight() - - static_cast(requestRect.height_); - sceneSession->GetSessionProperty()->SetRequestRect(requestRect); - TLOGD(WmsLogTag::WMS_KEYBOARD, "Id: %{public}d, rect: %{public}s", sceneSession->GetPersistentId(), - SessionHelper::TransferToWSRect(requestRect).ToString().c_str()); - sceneSession->UpdateSessionRect(SessionHelper::TransferToWSRect(requestRect), SizeChangeReason::UNDEFINED); -} - -void SceneSessionManager::UpdateCallingWindowIdAndPosition(const sptr& property, - const sptr& sceneSession) -{ - if (sceneSession->GetSessionProperty() == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "Failed to update calling window id: %{public}d", property->GetCallingWindow()); - return; - } - uint32_t curWindowId = sceneSession->GetSessionProperty()->GetCallingWindow(); - uint32_t newWindowId = property->GetCallingWindow(); - // When calling window id changes, restore the old calling window, raise the new calling window. - if (curWindowId != INVALID_WINDOW_ID && newWindowId != curWindowId && callingSession_ != nullptr) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "CallingWindow curId: %{public}d, newId: %{public}d", curWindowId, newWindowId); - RestoreCallingSessionSizeIfNeed(); - - callingSession_ = GetSceneSession(newWindowId); - if (callingSession_ == nullptr) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "Using focusedSession id: %{public}d", focusedSessionId_); - callingSession_ = GetSceneSession(focusedSessionId_); - if (callingSession_ == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "Calling window id invalid,Calling session is null"); - return; - } else { - newWindowId = focusedSessionId_; - } - } - ResizeSoftInputCallingSessionIfNeed(sceneSession); - } - sceneSession->GetSessionProperty()->SetCallingWindow(newWindowId); - - if (callingWindowIdChangeFunc_ != nullptr) { - callingWindowIdChangeFunc_(newWindowId); - } -} - void SceneSessionManager::InitPersistentStorage() { if (ScenePersistentStorage::HasKey("maximize_state", ScenePersistentStorageType::MAXIMIZE_STATE)) { @@ -7499,7 +7224,7 @@ void SceneSessionManager::ReportWindowProfileInfos() std::shared_lock lock(sceneSessionMapMutex_); sceneSessionMapCopy = sceneSessionMap_; } - auto focusWindowId = GetFocusedSession(); + auto focusWindowId = GetFocusedSessionId(); for (const auto& elem : sceneSessionMapCopy) { auto curSession = elem.second; if (curSession == nullptr || curSession->GetSessionInfo().isSystem_ || 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 34d6261241..4422ee573f 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 @@ -478,35 +478,6 @@ WMError SceneSessionManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgen return static_cast(reply.ReadInt32()); } -WSError SceneSessionManagerProxy::SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("WriteInterfaceToken failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - if (!data.WriteInt32(persistentId)) { - WLOGFE("Write persistentId failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - if (!data.WriteUint32(static_cast(gravity))) { - WLOGFE("Write gravity failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - if (!data.WriteUint32(percent)) { - WLOGFE("Write percent failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - if (Remote()->SendRequest(static_cast(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_GRAVITY), - data, reply, option) != ERR_NONE) { - WLOGFE("SendRequest failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - return static_cast(reply.ReadInt32()); -} - WMError SceneSessionManagerProxy::SetGestureNavigaionEnabled(bool enable) { 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 17288d8853..bf5103aecb 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 @@ -101,8 +101,6 @@ const std::map SceneSessionManagerStub::s &SceneSessionManagerStub::HandleNotifyDumpInfoResult), std::make_pair(static_cast(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_CONTINUE_STATE), &SceneSessionManagerStub::HandleSetSessionContinueState), - std::make_pair(static_cast(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_GRAVITY), - &SceneSessionManagerStub::HandleSetSessionGravity), std::make_pair(static_cast(SceneSessionManagerMessage::TRANS_ID_CLEAR_SESSION), &SceneSessionManagerStub::HandleClearSession), std::make_pair(static_cast(SceneSessionManagerMessage::TRANS_ID_CLEAR_ALL_SESSIONS), @@ -585,17 +583,6 @@ int SceneSessionManagerStub::HandleSetSessionContinueState(MessageParcel &data, return ERR_NONE; } -int SceneSessionManagerStub::HandleSetSessionGravity(MessageParcel &data, MessageParcel &reply) -{ - WLOGFI("run HandleSetSessionGravity!"); - auto persistentId = data.ReadInt32(); - SessionGravity gravity = static_cast(data.ReadUint32()); - uint32_t percent = data.ReadUint32(); - WSError ret = SetSessionGravity(persistentId, gravity, percent); - reply.WriteInt32(static_cast(ret)); - return ERR_NONE; -} - int SceneSessionManagerStub::HandleGetSessionDump(MessageParcel &data, MessageParcel &reply) { std::vector params; diff --git a/window_scene/test/unittest/scene_session_manager_stub_test.cpp b/window_scene/test/unittest/scene_session_manager_stub_test.cpp index 84f1262e1d..6a661c128d 100644 --- a/window_scene/test/unittest/scene_session_manager_stub_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_stub_test.cpp @@ -364,24 +364,6 @@ HWTEST_F(SceneSessionManagerStubTest, HandleSetSessionContinueState, Function | EXPECT_EQ(res, ERR_NONE); } -/** - * @tc.name: HandleSetSessionGravity - * @tc.desc: test HandleSetSessionGravity - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionManagerStubTest, HandleSetSessionGravity, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - data.WriteInt32(1); - data.WriteUint32(0); - data.WriteUint32(10); - - int res = stub_->HandleSetSessionGravity(data, reply); - EXPECT_EQ(res, ERR_NONE); -} - /** * @tc.name: HandleUpdateSessionWindowVisibilityListener * @tc.desc: test HandleUpdateSessionWindowVisibilityListener diff --git a/window_scene/test/unittest/scene_session_manager_test.cpp b/window_scene/test/unittest/scene_session_manager_test.cpp index 7f847d2410..ac75fc3628 100644 --- a/window_scene/test/unittest/scene_session_manager_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_test.cpp @@ -1823,55 +1823,6 @@ HWTEST_F(SceneSessionManagerTest, ChangeUIAbilityVisibilityBySCB, Function | Sma EXPECT_EQ(ret, 2097202); } -/** - * @tc.name: RegisterInputMethodShownFunc - * @tc.desc: SceneSesionManager register input method show func - * @tc.type: FUNC -*/ -HWTEST_F(SceneSessionManagerTest, RegisterInputMethodShownFunc, Function | SmallTest | Level3) -{ - SessionInfo info; - info.abilityName_ = "SetBrightness"; - info.bundleName_ = "SetBrightness1"; - sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); - int ret = 0; - ssm_->RegisterInputMethodShownFunc(nullptr); - ASSERT_EQ(ret, 0); - ssm_->RegisterInputMethodShownFunc(sceneSession); - ASSERT_EQ(ret, 0); -} - -/** - * @tc.name: OnInputMethodShown - * @tc.desc: SceneSesionManager on input method shown - * @tc.type: FUNC -*/ -HWTEST_F(SceneSessionManagerTest, OnInputMethodShown, Function | SmallTest | Level3) -{ - int32_t persistentId = 65535; - int ret = 0; - ssm_->OnInputMethodShown(persistentId); - ASSERT_EQ(ret, 0); -} - -/** - * @tc.name: RegisterInputMethodHideFunc - * @tc.desc: SceneSesionManager register input method hide func - * @tc.type: FUNC -*/ -HWTEST_F(SceneSessionManagerTest, RegisterInputMethodHideFunc, Function | SmallTest | Level3) -{ - SessionInfo info; - info.abilityName_ = "SetBrightness"; - info.bundleName_ = "SetBrightness1"; - sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); - int ret = 0; - ssm_->RegisterInputMethodHideFunc(nullptr); - ASSERT_EQ(ret, 0); - ssm_->RegisterInputMethodHideFunc(sceneSession); - ASSERT_EQ(ret, 0); -} - /** * @tc.name: SetAbilitySessionInfo * @tc.desc: SceneSesionManager set ability session info @@ -2508,21 +2459,21 @@ HWTEST_F(SceneSessionManagerTest, SetGestureNavigaionEnabled02, Function | Small } /** - * @tc.name: SetFocusedSession - * @tc.desc: SceneSesionManager set focused session + * @tc.name: SetFocusedSessionId + * @tc.desc: SceneSesionManager set focused session id * @tc.type: FUNC */ -HWTEST_F(SceneSessionManagerTest, SetFocusedSession, Function | SmallTest | Level3) +HWTEST_F(SceneSessionManagerTest, SetFocusedSessionId, Function | SmallTest | Level3) { - int32_t focusedSession_ = ssm_->GetFocusedSession(); + int32_t focusedSession_ = ssm_->GetFocusedSessionId(); EXPECT_EQ(focusedSession_, INVALID_SESSION_ID); int32_t persistendId_ = INVALID_SESSION_ID; - WSError result01 = ssm_->SetFocusedSession(persistendId_); + WSError result01 = ssm_->SetFocusedSessionId(persistendId_); EXPECT_EQ(result01, WSError::WS_DO_NOTHING); persistendId_ = 10086; - WSError result02 = ssm_->SetFocusedSession(persistendId_); + WSError result02 = ssm_->SetFocusedSessionId(persistendId_); EXPECT_EQ(result02, WSError::WS_OK); - ASSERT_EQ(ssm_->GetFocusedSession(), 10086); + ASSERT_EQ(ssm_->GetFocusedSessionId(), 10086); } /** @@ -2532,7 +2483,7 @@ HWTEST_F(SceneSessionManagerTest, SetFocusedSession, Function | SmallTest | Leve */ HWTEST_F(SceneSessionManagerTest, RequestFocusStatus, Function | SmallTest | Level3) { - int32_t focusedSession_ = SceneSessionManager::GetInstance().GetFocusedSession(); + int32_t focusedSession_ = SceneSessionManager::GetInstance().GetFocusedSessionId(); EXPECT_EQ(focusedSession_, INVALID_SESSION_ID); int32_t persistentId_ = INVALID_SESSION_ID; WMError result01 = SceneSessionManager::GetInstance().RequestFocusStatus(persistentId_, true); @@ -2551,7 +2502,7 @@ HWTEST_F(SceneSessionManagerTest, RequestFocusStatus, Function | SmallTest | Lev */ HWTEST_F(SceneSessionManagerTest, RaiseWindowToTop, Function | SmallTest | Level3) { - int32_t focusedSession_ = ssm_->GetFocusedSession(); + int32_t focusedSession_ = ssm_->GetFocusedSessionId(); EXPECT_EQ(focusedSession_, INVALID_SESSION_ID); int32_t persistentId_ = INVALID_SESSION_ID; WSError result01 = ssm_->RaiseWindowToTop(persistentId_); @@ -2570,7 +2521,7 @@ HWTEST_F(SceneSessionManagerTest, RaiseWindowToTop, Function | SmallTest | Level */ HWTEST_F(SceneSessionManagerTest, ShiftAppWindowFocus, Function | SmallTest | Level3) { - int32_t focusedSession_ = ssm_->GetFocusedSession(); + int32_t focusedSession_ = ssm_->GetFocusedSessionId(); EXPECT_EQ(focusedSession_, INVALID_SESSION_ID); int32_t sourcePersistentId_ = INVALID_SESSION_ID; int32_t targetPersistentId_ = INVALID_SESSION_ID; diff --git a/window_scene/test/unittest/scene_session_test.cpp b/window_scene/test/unittest/scene_session_test.cpp index 8d882aecb2..7cd2414385 100644 --- a/window_scene/test/unittest/scene_session_test.cpp +++ b/window_scene/test/unittest/scene_session_test.cpp @@ -1552,7 +1552,7 @@ HWTEST_F(SceneSessionTest, UpdateInputMethodSessionRect, Function | SmallTest | sptr property = new(std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); uint32_t p = 10; - property->SetSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); + property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); scensession->SetSessionProperty(property); WSRect rect({1, 1, 1, 1}); @@ -1583,7 +1583,7 @@ HWTEST_F(SceneSessionTest, UpdateSessionRect, Function | SmallTest | Level2) sptr property = new(std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); uint32_t p = 10; - property->SetSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); + property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); scensession->SetSessionProperty(property); WSRect rect({1, 1, 1, 1}); @@ -1613,7 +1613,7 @@ HWTEST_F(SceneSessionTest, UpdateSessionRect1, Function | SmallTest | Level2) sptr property = new(std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); uint32_t p = 10; - property->SetSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); + property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); scensession->SetSessionProperty(property); WSRect rect({1, 1, 1, 1}); @@ -1643,7 +1643,7 @@ HWTEST_F(SceneSessionTest, UpdateSessionRect2, Function | SmallTest | Level2) sptr property = new(std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); uint32_t p = 10; - property->SetSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); + property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); scensession->SetSessionProperty(property); WSRect rect({1, 1, 1, 1}); @@ -1673,7 +1673,7 @@ HWTEST_F(SceneSessionTest, RaiseAboveTarget, Function | SmallTest | Level2) sptr property = new(std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); uint32_t p = 10; - property->SetSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); + property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); scensession->SetSessionProperty(property); WSError result = scensession->RaiseAboveTarget(0); @@ -1701,7 +1701,7 @@ HWTEST_F(SceneSessionTest, BindDialogSessionTarget, Function | SmallTest | Level sptr property = new(std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); uint32_t p = 10; - property->SetSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); + property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); scensession->SetSessionProperty(property); sptr sceneSession = nullptr; @@ -1987,7 +1987,7 @@ HWTEST_F(SceneSessionTest, RequestSessionBack, Function | SmallTest | Level2) sptr property = new(std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); uint32_t p = 10; - property->SetSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); + property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); scensession->SetSessionProperty(property); WSError result = scensession->RequestSessionBack(true); @@ -2147,7 +2147,7 @@ HWTEST_F(SceneSessionTest, PendingSessionActivation, Function | SmallTest | Leve sptr property = new(std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); uint32_t p = 10; - property->SetSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); + property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); scensession->SetSessionProperty(property); sptr abilitySessionInfo = new AAFwk::SessionInfo(); @@ -2181,7 +2181,7 @@ HWTEST_F(SceneSessionTest, TerminateSession, Function | SmallTest | Level2) sptr property = new(std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); uint32_t p = 10; - property->SetSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); + property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); scensession->SetSessionProperty(property); sptr abilitySessionInfo = new AAFwk::SessionInfo(); @@ -2215,7 +2215,7 @@ HWTEST_F(SceneSessionTest, NotifySessionException, Function | SmallTest | Level2 sptr property = new(std::nothrow) WindowSessionProperty(); property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); uint32_t p = 10; - property->SetSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); + property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); scensession->SetSessionProperty(property); sptr abilitySessionInfo = new AAFwk::SessionInfo(); diff --git a/window_scene/test/unittest/session_test.cpp b/window_scene/test/unittest/session_test.cpp index f895528624..febc3821c1 100644 --- a/window_scene/test/unittest/session_test.cpp +++ b/window_scene/test/unittest/session_test.cpp @@ -1644,21 +1644,6 @@ HWTEST_F(WindowSessionTest, PendingSessionToBackgroundForDelegator, Function | S ASSERT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator()); } -/** - * @tc.name: SetNotifyCallingSessionForegroundFunc - * @tc.desc: SetNotifyCallingSessionForegroundFunc Test - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionTest, SetNotifyCallingSessionForegroundFunc, Function | SmallTest | Level2) -{ - ASSERT_NE(session_, nullptr); - session_->state_ = SessionState::STATE_DISCONNECT; - NotifyCallingSessionForegroundFunc func = nullptr; - session_->SetNotifyCallingSessionForegroundFunc(func); - - ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); -} - /** * @tc.name: NotifyScreenshot * @tc.desc: NotifyScreenshot Test diff --git a/window_scene/test/unittest/window_session_property_test.cpp b/window_scene/test/unittest/window_session_property_test.cpp index 53f31b7ae4..e1393f521c 100755 --- a/window_scene/test/unittest/window_session_property_test.cpp +++ b/window_scene/test/unittest/window_session_property_test.cpp @@ -280,16 +280,16 @@ HWTEST_F(WindowSessionPropertyTest, SetSystemBarProperty, Function | SmallTest | } /** - * @tc.name: SetSessionGravity - * @tc.desc: SetSessionGravity test + * @tc.name: SetKeyboardSessionGravity + * @tc.desc: SetKeyboardSessionGravity test * @tc.type: FUNC */ -HWTEST_F(WindowSessionPropertyTest, SetSessionGravity, Function | SmallTest | Level2) +HWTEST_F(WindowSessionPropertyTest, SetKeyboardSessionGravity, Function | SmallTest | Level2) { SessionGravity sessionGravity = SessionGravity::SESSION_GRAVITY_FLOAT; uint32_t percent = 1234567890; WindowSessionProperty windowSessionProperty; - windowSessionProperty.SetSessionGravity(sessionGravity, percent); + windowSessionProperty.SetKeyboardSessionGravity(sessionGravity, percent); WindowSessionProperty *property = new WindowSessionProperty(); ASSERT_EQ(property->GetTokenState(), false); } diff --git a/wm/include/window_scene_session_impl.h b/wm/include/window_scene_session_impl.h index 299a0cffa7..919c2c4d74 100644 --- a/wm/include/window_scene_session_impl.h +++ b/wm/include/window_scene_session_impl.h @@ -113,7 +113,7 @@ public: virtual std::shared_ptr Snapshot() override; WMError SetTouchHotAreas(const std::vector& rects) override; virtual WmErrorCode KeepKeyboardOnFocus(bool keepKeyboardFlag) override; - virtual WMError SetCallingWindow(uint32_t callingWindowId) override; + virtual WMError SetCallingWindow(uint32_t callingSessionId) override; virtual bool IsTransparent() const override; virtual bool IsTurnScreenOn() const override; diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index ea989c7c1d..3523bb3902 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -65,7 +65,6 @@ public: const sptr& iSession); WMError Show(uint32_t reason = 0, bool withAnimation = false) override; WMError Hide(uint32_t reason = 0, bool withAnimation = false, bool isFromInnerkits = true) override; - WMError SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) override; WMError Destroy() override; virtual WMError Destroy(bool needNotifyServer, bool needClearListener = true); WMError NapiSetUIContent(const std::string& contentInfo, napi_env env, diff --git a/wm/src/window_extension_session_impl.cpp b/wm/src/window_extension_session_impl.cpp index 9d459775db..d5dbe22f06 100644 --- a/wm/src/window_extension_session_impl.cpp +++ b/wm/src/window_extension_session_impl.cpp @@ -548,7 +548,8 @@ void WindowExtensionSessionImpl::NotifySessionBackground(uint32_t reason, bool w void WindowExtensionSessionImpl::NotifyOccupiedAreaChangeInfo(sptr info) { - WLOGD("TextFieldPosY = %{public}lf, KeyBoardHeight = %{public}d", info->textFieldPositionY_, info->rect_.height_); + TLOGI(WmsLogTag::WMS_KEYBOARD, "TextFieldPosY = %{public}f, KeyBoardHeight = %{public}d", + info->textFieldPositionY_, info->rect_.height_); if (occupiedAreaChangeListener_) { occupiedAreaChangeListener_->OnSizeChange(info); } diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index a52e0c76ec..c762cef94c 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -2505,24 +2505,26 @@ WmErrorCode WindowSceneSessionImpl::KeepKeyboardOnFocus(bool keepKeyboardFlag) return WmErrorCode::WM_OK; } -WMError WindowSceneSessionImpl::SetCallingWindow(uint32_t callingWindowId) +WMError WindowSceneSessionImpl::SetCallingWindow(uint32_t callingSessionId) { if (IsWindowSessionInvalid()) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "Set calling window id failed, window session is InValid!"); + TLOGE(WmsLogTag::WMS_KEYBOARD, "Set calling session id failed, window session is invalid!"); return WMError::WM_ERROR_INVALID_WINDOW; } if (property_ == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "Set calling window id failed, property_ is nullptr!"); + TLOGE(WmsLogTag::WMS_KEYBOARD, "Set calling session id failed, property_ is nullptr!"); return WMError::WM_ERROR_NULLPTR; } - if (callingWindowId != property_->GetCallingWindow()) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "Set calling window id form %{public}d to: %{public}d", - property_->GetCallingWindow(), callingWindowId); + if (callingSessionId != property_->GetCallingSessionId()) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "Set calling session id form %{public}d to: %{public}d", + property_->GetCallingSessionId(), callingSessionId); } - property_->SetCallingWindow(callingWindowId); - - return UpdateProperty(WSPropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW); + if (hostSession_) { + hostSession_->SetCallingSessionId(callingSessionId); + } + property_->SetCallingSessionId(callingSessionId); + return WMError::WM_OK; } void WindowSceneSessionImpl::DumpSessionElementInfo(const std::vector& params) @@ -2829,6 +2831,8 @@ WMError WindowSceneSessionImpl::HideNonSecureWindows(bool shouldHide) WMError WindowSceneSessionImpl::SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "Set textFieldPositionY: %{public}f, textFieldHeight:%{public}f", + textFieldPositionY, textFieldHeight); property_->SetTextFieldPositionY(textFieldPositionY); property_->SetTextFieldHeight(textFieldHeight); UpdateProperty(WSPropertyChangeAction::ACTION_UPDATE_TEXTFIELD_AVOID_INFO); diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index be35c11d3a..b173982614 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -143,7 +143,7 @@ WindowSessionImpl::WindowSessionImpl(const sptr& option) property_->SetKeepScreenOn(option->IsKeepScreenOn()); property_->SetWindowMode(option->GetWindowMode()); property_->SetWindowFlags(option->GetWindowFlags()); - property_->SetCallingWindow(option->GetCallingWindow()); + property_->SetCallingSessionId(option->GetCallingWindow()); property_->SetExtensionFlag(option->GetExtensionTag()); isMainHandlerAvailable_ = option->GetMainHandlerAvailable(); @@ -2573,10 +2573,14 @@ WMError WindowSessionImpl::SetWindowGravity(WindowGravity gravity, uint32_t perc auto sessionGravity = static_cast(gravity); TLOGI(WmsLogTag::WMS_KEYBOARD, "Set window gravity: %{public}u, percent: %{public}u", sessionGravity, percent); if (property_ != nullptr) { - property_->SetSessionGravity(sessionGravity, percent); + property_->SetKeyboardSessionGravity(sessionGravity, percent); } - return SingletonContainer::Get().SetSessionGravity(GetPersistentId(), - static_cast(gravity), percent); + + if (hostSession_ != nullptr) { + return static_cast(hostSession_->SetKeyboardSessionGravity( + static_cast(gravity), percent)); + } + return WMError::WM_OK; } WMError WindowSessionImpl::SetSystemBarProperty(WindowType type, const SystemBarProperty& property) @@ -2589,12 +2593,6 @@ WMError WindowSessionImpl::SetSpecificBarProperty(WindowType type, const SystemB return WMError::WM_OK; } -WMError WindowSessionImpl::SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) -{ - property_->SetTextFieldPositionY(textFieldPositionY); - property_->SetTextFieldHeight(textFieldHeight); - return WMError::WM_OK; -} void WindowSessionImpl::NotifyOccupiedAreaChangeInfo(sptr info) { -- Gitee