From 4906005d07702d373a027aad469fd0feab731723 Mon Sep 17 00:00:00 2001 From: yanghongnan Date: Thu, 9 May 2024 15:34:01 +0800 Subject: [PATCH] implementations for setImmersiveModeEnabled. Signed-off-by: yanghongnan --- interfaces/innerkits/wm/window.h | 14 ++++ .../window_runtime/window_napi/js_window.cpp | 74 +++++++++++++++++++ .../window_runtime/window_napi/js_window.h | 4 + previewer/include/window.h | 4 + previewer/include/window_impl.h | 2 + previewer/src/window_impl.cpp | 10 +++ .../wms/window_fuzzer/window_fuzzer.cpp | 3 + wm/include/window_impl.h | 3 + wm/include/window_scene_session_impl.h | 3 + wm/src/window_impl.cpp | 29 ++++++++ wm/src/window_scene_session_impl.cpp | 35 ++++++++- wm/test/unittest/window_impl_test.cpp | 61 +++++++++++++++ .../window_scene_session_impl_test.cpp | 45 +++++++++++ wm/test/unittest/window_test.cpp | 14 ++++ 14 files changed, 298 insertions(+), 3 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 0397bbbd38..dbc31ac5f6 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -1973,6 +1973,20 @@ public: * @return WM_OK means set success, others means set failed */ virtual WMError AdjustKeyboardLayout(const KeyboardLayoutParams& params) { return WMError::WM_OK; } + + /** + * @brief Set whether to enable immersive mode. + * @param enable the value true means to enable immersive mode, and false means the opposite. + * @return WM_OK means set success, others means set failed. + */ + virtual WMError SetImmersiveModeEnabledState(bool enable) { return WMError::WM_OK; } + + /** + * @brief Get whether the immersive mode is enabled or not. + * + * @return true means the immersive mode is enabled, and false means the opposite. + */ + virtual bool GetImmersiveModeEnabledState() const { return true; } }; } } diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index 023ea0c404..e545e0b4d8 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -825,6 +825,20 @@ napi_value JsWindow::SetWindowGrayScale(napi_env env, napi_callback_info info) return (me != nullptr) ? me->OnSetWindowGrayScale(env, info) : nullptr; } +napi_value JsWindow::SetImmersiveModeEnabledState(napi_env env, napi_callback_info info) +{ + WLOGI("[NAPI]SetImmersiveModeEnabledState"); + JsWindow* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnSetImmersiveModeEnabledState(env, info) : nullptr; +} + +napi_value JsWindow::GetImmersiveModeEnabledState(napi_env env, napi_callback_info info) +{ + WLOGI("[NAPI]GetImmersiveModeEnabledState"); + JsWindow* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnGetImmersiveModeEnabledState(env, info) : nullptr; +} + static void UpdateSystemBarProperties(std::map& systemBarProperties, const std::map& systemBarPropertyFlags, sptr windowToken) { @@ -5759,6 +5773,64 @@ napi_value JsWindow::OnSetWindowGrayScale(napi_env env, napi_callback_info info) return result; } +napi_value JsWindow::OnSetImmersiveModeEnabledState(napi_env env, napi_callback_info info) +{ + size_t argc = 4; + napi_value argv[4] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc < 1) { + WLOGFE("Argc is invalid: %{public}zu", argc); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } + if (windowToken_ == nullptr) { + WLOGFE("windowToken_ is nullptr"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + if (!WindowHelper::IsMainWindow(windowToken_->GetType()) && + !WindowHelper::IsSubWindow(windowToken_->GetType())) { + WLOGFE("[NAPI]OnSetImmersiveModeEnabledState is not allowed since invalid window type"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + } + napi_value nativeVal = argv[0]; + if (nativeVal == nullptr) { + WLOGFE("Failed to convert parameter to enable"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } + bool enable = true; + napi_get_value_bool(env, nativeVal, &enable); + WLOGFI("[NAPI]OnSetImmersiveModeEnabledState to %{public}d", static_cast(enable)); + WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->SetImmersiveModeEnabledState(enable)); + if (ret != WmErrorCode::WM_OK) { + WLOGFE("Window immersive mode set enabled failed, ret = %{public}d", ret); + return NapiThrowError(env, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY); + } + WLOGI("window [%{public}u, %{public}s] OnSetImmersiveModeEnabledState end", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str()); + return NapiGetUndefined(env); +} + +napi_value JsWindow::OnGetImmersiveModeEnabledState(napi_env env, napi_callback_info info) +{ + if (windowToken_ == nullptr) { + WLOGFE("windowToken_ is nullptr"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + if (!WindowHelper::IsMainWindow(windowToken_->GetType())) { + WLOGFE("[NAPI]OnGetImmersiveModeEnabledState is not allowed since window is main window"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + } + wptr weakToken(windowToken_); + auto window = weakToken.promote(); + if (window == nullptr) { + WLOGFE("window is nullptr"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + bool isEnabled = window->GetImmersiveModeEnabledState(); + WLOGI("window [%{public}u, %{public}s] get isImmersiveMode end, isEnabled = %{public}u", + window->GetWindowId(), window->GetWindowName().c_str(), isEnabled); + return CreateJsValue(env, isEnabled); +} + void BindFunctions(napi_env env, napi_value object, const char *moduleName) { BindNativeFunction(env, object, "show", moduleName, JsWindow::Show); @@ -5868,6 +5940,8 @@ void BindFunctions(napi_env env, napi_value object, const char *moduleName) BindNativeFunction(env, object, "setTitleButtonVisible", moduleName, JsWindow::SetTitleButtonVisible); BindNativeFunction(env, object, "setWindowMask", moduleName, JsWindow::SetWindowMask); BindNativeFunction(env, object, "setWindowGrayScale", moduleName, JsWindow::SetWindowGrayScale); + BindNativeFunction(env, object, "setImmersiveModeEnabledState", moduleName, JsWindow::SetImmersiveModeEnabledState); + BindNativeFunction(env, object, "getImmersiveModeEnabledState", moduleName, JsWindow::GetImmersiveModeEnabledState); } } // namespace Rosen } // namespace OHOS diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.h b/interfaces/kits/napi/window_runtime/window_napi/js_window.h index 5b1e070f3d..73fdfd833a 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.h @@ -152,6 +152,8 @@ public: static napi_value SetTitleButtonVisible(napi_env env, napi_callback_info info); static napi_value SetWindowMask(napi_env env, napi_callback_info info); static napi_value SetWindowGrayScale(napi_env env, napi_callback_info info); + static napi_value SetImmersiveModeEnabledState(napi_env env, napi_callback_info info); + static napi_value GetImmersiveModeEnabledState(napi_env env, napi_callback_info info); private: std::string GetWindowName(); @@ -214,6 +216,8 @@ private: napi_value OnGetWindowDecorHeight(napi_env env, napi_callback_info info); napi_value OnGetTitleButtonRect(napi_env env, napi_callback_info info); napi_value OnSetTitleButtonVisible(napi_env env, napi_callback_info info); + napi_value OnSetImmersiveModeEnabledState(napi_env env, napi_callback_info info); + napi_value OnGetImmersiveModeEnabledState(napi_env env, napi_callback_info info); // colorspace, gamut napi_value OnIsSupportWideGamut(napi_env env, napi_callback_info info); diff --git a/previewer/include/window.h b/previewer/include/window.h index d0a6150817..2c9cae7bb2 100644 --- a/previewer/include/window.h +++ b/previewer/include/window.h @@ -329,6 +329,10 @@ public: } virtual WMError SetGrayScale(float grayScale) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } + + virtual WMError SetImmersiveModeEnabledState(bool enable) { return WMError::WM_OK; } + + virtual bool GetImmersiveModeEnabledState() const { return true; } }; } } diff --git a/previewer/include/window_impl.h b/previewer/include/window_impl.h index b0add9e5ca..e4f667a3fb 100644 --- a/previewer/include/window_impl.h +++ b/previewer/include/window_impl.h @@ -217,6 +217,8 @@ public: virtual WmErrorCode KeepKeyboardOnFocus(bool keepKeyboardFlag) override; virtual WMError SetSingleFrameComposerEnabled(bool enable) override; virtual WMError SetLandscapeMultiWindow(bool isLandscapeMultiWindow) override; + virtual WMError SetImmersiveModeEnabledState(bool enable) override; + virtual bool GetImmersiveModeEnabledState() const override; private: static std::map>> windowMap_; diff --git a/previewer/src/window_impl.cpp b/previewer/src/window_impl.cpp index 370b8946ab..9ace9e1854 100644 --- a/previewer/src/window_impl.cpp +++ b/previewer/src/window_impl.cpp @@ -900,5 +900,15 @@ WMError WindowImpl::SetLandscapeMultiWindow(bool isLandscapeMultiWindow) { return WMError::WM_OK; } + +WMError WindowImpl::SetImmersiveModeEnabledState(bool enable) +{ + return WMError::WM_OK; +} + +bool WindowImpl::GetImmersiveModeEnabledState() const +{ + return true; +} } // namespace Rosen } // namespace OHOS diff --git a/test/fuzztest/wms/window_fuzzer/window_fuzzer.cpp b/test/fuzztest/wms/window_fuzzer/window_fuzzer.cpp index 26aeb90c55..e31bb350c9 100644 --- a/test/fuzztest/wms/window_fuzzer/window_fuzzer.cpp +++ b/test/fuzztest/wms/window_fuzzer/window_fuzzer.cpp @@ -372,6 +372,9 @@ void CheckWindowImplFunctionsPart1(sptr window, const uint8_t* data, siz startPos += GetObject(systemBarProperty1, data + startPos, size - startPos); window->SetSpecificBarProperty(windowType, systemBarProperty1); + startPos += GetObject(boolVal, data + startPos, size - startPos); + window->SetImmersiveModeEnabledState(boolVal); + startPos += GetObject(boolVal, data + startPos, size - startPos); window->SetLayoutFullScreen(boolVal); diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 124557e330..cd599334fb 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -203,6 +203,8 @@ public: virtual void StartMove() override; virtual WMError SetGlobalMaximizeMode(MaximizeMode mode) override; virtual MaximizeMode GetGlobalMaximizeMode() const override; + virtual WMError SetImmersiveModeEnabledState(bool enable) override; + virtual bool GetImmersiveModeEnabledState() const override; virtual WMError RequestFocus() const override; virtual void SetInputEventConsumer(const std::shared_ptr& inputEventConsumer) override; @@ -600,6 +602,7 @@ private: static std::map>> subWindowMap_; static std::map>> appFloatingWindowMap_; static std::map>> appDialogWindowMap_; + static bool enableImmersiveMode_; sptr property_; WindowState state_ { WindowState::STATE_INITIAL }; WindowState subWindowState_ {WindowState::STATE_INITIAL}; diff --git a/wm/include/window_scene_session_impl.h b/wm/include/window_scene_session_impl.h index 2d7b5642f0..c8d2be17e9 100644 --- a/wm/include/window_scene_session_impl.h +++ b/wm/include/window_scene_session_impl.h @@ -151,6 +151,8 @@ public: void NotifyKeyboardPanelInfoChange(const KeyboardPanelInfo& keyboardPanelInfo) override; void UpdateDensity() override; WMError AdjustKeyboardLayout(const KeyboardLayoutParams& params) override; + virtual WMError SetImmersiveModeEnabledState(bool enable) override; + virtual bool GetImmersiveModeEnabledState() const override; protected: void DestroySubWindow(); @@ -180,6 +182,7 @@ private: bool IsValidSystemWindowType(const WindowType& type); WMError CheckParmAndPermission(); static uint32_t maxFloatingWindowSize_; + static bool enableImmersiveMode_; void TransformSurfaceNode(const Transform& trans); void AdjustWindowAnimationFlag(bool withAnimation = false); void RegisterSessionRecoverListener(bool isSpecificSession); diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index cac7e28b80..2d396aaf90 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -74,6 +74,7 @@ std::map> WindowImpl::dialogDeathR std::recursive_mutex WindowImpl::globalMutex_; int g_constructorCnt = 0; int g_deConstructorCnt = 0; +bool WindowImpl::enableImmersiveMode_ = true; WindowImpl::WindowImpl(const sptr& option) { property_ = new (std::nothrow) WindowProperty(); @@ -872,6 +873,7 @@ WMError WindowImpl::SetLayoutFullScreen(bool status) } } } + enableImmersiveMode_ = status; return ret; } @@ -2014,6 +2016,33 @@ MaximizeMode WindowImpl::GetGlobalMaximizeMode() const return SingletonContainer::Get().GetMaximizeMode(); } +WMError WindowImpl::SetImmersiveModeEnabledState(bool enable) +{ + WLOGI("WindowImpl id: %{public}u SetImmersiveModeEnabledState: %{public}u", property_->GetWindowId(), + static_cast(enable)); + if (!IsWindowValid() || + !WindowHelper::IsWindowModeSupported(GetModeSupportInfo(), WindowMode::WINDOW_MODE_FULLSCREEN)) { + WLOGFE("invalid window or fullscreen mode is not be supported, winId:%{public}u", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + const WindowType curWindowType = GetType(); + if (!WindowHelper::IsMainWindow(curWindowType) && !WindowHelper::IsSubWindow(curWindowType)) { + return WMError::WM_ERROR_INVALID_WINDOW; + } + + enableImmersiveMode_ = enable; + const WindowMode mode = GetMode(); + if (mode == WindowMode::WINDOW_MODE_FULLSCREEN) { + return SetLayoutFullScreen(enableImmersiveMode_); + } + return WMError::WM_OK; +} + +bool WindowImpl::GetImmersiveModeEnabledState() const +{ + return enableImmersiveMode_; +} + WMError WindowImpl::NotifyWindowTransition(TransitionReason reason) { sptr fromInfo = new(std::nothrow) WindowTransitionInfo(); diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index b41284cb04..5b89412463 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -77,6 +77,7 @@ constexpr float MAX_GRAY_SCALE = 1.0f; } uint32_t WindowSceneSessionImpl::maxFloatingWindowSize_ = 1920; std::mutex WindowSceneSessionImpl::keyboardPanelInfoChangeListenerMutex_; +bool WindowSceneSessionImpl::enableImmersiveMode_ = true; WindowSceneSessionImpl::WindowSceneSessionImpl(const sptr& option) : WindowSessionImpl(option) { @@ -1564,7 +1565,7 @@ WMError WindowSceneSessionImpl::SetLayoutFullScreen(bool status) } bool preStatus = property_->IsLayoutFullScreen(); - property_->SetIsLayoutFullScreen(status); + property_->SetIsLayoutFullScreen(true); UpdateProperty(WSPropertyChangeAction::ACTION_UPDATE_MAXIMIZE_STATE); if (WindowHelper::IsMainWindow(GetType()) && @@ -1588,7 +1589,7 @@ WMError WindowSceneSessionImpl::SetLayoutFullScreen(bool status) TLOGE(WmsLogTag::WMS_IMMS, "SetLayoutFullScreenByApiVersion errCode:%{public}d winId:%{public}u", static_cast(ret), GetWindowId()); } - + enableImmersiveMode_ = status; return ret; } @@ -1796,7 +1797,7 @@ WMError WindowSceneSessionImpl::Maximize(MaximizeLayoutOption option) if (!WindowHelper::IsWindowModeSupported(property_->GetModeSupportInfo(), WindowMode::WINDOW_MODE_FULLSCREEN)) { return WMError::WM_ERROR_INVALID_WINDOW; } - property_->SetIsLayoutFullScreen(option.decor == ShowType::HIDE); + return SetLayoutFullScreen(enableImmersiveMode_); return SetFullScreen(true); } @@ -3312,5 +3313,33 @@ WMError WindowSceneSessionImpl::AdjustKeyboardLayout(const KeyboardLayoutParams& } return WMError::WM_OK; } + +WMError WindowSceneSessionImpl::SetImmersiveModeEnabledState(bool enable) +{ + WLOGFD("id: %{public}u, SetImmersiveModeEnabledState: %{public}u", GetWindowId(), enable); + if (hostSession_ == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + if (!WindowHelper::IsWindowModeSupported(property_->GetModeSupportInfo(), WindowMode::WINDOW_MODE_FULLSCREEN)) { + return WMError::WM_ERROR_INVALID_WINDOW; + } + const WindowType curWindowType = GetType(); + if (!WindowHelper::IsMainWindow(curWindowType) && !WindowHelper::IsSubWindow(curWindowType)) { + return WMError::WM_ERROR_INVALID_WINDOW; + } + + enableImmersiveMode_ = enable; + WindowMode mode = GetMode(); + if (mode == WindowMode::WINDOW_MODE_FULLSCREEN) { + return SetLayoutFullScreen(enableImmersiveMode_); + } + return WMError::WM_OK; +} + +bool WindowSceneSessionImpl::GetImmersiveModeEnabledState() const +{ + WLOGFD("id: %{public}u, GetImmersiveModeEnabledState = %{public}u", GetWindowId(), enableImmersiveMode_); + return enableImmersiveMode_; +} } // namespace Rosen } // namespace OHOS diff --git a/wm/test/unittest/window_impl_test.cpp b/wm/test/unittest/window_impl_test.cpp index e67f087bcb..96221a4c69 100644 --- a/wm/test/unittest/window_impl_test.cpp +++ b/wm/test/unittest/window_impl_test.cpp @@ -2282,6 +2282,67 @@ HWTEST_F(WindowImplTest, SetLayoutFullScreen, Function | SmallTest | Level3) ASSERT_EQ(WMError::WM_OK, window->Destroy()); } +/* + * @tc.name: SetImmersiveModeEnabledState + * @tc.desc: SetImmersiveModeEnabledState test + * @tc.type: FUNC + */ +HWTEST_F(WindowImplTest, SetImmersiveModeEnabledState, Function | SmallTest | Level3) +{ + sptr option = new WindowOption(); + option->SetWindowName("SetImmersiveModeEnabledState"); + option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + sptr window = new WindowImpl(option); + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetWindowFlags(0)); + EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); + window->UpdateModeSupportInfo(0); + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetImmersiveModeEnabledState(true)); + window->UpdateModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL); + + EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Show()); + + EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(1).WillOnce(Return(WMError::WM_DO_NOTHING)); + ASSERT_EQ(WMError::WM_DO_NOTHING, window->SetImmersiveModeEnabledState(true)); + + window->property_->SetWindowFlags(window->property_->GetWindowFlags() | + (static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID))); + EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(2) + .WillOnce(Return(WMError::WM_OK)) + .WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(true)); + ASSERT_EQ(true, window->GetImmersiveModeEnabledState()); + + window->property_->SetWindowFlags(window->property_->GetWindowFlags() | + (static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID))); + EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(2) + .WillOnce(Return(WMError::WM_OK)) + .WillOnce(Return(WMError::WM_DO_NOTHING)); + ASSERT_EQ(WMError::WM_DO_NOTHING, window->SetImmersiveModeEnabledState(true)); + + window->property_->SetWindowFlags(window->property_->GetWindowFlags() & + (~static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID))); + EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(2) + .WillOnce(Return(WMError::WM_OK)) + .WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(false)); + ASSERT_EQ(false, window->GetImmersiveModeEnabledState()); + + window->property_->SetWindowFlags(window->property_->GetWindowFlags() & + (~static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID))); + EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(2) + .WillOnce(Return(WMError::WM_OK)) + .WillOnce(Return(WMError::WM_DO_NOTHING)); + ASSERT_EQ(WMError::WM_DO_NOTHING, window->SetImmersiveModeEnabledState(false)); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + + /* * @tc.name: SetFullScreen * @tc.desc: SetFullScreen test diff --git a/wm/test/unittest/window_scene_session_impl_test.cpp b/wm/test/unittest/window_scene_session_impl_test.cpp index c46cd4593d..0be4c578ff 100644 --- a/wm/test/unittest/window_scene_session_impl_test.cpp +++ b/wm/test/unittest/window_scene_session_impl_test.cpp @@ -1490,6 +1490,51 @@ HWTEST_F(WindowSceneSessionImplTest, SetSnapshotSkip, Function | SmallTest | Lev } } +/* + * @tc.name: SetImmersiveModeEnabledState + * @tc.desc: SetImmersiveModeEnabledState test + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest, SetImmersiveModeEnabledState, Function | SmallTest | Level3) +{ + sptr option = new (std::nothrow) WindowOption(); + sptr window = new (std::nothrow) WindowSceneSessionImpl(option); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->SetImmersiveModeEnabledState(false)); + + window->property_->SetPersistentId(1); + SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"}; + sptr session = new (std::nothrow) SessionMocker(sessionInfo); + ASSERT_NE(nullptr, session); + window->hostSession_ = session; + window->property_->SetWindowName("SetImmersiveModeEnabledState"); + window->property_->SetWindowType(WindowType::WINDOW_TYPE_PIP); + window->state_ = WindowState::STATE_CREATED; + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetImmersiveModeEnabledState(false)); + + window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(true)); + ASSERT_EQ(true, window->GetImmersiveModeEnabledState()); + ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(false)); + ASSERT_EQ(false, window->GetImmersiveModeEnabledState()); + + window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + ASSERT_EQ(WMError::WM_OK, window->SetLayoutFullScreen(true)); + ASSERT_EQ(true, window->IsLayoutFullScreen()); + ASSERT_EQ(WMError::WM_OK, window->SetLayoutFullScreen(false)); + ASSERT_EQ(false, window->IsLayoutFullScreen()); + ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(true)); + ASSERT_EQ(true, window->IsLayoutFullScreen()); + ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(false)); + ASSERT_EQ(false, window->IsLayoutFullScreen()); + + window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + ASSERT_EQ(WMError::WM_OK, window->SetImmersiveModeEnabledState(true)); + ASSERT_EQ(false, window->IsLayoutFullScreen()); + ASSERT_EQ(true, window->GetImmersiveModeEnabledState()); + ASSERT_EQ(WMError::WM_OK, window->MaximizeFloating()); + ASSERT_EQ(true, window->IsLayoutFullScreen()); +} + /* * @tc.name: SetLayoutFullScreen * @tc.desc: SetLayoutFullScreen test diff --git a/wm/test/unittest/window_test.cpp b/wm/test/unittest/window_test.cpp index 4430731d17..b87c0a36cf 100644 --- a/wm/test/unittest/window_test.cpp +++ b/wm/test/unittest/window_test.cpp @@ -424,6 +424,20 @@ HWTEST_F(WindowTest, GetAvoidAreaByType, Function | SmallTest | Level2) ASSERT_EQ(WMError::WM_OK, window->Destroy()); } +/** + * @tc.name: SetImmersiveModeEnabledState + * @tc.desc: get + * @tc.type: FUNC + */ +HWTEST_F(WindowTest, SetImmersiveModeEnabledState, Function | SmallTest | Level2) +{ + sptr window = new Window(); + ASSERT_NE(nullptr, window); + auto ret = window->SetImmersiveModeEnabledState(true); + ASSERT_EQ(WMError::WM_OK, ret); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + /** * @tc.name: SetLayoutFullScreen * @tc.desc: get