mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-28 01:21:13 +00:00
add ScreenChangeListener and DisplayChangeListener Binder Interface
Signed-off-by: xiaojianfeng <xiaojianfeng3@huawei.com> Change-Id: I44eb326765d0450bfe439595508fd97504326c08
This commit is contained in:
parent
121be3aaad
commit
9e2a46d08e
@ -17,11 +17,11 @@
|
||||
#define OHOS_ROSEN_DISPLAY_MANAGER_AGENT_H
|
||||
|
||||
#include <refbase.h>
|
||||
#include <zidl/display_manager_agent_stub.h>
|
||||
#include <display_manager_agent_default.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class DisplayManagerAgent : public DisplayManagerAgentStub {
|
||||
class DisplayManagerAgent : public DisplayManagerAgentDefault {
|
||||
public:
|
||||
DisplayManagerAgent() = default;
|
||||
~DisplayManagerAgent() = default;
|
||||
|
39
dm/include/display_manager_agent_default.h
Normal file
39
dm/include/display_manager_agent_default.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 MASTER_DISPLAY_MANAGER_AGENT_DEFAULT_H
|
||||
#define MASTER_DISPLAY_MANAGER_AGENT_DEFAULT_H
|
||||
|
||||
#include <zidl/display_manager_agent_stub.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class DisplayManagerAgentDefault : public DisplayManagerAgentStub {
|
||||
public:
|
||||
DisplayManagerAgentDefault() = default;
|
||||
~DisplayManagerAgentDefault() = default;
|
||||
|
||||
void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) override {};
|
||||
void NotifyDisplayStateChanged(DisplayState state) override {};
|
||||
void OnScreenConnect(sptr<ScreenInfo>) override {};
|
||||
void OnScreenDisconnect(ScreenId) override {};
|
||||
void OnScreenChange(const std::vector<const sptr<ScreenInfo>>&, ScreenChangeEvent) override {};
|
||||
void OnDisplayCreate(sptr<DisplayInfo>) override {};
|
||||
void OnDisplayDestroy(DisplayId) override {};
|
||||
void OnDisplayChange(sptr<DisplayInfo>, DisplayChangeEvent) override {};
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // MASTER_DISPLAY_MANAGER_AGENT_DEFAULT_H
|
@ -17,13 +17,17 @@
|
||||
#define OHOS_ROSEN_DISPLAY_MANAGER_AGENT_INTERFACE_H
|
||||
|
||||
#include <iremote_broker.h>
|
||||
#include "display_info.h"
|
||||
#include "dm_common.h"
|
||||
#include "screen_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
enum class DisplayManagerAgentType : uint32_t {
|
||||
DISPLAY_POWER_EVENT_LISTENER,
|
||||
DISPLAY_STATE_LISTENER,
|
||||
SCREEN_EVENT_LISTENER,
|
||||
DISPLAY_EVENT_LISTENER,
|
||||
};
|
||||
|
||||
class IDisplayManagerAgent : public IRemoteBroker {
|
||||
@ -33,9 +37,21 @@ public:
|
||||
enum {
|
||||
TRANS_ID_NOTIFY_DISPLAY_POWER_EVENT = 1,
|
||||
TRANS_ID_NOTIFY_DISPLAY_STATE_CHANGED,
|
||||
TRANS_ID_ON_SCREEN_CONNECT,
|
||||
TRANS_ID_ON_SCREEN_DISCONNECT,
|
||||
TRANS_ID_ON_SCREEN_CHANGED,
|
||||
TRANS_ID_ON_DISPLAY_CONNECT,
|
||||
TRANS_ID_ON_DISPLAY_DISCONNECT,
|
||||
TRANS_ID_ON_DISPLAY_CHANGED,
|
||||
};
|
||||
virtual void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) = 0;
|
||||
virtual void NotifyDisplayStateChanged(DisplayState state) = 0;
|
||||
virtual void OnScreenConnect(sptr<ScreenInfo>) = 0;
|
||||
virtual void OnScreenDisconnect(ScreenId) = 0;
|
||||
virtual void OnScreenChange(const std::vector<const sptr<ScreenInfo>>&, ScreenChangeEvent) = 0;
|
||||
virtual void OnDisplayCreate(sptr<DisplayInfo>) = 0;
|
||||
virtual void OnDisplayDestroy(DisplayId) = 0;
|
||||
virtual void OnDisplayChange(sptr<DisplayInfo>, DisplayChangeEvent) = 0;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
@ -28,7 +28,12 @@ public:
|
||||
|
||||
virtual void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) override;
|
||||
virtual void NotifyDisplayStateChanged(DisplayState state) override;
|
||||
|
||||
virtual void OnScreenConnect(sptr<ScreenInfo>) override;
|
||||
virtual void OnScreenDisconnect(ScreenId) override;
|
||||
virtual void OnScreenChange(const std::vector<const sptr<ScreenInfo>>&, ScreenChangeEvent) override;
|
||||
virtual void OnDisplayCreate(sptr<DisplayInfo>) override;
|
||||
virtual void OnDisplayDestroy(DisplayId) override;
|
||||
virtual void OnDisplayChange(sptr<DisplayInfo>, DisplayChangeEvent) override;
|
||||
private:
|
||||
static inline BrokerDelegator<DisplayManagerAgentProxy> delegator_;
|
||||
};
|
||||
|
@ -67,6 +67,145 @@ void DisplayManagerAgentProxy::NotifyDisplayStateChanged(DisplayState state)
|
||||
WLOGFE("SendRequest failed");
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentProxy::OnScreenConnect(sptr<ScreenInfo> screenInfo)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("WriteInterfaceToken failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(screenInfo.GetRefPtr())) {
|
||||
WLOGFE("Write ScreenInfo failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_CONNECT, data, reply, option) != ERR_NONE) {
|
||||
WLOGFE("SendRequest failed");
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentProxy::OnScreenDisconnect(ScreenId screenId)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("WriteInterfaceToken failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteUint64(screenId)) {
|
||||
WLOGFE("Write ScreenId failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_DISCONNECT, data, reply, option) != ERR_NONE) {
|
||||
WLOGFE("SendRequest failed");
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentProxy::OnScreenChange(
|
||||
const std::vector<const sptr<ScreenInfo>>& screenInfos, ScreenChangeEvent event)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("WriteInterfaceToken failed");
|
||||
return;
|
||||
}
|
||||
|
||||
size_t size = screenInfos.size();
|
||||
if (!data.WriteUint32(size)) {
|
||||
WLOGFE("Write creenInfos' size failed");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (!data.WriteParcelable(screenInfos[i].GetRefPtr())) {
|
||||
WLOGFE("Write screenInfos[%{public}d] size failed", i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(event))) {
|
||||
WLOGFE("Write ScreenChangeEvent failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Remote()->SendRequest(TRANS_ID_ON_SCREEN_CHANGED, data, reply, option) != ERR_NONE) {
|
||||
WLOGFE("SendRequest failed");
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentProxy::OnDisplayCreate(sptr<DisplayInfo> displayInfo)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("WriteInterfaceToken failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(displayInfo.GetRefPtr())) {
|
||||
WLOGFE("Write DisplayInfo failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Remote()->SendRequest(TRANS_ID_ON_DISPLAY_CONNECT, data, reply, option) != ERR_NONE) {
|
||||
WLOGFE("SendRequest failed");
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentProxy::OnDisplayDestroy(DisplayId displayId)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("WriteInterfaceToken failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteUint64(displayId)) {
|
||||
WLOGFE("Write DisplayId failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Remote()->SendRequest(TRANS_ID_ON_DISPLAY_DISCONNECT, data, reply, option) != ERR_NONE) {
|
||||
WLOGFE("SendRequest failed");
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentProxy::OnDisplayChange(sptr<DisplayInfo> displayInfo, DisplayChangeEvent event)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("WriteInterfaceToken failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(displayInfo.GetRefPtr())) {
|
||||
WLOGFE("Write DisplayInfo failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(event))) {
|
||||
WLOGFE("Write DisplayChangeEvent failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Remote()->SendRequest(TRANS_ID_ON_DISPLAY_CHANGED, data, reply, option) != ERR_NONE) {
|
||||
WLOGFE("SendRequest failed");
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
|
@ -43,6 +43,64 @@ int32_t DisplayManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& d
|
||||
NotifyDisplayStateChanged(state);
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_ON_SCREEN_CONNECT: {
|
||||
sptr<ScreenInfo> screenInfo = data.ReadParcelable<ScreenInfo>();
|
||||
OnScreenConnect(screenInfo);
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_ON_SCREEN_DISCONNECT: {
|
||||
ScreenId screenId;
|
||||
if (!data.ReadUint64(screenId)) {
|
||||
WLOGFE("Read ScreenId failed");
|
||||
return -1;
|
||||
}
|
||||
OnScreenDisconnect(screenId);
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_ON_SCREEN_CHANGED: {
|
||||
std::vector<const sptr<ScreenInfo>> screenInfos;
|
||||
uint32_t size;
|
||||
if (!data.ReadUint32(size)) {
|
||||
WLOGFE("Read ScreenChangeEvent failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
screenInfos.push_back(data.ReadParcelable<ScreenInfo>());
|
||||
}
|
||||
|
||||
uint32_t event;
|
||||
if (!data.ReadUint32(event)) {
|
||||
WLOGFE("Read ScreenChangeEvent failed");
|
||||
return -1;
|
||||
}
|
||||
OnScreenChange(screenInfos, static_cast<ScreenChangeEvent>(event));
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_ON_DISPLAY_CONNECT: {
|
||||
sptr<DisplayInfo> displayInfo = data.ReadParcelable<DisplayInfo>();
|
||||
OnDisplayCreate(displayInfo);
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_ON_DISPLAY_DISCONNECT: {
|
||||
DisplayId displayId;
|
||||
if (!data.ReadUint64(displayId)) {
|
||||
return -1;
|
||||
WLOGFE("Read DisplayId failed");
|
||||
}
|
||||
OnDisplayDestroy(displayId);
|
||||
break;
|
||||
}
|
||||
case TRANS_ID_ON_DISPLAY_CHANGED: {
|
||||
sptr<DisplayInfo> displayInfo = data.ReadParcelable<DisplayInfo>();
|
||||
uint32_t event;
|
||||
if (!data.ReadUint32(event)) {
|
||||
WLOGFE("Read DisplayChangeEvent failed");
|
||||
return -1;
|
||||
}
|
||||
OnDisplayChange(displayInfo, static_cast<DisplayChangeEvent>(event));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -34,11 +34,17 @@ public:
|
||||
bool NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status);
|
||||
bool NotifyDisplayStateChanged(DisplayState state);
|
||||
|
||||
void OnScreenConnect(sptr<ScreenInfo> screenInfo);
|
||||
void OnScreenDisconnect(ScreenId);
|
||||
void OnScreenChange(const std::vector<const sptr<ScreenInfo>>&, ScreenChangeEvent);
|
||||
void OnDisplayCreate(sptr<DisplayInfo>);
|
||||
void OnDisplayDestroy(DisplayId);
|
||||
void OnDisplayChange(sptr<DisplayInfo>, DisplayChangeEvent);
|
||||
|
||||
private:
|
||||
DisplayManagerAgentController() : dmAgentContainer_(mutex_) {}
|
||||
DisplayManagerAgentController() {}
|
||||
virtual ~DisplayManagerAgentController() = default;
|
||||
|
||||
std::recursive_mutex mutex_;
|
||||
ClientAgentContainer<IDisplayManagerAgent, DisplayManagerAgentType> dmAgentContainer_;
|
||||
};
|
||||
}
|
||||
|
@ -26,20 +26,17 @@ WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAgentController)
|
||||
bool DisplayManagerAgentController::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
DisplayManagerAgentType type)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
return dmAgentContainer_.RegisterAgentLocked(displayManagerAgent, type);
|
||||
return dmAgentContainer_.RegisterAgent(displayManagerAgent, type);
|
||||
}
|
||||
|
||||
bool DisplayManagerAgentController::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
DisplayManagerAgentType type)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
return dmAgentContainer_.UnregisterAgentLocked(displayManagerAgent, type);
|
||||
return dmAgentContainer_.UnregisterAgent(displayManagerAgent, type);
|
||||
}
|
||||
|
||||
bool DisplayManagerAgentController::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER);
|
||||
if (agents.empty()) {
|
||||
return false;
|
||||
@ -53,7 +50,6 @@ bool DisplayManagerAgentController::NotifyDisplayPowerEvent(DisplayPowerEvent ev
|
||||
|
||||
bool DisplayManagerAgentController::NotifyDisplayStateChanged(DisplayState state)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_STATE_LISTENER);
|
||||
if (agents.empty()) {
|
||||
return false;
|
||||
@ -64,5 +60,78 @@ bool DisplayManagerAgentController::NotifyDisplayStateChanged(DisplayState state
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DisplayManagerAgentController::OnScreenConnect(sptr<ScreenInfo> screenInfo)
|
||||
{
|
||||
auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
|
||||
if (agents.empty()) {
|
||||
return;
|
||||
}
|
||||
WLOGFI("OnScreenConnect");
|
||||
for (auto& agent : agents) {
|
||||
agent->OnScreenConnect(screenInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentController::OnScreenDisconnect(ScreenId screenId)
|
||||
{
|
||||
auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
|
||||
if (agents.empty()) {
|
||||
return;
|
||||
}
|
||||
WLOGFI("OnScreenDisconnect");
|
||||
for (auto& agent : agents) {
|
||||
agent->OnScreenDisconnect(screenId);
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentController::OnScreenChange(
|
||||
const std::vector<const sptr<ScreenInfo>>& screenInfos, ScreenChangeEvent screenChangeEvent)
|
||||
{
|
||||
auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::SCREEN_EVENT_LISTENER);
|
||||
if (agents.empty()) {
|
||||
return;
|
||||
}
|
||||
WLOGFI("OnScreenChange");
|
||||
for (auto& agent : agents) {
|
||||
agent->OnScreenChange(screenInfos, screenChangeEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentController::OnDisplayCreate(sptr<DisplayInfo> displayInfo)
|
||||
{
|
||||
auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_EVENT_LISTENER);
|
||||
if (agents.empty()) {
|
||||
return;
|
||||
}
|
||||
WLOGFI("OnDisplayCreate");
|
||||
for (auto& agent : agents) {
|
||||
agent->OnDisplayCreate(displayInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentController::OnDisplayDestroy(DisplayId displayId)
|
||||
{
|
||||
auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_EVENT_LISTENER);
|
||||
if (agents.empty()) {
|
||||
return;
|
||||
}
|
||||
WLOGFI("OnDisplayDestroy");
|
||||
for (auto& agent : agents) {
|
||||
agent->OnDisplayDestroy(displayId);
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerAgentController::OnDisplayChange(sptr<DisplayInfo> displayInfo, DisplayChangeEvent screenChangeEvent)
|
||||
{
|
||||
auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_EVENT_LISTENER);
|
||||
if (agents.empty()) {
|
||||
return;
|
||||
}
|
||||
WLOGFI("OnDisplayChange");
|
||||
for (auto& agent : agents) {
|
||||
agent->OnDisplayChange(displayInfo, screenChangeEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ class DisplayManager {
|
||||
friend class DisplayManagerAgent;
|
||||
WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManager);
|
||||
public:
|
||||
class IDisplayListener : public RefBase {
|
||||
class IDisplayListener : public virtual RefBase {
|
||||
public:
|
||||
virtual void OnCreate(DisplayId) = 0;
|
||||
virtual void OnDestroy(DisplayId) = 0;
|
||||
|
@ -89,6 +89,10 @@ enum class Rotation : uint32_t {
|
||||
ROTATION_180,
|
||||
ROTATION_270,
|
||||
};
|
||||
|
||||
enum class DisplayChangeEvent : uint32_t {
|
||||
DISPLAY_SIZE_CHANGED,
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // OHOS_ROSEN_DM_COMMON_H
|
@ -24,11 +24,11 @@
|
||||
#include "wm_single_instance.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class IScreenListener : public RefBase {
|
||||
class IScreenListener : public virtual RefBase {
|
||||
public:
|
||||
virtual void OnConnect(ScreenId) = 0;
|
||||
virtual void OnDisconnect(ScreenId) = 0;
|
||||
virtual void OnChange(std::vector<ScreenId>, ScreenChangeEvent) = 0;
|
||||
virtual void OnChange(const std::vector<ScreenId>&, ScreenChangeEvent) = 0;
|
||||
};
|
||||
|
||||
class ScreenManager : public RefBase {
|
||||
|
@ -27,11 +27,11 @@ namespace Rosen {
|
||||
template <typename T1, typename T2>
|
||||
class ClientAgentContainer {
|
||||
public:
|
||||
ClientAgentContainer(std::recursive_mutex& mutex);
|
||||
ClientAgentContainer();
|
||||
virtual ~ClientAgentContainer() = default;
|
||||
|
||||
bool RegisterAgentLocked(const sptr<T1>& agent, T2 type);
|
||||
bool UnregisterAgentLocked(const sptr<T1>& agent, T2 type);
|
||||
bool RegisterAgent(const sptr<T1>& agent, T2 type);
|
||||
bool UnregisterAgent(const sptr<T1>& agent, T2 type);
|
||||
std::vector<sptr<T1>> GetAgentsByType(T2 type);
|
||||
|
||||
private:
|
||||
@ -49,19 +49,19 @@ private:
|
||||
sptr<IRemoteObject> remoteObject_;
|
||||
};
|
||||
|
||||
std::recursive_mutex& mutex_;
|
||||
std::recursive_mutex mutex_;
|
||||
std::map<T2, std::vector<sptr<T1>>> agentMap_;
|
||||
sptr<AgentDeathRecipient> deathRecipient_;
|
||||
};
|
||||
|
||||
template<typename T1, typename T2>
|
||||
ClientAgentContainer<T1, T2>::ClientAgentContainer(std::recursive_mutex& mutex)
|
||||
: mutex_(mutex), deathRecipient_(new AgentDeathRecipient(
|
||||
std::bind(&ClientAgentContainer<T1, T2>::RemoveAgent, this, std::placeholders::_1))) {}
|
||||
ClientAgentContainer<T1, T2>::ClientAgentContainer() : deathRecipient_(
|
||||
new AgentDeathRecipient(std::bind(&ClientAgentContainer<T1, T2>::RemoveAgent, this, std::placeholders::_1))) {}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
bool ClientAgentContainer<T1, T2>::RegisterAgentLocked(const sptr<T1>& agent, T2 type)
|
||||
bool ClientAgentContainer<T1, T2>::RegisterAgent(const sptr<T1>& agent, T2 type)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
agentMap_[type].push_back(agent);
|
||||
WLOG_I("ClientAgentContainer agent registered type:%{public}u", type);
|
||||
if (deathRecipient_ == nullptr || !agent->AsObject()->AddDeathRecipient(deathRecipient_)) {
|
||||
@ -71,8 +71,9 @@ bool ClientAgentContainer<T1, T2>::RegisterAgentLocked(const sptr<T1>& agent, T2
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
bool ClientAgentContainer<T1, T2>::UnregisterAgentLocked(const sptr<T1>& agent, T2 type)
|
||||
bool ClientAgentContainer<T1, T2>::UnregisterAgent(const sptr<T1>& agent, T2 type)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (agent == nullptr || agentMap_.count(type) == 0) {
|
||||
WLOG_E("ClientAgentContainer agent or type is invalid");
|
||||
return false;
|
||||
@ -86,6 +87,7 @@ bool ClientAgentContainer<T1, T2>::UnregisterAgentLocked(const sptr<T1>& agent,
|
||||
template<typename T1, typename T2>
|
||||
std::vector<sptr<T1>> ClientAgentContainer<T1, T2>::GetAgentsByType(T2 type)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (agentMap_.count(type) == 0) {
|
||||
WLOG_W("ClientAgentContainer no such type of agent registered! type:%{public}u", type);
|
||||
return std::vector<sptr<T1>>();
|
||||
|
@ -30,13 +30,13 @@ public:
|
||||
void Update(sptr<ScreenGroupInfo> info);
|
||||
|
||||
virtual bool Marshalling(Parcel& parcel) const override;
|
||||
static sptr<ScreenGroupInfo> Unmarshalling(Parcel& parcel);
|
||||
ScreenGroupInfo* Unmarshalling(Parcel& parcel);
|
||||
|
||||
std::vector<ScreenId> children_;
|
||||
std::vector<Point> position_;
|
||||
ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE };
|
||||
protected:
|
||||
sptr<ScreenGroupInfo> InnerUnmarshalling(Parcel& parcel);
|
||||
ScreenGroupInfo* InnerUnmarshalling(Parcel& parcel);
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // FOUNDATION_DMSERVER_SCREEN_GROUP_INFO_H
|
@ -29,7 +29,7 @@ public:
|
||||
void Update(sptr<ScreenInfo> info);
|
||||
|
||||
virtual bool Marshalling(Parcel& parcel) const override;
|
||||
static sptr<ScreenInfo> Unmarshalling(Parcel& parcel);
|
||||
static ScreenInfo* Unmarshalling(Parcel& parcel);
|
||||
|
||||
ScreenId id_ { SCREEN_ID_INVALID };
|
||||
uint32_t width_ { 0 };
|
||||
@ -40,7 +40,7 @@ public:
|
||||
ScreenId parent_ { 0 };
|
||||
bool hasChild_ { false };
|
||||
protected:
|
||||
sptr<ScreenInfo> InnerUnmarshalling(Parcel& parcel);
|
||||
ScreenInfo* InnerUnmarshalling(Parcel& parcel);
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H
|
@ -45,13 +45,13 @@ bool ScreenGroupInfo::Marshalling(Parcel &parcel) const
|
||||
return true;
|
||||
}
|
||||
|
||||
sptr<ScreenGroupInfo> ScreenGroupInfo::Unmarshalling(Parcel &parcel)
|
||||
ScreenGroupInfo* ScreenGroupInfo::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
sptr<ScreenGroupInfo> screenGroupInfo = new ScreenGroupInfo();
|
||||
ScreenGroupInfo* screenGroupInfo = new ScreenGroupInfo();
|
||||
return screenGroupInfo->InnerUnmarshalling(parcel);
|
||||
}
|
||||
|
||||
sptr<ScreenGroupInfo> ScreenGroupInfo::InnerUnmarshalling(Parcel& parcel)
|
||||
ScreenGroupInfo* ScreenGroupInfo::InnerUnmarshalling(Parcel& parcel)
|
||||
{
|
||||
uint32_t combination;
|
||||
if (!ScreenInfo::InnerUnmarshalling(parcel) || !parcel.ReadUint32(combination) ||
|
||||
|
@ -37,13 +37,13 @@ bool ScreenInfo::Marshalling(Parcel &parcel) const
|
||||
parcel.WriteBool(hasChild_);
|
||||
}
|
||||
|
||||
sptr<ScreenInfo> ScreenInfo::Unmarshalling(Parcel &parcel)
|
||||
ScreenInfo* ScreenInfo::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
sptr<ScreenInfo> info = new ScreenInfo();
|
||||
ScreenInfo* info = new ScreenInfo();
|
||||
return info->InnerUnmarshalling(parcel);
|
||||
}
|
||||
|
||||
sptr<ScreenInfo> ScreenInfo::InnerUnmarshalling(Parcel& parcel)
|
||||
ScreenInfo* ScreenInfo::InnerUnmarshalling(Parcel& parcel)
|
||||
{
|
||||
bool res = parcel.ReadUint64(id_) &&
|
||||
parcel.ReadUint32(width_) && parcel.ReadUint32(height_) &&
|
||||
|
@ -36,10 +36,9 @@ public:
|
||||
void UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& tints);
|
||||
|
||||
private:
|
||||
WindowManagerAgentController() : wmAgentContainer_(mutex_) {}
|
||||
WindowManagerAgentController() {}
|
||||
virtual ~WindowManagerAgentController() = default;
|
||||
|
||||
std::recursive_mutex mutex_;
|
||||
ClientAgentContainer<IWindowManagerAgent, WindowManagerAgentType> wmAgentContainer_;
|
||||
};
|
||||
}
|
||||
|
@ -26,21 +26,18 @@ WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerAgentController)
|
||||
void WindowManagerAgentController::RegisterWindowManagerAgent(const sptr<IWindowManagerAgent>& windowManagerAgent,
|
||||
WindowManagerAgentType type)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
wmAgentContainer_.RegisterAgentLocked(windowManagerAgent, type);
|
||||
wmAgentContainer_.RegisterAgent(windowManagerAgent, type);
|
||||
}
|
||||
|
||||
void WindowManagerAgentController::UnregisterWindowManagerAgent(const sptr<IWindowManagerAgent>& windowManagerAgent,
|
||||
WindowManagerAgentType type)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
wmAgentContainer_.UnregisterAgentLocked(windowManagerAgent, type);
|
||||
wmAgentContainer_.UnregisterAgent(windowManagerAgent, type);
|
||||
}
|
||||
|
||||
void WindowManagerAgentController::UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
|
||||
WindowType windowType, DisplayId displayId, bool focused)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
WLOGFI("UpdateFocusStatus");
|
||||
for (auto& agent : wmAgentContainer_.GetAgentsByType(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS)) {
|
||||
agent->UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused);
|
||||
@ -52,7 +49,6 @@ void WindowManagerAgentController::UpdateSystemBarRegionTints(DisplayId displayI
|
||||
if (tints.empty()) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
WLOGFI("UpdateSystemBarRegionTints");
|
||||
for (auto& agent : wmAgentContainer_.GetAgentsByType(
|
||||
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR)) {
|
||||
|
Loading…
Reference in New Issue
Block a user