diff --git a/bundle.json b/bundle.json index 0b01d4ed9a9af1df10a11de670fbe7fb54ba6e13..47079b78a848c6d151a989a9d589139d9d494603 100755 --- a/bundle.json +++ b/bundle.json @@ -32,7 +32,8 @@ "window_manager_feature_cam_mode", "window_manager_feature_multi_usr", "window_manager_feature_screenless", - "window_manager_feature_asbng_path" + "window_manager_feature_asbng_path", + "window_manager_device_type" ], "adapted_system_type": [ "standard" ], "rom": "8000KB", @@ -128,6 +129,7 @@ "//foundation/window/window_manager/wm:libpip_ndk" ], "service_group": [ + "//foundation/window/window_manager/product:libdms_ext", "//foundation/window/window_manager/sa_profile:wms_sa_profile", "//foundation/window/window_manager/dmserver:libdms", "//foundation/window/window_manager/wmserver:libwms" diff --git a/product/BUILD.gn b/product/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0eb4f9693f34c78d68b7d9c8333abd08954a1356 --- /dev/null +++ b/product/BUILD.gn @@ -0,0 +1,29 @@ +#Copyright (c) 2025-2025 Huawei Device Co., Ltd. +#Licensed under the Apache License, Version 2.0 (the "License"); +#you may not use this file except in compliance with the License. +#You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +#Unless required by applicable law or agreed to in writing, software +#distributed under the License is distributed on an "AS IS" BASIS, +#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#See the License for the specific language governing permissions and +#limitations under the License. + +import("//build/ohos.gni") +import("../windowmanager_aafwk.gni") + +group("libdms_ext") { + # window_manager_device_type必须显示初始化(非"null") + assert( + window_manager_device_type != "null", + "FATAL ERROR: device_type:'${window_manager_device_type}' cannot be 'null'. Please set value in part_config.json" + ) + + if (window_manager_device_type == "phone") { + deps = [ "phone:libdm_extension" ] + } else if (window_manager_device_type == "pc") { + deps = [ "pc:libdm_extension" ] + } +} \ No newline at end of file diff --git a/product/pc/BUILD.gn b/product/pc/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8bff35ecfef03cee167f590f55e3f127044956c2 --- /dev/null +++ b/product/pc/BUILD.gn @@ -0,0 +1,106 @@ +#Copyright (c) 2025-2025 Huawei Device Co., Ltd. +#Licensed under the Apache License, Version 2.0 (the "License"); +#you may not use this file except in compliance with the License. +#You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +#Unless required by applicable law or agreed to in writing, software +#distributed under the License is distributed on an "AS IS" BASIS, +#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#See the License for the specific language governing permissions and +#limitations under the License. +import("//build/ohos.gni") +import("../../windowmanager_aafwk.gni") + +config("libdm_extension_private_config") { + include_dirs = [ + "${window_base_path}/dmserver/include", + "dms/src", + "${window_base_path}//window_scene/session/screen/include", + ] +} + +config("libdm_extension_public_config") { + include_dirs = [ + "${window_base_path}/interfaces/innerkits", + "${window_base_path}/interfaces/innerkits/dm", + "${window_base_path}/utils/include", + "${window_base_path}/dmserver/include", + "${window_base_path}/window_scene/screen_session_manager/include", + ] +} + +## Build libdm_extension.so +ohos_shared_library("libdm_extension") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } + sources = [ + "dms/src/screen_session_manager_extension.cpp", + "dms/src/screen_session_manager_register.cpp" + ] + + configs = [ + ":libdm_extension_private_config", + ] + public_configs = [ + ":libdm_extension_public_config", + ] + + deps = [ + "${window_base_path}/dmserver:display_manager_interface_source_set_proxy", + "${window_base_path}/utils:libwmutil", + "${window_base_path}/utils:libwmutil_base", + "${window_base_path}/window_scene/interfaces/innerkits:libwsutils", + "${window_base_path}/window_scene/common:window_scene_common", + "${window_base_path}/window_scene/screen_session_manager:screen_session_manager", + "${window_base_path}/window_scene:window_scene", + ] + + external_deps = [ + "c_utils:utils", + "graphic_2d:librender_service_base", + "graphic_2d:librender_service_client", + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:dataobs_manager", + "ability_runtime:extension_manager", + "access_token:libaccesstoken_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", + "data_share:datashare_common", + "data_share:datashare_consumer", + "eventhandler:libeventhandler", + "hicollie:libhicollie", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "init:libbeget_proxy", + "ipc:ipc_core", + "libxml2:libxml2", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + part_name = "window_manager" + subsystem_name = "window" + + defines = [] + if (build_variant == "user") { + defines += [ "IS_RELEASE_VERSION" ] + } + visibility = [ "*" ] +} \ No newline at end of file diff --git a/product/pc/dms/src/pc_screen_behavior.cpp b/product/pc/dms/src/pc_screen_behavior.cpp new file mode 100644 index 0000000000000000000000000000000000000000..639499ad280ec9d76764f3895eace20a1ad95a75 --- /dev/null +++ b/product/pc/dms/src/pc_screen_behavior.cpp @@ -0,0 +1,106 @@ +#include "pc_screen_behavior.h" +#include "screen_session.h" +#include "screen_session_manager.h" +#include +#include +#include +#include +#include +#include +#include +#include "input_manager.h" + +#include +#ifdef DEVICE_STATUS_ENABLE +#include +#endif // DEVICE_STATUS_ENABLE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dm_common.h" +#include "fold_screen_state_internel.h" +#ifdef WM_MULTI_SCREEN_ENABLE +#include "multi_screen_change_utils.h" +#include "multi_screen_manager.h" +#include "multi_screen_power_change_manager.h" +#endif +#include "connection/screen_cast_connection.h" +#include "connection/screen_snapshot_picker_connection.h" +#include "dms_xcollie.h" +#include "mock_session_manager_service.h" +#include "param_update/param_update_helper.h" +#include "permission.h" +#include "pipeline/rs_node_map.h" +#include "publish/screen_session_publish.h" +#include "rs_adapter.h" +#include "scene_board_judgement.h" +#include "screen_cache.h" +#include "screen_rotation_property.h" +#include "screen_scene_config.h" +#include "screen_sensor_connector.h" +#include "screen_sensor_plugin.h" +#include "screen_session_dumper.h" +#include "screen_setting_helper.h" +#include "session_permission.h" +#include "surface_capture_future.h" +#include "sys_cap_util.h" +#include "window_manager_hilog.h" +#ifdef POWERMGR_DISPLAY_MANAGER_ENABLE +#include +#endif +#ifdef FOLD_ABILITY_ENABLE +#include "fold_screen_controller/secondary_fold_sensor_manager.h" +#include "fold_screen_controller/super_fold_policy.h" +#include "fold_screen_controller/super_fold_sensor_manager.h" +#include "fold_screen_controller/super_fold_state_manager.h" +#endif +#include "screen_aod_plugin.h" +#include "wm_single_instance.h" + +using namespace OHOS::Rosen; +using OHOS::sptr; +// const int32_t PRODUCT_CODE_SIZE = 4; + +sptr PcScreenBehavior::GetPhysicalScreenSession(ScreenId screenId, ScreenId defScreenId, ScreenProperty property) +{ + TLOGI(WmsLogTag::DMS, "PC: Creating physical screen session %{public}lu", screenId); + ScreenSessionConfig config = { + .screenId = screenId, + .rsId = screenId, + .defaultScreenId = defScreenId, + .property = property, + }; + return new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_REAL); +} + +sptr PcScreenBehavior::GetPhysicalScreenSession(ScreenId screenId) const +{ + TLOGI(WmsLogTag::DMS, "GetPhysicalScreenSession is not supported on pc"); + return nullptr; +} +void PcScreenBehavior::FreeDisplayMirrorNodeInner(const sptr mirrorSession) +{ + if (mirrorSession == nullptr) { + TLOGI(WmsLogTag::DMS, "mirrorSession is null"); + return; + } + { + std::shared_ptr displayNode = mirrorSession->GetDisplayNode(); + if (displayNode == nullptr) { + TLOGI(WmsLogTag::DMS, "displayNode is null"); + return; + } + displayNode->RemoveFromTree(); + mirrorSession->ReleaseDisplayNode(); + } + TLOGI(WmsLogTag::DMS, "free displayNode on pc"); + RSTransactionAdapter::FlushImplicitTransaction(mirrorSession->GetRSUIContext()); +} \ No newline at end of file diff --git a/product/pc/dms/src/pc_screen_behavior.h b/product/pc/dms/src/pc_screen_behavior.h new file mode 100644 index 0000000000000000000000000000000000000000..cd8ace873f34866c9a56b9fcd965fe85a20e915d --- /dev/null +++ b/product/pc/dms/src/pc_screen_behavior.h @@ -0,0 +1,23 @@ +#ifndef PC_SCREEN_BEHAVIOR_H +#define PC_SCREEN_BEHAVIOR_H + +#include "screen_property.h" +#include "screen_session.h" +#include "screen_session_manager.h" + +namespace OHOS { +namespace Rosen { + +class ScreenSessionManager; + +class PcScreenBehavior : public ScreenSessionManager { + WM_DECLARE_SINGLE_INSTANCE(PcScreenBehavior) +public: + sptr GetPhysicalScreenSession(ScreenId screenId, ScreenId defScreenId, ScreenProperty property); + sptr GetPhysicalScreenSession(ScreenId screenId) const; + + void FreeDisplayMirrorNodeInner(const sptr mirrorSession); +}; +} // namespace Rosen +} // namespace OHOS +#endif \ No newline at end of file diff --git a/product/pc/dms/src/pc_screen_behavior_init.cpp b/product/pc/dms/src/pc_screen_behavior_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0d8e0fdf09d83f95ec7177c26203a6a573eac532 --- /dev/null +++ b/product/pc/dms/src/pc_screen_behavior_init.cpp @@ -0,0 +1,12 @@ +#include "pc_screen_behavior.h" +#include "screen_session_manager.h" + +using namespace OHOS::Rosen; +WM_IMPLEMENT_SINGLE_INSTANCE(PcScreenBehavior) +// extern "C"后最近一个定义为C符号 +extern "C" attribute((constructor)) void ScreenBehaviorInitFunc() +{ + TLOGI(WmsLogTag::DMS, "jjl startpc"); + ScreenSessionManager::SetInstance(&PcScreenBehavior::GetInstance()); + TLOGE(WmsLogTag::DMS, "PcScreenBehavior registered successfully"); +} \ No newline at end of file diff --git a/product/pc/dms/src/screen_session_manager_extension.cpp b/product/pc/dms/src/screen_session_manager_extension.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9eef408f12eb78a4af4cb77df1628eebbbbe5858 --- /dev/null +++ b/product/pc/dms/src/screen_session_manager_extension.cpp @@ -0,0 +1,288 @@ +/* + * Copyright (c) 2025 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 "screen_session_manager_extension.h" +#include "screen_session.h" +#include "screen_session_manager.h" +#include +#include +#include +#include +#include +#include +#include +#include "input_manager.h" + +#include +#ifdef DEVICE_STATUS_ENABLE +#include +#endif // DEVICE_STATUS_ENABLE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dm_common.h" +#include "fold_screen_state_internel.h" +#ifdef WM_MULTI_SCREEN_ENABLE +#include "multi_screen_change_utils.h" +#include "multi_screen_manager.h" +#include "multi_screen_power_change_manager.h" +#endif +#include "connection/screen_cast_connection.h" +#include "connection/screen_snapshot_picker_connection.h" +#include "dms_xcollie.h" +#include "mock_session_manager_service.h" +#include "param_update/param_update_helper.h" +#include "permission.h" +#include "pipeline/rs_node_map.h" +#include "publish/screen_session_publish.h" +#include "rs_adapter.h" +#include "scene_board_judgement.h" +#include "screen_cache.h" +#include "screen_rotation_property.h" +#include "screen_scene_config.h" +#include "screen_sensor_connector.h" +#include "screen_sensor_plugin.h" +#include "screen_session_dumper.h" +#include "screen_setting_helper.h" +#include "session_permission.h" +#include "surface_capture_future.h" +#include "sys_cap_util.h" +#include "window_manager_hilog.h" +#ifdef POWERMGR_DISPLAY_MANAGER_ENABLE +#include +#endif +#ifdef FOLD_ABILITY_ENABLE +#include "fold_screen_controller/secondary_fold_sensor_manager.h" +#include "fold_screen_controller/super_fold_policy.h" +#include "fold_screen_controller/super_fold_sensor_manager.h" +#include "fold_screen_controller/super_fold_state_manager.h" +#endif +#include "screen_aod_plugin.h" +#include "wm_single_instance.h" + +using namespace OHOS::Rosen; +using OHOS::sptr; +const int32_t PRODUCT_CODE_SIZE = 4; + +sptr + PcScreenBehavior::GetPhysicalScreenSession(ScreenId screenId, ScreenId defScreenId, ScreenProperty property) +{ + TLOGI(WmsLogTag::DMS, "PC: Creating physical screen session %{public}lu", screenId); + ScreenSessionConfig config = { + .screenId = screenId, + .rsId = screenId, + .defaultScreenId = defScreenId, + .property = property, + }; + return new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_REAL); +} + +sptr + PcScreenBehavior::GetPhysicalScreenSession(ScreenId screenId) const +{ + TLOGI(WmsLogTag::DMS, "GetPhysicalScreenSession is not supported on pc"); + return nullptr; +} +void PcScreenBehavior::FreeDisplayMirrorNodeInner(const sptr mirrorSession) +{ + if (mirrorSession == nullptr) { + TLOGI(WmsLogTag::DMS, "mirrorSession is null"); + return; + } + { + std::shared_ptr displayNode = mirrorSession->GetDisplayNode(); + if (displayNode == nullptr) { + TLOGI(WmsLogTag::DMS, "displayNode is null"); + return; + } + displayNode->RemoveFromTree(); + mirrorSession->ReleaseDisplayNode(); + } + TLOGI(WmsLogTag::DMS, "free displayNode on pc"); + RSTransactionAdapter::FlushImplicitTransaction(mirrorSession->GetRSUIContext()); +} + +void PcScreenBehavior::OnScreenChange(ScreenId screenId, ScreenEvent screenEvent, ScreenChangeReason reason) +{ + if (reason == ScreenChangeReason::HWCDEAD) { + NotifyAbnormalScreenConnectChange(screenId); + TLOGW(WmsLogTag::DMS, + "screenId: %{public}" PRIu64 " ScreenChangeReason: %{public}d", + screenId, + static_cast(reason)); + return; + } + OnScreenChangeForPC(screenId, screenEvent, reason); +} + +void PcScreenBehavior::GetAndMergeEdidInfo(sptr screenSession) +{ + ScreenId screenId = screenSession->GetScreenId(); + struct BaseEdid edid; + if (!GetEdid(screenId, edid)) { + TLOGE(WmsLogTag::DMS, "get EDID failed."); + return; + } + std::string serialNumber = ConvertEdidToString(edid); + screenSession->SetSerialNumber(serialNumber); + if (!edid.displayProductName_.empty()) { + screenSession->SetName(edid.displayProductName_); + } else { + std::string productCodeStr; + std::string connector = "-"; + std::ostringstream oss; + oss << std::hex << std::uppercase << std::setw(PRODUCT_CODE_SIZE) << std::setfill('0') << edid.productCode_; + productCodeStr = oss.str(); + screenSession->SetName(edid.manufacturerName_ + connector + productCodeStr); + } +} + +void PcScreenBehavior::HandleScreenConnectEvent(sptr screenSession, + ScreenId screenId, ScreenEvent screenEvent) +{ + bool phyMirrorEnable = IsDefaultMirrorMode(screenId); + HandlePhysicalMirrorConnect(screenSession, phyMirrorEnable); + auto clientProxy = GetClientProxy(); +#ifdef FOLD_ABILITY_ENABLE + if (FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { + SuperFoldStateManager::GetInstance().RefreshExternalRegion(); + } + if (foldScreenController_ != nullptr) { + if ((screenId == 0 || (screenId == SCREEN_ID_MAIN && isCoordinationFlag_ == true)) && clientProxy) { + TLOGW(WmsLogTag::DMS,"event: connect %{public}" PRIu64 ", %{public}" PRIu64", " + "name=%{public}s",screenId, screenSession->GetRSScreenId(), screenSession->GetName().c_str()); + clientProxy->OnScreenConnectionChanged(GetSessionOption(screenSession, screenId), screenEvent); + } + return; + } +#endif + if (clientProxy) { + { + std::unique_lock lock(displayAddMutex_); + needWaitAvailableArea_ = true; + } + clientProxy->OnScreenConnectionChanged(GetSessionOption(screenSession, screenId), screenEvent); + sptr internalSession = GetInternalScreenSession(); + if (!RecoverRestoredMultiScreenMode(screenSession)) { + SetMultiScreenDefaultRelativePosition(); + ReportHandleScreenEvent(ScreenEvent::CONNECTED, ScreenCombination::SCREEN_EXTEND); + } + sptr newInternalSession = GetInternalScreenSession(); + if (newInternalSession != nullptr && internalSession != nullptr && + internalSession->GetScreenId() != newInternalSession->GetScreenId()) { + TLOGW(WmsLogTag::DMS, "main screen changed, reset screenSession."); + screenSession = internalSession; + } + SetExtendedScreenFallbackPlan(screenSession->GetScreenId()); + } + if (phyMirrorEnable) { + NotifyScreenConnected(screenSession->ConvertToScreenInfo()); + // when display add, need wait update available area, ensure display info is accurate + WaitUpdateAvailableAreaForPc(); + NotifyDisplayCreate(screenSession->ConvertToDisplayInfo()); + } + TLOGW(WmsLogTag::DMS, "connect end. ScreenId: %{public}" PRIu64, screenId); +} + +DMError PcScreenBehavior::GetDisplayCapability(std::string& capabilitInfo) +{ + if (isFoldDevice) { + if (FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { + return GetSecondaryDisplayCapability(capabilitInfo); + } + return GetFoldableDeviceCapability(capabilitInfo); + } + if (FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { + return GetSuperFoldCapability(capabilitInfo); + } + + std::vector orientation = ORIENTATION_DEFAULT; + if (!FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { + orientation = { "1", "0", "3", "2" }; + } + nlohmann::ordered_json jsonDisplayCapabilityList; + jsonDisplayCapabilityList["capability"] = nlohmann::json::array(); + nlohmann::ordered_json capabilityInfo = GetCapabilityJson(FoldStatus::UNKNOWN, FoldDisplayMode::UNKNOWN, + ROTATION_DEFAULT, orientation); + jsonDisplayCapabilityList["capability"].push_back(std::move(capabilityInfo)); + + capabilitInfo = jsonDisplayCapabilityList.dump(); + return DMError::DM_OK; +} + +sptr ScreenSessionManager::GetOrCreateScreenSession(ScreenId screenId) +{ + TLOGW(WmsLogTag::DMS, "ENTER. ScreenId: %{public}" PRIu64 "", screenId); + sptr screenSession = GetScreenSession(screenId); + if (screenSession) { + TLOGW(WmsLogTag::DMS, "screenSession Exist ScreenId: %{public}" PRIu64, screenId); + return screenSession; + } + std::lock_guard lock_phy(phyScreenPropMapMutex_); + if (phyScreenPropMap_.size() > 1) { + // pc is none, pad&&phone is mirror + TLOGW(WmsLogTag::DMS, "Only Support one External screen."); + return nullptr; + } + screenIdManager_.UpdateScreenId(screenId, screenId); + + ScreenProperty property; + CreateScreenProperty(screenId, property); + TLOGW(WmsLogTag::DMS, "call create screen property end"); + screenEventTracker_.RecordEvent("CreateScreenProperty by rsInterface success."); + { + std::lock_guard lock_phy(phyScreenPropMapMutex_); + phyScreenPropMap_[screenId] = property; + } + + if (HandleFoldScreenSessionCreate(screenId) == false) { + return nullptr; + } + + sptr session = GetScreenSessionInner(screenId, property); + if (session == nullptr) { + TLOGE(WmsLogTag::DMS, "get screen session fail ScreenId: %{public}" PRIu64, screenId); + return session; + } + session->RegisterScreenChangeListener(this); + InitExtendScreenDensity(session, property); + InitAbstractScreenModesInfo(session); + session->groupSmsId_ = 1; + { + std::lock_guard lock(screenSessionMapMutex_); + screenSessionMap_[screenId] = session; + } + SetMultiScreenFrameControl(); + screenEventTracker_.RecordEvent("create screen session success."); + SetHdrFormats(GetPhyScreenId(screenId), session); + SetColorSpaces(GetPhyScreenId(screenId), session); + SetSupportedRefreshRate(session); + if (session->GetFakeScreenSession() != nullptr) { + std::vector supportedRefreshRateFake = session->GetSupportedRefreshRate(); + sptr screenSessionFake = session->GetFakeScreenSession(); + screenSessionFake->SetSupportedRefreshRate(std::move(supportedRefreshRateFake)); + } + RegisterRefreshRateChangeListener(); + TLOGW(WmsLogTag::DMS, "CreateScreenSession success. ScreenId: %{public}" PRIu64 "", screenId); + return session; +} \ No newline at end of file diff --git a/product/pc/dms/src/screen_session_manager_extension.h b/product/pc/dms/src/screen_session_manager_extension.h new file mode 100644 index 0000000000000000000000000000000000000000..7e569050099dfe5b8a6cea949c3defc5deba354b --- /dev/null +++ b/product/pc/dms/src/screen_session_manager_extension.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 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 SCREEN_SESSION_MANAGER_EXTENSION_H +#define SCREEN_SESSION_MANAGER_EXTENSION_H + +#include "fold_screen_state_internel.h" +#include "screen_property.h" +#include "screen_session.h" +#include "screen_session_manager.h" + +namespace OHOS { +namespace Rosen { + +class ScreenSessionManager; + +class PcScreenBehavior : public ScreenSessionManager { + WM_DECLARE_SINGLE_INSTANCE(PcScreenBehavior) +private: + bool isFoldDevice = system::GetParameter("const.window.foldscreen.type", "") != ""; + +public: + sptr GetPhysicalScreenSession(ScreenId screenId, ScreenId defScreenId, ScreenProperty property); + sptr GetPhysicalScreenSession(ScreenId screenId) const; + sptr GetOrCreateScreenSession(ScreenId screenId); + + void FreeDisplayMirrorNodeInner(const sptr mirrorSession); + void OnScreenChange(ScreenId screenId, ScreenEvent screenEvent, ScreenChangeReason reason); + void GetAndMergeEdidInfo(sptr screenSession); + void HandleScreenConnectEvent(sptr screenSession, ScreenId screenId, ScreenEvent screenEvent); + DMError GetDisplayCapability(std::string& capabilitInfo); +}; +} // namespace Rosen +} // namespace OHOS +#endif \ No newline at end of file diff --git a/product/pc/dms/src/screen_session_manager_register.cpp b/product/pc/dms/src/screen_session_manager_register.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3edb6ba0337a4b825778a333b49eaddb13f56da7 --- /dev/null +++ b/product/pc/dms/src/screen_session_manager_register.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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 "screen_session_manager_extension.h" +#include "screen_session_manager.h" + +using namespace OHOS::Rosen; +WM_IMPLEMENT_SINGLE_INSTANCE(PcScreenBehavior) + // extern "C"后最近一个定义为C符号 +extern "C" __attribute__((constructor)) void ScreenBehaviorInitFunc() +{ + TLOGI(WmsLogTag::DMS, "startpc"); + ScreenSessionManager::SetInstance(&PcScreenBehavior::GetInstance()); + TLOGE(WmsLogTag::DMS, "PcScreenBehavior registered successfully"); +} \ No newline at end of file diff --git a/product/phone/BUILD.gn b/product/phone/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..521be64f167909f5da1292185920cc9c40fdc6f5 --- /dev/null +++ b/product/phone/BUILD.gn @@ -0,0 +1,106 @@ +#Copyright (c) 2025-2025 Huawei Device Co., Ltd. +#Licensed under the Apache License, Version 2.0 (the "License"); +#you may not use this file except in compliance with the License. +#You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +#Unless required by applicable law or agreed to in writing, software +#distributed under the License is distributed on an "AS IS" BASIS, +#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#See the License for the specific language governing permissions and +#limitations under the License. +import("//build/ohos.gni") +import("../../windowmanager_aafwk.gni") + +config("libdm_extension_private_config") { + include_dirs = [ + "${window_base_path}/dmserver/include", + "dms/src", + "${window_base_path}//window_scene/session/screen/include", + ] +} + +config("libdm_extension_public_config") { + include_dirs = [ + "${window_base_path}/interfaces/innerkits", + "${window_base_path}/interfaces/innerkits/dm", + "${window_base_path}/utils/include", + "${window_base_path}/dmserver/include", + "${window_base_path}/window_scene/screen_session_manager/include", + ] +} + +## Build libdm_extension.so +ohos_shared_library("libdm_extension") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } + sources = [ + "dms/src/screen_session_manager_extension.cpp", + "dms/src/screen_session_manager_register.cpp" + ] + + configs = [ + ":libdm_extension_private_config", + ] + + public_configs = [ + ":libdm_extension_public_config", + ] + + deps = [ + "${window_base_path}/dmserver:display_manager_interface_source_set_proxy", + "${window_base_path}/utils:libwmutil", + "${window_base_path}/utils:libwmutil_base", + "${window_base_path}/window_scene/interfaces/innerkits:libwsutils", + "${window_base_path}/window_scene/common:window_scene_common", + "${window_base_path}/window_scene/screen_session_manager:screen_session_manager", + ] + + external_deps = [ + "c_utils:utils", + "graphic_2d:librender_service_base", + "graphic_2d:librender_service_client", + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:dataobs_manager", + "ability_runtime:extension_manager", + "access_token:libaccesstoken_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", + "data_share:datashare_common", + "data_share:datashare_consumer", + "eventhandler:libeventhandler", + "hicollie:libhicollie", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "init:libbeget_proxy", + "ipc:ipc_core", + "libxml2:libxml2", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + part_name = "window_manager" + subsystem_name = "window" + + defines = [] + if (build_variant == "user") { + defines += [ "IS_RELEASE_VERSION" ] + } + visibility = [ "*" ] +} \ No newline at end of file diff --git a/product/phone/dms/src/phone_screen_behavior.cpp b/product/phone/dms/src/phone_screen_behavior.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d62ded11373d8ecf059b60ce0c75d2e6f5426845 --- /dev/null +++ b/product/phone/dms/src/phone_screen_behavior.cpp @@ -0,0 +1,6 @@ +#include "phone_screen_behavior.h" +#include "screen_session_manager.h" +#include "screen_session.h" +#include "window_manager_hilog.h" + +using namespace OHOS::Rosen; \ No newline at end of file diff --git a/product/phone/dms/src/phone_screen_behavior.h b/product/phone/dms/src/phone_screen_behavior.h new file mode 100644 index 0000000000000000000000000000000000000000..1b3c9a8a9cd24440ff5a239c9fe93ab4cd45ced8 --- /dev/null +++ b/product/phone/dms/src/phone_screen_behavior.h @@ -0,0 +1,18 @@ +#ifndef PHONE_SCREEN_BEHAVIOR_H +#define PHONE_SCREEN_BEHAVIOR_H + +#include "screen_property.h" +#include "screen_session.h" +#include "screen_session_manager.h" + +namespace OHOS { +namespace Rosen { + +class ScreenSessionManager; + +class PhoneScreenBehavior : public ScreenSessionManager { + WM_DECLARE_SINGLE_INSTANCE(PhoneScreenBehavior) +}; +} // namespace Rosen +} // namespace OHOS +#endif \ No newline at end of file diff --git a/product/phone/dms/src/phone_screen_behavior_init.cpp b/product/phone/dms/src/phone_screen_behavior_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5f6a961a2cd332957fb52012b32dabb39a176ebc --- /dev/null +++ b/product/phone/dms/src/phone_screen_behavior_init.cpp @@ -0,0 +1,13 @@ +#include "phone_screen_behavior.h" +#include "screen_session_manager.h" + +using namespace OHOS::Rosen; +WM_IMPLEMENT_SINGLE_INSTANCE(PhoneScreenBehavior) + +// extern "C"后最近一个定义为C符号 +extern "C" attribute((constructor)) void ScreenBehaviorInitFunc() +{ + TLOGI(WmsLogTag::DMS, "jjl startphone"); + ScreenSessionManager::SetInstance(&PhoneScreenBehavior::GetInstance()); + TLOGI(WmsLogTag::DMS, "PhoneScreenBehavior registered successfully"); +} \ No newline at end of file diff --git a/product/phone/dms/src/screen_session_manager_extension.cpp b/product/phone/dms/src/screen_session_manager_extension.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c8329808ff6e0f4e03460212014f81c71e4814aa --- /dev/null +++ b/product/phone/dms/src/screen_session_manager_extension.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 "screen_session_manager_extension.h" +#include "screen_session_manager.h" +#include "screen_session.h" +#include "window_manager_hilog.h" + +using namespace OHOS::Rosen; \ No newline at end of file diff --git a/product/phone/dms/src/screen_session_manager_extension.h b/product/phone/dms/src/screen_session_manager_extension.h new file mode 100644 index 0000000000000000000000000000000000000000..b44772d8d59be4bb25cb868ff62b66810f0947bb --- /dev/null +++ b/product/phone/dms/src/screen_session_manager_extension.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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 SCREEN_SESSION_MANAGER_EXTENSION_H +#define SCREEN_SESSION_MANAGER_EXTENSION_H + +#include "screen_property.h" +#include "screen_session.h" +#include "screen_session_manager.h" + +namespace OHOS { +namespace Rosen { + +class ScreenSessionManager; + +class PhoneScreenBehavior : public ScreenSessionManager { + WM_DECLARE_SINGLE_INSTANCE(PhoneScreenBehavior) +}; +} // namespace Rosen +} // namespace OHOS +#endif \ No newline at end of file diff --git a/product/phone/dms/src/screen_session_manager_register.cpp b/product/phone/dms/src/screen_session_manager_register.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a3c0fe4ffc26d81820e76b1ffbf005574ede33d4 --- /dev/null +++ b/product/phone/dms/src/screen_session_manager_register.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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 "screen_session_manager_extension.h" +#include "screen_session_manager.h" + +using namespace OHOS::Rosen; +WM_IMPLEMENT_SINGLE_INSTANCE(PhoneScreenBehavior) + +// extern "C"后最近一个定义为C符号 +extern "C" __attribute__((constructor)) void ScreenBehaviorInitFunc() +{ + TLOGI(WmsLogTag::DMS, "startphone"); + ScreenSessionManager::SetInstance(&PhoneScreenBehavior::GetInstance()); + TLOGI(WmsLogTag::DMS, "PhoneScreenBehavior registered successfully"); +} \ No newline at end of file diff --git a/utils/include/window_manager_hilog.h b/utils/include/window_manager_hilog.h index 94c974f65f65a75e1cca91d382b1fd7b76579ad3..56cd4c80c717c9a70d16e852b9d71557c32751aa 100644 --- a/utils/include/window_manager_hilog.h +++ b/utils/include/window_manager_hilog.h @@ -27,15 +27,23 @@ static constexpr unsigned int HILOG_DOMAIN_DISPLAY = 0xD004201; #define PRINT_WLOG(level, ...) HILOG_IMPL(LABEL.type, level, LABEL.domain, LABEL.tag, ##__VA_ARGS__) +#ifndef WLOGD #define WLOGD(fmt, ...) PRINT_WLOG(LOG_DEBUG, "(%{public}d)" fmt, __LINE__, ##__VA_ARGS__) +#endif +#ifndef WLOGI #define WLOGI(fmt, ...) PRINT_WLOG(LOG_INFO, "(%{public}d)" fmt, __LINE__, ##__VA_ARGS__) +#endif +#ifndef WLOGW #define WLOGW(fmt, ...) PRINT_WLOG(LOG_WARN, "(%{public}d)" fmt, __LINE__, ##__VA_ARGS__) +#endif +#ifndef #define WLOGE(fmt, ...) PRINT_WLOG(LOG_ERROR, "(%{public}d)" fmt, __LINE__, ##__VA_ARGS__) +#endif #define C_W_FUNC __func__ #define WLOGFD(fmt, ...) WLOGD("%{public}s: " fmt, C_W_FUNC, ##__VA_ARGS__) -#define WLOGFI(fmt, ...) WLOGI("%{public}s: " fmt, C_W_FUNC, ##__VA_ARGS__) +#define WLOGFI(fmt, ...) WLOGI("%{public}s: " fmt, C_W_FUNC, ##__VA_ARGS__)` #define WLOGFW(fmt, ...) WLOGW("%{public}s: " fmt, C_W_FUNC, ##__VA_ARGS__) #define WLOGFE(fmt, ...) WLOGE("%{public}s: " fmt, C_W_FUNC, ##__VA_ARGS__) diff --git a/utils/include/wm_single_instance.h b/utils/include/wm_single_instance.h index 45419145908e5f9f763aa833f6b7df1aaa4a0b0e..edbc0a533a2aa6867fd45620d370cd10e02d2e2c 100644 --- a/utils/include/wm_single_instance.h +++ b/utils/include/wm_single_instance.h @@ -15,29 +15,51 @@ #ifndef OHOS_WM_SINGLE_INSTANCE_H #define OHOS_WM_SINGLE_INSTANCE_H +#include +#include +#include "window_manager_hilog.h" + namespace OHOS { namespace Rosen { -#define WM_DECLARE_SINGLE_INSTANCE_BASE(className) \ -public: \ - static className& GetInstance(); \ - className(const className&) = delete; \ - className& operator= (const className&) = delete; \ - className(className&&) = delete; \ - className& operator= (className&&) = delete; \ +#define WM_DECLARE_SINGLE_INSTANCE_BASE(className) \ +public: \ + typedef className __LocalType##className; \ + static __LocalType##className& GetInstance(); \ + static void SetInstance(__LocalType##className* newInstance); \ + className(const className&) = delete; \ + className& operator=(const className&) = delete; \ + className(className&&) = delete; \ + className& operator=(className&&) = delete; \ + static __LocalType##className* _singleton; #define WM_DECLARE_SINGLE_INSTANCE(className) \ WM_DECLARE_SINGLE_INSTANCE_BASE(className) \ protected: \ className() = default; \ - virtual ~className() = default; \ - -#define WM_IMPLEMENT_SINGLE_INSTANCE(className) \ -className& className::GetInstance() \ -{ \ - static className instance; \ - return instance; \ -} \ + virtual ~className() = default; +#define WM_IMPLEMENT_SINGLE_INSTANCE(className) \ + className* className::_singleton = nullptr; \ + className& className::GetInstance() \ + { \ + if (!_singleton) { \ + _singleton = new className(); \ + } \ + TLOGI(WmsLogTag::DMS, "GetDefaultInstance:instance address = %{public}s %{public}p", #className, _singleton); \ + return *_singleton; \ + } \ + void className::SetInstance(className* newInstance) \ + { \ + TLOGI(WmsLogTag::DMS, \ + "SetInstance:instance address = %{public}s %{public}p %{public}p", \ + #className, \ + newInstance, \ + _singleton); \ + if (_singleton) { \ + TLOGE(WmsLogTag::DMS, "c %{public}s %{public}p", #className, _singleton); \ + } \ + _singleton = newInstance; \ + } +} // namespace Rosen } // namespace OHOS -} -#endif // OHOS_SINGLE_INSTANCE_H +#endif // OHOS_SINGLE_INSTANCE_H \ No newline at end of file diff --git a/window_scene/screen_session_manager/BUILD.gn b/window_scene/screen_session_manager/BUILD.gn index d2f89128ab798ad8539db502c72c4ed038bd4485..a6b1fb672ac147a6d56763eec5a648ff9a84c12a 100644 --- a/window_scene/screen_session_manager/BUILD.gn +++ b/window_scene/screen_session_manager/BUILD.gn @@ -32,7 +32,6 @@ config("session_manager_public_config") { "${window_base_path}/wmserver/include/zidl", # for screen_session_manager - "${window_base_path}/utils/include", "${window_base_path}/dm/include", "${window_base_path}/interfaces/innerkits/dm", "${window_base_path}/dmserver/include", diff --git a/window_scene/screen_session_manager/include/screen_session_manager.h b/window_scene/screen_session_manager/include/screen_session_manager.h index ca778ddaa5a972a7de6adc43323384c94651b94b..a23e2dcf2d4cbe6a3e216db2ba5964bbaff996b2 100644 --- a/window_scene/screen_session_manager/include/screen_session_manager.h +++ b/window_scene/screen_session_manager/include/screen_session_manager.h @@ -60,8 +60,12 @@ static const std::map SCREEN_STATUS_POWER_ {ScreenPowerStatus::POWER_STATUS_DOZE_SUSPEND, DisplayPowerEvent::DISPLAY_DOZE_SUSPEND} }; +using SetScreenBehaviorFunc = void (*)(); + +extern const std::vector ROTATION_DEFAULT; +extern const std::vector ORIENTATION_DEFAULT; class ScreenSessionManager : public SystemAbility, public ScreenSessionManagerStub, public IScreenChangeListener { -DECLARE_SYSTEM_ABILITY(ScreenSessionManager) +DECLARE_SYSTEM_ABILITY(ScreenSessionManager); WM_DECLARE_SINGLE_INSTANCE_BASE(ScreenSessionManager) public: @@ -459,6 +463,9 @@ public: ScreenCombination GetScreenCombination(ScreenId screenId) override; DMError SetScreenSkipProtectedWindow(const std::vector& screenIds, bool isEnable) override; void UpdateValidArea(ScreenId screenId, uint32_t validWidth, uint32_t validHeight); + virtual sptr GetPhysicalScreenSession(ScreenId screenId) const; + virtual sptr GetPhysicalScreenSession(ScreenId screenId, + ScreenId defScreenId, ScreenProperty property); bool GetIsRealScreen(ScreenId screenId) override; void UnregisterSettingWireCastObserver(ScreenId screenId); void RegisterSettingWireCastObserver(sptr& screenSession); @@ -466,7 +473,8 @@ public: SessionOption GetSessionOption(sptr screenSession, ScreenId screenId); virtual DMError SetSystemKeyboardStatus(bool isTpKeyboardOn = false) override; - sptr GetPhysicalScreenSession(ScreenId screenId) const; + virtual sptr GetPhysicalScreenSession(ScreenId screenId) const; + virtual sptr GetPhysicalScreenSession(ScreenId screenId, ScreenId defScreenId, ScreenProperty property); sptr GetScreenSessionByRsId(ScreenId rsScreenId); void NotifyExtendScreenCreateFinish() override; void NotifyExtendScreenDestroyFinish() override; @@ -498,9 +506,20 @@ public: protected: ScreenSessionManager(); virtual ~ScreenSessionManager() = default; + std::string ConvertEdidToString(const struct BaseEdid edidData); + bool IsDefaultMirrorMode(ScreenId screenId); + std::mutex displayAddMutex_; + bool needWaitAvailableArea_ = false; + sptr GetInternalScreenSession(); + bool RecoverRestoredMultiScreenMode(sptr screenSession); + void SetMultiScreenDefaultRelativePosition(); + void ReportHandleScreenEvent(ScreenEvent screenEvent, ScreenCombination screenCombination); + void SetExtendedScreenFallbackPlan(ScreenId screenId); + void WaitUpdateAvailableAreaForPc(); private: void OnStart() override; + void LoadDmsExtension(); void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; void Init(); void LoadScreenSceneXml(); @@ -535,7 +554,6 @@ private: sptr CreateFakePhysicalMirrorSessionInner(ScreenId screenId, ScreenId defaultScreenId, ScreenProperty property); sptr GetFakePhysicalScreenSession(ScreenId screenId, ScreenId defScreenId, ScreenProperty property); - sptr GetPhysicalScreenSession(ScreenId screenId, ScreenId defScreenId, ScreenProperty property); void FreeDisplayMirrorNodeInner(const sptr mirrorSession); void MirrorSwitchNotify(ScreenId screenId); ScreenId GetDefaultScreenId(); @@ -544,15 +562,11 @@ private: void PhyMirrorConnectWakeupScreen(); bool GetIsCurrentInUseById(ScreenId screenId); void GetAndMergeEdidInfo(sptr screenSession); - std::string ConvertEdidToString(const struct BaseEdid edidData); - bool RecoverRestoredMultiScreenMode(sptr screenSession); bool CheckMultiScreenInfoMap(std::map multiScreenInfoMap, const std::string& serialNumber); - void SetExtendedScreenFallbackPlan(ScreenId screenId); void SetExtendedScreenFallbackPlanEvent(int32_t res); void SetInnerScreenFallbackPlan(sptr screenSession); int32_t GetCurrentInUseScreenNumber(); - void ReportHandleScreenEvent(ScreenEvent screenEvent, ScreenCombination screenCombination); void HandleScreenConnectEvent(sptr screenSession, ScreenId screenId, ScreenEvent screenEvent); void HandleScreenDisconnectEvent(sptr screenSession, ScreenId screenId, ScreenEvent screenEvent); void HandlePhysicalMirrorDisconnect(sptr screenSession, ScreenId screenId, bool phyMirrorEnable); @@ -569,7 +583,6 @@ private: void RecoverMultiScreenMode(sptr screenSession); void GetCurrentScreenPhyBounds(float& phyWidth, float& phyHeight, bool& isReset, const ScreenId& screenid); void SetPhysicalRotationClientInner(ScreenId screenId, int rotation); - sptr GetInternalScreenSession(); void ExitOuterOnlyMode(ScreenId mainScreenId, ScreenId secondaryScreenId, MultiScreenMode screenMode); void AdaptSuperHorizonalBoot(sptr screenSession, ScreenId screenId); @@ -589,7 +602,6 @@ private: bool GetPowerStatus(ScreenPowerState state, PowerStateChangeReason reason, ScreenPowerStatus& status); DMError CheckDisplayMangerAgentTypeAndPermission( const sptr& displayManagerAgent, DisplayManagerAgentType type); - void SetMultiScreenDefaultRelativePosition(); void SetRelativePositionForDisconnect(MultiScreenPositionOptions defaultScreenOptions); int Dump(int fd, const std::vector& args) override; sptr HookDisplayInfoByUid(sptr displayInfo, const sptr& screenSession); @@ -727,7 +739,6 @@ private: bool isFoldScreenOuterScreenReady_ = false; bool isCameraBackSelfie_ = false; bool isDeviceShutDown_ = false; - bool needWaitAvailableArea_ = false; uint32_t hdmiScreenCount_ = 0; uint32_t virtualScreenCount_ = 0; uint32_t currentExpandScreenCount_ = 0; @@ -787,7 +798,6 @@ private: std::mutex screenChangeMutex_; std::mutex screenMaskMutex_; std::condition_variable screenMaskCV_; - std::mutex displayAddMutex_; std::mutex screenModeChangeMutex_; std::condition_variable displayAddCV_; mutable std::mutex setPcStatusMutex_; @@ -835,7 +845,6 @@ private: float& translateX, float& translateY); void RegisterApplicationStateObserver(); void SetPostureAndHallSensorEnabled(); - bool IsDefaultMirrorMode(ScreenId screenId); void SetCastFromSettingData(); void RegisterCastObserver(std::vector& mirrorScreenIds); void SetCastPrivacyFromSettingData(); @@ -854,7 +863,6 @@ private: void SetExtendScreenDpi(); bool HandleSwitchPcMode(); void SwitchModeHandleExternalScreen(bool isSwitchToPcMode); - void WaitUpdateAvailableAreaForPc(); std::unordered_map> screenCastInfoMap_; std::shared_mutex screenCastInfoMapMutex_; diff --git a/window_scene/screen_session_manager/src/screen_session_manager.cpp b/window_scene/screen_session_manager/src/screen_session_manager.cpp index 4e1c16aee825f0c104ae2dc5cfedd3329b9a3b8a..8b3b5f6f5c3326ce535b1b35c38a721a61c253cf 100644 --- a/window_scene/screen_session_manager/src/screen_session_manager.cpp +++ b/window_scene/screen_session_manager/src/screen_session_manager.cpp @@ -76,9 +76,17 @@ #include "fold_screen_controller/super_fold_policy.h" #endif #include "screen_aod_plugin.h" +#include "wm_single_instance.h" namespace OHOS::Rosen { +const std::vector ROTATION_DEFAULT = {"0", "1", "2", "3"}; +const std::vector ORIENTATION_DEFAULT = {"0", "1", "2", "3"}; namespace { +#if (defined(aarch64) || defined(x86_64)) +const std::string EXT_PLUGIN_SO_PATH = "/system/lib64/libdm_extension.z.so"; +#else +const std::string EXT_PLUGIN_SO_PATH = "/system/lib/libdm_extension.z.so"; +#endif const std::string SCREEN_SESSION_MANAGER_THREAD = "OS_ScreenSessionManager"; const std::string SCREEN_SESSION_MANAGER_SCREEN_POWER_THREAD = "OS_ScreenSessionManager_ScreenPower"; const std::string SCREEN_CAPTURE_PERMISSION = "ohos.permission.CAPTURE_SCREEN"; @@ -119,6 +127,7 @@ static const int32_t ROTATION_270 = 3; constexpr int32_t REMOVE_DISPLAY_MODE = 0; #endif const unsigned int XCOLLIE_TIMEOUT_10S = 10; +constexpr uint32_t SLEEP_TIME_US = 10000; constexpr int32_t CAST_WIRED_PROJECTION_START = 1005; constexpr int32_t CAST_WIRED_PROJECTION_STOP = 1007; constexpr int32_t RES_FAILURE_FOR_PRIVACY_WINDOW = -2; @@ -148,8 +157,6 @@ constexpr float DEFAULT_SCALE = 1.0f; constexpr float SECONDARY_ROTATION_90 = 90.0F; constexpr float SECONDARY_ROTATION_270 = 270.0F; static const constexpr char* SET_SETTING_DPI_KEY {"default_display_dpi"}; -const std::vector ROTATION_DEFAULT = {"0", "1", "2", "3"}; -const std::vector ORIENTATION_DEFAULT = {"0", "1", "2", "3"}; const uint32_t MAX_INTERVAL_US = 1800000000; // 30分钟 const int32_t MAP_SIZE = 300; const std::string NO_EXIST_BUNDLE_MANE = "null"; @@ -227,8 +234,26 @@ inline int32_t GetUserIdByCallingUid() WM_IMPLEMENT_SINGLE_INSTANCE(ScreenSessionManager) -const bool REGISTER_RESULT = !SceneBoardJudgement::IsSceneBoardEnabled() ? false : - SystemAbility::MakeAndRegisterAbility(&ScreenSessionManager::GetInstance()); + +void LoadDmsExtension() +{ + TLOGE(WmsLogTag::DMS, "start"); + void* handler = nullptr; + int32_t cnt = 0; + int32_t retryTimes = 3; + do { + cnt++; + handler = dlopen(EXT_PLUGIN_SO_PATH.c_str(), RTLD_NOW | RTLD_NODELETE); + TLOGI(WmsLogTag::DMS, "dlopen %{public}s, retry cnt: %{public}d", EXT_PLUGIN_SO_PATH.c_str(), cnt); + usleep(SLEEP_TIME_US); + } while (!handler && cnt < retryTimes); +} +bool getScreenSessionMngSystemAbility() +{ + LoadDmsExtension(); + return SystemAbility::MakeAndRegisterAbility(&ScreenSessionManager::GetInstance()); +} +const bool REGISTER_RESULT = !SceneBoardJudgement::IsSceneBoardEnabled() ? false : getScreenSessionMngSystemAbility(); ScreenSessionManager::ScreenSessionManager() : SystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, true), rsInterface_(RSInterfaces::GetInstance()) @@ -470,7 +495,6 @@ void ScreenSessionManager::Init() void ScreenSessionManager::OnStart() { - TLOGI(WmsLogTag::DMS, "start"); DmsXcollie dmsXcollie("DMS:OnStart", XCOLLIE_TIMEOUT_10S, [this](void *) { screenEventTracker_.LogWarningAllInfos(); }); Init(); @@ -488,7 +512,7 @@ void ScreenSessionManager::OnStart() TLOGI(WmsLogTag::DMS, "end"); screenEventTracker_.RecordEvent("Dms onstart end."); } - +//pc为主 void ScreenSessionManager::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) { HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "OnAddSystemAbility: %d", systemAbilityId); @@ -878,10 +902,8 @@ void ScreenSessionManager::FreeDisplayMirrorNodeInner(const sptr if (displayNode == nullptr) { return; } - if (!g_isPcDevice) { - hdmiScreenCount_ = hdmiScreenCount_ > 0 ? hdmiScreenCount_ - 1 : 0; - NotifyCaptureStatusChanged(); - } + hdmiScreenCount_ = hdmiScreenCount_ > 0 ? hdmiScreenCount_ - 1 : 0; + NotifyCaptureStatusChanged(); displayNode->RemoveFromTree(); mirrorSession->ReleaseDisplayNode(); displayNode = nullptr; @@ -935,11 +957,7 @@ void ScreenSessionManager::OnScreenChange(ScreenId screenId, ScreenEvent screenE screenId, static_cast(reason)); return; } - if (g_isPcDevice) { - OnScreenChangeForPC(screenId, screenEvent, reason); - } else { - OnScreenChangeDefault(screenId, screenEvent, reason); - } + OnScreenChangeDefault(screenId, screenEvent, reason); } void ScreenSessionManager::OnScreenChangeForPC(ScreenId screenId, ScreenEvent screenEvent, ScreenChangeReason reason) @@ -959,12 +977,11 @@ void ScreenSessionManager::OnScreenChangeForPC(ScreenId screenId, ScreenEvent sc } AdaptSuperHorizonalBoot(screenSession, screenId); if (g_isPcDevice) { - auto physicalScreenSession = GetOrCreatePhysicalScreenSession(screenId); - if (!physicalScreenSession) { - TLOGE(WmsLogTag::DMS, "physicalScreenSession is nullptr"); - return; - } - AdaptSuperHorizonalBoot(physicalScreenSession, screenId); + auto physicalScreenSession = GetOrCreatePhysicalScreenSession(screenId); + if (!physicalScreenSession) { + TLOGE(WmsLogTag::DMS, "physicalScreenSession is nullptr"); + return; + } } OnFoldScreenChange(screenSession); if (screenEvent == ScreenEvent::CONNECTED) { @@ -1142,10 +1159,6 @@ void ScreenSessionManager::SendCastEvent(const bool &isPlugIn) void ScreenSessionManager::NotifyCastWhenScreenConnectChange(bool isConnected) { - if (g_isPcDevice) { - TLOGI(WmsLogTag::DMS, "pc device"); - return; - } if (!SessionPermission::IsSystemCalling() && !SessionPermission::IsStartByHdcd()) { TLOGE(WmsLogTag::DMS, "permission denied! calling: %{public}s, pid: %{public}d", SysCapUtil::GetClientName().c_str(), IPCSkeleton::GetCallingPid()); @@ -1220,13 +1233,8 @@ void ScreenSessionManager::SetMultiScreenDefaultRelativePosition() if (extendSession != nullptr && mainSession != nullptr) { ScreenProperty mainProperty = mainSession->GetScreenProperty(); int32_t mainWidth = mainProperty.GetBounds().rect_.GetWidth(); - if (g_isPcDevice) { - mainOptions = { mainSession->GetRSScreenId(), 0, 0 }; - extendOptions = { extendSession->GetRSScreenId(), mainWidth, 0 }; - } else { - mainOptions = { mainSession->GetScreenId(), 0, 0 }; - extendOptions = { extendSession->GetScreenId(), mainWidth, 0 }; - } + mainOptions = { mainSession->GetScreenId(), 0, 0 }; + extendOptions = { extendSession->GetScreenId(), mainWidth, 0 }; auto ret = SetMultiScreenRelativePosition(mainOptions, extendOptions); if (ret != DMError::DM_OK) { TLOGE(WmsLogTag::DMS, "set Relative Position failed, DMError:%{public}d", static_cast(ret)); @@ -1247,18 +1255,6 @@ void ScreenSessionManager::GetAndMergeEdidInfo(sptr screenSession std::string serialNumber = ConvertEdidToString(edid); TLOGI(WmsLogTag::DMS, "serialNumber: %{public}s", serialNumber.c_str()); screenSession->SetSerialNumber(serialNumber); - if (g_isPcDevice) { - if (!edid.displayProductName_.empty()) { - screenSession->SetName(edid.displayProductName_); - } else { - std::string productCodeStr; - std::string connector = "-"; - std::ostringstream oss; - oss << std::hex << std::uppercase << std::setw(fillInfo) << std::setfill('0') << edid.productCode_; - productCodeStr = oss.str(); - screenSession->SetName(edid.manufacturerName_ + connector + productCodeStr); - } - } } std::string ScreenSessionManager::ConvertEdidToString(const struct BaseEdid edid) @@ -1451,7 +1447,7 @@ void ScreenSessionManager::RegisterSettingWireCastObserver(sptr& return; } bool phyMirrorEnable = IsDefaultMirrorMode(screenSession->GetScreenId()); - if (!g_isPcDevice && phyMirrorEnable && screenSession->GetScreenProperty().GetScreenType() == ScreenType::REAL) { + if (phyMirrorEnable && screenSession->GetScreenProperty().GetScreenType() == ScreenType::REAL) { TLOGI(WmsLogTag::DMS, "Register Setting wire cast Observer"); SettingObserver::UpdateFunc updateFunc = [this](const std::string& key) { SetCastPrivacyFromSettingData(); }; ScreenSettingHelper::RegisterSettingWireCastObserver(updateFunc); @@ -1460,9 +1456,6 @@ void ScreenSessionManager::RegisterSettingWireCastObserver(sptr& void ScreenSessionManager::UnregisterSettingWireCastObserver(ScreenId screenId) { - if (g_isPcDevice) { - return; - } { std::lock_guard lock(screenSessionMapMutex_); for (const auto& sessionIt : screenSessionMap_) { @@ -1532,26 +1525,7 @@ void ScreenSessionManager::HandleScreenConnectEvent(sptr screenSe return; } #endif - if (clientProxy && g_isPcDevice) { - { - std::unique_lock lock(displayAddMutex_); - needWaitAvailableArea_ = true; - } - clientProxy->OnScreenConnectionChanged(GetSessionOption(screenSession, screenId), screenEvent); - sptr internalSession = GetInternalScreenSession(); - if (!RecoverRestoredMultiScreenMode(screenSession)) { - SetMultiScreenDefaultRelativePosition(); - ReportHandleScreenEvent(ScreenEvent::CONNECTED, ScreenCombination::SCREEN_EXTEND); - } - sptr newInternalSession = GetInternalScreenSession(); - if (newInternalSession != nullptr && internalSession != nullptr && - internalSession->GetScreenId() != newInternalSession->GetScreenId()) { - TLOGW(WmsLogTag::DMS, "main screen changed, reset screenSession."); - screenSession = internalSession; - } - SetExtendedScreenFallbackPlan(screenSession->GetScreenId()); - } - if (clientProxy && !g_isPcDevice && !phyMirrorEnable) { + if (clientProxy && !phyMirrorEnable) { TLOGW(WmsLogTag::DMS, "screen connect and notify to scb."); clientProxy->OnScreenConnectionChanged(GetSessionOption(screenSession, screenId), screenEvent); } @@ -2560,46 +2534,38 @@ DMError ScreenSessionManager::SetScreenColorTransform(ScreenId screenId) return screenSession->SetScreenColorTransform(); } -sptr ScreenSessionManager::GetPhysicalScreenSession(ScreenId screenId, ScreenId defScreenId, - ScreenProperty property) +sptr +ScreenSessionManager::GetPhysicalScreenSession(ScreenId screenId, ScreenId defScreenId, ScreenProperty property) { - sptr screenSession = nullptr; + TLOGI(WmsLogTag::DMS, "jjl start1"); + sptr screenSession = nullptr; ScreenSessionConfig config; - if (g_isPcDevice) { - config = { - .screenId = screenId, - .rsId = screenId, - .defaultScreenId = defScreenId, - .property = property, - }; - screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_REAL); - } else { - sptr defaultScreen = GetDefaultScreenSession(); - if (defaultScreen == nullptr || defaultScreen->GetDisplayNode() == nullptr) { - TLOGE(WmsLogTag::DMS, "default screen null"); - return screenSession; - } - NodeId nodeId = defaultScreen->GetDisplayNode()->GetId(); - TLOGI(WmsLogTag::DMS, "physical mirror screen nodeId: %{public}" PRIu64, nodeId); - config = { - .screenId = screenId, - .rsId = screenId, - .defaultScreenId = defScreenId, - .mirrorNodeId = nodeId, - .property = property, - }; - screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_MIRROR); - screenSession->SetIsPhysicalMirrorSwitch(true); + + sptr defaultScreen = GetDefaultScreenSession(); + if (defaultScreen == nullptr || defaultScreen->GetDisplayNode() == nullptr) { + TLOGE(WmsLogTag::DMS, "default screen null"); + return screenSession; + } + NodeId nodeId = defaultScreen->GetDisplayNode()->GetId(); + TLOGI(WmsLogTag::DMS, "physical mirror screen nodeId: %{public}" PRIu64, nodeId); + config = { + .screenId = screenId, + .rsId = screenId, + .defaultScreenId = defScreenId, + .mirrorNodeId = nodeId, + .property = property, + }; + screenSession = new ScreenSession(config, ScreenSessionReason::CREATE_SESSION_FOR_MIRROR); + screenSession->SetIsPhysicalMirrorSwitch(true); #ifdef FOLD_ABILITY_ENABLE - if (foldScreenController_ != nullptr && FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { - DMRect mainScreenRegion = {0, 0, 0, 0}; - foldScreenController_->SetMainScreenRegion(mainScreenRegion); - screenSession->SetMirrorScreenRegion(screenId, mainScreenRegion); - screenSession->SetIsEnableRegionRotation(true); - screenSession->EnableMirrorScreenRegion(); - } -#endif + if (foldScreenController_ != nullptr && FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { + DMRect mainScreenRegion = { 0, 0, 0, 0 }; + foldScreenController_->SetMainScreenRegion(mainScreenRegion); + screenSession->SetMirrorScreenRegion(screenId, mainScreenRegion); + screenSession->SetIsEnableRegionRotation(true); + screenSession->EnableMirrorScreenRegion(); } +#endif return screenSession; } @@ -2994,14 +2960,6 @@ sptr ScreenSessionManager::GetOrCreateScreenSession(ScreenId scre return screenSession; } - if (g_isPcDevice) { - std::lock_guard lock_phy(phyScreenPropMapMutex_); - if (phyScreenPropMap_.size() > 1) { - // pc is none, pad&&phone is mirror - TLOGW(WmsLogTag::DMS, "Only Support one External screen."); - return nullptr; - } - } screenIdManager_.UpdateScreenId(screenId, screenId); ScreenProperty property; @@ -3030,9 +2988,6 @@ sptr ScreenSessionManager::GetOrCreateScreenSession(ScreenId scre std::lock_guard lock(screenSessionMapMutex_); screenSessionMap_[screenId] = session; } - if (g_isPcDevice) { - SetMultiScreenFrameControl(); - } screenEventTracker_.RecordEvent("create screen session success."); SetHdrFormats(GetPhyScreenId(screenId), session); SetColorSpaces(GetPhyScreenId(screenId), session); @@ -9619,9 +9574,6 @@ DMError ScreenSessionManager::GetDisplayCapability(std::string& capabilitInfo) } std::vector orientation = ORIENTATION_DEFAULT; - if (g_isPcDevice && !FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { - orientation = {"1", "0", "3", "2"}; - } nlohmann::ordered_json jsonDisplayCapabilityList; jsonDisplayCapabilityList["capability"] = nlohmann::json::array(); nlohmann::ordered_json capabilityInfo = GetCapabilityJson(FoldStatus::UNKNOWN, FoldDisplayMode::UNKNOWN, diff --git a/windowmanager_aafwk.gni b/windowmanager_aafwk.gni index 720ace020dfd0f1a4f51a4bd99f3b7b0de4f122b..68fa18bf0a6335ff891717cf21d91084b98d0fae 100644 --- a/windowmanager_aafwk.gni +++ b/windowmanager_aafwk.gni @@ -44,6 +44,7 @@ declare_args() { window_manager_feature_cam_mode = true window_manager_feature_multi_usr = true window_manager_feature_screenless = false + window_manager_device_type = "phone" # 默认为null, 测试需要临时改为phone # Set atomicservice basic engine so path window_manager_feature_asbng_path = "" @@ -62,3 +63,4 @@ if (window_manager_feature_asbng_path == "") { print( "window_manager_feature_subscribe_motion = ${window_manager_feature_subscribe_motion}") + \ No newline at end of file