merge master

Signed-off-by: hejunfei <hejunfei@huawei.com>
This commit is contained in:
hejunfei 2024-08-29 14:29:08 +08:00
commit 575e300344
505 changed files with 15917 additions and 6518 deletions

View File

@ -17,6 +17,7 @@
"SystemCapability.Window.SessionManager" "SystemCapability.Window.SessionManager"
], ],
"features": [ "features": [
"window_manager_use_sceneboard",
"window_manager_feature_coverage = false", "window_manager_feature_coverage = false",
"window_manager_dayu210_resource_config", "window_manager_dayu210_resource_config",
"window_manager_feature_subscribe_motion", "window_manager_feature_subscribe_motion",
@ -94,6 +95,7 @@
"fwk_group": [ "fwk_group": [
"//foundation/window/window_manager/interfaces/kits/js/declaration:window", "//foundation/window/window_manager/interfaces/kits/js/declaration:window",
"//foundation/window/window_manager/dm:libdm", "//foundation/window/window_manager/dm:libdm",
"//foundation/window/window_manager/dm:libdm_ndk",
"//foundation/window/window_manager/extension/extension_connection:libwindow_extension_client", "//foundation/window/window_manager/extension/extension_connection:libwindow_extension_client",
"//foundation/window/window_manager/extension/modal_system_ui_extension:libmodal_system_ui_extension_client", "//foundation/window/window_manager/extension/modal_system_ui_extension:libmodal_system_ui_extension_client",
"//foundation/window/window_manager/extension/window_extension:libwindow_extension", "//foundation/window/window_manager/extension/window_extension:libwindow_extension",

View File

@ -142,9 +142,46 @@ ohos_shared_library("libdm") {
innerapi_tags = [ "platformsdk" ] innerapi_tags = [ "platformsdk" ]
part_name = "window_manager" part_name = "window_manager"
subsystem_name = "window" subsystem_name = "window"
defines = []
if (build_variant == "user") {
defines += [ "IS_RELEASE_VERSION" ]
}
} }
group("test") { group("test") {
testonly = true testonly = true
deps = [ "test:test" ] deps = [ "test:test" ]
} }
## Build libdm_ndk.so
ohos_shared_library("libdm_ndk") {
branch_protector_ret = "pac_ret"
output_name = "libnative_display_manager"
output_extension = "so"
sanitize = {
cfi = true
cfi_cross_dso = true
cfi_vcall_icall_only = true
debug = false
}
include_dirs = [
"${window_base_path}/interfaces/kits/dmndk/dm",
"${window_base_path}/interfaces/inner_kits/dm",
]
sources = [ "src/oh_display_manager.cpp" ]
deps = [ ":libdm" ]
innerapi_tags = [ "ndk" ]
external_deps = [
"c_utils:utils",
"hilog:libhilog",
]
part_name = "window_manager"
subsystem_name = "window"
}

View File

@ -83,8 +83,10 @@ public:
virtual FoldStatus GetFoldStatus(); virtual FoldStatus GetFoldStatus();
virtual FoldDisplayMode GetFoldDisplayMode(); virtual FoldDisplayMode GetFoldDisplayMode();
virtual void SetFoldDisplayMode(const FoldDisplayMode); virtual void SetFoldDisplayMode(const FoldDisplayMode);
virtual DMError SetFoldDisplayModeFromJs(const FoldDisplayMode);
virtual void SetDisplayScale(ScreenId screenId, float scaleX, float scaleY, float pivotX, float pivotY); virtual void SetDisplayScale(ScreenId screenId, float scaleX, float scaleY, float pivotX, float pivotY);
virtual void SetFoldStatusLocked(bool locked); virtual void SetFoldStatusLocked(bool locked);
virtual DMError SetFoldStatusLockedFromJs(bool locked);
virtual sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion(); virtual sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion();
virtual void SetVirtualScreenBlackList(ScreenId screenId, std::vector<uint64_t>& windowIdList); virtual void SetVirtualScreenBlackList(ScreenId screenId, std::vector<uint64_t>& windowIdList);
virtual void DisablePowerOffRenderControl(ScreenId screenId); virtual void DisablePowerOffRenderControl(ScreenId screenId);
@ -114,9 +116,10 @@ public:
virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId); virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId);
virtual DMError GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos); virtual DMError GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos);
virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, ScreenId& screenGroupId); virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, ScreenId& screenGroupId);
virtual DMError MultiScreenModeSwitch(ScreenId mainScreenId, ScreenId secondaryScreenId, virtual DMError SetMultiScreenMode(ScreenId mainScreenId, ScreenId secondaryScreenId,
ScreenSourceMode secondaryScreenMode); MultiScreenMode screenMode);
virtual DMError MultiScreenRelativePosition(ExtendOption mainScreenOption, ExtendOption secondaryScreenOption); virtual DMError SetMultiScreenRelativePosition(MultiScreenPositionOptions mainScreenOptions,
MultiScreenPositionOptions secondScreenOption);
virtual DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint, ScreenId& screenGroupId); virtual DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint, ScreenId& screenGroupId);
virtual DMError StopMirror(const std::vector<ScreenId>& mirrorScreenIds); virtual DMError StopMirror(const std::vector<ScreenId>& mirrorScreenIds);
virtual DMError StopExpand(const std::vector<ScreenId>& expandScreenIds); virtual DMError StopExpand(const std::vector<ScreenId>& expandScreenIds);

View File

@ -27,7 +27,7 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "Display"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "Display"};
} }
class Display::Impl : public RefBase { class Display::Impl : public RefBase {
public: public:

View File

@ -29,13 +29,13 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManager"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManager"};
const static uint32_t MAX_RETRY_NUM = 6; const static uint32_t MAX_RETRY_NUM = 6;
const static uint32_t RETRY_WAIT_MS = 500; const static uint32_t RETRY_WAIT_MS = 500;
const static uint32_t MAX_DISPLAY_SIZE = 32; const static uint32_t MAX_DISPLAY_SIZE = 32;
const static uint32_t MAX_INTERVAL_US = 25000; const static uint32_t MAX_INTERVAL_US = 25000;
std::atomic<bool> g_dmIsDestroyed = false; std::atomic<bool> g_dmIsDestroyed = false;
std::mutex snapBypickerMutex; std::mutex snapBypickerMutex;
} }
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManager) WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManager)
@ -58,8 +58,10 @@ public:
FoldStatus GetFoldStatus(); FoldStatus GetFoldStatus();
FoldDisplayMode GetFoldDisplayMode(); FoldDisplayMode GetFoldDisplayMode();
void SetFoldDisplayMode(const FoldDisplayMode); void SetFoldDisplayMode(const FoldDisplayMode);
DMError SetFoldDisplayModeFromJs(const FoldDisplayMode);
void SetDisplayScale(ScreenId screenId, float scaleX, float scaleY, float pivotX, float pivotY); void SetDisplayScale(ScreenId screenId, float scaleX, float scaleY, float pivotX, float pivotY);
void SetFoldStatusLocked(bool locked); void SetFoldStatusLocked(bool locked);
DMError SetFoldStatusLockedFromJs(bool locked);
sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion(); sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion();
DMError RegisterDisplayListener(sptr<IDisplayListener> listener); DMError RegisterDisplayListener(sptr<IDisplayListener> listener);
DMError UnregisterDisplayListener(sptr<IDisplayListener> listener); DMError UnregisterDisplayListener(sptr<IDisplayListener> listener);
@ -848,6 +850,11 @@ void DisplayManager::SetFoldDisplayMode(const FoldDisplayMode mode)
pImpl_->SetFoldDisplayMode(mode); pImpl_->SetFoldDisplayMode(mode);
} }
DMError DisplayManager::SetFoldDisplayModeFromJs(const FoldDisplayMode mode)
{
return pImpl_->SetFoldDisplayModeFromJs(mode);
}
void DisplayManager::SetDisplayScale(ScreenId screenId, float scaleX, float scaleY, float pivotX, float pivotY) void DisplayManager::SetDisplayScale(ScreenId screenId, float scaleX, float scaleY, float pivotX, float pivotY)
{ {
pImpl_->SetDisplayScale(screenId, scaleX, scaleY, pivotX, pivotY); pImpl_->SetDisplayScale(screenId, scaleX, scaleY, pivotX, pivotY);
@ -864,16 +871,31 @@ void DisplayManager::Impl::SetFoldDisplayMode(const FoldDisplayMode mode)
SingletonContainer::Get<DisplayManagerAdapter>().SetFoldDisplayMode(mode); SingletonContainer::Get<DisplayManagerAdapter>().SetFoldDisplayMode(mode);
} }
DMError DisplayManager::Impl::SetFoldDisplayModeFromJs(const FoldDisplayMode mode)
{
return SingletonContainer::Get<DisplayManagerAdapter>().SetFoldDisplayModeFromJs(mode);
}
void DisplayManager::SetFoldStatusLocked(bool locked) void DisplayManager::SetFoldStatusLocked(bool locked)
{ {
pImpl_->SetFoldStatusLocked(locked); pImpl_->SetFoldStatusLocked(locked);
} }
DMError DisplayManager::SetFoldStatusLockedFromJs(bool locked)
{
return pImpl_->SetFoldStatusLockedFromJs(locked);
}
void DisplayManager::Impl::SetFoldStatusLocked(bool locked) void DisplayManager::Impl::SetFoldStatusLocked(bool locked)
{ {
SingletonContainer::Get<DisplayManagerAdapter>().SetFoldStatusLocked(locked); SingletonContainer::Get<DisplayManagerAdapter>().SetFoldStatusLocked(locked);
} }
DMError DisplayManager::Impl::SetFoldStatusLockedFromJs(bool locked)
{
return SingletonContainer::Get<DisplayManagerAdapter>().SetFoldStatusLockedFromJs(locked);
}
sptr<FoldCreaseRegion> DisplayManager::GetCurrentFoldCreaseRegion() sptr<FoldCreaseRegion> DisplayManager::GetCurrentFoldCreaseRegion()
{ {
return pImpl_->GetCurrentFoldCreaseRegion(); return pImpl_->GetCurrentFoldCreaseRegion();
@ -1475,6 +1497,8 @@ void DisplayManager::Impl::NotifyDisplayModeChanged(FoldDisplayMode displayMode)
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(mutex_);
displayModeListeners = displayModeListeners_; displayModeListeners = displayModeListeners_;
} }
auto displayInfo = SingletonContainer::Get<DisplayManagerAdapter>().GetDefaultDisplayInfo();
NotifyDisplayChange(displayInfo);
for (auto& listener : displayModeListeners) { for (auto& listener : displayModeListeners) {
listener->OnDisplayModeChanged(displayMode); listener->OnDisplayModeChanged(displayMode);
} }

View File

@ -28,7 +28,7 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAdapter"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAdapter"};
} }
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapter) WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapter)
WM_IMPLEMENT_SINGLE_INSTANCE(ScreenManagerAdapter) WM_IMPLEMENT_SINGLE_INSTANCE(ScreenManagerAdapter)
@ -435,8 +435,9 @@ void DMSDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
BaseAdapter::~BaseAdapter() BaseAdapter::~BaseAdapter()
{ {
WLOGFD("BaseAdapter destory!"); WLOGFI("BaseAdapter destory!");
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(mutex_);
Clear();
displayManagerServiceProxy_ = nullptr; displayManagerServiceProxy_ = nullptr;
} }
@ -458,20 +459,20 @@ DMError ScreenManagerAdapter::MakeMirror(ScreenId mainScreenId, std::vector<Scre
return displayManagerServiceProxy_->MakeMirror(mainScreenId, mirrorScreenId, screenGroupId); return displayManagerServiceProxy_->MakeMirror(mainScreenId, mirrorScreenId, screenGroupId);
} }
DMError ScreenManagerAdapter::MultiScreenModeSwitch(ScreenId mainScreenId, ScreenId secondaryScreenId, DMError ScreenManagerAdapter::SetMultiScreenMode(ScreenId mainScreenId, ScreenId secondaryScreenId,
ScreenSourceMode secondaryScreenMode) MultiScreenMode screenMode)
{ {
INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED); INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
return displayManagerServiceProxy_->MultiScreenModeSwitch(mainScreenId, secondaryScreenId, secondaryScreenMode); return displayManagerServiceProxy_->SetMultiScreenMode(mainScreenId, secondaryScreenId, screenMode);
} }
DMError ScreenManagerAdapter::MultiScreenRelativePosition(ExtendOption mainScreenOption, DMError ScreenManagerAdapter::SetMultiScreenRelativePosition(MultiScreenPositionOptions mainScreenOptions,
ExtendOption secondaryScreenOption) MultiScreenPositionOptions secondScreenOption)
{ {
INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED); INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
return displayManagerServiceProxy_->MultiScreenRelativePosition(mainScreenOption, secondaryScreenOption); return displayManagerServiceProxy_->SetMultiScreenRelativePosition(mainScreenOptions, secondScreenOption);
} }
DMError ScreenManagerAdapter::StopMirror(const std::vector<ScreenId>& mirrorScreenIds) DMError ScreenManagerAdapter::StopMirror(const std::vector<ScreenId>& mirrorScreenIds)
@ -609,6 +610,13 @@ void DisplayManagerAdapter::SetFoldDisplayMode(const FoldDisplayMode mode)
return displayManagerServiceProxy_->SetFoldDisplayMode(mode); return displayManagerServiceProxy_->SetFoldDisplayMode(mode);
} }
DMError DisplayManagerAdapter::SetFoldDisplayModeFromJs(const FoldDisplayMode mode)
{
INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
return displayManagerServiceProxy_->SetFoldDisplayModeFromJs(mode);
}
void DisplayManagerAdapter::SetDisplayScale(ScreenId screenId, void DisplayManagerAdapter::SetDisplayScale(ScreenId screenId,
float scaleX, float scaleY, float pivotX, float pivotY) float scaleX, float scaleY, float pivotX, float pivotY)
{ {
@ -624,6 +632,13 @@ void DisplayManagerAdapter::SetFoldStatusLocked(bool locked)
return displayManagerServiceProxy_->SetFoldStatusLocked(locked); return displayManagerServiceProxy_->SetFoldStatusLocked(locked);
} }
DMError DisplayManagerAdapter::SetFoldStatusLockedFromJs(bool locked)
{
INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
return displayManagerServiceProxy_->SetFoldStatusLockedFromJs(locked);
}
sptr<FoldCreaseRegion> DisplayManagerAdapter::GetCurrentFoldCreaseRegion() sptr<FoldCreaseRegion> DisplayManagerAdapter::GetCurrentFoldCreaseRegion()
{ {
INIT_PROXY_CHECK_RETURN(nullptr); INIT_PROXY_CHECK_RETURN(nullptr);

View File

@ -0,0 +1,585 @@
/*
* Copyright (c) 2024 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 <securec.h>
#include <shared_mutex>
#include "display.h"
#include "display_info.h"
#include "display_manager.h"
#include "dm_common.h"
#include "oh_display_info.h"
#include "oh_display_manager.h"
#include "window_manager_hilog.h"
using namespace OHOS;
using namespace Rosen;
class OH_DisplayModeChangeListener : public DisplayManager::IDisplayModeListener {
private:
OH_NativeDisplayManager_FoldDisplayModeChangeCallback innerDisplayModeChangeFunc_;
public:
explicit OH_DisplayModeChangeListener(OH_NativeDisplayManager_FoldDisplayModeChangeCallback displayModeChangeFunc)
{
innerDisplayModeChangeFunc_ = displayModeChangeFunc;
}
void OnDisplayModeChanged(FoldDisplayMode displayMode)
{
if (innerDisplayModeChangeFunc_ == NULL) {
TLOGI(WmsLogTag::DMS, "[DMNDK] OnDisplayModeChanged callback is null");
return;
}
TLOGI(WmsLogTag::DMS, "[DMNDK] displayMode callback displayMode=%{public}d", displayMode);
innerDisplayModeChangeFunc_(static_cast<NativeDisplayManager_FoldDisplayMode>(displayMode));
}
};
class OH_DisplayChangeListener : public DisplayManager::IDisplayListener {
private:
OH_NativeDisplayManager_DisplayChangeCallback innerDisplayChangeFunc_;
public:
explicit OH_DisplayChangeListener(OH_NativeDisplayManager_DisplayChangeCallback displayChangeFunc)
{
innerDisplayChangeFunc_ = displayChangeFunc;
}
void OnCreate(DisplayId)
{
TLOGI(WmsLogTag::DMS, "[DMNDK] current not support create callback.");
}
void OnDestroy(DisplayId)
{
TLOGI(WmsLogTag::DMS, "[DMNDK] current not support delete callback.");
}
void OnChange(DisplayId displayId)
{
if (innerDisplayChangeFunc_ == NULL) {
TLOGI(WmsLogTag::DMS, "[DMNDK] OnChange callback is null");
return;
}
TLOGI(WmsLogTag::DMS, "[DMNDK] OnChange callback displayId=%{public}" PRIu64, displayId);
innerDisplayChangeFunc_(static_cast<uint64_t>(displayId));
sptr<Display> display = DisplayManager::GetInstance().GetDefaultDisplaySync();
if (display != nullptr) {
TLOGI(WmsLogTag::DMS, "[DMNDK] OnChange callback rotation=%{public}d orientation=%{public}d",
display->GetRotation(), display->GetOrientation());
}
}
};
static sptr<DisplayInfo> OH_GetDefaultDisplayInfo()
{
sptr<Display> defaultDisplay = DisplayManager::GetInstance().GetDefaultDisplaySync();
if (defaultDisplay == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get default display null.");
return nullptr;
}
auto info = defaultDisplay->GetDisplayInfo();
if (info == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get default display info null.");
return nullptr;
}
return info;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayId(uint64_t *displayId)
{
if (displayId == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input displayId null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
auto displayInfo = OH_GetDefaultDisplayInfo();
if (displayInfo == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get default display info null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*displayId = displayInfo->GetDisplayId();
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayWidth(int32_t *displayWidth)
{
if (displayWidth == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input displayWidth null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
auto displayInfo = OH_GetDefaultDisplayInfo();
if (displayInfo == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get default display info null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*displayWidth = displayInfo->GetWidth();
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayHeight(int32_t *displayHeight)
{
if (displayHeight == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input displayHeight null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
auto displayInfo = OH_GetDefaultDisplayInfo();
if (displayInfo == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get default display info null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*displayHeight = displayInfo->GetHeight();
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayRotation(
NativeDisplayManager_Rotation *displayRotation)
{
if (displayRotation == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input displayRotation null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
auto displayInfo = OH_GetDefaultDisplayInfo();
if (displayInfo == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get default display info null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*displayRotation = static_cast<NativeDisplayManager_Rotation>(displayInfo->GetRotation());
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayOrientation(
NativeDisplayManager_Orientation *displayOrientation)
{
if (displayOrientation == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input displayOrientation null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
auto displayInfo = OH_GetDefaultDisplayInfo();
if (displayInfo == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get default display info null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*displayOrientation = static_cast<NativeDisplayManager_Orientation>(displayInfo->GetDisplayOrientation());
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayVirtualPixelRatio(float *virtualPixel)
{
if (virtualPixel == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input virtualPixel null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
auto displayInfo = OH_GetDefaultDisplayInfo();
if (displayInfo == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get default display info null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*virtualPixel = displayInfo->GetVirtualPixelRatio();
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayRefreshRate(uint32_t *refreshRate)
{
if (refreshRate == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input refreshRate null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
auto displayInfo = OH_GetDefaultDisplayInfo();
if (displayInfo == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get default display info null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*refreshRate = displayInfo->GetRefreshRate();
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayDensityDpi(int32_t *densityDpi)
{
if (densityDpi == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input densityDpi null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
auto displayInfo = OH_GetDefaultDisplayInfo();
if (displayInfo == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get default display info null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*densityDpi = displayInfo->GetVirtualPixelRatio() * DOT_PER_INCH;
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayDensityPixels(float *densityPixels)
{
if (densityPixels == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input densityPixels null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
auto displayInfo = OH_GetDefaultDisplayInfo();
if (displayInfo == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get default display info null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*densityPixels = displayInfo->GetVirtualPixelRatio();
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayScaledDensity(float *scaledDensity)
{
if (scaledDensity == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input scaledDensity null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
auto displayInfo = OH_GetDefaultDisplayInfo();
if (displayInfo == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get default display info null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*scaledDensity = displayInfo->GetVirtualPixelRatio();
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayDensityXdpi(float *xDpi)
{
if (xDpi == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input xDpi null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
auto displayInfo = OH_GetDefaultDisplayInfo();
if (displayInfo == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get default display info null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*xDpi = displayInfo->GetXDpi();
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayDensityYdpi(float *yDpi)
{
if (yDpi == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input yDpi null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
auto displayInfo = OH_GetDefaultDisplayInfo();
if (displayInfo == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get default display info null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*yDpi = displayInfo->GetYDpi();
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
static void OH_SetDisplayRect(const DMRect &dmRect, NativeDisplayManager_Rect *displayRectItem)
{
displayRectItem->left = dmRect.posX_;
displayRectItem->top = dmRect.posY_;
displayRectItem->width = dmRect.width_;
displayRectItem->height = dmRect.height_;
}
static NativeDisplayManager_Rect* OH_CreateBoundingRects(const std::vector<DMRect> &boundingRects)
{
int32_t boundSize = static_cast<int32_t>(boundingRects.size());
NativeDisplayManager_Rect *ohBoundingRects =
static_cast<NativeDisplayManager_Rect*>(malloc(sizeof(NativeDisplayManager_Rect) * boundSize));
if (ohBoundingRects == NULL) {
TLOGE(WmsLogTag::DMS, "[DMNDK] memory failed.");
return NULL;
}
auto retMemset = memset_s(ohBoundingRects, sizeof(NativeDisplayManager_Rect) * boundSize, 0,
sizeof(NativeDisplayManager_Rect) * boundSize);
if (retMemset != 0) {
free(ohBoundingRects);
ohBoundingRects = NULL;
TLOGE(WmsLogTag::DMS, "[DMNDK] memset failed.");
return NULL;
}
TLOGI(WmsLogTag::DMS, "[DMNDK] bounding size:%{public}d.", boundSize);
for (int i = 0; i < boundSize; i++) {
OH_SetDisplayRect(boundingRects[i], (ohBoundingRects + i));
}
return ohBoundingRects;
}
static void OH_SetWaterfallDisplayAreaRects(const WaterfallDisplayAreaRects &waterArea,
NativeDisplayManager_CutoutInfo *ohCutoutInfo)
{
if (ohCutoutInfo == NULL) {
TLOGE(WmsLogTag::DMS, "[DMNDK] ohCutoutInfo is null.");
return;
}
TLOGI(WmsLogTag::DMS, "[DMNDK] set waterfall Area.");
OH_SetDisplayRect(waterArea.left, &(ohCutoutInfo->waterfallDisplayAreaRects.left));
OH_SetDisplayRect(waterArea.top, &(ohCutoutInfo->waterfallDisplayAreaRects.top));
OH_SetDisplayRect(waterArea.right, &(ohCutoutInfo->waterfallDisplayAreaRects.right));
OH_SetDisplayRect(waterArea.bottom, &(ohCutoutInfo->waterfallDisplayAreaRects.bottom));
}
static NativeDisplayManager_CutoutInfo* OH_CreateCutoutInfoObject(const sptr<CutoutInfo> &cutoutInfo)
{
NativeDisplayManager_CutoutInfo *ohCutoutInfo =
static_cast<NativeDisplayManager_CutoutInfo*>(malloc(sizeof(NativeDisplayManager_CutoutInfo)));
if (ohCutoutInfo == NULL) {
TLOGE(WmsLogTag::DMS, "[DMNDK] memory failed.");
return NULL;
}
auto retMemset = memset_s(ohCutoutInfo, sizeof(NativeDisplayManager_CutoutInfo), 0,
sizeof(NativeDisplayManager_CutoutInfo));
if (retMemset != 0) {
free(ohCutoutInfo);
ohCutoutInfo = NULL;
TLOGE(WmsLogTag::DMS, "[DMNDK] memset failed.");
return NULL;
}
std::vector<DMRect> boundingRects = cutoutInfo->GetBoundingRects();
WaterfallDisplayAreaRects waterRects = cutoutInfo->GetWaterfallDisplayAreaRects();
ohCutoutInfo->boundingRectsLength = static_cast<int32_t>(boundingRects.size());
TLOGI(WmsLogTag::DMS, "[DMNDK] boundingRectsLength=%{public}d.", ohCutoutInfo->boundingRectsLength);
ohCutoutInfo->boundingRects = OH_CreateBoundingRects(boundingRects);
if (ohCutoutInfo->boundingRects == NULL) {
TLOGE(WmsLogTag::DMS, "[DMNDK] create bounding rects failed.");
free(ohCutoutInfo);
ohCutoutInfo = NULL;
return NULL;
}
OH_SetWaterfallDisplayAreaRects(waterRects, ohCutoutInfo);
return ohCutoutInfo;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_CreateDefaultDisplayCutoutInfo(
NativeDisplayManager_CutoutInfo **cutoutInfo)
{
if (cutoutInfo == NULL) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input cutoutInfo null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
TLOGI(WmsLogTag::DMS, "[DMNDK] get display cutout info.");
sptr<Display> defaultDisplay = DisplayManager::GetInstance().GetDefaultDisplaySync();
if (defaultDisplay == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get cutout info (display) null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
sptr<CutoutInfo> cutoutInfoInner = defaultDisplay->GetCutoutInfo();
if (cutoutInfoInner == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] get cutout info (from display) null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*cutoutInfo = OH_CreateCutoutInfoObject(cutoutInfoInner);
if (*cutoutInfo == NULL) {
TLOGE(WmsLogTag::DMS, "[DMNDK] convert cutout info null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
TLOGI(WmsLogTag::DMS, "[DMNDK] get display cutout info success.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_DestroyDefaultDisplayCutoutInfo(
NativeDisplayManager_CutoutInfo *cutoutInfo)
{
if (cutoutInfo == NULL) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input cutoutInfo null pointer.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
if (cutoutInfo->boundingRects != NULL) {
free(cutoutInfo->boundingRects);
cutoutInfo->boundingRects = NULL;
}
free(cutoutInfo);
cutoutInfo = NULL;
TLOGI(WmsLogTag::DMS, "[DMNDK] destroy cutoutInfo end.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
bool OH_NativeDisplayManager_IsFoldable()
{
bool isFoldable = DisplayManager::GetInstance().IsFoldable();
TLOGI(WmsLogTag::DMS, "[DMNDK] get display isFoldable=%{public}d.", isFoldable);
return isFoldable;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetFoldDisplayMode(
NativeDisplayManager_FoldDisplayMode *foldDisplayMode)
{
TLOGI(WmsLogTag::DMS, "[DMNDK] get fold display mode.");
if (foldDisplayMode == NULL) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input foldDisplayMode null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
if (!DisplayManager::GetInstance().IsFoldable()) {
TLOGE(WmsLogTag::DMS, "[DMNDK] device is not foldable.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_DEVICE_NOT_SUPPORTED;
}
FoldDisplayMode foldMode = DisplayManager::GetInstance().GetFoldDisplayMode();
switch (foldMode) {
case FoldDisplayMode::SUB:
*foldDisplayMode = NativeDisplayManager_FoldDisplayMode::DISPLAY_MANAGER_FOLD_DISPLAY_MODE_SUB;
break;
case FoldDisplayMode::MAIN:
*foldDisplayMode = NativeDisplayManager_FoldDisplayMode::DISPLAY_MANAGER_FOLD_DISPLAY_MODE_MAIN;
break;
case FoldDisplayMode::FULL:
*foldDisplayMode = NativeDisplayManager_FoldDisplayMode::DISPLAY_MANAGER_FOLD_DISPLAY_MODE_FULL;
break;
case FoldDisplayMode::COORDINATION:
*foldDisplayMode = NativeDisplayManager_FoldDisplayMode::DISPLAY_MANAGER_FOLD_DISPLAY_MODE_COORDINATION;
break;
default:
*foldDisplayMode = NativeDisplayManager_FoldDisplayMode::DISPLAY_MANAGER_FOLD_DISPLAY_MODE_UNKNOWN;
break;
}
TLOGI(WmsLogTag::DMS, "[DMNDK] current fold display mode: %{public}d.", *foldDisplayMode);
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
std::shared_mutex foldChangeMutex;
std::map<uint32_t, OH_NativeDisplayManager_FoldDisplayModeChangeCallback> g_foldChangeCallbackMap;
std::map<uint32_t, sptr<DisplayManager::IDisplayModeListener>> g_foldDisplayModeChangeListenerMap;
bool CheckFoldChangeHasRegistered(OH_NativeDisplayManager_FoldDisplayModeChangeCallback displayModeChangeCallback)
{
if (g_foldChangeCallbackMap.empty()) {
return false;
}
for (auto iter : g_foldChangeCallbackMap) {
if (iter.second == displayModeChangeCallback) {
return true;
}
}
return false;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_RegisterFoldDisplayModeChangeListener(
OH_NativeDisplayManager_FoldDisplayModeChangeCallback displayModeChangeCallback, uint32_t *listenerIndex)
{
TLOGI(WmsLogTag::DMS, "[DMNDK] register fold display mode change listener.");
if (displayModeChangeCallback == NULL || listenerIndex == NULL) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input params null.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
if (!DisplayManager::GetInstance().IsFoldable()) {
TLOGE(WmsLogTag::DMS, "[DMNDK] device is not foldable.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_DEVICE_NOT_SUPPORTED;
}
std::unique_lock<std::shared_mutex> lock(foldChangeMutex);
if (CheckFoldChangeHasRegistered(displayModeChangeCallback)) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input params error (has registered).");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
sptr<DisplayManager::IDisplayModeListener> displayModeListener =
sptr<OH_DisplayModeChangeListener>::MakeSptr(displayModeChangeCallback);
if (displayModeListener == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] display mode listener MakeSptr fail.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
static std::atomic<uint32_t> registerCount = 1;
DMError ret = DisplayManager::GetInstance().RegisterDisplayModeListener(displayModeListener);
if (ret != DMError::DM_OK) {
TLOGE(WmsLogTag::DMS, "[DMNDK] display mode listener register failed ret=%{public}d.", ret);
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*listenerIndex = registerCount++;
g_foldChangeCallbackMap.emplace(*listenerIndex, displayModeChangeCallback);
g_foldDisplayModeChangeListenerMap.emplace(*listenerIndex, displayModeListener);
TLOGI(WmsLogTag::DMS, "[DMNDK] register fold change success and listenerIndex= %{public}d.", *listenerIndex);
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_UnregisterFoldDisplayModeChangeListener(uint32_t listenerIndex)
{
TLOGI(WmsLogTag::DMS, "[DMNDK] unregister fold display mode change listener %{public}d.", listenerIndex);
if (!DisplayManager::GetInstance().IsFoldable()) {
TLOGE(WmsLogTag::DMS, "[DMNDK] unregister fail(device is not foldable).");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_DEVICE_NOT_SUPPORTED;
}
std::unique_lock<std::shared_mutex> lock(foldChangeMutex);
auto iter = g_foldDisplayModeChangeListenerMap.find(listenerIndex);
if (iter == g_foldDisplayModeChangeListenerMap.end()) {
TLOGE(WmsLogTag::DMS, "[DMNDK] unregister fold change listener fail(not find register info).");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
DMError ret = DMError::DM_OK;
if (iter->second != nullptr) {
ret = DisplayManager::GetInstance().UnregisterDisplayModeListener(iter->second);
g_foldDisplayModeChangeListenerMap.erase(listenerIndex);
g_foldChangeCallbackMap.erase(listenerIndex);
TLOGI(WmsLogTag::DMS, "[DMNDK] unregister fold change listener ert=%{public}d", ret);
}
return ret == DMError::DM_OK ? NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK :
NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
std::shared_mutex displayChangeMutex;
std::map<uint32_t, OH_NativeDisplayManager_DisplayChangeCallback> g_displayChangeCallbackMap;
std::map<uint32_t, sptr<DisplayManager::IDisplayListener>> g_displayChangeListenerMap;
bool CheckDisplayChangeHasRegistered(OH_NativeDisplayManager_DisplayChangeCallback displayChangeCallback)
{
if (g_displayChangeCallbackMap.empty()) {
return false;
}
for (auto iter : g_displayChangeCallbackMap) {
if (iter.second == displayChangeCallback) {
return true;
}
}
return false;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_RegisterDisplayChangeListener(
OH_NativeDisplayManager_DisplayChangeCallback displayChangeCallback, uint32_t *listenerIndex)
{
TLOGI(WmsLogTag::DMS, "[DMNDK] register display change listener.");
if (displayChangeCallback == NULL || listenerIndex == NULL) {
TLOGE(WmsLogTag::DMS, "[DMNDK] register display change listener fail(input params null).");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
std::unique_lock<std::shared_mutex> lock(displayChangeMutex);
if (CheckDisplayChangeHasRegistered(displayChangeCallback)) {
TLOGE(WmsLogTag::DMS, "[DMNDK] input params error (has registered).");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
sptr<DisplayManager::IDisplayListener> displayListener =
sptr<OH_DisplayChangeListener>::MakeSptr(displayChangeCallback);
if (displayListener == nullptr) {
TLOGE(WmsLogTag::DMS, "[DMNDK] register display change MakeSptr fail.");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
static std::atomic<uint32_t> registerCount = 1;
DMError ret = DisplayManager::GetInstance().RegisterDisplayListener(displayListener);
if (ret != DMError::DM_OK) {
TLOGE(WmsLogTag::DMS, "[DMNDK] display change listener register failed ret=%{public}d.", ret);
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}
*listenerIndex = registerCount++;
g_displayChangeCallbackMap.emplace(*listenerIndex, displayChangeCallback);
g_displayChangeListenerMap.emplace(*listenerIndex, displayListener);
TLOGI(WmsLogTag::DMS, "[DMNDK] register display change success and listenerIndex= %{public}d.", *listenerIndex);
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK;
}
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_UnregisterDisplayChangeListener(uint32_t listenerIndex)
{
TLOGI(WmsLogTag::DMS, "[DMNDK] unregister display change listener %{public}d.", listenerIndex);
std::unique_lock<std::shared_mutex> lock(displayChangeMutex);
auto iter = g_displayChangeListenerMap.find(listenerIndex);
if (iter == g_displayChangeListenerMap.end()) {
TLOGE(WmsLogTag::DMS, "[DMNDK] unregister display change listener fail(not find register info).");
return NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM;
}
DMError ret = DMError::DM_OK;
if (iter->second != nullptr) {
ret = DisplayManager::GetInstance().UnregisterDisplayListener(iter->second);
g_displayChangeListenerMap.erase(listenerIndex);
g_displayChangeCallbackMap.erase(listenerIndex);
TLOGI(WmsLogTag::DMS, "[DMNDK] unregister display change listener ert=%{public}d", ret);
}
return ret == DMError::DM_OK ? NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK :
NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL;
}

View File

@ -27,7 +27,7 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "Screen"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "Screen"};
} }
class Screen::Impl : public RefBase { class Screen::Impl : public RefBase {
public: public:

View File

@ -26,7 +26,7 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenGroup"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenGroup"};
} }
class ScreenGroup::Impl : public RefBase { class ScreenGroup::Impl : public RefBase {
public: public:

View File

@ -27,8 +27,8 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenManager"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenManager"};
const static uint32_t MAX_SCREEN_SIZE = 32; const static uint32_t MAX_SCREEN_SIZE = 32;
} }
class ScreenManager::Impl : public RefBase { class ScreenManager::Impl : public RefBase {
public: public:
@ -482,24 +482,24 @@ DMError ScreenManager::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> m
return ret; return ret;
} }
DMError ScreenManager::MultiScreenModeSwitch(ScreenId mainScreenId, ScreenId secondaryScreenId, DMError ScreenManager::SetMultiScreenMode(ScreenId mainScreenId, ScreenId secondaryScreenId,
ScreenSourceMode secondaryScreenMode) MultiScreenMode screenMode)
{ {
WLOGFI("mainScreenId:%{public}" PRIu64",secondaryScreenId:%{public}" PRIu64",secondaryScreenMode:%{public}u", WLOGFI("mainScreenId:%{public}" PRIu64",secondaryScreenId:%{public}" PRIu64",screenMode:%{public}u",
mainScreenId, secondaryScreenId, secondaryScreenMode); mainScreenId, secondaryScreenId, screenMode);
DMError ret = SingletonContainer::Get<ScreenManagerAdapter>().MultiScreenModeSwitch(mainScreenId, DMError ret = SingletonContainer::Get<ScreenManagerAdapter>().SetMultiScreenMode(mainScreenId,
secondaryScreenId, secondaryScreenMode); secondaryScreenId, screenMode);
return ret; return ret;
} }
DMError ScreenManager::MultiScreenRelativePosition(ExtendOption mainScreenOption, DMError ScreenManager::SetMultiScreenRelativePosition(MultiScreenPositionOptions mainScreenOptions,
ExtendOption secondaryScreenOption) MultiScreenPositionOptions secondScreenOption)
{ {
WLOGFI("mId:%{public}" PRIu64", X:%{public}u, Y:%{public}u,sId:%{public}" PRIu64", X:%{public}u, Y:%{public}u", WLOGFI("mId:%{public}" PRIu64", X:%{public}u, Y:%{public}u,sId:%{public}" PRIu64", X:%{public}u, Y:%{public}u",
mainScreenOption.screenId_, mainScreenOption.startX_, mainScreenOption.startY_, mainScreenOptions.screenId_, mainScreenOptions.startX_, mainScreenOptions.startY_,
secondaryScreenOption.screenId_, secondaryScreenOption.startX_, secondaryScreenOption.startY_); secondScreenOption.screenId_, secondScreenOption.startX_, secondScreenOption.startY_);
DMError ret = SingletonContainer::Get<ScreenManagerAdapter>().MultiScreenRelativePosition(mainScreenOption, DMError ret = SingletonContainer::Get<ScreenManagerAdapter>().SetMultiScreenRelativePosition(mainScreenOptions,
secondaryScreenOption); secondScreenOption);
return ret; return ret;
} }

View File

@ -24,7 +24,7 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAgentProxy"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAgentProxy"};
} }
void DisplayManagerAgentProxy::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) void DisplayManagerAgentProxy::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status)

View File

@ -25,7 +25,7 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAgentStub"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAgentStub"};
} }
int32_t DisplayManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data, int32_t DisplayManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data,

View File

@ -68,11 +68,16 @@ ohos_shared_library("libdm_lite") {
innerapi_tags = [ "platformsdk" ] innerapi_tags = [ "platformsdk" ]
part_name = "window_manager" part_name = "window_manager"
subsystem_name = "window" subsystem_name = "window"
defines = []
if (build_variant == "user") {
defines += [ "IS_RELEASE_VERSION" ]
}
} }
group("test") { group("test") {
testonly = true testonly = true
if (scene_board_enabled) { if (window_manager_use_sceneboard) {
deps = [ "test:test" ] deps = [ "test:test" ]
} else { } else {
deps = [] deps = []

View File

@ -27,7 +27,7 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayLite"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayLite"};
} }
class DisplayLite::Impl : public RefBase { class DisplayLite::Impl : public RefBase {
public: public:

View File

@ -26,7 +26,7 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAdapterLite"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAdapterLite"};
} }
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapterLite) WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapterLite)

View File

@ -26,7 +26,7 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerLite"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerLite"};
} }
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerLite) WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerLite)

View File

@ -105,6 +105,10 @@ ohos_shared_library("libdms") {
part_name = "window_manager" part_name = "window_manager"
subsystem_name = "window" subsystem_name = "window"
if (build_variant == "user") {
defines += [ "IS_RELEASE_VERSION" ]
}
} }
group("test") { group("test") {

View File

@ -104,6 +104,7 @@ public:
TRANS_ID_SCENE_BOARD_DUMP_ALL_SCREEN, TRANS_ID_SCENE_BOARD_DUMP_ALL_SCREEN,
TRANS_ID_SCENE_BOARD_DUMP_SPECIAL_SCREEN, TRANS_ID_SCENE_BOARD_DUMP_SPECIAL_SCREEN,
TRANS_ID_SCENE_BOARD_SET_FOLD_DISPLAY_MODE, TRANS_ID_SCENE_BOARD_SET_FOLD_DISPLAY_MODE,
TRANS_ID_SET_FOLD_DISPLAY_MODE_FROM_JS,
TRANS_ID_SCENE_BOARD_GET_FOLD_DISPLAY_MODE, TRANS_ID_SCENE_BOARD_GET_FOLD_DISPLAY_MODE,
TRANS_ID_SCENE_BOARD_SET_DISPLAY_SCALE, TRANS_ID_SCENE_BOARD_SET_DISPLAY_SCALE,
TRANS_ID_SCENE_BOARD_IS_FOLDABLE, TRANS_ID_SCENE_BOARD_IS_FOLDABLE,
@ -111,6 +112,7 @@ public:
TRANS_ID_SCENE_BOARD_GET_CURRENT_FOLD_CREASE_REGION, TRANS_ID_SCENE_BOARD_GET_CURRENT_FOLD_CREASE_REGION,
TRANS_ID_SCENE_BOARD_MAKE_UNIQUE_SCREEN, TRANS_ID_SCENE_BOARD_MAKE_UNIQUE_SCREEN,
TRANS_ID_SCENE_BOARD_LOCK_FOLD_DISPLAY_STATUS, TRANS_ID_SCENE_BOARD_LOCK_FOLD_DISPLAY_STATUS,
TRANS_ID_SET_LOCK_FOLD_DISPLAY_STATUS_FROM_JS,
TRANS_ID_SET_CLIENT = 2500, TRANS_ID_SET_CLIENT = 2500,
TRANS_ID_GET_SCREEN_PROPERTY, TRANS_ID_GET_SCREEN_PROPERTY,
TRANS_ID_GET_DISPLAY_NODE, TRANS_ID_GET_DISPLAY_NODE,
@ -150,7 +152,7 @@ public:
virtual sptr<DisplayInfo> GetDisplayInfoByScreen(ScreenId screenId) = 0; virtual sptr<DisplayInfo> GetDisplayInfoByScreen(ScreenId screenId) = 0;
virtual DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow) = 0; virtual DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow) = 0;
virtual bool ConvertScreenIdToRsScreenId(ScreenId screenId, ScreenId& rsScreenId) { return false; }; virtual bool ConvertScreenIdToRsScreenId(ScreenId screenId, ScreenId& rsScreenId) { return false; };
virtual void UpdateDisplayHookInfo(int32_t uid, bool enable, DMHookInfo hookInfo) {}; virtual void UpdateDisplayHookInfo(int32_t uid, bool enable, const DMHookInfo& hookInfo) {};
virtual ScreenId CreateVirtualScreen(VirtualScreenOption option, virtual ScreenId CreateVirtualScreen(VirtualScreenOption option,
const sptr<IRemoteObject>& displayManagerAgent) = 0; const sptr<IRemoteObject>& displayManagerAgent) = 0;
@ -238,13 +240,13 @@ public:
virtual DMError GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos) = 0; virtual DMError GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos) = 0;
virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenIds, virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenIds,
ScreenId& screenGroupId) = 0; ScreenId& screenGroupId) = 0;
virtual DMError MultiScreenModeSwitch(ScreenId mainScreenId, ScreenId secondaryScreenId, virtual DMError SetMultiScreenMode(ScreenId mainScreenId, ScreenId secondaryScreenId,
ScreenSourceMode secondaryScreenMode) MultiScreenMode screenMode)
{ {
return DMError::DM_ERROR_DEVICE_NOT_SUPPORT; return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
} }
virtual DMError MultiScreenRelativePosition(ExtendOption mainScreenOption, virtual DMError SetMultiScreenRelativePosition(MultiScreenPositionOptions mainScreenOptions,
ExtendOption secondaryScreenOption) MultiScreenPositionOptions secondScreenOption)
{ {
return DMError::DM_ERROR_DEVICE_NOT_SUPPORT; return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
} }
@ -277,10 +279,14 @@ public:
virtual void SetFoldDisplayMode(const FoldDisplayMode) {} virtual void SetFoldDisplayMode(const FoldDisplayMode) {}
virtual DMError SetFoldDisplayModeFromJs(const FoldDisplayMode) { return DMError::DM_OK; }
virtual void SetDisplayScale(ScreenId screenId, float scaleX, float scaleY, float pivotX, float pivotY) {} virtual void SetDisplayScale(ScreenId screenId, float scaleX, float scaleY, float pivotX, float pivotY) {}
virtual void SetFoldStatusLocked(bool locked) {} virtual void SetFoldStatusLocked(bool locked) {}
virtual DMError SetFoldStatusLockedFromJs(bool locked) { return DMError::DM_OK; }
virtual sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion() { return nullptr; } virtual sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion() { return nullptr; }
virtual DMError HasImmersiveWindow(bool& immersive) { return DMError::DM_ERROR_DEVICE_NOT_SUPPORT; } virtual DMError HasImmersiveWindow(bool& immersive) { return DMError::DM_ERROR_DEVICE_NOT_SUPPORT; }

View File

@ -99,6 +99,7 @@ public:
std::shared_ptr<class RSSurfaceNode>& surfaceNode) override; std::shared_ptr<class RSSurfaceNode>& surfaceNode) override;
DMError ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height) override; DMError ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height) override;
DMError MakeUniqueScreen(const std::vector<ScreenId>& screenIds) override; DMError MakeUniqueScreen(const std::vector<ScreenId>& screenIds) override;
std::vector<DisplayPhysicalResolution> GetAllDisplayPhysicalResolution() override;
private: private:
static inline BrokerDelegator<DisplayManagerProxy> delegator_; static inline BrokerDelegator<DisplayManagerProxy> delegator_;
}; };

View File

@ -114,6 +114,7 @@ public:
void RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener); void RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener);
void RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener>& listener); void RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener>& listener);
void NotifyPrivateWindowStateChanged(bool hasPrivate); void NotifyPrivateWindowStateChanged(bool hasPrivate);
std::vector<DisplayPhysicalResolution> GetAllDisplayPhysicalResolution() override;
private: private:
DisplayManagerService(); DisplayManagerService();
@ -137,6 +138,7 @@ private:
sptr<DisplayDumper> displayDumper_; sptr<DisplayDumper> displayDumper_;
AtomicMap<ScreenId, uint32_t> accessTokenIdMaps_; AtomicMap<ScreenId, uint32_t> accessTokenIdMaps_;
bool isAutoRotationOpen_; bool isAutoRotationOpen_;
std::vector<DisplayPhysicalResolution> allDisplayPhysicalResolution_ {};
}; };
} // namespace OHOS::Rosen } // namespace OHOS::Rosen

View File

@ -22,10 +22,10 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "AbstractDisplay"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "AbstractDisplay"};
constexpr int32_t PAD_SCREEN_WIDTH = 2560; constexpr int32_t PAD_SCREEN_WIDTH = 2560;
constexpr int32_t PHONE_SCREEN_WIDTH = 2160; constexpr int32_t PHONE_SCREEN_WIDTH = 2160;
constexpr float INCH_2_MM = 25.4f; constexpr float INCH_2_MM = 25.4f;
} }
AbstractDisplay::AbstractDisplay(DisplayId id, sptr<SupportedScreenModes>& info, sptr<AbstractScreen>& absScreen) AbstractDisplay::AbstractDisplay(DisplayId id, sptr<SupportedScreenModes>& info, sptr<AbstractScreen>& absScreen)

View File

@ -31,7 +31,7 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "AbstractDisplayController"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "AbstractDisplayController"};
} }
AbstractDisplayController::AbstractDisplayController(std::recursive_mutex& mutex, DisplayStateChangeListener listener) AbstractDisplayController::AbstractDisplayController(std::recursive_mutex& mutex, DisplayStateChangeListener listener)

View File

@ -23,8 +23,8 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "AbstractScreenGroup"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "AbstractScreenGroup"};
constexpr float MAX_ZORDER = 100000.0f; constexpr float MAX_ZORDER = 100000.0f;
} }
AbstractScreen::AbstractScreen(sptr<AbstractScreenController> screenController, const std::string& name, ScreenId dmsId, AbstractScreen::AbstractScreen(sptr<AbstractScreenController> screenController, const std::string& name, ScreenId dmsId,

View File

@ -38,10 +38,10 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "AbstractScreenController"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "AbstractScreenController"};
const std::string CONTROLLER_THREAD_ID = "AbstractScreenControllerThread"; const std::string CONTROLLER_THREAD_ID = "AbstractScreenControllerThread";
const static uint32_t MAX_RETRY_NUM = 3; const static uint32_t MAX_RETRY_NUM = 3;
const static uint32_t RETRY_WAIT_MS = 100; const static uint32_t RETRY_WAIT_MS = 100;
} }
AbstractScreenController::AbstractScreenController(std::recursive_mutex& mutex) AbstractScreenController::AbstractScreenController(std::recursive_mutex& mutex)

View File

@ -21,8 +21,8 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayCutoutController"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayCutoutController"};
const uint32_t NO_WATERFALL_DISPLAY_COMPRESSION_SIZE = 0; const uint32_t NO_WATERFALL_DISPLAY_COMPRESSION_SIZE = 0;
} }
bool DisplayCutoutController::isWaterfallDisplay_ = false; bool DisplayCutoutController::isWaterfallDisplay_ = false;

View File

@ -28,38 +28,38 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayDumper"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayDumper"};
constexpr int SCREEN_NAME_MAX_LENGTH = 20; constexpr int SCREEN_NAME_MAX_LENGTH = 20;
const std::string ARG_DUMP_HELP = "-h"; const std::string ARG_DUMP_HELP = "-h";
const std::string ARG_DUMP_ALL = "-a"; const std::string ARG_DUMP_ALL = "-a";
const std::string ARG_DUMP_SCREEN = "-s"; const std::string ARG_DUMP_SCREEN = "-s";
const std::string ARG_DUMP_DISPLAY = "-d"; const std::string ARG_DUMP_DISPLAY = "-d";
// set the output width of screen // set the output width of screen
constexpr int W_SCREEN_NAME = 21; constexpr int W_SCREEN_NAME = 21;
constexpr int W_SCREEN_TYPE = 9; constexpr int W_SCREEN_TYPE = 9;
constexpr int W_GROUP_TYPE = 8; constexpr int W_GROUP_TYPE = 8;
constexpr int W_DMS_ID = 6; constexpr int W_DMS_ID = 6;
constexpr int W_RS_ID = 21; constexpr int W_RS_ID = 21;
constexpr int W_ACTIVE_IDX = 10; constexpr int W_ACTIVE_IDX = 10;
constexpr int W_VIR_PIXEL_RATIO = 4; constexpr int W_VIR_PIXEL_RATIO = 4;
constexpr int W_SCREEN_ROTATION = 9; constexpr int W_SCREEN_ROTATION = 9;
constexpr int W_ORIENTATION = 12; constexpr int W_ORIENTATION = 12;
constexpr int W_REQUESTED_ORIENTATION = 19; constexpr int W_REQUESTED_ORIENTATION = 19;
constexpr int W_NODE_ID = 21; constexpr int W_NODE_ID = 21;
constexpr int W_MIRROR_TYPE = 11; constexpr int W_MIRROR_TYPE = 11;
constexpr int W_MIRROR_NODE_ID = 13; constexpr int W_MIRROR_NODE_ID = 13;
// set the output width of display // set the output width of display
constexpr int W_DISPLAY_ID = 10; constexpr int W_DISPLAY_ID = 10;
constexpr int W_ABSTR_SCREEN_ID = 9; constexpr int W_ABSTR_SCREEN_ID = 9;
constexpr int W_REFRESH_RATE = 12; constexpr int W_REFRESH_RATE = 12;
constexpr int W_DISPLAY_ROTATION = 9; constexpr int W_DISPLAY_ROTATION = 9;
constexpr int W_DISPLAY_ORIENTATION = 18; constexpr int W_DISPLAY_ORIENTATION = 18;
constexpr int W_DISPLAY_FREEZE_FLAG = 11; constexpr int W_DISPLAY_FREEZE_FLAG = 11;
constexpr int W_DISPLAY_OFFSET_X = 5; constexpr int W_DISPLAY_OFFSET_X = 5;
constexpr int W_DISPLAY_OFFSET_Y = 5; constexpr int W_DISPLAY_OFFSET_Y = 5;
constexpr int W_DISPLAY_WIDTH = 5; constexpr int W_DISPLAY_WIDTH = 5;
constexpr int W_DISPLAY_HEITHT = 5; constexpr int W_DISPLAY_HEITHT = 5;
} }
DisplayDumper::DisplayDumper(const sptr<AbstractDisplayController>& abstractDisplayController, DisplayDumper::DisplayDumper(const sptr<AbstractDisplayController>& abstractDisplayController,

View File

@ -19,7 +19,7 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAgentController"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAgentController"};
} }
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAgentController) WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAgentController)

View File

@ -30,7 +30,7 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerConfig"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerConfig"};
} }
std::map<std::string, bool> DisplayManagerConfig::enableConfig_; std::map<std::string, bool> DisplayManagerConfig::enableConfig_;

View File

@ -24,7 +24,7 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerProxy"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerProxy"};
} }
sptr<DisplayInfo> DisplayManagerProxy::GetDefaultDisplayInfo() sptr<DisplayInfo> DisplayManagerProxy::GetDefaultDisplayInfo()
@ -1766,4 +1766,40 @@ DMError DisplayManagerProxy::MakeUniqueScreen(const std::vector<ScreenId>& scree
} }
return static_cast<DMError>(reply.ReadInt32()); return static_cast<DMError>(reply.ReadInt32());
} }
std::vector<DisplayPhysicalResolution> DisplayManagerProxy::GetAllDisplayPhysicalResolution()
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
TLOGE(WmsLogTag::DMS, "remote is nullptr");
return std::vector<DisplayPhysicalResolution> {};
}
MessageOption option;
MessageParcel reply;
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
TLOGE(WmsLogTag::DMS, "WriteInterfaceToken failed");
return std::vector<DisplayPhysicalResolution> {};
}
if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_GET_ALL_PHYSICAL_DISPLAY_RESOLUTION),
data, reply, option) != ERR_NONE) {
TLOGE(WmsLogTag::DMS, "SendRequest failed");
return std::vector<DisplayPhysicalResolution> {};
}
std::vector<DisplayPhysicalResolution> allPhysicalSize;
int32_t displayInfoSize = 0;
bool readRet = reply.ReadInt32(displayInfoSize);
if (!readRet || displayInfoSize <= 0) {
TLOGE(WmsLogTag::DMS, "read failed");
return std::vector<DisplayPhysicalResolution> {};
}
for (int32_t i = 0; i < displayInfoSize; i++) {
DisplayPhysicalResolution physicalItem;
physicalItem.foldDisplayMode_ = static_cast<FoldDisplayMode>(reply.ReadUint32());
physicalItem.physicalWidth_ = reply.ReadUint32();
physicalItem.physicalHeight_ = reply.ReadUint32();
allPhysicalSize.emplace_back(physicalItem);
}
return allPhysicalSize;
}
} // namespace OHOS::Rosen } // namespace OHOS::Rosen

View File

@ -33,8 +33,8 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerService"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerService"};
const std::string SCREEN_CAPTURE_PERMISSION = "ohos.permission.CAPTURE_SCREEN"; const std::string SCREEN_CAPTURE_PERMISSION = "ohos.permission.CAPTURE_SCREEN";
} }
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService) WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService)
const bool REGISTER_RESULT = SceneBoardJudgement::IsSceneBoardEnabled() ? false : const bool REGISTER_RESULT = SceneBoardJudgement::IsSceneBoardEnabled() ? false :
@ -799,4 +799,21 @@ void DisplayManagerService::NotifyPrivateWindowStateChanged(bool hasPrivate)
{ {
DisplayManagerAgentController::GetInstance().NotifyPrivateWindowStateChanged(hasPrivate); DisplayManagerAgentController::GetInstance().NotifyPrivateWindowStateChanged(hasPrivate);
} }
std::vector<DisplayPhysicalResolution> DisplayManagerService::GetAllDisplayPhysicalResolution()
{
if (allDisplayPhysicalResolution_.empty()) {
sptr<DisplayInfo> displayInfo = DisplayManagerService::GetDefaultDisplayInfo();
if (displayInfo == nullptr) {
TLOGE(WmsLogTag::DMS, "default display null");
return allDisplayPhysicalResolution_;
}
DisplayPhysicalResolution defaultResolution;
defaultResolution.foldDisplayMode_ = FoldDisplayMode::UNKNOWN;
defaultResolution.physicalWidth_ = displayInfo->GetWidth();
defaultResolution.physicalHeight_ = displayInfo->GetHeight();
allDisplayPhysicalResolution_.emplace_back(defaultResolution);
}
return allDisplayPhysicalResolution_;
}
} // namespace OHOS::Rosen } // namespace OHOS::Rosen

View File

@ -23,7 +23,7 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerServiceInner"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerServiceInner"};
} }
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerServiceInner) WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerServiceInner)

View File

@ -26,8 +26,8 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerStub"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerStub"};
const static uint32_t MAX_SCREEN_SIZE = 32; const static uint32_t MAX_SCREEN_SIZE = 32;
} }
int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
@ -432,6 +432,33 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
reply.WriteInt32(static_cast<int32_t>(ret)); reply.WriteInt32(static_cast<int32_t>(ret));
break; break;
} }
case DisplayManagerMessage::TRANS_ID_GET_ALL_PHYSICAL_DISPLAY_RESOLUTION: {
auto physicalInfos = GetAllDisplayPhysicalResolution();
size_t infoSize = physicalInfos.size();
bool writeRet = reply.WriteInt32(static_cast<int32_t>(infoSize));
if (!writeRet) {
WLOGFE("write physical size error");
break;
}
for (const auto &physicalItem : physicalInfos) {
writeRet = reply.WriteUint32(static_cast<uint32_t>(physicalItem.foldDisplayMode_));
if (!writeRet) {
WLOGFE("write display mode error");
break;
}
writeRet = reply.WriteUint32(physicalItem.physicalWidth_);
if (!writeRet) {
WLOGFE("write physical width error");
break;
}
writeRet = reply.WriteUint32(physicalItem.physicalHeight_);
if (!writeRet) {
WLOGFE("write physical height error");
break;
}
}
break;
}
default: default:
WLOGFW("unknown transaction code"); WLOGFW("unknown transaction code");
return IPCObjectStub::OnRemoteRequest(code, data, reply, option); return IPCObjectStub::OnRemoteRequest(code, data, reply, option);

View File

@ -21,7 +21,7 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayPowerController"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayPowerController"};
} }
bool DisplayPowerController::SuspendBegin(PowerStateChangeReason reason) bool DisplayPowerController::SuspendBegin(PowerStateChangeReason reason)

View File

@ -23,7 +23,7 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenRotationController"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenRotationController"};
} }
DisplayId ScreenRotationController::defaultDisplayId_ = 0; DisplayId ScreenRotationController::defaultDisplayId_ = 0;

View File

@ -23,7 +23,7 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SensorConnector"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SensorConnector"};
#ifdef SENSOR_ENABLE #ifdef SENSOR_ENABLE
constexpr int64_t ORIENTATION_SENSOR_SAMPLING_RATE = 200000000; // 200ms constexpr int64_t ORIENTATION_SENSOR_SAMPLING_RATE = 200000000; // 200ms

View File

@ -23,7 +23,7 @@ using namespace testing::ext;
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr uint32_t SLEEP_TIME_US = 100000; constexpr uint32_t SLEEP_TIME_US = 100000;
} }
class DisplayManagerServiceInnerTest : public testing::Test { class DisplayManagerServiceInnerTest : public testing::Test {
public: public:

View File

@ -30,7 +30,7 @@ using namespace testing::ext;
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr uint32_t SLEEP_TIME_US = 100000; constexpr uint32_t SLEEP_TIME_US = 100000;
} }
class DisplayManagerServiceTest : public testing::Test { class DisplayManagerServiceTest : public testing::Test {
public: public:
@ -557,6 +557,102 @@ HWTEST_F(DisplayManagerServiceTest, RemoveSurfaceNodeFromDisplay, Function | Sma
DMError ret = dms_->RemoveSurfaceNodeFromDisplay(displayId, surfaceNode); DMError ret = dms_->RemoveSurfaceNodeFromDisplay(displayId, surfaceNode);
ASSERT_EQ(ret, DMError::DM_ERROR_NULLPTR); ASSERT_EQ(ret, DMError::DM_ERROR_NULLPTR);
} }
/**
* @tc.name: SetOrientation
* @tc.desc: DMS SetOrientation
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerServiceTest, SetOrientation, Function | SmallTest | Level3)
{
ScreenId screenId = 0;
Orientation orientation = Orientation::VERTICAL;
auto ret = dms_->SetOrientation(screenId, orientation);
ASSERT_NE(ret, DMError::DM_ERROR_INVALID_PARAM);
orientation = Orientation::SENSOR_VERTICAL;
ASSERT_NE(ret, DMError::DM_ERROR_INVALID_PARAM);
}
/**
* @tc.name: GetDisplaySnapshot
* @tc.desc: DMS GetDisplaySnapshot
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerServiceTest, GetDisplaySnapshot, Function | SmallTest | Level3)
{
DisplayId displayId = -1;
DmErrorCode* errorCode = nullptr;
auto ret = dms_->GetDisplaySnapshot(displayId, errorCode);
ASSERT_EQ(nullptr, ret);
}
/**
* @tc.name: AddSurfaceNodeToDisplay
* @tc.desc: DMS AddSurfaceNodeToDisplay
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerServiceTest, AddSurfaceNodeToDisplay02, Function | SmallTest | Level3)
{
DisplayId displayId = 1;
struct RSSurfaceNodeConfig config;
std::shared_ptr<RSSurfaceNode> surfaceNode = nullptr;
bool onTop = true;
auto ret = dms_->AddSurfaceNodeToDisplay(displayId, surfaceNode, onTop);
ASSERT_EQ(DMError::DM_ERROR_NULLPTR, ret);
}
/**
* @tc.name: GetAllScreenInfos
* @tc.desc: DMS GetAllScreenInfos
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerServiceTest, GetAllScreenInfos, Function | SmallTest | Level3)
{
std::vector<sptr<ScreenInfo>> screenInfos;
auto ret =dms_->GetAllScreenInfos(screenInfos);
ASSERT_EQ(DMError::DM_OK, ret);
}
/**
* @tc.name: MakeExpand
* @tc.desc: DMS MakeExpand
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerServiceTest, MakeExpand01, Function | SmallTest | Level3)
{
std::vector<ScreenId> expandScreenIds{1};
std::vector<Point> startPoints(1);
ScreenId screenGroupId = 3;
auto ret = dms_->MakeExpand(expandScreenIds, startPoints, screenGroupId);
ASSERT_NE(ret, DMError::DM_ERROR_INVALID_PARAM);
}
/**
* @tc.name: MakeExpand
* @tc.desc: DMS MakeExpand
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerServiceTest, MakeExpand02, Function | SmallTest | Level3)
{
std::vector<ScreenId> expandScreenIds{1, 2, 3, 4, 5};
std::vector<Point> startPoints(1);
ScreenId screenGroupId = 3;
auto ret = dms_->MakeExpand(expandScreenIds, startPoints, screenGroupId);
ASSERT_NE(ret, DMError::DM_ERROR_NOT_SYSTEM_APP);
}
/**
* @tc.name: StopExpand
* @tc.desc: DMS StopExpand
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerServiceTest, StopExpand, Function | SmallTest | Level3)
{
std::vector<ScreenId> expandScreenIds{0, 1, 2, 3, 4, 5};
auto ret = dms_->StopExpand(expandScreenIds);
ASSERT_EQ(ret, DMError::DM_OK);
}
} }
} // namespace Rosen } // namespace Rosen
} // namespace OHOS } // namespace OHOS

View File

@ -31,7 +31,7 @@ using namespace testing::ext;
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr uint32_t SLEEP_TIME_IN_US = 100000; // 100ms constexpr uint32_t SLEEP_TIME_IN_US = 100000; // 100ms
} }
using RemoteMocker = MockIRemoteObject; using RemoteMocker = MockIRemoteObject;
class DisplayManagerStubTest : public testing::Test { class DisplayManagerStubTest : public testing::Test {

View File

@ -26,7 +26,7 @@ using namespace testing::ext;
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr uint32_t SLEEP_TIME_US = 2000000; constexpr uint32_t SLEEP_TIME_US = 2000000;
} }
class ScreenRotationControllerTest : public testing::Test { class ScreenRotationControllerTest : public testing::Test {
public: public:

View File

@ -20,7 +20,7 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionClientStubImpl"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionClientStubImpl"};
} }
void WindowExtensionClientStubImpl::OnWindowReady(const std::shared_ptr<RSSurfaceNode>& surfaceNode) void WindowExtensionClientStubImpl::OnWindowReady(const std::shared_ptr<RSSurfaceNode>& surfaceNode)

View File

@ -32,7 +32,7 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionConnection"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionConnection"};
} }
class WindowExtensionConnection::Impl : public AAFwk::AbilityConnectionStub { class WindowExtensionConnection::Impl : public AAFwk::AbilityConnectionStub {

View File

@ -22,7 +22,7 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionProxy"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionProxy"};
} }
void WindowExtensionClientProxy::OnWindowReady(const std::shared_ptr<RSSurfaceNode>& surfaceNode) void WindowExtensionClientProxy::OnWindowReady(const std::shared_ptr<RSSurfaceNode>& surfaceNode)

View File

@ -20,7 +20,7 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionClientStub"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionClientStub"};
} }
int WindowExtensionClientStub::OnRemoteRequest(uint32_t code, MessageParcel& data, int WindowExtensionClientStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
MessageParcel& reply, MessageOption& option) MessageParcel& reply, MessageOption& option)

View File

@ -61,4 +61,9 @@ ohos_shared_library("libmodal_system_ui_extension_client") {
innerapi_tags = [ "platformsdk_indirect" ] innerapi_tags = [ "platformsdk_indirect" ]
part_name = "window_manager" part_name = "window_manager"
subsystem_name = "window" subsystem_name = "window"
defines = []
if (build_variant == "user") {
defines += [ "IS_RELEASE_VERSION" ]
}
} }

View File

@ -83,6 +83,11 @@ ohos_shared_library("libwindow_extension") {
part_name = "window_manager" part_name = "window_manager"
subsystem_name = "window" subsystem_name = "window"
defines = []
if (build_variant == "user") {
defines += [ "IS_RELEASE_VERSION" ]
}
} }
config("window_extension_module_private_config") { config("window_extension_module_private_config") {

View File

@ -35,7 +35,7 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "JSWindowExtension"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "JSWindowExtension"};
} }
int JsWindowExtension::extensionCnt_ = 0; int JsWindowExtension::extensionCnt_ = 0;

View File

@ -31,9 +31,9 @@ namespace Rosen {
using namespace AbilityRuntime; using namespace AbilityRuntime;
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "JSWindowExtensionContext"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "JSWindowExtensionContext"};
std::shared_ptr<AppExecFwk::EventHandler> handler_; std::shared_ptr<AppExecFwk::EventHandler> handler_;
constexpr int32_t MIN_ARG_COUNT = 2; constexpr int32_t MIN_ARG_COUNT = 2;
} }
napi_value NapiGetUndefined(napi_env env) napi_value NapiGetUndefined(napi_env env)

View File

@ -22,7 +22,7 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtension"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtension"};
} }
WindowExtension* WindowExtension::Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime) WindowExtension* WindowExtension::Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime)

View File

@ -23,7 +23,7 @@ namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionContext"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionContext"};
} }
const size_t WindowExtensionContext::CONTEXT_TYPE_ID(std::hash<const char*> {} ("WindowExtensionContext")); const size_t WindowExtensionContext::CONTEXT_TYPE_ID(std::hash<const char*> {} ("WindowExtensionContext"));

View File

@ -20,7 +20,7 @@
namespace OHOS::Rosen { namespace OHOS::Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionStub"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionStub"};
} }
WindowExtensionModuleLoader::WindowExtensionModuleLoader() = default; WindowExtensionModuleLoader::WindowExtensionModuleLoader() = default;
WindowExtensionModuleLoader::~WindowExtensionModuleLoader() = default; WindowExtensionModuleLoader::~WindowExtensionModuleLoader() = default;

View File

@ -24,7 +24,7 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionStubImpl"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionStubImpl"};
} }
WindowExtensionStubImpl::WindowExtensionStubImpl(const std::string& windowName) : windowName_(windowName) WindowExtensionStubImpl::WindowExtensionStubImpl(const std::string& windowName) : windowName_(windowName)

View File

@ -23,7 +23,7 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionProxy"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionProxy"};
} }
void WindowExtensionProxy::SetBounds(const Rect& rect) void WindowExtensionProxy::SetBounds(const Rect& rect)

View File

@ -19,7 +19,7 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionStub"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionStub"};
} }
int WindowExtensionStub::OnRemoteRequest(uint32_t code, MessageParcel& data, int WindowExtensionStub::OnRemoteRequest(uint32_t code, MessageParcel& data,

View File

@ -79,15 +79,36 @@ ohos_unittest("extension_window_extension_context_test") {
## Build window_extension_unittest_common.a {{{ ## Build window_extension_unittest_common.a {{{
config("window_extension_unittest_common_public_config") { config("window_extension_unittest_common_public_config") {
include_dirs = [ include_dirs = [
"../../../../interfaces/innerkits/wm",
"../../../../window_scene/session/host/include",
"../../../../wm/include",
"../../include", "../../include",
"../../include/zidl", "../../include/zidl",
"../../../extension_connection/include", "../../../extension_connection/include",
"../../../extension_connection/include/zidl", "../../../extension_connection/include/zidl",
"../../../../interfaces/innerkits/extension", "../../../../interfaces/innerkits/extension",
"${window_base_path}/test/common/mock",
"${window_base_path}/dm/include",
"${window_base_path}/dmserver/include",
"${window_base_path}/wm/include",
"${window_base_path}/wm/include/zidl",
"${window_base_path}/wm/test/mock",
"${window_base_path}/wmserver/include",
"${window_base_path}/wmserver/include/window_snapshot",
"${window_base_path}/interfaces/innerkits/wm",
"${window_base_path}/utils/include",
"${window_base_path}/window_scene",
"${window_base_path}/window_scene/test/mock",
"${window_base_path}/window_scene/session/host/include/zidl",
"//third_party/googletest/googlemock/include", "//third_party/googletest/googlemock/include",
# for abilityContext
"${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
"//third_party/node/deps/icu-small/source/common",
"${ability_runtime_inner_api_path}/ability_manager/include",
"//foundation/ability/ability_base/interfaces/kits/native/configuration/include/",
# abilityContext end
"${accessibility_path}/interfaces/innerkits/common/include/",
] ]
} }
@ -102,10 +123,22 @@ ohos_static_library("window_extension_unittest_common") {
] ]
public_deps = [ public_deps = [
# need delete it for abilitycontext
"${ability_runtime_inner_api_path}/ability_manager:ability_manager",
"${arkui_path}/ace_engine/interfaces/inner_api/ace:ace_uicontent",
"${arkui_path}/napi:ace_napi",
"${window_base_path}/dm:libdm",
"${window_base_path}/dmserver:libdms",
"${window_base_path}/utils:libwmutil",
"${window_base_path}/utils:libwmutil_base",
"${window_base_path}/window_scene/common:window_scene_common",
"${window_base_path}/window_scene/session:scene_session",
"${window_base_path}/window_scene/session_manager:scene_session_manager",
"${window_base_path}/wm:libwm", "${window_base_path}/wm:libwm",
"${window_base_path}/wm:libwm_lite",
"${window_base_path}/wmserver:libwms",
"//commonlibrary/c_utils/base:utils", "//commonlibrary/c_utils/base:utils",
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
"//foundation/multimedia/image_framework/interfaces/innerkits:image_native",
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client",
"//third_party/googletest:gmock", "//third_party/googletest:gmock",
"//third_party/googletest:gtest_main", "//third_party/googletest:gtest_main",
@ -120,6 +153,10 @@ ohos_static_library("window_extension_unittest_common") {
] ]
external_deps = [ external_deps = [
"ability_base:configuration",
"ability_base:want",
"ability_runtime:ability_context_native",
"accessibility:accessibility_common",
"c_utils:utils", "c_utils:utils",
"hilog:libhilog", "hilog:libhilog",
"input:libmmi-client", "input:libmmi-client",

View File

@ -21,6 +21,7 @@
#include "window_extension_client_interface.h" #include "window_extension_client_interface.h"
#include "window_extension_client_stub_impl.h" #include "window_extension_client_stub_impl.h"
#include "mock_message_parcel.h" #include "mock_message_parcel.h"
#include "iremote_object_mocker.h"
using namespace testing; using namespace testing;
using namespace testing::ext; using namespace testing::ext;
@ -35,7 +36,7 @@ public:
void TearDown() override; void TearDown() override;
sptr<WindowExtensionStub> mockWindowExtensionStub_; sptr<WindowExtensionStub> mockWindowExtensionStub_;
sptr<WindowExtensionProxy> windowExtensionProxy_; sptr<WindowExtensionProxy> windowExtensionProxy_;
sptr<IRemoteObject> impl; sptr<IRemoteObject> impl_;
sptr<WindowExtensionClientProxy> windowExtensionClientProxy_; sptr<WindowExtensionClientProxy> windowExtensionClientProxy_;
}; };
@ -51,8 +52,9 @@ void WindowExtensionProxyTest::SetUp()
{ {
mockWindowExtensionStub_ = new WindowExtensionStubImpl("name"); mockWindowExtensionStub_ = new WindowExtensionStubImpl("name");
windowExtensionProxy_ = new WindowExtensionProxy(mockWindowExtensionStub_); windowExtensionProxy_ = new WindowExtensionProxy(mockWindowExtensionStub_);
impl = nullptr; impl_ = new IRemoteObjectMocker();
windowExtensionClientProxy_ = new WindowExtensionClientProxy(impl); ASSERT_NE(nullptr, impl_);
windowExtensionClientProxy_ = new WindowExtensionClientProxy(impl_);
} }
void WindowExtensionProxyTest::TearDown() void WindowExtensionProxyTest::TearDown()
@ -90,6 +92,10 @@ HWTEST_F(WindowExtensionProxyTest, OnWindowReady, Function | SmallTest | Level2)
MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false); MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false);
windowExtensionClientProxy_->OnWindowReady(nullptr); windowExtensionClientProxy_->OnWindowReady(nullptr);
struct RSSurfaceNodeConfig config;
auto surfaceNode = RSSurfaceNode::Create(config);
windowExtensionClientProxy_->OnWindowReady(surfaceNode);
} }
/** /**
@ -102,6 +108,8 @@ HWTEST_F(WindowExtensionProxyTest, OnBackPress, Function | SmallTest | Level2)
ASSERT_NE(nullptr, windowExtensionClientProxy_); ASSERT_NE(nullptr, windowExtensionClientProxy_);
MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
windowExtensionClientProxy_->OnBackPress(); windowExtensionClientProxy_->OnBackPress();
MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false);
windowExtensionClientProxy_->OnBackPress();
} }
/** /**
@ -116,6 +124,9 @@ HWTEST_F(WindowExtensionProxyTest, OnKeyEvent, Function | SmallTest | Level2)
ASSERT_NE(nullptr, keyEvent); ASSERT_NE(nullptr, keyEvent);
MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
windowExtensionClientProxy_->OnKeyEvent(keyEvent); windowExtensionClientProxy_->OnKeyEvent(keyEvent);
MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false);
windowExtensionClientProxy_->OnKeyEvent(keyEvent);
} }
/** /**
@ -130,6 +141,9 @@ HWTEST_F(WindowExtensionProxyTest, OnPointerEvent, Function | SmallTest | Level2
ASSERT_NE(nullptr, pointerEvent); ASSERT_NE(nullptr, pointerEvent);
MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
windowExtensionClientProxy_->OnPointerEvent(pointerEvent); windowExtensionClientProxy_->OnPointerEvent(pointerEvent);
MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false);
windowExtensionClientProxy_->OnPointerEvent(pointerEvent);
} }
/** /**

View File

@ -20,6 +20,7 @@
#include "window_extension_client_interface.h" #include "window_extension_client_interface.h"
#include "window_extension_client_stub_impl.h" #include "window_extension_client_stub_impl.h"
#include "iremote_object_mocker.h" #include "iremote_object_mocker.h"
#include "window_extension_session_impl.h"
using namespace testing; using namespace testing;
using namespace testing::ext; using namespace testing::ext;
@ -85,16 +86,27 @@ HWTEST_F(WindowExtensionStubImplTest, CreateWindow, Function | SmallTest | Level
*/ */
HWTEST_F(WindowExtensionStubImplTest, SetBounds, Function | SmallTest | Level2) HWTEST_F(WindowExtensionStubImplTest, SetBounds, Function | SmallTest | Level2)
{ {
WindowExtensionStubImpl windowExtensionStubImpl("WindowExtensionStubImplTest_SetBounds"); WindowExtensionStubImpl windowExtensionStubImpl("windowName");
sptr<WindowOption> option = new WindowOption(); Rect rect = { 150, 150, 400, 600 };
windowExtensionStubImpl.SetBounds(rect);
sptr<WindowOption> option = new(std::nothrow) WindowOption();
ASSERT_NE(nullptr, option); ASSERT_NE(nullptr, option);
option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT); option->SetWindowRect(rect);
option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); sptr<WindowExtensionSessionImpl> window = new(std::nothrow) WindowExtensionSessionImpl(option);
Rect baseWindowRect = { 150, 150, 400, 600 };
option->SetWindowRect(baseWindowRect);
sptr<Window> window = Window::Create("WindowExtensionStubImplTest_SetBounds", option, nullptr);
ASSERT_NE(nullptr, window); ASSERT_NE(nullptr, window);
windowExtensionStubImpl.SetBounds(baseWindowRect); window->property_->SetWindowRect(rect);
windowExtensionStubImpl.window_ = window;
windowExtensionStubImpl.SetBounds(rect);
Rect rect2 = { 100, 100, 200, 300 };
windowExtensionStubImpl.SetBounds(rect2);
rect2 = { 100, 150, 200, 600 };
windowExtensionStubImpl.SetBounds(rect2);
rect2 = { 150, 100, 400, 300 };
windowExtensionStubImpl.SetBounds(rect2);
} }
/** /**
@ -105,9 +117,14 @@ HWTEST_F(WindowExtensionStubImplTest, SetBounds, Function | SmallTest | Level2)
HWTEST_F(WindowExtensionStubImplTest, Hide, Function | SmallTest | Level2) HWTEST_F(WindowExtensionStubImplTest, Hide, Function | SmallTest | Level2)
{ {
WindowExtensionStubImpl windowExtensionStubImpl("windowName"); WindowExtensionStubImpl windowExtensionStubImpl("windowName");
auto window = windowExtensionStubImpl.window_.promote();
windowExtensionStubImpl.Hide(); windowExtensionStubImpl.Hide();
ASSERT_EQ(windowExtensionStubImpl.window_.promote(), windowExtensionStubImpl.GetWindow());
sptr<WindowOption> option = new(std::nothrow) WindowOption();
ASSERT_NE(nullptr, option);
sptr<WindowExtensionSessionImpl> window = new(std::nothrow) WindowExtensionSessionImpl(option);
ASSERT_NE(nullptr, window);
windowExtensionStubImpl.window_ = window;
windowExtensionStubImpl.Hide();
} }
/** /**
@ -118,9 +135,14 @@ HWTEST_F(WindowExtensionStubImplTest, Hide, Function | SmallTest | Level2)
HWTEST_F(WindowExtensionStubImplTest, Show, Function | SmallTest | Level2) HWTEST_F(WindowExtensionStubImplTest, Show, Function | SmallTest | Level2)
{ {
WindowExtensionStubImpl windowExtensionStubImpl("windowName"); WindowExtensionStubImpl windowExtensionStubImpl("windowName");
auto window = windowExtensionStubImpl.window_.promote();
windowExtensionStubImpl.Show(); windowExtensionStubImpl.Show();
ASSERT_EQ(windowExtensionStubImpl.window_.promote(), windowExtensionStubImpl.GetWindow());
sptr<WindowOption> option = new(std::nothrow) WindowOption();
ASSERT_NE(nullptr, option);
sptr<WindowExtensionSessionImpl> window = new(std::nothrow) WindowExtensionSessionImpl(option);
ASSERT_NE(nullptr, window);
windowExtensionStubImpl.window_ = window;
windowExtensionStubImpl.Show();
} }
/** /**
@ -131,9 +153,14 @@ HWTEST_F(WindowExtensionStubImplTest, Show, Function | SmallTest | Level2)
HWTEST_F(WindowExtensionStubImplTest, RequestFocus, Function | SmallTest | Level2) HWTEST_F(WindowExtensionStubImplTest, RequestFocus, Function | SmallTest | Level2)
{ {
WindowExtensionStubImpl windowExtensionStubImpl("windowName"); WindowExtensionStubImpl windowExtensionStubImpl("windowName");
auto window = windowExtensionStubImpl.window_.promote();
windowExtensionStubImpl.RequestFocus(); windowExtensionStubImpl.RequestFocus();
ASSERT_EQ(windowExtensionStubImpl.window_.promote(), windowExtensionStubImpl.GetWindow());
sptr<WindowOption> option = new(std::nothrow) WindowOption();
ASSERT_NE(nullptr, option);
sptr<WindowExtensionSessionImpl> window = new(std::nothrow) WindowExtensionSessionImpl(option);
ASSERT_NE(nullptr, window);
windowExtensionStubImpl.window_ = window;
windowExtensionStubImpl.RequestFocus();
} }
/** /**

View File

@ -560,6 +560,14 @@ public:
*/ */
void SetFoldDisplayMode(const FoldDisplayMode mode); void SetFoldDisplayMode(const FoldDisplayMode mode);
/**
* @brief Change the display mode of the foldable device from js.
*
* @param mode target display mode to change.
* @return DM_OK means set success, others means set failed.
*/
DMError SetFoldDisplayModeFromJs(const FoldDisplayMode mode);
/** /**
* @brief Set display scale. * @brief Set display scale.
* *
@ -578,6 +586,14 @@ public:
*/ */
void SetFoldStatusLocked(bool locked); void SetFoldStatusLocked(bool locked);
/**
* @brief Locked fold status from js.
*
* @param locked locked fold status is locked.
* @return DM_OK means set success, others means set failed.
*/
DMError SetFoldStatusLockedFromJs(bool locked);
/** /**
* @brief Get the fold crease region in the current display mode. * @brief Get the fold crease region in the current display mode.
* *

View File

@ -26,13 +26,14 @@ using DisplayId = uint64_t;
using ScreenId = uint64_t; using ScreenId = uint64_t;
namespace { namespace {
constexpr DisplayId DISPLAY_ID_INVALID = -1ULL; constexpr DisplayId DISPLAY_ID_INVALID = -1ULL;
constexpr ScreenId SCREEN_ID_INVALID = -1ULL; constexpr ScreenId SCREEN_ID_INVALID = -1ULL;
constexpr int DOT_PER_INCH = 160; constexpr ScreenId ERROR_ID_NOT_SYSTEM_APP = -202ULL;
const static std::string DEFAULT_SCREEN_NAME = "buildIn"; constexpr int DOT_PER_INCH = 160;
constexpr int DOT_PER_INCH_MAXIMUM_VALUE = 640; const static std::string DEFAULT_SCREEN_NAME = "buildIn";
constexpr int DOT_PER_INCH_MINIMUM_VALUE = 80; constexpr int DOT_PER_INCH_MAXIMUM_VALUE = 640;
constexpr uint32_t BASELINE_DENSITY = 160; constexpr int DOT_PER_INCH_MINIMUM_VALUE = 80;
constexpr uint32_t BASELINE_DENSITY = 160;
} }
/** /**
@ -44,6 +45,8 @@ struct DMHookInfo {
uint32_t width_; uint32_t width_;
uint32_t height_; uint32_t height_;
float_t density_; float_t density_;
uint32_t rotation_;
bool enableHookRotation_;
}; };
/** /**
@ -366,6 +369,13 @@ enum class ScreenCombination : uint32_t {
SCREEN_EXPAND, SCREEN_EXPAND,
SCREEN_MIRROR, SCREEN_MIRROR,
SCREEN_UNIQUE, SCREEN_UNIQUE,
SCREEN_EXTAND,
SCREEN_MAIN,
};
enum class MultiScreenMode : uint32_t {
SCREEN_MIRROR = 0,
SCREEN_EXTAND = 1,
}; };
struct Point { struct Point {
@ -388,7 +398,7 @@ struct ExpandOption {
uint32_t startY_; uint32_t startY_;
}; };
struct ExtendOption { struct MultiScreenPositionOptions {
ScreenId screenId_; ScreenId screenId_;
uint32_t startX_; uint32_t startX_;
uint32_t startY_; uint32_t startY_;

View File

@ -117,21 +117,21 @@ public:
* *
* @param mainScreenId Main screen id. * @param mainScreenId Main screen id.
* @param secondaryScreenId secondary screen id. * @param secondaryScreenId secondary screen id.
* @param secondaryScreenMode Screen Combination Mode. * @param screenMode Screen Combination Mode.
* @return DM_OK means make mirror success, others means make mirror failed. * @return DM_OK means make mirror success, others means make mirror failed.
*/ */
DMError MultiScreenModeSwitch(ScreenId mainScreenId, ScreenId secondaryScreenId, DMError SetMultiScreenMode(ScreenId mainScreenId, ScreenId secondaryScreenId,
ScreenSourceMode secondaryScreenMode); MultiScreenMode screenMode);
/** /**
* @brief Set Screen Relative Position * @brief Set Screen Relative Position
* *
* @param mainScreenOption Main screen id and position. * @param mainScreenOptions Main screen id and position.
* @param secondaryScreenOption secondary screen id and position. * @param secondScreenOption secondary screen id and position.
* @return DM_OK means make mirror success, others means make mirror failed. * @return DM_OK means make mirror success, others means make mirror failed.
*/ */
DMError MultiScreenRelativePosition(ExtendOption mainScreenOption, DMError SetMultiScreenRelativePosition(MultiScreenPositionOptions mainScreenOptions,
ExtendOption secondaryScreenOption); MultiScreenPositionOptions secondScreenOption);
/** /**
* @brief Make screens as unique-screen. * @brief Make screens as unique-screen.

View File

@ -29,11 +29,11 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
const std::string RECT_FORM_KEY_POS_X = "ext_pos_x"; const std::string RECT_FORM_KEY_POS_X = "ext_pos_x";
const std::string RECT_FORM_KEY_POS_Y = "ext_pos_y"; const std::string RECT_FORM_KEY_POS_Y = "ext_pos_y";
const std::string RECT_FORM_KEY_HEIGHT = "ext_pos_heigh"; const std::string RECT_FORM_KEY_HEIGHT = "ext_pos_heigh";
const std::string RECT_FORM_KEY_WIDTH = "ext_pos_width"; const std::string RECT_FORM_KEY_WIDTH = "ext_pos_width";
const std::string WINDOW_ID = "ext_window_id"; const std::string WINDOW_ID = "ext_window_id";
} }
class RSSurfaceNode; class RSSurfaceNode;

View File

@ -28,31 +28,31 @@
typedef struct napi_env__* napi_env; typedef struct napi_env__* napi_env;
typedef struct napi_value__* napi_value; typedef struct napi_value__* napi_value;
namespace OHOS::MMI { namespace OHOS::MMI {
class PointerEvent; class PointerEvent;
class KeyEvent; class KeyEvent;
class AxisEvent; class AxisEvent;
} }
namespace OHOS::AppExecFwk { namespace OHOS::AppExecFwk {
class Configuration; class Configuration;
class Ability; class Ability;
} }
namespace OHOS::AbilityRuntime { namespace OHOS::AbilityRuntime {
class AbilityContext; class AbilityContext;
class Context; class Context;
} }
namespace OHOS::AAFwk { namespace OHOS::AAFwk {
class Want; class Want;
class WantParams; class WantParams;
} }
namespace OHOS::Ace { namespace OHOS::Ace {
class UIContent; class UIContent;
} }
namespace OHOS::Media { namespace OHOS::Media {
class PixelMap; class PixelMap;
} }
namespace OHOS::Accessibility { namespace OHOS::Accessibility {
@ -461,6 +461,21 @@ public:
virtual void OnSubWindowClose(bool& terminateCloseProcess) {} virtual void OnSubWindowClose(bool& terminateCloseProcess) {}
}; };
/**
* @class ISwitchFreeMultiWindowListener
*
* @brief ISwitchFreeMultiWindowListener is used to observe the free multi window state when it changed.
*/
class ISwitchFreeMultiWindowListener : virtual public RefBase {
public:
/**
* @brief Notify caller when free multi window state changed.
*
* @param enable Whether free multi window state enabled.
*/
virtual void OnSwitchFreeMultiWindow(bool enable) {}
};
/** /**
* @class IKeyboardPanelInfoChangeListener * @class IKeyboardPanelInfoChangeListener
* *
@ -823,7 +838,7 @@ public:
* @param y * @param y
* @return WMError * @return WMError
*/ */
virtual WMError MoveTo(int32_t x, int32_t y) { return WMError::WM_OK; } virtual WMError MoveTo(int32_t x, int32_t y, bool isMoveToGlobal = false) { return WMError::WM_OK; }
/** /**
* @brief move the window to (x, y) * @brief move the window to (x, y)
* *
@ -963,7 +978,7 @@ public:
* *
* @return WM_OK means raise success, others means raise failed. * @return WM_OK means raise success, others means raise failed.
*/ */
virtual WmErrorCode RaiseToAppTop() { return WmErrorCode::WM_OK; } virtual WMError RaiseToAppTop() { return WMError::WM_OK; }
/** /**
* @brief Set skip flag of snapshot. * @brief Set skip flag of snapshot.
* *
@ -1631,7 +1646,7 @@ public:
* *
* @return WM_OK means raise success, others means raise failed. * @return WM_OK means raise success, others means raise failed.
*/ */
virtual WmErrorCode RaiseAboveTarget(int32_t subWindowId) { return WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT; } virtual WMError RaiseAboveTarget(int32_t subWindowId) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; }
/** /**
* @brief Hide non-system floating windows. * @brief Hide non-system floating windows.
@ -1999,6 +2014,24 @@ public:
virtual WMError UnregisterSubWindowCloseListeners( virtual WMError UnregisterSubWindowCloseListeners(
const sptr<ISubWindowCloseListener>& listener) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } const sptr<ISubWindowCloseListener>& listener) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; }
/**
* @brief Register switch free multi-window listener.
*
* @param listener ISwitchFreeMultiWindowListener.
* @return WM_OK means register success, others means register failed.
*/
virtual WMError RegisterSwitchFreeMultiWindowListener(
const sptr<ISwitchFreeMultiWindowListener>& listener) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; }
/**
* @brief Unregister switch free multi-window listener.
*
* @param listener ISwitchFreeMultiWindowListener.
* @return WM_OK means unregister success, others means unregister failed.
*/
virtual WMError UnregisterSwitchFreeMultiWindowListener(
const sptr<ISwitchFreeMultiWindowListener>& listener) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; }
/** /**
* @brief Set Shaped Window Mask. * @brief Set Shaped Window Mask.
* *
@ -2166,24 +2199,26 @@ public:
*/ */
virtual WMError SetContinueState(int32_t continueState) { return WMError::WM_DO_NOTHING; } virtual WMError SetContinueState(int32_t continueState) { return WMError::WM_DO_NOTHING; }
/**
* @brief Set the parent window of sub window created by UIExtension
*
* @param parent window
*/
virtual void SetParentExtensionWindow(const wptr<Window>& parentExtensionWindow) {}
/**
* @brief Notify the window that set UI content complete
*/
virtual void NotifySetUIContent() {}
/** /**
* @brief Notify host that UIExtension timeout * @brief Notify host that UIExtension timeout
* *
* @param errorCode error code when UIExtension timeout * @param errorCode error code when UIExtension timeout
*/ */
virtual void NotifyExtensionTimeout(int32_t errorCode) {} virtual void NotifyExtensionTimeout(int32_t errorCode) {}
/*
* @brief Get the real parent id of UIExtension
*
* @return Real parent id of UIExtension
*/
virtual int32_t GetRealParentId() const { return static_cast<int32_t>(INVALID_WINDOW_ID); }
/**
* @brief Notify modal UIExtension it may be covered
*
* @param byLoadContent True when called by loading content, false when called by creating non topmost subwindow
*/
virtual void NotifyModalUIExtensionMayBeCovered(bool byLoadContent) {}
}; };
} }
} }

View File

@ -618,12 +618,12 @@ public:
*/ */
WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) const; WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) const;
/** /**
* @brief Set gesture navigaion enabled. * @brief Set gesture navigation enabled.
* *
* @param enable True means set gesture on, false means set gesture off. * @param enable True means set gesture on, false means set gesture off.
* @return WM_OK means set success, others means set failed. * @return WM_OK means set success, others means set failed.
*/ */
WMError SetGestureNavigaionEnabled(bool enable) const; WMError SetGestureNavigationEnabled(bool enable) const;
/** /**
* @brief Get focus window. * @brief Get focus window.

View File

@ -265,6 +265,13 @@ public:
*/ */
void SetWindowTopmost(bool isTopmost); void SetWindowTopmost(bool isTopmost);
/**
* @brief Set real parent id of UIExtension
*
* @param realParentId real parent id of UIExtension
*/
void SetRealParentId(int32_t realParentId);
/** /**
* @brief Get window rect. * @brief Get window rect.
* *
@ -447,6 +454,13 @@ public:
*/ */
bool GetWindowTopmost() const; bool GetWindowTopmost() const;
/**
* @brief Get the real parent id of UIExtension
*
* @return Return the real parent id of UIExtension
*/
int32_t GetRealParentId() const;
private: private:
Rect windowRect_ { 0, 0, 0, 0 }; Rect windowRect_ { 0, 0, 0, 0 };
WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
@ -474,11 +488,16 @@ private:
std::string subWindowTitle_ = { "" }; std::string subWindowTitle_ = { "" };
bool subWindowDecorEnable_ = false; bool subWindowDecorEnable_ = false;
bool onlySupportSceneBoard_ = false; bool onlySupportSceneBoard_ = false;
bool isExtensionTag_ = false;
uint32_t uiExtensionUsage_ = static_cast<uint32_t>(UIExtensionUsage::EMBEDDED);
bool dialogDecorEnable_ = false; bool dialogDecorEnable_ = false;
std::string dialogTitle_ = { "" }; std::string dialogTitle_ = { "" };
bool isTopmost_ = false; bool isTopmost_ = false;
/*
* UIExtension
*/
int32_t realParentId_ = INVALID_WINDOW_ID;
uint32_t uiExtensionUsage_ = static_cast<uint32_t>(UIExtensionUsage::EMBEDDED);
bool isExtensionTag_ = false;
}; };
} // namespace Rosen } // namespace Rosen
} // namespace OHOS } // namespace OHOS

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -18,15 +18,12 @@
#include <mutex> #include <mutex>
#include <refbase.h>
#include <iremote_object.h>
#include "window.h" #include "window.h"
#include "window_option.h" #include "window_option.h"
#include "wm_common.h" #include "wm_common.h"
namespace OHOS::AppExecFwk { namespace OHOS::AppExecFwk {
class Configuration; class Configuration;
} }
namespace OHOS { namespace OHOS {
@ -166,24 +163,18 @@ public:
public: public:
static const DisplayId DEFAULT_DISPLAY_ID = 0; static const DisplayId DEFAULT_DISPLAY_ID = 0;
static const std::string MAIN_WINDOW_ID;
private: private:
/** void OnLastStrongRef(const void *) override;
* @param context the context of a main window
* @return the name of main window
*/
std::string GenerateMainWindowName(const std::shared_ptr<AbilityRuntime::Context>& context) const;
private: private:
mutable std::mutex mainWindowMutex_; mutable std::mutex mainWindowMutex_;
sptr<Window> mainWindow_ = nullptr; sptr<Window> mainWindow_ = nullptr;
// Above guarded by mainWindowMutex_ // Above guarded by mainWindowMutex_
static inline std::atomic<uint32_t> count { 0 }; uint32_t mainWindowId_ = 0;
DisplayId displayId_ = DEFAULT_DISPLAY_ID;
std::shared_ptr<AbilityRuntime::Context> context_ = nullptr;
}; };
} // namespace Rosen } // namespace Rosen
} // namespace OHOS } // namespace OHOS
#endif // INTERFACES_INNERKITS_WINDOW_SCENE_H #endif // INTERFACES_INNERKITS_WINDOW_SCENE_H

View File

@ -96,6 +96,19 @@ enum class WindowType : uint32_t {
WINDOW_TYPE_UI_EXTENSION = 3000 WINDOW_TYPE_UI_EXTENSION = 3000
}; };
/**
* @struct HookInfo.
*
* @brief hook diaplayinfo deepending on the window size.
*/
struct HookInfo {
uint32_t width_;
uint32_t height_;
float_t density_;
uint32_t rotation_;
bool enableHookRotation_;
};
/** /**
* @brief Enumerates mode of window. * @brief Enumerates mode of window.
*/ */
@ -352,6 +365,7 @@ enum class WindowSizeChangeReason : uint32_t {
PIP_SHOW, PIP_SHOW,
PIP_AUTO_START, PIP_AUTO_START,
PIP_RATIO_CHANGE, PIP_RATIO_CHANGE,
PIP_RESTORE,
UPDATE_DPI_SYNC, UPDATE_DPI_SYNC,
END, END,
}; };
@ -495,6 +509,8 @@ namespace {
constexpr int32_t SYSTEM_USERID = 0; constexpr int32_t SYSTEM_USERID = 0;
constexpr int32_t BASE_USER_RANGE = 200000; constexpr int32_t BASE_USER_RANGE = 200000;
constexpr int32_t DEFAULT_SCREEN_ID = 0; constexpr int32_t DEFAULT_SCREEN_ID = 0;
constexpr int32_t FULL_CIRCLE_DEGREE = 360;
constexpr int32_t ONE_FOURTH_FULL_CIRCLE_DEGREE = 90;
} }
inline int32_t GetUserIdByUid(int32_t uid) inline int32_t GetUserIdByUid(int32_t uid)

View File

@ -24,15 +24,15 @@
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
namespace { namespace {
const std::map<DisplayState, DisplayStateMode> NATIVE_TO_CJ_DISPLAY_STATE_MAP { const std::map<DisplayState, DisplayStateMode> NATIVE_TO_CJ_DISPLAY_STATE_MAP {
{ DisplayState::UNKNOWN, DisplayStateMode::STATE_UNKNOWN }, { DisplayState::UNKNOWN, DisplayStateMode::STATE_UNKNOWN },
{ DisplayState::OFF, DisplayStateMode::STATE_OFF }, { DisplayState::OFF, DisplayStateMode::STATE_OFF },
{ DisplayState::ON, DisplayStateMode::STATE_ON }, { DisplayState::ON, DisplayStateMode::STATE_ON },
{ DisplayState::DOZE, DisplayStateMode::STATE_DOZE }, { DisplayState::DOZE, DisplayStateMode::STATE_DOZE },
{ DisplayState::DOZE_SUSPEND, DisplayStateMode::STATE_DOZE_SUSPEND }, { DisplayState::DOZE_SUSPEND, DisplayStateMode::STATE_DOZE_SUSPEND },
{ DisplayState::VR, DisplayStateMode::STATE_VR }, { DisplayState::VR, DisplayStateMode::STATE_VR },
{ DisplayState::ON_SUSPEND, DisplayStateMode::STATE_ON_SUSPEND }, { DisplayState::ON_SUSPEND, DisplayStateMode::STATE_ON_SUSPEND },
}; };
} }
static thread_local std::map<uint64_t, sptr<DisplayImpl>> g_cjDisplayMap; static thread_local std::map<uint64_t, sptr<DisplayImpl>> g_cjDisplayMap;
std::recursive_mutex g_mutex; std::recursive_mutex g_mutex;

View File

@ -348,7 +348,7 @@ int32_t FFiOHOSWindowSetGestureNavigationEnabled(bool enable)
{ {
TLOGI(WmsLogTag::WMS_DIALOG, "[Window] FFiOHOSWindowSetGestureNavigationEnabled start"); TLOGI(WmsLogTag::WMS_DIALOG, "[Window] FFiOHOSWindowSetGestureNavigationEnabled start");
WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at( WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(
SingletonContainer::Get<WindowManager>().SetGestureNavigaionEnabled(enable)); SingletonContainer::Get<WindowManager>().SetGestureNavigationEnabled(enable));
if (ret != WmErrorCode::WM_OK) { if (ret != WmErrorCode::WM_OK) {
TLOGE(WmsLogTag::WMS_DIALOG, "[Window] FFiOHOSWindowSetGestureNavigationEnabled error %{public}d", ret); TLOGE(WmsLogTag::WMS_DIALOG, "[Window] FFiOHOSWindowSetGestureNavigationEnabled error %{public}d", ret);
return static_cast<int32_t>(ret); return static_cast<int32_t>(ret);
@ -788,6 +788,18 @@ int32_t FfiOHOSOffKeyboardHeightChange(int64_t id)
return ret; return ret;
} }
int32_t FfiOHOSOnWindowEvent(int64_t id, int64_t callbackId)
{
TLOGI(WmsLogTag::WMS_DIALOG, "[Window] OnWindowEvent start");
auto instance = FFIData::GetData<CJWindowImpl>(id);
if (instance == nullptr) {
return WM_ERROR_STATE_ABNORMALLY;
}
int32_t ret = instance->OnRegisterWindowCallback("windowEvent", callbackId);
TLOGI(WmsLogTag::WMS_DIALOG, "[Window] OnWindowEvent success");
return ret;
}
// WindowStage // WindowStage
RetDataI64 FfiOHOSBindWindowStage(int64_t windowStageImplPtr) RetDataI64 FfiOHOSBindWindowStage(int64_t windowStageImplPtr)
{ {

View File

@ -87,6 +87,7 @@ extern "C" {
FFI_EXPORT int32_t FFiOHOSSetWindowColorSpace(int64_t id, uint32_t colorSpace); FFI_EXPORT int32_t FFiOHOSSetWindowColorSpace(int64_t id, uint32_t colorSpace);
FFI_EXPORT int32_t FfiOHOSOnKeyboardHeightChange(int64_t id, int64_t callbackId); FFI_EXPORT int32_t FfiOHOSOnKeyboardHeightChange(int64_t id, int64_t callbackId);
FFI_EXPORT int32_t FfiOHOSOffKeyboardHeightChange(int64_t id); FFI_EXPORT int32_t FfiOHOSOffKeyboardHeightChange(int64_t id);
FFI_EXPORT int32_t FfiOHOSOnWindowEvent(int64_t id, int64_t callbackId);
// WindowStage // WindowStage
FFI_EXPORT RetDataI64 FfiOHOSBindWindowStage(int64_t windowStageImplPtr); FFI_EXPORT RetDataI64 FfiOHOSBindWindowStage(int64_t windowStageImplPtr);

View File

@ -740,6 +740,7 @@ int32_t CJWindowImpl::SetResizeByDragEnabled(bool enable)
return static_cast<int32_t>(ret); return static_cast<int32_t>(ret);
} }
/** @note @window.hierarchy */
int32_t CJWindowImpl::RaiseToAppTop() int32_t CJWindowImpl::RaiseToAppTop()
{ {
ResWindow result = CheckWindow(); ResWindow result = CheckWindow();
@ -747,7 +748,7 @@ int32_t CJWindowImpl::RaiseToAppTop()
return result.ret; return result.ret;
} }
sptr<Window> weakWindow = result.nativeWindow; sptr<Window> weakWindow = result.nativeWindow;
WmErrorCode ret = weakWindow->RaiseToAppTop(); WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->RaiseToAppTop());
TLOGI(WmsLogTag::WMS_DIALOG, "Window [%{public}u, %{public}s] zorder raise success", TLOGI(WmsLogTag::WMS_DIALOG, "Window [%{public}u, %{public}s] zorder raise success",
weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str());
return static_cast<int32_t>(ret); return static_cast<int32_t>(ret);
@ -796,6 +797,7 @@ uint32_t CJWindowImpl::GetWindowColorSpace(int32_t* errCode)
return static_cast<uint32_t>(colorSpace); return static_cast<uint32_t>(colorSpace);
} }
/** @note @window.hierarchy */
int32_t CJWindowImpl::SetRaiseByClickEnabled(bool enable) int32_t CJWindowImpl::SetRaiseByClickEnabled(bool enable)
{ {
ResWindow result = CheckWindow(); ResWindow result = CheckWindow();
@ -809,6 +811,7 @@ int32_t CJWindowImpl::SetRaiseByClickEnabled(bool enable)
return static_cast<int32_t>(ret); return static_cast<int32_t>(ret);
} }
/** @note @window.hierarchy */
int32_t CJWindowImpl::RaiseAboveTarget(int32_t windowId) int32_t CJWindowImpl::RaiseAboveTarget(int32_t windowId)
{ {
ResWindow result = CheckWindow(); ResWindow result = CheckWindow();
@ -816,7 +819,7 @@ int32_t CJWindowImpl::RaiseAboveTarget(int32_t windowId)
return result.ret; return result.ret;
} }
sptr<Window> weakWindow = result.nativeWindow; sptr<Window> weakWindow = result.nativeWindow;
WmErrorCode ret = weakWindow->RaiseAboveTarget(windowId); WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->RaiseAboveTarget(windowId));
return static_cast<int32_t>(ret); return static_cast<int32_t>(ret);
} }

View File

@ -143,6 +143,7 @@ int32_t WindowManagerImpl::FindWindow(std::string name, int64_t& windowId)
} }
} }
/** @note @window.hierarchy */
int32_t WindowManagerImpl::GetLastWindow(OHOS::AbilityRuntime::Context* ctx, int64_t& id) int32_t WindowManagerImpl::GetLastWindow(OHOS::AbilityRuntime::Context* ctx, int64_t& id)
{ {
sptr<Window> window = nullptr; sptr<Window> window = nullptr;

View File

@ -74,6 +74,7 @@ FFI_EXPORT int FFiOHOSMinimize = 0;
FFI_EXPORT int FFiOHOSSetWindowColorSpace = 0; FFI_EXPORT int FFiOHOSSetWindowColorSpace = 0;
FFI_EXPORT int FfiOHOSOnKeyboardHeightChange = 0; FFI_EXPORT int FfiOHOSOnKeyboardHeightChange = 0;
FFI_EXPORT int FfiOHOSOffKeyboardHeightChange = 0; FFI_EXPORT int FfiOHOSOffKeyboardHeightChange = 0;
FFI_EXPORT int FfiOHOSOnWindowEvent = 0;
FFI_EXPORT int FfiOHOSBindWindowStage = 0; FFI_EXPORT int FfiOHOSBindWindowStage = 0;
FFI_EXPORT int FfiOHOSGetMainWindow = 0; FFI_EXPORT int FfiOHOSGetMainWindow = 0;
FFI_EXPORT int FfiOHOSCreateSubWindow = 0; FFI_EXPORT int FfiOHOSCreateSubWindow = 0;

View File

@ -104,7 +104,18 @@ WmErrorCode CjWindowRegisterManager::ProcessAvoidAreaChangeRegister(
WmErrorCode CjWindowRegisterManager::ProcessLifeCycleEventRegister( WmErrorCode CjWindowRegisterManager::ProcessLifeCycleEventRegister(
sptr<CjWindowListener> listener, sptr<Window> window, bool isRegister) sptr<CjWindowListener> listener, sptr<Window> window, bool isRegister)
{ {
return WmErrorCode::WM_OK; if (window == nullptr) {
TLOGE(WmsLogTag::WMS_SUB, "[WindowRegister] window is nullptr");
return WmErrorCode::WM_ERROR_STATE_ABNORMALLY;
}
sptr<IWindowLifeCycle> thisListener(listener);
WmErrorCode ret;
if (isRegister) {
ret = WM_JS_TO_ERROR_CODE_MAP.at(window->RegisterLifeCycleListener(thisListener));
} else {
ret = WM_JS_TO_ERROR_CODE_MAP.at(window->UnregisterLifeCycleListener(thisListener));
}
return ret;
} }
WmErrorCode CjWindowRegisterManager::ProcessOccupiedAreaChangeRegister( WmErrorCode CjWindowRegisterManager::ProcessOccupiedAreaChangeRegister(

View File

@ -155,6 +155,7 @@ int32_t CJWindowStageImpl::DisableWindowDecor()
return static_cast<int32_t>(WmErrorCode::WM_OK); return static_cast<int32_t>(WmErrorCode::WM_OK);
} }
/** @note @window.hierarchy */
int32_t CJWindowStageImpl::SetShowOnLockScreen(bool showOnLockScreen) int32_t CJWindowStageImpl::SetShowOnLockScreen(bool showOnLockScreen)
{ {
if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) { if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {

View File

@ -0,0 +1,36 @@
# Copyright (c) 2024 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("//build/ohos/ndk/ndk.gni")
import("../../../windowmanager_aafwk.gni")
ohos_ndk_headers("display_manager_header") {
dest_dir = "$ndk_headers_out_dir/window_manager"
sources = [
"oh_display_info.h",
"oh_display_manager.h",
]
}
ohos_ndk_library("native_display_manager") {
output_name = "native_display_manager"
output_extension = "so"
ndk_description_file = "./libdm.ndk.json"
system_capability = "SystemCapability.Window.SessionManager"
system_capability_headers = [
"oh_display_info.h",
"oh_display_manager.h",
]
min_compact_version = "12"
}

View File

@ -0,0 +1,204 @@
/*
* Copyright (c) 2024 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 OH_NATIVE_DISPLAY_INFO_H
#define OH_NATIVE_DISPLAY_INFO_H
/**
* @addtogroup OH_DisplayInfo
* @{
*
* @brief Defines the data structures for the C APIs of the display module.
*
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
* @version 1.0
*/
/**
* @file oh_display_info.h
*
* @brief Defines the data structures for the C APIs of the display module.
*
* @kit ArkUI
* @library libnative_display_manager.so
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
* @version 1.0
*/
#include "stdint.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Enumerates rotations.
*
* @since 12
* @version 1.0
*/
typedef enum {
/** device rotation 0 degree */
DISPLAY_MANAGER_ROTATION_0,
/** device rotation 90 degrees */
DISPLAY_MANAGER_ROTATION_90,
/** device rotation 180 degrees */
DISPLAY_MANAGER_ROTATION_180,
/** device rotation 270 degree */
DISPLAY_MANAGER_ROTATION_270,
} NativeDisplayManager_Rotation;
/**
* @brief Enumerates orientations.
*
* @since 12
* @version 1.0
*/
typedef enum {
/** device portrait show */
DISPLAY_MANAGER_PORTRAIT = 0,
/** device landscape show */
DISPLAY_MANAGER_LANDSCAPE = 1,
/** device portrait inverted show */
DISPLAY_MANAGER_PORTRAIT_INVERTED = 2,
/** device landscape inverted show */
DISPLAY_MANAGER_LANDSCAPE_INVERTED = 3,
/** device unknow show */
DISPLAY_MANAGER_UNKNOWN,
} NativeDisplayManager_Orientation;
/**
* @brief Enumerates the result types of the display manager interface.
*
* @since 12
* @version 1.0
*/
typedef enum {
/** @error Operation is successful */
DISPLAY_MANAGER_OK = 0,
/** @error Operation no permission */
DISPLAY_MANAGER_ERROR_NO_PERMISSION = 201,
/** @error Operation not system app */
DISPLAY_MANAGER_ERROR_NOT_SYSTEM_APP = 202,
/** @error Operation invalid param */
DISPLAY_MANAGER_ERROR_INVALID_PARAM = 401,
/** @error Operation device not supported */
DISPLAY_MANAGER_ERROR_DEVICE_NOT_SUPPORTED = 801,
/** @error Operation screen invalid */
DISPLAY_MANAGER_ERROR_INVALID_SCREEN = 1400001,
/** @error Operation invalid call */
DISPLAY_MANAGER_ERROR_INVALID_CALL = 1400002,
/** @error Operation system abnormal */
DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL = 1400003,
} NativeDisplayManager_ErrorCode;
/**
* @brief Enumerates the fold display mode.
*
* @since 12
* @version 1.0
*/
typedef enum {
/** display mode unknown */
DISPLAY_MANAGER_FOLD_DISPLAY_MODE_UNKNOWN = 0,
/** display mode full */
DISPLAY_MANAGER_FOLD_DISPLAY_MODE_FULL = 1,
/** display mode main */
DISPLAY_MANAGER_FOLD_DISPLAY_MODE_MAIN = 2,
/** display mode sub */
DISPLAY_MANAGER_FOLD_DISPLAY_MODE_SUB = 3,
/** display mode coordination */
DISPLAY_MANAGER_FOLD_DISPLAY_MODE_COORDINATION = 4,
} NativeDisplayManager_FoldDisplayMode;
/**
* @brief Defines the display rect data structure.
*
* @since 12
* @version 1.0
*/
typedef struct {
/* rect left */
int32_t left;
/* rect top */
int32_t top;
/* rect width */
uint32_t width;
/* rect height */
uint32_t height;
} NativeDisplayManager_Rect;
/**
* @brief Defines the display waterfallDisplayAreaRects data structure.
*
* @since 12
* @version 1.0
*/
typedef struct {
/* waterfall left rect */
NativeDisplayManager_Rect left;
/* waterfall top rect */
NativeDisplayManager_Rect top;
/* waterfall right rect */
NativeDisplayManager_Rect right;
/* waterfall bottom rect */
NativeDisplayManager_Rect bottom;
} NativeDisplayManager_WaterfallDisplayAreaRects;
/**
* @brief Defines the display cutout info data structure.
*
* @since 12
* @version 1.0
*/
typedef struct {
/* boundingRects length */
int32_t boundingRectsLength;
/* boundingRects info pointer */
NativeDisplayManager_Rect *boundingRects;
/* waterfallDisplayAreaRects info */
NativeDisplayManager_WaterfallDisplayAreaRects waterfallDisplayAreaRects;
} NativeDisplayManager_CutoutInfo;
#ifdef __cplusplus
}
#endif
/** @} */
#endif // OH_NATIVE_DISPLAY_INFO_H

View File

@ -0,0 +1,318 @@
/*
* Copyright (c) 2024 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 OH_NATIVE_DISPLAY_MANAGER_H
#define OH_NATIVE_DISPLAY_MANAGER_H
/**
* @addtogroup OH_DisplayManager
* @{
*
* @brief Defines the data structures for the C APIs of the display module.
*
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
* @version 1.0
*/
/**
* @file oh_display_manager.h
*
* @brief Defines the data structures for the C APIs of the display module.
*
* @kit ArkUI
* @library libnative_display_manager.so.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
* @version 1.0
*/
#include "oh_display_info.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Obtain the default display Id.
*
* @param { *displayId } Indicates the pointer to an <b>uint64_t</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayId(uint64_t *displayId);
/**
* @brief Obtain the default display width.
*
* @param { *displayWidth } Indicates the pointer to an <b>int32_t</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayWidth(int32_t *displayWidth);
/**
* @brief Obtain the default display height.
*
* @param { *displayHeight } Indicates the pointer to an <b>int32_t</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayHeight(int32_t *displayHeight);
/**
* @brief Obtain the default display rotation.
*
* @param { *displayRotation } Indicates the pointer to an <b>NativeDisplayManager_Rotation</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayRotation(
NativeDisplayManager_Rotation *displayRotation);
/**
* @brief Obtain the default display orientation.
*
* @param { *displayOrientation } Indicates the pointer to an <b>NativeDisplayManager_Orientation</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayOrientation(
NativeDisplayManager_Orientation *displayOrientation);
/**
* @brief Obtain the default display virtualPixels.
*
* @param { *virtualPixels } Indicates the pointer to an <b>float</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayVirtualPixelRatio(float *virtualPixels);
/**
* @brief Obtain the default display refreshRate.
*
* @param { *refreshRate } Indicates the pointer to an <b>uint32_t</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayRefreshRate(uint32_t *refreshRate);
/**
* @brief Obtain the default display densityDpi.
*
* @param { *densityDpi } Indicates the pointer to an <b>int32_t</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayDensityDpi(int32_t *densityDpi);
/**
* @brief Obtain the default display densityPixels.
*
* @param { *densityPixels } Indicates the pointer to an <b>float</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayDensityPixels(float *densityPixels);
/**
* @brief Obtain the default display scaledDensity.
*
* @param { *scaledDensity } Indicates the pointer to an <b>float</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayScaledDensity(float *scaledDensity);
/**
* @brief Obtain the default display xDpi.
*
* @param { *xDpi } Indicates the pointer to an <b>float</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayDensityXdpi(float *xDpi);
/**
* @brief Obtain the default display yDpi.
*
* @param { *yDpi } Indicates the pointer to an <b>float</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetDefaultDisplayDensityYdpi(float *yDpi);
/**
* @brief Create the cutout info of the device.
*
* @param { **cutoutInfo } Indicates the pointer to an <b>NativeDisplayManager_CutoutInfo</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_CreateDefaultDisplayCutoutInfo(
NativeDisplayManager_CutoutInfo **cutoutInfo);
/**
* @brief Destroy an <b>NativeDisplayManager_CutoutInfo</b> object and reclaims the memory occupied by the object.
*
* @param { **cutoutInfo } Indicates the pointer to an <b>NativeDisplayManager_CutoutInfo</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_DestroyDefaultDisplayCutoutInfo(
NativeDisplayManager_CutoutInfo *cutoutInfo);
/**
* @brief Check whether the device is foldable.
*
* @return { bool } true means the device is foldable.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
bool OH_NativeDisplayManager_IsFoldable();
/**
* @brief Get the display mode of the foldable device.
*
* @param { *displayMode } Indicates the pointer to an <b>NativeDisplayManager_FoldDisplayMode</b> object.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_DEVICE_NOT_SUPPORTED } device not support.
* @syscap SystemCapability.Window.SessionManager
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_GetFoldDisplayMode(
NativeDisplayManager_FoldDisplayMode *displayMode);
/**
* @brief the callback function type when display change.
*
* @param { *displayId } change display id.
* @syscap SystemCapability.Window.SessionManager
* @since 12
*/
typedef void (*OH_NativeDisplayManager_DisplayChangeCallback)(uint64_t displayId);
/**
* @brief Register the callback for display change listener.
*
* @param { displayChangeCallback } display change callback.
* @param { *listenerIndex } Indicates the pointer to an <b>uint32_t</b> object. used in unregister call.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_RegisterDisplayChangeListener(
OH_NativeDisplayManager_DisplayChangeCallback displayChangeCallback, uint32_t *listenerIndex);
/**
* @brief Unregister the callback for display changes listener.
*
* @param { listenerIndex } display changed listener index.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_UnregisterDisplayChangeListener(uint32_t listenerIndex);
/**
* @brief the callback function type when display fold change.
*
* @param { displayMode } current fold display mode.
* @syscap SystemCapability.Window.SessionManager
* @since 12
*/
typedef void (*OH_NativeDisplayManager_FoldDisplayModeChangeCallback)(
NativeDisplayManager_FoldDisplayMode displayMode);
/**
* @brief Register the callback for display mode change listener.
*
* @param { displayModeChangeCallback } display mode change callback.
* @param { *listenerIndex } Indicates the pointer to an <b>uint32_t</b> object. used in unregister call.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_DEVICE_NOT_SUPPORTED } device not support.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.Window.SessionManager
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_RegisterFoldDisplayModeChangeListener(
OH_NativeDisplayManager_FoldDisplayModeChangeCallback displayModeChangeCallback, uint32_t *listenerIndex);
/**
* @brief Unregister the callback for display mode change listener.
*
* @param { listenerIndex } display mode change listener index.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_DEVICE_NOT_SUPPORTED } device not support.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.Window.SessionManager
* @since 12
*/
NativeDisplayManager_ErrorCode OH_NativeDisplayManager_UnregisterFoldDisplayModeChangeListener(uint32_t listenerIndex);
#ifdef __cplusplus
}
#endif
/** @} */
#endif // OH_NATIVE_DISPLAY_MANAGER_H

View File

@ -0,0 +1,82 @@
[
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_GetDefaultDisplayId"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_GetDefaultDisplayWidth"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_GetDefaultDisplayHeight"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_GetDefaultDisplayRotation"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_GetDefaultDisplayOrientation"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_GetDefaultDisplayVirtualPixelRatio"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_GetDefaultDisplayRefreshRate"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_GetDefaultDisplayDensityDpi"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_GetDefaultDisplayDensityPixels"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_GetDefaultDisplayScaledDensity"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_GetDefaultDisplayDensityXdpi"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_GetDefaultDisplayDensityYdpi"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_CreateDefaultDisplayCutoutInfo"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_DestroyDefaultDisplayCutoutInfo"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_IsFoldable"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_GetFoldDisplayMode"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_RegisterFoldDisplayModeChangeListener"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_UnregisterFoldDisplayModeChangeListener"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_RegisterDisplayChangeListener"
},
{
"first_instroduced":"12",
"name":"OH_NativeDisplayManager_UnregisterDisplayChangeListener"
}
]

View File

@ -135,6 +135,7 @@ napi_value AsyncProcess(napi_env env,
napi_value resourceName = nullptr; napi_value resourceName = nullptr;
if (!NAPICall(env, napi_create_string_latin1(env, funcname.c_str(), NAPI_AUTO_LENGTH, &resourceName))) { if (!NAPICall(env, napi_create_string_latin1(env, funcname.c_str(), NAPI_AUTO_LENGTH, &resourceName))) {
delete info; delete info;
napi_delete_reference(env, callbackRef);
return nullptr; return nullptr;
} }
@ -147,16 +148,19 @@ napi_value AsyncProcess(napi_env env,
if (result == nullptr) { if (result == nullptr) {
delete info; delete info;
napi_delete_reference(env, callbackRef);
return nullptr; return nullptr;
} }
if (!NAPICall(env, napi_create_async_work(env, nullptr, resourceName, AsyncFunc<ParamT>, if (!NAPICall(env, napi_create_async_work(env, nullptr, resourceName, AsyncFunc<ParamT>,
CompleteFunc<ParamT>, reinterpret_cast<void *>(info), &info->asyncWork))) { CompleteFunc<ParamT>, reinterpret_cast<void *>(info), &info->asyncWork))) {
delete info; delete info;
napi_delete_reference(env, callbackRef);
return nullptr; return nullptr;
} }
if (!NAPICall(env, napi_queue_async_work(env, info->asyncWork))) { if (!NAPICall(env, napi_queue_async_work(env, info->asyncWork))) {
delete info; delete info;
napi_delete_reference(env, callbackRef);
return nullptr; return nullptr;
} }

View File

@ -35,16 +35,16 @@ constexpr size_t ARGC_ONE = 1;
constexpr size_t ARGC_TWO = 2; constexpr size_t ARGC_TWO = 2;
constexpr int32_t INDEX_ONE = 1; constexpr int32_t INDEX_ONE = 1;
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsDisplay"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsDisplay"};
const std::map<DisplayState, DisplayStateMode> NATIVE_TO_JS_DISPLAY_STATE_MAP { const std::map<DisplayState, DisplayStateMode> NATIVE_TO_JS_DISPLAY_STATE_MAP {
{ DisplayState::UNKNOWN, DisplayStateMode::STATE_UNKNOWN }, { DisplayState::UNKNOWN, DisplayStateMode::STATE_UNKNOWN },
{ DisplayState::OFF, DisplayStateMode::STATE_OFF }, { DisplayState::OFF, DisplayStateMode::STATE_OFF },
{ DisplayState::ON, DisplayStateMode::STATE_ON }, { DisplayState::ON, DisplayStateMode::STATE_ON },
{ DisplayState::DOZE, DisplayStateMode::STATE_DOZE }, { DisplayState::DOZE, DisplayStateMode::STATE_DOZE },
{ DisplayState::DOZE_SUSPEND, DisplayStateMode::STATE_DOZE_SUSPEND }, { DisplayState::DOZE_SUSPEND, DisplayStateMode::STATE_DOZE_SUSPEND },
{ DisplayState::VR, DisplayStateMode::STATE_VR }, { DisplayState::VR, DisplayStateMode::STATE_VR },
{ DisplayState::ON_SUSPEND, DisplayStateMode::STATE_ON_SUSPEND }, { DisplayState::ON_SUSPEND, DisplayStateMode::STATE_ON_SUSPEND },
}; };
using GraphicCM_ColorSpaceType = enum { using GraphicCM_ColorSpaceType = enum {
GRAPHIC_CM_COLORSPACE_NONE, GRAPHIC_CM_COLORSPACE_NONE,

View File

@ -21,11 +21,12 @@
#include "js_runtime_utils.h" #include "js_runtime_utils.h"
#include "window_manager_hilog.h" #include "window_manager_hilog.h"
#include "js_display.h" #include "js_display.h"
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
using namespace AbilityRuntime; using namespace AbilityRuntime;
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsDisplayListener"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsDisplayListener"};
} }
JsDisplayListener::JsDisplayListener(napi_env env) : env_(env) JsDisplayListener::JsDisplayListener(napi_env env) : env_(env)

View File

@ -33,7 +33,7 @@ constexpr size_t ARGC_ONE = 1;
constexpr size_t ARGC_TWO = 2; constexpr size_t ARGC_TWO = 2;
constexpr int32_t INDEX_ONE = 1; constexpr int32_t INDEX_ONE = 1;
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsDisplayManager"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsDisplayManager"};
} }
class JsDisplayManager { class JsDisplayManager {
@ -557,9 +557,13 @@ napi_value OnRegisterDisplayManagerCallback(napi_env env, napi_callback_info inf
std::lock_guard<std::mutex> lock(mtx_); std::lock_guard<std::mutex> lock(mtx_);
DmErrorCode ret = DM_JS_TO_ERROR_CODE_MAP.at(RegisterDisplayListenerWithType(env, cbType, value)); DmErrorCode ret = DM_JS_TO_ERROR_CODE_MAP.at(RegisterDisplayListenerWithType(env, cbType, value));
if (ret != DmErrorCode::DM_OK) { if (ret != DmErrorCode::DM_OK) {
DmErrorCode errCode = DmErrorCode::DM_ERROR_INVALID_PARAM;
if (ret == DmErrorCode::DM_ERROR_NOT_SYSTEM_APP) {
errCode = ret;
}
WLOGFE("Failed to register display listener with type"); WLOGFE("Failed to register display listener with type");
std::string errMsg = "Failed to register display listener with type"; std::string errMsg = "Failed to register display listener with type";
napi_throw(env, CreateJsError(env, static_cast<int32_t>(DmErrorCode::DM_ERROR_INVALID_PARAM), errMsg)); napi_throw(env, CreateJsError(env, static_cast<int32_t>(errCode), errMsg));
return NapiGetUndefined(env); return NapiGetUndefined(env);
} }
return NapiGetUndefined(env); return NapiGetUndefined(env);
@ -597,9 +601,13 @@ napi_value OnUnregisterDisplayManagerCallback(napi_env env, napi_callback_info i
} }
} }
if (ret != DmErrorCode::DM_OK) { if (ret != DmErrorCode::DM_OK) {
DmErrorCode errCode = DmErrorCode::DM_ERROR_INVALID_PARAM;
if (ret == DmErrorCode::DM_ERROR_NOT_SYSTEM_APP) {
errCode = ret;
}
WLOGFW("failed to unregister display listener with type"); WLOGFW("failed to unregister display listener with type");
std::string errMsg = "failed to unregister display listener with type"; std::string errMsg = "failed to unregister display listener with type";
napi_throw(env, CreateJsError(env, static_cast<int32_t>(DmErrorCode::DM_ERROR_INVALID_PARAM), errMsg)); napi_throw(env, CreateJsError(env, static_cast<int32_t>(errCode), errMsg));
return NapiGetUndefined(env); return NapiGetUndefined(env);
} }
return NapiGetUndefined(env); return NapiGetUndefined(env);
@ -737,7 +745,12 @@ napi_value OnSetFoldDisplayMode(napi_env env, napi_callback_info info)
napi_throw(env, CreateJsError(env, static_cast<int32_t>(DmErrorCode::DM_ERROR_INVALID_PARAM), errMsg)); napi_throw(env, CreateJsError(env, static_cast<int32_t>(DmErrorCode::DM_ERROR_INVALID_PARAM), errMsg));
return NapiGetUndefined(env); return NapiGetUndefined(env);
} }
SingletonContainer::Get<DisplayManager>().SetFoldDisplayMode(mode); DmErrorCode errCode = DM_JS_TO_ERROR_CODE_MAP.at(
SingletonContainer::Get<DisplayManager>().SetFoldDisplayModeFromJs(mode));
if (errCode != DmErrorCode::DM_OK) {
napi_throw(env, CreateJsError(env, static_cast<int32_t>(errCode)));
return NapiGetUndefined(env);
}
WLOGI("[NAPI]" PRIu64", setFoldDisplayMode"); WLOGI("[NAPI]" PRIu64", setFoldDisplayMode");
return NapiGetUndefined(env); return NapiGetUndefined(env);
} }
@ -759,7 +772,12 @@ napi_value OnSetFoldStatusLocked(napi_env env, napi_callback_info info)
napi_throw(env, CreateJsError(env, static_cast<int32_t>(DmErrorCode::DM_ERROR_INVALID_PARAM), errMsg)); napi_throw(env, CreateJsError(env, static_cast<int32_t>(DmErrorCode::DM_ERROR_INVALID_PARAM), errMsg));
return NapiGetUndefined(env); return NapiGetUndefined(env);
} }
SingletonContainer::Get<DisplayManager>().SetFoldStatusLocked(locked); DmErrorCode errCode = DM_JS_TO_ERROR_CODE_MAP.at(
SingletonContainer::Get<DisplayManager>().SetFoldStatusLockedFromJs(locked));
if (errCode != DmErrorCode::DM_OK) {
napi_throw(env, CreateJsError(env, static_cast<int32_t>(errCode)));
return NapiGetUndefined(env);
}
WLOGI("[NAPI]" PRIu64", SetFoldStatusLocked"); WLOGI("[NAPI]" PRIu64", SetFoldStatusLocked");
return NapiGetUndefined(env); return NapiGetUndefined(env);
} }

View File

@ -106,4 +106,9 @@ ohos_shared_library("embeddablewindowstage_kit") {
innerapi_tags = [ "platformsdk" ] innerapi_tags = [ "platformsdk" ]
part_name = "window_manager" part_name = "window_manager"
subsystem_name = "window" subsystem_name = "window"
defines = []
if (build_variant == "user") {
defines += [ "IS_RELEASE_VERSION" ]
}
} }

View File

@ -23,6 +23,7 @@
#include "js_extension_window_register_manager.h" #include "js_extension_window_register_manager.h"
#include "session_info.h" #include "session_info.h"
#include "window.h" #include "window.h"
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
class JsEmbeddableWindowStage { class JsEmbeddableWindowStage {

View File

@ -112,4 +112,9 @@ ohos_shared_library("extensionwindow_napi") {
innerapi_tags = [ "platformsdk" ] innerapi_tags = [ "platformsdk" ]
part_name = "window_manager" part_name = "window_manager"
subsystem_name = "window" subsystem_name = "window"
defines = []
if (build_variant == "user") {
defines += [ "IS_RELEASE_VERSION" ]
}
} }

View File

@ -894,7 +894,9 @@ napi_value JsExtensionWindow::OnCreateSubWindowWithOptions(napi_env env, napi_ca
static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "create sub window failed")); static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "create sub window failed"));
return; return;
} }
window->SetParentExtensionWindow(extWindow); if (!window->IsTopmost()) {
extWindow->NotifyModalUIExtensionMayBeCovered(false);
}
task.Resolve(env, CreateJsWindowObject(env, window)); task.Resolve(env, CreateJsWindowObject(env, window));
TLOGI(WmsLogTag::WMS_UIEXT, "[NAPI]Create sub window %{public}s end", windowName.c_str()); TLOGI(WmsLogTag::WMS_UIEXT, "[NAPI]Create sub window %{public}s end", windowName.c_str());
}; };

View File

@ -65,4 +65,9 @@ ohos_shared_library("pipwindow_napi") {
relative_install_dir = "module" relative_install_dir = "module"
part_name = "window_manager" part_name = "window_manager"
subsystem_name = "window" subsystem_name = "window"
defines = []
if (build_variant == "user") {
defines += [ "IS_RELEASE_VERSION" ]
}
} }

View File

@ -61,4 +61,9 @@ ohos_shared_library("pip_napi") {
relative_install_dir = "module" relative_install_dir = "module"
part_name = "window_manager" part_name = "window_manager"
subsystem_name = "window" subsystem_name = "window"
defines = []
if (build_variant == "user") {
defines += [ "IS_RELEASE_VERSION" ]
}
} }

View File

@ -24,6 +24,7 @@ using namespace AbilityRuntime;
using namespace Ace; using namespace Ace;
namespace { namespace {
constexpr int32_t NUMBER_ONE = 1; constexpr int32_t NUMBER_ONE = 1;
constexpr int32_t NUMBER_TWO = 2;
} }
napi_value NapiGetUndefined(napi_env env) napi_value NapiGetUndefined(napi_env env)
@ -73,7 +74,7 @@ napi_value JsPipManager::OnInitXComponentController(napi_env env, napi_callback_
std::shared_ptr<XComponentController> xComponentControllerResult = std::shared_ptr<XComponentController> xComponentControllerResult =
XComponentController::GetXComponentControllerFromNapiValue(env, xComponentController); XComponentController::GetXComponentControllerFromNapiValue(env, xComponentController);
sptr<Window> pipWindow = Window::Find(PIP_WINDOW_NAME); sptr<Window> pipWindow = Window::Find(PIP_WINDOW_NAME);
if (!pipWindow) { if (pipWindow == nullptr) {
TLOGE(WmsLogTag::WMS_PIP, "[NAPI]Failed to find pip window"); TLOGE(WmsLogTag::WMS_PIP, "[NAPI]Failed to find pip window");
return NapiGetUndefined(env); return NapiGetUndefined(env);
} }
@ -122,6 +123,117 @@ napi_value JsPipManager::OnGetCustomUIController(napi_env env, napi_callback_inf
return uiController; return uiController;
} }
napi_value JsPipManager::GetTypeNode(napi_env env, napi_callback_info info)
{
JsPipManager* me = CheckParamsAndGetThis<JsPipManager>(env, info);
return (me != nullptr) ? me->OnGetTypeNode(env, info) : nullptr;
}
napi_value JsPipManager::OnGetTypeNode(napi_env env, napi_callback_info info)
{
TLOGD(WmsLogTag::WMS_PIP, "[NAPI]");
sptr<Window> pipWindow = Window::Find(PIP_WINDOW_NAME);
if (pipWindow == nullptr) {
TLOGE(WmsLogTag::WMS_PIP, "[NAPI]Failed to find pip window");
return NapiGetUndefined(env);
}
int32_t windowId = static_cast<int32_t>(pipWindow->GetWindowId());
TLOGI(WmsLogTag::WMS_PIP, "[NAPI]winId: %{public}u", windowId);
sptr<PictureInPictureController> pipController = PictureInPictureManager::GetPipControllerInfo(windowId);
if (pipController == nullptr) {
TLOGE(WmsLogTag::WMS_PIP, "[NAPI]Failed to get pictureInPictureController");
return NapiGetUndefined(env);
}
napi_ref ref = pipController->GetTypeNode();
if (ref == nullptr) {
TLOGI(WmsLogTag::WMS_PIP, "[NAPI] invalid typeNode");
return NapiGetUndefined(env);
}
napi_value typeNode = nullptr;
napi_get_reference_value(env, ref, &typeNode);
return typeNode;
}
napi_value JsPipManager::SetTypeNodeEnabled(napi_env env, napi_callback_info info)
{
JsPipManager* me = CheckParamsAndGetThis<JsPipManager>(env, info);
return (me != nullptr) ? me->OnSetTypeNodeEnabled(env, info) : nullptr;
}
napi_value JsPipManager::OnSetTypeNodeEnabled(napi_env env, napi_callback_info info)
{
TLOGD(WmsLogTag::WMS_PIP, "[NAPI]");
sptr<Window> pipWindow = Window::Find(PIP_WINDOW_NAME);
if (pipWindow == nullptr) {
TLOGE(WmsLogTag::WMS_PIP, "[NAPI]Failed to find pip window");
return NapiGetUndefined(env);
}
int32_t windowId = static_cast<int32_t>(pipWindow->GetWindowId());
TLOGI(WmsLogTag::WMS_PIP, "[NAPI]winId: %{public}u", windowId);
sptr<PictureInPictureController> pipController = PictureInPictureManager::GetPipControllerInfo(windowId);
if (pipController == nullptr) {
TLOGE(WmsLogTag::WMS_PIP, "[NAPI]Failed to get pictureInPictureController");
return NapiGetUndefined(env);
}
pipController->OnPictureInPictureStart();
return NapiGetUndefined(env);
}
napi_value JsPipManager::RegisterCallback(napi_env env, napi_callback_info info)
{
JsPipManager* me = CheckParamsAndGetThis<JsPipManager>(env, info);
return (me != nullptr) ? me->OnRegisterCallback(env, info) : nullptr;
}
bool NapiIsCallable(napi_env env, napi_value value)
{
bool result = false;
napi_is_callable(env, value, &result);
return result;
}
napi_value JsPipManager::OnRegisterCallback(napi_env env, napi_callback_info info)
{
TLOGI(WmsLogTag::WMS_PIP, "[NAPI]");
size_t argc = 4;
napi_value argv[4] = {nullptr};
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
if (argc < NUMBER_TWO) {
TLOGE(WmsLogTag::WMS_PIP, "Params count not match: %{public}zu", argc);
return NapiThrowInvalidParam(env);
}
std::string cbType;
if (!ConvertFromJsValue(env, argv[0], cbType)) {
TLOGE(WmsLogTag::WMS_PIP, "Failed to convert param to cbType");
return NapiThrowInvalidParam(env);
}
napi_value value = argv[1];
if (value == nullptr || !NapiIsCallable(env, value)) {
TLOGE(WmsLogTag::WMS_PIP, "Callback is null or not callable");
return NapiThrowInvalidParam(env);
}
std::shared_ptr<NativeReference> callbackRef;
napi_ref result = nullptr;
napi_create_reference(env, value, 1, &result);
callbackRef.reset(reinterpret_cast<NativeReference*>(result));
PictureInPictureManager::innerCallbackRef_ = callbackRef;
TLOGI(WmsLogTag::WMS_PIP, "Register type %{public}s success!", cbType.c_str());
return NapiGetUndefined(env);
}
napi_value JsPipManager::UnregisterCallback(napi_env env, napi_callback_info info)
{
JsPipManager* me = CheckParamsAndGetThis<JsPipManager>(env, info);
return (me != nullptr) ? me->OnUnregisterCallback(env, info) : nullptr;
}
napi_value JsPipManager::OnUnregisterCallback(napi_env env, napi_callback_info info)
{
TLOGI(WmsLogTag::WMS_PIP, "[NAPI]");
PictureInPictureManager::innerCallbackRef_ = nullptr;
return NapiGetUndefined(env);
}
napi_value JsPipManagerInit(napi_env env, napi_value exportObj) napi_value JsPipManagerInit(napi_env env, napi_value exportObj)
{ {
TLOGD(WmsLogTag::WMS_PIP, "[NAPI]JsPipManager::JsPipManagerInit"); TLOGD(WmsLogTag::WMS_PIP, "[NAPI]JsPipManager::JsPipManagerInit");
@ -134,6 +246,10 @@ napi_value JsPipManagerInit(napi_env env, napi_value exportObj)
const char* moduleName = "JsPipManager"; const char* moduleName = "JsPipManager";
BindNativeFunction(env, exportObj, "initXComponentController", moduleName, JsPipManager::InitXComponentController); BindNativeFunction(env, exportObj, "initXComponentController", moduleName, JsPipManager::InitXComponentController);
BindNativeFunction(env, exportObj, "getCustomUIController", moduleName, JsPipManager::GetCustomUIController); BindNativeFunction(env, exportObj, "getCustomUIController", moduleName, JsPipManager::GetCustomUIController);
BindNativeFunction(env, exportObj, "getTypeNode", moduleName, JsPipManager::GetTypeNode);
BindNativeFunction(env, exportObj, "on", moduleName, JsPipManager::RegisterCallback);
BindNativeFunction(env, exportObj, "off", moduleName, JsPipManager::UnregisterCallback);
BindNativeFunction(env, exportObj, "setTypeNodeEnabled", moduleName, JsPipManager::SetTypeNodeEnabled);
return NapiGetUndefined(env); return NapiGetUndefined(env);
} }
} // namespace Rosen } // namespace Rosen

View File

@ -28,9 +28,17 @@ public:
static void Finalizer(napi_env env, void* data, void* hint); static void Finalizer(napi_env env, void* data, void* hint);
static napi_value InitXComponentController(napi_env env, napi_callback_info info); static napi_value InitXComponentController(napi_env env, napi_callback_info info);
static napi_value GetCustomUIController(napi_env env, napi_callback_info info); static napi_value GetCustomUIController(napi_env env, napi_callback_info info);
static napi_value GetTypeNode(napi_env env, napi_callback_info info);
static napi_value RegisterCallback(napi_env env, napi_callback_info info);
static napi_value UnregisterCallback(napi_env env, napi_callback_info info);
static napi_value SetTypeNodeEnabled(napi_env env, napi_callback_info info);
private: private:
napi_value OnInitXComponentController(napi_env env, napi_callback_info info); napi_value OnInitXComponentController(napi_env env, napi_callback_info info);
napi_value OnGetCustomUIController(napi_env env, napi_callback_info info); napi_value OnGetCustomUIController(napi_env env, napi_callback_info info);
napi_value OnGetTypeNode(napi_env env, napi_callback_info info);
napi_value OnRegisterCallback(napi_env env, napi_callback_info info);
napi_value OnUnregisterCallback(napi_env env, napi_callback_info info);
napi_value OnSetTypeNodeEnabled(napi_env env, napi_callback_info info);
}; };
} // namespace Rosen } // namespace Rosen
} // namespace OHOS } // namespace OHOS

View File

@ -28,6 +28,7 @@ namespace OHOS {
namespace Rosen { namespace Rosen {
using namespace AbilityRuntime; using namespace AbilityRuntime;
namespace { namespace {
constexpr int32_t NUMBER_ZERO = 0;
constexpr int32_t NUMBER_ONE = 1; constexpr int32_t NUMBER_ONE = 1;
constexpr int32_t NUMBER_TWO = 2; constexpr int32_t NUMBER_TWO = 2;
constexpr int32_t NUMBER_FOUR = 4; constexpr int32_t NUMBER_FOUR = 4;
@ -283,7 +284,7 @@ napi_value JsPipController::OnSetPiPControlEnabled(napi_env env, napi_callback_i
return NapiThrowInvalidParam(env, "Invalid args count, 2 args is needed."); return NapiThrowInvalidParam(env, "Invalid args count, 2 args is needed.");
} }
auto controlType = PiPControlType::VIDEO_PLAY_PAUSE; auto controlType = PiPControlType::VIDEO_PLAY_PAUSE;
std::string errMsg; std::string errMsg = "";
if (!ConvertFromJsValue(env, argv[0], controlType)) { if (!ConvertFromJsValue(env, argv[0], controlType)) {
errMsg = "Failed to convert parameter to int"; errMsg = "Failed to convert parameter to int";
TLOGE(WmsLogTag::WMS_PIP, "%{public}s", errMsg.c_str()); TLOGE(WmsLogTag::WMS_PIP, "%{public}s", errMsg.c_str());
@ -291,7 +292,7 @@ napi_value JsPipController::OnSetPiPControlEnabled(napi_env env, napi_callback_i
} }
bool enabled = true; bool enabled = true;
if (!ConvertFromJsValue(env, argv[1], enabled)) { if (!ConvertFromJsValue(env, argv[1], enabled)) {
errMsg = "Failed to convert parameter to int"; errMsg = "Failed to convert parameter to bool";
TLOGE(WmsLogTag::WMS_PIP, "%{public}s", errMsg.c_str()); TLOGE(WmsLogTag::WMS_PIP, "%{public}s", errMsg.c_str());
return NapiThrowInvalidParam(env, errMsg); return NapiThrowInvalidParam(env, errMsg);
} }
@ -321,7 +322,7 @@ napi_value JsPipController::OnRegisterCallback(napi_env env, napi_callback_info
TLOGE(WmsLogTag::WMS_PIP, "JsPipController Params not match: %{public}zu", argc); TLOGE(WmsLogTag::WMS_PIP, "JsPipController Params not match: %{public}zu", argc);
return NapiThrowInvalidParam(env); return NapiThrowInvalidParam(env);
} }
std::string cbType; std::string cbType = "";
if (!ConvertFromJsValue(env, argv[0], cbType)) { if (!ConvertFromJsValue(env, argv[0], cbType)) {
TLOGE(WmsLogTag::WMS_PIP, "Failed to convert parameter to callbackType"); TLOGE(WmsLogTag::WMS_PIP, "Failed to convert parameter to callbackType");
return NapiThrowInvalidParam(env); return NapiThrowInvalidParam(env);
@ -462,11 +463,11 @@ napi_value JsPipController::OnUnregisterCallback(napi_env env, napi_callback_inf
size_t argc = NUMBER_FOUR; size_t argc = NUMBER_FOUR;
napi_value argv[NUMBER_FOUR] = {nullptr}; napi_value argv[NUMBER_FOUR] = {nullptr};
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
if (argc > NUMBER_TWO) { if (argc == NUMBER_ZERO || argc > NUMBER_TWO) {
TLOGE(WmsLogTag::WMS_PIP, "JsPipController Params not match: %{public}zu", argc); TLOGE(WmsLogTag::WMS_PIP, "JsPipController Params not match: %{public}zu", argc);
return NapiThrowInvalidParam(env); return NapiThrowInvalidParam(env);
} }
std::string cbType; std::string cbType = "";
if (!ConvertFromJsValue(env, argv[0], cbType)) { if (!ConvertFromJsValue(env, argv[0], cbType)) {
TLOGE(WmsLogTag::WMS_PIP, "Failed to convert parameter to string"); TLOGE(WmsLogTag::WMS_PIP, "Failed to convert parameter to string");
return NapiThrowInvalidParam(env); return NapiThrowInvalidParam(env);

View File

@ -67,7 +67,7 @@ private:
void ProcessActionEventUnRegister(const sptr<JsPiPWindowListener>& listener); void ProcessActionEventUnRegister(const sptr<JsPiPWindowListener>& listener);
void ProcessControlEventUnRegister(const sptr<JsPiPWindowListener>& listener); void ProcessControlEventUnRegister(const sptr<JsPiPWindowListener>& listener);
sptr<PictureInPictureController> pipController_; sptr<PictureInPictureController> pipController_ = nullptr;
std::map<std::string, ListenerType> listenerCodeMap_; std::map<std::string, ListenerType> listenerCodeMap_;
std::unordered_map<std::string, std::set<sptr<JsPiPWindowListener>>> jsCbMap_; std::unordered_map<std::string, std::set<sptr<JsPiPWindowListener>>> jsCbMap_;
}; };

View File

@ -17,6 +17,7 @@
#include "js_pip_controller.h" #include "js_pip_controller.h"
#include "window_manager_hilog.h" #include "window_manager_hilog.h"
#include "picture_in_picture_manager.h"
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
@ -80,6 +81,10 @@ void JsPiPWindowListener::OnPictureInPictureOperationError(int32_t errorCode)
void JsPiPWindowListener::OnPipListenerCallback(PiPState state, int32_t errorCode) void JsPiPWindowListener::OnPipListenerCallback(PiPState state, int32_t errorCode)
{ {
TLOGI(WmsLogTag::WMS_PIP, "state: %{public}d", static_cast<int32_t>(state)); TLOGI(WmsLogTag::WMS_PIP, "state: %{public}d", static_cast<int32_t>(state));
if (PictureInPictureManager::innerCallbackRef_ != nullptr) {
napi_value value[] = { CreateJsValue(env_, static_cast<uint32_t>(state))};
CallJsFunction(env_, PictureInPictureManager::innerCallbackRef_->GetNapiValue(), value, ArraySize(value));
}
auto napiTask = [jsCallback = jsCallBack_, state, errorCode, env = env_]() { auto napiTask = [jsCallback = jsCallBack_, state, errorCode, env = env_]() {
napi_value argv[] = {CreateJsValue(env, static_cast<uint32_t>(state)), CreateJsValue(env, errorCode)}; napi_value argv[] = {CreateJsValue(env, static_cast<uint32_t>(state)), CreateJsValue(env, errorCode)};
CallJsFunction(env, jsCallback->GetNapiValue(), argv, ArraySize(argv)); CallJsFunction(env, jsCallback->GetNapiValue(), argv, ArraySize(argv));

View File

@ -20,7 +20,6 @@
#include "js_runtime_utils.h" #include "js_runtime_utils.h"
#include "window_manager_hilog.h" #include "window_manager_hilog.h"
#include "window.h" #include "window.h"
#include "picture_in_picture_manager.h"
#include "xcomponent_controller.h" #include "xcomponent_controller.h"
#include <algorithm> #include <algorithm>
@ -217,9 +216,46 @@ napi_value JsPipWindowManager::CreatePipController(napi_env env, napi_callback_i
return (me != nullptr) ? me->OnCreatePipController(env, info) : nullptr; return (me != nullptr) ? me->OnCreatePipController(env, info) : nullptr;
} }
napi_value JsPipWindowManager::NapiSendTask(napi_env env, PipOption& pipOption)
{
napi_value result = nullptr;
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, nullptr, &result);
auto asyncTask = [this, env, task = napiAsyncTask.get(), pipOption]() {
if (!PictureInPictureManager::IsSupportPiP()) {
task->Reject(env, CreateJsError(env, static_cast<int32_t>(
WMError::WM_ERROR_DEVICE_NOT_SUPPORT), "device not support pip."));
return;
}
sptr<PipOption> pipOptionPtr = new PipOption(pipOption);
auto context = static_cast<std::weak_ptr<AbilityRuntime::Context>*>(pipOptionPtr->GetContext());
if (context == nullptr) {
task->Reject(env, CreateJsError(env, static_cast<int32_t>(
WMError::WM_ERROR_PIP_INTERNAL_ERROR), "Invalid context"));
return;
}
sptr<Window> mainWindow = Window::GetMainWindowWithContext(context->lock());
if (mainWindow == nullptr) {
task->Reject(env, CreateJsError(env, static_cast<int32_t>(
WMError::WM_ERROR_PIP_INTERNAL_ERROR), "Invalid mainWindow"));
return;
}
sptr<PictureInPictureController> pipController =
new PictureInPictureController(pipOptionPtr, mainWindow, mainWindow->GetWindowId(), env);
task->Resolve(env, CreateJsPipControllerObject(env, pipController));
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
napiAsyncTask->Reject(env, CreateJsError(env,
static_cast<int32_t>(WMError::WM_ERROR_PIP_INTERNAL_ERROR), "Send event failed"));
} else {
napiAsyncTask.release();
}
return result;
}
napi_value JsPipWindowManager::OnCreatePipController(napi_env env, napi_callback_info info) napi_value JsPipWindowManager::OnCreatePipController(napi_env env, napi_callback_info info)
{ {
TLOGI(WmsLogTag::WMS_PIP, "OnCreatePipController called"); TLOGI(WmsLogTag::WMS_PIP, "[NAPI]");
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);
size_t argc = 4; size_t argc = 4;
napi_value argv[4] = {nullptr}; napi_value argv[4] = {nullptr};
@ -239,34 +275,20 @@ napi_value JsPipWindowManager::OnCreatePipController(napi_env env, napi_callback
TLOGE(WmsLogTag::WMS_PIP, "%{public}s", errMsg.c_str()); TLOGE(WmsLogTag::WMS_PIP, "%{public}s", errMsg.c_str());
return NapiThrowInvalidParam(env, errMsg); return NapiThrowInvalidParam(env, errMsg);
} }
napi_value callback = argc > 1 ? (GetType(env, argv[1]) == napi_function ? argv[1] : nullptr) : nullptr; if (argc > 1) {
NapiAsyncTask::CompleteCallback complete = [=](napi_env env, NapiAsyncTask& task, int32_t status) { napi_value typeNode = argv[1];
if (!PictureInPictureManager::IsSupportPiP()) { napi_ref typeNodeRef = nullptr;
task.Reject(env, CreateJsError(env, static_cast<int32_t>( if (typeNode != nullptr && GetType(env, typeNode) != napi_undefined) {
WMError::WM_ERROR_DEVICE_NOT_SUPPORT), "device not support pip.")); TLOGI(WmsLogTag::WMS_PIP, "typeNode enabled");
return; pipOption.SetTypeNodeEnabled(true);
napi_create_reference(env, typeNode, 1, &typeNodeRef);
pipOption.SetTypeNodeRef(typeNodeRef);
} else {
pipOption.SetTypeNodeEnabled(false);
pipOption.SetTypeNodeRef(nullptr);
} }
sptr<PipOption> pipOptionPtr = new PipOption(pipOption); }
auto context = static_cast<std::weak_ptr<AbilityRuntime::Context>*>(pipOptionPtr->GetContext()); return NapiSendTask(env, pipOption);
if (context == nullptr) {
task.Reject(env, CreateJsError(env, static_cast<int32_t>(
WMError::WM_ERROR_PIP_INTERNAL_ERROR), "Invalid context"));
return;
}
sptr<Window> mainWindow = Window::GetMainWindowWithContext(context->lock());
if (mainWindow == nullptr) {
task.Reject(env, CreateJsError(env, static_cast<int32_t>(
WMError::WM_ERROR_PIP_INTERNAL_ERROR), "Invalid mainWindow"));
return;
}
sptr<PictureInPictureController> pipController =
new PictureInPictureController(pipOptionPtr, mainWindow, mainWindow->GetWindowId(), env);
task.Resolve(env, CreateJsPipControllerObject(env, pipController));
};
napi_value result = nullptr;
NapiAsyncTask::Schedule("JsPipWindowManager::OnCreatePipController", env,
CreateAsyncTaskWithLastParam(env, callback, nullptr, std::move(complete), &result));
return result;
} }
napi_value JsPipWindowManagerInit(napi_env env, napi_value exportObj) napi_value JsPipWindowManagerInit(napi_env env, napi_value exportObj)

View File

@ -17,6 +17,7 @@
#define OHOS_JS_PIP_WINDOW_MANAGER_H #define OHOS_JS_PIP_WINDOW_MANAGER_H
#include "js_runtime_utils.h" #include "js_runtime_utils.h"
#include "picture_in_picture_manager.h"
#include <mutex> #include <mutex>
namespace OHOS { namespace OHOS {
@ -30,8 +31,9 @@ public:
static napi_value IsPipEnabled(napi_env env, napi_callback_info info); static napi_value IsPipEnabled(napi_env env, napi_callback_info info);
static napi_value CreatePipController(napi_env env, napi_callback_info info); static napi_value CreatePipController(napi_env env, napi_callback_info info);
private: private:
static napi_value OnIsPipEnabled(napi_env env, napi_callback_info info); napi_value OnIsPipEnabled(napi_env env, napi_callback_info info);
static napi_value OnCreatePipController(napi_env env, napi_callback_info info); napi_value OnCreatePipController(napi_env env, napi_callback_info info);
napi_value NapiSendTask(napi_env env, PipOption& pipOption);
static std::mutex mutex_; static std::mutex mutex_;
}; };
} }

View File

@ -31,7 +31,7 @@ using namespace AbilityRuntime;
constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_ONE = 1;
constexpr size_t ARGC_TWO = 2; constexpr size_t ARGC_TWO = 2;
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsScreen"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsScreen"};
} }
static thread_local std::map<ScreenId, std::shared_ptr<NativeReference>> g_JsScreenMap; static thread_local std::map<ScreenId, std::shared_ptr<NativeReference>> g_JsScreenMap;

View File

@ -19,15 +19,40 @@
#include "js_runtime_utils.h" #include "js_runtime_utils.h"
#include "window_manager_hilog.h" #include "window_manager_hilog.h"
#include "js_screen.h" #include "js_screen.h"
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
using namespace AbilityRuntime; using namespace AbilityRuntime;
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsScreenListener"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsScreenListener"};
} }
inline uint32_t SCREEN_DISCONNECT_TYPE = 0; inline uint32_t SCREEN_DISCONNECT_TYPE = 0;
inline uint32_t SCREEN_CONNECT_TYPE = 1; inline uint32_t SCREEN_CONNECT_TYPE = 1;
JsScreenListener::JsScreenListener(napi_env env) : env_(env)
{
TLOGI(WmsLogTag::DMS, "Constructor execution");
napi_add_env_cleanup_hook(env_, CleanEnv, this);
}
JsScreenListener::~JsScreenListener()
{
TLOGI(WmsLogTag::DMS, "Destructor execution");
napi_remove_env_cleanup_hook(env_, CleanEnv, this);
env_ = nullptr;
}
void JsScreenListener::CleanEnv(void* obj)
{
JsScreenListener* thisObj = reinterpret_cast<JsScreenListener*>(obj);
if (!thisObj) {
TLOGE(WmsLogTag::DMS, "obj is nullptr");
return;
}
TLOGI(WmsLogTag::DMS, "env_ is invalid, set to nullptr");
thisObj->env_ = nullptr;
}
void JsScreenListener::AddCallback(const std::string& type, napi_value jsListenerObject) void JsScreenListener::AddCallback(const std::string& type, napi_value jsListenerObject)
{ {
WLOGI("JsScreenListener::AddCallback is called"); WLOGI("JsScreenListener::AddCallback is called");

View File

@ -25,14 +25,15 @@ namespace OHOS {
namespace Rosen { namespace Rosen {
class JsScreenListener : public ScreenManager::IScreenListener { class JsScreenListener : public ScreenManager::IScreenListener {
public: public:
explicit JsScreenListener(napi_env env) : env_(env) {} explicit JsScreenListener(napi_env env);
~JsScreenListener() override = default; ~JsScreenListener() override;
void AddCallback(const std::string& type, napi_value jsListenerObject); void AddCallback(const std::string& type, napi_value jsListenerObject);
void RemoveAllCallback(); void RemoveAllCallback();
void RemoveCallback(napi_env env, const std::string& type, napi_value jsListenerObject); void RemoveCallback(napi_env env, const std::string& type, napi_value jsListenerObject);
void OnConnect(ScreenId id) override; void OnConnect(ScreenId id) override;
void OnDisconnect(ScreenId id) override; void OnDisconnect(ScreenId id) override;
void OnChange(ScreenId id) override; void OnChange(ScreenId id) override;
static void CleanEnv(void* obj);
private: private:
void CallJsMethod(const std::string& methodName, napi_value const * argv = nullptr, size_t argc = 0); void CallJsMethod(const std::string& methodName, napi_value const * argv = nullptr, size_t argc = 0);

View File

@ -41,7 +41,7 @@ constexpr int32_t INDEX_ONE = 1;
constexpr int32_t INDEX_TWO = 2; constexpr int32_t INDEX_TWO = 2;
constexpr uint32_t MAX_SCREENS_NUM = 1000; constexpr uint32_t MAX_SCREENS_NUM = 1000;
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsScreenManager"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "JsScreenManager"};
} }
class JsScreenManager { class JsScreenManager {
@ -81,16 +81,16 @@ static napi_value MakeMirror(napi_env env, napi_callback_info info)
return (me != nullptr) ? me->OnMakeMirror(env, info) : nullptr; return (me != nullptr) ? me->OnMakeMirror(env, info) : nullptr;
} }
static napi_value MultiScreenModeSwitch(napi_env env, napi_callback_info info) static napi_value SetMultiScreenMode(napi_env env, napi_callback_info info)
{ {
JsScreenManager* me = CheckParamsAndGetThis<JsScreenManager>(env, info); JsScreenManager* me = CheckParamsAndGetThis<JsScreenManager>(env, info);
return (me != nullptr) ? me->OnMultiScreenModeSwitch(env, info) : nullptr; return (me != nullptr) ? me->OnSetMultiScreenMode(env, info) : nullptr;
} }
static napi_value MultiScreenRelativePosition(napi_env env, napi_callback_info info) static napi_value SetMultiScreenRelativePosition(napi_env env, napi_callback_info info)
{ {
JsScreenManager* me = CheckParamsAndGetThis<JsScreenManager>(env, info); JsScreenManager* me = CheckParamsAndGetThis<JsScreenManager>(env, info);
return (me != nullptr) ? me->OnMultiScreenRelativePosition(env, info) : nullptr; return (me != nullptr) ? me->OnSetMultiScreenRelativePosition(env, info) : nullptr;
} }
static napi_value MakeExpand(napi_env env, napi_callback_info info) static napi_value MakeExpand(napi_env env, napi_callback_info info)
@ -251,7 +251,7 @@ DmErrorCode UnregisterAllScreenListenerWithType(const std::string& type)
if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
WLOGFE("JsScreenManager::UnregisterAllScreenListenerWithType methodName %{public}s not registered!", WLOGFE("JsScreenManager::UnregisterAllScreenListenerWithType methodName %{public}s not registered!",
type.c_str()); type.c_str());
return DmErrorCode::DM_ERROR_INVALID_CALLING; return DmErrorCode::DM_OK;
} }
for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) { for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) {
it->second->RemoveAllCallback(); it->second->RemoveAllCallback();
@ -271,7 +271,7 @@ DmErrorCode UnRegisterScreenListenerWithType(napi_env env, const std::string& ty
if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
WLOGI("JsScreenManager::UnRegisterScreenListenerWithType methodName %{public}s not registered!", WLOGI("JsScreenManager::UnRegisterScreenListenerWithType methodName %{public}s not registered!",
type.c_str()); type.c_str());
return DmErrorCode::DM_ERROR_INVALID_CALLING; return DmErrorCode::DM_OK;
} }
if (value == nullptr) { if (value == nullptr) {
WLOGFE("JsScreenManager::UnRegisterScreenListenerWithType value is nullptr"); WLOGFE("JsScreenManager::UnRegisterScreenListenerWithType value is nullptr");
@ -370,7 +370,11 @@ napi_value OnUnregisterScreenManagerCallback(napi_env env, napi_callback_info in
} }
std::lock_guard<std::mutex> lock(mtx_); std::lock_guard<std::mutex> lock(mtx_);
if (argc == ARGC_ONE) { if (argc == ARGC_ONE) {
UnregisterAllScreenListenerWithType(cbType); DmErrorCode ret = UnregisterAllScreenListenerWithType(cbType);
if (ret != DmErrorCode::DM_OK) {
WLOGFE("unregister all callback failed");
napi_throw(env, CreateJsError(env, static_cast<int32_t>(ret)));
}
} else { } else {
napi_value value = argv[INDEX_ONE]; napi_value value = argv[INDEX_ONE];
if ((value == nullptr) || (!NapiIsCallable(env, value))) { if ((value == nullptr) || (!NapiIsCallable(env, value))) {
@ -443,9 +447,8 @@ napi_value OnMakeMirror(napi_env env, napi_callback_info info)
return result; return result;
} }
napi_value OnMultiScreenModeSwitch(napi_env env, napi_callback_info info) napi_value OnSetMultiScreenMode(napi_env env, napi_callback_info info)
{ {
WLOGI("OnMakeMirror is called");
size_t argc = ARGC_FOUR; size_t argc = ARGC_FOUR;
napi_value argv[ARGC_FOUR] = {nullptr}; napi_value argv[ARGC_FOUR] = {nullptr};
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
@ -460,24 +463,24 @@ napi_value OnMultiScreenModeSwitch(napi_env env, napi_callback_info info)
if (!ConvertFromJsValue(env, argv[INDEX_ONE], secondaryScreenId)) { if (!ConvertFromJsValue(env, argv[INDEX_ONE], secondaryScreenId)) {
return NapiThrowError(env, DmErrorCode::DM_ERROR_INVALID_PARAM, "Failed to convert parameter to int"); return NapiThrowError(env, DmErrorCode::DM_ERROR_INVALID_PARAM, "Failed to convert parameter to int");
} }
ScreenSourceMode secondaryScreenMode; MultiScreenMode screenMode;
if (!ConvertFromJsValue(env, argv[INDEX_TWO], secondaryScreenMode)) { if (!ConvertFromJsValue(env, argv[INDEX_TWO], screenMode)) {
return NapiThrowError(env, DmErrorCode::DM_ERROR_INVALID_PARAM, "Failed to convert parameter"); return NapiThrowError(env, DmErrorCode::DM_ERROR_INVALID_PARAM, "Failed to convert parameter");
} }
napi_value lastParam = nullptr; napi_value lastParam = nullptr;
napi_value result = nullptr; napi_value result = nullptr;
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [mainScreenId, secondaryScreenId, env, secondaryScreenMode, auto asyncTask = [mainScreenId, secondaryScreenId, env, screenMode,
task = napiAsyncTask.get()]() { task = napiAsyncTask.get()]() {
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "JsScreenManager::OnMultiScreenModeSwitch"); HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "JsScreenManager::OnSetMultiScreenMode");
DmErrorCode ret = DM_JS_TO_ERROR_CODE_MAP.at( DmErrorCode ret = DM_JS_TO_ERROR_CODE_MAP.at(
SingletonContainer::Get<ScreenManager>().MultiScreenModeSwitch(mainScreenId, secondaryScreenId, SingletonContainer::Get<ScreenManager>().SetMultiScreenMode(mainScreenId, secondaryScreenId,
secondaryScreenMode)); screenMode));
if (ret == DmErrorCode::DM_OK) { if (ret == DmErrorCode::DM_OK) {
task->Resolve(env, NapiGetUndefined(env)); task->Resolve(env, NapiGetUndefined(env));
} else { } else {
task->Reject(env, task->Reject(env,
CreateJsError(env, static_cast<int32_t>(ret), "JsScreenManager::OnMultiScreenModeSwitch failed.")); CreateJsError(env, static_cast<int32_t>(ret), "JsScreenManager::OnSetMultiScreenMode failed."));
} }
delete task; delete task;
}; };
@ -485,37 +488,36 @@ napi_value OnMultiScreenModeSwitch(napi_env env, napi_callback_info info)
return result; return result;
} }
napi_value OnMultiScreenRelativePosition(napi_env env, napi_callback_info info) napi_value OnSetMultiScreenRelativePosition(napi_env env, napi_callback_info info)
{ {
WLOGI("OnMakeMirror is called");
size_t argc = ARGC_FOUR; size_t argc = ARGC_FOUR;
napi_value argv[ARGC_FOUR] = {nullptr}; napi_value argv[ARGC_FOUR] = {nullptr};
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
if (argc < ARGC_TWO) { if (argc < ARGC_TWO) {
return NapiThrowError(env, DmErrorCode::DM_ERROR_INVALID_PARAM, "Invalid args count, need two args"); return NapiThrowError(env, DmErrorCode::DM_ERROR_INVALID_PARAM, "Invalid args count, need two args");
} }
ExtendOption mainScreenOption; MultiScreenPositionOptions mainScreenOptions;
if (GetExtendOptionFromJs(env, argv[INDEX_ZERO], mainScreenOption) == -1) { if (GetMultiScreenPositionOptionsFromJs(env, argv[INDEX_ZERO], mainScreenOptions) == -1) {
return NapiThrowError(env, DmErrorCode::DM_ERROR_INVALID_PARAM, "Failed to convert parameter to int"); return NapiThrowError(env, DmErrorCode::DM_ERROR_INVALID_PARAM, "Failed to convert parameter to int");
} }
ExtendOption secondaryScreenOption; MultiScreenPositionOptions secondScreenOption;
if (GetExtendOptionFromJs(env, argv[INDEX_ONE], secondaryScreenOption) == -1) { if (GetMultiScreenPositionOptionsFromJs(env, argv[INDEX_ONE], secondScreenOption) == -1) {
return NapiThrowError(env, DmErrorCode::DM_ERROR_INVALID_PARAM, "Failed to convert parameter to int"); return NapiThrowError(env, DmErrorCode::DM_ERROR_INVALID_PARAM, "Failed to convert parameter to int");
} }
napi_value lastParam = nullptr; napi_value lastParam = nullptr;
napi_value result = nullptr; napi_value result = nullptr;
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [mainScreenOption, secondaryScreenOption, env, auto asyncTask = [mainScreenOptions, secondScreenOption, env,
task = napiAsyncTask.get()]() { task = napiAsyncTask.get()]() {
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "JsScreenManager::OnMultiScreenRelativePosition"); HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "JsScreenManager::OnSetMultiScreenRelativePosition");
DmErrorCode ret = DM_JS_TO_ERROR_CODE_MAP.at( DmErrorCode ret = DM_JS_TO_ERROR_CODE_MAP.at(
SingletonContainer::Get<ScreenManager>().MultiScreenRelativePosition(mainScreenOption, SingletonContainer::Get<ScreenManager>().SetMultiScreenRelativePosition(mainScreenOptions,
secondaryScreenOption)); secondScreenOption));
if (ret == DmErrorCode::DM_OK) { if (ret == DmErrorCode::DM_OK) {
task->Resolve(env, NapiGetUndefined(env)); task->Resolve(env, NapiGetUndefined(env));
} else { } else {
task->Reject(env, task->Reject(env,
CreateJsError(env, static_cast<int32_t>(ret), "OnMultiScreenRelativePosition failed.")); CreateJsError(env, static_cast<int32_t>(ret), "OnSetMultiScreenRelativePosition failed."));
} }
delete task; delete task;
}; };
@ -711,7 +713,8 @@ static int32_t GetExpandOptionFromJs(napi_env env, napi_value optionObject, Expa
return 0; return 0;
} }
static int32_t GetExtendOptionFromJs(napi_env env, napi_value optionObject, ExtendOption& option) static int32_t GetMultiScreenPositionOptionsFromJs(napi_env env, napi_value optionObject,
MultiScreenPositionOptions& option)
{ {
napi_value screedIdValue = nullptr; napi_value screedIdValue = nullptr;
napi_value startXValue = nullptr; napi_value startXValue = nullptr;
@ -719,7 +722,7 @@ static int32_t GetExtendOptionFromJs(napi_env env, napi_value optionObject, Exte
uint32_t screenId; uint32_t screenId;
uint32_t startX; uint32_t startX;
uint32_t startY; uint32_t startY;
napi_get_named_property(env, optionObject, "screenId", &screedIdValue); napi_get_named_property(env, optionObject, "id", &screedIdValue);
napi_get_named_property(env, optionObject, "startX", &startXValue); napi_get_named_property(env, optionObject, "startX", &startXValue);
napi_get_named_property(env, optionObject, "startY", &startYValue); napi_get_named_property(env, optionObject, "startY", &startYValue);
if (!ConvertFromJsValue(env, screedIdValue, screenId)) { if (!ConvertFromJsValue(env, screedIdValue, screenId)) {
@ -748,13 +751,11 @@ napi_value OnCreateVirtualScreen(napi_env env, napi_callback_info info)
napi_value argv[4] = {nullptr}; napi_value argv[4] = {nullptr};
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
if (argc < ARGC_ONE) { if (argc < ARGC_ONE) {
WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
errMsg = "Invalid args count, need one arg at least!"; errMsg = "Invalid args count, need one arg at least!";
errCode = DmErrorCode::DM_ERROR_INVALID_PARAM; errCode = DmErrorCode::DM_ERROR_INVALID_PARAM;
} else { } else {
napi_value object = argv[0]; napi_value object = argv[0];
if (object == nullptr) { if (object == nullptr) {
WLOGFE("Failed to convert parameter to VirtualScreenOption.");
errMsg = "Failed to get options, options is nullptr"; errMsg = "Failed to get options, options is nullptr";
errCode = DmErrorCode::DM_ERROR_INVALID_PARAM; errCode = DmErrorCode::DM_ERROR_INVALID_PARAM;
} else { } else {
@ -776,9 +777,11 @@ napi_value OnCreateVirtualScreen(napi_env env, napi_callback_info info)
auto screenId = SingletonContainer::Get<ScreenManager>().CreateVirtualScreen(option); auto screenId = SingletonContainer::Get<ScreenManager>().CreateVirtualScreen(option);
auto screen = SingletonContainer::Get<ScreenManager>().GetScreenById(screenId); auto screen = SingletonContainer::Get<ScreenManager>().GetScreenById(screenId);
if (screen == nullptr) { if (screen == nullptr) {
task->Reject(env, CreateJsError(env, DmErrorCode ret = DmErrorCode::DM_ERROR_INVALID_SCREEN;
static_cast<int32_t>(DmErrorCode::DM_ERROR_INVALID_SCREEN), if (screenId == ERROR_ID_NOT_SYSTEM_APP) {
"ScreenManager::CreateVirtualScreen failed.")); ret = DmErrorCode::DM_ERROR_NOT_SYSTEM_APP;
}
task->Reject(env, CreateJsError(env, static_cast<int32_t>(ret), "CreateVirtualScreen failed."));
WLOGFE("ScreenManager::CreateVirtualScreen failed."); WLOGFE("ScreenManager::CreateVirtualScreen failed.");
return; return;
} }
@ -1037,6 +1040,10 @@ napi_value OnSetScreenRotationLocked(napi_env env, napi_callback_info info)
void NapiSendDmsEvent(napi_env env, std::function<void()> asyncTask, void NapiSendDmsEvent(napi_env env, std::function<void()> asyncTask,
std::unique_ptr<AbilityRuntime::NapiAsyncTask>& napiAsyncTask) std::unique_ptr<AbilityRuntime::NapiAsyncTask>& napiAsyncTask)
{ {
if (!env) {
WLOGFE("env is null");
return;
}
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
napiAsyncTask->Reject(env, CreateJsError(env, napiAsyncTask->Reject(env, CreateJsError(env,
static_cast<int32_t>(DmErrorCode::DM_ERROR_INVALID_SCREEN), "Send event failed!")); static_cast<int32_t>(DmErrorCode::DM_ERROR_INVALID_SCREEN), "Send event failed!"));
@ -1103,6 +1110,29 @@ napi_value InitScreenSourceMode(napi_env env)
return objValue; return objValue;
} }
napi_value InitMultiScreenMode(napi_env env)
{
WLOGD("JsScreenManager::InitMultiScreenMode called");
if (env == nullptr) {
WLOGFE("env is nullptr");
return nullptr;
}
napi_value objValue = nullptr;
napi_create_object(env, &objValue);
if (objValue == nullptr) {
WLOGFE("Failed to get object");
return nullptr;
}
napi_set_named_property(env, objValue, "SCREEN_MIRROR",
CreateJsValue(env, static_cast<uint32_t>(MultiScreenMode::SCREEN_MIRROR)));
napi_set_named_property(env, objValue, "SCREEN_EXTAND",
CreateJsValue(env, static_cast<uint32_t>(MultiScreenMode::SCREEN_EXTAND)));
return objValue;
}
napi_value InitDisplayErrorCode(napi_env env) napi_value InitDisplayErrorCode(napi_env env)
{ {
WLOGD("JsDisplayManager::InitDisplayErrorCode called"); WLOGD("JsDisplayManager::InitDisplayErrorCode called");
@ -1196,15 +1226,16 @@ napi_value JsScreenManagerInit(napi_env env, napi_value exportObj)
napi_set_named_property(env, exportObj, "ScreenSourceMode", InitScreenSourceMode(env)); napi_set_named_property(env, exportObj, "ScreenSourceMode", InitScreenSourceMode(env));
napi_set_named_property(env, exportObj, "DmErrorCode", InitDisplayErrorCode(env)); napi_set_named_property(env, exportObj, "DmErrorCode", InitDisplayErrorCode(env));
napi_set_named_property(env, exportObj, "DMError", InitDisplayError(env)); napi_set_named_property(env, exportObj, "DMError", InitDisplayError(env));
napi_set_named_property(env, exportObj, "MultiScreenMode", InitMultiScreenMode(env));
const char *moduleName = "JsScreenManager"; const char *moduleName = "JsScreenManager";
BindNativeFunction(env, exportObj, "getAllScreens", moduleName, JsScreenManager::GetAllScreens); BindNativeFunction(env, exportObj, "getAllScreens", moduleName, JsScreenManager::GetAllScreens);
BindNativeFunction(env, exportObj, "on", moduleName, JsScreenManager::RegisterScreenManagerCallback); BindNativeFunction(env, exportObj, "on", moduleName, JsScreenManager::RegisterScreenManagerCallback);
BindNativeFunction(env, exportObj, "off", moduleName, JsScreenManager::UnregisterScreenMangerCallback); BindNativeFunction(env, exportObj, "off", moduleName, JsScreenManager::UnregisterScreenMangerCallback);
BindNativeFunction(env, exportObj, "makeMirror", moduleName, JsScreenManager::MakeMirror); BindNativeFunction(env, exportObj, "makeMirror", moduleName, JsScreenManager::MakeMirror);
BindNativeFunction(env, exportObj, "MultiScreenModeSwitch", moduleName, JsScreenManager::MultiScreenModeSwitch); BindNativeFunction(env, exportObj, "setMultiScreenMode", moduleName, JsScreenManager::SetMultiScreenMode);
BindNativeFunction(env, exportObj, "MultiScreenRelativePosition", moduleName, BindNativeFunction(env, exportObj, "setMultiScreenRelativePosition", moduleName,
JsScreenManager::MultiScreenRelativePosition); JsScreenManager::SetMultiScreenRelativePosition);
BindNativeFunction(env, exportObj, "makeExpand", moduleName, JsScreenManager::MakeExpand); BindNativeFunction(env, exportObj, "makeExpand", moduleName, JsScreenManager::MakeExpand);
BindNativeFunction(env, exportObj, "stopMirror", moduleName, JsScreenManager::StopMirror); BindNativeFunction(env, exportObj, "stopMirror", moduleName, JsScreenManager::StopMirror);
BindNativeFunction(env, exportObj, "stopExpand", moduleName, JsScreenManager::StopExpand); BindNativeFunction(env, exportObj, "stopExpand", moduleName, JsScreenManager::StopExpand);

View File

@ -98,6 +98,11 @@ ohos_shared_library("window_native_kit") {
innerapi_tags = [ "platformsdk" ] innerapi_tags = [ "platformsdk" ]
part_name = "window_manager" part_name = "window_manager"
subsystem_name = "window" subsystem_name = "window"
defines = []
if (build_variant == "user") {
defines += [ "IS_RELEASE_VERSION" ]
}
} }
ohos_shared_library("window_napi") { ohos_shared_library("window_napi") {

View File

@ -31,12 +31,13 @@
#include "pixel_map_napi.h" #include "pixel_map_napi.h"
#include "permission.h" #include "permission.h"
#include "singleton_container.h" #include "singleton_container.h"
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
using namespace AbilityRuntime; using namespace AbilityRuntime;
namespace { namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "JsWindowManager"}; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "JsWindowManager"};
const std::string PIP_WINDOW = "pip_window"; const std::string PIP_WINDOW = "pip_window";
} }
JsWindowManager::JsWindowManager() : registerManager_(std::make_unique<JsWindowRegisterManager>()) JsWindowManager::JsWindowManager() : registerManager_(std::make_unique<JsWindowRegisterManager>())
@ -107,6 +108,7 @@ napi_value JsWindowManager::GetTopWindow(napi_env env, napi_callback_info info)
return (me != nullptr) ? me->OnGetTopWindow(env, info) : nullptr; return (me != nullptr) ? me->OnGetTopWindow(env, info) : nullptr;
} }
/** @note @window.hierarchy */
napi_value JsWindowManager::GetLastWindow(napi_env env, napi_callback_info info) napi_value JsWindowManager::GetLastWindow(napi_env env, napi_callback_info info)
{ {
JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(env, info); JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(env, info);
@ -993,14 +995,18 @@ napi_value JsWindowManager::OnSetWindowLayoutMode(napi_env env, napi_callback_in
napi_value argv[4] = {nullptr}; napi_value argv[4] = {nullptr};
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
if (argc < 1) { // 1: minimum params num if (argc < 1) { // 1: minimum params num
WLOGFE("Argc is invalid: %{public}zu", argc); TLOGI(WmsLogTag::WMS_LAYOUT, "Argc is invalid: %{public}zu", argc);
errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
} }
WindowLayoutMode winLayoutMode = WindowLayoutMode::CASCADE; WindowLayoutMode winLayoutMode = WindowLayoutMode::CASCADE;
if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) {
TLOGI(WmsLogTag::WMS_LAYOUT, "set window layout mode permission denied!");
return NapiThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP);
}
if (errCode == WmErrorCode::WM_OK) { if (errCode == WmErrorCode::WM_OK) {
napi_value nativeMode = argv[0]; napi_value nativeMode = argv[0];
if (nativeMode == nullptr) { if (nativeMode == nullptr) {
WLOGFE("Failed to convert parameter to windowLayoutMode"); TLOGI(WmsLogTag::WMS_LAYOUT, "Failed to convert parameter to windowLayoutMode");
errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
} else { } else {
uint32_t resultValue = 0; uint32_t resultValue = 0;
@ -1012,7 +1018,7 @@ napi_value JsWindowManager::OnSetWindowLayoutMode(napi_env env, napi_callback_in
errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; errCode = WmErrorCode::WM_ERROR_INVALID_PARAM;
} }
if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) {
WLOGFE("JsWindowManager::OnSetWindowLayoutMode failed, Invalidate params."); TLOGI(WmsLogTag::WMS_LAYOUT, "JsWindowManager::OnSetWindowLayoutMode failed, Invalidate params.");
napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_INVALID_PARAM)); napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_INVALID_PARAM));
return NapiGetUndefined(env); return NapiGetUndefined(env);
} }
@ -1063,7 +1069,7 @@ napi_value JsWindowManager::OnSetGestureNavigationEnabled(napi_env env, napi_cal
NapiAsyncTask::CompleteCallback complete = NapiAsyncTask::CompleteCallback complete =
[gestureNavigationEnable](napi_env env, NapiAsyncTask& task, int32_t status) { [gestureNavigationEnable](napi_env env, NapiAsyncTask& task, int32_t status) {
WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at( WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(
SingletonContainer::Get<WindowManager>().SetGestureNavigaionEnabled(gestureNavigationEnable)); SingletonContainer::Get<WindowManager>().SetGestureNavigationEnabled(gestureNavigationEnable));
if (ret == WmErrorCode::WM_OK) { if (ret == WmErrorCode::WM_OK) {
task.Resolve(env, NapiGetUndefined(env)); task.Resolve(env, NapiGetUndefined(env));
WLOGD("SetGestureNavigationEnabled success"); WLOGD("SetGestureNavigationEnabled success");

Some files were not shown because too many files have changed in this diff Show More