!1798 dm/sm/wm增加对dms/wms死亡时的监听处理

Merge pull request !1798 from xiahaiqin/register
This commit is contained in:
openharmony_ci 2022-10-31 12:05:31 +00:00 committed by Gitee
commit 70f66c488c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 113 additions and 33 deletions

View File

@ -49,6 +49,7 @@ public:
bool RegisterScreenshotListener(sptr<IScreenshotListener> listener);
bool UnregisterScreenshotListener(sptr<IScreenshotListener> listener);
sptr<Display> GetDisplayByScreenId(ScreenId screenId);
void OnRemoteDied();
private:
void ClearDisplayStateCallback();
void NotifyScreenshot(sptr<ScreenshotInfo> info);
@ -793,4 +794,19 @@ bool DisplayManager::Unfreeze(std::vector<DisplayId> displayIds)
}
return SingletonContainer::Get<DisplayManagerAdapter>().SetFreeze(displayIds, false);
}
void DisplayManager::Impl::OnRemoteDied()
{
WLOGFI("dms is died");
std::lock_guard<std::recursive_mutex> lock(mutex_);
displayManagerListener_ = nullptr;
displayStateAgent_ = nullptr;
powerEventListenerAgent_ = nullptr;
screenshotListenerAgent_ = nullptr;
}
void DisplayManager::OnRemoteDied()
{
pImpl_->OnRemoteDied();
}
} // namespace OHOS::Rosen

View File

@ -19,6 +19,8 @@
#include <iservice_registry.h>
#include <system_ability_definition.h>
#include "display_manager.h"
#include "screen_manager.h"
#include "window_manager_hilog.h"
namespace OHOS::Rosen {
@ -283,7 +285,10 @@ void DMSDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
WLOGFE("object is null");
return;
}
WLOGFI("dms OnRemoteDied");
adapter_.Clear();
SingletonContainer::Get<DisplayManager>().OnRemoteDied();
SingletonContainer::Get<ScreenManager>().OnRemoteDied();
return;
}

View File

@ -45,6 +45,7 @@ public:
bool UnregisterScreenGroupListener(sptr<IScreenGroupListener> listener);
bool RegisterVirtualScreenGroupListener(sptr<IVirtualScreenGroupListener> listener);
bool UnregisterVirtualScreenGroupListener(sptr<IVirtualScreenGroupListener> listener);
void OnRemoteDied();
private:
void NotifyScreenConnect(sptr<ScreenInfo> info);
@ -574,4 +575,17 @@ bool ScreenManager::Impl::isAllListenersRemoved() const
{
return screenListeners_.empty() && screenGroupListeners_.empty() && virtualScreenGroupListeners_.empty();
}
void ScreenManager::Impl::OnRemoteDied()
{
WLOGFI("dms is died");
std::lock_guard<std::recursive_mutex> lock(mutex_);
screenManagerListener_ = nullptr;
virtualScreenAgent_ = nullptr;
}
void ScreenManager::OnRemoteDied()
{
pImpl_->OnRemoteDied();
}
} // namespace OHOS::Rosen

View File

@ -28,6 +28,7 @@
namespace OHOS::Rosen {
class DisplayManager {
WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManager);
friend class DMSDeathRecipient;
public:
class IDisplayListener : public virtual RefBase {
public:
@ -76,6 +77,7 @@ public:
private:
DisplayManager();
~DisplayManager();
void OnRemoteDied();
class Impl;
sptr<Impl> pImpl_;

View File

@ -26,6 +26,7 @@
namespace OHOS::Rosen {
class ScreenManager : public RefBase {
WM_DECLARE_SINGLE_INSTANCE_BASE(ScreenManager);
friend class DMSDeathRecipient;
public:
class IScreenListener : public virtual RefBase {
public:
@ -73,6 +74,7 @@ public:
private:
ScreenManager();
~ScreenManager();
void OnRemoteDied();
class Impl;
sptr<Impl> pImpl_;

View File

@ -119,6 +119,7 @@ public:
class WindowManager {
WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManager);
friend class WindowManagerAgent;
friend class WMSDeathRecipient;
public:
bool RegisterFocusChangedListener(const sptr<IFocusChangedListener>& listener);
bool UnregisterFocusChangedListener(const sptr<IFocusChangedListener>& listener);
@ -151,6 +152,7 @@ private:
void UpdateWindowVisibilityInfo(
const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos) const;
void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) const;
void OnRemoteDied() const;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -16,6 +16,7 @@
#include "window_adapter.h"
#include <iservice_registry.h>
#include <system_ability_definition.h>
#include "window_manager.h"
#include "window_manager_hilog.h"
#include "wm_common.h"
@ -221,7 +222,9 @@ void WMSDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
WLOGFE("object is null");
return;
}
WLOGFI("wms OnRemoteDied");
SingletonContainer::Get<WindowAdapter>().ClearWindowAdapter();
SingletonContainer::Get<WindowManager>().OnRemoteDied();
}
WMError WindowAdapter::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId)

View File

@ -247,18 +247,23 @@ bool WindowManager::RegisterFocusChangedListener(const sptr<IFocusChangedListene
}
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
auto iter = std::find(pImpl_->focusChangedListeners_.begin(), pImpl_->focusChangedListeners_.end(), listener);
if (iter != pImpl_->focusChangedListeners_.end()) {
WLOGFW("Listener is already registered.");
return true;
}
pImpl_->focusChangedListeners_.push_back(listener);
bool ret = true;
if (pImpl_->focusChangedListenerAgent_ == nullptr) {
pImpl_->focusChangedListenerAgent_ = new WindowManagerAgent();
ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_);
}
if (!ret) {
WLOGFW("RegisterWindowManagerAgent failed !");
pImpl_->focusChangedListenerAgent_ = nullptr;
} else {
auto iter = std::find(pImpl_->focusChangedListeners_.begin(), pImpl_->focusChangedListeners_.end(), listener);
if (iter != pImpl_->focusChangedListeners_.end()) {
WLOGFW("Listener is already registered.");
return true;
}
pImpl_->focusChangedListeners_.push_back(listener);
}
return ret;
}
@ -293,19 +298,24 @@ bool WindowManager::RegisterSystemBarChangedListener(const sptr<ISystemBarChange
}
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
auto iter = std::find(pImpl_->systemBarChangedListeners_.begin(), pImpl_->systemBarChangedListeners_.end(),
listener);
if (iter != pImpl_->systemBarChangedListeners_.end()) {
WLOGFW("Listener is already registered.");
return true;
}
pImpl_->systemBarChangedListeners_.push_back(listener);
bool ret = true;
if (pImpl_->systemBarChangedListenerAgent_ == nullptr) {
pImpl_->systemBarChangedListenerAgent_ = new WindowManagerAgent();
ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_);
}
if (!ret) {
WLOGFW("RegisterWindowManagerAgent failed !");
pImpl_->systemBarChangedListenerAgent_ = nullptr;
} else {
auto iter = std::find(pImpl_->systemBarChangedListeners_.begin(), pImpl_->systemBarChangedListeners_.end(),
listener);
if (iter != pImpl_->systemBarChangedListeners_.end()) {
WLOGFW("Listener is already registered.");
return true;
}
pImpl_->systemBarChangedListeners_.push_back(listener);
}
return ret;
}
@ -362,18 +372,23 @@ bool WindowManager::RegisterWindowUpdateListener(const sptr<IWindowUpdateListene
return false;
}
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
auto iter = std::find(pImpl_->windowUpdateListeners_.begin(), pImpl_->windowUpdateListeners_.end(), listener);
if (iter != pImpl_->windowUpdateListeners_.end()) {
WLOGFI("Listener is already registered.");
return true;
}
pImpl_->windowUpdateListeners_.emplace_back(listener);
bool ret = true;
if (pImpl_->windowUpdateListenerAgent_ == nullptr) {
pImpl_->windowUpdateListenerAgent_ = new WindowManagerAgent();
ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_);
}
if (!ret) {
WLOGFW("RegisterWindowManagerAgent failed !");
pImpl_->windowUpdateListenerAgent_ = nullptr;
} else {
auto iter = std::find(pImpl_->windowUpdateListeners_.begin(), pImpl_->windowUpdateListeners_.end(), listener);
if (iter != pImpl_->windowUpdateListeners_.end()) {
WLOGFI("Listener is already registered.");
return true;
}
pImpl_->windowUpdateListeners_.emplace_back(listener);
}
return ret;
}
@ -406,13 +421,6 @@ bool WindowManager::RegisterVisibilityChangedListener(const sptr<IVisibilityChan
return false;
}
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
auto iter = std::find(pImpl_->windowVisibilityListeners_.begin(), pImpl_->windowVisibilityListeners_.end(),
listener);
if (iter != pImpl_->windowVisibilityListeners_.end()) {
WLOGFW("Listener is already registered.");
return true;
}
pImpl_->windowVisibilityListeners_.emplace_back(listener);
bool ret = true;
if (pImpl_->windowVisibilityListenerAgent_ == nullptr) {
pImpl_->windowVisibilityListenerAgent_ = new WindowManagerAgent();
@ -420,6 +428,18 @@ bool WindowManager::RegisterVisibilityChangedListener(const sptr<IVisibilityChan
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY,
pImpl_->windowVisibilityListenerAgent_);
}
if (!ret) {
WLOGFW("RegisterWindowManagerAgent failed !");
pImpl_->windowVisibilityListenerAgent_ = nullptr;
} else {
auto iter = std::find(pImpl_->windowVisibilityListeners_.begin(), pImpl_->windowVisibilityListeners_.end(),
listener);
if (iter != pImpl_->windowVisibilityListeners_.end()) {
WLOGFW("Listener is already registered.");
return true;
}
pImpl_->windowVisibilityListeners_.emplace_back(listener);
}
return ret;
}
@ -453,13 +473,6 @@ bool WindowManager::RegisterCameraFloatWindowChangedListener(const sptr<ICameraF
}
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
auto iter = std::find(pImpl_->cameraFloatWindowChangedListeners_.begin(),
pImpl_->cameraFloatWindowChangedListeners_.end(), listener);
if (iter != pImpl_->cameraFloatWindowChangedListeners_.end()) {
WLOGFW("Listener is already registered.");
return true;
}
pImpl_->cameraFloatWindowChangedListeners_.push_back(listener);
bool ret = true;
if (pImpl_->cameraFloatWindowChangedListenerAgent_ == nullptr) {
pImpl_->cameraFloatWindowChangedListenerAgent_ = new WindowManagerAgent();
@ -467,6 +480,18 @@ bool WindowManager::RegisterCameraFloatWindowChangedListener(const sptr<ICameraF
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT,
pImpl_->cameraFloatWindowChangedListenerAgent_);
}
if (!ret) {
WLOGFW("RegisterWindowManagerAgent failed !");
pImpl_->cameraFloatWindowChangedListenerAgent_ = nullptr;
} else {
auto iter = std::find(pImpl_->cameraFloatWindowChangedListeners_.begin(),
pImpl_->cameraFloatWindowChangedListeners_.end(), listener);
if (iter != pImpl_->cameraFloatWindowChangedListeners_.end()) {
WLOGFW("Listener is already registered.");
return true;
}
pImpl_->cameraFloatWindowChangedListeners_.push_back(listener);
}
return ret;
}
@ -554,5 +579,16 @@ void WindowManager::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool i
{
pImpl_->UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
}
void WindowManager::OnRemoteDied() const
{
WLOGFI("wms is died");
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
pImpl_->focusChangedListenerAgent_ = nullptr;
pImpl_->systemBarChangedListenerAgent_ = nullptr;
pImpl_->windowUpdateListenerAgent_ = nullptr;
pImpl_->windowVisibilityListenerAgent_ = nullptr;
pImpl_->cameraFloatWindowChangedListenerAgent_ = nullptr;
}
} // namespace Rosen
} // namespace OHOS