From d91f1bb7a6c364aa5ab98ef69f41c8aa66d88b37 Mon Sep 17 00:00:00 2001 From: chenqinxin Date: Sat, 8 Jan 2022 19:37:25 +0800 Subject: [PATCH] add display power interface Signed-off-by: chenqinxin Change-Id: I87574556ce30af234ffc70fa7bc1d7fb04f5538a --- dm/include/display_manager_adapter.h | 10 +++ dm/src/display_manager.cpp | 84 +++++++++++++++++++ dm/src/display_manager_adapter.cpp | 51 +++++++++++ dmserver/include/display_manager_interface.h | 11 ++- dmserver/include/display_manager_proxy.h | 6 ++ dmserver/include/display_manager_service.h | 8 ++ dmserver/include/display_power_controller.h | 41 +++++++++ dmserver/src/display_manager_proxy.cpp | 79 +++++++++++++++++ dmserver/src/display_manager_service.cpp | 20 +++++ dmserver/src/display_manager_stub.cpp | 20 ++++- dmserver/src/display_power_controller.cpp | 72 ++++++++++++++++ interfaces/innerkits/dm/display_manager.h | 13 +++ interfaces/innerkits/dm/dm_common.h | 27 +++++- wm/BUILD.gn | 1 + wm/src/window_impl.cpp | 3 +- wmserver/BUILD.gn | 2 + wmserver/include/window_manager_service.h | 4 + .../include/window_manager_service_inner.h | 31 +++++++ wmserver/src/window_layout_policy.cpp | 4 + wmserver/src/window_manager_service.cpp | 15 ++++ wmserver/src/window_manager_service_inner.cpp | 32 +++++++ 21 files changed, 527 insertions(+), 7 deletions(-) create mode 100644 dmserver/include/display_power_controller.h create mode 100644 dmserver/src/display_power_controller.cpp create mode 100644 wmserver/include/window_manager_service_inner.h create mode 100644 wmserver/src/window_manager_service_inner.cpp diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index 7037c76bc0..eae13dbe5c 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -39,11 +39,20 @@ public: sptr surface); bool DestroyVirtualDisplay(DisplayId displayId); sptr GetDisplaySnapshot(DisplayId displayId); + + bool SuspendBegin(PowerStateChangeReason reason); + bool SetDisplayState(DisplayState state, DisplayStateCallback callback); + DisplayState GetDisplayState(uint64_t displayId); + void NotifyDisplayEvent(DisplayEvent event); + void Clear(); + private: DisplayManagerAdapter() = default; ~DisplayManagerAdapter() = default; bool InitDMSProxyLocked(); + void NotifyDisplayChange(DisplayState state); + static inline SingletonDelegator delegator; std::mutex mutex_; @@ -51,6 +60,7 @@ private: sptr dmsDeath_ = nullptr; std::map> displayMap_; DisplayId defaultDisplayId_; + DisplayStateCallback callback_; }; } // namespace OHOS::Rosen #endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index a391e69742..2df4a0af41 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -16,8 +16,10 @@ #include "display_manager.h" #include +#include #include "display_manager_adapter.h" +#include "dm_common.h" #include "window_manager_hilog.h" namespace OHOS::Rosen { @@ -153,4 +155,86 @@ bool DisplayManager::DestroyVirtualDisplay(DisplayId displayId) WLOGFI("DisplayManager::DestroyVirtualDisplay override params"); return SingletonContainer::Get().DestroyVirtualDisplay(displayId); } + +bool DisplayManager::WakeUpBegin(PowerStateChangeReason reason) +{ + return true; +} + +bool DisplayManager::WakeUpEnd() +{ + return true; +} + +bool DisplayManager::SuspendBegin(PowerStateChangeReason reason) +{ + // dms->wms notify other windows to hide + return SingletonContainer::Get().SuspendBegin(reason); +} + +bool DisplayManager::SuspendEnd() +{ + return true; +} + +bool DisplayManager::SetScreenPowerForAll(DisplayPowerState state, PowerStateChangeReason reason) +{ + // TODO: should get all screen ids + ScreenId defaultId = GetDefaultDisplayId(); + if (defaultId == DISPLAY_ID_INVALD) { + return false; + } + WLOGFI("state:%{public}u, reason:%{public}u, defaultId:%{public}" PRIu64".", state, reason, defaultId); + ScreenPowerStatus status; + switch (state) { + case DisplayPowerState::POWER_ON: { + status = ScreenPowerStatus::POWER_STATUS_ON; + break; + } + case DisplayPowerState::POWER_OFF: { + status = ScreenPowerStatus::POWER_STATUS_OFF; + break; + } + default: { + WLOGFW("SetScreenPowerStatus state not support"); + return false; + } + } + RSInterfaces::GetInstance().SetScreenPowerStatus(defaultId, status); + return true; +} + +DisplayPowerState DisplayManager::GetScreenPower(uint64_t screenId) +{ + DisplayPowerState res = static_cast(RSInterfaces::GetInstance().GetScreenPowerStatus(screenId)); + WLOGFI("GetScreenPower:%{public}u, defaultId:%{public}" PRIu64".", res, screenId); + return res; +} + +bool DisplayManager::SetDisplayState(DisplayState state, DisplayStateCallback callback) +{ + WLOGFI("state:%{public}u", state); + return SingletonContainer::Get().SetDisplayState(state, callback); +} + +DisplayState DisplayManager::GetDisplayState(uint64_t displayId) +{ + return SingletonContainer::Get().GetDisplayState(displayId); +} + +bool DisplayManager::SetScreenBrightness(uint64_t screenId, uint32_t level) +{ + return true; +} + +uint32_t DisplayManager::GetScreenBrightness(uint64_t screenId) const +{ + return 0; +} + +void DisplayManager::NotifyDisplayEvent(DisplayEvent event) +{ + // Unlock event dms->wms restore other hidden windows + SingletonContainer::Get().NotifyDisplayEvent(event); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 1aa9a4c1ae..29cef8d722 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -97,6 +97,57 @@ bool DisplayManagerAdapter::DestroyVirtualDisplay(DisplayId displayId) return displayManagerServiceProxy_->DestroyVirtualDisplay(displayId); } +bool DisplayManagerAdapter::SuspendBegin(PowerStateChangeReason reason) +{ + std::lock_guard lock(mutex_); + if (!InitDMSProxyLocked()) { + return false; + } + return displayManagerServiceProxy_->SuspendBegin(reason); +} + +bool DisplayManagerAdapter::SetDisplayState(DisplayState state, DisplayStateCallback callback) +{ + std::lock_guard lock(mutex_); + if (!InitDMSProxyLocked()) { + return false; + } + callback_ = callback; + bool ret = displayManagerServiceProxy_->SetDisplayState(state); + if (state == DisplayState::OFF) { + NotifyDisplayChange(state); + } + // TODO: NotifyDisplayChange ON when keyguard is drawn + return ret; +} + +DisplayState DisplayManagerAdapter::GetDisplayState(uint64_t displayId) +{ + std::lock_guard lock(mutex_); + if (!InitDMSProxyLocked()) { + return DisplayState::UNKNOWN; + } + return displayManagerServiceProxy_->GetDisplayState(displayId); +} + +void DisplayManagerAdapter::NotifyDisplayEvent(DisplayEvent event) +{ + std::lock_guard lock(mutex_); + if (!InitDMSProxyLocked()) { + return; + } + displayManagerServiceProxy_->NotifyDisplayEvent(event); +} + +void DisplayManagerAdapter::NotifyDisplayChange(DisplayState state) +{ + if (callback_) { + callback_(state); + return; + } + WLOGFW("callback_ target is not set!"); +} + bool DisplayManagerAdapter::InitDMSProxyLocked() { WLOGFI("InitDMSProxy"); diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h index c7a73f6abb..5ce9d66e28 100644 --- a/dmserver/include/display_manager_interface.h +++ b/dmserver/include/display_manager_interface.h @@ -20,6 +20,7 @@ #include #include +#include "dm_common.h" #include "display_info.h" #include "virtual_display_info.h" @@ -34,6 +35,10 @@ public: TRANS_ID_CREATE_VIRTUAL_DISPLAY, TRANS_ID_DESTROY_VIRTUAL_DISPLAY, TRANS_ID_GET_DISPLAY_SNAPSHOT, + TRANS_ID_SUSPEND_BEGIN, + TRANS_ID_SET_DISPLAY_STATE, + TRANS_ID_GET_DISPLAY_STATE, + TRANS_ID_NOTIFY_DISPLAY_EVENT, }; virtual DisplayId GetDefaultDisplayId() = 0; @@ -42,8 +47,12 @@ public: virtual DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, sptr surface) = 0; virtual bool DestroyVirtualDisplay(DisplayId displayId) = 0; - virtual sptr GetDispalySnapshot(DisplayId displayId) = 0; + + virtual bool SuspendBegin(PowerStateChangeReason reason) = 0; + virtual bool SetDisplayState(DisplayState state) = 0; + virtual DisplayState GetDisplayState(uint64_t displayId) = 0; + virtual void NotifyDisplayEvent(DisplayEvent event) = 0; }; } // namespace OHOS::Rosen diff --git a/dmserver/include/display_manager_proxy.h b/dmserver/include/display_manager_proxy.h index ab8d6b24ab..4b81d380dc 100644 --- a/dmserver/include/display_manager_proxy.h +++ b/dmserver/include/display_manager_proxy.h @@ -34,6 +34,12 @@ public: sptr surface) override; bool DestroyVirtualDisplay(DisplayId displayId) override; sptr GetDispalySnapshot(DisplayId displayId) override; + + bool SuspendBegin(PowerStateChangeReason reason) override; + bool SetDisplayState(DisplayState state) override; + DisplayState GetDisplayState(uint64_t displayId) override; + void NotifyDisplayEvent(DisplayEvent event) override; + private: static inline BrokerDelegator delegator_; }; diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index 0684e31432..05bca80997 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -25,6 +25,7 @@ #include "abstract_display.h" #include "abstract_display_manager.h" #include "display_manager_stub.h" +#include "display_power_controller.h" #include "single_instance.h" #include "singleton_delegator.h" @@ -44,6 +45,12 @@ public: DisplayId GetDefaultDisplayId() override; DisplayInfo GetDisplayInfoById(DisplayId displayId) override; sptr GetDispalySnapshot(DisplayId displayId) override; + + bool SuspendBegin(PowerStateChangeReason reason) override; + bool SetDisplayState(DisplayState state) override; + DisplayState GetDisplayState(uint64_t displayId) override; + void NotifyDisplayEvent(DisplayEvent event) override; + private: DisplayManagerService(); ~DisplayManagerService() = default; @@ -53,6 +60,7 @@ private: static inline SingletonDelegator delegator_; std::map> abstractDisplayMap_; + DisplayPowerController displayPowerController_; }; } // namespace OHOS::Rosen diff --git a/dmserver/include/display_power_controller.h b/dmserver/include/display_power_controller.h new file mode 100644 index 0000000000..33a0fedd7c --- /dev/null +++ b/dmserver/include/display_power_controller.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 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_DISPLAY_POWER_CONTROLLER_H +#define OHOS_ROSEN_DISPLAY_POWER_CONTROLLER_H + +#include +#include +#include "dm_common.h" + +namespace OHOS { +namespace Rosen { +class DisplayPowerController { +public: + DisplayPowerController() = default; + virtual ~DisplayPowerController() = default; + + bool SuspendBegin(PowerStateChangeReason reason); + bool SetDisplayState(DisplayState state); + DisplayState GetDisplayState(uint64_t displayId); + void NotifyDisplayEvent(DisplayEvent event); + +private: + std::recursive_mutex mutex_; + DisplayState displayState_ { DisplayState::ON }; +}; +} +} +#endif // OHOS_ROSEN_DISPLAY_POWER_CONTROLLER_H \ No newline at end of file diff --git a/dmserver/src/display_manager_proxy.cpp b/dmserver/src/display_manager_proxy.cpp index 5bc29b9384..55a285e2df 100644 --- a/dmserver/src/display_manager_proxy.cpp +++ b/dmserver/src/display_manager_proxy.cpp @@ -168,4 +168,83 @@ sptr DisplayManagerProxy::GetDispalySnapshot(DisplayId displayI } return pixelMap; } + +bool DisplayManagerProxy::SuspendBegin(PowerStateChangeReason reason) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return false; + } + if (!data.WriteUint32(static_cast(reason))) { + WLOGFE("Write PowerStateChangeReason failed"); + return false; + } + if (Remote()->SendRequest(TRANS_ID_SUSPEND_BEGIN, data, reply, option) != ERR_NONE) { + WLOGFW("SendRequest failed"); + return false; + } + return reply.ReadBool(); +} + +bool DisplayManagerProxy::SetDisplayState(DisplayState state) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return false; + } + if (!data.WriteUint32(static_cast(state))) { + WLOGFE("Write DisplayState failed"); + return false; + } + if (Remote()->SendRequest(TRANS_ID_SET_DISPLAY_STATE, data, reply, option) != ERR_NONE) { + WLOGFW("SendRequest failed"); + return false; + } + return reply.ReadBool(); +} + +DisplayState DisplayManagerProxy::GetDisplayState(uint64_t displayId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return DisplayState::UNKNOWN; + } + if (!data.WriteUint64(static_cast(displayId))) { + WLOGFE("Write displayId failed"); + return DisplayState::UNKNOWN; + } + if (Remote()->SendRequest(TRANS_ID_GET_DISPLAY_STATE, data, reply, option) != ERR_NONE) { + WLOGFW("SendRequest failed"); + return DisplayState::UNKNOWN; + } + return static_cast(reply.ReadUint32()); +} + +void DisplayManagerProxy::NotifyDisplayEvent(DisplayEvent event) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!data.WriteUint32(static_cast(event))) { + WLOGFE("Write DisplayEvent failed"); + return; + } + if (Remote()->SendRequest(TRANS_ID_NOTIFY_DISPLAY_EVENT, data, reply, option) != ERR_NONE) { + WLOGFW("SendRequest failed"); + return; + } +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index d95ee09530..5907c5b937 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -112,4 +112,24 @@ void DisplayManagerService::OnStop() { WLOGFI("ready to stop display service."); } + +bool DisplayManagerService::SuspendBegin(PowerStateChangeReason reason) +{ + return displayPowerController_.SuspendBegin(reason); +} + +bool DisplayManagerService::SetDisplayState(DisplayState state) +{ + return displayPowerController_.SetDisplayState(state); +} + +DisplayState DisplayManagerService::GetDisplayState(uint64_t displayId) +{ + return displayPowerController_.GetDisplayState(displayId); +} + +void DisplayManagerService::NotifyDisplayEvent(DisplayEvent event) +{ + displayPowerController_.NotifyDisplayEvent(event); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp index 90c35cdd42..107d4db7b9 100644 --- a/dmserver/src/display_manager_stub.cpp +++ b/dmserver/src/display_manager_stub.cpp @@ -64,13 +64,31 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, } case TRANS_ID_GET_DISPLAY_SNAPSHOT: { DisplayId displayId = data.ReadUint64(); - sptr dispalySnapshot = GetDispalySnapshot(displayId); if (dispalySnapshot == nullptr) { reply.WriteParcelable(nullptr); break; } reply.WriteParcelable(dispalySnapshot.GetRefPtr()); + } + case TRANS_ID_SUSPEND_BEGIN: { + PowerStateChangeReason reason = static_cast(data.ReadUint32()); + reply.WriteBool(SuspendBegin(reason)); + break; + } + case TRANS_ID_SET_DISPLAY_STATE: { + DisplayState state = static_cast(data.ReadUint32()); + reply.WriteBool(SetDisplayState(state)); + break; + } + case TRANS_ID_GET_DISPLAY_STATE: { + DisplayState state = GetDisplayState(data.ReadUint64()); + reply.WriteUint32(static_cast(state)); + break; + } + case TRANS_ID_NOTIFY_DISPLAY_EVENT: { + DisplayEvent event = static_cast(data.ReadUint32()); + NotifyDisplayEvent(event); break; } default: diff --git a/dmserver/src/display_power_controller.cpp b/dmserver/src/display_power_controller.cpp new file mode 100644 index 0000000000..c32ff11c59 --- /dev/null +++ b/dmserver/src/display_power_controller.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2021 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 "display_power_controller.h" +#include "window_manager_service_inner.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayPowerController"}; +} + +bool DisplayPowerController::SuspendBegin(PowerStateChangeReason reason) +{ + WLOGFI("reason:%{public}u", reason); + return WindowManagerServiceInner::GetInstance().NotifyDisplaySuspend(); +} + +bool DisplayPowerController::SetDisplayState(DisplayState state) +{ + WLOGFI("state:%{public}u", state); + std::lock_guard lock(mutex_); + if (displayState_ == state) { + WLOGFI("state is already set"); + return true; + } + switch (state) { + case DisplayState::ON: { + // TODO: open vsync and SendSystemEvent to keyguard + break; + } + case DisplayState::OFF: { + // TODO: SendSystemEvent to keyguard + displayState_ = state; + break; + } + default: + WLOGFW("unknown DisplayState!"); + } + return true; +} + +DisplayState DisplayPowerController::GetDisplayState(uint64_t displayId) +{ + std::lock_guard lock(mutex_); + return displayState_; +} + +void DisplayPowerController::NotifyDisplayEvent(DisplayEvent event) +{ + if (event == DisplayEvent::UNLOCK) { + WLOGFI("DisplayEvent UNLOCK"); + WindowManagerServiceInner::GetInstance().RestoreSuspendedWindows(); + return; + } + // TODO: set displayState_ ON when keyguard is drawn +} +} +} \ No newline at end of file diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index 92bb9dc4b1..97ed134f2f 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -21,6 +21,7 @@ #include #include "display.h" +#include "dm_common.h" #include "single_instance.h" #include "virtual_display_info.h" // #include "wm_common.h" @@ -49,6 +50,18 @@ public: sptr GetScreenshot(DisplayId displayId, const Media::Rect &rect, const Media::Size &size, int rotation); + bool WakeUpBegin(PowerStateChangeReason reason); + bool WakeUpEnd(); + bool SuspendBegin(PowerStateChangeReason reason); + bool SuspendEnd(); + bool SetScreenPowerForAll(DisplayPowerState state, PowerStateChangeReason reason); + DisplayPowerState GetScreenPower(uint64_t screenId); + bool SetDisplayState(DisplayState state, DisplayStateCallback callback); + DisplayState GetDisplayState(uint64_t displayId); + bool SetScreenBrightness(uint64_t screenId, uint32_t level); + uint32_t GetScreenBrightness(uint64_t screenId) const; + void NotifyDisplayEvent(DisplayEvent event); + private: bool CheckRectOffsetValid(int32_t param) const; bool CheckRectSizeValid(int32_t param) const; diff --git a/interfaces/innerkits/dm/dm_common.h b/interfaces/innerkits/dm/dm_common.h index fdc5202745..31f9e1f523 100644 --- a/interfaces/innerkits/dm/dm_common.h +++ b/interfaces/innerkits/dm/dm_common.h @@ -16,11 +16,32 @@ #ifndef OHOS_ROSEN_DM_COMMON_H #define OHOS_ROSEN_DM_COMMON_H -#include - namespace OHOS { namespace Rosen { constexpr int32_t INVALID_DISPLAY_ID = -1; +enum class PowerStateChangeReason : uint32_t { + POWER_BUTTON +}; + +enum class DisplayPowerState : uint32_t { + POWER_ON, + POWER_STAND_BY, + POWER_SUSPEND, + POWER_OFF, + POWER_BUTT, + INVALID_STATE, +}; + +enum class DisplayState : uint32_t { + ON, + OFF, + UNKNOWN +}; + +enum class DisplayEvent : uint32_t { + UNLOCK +}; +using DisplayStateCallback = std::function; } } -#endif // OHOS_ROSEN_DM_COMMON_H +#endif // OHOS_ROSEN_DM_COMMON_H \ No newline at end of file diff --git a/wm/BUILD.gn b/wm/BUILD.gn index 3b813c46b4..fa58a7a367 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -52,6 +52,7 @@ config("libwm_public_config") { include_dirs = [ "//foundation/windowmanager/interfaces/innerkits/wm", "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/dm/include", "//foundation/windowmanager/dmserver/include", "//foundation/windowmanager/utils/include", "../interfaces/innerkits/dm", diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index b3cacc1a3f..6dd6f004c4 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -554,8 +554,7 @@ void WindowImpl::UpdateConfiguration(const std::shared_ptrUpdateConfiguration(configuration); + uiContent_->UpdateConfiguration(configuration); } if (subWindowMap_.count(GetWindowId()) == 0) { return; diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index e38eb6257b..86ce6f97ca 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -37,12 +37,14 @@ ohos_shared_library("libwms") { "../dmserver/src/display_manager_service_inner.cpp", "../dmserver/src/display_manager_stub.cpp", "../dmserver/src/display_node_control.cpp", + "../dmserver/src/display_power_controller.cpp", "../dmserver/src/screen.cpp", "../wm/src/zidl/window_manager_agent_proxy.cpp", "src/input_window_monitor.cpp", "src/window_controller.cpp", "src/window_layout_policy.cpp", "src/window_manager_service.cpp", + "src/window_manager_service_inner.cpp", "src/window_manager_stub.cpp", "src/window_node.cpp", "src/window_node_container.cpp", diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 36935f3a10..2cee42de12 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -56,6 +56,10 @@ public: void RegisterFocusChangedListener(const sptr& windowManagerAgent) override; void UnregisterFocusChangedListener(const sptr& windowManagerAgent) override; + // Inner interfaces + WMError NotifyDisplaySuspend(); + void RestoreSuspendedWindows(); + protected: WindowManagerService(); virtual ~WindowManagerService() = default; diff --git a/wmserver/include/window_manager_service_inner.h b/wmserver/include/window_manager_service_inner.h new file mode 100644 index 0000000000..8eab81f7c7 --- /dev/null +++ b/wmserver/include/window_manager_service_inner.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021 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_WINDOW_MANAGER_SERVICE_INNER_H +#define OHOS_WINDOW_MANAGER_SERVICE_INNER_H + +#include "single_instance.h" + +namespace OHOS { +namespace Rosen { +class WindowManagerServiceInner { +DECLARE_SINGLE_INSTANCE(WindowManagerServiceInner) +public: + bool NotifyDisplaySuspend(); + void RestoreSuspendedWindows(); +}; +} +} +#endif // OHOS_WINDOW_MANAGER_SERVICE_INNER_H diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index 75b497a652..cd7899e6d1 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -55,6 +55,10 @@ void WindowLayoutPolicy::LayoutWindowNode(sptr& node) return; } if (node->parent_ != nullptr) { // isn't root node + if (!node->currentVisibility_) { + WLOGFI("window[%{public}d] currently not visible, no need layout", node->GetWindowId()); + return; + } UpdateLayoutRect(node); if (avoidTypes_.find(node->GetWindowType()) != avoidTypes_.end()) { RecordAvoidRect(node); diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 56a0fa8665..594f9a0f6c 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -224,5 +224,20 @@ void WindowManagerService::OnWindowEvent(Event event, uint32_t windowId) break; } } + +WMError WindowManagerService::NotifyDisplaySuspend() +{ + WLOGFI("NotifyDisplaySuspend"); + std::lock_guard lock(mutex_); + // TODO: notify windows covered by keyguard window to hide + return WMError::WM_OK; +} + +void WindowManagerService::RestoreSuspendedWindows() +{ + WLOGFI("RestoreSuspendedWindows"); + std::lock_guard lock(mutex_); + // TODO: restore windows covered by keyguard +} } } \ No newline at end of file diff --git a/wmserver/src/window_manager_service_inner.cpp b/wmserver/src/window_manager_service_inner.cpp new file mode 100644 index 0000000000..3a933d9946 --- /dev/null +++ b/wmserver/src/window_manager_service_inner.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021 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 "window_manager_service_inner.h" +#include "window_manager_service.h" + +namespace OHOS { +namespace Rosen { + +bool WindowManagerServiceInner::NotifyDisplaySuspend() +{ + WMError ret = WindowManagerService::GetInstance().NotifyDisplaySuspend(); + return ret == WMError::WM_OK; +} +void WindowManagerServiceInner::RestoreSuspendedWindows() +{ + WindowManagerService::GetInstance().RestoreSuspendedWindows(); +} +} +} -- Gitee