diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index 6e023c95e1476aeaa168dbf09430535378be9f5f..8d11dcd6a20d052d0ed0ee60e294121f20f21b8a 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -61,6 +61,7 @@ public: virtual sptr GetDisplayInfoByScreenId(ScreenId screenId); virtual std::vector GetAllDisplayIds(); virtual std::shared_ptr GetDisplaySnapshot(DisplayId displayId, DmErrorCode* errorCode = nullptr); + virtual DMError DisableDisplaySnapshot(bool disableOrNot); virtual DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow); virtual bool WakeUpBegin(PowerStateChangeReason reason); virtual bool WakeUpEnd(); @@ -105,6 +106,7 @@ public: virtual DMError MakeExpand(std::vector screenId, std::vector startPoint, ScreenId& screenGroupId); virtual DMError StopMirror(const std::vector& mirrorScreenIds); virtual DMError StopExpand(const std::vector& expandScreenIds); + virtual DMError DisableMirror(bool disableOrNot); virtual void RemoveVirtualScreenFromGroup(std::vector); virtual DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId); virtual sptr GetScreenInfo(ScreenId screenId); diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index 7f8a852dfbfeedfae88784f5b29d5cf1f9a586bc..c37c462e0f228cf1f367fbf7ea31940361dc7a2e 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -521,6 +521,11 @@ std::shared_ptr DisplayManager::GetScreenshot(DisplayId display return dstScreenshot; } +DMError DisplayManager::DisableScreenshot(bool disableOrNot) +{ + return SingletonContainer::Get().DisableDisplaySnapshot(disableOrNot); +} + sptr DisplayManager::GetDefaultDisplay() { return pImpl_->GetDefaultDisplay(); diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index dd58c6b09b6e27a69d90cd8c0fee77268bea43b0..cf6acfb24eefddaf99c5d0012e556391353527fb 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -68,6 +68,13 @@ std::shared_ptr DisplayManagerAdapter::GetDisplaySnapshot(Displ return displayManagerServiceProxy_->GetDisplaySnapshot(displayId, errorCode); } +DMError DisplayManagerAdapter::DisableDisplaySnapshot(bool disableOrNot) +{ + INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED); + + return displayManagerServiceProxy_->DisableDisplaySnapshot(disableOrNot); +} + DMError ScreenManagerAdapter::GetScreenSupportedColorGamuts(ScreenId screenId, std::vector& colorGamuts) { @@ -368,6 +375,13 @@ DMError ScreenManagerAdapter::StopMirror(const std::vector& mirrorScre return displayManagerServiceProxy_->StopMirror(mirrorScreenIds); } +DMError ScreenManagerAdapter::DisableMirror(bool disableOrNot) +{ + INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED); + + return displayManagerServiceProxy_->DisableMirror(disableOrNot); +} + sptr ScreenManagerAdapter::GetScreenInfo(ScreenId screenId) { if (screenId == SCREEN_ID_INVALID) { diff --git a/dm/src/screen_manager.cpp b/dm/src/screen_manager.cpp index 013b6dcb04806b2d983c20519cb76b5822776041..1cc7f99a0b717f01aeca304d82744878da240f45 100644 --- a/dm/src/screen_manager.cpp +++ b/dm/src/screen_manager.cpp @@ -486,6 +486,12 @@ DMError ScreenManager::StopMirror(const std::vector& mirrorScreenIds) return SingletonContainer::Get().StopMirror(mirrorScreenIds); } +DMError ScreenManager::DisableMirror(bool disableOrNot) +{ + WLOGFI("Disable mirror %{public}d", disableOrNot); + return SingletonContainer::Get().DisableMirror(disableOrNot); +} + DMError ScreenManager::RemoveVirtualScreenFromGroup(std::vector screens) { WLOGFI("screens.size=%{public}llu", (unsigned long long)screens.size()); diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h index b6793d1b68f31f568c7684525a1d578327c0e7a4..826071e19d69e7499827d5a7d26278b1325fb994 100644 --- a/dmserver/include/display_manager_interface.h +++ b/dmserver/include/display_manager_interface.h @@ -39,6 +39,7 @@ public: TRANS_ID_GET_DISPLAY_BY_ID, TRANS_ID_GET_DISPLAY_BY_SCREEN, TRANS_ID_GET_DISPLAY_SNAPSHOT, + TRANS_ID_DISABLE_DISPLAY_SNAPSHOT, TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT, TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT, TRANS_ID_WAKE_UP_BEGIN, @@ -81,6 +82,7 @@ public: TRANS_ID_REMOVE_SURFACE_NODE, TRANS_ID_SCREEN_STOP_MIRROR, TRANS_ID_SCREEN_STOP_EXPAND, + TRANS_ID_SCREEN_DISABLE_MIRROR, TRANS_ID_SCENE_BOARD_SCREEN_BASE = 2000, TRANS_ID_SCENE_BOARD_DUMP_ALL_SCREEN, TRANS_ID_SCENE_BOARD_DUMP_SPECIAL_SCREEN, @@ -103,6 +105,7 @@ public: virtual DMError SetOrientation(ScreenId screenId, Orientation orientation) = 0; virtual std::shared_ptr GetDisplaySnapshot(DisplayId displayId, DmErrorCode* errorCode = nullptr) = 0; + virtual DMError DisableDisplaySnapshot(bool disableOrNot) { return DMError::DM_ERROR_INVALID_PERMISSION; } virtual DMError SetScreenRotationLocked(bool isLocked) = 0; virtual DMError IsScreenRotationLocked(bool& isLocked) = 0; @@ -139,6 +142,7 @@ public: ScreenId& screenGroupId) = 0; virtual DMError StopMirror(const std::vector& mirrorScreenIds) = 0; virtual DMError StopExpand(const std::vector& expandScreenIds) = 0; + virtual DMError DisableMirror(bool disableOrNot) { return DMError::DM_ERROR_INVALID_PERMISSION; } virtual void RemoveVirtualScreenFromGroup(std::vector screens) = 0; virtual DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId) = 0; virtual DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio) = 0; diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index bf23bfb53bebe2e85bb70960806d0046ed4c1ccf..dfbe35b51bb3c52011b4155756701aa83af77d25 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -170,6 +170,14 @@ public: std::shared_ptr GetScreenshot(DisplayId displayId, const Media::Rect &rect, const Media::Size &size, int rotation, DmErrorCode* errorCode = nullptr); + /** + * @brief Disable/enable global screenshot. + * + * @param disableOrNot disable screenshot or not. + * @return DM_OK means disable or enable screenshot success, others means failed. + */ + DMError DisableScreenshot(bool disableOrNot); + /** * @brief Begin to wake up screen. * diff --git a/interfaces/innerkits/dm/screen_manager.h b/interfaces/innerkits/dm/screen_manager.h index ba2424dd8b0ace04cfcdbd7fa9034ce4caa8da3b..ec16af4dc280b12f075d09c9a34b00b6e8cd6426 100644 --- a/interfaces/innerkits/dm/screen_manager.h +++ b/interfaces/innerkits/dm/screen_manager.h @@ -66,7 +66,7 @@ public: * * @param info Change info of screen mirror. */ - virtual void OnMirrorChange([[maybe_unused]]const ChangeInfo& info) {} + virtual void OnMirrorChange([[maybe_unused]]const ChangeInfo& info) {} }; /** @@ -128,6 +128,14 @@ public: */ DMError StopMirror(const std::vector& mirrorScreenIds); + /** + * @brief Disable/enable global mirror screen. + * + * @param disableOrNot disable mirror screen or not. + * @return DM_OK means disable or enable mirror success, others means failed. + */ + DMError DisableMirror(bool disableOrNot); + /** * @brief Remove virtual screen from group. * diff --git a/window_scene/session_manager/include/screen_session_manager.h b/window_scene/session_manager/include/screen_session_manager.h index 0b69c9e2d7ad33cbe9e53f7f5e7851743200a8ce..2bfebf76d943ea22eaf1fe13be6e0b8b4f4f7dff 100644 --- a/window_scene/session_manager/include/screen_session_manager.h +++ b/window_scene/session_manager/include/screen_session_manager.h @@ -91,12 +91,14 @@ public: virtual DMError MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenIds, ScreenId& screenGroupId) override; virtual DMError StopMirror(const std::vector& mirrorScreenIds) override; + DMError DisableMirror(bool disableOrNot) override; virtual DMError MakeExpand(std::vector screenId, std::vector startPoint, ScreenId& screenGroupId) override; virtual DMError StopExpand(const std::vector& expandScreenIds) override; virtual sptr GetScreenGroupInfoById(ScreenId screenId) override; virtual void RemoveVirtualScreenFromGroup(std::vector screens) override; virtual std::shared_ptr GetDisplaySnapshot(DisplayId displayId, DmErrorCode* errorCode) override; + DMError DisableDisplaySnapshot(bool disableOrNot) override; virtual sptr GetDisplayInfoById(DisplayId displayId) override; sptr GetDisplayInfoByScreen(ScreenId screenId) override; std::vector GetAllDisplayIds() override; @@ -238,6 +240,9 @@ private: std::map, std::vector> screenAgentMap_; std::map> smsScreenGroupMap_; + std::atomic_bool disableDisplaySnapshotOrNot_ = false; + std::atomic_bool disableMirrorOrNot_ = false; + bool isAutoRotationOpen_ = false; bool isExpandCombination_ = false; sptr deathRecipient_ { nullptr }; diff --git a/window_scene/session_manager/include/zidl/screen_session_manager_proxy.h b/window_scene/session_manager/include/zidl/screen_session_manager_proxy.h index 268b79d8cf07318d4b8c528c9fdd2fed1b20d6bc..093ff0fb2c9cb11f850ff5b6a358d570c989b645 100644 --- a/window_scene/session_manager/include/zidl/screen_session_manager_proxy.h +++ b/window_scene/session_manager/include/zidl/screen_session_manager_proxy.h @@ -64,6 +64,7 @@ public: virtual DMError MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenIds, ScreenId& screenGroupId) override; virtual DMError StopMirror(const std::vector& mirrorScreenIds) override; + DMError DisableMirror(bool disableOrNot) override; virtual DMError MakeExpand(std::vector screenId, std::vector startPoint, ScreenId& screenGroupId) override; @@ -74,6 +75,7 @@ public: virtual void RemoveVirtualScreenFromGroup(std::vector screens) override; virtual std::shared_ptr GetDisplaySnapshot(DisplayId displayId, DmErrorCode* errorCode) override; + DMError DisableDisplaySnapshot(bool disableOrNot) override; virtual sptr GetDisplayInfoById(DisplayId displayId) override; virtual sptr GetDisplayInfoByScreen(ScreenId screenId) override; diff --git a/window_scene/session_manager/src/screen_session_manager.cpp b/window_scene/session_manager/src/screen_session_manager.cpp index dbba6bcf7471f2f07f415a87d1128f26362b3687..afb935b6ec04c67253af24bc1debea6668df1197 100644 --- a/window_scene/session_manager/src/screen_session_manager.cpp +++ b/window_scene/session_manager/src/screen_session_manager.cpp @@ -1170,6 +1170,29 @@ DMError ScreenSessionManager::DestroyVirtualScreen(ScreenId screenId) return DMError::DM_OK; } +DMError ScreenSessionManager::DisableMirror(bool disableOrNot) +{ + WLOGFI("SCB:ScreenSessionManager::DisableMirror %{public}d", disableOrNot); + if (!SessionPermission::IsSystemCalling()) { + WLOGFI("DisableMirror permission denied!"); + return DMError::DM_ERROR_NOT_SYSTEM_APP; + } + WLOGFI("SCB:ScreenSessionManager::DisableMirror enter %{public}d", disableOrNot); + disableMirrorOrNot_ = disableOrNot; + if (disableOrNot) { + std::vector screenIds; + auto allScreenIds = GetAllScreenIds(); + for (auto screenId : allScreenIds) { + auto screen = GetScreenSession(screenId); + if (screen && screen->GetScreenProperty().GetScreenType() == ScreenType::VIRTUAL) { + screenIds.push_back(screenId); + } + } + StopMirror(screenIds); + } + return DMError::DM_OK; +} + DMError ScreenSessionManager::MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenIds, ScreenId& screenGroupId) { @@ -1178,6 +1201,10 @@ DMError ScreenSessionManager::MakeMirror(ScreenId mainScreenId, std::vector ScreenSessionManager::GetScreenSnapshot(Display std::shared_ptr ScreenSessionManager::GetDisplaySnapshot(DisplayId displayId, DmErrorCode* errorCode) { WLOGFI("SCB: ScreenSessionManager::GetDisplaySnapshot ENTER!"); + if (disableDisplaySnapshotOrNot_) { + WLOGFW("SCB: ScreenSessionManager::GetDisplaySnapshot was disabled!"); + return nullptr; + } HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:GetDisplaySnapshot(%" PRIu64")", displayId); auto res = GetScreenSnapshot(displayId); if (res != nullptr) { @@ -1842,6 +1873,18 @@ std::shared_ptr ScreenSessionManager::GetDisplaySnapshot(Displa return res; } +DMError ScreenSessionManager::DisableDisplaySnapshot(bool disableOrNot) +{ + WLOGFD("SCB: ScreenSessionManager::DisableDisplaySnapshot %{public}d", disableOrNot); + if (!SessionPermission::IsSystemCalling()) { + WLOGFE("DisableDisplaySnapshot permission denied!"); + return DMError::DM_ERROR_NOT_SYSTEM_APP; + } + WLOGFI("SCB: ScreenSessionManager::DisableDisplaySnapshot enter %{public}d", disableOrNot); + disableDisplaySnapshotOrNot_ = disableOrNot; + return DMError::DM_OK; +} + bool ScreenSessionManager::OnRemoteDied(const sptr& agent) { if (agent == nullptr) { diff --git a/window_scene/session_manager/src/zidl/screen_session_manager_proxy.cpp b/window_scene/session_manager/src/zidl/screen_session_manager_proxy.cpp index 3aae36675fcc1b824287289cff6e593c87938751..1da703aaa004087f1542fc11d07c18495d993d22 100644 --- a/window_scene/session_manager/src/zidl/screen_session_manager_proxy.cpp +++ b/window_scene/session_manager/src/zidl/screen_session_manager_proxy.cpp @@ -702,6 +702,34 @@ DMError ScreenSessionManagerProxy::StopMirror(const std::vector& mirro return static_cast(reply.ReadInt32()); } +DMError ScreenSessionManagerProxy::DisableMirror(bool disableOrNot) +{ + WLOGFI("SCB: ScreenSessionManagerProxy::DisableMirror %{public}d", disableOrNot); + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("DisableMirror fail: remote is null"); + return DMError::DM_ERROR_NULLPTR; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("DisableMirror fail: WriteinterfaceToken failed"); + return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; + } + if (!data.WriteBool(disableOrNot)) { + WLOGFE("DisableMirror fail: data write failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_SCREEN_DISABLE_MIRROR), + data, reply, option) != ERR_NONE) { + WLOGFW("DisableMirror fail: SendRequest failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + return static_cast(reply.ReadInt32()); +} + DMError ScreenSessionManagerProxy::MakeExpand(std::vector screenId, std::vector startPoint, ScreenId& screenGroupId) { @@ -866,6 +894,34 @@ std::shared_ptr ScreenSessionManagerProxy::GetDisplaySnapshot(D return pixelMap; } +DMError ScreenSessionManagerProxy::DisableDisplaySnapshot(bool disableOrNot) +{ + WLOGFI("SCB: ScreenSessionManagerProxy::DisableDisplaySnapshot %{public}d", disableOrNot); + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("DisableDisplaySnapshot fail: remote is null"); + return DMError::DM_ERROR_NULLPTR; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("DisableDisplaySnapshot fail: WriteinterfaceToken failed"); + return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; + } + if (!data.WriteBool(disableOrNot)) { + WLOGFE("DisableDisplaySnapshot fail: data write failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_DISABLE_DISPLAY_SNAPSHOT), + data, reply, option) != ERR_NONE) { + WLOGFW("DisableDisplaySnapshot fail: SendRequest failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + return static_cast(reply.ReadInt32()); +} + sptr ScreenSessionManagerProxy::GetDisplayInfoById(DisplayId displayId) { sptr remote = Remote(); diff --git a/window_scene/session_manager/src/zidl/screen_session_manager_stub.cpp b/window_scene/session_manager/src/zidl/screen_session_manager_stub.cpp index 31839b6c7306ca0e582679f88f81427c496b6b1c..c0528035373d23dc701027a2b4b4648f75e2b8c1 100644 --- a/window_scene/session_manager/src/zidl/screen_session_manager_stub.cpp +++ b/window_scene/session_manager/src/zidl/screen_session_manager_stub.cpp @@ -216,6 +216,11 @@ int32_t ScreenSessionManagerStub::OnRemoteRequest(uint32_t code, MessageParcel& reply.WriteInt32(static_cast(ret)); break; } + case DisplayManagerMessage::TRANS_ID_SCREEN_DISABLE_MIRROR: { + DMError ret = DisableMirror(data.ReadBool()); + reply.WriteInt32(static_cast(ret)); + break; + } case DisplayManagerMessage::TRANS_ID_SCREEN_MAKE_EXPAND: { std::vector screenId; if (!data.ReadUInt64Vector(&screenId)) { @@ -266,6 +271,11 @@ int32_t ScreenSessionManagerStub::OnRemoteRequest(uint32_t code, MessageParcel& reply.WriteParcelable(displaySnapshot == nullptr ? nullptr : displaySnapshot.get()); break; } + case DisplayManagerMessage::TRANS_ID_DISABLE_DISPLAY_SNAPSHOT: { + DMError ret = DisableDisplaySnapshot(data.ReadBool()); + reply.WriteInt32(static_cast(ret)); + break; + } case DisplayManagerMessage::TRANS_ID_SET_SCREEN_ACTIVE_MODE: { ScreenId screenId = static_cast(data.ReadUint64()); uint32_t modeId = data.ReadUint32();