wms向dms注册监听事件

Signed-off-by: chenqinxin <chenqinxin1@huawei.com>
Change-Id: I9d4465a9a0b55a5bbf982c80effd7a35c59c4db1
This commit is contained in:
chenqinxin
2022-01-24 12:32:11 +08:00
parent 0f9f1ae6de
commit e117c55cbc
26 changed files with 258 additions and 89 deletions
+5
View File
@@ -274,22 +274,26 @@ void DisplayManager::NotifyDisplayStateChanged(DisplayState state)
bool DisplayManager::WakeUpBegin(PowerStateChangeReason reason)
{
WLOGFI("WakeUpBegin start, reason:%{public}u", reason);
return SingletonContainer::Get<DisplayManagerAdapter>().WakeUpBegin(reason);
}
bool DisplayManager::WakeUpEnd()
{
WLOGFI("WakeUpEnd start");
return SingletonContainer::Get<DisplayManagerAdapter>().WakeUpEnd();
}
bool DisplayManager::SuspendBegin(PowerStateChangeReason reason)
{
// dms->wms notify other windows to hide
WLOGFI("SuspendBegin start, reason:%{public}u", reason);
return SingletonContainer::Get<DisplayManagerAdapter>().SuspendBegin(reason);
}
bool DisplayManager::SuspendEnd()
{
WLOGFI("SuspendEnd start");
return SingletonContainer::Get<DisplayManagerAdapter>().SuspendEnd();
}
@@ -379,6 +383,7 @@ uint32_t DisplayManager::GetScreenBrightness(uint64_t screenId) const
void DisplayManager::NotifyDisplayEvent(DisplayEvent event)
{
// Unlock event dms->wms restore other hidden windows
WLOGFI("DisplayEvent:%{public}u", event);
SingletonContainer::Get<DisplayManagerAdapter>().NotifyDisplayEvent(event);
}
} // namespace OHOS::Rosen
+6 -1
View File
@@ -27,12 +27,15 @@
#include "abstract_display.h"
#include "abstract_display_controller.h"
#include "abstract_screen_controller.h"
#include "display_change_listener.h"
#include "display_manager_stub.h"
#include "display_power_controller.h"
#include "singleton_delegator.h"
namespace OHOS::Rosen {
class DisplayManagerService : public SystemAbility, public DisplayManagerStub {
friend class DisplayManagerServiceInner;
friend class DisplayPowerController;
DECLARE_SYSTEM_ABILITY(DisplayManagerService);
WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService);
@@ -58,7 +61,6 @@ public:
bool SetDisplayState(DisplayState state) override;
DisplayState GetDisplayState(uint64_t displayId) override;
void NotifyDisplayEvent(DisplayEvent event) override;
bool NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status);
sptr<AbstractScreenController> GetAbstractScreenController();
DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) override;
@@ -69,6 +71,8 @@ private:
bool Init();
DisplayId GetDisplayIdFromScreenId(ScreenId screenId);
ScreenId GetScreenIdFromDisplayId(DisplayId displayId);
void RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener);
void NotifyDisplayStateChange(DisplayStateChangeType type);
std::recursive_mutex mutex_;
static inline SingletonDelegator<DisplayManagerService> delegator_;
@@ -76,6 +80,7 @@ private:
sptr<AbstractDisplayController> abstractDisplayController_;
DisplayPowerController displayPowerController_;
std::map<ScreenId, std::shared_ptr<RSDisplayNode>> displayNodeMap_;
sptr<IDisplayChangeListener> displayChangeListener_;
};
} // namespace OHOS::Rosen
@@ -20,6 +20,7 @@
#include <system_ability.h>
#include "abstract_display.h"
#include "display_change_listener.h"
#include "wm_single_instance.h"
#include "singleton_delegator.h"
@@ -33,6 +34,7 @@ public:
const sptr<AbstractDisplay> GetDefaultDisplay();
const sptr<AbstractDisplay> GetDisplayById(DisplayId displayId);
std::vector<DisplayId> GetAllDisplayIds();
void RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener);
};
} // namespace OHOS::Rosen
+13
View File
@@ -60,6 +60,19 @@ bool DisplayManagerService::Init()
return true;
}
void DisplayManagerService::RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)
{
displayChangeListener_ = listener;
WLOGFI("IDisplayChangeListener registered");
}
void DisplayManagerService::NotifyDisplayStateChange(DisplayStateChangeType type)
{
if (displayChangeListener_ != nullptr) {
displayChangeListener_->OnDisplayStateChange(type);
}
}
DisplayId DisplayManagerService::GetDisplayIdFromScreenId(ScreenId screenId)
{
return (DisplayId)screenId;
@@ -74,4 +74,9 @@ std::vector<const sptr<AbstractDisplay>> DisplayManagerServiceInner::GetAllDispl
}
return res;
}
void DisplayManagerServiceInner::RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)
{
DisplayManagerService::GetInstance().RegisterDisplayChangeListener(listener);
}
} // namespace OHOS::Rosen
+3 -2
View File
@@ -14,6 +14,7 @@
*/
#include "display_power_controller.h"
#include "display_manager_service.h"
#include "display_manager_agent_controller.h"
#include "window_manager_hilog.h"
@@ -26,7 +27,7 @@ namespace {
bool DisplayPowerController::SuspendBegin(PowerStateChangeReason reason)
{
WLOGFI("reason:%{public}u", reason);
// TODO: return WindowManagerServiceInner::GetInstance().NotifyDisplaySuspend();
DisplayManagerService::GetInstance().NotifyDisplayStateChange(DisplayStateChangeType::BEFORE_SUSPEND);
return true;
}
@@ -69,7 +70,7 @@ void DisplayPowerController::NotifyDisplayEvent(DisplayEvent event)
{
if (event == DisplayEvent::UNLOCK) {
WLOGFI("DisplayEvent UNLOCK");
// TODO: WindowManagerServiceInner::GetInstance().RestoreSuspendedWindows();
DisplayManagerService::GetInstance().NotifyDisplayStateChange(DisplayStateChangeType::BEFORE_UNLOCK);
DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DESKTOP_READY,
EventStatus::BEGIN);
return;
+1 -1
View File
@@ -63,7 +63,7 @@ public:
virtual WindowType GetType() const = 0;
virtual WindowMode GetMode() const = 0;
virtual const std::string& GetWindowName() const = 0;
virtual uint32_t GetWindowId() = 0;
virtual uint32_t GetWindowId() const = 0;
virtual uint32_t GetWindowFlags() const = 0;
virtual bool GetShowState() const = 0;
virtual bool GetFocusable() const = 0;
@@ -13,19 +13,21 @@
* limitations under the License.
*/
#ifndef OHOS_WINDOW_MANAGER_SERVICE_INNER_H
#define OHOS_WINDOW_MANAGER_SERVICE_INNER_H
#ifndef OHOS_ROSEN_DISPLAY_CHANGE_LISTENER_H
#define OHOS_ROSEN_DISPLAY_CHANGE_LISTENER_H
#include "wm_single_instance.h"
#include <refbase.h>
namespace OHOS {
namespace Rosen {
class WindowManagerServiceInner {
WM_DECLARE_SINGLE_INSTANCE(WindowManagerServiceInner)
enum class DisplayStateChangeType : uint32_t {
BEFORE_SUSPEND,
BEFORE_UNLOCK,
};
class IDisplayChangeListener : public RefBase {
public:
bool NotifyDisplaySuspend();
void RestoreSuspendedWindows();
virtual void OnDisplayStateChange(DisplayStateChangeType type) = 0;
};
}
}
#endif // OHOS_WINDOW_MANAGER_SERVICE_INNER_H
#endif // OHOS_ROSEN_DISPLAY_CHANGE_LISTENER_H
@@ -13,21 +13,27 @@
* limitations under the License.
*/
#include "window_manager_service_inner.h"
#include "window_manager_service.h"
#ifndef OHOS_ROSEN_WM_COMMON_INNER_H
#define OHOS_ROSEN_WM_COMMON_INNER_H
#include <cinttypes>
namespace OHOS {
namespace Rosen {
WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerServiceInner)
enum class WindowState : uint32_t {
STATE_INITIAL,
STATE_CREATED,
STATE_SHOWN,
STATE_HIDDEN,
STATE_DESTROYED,
STATE_BOTTOM = STATE_DESTROYED,
STATE_FROZEN,
STATE_UNFROZEN,
};
bool WindowManagerServiceInner::NotifyDisplaySuspend()
{
WMError ret = WindowManagerService::GetInstance().NotifyDisplaySuspend();
return ret == WMError::WM_OK;
}
void WindowManagerServiceInner::RestoreSuspendedWindows()
{
WindowManagerService::GetInstance().RestoreSuspendedWindows();
}
enum class WindowStateChangeReason : uint32_t {
KEYGUARD,
};
}
}
#endif // OHOS_ROSEN_WM_COMMON_INNER_H
+1
View File
@@ -31,6 +31,7 @@ public:
void UpdateWindowMode(WindowMode mode) override;
void UpdateFocusStatus(bool focused) override;
void UpdateAvoidArea(const std::vector<Rect>& avoidAreas) override;
void UpdateWindowState(WindowState state) override;
private:
sptr<WindowImpl> window_;
+7 -11
View File
@@ -15,16 +15,20 @@
#ifndef OHOS_ROSEN_WINDOW_IMPL_H
#define OHOS_ROSEN_WINDOW_IMPL_H
#include <map>
#include <ability_context.h>
#include <i_input_event_consumer.h>
#include <key_event.h>
#include <refbase.h>
#include <ui_content.h>
#include "input_transfer_station.h"
#include "vsync_station.h"
#include "window.h"
#include "window_property.h"
#include "wm_common_inner.h"
namespace OHOS {
namespace Rosen {
@@ -53,7 +57,7 @@ public:
virtual bool GetFocusable() const override;
virtual bool GetTouchable() const override;
virtual const std::string& GetWindowName() const override;
virtual uint32_t GetWindowId() override;
virtual uint32_t GetWindowId() const override;
virtual uint32_t GetWindowFlags() const override;
virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) const override;
virtual bool IsFullScreen() const override;
@@ -99,6 +103,7 @@ public:
void UpdateFocusStatus(bool focused);
virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
void UpdateAvoidArea(const std::vector<Rect>& avoidAreas);
void UpdateWindowState(WindowState state);
virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine,
NativeValue* storage, bool isdistributed) override;
@@ -131,21 +136,12 @@ private:
bool IsWindowValid() const;
void OnVsync(int64_t timeStamp);
enum WindowState {
STATE_INITIAL,
STATE_CREATED,
STATE_SHOWN,
STATE_HIDDEN,
STATE_DESTROYED,
STATE_BOTTOM = STATE_DESTROYED,
};
std::shared_ptr<VsyncStation::VsyncCallback> callback_ =
std::make_shared<VsyncStation::VsyncCallback>(VsyncStation::VsyncCallback());
static std::map<std::string, std::pair<uint32_t, sptr<Window>>> windowMap_;
static std::map<uint32_t, std::vector<sptr<Window>>> subWindowMap_;
sptr<WindowProperty> property_;
WindowState state_ { STATE_INITIAL };
WindowState state_ { WindowState::STATE_INITIAL };
sptr<IWindowLifeCycle> lifecycleListener_;
sptr<IWindowChangeListener> windowChangeListener_;
sptr<IAvoidAreaChangedListener> avoidAreaChangeListener_;
+3
View File
@@ -18,6 +18,7 @@
#include "iremote_broker.h"
#include "window_property.h"
#include "wm_common_inner.h"
namespace OHOS {
namespace Rosen {
@@ -31,6 +32,7 @@ public:
TRANS_ID_UPDATE_WINDOW_MODE,
TRANS_ID_UPDATE_FOCUS_STATUS,
TRANS_ID_UPDATE_AVOID_AREA,
TRANS_ID_UPDATE_WINDOW_STATE,
};
virtual void UpdateWindowProperty(const WindowProperty& windowProperty) = 0;
@@ -38,6 +40,7 @@ public:
virtual void UpdateWindowMode(WindowMode mode) = 0;
virtual void UpdateFocusStatus(bool focused) = 0;
virtual void UpdateAvoidArea(const std::vector<Rect>& avoidAreas) = 0;
virtual void UpdateWindowState(WindowState state) = 0;
};
} // namespace Rosen
} // namespace OHOS
+1
View File
@@ -32,6 +32,7 @@ public:
void UpdateWindowMode(WindowMode mode) override;
void UpdateFocusStatus(bool focused) override;
void UpdateAvoidArea(const std::vector<Rect>& avoidAreas) override;
void UpdateWindowState(WindowState state) override;
private:
static inline BrokerDelegator<WindowProxy> delegator_;
+9
View File
@@ -66,5 +66,14 @@ void WindowAgent::UpdateAvoidArea(const std::vector<Rect>& avoidArea)
}
window_->UpdateAvoidArea(avoidArea);
}
void WindowAgent::UpdateWindowState(WindowState state)
{
if (window_ == nullptr) {
WLOGFE("window_ is nullptr");
return;
}
window_->UpdateWindowState(state);
}
} // namespace Rosen
} // namespace OHOS
+49 -33
View File
@@ -94,7 +94,7 @@ WindowMode WindowImpl::GetMode() const
bool WindowImpl::GetShowState() const
{
return state_ == STATE_SHOWN;
return state_ == WindowState::STATE_SHOWN;
}
bool WindowImpl::GetFocusable() const
@@ -112,7 +112,7 @@ const std::string& WindowImpl::GetWindowName() const
return name_;
}
uint32_t WindowImpl::GetWindowId()
uint32_t WindowImpl::GetWindowId() const
{
return property_->GetWindowId();
}
@@ -148,10 +148,9 @@ WMError WindowImpl::SetWindowType(WindowType type)
{
WLOGFI("window id: %{public}d, type:%{public}d", property_->GetWindowId(), static_cast<uint32_t>(type));
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (state_ == STATE_CREATED) {
if (state_ == WindowState::STATE_CREATED) {
if (!(WindowHelper::IsAppWindow(type) || WindowHelper::IsSystemWindow(type))) {
WLOGFE("window type is invalid %{public}d", type);
return WMError::WM_ERROR_INVALID_PARAM;
@@ -169,12 +168,11 @@ WMError WindowImpl::SetWindowMode(WindowMode mode)
{
WLOGFI("[Client] Window %{public}d mode %{public}d", property_->GetWindowId(), static_cast<uint32_t>(mode));
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (state_ == STATE_CREATED || state_ == STATE_HIDDEN) {
if (state_ == WindowState::STATE_CREATED || state_ == WindowState::STATE_HIDDEN) {
property_->SetWindowMode(mode);
} else if (state_ == STATE_SHOWN) {
} else if (state_ == WindowState::STATE_SHOWN) {
property_->SetWindowMode(mode);
return SingletonContainer::Get<WindowAdapter>().SetWindowMode(property_->GetWindowId(), mode);
}
@@ -200,14 +198,13 @@ WMError WindowImpl::RemoveWindowFlag(WindowFlag flag)
WMError WindowImpl::SetWindowFlags(uint32_t flags)
{
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (property_->GetWindowFlags() == flags) {
return WMError::WM_OK;
}
property_->SetWindowFlags(flags);
if (state_ == STATE_CREATED || state_ == STATE_HIDDEN) {
if (state_ == WindowState::STATE_CREATED || state_ == WindowState::STATE_HIDDEN) {
return WMError::WM_OK;
}
WMError ret = SingletonContainer::Get<WindowAdapter>().SetWindowFlags(property_->GetWindowId(), flags);
@@ -258,14 +255,13 @@ WMError WindowImpl::SetSystemBarProperty(WindowType type, const SystemBarPropert
property_->GetWindowId(), static_cast<uint32_t>(type), property.enable_,
property.backgroundColor_, property.contentColor_);
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (GetSystemBarPropertyByType(type) == property) {
return WMError::WM_OK;
}
property_->SetSystemBarProperty(type, property);
if (state_ == STATE_CREATED || state_ == STATE_HIDDEN) {
if (state_ == WindowState::STATE_CREATED || state_ == WindowState::STATE_HIDDEN) {
return WMError::WM_OK;
}
WMError ret = SingletonContainer::Get<WindowAdapter>().SetSystemBarProperty(property_->GetWindowId(),
@@ -281,7 +277,6 @@ WMError WindowImpl::SetLayoutFullScreen(bool status)
{
WLOGFI("[Client] Window %{public}d SetLayoutFullScreen: %{public}d", property_->GetWindowId(), status);
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
WMError ret = SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
@@ -386,7 +381,7 @@ WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr<
if (parentName != "") { // add to subWindowMap_
subWindowMap_[property_->GetParentId()].push_back(this);
}
state_ = STATE_CREATED;
state_ = WindowState::STATE_CREATED;
InputTransferStation::GetInstance().AddInputWindow(this);
return ret;
}
@@ -395,9 +390,7 @@ WMError WindowImpl::Destroy()
{
NotifyBeforeDestroy();
WLOGFI("[Client] Window %{public}d Destroy", property_->GetWindowId());
// should destroy surface here
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_OK;
}
WLOGFI("destroy window id: %{public}d", property_->GetWindowId());
@@ -413,7 +406,7 @@ WMError WindowImpl::Destroy()
}
}
subWindowMap_.erase(GetWindowId());
state_ = STATE_DESTROYED;
state_ = WindowState::STATE_DESTROYED;
InputTransferStation::GetInstance().RemoveInputWindow(this);
return ret;
}
@@ -422,10 +415,9 @@ WMError WindowImpl::Show()
{
WLOGFI("[Client] Window %{public}d Show", property_->GetWindowId());
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (state_ == STATE_SHOWN && property_->GetWindowType() == WindowType::WINDOW_TYPE_WALLPAPER) {
if (state_ == WindowState::STATE_SHOWN && property_->GetWindowType() == WindowType::WINDOW_TYPE_WALLPAPER) {
WLOGFI("Minimize all app window");
WMError ret = SingletonContainer::Get<WindowAdapter>().MinimizeAllAppNodeAbility(property_->GetWindowId());
if (ret != WMError::WM_OK) {
@@ -434,14 +426,14 @@ WMError WindowImpl::Show()
}
return ret;
}
if (state_ == STATE_SHOWN) {
if (state_ == WindowState::STATE_SHOWN) {
WLOGFI("window is already shown id: %{public}d", property_->GetWindowId());
return WMError::WM_OK;
}
SetDefaultOption();
WMError ret = SingletonContainer::Get<WindowAdapter>().AddWindow(property_);
if (ret == WMError::WM_OK || ret == WMError::WM_ERROR_DEATH_RECIPIENT) {
state_ = STATE_SHOWN;
state_ = WindowState::STATE_SHOWN;
NotifyAfterForeground();
} else {
WLOGFE("show errCode:%{public}d for winId:%{public}d", static_cast<int32_t>(ret), property_->GetWindowId());
@@ -453,10 +445,9 @@ WMError WindowImpl::Hide()
{
WLOGFI("[Client] Window %{public}d Hide", property_->GetWindowId());
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) {
if (state_ == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) {
WLOGFI("window is already hidden id: %{public}d", property_->GetWindowId());
return WMError::WM_OK;
}
@@ -465,7 +456,7 @@ WMError WindowImpl::Hide()
WLOGFE("hide errCode:%{public}d for winId:%{public}d", static_cast<int32_t>(ret), property_->GetWindowId());
return ret;
}
state_ = STATE_HIDDEN;
state_ = WindowState::STATE_HIDDEN;
NotifyAfterBackground();
return ret;
}
@@ -473,10 +464,9 @@ WMError WindowImpl::Hide()
WMError WindowImpl::MoveTo(int32_t x, int32_t y)
{
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) {
if (state_ == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) {
Rect rect = GetRect();
property_->SetWindowRect({ x, y, rect.width_, rect.height_ });
WLOGFI("window is hidden or created! id: %{public}d, rect: [%{public}d, %{public}d, %{public}d, %{public}d]",
@@ -489,10 +479,9 @@ WMError WindowImpl::MoveTo(int32_t x, int32_t y)
WMError WindowImpl::Resize(uint32_t width, uint32_t height)
{
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (state_ == STATE_HIDDEN || state_ == STATE_CREATED) {
if (state_ == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) {
Rect rect = GetRect();
property_->SetWindowRect({ rect.posX_, rect.posY_, width, height });
WLOGFI("window is hidden or created! id: %{public}d, rect: [%{public}d, %{public}d, %{public}d, %{public}d]",
@@ -511,7 +500,6 @@ WMError WindowImpl::Maximize()
{
WLOGFI("[Client] Window %{public}d Maximize", property_->GetWindowId());
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
@@ -524,7 +512,6 @@ WMError WindowImpl::Minimize()
{
WLOGFI("[Client] Window %{public}d Minimize", property_->GetWindowId());
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
@@ -541,7 +528,6 @@ WMError WindowImpl::Recover()
{
WLOGFI("[Client] Window %{public}d Normalize", property_->GetWindowId());
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
@@ -554,7 +540,6 @@ WMError WindowImpl::Close()
{
WLOGFI("[Client] Window %{public}d Close", property_->GetWindowId());
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
@@ -570,7 +555,6 @@ WMError WindowImpl::Close()
WMError WindowImpl::RequestFocus() const
{
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
return SingletonContainer::Get<WindowAdapter>().RequestFocus(property_->GetWindowId());
@@ -761,6 +745,34 @@ void WindowImpl::UpdateAvoidArea(const std::vector<Rect>& avoidArea)
}
}
void WindowImpl::UpdateWindowState(WindowState state)
{
WLOGFI("[Client] Window %{public}u, WindowState to set:%{public}u", GetWindowId(), state);
if (!IsWindowValid()) {
return;
}
switch (state) {
case WindowState::STATE_FROZEN: {
state_ = WindowState::STATE_HIDDEN;
if (uiContent_ != nullptr) {
uiContent_->Background();
}
break;
}
case WindowState::STATE_UNFROZEN: {
state_ = WindowState::STATE_SHOWN;
if (uiContent_ != nullptr) {
uiContent_->Foreground();
}
break;
}
default: {
WLOGFE("windowState to set is invalid");
break;
}
}
}
void WindowImpl::SetDefaultOption()
{
auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId());
@@ -815,7 +827,11 @@ void WindowImpl::SetDefaultOption()
}
bool WindowImpl::IsWindowValid() const
{
return ((state_ > STATE_INITIAL) && (state_ < STATE_BOTTOM));
bool res = ((state_ > WindowState::STATE_INITIAL) && (state_ < WindowState::STATE_BOTTOM));
if (!res) {
WLOGFI("window is already destroyed or not created! id: %{public}u", GetWindowId());
}
return res;
}
bool WindowImpl::IsLayoutFullScreen() const
+20
View File
@@ -123,6 +123,26 @@ void WindowProxy::UpdateAvoidArea(const std::vector<Rect>& avoidArea)
}
return;
}
void WindowProxy::UpdateWindowState(WindowState state)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return;
}
if (!data.WriteUint32(static_cast<uint32_t>(state))) {
WLOGFE("Write isStopped");
return;
}
if (Remote()->SendRequest(TRANS_ID_UPDATE_WINDOW_STATE, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
return;
}
} // namespace Rosen
} // namespace OHOS
+4
View File
@@ -60,6 +60,10 @@ int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce
UpdateAvoidArea(avoidArea);
break;
}
case TRANS_ID_UPDATE_WINDOW_STATE: {
UpdateWindowState(static_cast<WindowState>(data.ReadUint32()));
break;
}
default:
break;
}
-1
View File
@@ -59,7 +59,6 @@ ohos_shared_library("libwms") {
"src/window_layout_policy.cpp",
"src/window_manager_agent_controller.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",
+1
View File
@@ -42,6 +42,7 @@ public:
WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property);
std::vector<Rect> GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType);
WMError MinimizeAllAppNodeAbility(uint32_t windowId);
void NotifyDisplayStateChange(DisplayStateChangeType type);
private:
uint32_t GenWindowId();
+8 -5
View File
@@ -23,6 +23,7 @@
#include <nocopyable.h>
#include <parameters.h>
#include <system_ability.h>
#include "display_change_listener.h"
#include "singleton_delegator.h"
#include "wm_single_instance.h"
#include "window_controller.h"
@@ -32,9 +33,13 @@
namespace OHOS {
namespace Rosen {
class DisplayChangeListener : public IDisplayChangeListener {
public:
virtual void OnDisplayStateChange(DisplayStateChangeType type) override;
};
class WindowManagerService : public SystemAbility, public WindowManagerStub {
friend class DisplayChangeListener;
DECLARE_SYSTEM_ABILITY(WindowManagerService);
WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManagerService);
public:
@@ -63,10 +68,6 @@ public:
void UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
// Inner interfaces
WMError NotifyDisplaySuspend();
void RestoreSuspendedWindows();
protected:
WindowManagerService();
virtual ~WindowManagerService() = default;
@@ -75,6 +76,8 @@ private:
bool Init();
void RegisterSnapshotHandler();
void OnWindowEvent(Event event, uint32_t windowId);
void NotifyDisplayStateChange(DisplayStateChangeType type);
static inline SingletonDelegator<WindowManagerService> delegator;
std::recursive_mutex mutex_;
sptr<WindowRoot> windowRoot_;
+5
View File
@@ -23,6 +23,7 @@
#include "window_node.h"
#include "window_zorder_policy.h"
#include "wm_common.h"
#include "wm_common_inner.h"
namespace OHOS {
namespace Rosen {
@@ -53,6 +54,8 @@ public:
void UpdateDisplayInfo();
bool isVerticalDisplay() const;
void NotifyWindowStateChange(WindowState state, WindowStateChangeReason reason);
class DisplayRects : public RefBase {
public:
DisplayRects() = default;
@@ -90,6 +93,8 @@ private:
WMError UpdateWindowPairInfo(sptr<WindowNode>& triggerNode, sptr<WindowNode>& pairNode);
void NotifyIfSystemBarTintChanged();
void NotifyIfSystemBarRegionChanged();
void TraverseAndUpdateWindowState(WindowState state, int32_t topPriority);
void UpdateWindowState(sptr<WindowNode> node, int32_t topPriority, WindowState state);
sptr<AvoidAreaController> avoidController_;
sptr<WindowZorderPolicy> zorderPolicy_ = new WindowZorderPolicy();
+2
View File
@@ -55,6 +55,8 @@ public:
WMError HandleSplitWindowModeChange(sptr<WindowNode>& node, bool isChangeToSplit);
std::shared_ptr<RSSurfaceNode> GetSurfaceNodeByAbilityToken(const sptr<IRemoteObject>& abilityToken) const;
void NotifyWindowStateChange(WindowState state, WindowStateChangeReason reason);
private:
void OnRemoteDied(const sptr<IRemoteObject>& remoteObject);
WMError DestroyWindowInner(sptr<WindowNode>& node);
+24
View File
@@ -204,6 +204,30 @@ WMError WindowController::MinimizeAllAppNodeAbility(uint32_t windowId)
return windowRoot_->MinimizeAllAppNodeAbility(node);
}
void WindowController::NotifyDisplayStateChange(DisplayStateChangeType type)
{
WLOGFI("DisplayStateChangeType:%{public}u", type);
WindowState state;
WindowStateChangeReason reason;
switch (type) {
case DisplayStateChangeType::BEFORE_SUSPEND: {
state = WindowState::STATE_FROZEN;
reason = WindowStateChangeReason::KEYGUARD;
break;
}
case DisplayStateChangeType::BEFORE_UNLOCK: {
state = WindowState::STATE_UNFROZEN;
reason = WindowStateChangeReason::KEYGUARD;
break;
}
default: {
WLOGFE("unknown DisplayStateChangeType:%{public}u", type);
return;
}
}
windowRoot_->NotifyWindowStateChange(state, reason);
}
WMError WindowController::SetWindowType(uint32_t windowId, WindowType type)
{
auto node = windowRoot_->GetWindowNode(windowId);
+15 -15
View File
@@ -22,6 +22,7 @@
#include <ability_manager_client.h>
#include "dm_common.h"
#include "display_manager_service_inner.h"
#include "singleton_container.h"
#include "window_manager_agent_controller.h"
#include "window_inner_manager.h"
@@ -54,6 +55,8 @@ void WindowManagerService::OnStart()
}
RegisterSnapshotHandler();
SingletonContainer::Get<WindowInnerManager>().Init();
sptr<IDisplayChangeListener> listener = new DisplayChangeListener();
DisplayManagerServiceInner::GetInstance().RegisterDisplayChangeListener(listener);
}
void WindowManagerService::RegisterSnapshotHandler()
@@ -284,26 +287,23 @@ void WindowManagerService::OnWindowEvent(Event event, uint32_t windowId)
}
}
WMError WindowManagerService::NotifyDisplaySuspend()
{
WLOGFI("NotifyDisplaySuspend");
std::lock_guard<std::recursive_mutex> lock(mutex_);
// TODO: notify windows covered by keyguard window to hide
return WMError::WM_OK;
}
void WindowManagerService::RestoreSuspendedWindows()
{
WLOGFI("RestoreSuspendedWindows");
std::lock_guard<std::recursive_mutex> lock(mutex_);
// TODO: restore windows covered by keyguard
}
WMError WindowManagerService::MinimizeAllAppNodeAbility(uint32_t windowId)
{
WM_SCOPED_TRACE("wms:MinimizeAllAppNodeAbility");
std::lock_guard<std::recursive_mutex> lock(mutex_);
return windowController_->MinimizeAllAppNodeAbility(windowId);
}
void WindowManagerService::NotifyDisplayStateChange(DisplayStateChangeType type)
{
WLOGFE("NotifyDisplayStateChange");
std::lock_guard<std::recursive_mutex> lock(mutex_);
return windowController_->NotifyDisplayStateChange(type);
}
void DisplayChangeListener::OnDisplayStateChange(DisplayStateChangeType type)
{
WindowManagerService::GetInstance().NotifyDisplayStateChange(type);
}
}
}
+36
View File
@@ -654,6 +654,42 @@ bool WindowNodeContainer::isVerticalDisplay() const
return displayRects_->isVertical_;
}
void WindowNodeContainer::NotifyWindowStateChange(WindowState state, WindowStateChangeReason reason)
{
switch (reason) {
case WindowStateChangeReason::KEYGUARD: {
int32_t topPriority = zorderPolicy_->GetWindowPriority(WindowType::WINDOW_TYPE_KEYGUARD);
TraverseAndUpdateWindowState(state, topPriority);
break;
}
default:
return;
}
}
void WindowNodeContainer::TraverseAndUpdateWindowState(WindowState state, int32_t topPriority)
{
std::vector<sptr<WindowNode>> rootNodes = { belowAppWindowNode_, appWindowNode_, aboveAppWindowNode_ };
for (auto& node : rootNodes) {
UpdateWindowState(node, topPriority, state);
}
}
void WindowNodeContainer::UpdateWindowState(sptr<WindowNode> node, int32_t topPriority, WindowState state)
{
if (node == nullptr) {
return;
}
if (node->parent_ != nullptr && node->currentVisibility_) {
if (node->priority_ < topPriority) {
node->GetWindowToken()->UpdateWindowState(state);
}
}
for (auto& childNode : node->children_) {
UpdateWindowState(childNode, topPriority, state);
}
}
void WindowNodeContainer::SendSplitScreenEvent(WindowMode mode)
{
// should define in common_event_support.h and @ohos.commonEvent.d.ts
+10
View File
@@ -300,6 +300,16 @@ std::shared_ptr<RSSurfaceNode> WindowRoot::GetSurfaceNodeByAbilityToken(const sp
return nullptr;
}
void WindowRoot::NotifyWindowStateChange(WindowState state, WindowStateChangeReason reason)
{
for (auto& elem : windowNodeContainerMap_) {
if (elem.second == nullptr) {
continue;
}
elem.second->NotifyWindowStateChange(state, reason);
}
}
void WindowRoot::OnRemoteDied(const sptr<IRemoteObject>& remoteObject)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);