mirror of
https://gitee.com/openharmony/window_window_manager
synced 2025-02-26 10:45:49 +00:00
dm拆分客户端代码
Signed-off-by: y30046716 <yaodixiong@huawei.com> Change-Id: Ife7c1af8ca3c662d45f908280d5b195b74036135
This commit is contained in:
parent
9df4f8ff37
commit
bbd61484ba
13
bundle.json
13
bundle.json
@ -160,6 +160,19 @@
|
||||
"header_base": "//foundation/window/window_manager/interfaces/innerkits/dm"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "so",
|
||||
"name": "//foundation/window/window_manager/dm_lite:libdm_lite",
|
||||
"header": {
|
||||
"header_files": [
|
||||
"display_lite.h",
|
||||
"display_manager_lite.h",
|
||||
"../dm/display_property.h",
|
||||
"../dm/dm_common.h"
|
||||
],
|
||||
"header_base": "//foundation/window/window_manager/interfaces/innerkits/dm_lite"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "so",
|
||||
"name": "//foundation/window/window_manager/extension/extension_connection:libwindow_extension_client",
|
||||
|
71
dm_lite/BUILD.gn
Normal file
71
dm_lite/BUILD.gn
Normal file
@ -0,0 +1,71 @@
|
||||
# Copyright (c) 2023 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("../windowmanager_aafwk.gni")
|
||||
|
||||
config("libdm_private_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"../dm/include",
|
||||
]
|
||||
}
|
||||
|
||||
config("libdm_public_config") {
|
||||
include_dirs = [
|
||||
"../interfaces/innerkits/dm",
|
||||
"../interfaces/innerkits/dm_lite",
|
||||
"../utils/include",
|
||||
]
|
||||
}
|
||||
|
||||
## Build libdm.so
|
||||
ohos_shared_library("libdm_lite") {
|
||||
branch_protector_ret = "pac_ret"
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
sources = [
|
||||
"../dm/src/zidl/display_manager_agent_stub.cpp",
|
||||
"../window_scene/session_manager/src/zidl/screen_session_manager_lite_proxy.cpp",
|
||||
"src/display_lite.cpp",
|
||||
"src/display_manager_adapter_lite.cpp",
|
||||
"src/display_manager_lite.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
":libdm_private_config",
|
||||
"../resources/config/build:coverage_flags",
|
||||
]
|
||||
|
||||
public_configs = [ ":libdm_public_config" ]
|
||||
|
||||
deps = [
|
||||
"${window_base_path}/utils:libwmutil_base",
|
||||
"${window_base_path}/window_scene/session_manager:session_manager_lite",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:ability_manager",
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_single",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
part_name = "window_manager"
|
||||
subsystem_name = "window"
|
||||
}
|
59
dm_lite/include/display_manager_adapter_lite.h
Normal file
59
dm_lite/include/display_manager_adapter_lite.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_LITE_H
|
||||
#define FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_LITE_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
#include "display_lite.h"
|
||||
#include "dm_common.h"
|
||||
#include "singleton_delegator.h"
|
||||
#include "zidl/screen_session_manager_lite_interface.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class BaseAdapterLite {
|
||||
public:
|
||||
virtual ~BaseAdapterLite();
|
||||
virtual DMError RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
DisplayManagerAgentType type);
|
||||
virtual DMError UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
DisplayManagerAgentType type);
|
||||
virtual void Clear();
|
||||
protected:
|
||||
bool InitDMSProxy();
|
||||
std::recursive_mutex mutex_;
|
||||
sptr<IScreenSessionManagerLite> displayManagerServiceProxy_ = nullptr;
|
||||
sptr<IRemoteObject::DeathRecipient> dmsDeath_ = nullptr;
|
||||
bool isProxyValid_ { false };
|
||||
};
|
||||
|
||||
class DMSDeathRecipientLite : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
explicit DMSDeathRecipientLite(BaseAdapterLite& adapter);
|
||||
virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override;
|
||||
private:
|
||||
BaseAdapterLite& adapter_;
|
||||
};
|
||||
|
||||
class DisplayManagerAdapterLite : public BaseAdapterLite {
|
||||
WM_DECLARE_SINGLE_INSTANCE(DisplayManagerAdapterLite);
|
||||
public:
|
||||
private:
|
||||
static inline SingletonDelegator<DisplayManagerAdapterLite> delegator;
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_LITE_H
|
65
dm_lite/src/display_lite.cpp
Normal file
65
dm_lite/src/display_lite.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_lite.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <new>
|
||||
#include <refbase.h>
|
||||
|
||||
#include "class_var_definition.h"
|
||||
#include "display_info.h"
|
||||
#include "display_manager_adapter_lite.h"
|
||||
#include "dm_common.h"
|
||||
#include "singleton_container.h"
|
||||
#include "window_manager_hilog.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayLite"};
|
||||
}
|
||||
class DisplayLite::Impl : public RefBase {
|
||||
public:
|
||||
Impl(const std::string& name, sptr<DisplayInfo> info)
|
||||
{
|
||||
displayInfo_ = info;
|
||||
name_= name;
|
||||
}
|
||||
~Impl() = default;
|
||||
DEFINE_VAR_FUNC_GET_SET_WITH_LOCK(sptr<DisplayInfo>, DisplayInfo, displayInfo);
|
||||
DEFINE_VAR_FUNC_GET_SET(std::string, Name, name);
|
||||
};
|
||||
|
||||
DisplayLite::DisplayLite(const std::string& name, sptr<DisplayInfo> info)
|
||||
: pImpl_(new Impl(name, info))
|
||||
{
|
||||
}
|
||||
|
||||
DisplayLite::~DisplayLite()
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayLite::UpdateDisplayInfo(sptr<DisplayInfo> displayInfo) const
|
||||
{
|
||||
if (displayInfo == nullptr) {
|
||||
WLOGFE("displayInfo is nullptr");
|
||||
return;
|
||||
}
|
||||
if (pImpl_ == nullptr) {
|
||||
WLOGFE("pImpl_ is nullptr");
|
||||
return;
|
||||
}
|
||||
pImpl_->SetDisplayInfo(displayInfo);
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
121
dm_lite/src/display_manager_adapter_lite.cpp
Normal file
121
dm_lite/src/display_manager_adapter_lite.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
// /*
|
||||
// * Copyright (c) 2023 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_manager_adapter_lite.h"
|
||||
|
||||
#include <iremote_broker.h>
|
||||
#include <iservice_registry.h>
|
||||
#include <system_ability_definition.h>
|
||||
|
||||
#include "display_manager_lite.h"
|
||||
#include "dm_common.h"
|
||||
#include "window_manager_hilog.h"
|
||||
#include "session_manager_lite.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAdapterLite"};
|
||||
}
|
||||
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapterLite)
|
||||
|
||||
|
||||
#define INIT_PROXY_CHECK_RETURN(ret) \
|
||||
do { \
|
||||
if (!InitDMSProxy()) { \
|
||||
WLOGFE("InitDMSProxy fail"); \
|
||||
return ret; \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
DMError BaseAdapterLite::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
DisplayManagerAgentType type)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
|
||||
|
||||
return displayManagerServiceProxy_->RegisterDisplayManagerAgent(displayManagerAgent, type);
|
||||
}
|
||||
|
||||
DMError BaseAdapterLite::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
|
||||
DisplayManagerAgentType type)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
|
||||
|
||||
return displayManagerServiceProxy_->UnregisterDisplayManagerAgent(displayManagerAgent, type);
|
||||
}
|
||||
|
||||
bool BaseAdapterLite::InitDMSProxy()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!isProxyValid_) {
|
||||
displayManagerServiceProxy_ = SessionManagerLite::GetInstance().GetScreenSessionManagerLiteProxy();
|
||||
if ((!displayManagerServiceProxy_) || (!displayManagerServiceProxy_->AsObject())) {
|
||||
WLOGFE("Failed to get system scene session manager services");
|
||||
return false;
|
||||
}
|
||||
dmsDeath_ = new (std::nothrow) DMSDeathRecipientLite(*this);
|
||||
if (!dmsDeath_) {
|
||||
WLOGFE("Failed to create death Recipient ptr DMSDeathRecipientLite");
|
||||
return false;
|
||||
}
|
||||
sptr<IRemoteObject> remoteObject = displayManagerServiceProxy_->AsObject();
|
||||
if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(dmsDeath_)) {
|
||||
WLOGFE("Failed to add death recipient.");
|
||||
return false;
|
||||
}
|
||||
isProxyValid_ = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
DMSDeathRecipientLite::DMSDeathRecipientLite(BaseAdapterLite& adapter) : adapter_(adapter)
|
||||
{
|
||||
}
|
||||
|
||||
void DMSDeathRecipientLite::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
|
||||
{
|
||||
if (wptrDeath == nullptr) {
|
||||
WLOGFE("wptrDeath is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> object = wptrDeath.promote();
|
||||
if (!object) {
|
||||
WLOGFE("object is nullptr");
|
||||
return;
|
||||
}
|
||||
WLOGFI("dms OnRemoteDied");
|
||||
adapter_.Clear();
|
||||
SingletonContainer::Get<DisplayManagerLite>().OnRemoteDied();
|
||||
SingletonContainer::Get<SessionManagerLite>().ClearSessionManagerProxy();
|
||||
return;
|
||||
}
|
||||
|
||||
BaseAdapterLite::~BaseAdapterLite()
|
||||
{
|
||||
WLOGFI("BaseAdapterLite destroy");
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
displayManagerServiceProxy_ = nullptr;
|
||||
}
|
||||
|
||||
void BaseAdapterLite::Clear()
|
||||
{
|
||||
WLOGFI("BaseAdapterLite Clear");
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if ((displayManagerServiceProxy_ != nullptr) && (displayManagerServiceProxy_->AsObject() != nullptr)) {
|
||||
displayManagerServiceProxy_->AsObject()->RemoveDeathRecipient(dmsDeath_);
|
||||
}
|
||||
isProxyValid_ = false;
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
267
dm_lite/src/display_manager_lite.cpp
Normal file
267
dm_lite/src/display_manager_lite.cpp
Normal file
@ -0,0 +1,267 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_manager_lite.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
|
||||
#include "display_manager_adapter_lite.h"
|
||||
#include "display_manager_agent_default.h"
|
||||
#include "dm_common.h"
|
||||
#include "singleton_delegator.h"
|
||||
#include "window_manager_hilog.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerLite"};
|
||||
}
|
||||
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerLite)
|
||||
|
||||
class DisplayManagerLite::Impl : public RefBase {
|
||||
public:
|
||||
Impl(std::recursive_mutex& mutex) : mutex_(mutex) {}
|
||||
~Impl();
|
||||
static inline SingletonDelegator<DisplayManagerLite> delegator;
|
||||
|
||||
DMError RegisterDisplayListener(sptr<IDisplayListener> listener);
|
||||
DMError UnregisterDisplayListener(sptr<IDisplayListener> listener);
|
||||
void OnRemoteDied();
|
||||
private:
|
||||
void NotifyDisplayCreate(sptr<DisplayInfo> info);
|
||||
void NotifyDisplayDestroy(DisplayId);
|
||||
void NotifyDisplayChange(sptr<DisplayInfo> displayInfo);
|
||||
bool UpdateDisplayInfoLocked(sptr<DisplayInfo>);
|
||||
void Clear();
|
||||
|
||||
std::map<DisplayId, sptr<DisplayLite>> displayMap_;
|
||||
std::recursive_mutex& mutex_;
|
||||
std::set<sptr<IDisplayListener>> displayListeners_;
|
||||
class DisplayManagerListener;
|
||||
sptr<DisplayManagerListener> displayManagerListener_;
|
||||
};
|
||||
|
||||
class DisplayManagerLite::Impl::DisplayManagerListener : public DisplayManagerAgentDefault {
|
||||
public:
|
||||
explicit DisplayManagerListener(sptr<Impl> impl) : pImpl_(impl)
|
||||
{
|
||||
}
|
||||
|
||||
void OnDisplayCreate(sptr<DisplayInfo> displayInfo) override
|
||||
{
|
||||
if (displayInfo == nullptr || displayInfo->GetDisplayId() == DISPLAY_ID_INVALID) {
|
||||
WLOGFE("onDisplayCreate: displayInfo is nullptr");
|
||||
return;
|
||||
}
|
||||
if (pImpl_ == nullptr) {
|
||||
WLOGFE("onDisplayCreate: pImpl_ is nullptr");
|
||||
return;
|
||||
}
|
||||
pImpl_->NotifyDisplayCreate(displayInfo);
|
||||
std::set<sptr<IDisplayListener>> displayListeners;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
|
||||
displayListeners = pImpl_->displayListeners_;
|
||||
}
|
||||
for (auto listener : displayListeners) {
|
||||
listener->OnCreate(displayInfo->GetDisplayId());
|
||||
}
|
||||
};
|
||||
|
||||
void OnDisplayDestroy(DisplayId displayId) override
|
||||
{
|
||||
if (displayId == DISPLAY_ID_INVALID) {
|
||||
WLOGFE("onDisplayDestroy: displayId is invalid");
|
||||
return;
|
||||
}
|
||||
if (pImpl_ == nullptr) {
|
||||
WLOGFE("onDisplayDestroy: impl is nullptr");
|
||||
return;
|
||||
}
|
||||
pImpl_->NotifyDisplayDestroy(displayId);
|
||||
std::set<sptr<IDisplayListener>> displayListeners;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
|
||||
displayListeners = pImpl_->displayListeners_;
|
||||
}
|
||||
for (auto listener : displayListeners) {
|
||||
listener->OnDestroy(displayId);
|
||||
}
|
||||
};
|
||||
|
||||
void OnDisplayChange(sptr<DisplayInfo> displayInfo, DisplayChangeEvent event) override
|
||||
{
|
||||
if (displayInfo == nullptr || displayInfo->GetDisplayId() == DISPLAY_ID_INVALID) {
|
||||
WLOGFE("onDisplayChange: displayInfo is nullptr");
|
||||
return;
|
||||
}
|
||||
if (pImpl_ == nullptr) {
|
||||
WLOGFE("onDisplayChange: pImpl_ is nullptr");
|
||||
return;
|
||||
}
|
||||
WLOGD("onDisplayChange: display %{public}" PRIu64", event %{public}u", displayInfo->GetDisplayId(), event);
|
||||
pImpl_->NotifyDisplayChange(displayInfo);
|
||||
std::set<sptr<IDisplayListener>> displayListeners;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
|
||||
displayListeners = pImpl_->displayListeners_;
|
||||
}
|
||||
for (auto listener : displayListeners) {
|
||||
listener->OnChange(displayInfo->GetDisplayId());
|
||||
}
|
||||
};
|
||||
private:
|
||||
sptr<Impl> pImpl_;
|
||||
};
|
||||
|
||||
void DisplayManagerLite::Impl::Clear()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
DMError res = DMError::DM_OK;
|
||||
if (displayManagerListener_ != nullptr) {
|
||||
res = SingletonContainer::Get<DisplayManagerAdapterLite>().UnregisterDisplayManagerAgent(
|
||||
displayManagerListener_, DisplayManagerAgentType::DISPLAY_EVENT_LISTENER);
|
||||
}
|
||||
displayManagerListener_ = nullptr;
|
||||
if (res != DMError::DM_OK) {
|
||||
WLOGFW("UnregisterDisplayManagerAgent DISPLAY_EVENT_LISTENER failed");
|
||||
}
|
||||
}
|
||||
|
||||
DisplayManagerLite::Impl::~Impl()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
DisplayManagerLite::DisplayManagerLite() : pImpl_(new Impl(mutex_))
|
||||
{
|
||||
}
|
||||
|
||||
DisplayManagerLite::~DisplayManagerLite()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
destroyed_ = true;
|
||||
}
|
||||
|
||||
DMError DisplayManagerLite::Impl::RegisterDisplayListener(sptr<IDisplayListener> listener)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
DMError ret = DMError::DM_OK;
|
||||
if (displayManagerListener_ == nullptr) {
|
||||
displayManagerListener_ = new DisplayManagerListener(this);
|
||||
ret = SingletonContainer::Get<DisplayManagerAdapterLite>().RegisterDisplayManagerAgent(
|
||||
displayManagerListener_,
|
||||
DisplayManagerAgentType::DISPLAY_EVENT_LISTENER);
|
||||
}
|
||||
if (ret != DMError::DM_OK) {
|
||||
WLOGFW("RegisterDisplayManagerAgent failed");
|
||||
displayManagerListener_ = nullptr;
|
||||
} else {
|
||||
displayListeners_.insert(listener);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
DMError DisplayManagerLite::RegisterDisplayListener(sptr<IDisplayListener> listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
WLOGFE("RegisterDisplayListener listener is nullptr");
|
||||
return DMError::DM_ERROR_NULLPTR;
|
||||
}
|
||||
return pImpl_->RegisterDisplayListener(listener);
|
||||
}
|
||||
|
||||
DMError DisplayManagerLite::Impl::UnregisterDisplayListener(sptr<IDisplayListener> listener)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
auto iter = std::find(displayListeners_.begin(), displayListeners_.end(), listener);
|
||||
if (iter == displayListeners_.end()) {
|
||||
WLOGFE("could not find this listener");
|
||||
return DMError::DM_ERROR_NULLPTR;
|
||||
}
|
||||
displayListeners_.erase(iter);
|
||||
DMError ret = DMError::DM_OK;
|
||||
if (displayListeners_.empty() && displayManagerListener_ != nullptr) {
|
||||
ret = SingletonContainer::Get<DisplayManagerAdapterLite>().UnregisterDisplayManagerAgent(
|
||||
displayManagerListener_,
|
||||
DisplayManagerAgentType::DISPLAY_EVENT_LISTENER);
|
||||
displayManagerListener_ = nullptr;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
DMError DisplayManagerLite::UnregisterDisplayListener(sptr<IDisplayListener> listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
WLOGFE("UnregisterDisplayListener listener is nullptr");
|
||||
return DMError::DM_ERROR_NULLPTR;
|
||||
}
|
||||
return pImpl_->UnregisterDisplayListener(listener);
|
||||
}
|
||||
|
||||
void DisplayManagerLite::Impl::NotifyDisplayCreate(sptr<DisplayInfo> info)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
UpdateDisplayInfoLocked(info);
|
||||
}
|
||||
|
||||
void DisplayManagerLite::Impl::NotifyDisplayDestroy(DisplayId displayId)
|
||||
{
|
||||
WLOGFD("displayId:%{public}" PRIu64".", displayId);
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
displayMap_.erase(displayId);
|
||||
}
|
||||
|
||||
void DisplayManagerLite::Impl::NotifyDisplayChange(sptr<DisplayInfo> displayInfo)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
UpdateDisplayInfoLocked(displayInfo);
|
||||
}
|
||||
|
||||
bool DisplayManagerLite::Impl::UpdateDisplayInfoLocked(sptr<DisplayInfo> displayInfo)
|
||||
{
|
||||
if (displayInfo == nullptr) {
|
||||
WLOGFE("displayInfo is null");
|
||||
return false;
|
||||
}
|
||||
DisplayId displayId = displayInfo->GetDisplayId();
|
||||
WLOGFD("displayId:%{public}" PRIu64".", displayId);
|
||||
if (displayId == DISPLAY_ID_INVALID) {
|
||||
WLOGFE("displayId is invalid");
|
||||
return false;
|
||||
}
|
||||
auto iter = displayMap_.find(displayId);
|
||||
if (iter != displayMap_.end() && iter->second != nullptr) {
|
||||
WLOGFD("get screen in screen map");
|
||||
iter->second->UpdateDisplayInfo(displayInfo);
|
||||
return true;
|
||||
}
|
||||
sptr<DisplayLite> display = new DisplayLite("", displayInfo);
|
||||
displayMap_[displayId] = display;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DisplayManagerLite::Impl::OnRemoteDied()
|
||||
{
|
||||
WLOGFI("dms is died");
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
displayManagerListener_ = nullptr;
|
||||
}
|
||||
|
||||
void DisplayManagerLite::OnRemoteDied()
|
||||
{
|
||||
pImpl_->OnRemoteDied();
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
46
interfaces/innerkits/dm_lite/display_lite.h
Normal file
46
interfaces/innerkits/dm_lite/display_lite.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 FOUNDATION_DM_DISPLAY_LITE_H
|
||||
#define FOUNDATION_DM_DISPLAY_LITE_H
|
||||
|
||||
#include <string>
|
||||
#include "dm_common.h"
|
||||
#include "noncopyable.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class DisplayInfo;
|
||||
class CutoutInfo;
|
||||
|
||||
class DisplayLite : public RefBase {
|
||||
friend class DisplayManagerLite;
|
||||
public:
|
||||
~DisplayLite();
|
||||
DisplayLite(const DisplayLite&) = delete;
|
||||
DisplayLite(DisplayLite&&) = delete;
|
||||
DisplayLite& operator=(const DisplayLite&) = delete;
|
||||
DisplayLite& operator=(DisplayLite&&) = delete;
|
||||
protected:
|
||||
// No more methods or variables can be defined here.
|
||||
DisplayLite(const std::string& name, sptr<DisplayInfo> info);
|
||||
private:
|
||||
// No more methods or variables can be defined here.
|
||||
void UpdateDisplayInfo(sptr<DisplayInfo>) const;
|
||||
class Impl;
|
||||
sptr<Impl> pImpl_;
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
|
||||
#endif // FOUNDATION_DM_DISPLAY_LITE_H
|
77
interfaces/innerkits/dm_lite/display_manager_lite.h
Normal file
77
interfaces/innerkits/dm_lite/display_manager_lite.h
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 FOUNDATION_DM_DISPLAY_MANAGER_LITE_H
|
||||
#define FOUNDATION_DM_DISPLAY_MANAGER_LITE_H
|
||||
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
|
||||
#include "display_lite.h"
|
||||
#include "dm_common.h"
|
||||
#include "wm_single_instance.h"
|
||||
#include "display_change_info.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class DisplayManagerLite {
|
||||
WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerLite);
|
||||
friend class DMSDeathRecipientLite;
|
||||
public:
|
||||
class IDisplayListener : public virtual RefBase {
|
||||
public:
|
||||
/**
|
||||
* @brief Notify when a new display is created.
|
||||
*/
|
||||
virtual void OnCreate(DisplayId) = 0;
|
||||
|
||||
/**
|
||||
* @brief Notify when the display is destroyed.
|
||||
*/
|
||||
virtual void OnDestroy(DisplayId) = 0;
|
||||
|
||||
/**
|
||||
* @brief Notify when the state of a display changes
|
||||
*/
|
||||
virtual void OnChange(DisplayId) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Resgister a display listener.
|
||||
*
|
||||
* @param listener IDisplayListener.
|
||||
* @return DM_OK means register success, others means register failed.
|
||||
*/
|
||||
DMError RegisterDisplayListener(sptr<IDisplayListener> listener);
|
||||
|
||||
/**
|
||||
* @brief Unregister an existed display listener.
|
||||
*
|
||||
* @param listener IDisplayListener.
|
||||
* @return DM_OK means unregister success, others means unregister failed.
|
||||
*/
|
||||
DMError UnregisterDisplayListener(sptr<IDisplayListener> listener);
|
||||
private:
|
||||
DisplayManagerLite();
|
||||
~DisplayManagerLite();
|
||||
void OnRemoteDied();
|
||||
|
||||
class Impl;
|
||||
std::recursive_mutex mutex_;
|
||||
bool destroyed_ = false;
|
||||
sptr<Impl> pImpl_;
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
|
||||
#endif // FOUNDATION_DM_DISPLAY_MANAGER_LITE_H
|
@ -117,6 +117,8 @@ ohos_shared_library("libwmutil_base") {
|
||||
"src/cutout_info.cpp",
|
||||
"src/display_change_info.cpp",
|
||||
"src/display_info.cpp",
|
||||
"src/screen_group_info.cpp",
|
||||
"src/screen_info.cpp",
|
||||
"src/screenshot_info.cpp",
|
||||
"src/singleton_container.cpp",
|
||||
"src/string_util.cpp",
|
||||
|
@ -82,6 +82,8 @@ public:
|
||||
virtual bool SetDisplayState(DisplayState state) { return false; }
|
||||
virtual DisplayState GetDisplayState(DisplayId displayId) {return DisplayState::UNKNOWN; }
|
||||
virtual void NotifyDisplayEvent(DisplayEvent event) {}
|
||||
virtual bool SetSpecifiedScreenPower(ScreenId, ScreenPowerState, PowerStateChangeReason) { return false; }
|
||||
virtual bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason) { return false; }
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
Loading…
x
Reference in New Issue
Block a user