add scene&screen session

Signed-off-by: chyyy0213 <chenhaiying3@huawei.com>
Change-Id: I97526be72b07668f8bd46d2a9892a152a7e23d71
Signed-off-by: chyyy0213 <chenhaiying3@huawei.com>
This commit is contained in:
chyyy0213 2023-05-05 15:17:39 +08:00
parent 99d44e27d9
commit 6393b414bc
31 changed files with 810 additions and 133 deletions

View File

@ -68,6 +68,7 @@ ohos_shared_library("libdms") {
"ipc:ipc_single",
"safwk:system_ability_fwk",
"sensor:sensor_interface_native",
"window_manager:libwsutils",
]
if (defined(use_new_skia) && use_new_skia) {

View File

@ -19,6 +19,7 @@
#include <hitrace_meter.h>
#include <ipc_skeleton.h>
#include <iservice_registry.h>
#include "scene_board_judgement.h"
#include <system_ability_definition.h>
#include "display_manager_agent_controller.h"
@ -36,7 +37,8 @@ namespace {
const std::string SCREEN_CAPTURE_PERMISSION = "ohos.permission.CAPTURE_SCREEN";
}
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService)
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get<DisplayManagerService>());
const bool REGISTER_RESULT = SceneBoardJudgement::IsSceneBoardEnabled() ? false :
SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get<DisplayManagerService>());
#define CHECK_SCREEN_AND_RETURN(screenId, ret) \
do { \

View File

@ -133,6 +133,7 @@ ohos_shared_library("windowstage_kit") {
external_deps = [
"ability_runtime:runtime",
"ace_engine:ace_uicontent",
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"napi:ace_napi",

View File

@ -31,8 +31,9 @@ constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "JsWindo
} // namespace
std::unique_ptr<JsWindowRegisterManager> g_listenerManager = std::make_unique<JsWindowRegisterManager>();
JsWindowStage::JsWindowStage(const std::shared_ptr<Rosen::WindowScene>& windowScene)
: windowScene_(windowScene)
JsWindowStage::JsWindowStage(const std::shared_ptr<Rosen::WindowScene>& windowScene,
const std::shared_ptr<Ace::NG::UIWindow>& uiWindow)
: windowScene_(windowScene), uiWindow_(uiWindow)
{
}
@ -129,11 +130,6 @@ NativeValue* JsWindowStage::OnSetUIContent(NativeEngine& engine, NativeCallbackI
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
return engine.CreateUndefined();
}
auto weakScene = windowScene_.lock();
if (weakScene == nullptr || weakScene->GetMainWindow() == nullptr) {
WLOGFE("[NAPI]WindowScene is null or window is null");
return engine.CreateUndefined();
}
// Parse info->argv[0] as abilitycontext
auto objContext = ConvertNativeValueTo<NativeObject>(info.argv[0]);
@ -148,6 +144,19 @@ NativeValue* JsWindowStage::OnSetUIContent(NativeEngine& engine, NativeCallbackI
WLOGFE("[NAPI]Failed to convert parameter to url");
return engine.CreateUndefined();
}
auto uiWindow = uiWindow_.lock();
if (uiWindow) {
uiWindow->LoadContent(contextUrl, &engine, nullptr);
uiWindow->Connect();
return engine.CreateUndefined();
}
auto weakScene = windowScene_.lock();
if (weakScene == nullptr || weakScene->GetMainWindow() == nullptr) {
WLOGFE("[NAPI]WindowScene is null or window is null");
return engine.CreateUndefined();
}
weakScene->GetMainWindow()->SetUIContent(contextUrl, &engine, info.argv[CONTENT_STORAGE_ARG]);
return engine.CreateUndefined();
}
@ -336,16 +345,16 @@ NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackIn
std::shared_ptr<NativeReference> contentStorage = (storage == nullptr) ? nullptr :
std::shared_ptr<NativeReference>(engine.CreateReference(storage, 1));
AsyncTask::CompleteCallback complete =
[weak = windowScene_, contentStorage, contextUrl, errCode](
[weak = windowScene_, contentStorage, contextUrl, weakUIWindow = uiWindow_](
NativeEngine& engine, AsyncTask& task, int32_t status) {
auto weakScene = weak.lock();
if (weakScene == nullptr) {
WLOGFE("[NAPI]Window scene is null");
task.Reject(engine, CreateJsError(engine,
static_cast<int32_t>(WmErrorCode::WM_ERROR_STAGE_ABNORMALLY)));
if (auto uiWindow = weakUIWindow.lock()) {
NativeValue* nativeStorage = contentStorage ? contentStorage->Get() : nullptr;
uiWindow->LoadContent(contextUrl, &engine, nativeStorage);
task.Resolve(engine, engine.CreateUndefined());
return;
}
auto win = weakScene->GetMainWindow();
auto weakScene = weak.lock();
sptr<Window> win = weakScene ? weakScene->GetMainWindow() : nullptr;
if (win == nullptr) {
task.Reject(engine, CreateJsError(engine,
static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
@ -545,13 +554,13 @@ NativeValue* JsWindowStage::OnDisableWindowDecor(NativeEngine& engine, NativeCal
}
NativeValue* CreateJsWindowStage(NativeEngine& engine,
std::shared_ptr<Rosen::WindowScene> windowScene)
std::shared_ptr<Rosen::WindowScene> windowScene, std::shared_ptr<Ace::NG::UIWindow> uiWindow)
{
WLOGFD("[NAPI]CreateJsWindowStage");
NativeValue* objValue = engine.CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
std::unique_ptr<JsWindowStage> jsWindowStage = std::make_unique<JsWindowStage>(windowScene);
std::unique_ptr<JsWindowStage> jsWindowStage = std::make_unique<JsWindowStage>(windowScene, uiWindow);
object->SetNativePointer(jsWindowStage.release(), JsWindowStage::Finalizer, nullptr);
const char *moduleName = "JsWindowStage";

View File

@ -21,12 +21,15 @@
#include "native_engine/native_reference.h"
#include "native_engine/native_value.h"
#include "window_scene.h"
#include "ui_window.h"
namespace OHOS {
namespace Rosen {
NativeValue* CreateJsWindowStage(NativeEngine& engine, std::shared_ptr<Rosen::WindowScene> windowScene);
NativeValue* CreateJsWindowStage(NativeEngine& engine, std::shared_ptr<Rosen::WindowScene> windowScene,
std::shared_ptr<Ace::NG::UIWindow> uiWindow = nullptr);
class JsWindowStage {
public:
explicit JsWindowStage(const std::shared_ptr<Rosen::WindowScene>& windowScene);
explicit JsWindowStage(const std::shared_ptr<Rosen::WindowScene>& windowScene,
const std::shared_ptr<Ace::NG::UIWindow>& uiWindow);
~JsWindowStage();
static void Finalizer(NativeEngine* engine, void* data, void* hint);
static NativeValue* SetUIContent(NativeEngine* engine, NativeCallbackInfo* info);
@ -55,6 +58,7 @@ private:
NativeValue* OnDisableWindowDecor(NativeEngine& engine, NativeCallbackInfo& info);
std::weak_ptr<Rosen::WindowScene> windowScene_;
std::weak_ptr<Ace::NG::UIWindow> uiWindow_;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -0,0 +1,64 @@
/*
* 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_ACE_INTERFACE_INNER_API_UI_WINDOW_H
#define FOUNDATION_ACE_INTERFACE_INNER_API_UI_WINDOW_H
#include <refbase.h>
#include "ui_content.h"
namespace OHOS::Rosen {
class RSSurfaceNode;
class ISession;
class ISessionStageStateListener;
}
namespace OHOS::Ace::NG {
class ACE_EXPORT UIWindow {
public:
static std::shared_ptr<UIWindow> CreateRootScene() {
return nullptr;
};
static std::shared_ptr<UIWindow> CreateWindowScene(const std::shared_ptr<AbilityRuntime::Context>& context,
const sptr<Rosen::ISession>& iSession, const std::shared_ptr<Rosen::RSSurfaceNode>& surfaceNode) {
return nullptr;
};
static std::shared_ptr<UIWindow> CreateWindowExtension(const std::shared_ptr<AbilityRuntime::Context>& context,
const sptr<Rosen::ISession>& iSession, const std::shared_ptr<Rosen::RSSurfaceNode>& surfaceNode) {
return nullptr;
};
virtual ~UIWindow() = default;
virtual void LoadContent(const std::string& contentUrl, NativeEngine* engine, NativeValue* storage,
AbilityRuntime::Context* context = nullptr) = 0;
// for lifecycle
virtual void RegisterSessionStageStateListener(
const std::shared_ptr<Rosen::ISessionStageStateListener>& listener) = 0;
virtual void Connect() = 0;
virtual void Foreground() = 0;
virtual void Background() = 0;
virtual void Disconnect() = 0;
};
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_INTERFACE_INNER_API_UI_WINDOW_H

View File

@ -13,7 +13,8 @@
import("//build/ohos.gni")
import("//foundation/window/window_manager/windowmanager_aafwk.gni")
config("libwscommon_public_config") {
config("window_scene_common_public_config") {
include_dirs = [
"${window_base_path}/window_scene",
@ -26,12 +27,13 @@ config("libwscommon_public_config") {
ohos_shared_library("window_scene_common") {
sources = [ "src/message_scheduler.cpp" ]
public_configs = [ ":libwscommon_public_config" ]
public_configs = [ ":window_scene_common_public_config" ]
external_deps = [
"eventhandler:libeventhandler",
"hilog_native:libhilog",
]
part_name = "window_manager"
subsystem_name = "window"
}

View File

@ -26,6 +26,7 @@ config("session_public_config") {
ohos_shared_library("scene_session") {
sources = [
"container/src/extension_session_stage.cpp",
"container/src/scene_session_stage.cpp",
"container/src/session_stage.cpp",
"container/src/window_event_channel.cpp",
"container/src/zidl/session_stage_proxy.cpp",
@ -33,24 +34,42 @@ ohos_shared_library("scene_session") {
"container/src/zidl/window_event_channel_proxy.cpp",
"container/src/zidl/window_event_channel_stub.cpp",
"host/src/extension_session.cpp",
"host/src/root_scene_session.cpp",
"host/src/scene_session.cpp",
"host/src/session.cpp",
"host/src/zidl/session_proxy.cpp",
"host/src/zidl/session_stub.cpp",
]
cflags_cc = [ "-std=c++17" ]
public_configs = [ ":session_public_config" ]
deps = [ "${graphic_base_path}/graphic_2d/rosen/modules/render_service_client:librender_service_client" ]
public_deps =
[ "${window_base_path}/window_scene/interfaces/innerkits:libwsutils" ]
external_deps = [
"c_utils:utils",
"hilog_native:libhilog",
"input:libmmi-client",
"ipc:ipc_single",
"multimedia_image_framework:image_native",
]
part_name = "window_manager"
subsystem_name = "window"
}
ohos_shared_library("screen_session") {
sources = [
"screen/src/screen_property.cpp",
"screen/src/screen_session.cpp",
]
public_configs = [ ":session_public_config" ]
deps = [ "${graphic_base_path}/graphic_2d/rosen/modules/render_service_client:librender_service_client" ]
part_name = "window_manager"
subsystem_name = "window"
}

View File

@ -0,0 +1,34 @@
/*
* 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 OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_STAGE_H
#define OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_STAGE_H
#include "interfaces/include/ws_common.h"
#include "session/container/include/session_stage.h"
namespace OHOS::Rosen {
class SceneSessionStage : public SessionStage {
public:
SceneSessionStage(const sptr<ISession>& sceneSession);
~SceneSessionStage() = default;
WSError Connect() override;
WSError Recover() override;
WSError Maximize() override;
};
} // namespace OHOS::Rosen
#endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_STAGE_H

View File

@ -18,7 +18,6 @@
#include <memory>
#include <mutex>
#include <refbase.h>
#include <vector>
#include "interfaces/include/ws_common.h"
@ -35,25 +34,22 @@ class AxisEvent;
namespace OHOS::Rosen {
class ISessionStageStateListener {
public:
virtual void AfterForeground() {};
virtual void AfterBackground() {};
virtual void AfterActive() {};
virtual void AfterInactive() {};
virtual void AfterForeground() = 0;
virtual void AfterBackground() = 0;
virtual void AfterActive() = 0;
virtual void AfterInactive() = 0;
};
class ISizeChangeListener {
public:
virtual void OnSizeChange(WSRect rect, SizeChangeReason reason) = 0;
virtual void OnSizeChange(const WSRect& rect, SizeChangeReason reason) = 0;
};
class IPointerEventListener {
class IInputEventListener {
public:
virtual void OnPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) = 0;
};
class IKeyEventListener {
public:
virtual void OnKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) = 0;
virtual void OnAxisEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent) = 0;
};
class SessionStage : public SessionStageStub, public virtual RefBase {
@ -66,6 +62,15 @@ class SessionStage : public SessionStageStub, public virtual RefBase {
} \
} while (0)
#define CALL_INPUT_EVENT_LISTENER(listeners, inputCb, event) \
do { \
for (auto& listener : (listeners)) { \
if (!listener.expired()) { \
listener.lock()->inputCb(event); \
} \
} \
} while (0)
public:
explicit SessionStage(const sptr<ISession>& session);
virtual ~SessionStage() = default;
@ -79,26 +84,47 @@ public:
virtual WSError Recover();
virtual WSError Maximize();
// IPC
WSError SetActive(bool active) override;
WSError UpdateRect(const WSRect& rect, SizeChangeReason reason) override;
bool RegisterSessionStageStateListener(const std::shared_ptr<ISessionStageStateListener>& listener);
bool UnregisterSessionStageStateListener(const std::shared_ptr<ISessionStageStateListener>& listener);
bool RegisterSizeChangeListener(const std::shared_ptr<ISizeChangeListener>& listener);
bool UnregisterSizeChangeListener(const std::shared_ptr<ISizeChangeListener>& listener);
bool RegisterPointerEventListener(const std::shared_ptr<IPointerEventListener>& listener);
bool UnregisterPointerEventListener(const std::shared_ptr<IPointerEventListener>& listener);
bool RegisterKeyEventListener(const std::shared_ptr<IKeyEventListener>& listener);
bool UnregisterKeyEventListener(const std::shared_ptr<IKeyEventListener>& listener);
bool RegisterInputEventListener(const std::shared_ptr<IInputEventListener>& listener);
bool UnregisterInputEventListener(const std::shared_ptr<IInputEventListener>& listener);
// for window event
void NotifyPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
void NotifyKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
inline void NotifyPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
{
auto listeners = GetListeners<IInputEventListener>();
CALL_INPUT_EVENT_LISTENER(listeners, OnPointerEvent, pointerEvent);
}
inline void NotifyKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
{
auto listeners = GetListeners<IInputEventListener>();
CALL_INPUT_EVENT_LISTENER(listeners, OnKeyEvent, keyEvent);
}
inline void NotifyAxisEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent)
{
auto listeners = GetListeners<IInputEventListener>();
CALL_INPUT_EVENT_LISTENER(listeners, OnAxisEvent, axisEvent);
}
protected:
void NotifySizeChange(const WSRect& rect, SizeChangeReason reason);
void NotifySizeChange(const WSRect& rect, SizeChangeReason reason)
{
auto sizeChangeListeners = GetListeners<ISizeChangeListener>();
for (auto& listener : sizeChangeListeners) {
if (!listener.expired()) {
listener.lock()->OnSizeChange(rect, reason);
}
}
}
inline void NotifyAfterForeground()
{
auto sessionStateListeners = GetListeners<ISessionStageStateListener>();
@ -133,6 +159,7 @@ private:
template<typename T1, typename T2, typename Ret>
using EnableIfSame = typename std::enable_if<std::is_same_v<T1, T2>, Ret>::type;
template<typename T>
inline EnableIfSame<T, ISessionStageStateListener, std::vector<std::weak_ptr<ISessionStageStateListener>>>
GetListeners()
@ -161,36 +188,23 @@ private:
}
template<typename T>
inline EnableIfSame<T, IPointerEventListener, std::vector<std::weak_ptr<IPointerEventListener>>> GetListeners()
inline EnableIfSame<T, IInputEventListener, std::vector<std::weak_ptr<IInputEventListener>>> GetListeners()
{
std::vector<std::weak_ptr<IPointerEventListener>> pointerEventListeners;
std::vector<std::weak_ptr<IInputEventListener>> inputEventListeners;
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (auto& listener : pointerEventListeners_) {
pointerEventListeners.push_back(listener);
for (auto& listener : inputEventListeners_) {
inputEventListeners.push_back(listener);
}
}
return pointerEventListeners;
}
template<typename T>
inline EnableIfSame<T, IKeyEventListener, std::vector<std::weak_ptr<IKeyEventListener>>> GetListeners()
{
std::vector<std::weak_ptr<IKeyEventListener>> keyEventListeners;
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (auto& listener : keyEventListeners_) {
keyEventListeners.push_back(listener);
}
}
return keyEventListeners;
return inputEventListeners;
}
std::recursive_mutex mutex_;
std::vector<std::shared_ptr<IPointerEventListener>> pointerEventListeners_;
std::vector<std::shared_ptr<IKeyEventListener>> keyEventListeners_;
std::vector<std::shared_ptr<ISessionStageStateListener>> sessionStageStateListeners_;
std::vector<std::shared_ptr<ISizeChangeListener>> sizeChangeListeners_;
std::vector<std::shared_ptr<IInputEventListener>> inputEventListeners_;
};
} // namespace OHOS::Rosen
#endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_STAGE_H

View File

@ -19,7 +19,7 @@
#include "window_manager_hilog.h"
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "ExtensionSessionStage" };
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "ExtensionSessionStage" };
}
ExtensionSessionStage::ExtensionSessionStage(const sptr<ISession>& extensionSession) : SessionStage(extensionSession) {}

View File

@ -0,0 +1,55 @@
/*
* 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 "session/container/include/scene_session_stage.h"
#include "session/container/include/window_event_channel.h"
#include "window_manager_hilog.h"
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSessionStage" };
}
SceneSessionStage::SceneSessionStage(const sptr<ISession>& sceneSession) : SessionStage(sceneSession) {}
WSError SceneSessionStage::Connect()
{
if (session_ == nullptr) {
WLOGFE("session is invalid");
return WSError::WS_ERROR_NULLPTR;
}
sptr<SceneSessionStage> sceneSessionStage(this);
sptr<IWindowEventChannel> eventChannel(new WindowEventChannel(sceneSessionStage));
return session_->Connect(sceneSessionStage, eventChannel);
}
WSError SceneSessionStage::Recover()
{
if (session_ == nullptr) {
WLOGFE("sceneSession is invalid");
return WSError::WS_ERROR_NULLPTR;
}
return session_->Recover();
}
WSError SceneSessionStage::Maximize()
{
if (session_ == nullptr) {
WLOGFE("sceneSession is invalid");
return WSError::WS_ERROR_NULLPTR;
}
return session_->Maximize();
}
} // namespace OHOS::Rosen

View File

@ -20,8 +20,9 @@
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStage"};
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStage" };
}
SessionStage::SessionStage(const sptr<ISession>& session) : session_(session) {}
bool SessionStage::RegisterSessionStageStateListener(const std::shared_ptr<ISessionStageStateListener>& listener)
@ -44,24 +45,14 @@ bool SessionStage::UnregisterSizeChangeListener(const std::shared_ptr<ISizeChang
return UnregisterListenerLocked(sizeChangeListeners_, listener);
}
bool SessionStage::RegisterPointerEventListener(const std::shared_ptr<IPointerEventListener>& listener)
bool SessionStage::RegisterInputEventListener(const std::shared_ptr<IInputEventListener>& listener)
{
return RegisterListenerLocked(pointerEventListeners_, listener);
return RegisterListenerLocked(inputEventListeners_, listener);
}
bool SessionStage::UnregisterPointerEventListener(const std::shared_ptr<IPointerEventListener>& listener)
bool SessionStage::UnregisterInputEventListener(const std::shared_ptr<IInputEventListener>& listener)
{
return UnregisterListenerLocked(pointerEventListeners_, listener);
}
bool SessionStage::RegisterKeyEventListener(const std::shared_ptr<IKeyEventListener>& listener)
{
return RegisterListenerLocked(keyEventListeners_, listener);
}
bool SessionStage::UnregisterKeyEventListener(const std::shared_ptr<IKeyEventListener>& listener)
{
return UnregisterListenerLocked(keyEventListeners_, listener);
return UnregisterListenerLocked(inputEventListeners_, listener);
}
template<typename T>
@ -74,7 +65,7 @@ bool SessionStage::RegisterListenerLocked(std::vector<std::shared_ptr<T>>& holde
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (std::find(holder.begin(), holder.end(), listener) != holder.end()) {
WLOGFW("Listener already registered");
return true;
return false;
}
holder.emplace_back(listener);
return true;
@ -94,36 +85,6 @@ bool SessionStage::UnregisterListenerLocked(std::vector<std::shared_ptr<T>>& hol
return true;
}
void SessionStage::NotifySizeChange(const WSRect& rect, SizeChangeReason reason)
{
auto sizeChangeListeners = GetListeners<ISizeChangeListener>();
for (auto& listener : sizeChangeListeners) {
if (!listener.expired()) {
listener.lock()->OnSizeChange(rect, reason);
}
}
}
void SessionStage::NotifyPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
{
auto pointerEventListeners = GetListeners<IPointerEventListener>();
for (auto& listener : pointerEventListeners) {
if (!listener.expired()) {
listener.lock()->OnPointerEvent(pointerEvent);
}
}
}
void SessionStage::NotifyKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
{
auto keyEventListeners = GetListeners<IKeyEventListener>();
for (auto& listener : keyEventListeners) {
if (!listener.expired()) {
listener.lock()->OnKeyEvent(keyEvent);
}
}
}
WSError SessionStage::Connect()
{
if (session_ == nullptr) {

View File

@ -23,7 +23,7 @@
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStageProxy"};
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStageProxy"};
}
WSError SessionStageProxy::SetActive(bool active)

View File

@ -21,7 +21,7 @@
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStageStub"};
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStageStub"};
}
const std::map<uint32_t, SessionStageStubFunc> SessionStageStub::stubFuncMap_{

View File

@ -26,7 +26,7 @@
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventChannelProxy"};
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventChannelProxy"};
}
WSError WindowEventChannelProxy::TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent)

View File

@ -24,7 +24,7 @@
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventChannelStub"};
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventChannelStub"};
}
const std::map<uint32_t, WindowEventChannelStubFunc> WindowEventChannelStub::stubFuncMap_{

View File

@ -0,0 +1,48 @@
/*
* 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 OHOS_ROSEN_WINDOW_SCENE_ROOT_SCENE_SESSION_H
#define OHOS_ROSEN_WINDOW_SCENE_ROOT_SCENE_SESSION_H
#include "interfaces/include/ws_common.h"
#include "scene_session.h"
namespace OHOS::AbilityRuntime {
class Context;
}
class NativeEngine;
class NativeValue;
namespace OHOS::Rosen {
class RootSceneSession : public RefBase {
public:
using LoadContentFunc =
std::function<void(const std::string&, NativeEngine*, NativeValue*, AbilityRuntime::Context*)>;
RootSceneSession() = default;
~RootSceneSession() = default;
void SetPendingSessionActivationEventListener(const NotifyPendingSessionActivationFunc& func);
void SetLoadContentFunc(const LoadContentFunc& loadContentFunc);
void LoadContent(
const std::string& contentUrl, NativeEngine* engine, NativeValue* storage, AbilityRuntime::Context* context);
private:
LoadContentFunc loadContentFunc_;
NotifyPendingSessionActivationFunc pendingSessionActivationFunc_;
};
} // namespace OHOS::Rosen
#endif // OHOS_ROSEN_WINDOW_SCENE_ROOT_SCENE_SESSION_H

View File

@ -0,0 +1,33 @@
/*
* 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 OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H
#define OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H
#include "interfaces/include/ws_common.h"
#include "session/host/include/session.h"
namespace OHOS::Rosen {
class SceneSession : public Session {
public:
SceneSession(const SessionInfo& info);
~SceneSession() = default;
WSError Recover() override;
WSError Maximize() override;
};
} // namespace OHOS::Rosen
#endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H

View File

@ -31,15 +31,20 @@ class KeyEvent;
class AxisEvent;
} // namespace OHOS::MMI
namespace OHOS::Media {
class PixelMap;
}
namespace OHOS::Rosen {
class RSSurfaceNode;
using NotifyPendingSessionActivationFunc = std::function<void(const SessionInfo& info)>;
class ILifecycleListener {
public:
virtual void OnForeground() {};
virtual void OnBackground() {};
virtual void OnForeground() = 0;
virtual void OnBackground() = 0;
};
class Session : public SessionStub, public virtual RefBase {
public:
explicit Session(const SessionInfo& info);
@ -47,13 +52,15 @@ public:
void SetPersistentId(uint64_t persistentId);
uint64_t GetPersistentId() const;
std::shared_ptr<RSSurfaceNode> GetSurfaceNode() const;
std::shared_ptr<Media::PixelMap> GetSnapshot() const;
SessionState GetSessionState() const;
virtual WSError SetActive(bool active);
virtual WSError UpdateRect(const WSRect& rect, SizeChangeReason reason);
WSError Connect(
const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel) override;
WSError Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel) override;
WSError Foreground() override;
WSError Background() override;
WSError Disconnect() override;
@ -62,15 +69,19 @@ public:
WSError Recover() override;
WSError Maximize() override;
// for window event
virtual void NotifyForeground();
virtual void NotifyBackground();
WSError TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
WSError TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
bool RegisterLifecycleListener(const std::shared_ptr<ILifecycleListener>& listener);
bool UnregisterLifecycleListener(const std::shared_ptr<ILifecycleListener>& listener);
const SessionInfo& GetSessionInfo() const;
void SetPendingSessionActivationEventListener(const NotifyPendingSessionActivationFunc& func);
protected:
SessionState GetSessionState() const;
void UpdateSessionState(SessionState state);
bool IsSessionValid() const;
bool isActive_ = false;
@ -80,13 +91,38 @@ protected:
NotifyPendingSessionActivationFunc pendingSessionActivationFunc_;
private:
template<typename T>
bool RegisterListenerLocked(std::vector<std::shared_ptr<T>>& holder, const std::shared_ptr<T>& listener);
template<typename T>
bool UnregisterListenerLocked(std::vector<std::shared_ptr<T>>& holder, const std::shared_ptr<T>& listener);
template<typename T1, typename T2, typename Ret>
using EnableIfSame = typename std::enable_if<std::is_same_v<T1, T2>, Ret>::type;
template<typename T>
inline EnableIfSame<T, ILifecycleListener, std::vector<std::weak_ptr<ILifecycleListener>>> GetListeners()
{
std::vector<std::weak_ptr<ILifecycleListener>> lifecycleListeners;
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (auto& listener : lifecycleListeners_) {
lifecycleListeners.push_back(listener);
}
}
return lifecycleListeners;
}
std::shared_ptr<RSSurfaceNode> CreateSurfaceNode(std::string name);
std::shared_ptr<Media::PixelMap> Snapshot();
uint64_t persistentId_ = INVALID_SESSION_ID;
std::shared_ptr<RSSurfaceNode> surfaceNode_ = nullptr;
SessionState state_ = SessionState::STATE_DISCONNECT;
std::recursive_mutex mutex_;
std::vector<std::shared_ptr<ILifecycleListener>> lifecycleListeners_;
sptr<IWindowEventChannel> windowEventChannel_ = nullptr;
std::shared_ptr<Media::PixelMap> snapshot_;
};
} // namespace OHOS::Rosen
#endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_H

View File

@ -17,6 +17,7 @@
#define OHOS_ROSEN_WINDOW_SCENE_SESSION_INTERFACE_H
#include <iremote_broker.h>
#include "interfaces/include/ws_common.h"
#include "session/container/include/zidl/session_stage_interface.h"
#include "session/container/include/zidl/window_event_channel_interface.h"

View File

@ -0,0 +1,36 @@
/*
* 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 "session/host/include/root_scene_session.h"
namespace OHOS::Rosen {
void RootSceneSession::SetPendingSessionActivationEventListener(const NotifyPendingSessionActivationFunc& func)
{
pendingSessionActivationFunc_ = func;
}
void RootSceneSession::SetLoadContentFunc(const LoadContentFunc& loadContentFunc)
{
loadContentFunc_ = loadContentFunc;
}
void RootSceneSession::LoadContent(
const std::string& contentUrl, NativeEngine* engine, NativeValue* storage, AbilityRuntime::Context* context)
{
if (loadContentFunc_) {
loadContentFunc_(contentUrl, engine, storage, context);
}
}
} // namespace OHOS::Rosen

View File

@ -0,0 +1,45 @@
/*
* 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 "session/host/include/scene_session.h"
#include "window_manager_hilog.h"
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSession" };
}
SceneSession::SceneSession(const SessionInfo& info) : Session(info) {}
WSError SceneSession::Recover()
{
WLOGFI("Recover session, id: %{public}" PRIu64 ", state: %{public}u", GetPersistentId(),
static_cast<uint32_t>(GetSessionState()));
if (!IsSessionValid()) {
return WSError::WS_ERROR_INVALID_SESSION;
}
return WSError::WS_OK;
}
WSError SceneSession::Maximize()
{
WLOGFI("Maximum session id: %{public}" PRIu64 " state: %{public}u", GetPersistentId(),
static_cast<uint32_t>(GetSessionState()));
if (!IsSessionValid()) {
return WSError::WS_ERROR_INVALID_SESSION;
}
return WSError::WS_OK;
}
} // namespace OHOS::Rosen

View File

@ -15,8 +15,9 @@
#include "session/host/include/session.h"
#include "surface_capture_future.h"
#include <transaction/rs_interfaces.h>
#include <ui/rs_surface_node.h>
#include "window_manager_hilog.h"
namespace OHOS::Rosen {
@ -53,6 +54,66 @@ const SessionInfo& Session::GetSessionInfo() const
return sessionInfo_;
}
bool Session::RegisterLifecycleListener(const std::shared_ptr<ILifecycleListener>& listener)
{
return RegisterListenerLocked(lifecycleListeners_, listener);
}
bool Session::UnregisterLifecycleListener(const std::shared_ptr<ILifecycleListener>& listener)
{
return UnregisterListenerLocked(lifecycleListeners_, listener);
}
template<typename T>
bool Session::RegisterListenerLocked(std::vector<std::shared_ptr<T>>& holder, const std::shared_ptr<T>& listener)
{
if (listener == nullptr) {
WLOGFE("listener is nullptr");
return false;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (std::find(holder.begin(), holder.end(), listener) != holder.end()) {
WLOGFE("Listener already registered");
return false;
}
holder.emplace_back(listener);
return true;
}
template<typename T>
bool Session::UnregisterListenerLocked(std::vector<std::shared_ptr<T>>& holder, const std::shared_ptr<T>& listener)
{
if (listener == nullptr) {
WLOGFE("listener could not be null");
return false;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
holder.erase(std::remove_if(holder.begin(), holder.end(),
[listener](std::shared_ptr<T> registeredListener) { return registeredListener == listener; }),
holder.end());
return true;
}
void Session::NotifyForeground()
{
auto lifecycleListeners = GetListeners<ILifecycleListener>();
for (auto& listener : lifecycleListeners) {
if (!listener.expired()) {
listener.lock()->OnForeground();
}
}
}
void Session::NotifyBackground()
{
auto lifecycleListeners = GetListeners<ILifecycleListener>();
for (auto& listener : lifecycleListeners) {
if (!listener.expired()) {
listener.lock()->OnBackground();
}
}
}
SessionState Session::GetSessionState() const
{
return state_;
@ -86,7 +147,7 @@ RSSurfaceNode::SharedPtr Session::CreateSurfaceNode(std::string name)
}
struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
rsSurfaceNodeConfig.SurfaceNodeName = name;
return RSSurfaceNode::Create(rsSurfaceNodeConfig, RSSurfaceNodeType::EXTENSION_ABILITY_NODE);
return RSSurfaceNode::Create(rsSurfaceNodeConfig);
}
WSError Session::UpdateRect(const WSRect& rect, SizeChangeReason reason)
@ -98,7 +159,6 @@ WSError Session::UpdateRect(const WSRect& rect, SizeChangeReason reason)
return WSError::WS_ERROR_INVALID_SESSION;
}
sessionStage_->UpdateRect(rect, reason);
winRect_ = rect;
return WSError::WS_OK;
}
@ -133,12 +193,11 @@ WSError Session::Foreground()
return WSError::WS_ERROR_INVALID_SESSION;
}
UpdateSessionState(SessionState::STATE_FOREGROUND);
if (!isActive_) {
SetActive(true);
UpdateSessionState(SessionState::STATE_ACTIVE);
} else {
UpdateSessionState(SessionState::STATE_FOREGROUND);
}
NotifyForeground();
return WSError::WS_OK;
}
@ -152,6 +211,9 @@ WSError Session::Background()
return WSError::WS_ERROR_INVALID_SESSION;
}
UpdateSessionState(SessionState::STATE_BACKGROUND);
snapshot_ = Snapshot();
NotifyBackground();
return WSError::WS_OK;
}
@ -215,7 +277,6 @@ WSError Session::Maximize()
return WSError::WS_OK;
}
// for window event
WSError Session::TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
{
WLOGFD("Session TransferPointEvent");
@ -223,18 +284,34 @@ WSError Session::TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>&
WLOGFE("windowEventChannel_ is null");
return WSError::WS_ERROR_NULLPTR;
}
windowEventChannel_->TransferPointerEvent(pointerEvent);
return WSError::WS_OK;
return windowEventChannel_->TransferPointerEvent(pointerEvent);
}
WSError Session::TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
{
WLOGFD("Session TransferPointEvent");
WLOGFD("Session TransferKeyEvent");
if (!windowEventChannel_) {
WLOGFE("windowEventChannel_ is null");
return WSError::WS_ERROR_NULLPTR;
}
windowEventChannel_->TransferKeyEvent(keyEvent);
return WSError::WS_OK;
return windowEventChannel_->TransferKeyEvent(keyEvent);
}
std::shared_ptr<Media::PixelMap> Session::GetSnapshot() const
{
return snapshot_;
}
std::shared_ptr<Media::PixelMap> Session::Snapshot()
{
auto callback = std::make_shared<SurfaceCaptureFuture>();
RSInterfaces::GetInstance().TakeSurfaceCapture(surfaceNode_, callback);
auto pixelMap = callback->GetResult(2000); // wait for <= 2000ms
if (pixelMap != nullptr) {
WLOGFD("Save pixelMap WxH = %{public}dx%{public}d", pixelMap->GetWidth(), pixelMap->GetHeight());
} else {
WLOGFE("Failed to get pixelMap, return nullptr");
}
return pixelMap;
}
} // namespace OHOS::Rosen

View File

@ -0,0 +1,39 @@
/*
* 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 OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H
#define OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H
#include "common/rs_rect.h"
namespace OHOS::Rosen {
class ScreenProperty {
public:
ScreenProperty() = default;
~ScreenProperty() = default;
void SetRotation(float rotation);
float GetRotation() const;
void SetBounds(const RRect& bounds);
RRect GetBounds() const;
private:
float rotation_ { 0.0f };
RRect bounds_;
};
} // namespace OHOS::Rosen
#endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H

View File

@ -0,0 +1,64 @@
/*
* 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 OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_H
#define OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_H
#include <refbase.h>
#include <screen_manager/screen_types.h>
#include <vector>
#include "screen_property.h"
namespace OHOS::Rosen {
class IScreenChangeListener : public RefBase {
public:
IScreenChangeListener() = default;
virtual ~IScreenChangeListener() = default;
virtual void OnConnect() = 0;
virtual void OnDisconnect() = 0;
virtual void OnPropertyChange(const ScreenProperty& newProperty) = 0;
};
enum class ScreenState : int32_t {
INIT,
CONNECTION,
DISCONNECTION,
};
class ScreenSession : public RefBase {
public:
explicit ScreenSession(ScreenId screenId, const ScreenProperty& property);
~ScreenSession() = default;
void RegisterScreenChangeListener(IScreenChangeListener* screenChangeListener);
void UnregisterScreenChangeListener(IScreenChangeListener* screenChangeListener);
ScreenId GetScreenId();
ScreenProperty GetScreenProperty() const;
void Connect();
void Disconnect();
private:
ScreenId screenId_;
ScreenProperty property_;
ScreenState screenState_ { ScreenState::INIT };
std::vector<IScreenChangeListener*> screenChangeListenerList_;
};
} // namespace OHOS::Rosen
#endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_H

View File

@ -0,0 +1,38 @@
/*
* 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 "session/screen/include/screen_property.h"
namespace OHOS::Rosen {
void ScreenProperty::SetRotation(float rotation)
{
rotation_ = rotation;
}
float ScreenProperty::GetRotation() const
{
return rotation_;
}
void ScreenProperty::SetBounds(const RRect& bounds)
{
bounds_ = bounds;
}
RRect ScreenProperty::GetBounds() const
{
return bounds_;
}
} // namespace OHOS::Rosen

View File

@ -0,0 +1,87 @@
/*
* 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 "session/screen/include/screen_session.h"
#include "window_manager_hilog.h"
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "ScreenSession" };
}
ScreenSession::ScreenSession(ScreenId screenId, const ScreenProperty& property)
: screenId_(screenId), property_(property)
{}
void ScreenSession::RegisterScreenChangeListener(IScreenChangeListener* screenChangeListener)
{
if (screenChangeListener == nullptr) {
WLOGFE("Failed to register screen change listener, listener is null!");
return;
}
if (std::find(screenChangeListenerList_.begin(), screenChangeListenerList_.end(), screenChangeListener) !=
screenChangeListenerList_.end()) {
WLOGFE("Repeat to register screen change listener!");
return;
}
screenChangeListenerList_.emplace_back(screenChangeListener);
if (screenState_ == ScreenState::CONNECTION) {
screenChangeListener->OnConnect();
}
}
void ScreenSession::UnregisterScreenChangeListener(IScreenChangeListener* screenChangeListener)
{
if (screenChangeListener == nullptr) {
WLOGFE("Failed to unregister screen change listener, listener is null!");
return;
}
screenChangeListenerList_.erase(
std::remove_if(screenChangeListenerList_.begin(), screenChangeListenerList_.end(),
[screenChangeListener](IScreenChangeListener* listener) { return screenChangeListener == listener; }),
screenChangeListenerList_.end());
}
ScreenId ScreenSession::GetScreenId()
{
return screenId_;
}
ScreenProperty ScreenSession::GetScreenProperty() const
{
return property_;
}
void ScreenSession::Connect()
{
screenState_ = ScreenState::CONNECTION;
for (auto& listener : screenChangeListenerList_) {
listener->OnConnect();
}
}
void ScreenSession::Disconnect()
{
screenState_ = ScreenState::DISCONNECTION;
for (auto& listener : screenChangeListenerList_) {
listener->OnDisconnect();
}
}
} // namespace OHOS::Rosen

View File

@ -16,6 +16,8 @@
#ifndef OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_BASE_H
#define OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_BASE_H
#include <unistd.h>
#include "common/include/message_scheduler.h"
#include "interfaces/include/ws_common.h"
namespace OHOS::Rosen {

View File

@ -12,6 +12,8 @@
# limitations under the License.
import("//build/ohos.gni")
import("//foundation/window/window_manager/windowmanager_aafwk.gni")
config("libwms_config") {
visibility = [ ":*" ]
@ -109,6 +111,7 @@ ohos_shared_library("libwms") {
"ipc:ipc_single",
"power_manager:powermgr_client",
"safwk:system_ability_fwk",
"window_manager:libwsutils",
]
if (is_standard_system) {

View File

@ -25,6 +25,7 @@
#include <ipc_skeleton.h>
#include <parameters.h>
#include <rs_iwindow_animation_controller.h>
#include "scene_board_judgement.h"
#include <system_ability_definition.h>
#include <sstream>
#include "xcollie/watchdog.h"
@ -55,7 +56,8 @@ namespace {
}
WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerService)
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get<WindowManagerService>());
const bool REGISTER_RESULT = SceneBoardJudgement::IsSceneBoardEnabled() ? false :
SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get<WindowManagerService>());
WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true),
rsInterface_(RSInterfaces::GetInstance()),