From edeb69bcfd90da43bc5634813c839602cd2bbdc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=95=AC=E6=9D=BE?= <18328528985@163.com> Date: Tue, 9 Sep 2025 22:19:08 +0800 Subject: [PATCH] pip mulscreen collaboration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周敬松 <18328528985@163.com> --- .../js_scene_session_manager.cpp | 32 +++ .../js_scene_session_manager.h | 2 + window_scene/session_manager/BUILD.gn | 2 + .../include/scene_session_manager.h | 11 + .../include/scene_session_manager_lite.h | 5 + .../include/zidl/pip_change_listener.h | 34 +++ .../include/zidl/pip_change_listener_proxy.h | 35 +++ .../include/zidl/pip_change_listener_stub.h | 35 +++ .../scene_session_manager_lite_interface.h | 13 ++ .../zidl/scene_session_manager_lite_proxy.h | 5 +- .../zidl/scene_session_manager_lite_stub.h | 4 + .../src/scene_session_manager.cpp | 87 ++++++++ .../src/scene_session_manager_lite.cpp | 25 +++ .../src/zidl/pip_change_listener_proxy.cpp | 48 +++++ .../src/zidl/pip_change_listener_stub.cpp | 44 ++++ .../zidl/scene_session_manager_lite_proxy.cpp | 145 +++++++++++++ .../zidl/scene_session_manager_lite_stub.cpp | 85 ++++++++ window_scene/test/unittest/BUILD.gn | 29 +++ .../pip_change_listener_proxy_test.cpp | 110 ++++++++++ .../pip_change_listener_stub_test.cpp | 85 ++++++++ .../scene_session_manager_lite_proxy_test.cpp | 202 ++++++++++++++++++ .../scene_session_manager_lite_stub_test.cpp | 126 +++++++++++ .../scene_session_manager_lite_test.cpp | 40 ++++ .../unittest/scene_session_manager_test.cpp | 6 + 24 files changed, 1209 insertions(+), 1 deletion(-) create mode 100644 window_scene/session_manager/include/zidl/pip_change_listener.h create mode 100644 window_scene/session_manager/include/zidl/pip_change_listener_proxy.h create mode 100644 window_scene/session_manager/include/zidl/pip_change_listener_stub.h create mode 100644 window_scene/session_manager/src/zidl/pip_change_listener_proxy.cpp create mode 100644 window_scene/session_manager/src/zidl/pip_change_listener_stub.cpp create mode 100644 window_scene/test/unittest/pip_change_listener_proxy_test.cpp create mode 100644 window_scene/test/unittest/pip_change_listener_stub_test.cpp diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index 89767ca4c7..ec940c96cb 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -325,6 +325,8 @@ napi_value JsSceneSessionManager::Init(napi_env env, napi_value exportObj) JsSceneSessionManager::SetPiPSettingSwitchStatus); BindNativeFunction(env, exportObj, "applyFeatureConfig", moduleName, JsSceneSessionManager::ApplyFeatureConfig); + BindNativeFunction(env, exportObj, "getPipDeviceCollaborationPolicy", moduleName, + JsSceneSessionManager::GetPipDeviceCollaborationPolicy); return NapiGetUndefined(env); } @@ -5281,4 +5283,34 @@ napi_value JsSceneSessionManager::OnSetPiPSettingSwitchStatus(napi_env env, napi SceneSessionManager::GetInstance().SetPiPSettingSwitchStatus(switchStatus); return NapiGetUndefined(env); } + +napi_value JsSceneSessionManager::GetPipDeviceCollaborationPolicy(napi_env env, napi_callback_info info) +{ + TLOGI(WmsLogTag::WMS_PIP, "in"); + JsSceneSessionManager* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnGetPipDeviceCollaborationPolicy(env, info) : nullptr; +} + +napi_value JsSceneSessionManager::OnGetPipDeviceCollaborationPolicy(napi_env env, napi_callback_info info) +{ + size_t argc = ARGC_ONE; + napi_value argv[ARGC_ONE] = { nullptr }; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc != ARGC_ONE) { + TLOGE(WmsLogTag::WMS_PIP, "Argc is invalid: %{public}zu", argc); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + int32_t screenId = -1; + if (!ConvertFromJsValue(env, argv[ARG_INDEX_ZERO], screenId)) { + TLOGE(WmsLogTag::WMS_PIP, "Failed to convert parameter to screenId, %{public}d", screenId); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + TLOGI(WmsLogTag::WMS_PIP, "screenId %{public}d", screenId); + bool isPipEnabled = SceneSessionManager::GetInstance().GetPipDeviceCollaborationPolicy(screenId); + return CreateJsValue(env, isPipEnabled); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h index 1aca2a271c..e48d3d0690 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h @@ -176,6 +176,7 @@ public: * PiP Window */ static napi_value SetPiPSettingSwitchStatus(napi_env env, napi_callback_info info); + static napi_value GetPipDeviceCollaborationPolicy(napi_env env, napi_callback_info info); private: napi_value OnSetBehindWindowFilterEnabled(napi_env env, napi_callback_info info); @@ -341,6 +342,7 @@ private: void OnStartPiPFailed(DisplayId displayId); void ProcessStartPiPFailedRegister(); napi_value OnSetPiPSettingSwitchStatus(napi_env env, napi_callback_info info); + napi_value OnGetPipDeviceCollaborationPolicy(napi_env env, napi_callback_info info); /* * Window Animation diff --git a/window_scene/session_manager/BUILD.gn b/window_scene/session_manager/BUILD.gn index 3b355dba10..e1539ee973 100644 --- a/window_scene/session_manager/BUILD.gn +++ b/window_scene/session_manager/BUILD.gn @@ -91,6 +91,8 @@ ohos_shared_library("scene_session_manager") { "src/zidl/session_lifecycle_listener_stub.cpp", "src/zidl/session_router_stack_listener_proxy.cpp", "src/zidl/session_router_stack_listener_stub.cpp", + "src/zidl/pip_change_listener_proxy.cpp", + "src/zidl/pip_change_listener_stub.cpp", ] public_configs = [ ":session_manager_public_config" ] diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index b8488c0c14..c97e175cfb 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -59,6 +59,7 @@ #include "wm_single_instance.h" #include "zidl/session_lifecycle_listener_interface.h" #include "zidl/session_router_stack_listener.h" +#include "zidl/pip_change_listener.h" namespace OHOS::AAFwk { class SessionInfo; @@ -651,6 +652,11 @@ public: WMError GetPiPSettingSwitchStatus(bool& switchStatus) override; void SetPiPSettingSwitchStatus(bool switchStatus); void SetStartPiPFailedListener(NotifyStartPiPFailedFunc&& func); + bool GetPipDeviceCollaborationPolicy(int32_t screenId); + WMError SetPipEnableByScreenId(int32_t screenId, bool enabled); + WMError UnsetPipEnableByScreenId(int32_t screenId); + WMError RegisterPipChgListenerByScreenId(int32_t screenId, const sptr& listener); + WMError UnregisterPipChgListenerByScreenId(int32_t screenId); /* * FloatingBall Window @@ -1364,11 +1370,16 @@ private: std::mutex pipSettingSwitchMutex_; uint64_t pipWindowSurfaceId_ = 0; bool pipSwitchStatus_ = true; + std::shared_mutex screenPipEnabledMapLock_; + std::unordered_map screenPipEnabledMap_; + std::shared_mutex pipChgListenerMapMutex_; + std::map> pipChgListenerMap_; bool CheckPiPPriority(const PiPTemplateInfo& pipTemplateInfo, DisplayId displayId = 0); bool IsEnablePiPCreate(const sptr& property); bool IsPiPForbidden(const sptr& property, const WindowType& type); bool IsLastPiPWindowVisible(uint64_t surfaceId, WindowVisibilityState lastVisibilityState); void NotifyPiPWindowVisibleChange(bool isScreenLocked); + void NotifyMulScreenPipStart(const sptr& property, WindowType type); /* * Floating ball diff --git a/window_scene/session_manager/include/scene_session_manager_lite.h b/window_scene/session_manager/include/scene_session_manager_lite.h index a09661fd02..5c66dfe11a 100644 --- a/window_scene/session_manager/include/scene_session_manager_lite.h +++ b/window_scene/session_manager/include/scene_session_manager_lite.h @@ -105,6 +105,11 @@ public: WMError EnterKioskMode(const sptr& token) override; WMError ExitKioskMode(const sptr& token) override; WSError SendPointerEventForHover(const std::shared_ptr& pointerEvent) override; + WMError SetPipEnableByScreenId(int32_t screenId, bool enabled) override; + WMError UnsetPipEnableByScreenId(int32_t screenId) override; + + WMError RegisterPipChgListenerByScreenId(int32_t screenId, const sptr& listener) override; + WMError UnregisterPipChgListenerByScreenId(int32_t screenId) override; }; } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/include/zidl/pip_change_listener.h b/window_scene/session_manager/include/zidl/pip_change_listener.h new file mode 100644 index 0000000000..cded77e08c --- /dev/null +++ b/window_scene/session_manager/include/zidl/pip_change_listener.h @@ -0,0 +1,34 @@ +/* + * 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 OHOS_ROSEN_PIP_CHANGE_LISTENER_H +#define OHOS_ROSEN_PIP_CHANGE_LISTENER_H + +#include "iremote_stub.h" +#include "iremote_broker.h" + +namespace OHOS::Rosen { +class IPipChangeListener : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IPipChangeListener"); + + enum class IPipChangeListenerMessage : uint32_t { + TRANS_ON_PIP_CHANGE_EVENT = 0, + }; + + virtual void OnPipStart(int32_t windowId) = 0; +}; +} // namespace OHOS::Rosen +#endif \ No newline at end of file diff --git a/window_scene/session_manager/include/zidl/pip_change_listener_proxy.h b/window_scene/session_manager/include/zidl/pip_change_listener_proxy.h new file mode 100644 index 0000000000..cd226dc442 --- /dev/null +++ b/window_scene/session_manager/include/zidl/pip_change_listener_proxy.h @@ -0,0 +1,35 @@ +/* + * 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 OHOS_SESSION_PIP_CHANGE_LISTENER_PROXY_H +#define OHOS_SESSION_PIP_CHANGE_LISTENER_PROXY_H + +#include +#include "pip_change_listener.h" + +namespace OHOS::Rosen { +class PipChangeListenerProxy : public IRemoteProxy { +public: + explicit PipChangeListenerProxy(const sptr& impl) : IRemoteProxy(impl) {} + + virtual ~PipChangeListenerProxy() = default; + + void OnPipStart(int32_t windowId) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace OHOS +#endif //OHOS_SESSION_PIP_CHANGE_LISTENER_PROXY_H \ No newline at end of file diff --git a/window_scene/session_manager/include/zidl/pip_change_listener_stub.h b/window_scene/session_manager/include/zidl/pip_change_listener_stub.h new file mode 100644 index 0000000000..a38baa322e --- /dev/null +++ b/window_scene/session_manager/include/zidl/pip_change_listener_stub.h @@ -0,0 +1,35 @@ +/* + * 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 OHOS_SESSION_PIP_STUB_LISTENER_STUB_H +#define OHOS_SESSION_PIP_STUB_LISTENER_STUB_H + +#include +#include +#include "pip_change_listener.h" + +namespace OHOS::Rosen { +class PipChangeListenerStub : public IRemoteStub { +public: + PipChangeListenerStub() = default; + virtual ~PipChangeListenerStub() = default; + + int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; + +private: + int HandleOnPipChange(MessageParcel& data, MessageParcel& reply); +}; +} // namespace OHOS +#endif //OHOS_SESSION_PIP_STUB_LISTENER_STUB_H \ No newline at end of file diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_lite_interface.h b/window_scene/session_manager/include/zidl/scene_session_manager_lite_interface.h index 369233df93..b545d101e8 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_lite_interface.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_lite_interface.h @@ -28,6 +28,7 @@ #include "zidl/window_manager_lite_interface.h" #include "session_lifecycle_listener_interface.h" #include "session_router_stack_listener.h" +#include "pip_change_listener.h" namespace OHOS::Media { class PixelMap; @@ -109,6 +110,10 @@ public: TRANS_ID_SET_START_WINDOW_BACKGROUND_COLOR, TRANS_IS_SET_IMAGE_FOR_RECENT, TRANS_ID_IS_FOCUS_WINDOW_PARENT, + TRANS_ID_SET_PIP_ENABLED_BY_SCREENID, + TRANS_ID_UNSET_PIP_ENABLED_BY_SCREENID, + TRANS_ID_REGISTER_PIP_CHG_LISTENER, + TRANS_ID_UNREGISTER_PIP_CHG_LISTENER, }; /* @@ -408,6 +413,14 @@ public: */ virtual WSError SendPointerEventForHover(const std::shared_ptr& pointerEvent) { return WSError::WS_OK; } + + virtual WMError SetPipEnableByScreenId(int32_t screenId, bool enabled) { return WMError::WM_OK; } + virtual WMError UnsetPipEnableByScreenId(int32_t screenId) { return WMError::WM_OK; } + virtual WMError RegisterPipChgListenerByScreenId(int32_t screenId, const sptr& listener) + { + return WMError::WM_OK; + } + virtual WMError UnregisterPipChgListenerByScreenId(int32_t screenId) { return WMError::WM_OK; } }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_LITE_INTERFACE_H diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h b/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h index 46dbc73f6b..0837a3b228 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h @@ -110,7 +110,10 @@ public: WMError CreateNewInstanceKey(const std::string& bundleName, std::string& instanceKey) override; WMError RemoveInstanceKey(const std::string& bundleName, const std::string& instanceKey) override; WMError TransferSessionToTargetScreen(const TransferSessionInfo& info) override; - + WMError SetPipEnableByScreenId(int32_t screenId, bool enabled) override; + WMError UnsetPipEnableByScreenId(int32_t screenId) override; + WMError RegisterPipChgListenerByScreenId(int32_t screenId, const sptr& listener) override; + WMError UnregisterPipChgListenerByScreenId(int32_t screenId) override; WMError UpdateKioskAppList(const std::vector& kioskAppList) override; WMError EnterKioskMode(const sptr& token) override; WMError ExitKioskMode(const sptr& token) override; diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_lite_stub.h b/window_scene/session_manager/include/zidl/scene_session_manager_lite_stub.h index 3a3488e9a5..5defd4f305 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_lite_stub.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_lite_stub.h @@ -97,6 +97,10 @@ private: int HandleEnterKioskMode(MessageParcel& data, MessageParcel& reply); int HandleExitKioskMode(MessageParcel& data, MessageParcel& reply); int HandleSendPointerEventForHover(MessageParcel& data, MessageParcel& reply); + int HandleSetPipEnableByScreenId(MessageParcel& data, MessageParcel& reply); + int HandleUnsetPipEnableByScreenId(MessageParcel& data, MessageParcel& reply); + int HandleRegisterPipChgListener(MessageParcel& data, MessageParcel& reply); + int HandleUnRegisterPipChgListener(MessageParcel& data, MessageParcel& reply); int ProcessRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option); }; diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 0a0bdb0f74..f3760b909f 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -3844,6 +3844,7 @@ WSError SceneSessionManager::CreateAndConnectSpecificSession(const sptr& prop TLOGI(WmsLogTag::WMS_PIP, "screen name %{public}s", screenName.c_str()); return true; } + + if (type == WindowType::WINDOW_TYPE_PIP && !GetPipDeviceCollaborationPolicy(screenId)) { + return true; + } return false; } +void SceneSessionManager::NotifyMulScreenPipStart(const sptr& property, WindowType type) +{ + sptr parentSession = GetSceneSession(property->GetParentPersistentId()); + if (parentSession == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "invalid parentSession"); + return; + } + sptr parentProperty = parentSession->GetSessionProperty(); + if (parentProperty == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "invalid parentProperty"); + return; + } + DisplayId screenId = parentProperty->GetDisplayId(); + if (screenId == SCREEN_ID_INVALID) { + TLOGE(WmsLogTag::WMS_PIP, "invalid screenId"); + return; + } + + int32_t windowId = parentSession->GetWindowId(); + TLOGI(WmsLogTag::WMS_PIP, "NotifyMulScreenPipStart: type:%{public}d, %{public}lu, %{public}d", + type, screenId, windowId); + if (type != WindowType::WINDOW_TYPE_PIP || GetPipDeviceCollaborationPolicy(screenId)) { + return; + } + + std::shared_lock lock(pipChgListenerMapMutex_); + auto iter = pipChgListenerMap_.find(screenId); + if (iter != pipChgListenerMap_.end()) { + if (iter->second != nullptr) { + iter->second->OnPipStart(windowId); + } + } +} + WSError SceneSessionManager::IsFloatingBallValid(const sptr& parentSession) { if (parentSession == nullptr || parentSession->GetSessionState() == SessionState::STATE_DISCONNECT || @@ -17496,6 +17535,54 @@ WMError SceneSessionManager::GetPiPSettingSwitchStatus(bool& switchStatus) return WMError::WM_OK; } +WMError SceneSessionManager::SetPipEnableByScreenId(int32_t screenId, bool isEnabled) +{ + TLOGI(WmsLogTag::WMS_PIP, "SetPipEnableByScreenId: %{public}d, isEnable: %{public}d", screenId, isEnabled); + std::unique_lock lock(screenPipEnabledMapLock_); + screenPipEnabledMap_.insert_or_assign(screenId, isEnabled); + return WMError::WM_OK; +} + +WMError SceneSessionManager::UnsetPipEnableByScreenId(int32_t screenId) +{ + TLOGI(WmsLogTag::WMS_PIP, "UnsetPipEnableByScreenId: %{public}d", screenId); + std::unique_lock lock(screenPipEnabledMapLock_); + screenPipEnabledMap_.erase(screenId); + return WMError::WM_OK; +} + +bool SceneSessionManager::GetPipDeviceCollaborationPolicy(int32_t screenId) +{ + TLOGI(WmsLogTag::WMS_PIP, "GetPipDeviceCollaborationPolicy: %{public}d", screenId); + std::shared_lock lock(screenPipEnabledMapLock_); + auto iter = screenPipEnabledMap_.find(screenId); + if (iter == screenPipEnabledMap_.end()) { + return true; // 默认支持 + } + return iter->second; +} + +WMError SceneSessionManager::RegisterPipChgListenerByScreenId(int32_t screenId, + const sptr& listener) +{ + TLOGI(WmsLogTag::WMS_PIP, "RegisterPipChgListenerByScreenId: %{public}d", screenId); + if (listener == nullptr) { + TLOGNE(WmsLogTag::WMS_LIFE, "listener is nullptr"); + return WMError::WM_ERROR_INVALID_PARAM; + } + std::unique_lock lock(pipChgListenerMapMutex_); + pipChgListenerMap_.insert_or_assign(screenId, listener); + return WMError::WM_OK; +} + +WMError SceneSessionManager::UnregisterPipChgListenerByScreenId(int32_t screenId) +{ + TLOGI(WmsLogTag::WMS_PIP, "UnregisterPipChgListenerByScreenId: %{public}d", screenId); + std::unique_lock lock(pipChgListenerMapMutex_); + pipChgListenerMap_.erase(screenId); + return WMError::WM_OK; +} + WMError SceneSessionManager::UpdateScreenLockState(int32_t persistentId) { if (persistentId < 0) { diff --git a/window_scene/session_manager/src/scene_session_manager_lite.cpp b/window_scene/session_manager/src/scene_session_manager_lite.cpp index a80235646a..a3badb4332 100644 --- a/window_scene/session_manager/src/scene_session_manager_lite.cpp +++ b/window_scene/session_manager/src/scene_session_manager_lite.cpp @@ -400,4 +400,29 @@ WSError SceneSessionManagerLite::SendPointerEventForHover(const std::shared_ptr< { return SceneSessionManager::GetInstance().SendPointerEventForHover(pointerEvent); } + +WMError SceneSessionManagerLite::SetPipEnableByScreenId(int32_t screenId, bool isEnabled) +{ + WLOGFD("in"); + return SceneSessionManager::GetInstance().SetPipEnableByScreenId(screenId, isEnabled); +} + +WMError SceneSessionManagerLite::UnsetPipEnableByScreenId(int32_t screenId) +{ + WLOGFD("in"); + return SceneSessionManager::GetInstance().UnsetPipEnableByScreenId(screenId); +} + +WMError SceneSessionManagerLite::RegisterPipChgListenerByScreenId(int32_t screenId, + const sptr& listener) +{ + WLOGFD("in"); + return SceneSessionManager::GetInstance().RegisterPipChgListenerByScreenId(screenId, listener); +} + +WMError SceneSessionManagerLite::UnregisterPipChgListenerByScreenId(int32_t screenId) +{ + WLOGFD("in"); + return SceneSessionManager::GetInstance().UnregisterPipChgListenerByScreenId(screenId); +} } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/src/zidl/pip_change_listener_proxy.cpp b/window_scene/session_manager/src/zidl/pip_change_listener_proxy.cpp new file mode 100644 index 0000000000..61701aab17 --- /dev/null +++ b/window_scene/session_manager/src/zidl/pip_change_listener_proxy.cpp @@ -0,0 +1,48 @@ +/* + * 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 "session_manager/include/zidl/pip_change_listener_proxy.h" +#include "hilog_tag_wrapper.h" +#include "window_manager_hilog.h" + +namespace OHOS::Rosen { +void PipChangeListenerProxy::OnPipStart(int32_t windowId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_PIP, "Write interfaceToken failed"); + return; + } + + if (!data.WriteInt32(windowId)) { + TLOGE(WmsLogTag::WMS_PIP, "Write windowId failed"); + return; + } + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "remote is null"); + return; + } + int errCode = remote->SendRequest(static_cast( + IPipChangeListenerMessage::TRANS_ON_PIP_CHANGE_EVENT), data, reply, option); + if (errCode != NO_ERROR) { + TLOGE(WmsLogTag::WMS_PIP, "SendRequest failed %{public}d.", errCode); + return; + } +} +} // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/session_manager/src/zidl/pip_change_listener_stub.cpp b/window_scene/session_manager/src/zidl/pip_change_listener_stub.cpp new file mode 100644 index 0000000000..d16b0060e0 --- /dev/null +++ b/window_scene/session_manager/src/zidl/pip_change_listener_stub.cpp @@ -0,0 +1,44 @@ +/* + * 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 "session_manager/include/zidl/pip_change_listener_stub.h" +#include "window_manager_hilog.h" +#include "hilog_tag_wrapper.h" + +namespace OHOS::Rosen { + +int PipChangeListenerStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, + MessageOption& option) +{ + TLOGD(WmsLogTag::WMS_PIP, "In"); + if (data.ReadInterfaceToken() != GetDescriptor()) { + TLOGE(WmsLogTag::WMS_PIP, "local descriptor not equal to remote."); + return ERR_TRANSACTION_FAILED; + } + return HandleOnPipChange(data, reply); +} + +int PipChangeListenerStub::HandleOnPipChange(MessageParcel& data, MessageParcel& reply) +{ + TLOGD(WmsLogTag::WMS_PIP, "In"); + int32_t windowId = 0; + if (!data.ReadInt32(windowId)) { + TLOGE(WmsLogTag::WMS_PIP, "Failed to read windowId"); + return ERR_INVALID_DATA; + } + OnPipStart(windowId); + return ERR_NONE; +} +} \ No newline at end of file diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp index 2a7139fc5b..eaebd8fdb8 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp @@ -2270,4 +2270,149 @@ WSError SceneSessionManagerLiteProxy::SendPointerEventForHover(const std::shared } return static_cast(ret); } + +WMError SceneSessionManagerLiteProxy::SetPipEnableByScreenId(int32_t screenId, bool isEnabled) +{ + TLOGD(WmsLogTag::WMS_PIP, "SetPipEnableByScreenId"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_PIP, "Write interfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteInt32(screenId)) { + TLOGE(WmsLogTag::WMS_PIP, "Failed to write screenId"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteBool(isEnabled)) { + TLOGE(WmsLogTag::WMS_PIP, "Write isEnabled failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "remote is null"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (remote->SendRequest( + static_cast(SceneSessionManagerLiteMessage::TRANS_ID_SET_PIP_ENABLED_BY_SCREENID), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::WMS_PIP, "SendRequest failed."); + return WMError::WM_ERROR_IPC_FAILED; + } + int32_t ret = 0; + if (!reply.ReadInt32(ret)) { + TLOGE(WmsLogTag::WMS_PIP, "read ret failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + return static_cast(ret); +} + +WMError SceneSessionManagerLiteProxy::UnsetPipEnableByScreenId(int32_t screenId) +{ + TLOGD(WmsLogTag::WMS_PIP, "UnsetPipEnableByScreenId"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_PIP, "Write interfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteInt32(screenId)) { + TLOGE(WmsLogTag::WMS_PIP, "Failed to write screenId"); + return WMError::WM_ERROR_IPC_FAILED; + } + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "remote is null"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (remote->SendRequest( + static_cast(SceneSessionManagerLiteMessage::TRANS_ID_UNSET_PIP_ENABLED_BY_SCREENID), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::WMS_PIP, "SendRequest failed."); + return WMError::WM_ERROR_IPC_FAILED; + } + int32_t ret = 0; + if (!reply.ReadInt32(ret)) { + TLOGE(WmsLogTag::WMS_PIP, "read ret failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + return static_cast(ret); +} + +WMError SceneSessionManagerLiteProxy::RegisterPipChgListenerByScreenId(int32_t screenId, + const sptr& listener) +{ + TLOGD(WmsLogTag::WMS_PIP, "in"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_PIP, "Write interfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteInt32(screenId)) { + TLOGE(WmsLogTag::WMS_PIP, "Failed to write screenId"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (listener == nullptr || listener->AsObject() == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "listener is null"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteRemoteObject(listener->AsObject())) { + TLOGE(WmsLogTag::WMS_PIP, "Write listener failed."); + return WMError::WM_ERROR_IPC_FAILED; + } + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "remote is null"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (remote->SendRequest(static_cast(SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_PIP_CHG_LISTENER), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::WMS_PIP, "SendRequest failed."); + return WMError::WM_ERROR_IPC_FAILED; + } + int32_t ret = 0; + if (!reply.ReadInt32(ret)) { + TLOGE(WmsLogTag::WMS_PIP, "Read ret failed."); + return WMError::WM_ERROR_IPC_FAILED; + } + return static_cast(ret); +} + +WMError SceneSessionManagerLiteProxy::UnregisterPipChgListenerByScreenId(int32_t screenId) +{ + TLOGD(WmsLogTag::WMS_PIP, "in"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_PIP, "Write interfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteInt32(screenId)) { + TLOGE(WmsLogTag::WMS_PIP, "Failed to write screenId"); + return WMError::WM_ERROR_IPC_FAILED; + } + + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "remote is null"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (remote->SendRequest( + static_cast(SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_PIP_CHG_LISTENER), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::WMS_PIP, "SendRequest failed."); + return WMError::WM_ERROR_IPC_FAILED; + } + int32_t ret = 0; + if (!reply.ReadInt32(ret)) { + TLOGE(WmsLogTag::WMS_PIP, "Read ret failed."); + return WMError::WM_ERROR_IPC_FAILED; + } + return static_cast(ret); +} } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp index 55be5177f0..cac43bc431 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp @@ -127,6 +127,14 @@ int SceneSessionManagerLiteStub::ProcessRemoteRequest(uint32_t code, MessageParc return HandleCloseTargetPiPWindow(data, reply); case static_cast(SceneSessionManagerLiteMessage::TRANS_ID_GET_CURRENT_PIP_WINDOW_INFO): return HandleGetCurrentPiPWindowInfo(data, reply); + case static_cast(SceneSessionManagerLiteMessage::TRANS_ID_SET_PIP_ENABLED_BY_SCREENID): + return HandleSetPipEnableByScreenId(data, reply); + case static_cast(SceneSessionManagerLiteMessage::TRANS_ID_UNSET_PIP_ENABLED_BY_SCREENID): + return HandleUnsetPipEnableByScreenId(data, reply); + case static_cast(SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_PIP_CHG_LISTENER): + return HandleRegisterPipChgListener(data, reply); + case static_cast(SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_PIP_CHG_LISTENER): + return HandleUnRegisterPipChgListener(data, reply); case static_cast(SceneSessionManagerLiteMessage::TRANS_ID_GET_ROOT_MAIN_WINDOW_ID): return HandleGetRootMainWindowId(data, reply); case static_cast(SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_INFO): @@ -1432,4 +1440,81 @@ int SceneSessionManagerLiteStub::HandleSendPointerEventForHover(MessageParcel& d } return ERR_NONE; } + +int SceneSessionManagerLiteStub::HandleSetPipEnableByScreenId(MessageParcel& data, MessageParcel& reply) +{ + TLOGD(WmsLogTag::WMS_PIP, "HandleSetPipEnableByScreenId"); + int screenId; + if (!data.ReadInt32(screenId)) { + TLOGE(WmsLogTag::WMS_LIFE, "read screenId failed"); + return ERR_INVALID_DATA; + } + bool isPipEnabled = true; + if (!data.ReadBool(isPipEnabled)) { + TLOGE(WmsLogTag::WMS_PIP, "Read isPipEnabled failed"); + return ERR_INVALID_DATA; + } + WMError errCode = SetPipEnableByScreenId(screenId, isPipEnabled); + if (!reply.WriteInt32(static_cast(errCode))) { + return ERR_INVALID_DATA; + } + return ERR_NONE; +} + +int SceneSessionManagerLiteStub::HandleUnsetPipEnableByScreenId(MessageParcel& data, MessageParcel& reply) +{ + TLOGD(WmsLogTag::WMS_PIP, "HandleUnsetPipEnableByScreenId"); + int screenId; + if (!data.ReadInt32(screenId)) { + TLOGE(WmsLogTag::WMS_LIFE, "read screenId failed"); + return ERR_INVALID_DATA; + } + WMError errCode = UnsetPipEnableByScreenId(screenId); + if (!reply.WriteInt32(static_cast(errCode))) { + return ERR_INVALID_DATA; + } + return ERR_NONE; +} + +int SceneSessionManagerLiteStub::HandleRegisterPipChgListener(MessageParcel& data, MessageParcel& reply) +{ + TLOGD(WmsLogTag::WMS_PIP, "in"); + int32_t screenId; + if (!data.ReadInt32(screenId)) { + TLOGE(WmsLogTag::WMS_PIP, "read screenId failed"); + return ERR_INVALID_DATA; + } + + sptr listenerObject = data.ReadRemoteObject(); + if (listenerObject == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "remote object is nullptr!"); + return ERR_INVALID_DATA; + } + sptr listener = iface_cast(listenerObject); + if (listener == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "listener is nullptr!"); + return ERR_INVALID_DATA; + } + + WMError ret = RegisterPipChgListenerByScreenId(screenId, listener); + if (!reply.WriteInt32(static_cast(ret))) { + return ERR_INVALID_DATA; + } + return ERR_NONE; +} + +int SceneSessionManagerLiteStub::HandleUnRegisterPipChgListener(MessageParcel& data, MessageParcel& reply) +{ + TLOGD(WmsLogTag::WMS_PIP, "in"); + int32_t screenId; + if (!data.ReadInt32(screenId)) { + TLOGE(WmsLogTag::WMS_PIP, "read screenId failed"); + return ERR_INVALID_DATA; + } + WMError ret = UnregisterPipChgListenerByScreenId(screenId); + if (!reply.WriteInt32(static_cast(ret))) { + return ERR_INVALID_DATA; + } + return ERR_NONE; +} } // namespace OHOS::Rosen diff --git a/window_scene/test/unittest/BUILD.gn b/window_scene/test/unittest/BUILD.gn index 08faedc63e..c35640b2af 100644 --- a/window_scene/test/unittest/BUILD.gn +++ b/window_scene/test/unittest/BUILD.gn @@ -71,6 +71,8 @@ group("unittest") { ":ws_window_manager_lru_test", ":ws_window_manager_service_dump_test", ":ws_window_scene_config_test", + ":pip_change_listener_proxy_test", + ":pip_change_listener_stub_test", "animation:ws_scene_session_animation_test", "animation:ws_session_proxy_animation_test", "animation:ws_ui_effect_controller_proxy_test", @@ -1600,4 +1602,31 @@ ohos_unittest("ws_session_utils_test") { external_deps = test_external_deps } + +ohos_unittest("pip_change_listener_proxy_test") { + module_out_path = module_out_path + + include_dirs = [ "../mock" ] + + sources = [ + "../mock/mock_message_parcel.cpp", + "pip_change_listener_proxy_test.cpp", + ] + + deps = [ ":ws_unittest_common" ] + + external_deps = test_external_deps +} + +ohos_unittest("pip_change_listener_stub_test") { + module_out_path = module_out_path + + sources = [ + "pip_change_listener_stub_test.cpp", + ] + + deps = [ ":ws_unittest_common" ] + + external_deps = test_external_deps +} ## Build ws_unittest_common.a }}} diff --git a/window_scene/test/unittest/pip_change_listener_proxy_test.cpp b/window_scene/test/unittest/pip_change_listener_proxy_test.cpp new file mode 100644 index 0000000000..d6e3f9fc92 --- /dev/null +++ b/window_scene/test/unittest/pip_change_listener_proxy_test.cpp @@ -0,0 +1,110 @@ +/* + * 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 +#include "iremote_object_mocker.h" +#include "session_manager/include/zidl/pip_change_listener_proxy.h" +#include "mock_message_parcel.h" +#include "window_manager_hilog.h" + +using namespace testing; +using namespace testing::ext; + +namespace { + std::string logMsg; + void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char* tag, + const char* msg) + { + logMsg = msg; + } +} + +namespace OHOS { +namespace Rosen { +class PipChangeListenerProxyTest : public testing::Test { +public: + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; + void SetUp() override; + void TearDown() override; + +private: + sptr iRemoteObjectMocker_; + sptr pipChgListenerProxy_; +}; + +void PipChangeListenerProxyTest::SetUp() +{ + iRemoteObjectMocker_ = sptr::MakeSptr(); + ASSERT_NE(iRemoteObjectMocker_, nullptr); + pipChgListenerProxy_ = sptr::MakeSptr(iRemoteObjectMocker_); + ASSERT_NE(pipChgListenerProxy_, nullptr); + logMsg.clear(); + LOG_SetCallback(MyLogCallback); +} + +void PipChangeListenerProxyTest::TearDown() +{ + MockMessageParcel::ClearAllErrorFlag(); + iRemoteObjectMocker_ = nullptr; + pipChgListenerProxy_ = nullptr; + LOG_SetCallback(nullptr); +} + +namespace { +HWTEST_F(PipChangeListenerProxyTest, OnPipStart_ShouldFailed_WhenWriteInterfaceTokenFailed, TestSize.Level1) +{ + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); + pipChgListenerProxy_->OnPipStart(1); + GTEST_LOG_(INFO) << logMsg; + EXPECT_TRUE(logMsg.find("Write interfaceToken failed") != std::string::npos); +} + +HWTEST_F(PipChangeListenerProxyTest, OnPipStart_ShouldFailed_WhenWriteIntFailed, TestSize.Level1) +{ + MockMessageParcel::SetWriteInt32ErrorFlag(true); + pipChgListenerProxy_->OnPipStart(1); + GTEST_LOG_(INFO) << logMsg; + EXPECT_TRUE(logMsg.find("Write windowId failed") != std::string::npos); +} + +HWTEST_F(PipChangeListenerProxyTest, OnPipStart_ShouldFailed_WhenRemoteObjIsNull, TestSize.Level1) +{ + sptr pipChgListenerProxy = sptr::MakeSptr(nullptr); + ASSERT_NE(pipChgListenerProxy, nullptr); + + pipChgListenerProxy->OnPipStart(1); + GTEST_LOG_(INFO) << logMsg; + EXPECT_TRUE(logMsg.find("remote is null") != std::string::npos); +} + +HWTEST_F(PipChangeListenerProxyTest, OnPipStart_ShouldFailed_WhenSendReqFailed, TestSize.Level1) +{ + iRemoteObjectMocker_->SetRequestResult(1); + pipChgListenerProxy_->OnPipStart(1); + GTEST_LOG_(INFO) << logMsg; + EXPECT_TRUE(logMsg.find("SendRequest failed") != std::string::npos); + iRemoteObjectMocker_->SetRequestResult(0); +} + +HWTEST_F(PipChangeListenerProxyTest, OnPipStart_ShouldSuccess_WhenAllOperationsSucceed, TestSize.Level1) +{ + pipChgListenerProxy_->OnPipStart(1); + GTEST_LOG_(INFO) << logMsg; + EXPECT_TRUE(logMsg.empty()); +} +} // namespace +} // Rosen +} // OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/pip_change_listener_stub_test.cpp b/window_scene/test/unittest/pip_change_listener_stub_test.cpp new file mode 100644 index 0000000000..e94765a622 --- /dev/null +++ b/window_scene/test/unittest/pip_change_listener_stub_test.cpp @@ -0,0 +1,85 @@ +/* + * 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 +#include "iremote_object_mocker.h" +#include "session_manager/include/zidl/pip_change_listener_stub.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +class MockPipChangeListenerStub : public PipChangeListenerStub { +public: + void OnPipStart(int32_t windowId) override {} +}; + +class PipChangeListenerStubTest : public testing::Test { +public: + void SetUp() override; + void TearDown() override; +private: + sptr stub_; +}; + +void PipChangeListenerStubTest::SetUp() +{ + stub_ = sptr::MakeSptr(); +} + +void PipChangeListenerStubTest::TearDown() +{ + stub_ = nullptr; +} + +namespace { +HWTEST_F(PipChangeListenerStubTest, OnRemoteRequest_ShouldReturnFailed_WhenReadInterfaceTokenFails, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + uint32_t code = + static_cast(MockPipChangeListenerStub::IPipChangeListenerMessage::TRANS_ON_PIP_CHANGE_EVENT); + auto res = stub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(res, ERR_TRANSACTION_FAILED); +} + +HWTEST_F(PipChangeListenerStubTest, OnRemoteRequest_ShouldReturnInvalidData_WhenReadIntFails, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInterfaceToken(PipChangeListenerStub::GetDescriptor()); + uint32_t code = + static_cast(MockPipChangeListenerStub::IPipChangeListenerMessage::TRANS_ON_PIP_CHANGE_EVENT); + auto res = stub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(res, ERR_INVALID_DATA); +} + +HWTEST_F(PipChangeListenerStubTest, HandleOnPipChange_ShouldReturnErrNone_WhenAllOperationsSucceed, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + + data.WriteInt32(1); + auto res = stub_->HandleOnPipChange(data, reply); + EXPECT_EQ(res, ERR_NONE); +} +} // namespace +} // Rosen +} // OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/scene_session_manager_lite_proxy_test.cpp b/window_scene/test/unittest/scene_session_manager_lite_proxy_test.cpp index 16f1e2befe..8f301a0bfc 100644 --- a/window_scene/test/unittest/scene_session_manager_lite_proxy_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_lite_proxy_test.cpp @@ -22,6 +22,7 @@ #include "session_manager/include/zidl/scene_session_manager_lite_interface.h" #include "session_manager/include/zidl/scene_session_manager_lite_proxy.h" #include "session_manager/include/zidl/session_router_stack_listener_stub.h" +#include "session_manager/include/zidl/pip_change_listener_stub.h" #include "window_manager_agent.h" using namespace testing; @@ -35,6 +36,10 @@ public: void SetUp() override; void TearDown() override; sptr iRemoteObjectMocker; + +private: + sptr iRemoteObjectMocker_ {nullptr}; + sptr sceneSessionManagerLiteProxy_ {nullptr}; }; void sceneSessionManagerLiteProxyTest::SetUpTestCase() @@ -47,10 +52,17 @@ void sceneSessionManagerLiteProxyTest::TearDownTestCase() void sceneSessionManagerLiteProxyTest::SetUp() { + iRemoteObjectMocker_ = sptr::MakeSptr(); + ASSERT_NE(iRemoteObjectMocker_, nullptr); + sceneSessionManagerLiteProxy_ = sptr::MakeSptr(iRemoteObjectMocker_); + ASSERT_NE(sceneSessionManagerLiteProxy_, nullptr); } void sceneSessionManagerLiteProxyTest::TearDown() { + iRemoteObjectMocker_ = nullptr; + sceneSessionManagerLiteProxy_ = nullptr; + MockMessageParcel::ClearAllErrorFlag(); } namespace { @@ -308,4 +320,194 @@ HWTEST_F(sceneSessionManagerLiteProxyTest, NotifyAppUseControlList, TestSize.Lev errCode = sceneSessionManagerLiteProxy->NotifyAppUseControlList(type, userId, controlList); EXPECT_EQ(errCode, WSError::WS_ERROR_INVALID_PARAM); } + +HWTEST_F(sceneSessionManagerLiteProxyTest, UnregPipChgListenerByScreenId_WriteTokenFailed, TestSize.Level1) +{ + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); + EXPECT_EQ(sceneSessionManagerLiteProxy_->UnregisterPipChgListenerByScreenId(1), WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, UnregPipChgListenerByScreenId_WriteIntFailed, TestSize.Level1) +{ + MockMessageParcel::SetWriteInt32ErrorFlag(true); + EXPECT_EQ(sceneSessionManagerLiteProxy_->UnregisterPipChgListenerByScreenId(1), WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, UnregPipChgListenerByScreenId_ReadIntFailed, TestSize.Level1) +{ + MockMessageParcel::SetReadInt32ErrorFlag(true); + EXPECT_EQ(sceneSessionManagerLiteProxy_->UnregisterPipChgListenerByScreenId(1), WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, UnregPipChgListenerByScreenId_SendReqFailed, TestSize.Level1) +{ + iRemoteObjectMocker_->SetRequestResult(1); + EXPECT_EQ(sceneSessionManagerLiteProxy_->UnregisterPipChgListenerByScreenId(1), WMError::WM_ERROR_IPC_FAILED); + iRemoteObjectMocker_->SetRequestResult(0); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, UnregPipChgListenerByScreenId_RemoteNullFailed, TestSize.Level1) +{ + sptr liteProxyNullRemote = sptr::MakeSptr(nullptr); + ASSERT_NE(liteProxyNullRemote, nullptr); + EXPECT_EQ(liteProxyNullRemote->UnregisterPipChgListenerByScreenId(1), WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, RegisterPipChgListenerByScreenId_ShouldReturnOk_WhenNotReg, TestSize.Level1) +{ + EXPECT_EQ(sceneSessionManagerLiteProxy_->UnregisterPipChgListenerByScreenId(1), WMError::WM_OK); +} + +class MockPipChgListener : public PipChangeListenerStub { +public: + void OnPipStart(int32_t windowId) override {}; +}; + +HWTEST_F(sceneSessionManagerLiteProxyTest, RegPipChgListenerByScreenId_Success, TestSize.Level1) +{ + sptr listener = sptr::MakeSptr(); + EXPECT_EQ(sceneSessionManagerLiteProxy_->RegisterPipChgListenerByScreenId(1, listener), WMError::WM_OK); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, UnregPipChgListenerByScreenId_ShouldReturnOk_WhenRegOK, TestSize.Level1) +{ + sptr listener = sptr::MakeSptr(); + EXPECT_EQ(sceneSessionManagerLiteProxy_->RegisterPipChgListenerByScreenId(1, listener), WMError::WM_OK); + EXPECT_EQ(sceneSessionManagerLiteProxy_->UnregisterPipChgListenerByScreenId(1), WMError::WM_OK); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, RegPipChgListenerByScreenId_WriteTokenFailed, TestSize.Level1) +{ + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); + auto result = sceneSessionManagerLiteProxy_->RegisterPipChgListenerByScreenId(1, nullptr); + EXPECT_EQ(result, WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, RegPipChgListenerByScreenId_WriteIntFailed, TestSize.Level1) +{ + MockMessageParcel::SetWriteInt32ErrorFlag(true); + auto result = sceneSessionManagerLiteProxy_->RegisterPipChgListenerByScreenId(1, nullptr); + EXPECT_EQ(result, WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, RegPipChgListenerByScreenId_NullListenerFailed, TestSize.Level1) +{ + auto result = sceneSessionManagerLiteProxy_->RegisterPipChgListenerByScreenId(1, nullptr); + EXPECT_EQ(result, WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, RegPipChgListenerByScreenId_WriteRemoteObjFailed, TestSize.Level1) +{ + MockMessageParcel::SetWriteRemoteObjectErrorFlag(true); + sptr listener = sptr::MakeSptr(); + auto result = sceneSessionManagerLiteProxy_->RegisterPipChgListenerByScreenId(1, listener); + EXPECT_EQ(result, WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, RegPipChgListenerByScreenId_SendReqFailed, TestSize.Level1) +{ + iRemoteObjectMocker_->SetRequestResult(1); + sptr listener = sptr::MakeSptr(); + auto result = sceneSessionManagerLiteProxy_->RegisterPipChgListenerByScreenId(1, listener); + EXPECT_EQ(result, WMError::WM_ERROR_IPC_FAILED); + iRemoteObjectMocker_->SetRequestResult(0); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, RegPipChgListenerByScreenId_RemoteNullFailed, TestSize.Level1) +{ + sptr liteProxyNullRemote = sptr::MakeSptr(nullptr); + ASSERT_NE(liteProxyNullRemote, nullptr); + sptr listener = sptr::MakeSptr(); + EXPECT_EQ(liteProxyNullRemote->RegisterPipChgListenerByScreenId(1, listener), WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, RegPipChgListenerByScreenId_ReadIntFailed, TestSize.Level1) +{ + MockMessageParcel::SetReadInt32ErrorFlag(true); + sptr listener = sptr::MakeSptr(); + auto result = sceneSessionManagerLiteProxy_->RegisterPipChgListenerByScreenId(1, listener); + EXPECT_EQ(result, WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, SetPipEnableByScreenId_Success, TestSize.Level1) +{ + EXPECT_EQ(sceneSessionManagerLiteProxy_->SetPipEnableByScreenId(1, false), WMError::WM_OK); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, SetPipEnableByScreenId_WriteTokenFailed, TestSize.Level1) +{ + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); + EXPECT_EQ(sceneSessionManagerLiteProxy_->SetPipEnableByScreenId(1, false), WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, SetPipEnableByScreenId_WriteIntFailed, TestSize.Level1) +{ + MockMessageParcel::SetWriteInt32ErrorFlag(true); + EXPECT_EQ(sceneSessionManagerLiteProxy_->SetPipEnableByScreenId(1, false), WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, SetPipEnableByScreenId_WriteBoolFailed, TestSize.Level1) +{ + MockMessageParcel::SetWriteBoolErrorFlag(true); + EXPECT_EQ(sceneSessionManagerLiteProxy_->SetPipEnableByScreenId(1, false), WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, SetPipEnableByScreenId_SendReqFailed, TestSize.Level1) +{ + iRemoteObjectMocker_->SetRequestResult(1); + EXPECT_EQ(sceneSessionManagerLiteProxy_->SetPipEnableByScreenId(1, false), WMError::WM_ERROR_IPC_FAILED); + iRemoteObjectMocker_->SetRequestResult(0); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, SetPipEnableByScreenId_RemoteNullFailed, TestSize.Level1) +{ + sptr liteProxyNullRemote = sptr::MakeSptr(nullptr); + ASSERT_NE(liteProxyNullRemote, nullptr); + EXPECT_EQ(liteProxyNullRemote->SetPipEnableByScreenId(1, false), WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, SetPipEnableByScreenId_ReadIntFailed, TestSize.Level1) +{ + MockMessageParcel::SetReadInt32ErrorFlag(true); + EXPECT_EQ(sceneSessionManagerLiteProxy_->SetPipEnableByScreenId(1, false), WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, UnsetPipEnableByScreenId_Success, TestSize.Level1) +{ + EXPECT_EQ(sceneSessionManagerLiteProxy_->UnsetPipEnableByScreenId(1), WMError::WM_OK); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, UnsetPipEnableByScreenId_WriteTokenFailed, TestSize.Level1) +{ + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); + EXPECT_EQ(sceneSessionManagerLiteProxy_->UnsetPipEnableByScreenId(1), WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, UnsetPipEnableByScreenId_WriteIntFailed, TestSize.Level1) +{ + MockMessageParcel::SetWriteInt32ErrorFlag(true); + EXPECT_EQ(sceneSessionManagerLiteProxy_->UnsetPipEnableByScreenId(1), WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, UnsetPipEnableByScreenId_SendReqFailed, TestSize.Level1) +{ + iRemoteObjectMocker_->SetRequestResult(1); + EXPECT_EQ(sceneSessionManagerLiteProxy_->UnsetPipEnableByScreenId(1), WMError::WM_ERROR_IPC_FAILED); + iRemoteObjectMocker_->SetRequestResult(0); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, UnsetPipEnableByScreenId_RemoteNullFailed, TestSize.Level1) +{ + sptr liteProxyNullRemote = sptr::MakeSptr(nullptr); + ASSERT_NE(liteProxyNullRemote, nullptr); + EXPECT_EQ(liteProxyNullRemote->UnsetPipEnableByScreenId(1), WMError::WM_ERROR_IPC_FAILED); +} + +HWTEST_F(sceneSessionManagerLiteProxyTest, UnsetPipEnableByScreenId_ReadIntFailed, TestSize.Level1) +{ + MockMessageParcel::SetReadInt32ErrorFlag(true); + EXPECT_EQ(sceneSessionManagerLiteProxy_->UnsetPipEnableByScreenId(1), WMError::WM_ERROR_IPC_FAILED); +} +} +} } \ No newline at end of file diff --git a/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp b/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp index 5df6df25e4..5a307000b3 100644 --- a/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp @@ -19,6 +19,7 @@ #include "iremote_object_mocker.h" #include "session_manager/include/zidl/scene_session_manager_lite_stub.h" #include "session_manager/include/zidl/session_router_stack_listener_stub.h" +#include "session_manager/include/zidl/pip_change_listener_stub.h" using namespace testing; using namespace testing::ext; @@ -301,6 +302,14 @@ class MockSceneSessionManagerLiteStub : public SceneSessionManagerLiteStub { { return WSError::WS_OK; } + + WMError SetPipEnableByScreenId(int32_t screenId, bool enabled) override { return WMError::WM_OK; } + WMError UnsetPipEnableByScreenId(int32_t screenId) override { return WMError::WM_OK; } + WMError RegisterPipChgListenerByScreenId(int32_t screenId, const sptr& listener) + { + return WMError::WM_OK; + } + WMError UnregisterPipChgListenerByScreenId(int32_t screenId) override { return WMError::WM_OK; } }; class SceneSessionManagerLiteStubTest : public testing::Test { @@ -1317,6 +1326,123 @@ HWTEST_F(SceneSessionManagerLiteStubTest, HandleSendPointerEventForHover, Functi res = sceneSessionManagerLiteStub_->SceneSessionManagerLiteStub::HandleSendPointerEventForHover(data, reply); EXPECT_EQ(ERR_NONE, res); } + +HWTEST_F(SceneSessionManagerLiteStubTest, HandleUnRegPipChgListener_ReadIntFailed, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + EXPECT_EQ(sceneSessionManagerLiteStub_->HandleUnRegisterPipChgListener(data, reply), ERR_INVALID_DATA); +} + +HWTEST_F(SceneSessionManagerLiteStubTest, HandleUnRegPipChgListener_Success, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + uint32_t code = static_cast( + ISceneSessionManagerLite::SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_PIP_CHG_LISTENER); + data.WriteInt32(1); + auto result = sceneSessionManagerLiteStub_-> + SceneSessionManagerLiteStub::ProcessRemoteRequest(code, data, reply, option); + EXPECT_EQ(result, ERR_NONE); +} + +HWTEST_F(SceneSessionManagerLiteStubTest, HandleRegPipChgListener_ReadIntFailed, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + EXPECT_EQ(sceneSessionManagerLiteStub_->HandleRegisterPipChgListener(data, reply), ERR_INVALID_DATA); +} + +HWTEST_F(SceneSessionManagerLiteStubTest, HandleRegPipChgListener_ReadListenerFailed, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + data.WriteInt32(1); + EXPECT_EQ(sceneSessionManagerLiteStub_->HandleRegisterPipChgListener(data, reply), ERR_INVALID_DATA); +} + +class MockPipChgListener : public PipChangeListenerStub { +public: + void OnPipStart(int32_t windowId) override {}; +}; + +HWTEST_F(SceneSessionManagerLiteStubTest, HandleRegPipChgListener_NullListenerFailed, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + data.WriteInt32(1); + + data.WriteRemoteObject(nullptr); + EXPECT_EQ(sceneSessionManagerLiteStub_->HandleRegisterPipChgListener(data, reply), ERR_INVALID_DATA); +} + +HWTEST_F(SceneSessionManagerLiteStubTest, HandleRegPipChgListener_Success, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInt32(1); + sptr listener = sptr::MakeSptr(); + data.WriteRemoteObject(listener->AsObject()); + uint32_t code = static_cast( + ISceneSessionManagerLite::SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_PIP_CHG_LISTENER); + auto result = sceneSessionManagerLiteStub_-> + SceneSessionManagerLiteStub::ProcessRemoteRequest(code, data, reply, option); + EXPECT_EQ(result, ERR_NONE); +} + +HWTEST_F(SceneSessionManagerLiteStubTest, HandleUnsetPipEnableByScreenId_Success, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInt32(1); + uint32_t code = static_cast( + ISceneSessionManagerLite::SceneSessionManagerLiteMessage::TRANS_ID_UNSET_PIP_ENABLED_BY_SCREENID); + auto result = sceneSessionManagerLiteStub_-> + SceneSessionManagerLiteStub::ProcessRemoteRequest(code, data, reply, option); + EXPECT_EQ(result, ERR_NONE); +} + +HWTEST_F(SceneSessionManagerLiteStubTest, HandleUnsetPipEnableByScreenId_ReadIntFailed, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + EXPECT_EQ(sceneSessionManagerLiteStub_->HandleUnsetPipEnableByScreenId(data, reply), ERR_INVALID_DATA); +} + +HWTEST_F(SceneSessionManagerLiteStubTest, HandleSetPipEnableByScreenId_Success, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInt32(1); + data.WriteBool(true); + uint32_t code = static_cast( + ISceneSessionManagerLite::SceneSessionManagerLiteMessage::TRANS_ID_SET_PIP_ENABLED_BY_SCREENID); + auto result = sceneSessionManagerLiteStub_-> + SceneSessionManagerLiteStub::ProcessRemoteRequest(code, data, reply, option); + EXPECT_EQ(result, ERR_NONE); +} + +HWTEST_F(SceneSessionManagerLiteStubTest, HandleSetPipEnableByScreenId_ReadIntFailed, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + EXPECT_EQ(sceneSessionManagerLiteStub_->HandleSetPipEnableByScreenId(data, reply), ERR_INVALID_DATA); +} + +HWTEST_F(SceneSessionManagerLiteStubTest, HandleSetPipEnableByScreenId_ReadBoolFailed, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + data.WriteInt32(1); + EXPECT_EQ(sceneSessionManagerLiteStub_->HandleSetPipEnableByScreenId(data, reply), ERR_INVALID_DATA); +} } // namespace } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/scene_session_manager_lite_test.cpp b/window_scene/test/unittest/scene_session_manager_lite_test.cpp index 1aaf445e06..f7aa229812 100644 --- a/window_scene/test/unittest/scene_session_manager_lite_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_lite_test.cpp @@ -17,6 +17,7 @@ #include "session_manager/include/scene_session_manager.h" #include "session_manager/include/scene_session_manager_lite.h" +#include "session_manager/include/zidl/pip_change_listener_stub.h" using namespace testing; using namespace testing::ext; @@ -77,6 +78,45 @@ HWTEST_F(SceneSessionManagerLiteTest, IsFocusWindowParent, TestSize.Level1) EXPECT_EQ(SceneSessionManagerLite::GetInstance().IsFocusWindowParent(token, isParent), WSError::WS_ERROR_INVALID_PERMISSION); } + +class MockPipChgListener : public PipChangeListenerStub { +public: + void OnPipStart(int32_t windowId) override {}; +}; + +HWTEST_F(SceneSessionManagerLiteTest, UnregPipChgListenerByScreenId_ShouldStillRetOK_WhenNotReg, TestSize.Level1) +{ + EXPECT_EQ(SceneSessionManagerLite::GetInstance().UnregisterPipChgListenerByScreenId(1), WMError::WM_OK); +} + +HWTEST_F(SceneSessionManagerLiteTest, UnregPipChgListenerByScreenId_ShouldRetOK_WhenRegOk, TestSize.Level1) +{ + sptr listener = sptr::MakeSptr(); + EXPECT_EQ(SceneSessionManagerLite::GetInstance().RegisterPipChgListenerByScreenId(1, listener), WMError::WM_OK); + EXPECT_EQ(SceneSessionManagerLite::GetInstance().UnregisterPipChgListenerByScreenId(1), WMError::WM_OK); +} + +HWTEST_F(SceneSessionManagerLiteTest, RegisterPipChgListenerByScreenId, TestSize.Level1) +{ + auto result = SceneSessionManagerLite::GetInstance().RegisterPipChgListenerByScreenId(1, nullptr); + EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PARAM); +} + +HWTEST_F(SceneSessionManagerLiteTest, SetPipEnableByScreenId, TestSize.Level1) +{ + EXPECT_EQ(SceneSessionManagerLite::GetInstance().SetPipEnableByScreenId(1, true), WMError::WM_OK); +} + +HWTEST_F(SceneSessionManagerLiteTest, UnsetPipEnableByScreenId_ShouldRetOk_WhenNotSet, TestSize.Level1) +{ + EXPECT_EQ(SceneSessionManagerLite::GetInstance().UnsetPipEnableByScreenId(1), WMError::WM_OK); +} + +HWTEST_F(SceneSessionManagerLiteTest, UnsetPipEnableByScreenId_ShouldRetOk_WhenSetOk, TestSize.Level1) +{ + EXPECT_EQ(SceneSessionManagerLite::GetInstance().SetPipEnableByScreenId(1, true), WMError::WM_OK); + EXPECT_EQ(SceneSessionManagerLite::GetInstance().UnsetPipEnableByScreenId(1), WMError::WM_OK); +} } // namespace } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/scene_session_manager_test.cpp b/window_scene/test/unittest/scene_session_manager_test.cpp index fb858f0ca8..ad92dca05d 100644 --- a/window_scene/test/unittest/scene_session_manager_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_test.cpp @@ -95,6 +95,7 @@ void SceneSessionManagerTest::TearDown() MockAccesstokenKit::ChangeMockStateToInit(); usleep(WAIT_SYNC_IN_NS); ssm_->sceneSessionMap_.clear(); + ssm_->screenPipEnabledMap_.clear(); } void SceneSessionManagerTest::SetVisibleForAccessibility(sptr& sceneSession) @@ -1722,6 +1723,11 @@ HWTEST_F(SceneSessionManagerTest, TestIsPiPForbidden, TestSize.Level1) ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert({ displayId, screenSession }); ASSERT_TRUE(ssm_->IsPiPForbidden(property, WindowType::WINDOW_TYPE_PIP)); ASSERT_TRUE(!ssm_->IsPiPForbidden(property, WindowType::WINDOW_TYPE_FLOAT)); + + screenSessionForPad->SetName("CustomScbScreen"); + ssm_->SetPipEnableByScreenId(displayIdForPad, false); + ASSERT_TRUE(ssm_->IsPiPForbidden(property, WindowType::WINDOW_TYPE_PIP)); + ASSERT_TRUE(!ssm_->IsPiPForbidden(property, WindowType::WINDOW_TYPE_FB)); } /** -- Gitee