From 3dd51efae2538ace3487db0c6dfe9a37cb60cf4e Mon Sep 17 00:00:00 2001 From: zhangdingzhong Date: Sun, 14 Apr 2024 20:16:40 +0800 Subject: [PATCH 01/15] =?UTF-8?q?DFX=E7=AA=97=E5=8F=A3=E5=B1=82=E7=BA=A7?= =?UTF-8?q?=E7=84=A6=E7=82=B9=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdingzhong --- window_scene/session/host/include/session.h | 1 + window_scene/session/host/src/session.cpp | 5 + window_scene/session_manager/BUILD.gn | 1 + .../include/anomaly_detection.h | 37 ++++++ .../include/scene_session_manager.h | 2 + .../session_manager/src/anomaly_detection.cpp | 108 ++++++++++++++++++ .../src/scene_session_manager.cpp | 10 ++ 7 files changed, 164 insertions(+) create mode 100644 window_scene/session_manager/include/anomaly_detection.h create mode 100644 window_scene/session_manager/src/anomaly_detection.cpp diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index 3a72762049..b985f5efb1 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -274,6 +274,7 @@ public: bool NeedNotify() const; void SetNeedNotify(bool needNotify); bool GetFocusable() const; + bool IsFocused() const; WSError SetTouchable(bool touchable); bool GetTouchable() const; void SetForceTouchable(bool touchable); diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index b5a678aaf4..050b0cfe91 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -422,6 +422,11 @@ bool Session::GetFocusable() const return true; } +bool Session::IsFocused() const +{ + return isFocused_; +} + void Session::SetNeedNotify(bool needNotify) { needNotify_ = needNotify; diff --git a/window_scene/session_manager/BUILD.gn b/window_scene/session_manager/BUILD.gn index e1aaf8f97d..9be9bc450c 100644 --- a/window_scene/session_manager/BUILD.gn +++ b/window_scene/session_manager/BUILD.gn @@ -80,6 +80,7 @@ ohos_shared_library("scene_session_manager") { "src/zidl/scene_session_manager_stub.cpp", "src/zidl/session_listener_proxy.cpp", "src/zidl/session_listener_stub.cpp", + "src/anomaly_detection.cpp", ] public_configs = [ diff --git a/window_scene/session_manager/include/anomaly_detection.h b/window_scene/session_manager/include/anomaly_detection.h new file mode 100644 index 0000000000..8fa9d06242 --- /dev/null +++ b/window_scene/session_manager/include/anomaly_detection.h @@ -0,0 +1,37 @@ +/* + * 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 ANOMALY_DETECTION +#define ANOMALY_DETECTION + +#include "session/host/include/scene_session.h" + +namespace OHOS { +namespace Rosen { + +enum class WindowDFXHelperType : uint32_t { + WINDOW_RECT_CHECK, + WINDOW_ZORDER_CHECK, + WINDOW_FOCUS_CHECK, +}; + +class AnomalyDetection { +public: + static void SceneZorderCheckProcess(); + static void FocusCheckProcess(int32_t focusId, int32_t nextId); +}; +} // namespace Rosen +} // namespace OHOS +#endif // ANOMALY_DETECTION \ No newline at end of file diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index f8d66b8276..1aa68c3d13 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -103,6 +103,7 @@ public: class SceneSessionManager : public SceneSessionManagerStub { WM_DECLARE_SINGLE_INSTANCE_BASE(SceneSessionManager) public: + friend class AnomalyDetection; bool IsSessionVisible(const sptr& session); sptr RequestSceneSession(const SessionInfo& sessionInfo, sptr property = nullptr); @@ -288,6 +289,7 @@ public: int32_t parentId) override; WSError AddOrRemoveSecureSession(int32_t persistentId, bool shouldHide) override; WSError AddOrRemoveSecureExtSession(int32_t persistentId, int32_t parentId, bool shouldHide) override; + void CheckSceneZOrder(); int32_t StartUIAbilityBySCB(sptr& abilitySessionInfo); int32_t StartUIAbilityBySCB(sptr& sceneSessions); int32_t ChangeUIAbilityVisibilityBySCB(sptr& sceneSessions, bool visibility); diff --git a/window_scene/session_manager/src/anomaly_detection.cpp b/window_scene/session_manager/src/anomaly_detection.cpp new file mode 100644 index 0000000000..87a3e5cb31 --- /dev/null +++ b/window_scene/session_manager/src/anomaly_detection.cpp @@ -0,0 +1,108 @@ +/* + * 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 "anomaly_detection.h" + +#include "dfx_hisysevent.h" +#include "window_manager_hilog.h" +#include "interfaces/include/ws_common.h" +#include "session_manager/include/scene_session_manager.h" +#include "session_helper.h" +#include "window_helper.h" +#include "screen_session_manager/include/screen_session_manager_client.h" +#include "session/screen/include/screen_property.h" + +namespace OHOS { +namespace Rosen { +namespace { +constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "AnomalyDetection" }; +} + +void AnomalyDetection::SceneZorderCheckProcess() +{ + TLOGI(WmsLogTag::WMS_FOCUS, "SceneZorderCheckProcess"); + bool keyGuardFlag = false; + uint32_t curZOrder = 0; + auto func = [&curZOrder, &keyGuardFlag](sptr session) { + if ((session == nullptr) || (!SceneSessionManager::GetInstance().IsSessionVisible(session))) { + return false; + } + // check zorder = 0 + if (session->GetZOrder() == 0) { + TLOGE(WmsLogTag::WMS_FOCUS, "ZorderCheck err, zorder 0"); + } + // repetitive zorder + if (session->GetZOrder() == curZOrder) { + TLOGE(WmsLogTag::WMS_FOCUS, "ZorderCheck err, repetitive zorder %{public}d", session->GetZOrder()); + } + curZOrder = session->GetZOrder(); + // callingSession check for input method + if (session->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { + uint32_t callingWindowId = session->GetSessionProperty()->GetCallingSessionId(); + const auto& callingSession = + SceneSessionManager::GetInstance().GetSceneSession(static_cast(callingWindowId)); + if (callingSession->GetZOrder() > session->GetZOrder()) { + TLOGE(WmsLogTag::WMS_FOCUS, "ZorderCheck err, callingSession %{public}d curSession %{public}d", + callingSession->GetZOrder(), session->GetZOrder()); + } + } + // subWindow/dialogWindow + if (WindowHelper::IsSubWindow(session->GetWindowType()) || + session->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG) { + auto mainSession = session->GetParentSession(); + if (session->GetZOrder() < mainSession->GetZOrder()) { + TLOGE(WmsLogTag::WMS_FOCUS, "ZorderCheck err, subWindow %{public}d mainSession %{public}d", + session->GetZOrder(), mainSession->GetZOrder()); + } + } + if (session->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) { + keyGuardFlag = true; + return false; + }; + if (keyGuardFlag && session->IsShowWhenLocked()) { + TLOGE(WmsLogTag::WMS_FOCUS, "ZorderCheck err %{public}d IsShowWhenLocked", session->GetZOrder()); + } + return false; + }; + SceneSessionManager::GetInstance().TraverseSessionTree(func, false); +} + +void AnomalyDetection::FocusCheckProcess(int32_t focusId, int32_t nextId) +{ + TLOGI(WmsLogTag::WMS_FOCUS, "FocusCheckProcess"); + if (nextId == INVALID_SESSION_ID) { + TLOGE(WmsLogTag::WMS_FOCUS, "FocusCheck err: invalid id, focusID:%{public}d nextId:%{public}d", + focusId, nextId); + } + bool focusSessionFlag = false; + auto func = [&focusSessionFlag](sptr session) { + if (session == nullptr) { + return false; + } + if (session->IsFocused()) { + focusSessionFlag = true; + return false; + } + if (focusSessionFlag && session->GetBlockingFocus() && + SceneSessionManager::GetInstance().IsSessionVisible(session)) { + TLOGE(WmsLogTag::WMS_FOCUS, "FocusCheck err: blockingFocus, sessionID:%{public}d", + session->GetPersistentId()); + }; + return false; + }; + SceneSessionManager::GetInstance().TraverseSessionTree(func, false); +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index f358315fe9..a355547d8b 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -95,6 +95,7 @@ #include "window_visibility_info.h" #include "window_drawing_content_info.h" +#include "session_manager/include/anomaly_detection.h" #ifdef MEMMGR_WINDOW_ENABLE #include "mem_mgr_client.h" #include "mem_mgr_window_info.h" @@ -3973,6 +3974,7 @@ WSError SceneSessionManager::ShiftFocus(sptr& nextSession) UpdateFocusStatus(nextSession, true); bool scbPrevFocus = focusedSession && focusedSession->GetSessionInfo().isSystem_; bool scbCurrFocus = nextSession && nextSession->GetSessionInfo().isSystem_; + AnomalyDetection::FocusCheckProcess(focusedId, nextId); if (!scbPrevFocus && scbCurrFocus) { if (notifySCBAfterFocusedFunc_ != nullptr) { notifySCBAfterFocusedFunc_(); @@ -7563,6 +7565,14 @@ WMError SceneSessionManager::GetCallingWindowRect(int32_t persistentId, Rect& re return WMError::WM_OK; } +void SceneSessionManager::CheckSceneZOrder() +{ + auto task = [this]() { + AnomalyDetection::SceneZorderCheckProcess(); + }; + taskScheduler_->PostAsyncTask(task, "CheckSceneZOrder"); +} + WMError SceneSessionManager::GetWindowBackHomeStatus(bool &isBackHome) { if (!SessionPermission::IsSACalling()) { -- Gitee From f06129b29850c3aa63b92a3eb5d8e0c42f2097f9 Mon Sep 17 00:00:00 2001 From: zhangdingzhong Date: Sun, 14 Apr 2024 21:45:20 +0800 Subject: [PATCH 02/15] =?UTF-8?q?DFX=20=E7=AA=97=E5=8F=A3=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdingzhong --- .../session/host/include/main_session.h | 1 + window_scene/session/host/include/session.h | 6 ++- .../session/host/include/sub_session.h | 1 + .../session/host/include/system_session.h | 1 + .../session/host/src/main_session.cpp | 8 ++++ window_scene/session/host/src/session.cpp | 40 +++++++++++++++++++ window_scene/session/host/src/sub_session.cpp | 8 ++++ .../session/host/src/system_session.cpp | 11 +++++ 8 files changed, 75 insertions(+), 1 deletion(-) diff --git a/window_scene/session/host/include/main_session.h b/window_scene/session/host/include/main_session.h index 1108fe97b2..498395d17a 100644 --- a/window_scene/session/host/include/main_session.h +++ b/window_scene/session/host/include/main_session.h @@ -32,6 +32,7 @@ public: WSError TransferKeyEvent(const std::shared_ptr& keyEvent) override; WSError SetTopmost(bool topmost) override; bool IsTopmost() const override; + void RectCheck(uint32_t curWidth, uint32_t curHeigth) override; protected: void UpdatePointerArea(const WSRect& rect) override; diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index 3a72762049..f34b98018b 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -380,7 +380,11 @@ public: void RegisterWindowModeChangedCallback(const std::function& callback); void SetAttachState(bool isAttach); void RegisterDetachCallback(const sptr& callback); - void RegisterWindowBackHomeCallback(const std::function& callback) {}; + SystemSessionConfig GetSystemSessionConfig() const; + void RectCheckProcess(); + virtual void RectCheck(uint32_t curWidth, uint32_t curHeigth) {}; + void RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeigth, + uint32_t minWidth, uint32_t minHeigth, uint32_t maxFloatingWindowSize); protected: class SessionLifeCycleTask : public virtual RefBase { diff --git a/window_scene/session/host/include/sub_session.h b/window_scene/session/host/include/sub_session.h index 4a6791b72f..f0d9cbd7e7 100644 --- a/window_scene/session/host/include/sub_session.h +++ b/window_scene/session/host/include/sub_session.h @@ -33,6 +33,7 @@ public: WSError TransferKeyEvent(const std::shared_ptr& keyEvent) override; int32_t GetMissionId() const override; + void RectCheck(uint32_t curWidth, uint32_t curHeigth) override; protected: void UpdatePointerArea(const WSRect& rect) override; bool CheckPointerEventDispatch(const std::shared_ptr& pointerEvent) const override; diff --git a/window_scene/session/host/include/system_session.h b/window_scene/session/host/include/system_session.h index 96213823fe..a20fb49c06 100644 --- a/window_scene/session/host/include/system_session.h +++ b/window_scene/session/host/include/system_session.h @@ -38,6 +38,7 @@ public: WSError NotifyClientToUpdateRect(std::shared_ptr rsTransaction) override; int32_t GetMissionId() const override; + void RectCheck(uint32_t curWidth, uint32_t curHeigth) override; protected: bool CheckKeyEventDispatch(const std::shared_ptr& keyEvent) const; diff --git a/window_scene/session/host/src/main_session.cpp b/window_scene/session/host/src/main_session.cpp index 5863e4d62b..ab7a2981e5 100644 --- a/window_scene/session/host/src/main_session.cpp +++ b/window_scene/session/host/src/main_session.cpp @@ -194,4 +194,12 @@ bool MainSession::IfNotNeedAvoidKeyBoardForSplit() } return true; } + +void MainSession::RectCheck(uint32_t curWidth, uint32_t curHeigth) +{ + uint32_t minWidth = GetSystemConfig().miniWidthOfMainWindow_; + uint32_t minHeigth = GetSystemConfig().miniHeightOfMainWindow_; + uint32_t maxFloatingWindowSize = GetSystemConfig().maxFloatingWindowSize_; + RectSizeCheckProcess(curWidth, curHeigth, minWidth, minHeigth, maxFloatingWindowSize); +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index b5a678aaf4..a42040799a 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -736,6 +736,7 @@ WSError Session::UpdateRect(const WSRect& rect, SizeChangeReason reason, winRect_ = rect; if (sessionStage_ != nullptr) { sessionStage_->UpdateRect(rect, reason, rsTransaction); + RectCheckProcess(); } else { WLOGFE("sessionStage_ is nullptr"); } @@ -1977,6 +1978,39 @@ sptr Session::GetSessionProperty() const return property_; } +void Session::RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeigth, + uint32_t minWidth, uint32_t minHeigth, uint32_t maxFloatingWindowSize) +{ + if ((curWidth < minWidth) || (curWidth > maxFloatingWindowSize) || + (curHeigth < minHeigth) || (curHeigth > maxFloatingWindowSize)) { + WLOGFE("RectSizeCheckProcess sessionId: %{public}d rect %{public}s", + GetPersistentId(), GetSessionRect().ToString().c_str()); + } +} + +void Session::RectCheckProcess() +{ + auto displayId = GetSessionProperty()->GetDisplayId(); + stdmap screenProperties = + Rosen::ScreenSessionManagerClient::GetInstance().getAllScreenProperties(); + if (screenProperties.find(displayId) == screenProperties.end) { + return; + } + auto screenProperty = screenProperties[displayId]; + float density = screenProperty.GetDensity(); + if (density <= 0) { + return; + } + uint32_t curWidth = static_castSetSessionRect().width_ / density; + uint32_t curHeigth = static_castSetSessionRect().heigth / density; + float ratio = GetAspectRatio(); + float actRatio = static_cast(curWidth) / curHeigth; + if ((ratio != 0) && !NearEqual(ratio, actRatio)) { + WLOGFE("RectCheckProcess ratio %{public}f != actRatio: %{public}f", ratio, actRatio); + } + RectCheck(curWidth, curHeigth); +} + void Session::SetSessionRect(const WSRect& rect) { if (winRect_ == rect) { @@ -1985,6 +2019,7 @@ void Session::SetSessionRect(const WSRect& rect) } winRect_ = rect; isDirty_ = true; + RectCheckProcess(); } WSRect Session::GetSessionRect() const @@ -2031,6 +2066,11 @@ void Session::SetSystemConfig(const SystemSessionConfig& systemConfig) systemConfig_ = systemConfig; } +SystemSessionConfig Session::GetSystemConfig() +{ + return systemConfig_; +} + void Session::SetSnapshotScale(const float snapshotScale) { snapshotScale_ = snapshotScale; diff --git a/window_scene/session/host/src/sub_session.cpp b/window_scene/session/host/src/sub_session.cpp index bdbc9c2e15..c3da1c6200 100644 --- a/window_scene/session/host/src/sub_session.cpp +++ b/window_scene/session/host/src/sub_session.cpp @@ -185,4 +185,12 @@ bool SubSession::IfNotNeedAvoidKeyBoardForSplit() } return true; } + +void SubSession::RectCheck(uint32_t curWidth, uint32_t curHeigth) +{ + uint32_t minWidth = GetSystemConfig().miniWidthOfSubWindow_; + uint32_t minHeigth = GetSystemConfig().miniHeightOfSubWindow_; + uint32_t maxFloatingWindowSize = GetSystemConfig().maxFloatingWindowSize_; + RectSizeCheckProcess(curWidth, curHeigth, minWidth, minHeigth, maxFloatingWindowSize); +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/system_session.cpp b/window_scene/session/host/src/system_session.cpp index ae75549483..3467344c0c 100644 --- a/window_scene/session/host/src/system_session.cpp +++ b/window_scene/session/host/src/system_session.cpp @@ -26,6 +26,9 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SystemSession" }; } // namespace +constexpr uint32_t MIN_SYSTEM_WINDOW_WIDTH = 5; +constexpr uint32_t MIN_SYSTEM_WINDOW_HEIGTH = 5; + SystemSession::SystemSession(const SessionInfo& info, const sptr& specificCallback) : SceneSession(info, specificCallback) { @@ -306,4 +309,12 @@ bool SystemSession::NeedSystemPermission(WindowType type) type == WindowType::WINDOW_TYPE_DRAGGING_EFFECT || type == WindowType::WINDOW_TYPE_APP_LAUNCHING || type == WindowType::WINDOW_TYPE_PIP); } + +void SystemSession::RectCheck(uint32_t curWidth, uint32_t curHeigth) +{ + uint32_t minWidth = MIN_SYSTEM_WINDOW_WIDTH; + uint32_t minHeigth = MIN_SYSTEM_WINDOW_HEIGTH; + uint32_t maxFloatingWindowSize = GetSystemConfig().maxFloatingWindowSize_; + RectSizeCheckProcess(curWidth, curHeigth, minWidth, minHeigth, maxFloatingWindowSize); +} } // namespace OHOS::Rosen -- Gitee From bfa012d8942733e7d8dc9c65374015f9987c26e4 Mon Sep 17 00:00:00 2001 From: zhangdingzhong Date: Sun, 14 Apr 2024 21:45:20 +0800 Subject: [PATCH 03/15] =?UTF-8?q?DFX=20=E7=AA=97=E5=8F=A3=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdingzhong --- .../session/host/include/main_session.h | 1 + window_scene/session/host/include/session.h | 7 +++- .../session/host/include/sub_session.h | 1 + .../session/host/include/system_session.h | 1 + .../session/host/src/main_session.cpp | 8 ++++ window_scene/session/host/src/session.cpp | 40 +++++++++++++++++++ window_scene/session/host/src/sub_session.cpp | 8 ++++ .../session/host/src/system_session.cpp | 11 +++++ 8 files changed, 76 insertions(+), 1 deletion(-) diff --git a/window_scene/session/host/include/main_session.h b/window_scene/session/host/include/main_session.h index 1108fe97b2..498395d17a 100644 --- a/window_scene/session/host/include/main_session.h +++ b/window_scene/session/host/include/main_session.h @@ -32,6 +32,7 @@ public: WSError TransferKeyEvent(const std::shared_ptr& keyEvent) override; WSError SetTopmost(bool topmost) override; bool IsTopmost() const override; + void RectCheck(uint32_t curWidth, uint32_t curHeigth) override; protected: void UpdatePointerArea(const WSRect& rect) override; diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index 3a72762049..e33e8912ac 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -380,7 +380,12 @@ public: void RegisterWindowModeChangedCallback(const std::function& callback); void SetAttachState(bool isAttach); void RegisterDetachCallback(const sptr& callback); - void RegisterWindowBackHomeCallback(const std::function& callback) {}; + SystemSessionConfig GetSystemSessionConfig() const; + void RectCheckProcess(); + void RegisterWindowBackHomeCallback(const std::function& callback) {}; + virtual void RectCheck(uint32_t curWidth, uint32_t curHeigth) {}; + void RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeigth, + uint32_t minWidth, uint32_t minHeigth, uint32_t maxFloatingWindowSize); protected: class SessionLifeCycleTask : public virtual RefBase { diff --git a/window_scene/session/host/include/sub_session.h b/window_scene/session/host/include/sub_session.h index 4a6791b72f..f0d9cbd7e7 100644 --- a/window_scene/session/host/include/sub_session.h +++ b/window_scene/session/host/include/sub_session.h @@ -33,6 +33,7 @@ public: WSError TransferKeyEvent(const std::shared_ptr& keyEvent) override; int32_t GetMissionId() const override; + void RectCheck(uint32_t curWidth, uint32_t curHeigth) override; protected: void UpdatePointerArea(const WSRect& rect) override; bool CheckPointerEventDispatch(const std::shared_ptr& pointerEvent) const override; diff --git a/window_scene/session/host/include/system_session.h b/window_scene/session/host/include/system_session.h index 96213823fe..a20fb49c06 100644 --- a/window_scene/session/host/include/system_session.h +++ b/window_scene/session/host/include/system_session.h @@ -38,6 +38,7 @@ public: WSError NotifyClientToUpdateRect(std::shared_ptr rsTransaction) override; int32_t GetMissionId() const override; + void RectCheck(uint32_t curWidth, uint32_t curHeigth) override; protected: bool CheckKeyEventDispatch(const std::shared_ptr& keyEvent) const; diff --git a/window_scene/session/host/src/main_session.cpp b/window_scene/session/host/src/main_session.cpp index 5863e4d62b..ab7a2981e5 100644 --- a/window_scene/session/host/src/main_session.cpp +++ b/window_scene/session/host/src/main_session.cpp @@ -194,4 +194,12 @@ bool MainSession::IfNotNeedAvoidKeyBoardForSplit() } return true; } + +void MainSession::RectCheck(uint32_t curWidth, uint32_t curHeigth) +{ + uint32_t minWidth = GetSystemConfig().miniWidthOfMainWindow_; + uint32_t minHeigth = GetSystemConfig().miniHeightOfMainWindow_; + uint32_t maxFloatingWindowSize = GetSystemConfig().maxFloatingWindowSize_; + RectSizeCheckProcess(curWidth, curHeigth, minWidth, minHeigth, maxFloatingWindowSize); +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index b5a678aaf4..a42040799a 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -736,6 +736,7 @@ WSError Session::UpdateRect(const WSRect& rect, SizeChangeReason reason, winRect_ = rect; if (sessionStage_ != nullptr) { sessionStage_->UpdateRect(rect, reason, rsTransaction); + RectCheckProcess(); } else { WLOGFE("sessionStage_ is nullptr"); } @@ -1977,6 +1978,39 @@ sptr Session::GetSessionProperty() const return property_; } +void Session::RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeigth, + uint32_t minWidth, uint32_t minHeigth, uint32_t maxFloatingWindowSize) +{ + if ((curWidth < minWidth) || (curWidth > maxFloatingWindowSize) || + (curHeigth < minHeigth) || (curHeigth > maxFloatingWindowSize)) { + WLOGFE("RectSizeCheckProcess sessionId: %{public}d rect %{public}s", + GetPersistentId(), GetSessionRect().ToString().c_str()); + } +} + +void Session::RectCheckProcess() +{ + auto displayId = GetSessionProperty()->GetDisplayId(); + stdmap screenProperties = + Rosen::ScreenSessionManagerClient::GetInstance().getAllScreenProperties(); + if (screenProperties.find(displayId) == screenProperties.end) { + return; + } + auto screenProperty = screenProperties[displayId]; + float density = screenProperty.GetDensity(); + if (density <= 0) { + return; + } + uint32_t curWidth = static_castSetSessionRect().width_ / density; + uint32_t curHeigth = static_castSetSessionRect().heigth / density; + float ratio = GetAspectRatio(); + float actRatio = static_cast(curWidth) / curHeigth; + if ((ratio != 0) && !NearEqual(ratio, actRatio)) { + WLOGFE("RectCheckProcess ratio %{public}f != actRatio: %{public}f", ratio, actRatio); + } + RectCheck(curWidth, curHeigth); +} + void Session::SetSessionRect(const WSRect& rect) { if (winRect_ == rect) { @@ -1985,6 +2019,7 @@ void Session::SetSessionRect(const WSRect& rect) } winRect_ = rect; isDirty_ = true; + RectCheckProcess(); } WSRect Session::GetSessionRect() const @@ -2031,6 +2066,11 @@ void Session::SetSystemConfig(const SystemSessionConfig& systemConfig) systemConfig_ = systemConfig; } +SystemSessionConfig Session::GetSystemConfig() +{ + return systemConfig_; +} + void Session::SetSnapshotScale(const float snapshotScale) { snapshotScale_ = snapshotScale; diff --git a/window_scene/session/host/src/sub_session.cpp b/window_scene/session/host/src/sub_session.cpp index bdbc9c2e15..c3da1c6200 100644 --- a/window_scene/session/host/src/sub_session.cpp +++ b/window_scene/session/host/src/sub_session.cpp @@ -185,4 +185,12 @@ bool SubSession::IfNotNeedAvoidKeyBoardForSplit() } return true; } + +void SubSession::RectCheck(uint32_t curWidth, uint32_t curHeigth) +{ + uint32_t minWidth = GetSystemConfig().miniWidthOfSubWindow_; + uint32_t minHeigth = GetSystemConfig().miniHeightOfSubWindow_; + uint32_t maxFloatingWindowSize = GetSystemConfig().maxFloatingWindowSize_; + RectSizeCheckProcess(curWidth, curHeigth, minWidth, minHeigth, maxFloatingWindowSize); +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/system_session.cpp b/window_scene/session/host/src/system_session.cpp index ae75549483..3467344c0c 100644 --- a/window_scene/session/host/src/system_session.cpp +++ b/window_scene/session/host/src/system_session.cpp @@ -26,6 +26,9 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SystemSession" }; } // namespace +constexpr uint32_t MIN_SYSTEM_WINDOW_WIDTH = 5; +constexpr uint32_t MIN_SYSTEM_WINDOW_HEIGTH = 5; + SystemSession::SystemSession(const SessionInfo& info, const sptr& specificCallback) : SceneSession(info, specificCallback) { @@ -306,4 +309,12 @@ bool SystemSession::NeedSystemPermission(WindowType type) type == WindowType::WINDOW_TYPE_DRAGGING_EFFECT || type == WindowType::WINDOW_TYPE_APP_LAUNCHING || type == WindowType::WINDOW_TYPE_PIP); } + +void SystemSession::RectCheck(uint32_t curWidth, uint32_t curHeigth) +{ + uint32_t minWidth = MIN_SYSTEM_WINDOW_WIDTH; + uint32_t minHeigth = MIN_SYSTEM_WINDOW_HEIGTH; + uint32_t maxFloatingWindowSize = GetSystemConfig().maxFloatingWindowSize_; + RectSizeCheckProcess(curWidth, curHeigth, minWidth, minHeigth, maxFloatingWindowSize); +} } // namespace OHOS::Rosen -- Gitee From 364fe391a74469f02ff3a6963981b41e5958b966 Mon Sep 17 00:00:00 2001 From: zhangdingzhong Date: Mon, 15 Apr 2024 10:45:18 +0800 Subject: [PATCH 04/15] =?UTF-8?q?DFX=E7=AA=97=E5=8F=A3=E5=B1=82=E7=BA=A7?= =?UTF-8?q?=E7=84=A6=E7=82=B9=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdingzhong --- .../js_scene_session_manager.cpp | 14 ++++++++++++++ .../js_scene_session_manager.h | 2 ++ 2 files changed, 16 insertions(+) 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 6707b16def..2998bd336c 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 @@ -98,6 +98,7 @@ napi_value JsSceneSessionManager::Init(napi_env env, napi_value exportObj) BindNativeFunction(env, exportObj, "getWindowSceneConfig", moduleName, JsSceneSessionManager::GetWindowSceneConfig); BindNativeFunction(env, exportObj, "processBackEvent", moduleName, JsSceneSessionManager::ProcessBackEvent); + BindNativeFunction(env, exportObj, "checkSceneZOrder", moduleName, JsSceneSessionManager::CheckSceneZOrder); BindNativeFunction(env, exportObj, "updateFocus", moduleName, JsSceneSessionManager::UpdateFocus); BindNativeFunction(env, exportObj, "switchUser", moduleName, JsSceneSessionManager::SwitchUser); BindNativeFunction(env, exportObj, "requestSceneSessionByCall", moduleName, @@ -456,6 +457,13 @@ napi_value JsSceneSessionManager::ProcessBackEvent(napi_env env, napi_callback_i return (me != nullptr) ? me->OnProcessBackEvent(env, info) : nullptr; } +napi_value JsSceneSessionManager::CheckSceneZOrder(napi_env env, napi_callback_info info) +{ + WLOGFI("[NAPI]CheckSceneZOrder"); + JsSceneSessionManager* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnCheckSceneZOrder(env, info) : nullptr; +} + napi_value JsSceneSessionManager::SwitchUser(napi_env env, napi_callback_info info) { WLOGFI("[NAPI]SwitchUser"); @@ -801,6 +809,12 @@ napi_value JsSceneSessionManager::OnProcessBackEvent(napi_env env, napi_callback return NapiGetUndefined(env); } +napi_value JsSceneSessionManager::OnCheckSceneZOrder(napi_env env, napi_callback_info info) +{ + SceneSessionManager::GetInstance().CheckSceneZOrder(); + return NapiGetUndefined(env); +} + napi_value JsSceneSessionManager::OnGetAllAbilityInfos(napi_env env, napi_callback_info info) { size_t argc = 4; 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 d4b84f9c87..80585cc834 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 @@ -50,6 +50,7 @@ public: static napi_value RegisterCallback(napi_env env, napi_callback_info info); static napi_value GetWindowSceneConfig(napi_env env, napi_callback_info info); static napi_value ProcessBackEvent(napi_env env, napi_callback_info info); + static napi_value CheckSceneZOrder(napi_env env, napi_callback_info info); static napi_value UpdateFocus(napi_env env, napi_callback_info info); static napi_value SwitchUser(napi_env env, napi_callback_info info); static napi_value GetSessionSnapshotFilePath(napi_env env, napi_callback_info info); @@ -89,6 +90,7 @@ private: napi_value OnChangeUIAbilityVisibilityBySCB(napi_env env, napi_callback_info info); napi_value OnGetWindowSceneConfig(napi_env env, napi_callback_info info); napi_value OnProcessBackEvent(napi_env env, napi_callback_info info); + napi_value OnCheckSceneZOrder(napi_env env, napi_callback_info info); napi_value OnUpdateFocus(napi_env env, napi_callback_info info); napi_value OnSwitchUser(napi_env env, napi_callback_info info); napi_value OnGetSessionSnapshotFilePath(napi_env env, napi_callback_info info); -- Gitee From 5a6b3211f794f47339c6fc2923a41ef12e1d3a81 Mon Sep 17 00:00:00 2001 From: zhangdingzhong Date: Mon, 15 Apr 2024 11:23:26 +0800 Subject: [PATCH 05/15] =?UTF-8?q?DFX=20=E7=AA=97=E5=8F=A3=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E6=A3=80=E6=B5=8B=20fix=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdingzhong --- window_scene/session/host/src/session.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index a42040799a..c306c0052f 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -35,6 +35,7 @@ #include "parameters.h" #include #include "hitrace_meter.h" +#include "screen_session_manager/include/screen_session_manager_client.h" namespace OHOS::Rosen { namespace { @@ -1991,7 +1992,7 @@ void Session::RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeigth, void Session::RectCheckProcess() { auto displayId = GetSessionProperty()->GetDisplayId(); - stdmap screenProperties = + std::map screenProperties = Rosen::ScreenSessionManagerClient::GetInstance().getAllScreenProperties(); if (screenProperties.find(displayId) == screenProperties.end) { return; @@ -2001,8 +2002,8 @@ void Session::RectCheckProcess() if (density <= 0) { return; } - uint32_t curWidth = static_castSetSessionRect().width_ / density; - uint32_t curHeigth = static_castSetSessionRect().heigth / density; + uint32_t curWidth = static_cast(GetSessionRect().width_ / density); + uint32_t curHeigth = static_cast(GetSessionRect().heigth / density); float ratio = GetAspectRatio(); float actRatio = static_cast(curWidth) / curHeigth; if ((ratio != 0) && !NearEqual(ratio, actRatio)) { -- Gitee From ecae6d2751bfe08899a7d583cbcedc27c98a0260 Mon Sep 17 00:00:00 2001 From: zhangdingzhong Date: Mon, 15 Apr 2024 11:42:26 +0800 Subject: [PATCH 06/15] =?UTF-8?q?DFX=E7=AA=97=E5=8F=A3=E5=B1=82=E7=BA=A7?= =?UTF-8?q?=E7=84=A6=E7=82=B9=E6=A3=80=E6=B5=8B=20bug=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdingzhong --- window_scene/session_manager/src/anomaly_detection.cpp | 9 ++------- .../session_manager/src/scene_session_manager.cpp | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/window_scene/session_manager/src/anomaly_detection.cpp b/window_scene/session_manager/src/anomaly_detection.cpp index 87a3e5cb31..2421105604 100644 --- a/window_scene/session_manager/src/anomaly_detection.cpp +++ b/window_scene/session_manager/src/anomaly_detection.cpp @@ -16,23 +16,19 @@ #include "anomaly_detection.h" #include "dfx_hisysevent.h" -#include "window_manager_hilog.h" #include "interfaces/include/ws_common.h" #include "session_manager/include/scene_session_manager.h" -#include "session_helper.h" #include "window_helper.h" #include "screen_session_manager/include/screen_session_manager_client.h" -#include "session/screen/include/screen_property.h" namespace OHOS { namespace Rosen { namespace { -constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "AnomalyDetection" }; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "AnomalyDetection" }; } void AnomalyDetection::SceneZorderCheckProcess() { - TLOGI(WmsLogTag::WMS_FOCUS, "SceneZorderCheckProcess"); bool keyGuardFlag = false; uint32_t curZOrder = 0; auto func = [&curZOrder, &keyGuardFlag](sptr session) { @@ -81,7 +77,6 @@ void AnomalyDetection::SceneZorderCheckProcess() void AnomalyDetection::FocusCheckProcess(int32_t focusId, int32_t nextId) { - TLOGI(WmsLogTag::WMS_FOCUS, "FocusCheckProcess"); if (nextId == INVALID_SESSION_ID) { TLOGE(WmsLogTag::WMS_FOCUS, "FocusCheck err: invalid id, focusID:%{public}d nextId:%{public}d", focusId, nextId); @@ -99,7 +94,7 @@ void AnomalyDetection::FocusCheckProcess(int32_t focusId, int32_t nextId) SceneSessionManager::GetInstance().IsSessionVisible(session)) { TLOGE(WmsLogTag::WMS_FOCUS, "FocusCheck err: blockingFocus, sessionID:%{public}d", session->GetPersistentId()); - }; + } return false; }; SceneSessionManager::GetInstance().TraverseSessionTree(func, false); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index a355547d8b..dd29466f89 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -95,7 +95,7 @@ #include "window_visibility_info.h" #include "window_drawing_content_info.h" -#include "session_manager/include/anomaly_detection.h" +#include "anomaly_detection.h" #ifdef MEMMGR_WINDOW_ENABLE #include "mem_mgr_client.h" #include "mem_mgr_window_info.h" -- Gitee From cc82582be0ca5cff1317db1fb191d688d367bda1 Mon Sep 17 00:00:00 2001 From: zhangdingzhong Date: Mon, 15 Apr 2024 15:28:27 +0800 Subject: [PATCH 07/15] =?UTF-8?q?DFX=20=E7=AA=97=E5=8F=A3=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E6=A3=80=E6=B5=8B=20fix=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdingzhong --- .../session/host/include/main_session.h | 2 +- window_scene/session/host/include/session.h | 6 ++--- .../session/host/include/sub_session.h | 2 +- .../session/host/include/system_session.h | 2 +- .../session/host/src/main_session.cpp | 6 ++--- window_scene/session/host/src/session.cpp | 26 +++++++++---------- window_scene/session/host/src/sub_session.cpp | 6 ++--- .../session/host/src/system_session.cpp | 8 +++--- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/window_scene/session/host/include/main_session.h b/window_scene/session/host/include/main_session.h index 498395d17a..4ec4354134 100644 --- a/window_scene/session/host/include/main_session.h +++ b/window_scene/session/host/include/main_session.h @@ -32,7 +32,7 @@ public: WSError TransferKeyEvent(const std::shared_ptr& keyEvent) override; WSError SetTopmost(bool topmost) override; bool IsTopmost() const override; - void RectCheck(uint32_t curWidth, uint32_t curHeigth) override; + void RectCheck(uint32_t curWidth, uint32_t curHeight) override; protected: void UpdatePointerArea(const WSRect& rect) override; diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index 6724fc3b09..1ded455567 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -383,9 +383,9 @@ public: void RegisterWindowBackHomeCallback(const std::function& callback) {}; SystemSessionConfig GetSystemConfig() const; void RectCheckProcess(); - virtual void RectCheck(uint32_t curWidth, uint32_t curHeigth) {}; - void RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeigth, - uint32_t minWidth, uint32_t minHeigth, uint32_t maxFloatingWindowSize); + virtual void RectCheck(uint32_t curWidth, uint32_t curHeight) {}; + void RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeight, uint32_t minWidth, + uint32_t minHeight, uint32_t maxFloatingWindowSize); protected: class SessionLifeCycleTask : public virtual RefBase { diff --git a/window_scene/session/host/include/sub_session.h b/window_scene/session/host/include/sub_session.h index f0d9cbd7e7..7835983dd6 100644 --- a/window_scene/session/host/include/sub_session.h +++ b/window_scene/session/host/include/sub_session.h @@ -33,7 +33,7 @@ public: WSError TransferKeyEvent(const std::shared_ptr& keyEvent) override; int32_t GetMissionId() const override; - void RectCheck(uint32_t curWidth, uint32_t curHeigth) override; + void RectCheck(uint32_t curWidth, uint32_t curHeight) override; protected: void UpdatePointerArea(const WSRect& rect) override; bool CheckPointerEventDispatch(const std::shared_ptr& pointerEvent) const override; diff --git a/window_scene/session/host/include/system_session.h b/window_scene/session/host/include/system_session.h index a20fb49c06..4b72a6ad91 100644 --- a/window_scene/session/host/include/system_session.h +++ b/window_scene/session/host/include/system_session.h @@ -38,7 +38,7 @@ public: WSError NotifyClientToUpdateRect(std::shared_ptr rsTransaction) override; int32_t GetMissionId() const override; - void RectCheck(uint32_t curWidth, uint32_t curHeigth) override; + void RectCheck(uint32_t curWidth, uint32_t curHeight) override; protected: bool CheckKeyEventDispatch(const std::shared_ptr& keyEvent) const; diff --git a/window_scene/session/host/src/main_session.cpp b/window_scene/session/host/src/main_session.cpp index ab7a2981e5..6c13253f5b 100644 --- a/window_scene/session/host/src/main_session.cpp +++ b/window_scene/session/host/src/main_session.cpp @@ -195,11 +195,11 @@ bool MainSession::IfNotNeedAvoidKeyBoardForSplit() return true; } -void MainSession::RectCheck(uint32_t curWidth, uint32_t curHeigth) +void MainSession::RectCheck(uint32_t curWidth, uint32_t curHeight) { uint32_t minWidth = GetSystemConfig().miniWidthOfMainWindow_; - uint32_t minHeigth = GetSystemConfig().miniHeightOfMainWindow_; + uint32_t minHeight = GetSystemConfig().miniHeightOfMainWindow_; uint32_t maxFloatingWindowSize = GetSystemConfig().maxFloatingWindowSize_; - RectSizeCheckProcess(curWidth, curHeigth, minWidth, minHeigth, maxFloatingWindowSize); + RectSizeCheckProcess(curWidth, curHeight, minWidth, minHeight, maxFloatingWindowSize); } } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index c306c0052f..f424990956 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -1979,12 +1979,12 @@ sptr Session::GetSessionProperty() const return property_; } -void Session::RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeigth, - uint32_t minWidth, uint32_t minHeigth, uint32_t maxFloatingWindowSize) +void Session::RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeight, uint32_t minWidth, + uint32_t minHeight, uint32_t maxFloatingWindowSize) { if ((curWidth < minWidth) || (curWidth > maxFloatingWindowSize) || - (curHeigth < minHeigth) || (curHeigth > maxFloatingWindowSize)) { - WLOGFE("RectSizeCheckProcess sessionId: %{public}d rect %{public}s", + (curHeight < minHeight) || (curHeight > maxFloatingWindowSize)) { + WLOGFE("RectCheck err sessionID: %{public}d rect %{public}s", GetPersistentId(), GetSessionRect().ToString().c_str()); } } @@ -1992,24 +1992,24 @@ void Session::RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeigth, void Session::RectCheckProcess() { auto displayId = GetSessionProperty()->GetDisplayId(); - std::map screenProperties = - Rosen::ScreenSessionManagerClient::GetInstance().getAllScreenProperties(); - if (screenProperties.find(displayId) == screenProperties.end) { + std::map screensProperties = + Rosen::ScreenSessionManagerClient::GetInstance().GetAllScreensProperties(); + if (screensProperties.find(displayId) == screensProperties.end()) { return; } - auto screenProperty = screenProperties[displayId]; + auto screenProperty = screensProperties[displayId]; float density = screenProperty.GetDensity(); if (density <= 0) { return; } uint32_t curWidth = static_cast(GetSessionRect().width_ / density); - uint32_t curHeigth = static_cast(GetSessionRect().heigth / density); + uint32_t curHeight = static_cast(GetSessionRect().height_ / density); float ratio = GetAspectRatio(); - float actRatio = static_cast(curWidth) / curHeigth; + float actRatio = static_cast(curWidth) / curHeight; if ((ratio != 0) && !NearEqual(ratio, actRatio)) { - WLOGFE("RectCheckProcess ratio %{public}f != actRatio: %{public}f", ratio, actRatio); + WLOGFE("RectCheck err ratio %{public}f != actRatio: %{public}f", ratio, actRatio); } - RectCheck(curWidth, curHeigth); + RectCheck(curWidth, curHeight); } void Session::SetSessionRect(const WSRect& rect) @@ -2067,7 +2067,7 @@ void Session::SetSystemConfig(const SystemSessionConfig& systemConfig) systemConfig_ = systemConfig; } -SystemSessionConfig Session::GetSystemConfig() +SystemSessionConfig Session::GetSystemConfig() const { return systemConfig_; } diff --git a/window_scene/session/host/src/sub_session.cpp b/window_scene/session/host/src/sub_session.cpp index c3da1c6200..d6d0057daa 100644 --- a/window_scene/session/host/src/sub_session.cpp +++ b/window_scene/session/host/src/sub_session.cpp @@ -186,11 +186,11 @@ bool SubSession::IfNotNeedAvoidKeyBoardForSplit() return true; } -void SubSession::RectCheck(uint32_t curWidth, uint32_t curHeigth) +void SubSession::RectCheck(uint32_t curWidth, uint32_t curHeight) { uint32_t minWidth = GetSystemConfig().miniWidthOfSubWindow_; - uint32_t minHeigth = GetSystemConfig().miniHeightOfSubWindow_; + uint32_t minHeight = GetSystemConfig().miniHeightOfSubWindow_; uint32_t maxFloatingWindowSize = GetSystemConfig().maxFloatingWindowSize_; - RectSizeCheckProcess(curWidth, curHeigth, minWidth, minHeigth, maxFloatingWindowSize); + RectSizeCheckProcess(curWidth, curHeight, minWidth, minHeight, maxFloatingWindowSize); } } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/system_session.cpp b/window_scene/session/host/src/system_session.cpp index 3467344c0c..1f81b658e5 100644 --- a/window_scene/session/host/src/system_session.cpp +++ b/window_scene/session/host/src/system_session.cpp @@ -27,7 +27,7 @@ constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "System } // namespace constexpr uint32_t MIN_SYSTEM_WINDOW_WIDTH = 5; -constexpr uint32_t MIN_SYSTEM_WINDOW_HEIGTH = 5; +constexpr uint32_t MIN_SYSTEM_WINDOW_HEIGHT = 5; SystemSession::SystemSession(const SessionInfo& info, const sptr& specificCallback) : SceneSession(info, specificCallback) @@ -310,11 +310,11 @@ bool SystemSession::NeedSystemPermission(WindowType type) type == WindowType::WINDOW_TYPE_PIP); } -void SystemSession::RectCheck(uint32_t curWidth, uint32_t curHeigth) +void SystemSession::RectCheck(uint32_t curWidth, uint32_t curHeight) { uint32_t minWidth = MIN_SYSTEM_WINDOW_WIDTH; - uint32_t minHeigth = MIN_SYSTEM_WINDOW_HEIGTH; + uint32_t minHeight = MIN_SYSTEM_WINDOW_HEIGHT; uint32_t maxFloatingWindowSize = GetSystemConfig().maxFloatingWindowSize_; - RectSizeCheckProcess(curWidth, curHeigth, minWidth, minHeigth, maxFloatingWindowSize); + RectSizeCheckProcess(curWidth, curHeight, minWidth, minHeight, maxFloatingWindowSize); } } // namespace OHOS::Rosen -- Gitee From 088e816c8f5b7b3f531e0d7d87bd27c114e7b1a6 Mon Sep 17 00:00:00 2001 From: zhangdingzhong Date: Mon, 15 Apr 2024 20:47:11 +0800 Subject: [PATCH 08/15] =?UTF-8?q?DFX=E7=AA=97=E5=8F=A3=E5=B1=82=E7=BA=A7?= =?UTF-8?q?=E7=84=A6=E7=82=B9=E6=A3=80=E6=B5=8B=20bug=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdingzhong --- .../js_scene_session_manager.cpp | 2 +- .../include/anomaly_detection.h | 10 ++++----- .../session_manager/src/anomaly_detection.cpp | 22 +++++++++---------- .../src/scene_session_manager.cpp | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index 2998bd336c..d381ca3abd 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 @@ -459,7 +459,7 @@ napi_value JsSceneSessionManager::ProcessBackEvent(napi_env env, napi_callback_i napi_value JsSceneSessionManager::CheckSceneZOrder(napi_env env, napi_callback_info info) { - WLOGFI("[NAPI]CheckSceneZOrder"); + WLOGD("[NAPI]CheckSceneZOrder"); JsSceneSessionManager* me = CheckParamsAndGetThis(env, info); return (me != nullptr) ? me->OnCheckSceneZOrder(env, info) : nullptr; } diff --git a/window_scene/session_manager/include/anomaly_detection.h b/window_scene/session_manager/include/anomaly_detection.h index 8fa9d06242..dfbf46a0e8 100644 --- a/window_scene/session_manager/include/anomaly_detection.h +++ b/window_scene/session_manager/include/anomaly_detection.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef ANOMALY_DETECTION -#define ANOMALY_DETECTION +#ifndef ANOMALY_DETECTION_H +#define ANOMALY_DETECTION_H #include "session/host/include/scene_session.h" @@ -29,9 +29,9 @@ enum class WindowDFXHelperType : uint32_t { class AnomalyDetection { public: - static void SceneZorderCheckProcess(); - static void FocusCheckProcess(int32_t focusId, int32_t nextId); + static void SceneZOrderCheckProcess(); + static void FocusCheckProcess(int32_t focusedId, int32_t nextId); }; } // namespace Rosen } // namespace OHOS -#endif // ANOMALY_DETECTION \ No newline at end of file +#endif // ANOMALY_DETECTION_H \ No newline at end of file diff --git a/window_scene/session_manager/src/anomaly_detection.cpp b/window_scene/session_manager/src/anomaly_detection.cpp index 2421105604..cb3003ad7c 100644 --- a/window_scene/session_manager/src/anomaly_detection.cpp +++ b/window_scene/session_manager/src/anomaly_detection.cpp @@ -27,7 +27,7 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "AnomalyDetection" }; } -void AnomalyDetection::SceneZorderCheckProcess() +void AnomalyDetection::SceneZOrderCheckProcess() { bool keyGuardFlag = false; uint32_t curZOrder = 0; @@ -37,20 +37,20 @@ void AnomalyDetection::SceneZorderCheckProcess() } // check zorder = 0 if (session->GetZOrder() == 0) { - TLOGE(WmsLogTag::WMS_FOCUS, "ZorderCheck err, zorder 0"); + TLOGE(WmsLogTag::WMS_FOCUS, "ZOrderCheck err, zorder 0"); } // repetitive zorder if (session->GetZOrder() == curZOrder) { - TLOGE(WmsLogTag::WMS_FOCUS, "ZorderCheck err, repetitive zorder %{public}d", session->GetZOrder()); + TLOGE(WmsLogTag::WMS_FOCUS, "ZOrderCheck err, repetitive zorder %{public}d", session->GetZOrder()); } curZOrder = session->GetZOrder(); // callingSession check for input method if (session->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { uint32_t callingWindowId = session->GetSessionProperty()->GetCallingSessionId(); const auto& callingSession = - SceneSessionManager::GetInstance().GetSceneSession(static_cast(callingWindowId)); + SceneSessionManager::GetInstance().GetSceneSession(static_cast(callingWindowId)); if (callingSession->GetZOrder() > session->GetZOrder()) { - TLOGE(WmsLogTag::WMS_FOCUS, "ZorderCheck err, callingSession %{public}d curSession %{public}d", + TLOGE(WmsLogTag::WMS_FOCUS, "ZOrderCheck err, callingSession: %{public}d curSession: %{public}d", callingSession->GetZOrder(), session->GetZOrder()); } } @@ -59,7 +59,7 @@ void AnomalyDetection::SceneZorderCheckProcess() session->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG) { auto mainSession = session->GetParentSession(); if (session->GetZOrder() < mainSession->GetZOrder()) { - TLOGE(WmsLogTag::WMS_FOCUS, "ZorderCheck err, subWindow %{public}d mainSession %{public}d", + TLOGE(WmsLogTag::WMS_FOCUS, "ZOrderCheck err, subSession %{public}d mainSession %{public}d", session->GetZOrder(), mainSession->GetZOrder()); } } @@ -68,18 +68,18 @@ void AnomalyDetection::SceneZorderCheckProcess() return false; }; if (keyGuardFlag && session->IsShowWhenLocked()) { - TLOGE(WmsLogTag::WMS_FOCUS, "ZorderCheck err %{public}d IsShowWhenLocked", session->GetZOrder()); + TLOGE(WmsLogTag::WMS_FOCUS, "ZOrderCheck err %{public}d IsShowWhenLocked", session->GetZOrder()); } return false; }; SceneSessionManager::GetInstance().TraverseSessionTree(func, false); } -void AnomalyDetection::FocusCheckProcess(int32_t focusId, int32_t nextId) +void AnomalyDetection::FocusCheckProcess(int32_t focusedId, int32_t nextId) { if (nextId == INVALID_SESSION_ID) { - TLOGE(WmsLogTag::WMS_FOCUS, "FocusCheck err: invalid id, focusID:%{public}d nextId:%{public}d", - focusId, nextId); + TLOGE(WmsLogTag::WMS_FOCUS, "FocusCheck err: invalid id, focusedId:%{public}d nextId:%{public}d", + focusedId, nextId); } bool focusSessionFlag = false; auto func = [&focusSessionFlag](sptr session) { @@ -92,7 +92,7 @@ void AnomalyDetection::FocusCheckProcess(int32_t focusId, int32_t nextId) } if (focusSessionFlag && session->GetBlockingFocus() && SceneSessionManager::GetInstance().IsSessionVisible(session)) { - TLOGE(WmsLogTag::WMS_FOCUS, "FocusCheck err: blockingFocus, sessionID:%{public}d", + TLOGE(WmsLogTag::WMS_FOCUS, "FocusCheck err: blockingFocus, sessionId:%{public}d", session->GetPersistentId()); } return false; diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index dd29466f89..acc5b0d881 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -7568,7 +7568,7 @@ WMError SceneSessionManager::GetCallingWindowRect(int32_t persistentId, Rect& re void SceneSessionManager::CheckSceneZOrder() { auto task = [this]() { - AnomalyDetection::SceneZorderCheckProcess(); + AnomalyDetection::SceneZOrderCheckProcess(); }; taskScheduler_->PostAsyncTask(task, "CheckSceneZOrder"); } -- Gitee From d82c8116f868a0223e78b28bc0dc3f915c94d7ee Mon Sep 17 00:00:00 2001 From: zhangdingzhong Date: Mon, 15 Apr 2024 20:53:39 +0800 Subject: [PATCH 09/15] =?UTF-8?q?DFX=E7=AA=97=E5=8F=A3=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=20bug=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdingzhong --- window_scene/session/host/src/session.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index f424990956..50a39d89ed 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -1999,17 +1999,16 @@ void Session::RectCheckProcess() } auto screenProperty = screensProperties[displayId]; float density = screenProperty.GetDensity(); - if (density <= 0) { - return; - } - uint32_t curWidth = static_cast(GetSessionRect().width_ / density); - uint32_t curHeight = static_cast(GetSessionRect().height_ / density); - float ratio = GetAspectRatio(); - float actRatio = static_cast(curWidth) / curHeight; - if ((ratio != 0) && !NearEqual(ratio, actRatio)) { - WLOGFE("RectCheck err ratio %{public}f != actRatio: %{public}f", ratio, actRatio); + if (!NearZero(density)) { + uint32_t curWidth = static_cast(GetSessionRect().width_ / density); + uint32_t curHeight = static_cast(GetSessionRect().height_ / density); + float ratio = GetAspectRatio(); + float actRatio = static_cast(curWidth) / curHeight; + if ((ratio != 0) && !NearEqual(ratio, actRatio)) { + WLOGFE("RectCheck err ratio %{public}f != actRatio: %{public}f", ratio, actRatio); + } + RectCheck(curWidth, curHeight); } - RectCheck(curWidth, curHeight); } void Session::SetSessionRect(const WSRect& rect) -- Gitee From 0b7c3e64a77644a057bcd5a39aa4cb00e7e254f7 Mon Sep 17 00:00:00 2001 From: "hwwolify.liu" Date: Mon, 15 Apr 2024 22:13:38 +0800 Subject: [PATCH 10/15] update gn Signed-off-by: hwwolify.liu --- window_scene/session_manager/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/session_manager/BUILD.gn b/window_scene/session_manager/BUILD.gn index 9be9bc450c..6cec1282ae 100644 --- a/window_scene/session_manager/BUILD.gn +++ b/window_scene/session_manager/BUILD.gn @@ -76,11 +76,11 @@ ohos_shared_library("scene_session_manager") { "src/session_listener_controller.cpp", "src/session_manager_agent_controller.cpp", "src/window_scene_config.cpp", + "src/anomaly_detection.cpp", "src/zidl/scene_session_manager_lite_stub.cpp", "src/zidl/scene_session_manager_stub.cpp", "src/zidl/session_listener_proxy.cpp", "src/zidl/session_listener_stub.cpp", - "src/anomaly_detection.cpp", ] public_configs = [ -- Gitee From dd65204bc11edae6c8d5b49dfdb9ac2539453e4e Mon Sep 17 00:00:00 2001 From: "hwwolify.liu" Date: Mon, 15 Apr 2024 22:19:29 +0800 Subject: [PATCH 11/15] update gn Signed-off-by: hwwolify.liu --- window_scene/session_manager/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/session_manager/BUILD.gn b/window_scene/session_manager/BUILD.gn index 6cec1282ae..df77eaf541 100644 --- a/window_scene/session_manager/BUILD.gn +++ b/window_scene/session_manager/BUILD.gn @@ -65,6 +65,7 @@ ohos_shared_library("scene_session_manager") { } sources = [ "../../wm/src/zidl/window_manager_agent_proxy.cpp", + "src/anomaly_detection.cpp", "src/distributed_client.cpp", "src/extension_session_manager.cpp", "src/scb_session_handler.cpp", @@ -76,7 +77,6 @@ ohos_shared_library("scene_session_manager") { "src/session_listener_controller.cpp", "src/session_manager_agent_controller.cpp", "src/window_scene_config.cpp", - "src/anomaly_detection.cpp", "src/zidl/scene_session_manager_lite_stub.cpp", "src/zidl/scene_session_manager_stub.cpp", "src/zidl/session_listener_proxy.cpp", -- Gitee From e73e886a67d9d2a819dd5374fa42ea8e5f1e7004 Mon Sep 17 00:00:00 2001 From: zhangdingzhong Date: Tue, 16 Apr 2024 16:12:57 +0800 Subject: [PATCH 12/15] =?UTF-8?q?DFX=E7=AA=97=E5=8F=A3Rect=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E6=9C=80=E5=B0=8F=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdingzhong --- window_scene/common/include/window_session_property.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/window_scene/common/include/window_session_property.h b/window_scene/common/include/window_session_property.h index 8374e5e13b..874e6cecdc 100755 --- a/window_scene/common/include/window_session_property.h +++ b/window_scene/common/include/window_session_property.h @@ -219,11 +219,11 @@ struct SystemSessionConfig : public Parcelable { bool isStretchable_ = false; WindowMode defaultWindowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN; KeyboardAnimationConfig keyboardAnimationConfig_; - uint32_t maxFloatingWindowSize_ = UINT32_MAX; - uint32_t miniWidthOfMainWindow_ = 0; - uint32_t miniHeightOfMainWindow_ = 0; - uint32_t miniWidthOfSubWindow_ = 0; - uint32_t miniHeightOfSubWindow_ = 0; + uint32_t maxFloatingWindowSize_ = 1920; + uint32_t miniWidthOfMainWindow_ = 320; + uint32_t miniHeightOfMainWindow_ = 240; + uint32_t miniWidthOfSubWindow_ = 320; + uint32_t miniHeightOfSubWindow_ = 240; bool backgroundswitch = false; virtual bool Marshalling(Parcel& parcel) const override -- Gitee From e223f66894ace6de19d93de94c9188bb14b07320 Mon Sep 17 00:00:00 2001 From: zhangdingzhong Date: Wed, 17 Apr 2024 11:31:45 +0800 Subject: [PATCH 13/15] DFX rect foreground judge Signed-off-by: zhangdingzhong --- window_scene/session/host/src/session.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 59d34a96d7..c5a6b572e2 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -1996,6 +1996,9 @@ void Session::RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeight, uint32 void Session::RectCheckProcess() { + if (!IsSessionForeground()) { + return; + } auto displayId = GetSessionProperty()->GetDisplayId(); std::map screensProperties = Rosen::ScreenSessionManagerClient::GetInstance().GetAllScreensProperties(); -- Gitee From 513f425eb65ffc44151af50049c59ee0289f279d Mon Sep 17 00:00:00 2001 From: zhangdingzhong Date: Wed, 17 Apr 2024 11:52:10 +0800 Subject: [PATCH 14/15] DFX rect foreground judge Signed-off-by: zhangdingzhong --- window_scene/session/host/src/session.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index c5a6b572e2..52ac77edb3 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -1996,7 +1996,7 @@ void Session::RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeight, uint32 void Session::RectCheckProcess() { - if (!IsSessionForeground()) { + if (!(IsSessionForeground() || isVisible_)) { return; } auto displayId = GetSessionProperty()->GetDisplayId(); -- Gitee From fe4c52ebdca2b4be857c1c8ce845a7091a09f045 Mon Sep 17 00:00:00 2001 From: zhangdingzhong Date: Wed, 17 Apr 2024 16:37:24 +0800 Subject: [PATCH 15/15] DFX code check Signed-off-by: zhangdingzhong --- window_scene/common/include/window_session_property.h | 5 +++++ window_scene/session/host/src/session.cpp | 6 +++--- window_scene/session_manager/include/anomaly_detection.h | 6 +++--- window_scene/session_manager/src/anomaly_detection.cpp | 8 ++++---- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/window_scene/common/include/window_session_property.h b/window_scene/common/include/window_session_property.h index 874e6cecdc..0e20162f83 100755 --- a/window_scene/common/include/window_session_property.h +++ b/window_scene/common/include/window_session_property.h @@ -219,10 +219,15 @@ struct SystemSessionConfig : public Parcelable { bool isStretchable_ = false; WindowMode defaultWindowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN; KeyboardAnimationConfig keyboardAnimationConfig_; + // 1920: default max window size uint32_t maxFloatingWindowSize_ = 1920; + // 320: default minWidth main window size uint32_t miniWidthOfMainWindow_ = 320; + // 240: default minHeight main window size uint32_t miniHeightOfMainWindow_ = 240; + // 320: default minWidth sub window size uint32_t miniWidthOfSubWindow_ = 320; + // 240: default minHeight sub window size uint32_t miniHeightOfSubWindow_ = 240; bool backgroundswitch = false; diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 52ac77edb3..9a85d730e7 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -1989,7 +1989,7 @@ void Session::RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeight, uint32 { if ((curWidth < minWidth) || (curWidth > maxFloatingWindowSize) || (curHeight < minHeight) || (curHeight > maxFloatingWindowSize)) { - WLOGFE("RectCheck err sessionID: %{public}d rect %{public}s", + TLOGE(WmsLogTag::WMS_LAYOUT, "RectCheck err sessionID: %{public}d rect %{public}s", GetPersistentId(), GetSessionRect().ToString().c_str()); } } @@ -2007,13 +2007,13 @@ void Session::RectCheckProcess() } auto screenProperty = screensProperties[displayId]; float density = screenProperty.GetDensity(); - if (!NearZero(density)) { + if (!NearZero(density) && (GetSessionRect().height_ != 0)) { uint32_t curWidth = static_cast(GetSessionRect().width_ / density); uint32_t curHeight = static_cast(GetSessionRect().height_ / density); float ratio = GetAspectRatio(); float actRatio = static_cast(curWidth) / curHeight; if ((ratio != 0) && !NearEqual(ratio, actRatio)) { - WLOGFE("RectCheck err ratio %{public}f != actRatio: %{public}f", ratio, actRatio); + TLOGE(WmsLogTag::WMS_LAYOUT, "RectCheck err ratio %{public}f != actRatio: %{public}f", ratio, actRatio); } RectCheck(curWidth, curHeight); } diff --git a/window_scene/session_manager/include/anomaly_detection.h b/window_scene/session_manager/include/anomaly_detection.h index dfbf46a0e8..76f981eb87 100644 --- a/window_scene/session_manager/include/anomaly_detection.h +++ b/window_scene/session_manager/include/anomaly_detection.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef ANOMALY_DETECTION_H -#define ANOMALY_DETECTION_H +#ifndef OHOS_ROSEN_WINDOW_ANOMALY_DETECTION_H +#define OHOS_ROSEN_WINDOW_ANOMALY_DETECTION_H #include "session/host/include/scene_session.h" @@ -34,4 +34,4 @@ public: }; } // namespace Rosen } // namespace OHOS -#endif // ANOMALY_DETECTION_H \ No newline at end of file +#endif // OHOS_ROSEN_WINDOW_ANOMALY_DETECTION_H \ No newline at end of file diff --git a/window_scene/session_manager/src/anomaly_detection.cpp b/window_scene/session_manager/src/anomaly_detection.cpp index cb3003ad7c..20b56f0136 100644 --- a/window_scene/session_manager/src/anomaly_detection.cpp +++ b/window_scene/session_manager/src/anomaly_detection.cpp @@ -49,7 +49,7 @@ void AnomalyDetection::SceneZOrderCheckProcess() uint32_t callingWindowId = session->GetSessionProperty()->GetCallingSessionId(); const auto& callingSession = SceneSessionManager::GetInstance().GetSceneSession(static_cast(callingWindowId)); - if (callingSession->GetZOrder() > session->GetZOrder()) { + if ((callingSession != nullptr) && (callingSession->GetZOrder() > session->GetZOrder())) { TLOGE(WmsLogTag::WMS_FOCUS, "ZOrderCheck err, callingSession: %{public}d curSession: %{public}d", callingSession->GetZOrder(), session->GetZOrder()); } @@ -58,7 +58,7 @@ void AnomalyDetection::SceneZOrderCheckProcess() if (WindowHelper::IsSubWindow(session->GetWindowType()) || session->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG) { auto mainSession = session->GetParentSession(); - if (session->GetZOrder() < mainSession->GetZOrder()) { + if ((mainSession != nullptr) && (session->GetZOrder() < mainSession->GetZOrder())) { TLOGE(WmsLogTag::WMS_FOCUS, "ZOrderCheck err, subSession %{public}d mainSession %{public}d", session->GetZOrder(), mainSession->GetZOrder()); } @@ -66,8 +66,8 @@ void AnomalyDetection::SceneZOrderCheckProcess() if (session->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) { keyGuardFlag = true; return false; - }; - if (keyGuardFlag && session->IsShowWhenLocked()) { + } + if (keyGuardFlag && (!session->IsShowWhenLocked())) { TLOGE(WmsLogTag::WMS_FOCUS, "ZOrderCheck err %{public}d IsShowWhenLocked", session->GetZOrder()); } return false; -- Gitee