diff --git a/bundle.json b/bundle.json index 64b1db59a8..bf2beb6754 100755 --- a/bundle.json +++ b/bundle.json @@ -68,7 +68,7 @@ "frame_aware_sched_override", "imf", "frame_aware_sched", - "memmgr_plugin", + "memmgr_override", "data_share", "accessibility", "security_component_manager", diff --git a/dm/BUILD.gn b/dm/BUILD.gn index 3f5abce609..395c20a773 100644 --- a/dm/BUILD.gn +++ b/dm/BUILD.gn @@ -31,16 +31,21 @@ config("libdm_public_config") { include_dirs = [ "../interfaces/innerkits/dm", "../utils/include", - "${multimedia_path}/interfaces/innerkits/include", ] } +config("for_libdm_public_config") { + include_dirs = + [ "../../../multimedia/image_framework/interfaces/innerkits/include" ] +} + ## Build libdm_static.a ohos_static_library("libdm_static") { branch_protector_ret = "pac_ret" sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false integer_overflow = true ubsan = true @@ -71,7 +76,10 @@ ohos_static_library("libdm_static") { "${window_base_path}/window_scene/interfaces/innerkits:libwsutils", ] - public_external_deps = [ "graphic_2d:color_manager" ] + public_external_deps = [ + "graphic_2d:color_manager", + "image_framework:image_native", + ] external_deps = [ "ability_runtime:ability_manager", @@ -107,7 +115,10 @@ ohos_shared_library("libdm") { "../resources/config/build:coverage_flags", ] - public_configs = [ ":libdm_public_config" ] + public_configs = [ + ":for_libdm_public_config", + ":libdm_public_config", + ] deps = [ "${window_base_path}/utils:libwmutil", diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 01e1d6dd49..d1d58a9776 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -406,7 +406,7 @@ void DMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) WLOGFE("object is null"); return; } - WLOGFD("dms OnRemoteDied"); + WLOGFI("dms OnRemoteDied"); adapter_.Clear(); SingletonContainer::Get().OnRemoteDied(); SingletonContainer::Get().OnRemoteDied(); diff --git a/dm/test/unittest/display_manager_adapter_test.cpp b/dm/test/unittest/display_manager_adapter_test.cpp index a8fab55d03..6f3e8b2132 100644 --- a/dm/test/unittest/display_manager_adapter_test.cpp +++ b/dm/test/unittest/display_manager_adapter_test.cpp @@ -83,7 +83,7 @@ HWTEST_F(DisplayManagerAdapterTest, GetScreenSupportedColorGamuts, Function | Sm if (!SceneBoardJudgement::IsSceneBoardEnabled()) { ASSERT_EQ(err, DMError::DM_ERROR_RENDER_SERVICE_FAILED); } else { - ASSERT_EQ(err, DMError::DM_ERROR_INVALID_PARAM); + ASSERT_EQ(err, DMError::DM_OK); } } @@ -115,7 +115,7 @@ HWTEST_F(DisplayManagerAdapterTest, GetScreenColorGamut, Function | SmallTest | if (!SceneBoardJudgement::IsSceneBoardEnabled()) { ASSERT_EQ(err, DMError::DM_ERROR_RENDER_SERVICE_FAILED); } else { - ASSERT_EQ(err, DMError::DM_ERROR_INVALID_PARAM); + ASSERT_EQ(err, DMError::DM_OK); } } @@ -146,7 +146,7 @@ HWTEST_F(DisplayManagerAdapterTest, SetScreenGamutMap, Function | SmallTest | Le if (!SceneBoardJudgement::IsSceneBoardEnabled()) { ASSERT_EQ(err, DMError::DM_ERROR_RENDER_SERVICE_FAILED); } else { - ASSERT_EQ(err, DMError::DM_ERROR_INVALID_PARAM); + ASSERT_EQ(err, DMError::DM_ERROR_RENDER_SERVICE_FAILED); } } @@ -161,7 +161,7 @@ HWTEST_F(DisplayManagerAdapterTest, SetScreenColorTransform, Function | SmallTes if (!SceneBoardJudgement::IsSceneBoardEnabled()) { ASSERT_EQ(err, DMError::DM_OK); } else { - ASSERT_EQ(err, DMError::DM_ERROR_INVALID_PARAM); + ASSERT_EQ(err, DMError::DM_OK); } } @@ -300,7 +300,7 @@ HWTEST_F(DisplayManagerAdapterTest, GetPixelFormat, Function | SmallTest | Level if (!SceneBoardJudgement::IsSceneBoardEnabled()) { ASSERT_EQ(err, DMError::DM_ERROR_IPC_FAILED); } else { - ASSERT_EQ(err, DMError::DM_ERROR_INVALID_PARAM); + ASSERT_EQ(err, DMError::DM_OK); } } @@ -316,7 +316,7 @@ HWTEST_F(DisplayManagerAdapterTest, SetPixelFormat, Function | SmallTest | Level if (!SceneBoardJudgement::IsSceneBoardEnabled()) { ASSERT_EQ(err, DMError::DM_ERROR_IPC_FAILED); } else { - ASSERT_EQ(err, DMError::DM_ERROR_INVALID_PARAM); + ASSERT_EQ(err, DMError::DM_OK); } } @@ -579,7 +579,7 @@ HWTEST_F(DisplayManagerAdapterTest, SetDisplayState, Function | SmallTest | Leve { DisplayState state = DisplayState{1}; bool ret = SingletonContainer::Get().SetDisplayState(state); - ASSERT_FALSE(ret); + ASSERT_TRUE(ret); } /** diff --git a/dm/test/unittest/display_manager_test.cpp b/dm/test/unittest/display_manager_test.cpp index 7dd50d9e08..300c4aa8db 100644 --- a/dm/test/unittest/display_manager_test.cpp +++ b/dm/test/unittest/display_manager_test.cpp @@ -349,7 +349,7 @@ HWTEST_F(DisplayManagerTest, GetScreenBrightness, Function | SmallTest | Level1) */ HWTEST_F(DisplayManagerTest, GetDisplayById, Function | SmallTest | Level1) { - DisplayId displayId = 0; + DisplayId displayId = -1; DisplayManager::GetInstance().destroyed_ = true; auto ret = DisplayManager::GetInstance().GetDisplayById(displayId); ASSERT_EQ(ret, nullptr); @@ -650,6 +650,81 @@ HWTEST_F(DisplayManagerTest, RemoveSurfaceNodeFromDisplay, Function | SmallTest auto ret = DisplayManager::GetInstance().RemoveSurfaceNodeFromDisplay(0, surfaceNode); ASSERT_EQ(ret, DMError::DM_ERROR_IPC_FAILED); } + +/** + * @tc.name: RegisterFoldAngleListener01 + * @tc.desc: RegisterFoldAngleListener01 fun + * @tc.type: FUNC + */ +HWTEST_F(DisplayManagerTest, RegisterFoldAngleListener01, Function | SmallTest | Level1) +{ + sptr listener = nullptr; + auto ret = DisplayManager::GetInstance().RegisterFoldAngleListener(listener); + ASSERT_EQ(ret, DMError::DM_ERROR_NULLPTR); + listener = new DisplayManager::IFoldAngleListener(); + ret = DisplayManager::GetInstance().RegisterFoldAngleListener(listener); + ASSERT_EQ(ret, DisplayManager::GetInstance().pImpl_->RegisterFoldAngleListener(listener)); + listener.clear(); +} + +/** + * @tc.name: UnregisterFoldAngleListener01 + * @tc.desc: UnregisterFoldAngleListener01 fun + * @tc.type: FUNC + */ +HWTEST_F(DisplayManagerTest, UnregisterFoldAngleListener01, Function | SmallTest | Level1) +{ + sptr listener; + auto ret = DisplayManager::GetInstance().UnregisterFoldAngleListener(listener); + ASSERT_EQ(ret, DMError::DM_ERROR_NULLPTR); + listener = new DisplayManager::IFoldAngleListener(); + ret = DisplayManager::GetInstance().UnregisterFoldAngleListener(listener); + ASSERT_EQ(ret, DisplayManager::GetInstance().pImpl_->UnregisterFoldAngleListener(listener)); + listener.clear(); +} + +/** + * @tc.name: RegisterCaptureStatusListener01 + * @tc.desc: RegisterCaptureStatusListener01 fun + * @tc.type: FUNC + */ +HWTEST_F(DisplayManagerTest, RegisterCaptureStatusListener01, Function | SmallTest | Level1) +{ + sptr listener = nullptr; + auto ret = DisplayManager::GetInstance().RegisterCaptureStatusListener(listener); + ASSERT_EQ(ret, DMError::DM_ERROR_NULLPTR); + listener = new DisplayManager::ICaptureStatusListener(); + ret = DisplayManager::GetInstance().RegisterCaptureStatusListener(listener); + ASSERT_EQ(ret, DisplayManager::GetInstance().pImpl_->RegisterCaptureStatusListener(listener)); + listener.clear(); +} + +/** + * @tc.name: UnregisterCaptureStatusListener01 + * @tc.desc: UnregisterCaptureStatusListener01 fun + * @tc.type: FUNC + */ +HWTEST_F(DisplayManagerTest, UnregisterCaptureStatusListener01, Function | SmallTest | Level1) +{ + sptr listener; + auto ret = DisplayManager::GetInstance().UnregisterCaptureStatusListener(listener); + ASSERT_EQ(ret, DMError::DM_ERROR_NULLPTR); + listener = new DisplayManager::ICaptureStatusListener(); + ret = DisplayManager::GetInstance().UnregisterCaptureStatusListener(listener); + ASSERT_EQ(ret, DisplayManager::GetInstance().pImpl_->UnregisterCaptureStatusListener(listener)); + listener.clear(); +} + +/** + * @tc.name: IsCaptured01 + * @tc.desc: IsCaptured01 fun + * @tc.type: FUNC + */ +HWTEST_F(DisplayManagerTest, IsCaptured01, Function | SmallTest | Level1) +{ + auto ret = DisplayManager::GetInstance().IsCaptured(); + ASSERT_FALSE(ret); +} } } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/dm/test/unittest/display_test.cpp b/dm/test/unittest/display_test.cpp index bc837b7d67..bad6c932e1 100644 --- a/dm/test/unittest/display_test.cpp +++ b/dm/test/unittest/display_test.cpp @@ -185,7 +185,7 @@ HWTEST_F(DisplayTest, HasImmersiveWindow, Function | SmallTest | Level1) { bool immersive = false; DMError ret = defaultDisplay_->HasImmersiveWindow(immersive); - ASSERT_EQ(ret, DMError::DM_ERROR_DEVICE_NOT_SUPPORT); + ASSERT_EQ(ret, DMError::DM_OK); } } } // namespace Rosen diff --git a/dm/test/unittest/screen_manager_test.cpp b/dm/test/unittest/screen_manager_test.cpp index 06c73e5ba8..63253f76f5 100644 --- a/dm/test/unittest/screen_manager_test.cpp +++ b/dm/test/unittest/screen_manager_test.cpp @@ -543,7 +543,7 @@ HWTEST_F(ScreenManagerTest, GetVirtualScreenFlag01, Function | SmallTest | Level DMError ret = ScreenManager::GetInstance().SetVirtualScreenFlag(screenId, VirtualScreenFlag::CAST); ASSERT_EQ(DMError::DM_OK, ret); VirtualScreenFlag screenFlag = ScreenManager::GetInstance().GetVirtualScreenFlag(screenId); - ASSERT_EQ(VirtualScreenFlag::CAST, screenFlag); + ASSERT_EQ(VirtualScreenFlag::DEFAULT, screenFlag); ret = ScreenManager::GetInstance().DestroyVirtualScreen(screenId); ASSERT_EQ(DMError::DM_OK, ret); } @@ -581,6 +581,38 @@ HWTEST_F(ScreenManagerTest, SetVirtualMirrorScreenScaleMode02, Function | SmallT ret = ScreenManager::GetInstance().DestroyVirtualScreen(screenId); ASSERT_EQ(DMError::DM_OK, ret); } + +/** + * @tc.name: IsCaptured02 + * @tc.desc: IsCaptured02 fun + * @tc.type: FUNC + */ +HWTEST_F(ScreenManagerTest, IsCaptured02, Function | SmallTest | Level1) +{ + VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_, + defaultDensity_, nullptr, defaultFlags_}; + ScreenId screenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); + bool isCapture = DisplayManager::GetInstance().IsCaptured(); + ASSERT_TRUE(isCapture); + auto ret = ScreenManager::GetInstance().DestroyVirtualScreen(screenId); + ASSERT_EQ(DMError::DM_OK, ret); +} + +/** + * @tc.name: IsCaptured03 + * @tc.desc: IsCaptured03 fun + * @tc.type: FUNC + */ +HWTEST_F(ScreenManagerTest, IsCaptured03, Function | SmallTest | Level1) +{ + VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_, + defaultDensity_, nullptr, defaultFlags_}; + ScreenId screenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); + auto ret = ScreenManager::GetInstance().DestroyVirtualScreen(screenId); + ASSERT_EQ(DMError::DM_OK, ret); + bool isCapture = DisplayManager::GetInstance().IsCaptured(); + ASSERT_FALSE(isCapture); +} } } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/dm_lite/BUILD.gn b/dm_lite/BUILD.gn index 07efd095c5..cdb6caa951 100644 --- a/dm_lite/BUILD.gn +++ b/dm_lite/BUILD.gn @@ -37,6 +37,7 @@ ohos_shared_library("libdm_lite") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ diff --git a/dmserver/BUILD.gn b/dmserver/BUILD.gn index ef03b1eb23..a3b3f3dbdc 100644 --- a/dmserver/BUILD.gn +++ b/dmserver/BUILD.gn @@ -31,6 +31,7 @@ ohos_shared_library("libdms") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ @@ -78,9 +79,7 @@ ohos_shared_library("libdms") { ] if (defined(use_new_skia) && use_new_skia) { - include_dirs = [ "//third_party/skia/src" ] - } else { - include_dirs = [ "//third_party/flutter/skia/src" ] + include_dirs = [ "../../../../third_party/skia/src" ] } defines = [] diff --git a/extension/extension_connection/BUILD.gn b/extension/extension_connection/BUILD.gn index b4606bfe48..29f18a8ca1 100644 --- a/extension/extension_connection/BUILD.gn +++ b/extension/extension_connection/BUILD.gn @@ -33,6 +33,7 @@ ohos_shared_library("libwindow_extension_client") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } install_enable = true diff --git a/extension/modal_system_ui_extension/BUILD.gn b/extension/modal_system_ui_extension/BUILD.gn index 2ebb9aa834..4349ade00a 100644 --- a/extension/modal_system_ui_extension/BUILD.gn +++ b/extension/modal_system_ui_extension/BUILD.gn @@ -28,6 +28,7 @@ ohos_shared_library("libmodal_system_ui_extension_client") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } install_enable = true diff --git a/extension/window_extension/BUILD.gn b/extension/window_extension/BUILD.gn index 5a7881311e..77fd16ddb6 100644 --- a/extension/window_extension/BUILD.gn +++ b/extension/window_extension/BUILD.gn @@ -35,6 +35,7 @@ ohos_shared_library("libwindow_extension") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ @@ -93,6 +94,7 @@ ohos_shared_library("window_extension_module") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ "src/window_extension_module_loader.cpp" ] diff --git a/extension/window_extension/src/zidl/window_extension_stub.cpp b/extension/window_extension/src/zidl/window_extension_stub.cpp index f9537f391e..9a3366321a 100644 --- a/extension/window_extension/src/zidl/window_extension_stub.cpp +++ b/extension/window_extension/src/zidl/window_extension_stub.cpp @@ -53,6 +53,9 @@ int WindowExtensionStub::OnRemoteRequest(uint32_t code, MessageParcel& data, sptr object = data.ReadRemoteObject(); sptr token = iface_cast(object); GetExtensionWindow(token); + if (token == nullptr) { + return -1; + } break; } default: { diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index 22ac29c3c9..6f4c4ef9aa 100644 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -23,6 +23,7 @@ ohos_shared_library("wm_interface") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } public_configs = [ ":wm_interface_config" ] diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 50740918b8..0dad880268 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -445,6 +445,21 @@ public: virtual void OnRectChange(Rect rect, WindowSizeChangeReason reason) {} }; +/** + * @class IKeyboardPanelInfoChangeListener + * + * @brief IKeyboardPanelInfoChangeListener is used to observe the keyboard panel info. + */ +class IKeyboardPanelInfoChangeListener : virtual public RefBase { +public: + /** + * @brief Notify caller when keyboard info changed. + * + * @param KeyboardPanelInfo keyboardPanelInfo of the keyboard panel; + */ + virtual void OnKeyboardPanelInfoChanged(const KeyboardPanelInfo& keyboardPanelInfo) {} +}; + static WMError DefaultCreateErrCode = WMError::WM_OK; class Window : virtual public RefBase { public: @@ -1795,6 +1810,17 @@ public: return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } + /** + * @brief Set water mark flag. + * + * @param isEnable bool. + * @return WMError + */ + virtual WMError SetWaterMarkFlag(bool isEnable) + { + return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; + } + /** * @brief Set the modality of window. * @@ -1814,22 +1840,6 @@ public: */ virtual WMError Recover(uint32_t reason) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } - /** - * @brief Add uiextension window flag. - * - * @param flag Flag of uiextension window. - * @return WM_OK means add success, others means failed. - */ - virtual WMError AddExtensionWindowFlag(ExtensionWindowFlag flag) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } - - /** - * @brief Remove uiextension window flag. - * - * @param flag Flag of uiextension window - * @return WM_OK means remove success, others means failed. - */ - virtual WMError RemoveExtensionWindowFlag(ExtensionWindowFlag flag) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } - /** * @brief Make multi-window become landscape or not. * @@ -1882,6 +1892,28 @@ public: return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } + /** + * @brief Register keyboard panel info change listener. + * + * @param listener IKeyboardPanelInfoChangeListener. + * @return WM_OK means register success, others means register failed. + */ + virtual WMError RegisterKeyboardPanelInfoChangeListener(const sptr& listener) + { + return WMError::WM_OK; + } + + /** + * @brief Unregister keyboard panel info change listener. + * + * @param listener IKeyboardPanelInfoChangeListener. + * @return WM_OK means unregister success, others means unregister failed. + */ + virtual WMError UnregisterKeyboardPanelInfoChangeListener(const sptr& listener) + { + return WMError::WM_OK; + } + /** * @brief Get window by id * @@ -1927,6 +1959,13 @@ public: { return WMError::WM_OK; } + + /** + * @brief Set gray scale of window + * @param grayScale gray scale of window. + * @return WM_OK means set success, others means set failed. + */ + virtual WMError SetGrayScale(float grayScale) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } }; } } diff --git a/interfaces/innerkits/wm/window_option.h b/interfaces/innerkits/wm/window_option.h index 3e0c77d38b..7fe693b97d 100644 --- a/interfaces/innerkits/wm/window_option.h +++ b/interfaces/innerkits/wm/window_option.h @@ -237,6 +237,20 @@ public: */ void SetExtensionTag(bool isExtensionTag); + /** + * @brief Set Dialog Decor Enable Or Not. + * + * @param decorEnable true means enable, default disabled. + */ + void SetDialogDecorEnable(bool decorEnable); + + /** + * @brief Set Dialog title. + * + * @param dialogTitle true means enable, default disabled. + */ + void SetDialogTitle(const std::string& dialogTitle); + /** * @brief Get window rect. * @@ -391,6 +405,20 @@ public: */ bool GetExtensionTag() const; + /** + * @brief Get dialog decor enable + * + * @return true means the dialog decor is enabled, otherwise not. + */ + bool GetDialogDecorEnable() const; + + /** + * @brief Get dialog title + * + * @return Return the dialog title + */ + std::string GetDialogTitle() const; + private: Rect windowRect_ { 0, 0, 0, 0 }; WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; @@ -419,6 +447,8 @@ private: bool subWindowDecorEnable_ = false; bool onlySupportSceneBoard_ = false; bool isExtensionTag_ = false; + bool dialogDecorEnable_ = false; + std::string dialogTitle_ = { "" }; }; } // namespace Rosen } // namespace OHOS diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 15a44ed1fa..8606e8bdfa 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -289,11 +289,19 @@ enum class WindowFlag : uint32_t { }; /** - * @brief Enumerates flag of uiextension window. + * @brief Flag of uiextension window. */ -enum class ExtensionWindowFlag : uint32_t { - EXTENSION_WINDOW_FLAG_WATER_MARK = 1, - EXTENSION_WINDOW_FLAG_END = 1 << 1, +union ExtensionWindowFlags { + uint32_t bitData; + struct { + // Each flag should be false default, true when active + bool hideNonSecureWindowsFlag : 1; + bool waterMarkFlag : 1; + bool privacyModeFlag : 1; + }; + ExtensionWindowFlags() : bitData(0) {} + ExtensionWindowFlags(uint32_t bits) : bitData(bits) {} + ~ExtensionWindowFlags() {} }; /** @@ -365,6 +373,7 @@ enum class WindowSessionType : uint32_t { enum class WindowGravity : uint32_t { WINDOW_GRAVITY_FLOAT = 0, WINDOW_GRAVITY_BOTTOM, + WINDOW_GRAVITY_DEFAULT, }; /** @@ -550,6 +559,44 @@ struct Rect { } }; +/** + * @struct KeyboardPanelInfo + * + * @brief Info of keyboard panel + */ +struct KeyboardPanelInfo : public Parcelable { + Rect rect_ = {0, 0, 0, 0}; + WindowGravity gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM; + bool isShowing_ = false; + + bool Marshalling(Parcel& parcel) const + { + return parcel.WriteInt32(rect_.posX_) && parcel.WriteInt32(rect_.posY_) && + parcel.WriteUint32(rect_.width_) && parcel.WriteUint32(rect_.height_) && + parcel.WriteUint32(static_cast(gravity_)) && + parcel.WriteBool(isShowing_); + } + + static KeyboardPanelInfo* Unmarshalling(Parcel& parcel) + { + KeyboardPanelInfo* keyboardPanelInfo = new(std::nothrow)KeyboardPanelInfo; + if (keyboardPanelInfo == nullptr) { + return nullptr; + } + bool res = parcel.ReadInt32(keyboardPanelInfo->rect_.posX_) && + parcel.ReadInt32(keyboardPanelInfo->rect_.posY_) && parcel.ReadUint32(keyboardPanelInfo->rect_.width_) && + parcel.ReadUint32(keyboardPanelInfo->rect_.height_); + if (!res) { + delete keyboardPanelInfo; + return nullptr; + } + keyboardPanelInfo->gravity_ = static_cast(parcel.ReadUint32()); + keyboardPanelInfo->isShowing_ = parcel.ReadBool(); + + return keyboardPanelInfo; + } +}; + /** * @brief Enumerates avoid area type. */ diff --git a/interfaces/kits/napi/common/BUILD.gn b/interfaces/kits/napi/common/BUILD.gn index 8478980f57..72bc0b5bbd 100644 --- a/interfaces/kits/napi/common/BUILD.gn +++ b/interfaces/kits/napi/common/BUILD.gn @@ -36,6 +36,7 @@ ohos_static_library("dm_napi_common") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false integer_overflow = true ubsan = true diff --git a/interfaces/kits/napi/display_runtime/BUILD.gn b/interfaces/kits/napi/display_runtime/BUILD.gn index 1fa6778224..d2fc190232 100644 --- a/interfaces/kits/napi/display_runtime/BUILD.gn +++ b/interfaces/kits/napi/display_runtime/BUILD.gn @@ -20,9 +20,6 @@ config("display_config") { include_dirs = [ ".", "../../../../utils/include", - - # because of pixle_map.h - "//foundation/multimedia/image_framework/interfaces/innerkits/include", ] } @@ -32,6 +29,7 @@ ohos_shared_library("display_napi") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ @@ -61,6 +59,8 @@ ohos_shared_library("display_napi") { "napi:ace_napi", ] + public_external_deps = [ "image_framework:image_native" ] + relative_install_dir = "module" part_name = "window_manager" subsystem_name = "window" diff --git a/interfaces/kits/napi/display_runtime/js_display_manager.cpp b/interfaces/kits/napi/display_runtime/js_display_manager.cpp index f0458e9adb..c1d9e6c2a2 100644 --- a/interfaces/kits/napi/display_runtime/js_display_manager.cpp +++ b/interfaces/kits/napi/display_runtime/js_display_manager.cpp @@ -45,7 +45,7 @@ explicit JsDisplayManager(napi_env env) { static void Finalizer(napi_env env, void* data, void* hint) { - WLOGD("Finalizer is called"); + WLOGI("Finalizer is called"); std::unique_ptr(static_cast(data)); } diff --git a/interfaces/kits/napi/embeddable_window_stage/BUILD.gn b/interfaces/kits/napi/embeddable_window_stage/BUILD.gn index 3d56ced678..b12dd616f4 100644 --- a/interfaces/kits/napi/embeddable_window_stage/BUILD.gn +++ b/interfaces/kits/napi/embeddable_window_stage/BUILD.gn @@ -39,6 +39,7 @@ ohos_shared_library("embeddablewindowstage") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ "embeddable_window_stage_module.cpp" ] @@ -75,6 +76,7 @@ ohos_shared_library("embeddablewindowstage_kit") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ "js_embeddable_window_stage.cpp" ] diff --git a/interfaces/kits/napi/extension_window/BUILD.gn b/interfaces/kits/napi/extension_window/BUILD.gn index a0b6c3b86d..9c4e2cdcf1 100644 --- a/interfaces/kits/napi/extension_window/BUILD.gn +++ b/interfaces/kits/napi/extension_window/BUILD.gn @@ -39,6 +39,7 @@ ohos_shared_library("extensionwindow") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ "extension_window_module.cpp" ] @@ -74,6 +75,7 @@ ohos_shared_library("extensionwindow_napi") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ diff --git a/interfaces/kits/napi/picture_in_picture_napi/BUILD.gn b/interfaces/kits/napi/picture_in_picture_napi/BUILD.gn index 1049005a5f..650b192b71 100644 --- a/interfaces/kits/napi/picture_in_picture_napi/BUILD.gn +++ b/interfaces/kits/napi/picture_in_picture_napi/BUILD.gn @@ -24,6 +24,7 @@ ohos_shared_library("pipwindow_napi") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ diff --git a/interfaces/kits/napi/picture_in_picture_napi/inner/BUILD.gn b/interfaces/kits/napi/picture_in_picture_napi/inner/BUILD.gn index c4980348d3..b985f0c66b 100644 --- a/interfaces/kits/napi/picture_in_picture_napi/inner/BUILD.gn +++ b/interfaces/kits/napi/picture_in_picture_napi/inner/BUILD.gn @@ -24,6 +24,7 @@ ohos_shared_library("pip_napi") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ diff --git a/interfaces/kits/napi/screen_runtime/BUILD.gn b/interfaces/kits/napi/screen_runtime/BUILD.gn index 177ef07673..31da0c66ae 100644 --- a/interfaces/kits/napi/screen_runtime/BUILD.gn +++ b/interfaces/kits/napi/screen_runtime/BUILD.gn @@ -25,6 +25,7 @@ ohos_shared_library("screen_napi") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ diff --git a/interfaces/kits/napi/screenshot/BUILD.gn b/interfaces/kits/napi/screenshot/BUILD.gn index 4691aa669f..b1fd822f44 100644 --- a/interfaces/kits/napi/screenshot/BUILD.gn +++ b/interfaces/kits/napi/screenshot/BUILD.gn @@ -19,6 +19,7 @@ ohos_shared_library("screenshot") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ "native_screenshot_module.cpp" ] diff --git a/interfaces/kits/napi/window_extension_ability/BUILD.gn b/interfaces/kits/napi/window_extension_ability/BUILD.gn index 30e8edea89..3a359e9c58 100644 --- a/interfaces/kits/napi/window_extension_ability/BUILD.gn +++ b/interfaces/kits/napi/window_extension_ability/BUILD.gn @@ -39,6 +39,7 @@ ohos_shared_library("windowextensionability_napi") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ "window_extension_ability_module.cpp" ] diff --git a/interfaces/kits/napi/window_extension_context/BUILD.gn b/interfaces/kits/napi/window_extension_context/BUILD.gn index 91dfad5f6e..97915496f3 100644 --- a/interfaces/kits/napi/window_extension_context/BUILD.gn +++ b/interfaces/kits/napi/window_extension_context/BUILD.gn @@ -39,6 +39,7 @@ ohos_shared_library("windowextensioncontext_napi") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ "window_extension_context_module.cpp" ] diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn index 679fd791ca..21eab80ab1 100644 --- a/interfaces/kits/napi/window_runtime/BUILD.gn +++ b/interfaces/kits/napi/window_runtime/BUILD.gn @@ -44,6 +44,7 @@ ohos_shared_library("window_native_kit") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ @@ -101,6 +102,7 @@ ohos_shared_library("window_napi") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ @@ -145,6 +147,7 @@ ohos_shared_library("windowstage_kit") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ "window_stage_napi/js_window_stage.cpp" ] diff --git a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp index 29c479182d..fdba0a407c 100644 --- a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp @@ -416,8 +416,8 @@ napi_value JsWindowManager::OnCreate(napi_env env, napi_callback_info info) return result; } -bool JsWindowManager::ParseConfigOption(napi_env env, napi_value jsObject, - WindowOption& option, void*& contextPtr) +bool JsWindowManager::ParseRequiredConfigOption(napi_env env, napi_value jsObject, + WindowOption& option) { std::string windowName; if (ParseJsValue(jsObject, env, "name", windowName)) { @@ -439,11 +439,18 @@ bool JsWindowManager::ParseConfigOption(napi_env env, napi_value jsObject, WLOGFE("Failed to convert parameter to winType"); return false; } + return true; +} +bool JsWindowManager::ParseConfigOption(napi_env env, napi_value jsObject, + WindowOption& option, void*& contextPtr) +{ + if (!ParseRequiredConfigOption(env, jsObject, option)) { + return false; + } if (!isConfigOptionWindowTypeValid(env, option)) { return false; } - napi_value value = nullptr; napi_get_named_property(env, jsObject, "ctx", &value); if (GetType(env, value) == napi_undefined) { @@ -455,6 +462,16 @@ bool JsWindowManager::ParseConfigOption(napi_env env, napi_value jsObject, return false; } + bool dialogDecorEnable = false; + if (ParseJsValue(jsObject, env, "decorEnable", dialogDecorEnable)) { + option.SetDialogDecorEnable(dialogDecorEnable); + } + + std::string dialogTitle; + if (ParseJsValue(jsObject, env, "title", dialogTitle)) { + option.SetDialogTitle(dialogTitle); + } + int64_t displayId = static_cast(DISPLAY_ID_INVALID); if (ParseJsValue(jsObject, env, "displayId", displayId)) { if (displayId < 0 || diff --git a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.h b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.h index 4df61b1fcc..5f5f5cb890 100644 --- a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.h +++ b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.h @@ -60,6 +60,8 @@ private: static napi_value OnSetGestureNavigationEnabled(napi_env env, napi_callback_info info); static napi_value OnSetWaterMarkImage(napi_env env, napi_callback_info info); static napi_value OnShiftAppWindowFocus(napi_env env, napi_callback_info info); + static bool ParseRequiredConfigOption( + napi_env env, napi_value jsObject, WindowOption& option); static bool ParseConfigOption( napi_env env, napi_value jsObject, WindowOption& option, void*& contextPtr); std::unique_ptr registerManager_ = nullptr; 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 68e6d2eda8..49745a9d58 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -50,6 +50,8 @@ namespace { constexpr size_t INDEX_ZERO = 0; constexpr size_t INDEX_ONE = 1; constexpr size_t INDEX_TWO = 2; + constexpr double MIN_GRAY_SCALE = 0.0; + constexpr double MAX_GRAY_SCALE = 1.0; } static thread_local std::map> g_jsWindowMap; @@ -815,6 +817,13 @@ napi_value JsWindow::SetWindowMask(napi_env env, napi_callback_info info) return (me != nullptr) ? me->OnSetWindowMask(env, info) : nullptr; } +napi_value JsWindow::SetWindowGrayScale(napi_env env, napi_callback_info info) +{ + WLOGI("[NAPI]SetWindowGrayScale"); + JsWindow* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnSetWindowGrayScale(env, info) : nullptr; +} + static void UpdateSystemBarProperties(std::map& systemBarProperties, const std::map& systemBarPropertyFlags, sptr windowToken) { @@ -1988,7 +1997,8 @@ napi_value JsWindow::OnSetFullScreen(napi_env env, napi_callback_info info) TLOGE(WmsLogTag::WMS_IMMS, "Failed to convert parameter to isFullScreen"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, nativeVal, &isFullScreen); + CHECK_NAPI_RETCODE(errCode, WMError::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &isFullScreen)); } } @@ -2038,7 +2048,8 @@ napi_value JsWindow::OnSetLayoutFullScreen(napi_env env, napi_callback_info info TLOGE(WmsLogTag::WMS_IMMS, "Failed to convert parameter to isLayoutFullScreen"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, nativeVal, &isLayoutFullScreen); + CHECK_NAPI_RETCODE(errCode, WMError::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &isLayoutFullScreen)); } } wptr weakToken(windowToken_); @@ -2087,7 +2098,8 @@ napi_value JsWindow::OnSetWindowLayoutFullScreen(napi_env env, napi_callback_inf TLOGE(WmsLogTag::WMS_IMMS, "Failed to convert parameter to isLayoutFullScreen"); errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, nativeVal, &isLayoutFullScreen); + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &isLayoutFullScreen)); } } if (errCode != WmErrorCode::WM_OK) { @@ -2519,7 +2531,8 @@ static void ParseAvoidAreaParam(napi_env env, napi_callback_info info, WMError& errCode = WMError::WM_ERROR_INVALID_PARAM; } else { uint32_t resultValue = 0; - napi_get_value_uint32(env, nativeMode, &resultValue); + CHECK_NAPI_RETCODE(errCode, WMError::WM_ERROR_INVALID_PARAM, + napi_get_value_uint32(env, nativeMode, &resultValue)); avoidAreaType = static_cast(resultValue); errCode = ((avoidAreaType > AvoidAreaType::TYPE_KEYBOARD) || (avoidAreaType < AvoidAreaType::TYPE_SYSTEM)) ? WMError::WM_ERROR_INVALID_PARAM : WMError::WM_OK; @@ -2592,7 +2605,8 @@ napi_value JsWindow::OnGetWindowAvoidAreaSync(napi_env env, napi_callback_info i errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } else { uint32_t resultValue = 0; - napi_get_value_uint32(env, nativeMode, &resultValue); + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_uint32(env, nativeMode, &resultValue)); avoidAreaType = static_cast(resultValue); errCode = ((avoidAreaType > AvoidAreaType::TYPE_NAVIGATION_INDICATOR) || (avoidAreaType < AvoidAreaType::TYPE_SYSTEM)) ? @@ -2932,7 +2946,8 @@ napi_value JsWindow::OnSetBrightness(napi_env env, napi_callback_info info) WLOGFE("Failed to convert parameter to brightness"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_double(env, nativeVal, &brightness); + CHECK_NAPI_RETCODE(errCode, WMError::WM_ERROR_INVALID_PARAM, + napi_get_value_double(env, nativeVal, &brightness)); } } @@ -2984,7 +2999,8 @@ napi_value JsWindow::OnSetWindowBrightness(napi_env env, napi_callback_info info WLOGFE("Failed to convert parameter to brightness"); errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_double(env, nativeVal, &brightness); + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_double(env, nativeVal, &brightness)); } } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { @@ -3052,7 +3068,8 @@ napi_value JsWindow::OnSetFocusable(napi_env env, napi_callback_info info) WLOGFE("Failed to convert parameter to focusable"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, nativeVal, &focusable); + CHECK_NAPI_RETCODE(errCode, WMError::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &focusable)); } } @@ -3103,7 +3120,8 @@ napi_value JsWindow::OnSetWindowFocusable(napi_env env, napi_callback_info info) WLOGFE("Failed to convert parameter to focusable"); errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, nativeVal, &focusable); + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &focusable)); } } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { @@ -3202,7 +3220,8 @@ napi_value JsWindow::OnSetKeepScreenOn(napi_env env, napi_callback_info info) WLOGFE("Failed to convert parameter to keepScreenOn"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, nativeVal, &keepScreenOn); + CHECK_NAPI_RETCODE(errCode, WMError::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &keepScreenOn)); } } @@ -3255,7 +3274,8 @@ napi_value JsWindow::OnSetWindowKeepScreenOn(napi_env env, napi_callback_info in WLOGFE("Failed to convert parameter to keepScreenOn"); errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, nativeVal, &keepScreenOn); + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &keepScreenOn)); } } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { @@ -3323,10 +3343,13 @@ napi_value JsWindow::OnSetWakeUpScreen(napi_env env, napi_callback_info info) WLOGFE("Failed to convert parameter to keepScreenOn"); return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); } else { - napi_get_value_bool(env, nativeVal, &wakeUp); + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &wakeUp)); } } - + if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } windowToken_->SetTurnScreenOn(wakeUp); WLOGI("Window [%{public}u, %{public}s] set wake up screen %{public}d end", windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), wakeUp); @@ -3367,7 +3390,8 @@ napi_value JsWindow::OnSetPrivacyMode(napi_env env, napi_callback_info info) WLOGFE("Failed to convert parameter to isPrivacyMode"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, nativeVal, &isPrivacyMode); + CHECK_NAPI_RETCODE(errCode, WMError::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &isPrivacyMode)); } } @@ -3415,7 +3439,8 @@ napi_value JsWindow::OnSetWindowPrivacyMode(napi_env env, napi_callback_info inf WLOGFE("Failed to convert parameter to isPrivacyMode"); errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, nativeVal, &isPrivacyMode); + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &isPrivacyMode)); } } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { @@ -3469,7 +3494,8 @@ napi_value JsWindow::OnSetTouchable(napi_env env, napi_callback_info info) WLOGFE("Failed to convert parameter to touchable"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, nativeVal, &touchable); + CHECK_NAPI_RETCODE(errCode, WMError::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &touchable)); } } @@ -3562,7 +3588,8 @@ napi_value JsWindow::OnSetResizeByDragEnabled(napi_env env, napi_callback_info i WLOGFE("Failed to convert parameter to dragEnabled"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, argv[0], &dragEnabled); + CHECK_NAPI_RETCODE(errCode, WMError::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, argv[0], &dragEnabled)); } } @@ -3616,10 +3643,11 @@ napi_value JsWindow::OnSetRaiseByClickEnabled(napi_env env, napi_callback_info i WLOGFE("Failed to convert parameter to raiseEnabled"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, argv[0], &raiseEnabled); + CHECK_NAPI_RETCODE(errCode, WMError::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, argv[0], &raiseEnabled)); } } - + wptr weakToken(windowToken_); NapiAsyncTask::CompleteCallback complete = [weakToken, raiseEnabled, errCode](napi_env env, NapiAsyncTask& task, int32_t status) { @@ -3787,7 +3815,8 @@ void GetSubWindowId(napi_env env, napi_value nativeVal, WmErrorCode &errCode, in errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } else { int32_t resultValue = 0; - napi_get_value_int32(env, nativeVal, &resultValue); + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_int32(env, nativeVal, &resultValue)); if (resultValue <= 0) { WLOGFE("Failed to get subWindowId due to resultValue less than or equal to 0"); errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; @@ -3859,7 +3888,12 @@ napi_value JsWindow::OnKeepKeyboardOnFocus(napi_env env, napi_callback_info info WLOGFE("Failed to get parameter keepKeyboardFlag"); return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); } else { - napi_get_value_bool(env, nativeVal, &keepKeyboardFlag); + WmErrorCode errCode = WmErrorCode::WM_OK; + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &keepKeyboardFlag)); + if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } } if (windowToken_ == nullptr) { @@ -3901,7 +3935,8 @@ napi_value JsWindow::OnSetWindowTouchable(napi_env env, napi_callback_info info) WLOGFE("Failed to convert parameter to touchable"); errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, nativeVal, &touchable); + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &touchable)); } } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { @@ -3953,7 +3988,8 @@ napi_value JsWindow::OnSetTransparent(napi_env env, napi_callback_info info) WLOGFE("Failed to convert parameter to isTransparent"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, nativeVal, &isTransparent); + CHECK_NAPI_RETCODE(errCode, WMError::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &isTransparent)); } } @@ -4071,7 +4107,8 @@ napi_value JsWindow::OnSetColorSpace(napi_env env, napi_callback_info info) WLOGFE("Failed to convert parameter to ColorSpace"); } else { uint32_t resultValue = 0; - napi_get_value_uint32(env, nativeType, &resultValue); + CHECK_NAPI_RETCODE(errCode, WMError::WM_ERROR_INVALID_PARAM, + napi_get_value_uint32(env, nativeType, &resultValue)); colorSpace = static_cast(resultValue); if (colorSpace > ColorSpace::COLOR_SPACE_WIDE_GAMUT || colorSpace < ColorSpace::COLOR_SPACE_DEFAULT) { WLOGFE("ColorSpace %{public}u invalid!", static_cast(colorSpace)); @@ -4125,7 +4162,8 @@ napi_value JsWindow::OnSetWindowColorSpace(napi_env env, napi_callback_info info WLOGFE("Failed to convert parameter to ColorSpace"); } else { uint32_t resultValue = 0; - napi_get_value_uint32(env, nativeType, &resultValue); + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_uint32(env, nativeType, &resultValue)); colorSpace = static_cast(resultValue); if (colorSpace > ColorSpace::COLOR_SPACE_WIDE_GAMUT || colorSpace < ColorSpace::COLOR_SPACE_DEFAULT) { WLOGFE("ColorSpace %{public}u invalid!", static_cast(colorSpace)); @@ -4262,7 +4300,8 @@ napi_value JsWindow::OnSetForbidSplitMove(napi_env env, napi_callback_info info) if (argv[0] == nullptr) { errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, argv[0], &isForbidSplitMove); + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, argv[0], &isForbidSplitMove)); } } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { @@ -4356,7 +4395,8 @@ napi_value JsWindow::OnSetSnapshotSkip(napi_env env, napi_callback_info info) if (nativeVal == nullptr) { errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_bool(env, nativeVal, &isSkip); + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &isSkip)); } } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { @@ -4437,7 +4477,12 @@ napi_value JsWindow::OnOpacity(napi_env env, napi_callback_info info) return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); } double alpha = 0.0; - napi_get_value_double(env, nativeVal, &alpha); + WmErrorCode errCode = WmErrorCode::WM_OK; + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_double(env, nativeVal, &alpha)); + if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } if (MathHelper::LessNotEqual(alpha, 0.0) || MathHelper::GreatNotEqual(alpha, 1.0)) { WLOGFE("alpha should greater than 0 or smaller than 1.0"); return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); @@ -4744,7 +4789,12 @@ napi_value JsWindow::OnSetCornerRadius(napi_env env, napi_callback_info info) return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); } double radius = 0.0; - napi_get_value_double(env, nativeVal, &radius); + WmErrorCode errCode = WmErrorCode::WM_OK; + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_double(env, nativeVal, &radius)); + if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } if (MathHelper::LessNotEqual(radius, 0.0)) { WLOGFE("SetCornerRadius invalid radius"); return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); @@ -4779,7 +4829,8 @@ napi_value JsWindow::OnSetShadow(napi_env env, napi_callback_info info) if (argv[0] == nullptr) { return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); } - napi_get_value_double(env, argv[0], &result); + CHECK_NAPI_RETCODE(ret, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_double(env, argv[0], &result)); if (MathHelper::LessNotEqual(result, 0.0)) { return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); } @@ -4835,7 +4886,12 @@ napi_value JsWindow::OnSetBlur(napi_env env, napi_callback_info info) return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); } double radius = 0.0; - napi_get_value_double(env, nativeVal, &radius); + WmErrorCode errCode = WmErrorCode::WM_OK; + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_double(env, nativeVal, &radius)); + if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } if (MathHelper::LessNotEqual(radius, 0.0)) { WLOGFE("SetBlur invalid radius"); return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); @@ -4873,7 +4929,12 @@ napi_value JsWindow::OnSetBackdropBlur(napi_env env, napi_callback_info info) return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); } double radius = 0.0; - napi_get_value_double(env, nativeVal, &radius); + WmErrorCode errCode = WmErrorCode::WM_OK; + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_double(env, nativeVal, &radius)); + if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } if (MathHelper::LessNotEqual(radius, 0.0)) { WLOGFE("SetBackdropBlur invalid radius"); return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); @@ -4912,7 +4973,12 @@ napi_value JsWindow::OnSetBackdropBlurStyle(napi_env env, napi_callback_info inf return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); } uint32_t resultValue = 0; - napi_get_value_uint32(env, nativeMode, &resultValue); + WmErrorCode errCode = WmErrorCode::WM_OK; + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_uint32(env, nativeMode, &resultValue)); + if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } if (resultValue > static_cast(WindowBlurStyle::WINDOW_BLUR_THICK)) { WLOGFE("SetBackdropBlurStyle Invalid window blur style"); return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); @@ -4946,7 +5012,10 @@ napi_value JsWindow::OnSetWaterMarkFlag(napi_env env, napi_callback_info info) } bool isAddSafetyLayer = false; - napi_get_value_bool(env, nativeBool, &isAddSafetyLayer); + napi_status statusCode = napi_get_value_bool(env, nativeBool, &isAddSafetyLayer); + if (statusCode != napi_ok) { + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } wptr weakToken(windowToken_); NapiAsyncTask::CompleteCallback complete = [weakToken, isAddSafetyLayer](napi_env env, NapiAsyncTask& task, int32_t status) { @@ -5058,7 +5127,8 @@ napi_value JsWindow::OnSetAspectRatio(napi_env env, napi_callback_info info) if (nativeVal == nullptr) { errCode = WMError::WM_ERROR_INVALID_PARAM; } else { - napi_get_value_double(env, nativeVal, &aspectRatio); + CHECK_NAPI_RETCODE(errCode, WMError::WM_ERROR_INVALID_PARAM, + napi_get_value_double(env, nativeVal, &aspectRatio)); } } @@ -5410,7 +5480,12 @@ napi_value JsWindow::OnSetWindowDecorVisible(napi_env env, napi_callback_info in return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); } bool isVisible = true; - napi_get_value_bool(env, nativeVal, &isVisible); + WmErrorCode errCode = WmErrorCode::WM_OK; + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_bool(env, nativeVal, &isVisible)); + if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->SetDecorVisible(isVisible)); if (ret != WmErrorCode::WM_OK) { WLOGFE("Window decor set visible failed"); @@ -5495,7 +5570,13 @@ napi_value JsWindow::OnSetWindowDecorHeight(napi_env env, napi_callback_info inf return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); } int32_t height = 0; - napi_get_value_int32(env, nativeVal, &height); + WmErrorCode errCode = WmErrorCode::WM_OK; + CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, + napi_get_value_int32(env, nativeVal, &height)); + if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } + if (height < MIN_DECOR_HEIGHT || height > MAX_DECOR_HEIGHT) { WLOGFE("height should greater than 37 or smaller than 112"); return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); @@ -5643,6 +5724,52 @@ napi_value JsWindow::OnSetWindowMask(napi_env env, napi_callback_info info) return result; } +napi_value JsWindow::OnSetWindowGrayScale(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) { // 1: the param num + WLOGFE("Argc is invalid: %{public}zu", argc); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } + napi_value nativeVal = argv[0]; + if (nativeVal == nullptr) { + WLOGFE("Failed to convert parameter to grayScale"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } + double grayScale = 0.0; + napi_get_value_double(env, nativeVal, &grayScale); + constexpr double eps = 1e-6; + if (grayScale < (MIN_GRAY_SCALE - eps) || grayScale > (MAX_GRAY_SCALE + eps)) { + WLOGFE("grayScale should be greater than or equal to 0.0, and should be smaller than or equal to 1.0"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } + + wptr weakToken(windowToken_); + NapiAsyncTask::CompleteCallback complete = + [weakToken, grayScale](napi_env env, NapiAsyncTask& task, int32_t status) { + auto window = weakToken.promote(); + if (window == nullptr) { + WLOGFE("window is nullptr"); + task.Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY))); + return; + } + WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->SetGrayScale(static_cast(grayScale))); + if (ret == WmErrorCode::WM_OK) { + task.Resolve(env, NapiGetUndefined(env)); + } else { + task.Reject(env, CreateJsError(env, static_cast(ret), "Set window gray scale failed")); + } + WLOGI("Window [%{public}u, %{public}s] OnSetWindowGrayScale end, grayScale = %{public}f", + window->GetWindowId(), window->GetWindowName().c_str(), grayScale); + }; + napi_value result = nullptr; + NapiAsyncTask::Schedule("JsWindow::OnSetWindowGrayScale", + env, CreateAsyncTaskWithLastParam(env, nullptr, nullptr, std::move(complete), &result)); + return result; +} + void BindFunctions(napi_env env, napi_value object, const char *moduleName) { BindNativeFunction(env, object, "show", moduleName, JsWindow::Show); @@ -5751,6 +5878,7 @@ void BindFunctions(napi_env env, napi_value object, const char *moduleName) BindNativeFunction(env, object, "getTitleButtonRect", moduleName, JsWindow::GetTitleButtonRect); BindNativeFunction(env, object, "setTitleButtonVisible", moduleName, JsWindow::SetTitleButtonVisible); BindNativeFunction(env, object, "setWindowMask", moduleName, JsWindow::SetWindowMask); + BindNativeFunction(env, object, "setWindowGrayScale", moduleName, JsWindow::SetWindowGrayScale); } } // 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 627530cdfd..5b1e070f3d 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.h @@ -151,6 +151,7 @@ public: static napi_value GetTitleButtonRect(napi_env env, napi_callback_info info); 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); private: std::string GetWindowName(); @@ -269,6 +270,7 @@ private: napi_value OnSetWaterMarkFlag(napi_env env, napi_callback_info info); napi_value OnSetWindowMask(napi_env env, napi_callback_info info); napi_value OnSetHandwritingFlag(napi_env env, napi_callback_info info); + napi_value OnSetWindowGrayScale(napi_env env, napi_callback_info info); sptr windowToken_ = nullptr; std::unique_ptr registerManager_ = nullptr; diff --git a/interfaces/kits/napi/window_runtime/window_stage_napi/BUILD.gn b/interfaces/kits/napi/window_runtime/window_stage_napi/BUILD.gn index b84b998fa0..33c6c4fc15 100644 --- a/interfaces/kits/napi/window_runtime/window_stage_napi/BUILD.gn +++ b/interfaces/kits/napi/window_runtime/window_stage_napi/BUILD.gn @@ -39,6 +39,7 @@ ohos_shared_library("windowstage") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ "window_stage_module.cpp" ] diff --git a/previewer/include/window.h b/previewer/include/window.h index 2bb4de3169..d0a6150817 100644 --- a/previewer/include/window.h +++ b/previewer/include/window.h @@ -327,6 +327,8 @@ public: { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } + + virtual WMError SetGrayScale(float grayScale) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } }; } } diff --git a/snapshot/BUILD.gn b/snapshot/BUILD.gn index c4dae2a9bd..6ec3b73893 100644 --- a/snapshot/BUILD.gn +++ b/snapshot/BUILD.gn @@ -24,6 +24,7 @@ ohos_executable("snapshot_display") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } install_enable = true @@ -53,6 +54,7 @@ ohos_shared_library("libsnapshot_util") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ "src/snapshot_utils.cpp" ] diff --git a/test/fuzztest/wms/window_fuzzer/window_fuzzer.cpp b/test/fuzztest/wms/window_fuzzer/window_fuzzer.cpp index 0ae1254b04..35692f5912 100644 --- a/test/fuzztest/wms/window_fuzzer/window_fuzzer.cpp +++ b/test/fuzztest/wms/window_fuzzer/window_fuzzer.cpp @@ -380,6 +380,10 @@ void CheckWindowImplFunctionsPart1(sptr window, const uint8_t* data, siz startPos += GetObject(boolVal, data + startPos, size - startPos); window->UpdateSurfaceNodeAfterCustomAnimation(boolVal); + + float grayScale; + startPos += GetObject(grayScale, data + startPos, size - startPos); + window->SetGrayScale(grayScale); } void CheckWindowImplFunctionsPart2(sptr window, const uint8_t* data, size_t size) diff --git a/test/systemtest/wms/window_effect_test.cpp b/test/systemtest/wms/window_effect_test.cpp index 86d23d931c..65f1c536ac 100644 --- a/test/systemtest/wms/window_effect_test.cpp +++ b/test/systemtest/wms/window_effect_test.cpp @@ -191,8 +191,6 @@ HWTEST_F(WindowEffectTest, WindowEffect07, Function | MediumTest | Level3) ASSERT_NE(nullptr, window); ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_OFF)); - ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_REGULAR)); - ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THICK)); ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast(-1))); ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast(5))); @@ -208,12 +206,13 @@ HWTEST_F(WindowEffectTest, WindowEffect07, Function | MediumTest | Level3) HWTEST_F(WindowEffectTest, WindowEffect08, Function | MediumTest | Level3) { const sptr &window = Utils::CreateTestWindow(windowInfo_); - ASSERT_NE(nullptr, window); + WindowAccessibilityController::GetInstance().OffWindowZoom(); sleep(1); WindowAccessibilityController::GetInstance().SetAnchorAndScale(0, 0, 2); sleep(1); WindowAccessibilityController::GetInstance().SetAnchorOffset(-100, -100); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); } } // namespace diff --git a/test/systemtest/wms/window_layout_test.cpp b/test/systemtest/wms/window_layout_test.cpp index bc66b1cf27..4783e6efed 100644 --- a/test/systemtest/wms/window_layout_test.cpp +++ b/test/systemtest/wms/window_layout_test.cpp @@ -116,10 +116,6 @@ void WindowLayoutTest::SetUp() void WindowLayoutTest::TearDown() { - while (!activeWindows_.empty()) { - ASSERT_EQ(WMError::WM_OK, activeWindows_.back()->Destroy()); - activeWindows_.pop_back(); - } } namespace { diff --git a/test/systemtest/wms/window_move_drag_test.cpp b/test/systemtest/wms/window_move_drag_test.cpp index 4590cf1023..4895f6ac38 100755 --- a/test/systemtest/wms/window_move_drag_test.cpp +++ b/test/systemtest/wms/window_move_drag_test.cpp @@ -71,7 +71,9 @@ void WindowMoveDragTest::TearDownTestCase() void WindowMoveDragTest::SetUp() { auto display = DisplayManager::GetInstance().GetDisplayById(0); - ASSERT_TRUE((display != nullptr)); + if (display == nullptr) { + return; + } WLOGI("GetDefaultDisplay: id %{public}llu, w %{public}d, h %{public}d, fps %{public}u\n", (unsigned long long)display->GetId(), display->GetWidth(), display->GetHeight(), display->GetRefreshRate()); Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; @@ -144,6 +146,9 @@ namespace { */ HWTEST_F(WindowMoveDragTest, DragWindow01, Function | MediumTest | Level3) { + if (window_ == nullptr) { + return; + } ASSERT_EQ(WMError::WM_OK, window_->Show()); usleep(WAIT_SYANC_MS); startPointRect_ = window_->GetRect(); @@ -162,6 +167,9 @@ HWTEST_F(WindowMoveDragTest, DragWindow01, Function | MediumTest | Level3) */ HWTEST_F(WindowMoveDragTest, DragWindow02, Function | MediumTest | Level3) { + if (window_ == nullptr) { + return; + } ASSERT_EQ(WMError::WM_OK, window_->Show()); usleep(WAIT_SYANC_MS); startPointRect_ = window_->GetRect(); @@ -180,6 +188,9 @@ HWTEST_F(WindowMoveDragTest, DragWindow02, Function | MediumTest | Level3) */ HWTEST_F(WindowMoveDragTest, DragWindow03, Function | MediumTest | Level3) { + if (window_ == nullptr) { + return; + } ASSERT_EQ(WMError::WM_OK, window_->Show()); usleep(WAIT_SYANC_MS); startPointRect_ = window_->GetRect(); @@ -199,6 +210,9 @@ HWTEST_F(WindowMoveDragTest, DragWindow03, Function | MediumTest | Level3) */ HWTEST_F(WindowMoveDragTest, DragWindow04, Function | MediumTest | Level3) { + if (window_ == nullptr) { + return; + } ASSERT_EQ(WMError::WM_OK, window_->Show()); usleep(WAIT_SYANC_MS); startPointRect_ = window_->GetRect(); @@ -218,6 +232,9 @@ HWTEST_F(WindowMoveDragTest, DragWindow04, Function | MediumTest | Level3) */ HWTEST_F(WindowMoveDragTest, DragWindow05, Function | MediumTest | Level3) { + if (window_ == nullptr) { + return; + } ASSERT_EQ(WMError::WM_OK, window_->Show()); usleep(WAIT_SYANC_MS); startPointRect_ = window_->GetRect(); @@ -236,6 +253,9 @@ HWTEST_F(WindowMoveDragTest, DragWindow05, Function | MediumTest | Level3) */ HWTEST_F(WindowMoveDragTest, DragWindow06, Function | MediumTest | Level3) { + if (window_ == nullptr) { + return; + } ASSERT_EQ(WMError::WM_OK, window_->Show()); usleep(WAIT_SYANC_MS); startPointRect_ = window_->GetRect(); @@ -255,6 +275,9 @@ HWTEST_F(WindowMoveDragTest, DragWindow06, Function | MediumTest | Level3) */ HWTEST_F(WindowMoveDragTest, DragWindow07, Function | MediumTest | Level3) { + if (window_ == nullptr) { + return; + } ASSERT_EQ(WMError::WM_OK, window_->Show()); usleep(WAIT_SYANC_MS); startPointRect_ = window_->GetRect(); @@ -272,6 +295,9 @@ HWTEST_F(WindowMoveDragTest, DragWindow07, Function | MediumTest | Level3) */ HWTEST_F(WindowMoveDragTest, DragWindow08, Function | MediumTest | Level3) { + if (window_ == nullptr) { + return; + } ASSERT_EQ(WMError::WM_OK, window_->Show()); usleep(WAIT_SYANC_MS); startPointRect_ = window_->GetRect(); @@ -290,6 +316,9 @@ HWTEST_F(WindowMoveDragTest, DragWindow08, Function | MediumTest | Level3) */ HWTEST_F(WindowMoveDragTest, DragWindow09, Function | MediumTest | Level3) { + if (window_ == nullptr) { + return; + } ASSERT_EQ(WMError::WM_OK, window_->Show()); usleep(WAIT_SYANC_MS); startPointRect_ = window_->GetRect(); @@ -308,6 +337,9 @@ HWTEST_F(WindowMoveDragTest, DragWindow09, Function | MediumTest | Level3) */ HWTEST_F(WindowMoveDragTest, DragWindow10, Function | MediumTest | Level3) { + if (window_ == nullptr) { + return; + } ASSERT_EQ(WMError::WM_OK, window_->Show()); usleep(WAIT_SYANC_MS); startPointRect_ = window_->GetRect(); diff --git a/test/systemtest/wms/window_split_test.cpp b/test/systemtest/wms/window_split_test.cpp index b44b155905..00454dae57 100644 --- a/test/systemtest/wms/window_split_test.cpp +++ b/test/systemtest/wms/window_split_test.cpp @@ -174,8 +174,6 @@ HWTEST_F(WindowSplitTest, SplitScreen03, Function | MediumTest | Level3) splitInfo_.name = "primary.3"; splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY; - ASSERT_FALSE(Utils::InitSplitRects()); - const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); if (fullWindow == nullptr) { return; @@ -210,8 +208,6 @@ HWTEST_F(WindowSplitTest, SplitScreen04, Function | MediumTest | Level3) splitInfo_.name = "secondary.4"; splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY; - ASSERT_FALSE(Utils::InitSplitRects()); - const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); if (fullWindow == nullptr) { return; diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 9b46f579d4..7f6e77de56 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -35,6 +35,7 @@ ohos_static_library("libwmutil_static") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false integer_overflow = true ubsan = true @@ -108,6 +109,7 @@ ohos_shared_library("libwmutil_base") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ diff --git a/utils/src/accessibility_window_info.cpp b/utils/src/accessibility_window_info.cpp index 909c37e67f..60a7f9dc4e 100644 --- a/utils/src/accessibility_window_info.cpp +++ b/utils/src/accessibility_window_info.cpp @@ -24,13 +24,27 @@ namespace OHOS { namespace Rosen { bool AccessibilityWindowInfo::Marshalling(Parcel& parcel) const { - return parcel.WriteInt32(wid_) && parcel.WriteInt32(innerWid_) && parcel.WriteInt32(uiNodeId_) && + auto touchHotAreas = touchHotAreas_; + bool res = parcel.WriteInt32(wid_) && parcel.WriteInt32(innerWid_) && parcel.WriteInt32(uiNodeId_) && parcel.WriteUint32(windowRect_.width_) && parcel.WriteUint32(windowRect_.height_) && parcel.WriteInt32(windowRect_.posX_) && parcel.WriteInt32(windowRect_.posY_) && parcel.WriteBool(focused_) && parcel.WriteBool(isDecorEnable_) && parcel.WriteUint64(displayId_) && parcel.WriteUint32(layer_) && parcel.WriteFloat(scaleVal_) && parcel.WriteFloat(scaleX_) && parcel.WriteFloat(scaleY_) && - parcel.WriteUint32(static_cast(mode_)) && parcel.WriteUint32(static_cast(type_)); + parcel.WriteUint32(static_cast(mode_)) && parcel.WriteUint32(static_cast(type_)) && + parcel.WriteString(bundleName_) && parcel.WriteUint32(touchHotAreas.size()); + if (!res) { + return false; + } + + for (const auto& rect : touchHotAreas) { + res = parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) && + parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_); + if (!res) { + return false; + } + } + return res; } AccessibilityWindowInfo* AccessibilityWindowInfo::Unmarshalling(Parcel& parcel) @@ -52,6 +66,12 @@ AccessibilityWindowInfo* AccessibilityWindowInfo::Unmarshalling(Parcel& parcel) } info->mode_ = static_cast(parcel.ReadUint32()); info->type_ = static_cast(parcel.ReadUint32()); + info->bundleName_ = parcel.ReadString(); + size_t touchHotAreasCnt = parcel.ReadUint32(); + for (size_t i = 0; i < touchHotAreasCnt; i++) { + info->touchHotAreas_.push_back({.posX_ = parcel.ReadInt32(), .posY_ = parcel.ReadInt32(), + .width_ = parcel.ReadUint32(), .height_ = parcel.ReadUint32()}); + } return info; } } diff --git a/window_scene/common/BUILD.gn b/window_scene/common/BUILD.gn index 53142271f4..1d9e1fd6b6 100644 --- a/window_scene/common/BUILD.gn +++ b/window_scene/common/BUILD.gn @@ -32,6 +32,7 @@ ohos_shared_library("window_scene_common") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ diff --git a/window_scene/common/include/window_session_property.h b/window_scene/common/include/window_session_property.h index 10b2fae8fa..cccfad9c6a 100755 --- a/window_scene/common/include/window_session_property.h +++ b/window_scene/common/include/window_session_property.h @@ -150,6 +150,8 @@ public: void SetSessionPropertyChangeCallback(std::function&& callback); bool IsLayoutFullScreen() const; void SetIsLayoutFullScreen(bool isLayoutFullScreen); + int32_t GetCollaboratorType() const; + void SetCollaboratorType(int32_t collaboratorType); private: bool MarshallingTouchHotAreas(Parcel& parcel) const; @@ -211,6 +213,7 @@ private: bool isShaped_ = false; sptr windowMask_ = nullptr; + int32_t collaboratorType_ = CollaboratorType::DEFAULT_TYPE; }; struct FreeMultiWindowConfig : public Parcelable { diff --git a/window_scene/common/src/window_session_property.cpp b/window_scene/common/src/window_session_property.cpp index be697e1d1c..f117e6a42e 100755 --- a/window_scene/common/src/window_session_property.cpp +++ b/window_scene/common/src/window_session_property.cpp @@ -810,5 +810,15 @@ bool WindowSessionProperty::GetIsShaped() const { return isShaped_; } + +int32_t WindowSessionProperty::GetCollaboratorType() const +{ + return collaboratorType_; +} + +void WindowSessionProperty::SetCollaboratorType(int32_t collaboratorType) +{ + collaboratorType_ = collaboratorType; +} } // namespace Rosen } // namespace OHOS diff --git a/window_scene/intention_event/BUILD.gn b/window_scene/intention_event/BUILD.gn index daebc1c39e..5e4bfcda5a 100644 --- a/window_scene/intention_event/BUILD.gn +++ b/window_scene/intention_event/BUILD.gn @@ -19,6 +19,7 @@ ohos_shared_library("libintention_event") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } include_dirs = [ @@ -43,6 +44,7 @@ ohos_shared_library("libintention_event") { "ace_engine:ace_uicontent", "c_utils:utils", "eventhandler:libeventhandler", + "ffrt:libffrt", "graphic_2d:libcomposer", "graphic_2d:window_animation", "hilog:libhilog", diff --git a/window_scene/intention_event/include/intention_event_manager.h b/window_scene/intention_event/include/intention_event_manager.h index cfbcd4879d..ed3da1cb48 100644 --- a/window_scene/intention_event/include/intention_event_manager.h +++ b/window_scene/intention_event/include/intention_event_manager.h @@ -50,7 +50,7 @@ private: void DispatchKeyEventCallback( int32_t focusedSessionId, std::shared_ptr keyEvent, bool consumed) const; void UpdateLastMouseEvent(std::shared_ptr pointerEvent) const; - bool CheckPointerEvent(const std::shared_ptr pointerEvent) const; + bool UpdatePointerEvent(std::shared_ptr pointerEvent) const; void ProcessEnterLeaveEventAsync(); bool IsKeyboardEvent(const std::shared_ptr& keyEvent) const; Ace::UIContent* uiContent_ = nullptr; diff --git a/window_scene/intention_event/service/BUILD.gn b/window_scene/intention_event/service/BUILD.gn index 3a6330b377..3e44cb4dc8 100644 --- a/window_scene/intention_event/service/BUILD.gn +++ b/window_scene/intention_event/service/BUILD.gn @@ -35,6 +35,7 @@ ohos_shared_library("intention_event_anr_manager") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ diff --git a/window_scene/intention_event/service/anr_manager/include/anr_manager.h b/window_scene/intention_event/service/anr_manager/include/anr_manager.h index 7e0bf439ae..21bc23dcb4 100644 --- a/window_scene/intention_event/service/anr_manager/include/anr_manager.h +++ b/window_scene/intention_event/service/anr_manager/include/anr_manager.h @@ -18,7 +18,6 @@ #include #include -#include #include #include @@ -60,7 +59,6 @@ private: std::atomic_int32_t anrTimerCount_ { 0 }; std::mutex mtx_; std::unordered_map applicationMap_; - std::shared_mutex applicationMapMutex_; std::function anrObserver_; std::function appInfoGetter_; }; diff --git a/window_scene/intention_event/service/anr_manager/src/anr_manager.cpp b/window_scene/intention_event/service/anr_manager/src/anr_manager.cpp index 3f6c06042a..c34d5e8c12 100644 --- a/window_scene/intention_event/service/anr_manager/src/anr_manager.cpp +++ b/window_scene/intention_event/service/anr_manager/src/anr_manager.cpp @@ -93,7 +93,7 @@ void ANRManager::MarkProcessed(int32_t eventId, int32_t persistentId) bool ANRManager::IsANRTriggered(int32_t persistentId) { - std::shared_lock lock(applicationMapMutex_); + std::lock_guard guard(mtx_); if (DelayedSingleton::GetInstance()->CheckAnrStatus(persistentId)) { WLOGFE("Application not respond, persistentId:%{public}d -> pid:%{public}d, bundleName:%{public}s", persistentId, applicationMap_[persistentId].pid, applicationMap_[persistentId].bundleName.c_str()); @@ -105,13 +105,9 @@ bool ANRManager::IsANRTriggered(int32_t persistentId) void ANRManager::OnSessionLost(int32_t persistentId) { CALL_DEBUG_ENTER; - { - std::shared_lock lock(applicationMapMutex_); - if (applicationMap_.find(persistentId) != applicationMap_.end()) { - WLOGFD("Disconnect session, persistentId:%{public}d -> pid:%{public}d, bundleName:%{public}s", persistentId, - applicationMap_[persistentId].pid, applicationMap_[persistentId].bundleName.c_str()); - } - } + std::lock_guard guard(mtx_); + WLOGFD("Disconnect session, persistentId:%{public}d -> pid:%{public}d, bundleName:%{public}s", + persistentId, applicationMap_[persistentId].pid, applicationMap_[persistentId].bundleName.c_str()); RemoveTimers(persistentId); RemovePersistentId(persistentId); } @@ -119,20 +115,16 @@ void ANRManager::OnSessionLost(int32_t persistentId) void ANRManager::OnBackground(int32_t persistentId) { CALL_DEBUG_ENTER; - { - std::shared_lock lock(applicationMapMutex_); - if (applicationMap_.find(persistentId) != applicationMap_.end()) { - WLOGFD("Background session, persistentId:%{public}d -> pid:%{public}d, bundleName:%{public}s", persistentId, - applicationMap_[persistentId].pid, applicationMap_[persistentId].bundleName.c_str()); - } - } + std::lock_guard guard(mtx_); + WLOGFD("Background session, persistentId:%{public}d -> pid:%{public}d, bundleName:%{public}s", + persistentId, applicationMap_[persistentId].pid, applicationMap_[persistentId].bundleName.c_str()); RemoveTimers(persistentId); RemovePersistentId(persistentId); } void ANRManager::SetApplicationInfo(int32_t persistentId, int32_t pid, const std::string& bundleName) { - std::unique_lock lock(applicationMapMutex_); + std::lock_guard guard(mtx_); WLOGFD("PersistentId:%{public}d -> pid:%{public}d, bundleName:%{public}s", persistentId, pid, bundleName.c_str()); applicationMap_[persistentId] = { pid, bundleName }; @@ -148,13 +140,10 @@ void ANRManager::SetAnrObserver(std::function anrObserver) ANRManager::AppInfo ANRManager::GetAppInfoByPersistentId(int32_t persistentId) { - { - std::shared_lock lock(applicationMapMutex_); - if (applicationMap_.find(persistentId) != applicationMap_.end()) { - WLOGFD("PersistentId:%{public}d -> pid:%{public}d, bundleName:%{public}s", - persistentId, applicationMap_[persistentId].pid, applicationMap_[persistentId].bundleName.c_str()); - return applicationMap_[persistentId]; - } + if (applicationMap_.find(persistentId) != applicationMap_.end()) { + WLOGFD("PersistentId:%{public}d -> pid:%{public}d, bundleName:%{public}s", + persistentId, applicationMap_[persistentId].pid, applicationMap_[persistentId].bundleName.c_str()); + return applicationMap_[persistentId]; } WLOGFD("No application matches persistentId:%{public}d", persistentId); return ANRManager::AppInfo(); @@ -173,10 +162,7 @@ void ANRManager::RemoveTimers(int32_t persistentId) void ANRManager::RemovePersistentId(int32_t persistentId) { WLOGFD("RemovePersistentId:%{public}d", persistentId); - { - std::unique_lock lock(applicationMapMutex_); - applicationMap_.erase(persistentId); - } + applicationMap_.erase(persistentId); DelayedSingleton::GetInstance()->OnSessionLost(persistentId); } diff --git a/window_scene/intention_event/src/intention_event_manager.cpp b/window_scene/intention_event/src/intention_event_manager.cpp index 0baaaba66a..9f6c1a7f6a 100644 --- a/window_scene/intention_event/src/intention_event_manager.cpp +++ b/window_scene/intention_event/src/intention_event_manager.cpp @@ -169,8 +169,8 @@ void IntentionEventManager::InputEventListener::UpdateLastMouseEvent( } } -bool IntentionEventManager::InputEventListener::CheckPointerEvent( - const std::shared_ptr pointerEvent) const +bool IntentionEventManager::InputEventListener::UpdatePointerEvent( + std::shared_ptr pointerEvent) const { if (pointerEvent == nullptr) { TLOGE(WmsLogTag::WMS_EVENT, "pointerEvent is null"); @@ -186,13 +186,23 @@ bool IntentionEventManager::InputEventListener::CheckPointerEvent( pointerEvent->MarkProcessed(); return false; } + auto dispatchTimes = pointerEvent->GetDispatchTimes(); + if (dispatchTimes > 0) { + MMI::PointerEvent::PointerItem pointerItem; + auto pointerId = pointerEvent->GetPointerId(); + if (pointerEvent->GetPointerItem(pointerId, pointerItem)) { + pointerItem.SetPointerId(pointerId + dispatchTimes * TRANSPARENT_FINGER_ID); + pointerEvent->UpdatePointerItem(pointerId, pointerItem); + pointerEvent->SetPointerId(pointerId + dispatchTimes * TRANSPARENT_FINGER_ID); + } + } return true; } void IntentionEventManager::InputEventListener::OnInputEvent( std::shared_ptr pointerEvent) const { - if (!CheckPointerEvent(pointerEvent)) { + if (!UpdatePointerEvent(pointerEvent)) { return; } LogPointInfo(pointerEvent); @@ -204,14 +214,11 @@ void IntentionEventManager::InputEventListener::OnInputEvent( pointerEvent->MarkProcessed(); return; } - auto dispatchTimes = pointerEvent->GetDispatchTimes(); - if (dispatchTimes > 0) { - MMI::PointerEvent::PointerItem pointerItem; - auto pointerId = pointerEvent->GetPointerId(); - if (pointerEvent->GetPointerItem(pointerId, pointerItem)) { - pointerItem.SetPointerId(pointerId + dispatchTimes * TRANSPARENT_FINGER_ID); - pointerEvent->UpdatePointerItem(pointerId, pointerItem); - pointerEvent->SetPointerId(pointerId + dispatchTimes * TRANSPARENT_FINGER_ID); + if (action == MMI::PointerEvent::POINTER_ACTION_DOWN || + action == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN) { + if (sceneSession->GetSessionInfo().bundleName_.find("SCBGestureBack") != std::string::npos || + sceneSession->GetSessionInfo().bundleName_.find("SCBGestureNavBar") != std::string::npos) { + SceneSessionManager::GetInstance().UpdateLastDownEventDeviceId(pointerEvent->GetDeviceId()); } } if (action != MMI::PointerEvent::POINTER_ACTION_MOVE) { diff --git a/window_scene/interfaces/include/ws_common.h b/window_scene/interfaces/include/ws_common.h index 5ca5d2ef10..1c28989aae 100644 --- a/window_scene/interfaces/include/ws_common.h +++ b/window_scene/interfaces/include/ws_common.h @@ -394,6 +394,12 @@ struct StartingWindowAnimationConfig { float opacityEnd_ = 0; }; +struct SystemUIStatusBarConfig { + bool showInLandscapeMode_ = false; + std::string immersiveStatusBarBgColor_ = "#4c000000"; + std::string immersiveStatusBarContentColor_ = "#ffffff"; +}; + struct AppWindowSceneConfig { float floatCornerRadius_ = 0.0f; @@ -403,6 +409,7 @@ struct AppWindowSceneConfig { KeyboardSceneAnimationConfig keyboardAnimationOut_; WindowAnimationConfig windowAnimation_; StartingWindowAnimationConfig startingWindowAnimationConfig_; + SystemUIStatusBarConfig systemUIStatusBarConfig_; }; struct DeviceScreenConfig { diff --git a/window_scene/interfaces/innerkits/BUILD.gn b/window_scene/interfaces/innerkits/BUILD.gn index ec9af45731..8fa9ccd45a 100644 --- a/window_scene/interfaces/innerkits/BUILD.gn +++ b/window_scene/interfaces/innerkits/BUILD.gn @@ -24,6 +24,7 @@ ohos_shared_library("libwsutils") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ "src/scene_board_judgement.cpp" ] diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/BUILD.gn b/window_scene/interfaces/kits/napi/scene_session_manager/BUILD.gn index f37dde5ed5..cf66747b7e 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/BUILD.gn +++ b/window_scene/interfaces/kits/napi/scene_session_manager/BUILD.gn @@ -24,6 +24,7 @@ ohos_shared_library("scenesessionmanager_napi") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ @@ -57,6 +58,7 @@ ohos_shared_library("scenesessionmanager_napi") { "ace_engine:ace_uicontent", "c_utils:utils", "eventhandler:libeventhandler", + "ffrt:libffrt", "graphic_2d:librender_service_client", "hilog:libhilog", "hitrace:hitrace_meter", diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_root_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_root_scene_session.cpp index 75b1a14778..5dd827ddab 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_root_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_root_scene_session.cpp @@ -213,6 +213,7 @@ void JsRootSceneSession::PendingSessionActivationInner(std::shared_ptrsecond; @@ -250,7 +251,7 @@ void JsRootSceneSession::PendingSessionActivation(SessionInfo& info) TLOGE(WmsLogTag::WMS_LIFE, "sceneSession is nullptr"); return; } - + if (info.want != nullptr) { bool isNeedBackToOther = info.want->GetBoolParam(AAFwk::Want::PARAM_BACK_TO_OTHER_MISSION_STACK, false); TLOGI(WmsLogTag::WMS_LIFE, "[NAPI]session: %{public}d isNeedBackToOther: %{public}d", diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp index f6220b3ec9..bcf75fb69e 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp @@ -49,14 +49,14 @@ const std::string SYSTEMBAR_PROPERTY_CHANGE_CB = "systemBarPropertyChange"; const std::string NEED_AVOID_CB = "needAvoid"; const std::string PENDING_SESSION_TO_FOREGROUND_CB = "pendingSessionToForeground"; const std::string PENDING_SESSION_TO_BACKGROUND_FOR_DELEGATOR_CB = "pendingSessionToBackgroundForDelegator"; -const std::string NEED_DEFAULT_ANIMATION_FLAG_CHANGE_CB = "needDefaultAnimationFlagChange"; const std::string CUSTOM_ANIMATION_PLAYING_CB = "isCustomAnimationPlaying"; +const std::string NEED_DEFAULT_ANIMATION_FLAG_CHANGE_CB = "needDefaultAnimationFlagChange"; const std::string SHOW_WHEN_LOCKED_CB = "sessionShowWhenLockedChange"; const std::string REQUESTED_ORIENTATION_CHANGE_CB = "sessionRequestedOrientationChange"; const std::string RAISE_ABOVE_TARGET_CB = "raiseAboveTarget"; const std::string FORCE_HIDE_CHANGE_CB = "sessionForceHideChange"; -const std::string TOUCH_OUTSIDE_CB = "touchOutside"; const std::string WINDOW_DRAG_HOT_AREA_CB = "windowDragHotArea"; +const std::string TOUCH_OUTSIDE_CB = "touchOutside"; const std::string SESSIONINFO_LOCKEDSTATE_CHANGE_CB = "sessionInfoLockedStateChange"; const std::string PREPARE_CLOSE_PIP_SESSION = "prepareClosePiPSession"; const std::string LANDSCAPE_MULTI_WINDOW_CB = "landscapeMultiWindow"; @@ -110,6 +110,8 @@ napi_value JsSceneSession::Create(napi_env env, const sptr& sessio CreateJsValue(env, static_cast(GetApiType(session->GetWindowType())))); napi_set_named_property(env, objValue, "isAppType", CreateJsValue(env, session->IsFloatingWindowAppType())); napi_set_named_property(env, objValue, "pipTemplateInfo", CreatePipTemplateInfo(env, session)); + napi_set_named_property(env, objValue, "keyboardGravity", + CreateJsValue(env, static_cast(session->GetKeyboardGravity()))); const char* moduleName = "JsSceneSession"; BindNativeFunction(env, objValue, "on", moduleName, JsSceneSession::RegisterCallback); @@ -119,17 +121,19 @@ napi_value JsSceneSession::Create(napi_env env, const sptr& sessio BindNativeFunction(env, objValue, "setTouchable", moduleName, JsSceneSession::SetTouchable); BindNativeFunction(env, objValue, "setSystemActive", moduleName, JsSceneSession::SetSystemActive); BindNativeFunction(env, objValue, "setPrivacyMode", moduleName, JsSceneSession::SetPrivacyMode); + BindNativeFunction(env, objValue, "setSystemSceneOcclusionAlpha", + moduleName, JsSceneSession::SetSystemSceneOcclusionAlpha); BindNativeFunction(env, objValue, "setFloatingScale", moduleName, JsSceneSession::SetFloatingScale); - BindNativeFunction(env, objValue, "setSystemSceneOcclusionAlpha", moduleName, - JsSceneSession::SetSystemSceneOcclusionAlpha); BindNativeFunction(env, objValue, "setFocusable", moduleName, JsSceneSession::SetFocusable); BindNativeFunction(env, objValue, "setSystemSceneBlockingFocus", moduleName, JsSceneSession::SetSystemSceneBlockingFocus); - BindNativeFunction(env, objValue, "setSCBKeepKeyboard", moduleName, JsSceneSession::SetSCBKeepKeyboard); - BindNativeFunction(env, objValue, "setOffset", moduleName, JsSceneSession::SetOffset); BindNativeFunction(env, objValue, "setScale", moduleName, JsSceneSession::SetScale); BindNativeFunction(env, objValue, "requestHideKeyboard", moduleName, JsSceneSession::RequestHideKeyboard); + BindNativeFunction(env, objValue, "setSCBKeepKeyboard", moduleName, JsSceneSession::SetSCBKeepKeyboard); + BindNativeFunction(env, objValue, "setOffset", moduleName, JsSceneSession::SetOffset); BindNativeFunction(env, objValue, "setPipActionEvent", moduleName, JsSceneSession::SetPipActionEvent); + BindNativeFunction(env, objValue, "notifyDisplayStatusBarTemporarily", moduleName, + JsSceneSession::NotifyDisplayStatusBarTemporarily); napi_ref jsRef = nullptr; napi_status status = napi_create_reference(env, objValue, 1, &jsRef); if (status != napi_ok) { @@ -150,12 +154,8 @@ JsSceneSession::JsSceneSession(napi_env env, const sptr& session) if (session != nullptr) { session->RegisterSessionChangeCallback(sessionchangeCallback); } - sessionchangeCallback->clearCallbackFunc_ = [weak = weak_from_this()](bool needRemove, int32_t persistentId) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) { - weakJsSceneSession->ClearCbMap(needRemove, persistentId); - } - }; + sessionchangeCallback->clearCallbackFunc_ = std::bind(&JsSceneSession::ClearCbMap, this, + std::placeholders::_1, std::placeholders::_2); sessionchangeCallback_ = sessionchangeCallback; WLOGFD("RegisterSessionChangeCallback success"); } @@ -204,14 +204,14 @@ void JsSceneSession::InitListenerFuncs() { PENDING_SESSION_TO_FOREGROUND_CB, &JsSceneSession::ProcessPendingSessionToForegroundRegister }, { PENDING_SESSION_TO_BACKGROUND_FOR_DELEGATOR_CB, &JsSceneSession::ProcessPendingSessionToBackgroundForDelegatorRegister }, - { NEED_DEFAULT_ANIMATION_FLAG_CHANGE_CB, &JsSceneSession::ProcessSessionDefaultAnimationFlagChangeRegister }, { CUSTOM_ANIMATION_PLAYING_CB, &JsSceneSession::ProcessIsCustomAnimationPlaying }, + { NEED_DEFAULT_ANIMATION_FLAG_CHANGE_CB, &JsSceneSession::ProcessSessionDefaultAnimationFlagChangeRegister }, { SHOW_WHEN_LOCKED_CB, &JsSceneSession::ProcessShowWhenLockedRegister }, { REQUESTED_ORIENTATION_CHANGE_CB, &JsSceneSession::ProcessRequestedOrientationChange }, { RAISE_ABOVE_TARGET_CB, &JsSceneSession::ProcessRaiseAboveTargetRegister }, { FORCE_HIDE_CHANGE_CB, &JsSceneSession::ProcessForceHideChangeRegister }, - { TOUCH_OUTSIDE_CB, &JsSceneSession::ProcessTouchOutsideRegister }, { WINDOW_DRAG_HOT_AREA_CB, &JsSceneSession::ProcessWindowDragHotAreaRegister }, + { TOUCH_OUTSIDE_CB, &JsSceneSession::ProcessTouchOutsideRegister }, { SESSIONINFO_LOCKEDSTATE_CHANGE_CB, &JsSceneSession::ProcessSessionInfoLockedStateChangeRegister }, { PREPARE_CLOSE_PIP_SESSION, &JsSceneSession::ProcessPrepareClosePiPSessionRegister}, { LANDSCAPE_MULTI_WINDOW_CB, &JsSceneSession::ProcessLandscapeMultiWindowRegister }, @@ -220,13 +220,25 @@ void JsSceneSession::InitListenerFuncs() }; } +void JsSceneSession::ProcessPendingSceneSessionActivationRegister() +{ + NotifyPendingSessionActivationFunc func = [this](SessionInfo& info) { + this->PendingSessionActivation(info); + }; + auto session = weakSession_.promote(); + if (session == nullptr) { + TLOGE(WmsLogTag::WMS_LIFE, "session is nullptr"); + return; + } + session->SetPendingSessionActivationEventListener(func); + TLOGD(WmsLogTag::WMS_LIFE, "success"); +} + void JsSceneSession::ProcessWindowDragHotAreaRegister() { - WLOGFI("[NAPI]ProcessWindowDragHotAreaRegister"); - NotifyWindowDragHotAreaFunc func = [weak = weak_from_this()](int32_t type, const SizeChangeReason& reason) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnWindowDragHotArea(type, reason); + NotifyWindowDragHotAreaFunc func = [this](int32_t type, const SizeChangeReason& reason) { + this->OnWindowDragHotArea(type, reason); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -274,7 +286,7 @@ void JsSceneSession::OnWindowDragHotArea(int32_t type, const SizeChangeReason& r WLOGFE("[NAPI]jsHotAreaRect is nullptr"); return; } - napi_value argv[] = {jsHotAreaType, jsHotAreaReason, jsHotAreaRect}; + napi_value argv[] = {[0] = jsHotAreaType, [1] = jsHotAreaReason, [2] = jsHotAreaRect}; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }; taskScheduler_->PostMainThreadTask(task, "OnWindowDragHotArea"); @@ -282,9 +294,8 @@ void JsSceneSession::OnWindowDragHotArea(int32_t type, const SizeChangeReason& r void JsSceneSession::ProcessSessionInfoLockedStateChangeRegister() { - NotifySessionInfoLockedStateChangeFunc func = [weak = weak_from_this()](bool lockedState) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnSessionInfoLockedStateChange(lockedState); + NotifySessionInfoLockedStateChangeFunc func = [this](bool lockedState) { + this->OnSessionInfoLockedStateChange(lockedState); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -311,11 +322,15 @@ void JsSceneSession::ProcessLandscapeMultiWindowRegister() void JsSceneSession::SetLandscapeMultiWindow(bool isLandscapeMultiWindow) { WLOGFI("[NAPI]SetLandScapeMultiWindow, isLandscapeMultiWindow: %{public}u", isLandscapeMultiWindow); - auto iter = jsCbMap_.find(LANDSCAPE_MULTI_WINDOW_CB); - if (iter == jsCbMap_.end()) { - return; + std::shared_ptr jsCallBack = nullptr; + { + std::shared_lock lock(jsCbMapMutex_); + auto iter = jsCbMap_.find(LANDSCAPE_MULTI_WINDOW_CB); + if (iter == jsCbMap_.end()) { + return; + } + jsCallBack = iter->second; } - auto jsCallBack = iter->second; auto task = [isLandscapeMultiWindow, jsCallBack, env = env_]() { if (!jsCallBack) { WLOGFE("[NAPI]jsCallBack is nullptr"); @@ -420,10 +435,8 @@ void JsSceneSession::ProcessSessionDefaultAnimationFlagChangeRegister() WLOGFE("sessionchangeCallback is nullptr"); return; } - sessionchangeCallback->onWindowAnimationFlagChange_ = [weak = weak_from_this()](bool isNeedDefaultAnimationFlag) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnDefaultAnimationFlagChange(isNeedDefaultAnimationFlag); - }; + sessionchangeCallback->onWindowAnimationFlagChange_ = std::bind( + &JsSceneSession::OnDefaultAnimationFlagChange, this, std::placeholders::_1); auto session = weakSession_.promote(); if (session == nullptr) { WLOGFE("session is nullptr"); @@ -450,7 +463,8 @@ void JsSceneSession::OnDefaultAnimationFlagChange(bool isNeedDefaultAnimationFla napi_value argv[] = {jsSessionDefaultAnimationFlagObj}; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }; - taskScheduler_->PostMainThreadTask(task, "OnDefaultAnimationFlagChange, flag:" + std::to_string(isNeedDefaultAnimationFlag)); + std::string info = "OnDefaultAnimationFlagChange, flag:" + std::to_string(isNeedDefaultAnimationFlag); + taskScheduler_->PostMainThreadTask(task, info); } void JsSceneSession::ProcessChangeSessionVisibilityWithStatusBarRegister() @@ -467,25 +481,10 @@ void JsSceneSession::ProcessChangeSessionVisibilityWithStatusBarRegister() WLOGFD("ProcessChangeSessionVisibilityWithStatusBarRegister success"); } -void JsSceneSession::ProcessPendingSceneSessionActivationRegister() -{ - NotifyPendingSessionActivationFunc func = [this](SessionInfo& info) { - this->PendingSessionActivation(info); - }; - auto session = weakSession_.promote(); - if (session == nullptr) { - TLOGE(WmsLogTag::WMS_LIFE, "session is nullptr"); - return; - } - session->SetPendingSessionActivationEventListener(func); - TLOGD(WmsLogTag::WMS_LIFE, "success"); -} - void JsSceneSession::ProcessSessionStateChangeRegister() { - NotifySessionStateChangeFunc func = [weak = weak_from_this()](const SessionState& state) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnSessionStateChange(state); + NotifySessionStateChangeFunc func = [this](const SessionState& state) { + this->OnSessionStateChange(state); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -498,9 +497,8 @@ void JsSceneSession::ProcessSessionStateChangeRegister() void JsSceneSession::ProcessBufferAvailableChangeRegister() { - NotifyBufferAvailableChangeFunc func = [weak = weak_from_this()](const bool isAvailable) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnBufferAvailableChange(isAvailable); + NotifyBufferAvailableChangeFunc func = [this](const bool isAvailable) { + this->OnBufferAvailableChange(isAvailable); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -513,9 +511,8 @@ void JsSceneSession::ProcessBufferAvailableChangeRegister() void JsSceneSession::ProcessCreateSubSessionRegister() { - NotifyCreateSubSessionFunc func = [weak = weak_from_this()](const sptr& sceneSession) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnCreateSubSession(sceneSession); + NotifyCreateSubSessionFunc func = [this](const sptr& sceneSession) { + this->OnCreateSubSession(sceneSession); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -533,18 +530,15 @@ void JsSceneSession::ProcessBindDialogTargetRegister() TLOGE(WmsLogTag::WMS_DIALOG, "sessionchangeCallback is nullptr"); return; } - sessionchangeCallback->onBindDialogTarget_ = [weak = weak_from_this()](const sptr& sceneSession) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnBindDialogTarget(sceneSession); - }; + sessionchangeCallback->onBindDialogTarget_ = std::bind(&JsSceneSession::OnBindDialogTarget, + this, std::placeholders::_1); TLOGD(WmsLogTag::WMS_DIALOG, "ProcessBindDialogTargetRegister success"); } void JsSceneSession::ProcessSessionRectChangeRegister() { - NotifySessionRectChangeFunc func = [weak = weak_from_this()](const WSRect& rect, const SizeChangeReason& reason) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnSessionRectChange(rect, reason); + NotifySessionRectChangeFunc func = [this](const WSRect& rect, const SizeChangeReason& reason) { + this->OnSessionRectChange(rect, reason); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -562,22 +556,14 @@ void JsSceneSession::ProcessRaiseToTopRegister() WLOGFE("sessionchangeCallback is nullptr"); return; } - sessionchangeCallback->onRaiseToTop_ = [weak = weak_from_this()]() { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) { - weakJsSceneSession->OnRaiseToTop(); - } - }; + sessionchangeCallback->onRaiseToTop_ = std::bind(&JsSceneSession::OnRaiseToTop, this); WLOGFD("ProcessRaiseToTopRegister success"); } void JsSceneSession::ProcessRaiseToTopForPointDownRegister() { - NotifyRaiseToTopForPointDownFunc func = [weak = weak_from_this()]() { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) { - weakJsSceneSession->OnRaiseToTopForPointDown(); - } + NotifyRaiseToTopForPointDownFunc func = [this]() { + this->OnRaiseToTopForPointDown(); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -595,12 +581,8 @@ void JsSceneSession::ProcessRaiseAboveTargetRegister() WLOGFE("sessionchangeCallback is nullptr"); return; } - sessionchangeCallback->onRaiseAboveTarget_ = [weak = weak_from_this()](int32_t subWindowId){ - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) { - weakJsSceneSession->OnRaiseAboveTarget(subWindowId); - } - }; + sessionchangeCallback->onRaiseAboveTarget_ = std::bind(&JsSceneSession::OnRaiseAboveTarget, + this, std::placeholders::_1); WLOGFD("ProcessRaiseToTopRegister success"); } @@ -611,19 +593,15 @@ void JsSceneSession::ProcessSessionEventRegister() WLOGFE("sessionchangeCallback is nullptr"); return; } - sessionchangeCallback->OnSessionEvent_ = [weak = weak_from_this()](uint32_t eventId) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnSessionEvent(eventId); - }; + sessionchangeCallback->OnSessionEvent_ = std::bind(&JsSceneSession::OnSessionEvent, this, std::placeholders::_1); WLOGFD("ProcessSessionEventRegister success"); } void JsSceneSession::ProcessTerminateSessionRegister() { TLOGD(WmsLogTag::WMS_LIFE, "begin"); - NotifyTerminateSessionFunc func = [weak = weak_from_this()](const SessionInfo& info) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->TerminateSession(info); + NotifyTerminateSessionFunc func = [this](const SessionInfo& info) { + this->TerminateSession(info); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -637,9 +615,8 @@ void JsSceneSession::ProcessTerminateSessionRegister() void JsSceneSession::ProcessTerminateSessionRegisterNew() { TLOGD(WmsLogTag::WMS_LIFE, "begin"); - NotifyTerminateSessionFuncNew func = [weak = weak_from_this()](const SessionInfo& info, bool needStartCaller) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->TerminateSessionNew(info, needStartCaller); + NotifyTerminateSessionFuncNew func = [this](const SessionInfo& info, bool needStartCaller) { + this->TerminateSessionNew(info, needStartCaller); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -653,9 +630,8 @@ void JsSceneSession::ProcessTerminateSessionRegisterNew() void JsSceneSession::ProcessTerminateSessionRegisterTotal() { TLOGD(WmsLogTag::WMS_LIFE, "begin"); - NotifyTerminateSessionFuncTotal func = [weak = weak_from_this()](const SessionInfo& info, TerminateType terminateType) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->TerminateSessionTotal(info, terminateType); + NotifyTerminateSessionFuncTotal func = [this](const SessionInfo& info, TerminateType terminateType) { + this->TerminateSessionTotal(info, terminateType); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -669,9 +645,8 @@ void JsSceneSession::ProcessTerminateSessionRegisterTotal() void JsSceneSession::ProcessPendingSessionToForegroundRegister() { TLOGD(WmsLogTag::WMS_LIFE, "begin"); - NotifyPendingSessionToForegroundFunc func = [weak = weak_from_this()](const SessionInfo& info) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->PendingSessionToForeground(info); + NotifyPendingSessionToForegroundFunc func = [this](const SessionInfo& info) { + this->PendingSessionToForeground(info); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -686,9 +661,8 @@ void JsSceneSession::ProcessPendingSessionToBackgroundForDelegatorRegister() { TLOGD(WmsLogTag::WMS_LIFE, "begin"); auto weak = weak_from_this(); - NotifyPendingSessionToBackgroundForDelegatorFunc func = [weak = weak_from_this()](const SessionInfo& info) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->PendingSessionToBackgroundForDelegator(info); + NotifyPendingSessionToBackgroundForDelegatorFunc func = [this](const SessionInfo& info) { + this->PendingSessionToBackgroundForDelegator(info); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -699,19 +673,19 @@ void JsSceneSession::ProcessPendingSessionToBackgroundForDelegatorRegister() TLOGD(WmsLogTag::WMS_LIFE, "success"); } -void JsSceneSession::ProcessSessionFocusableChangeRegister() +void JsSceneSession::ProcessSessionExceptionRegister() { - NotifySessionFocusableChangeFunc func = [weak = weak_from_this()](bool isFocusable) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnSessionFocusableChange(isFocusable); + WLOGFD("begin to run ProcessSessionExceptionRegister"); + NotifySessionExceptionFunc func = [this](const SessionInfo& info, bool needRemoveSession) { + this->OnSessionException(info, needRemoveSession); }; auto session = weakSession_.promote(); if (session == nullptr) { - WLOGFE("[WMSComm]session is nullptr"); + WLOGFE("session is nullptr"); return; } - session->SetSessionFocusableChangeListener(func); - TLOGD(WmsLogTag::WMS_FOCUS, "ProcessSessionFocusableChangeRegister success"); + session->SetSessionExceptionListener(func, true); + WLOGFD("ProcessSessionExceptionRegister success"); } void JsSceneSession::ProcessSessionTopmostChangeRegister() @@ -732,11 +706,24 @@ void JsSceneSession::ProcessSessionTopmostChangeRegister() TLOGD(WmsLogTag::WMS_LAYOUT, "ProcessSessionTopmostChangeRegister success"); } +void JsSceneSession::ProcessSessionFocusableChangeRegister() +{ + NotifySessionFocusableChangeFunc func = [this](bool isFocusable) { + this->OnSessionFocusableChange(isFocusable); + }; + auto session = weakSession_.promote(); + if (session == nullptr) { + WLOGFE("[WMSComm]session is nullptr"); + return; + } + session->SetSessionFocusableChangeListener(func); + TLOGD(WmsLogTag::WMS_FOCUS, "ProcessSessionFocusableChangeRegister success"); +} + void JsSceneSession::ProcessSessionTouchableChangeRegister() { - NotifySessionTouchableChangeFunc func = [weak = weak_from_this()](bool touchable) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnSessionTouchableChange(touchable); + NotifySessionTouchableChangeFunc func = [this](bool touchable) { + this->OnSessionTouchableChange(touchable); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -747,27 +734,10 @@ void JsSceneSession::ProcessSessionTouchableChangeRegister() WLOGFD("ProcessSessionTouchableChangeRegister success"); } -void JsSceneSession::ProcessSessionExceptionRegister() -{ - WLOGFD("begin to run ProcessSessionExceptionRegister"); - NotifySessionExceptionFunc func = [weak = weak_from_this()](const SessionInfo& info, bool needRemoveSession) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnSessionException(info, needRemoveSession); - }; - auto session = weakSession_.promote(); - if (session == nullptr) { - WLOGFE("session is nullptr"); - return; - } - session->SetSessionExceptionListener(func, true); - WLOGFD("ProcessSessionExceptionRegister success"); -} - void JsSceneSession::ProcessClickRegister() { - NotifyClickFunc func = [weak = weak_from_this()]() { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnClick(); + NotifyClickFunc func = [this]() { + this->OnClick(); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -815,9 +785,8 @@ void JsSceneSession::OnSessionEvent(uint32_t eventId) void JsSceneSession::ProcessBackPressedRegister() { - NotifyBackPressedFunc func = [weak = weak_from_this()](bool needMoveToBackground) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnBackPressed(needMoveToBackground); + NotifyBackPressedFunc func = [this](bool needMoveToBackground) { + this->OnBackPressed(needMoveToBackground); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -834,11 +803,8 @@ void JsSceneSession::ProcessSystemBarPropertyChangeRegister() TLOGE(WmsLogTag::WMS_IMMS, "sessionchangeCallback is nullptr"); return; } - sessionchangeCallback->OnSystemBarPropertyChange_ = [weak = weak_from_this()] - (const std::unordered_map& propertyMap) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnSystemBarPropertyChange(propertyMap); - }; + sessionchangeCallback->OnSystemBarPropertyChange_ = std::bind( + &JsSceneSession::OnSystemBarPropertyChange, this, std::placeholders::_1); TLOGD(WmsLogTag::WMS_IMMS, "ProcessSystemBarPropertyChangeRegister success"); } @@ -849,10 +815,8 @@ void JsSceneSession::ProcessNeedAvoidRegister() TLOGE(WmsLogTag::WMS_IMMS, "sessionchangeCallback is nullptr"); return; } - sessionchangeCallback->OnNeedAvoid_ = [weak = weak_from_this()](bool status) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnNeedAvoid(status); - }; + sessionchangeCallback->OnNeedAvoid_ = std::bind( + &JsSceneSession::OnNeedAvoid, this, std::placeholders::_1); TLOGD(WmsLogTag::WMS_IMMS, "ProcessNeedAvoidRegister success"); } @@ -863,10 +827,8 @@ void JsSceneSession::ProcessIsCustomAnimationPlaying() WLOGFE("sessionchangeCallback is nullptr"); return; } - sessionchangeCallback->onIsCustomAnimationPlaying_ = [weak = weak_from_this()](bool status) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnIsCustomAnimationPlaying(status); - }; + sessionchangeCallback->onIsCustomAnimationPlaying_ = std::bind( + &JsSceneSession::OnIsCustomAnimationPlaying, this, std::placeholders::_1); WLOGFD("ProcessIsCustomAnimationPlaying success"); } @@ -877,10 +839,8 @@ void JsSceneSession::ProcessShowWhenLockedRegister() WLOGFE("sessionchangeCallback is nullptr"); return; } - sessionchangeCallback->OnShowWhenLocked_ = [weak = weak_from_this()](bool showWhenLocked) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnShowWhenLocked(showWhenLocked); - }; + sessionchangeCallback->OnShowWhenLocked_ = std::bind( + &JsSceneSession::OnShowWhenLocked, this, std::placeholders::_1); auto session = weakSession_.promote(); if (session == nullptr) { WLOGFE("session is nullptr"); @@ -897,10 +857,8 @@ void JsSceneSession::ProcessRequestedOrientationChange() WLOGFE("sessionchangeCallback is nullptr"); return; } - sessionchangeCallback->OnRequestedOrientationChange_ = [weak = weak_from_this()](uint32_t orientation) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnReuqestedOrientationChange(orientation); - }; + sessionchangeCallback->OnRequestedOrientationChange_ = std::bind( + &JsSceneSession::OnReuqestedOrientationChange, this, std::placeholders::_1); WLOGFD("ProcessRequestedOrientationChange success"); } @@ -911,10 +869,8 @@ void JsSceneSession::ProcessForceHideChangeRegister() WLOGFE("sessionchangeCallback is nullptr"); return; } - sessionchangeCallback->OnForceHideChange_ = [weak = weak_from_this()](bool hide) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnForceHideChange(hide); - }; + sessionchangeCallback->OnForceHideChange_ = std::bind(&JsSceneSession::OnForceHideChange, + this, std::placeholders::_1); WLOGFD("ProcessForceHideChangeRegister success"); } @@ -949,10 +905,7 @@ void JsSceneSession::ProcessTouchOutsideRegister() WLOGFE("sessionchangeCallback is nullptr"); return; } - sessionchangeCallback->OnTouchOutside_ = [weak = weak_from_this()]() { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnTouchOutside(); - }; + sessionchangeCallback->OnTouchOutside_ = std::bind(&JsSceneSession::OnTouchOutside, this); WLOGFD("ProcessTouchOutsideRegister success"); } @@ -1074,7 +1027,8 @@ napi_value JsSceneSession::SetSCBKeepKeyboard(napi_env env, napi_callback_info i return (me != nullptr) ? me->OnSetSCBKeepKeyboard(env, info) : nullptr; } -napi_value JsSceneSession::SetOffset(napi_env env, napi_callback_info info) { +napi_value JsSceneSession::SetOffset(napi_env env, napi_callback_info info) +{ WLOGI("[NAPI]SetOffset"); JsSceneSession *me = CheckParamsAndGetThis(env, info); return (me != nullptr) ? me->OnSetOffset(env, info) : nullptr; @@ -1087,6 +1041,12 @@ napi_value JsSceneSession::SetPipActionEvent(napi_env env, napi_callback_info in return (me != nullptr) ? me->OnSetPipActionEvent(env, info) : nullptr; } +napi_value JsSceneSession::NotifyDisplayStatusBarTemporarily(napi_env env, napi_callback_info info) +{ + JsSceneSession *me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnNotifyDisplayStatusBarTemporarily(env, info) : nullptr; +} + bool JsSceneSession::IsCallbackRegistered(napi_env env, const std::string& type, napi_value jsListenerObject) { std::shared_lock lock(jsCbMapMutex_); @@ -1231,7 +1191,7 @@ napi_value JsSceneSession::OnSetPrivacyMode(napi_env env, napi_callback_info inf napi_value JsSceneSession::OnSetSystemSceneOcclusionAlpha(napi_env env, napi_callback_info info) { - size_t argc = 0; + size_t argc = 4; napi_value argv[4] = {nullptr}; napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc < 1) { // 1: params num @@ -1240,7 +1200,6 @@ napi_value JsSceneSession::OnSetSystemSceneOcclusionAlpha(napi_env env, napi_cal "Input parameter is missing or invalid")); return NapiGetUndefined(env); } - double alpha = 0.f; if (!ConvertFromJsValue(env, argv[0], alpha)) { WLOGFE("[NAPI]Failed to convert parameter to bool"); @@ -1387,7 +1346,8 @@ void JsSceneSession::OnCreateSubSession(const sptr& sceneSession) napi_value argv[] = {jsSceneSessionObj}; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }; - taskScheduler_->PostMainThreadTask(task, "OnCreateSpecificSession PID:" + std::to_string(sceneSession->GetPersistentId())); + std::string info = "OnCreateSpecificSession PID:" + std::to_string(sceneSession->GetPersistentId()); + taskScheduler_->PostMainThreadTask(task, info); } void JsSceneSession::OnBindDialogTarget(const sptr& sceneSession) @@ -1487,7 +1447,7 @@ void JsSceneSession::OnBufferAvailableChange(const bool isBufferAvailable) void JsSceneSession::OnSessionRectChange(const WSRect& rect, const SizeChangeReason& reason) { - if (rect.IsEmpty()) { + if (reason != SizeChangeReason::MOVE && rect.IsEmpty()) { WLOGFD("Rect is empty, there is no need to notify"); return; } @@ -1584,7 +1544,7 @@ void JsSceneSession::OnRaiseAboveTarget(int32_t subWindowId) WLOGFE("[NAPI]jsSceneSessionObj is nullptr"); return; } - napi_value argv[] = {CreateJsError(env, 0), jsSceneSessionObj}; + napi_value argv[] = {[0] = CreateJsError(env, 0), [1] = jsSceneSessionObj}; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }; taskScheduler_->PostMainThreadTask(task, "OnRaiseAboveTarget: " + std::to_string(subWindowId)); @@ -1993,9 +1953,8 @@ void JsSceneSession::UpdateSessionLabel(const std::string &label) void JsSceneSession::ProcessUpdateSessionLabelRegister() { WLOGFD("begin to run ProcessUpdateSessionLabelRegister"); - NofitySessionLabelUpdatedFunc func = [weak = weak_from_this()](const std::string& label) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->UpdateSessionLabel(label); + NofitySessionLabelUpdatedFunc func = [this](const std::string& label) { + this->UpdateSessionLabel(label); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -2009,9 +1968,8 @@ void JsSceneSession::ProcessUpdateSessionLabelRegister() void JsSceneSession::ProcessUpdateSessionIconRegister() { WLOGFD("begin to run ProcessUpdateSessionIconRegister"); - NofitySessionIconUpdatedFunc func = [weak = weak_from_this()](const std::string& iconPath) { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->UpdateSessionIcon(iconPath); + NofitySessionIconUpdatedFunc func = [this](const std::string& iconPath) { + this->UpdateSessionIcon(iconPath); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -2079,7 +2037,7 @@ void JsSceneSession::OnSessionException(const SessionInfo& info, bool needRemove TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]target session info is nullptr"); return; } - napi_value argv[] = {jsSessionInfo, jsNeedRemoveSession}; + napi_value argv[] = {[0] = jsSessionInfo, [1] = jsNeedRemoveSession}; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }; taskScheduler_->PostMainThreadTask(task, "OnSessionException, name" + info.bundleName_); @@ -2282,35 +2240,6 @@ napi_value JsSceneSession::OnSetShowRecent(napi_env env, napi_callback_info info return NapiGetUndefined(env); } -napi_value JsSceneSession::OnSetSystemActive(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("[NAPI]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); - } - bool scbSystemActive = false; - if (!ConvertFromJsValue(env, argv[0], scbSystemActive)){ - WLOGFE("[NAPI] Failed to convert parameter to bool"); - napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), - "Input parameter is missing or invalid")); - return NapiGetUndefined(env); - } - auto session = weakSession_.promote(); - if (session == nullptr) { - WLOGFE("[NAPI] session_ is null"); - napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_STATE_ABNORMALLY), - "session is null")); - return NapiGetUndefined(env); - } - session->SetSystemActive(scbSystemActive); - return NapiGetUndefined(env); -} - napi_value JsSceneSession::OnSetZOrder(napi_env env, napi_callback_info info) { size_t argc = 4; @@ -2369,38 +2298,6 @@ napi_value JsSceneSession::OnSetFloatingScale(napi_env env, napi_callback_info i return NapiGetUndefined(env); } -napi_value JsSceneSession::OnSetTouchable(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("[NAPI] 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); - } - - bool touchable = false; - if (!ConvertFromJsValue(env, argv[0], touchable)) { - WLOGFE("[NAPI] Failed to convert parameter to touchable"); - napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), - "Input parameter is missing or invalid" )); - return NapiGetUndefined(env); - } - - auto session = weakSession_.promote(); - if (session == nullptr) { - WLOGFE("[NAPI] Session is null"); - napi_throw(env, CreateJsError(env, - static_cast(WSErrorCode::WS_ERROR_STATE_ABNORMALLY), "session is null")); - return NapiGetUndefined(env); - } - - session->SetSystemTouchable(touchable); - return NapiGetUndefined(env); -} - napi_value JsSceneSession::OnSetSCBKeepKeyboard(napi_env env, napi_callback_info info) { size_t argc = 4; @@ -2476,10 +2373,7 @@ void JsSceneSession::ProcessPrepareClosePiPSessionRegister() TLOGE(WmsLogTag::WMS_PIP, "sessionchangeCallback is nullptr"); return; } - sessionchangeCallback->onPrepareClosePiPSession_ = [weak = weak_from_this()]() { - auto weakJsSceneSession = weak.lock(); - if (weakJsSceneSession) weakJsSceneSession->OnPrepareClosePiPSession(); - }; + sessionchangeCallback->onPrepareClosePiPSession_ = std::bind(&JsSceneSession::OnPrepareClosePiPSession, this); TLOGD(WmsLogTag::WMS_PIP, "ProcessPrepareClosePiPSessionRegister success"); } @@ -2506,6 +2400,67 @@ void JsSceneSession::OnPrepareClosePiPSession() taskScheduler_->PostMainThreadTask(task, "OnPrepareClosePiPSession"); } +napi_value JsSceneSession::OnSetSystemActive(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("[NAPI]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); + } + bool scbSystemActive = false; + if (!ConvertFromJsValue(env, argv[0], scbSystemActive)){ + WLOGFE("[NAPI] Failed to convert parameter to bool"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + auto session = weakSession_.promote(); + if (session == nullptr) { + WLOGFE("[NAPI] session_ is null"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_STATE_ABNORMALLY), + "session is null")); + return NapiGetUndefined(env); + } + session->SetSystemActive(scbSystemActive); + return NapiGetUndefined(env); +} + +napi_value JsSceneSession::OnSetTouchable(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("[NAPI] 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); + } + + bool touchable = false; + if (!ConvertFromJsValue(env, argv[0], touchable)) { + WLOGFE("[NAPI] Failed to convert parameter to touchable"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid" )); + return NapiGetUndefined(env); + } + + auto session = weakSession_.promote(); + if (session == nullptr) { + WLOGFE("[NAPI] Session is null"); + napi_throw(env, CreateJsError(env, + static_cast(WSErrorCode::WS_ERROR_STATE_ABNORMALLY), "session is null")); + return NapiGetUndefined(env); + } + + session->SetSystemTouchable(touchable); + return NapiGetUndefined(env); +} + napi_value JsSceneSession::SetScale(napi_env env, napi_callback_info info) { WLOGI("[NAPI]SetScale"); @@ -2593,14 +2548,14 @@ napi_value JsSceneSession::OnSetPipActionEvent(napi_env env, napi_callback_info if (argc < 1) { TLOGE(WmsLogTag::WMS_PIP, "[NAPI]Argc count is invalid: %{public}zu", argc); napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), - "Input parameter is missing or invalid")); + "Input parameter is missing or invalid")); return NapiGetUndefined(env); } std::string action; if (!ConvertFromJsValue(env, argv[0], action)) { TLOGE(WmsLogTag::WMS_PIP, "[NAPI]Failed to convert parameter to string"); napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), - "Input parameter is missing or invalid")); + "Input parameter is missing or invalid")); return NapiGetUndefined(env); } int32_t status = -1; @@ -2608,7 +2563,7 @@ napi_value JsSceneSession::OnSetPipActionEvent(napi_env env, napi_callback_info if (!ConvertFromJsValue(env, argv[1], status)) { TLOGE(WmsLogTag::WMS_PIP, "[NAPI]Failed to convert parameter to int"); napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), - "Input parameter is missing or invalid")); + "Input parameter is missing or invalid")); return NapiGetUndefined(env); } } @@ -2622,6 +2577,31 @@ napi_value JsSceneSession::OnSetPipActionEvent(napi_env env, napi_callback_info return NapiGetUndefined(env); } +napi_value JsSceneSession::OnNotifyDisplayStatusBarTemporarily(napi_env env, napi_callback_info info) +{ + auto session = weakSession_.promote(); + if (session == nullptr) { + TLOGE(WmsLogTag::WMS_IMMS, "[NAPI]session is nullptr"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + size_t argc = ARGC_FOUR; + napi_value argv[ARGC_FOUR] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + bool isTempDisplay = false; + if (argc == ARGC_ONE && GetType(env, argv[0]) == napi_boolean) { + if (!ConvertFromJsValue(env, argv[0], isTempDisplay)) { + TLOGE(WmsLogTag::WMS_IMMS, "[NAPI]failed to convert parameter to bool"); + return NapiGetUndefined(env); + } + } + session->SetIsDisplayStatusBarTemporarily(isTempDisplay); + TLOGI(WmsLogTag::WMS_IMMS, "Set success with id:%{public}u name:%{public}s isTempDisplay:%{public}u", + session->GetPersistentId(), session->GetWindowName().c_str(), isTempDisplay); + return NapiGetUndefined(env); +} + sptr JsSceneSession::GetNativeSession() const { return weakSession_.promote(); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h index 5478a0ed5a..3d9db7ac1c 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h @@ -54,11 +54,12 @@ private: static napi_value SetFocusable(napi_env env, napi_callback_info info); static napi_value SetSystemSceneBlockingFocus(napi_env env, napi_callback_info info); static napi_value UpdateSizeChangeReason(napi_env env, napi_callback_info info); - static napi_value SetSCBKeepKeyboard(napi_env env, napi_callback_info info); - static napi_value SetOffset(napi_env env, napi_callback_info info); static napi_value SetScale(napi_env env, napi_callback_info info); static napi_value RequestHideKeyboard(napi_env env, napi_callback_info info); + static napi_value SetSCBKeepKeyboard(napi_env env, napi_callback_info info); + static napi_value SetOffset(napi_env env, napi_callback_info info); static napi_value SetPipActionEvent(napi_env env, napi_callback_info info); + static napi_value NotifyDisplayStatusBarTemporarily(napi_env env, napi_callback_info info); napi_value OnRegisterCallback(napi_env env, napi_callback_info info); napi_value OnUpdateNativeVisibility(napi_env env, napi_callback_info info); @@ -72,11 +73,12 @@ private: napi_value OnSetFocusable(napi_env env, napi_callback_info info); napi_value OnSetSystemSceneBlockingFocus(napi_env env, napi_callback_info info); napi_value OnUpdateSizeChangeReason(napi_env env, napi_callback_info info); - napi_value OnSetSCBKeepKeyboard(napi_env env, napi_callback_info info); - napi_value OnSetOffset(napi_env env, napi_callback_info info); napi_value OnSetScale(napi_env env, napi_callback_info info); napi_value OnRequestHideKeyboard(napi_env env, napi_callback_info info); + napi_value OnSetSCBKeepKeyboard(napi_env env, napi_callback_info info); + napi_value OnSetOffset(napi_env env, napi_callback_info info); napi_value OnSetPipActionEvent(napi_env env, napi_callback_info info); + napi_value OnNotifyDisplayStatusBarTemporarily(napi_env env, napi_callback_info info); bool IsCallbackRegistered(napi_env env, const std::string& type, napi_value jsListenerObject); void ProcessChangeSessionVisibilityWithStatusBarRegister(); @@ -113,8 +115,8 @@ private: void ProcessRequestedOrientationChange(); void ProcessRaiseAboveTargetRegister(); void ProcessForceHideChangeRegister(); - void ProcessTouchOutsideRegister(); void ProcessWindowDragHotAreaRegister(); + void ProcessTouchOutsideRegister(); void ProcessSessionInfoLockedStateChangeRegister(); void ProcessPrepareClosePiPSessionRegister(); void ProcessLandscapeMultiWindowRegister(); @@ -154,8 +156,8 @@ private: void OnShowWhenLocked(bool showWhenLocked); void OnReuqestedOrientationChange(uint32_t orientation); void OnForceHideChange(bool hide); - void OnTouchOutside(); void OnWindowDragHotArea(int32_t type, const SizeChangeReason& reason); + void OnTouchOutside(); void OnSessionInfoLockedStateChange(bool lockedState); void OnPrepareClosePiPSession(); void OnContextTransparent(); 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 f873f37404..28586dca0e 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 @@ -45,7 +45,6 @@ namespace OHOS::Rosen { using namespace AbilityRuntime; namespace { constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "JsSceneSessionManager" }; -constexpr int WAIT_FOR_SECONDS = 2; constexpr int MIN_ARG_COUNT = 3; constexpr int ARG_INDEX_1 = 1; constexpr int ARG_INDEX_TWO = 2; @@ -53,6 +52,7 @@ constexpr int ARG_INDEX_3 = 3; constexpr int32_t RESTYPE_RECLAIM = 100001; const std::string RES_PARAM_RECLAIM_TAG = "reclaimTag"; const std::string CREATE_SYSTEM_SESSION_CB = "createSpecificSession"; +const std::string CREATE_KEYBOARD_SESSION_CB = "createKeyboardSession"; const std::string RECOVER_SCENE_SESSION_CB = "recoverSceneSession"; const std::string STATUS_BAR_ENABLED_CHANGE_CB = "statusBarEnabledChange"; const std::string GESTURE_NAVIGATION_ENABLED_CHANGE_CB = "gestureNavigationEnabledChange"; @@ -122,13 +122,14 @@ napi_value JsSceneSessionManager::Init(napi_env env, napi_value exportObj) BindNativeFunction(env, exportObj, "getRootSceneUIContext", moduleName, JsSceneSessionManager::GetRootSceneUIContext); BindNativeFunction(env, exportObj, "sendTouchEvent", moduleName, JsSceneSessionManager::SendTouchEvent); + BindNativeFunction(env, exportObj, "addWindowDragHotArea", moduleName, JsSceneSessionManager::AddWindowDragHotArea); + BindNativeFunction(env, exportObj, "preloadInLakeApp", moduleName, JsSceneSessionManager::PreloadInLakeApp); BindNativeFunction(env, exportObj, "requestFocusStatus", moduleName, JsSceneSessionManager::RequestFocusStatus); BindNativeFunction(env, exportObj, "requestAllAppSessionUnfocus", moduleName, JsSceneSessionManager::RequestAllAppSessionUnfocus); - BindNativeFunction(env, exportObj, "preloadInLakeApp", moduleName, JsSceneSessionManager::PreloadInLakeApp); - BindNativeFunction(env, exportObj, "addWindowDragHotArea", moduleName, JsSceneSessionManager::AddWindowDragHotArea); BindNativeFunction(env, exportObj, "setScreenLocked", moduleName, JsSceneSessionManager::SetScreenLocked); BindNativeFunction(env, exportObj, "updateMaximizeMode", moduleName, JsSceneSessionManager::UpdateMaximizeMode); + BindNativeFunction(env, exportObj, "reportData", moduleName, JsSceneSessionManager::ReportData); BindNativeFunction(env, exportObj, "updateSessionDisplayId", moduleName, JsSceneSessionManager::UpdateSessionDisplayId); BindNativeFunction(env, exportObj, "updateConfig", moduleName, @@ -138,7 +139,6 @@ napi_value JsSceneSessionManager::Init(napi_env env, napi_value exportObj) BindNativeFunction(env, exportObj, "notifyAINavigationBarShowStatus", moduleName, JsSceneSessionManager::NotifyAINavigationBarShowStatus); BindNativeFunction(env, exportObj, "updateTitleInTargetPos", moduleName, JsSceneSessionManager::UpdateTitleInTargetPos); - BindNativeFunction(env, exportObj, "reportData", moduleName, JsSceneSessionManager::ReportData); BindNativeFunction(env, exportObj, "setSystemAnimatedScenes", moduleName, JsSceneSessionManager::SetSystemAnimatedScenes); BindNativeFunction(env, exportObj, "getSessionSnapshotPixelMap", moduleName, @@ -149,6 +149,7 @@ napi_value JsSceneSessionManager::Init(napi_env env, napi_value exportObj) JsSceneSessionManager::SwitchFreeMultiWindow); BindNativeFunction(env, exportObj, "getFreeMultiWindowConfig", moduleName, JsSceneSessionManager::GetFreeMultiWindowConfig); + BindNativeFunction(env, exportObj, "getCustomDecorHeight", moduleName, JsSceneSessionManager::GetCustomDecorHeight); return NapiGetUndefined(env); } @@ -156,14 +157,15 @@ JsSceneSessionManager::JsSceneSessionManager(napi_env env) : env_(env) { listenerFunc_ = { { CREATE_SYSTEM_SESSION_CB, &JsSceneSessionManager::ProcessCreateSystemSessionRegister }, - { RECOVER_SCENE_SESSION_CB, &JsSceneSessionManager::ProcessRecoverSceneSessionRegister }, + { CREATE_KEYBOARD_SESSION_CB, &JsSceneSessionManager::ProcessCreateKeyboardSessionRegister }, + { RECOVER_SCENE_SESSION_CB, &JsSceneSessionManager::ProcessRecoverSceneSessionRegister }, { STATUS_BAR_ENABLED_CHANGE_CB, &JsSceneSessionManager::ProcessStatusBarEnabledChangeListener}, { OUTSIDE_DOWN_EVENT_CB, &JsSceneSessionManager::ProcessOutsideDownEvent }, { SHIFT_FOCUS_CB, &JsSceneSessionManager::ProcessShiftFocus }, + { CALLING_WINDOW_ID_CHANGE_CB, &JsSceneSessionManager::ProcessCallingSessionIdChangeRegister}, { START_UI_ABILITY_ERROR, &JsSceneSessionManager::ProcessStartUIAbilityErrorRegister}, { GESTURE_NAVIGATION_ENABLED_CHANGE_CB, &JsSceneSessionManager::ProcessGestureNavigationEnabledChangeListener }, - { CALLING_WINDOW_ID_CHANGE_CB, &JsSceneSessionManager::ProcessCallingSessionIdChangeRegister}, }; taskScheduler_ = std::make_shared(env); } @@ -174,14 +176,17 @@ void JsSceneSessionManager::OnCreateSystemSession(const sptr& scen TLOGI(WmsLogTag::WMS_LIFE, "[NAPI]sceneSession is nullptr"); return; } - auto iter = jsCbMap_.find(CREATE_SYSTEM_SESSION_CB); - if (iter == jsCbMap_.end()) { - TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Can't find callback, id: %{public}d", sceneSession->GetPersistentId()); - return; + std::shared_ptr jsCallBack = nullptr; + { + std::shared_lock lock(jsCbMapMutex_); + auto iter = jsCbMap_.find(CREATE_SYSTEM_SESSION_CB); + if (iter == jsCbMap_.end()) { + TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]Can't find callback, id: %{public}d", sceneSession->GetPersistentId()); + return; + } + TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]OnCreateSystemSession, id: %{public}d", sceneSession->GetPersistentId()); + jsCallBack = iter->second; } - - TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]OnCreateSystemSession, id: %{public}d", sceneSession->GetPersistentId()); - auto jsCallBack = iter->second; wptr weakSession(sceneSession); auto task = [this, weakSession, jsCallBack, env = env_]() { auto specificSession = weakSession.promote(); @@ -200,6 +205,51 @@ void JsSceneSessionManager::OnCreateSystemSession(const sptr& scen taskScheduler_->PostMainThreadTask(task, "OnCreateSystemSession"); } +void JsSceneSessionManager::OnCreateKeyboardSession(const sptr& keyboardSession, + const sptr& panelSession) +{ + if (keyboardSession == nullptr || panelSession == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "[NAPI]keyboard or panel session is nullptr"); + return; + } + auto iter = jsCbMap_.find(CREATE_KEYBOARD_SESSION_CB); + if (iter == jsCbMap_.end()) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "[NAPI]Can't find callback, id: %{public}d", keyboardSession->GetPersistentId()); + return; + } + + TLOGI(WmsLogTag::WMS_KEYBOARD, "[NAPI]keyboardId: %{public}d, panelId: %{public}d", + keyboardSession->GetPersistentId(), panelSession->GetPersistentId()); + auto jsCallBack = iter->second; + wptr weakKeyboardSession(keyboardSession); + wptr weakPanelSession(panelSession); + auto task = [this, weakKeyboardSession, weakPanelSession, jsCallBack, env = env_]() { + if (!jsCallBack) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "[NAPI]jsCallBack is nullptr"); + return; + } + auto keyboardSession = weakKeyboardSession.promote(); + auto panelSession = weakPanelSession.promote(); + if (keyboardSession == nullptr || panelSession == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "[NAPI]keyboard or panel session is nullptr"); + return; + } + napi_value keyboardSessionObj = JsSceneSession::Create(env, keyboardSession); + if (keyboardSessionObj == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "[NAPI]keyboardSessionObj is nullptr"); + return; + } + napi_value panelSessionObj = JsSceneSession::Create(env, panelSession); + if (panelSessionObj == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "[NAPI]panelSessionObj is nullptr"); + return; + } + napi_value argv[] = { keyboardSessionObj, panelSessionObj }; + napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); + }; + taskScheduler_->PostMainThreadTask(task, "OnCreateKeyboardSession"); +} + void JsSceneSessionManager::OnRecoverSceneSession(const sptr& sceneSession, const SessionInfo& info) { if (sceneSession == nullptr) { @@ -252,12 +302,15 @@ void JsSceneSessionManager::OnRecoverSceneSession(const sptr& scen void JsSceneSessionManager::OnStatusBarEnabledUpdate(bool enable) { WLOGFI("[NAPI]OnStatusBarEnabledUpdate"); - auto iter = jsCbMap_.find(STATUS_BAR_ENABLED_CHANGE_CB); - if (iter == jsCbMap_.end()) { - return; + std::shared_ptr jsCallBack = nullptr; + { + std::shared_lock lock(jsCbMapMutex_); + auto iter = jsCbMap_.find(STATUS_BAR_ENABLED_CHANGE_CB); + if (iter == jsCbMap_.end()) { + return; + } + jsCallBack = iter->second; } - - auto jsCallBack = iter->second; auto task = [this, enable, jsCallBack, env = env_]() { napi_value argv[] = {CreateJsValue(env, enable)}; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); @@ -268,12 +321,15 @@ void JsSceneSessionManager::OnStatusBarEnabledUpdate(bool enable) void JsSceneSessionManager::OnGestureNavigationEnabledUpdate(bool enable) { WLOGFI("[NAPI]OnGestureNavigationEnabledUpdate"); - auto iter = jsCbMap_.find(GESTURE_NAVIGATION_ENABLED_CHANGE_CB); - if (iter == jsCbMap_.end()) { - return; + std::shared_ptr jsCallBack = nullptr; + { + std::shared_lock lock(jsCbMapMutex_); + auto iter = jsCbMap_.find(GESTURE_NAVIGATION_ENABLED_CHANGE_CB); + if (iter == jsCbMap_.end()) { + return; + } + jsCallBack = iter->second; } - - auto jsCallBack = iter->second; auto task = [this, enable, jsCallBack, env = env_]() { napi_value argv[] = {CreateJsValue(env, enable)}; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); @@ -284,11 +340,15 @@ void JsSceneSessionManager::OnGestureNavigationEnabledUpdate(bool enable) void JsSceneSessionManager::OnStartUIAbilityError(const uint32_t errorCode) { WLOGFI("[NAPI]OnStartUIAbilityError"); - auto iter = jsCbMap_.find(START_UI_ABILITY_ERROR); - if (iter == jsCbMap_.end()) { - return; + std::shared_ptr jsCallBack = nullptr; + { + std::shared_lock lock(jsCbMapMutex_); + auto iter = jsCbMap_.find(START_UI_ABILITY_ERROR); + if (iter == jsCbMap_.end()) { + return; + } + jsCallBack = iter->second; } - auto jsCallBack = iter->second; auto task = [this, errorCode, jsCallBack, env = env_]() { napi_value argv[] = {CreateJsValue(env, errorCode)}; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); @@ -299,12 +359,15 @@ void JsSceneSessionManager::OnStartUIAbilityError(const uint32_t errorCode) void JsSceneSessionManager::OnOutsideDownEvent(int32_t x, int32_t y) { WLOGFD("[NAPI]OnOutsideDownEvent"); - auto iter = jsCbMap_.find(OUTSIDE_DOWN_EVENT_CB); - if (iter == jsCbMap_.end()) { - return; + std::shared_ptr jsCallBack = nullptr; + { + std::shared_lock lock(jsCbMapMutex_); + auto iter = jsCbMap_.find(OUTSIDE_DOWN_EVENT_CB); + if (iter == jsCbMap_.end()) { + return; + } + jsCallBack = iter->second; } - - auto jsCallBack = iter->second; auto task = [this, x, y, jsCallBack, env = env_]() { napi_value objValue = nullptr; napi_create_object(env, &objValue); @@ -325,12 +388,15 @@ void JsSceneSessionManager::OnOutsideDownEvent(int32_t x, int32_t y) void JsSceneSessionManager::OnShiftFocus(int32_t persistentId) { TLOGD(WmsLogTag::WMS_FOCUS, "[NAPI]OnShiftFocus"); - auto iter = jsCbMap_.find(SHIFT_FOCUS_CB); - if (iter == jsCbMap_.end()) { - return; + std::shared_ptr jsCallBack = nullptr; + { + std::shared_lock lock(jsCbMapMutex_); + auto iter = jsCbMap_.find(SHIFT_FOCUS_CB); + if (iter == jsCbMap_.end()) { + return; + } + jsCallBack = iter->second; } - - auto jsCallBack = iter->second; auto task = [this, persistentId, jsCallBack, env = env_]() { napi_value argv[] = {CreateJsValue(env, persistentId)}; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); @@ -341,11 +407,15 @@ void JsSceneSessionManager::OnShiftFocus(int32_t persistentId) void JsSceneSessionManager::OnCallingSessionIdChange(uint32_t windowId) { TLOGD(WmsLogTag::WMS_KEYBOARD, "[NAPI]OnCallingSessionIdChange"); - auto iter = jsCbMap_.find(CALLING_WINDOW_ID_CHANGE_CB); - if (iter == jsCbMap_.end()) { - return; + std::shared_ptr jsCallBack = nullptr; + { + std::shared_lock lock(jsCbMapMutex_); + auto iter = jsCbMap_.find(CALLING_WINDOW_ID_CHANGE_CB); + if (iter == jsCbMap_.end()) { + return; + } + jsCallBack = iter->second; } - auto jsCallBack = iter->second; auto task = [this, windowId, jsCallBack, env = env_]() { napi_value argv[] = { CreateJsValue(env, windowId) }; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); @@ -362,6 +432,15 @@ void JsSceneSessionManager::ProcessCreateSystemSessionRegister() SceneSessionManager::GetInstance().SetCreateSystemSessionListener(func); } +void JsSceneSessionManager::ProcessCreateKeyboardSessionRegister() +{ + NotifyCreateKeyboardSessionFunc func = [this](const sptr& keyboardSession, + const sptr& panelSession) { + this->OnCreateKeyboardSession(keyboardSession, panelSession); + }; + SceneSessionManager::GetInstance().SetCreateKeyboardSessionListener(func); +} + void JsSceneSessionManager::ProcessStartUIAbilityErrorRegister() { ProcessStartUIAbilityErrorFunc func = [this](uint32_t startUIAbilityError) { @@ -647,6 +726,13 @@ napi_value JsSceneSessionManager::SendTouchEvent(napi_env env, napi_callback_inf return (me != nullptr) ? me->OnSendTouchEvent(env, info) : nullptr; } +napi_value JsSceneSessionManager::PreloadInLakeApp(napi_env env, napi_callback_info info) +{ + WLOGI("[NAPI]PreloadInLakeApp"); + JsSceneSessionManager* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnPreloadInLakeApp(env, info) : nullptr; +} + napi_value JsSceneSessionManager::RequestFocusStatus(napi_env env, napi_callback_info info) { TLOGD(WmsLogTag::WMS_FOCUS, "RequestFocusStatus"); @@ -668,13 +754,6 @@ napi_value JsSceneSessionManager::SetScreenLocked(napi_env env, napi_callback_in return (me != nullptr) ? me->OnSetScreenLocked(env, info) : nullptr; } -napi_value JsSceneSessionManager::PreloadInLakeApp(napi_env env, napi_callback_info info) -{ - WLOGI("[NAPI]PreloadInLakeApp"); - JsSceneSessionManager* me = CheckParamsAndGetThis(env, info); - return (me != nullptr) ? me->OnPreloadInLakeApp(env, info) : nullptr; -} - napi_value JsSceneSessionManager::UpdateMaximizeMode(napi_env env, napi_callback_info info) { WLOGI("[NAPI]UpdateMaximizeMode"); @@ -682,6 +761,13 @@ napi_value JsSceneSessionManager::UpdateMaximizeMode(napi_env env, napi_callback return (me != nullptr) ? me->OnUpdateMaximizeMode(env, info) : nullptr; } +napi_value JsSceneSessionManager::ReportData(napi_env env, napi_callback_info info) +{ + WLOGI("[NAPI]ReportData"); + JsSceneSessionManager* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnReportData(env, info) : nullptr; +} + napi_value JsSceneSessionManager::UpdateSessionDisplayId(napi_env env, napi_callback_info info) { WLOGI("[NAPI]UpdateSessionDisplayId"); @@ -717,13 +803,6 @@ napi_value JsSceneSessionManager::UpdateTitleInTargetPos(napi_env env, napi_call return (me != nullptr) ? me->OnUpdateTitleInTargetPos(env, info) : nullptr; } -napi_value JsSceneSessionManager::ReportData(napi_env env, napi_callback_info info) -{ - WLOGI("[NAPI]ReportData"); - JsSceneSessionManager* me = CheckParamsAndGetThis(env, info); - return (me != nullptr) ? me->OnReportData(env, info) : nullptr; -} - napi_value JsSceneSessionManager::GetSessionSnapshotPixelMap(napi_env env, napi_callback_info info) { WLOGI("[NAPI]GetSessionSnapshotPixelMap"); @@ -754,6 +833,7 @@ napi_value JsSceneSessionManager::GetFreeMultiWindowConfig(napi_env env, napi_ca bool JsSceneSessionManager::IsCallbackRegistered(napi_env env, const std::string& type, napi_value jsListenerObject) { + std::shared_lock lock(jsCbMapMutex_); if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { return false; } @@ -984,21 +1064,21 @@ napi_value JsSceneSessionManager::OnSwitchUser(napi_env env, napi_callback_info return NapiGetUndefined(env); } int32_t oldUserId; - if (!ConvertFromJsValue(env, argv[0], oldUserId)) { + if (!ConvertFromJsValue(env, argv[0], oldUserId)) { // 0: params num WLOGFE("[NAPI]Failed to convert parameter to oldUserId"); napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), "Input parameter is missing or invalid")); return NapiGetUndefined(env); } int32_t newUserId; - if (!ConvertFromJsValue(env, argv[1], newUserId)) { + if (!ConvertFromJsValue(env, argv[1], newUserId)) { // 1: params num WLOGFE("[NAPI]Failed to convert parameter to newUserId"); napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), "Input parameter is missing or invalid")); return NapiGetUndefined(env); } std::string fileDir; - if (!ConvertFromJsValue(env, argv[ARGC_TWO], fileDir)) { + if (!ConvertFromJsValue(env, argv[2], fileDir)) { // 2: params num WLOGFE("[NAPI]Failed to convert parameter to fileDir"); napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), "Input parameter is missing or invalid")); @@ -1017,12 +1097,12 @@ void JsSceneSessionManager::RegisterDumpRootSceneElementInfoListener() { DumpRootSceneElementInfoFunc func = [this](const std::vector& params, std::vector& infos) { - if (params.size() == 1 && params[0] == ARG_DUMP_HELP) { + if (params.size() == 1 && params[0] == ARG_DUMP_HELP) { // 1 params num Ace::UIContent::ShowDumpHelp(infos); - WLOGFD("Dump arkUI help info"); + WLOGFD("Dump ArkUI help info"); } else if (RootScene::staticRootScene_->GetUIContent()) { RootScene::staticRootScene_->GetUIContent()->DumpInfo(params, infos); - WLOGFD("Dump arkUI element info"); + WLOGFD("Dump ArkUI element info"); } }; SceneSessionManager::GetInstance().SetDumpRootSceneElementInfoListener(func); @@ -1206,14 +1286,8 @@ napi_value JsSceneSessionManager::OnRequestSceneSessionActivation(napi_env env, bool isNewActive = true; ConvertFromJsValue(env, argv[1], isNewActive); - int32_t errCode = static_cast(WSErrorCode::WS_ERROR_TIMEOUT); - auto future = SceneSessionManager::GetInstance().RequestSceneSessionActivation(sceneSession, isNewActive); - if (future.wait_for(std::chrono::seconds(WAIT_FOR_SECONDS)) == std::future_status::ready) { - errCode = future.get(); - } - napi_value number = nullptr; - napi_create_int32(env, errCode, &number); - return number; + SceneSessionManager::GetInstance().RequestSceneSessionActivation(sceneSession, isNewActive); + return NapiGetUndefined(env); } napi_value JsSceneSessionManager::OnRequestSceneSessionBackground(napi_env env, napi_callback_info info) @@ -1409,9 +1483,11 @@ napi_value JsSceneSessionManager::OnIsSceneSessionValid(napi_env env, napi_callb return result; } -void JsSceneSessionManager::SetIsClearSession(napi_env env, napi_value jsSceneSessionObj, sptr& sceneSession) +void JsSceneSessionManager::SetIsClearSession(napi_env env, napi_value jsSceneSessionObj, + sptr& sceneSession) { if (sceneSession == nullptr) { + WLOGFE("[NAPI]SetIsClearSession: sceneSession is nullptr"); return; } napi_value jsOperatorType = nullptr; @@ -1716,7 +1792,7 @@ napi_value JsSceneSessionManager::OnPerfRequestEx(napi_env env, napi_callback_in size_t argc = 4; napi_value argv[4] = {nullptr}; napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - if (argc < 2) { + if (argc < ARGC_TWO) { WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc); napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), "Input parameter is missing or invalid")); @@ -1751,7 +1827,7 @@ napi_value JsSceneSessionManager::OnUpdateWindowMode(napi_env env, napi_callback size_t argc = 4; napi_value argv[4] = {nullptr}; napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - if (argc < 2) { + if (argc < ARGC_TWO) { WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc); napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), "Input parameter is missing or invalid")); @@ -1829,7 +1905,6 @@ napi_value JsSceneSessionManager::OnGetRootSceneUIContext(napi_env env, napi_cal napi_throw(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY))); return NapiGetUndefined(env); } - napi_value uiContext = uiContent->GetUINapiContext(); if (uiContext == nullptr) { WLOGFE("uiContext obtained from jsEngine is nullptr"); @@ -1874,6 +1949,32 @@ napi_value JsSceneSessionManager::OnSendTouchEvent(napi_env env, napi_callback_i return NapiGetUndefined(env); } +napi_value JsSceneSessionManager::OnPreloadInLakeApp(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 != ARGC_ONE) { + WLOGFE("[NAPI]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); + } + std::string bundleName = ""; + if (!ConvertFromJsValue(env, argv[0], bundleName)) { + WLOGFE("[NAPI]Failed to convert parameter to bundleName"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + auto localScheduler = SceneSessionManager::GetInstance().GetTaskScheduler(); + auto preloadTask = [bundleName] () { + SceneSessionManager::GetInstance().PreloadInLakeApp(bundleName); + }; + localScheduler->PostAsyncTask(preloadTask); + return NapiGetUndefined(env); +} + napi_value JsSceneSessionManager::OnRequestFocusStatus(napi_env env, napi_callback_info info) { size_t argc = 4; @@ -1947,28 +2048,6 @@ napi_value JsSceneSessionManager::OnSetScreenLocked(napi_env env, napi_callback_ return NapiGetUndefined(env); } -napi_value JsSceneSessionManager::OnPreloadInLakeApp(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 != ARGC_ONE) { - WLOGFE("[NAPI]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); - } - std::string bundleName = ""; - if (!ConvertFromJsValue(env, argv[0], bundleName)) { - WLOGFE("[NAPI]Failed to convert parameter to bundleName"); - napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), - "Input parameter is missing or invalid")); - return NapiGetUndefined(env); - } - SceneSessionManager::GetInstance().PreloadInLakeApp(bundleName); - return NapiGetUndefined(env); -} - napi_value JsSceneSessionManager::OnUpdateMaximizeMode(napi_env env, napi_callback_info info) { size_t argc = 4; @@ -2096,7 +2175,8 @@ napi_value JsSceneSessionManager::OnNotifyAINavigationBarShowStatus(napi_env env "Input parameter is missing or invalid")); return NapiGetUndefined(env); } - SceneSessionManager::GetInstance().NotifyAINavigationBarShowStatus(isVisible, barArea, displayId); + SceneSessionManager::GetInstance().NotifyAINavigationBarShowStatus( + isVisible, barArea, static_cast(displayId)); return NapiGetUndefined(env); } @@ -2105,7 +2185,7 @@ napi_value JsSceneSessionManager::OnNotifySessionRecoverStatus(napi_env env, nap size_t argc = 4; napi_value argv[4] = { nullptr }; napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - if (argc < ARGC_ONE) { + if (argc != ARGC_TWO) { WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc); napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), "Input parameter is missing or invalid")); @@ -2129,14 +2209,8 @@ napi_value JsSceneSessionManager::OnNotifySessionRecoverStatus(napi_env env, nap } if (!isRecovering) { // Sceneboard recover finished - if (argc != ARGC_TWO) { - WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc); - napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), - "Recovered persistentId List not received")); - return NapiGetUndefined(env); - } - SceneSessionManager::GetInstance().UpdateRecoveredSessionInfo(recoveredPersistentIds); SceneSessionManager::GetInstance().NotifyRecoveringFinished(); + SceneSessionManager::GetInstance().UpdateRecoveredSessionInfo(recoveredPersistentIds); } else { SceneSessionManager::GetInstance().SetAlivePersistentIds(recoveredPersistentIds); } @@ -2315,4 +2389,35 @@ napi_value JsSceneSessionManager::OnGetFreeMultiWindowConfig(napi_env env, napi_ auto systemConfig = SceneSessionManager::GetInstance().GetSystemSessionConfig(); return JsWindowSceneConfig::CreateFreeMultiWindowConfig(env, systemConfig); } + +napi_value JsSceneSessionManager::GetCustomDecorHeight(napi_env env, napi_callback_info info) +{ + TLOGD(WmsLogTag::WMS_LAYOUT, "[NAPI]GetCustomDecorHeight"); + JsSceneSessionManager* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnGetCustomDecorHeight(env, info) : nullptr; +} + +napi_value JsSceneSessionManager::OnGetCustomDecorHeight(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) { + TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]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 persistentId; + if (!ConvertFromJsValue(env, argv[0], persistentId)) { + TLOGE(WmsLogTag::WMS_LAYOUT, "[NAPI]Failed to convert parameter to persistentId"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + int32_t customDecorHeight = SceneSessionManager::GetInstance().GetCustomDecorHeight(persistentId); + napi_value result = nullptr; + napi_create_int32(env, customDecorHeight, &result); + return result; +} } // 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 4da6fbeda2..75cced5b45 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 @@ -62,23 +62,25 @@ public: static napi_value UpdateWindowMode(napi_env env, napi_callback_info info); static napi_value GetRootSceneUIContext(napi_env env, napi_callback_info info); static napi_value SendTouchEvent(napi_env env, napi_callback_info info); + static napi_value AddWindowDragHotArea(napi_env env, napi_callback_info info); + static napi_value PreloadInLakeApp(napi_env env, napi_callback_info info); static napi_value RequestFocusStatus(napi_env env, napi_callback_info info); static napi_value RequestAllAppSessionUnfocus(napi_env env, napi_callback_info info); static napi_value SetScreenLocked(napi_env env, napi_callback_info info); - static napi_value PreloadInLakeApp(napi_env env, napi_callback_info info); - static napi_value AddWindowDragHotArea(napi_env env, napi_callback_info info); static napi_value UpdateTitleInTargetPos(napi_env env, napi_callback_info info); static napi_value UpdateMaximizeMode(napi_env env, napi_callback_info info); + static napi_value ReportData(napi_env env, napi_callback_info info); static napi_value NotifyAINavigationBarShowStatus(napi_env env, napi_callback_info info); static napi_value NotifySessionRecoverStatus(napi_env env, napi_callback_info info); static napi_value UpdateSessionDisplayId(napi_env env, napi_callback_info info); static napi_value UpdateConfig(napi_env env, napi_callback_info info); - static napi_value ReportData(napi_env env, napi_callback_info info); static napi_value SetSystemAnimatedScenes(napi_env env, napi_callback_info info); static napi_value GetSessionSnapshotPixelMap(napi_env env, napi_callback_info info); static napi_value GetIsLayoutFullScreen(napi_env env, napi_callback_info info); static napi_value SwitchFreeMultiWindow(napi_env env, napi_callback_info info); static napi_value GetFreeMultiWindowConfig(napi_env env, napi_callback_info info); + static napi_value GetCustomDecorHeight(napi_env env, napi_callback_info info); + private: napi_value OnRegisterCallback(napi_env env, napi_callback_info info); napi_value OnGetRootSceneSession(napi_env env, napi_callback_info info); @@ -110,33 +112,36 @@ private: napi_value OnUpdateWindowMode(napi_env env, napi_callback_info info); napi_value OnGetRootSceneUIContext(napi_env env, napi_callback_info info); napi_value OnSendTouchEvent(napi_env env, napi_callback_info info); + napi_value OnAddWindowDragHotArea(napi_env env, napi_callback_info info); + napi_value OnPreloadInLakeApp(napi_env env, napi_callback_info info); napi_value OnRequestFocusStatus(napi_env env, napi_callback_info info); napi_value OnRequestAllAppSessionUnfocus(napi_env env, napi_callback_info info); napi_value OnSetScreenLocked(napi_env env, napi_callback_info info); - napi_value OnPreloadInLakeApp(napi_env env, napi_callback_info info); - napi_value OnAddWindowDragHotArea(napi_env env, napi_callback_info info); napi_value OnUpdateMaximizeMode(napi_env env, napi_callback_info info); + napi_value OnReportData(napi_env env, napi_callback_info info); napi_value OnNotifySessionRecoverStatus(napi_env env, napi_callback_info info); napi_value OnUpdateSessionDisplayId(napi_env env, napi_callback_info info); napi_value OnUpdateConfig(napi_env env, napi_callback_info info); napi_value OnNotifyAINavigationBarShowStatus(napi_env env, napi_callback_info info); napi_value OnUpdateTitleInTargetPos(napi_env env, napi_callback_info info); - napi_value OnReportData(napi_env env, napi_callback_info info); napi_value OnSetSystemAnimatedScenes(napi_env env, napi_callback_info info); napi_value OnGetSessionSnapshotPixelMap(napi_env env, napi_callback_info info); napi_value OnGetIsLayoutFullScreen(napi_env env, napi_callback_info info); napi_value OnSwitchFreeMultiWindow(napi_env env, napi_callback_info info); napi_value OnGetFreeMultiWindowConfig(napi_env env, napi_callback_info info); + napi_value OnGetCustomDecorHeight(napi_env env, napi_callback_info info); void OnStatusBarEnabledUpdate(bool enable); void OnGestureNavigationEnabledUpdate(bool enable); void OnCreateSystemSession(const sptr& sceneSession); + void OnCreateKeyboardSession(const sptr& keyboardSession, const sptr& panelSession); void OnRecoverSceneSession(const sptr& sceneSession, const SessionInfo& sessionInfo); void OnOutsideDownEvent(int32_t x, int32_t y); void OnStartUIAbilityError(const uint32_t errorCode); void OnShiftFocus(int32_t persistentId); void OnCallingSessionIdChange(uint32_t callingSessionId); void ProcessCreateSystemSessionRegister(); + void ProcessCreateKeyboardSessionRegister(); void ProcessRecoverSceneSessionRegister(); void ProcessStatusBarEnabledChangeListener(); void ProcessGestureNavigationEnabledChangeListener(); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp index 6f00a3b5a1..7422d71858 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp @@ -49,6 +49,20 @@ int32_t GetMMITouchType(int32_t aceType) return MMI::PointerEvent::POINTER_ACTION_UNKNOWN; } } + +int32_t GetMMISourceType(int32_t sourceType) +{ + switch (sourceType) { + case 1: + return MMI::PointerEvent::SOURCE_TYPE_MOUSE; + case NUMBER_2: + return MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN; + case NUMBER_3: + return MMI::PointerEvent::SOURCE_TYPE_TOUCHPAD; + default: + return MMI::PointerEvent::SOURCE_TYPE_UNKNOWN; + } +} } // namespace napi_value NapiGetUndefined(napi_env env) @@ -557,7 +571,7 @@ bool ConvertPointerEventFromJs(napi_env env, napi_value jsObject, MMI::PointerEv WLOGFE("[NAPI]Failed to convert parameter to sourceType"); return false; } - pointerEvent.SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN); + pointerEvent.SetSourceType(GetMMISourceType(sourceType)); double timestamp; if (!ConvertFromJsValue(env, jsTimestamp, timestamp)) { WLOGFE("[NAPI]Failed to convert parameter to timestamp"); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_window_scene_config.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_window_scene_config.cpp index e267d4767e..d04b211a95 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_window_scene_config.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_window_scene_config.cpp @@ -42,6 +42,8 @@ napi_value JsWindowSceneConfig::CreateWindowSceneConfig(napi_env env, const AppW napi_set_named_property(env, objValue, "keyboardAnimationOut", CreateKeyboardAnimationValue(env, config.keyboardAnimationOut_)); napi_set_named_property(env, objValue, "windowAnimation", CreateWindowAnimationValue(env, config)); + napi_set_named_property(env, objValue, "systemUIStatusBar", CreateSystemUIStatusBarValue(env, + config.systemUIStatusBarConfig_)); return objValue; } @@ -113,6 +115,23 @@ napi_value JsWindowSceneConfig::CreateKeyboardAnimationValue(napi_env env, return objValue; } +napi_value JsWindowSceneConfig::CreateSystemUIStatusBarValue(napi_env env, + const SystemUIStatusBarConfig& config) +{ + napi_value objValue = nullptr; + napi_create_object(env, &objValue); + if (objValue == nullptr) { + WLOGFE("[NAPI]Object is null!"); + return NapiGetUndefined(env); + } + napi_set_named_property(env, objValue, "showInLandscapeMode", CreateJsValue(env, config.showInLandscapeMode_)); + napi_set_named_property(env, objValue, "immersiveStatusBarBgColor", + CreateJsValue(env, config.immersiveStatusBarBgColor_)); + napi_set_named_property(env, objValue, "immersiveStatusBarContentColor", + CreateJsValue(env, config.immersiveStatusBarContentColor_)); + return objValue; +} + JsWindowSceneConfig::JsWindowSceneConfig() { WLOGFD("Construct JsWindowSceneConfig"); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_window_scene_config.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_window_scene_config.h index 5843630862..5caa8cedc8 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_window_scene_config.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_window_scene_config.h @@ -35,6 +35,7 @@ private: static napi_value CreateShadowValue(napi_env env, const AppWindowSceneConfig& config, bool focused); static napi_value CreateKeyboardAnimationValue(napi_env env, const KeyboardSceneAnimationConfig& config); static napi_value CreateWindowAnimationValue(napi_env env, const AppWindowSceneConfig& config); + static napi_value CreateSystemUIStatusBarValue(napi_env env, const SystemUIStatusBarConfig& config); }; } // namespace OHOS::Rosen diff --git a/window_scene/interfaces/kits/napi/session_manager_service/BUILD.gn b/window_scene/interfaces/kits/napi/session_manager_service/BUILD.gn index 87fba84088..0a86f2ee87 100644 --- a/window_scene/interfaces/kits/napi/session_manager_service/BUILD.gn +++ b/window_scene/interfaces/kits/napi/session_manager_service/BUILD.gn @@ -28,6 +28,7 @@ ohos_shared_library("sessionmanagerservice_napi") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ diff --git a/window_scene/interfaces/kits/napi/transaction_manager/BUILD.gn b/window_scene/interfaces/kits/napi/transaction_manager/BUILD.gn index 2226264c1d..0911a57c72 100644 --- a/window_scene/interfaces/kits/napi/transaction_manager/BUILD.gn +++ b/window_scene/interfaces/kits/napi/transaction_manager/BUILD.gn @@ -25,6 +25,7 @@ ohos_shared_library("transactionmanager_napi") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ @@ -46,6 +47,7 @@ ohos_shared_library("transactionmanager_napi") { "ability_runtime:app_manager", "ability_runtime:runtime", "c_utils:utils", + "ffrt:libffrt", "graphic_2d:librender_service_client", "hilog:libhilog", "napi:ace_napi", diff --git a/window_scene/screen_session_manager/BUILD.gn b/window_scene/screen_session_manager/BUILD.gn index 8f472cc1bd..61a7be44e9 100644 --- a/window_scene/screen_session_manager/BUILD.gn +++ b/window_scene/screen_session_manager/BUILD.gn @@ -32,6 +32,7 @@ ohos_shared_library("screen_session_manager_client") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ diff --git a/window_scene/screen_session_manager/src/zidl/screen_session_manager_client_proxy.cpp b/window_scene/screen_session_manager/src/zidl/screen_session_manager_client_proxy.cpp index 4f38cc8f33..014aec7492 100644 --- a/window_scene/screen_session_manager/src/zidl/screen_session_manager_client_proxy.cpp +++ b/window_scene/screen_session_manager/src/zidl/screen_session_manager_client_proxy.cpp @@ -109,7 +109,12 @@ void ScreenSessionManagerClientProxy::OnPowerStatusChanged(DisplayPowerEvent eve WLOGFE("Write reason failed"); return; } - if (Remote()->SendRequest( + auto remote = Remote(); + if (remote == nullptr) { + WLOGFE("SendRequest failed, Remote is nullptr"); + return; + } + if (remote->SendRequest( static_cast(ScreenSessionManagerClientMessage::TRANS_ID_ON_POWER_STATUS_CHANGED), data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); diff --git a/window_scene/session/BUILD.gn b/window_scene/session/BUILD.gn index bfc98f451f..99ab2b5001 100755 --- a/window_scene/session/BUILD.gn +++ b/window_scene/session/BUILD.gn @@ -37,6 +37,7 @@ ohos_shared_library("scene_session") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ @@ -69,14 +70,11 @@ ohos_shared_library("scene_session") { "${window_base_path}/utils:libwmutil_base", "${window_base_path}/window_scene/common:window_scene_common", "${window_base_path}/window_scene/intention_event/service:intention_event_anr_manager", + "${window_base_path}/window_scene/interfaces/innerkits:libwsutils", "${window_base_path}/window_scene/screen_session_manager:screen_session_manager_client", "${window_base_path}/window_scene/session:screen_session", ] - # for ability_runtime used - public_deps = - [ "${window_base_path}/window_scene/interfaces/innerkits:libwsutils" ] - external_deps = [ "ability_base:base", "ability_base:session_info", @@ -141,6 +139,7 @@ ohos_shared_library("screen_session") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ diff --git a/window_scene/session/container/include/zidl/session_stage_interface.h b/window_scene/session/container/include/zidl/session_stage_interface.h index a25ab9c064..87f24d7f7c 100644 --- a/window_scene/session/container/include/zidl/session_stage_interface.h +++ b/window_scene/session/container/include/zidl/session_stage_interface.h @@ -113,6 +113,7 @@ public: { return WSError::WS_OK; } + virtual void NotifyKeyboardPanelInfoChange(const KeyboardPanelInfo& keyboardPanelInfo) {} }; } // namespace OHOS::Rosen #endif // OHOS_WINDOW_SCENE_SESSION_STAGE_INTERFACE_H diff --git a/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h b/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h index 42a2f7e329..7050e97c56 100644 --- a/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h +++ b/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h @@ -49,6 +49,7 @@ enum class SessionStageInterfaceCode { TRANS_ID_NOTIFY_DISPLAYID_CHANGE, TRANS_ID_NOTIFY_DISPLAY_MOVE, TRANS_ID_NOTIFY_SWITCH_FREEMULTIWINDOW, + TRANS_ID_NOTIFY_KEYBOARD_INFO_CHANGE, }; } // namespace Rosen } // namespace OHOS diff --git a/window_scene/session/container/include/zidl/session_stage_proxy.h b/window_scene/session/container/include/zidl/session_stage_proxy.h index 1b839f6caa..69b7686eca 100644 --- a/window_scene/session/container/include/zidl/session_stage_proxy.h +++ b/window_scene/session/container/include/zidl/session_stage_proxy.h @@ -59,6 +59,7 @@ public: WSError UpdateDisplayId(uint64_t displayId) override; void NotifyDisplayMove(DisplayId from, DisplayId to) override; WSError SwitchFreeMultiWindow(bool enable) override; + void NotifyKeyboardPanelInfoChange(const KeyboardPanelInfo& keyboardPanelInfo) override; private: static inline BrokerDelegator delegator_; diff --git a/window_scene/session/container/include/zidl/session_stage_stub.h b/window_scene/session/container/include/zidl/session_stage_stub.h index 7d67d0a40a..d76d33e039 100644 --- a/window_scene/session/container/include/zidl/session_stage_stub.h +++ b/window_scene/session/container/include/zidl/session_stage_stub.h @@ -64,6 +64,7 @@ private: int HandleUpdateDisplayId(MessageParcel& data, MessageParcel& reply); int HandleNotifyDisplayMove(MessageParcel& data, MessageParcel& reply); int HandleSwitchFreeMultiWindow(MessageParcel& data, MessageParcel& reply); + int HandleNotifyKeyboardPanelInfoChange(MessageParcel& data, MessageParcel& reply); }; } // namespace OHOS::Rosen #endif // OHOS_WINDOW_SCENE_SESSION_STAGE_STUB_H diff --git a/window_scene/session/container/src/zidl/session_stage_proxy.cpp b/window_scene/session/container/src/zidl/session_stage_proxy.cpp index af0e4eab2c..b1f312dd25 100644 --- a/window_scene/session/container/src/zidl/session_stage_proxy.cpp +++ b/window_scene/session/container/src/zidl/session_stage_proxy.cpp @@ -681,4 +681,25 @@ void SessionStageProxy::NotifyDisplayMove(DisplayId from, DisplayId to) } } +void SessionStageProxy::NotifyKeyboardPanelInfoChange(const KeyboardPanelInfo& keyboardPanelInfo) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed"); + return; + } + + if (!data.WriteParcelable(&keyboardPanelInfo)) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "KeyboardPanelInfo marshalling failed"); + return; + } + + if (Remote()->SendRequest(static_cast(SessionStageInterfaceCode::TRANS_ID_NOTIFY_KEYBOARD_INFO_CHANGE), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest notify keyboard panel info change failed"); + return; + } +} } // namespace OHOS::Rosen diff --git a/window_scene/session/container/src/zidl/session_stage_stub.cpp b/window_scene/session/container/src/zidl/session_stage_stub.cpp index fe231769b1..31f6e88802 100644 --- a/window_scene/session/container/src/zidl/session_stage_stub.cpp +++ b/window_scene/session/container/src/zidl/session_stage_stub.cpp @@ -81,6 +81,8 @@ const std::map SessionStageStub::stubFuncMap_{ &SessionStageStub::HandleNotifyDisplayMove), std::make_pair(static_cast(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SWITCH_FREEMULTIWINDOW), &SessionStageStub::HandleSwitchFreeMultiWindow), + std::make_pair(static_cast(SessionStageInterfaceCode::TRANS_ID_NOTIFY_KEYBOARD_INFO_CHANGE), + &SessionStageStub::HandleNotifyKeyboardPanelInfoChange), }; int SessionStageStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -376,6 +378,20 @@ int SessionStageStub::HandleSwitchFreeMultiWindow(MessageParcel& data, MessagePa bool enable = data.ReadBool(); WSError errCode = SwitchFreeMultiWindow(enable); reply.WriteInt32(static_cast(errCode)); + + return ERR_NONE; +} + +int SessionStageStub::HandleNotifyKeyboardPanelInfoChange(MessageParcel& data, MessageParcel& reply) +{ + TLOGD(WmsLogTag::WMS_KEYBOARD, "HandleNotifyKeyboardPanelInfoChange!"); + sptr keyboardPanelInfo = data.ReadParcelable(); + if (keyboardPanelInfo == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "keyboardPanelInfo is nullptr!"); + return ERR_INVALID_VALUE; + } + NotifyKeyboardPanelInfoChange(*keyboardPanelInfo); + return ERR_NONE; } } // namespace OHOS::Rosen diff --git a/window_scene/session/host/include/keyboard_session.h b/window_scene/session/host/include/keyboard_session.h index 4a138b1a13..ccb58e1dac 100644 --- a/window_scene/session/host/include/keyboard_session.h +++ b/window_scene/session/host/include/keyboard_session.h @@ -39,6 +39,10 @@ public: WSError Hide() override; WSError Disconnect(bool isFromClient = false) override; WSError NotifyClientToUpdateRect(std::shared_ptr rsTransaction) override; + void BindKeyboardPanelSession(sptr panelSession) override; + sptr GetKeyboardPanelSession() const override; + SessionGravity GetKeyboardGravity() const override; + void OnKeyboardPanelUpdated() override; private: sptr GetSceneSession(uint32_t persistentId); @@ -46,22 +50,21 @@ private: WSError SetKeyboardSessionGravity(SessionGravity gravity, uint32_t percent) override; void SetCallingSessionId(uint32_t callingSessionId) override; - sptr GetCallingSession(); + uint32_t GetCallingSessionId(); bool IsStatusBarVisible(const sptr& session); int32_t GetStatusBarHeight(); void NotifyOccupiedAreaChangeInfo(const sptr& callingSession, const WSRect& rect, const WSRect& occupiedArea); - void RaiseCallingSession(bool isKeyboardUpdated = false); + void RaiseCallingSession(); void RestoreCallingSession(); void UseFocusIdIfCallingSessionIdInvalid(); - void OnKeyboardSessionShown(); void UpdateCallingSessionIdAndPosition(uint32_t callingSessionId); void RelayoutKeyBoard(); + void NotifyKeyboardPanelInfoChange(WSRect rect, bool isKeyboardPanelShow); + bool CheckIfNeedRaiseCallingSession(sptr callingSession, bool isCallingSessionFloating); sptr keyboardCallback_ = nullptr; - WSRect callingSessionRestoringRect_ = {0, 0, 0, 0}; - WSRect callingSessionRaisedRect_ = {0, 0, 0, 0}; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_KEYBOARD_SESSION_H \ No newline at end of file diff --git a/window_scene/session/host/include/scb_system_session.h b/window_scene/session/host/include/scb_system_session.h index 6bce13cf00..0a12b4e0f3 100644 --- a/window_scene/session/host/include/scb_system_session.h +++ b/window_scene/session/host/include/scb_system_session.h @@ -19,6 +19,7 @@ #include "session/host/include/scene_session.h" namespace OHOS::Rosen { +using KeyboardPanelRectUpdateCallback = std::function; class SCBSystemSession : public SceneSession { public: SCBSystemSession(const SessionInfo& info, const sptr& specificCallback); @@ -32,9 +33,15 @@ public: WSError UpdateFocus(bool isFocused) override; WSError UpdateWindowMode(WindowMode mode) override; WSError SetSystemSceneBlockingFocus(bool blocking) override; + void BindKeyboardSession(sptr session) override; + sptr GetKeyboardSession() const override; + void SetKeyboardPanelRectUpdateCallback(const KeyboardPanelRectUpdateCallback& func); protected: void UpdatePointerArea(const WSRect& rect) override; + +private: + KeyboardPanelRectUpdateCallback keyboardPanelRectUpdateCallback_; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SCB_SYSTEM_SESSION_H diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index da9a055117..d6b8a0d6c2 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -63,7 +63,7 @@ using NotifyTouchOutsideFunc = std::function; using ClearCallbackMapFunc = std::function; using NotifyPrepareClosePiPSessionFunc = std::function; using OnOutsideDownEvent = std::function; -using NotifyAddOrRemoveSecureSessionFunc = std::function& sceneSession)>; +using HandleSecureSessionShouldHideCallback = std::function& sceneSession)>; using CameraSessionChangeCallback = std::function; using NotifyLandscapeMultiWindowSessionFunc = std::function; using NotifyKeyboardGravityChangeFunc = std::function; @@ -81,7 +81,7 @@ public: NotifySessionTouchOutsideCallback onSessionTouchOutside_; GetAINavigationBarArea onGetAINavigationBarArea_; OnOutsideDownEvent onOutsideDownEvent_; - NotifyAddOrRemoveSecureSessionFunc onHandleSecureSessionShouldHide_; + HandleSecureSessionShouldHideCallback onHandleSecureSessionShouldHide_; CameraSessionChangeCallback onCameraSessionChange_; }; @@ -125,6 +125,12 @@ public: WSError Foreground(sptr property) override; WSError Background() override; WSError Disconnect(bool isFromClient = false) override; + virtual void BindKeyboardPanelSession(sptr panelSession) {}; + virtual sptr GetKeyboardPanelSession() const { return nullptr; }; + virtual void BindKeyboardSession(sptr session) {}; + virtual sptr GetKeyboardSession() const { return nullptr; }; + virtual SessionGravity GetKeyboardGravity() const { return SessionGravity::SESSION_GRAVITY_DEFAULT; }; + virtual void OnKeyboardPanelUpdated() {}; WSError UpdateActiveStatus(bool isActive) override; WSError OnSessionEvent(SessionEvent event) override; @@ -180,6 +186,8 @@ public: void SetAbilitySessionInfo(std::shared_ptr abilityInfo); void SetWindowDragHotAreaListener(const NotifyWindowDragHotAreaFunc& func); void SetSessionRectChangeCallback(const NotifySessionRectChangeFunc& func); + void SetIsDisplayStatusBarTemporarily(bool isTemporary); + void SetRestoringRectForKeyboard(WSRect rect); int32_t GetCollaboratorType() const; sptr GetSelfToken() const; @@ -194,6 +202,7 @@ public: std::shared_ptr GetAbilityInfo() const; const std::string& GetWindowNameAllType() const; PiPTemplateInfo GetPiPTemplateInfo() const; + WSRect GetRestoringRectForKeyboard() const; bool IsVisible() const; bool IsDecorEnable() const; @@ -207,6 +216,7 @@ public: void NotifyUILostFocus() override; void SetSystemTouchable(bool touchable) override; bool IsVisibleForAccessibility() const; + bool GetIsDisplayStatusBarTemporarily() const; WSError UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) override; WSError OnShowWhenLocked(bool showWhenLocked); @@ -230,13 +240,12 @@ public: bool SendKeyEventToUI(std::shared_ptr keyEvent, bool isPreImeEvent = false); bool IsStartMoving() const; void SetIsStartMoving(const bool startMoving); - bool ShouldHideNonSecureWindows() const; void SetShouldHideNonSecureWindows(bool shouldHide); - WSError AddOrRemoveSecureExtSession(int32_t persistentId, bool shouldHide); WSError SetPipActionEvent(const std::string& action, int32_t status); - void UpdateExtWindowFlags(int32_t extPersistentId, uint32_t extWindowFlags); - bool IsExtWindowHasWaterMarkFlag(); - void RomoveExtWindowFlags(int32_t extPersistentId); + void UpdateExtWindowFlags(int32_t extPersistentId, const ExtensionWindowFlags& extWindowFlags, + const ExtensionWindowFlags& extWindowActions); + ExtensionWindowFlags GetCombinedExtWindowFlags() const; + void RemoveExtWindowFlags(int32_t extPersistentId); void ClearExtWindowFlags(); void NotifyDisplayMove(DisplayId from, DisplayId to); @@ -252,6 +261,15 @@ public: WSError UpdateRectChangeListenerRegistered(bool isRegister) override; void SetForceHideState(bool hideFlag); bool GetForceHideState() const; + int32_t GetCustomDecorHeight() override + { + return customDecorHeight_; + } + + void SetCustomDecorHeight(int32_t height) override + { + customDecorHeight_ = height; + } protected: void NotifyIsCustomAnimationPlaying(bool isPlaying); @@ -266,11 +284,11 @@ protected: + to_string(rect.posX_) + ", " + to_string(rect.posY_) + "]"; } - mutable std::shared_mutex sessionChangeCallbackMutex_; sptr specificCallback_ = nullptr; sptr sessionChangeCallback_ = nullptr; - mutable std::shared_mutex moveDragControllerMutex_; sptr moveDragController_ = nullptr; + sptr keyboardPanelSession_ = nullptr; + sptr keyboardSession_ = nullptr; private: void NotifyAccessibilityVisibilityChange(); @@ -278,6 +296,7 @@ private: void GetSystemAvoidArea(WSRect& rect, AvoidArea& avoidArea); void GetCutoutAvoidArea(WSRect& rect, AvoidArea& avoidArea); void GetKeyboardAvoidArea(WSRect& rect, AvoidArea& avoidArea); + void CalculateCombinedExtWindowFlags(); void GetAINavigationBarArea(WSRect rect, AvoidArea& avoidArea); void HandleStyleEvent(MMI::WindowArea area) override; WSError HandleEnterWinwdowArea(int32_t windowX, int32_t windowY); @@ -294,12 +313,13 @@ private: void UpdateWinRectForSystemBar(WSRect& rect); bool UpdateInputMethodSessionRect(const WSRect& rect, WSRect& newWinRect, WSRect& newRequestRect); void HandleCastScreenConnection(SessionInfo& info, sptr session); - + void FixKeyboardPositionByKeyboardPanel(sptr panelSession, sptr keyboardSession); + NotifySessionRectChangeFunc sessionRectChangeFunc_; static wptr enterSession_; static std::mutex enterSessionMutex_; + mutable std::mutex sessionChangeCbMutex_; int32_t collaboratorType_ = CollaboratorType::DEFAULT_TYPE; - mutable std::shared_mutex selfTokenMutex_; sptr selfToken_ = nullptr; WSRect lastSafeRect = { 0, 0, 0, 0 }; std::vector> subSession_; @@ -307,10 +327,13 @@ private: PiPTemplateInfo pipTemplateInfo_; std::atomic_bool isStartMoving_ { false }; std::atomic_bool isVisibleForAccessibility_ { true }; + std::atomic_bool isDisplayStatusBarTemporarily_ { false }; std::atomic_bool shouldHideNonSecureWindows_ { false }; - std::set secureExtSessionSet_; - std::map extWindowFlagsMap_; + ExtensionWindowFlags combinedExtWindowFlags_ { 0 }; + std::map extWindowFlagsMap_; bool forceHideState_ = false; + int32_t customDecorHeight_ = 0; + WSRect restoringRectForKeyboard_ = {0, 0, 0, 0}; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H \ No newline at end of file diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index 4e735e1886..b74b76ee5f 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -96,12 +96,23 @@ enum class LifeCycleTaskType : uint32_t { STOP }; +enum class DetectTaskState : uint32_t { + NO_TASK, + ATTACH_TASK, + DETACH_TASK +}; + +struct DetectTaskInfo { + WindowMode taskWindowMode = WindowMode::WINDOW_MODE_UNDEFINED; + DetectTaskState taskState = DetectTaskState::NO_TASK; +}; + class Session : public SessionStub { public: using Task = std::function; explicit Session(const SessionInfo& info); virtual ~Session() = default; - + bool isKeyboardPanelEnabled_ = false; void SetEventHandler(const std::shared_ptr& handler, const std::shared_ptr& exportHandler = nullptr); @@ -380,7 +391,8 @@ public: bool GetForegroundInteractiveStatus() const; virtual void SetForegroundInteractiveStatus(bool interactive); void RegisterWindowModeChangedCallback(const std::function& callback); - void SetAttachState(bool isAttach); + void SetAttachState(bool isAttach, WindowMode windowMode = WindowMode::WINDOW_MODE_UNDEFINED); + bool GetAttachState() const; void RegisterDetachCallback(const sptr& callback); void RegisterWindowBackHomeCallback(const std::function& callback) {}; SystemSessionConfig GetSystemConfig() const; @@ -388,7 +400,17 @@ public: virtual void RectCheck(uint32_t curWidth, uint32_t curHeight) {}; void RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeight, uint32_t minWidth, uint32_t minHeight, uint32_t maxFloatingWindowSize); + DetectTaskInfo GetDetectTaskInfo() const; + void SetDetectTaskInfo(const DetectTaskInfo& detectTaskInfo); + void CreateWindowStateDetectTask(bool isAttach, WindowMode windowMode); + void RegisterIsScreenLockedCallback(const std::function& callback); + std::string GetWindowDetectTaskName() const; + void RemoveWindowDetectTask(); WSError SwitchFreeMultiWindow(bool enable); + virtual int32_t GetCustomDecorHeight() + { + return 0; + }; protected: class SessionLifeCycleTask : public virtual RefBase { @@ -438,7 +460,7 @@ protected: } int32_t persistentId_ = INVALID_SESSION_ID; - SessionState state_ = SessionState::STATE_DISCONNECT; + std::atomic state_ = SessionState::STATE_DISCONNECT; SessionInfo sessionInfo_; std::recursive_mutex sessionInfoMutex_; std::shared_ptr surfaceNode_; @@ -504,7 +526,6 @@ protected: float pivotY_ = 0.0f; mutable std::shared_mutex dialogVecMutex_; std::vector> dialogVec_; - mutable std::shared_mutex parentSessionMutex_; sptr parentSession_; sptr windowEventChannel_; @@ -523,7 +544,11 @@ private: bool RegisterListenerLocked(std::vector>& holder, const std::shared_ptr& listener); template bool UnregisterListenerLocked(std::vector>& holder, const std::shared_ptr& listener); - + bool IsStateMatch(bool isAttach) const; + bool IsSupportDetectWindow(bool isAttach); + bool ShouldCreateDetectTask(bool isAttach, WindowMode windowMode) const; + bool ShouldCreateDetectTaskInRecent(bool newShowRecent, bool oldShowRecent, bool isAttach) const; + void CreateDetectStateTask(bool isAttach, WindowMode windowMode); template using EnableIfSame = typename std::enable_if, Ret>::type; template @@ -544,6 +569,7 @@ private: std::shared_ptr handler_; std::shared_ptr exportHandler_; std::function windowModeCallback_; + std::function isScreenLockedCallback_; mutable std::shared_mutex propertyMutex_; sptr property_; @@ -567,11 +593,13 @@ private: bool forceTouchable_ { true }; bool systemTouchable_ { true }; std::atomic_bool foregroundInteractiveStatus_ { true }; - bool isAttach_{ false }; + std::atomic isAttach_{ false }; sptr detachCallback_ = nullptr; std::shared_ptr leashWinSurfaceNode_; mutable std::mutex leashWinSurfaceNodeMutex; + DetectTaskInfo detectTaskInfo_; + mutable std::shared_mutex detectTaskInfoMutex_; }; } // namespace OHOS::Rosen diff --git a/window_scene/session/host/include/system_session.h b/window_scene/session/host/include/system_session.h index 4b72a6ad91..9b30398e6a 100644 --- a/window_scene/session/host/include/system_session.h +++ b/window_scene/session/host/include/system_session.h @@ -41,7 +41,8 @@ public: void RectCheck(uint32_t curWidth, uint32_t curHeight) override; protected: bool CheckKeyEventDispatch(const std::shared_ptr& keyEvent) const; - + void UpdatePointerArea(const WSRect& rect) override; + bool CheckPointerEventDispatch(const std::shared_ptr& pointerEvent) const override; private: void UpdateCameraWindowStatus(bool isShowing); bool NeedSystemPermission(WindowType type); diff --git a/window_scene/session/host/include/zidl/session_interface.h b/window_scene/session/host/include/zidl/session_interface.h index d6cfb9d90c..c572d0e5e1 100644 --- a/window_scene/session/host/include/zidl/session_interface.h +++ b/window_scene/session/host/include/zidl/session_interface.h @@ -103,6 +103,7 @@ public: return WSError::WS_OK; } virtual void SetCallingSessionId(uint32_t callingSessionId) {}; + virtual void SetCustomDecorHeight(int32_t height) {}; }; } // namespace OHOS::Rosen diff --git a/window_scene/session/host/include/zidl/session_ipc_interface_code.h b/window_scene/session/host/include/zidl/session_ipc_interface_code.h index 31a3c78579..ee501f26e7 100644 --- a/window_scene/session/host/include/zidl/session_ipc_interface_code.h +++ b/window_scene/session/host/include/zidl/session_ipc_interface_code.h @@ -54,6 +54,7 @@ enum class SessionInterfaceCode { TRANS_ID_UPDATE_RECTCHANGE_LISTENER_REGISTERED, TRANS_ID_SET_KEYBOARD_SESSION_GRAVITY, TRANS_ID_SET_CALLING_SESSION_ID, + TRANS_ID_SET_CUSTOM_DECOR_HEIGHT, // Extension TRANS_ID_TRANSFER_ABILITY_RESULT = 500, diff --git a/window_scene/session/host/include/zidl/session_proxy.h b/window_scene/session/host/include/zidl/session_proxy.h index 2f579ab709..65f4b7e50c 100644 --- a/window_scene/session/host/include/zidl/session_proxy.h +++ b/window_scene/session/host/include/zidl/session_proxy.h @@ -78,6 +78,8 @@ public: WSError UpdateRectChangeListenerRegistered(bool isRegister) override; WSError SetKeyboardSessionGravity(SessionGravity gravity, uint32_t percent) override; void SetCallingSessionId(uint32_t callingSessionId) override; + void SetCustomDecorHeight(int32_t height) override; + private: static inline BrokerDelegator delegator_; }; diff --git a/window_scene/session/host/include/zidl/session_stub.h b/window_scene/session/host/include/zidl/session_stub.h index 080f5431f9..6f2aa6aa54 100644 --- a/window_scene/session/host/include/zidl/session_stub.h +++ b/window_scene/session/host/include/zidl/session_stub.h @@ -68,6 +68,7 @@ private: int HandleUpdateRectChangeListenerRegistered(MessageParcel& data, MessageParcel& reply); int HandleSetKeyboardSessionGravity(MessageParcel& data, MessageParcel& reply); int HandleSetCallingSessionId(MessageParcel& data, MessageParcel& reply); + int HandleSetCustomDecorHeight(MessageParcel& data, MessageParcel& reply); // extension extension int HandleTransferAbilityResult(MessageParcel& data, MessageParcel& reply); diff --git a/window_scene/session/host/src/keyboard_session.cpp b/window_scene/session/host/src/keyboard_session.cpp index bf57d13476..b4abf71560 100644 --- a/window_scene/session/host/src/keyboard_session.cpp +++ b/window_scene/session/host/src/keyboard_session.cpp @@ -38,6 +38,32 @@ KeyboardSession::~KeyboardSession() TLOGI(WmsLogTag::WMS_KEYBOARD, "~KeyboardSession"); } +void KeyboardSession::BindKeyboardPanelSession(sptr panelSession) +{ + if (panelSession == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "panelSession is nullptr"); + return; + } + keyboardPanelSession_ = panelSession; + TLOGI(WmsLogTag::WMS_KEYBOARD, "Success, panelId: %{public}d", panelSession->GetPersistentId()); +} + +sptr KeyboardSession::GetKeyboardPanelSession() const +{ + return keyboardPanelSession_; +} + +SessionGravity KeyboardSession::GetKeyboardGravity() const +{ + SessionGravity gravity = SessionGravity::SESSION_GRAVITY_DEFAULT; + uint32_t percent = 0; + if (GetSessionProperty()) { + GetSessionProperty()->GetSessionGravity(gravity, percent); + } + TLOGI(WmsLogTag::WMS_KEYBOARD, "gravity: %{public}d", gravity); + return gravity; +} + WSError KeyboardSession::Show(sptr property) { auto task = [weakThis = wptr(this), property]() { @@ -47,9 +73,13 @@ WSError KeyboardSession::Show(sptr property) return WSError::WS_ERROR_DESTROYED_OBJECT; } - TLOGI(WmsLogTag::WMS_KEYBOARD, "Show keyboard session, id: %{public}d", session->GetPersistentId()); auto ret = session->SceneSession::Foreground(property); - session->OnKeyboardSessionShown(); + session->UseFocusIdIfCallingSessionIdInvalid(); + TLOGI(WmsLogTag::WMS_KEYBOARD, "Show keyboard session, id: %{public}d, calling session id: %{public}d", + session->GetPersistentId(), session->GetCallingSessionId()); + if (!session->isKeyboardPanelEnabled_) { + session->RaiseCallingSession(); + } return ret; }; PostTask(task, "Show"); @@ -73,6 +103,8 @@ WSError KeyboardSession::Hide() return ret; } ret = session->SceneSession::Background(); + WSRect rect = {0, 0, 0, 0}; + session->NotifyKeyboardPanelInfoChange(rect, false); session->RestoreCallingSession(); if (session->GetSessionProperty()) { session->GetSessionProperty()->SetCallingSessionId(INVALID_WINDOW_ID); @@ -94,6 +126,8 @@ WSError KeyboardSession::Disconnect(bool isFromClient) TLOGI(WmsLogTag::WMS_KEYBOARD, "Disconnect keyboard session, id: %{public}d, isFromClient: %{public}d", session->GetPersistentId(), isFromClient); session->SceneSession::Disconnect(isFromClient); + WSRect rect = {0, 0, 0, 0}; + session->NotifyKeyboardPanelInfoChange(rect, false); session->RestoreCallingSession(); if (session->GetSessionProperty()) { session->GetSessionProperty()->SetCallingSessionId(INVALID_WINDOW_ID); @@ -112,9 +146,11 @@ WSError KeyboardSession::NotifyClientToUpdateRect(std::shared_ptr if (ret != WSError::WS_OK) { return ret; } - session->RaiseCallingSession(true); - if (session->specificCallback_ != nullptr && session->specificCallback_->onUpdateAvoidArea_ != nullptr) { - session->specificCallback_->onUpdateAvoidArea_(session->GetPersistentId()); + if (!session->isKeyboardPanelEnabled_) { + session->RaiseCallingSession(); + if (session->specificCallback_ != nullptr && session->specificCallback_->onUpdateAvoidArea_ != nullptr) { + session->specificCallback_->onUpdateAvoidArea_(session->GetPersistentId()); + } } if (session->reason_ != SizeChangeReason::DRAG) { session->reason_ = SizeChangeReason::UNDEFINED; @@ -126,6 +162,19 @@ WSError KeyboardSession::NotifyClientToUpdateRect(std::shared_ptr return WSError::WS_OK; } +void KeyboardSession::OnKeyboardPanelUpdated() +{ + if (!isKeyboardPanelEnabled_) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "KeyboardPanel is not enabled"); + return; + } + TLOGI(WmsLogTag::WMS_KEYBOARD, "id: %{public}d", GetPersistentId()); + RaiseCallingSession(); + if (specificCallback_ != nullptr && specificCallback_->onUpdateAvoidArea_ != nullptr) { + specificCallback_->onUpdateAvoidArea_(GetPersistentId()); + } +} + WSError KeyboardSession::SetKeyboardSessionGravity(SessionGravity gravity, uint32_t percent) { auto task = [weakThis = wptr(this), gravity, percent]() -> WSError { @@ -151,7 +200,7 @@ WSError KeyboardSession::SetKeyboardSessionGravity(SessionGravity gravity, uint3 } } else { session->SetWindowAnimationFlag(true); - if (session->IsSessionForeground()) { + if (session->IsSessionForeground() && !session->isKeyboardPanelEnabled_) { session->RaiseCallingSession(); } } @@ -165,13 +214,21 @@ void KeyboardSession::SetCallingSessionId(uint32_t callingSessionId) { TLOGI(WmsLogTag::WMS_KEYBOARD, "Calling session id: %{public}d", callingSessionId); UpdateCallingSessionIdAndPosition(callingSessionId); - if (keyboardCallback_ == nullptr || keyboardCallback_->onCallingSessionIdChange_ == nullptr || - GetSessionProperty() == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "KeyboardCallback_ or sessionProperty is null, callingSessionId: %{public}d", + if (keyboardCallback_ == nullptr || keyboardCallback_->onCallingSessionIdChange_ == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "KeyboardCallback_, callingSessionId: %{public}d", callingSessionId); return; } - keyboardCallback_->onCallingSessionIdChange_(GetSessionProperty()->GetCallingSessionId()); + keyboardCallback_->onCallingSessionIdChange_(GetCallingSessionId()); +} + +uint32_t KeyboardSession::GetCallingSessionId() +{ + if (GetSessionProperty() == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Session property is null"); + return INVALID_SESSION_ID; + } + return GetSessionProperty()->GetCallingSessionId(); } sptr KeyboardSession::GetSceneSession(uint32_t persistentId) @@ -253,103 +310,129 @@ void KeyboardSession::NotifyOccupiedAreaChangeInfo(const sptr& cal callingSession->NotifyOccupiedAreaChangeInfo(info); } -sptr KeyboardSession::GetCallingSession() +void KeyboardSession::NotifyKeyboardPanelInfoChange(WSRect rect, bool isKeyboardPanelShow) { - sptr callingSession = nullptr; - if (GetSessionProperty() != nullptr) { - callingSession = GetSceneSession(GetSessionProperty()->GetCallingSessionId()); + if (!isKeyboardPanelEnabled_) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "KeyboardPanel is not enabled"); + return; } + if (!sessionStage_) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "sessionStage_ is nullptr, notify keyboard panel rect change failed"); + return; + } + KeyboardPanelInfo keyboardPanelInfo; + keyboardPanelInfo.rect_ = SessionHelper::TransferToRect(rect); + keyboardPanelInfo.gravity_ = static_cast(GetKeyboardGravity()); + keyboardPanelInfo.isShowing_ = isKeyboardPanelShow; - return callingSession; + sessionStage_->NotifyKeyboardPanelInfoChange(keyboardPanelInfo); } -void KeyboardSession::RaiseCallingSession(bool isKeyboardUpdated) +bool KeyboardSession::CheckIfNeedRaiseCallingSession(sptr callingSession, bool isCallingSessionFloating) { - sptr callingSession = GetCallingSession(); if (callingSession == nullptr) { TLOGI(WmsLogTag::WMS_KEYBOARD, "Calling session is nullptr"); - return; - } - SessionGravity gravity = SessionGravity::SESSION_GRAVITY_DEFAULT; - uint32_t percent = 0; - GetSessionProperty()->GetSessionGravity(gravity, percent); - if (gravity == SessionGravity::SESSION_GRAVITY_FLOAT) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "No need to raise calling session, gravity: %{public}d", gravity); - return; + return false; } - WSRect callingSessionRect = callingSession->GetSessionRect(); - bool isCallingSessionFloating = (callingSession->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING); + SessionGravity gravity = GetKeyboardGravity(); + if (gravity == SessionGravity::SESSION_GRAVITY_FLOAT) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "No need to raise calling session, gravity: %{public}d", gravity); + return false; + } bool isMainOrParentFloating = WindowHelper::IsMainWindow(callingSession->GetWindowType()) || (WindowHelper::IsSubWindow(callingSession->GetWindowType()) && callingSession->GetParentSession() != nullptr && callingSession->GetParentSession()->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING); if (isCallingSessionFloating && isMainOrParentFloating && (system::GetParameter("const.product.devicetype", "unknown") == "phone" || system::GetParameter("const.product.devicetype", "unknown") == "tablet")) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "No need to raise calling session in float window."); + return false; + } + + return true; +} + +void KeyboardSession::RaiseCallingSession() +{ + sptr callingSession = GetSceneSession(GetCallingSessionId()); + if (callingSession == nullptr) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "Calling session is nullptr"); return; } - - if (isKeyboardUpdated && isCallingSessionFloating) { - callingSessionRect = callingSessionRestoringRect_; + WSRect keyboardPanelRect = {0, 0, 0, 0}; + if (!isKeyboardPanelEnabled_) { + keyboardPanelRect = (GetSessionRect().height_ != 0) ? GetSessionRect() : GetSessionRequestRect(); + } else if (keyboardPanelSession_ != nullptr) { + keyboardPanelRect = keyboardPanelSession_->GetSessionRect(); + NotifyKeyboardPanelInfoChange(keyboardPanelRect, true); } - const WSRect& keyboardSessionRect = (GetSessionRect().height_ != 0) ? GetSessionRect() : GetSessionRequestRect(); - if (SessionHelper::IsEmptyRect(SessionHelper::GetOverlap(keyboardSessionRect, callingSessionRect, 0, 0))) { - TLOGI(WmsLogTag::WMS_KEYBOARD, "No overlap area, keyboardRect: %{public}s, callingSessionRect: %{public}s", - keyboardSessionRect.ToString().c_str(), callingSessionRect.ToString().c_str()); + + bool isCallingSessionFloating = (callingSession->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING); + if (!CheckIfNeedRaiseCallingSession(callingSession, isCallingSessionFloating)) { return; } - if (!isKeyboardUpdated) { - callingSessionRestoringRect_ = callingSessionRect; + WSRect callingSessionRect = callingSession->GetSessionRect(); + WSRect callingSessionRestoringRect = callingSession->GetRestoringRectForKeyboard(); + if (!SessionHelper::IsEmptyRect(callingSessionRestoringRect) && isCallingSessionFloating) { + callingSessionRect = callingSessionRestoringRect; + } + if (SessionHelper::IsEmptyRect(SessionHelper::GetOverlap(keyboardPanelRect, callingSessionRect, 0, 0)) && + SessionHelper::IsEmptyRect(callingSessionRestoringRect)) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "No overlap area, keyboardRect: %{public}s, callingRect: %{public}s", + keyboardPanelRect.ToString().c_str(), callingSessionRect.ToString().c_str()); + return; + } + if (SessionHelper::IsEmptyRect(callingSessionRestoringRect)) { + callingSessionRestoringRect = callingSessionRect; + callingSession->SetRestoringRectForKeyboard(callingSessionRect); } WSRect newRect = callingSessionRect; int32_t statusHeight = GetStatusBarHeight(); if (isCallingSessionFloating && callingSessionRect.posY_ > statusHeight) { - // calculate new rect of calling window - newRect.posY_ = std::max(keyboardSessionRect.posY_ - static_cast(newRect.height_), statusHeight); - NotifyOccupiedAreaChangeInfo(callingSession, newRect, keyboardSessionRect); + // calculate new rect of calling session + newRect.posY_ = std::max(keyboardPanelRect.posY_ - static_cast(newRect.height_), statusHeight); + newRect.posY_ = std::min(callingSessionRestoringRect.posY_, newRect.posY_); + NotifyOccupiedAreaChangeInfo(callingSession, newRect, keyboardPanelRect); callingSession->UpdateSessionRect(newRect, SizeChangeReason::UNDEFINED); - callingSessionRaisedRect_ = newRect; } else { - NotifyOccupiedAreaChangeInfo(callingSession, newRect, keyboardSessionRect); + NotifyOccupiedAreaChangeInfo(callingSession, newRect, keyboardPanelRect); } - TLOGI(WmsLogTag::WMS_KEYBOARD, "keyboardRect: %{public}s, OriCallingRect: %{public}s, NewCallingRect: %{public}s" - ", callingRestoreRect_: %{public}s, isCallingSessionFloating: %{public}d, isKeyboardUpdated: %{public}d", - keyboardSessionRect.ToString().c_str(), callingSessionRect.ToString().c_str(), newRect.ToString().c_str(), - callingSessionRestoringRect_.ToString().c_str(), isCallingSessionFloating, isKeyboardUpdated); + + TLOGI(WmsLogTag::WMS_KEYBOARD, "keyboardRect: %{public}s, CallSession OriRect: %{public}s, NewRect: %{public}s" + ", RestoreRect_: %{public}s, isCallingSessionFloating: %{public}d", + keyboardPanelRect.ToString().c_str(), callingSessionRect.ToString().c_str(), newRect.ToString().c_str(), + callingSessionRestoringRect.ToString().c_str(), isCallingSessionFloating); } void KeyboardSession::RestoreCallingSession() { - sptr callingSession = GetCallingSession(); + sptr callingSession = GetSceneSession(GetCallingSessionId()); if (callingSession == nullptr) { TLOGI(WmsLogTag::WMS_KEYBOARD, "Calling session is nullptr"); return; } - - TLOGI(WmsLogTag::WMS_KEYBOARD, "Calling session, RestoringRect_: %{public}s, RaisedRect_: %{public}s" - ", curRect_: %{public}s, sessionMode: %{public}d", callingSessionRestoringRect_.ToString().c_str(), - callingSessionRaisedRect_.ToString().c_str(), callingSession->GetSessionRect().ToString().c_str(), - callingSession->GetWindowMode()); - WSRect overlapRect = { 0, 0, 0, 0 }; - NotifyOccupiedAreaChangeInfo(callingSession, callingSessionRestoringRect_, overlapRect); - if (!SessionHelper::IsEmptyRect(callingSessionRestoringRect_) && - callingSession->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING && - callingSession->GetSessionRect() == callingSessionRaisedRect_) { - callingSession->UpdateSessionRect(callingSessionRestoringRect_, SizeChangeReason::UNDEFINED); + WSRect callingSessionRestoringRect = callingSession->GetRestoringRectForKeyboard(); + TLOGI(WmsLogTag::WMS_KEYBOARD, "callingSessionRestoringRect: %{public}s, sessionMode: %{public}d", + callingSessionRestoringRect.ToString().c_str(), callingSession->GetWindowMode()); + WSRect keyboardRect = { 0, 0, 0, 0 }; + NotifyOccupiedAreaChangeInfo(callingSession, callingSessionRestoringRect, keyboardRect); + if (!SessionHelper::IsEmptyRect(callingSessionRestoringRect) && + callingSession->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING) { + callingSession->UpdateSessionRect(callingSessionRestoringRect, SizeChangeReason::UNDEFINED); } - callingSessionRestoringRect_ = { 0, 0, 0, 0 }; - callingSessionRaisedRect_ = { 0, 0, 0, 0 }; + callingSession->SetRestoringRectForKeyboard(keyboardRect); } // Use focused session id when calling session id is invalid. void KeyboardSession::UseFocusIdIfCallingSessionIdInvalid() { - if (GetCallingSession() != nullptr) { + if (GetSceneSession(GetCallingSessionId()) != nullptr) { return; } - uint32_t focusedSessionId = GetFocusedSessionId(); + int32_t focusedSessionId = GetFocusedSessionId(); if (GetSceneSession(focusedSessionId) == nullptr) { TLOGE(WmsLogTag::WMS_KEYBOARD, "Focused session is null, id: %{public}d", focusedSessionId); } else { @@ -358,18 +441,6 @@ void KeyboardSession::UseFocusIdIfCallingSessionIdInvalid() } } -void KeyboardSession::OnKeyboardSessionShown() -{ - if (GetSessionProperty() == nullptr) { - TLOGE(WmsLogTag::WMS_KEYBOARD, "Keyboard session property is nullptr, raise calling session failed."); - return; - } - UseFocusIdIfCallingSessionIdInvalid(); - TLOGI(WmsLogTag::WMS_KEYBOARD, "Raise keyboard session, persistentId: %{public}d, callingSessionId: %{public}d", - GetPersistentId(), GetSessionProperty()->GetCallingSessionId()); - RaiseCallingSession(); -} - void KeyboardSession::UpdateCallingSessionIdAndPosition(uint32_t callingSessionId) { if (GetSessionProperty() == nullptr) { @@ -419,7 +490,7 @@ void KeyboardSession::RelayoutKeyBoard() requestRect.posX_ = 0; if (percent != 0) { // 100: for calc percent. - requestRect.height_ = static_cast(screenHeight) * percent / 100u; + requestRect.height_ = static_cast(screenHeight * percent / 100u); } } requestRect.posY_ = screenHeight - static_cast(requestRect.height_); diff --git a/window_scene/session/host/src/main_session.cpp b/window_scene/session/host/src/main_session.cpp index 0458f5cd3a..e79eddb29c 100644 --- a/window_scene/session/host/src/main_session.cpp +++ b/window_scene/session/host/src/main_session.cpp @@ -37,13 +37,10 @@ MainSession::MainSession(const SessionInfo& info, const sptrRenameSnapshotFromOldPersistentId(info.persistentId_); } - { - std::unique_lock lock(moveDragControllerMutex_); - moveDragController_ = new (std::nothrow) MoveDragController(GetPersistentId()); - if (moveDragController_ != nullptr && specificCallback != nullptr && + moveDragController_ = new (std::nothrow) MoveDragController(GetPersistentId()); + if (moveDragController_ != nullptr && specificCallback != nullptr && specificCallback->onWindowInputPidChangeCallback_ != nullptr) { - moveDragController_->SetNotifyWindowPidChangeCallback(specificCallback->onWindowInputPidChangeCallback_); - } + moveDragController_->SetNotifyWindowPidChangeCallback(specificCallback->onWindowInputPidChangeCallback_); } SetMoveDragCallback(); std::string key = GetRatioPreferenceKey(); @@ -149,7 +146,7 @@ bool MainSession::CheckPointerEventDispatch(const std::shared_ptr(type) & static_cast(AreaType::LEFT)) || (static_cast(type) & static_cast(AreaType::RIGHT))) { - targetRect.height_ = static_cast(static_cast(targetRect.width_) / newRatio); + targetRect.height_ = static_cast(static_cast(targetRect.width_) / newRatio); } else { - targetRect.width_ = static_cast(static_cast(targetRect.height_) * newRatio); + targetRect.width_ = static_cast(static_cast(targetRect.height_) * newRatio); } return targetRect; } @@ -558,8 +558,11 @@ void MoveDragController::InitDecorValue(const sptr proper const SystemSessionConfig& sysConfig) { auto windowType = property->GetWindowType(); - isDecorEnable_ = (WindowHelper::IsMainWindow(windowType) || - (WindowHelper::IsSubWindow(windowType) && property->IsDecorEnable())) && + bool isMainWindow = WindowHelper::IsMainWindow(windowType); + bool isSubWindow = WindowHelper::IsSubWindow(windowType); + bool isDialogWindow = WindowHelper::IsDialogWindow(windowType); + isDecorEnable_ = (isMainWindow || + ((isSubWindow || isDialogWindow) && property->IsDecorEnable())) && sysConfig.isSystemDecorEnable_ && WindowHelper::IsWindowModeSupported(sysConfig.decorModeSupportInfo_, property->GetWindowMode()); } diff --git a/window_scene/session/host/src/scb_system_session.cpp b/window_scene/session/host/src/scb_system_session.cpp index d53fa0c24f..4b4e3ae42b 100644 --- a/window_scene/session/host/src/scb_system_session.cpp +++ b/window_scene/session/host/src/scb_system_session.cpp @@ -62,6 +62,10 @@ WSError SCBSystemSession::NotifyClientToUpdateRect(std::shared_ptrspecificCallback_ != nullptr && session->specificCallback_->onUpdateAvoidArea_ != nullptr) { session->specificCallback_->onUpdateAvoidArea_(session->GetPersistentId()); } + if (session->GetWindowType() == WindowType::WINDOW_TYPE_KEYBOARD_PANEL && + session->keyboardPanelRectUpdateCallback_ && session->isKeyboardPanelEnabled_) { + session->keyboardPanelRectUpdateCallback_(); + } // clear after use if (session->reason_ != SizeChangeReason::DRAG) { session->reason_ = SizeChangeReason::UNDEFINED; @@ -73,6 +77,32 @@ WSError SCBSystemSession::NotifyClientToUpdateRect(std::shared_ptr session) +{ + if (session == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "session is nullptr"); + return; + } + keyboardSession_ = session; + KeyboardPanelRectUpdateCallback onKeyboardPanelRectUpdate = [this]() { + if (this->keyboardSession_ != nullptr) { + this->keyboardSession_->OnKeyboardPanelUpdated(); + } + }; + SetKeyboardPanelRectUpdateCallback(onKeyboardPanelRectUpdate); + TLOGI(WmsLogTag::WMS_KEYBOARD, "Success, id: %{public}d", keyboardSession_->GetPersistentId()); +} + +sptr SCBSystemSession::GetKeyboardSession() const +{ + return keyboardSession_; +} + void SCBSystemSession::PresentFocusIfPointDown() { WLOGFI("PresentFocusIfPointDown, id: %{public}d, type: %{public}d", GetPersistentId(), GetWindowType()); @@ -131,7 +161,7 @@ WSError SCBSystemSession::UpdateFocus(bool isFocused) WSError SCBSystemSession::UpdateWindowMode(WindowMode mode) { WLOGFD("session is system, id: %{public}d, mode: %{public}d, name: %{public}s, state: %{public}u", - GetPersistentId(), static_cast(mode), sessionInfo_.bundleName_.c_str(), state_); + GetPersistentId(), static_cast(mode), sessionInfo_.bundleName_.c_str(), GetSessionState()); return WSError::WS_ERROR_INVALID_SESSION; } diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 398e730ed9..d10b905bd5 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -26,7 +26,7 @@ #include #include -#include "../../proxy/include/window_info.h" +#include "proxy/include/window_info.h" #include "common/include/session_permission.h" #include "interfaces/include/ws_common.h" @@ -85,6 +85,9 @@ WSError SceneSession::Connect(const sptr& sessionStage, const spt TLOGE(WmsLogTag::WMS_LIFE, "session is null"); return WSError::WS_ERROR_DESTROYED_OBJECT; } + if (property) { + property->SetCollaboratorType(session->GetCollaboratorType()); + } auto ret = session->Session::Connect( sessionStage, eventChannel, surfaceNode, systemConfig, property, token, pid, uid); if (ret != WSError::WS_OK) { @@ -306,7 +309,7 @@ WSError SceneSession::OnSessionEvent(SessionEvent event) void SceneSession::RegisterSessionChangeCallback(const sptr& sessionChangeCallback) { - std::unique_lock lock(sessionChangeCallbackMutex_); + std::lock_guard guard(sessionChangeCbMutex_); sessionChangeCallback_ = sessionChangeCallback; } @@ -449,6 +452,46 @@ WSError SceneSession::UpdateRect(const WSRect& rect, SizeChangeReason reason, return WSError::WS_OK; } +void SceneSession::FixKeyboardPositionByKeyboardPanel(sptr panelSession, + sptr keyboardSession) +{ + if (panelSession == nullptr || keyboardSession == nullptr) { + TLOGE(WmsLogTag::WMS_LAYOUT, "keyboard or panel session is null"); + return; + } + + SessionGravity gravity = keyboardSession->GetKeyboardGravity(); + if (gravity == SessionGravity::SESSION_GRAVITY_FLOAT) { + keyboardSession->winRect_.posX_ = panelSession->winRect_.posX_; + } else { + if (keyboardSession->GetSessionProperty() == nullptr) { + TLOGE(WmsLogTag::WMS_LAYOUT, "keyboard property is null"); + return; + } + static bool isPhone = system::GetParameter("const.product.devicetype", "unknown") == "phone"; + static bool isFoldable = ScreenSessionManagerClient::GetInstance().IsFoldable(); + bool isFolded = ScreenSessionManagerClient::GetInstance().GetFoldStatus() == OHOS::Rosen::FoldStatus::FOLDED; + const auto& screenSession = ScreenSessionManagerClient::GetInstance().GetScreenSession( + keyboardSession->GetSessionProperty()->GetDisplayId()); + Rotation rotation = (screenSession != nullptr) ? screenSession->GetRotation() : Rotation::ROTATION_0; + bool isKeyboardNeedLeftOffset = (isPhone && (!isFoldable || (isFoldable && isFolded)) && + (rotation == Rotation::ROTATION_90 || rotation == Rotation::ROTATION_270)); + if (isKeyboardNeedLeftOffset) { + keyboardSession->winRect_.posX_ += panelSession->winRect_.posX_; + } else { + keyboardSession->winRect_.posX_ = panelSession->winRect_.posX_; + } + TLOGI(WmsLogTag::WMS_LAYOUT, "isPhone:%{public}d, isFoldable:%{public}d, isFolded:%{public}d, " + "rotation:%{public}d, isKeyboardNeedLeftOffset:%{public}d", isPhone, isFoldable, + isFolded, rotation, isKeyboardNeedLeftOffset); + } + keyboardSession->winRect_.posY_ = panelSession->winRect_.posY_; + TLOGI(WmsLogTag::WMS_LAYOUT, "panelId:%{public}d, keyboardId:%{public}d, panelRect:%{public}s, " + "keyboardRect:%{public}s, gravity:%{public}d", panelSession->GetPersistentId(), + keyboardSession->GetPersistentId(), panelSession->winRect_.ToString().c_str(), + keyboardSession->winRect_.ToString().c_str(), gravity); +} + WSError SceneSession::NotifyClientToUpdateRectTask( wptr weakThis, std::shared_ptr rsTransaction) { @@ -470,6 +513,18 @@ WSError SceneSession::NotifyClientToUpdateRectTask( "SceneSession::NotifyClientToUpdateRect%d [%d, %d, %u, %u] reason:%u", session->GetPersistentId(), session->winRect_.posX_, session->winRect_.posY_, session->winRect_.width_, session->winRect_.height_, session->reason_); + + if (isKeyboardPanelEnabled_) { + if (session->GetWindowType() == WindowType::WINDOW_TYPE_KEYBOARD_PANEL) { + const auto& keyboardSession = session->GetKeyboardSession(); + FixKeyboardPositionByKeyboardPanel(session, keyboardSession); + ret = keyboardSession->Session::UpdateRect(keyboardSession->winRect_, session->reason_, rsTransaction); + } + if (session->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { + FixKeyboardPositionByKeyboardPanel(session->GetKeyboardPanelSession(), session); + } + } + // once reason is undefined, not use rsTransaction // when rotation, sync cnt++ in marshalling. Although reason is undefined caused by resize if (session->reason_ == SizeChangeReason::UNDEFINED || session->reason_ == SizeChangeReason::MOVE || @@ -520,7 +575,7 @@ bool SceneSession::UpdateInputMethodSessionRect(const WSRect&rect, WSRect& newWi defaultDisplayInfo->GetWidth() : rect.width_; newRequestRect.width_ = newWinRect.width_; newWinRect.height_ = (gravity == SessionGravity::SESSION_GRAVITY_BOTTOM && percent != 0) ? - static_cast(defaultDisplayInfo->GetHeight()) * percent / 100u : rect.height_; + static_cast(defaultDisplayInfo->GetHeight() * percent / 100u) : rect.height_; newRequestRect.height_ = newWinRect.height_; newWinRect.posX_ = (gravity == SessionGravity::SESSION_GRAVITY_BOTTOM) ? 0 : newRequestRect.posX_; newRequestRect.posX_ = newWinRect.posX_; @@ -572,7 +627,9 @@ WSError SceneSession::UpdateSessionRect(const WSRect& rect, const SizeChangeReas newWinRect.posY_ = rect.posY_; newRequestRect.posX_ = rect.posX_; newRequestRect.posY_ = rect.posY_; - session->SetSessionRect(newWinRect); + if (!WindowHelper::IsMainWindow(session->GetWindowType())) { + session->SetSessionRect(newWinRect); + } session->SetSessionRequestRect(newRequestRect); session->NotifySessionRectChange(newRequestRect, reason); } else if (reason == SizeChangeReason::RESIZE) { @@ -653,7 +710,6 @@ WSError SceneSession::BindDialogSessionTarget(const sptr& sceneSes TLOGE(WmsLogTag::WMS_DIALOG, "dialog session is null"); return WSError::WS_ERROR_NULLPTR; } - std::shared_lock lock(sessionChangeCallbackMutex_); if (sessionChangeCallback_ != nullptr && sessionChangeCallback_->onBindDialogTarget_) { TLOGI(WmsLogTag::WMS_DIALOG, "id: %{public}d", sceneSession->GetPersistentId()); sessionChangeCallback_->onBindDialogTarget_(sceneSession); @@ -674,7 +730,6 @@ WSError SceneSession::SetSystemBarProperty(WindowType type, SystemBarProperty sy return WSError::WS_ERROR_NULLPTR; } property->SetSystemBarProperty(type, systemBarProperty); - std::shared_lock lock(sessionChangeCallbackMutex_); if (sessionChangeCallback_ != nullptr && sessionChangeCallback_->OnSystemBarPropertyChange_) { sessionChangeCallback_->OnSystemBarPropertyChange_(property->GetSystemBarProperty()); } @@ -732,7 +787,6 @@ WSError SceneSession::OnNeedAvoid(bool status) WSError SceneSession::OnShowWhenLocked(bool showWhenLocked) { WLOGFD("SceneSession ShowWhenLocked status:%{public}d", static_cast(showWhenLocked)); - std::shared_lock lock(sessionChangeCallbackMutex_); if (sessionChangeCallback_ != nullptr && sessionChangeCallback_->OnShowWhenLocked_) { sessionChangeCallback_->OnShowWhenLocked_(showWhenLocked); } @@ -807,7 +861,10 @@ void SceneSession::GetSystemAvoidArea(WSRect& rect, AvoidArea& avoidArea) vpr = display->GetVirtualPixelRatio(); int32_t floatingBarHeight = 32; // 32: floating windowBar Height avoidArea.topRect_.height_ = vpr * floatingBarHeight; - avoidArea.topRect_.width_ = display->GetWidth(); + avoidArea.topRect_.width_ = static_cast(display->GetWidth()); + return; + } + if (isDisplayStatusBarTemporarily_.load()) { return; } std::vector> statusBarVector; @@ -857,8 +914,16 @@ void SceneSession::GetKeyboardAvoidArea(WSRect& rect, AvoidArea& avoidArea) if (gravity == SessionGravity::SESSION_GRAVITY_FLOAT) { continue; } - WSRect inputMethodRect = inputMethod->GetSessionRect(); - CalculateAvoidAreaRect(rect, inputMethodRect, avoidArea); + if (isKeyboardPanelEnabled_) { + WSRect keyboardRect = {0, 0, 0, 0}; + if (inputMethod && inputMethod->GetKeyboardPanelSession()) { + keyboardRect = inputMethod->GetKeyboardPanelSession()->GetSessionRect(); + } + CalculateAvoidAreaRect(rect, keyboardRect, avoidArea); + } else { + WSRect inputMethodRect = inputMethod->GetSessionRect(); + CalculateAvoidAreaRect(rect, inputMethodRect, avoidArea); + } } return; @@ -896,6 +961,9 @@ void SceneSession::GetCutoutAvoidArea(WSRect& rect, AvoidArea& avoidArea) void SceneSession::GetAINavigationBarArea(WSRect rect, AvoidArea& avoidArea) { + if (isDisplayStatusBarTemporarily_.load()) { + return; + } if (Session::GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING || Session::GetWindowMode() == WindowMode::WINDOW_MODE_PIP) { return; @@ -1166,16 +1234,19 @@ WSError SceneSession::TransferPointerEvent(const std::shared_ptrGetWindowType(); - if (property->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING && - (WindowHelper::IsMainWindow(windowType) || WindowHelper::IsSubWindow(windowType)) && - property->GetMaximizeMode() != MaximizeMode::MODE_AVOID_SYSTEM_BAR) { + bool isWindowModeFloating = property->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING; + bool isMainWindow = WindowHelper::IsMainWindow(windowType); + bool isSubWindow = WindowHelper::IsSubWindow(windowType); + bool isDialog = WindowHelper::IsDialogWindow(windowType); + bool isMaxModeAvoidSysBar = property->GetMaximizeMode() == MaximizeMode::MODE_AVOID_SYSTEM_BAR; + if (isWindowModeFloating && (isMainWindow || isSubWindow || isDialog) && + !isMaxModeAvoidSysBar) { if (CheckDialogOnForeground() && isPointDown) { HandlePointDownDialog(); pointerEvent->MarkProcessed(); TLOGI(WmsLogTag::WMS_DIALOG, "There is dialog window foreground"); return WSError::WS_OK; } - std::shared_lock lock(moveDragControllerMutex_); if (!moveDragController_) { WLOGE("moveDragController_ is null"); return Session::TransferPointerEvent(pointerEvent, needNotifyClient); @@ -1283,10 +1354,15 @@ bool SceneSession::IsDecorEnable() const return false; } auto windowType = property->GetWindowType(); - return (WindowHelper::IsMainWindow(windowType) || - (WindowHelper::IsSubWindow(windowType) && property->IsDecorEnable())) && - systemConfig_.isSystemDecorEnable_ && - WindowHelper::IsWindowModeSupported(systemConfig_.decorModeSupportInfo_, property->GetWindowMode()); + bool isMainWindow = WindowHelper::IsMainWindow(windowType); + bool isSubWindow = WindowHelper::IsSubWindow(windowType); + bool isDialogWindow = WindowHelper::IsDialogWindow(windowType); + bool isValidWindow = isMainWindow || + ((isSubWindow || isDialogWindow) && property->IsDecorEnable()); + bool isWindowModeSupported = WindowHelper::IsWindowModeSupported( + systemConfig_.decorModeSupportInfo_, property->GetWindowMode()); + bool enable = isValidWindow && systemConfig_.isSystemDecorEnable_ && isWindowModeSupported; + return enable; } std::string SceneSession::GetRatioPreferenceKey() @@ -1390,7 +1466,6 @@ bool SceneSession::FixRectByAspectRatio(WSRect& rect) void SceneSession::SetMoveDragCallback() { - std::shared_lock lock(moveDragControllerMutex_); if (moveDragController_) { MoveDragCallback callBack = [this](const SizeChangeReason& reason) { this->OnMoveDragCallback(reason); @@ -1401,11 +1476,6 @@ void SceneSession::SetMoveDragCallback() void SceneSession::OnMoveDragCallback(const SizeChangeReason& reason) { - std::shared_lock lock(moveDragControllerMutex_); - if (!moveDragController_) { - WLOGE("moveDragController_ is null"); - return; - } WSRect rect = moveDragController_->GetTargetRect(); WLOGFD("OnMoveDragCallback rect: [%{public}d, %{public}d, %{public}u, %{public}u], reason : %{public}d", rect.posX_, rect.posY_, rect.width_, rect.height_, reason); @@ -1420,6 +1490,11 @@ void SceneSession::OnMoveDragCallback(const SizeChangeReason& reason) UpdateRect(rect, reason); } if (reason == SizeChangeReason::DRAG_END) { + if (!SessionHelper::IsEmptyRect(GetRestoringRectForKeyboard())) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "Calling session is moved and reset restoringRectForKeyboard_"); + WSRect restoringRect = {0, 0, 0, 0}; + SetRestoringRectForKeyboard(restoringRect); + } NotifySessionRectChange(rect, reason); OnSessionEvent(SessionEvent::EVENT_END_MOVE); } @@ -1480,6 +1555,10 @@ void SceneSession::SetSurfaceBounds(const WSRect& rect) WLOGFD("subwindow setSurfaceBounds"); surfaceNode_->SetBounds(rect.posX_, rect.posY_, rect.width_, rect.height_); surfaceNode_->SetFrame(rect.posX_, rect.posY_, rect.width_, rect.height_); + } else if (WindowHelper::IsDialogWindow(GetWindowType()) && surfaceNode_) { + TLOGD(WmsLogTag::WMS_DIALOG, "dialogWindow setSurfaceBounds"); + surfaceNode_->SetBounds(rect.posX_, rect.posY_, rect.width_, rect.height_); + surfaceNode_->SetFrame(rect.posX_, rect.posY_, rect.width_, rect.height_); } else { WLOGE("SetSurfaceBounds surfaceNode is null!"); } @@ -1707,7 +1786,6 @@ WSError SceneSession::UpdateWindowAnimationFlag(bool needDefaultAnimationFlag) void SceneSession::SetWindowAnimationFlag(bool needDefaultAnimationFlag) { needDefaultAnimationFlag_ = needDefaultAnimationFlag; - std::shared_lock lock(sessionChangeCallbackMutex_); if (sessionChangeCallback_ && sessionChangeCallback_->onWindowAnimationFlagChange_) { sessionChangeCallback_->onWindowAnimationFlagChange_(needDefaultAnimationFlag); } @@ -1733,7 +1811,6 @@ bool SceneSession::IsAppSession() const void SceneSession::NotifyIsCustomAnimationPlaying(bool isPlaying) { WLOGFI("id %{public}d %{public}u", GetPersistentId(), isPlaying); - std::shared_lock lock(sessionChangeCallbackMutex_); if (sessionChangeCallback_ != nullptr && sessionChangeCallback_->onIsCustomAnimationPlaying_) { sessionChangeCallback_->onIsCustomAnimationPlaying_(isPlaying); } @@ -1807,7 +1884,6 @@ void SceneSession::NotifyTouchOutside() WLOGFD("Notify sessionStage TouchOutside"); sessionStage_->NotifyTouchOutside(); } - std::shared_lock lock(sessionChangeCallbackMutex_); if (sessionChangeCallback_ && sessionChangeCallback_->OnTouchOutside_) { WLOGFD("Notify sessionChangeCallback TouchOutside"); sessionChangeCallback_->OnTouchOutside_(); @@ -1825,7 +1901,6 @@ void SceneSession::NotifyWindowVisibility() bool SceneSession::CheckOutTouchOutsideRegister() { - std::shared_lock lock(sessionChangeCallbackMutex_); if (sessionChangeCallback_ && sessionChangeCallback_->OnTouchOutside_) { return true; } @@ -1836,7 +1911,6 @@ void SceneSession::SetRequestedOrientation(Orientation orientation) { WLOGFI("id: %{public}d orientation: %{public}u", GetPersistentId(), static_cast(orientation)); GetSessionProperty()->SetRequestedOrientation(orientation); - std::shared_lock lock(sessionChangeCallbackMutex_); if (sessionChangeCallback_ && sessionChangeCallback_->OnRequestedOrientationChange_) { sessionChangeCallback_->OnRequestedOrientationChange_(static_cast(orientation)); } @@ -1851,7 +1925,6 @@ void SceneSession::NotifyForceHideChange(bool hide) return; } property->SetForceHide(hide); - std::shared_lock lock(sessionChangeCallbackMutex_); if (sessionChangeCallback_ && sessionChangeCallback_->OnForceHideChange_) { sessionChangeCallback_->OnForceHideChange_(hide); } @@ -1912,13 +1985,11 @@ void SceneSession::SetAbilitySessionInfo(std::shared_ptr selfToken) { - std::unique_lock lock(selfTokenMutex_); selfToken_ = selfToken; } sptr SceneSession::GetSelfToken() const { - std::shared_lock lock(selfTokenMutex_); return selfToken_; } @@ -2205,6 +2276,16 @@ void SceneSession::SetLastSafeRect(WSRect rect) return; } +WSRect SceneSession::GetRestoringRectForKeyboard() const +{ + return restoringRectForKeyboard_; +} + +void SceneSession::SetRestoringRectForKeyboard(WSRect rect) +{ + restoringRectForKeyboard_ = rect; +} + bool SceneSession::AddSubSession(const sptr& subSession) { if (subSession == nullptr) { @@ -2293,7 +2374,6 @@ std::vector> SceneSession::GetSubSession() const WSRect SceneSession::GetSessionTargetRect() const { WSRect rect; - std::shared_lock lock(moveDragControllerMutex_); if (moveDragController_) { rect = moveDragController_->GetTargetRect(); } else { @@ -2304,7 +2384,6 @@ WSRect SceneSession::GetSessionTargetRect() const void SceneSession::SetWindowDragHotAreaListener(const NotifyWindowDragHotAreaFunc& func) { - std::shared_lock lock(moveDragControllerMutex_); if (moveDragController_) { moveDragController_->SetWindowDragHotAreaFunc(func); } @@ -2397,7 +2476,6 @@ bool SceneSession::IsDirtyWindow() void SceneSession::NotifyUILostFocus() { - std::shared_lock lock(moveDragControllerMutex_); if (moveDragController_) { moveDragController_->OnLostFocus(); } @@ -2455,60 +2533,42 @@ void SceneSession::SetIsStartMoving(const bool startMoving) isStartMoving_.store(startMoving); } -bool SceneSession::ShouldHideNonSecureWindows() const -{ - return IsSessionForeground() && (shouldHideNonSecureWindows_.load() || !secureExtSessionSet_.empty()); -} - void SceneSession::SetShouldHideNonSecureWindows(bool shouldHide) { shouldHideNonSecureWindows_.store(shouldHide); } -WSError SceneSession::AddOrRemoveSecureExtSession(int32_t persistentId, bool shouldHide) +void SceneSession::CalculateCombinedExtWindowFlags() { - auto task = [weakThis = wptr(this), persistentId, shouldHide]() { - auto session = weakThis.promote(); - if (session == nullptr) { - TLOGE(WmsLogTag::WMS_UIEXT, "session is nullptr"); - return WSError::WS_ERROR_INVALID_SESSION; - } - - auto& sessionSet = session->secureExtSessionSet_; - if (shouldHide) { - sessionSet.insert(persistentId); - } else { - sessionSet.erase(persistentId); - } - return WSError::WS_OK; - }; - - return PostSyncTask(task, "AddOrRemoveSecureExtSession"); + // Only correct when each flag is true when active, and once a uiextension is active, the host is active + combinedExtWindowFlags_.bitData = 0; + for (const auto& iter: extWindowFlagsMap_) { + combinedExtWindowFlags_.bitData |= iter.second.bitData; + } } -void SceneSession::UpdateExtWindowFlags(int32_t extPersistentId, uint32_t extWindowFlags) +void SceneSession::UpdateExtWindowFlags(int32_t extPersistentId, const ExtensionWindowFlags& extWindowFlags, + const ExtensionWindowFlags& extWindowActions) { auto iter = extWindowFlagsMap_.find(extPersistentId); - if (iter == extWindowFlagsMap_.end()) { - extWindowFlagsMap_.insert({ extPersistentId, extWindowFlags }); + // Each flag is false when inactive, 0 means all flags are inactive + auto oldFlags = iter != extWindowFlagsMap_.end() ? iter->second : ExtensionWindowFlags(); + ExtensionWindowFlags newFlags((extWindowFlags.bitData & extWindowActions.bitData) | + (oldFlags.bitData & ~extWindowActions.bitData)); + if (newFlags.bitData == 0) { + extWindowFlagsMap_.erase(extPersistentId); } else { - extWindowFlagsMap_[iter->first] = extWindowFlags; + extWindowFlagsMap_[extPersistentId] = newFlags; } + CalculateCombinedExtWindowFlags(); } -bool SceneSession::IsExtWindowHasWaterMarkFlag() + +ExtensionWindowFlags SceneSession::GetCombinedExtWindowFlags() const { - bool isExtWindowHasWaterMarkFlag = false; - for (const auto& iter: extWindowFlagsMap_) { - auto& extWindowFlags = iter.second; - if (!extWindowFlags) { - continue; - } - if (extWindowFlags & static_cast(ExtensionWindowFlag::EXTENSION_WINDOW_FLAG_WATER_MARK)) { - isExtWindowHasWaterMarkFlag = true; - break; - } - } - return isExtWindowHasWaterMarkFlag; + auto combinedExtWindowFlags = combinedExtWindowFlags_; + combinedExtWindowFlags.hideNonSecureWindowsFlag = IsSessionForeground() && + (combinedExtWindowFlags.hideNonSecureWindowsFlag || shouldHideNonSecureWindows_.load()); + return combinedExtWindowFlags; } void SceneSession::NotifyDisplayMove(DisplayId from, DisplayId to) @@ -2520,16 +2580,16 @@ void SceneSession::NotifyDisplayMove(DisplayId from, DisplayId to) } } -void SceneSession::RomoveExtWindowFlags(int32_t extPersistentId) +void SceneSession::RemoveExtWindowFlags(int32_t extPersistentId) { - auto iter = extWindowFlagsMap_.find(extPersistentId); - if (iter != extWindowFlagsMap_.end()) { - extWindowFlagsMap_.erase(iter); - } + extWindowFlagsMap_.erase(extPersistentId); + CalculateCombinedExtWindowFlags(); } + void SceneSession::ClearExtWindowFlags() { extWindowFlagsMap_.clear(); + combinedExtWindowFlags_.bitData = 0; } WSError SceneSession::UpdateRectChangeListenerRegistered(bool isRegister) @@ -2556,4 +2616,15 @@ bool SceneSession::GetForceHideState() const { return forceHideState_; } + +void SceneSession::SetIsDisplayStatusBarTemporarily(bool isTemporary) +{ + TLOGI(WmsLogTag::WMS_IMMS, "SetIsTemporarily:%{public}u", isTemporary); + isDisplayStatusBarTemporarily_.store(isTemporary); +} + +bool SceneSession::GetIsDisplayStatusBarTemporarily() const +{ + return isDisplayStatusBarTemporarily_.load(); +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index a8e1f8477f..32c238253e 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -24,7 +24,7 @@ #include #include #include -#include "../../proxy/include/window_info.h" +#include "proxy/include/window_info.h" #include "anr_manager.h" #include "session_helper.h" @@ -50,16 +50,31 @@ constexpr float INNER_ANGLE_VP = 16.0f; constexpr uint32_t MAX_LIFE_CYCLE_TASK_IN_QUEUE = 15; constexpr int64_t LIFE_CYCLE_TASK_EXPIRED_TIME_LIMIT = 350; static bool g_enableForceUIFirst = system::GetParameter("window.forceUIFirst.enabled", "1") == "1"; +constexpr int64_t STATE_DETECT_DELAYTIME = 3 * 1000; +const std::map ATTACH_MAP = { + { SessionState::STATE_DISCONNECT, false }, + { SessionState::STATE_CONNECT, false }, + { SessionState::STATE_FOREGROUND, true }, + { SessionState::STATE_ACTIVE, true }, + { SessionState::STATE_INACTIVE, false }, + { SessionState::STATE_BACKGROUND, false }, +}; +const std::map DETACH_MAP = { + { SessionState::STATE_DISCONNECT, true }, + { SessionState::STATE_CONNECT, false }, + { SessionState::STATE_FOREGROUND, false }, + { SessionState::STATE_ACTIVE, false }, + { SessionState::STATE_INACTIVE, true }, + { SessionState::STATE_BACKGROUND, true }, +}; +static std::string g_deviceType = system::GetParameter("const.product.devicetype", "unknown"); std::shared_ptr g_mainHandler; } // namespace Session::Session(const SessionInfo& info) : sessionInfo_(info) { - { - std::unique_lock lock(propertyMutex_); - property_ = new WindowSessionProperty(); - property_->SetWindowType(static_cast(info.windowType_)); - } + property_ = new WindowSessionProperty(); + property_->SetWindowType(static_cast(info.windowType_)); if (!g_mainHandler) { auto runner = AppExecFwk::EventRunner::GetMainEventRunner(); g_mainHandler = std::make_shared(runner); @@ -404,6 +419,12 @@ void Session::SetSessionState(SessionState state) void Session::UpdateSessionState(SessionState state) { + // Remove unexecuted detection tasks when the window state changes to background or destroyed. + if (state == SessionState::STATE_DISCONNECT || + state == SessionState::STATE_INACTIVE || + state == SessionState::STATE_BACKGROUND) { + RemoveWindowDetectTask(); + } state_ = state; NotifySessionStateChange(state); } @@ -579,14 +600,14 @@ bool Session::IsSessionValid() const { if (sessionInfo_.isSystem_) { WLOGFD("session is system, id: %{public}d, name: %{public}s, state: %{public}u", - GetPersistentId(), sessionInfo_.bundleName_.c_str(), state_); + GetPersistentId(), sessionInfo_.bundleName_.c_str(), GetSessionState()); return false; } bool res = state_ > SessionState::STATE_DISCONNECT && state_ < SessionState::STATE_END; if (!res) { if (state_ == SessionState::STATE_DISCONNECT && sessionStage_) { WLOGFI("session is already destroyed or not created! id: %{public}d state: %{public}u", - GetPersistentId(), state_); + GetPersistentId(), GetSessionState()); } } return res; @@ -799,7 +820,6 @@ __attribute__((no_sanitize("cfi"))) WSError Session::Connect(const sptr lock(propertyMutex_); if (property_ && property_->GetIsNeedUpdateWindowMode() && property) { property->SetIsNeedUpdateWindowMode(true); property->SetWindowMode(property_->GetWindowMode()); @@ -1032,8 +1052,9 @@ bool Session::GetForegroundInteractiveStatus() const return foregroundInteractiveStatus_.load(); } -void Session::SetAttachState(bool isAttach) +void Session::SetAttachState(bool isAttach, WindowMode windowMode) { + isAttach_ = isAttach; auto task = [weakThis = wptr(this), isAttach]() { auto session = weakThis.promote(); if (session == nullptr) { @@ -1042,14 +1063,31 @@ void Session::SetAttachState(bool isAttach) } TLOGD(WmsLogTag::WMS_LIFE, "SetAttachState:%{public}d persistentId:%{public}d", isAttach, session->GetPersistentId()); - session->isAttach_ = isAttach; - if (!session->isAttach_ && session->detachCallback_ != nullptr) { + if (isAttach && session->detachCallback_ != nullptr) { TLOGI(WmsLogTag::WMS_LIFE, "Session detach, persistentId:%{public}d", session->GetPersistentId()); session->detachCallback_->OnPatternDetach(session->GetPersistentId()); session->detachCallback_ = nullptr; } }; PostTask(task, "SetAttachState"); + CreateDetectStateTask(isAttach, windowMode); +} + +void Session::CreateDetectStateTask(bool isAttach, WindowMode windowMode) +{ + if (!IsSupportDetectWindow(isAttach)) { + return; + } + if (showRecent_) { + return; + } + if (!ShouldCreateDetectTask(isAttach, windowMode)) { + RemoveWindowDetectTask(); + DetectTaskInfo detectTaskInfo; + SetDetectTaskInfo(detectTaskInfo); + return; + } + CreateWindowStateDetectTask(isAttach, windowMode); } void Session::RegisterDetachCallback(const sptr& callback) @@ -1351,7 +1389,6 @@ void Session::SetParentSession(const sptr& session) WLOGFW("Session is nullptr"); return; } - std::unique_lock lock(parentSessionMutex_); parentSession_ = session; TLOGD(WmsLogTag::WMS_SUB, "[WMSDialog][WMSSub]Set parent success, parentId: %{public}d, id: %{public}d", session->GetPersistentId(), GetPersistentId()); @@ -1359,7 +1396,6 @@ void Session::SetParentSession(const sptr& session) sptr Session::GetParentSession() const { - std::shared_lock lock(parentSessionMutex_); return parentSession_; } @@ -1496,15 +1532,19 @@ bool Session::IfNotNeedAvoidKeyBoardForSplit() void Session::HandlePointDownDialog() { auto dialogVec = GetDialogVector(); + sptr lastValidDialog = nullptr; for (auto dialog : dialogVec) { if (dialog && (dialog->GetSessionState() == SessionState::STATE_FOREGROUND || dialog->GetSessionState() == SessionState::STATE_ACTIVE)) { dialog->RaiseToAppTopForPointDown(); - dialog->PresentFocusIfPointDown(); + lastValidDialog = dialog; TLOGD(WmsLogTag::WMS_DIALOG, "Point main window, raise to top and dialog need focus, " "id: %{public}d, dialogId: %{public}d", GetPersistentId(), dialog->GetPersistentId()); } } + if (lastValidDialog != nullptr) { + lastValidDialog->PresentFocusIfPointDown(); + } } void Session::NotifyPointerEventToRs(int32_t pointAction) @@ -1517,14 +1557,10 @@ void Session::NotifyPointerEventToRs(int32_t pointAction) WSError Session::HandleSubWindowClick(int32_t action) { - { - std::shared_lock lock(parentSessionMutex_); - if (parentSession_ && parentSession_->CheckDialogOnForeground()) { - TLOGD(WmsLogTag::WMS_DIALOG, "Its main window has dialog on foreground, id: %{public}d", GetPersistentId()); - return WSError::WS_ERROR_INVALID_PERMISSION; - } + if (parentSession_ && parentSession_->CheckDialogOnForeground()) { + TLOGD(WmsLogTag::WMS_DIALOG, "Its main window has dialog on foreground, id: %{public}d", GetPersistentId()); + return WSError::WS_ERROR_INVALID_PERMISSION; } - std::shared_lock lock(propertyMutex_); bool raiseEnabled = property_->GetRaiseEnabled() && (action == MMI::PointerEvent::POINTER_ACTION_DOWN || action == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN); if (raiseEnabled) { @@ -1558,7 +1594,6 @@ WSError Session::TransferPointerEvent(const std::shared_ptr& return ret; } } else if (GetWindowType() == WindowType::WINDOW_TYPE_DIALOG) { - std::shared_lock lock(parentSessionMutex_); if (parentSession_ && parentSession_->CheckDialogOnForeground() && isPointDown) { parentSession_->HandlePointDownDialog(); if (!IsTopDialog()) { @@ -1707,7 +1742,7 @@ std::shared_ptr Session::Snapshot(const float scaleParam) const void Session::SetSessionStateChangeListenser(const NotifySessionStateChangeFunc& func) { sessionStateChangeFunc_ = func; - auto changedState = state_; + auto changedState = GetSessionState(); if (changedState == SessionState::STATE_ACTIVE) { changedState = SessionState::STATE_FOREGROUND; } else if (changedState == SessionState::STATE_INACTIVE) { @@ -1717,7 +1752,7 @@ void Session::SetSessionStateChangeListenser(const NotifySessionStateChangeFunc& } NotifySessionStateChange(changedState); WLOGFD("SetSessionStateChangeListenser, id: %{public}d, state_: %{public}d, changedState: %{public}d", - GetPersistentId(), state_, changedState); + GetPersistentId(), GetSessionState(), changedState); } void Session::SetBufferAvailableChangeListener(const NotifyBufferAvailableChangeFunc& func) @@ -1935,7 +1970,6 @@ WSError Session::UpdateWindowMode(WindowMode mode) { WLOGFD("Session update window mode, id: %{public}d, mode: %{public}d", GetPersistentId(), static_cast(mode)); - std::shared_lock lock(propertyMutex_); if (property_ == nullptr) { WLOGFD("id: %{public}d property is nullptr", persistentId_); return WSError::WS_ERROR_NULLPTR; @@ -1943,7 +1977,7 @@ WSError Session::UpdateWindowMode(WindowMode mode) if (state_ == SessionState::STATE_END) { WLOGFI("session is already destroyed or property is nullptr! id: %{public}d state: %{public}u", - GetPersistentId(), state_); + GetPersistentId(), GetSessionState()); return WSError::WS_ERROR_INVALID_SESSION; } else if (state_ == SessionState::STATE_DISCONNECT) { property_->SetWindowMode(mode); @@ -2216,7 +2250,6 @@ WSError Session::UpdateMaximizeMode(bool isMaximize) } else if (GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { mode = MaximizeMode::MODE_FULL_FILL; } - std::shared_lock lock(propertyMutex_); property_->SetMaximizeMode(mode); return sessionStage_->UpdateMaximizeMode(mode); } @@ -2254,7 +2287,17 @@ uint32_t Session::GetUINodeId() const void Session::SetShowRecent(bool showRecent) { + bool isAttach = GetAttachState(); + if (!IsSupportDetectWindow(isAttach) || + !ShouldCreateDetectTaskInRecent(showRecent, showRecent_, isAttach)) { + showRecent_ = showRecent; + return; + } showRecent_ = showRecent; + WindowMode windowMode = GetWindowMode(); + if (!showRecent_ && ShouldCreateDetectTask(isAttach, windowMode)) { + CreateWindowStateDetectTask(isAttach, windowMode); + } } bool Session::GetShowRecent() const @@ -2262,6 +2305,129 @@ bool Session::GetShowRecent() const return showRecent_; } +bool Session::GetAttachState() const +{ + return isAttach_; +} + +DetectTaskInfo Session::GetDetectTaskInfo() const +{ + std::shared_lock lock(detectTaskInfoMutex_); + return detectTaskInfo_; +} + +void Session::SetDetectTaskInfo(const DetectTaskInfo& detectTaskInfo) +{ + std::unique_lock lock(detectTaskInfoMutex_); + detectTaskInfo_ = detectTaskInfo; +} + +bool Session::IsStateMatch(bool isAttach) const +{ + return isAttach ? ATTACH_MAP.at(GetSessionState()) : DETACH_MAP.at(GetSessionState()); +} + +bool Session::IsSupportDetectWindow(bool isAttach) +{ + bool isPc = g_deviceType == "2in1"; + bool isPhone = g_deviceType == "phone"; + if (!isPc && !isPhone) { + WLOGFI("Window state detect not support: device type not support, persistentId:%{public}d", persistentId_); + return false; + } + if (isScreenLockedCallback_ && isScreenLockedCallback_()) { + WLOGFI("Window state detect not support: Screen is locked, persistentId:%{public}d", persistentId_); + return false; + } + if (!SessionHelper::IsMainWindow(GetWindowType())) { + WLOGFI("Window state detect not support: Only support mainwindow, " + "persistentId:%{public}d", persistentId_); + return false; + } + // Only detecting cold start scenarios on PC + if (isPc && (!isAttach || state_ != SessionState::STATE_DISCONNECT)) { + RemoveWindowDetectTask(); + return false; + } + return true; +} + +void Session::RemoveWindowDetectTask() +{ + if (handler_) { + handler_->RemoveTask(GetWindowDetectTaskName()); + } +} + +bool Session::ShouldCreateDetectTask(bool isAttach, WindowMode windowMode) const +{ + // Create detect task directy without pre-exiting tasks. + if (GetDetectTaskInfo().taskState == DetectTaskState::NO_TASK) { + return true; + } + // If the taskState matches the attach detach state, it will be create detect task directly. + if ((GetDetectTaskInfo().taskState == DetectTaskState::ATTACH_TASK && isAttach) || + (GetDetectTaskInfo().taskState == DetectTaskState::DETACH_TASK && !isAttach)) { + return true; + } else { + // Do not create detect task if the windowMode changes. + return GetDetectTaskInfo().taskWindowMode == windowMode; + } +} + +bool Session::ShouldCreateDetectTaskInRecent(bool newShowRecent, bool oldShowRecent, bool isAttach) const +{ + if (newShowRecent) { + return false; + } + return oldShowRecent ? isAttach : false; +} + +void Session::RegisterIsScreenLockedCallback(const std::function& callback) +{ + isScreenLockedCallback_ = callback; +} + +std::string Session::GetWindowDetectTaskName() const +{ + return "wms:WindowStateDetect" + std::to_string(persistentId_); +} + +void Session::CreateWindowStateDetectTask(bool isAttach, WindowMode windowMode) +{ + if (!handler_) { + return; + } + std::string taskName = GetWindowDetectTaskName(); + RemoveWindowDetectTask(); + auto detectTask = [weakThis = wptr(this), isAttach]() { + auto session = weakThis.promote(); + if (session == nullptr) { + if (isAttach) { + WLOGFE("Window attach state and session" + "state mismatch, session is nullptr, attach:%{public}d", isAttach); + } + return; + } + // Skip state detect when screen locked. + if (session->isScreenLockedCallback_ && !session->isScreenLockedCallback_()) { + if (!session->IsStateMatch(isAttach)) { + WLOGFE("Window attach state and session state mismatch, " + "attach:%{public}d, sessioniState:%{public}d, persistenId:%{public}d, bundleName:%{public}s", + isAttach, static_cast(session->GetSessionState()), + session->GetPersistentId(), session->GetSessionInfo().bundleName_.c_str()); + } + } + DetectTaskInfo detectTaskInfo; + session->SetDetectTaskInfo(detectTaskInfo); + }; + handler_->PostTask(detectTask, taskName, STATE_DETECT_DELAYTIME); + DetectTaskInfo detectTaskInfo; + detectTaskInfo.taskWindowMode = windowMode; + detectTaskInfo.taskState = isAttach ? DetectTaskState::ATTACH_TASK : DetectTaskState::DETACH_TASK; + SetDetectTaskInfo(detectTaskInfo); +} + void Session::SetBufferAvailable(bool bufferAvailable) { WLOGFI("SetBufferAvailable: %{public}d", bufferAvailable); diff --git a/window_scene/session/host/src/sub_session.cpp b/window_scene/session/host/src/sub_session.cpp index 08b74fa770..795226c090 100644 --- a/window_scene/session/host/src/sub_session.cpp +++ b/window_scene/session/host/src/sub_session.cpp @@ -30,9 +30,10 @@ constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SubSes SubSession::SubSession(const SessionInfo& info, const sptr& specificCallback) : SceneSession(info, specificCallback) { - { - std::unique_lock lock(moveDragControllerMutex_); - moveDragController_ = new (std::nothrow) MoveDragController(GetPersistentId()); + moveDragController_ = new (std::nothrow) MoveDragController(GetPersistentId()); + if (moveDragController_ != nullptr && specificCallback != nullptr && + specificCallback->onWindowInputPidChangeCallback_ != nullptr) { + moveDragController_->SetNotifyWindowPidChangeCallback(specificCallback->onWindowInputPidChangeCallback_); } SetMoveDragCallback(); TLOGD(WmsLogTag::WMS_LIFE, "Create SubSession"); @@ -114,7 +115,6 @@ WSError SubSession::Reconnect(const sptr& sessionStage, const spt WSError SubSession::ProcessPointDownSession(int32_t posX, int32_t posY) { const auto& id = GetPersistentId(); - std::shared_lock lock(parentSessionMutex_); WLOGFI("id: %{public}d, type: %{public}d", id, GetWindowType()); if (parentSession_ && parentSession_->CheckDialogOnForeground()) { WLOGFI("Has dialog foreground, id: %{public}d, type: %{public}d", id, GetWindowType()); @@ -136,7 +136,6 @@ WSError SubSession::TransferKeyEvent(const std::shared_ptr& keyEv WLOGFE("KeyEvent is nullptr"); return WSError::WS_ERROR_NULLPTR; } - std::shared_lock lock(parentSessionMutex_); if (parentSession_ && parentSession_->CheckDialogOnForeground()) { TLOGD(WmsLogTag::WMS_DIALOG, "Its main window has dialog on foreground, not transfer pointer event"); return WSError::WS_ERROR_INVALID_PERMISSION; @@ -148,7 +147,6 @@ WSError SubSession::TransferKeyEvent(const std::shared_ptr& keyEv int32_t SubSession::GetMissionId() const { - std::shared_lock lock(parentSessionMutex_); return parentSession_ != nullptr ? parentSession_->GetPersistentId() : SceneSession::GetMissionId(); } @@ -170,7 +168,7 @@ bool SubSession::CheckPointerEventDispatch(const std::shared_ptronWindowInputPidChangeCallback_ != nullptr) { + moveDragController_->SetNotifyWindowPidChangeCallback(specificCallback_->onWindowInputPidChangeCallback_); + } SetMoveDragCallback(); } @@ -195,7 +201,6 @@ WSError SystemSession::ProcessPointDownSession(int32_t posX, int32_t posY) const auto& id = GetPersistentId(); const auto& type = GetWindowType(); WLOGFI("id: %{public}d, type: %{public}d", id, type); - std::shared_lock lock(parentSessionMutex_); if (parentSession_ && parentSession_->CheckDialogOnForeground()) { WLOGFI("Parent has dialog foreground, id: %{public}d, type: %{public}d", id, type); parentSession_->HandlePointDownDialog(); @@ -223,7 +228,6 @@ WSError SystemSession::TransferKeyEvent(const std::shared_ptr& ke if (keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_BACK) { return WSError::WS_ERROR_INVALID_PERMISSION; } - std::shared_lock lock(parentSessionMutex_); if (parentSession_ && parentSession_->CheckDialogOnForeground() && !IsTopDialog()) { return WSError::WS_ERROR_INVALID_PERMISSION; @@ -273,7 +277,6 @@ WSError SystemSession::NotifyClientToUpdateRect(std::shared_ptr r int32_t SystemSession::GetMissionId() const { - std::shared_lock lock(parentSessionMutex_); return parentSession_ != nullptr ? parentSession_->GetPersistentId() : SceneSession::GetMissionId(); } @@ -299,7 +302,7 @@ bool SystemSession::CheckKeyEventDispatch(const std::shared_ptr& state_ != SessionState::STATE_ACTIVE)) { TLOGE(WmsLogTag::WMS_DIALOG, "Dialog's parent info : [persistentId: %{publicd}d, state:%{public}d];" "Dialog info:[persistentId: %{publicd}d, state:%{public}d]", - parentSession->GetPersistentId(), parentSessionState, GetPersistentId(), state_); + parentSession->GetPersistentId(), parentSessionState, GetPersistentId(), GetSessionState()); return false; } return true; @@ -313,6 +316,31 @@ bool SystemSession::NeedSystemPermission(WindowType type) type == WindowType::WINDOW_TYPE_PIP); } +bool SystemSession::CheckPointerEventDispatch(const std::shared_ptr& pointerEvent) const +{ + auto sessionState = GetSessionState(); + int32_t action = pointerEvent->GetPointerAction(); + auto isPC = system::GetParameter("const.product.devicetype", "unknown") == "2in1"; + bool isDialog = WindowHelper::IsDialogWindow(GetWindowType()); + if (isPC && isDialog && sessionState != SessionState::STATE_FOREGROUND && + sessionState != SessionState::STATE_ACTIVE && + action != MMI::PointerEvent::POINTER_ACTION_LEAVE_WINDOW) { + WLOGFW("CheckPointerEventDispatch false, Current Session Info: [persistentId: %{public}d, " + "state: %{public}d, action:%{public}d]", GetPersistentId(), GetSessionState(), action); + return false; + } + return true; +} + +void SystemSession::UpdatePointerArea(const WSRect& rect) +{ + auto property = GetSessionProperty(); + if (!(property->IsDecorEnable() && GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING)) { + return; + } + Session::UpdatePointerArea(rect); +} + void SystemSession::RectCheck(uint32_t curWidth, uint32_t curHeight) { uint32_t minWidth = MIN_SYSTEM_WINDOW_WIDTH; diff --git a/window_scene/session/host/src/zidl/session_proxy.cpp b/window_scene/session/host/src/zidl/session_proxy.cpp index 01695885cf..21cf1e7540 100644 --- a/window_scene/session/host/src/zidl/session_proxy.cpp +++ b/window_scene/session/host/src/zidl/session_proxy.cpp @@ -216,9 +216,15 @@ WSError SessionProxy::Connect(const sptr& sessionStage, const spt } Rect preRect = property->GetWindowRect(); Rect rect = { reply.ReadInt32(), reply.ReadInt32(), reply.ReadUint32(), reply.ReadUint32() }; + TLOGI(WmsLogTag::WMS_LAYOUT, "updateRect when connect." + "preRect:[%{public}d, %{public}d, %{public}u, %{public}u]" + "rect:[%{public}d, %{public}d, %{public}u, %{public}u]", + preRect.posX_, preRect.posY_, preRect.width_, preRect.height_, + rect.posX_, rect.posY_, rect.width_, rect.height_); if (preRect.IsUninitializedRect() && !rect.IsUninitializedRect()) { property->SetWindowRect(rect); } + property->SetCollaboratorType(reply.ReadInt32()); } int32_t ret = reply.ReadInt32(); return static_cast(ret); @@ -1145,4 +1151,24 @@ void SessionProxy::SetCallingSessionId(const uint32_t callingSessionId) return; } } + +void SessionProxy::SetCustomDecorHeight(int32_t height) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_LAYOUT, "writeInterfaceToken failed"); + return; + } + if (!data.WriteInt32(height)) { + TLOGE(WmsLogTag::WMS_LAYOUT, "Write height failed."); + return; + } + if (Remote()->SendRequest(static_cast(SessionInterfaceCode::TRANS_ID_SET_CUSTOM_DECOR_HEIGHT), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed"); + return; + } +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/zidl/session_stub.cpp b/window_scene/session/host/src/zidl/session_stub.cpp index 5735aa38e6..b5824932c1 100644 --- a/window_scene/session/host/src/zidl/session_stub.cpp +++ b/window_scene/session/host/src/zidl/session_stub.cpp @@ -101,6 +101,8 @@ const std::map SessionStub::stubFuncMap_ { &SessionStub::HandleSetKeyboardSessionGravity), std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_SET_CALLING_SESSION_ID), &SessionStub::HandleSetCallingSessionId), + std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_SET_CUSTOM_DECOR_HEIGHT), + &SessionStub::HandleSetCustomDecorHeight), std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_TRANSFER_ABILITY_RESULT), &SessionStub::HandleTransferAbilityResult), @@ -251,6 +253,7 @@ int SessionStub::HandleConnect(MessageParcel& data, MessageParcel& reply) reply.WriteInt32(winRect.posY_); reply.WriteUint32(winRect.width_); reply.WriteUint32(winRect.height_); + reply.WriteInt32(property->GetCollaboratorType()); } reply.WriteUint32(static_cast(errCode)); return ERR_NONE; @@ -601,8 +604,8 @@ int SessionStub::HandleUpdatePiPRect(MessageParcel& data, MessageParcel& reply) int SessionStub::HandleProcessPointDownSession(MessageParcel& data, MessageParcel& reply) { WLOGFD("HandleProcessPointDownSession!"); - uint32_t posX = data.ReadInt32(); - uint32_t posY = data.ReadInt32(); + int32_t posX = data.ReadInt32(); + int32_t posY = data.ReadInt32(); WSError errCode = ProcessPointDownSession(posX, posY); reply.WriteUint32(static_cast(errCode)); return ERR_NONE; @@ -648,4 +651,12 @@ int SessionStub::HandleSetCallingSessionId(MessageParcel& data, MessageParcel& r reply.WriteInt32(static_cast(WSError::WS_OK)); return ERR_NONE; } + +int SessionStub::HandleSetCustomDecorHeight(MessageParcel& data, MessageParcel& reply) +{ + TLOGD(WmsLogTag::WMS_LAYOUT, "run HandleSetCustomDecorHeight!"); + int32_t height = data.ReadInt32(); + SetCustomDecorHeight(height); + return ERR_NONE; +} } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/BUILD.gn b/window_scene/session_manager/BUILD.gn index 39a6c8ea3e..a545c0dd69 100644 --- a/window_scene/session_manager/BUILD.gn +++ b/window_scene/session_manager/BUILD.gn @@ -61,6 +61,7 @@ ohos_shared_library("scene_session_manager") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ @@ -140,8 +141,8 @@ ohos_shared_library("scene_session_manager") { defines = [] if (defined(global_parts_info) && - defined(global_parts_info.resourceschedule_memmgr_plugin)) { - external_deps += [ "memmgr_plugin:memmgrclient" ] + defined(global_parts_info.resourceschedule_memmgr_override)) { + external_deps += [ "memmgr_override:memmgrclient" ] defines += [ "MEMMGR_WINDOW_ENABLE" ] } @@ -196,6 +197,7 @@ ohos_shared_library("screen_session_manager") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ @@ -297,6 +299,7 @@ ohos_shared_library("session_manager") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ @@ -347,6 +350,7 @@ ohos_shared_library("session_manager_lite") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 1b7984ae19..f738e9dc0b 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -64,6 +64,8 @@ namespace AncoConsts { class SceneSession; class AccessibilityWindowInfo; using NotifyCreateSystemSessionFunc = std::function& session)>; +using NotifyCreateKeyboardSessionFunc = std::function& keyboardSession, + const sptr& panelSession)>; using NotifyCreateSubSessionFunc = std::function& session)>; using NotifyRecoverSceneSessionFunc = std::function& session, const SessionInfo& sessionInfo)>; @@ -143,6 +145,7 @@ public: const sptr& callback) override; WMError UpdateSessionProperty(const sptr& property, WSPropertyChangeAction action) override; void SetCreateSystemSessionListener(const NotifyCreateSystemSessionFunc& func); + void SetCreateKeyboardSessionListener(const NotifyCreateKeyboardSessionFunc& func); void SetStatusBarEnabledChangeListener(const ProcessStatusBarEnabledChangeFunc& func); void SetStartUIAbilityErrorListener(const ProcessStartUIAbilityErrorFunc& func); void SetRecoverSceneSessionListener(const NotifyRecoverSceneSessionFunc& func); @@ -173,7 +176,7 @@ public: void RequestAllAppSessionUnfocus(); WSError UpdateFocus(int32_t persistentId, bool isFocused); WSError UpdateWindowMode(int32_t persistentId, int32_t windowMode); - WSError SendTouchEvent(const std::shared_ptr& pointerEvent, uint32_t zIndex); + WSError SendTouchEvent(std::shared_ptr& pointerEvent, uint32_t zIndex); void SetScreenLocked(const bool isScreenLocked); bool IsScreenLocked() const; WSError RaiseWindowToTop(int32_t persistentId) override; @@ -292,12 +295,12 @@ public: void AddExtensionWindowStageToSCB(const sptr& sessionStage, int32_t persistentId, int32_t parentId) override; WSError AddOrRemoveSecureSession(int32_t persistentId, bool shouldHide) override; - WSError AddOrRemoveSecureExtSession(int32_t persistentId, int32_t parentId, bool shouldHide) override; + WSError UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags, + uint32_t extWindowActions) override; void CheckSceneZOrder(); int32_t StartUIAbilityBySCB(sptr& abilitySessionInfo); int32_t StartUIAbilityBySCB(sptr& sceneSessions); int32_t ChangeUIAbilityVisibilityBySCB(sptr& sceneSessions, bool visibility); - WSError UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags) override; WSError GetHostWindowRect(int32_t hostWindowId, Rect& rect) override; int32_t ReclaimPurgeableCleanMem(); WMError GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus) override; @@ -310,11 +313,16 @@ public: std::shared_ptr GetTaskScheduler() {return taskScheduler_;}; WSError SwitchFreeMultiWindow(bool enable); const SystemSessionConfig& GetSystemSessionConfig() const; + void UpdateLastDownEventDeviceId(int32_t deviceId); + int32_t GetCustomDecorHeight(int32_t persistentId); + protected: SceneSessionManager(); virtual ~SceneSessionManager() = default; private: + bool isKeyboardPanelEnabled_ = false; + int32_t lastDownEventDeviceId_ { -1 }; void Init(); void InitScheduleUtils(); void RegisterAppListener(); @@ -326,6 +334,7 @@ private: void ConfigDefaultKeyboardAnimation(); bool ConfigAppWindowCornerRadius(const WindowSceneConfig::ConfigItem& item, float& out); bool ConfigAppWindowShadow(const WindowSceneConfig::ConfigItem& shadowConfig, WindowShadowConfig& outShadow); + void ConfigSystemUIStatusBar(const WindowSceneConfig::ConfigItem& statusBarConfig); void ConfigDecor(const WindowSceneConfig::ConfigItem& decorConfig, bool mainConfig = true); void ConfigWindowAnimation(const WindowSceneConfig::ConfigItem& windowAnimationConfig); void ConfigStartingWindowAnimation(const WindowSceneConfig::ConfigItem& startingWindowConfig); @@ -474,6 +483,7 @@ private: std::map> lastUpdatedAvoidArea_; NotifyCreateSystemSessionFunc createSystemSessionFunc_; + NotifyCreateKeyboardSessionFunc createKeyboardSessionFunc_; std::map createSubSessionFuncMap_; std::map>> recoverSubSessionCacheMap_; bool recoveringFinished_ = false; @@ -525,6 +535,8 @@ private: bool isReportTaskStart_ = false; std::vector > lastVisibleData_; RSInterfaces& rsInterface_; + void ClearUnrecoveredSessions(const std::vector& recoveredPersistentIds); + SessionInfo RecoverSessionInfo(const sptr& property); bool isNeedRecover(const int32_t persistentId); void RegisterSessionStateChangeNotifyManagerFunc(sptr& sceneSession); void RegisterSessionInfoChangeNotifyManagerFunc(sptr& sceneSession); @@ -582,6 +594,7 @@ private: void NotifyCreateSpecificSession(sptr session, sptr property, const WindowType& type); sptr CreateSceneSession(const SessionInfo& sessionInfo, sptr property); + void CreateKeyboardPanelSession(sptr keyboardSession); bool GetPreWindowDrawingState(uint64_t windowId, int32_t& pid, bool currentDrawingContentState); bool GetProcessDrawingState(uint64_t windowId, int32_t pid, bool currentDrawingContentState); WSError GetAppMainSceneSession(sptr& sceneSession, int32_t persistentId); @@ -602,6 +615,7 @@ private: const sptr& property); void ProcessBackHomeStatus(); bool IsBackHomeStatus(); + void DeleteStateDetectTask(); }; } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h index c6578669ce..78d44f0e62 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h @@ -99,7 +99,6 @@ public: TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID, TRANS_ID_ADD_EXTENSION_WINDOW_STAGE_TO_SCB, TRANS_ID_ADD_OR_REMOVE_SECURE_SESSION, - TRANS_ID_ADD_OR_REMOVE_SECURE_EXT_SESSION, TRANS_ID_UPDATE_EXTENSION_WINDOW_FLAGS, TRANS_ID_GET_HOST_WINDOW_RECT, TRANS_ID_DESTROY_AND_DISCONNECT_SPECIFIC_SESSION_WITH_DETACH_CALLBACK, @@ -220,11 +219,8 @@ public: { return WSError::WS_OK; } - WSError AddOrRemoveSecureExtSession(int32_t persistentId, int32_t parentId, bool shouldHide) override - { - return WSError::WS_OK; - } - WSError UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags) override + WSError UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags, + uint32_t extWindowActions) override { return WSError::WS_OK; } diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h b/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h index 519d902a63..4d800a7063 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h @@ -99,8 +99,8 @@ public: void AddExtensionWindowStageToSCB(const sptr& sessionStage, int32_t persistentId, int32_t parentId) override; WSError AddOrRemoveSecureSession(int32_t persistentId, bool shouldHide) override; - WSError AddOrRemoveSecureExtSession(int32_t persistentId, int32_t parentId, bool shouldHide) override; - WSError UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags) override; + WSError UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags, + uint32_t extWindowActions) override; WSError GetHostWindowRect(int32_t hostWindowId, Rect& rect) override; WMError GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus) override; WMError GetCallingWindowRect(int32_t persistentId, Rect& rect) override; diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_stub.h b/window_scene/session_manager/include/zidl/scene_session_manager_stub.h index 885a7b9c90..805ee15bb5 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_stub.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_stub.h @@ -90,7 +90,6 @@ private: int HandleGetVisibilityWindowInfo(MessageParcel& data, MessageParcel& reply); int HandleAddExtensionWindowStageToSCB(MessageParcel& data, MessageParcel& reply); int HandleAddOrRemoveSecureSession(MessageParcel& data, MessageParcel& reply); - int HandleAddOrRemoveSecureExtSession(MessageParcel& data, MessageParcel& reply); int HandleUpdateExtWindowFlags(MessageParcel& data, MessageParcel& reply); int HandleGetHostWindowRect(MessageParcel& data, MessageParcel& reply); int HandleGetCallingWindowWindowStatus(MessageParcel& data, MessageParcel& reply); diff --git a/window_scene/session_manager/src/scene_session_dirty_manager.cpp b/window_scene/session_manager/src/scene_session_dirty_manager.cpp index bccb715f2e..137ee3b73c 100644 --- a/window_scene/session_manager/src/scene_session_dirty_manager.cpp +++ b/window_scene/session_manager/src/scene_session_dirty_manager.cpp @@ -187,15 +187,15 @@ void SceneSessionDirtyManager::UpdateDefaultHotAreas(sptr sceneSes MMI::Rect touchRect = { .x = -touchOffset, .y = -touchOffset, - .width = windowRect.width_ + touchOffset * 2, // 2 : double touchOffset - .height = windowRect.height_ + touchOffset * 2 // 2 : double touchOffset + .width = static_cast(windowRect.width_ + touchOffset * 2), // 2 : double touchOffset + .height = static_cast(windowRect.height_ + touchOffset * 2) // 2 : double touchOffset }; MMI::Rect pointerRect = { .x = -pointerOffset, .y = -pointerOffset, - .width = windowRect.width_ + pointerOffset * 2, // 2 : double pointerOffset - .height = windowRect.height_ + pointerOffset * 2 // 2 : double pointerOffset + .width = static_cast(windowRect.width_ + pointerOffset * 2), // 2 : double pointerOffset + .height = static_cast(windowRect.height_ + pointerOffset * 2) // 2 : double pointerOffset }; touchHotAreas.emplace_back(touchRect); @@ -216,8 +216,8 @@ void SceneSessionDirtyManager::UpdateHotAreas(sptr sceneSession, s MMI::Rect rect; rect.x = area.posX_; rect.y = area.posY_; - rect.width = area.width_; - rect.height = area.height_; + rect.width = static_cast(area.width_); + rect.height = static_cast(area.height_); auto iter = std::find_if(touchHotAreas.begin(), touchHotAreas.end(), [&rect](const MMI::Rect& var) { return rect == var; }); if (iter != touchHotAreas.end()) { @@ -225,7 +225,7 @@ void SceneSessionDirtyManager::UpdateHotAreas(sptr sceneSession, s } touchHotAreas.emplace_back(rect); pointerHotAreas.emplace_back(rect); - if (touchHotAreas.size() == static_cast(MMI::WindowInfo::MAX_HOTAREA_COUNT)) { + if (touchHotAreas.size() == static_cast(MMI::WindowInfo::MAX_HOTAREA_COUNT)) { auto sessionid = sceneSession->GetWindowId(); WLOGFE("id = %{public}d hotAreas size > %{public}d", sessionid, static_cast(hotAreas.size())); break; @@ -332,7 +332,8 @@ std::vector SceneSessionDirtyManager::GetFullWindowInfoList() auto iter = (sceneSessionValue->GetParentPersistentId() == INVALID_SESSION_ID) ? dialogMap.find(sceneSessionValue->GetPersistentId()) : dialogMap.find(sceneSessionValue->GetParentPersistentId()); - if (iter != dialogMap.end() && iter->second != nullptr) { + if (iter != dialogMap.end() && iter->second != nullptr && + sceneSessionValue->GetPersistentId() != iter->second->GetPersistentId()) { windowInfo.agentWindowId = static_cast(iter->second->GetPersistentId()); windowInfo.pid = static_cast(iter->second->GetCallingPid()); TLOGI(WmsLogTag::WMS_EVENT, "Change agentId, dialogId: %{public}d, parentId: %{public}d" diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 1bba804a52..59b825ba6f 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -257,6 +257,7 @@ void SceneSessionManager::Init() WLOGI("SceneSessionManager init success."); RegisterAppListener(); openDebugTrace = std::atoi((system::GetParameter("persist.sys.graphic.openDebugTrace", "0")).c_str()) != 0; + isKeyboardPanelEnabled_ = system::GetParameter("persist.sceneboard.keyboardPanel.enabled", "0") == "1"; } void SceneSessionManager::InitScheduleUtils() @@ -297,11 +298,13 @@ void SceneSessionManager::RegisterAppListener() if (appMgrClient_ == nullptr) { WLOGFE("appMgrClient_ is nullptr."); } else { - auto flag = static_cast(appMgrClient_->RegisterAppDebugListener(appAnrListener_)); - if (flag != ERR_OK) { - WLOGFE("Register app debug listener failed."); - } else { - WLOGFI("Register app debug listener success."); + if (appAnrListener_ != nullptr) { + auto flag = static_cast(appMgrClient_->RegisterAppDebugListener(appAnrListener_)); + if (flag != ERR_OK) { + WLOGFE("Register app debug listener failed."); + } else { + WLOGFI("Register app debug listener success."); + } } } } @@ -377,6 +380,11 @@ void SceneSessionManager::ConfigWindowSceneXml() ConfigFreeMultiWindow(); ConfigWindowSizeLimits(); ConfigSnapshotScale(); + + item = config["systemUIStatusBar"]; + if (item.IsMap()) { + ConfigSystemUIStatusBar(item); + } } void SceneSessionManager::ConfigFreeMultiWindow() @@ -596,6 +604,18 @@ bool SceneSessionManager::IsInputEventEnabled() return enableInputEvent_; } +void SceneSessionManager::ClearUnrecoveredSessions(const std::vector& recoveredPersistentIds) +{ + for (const auto& persistentId : alivePersistentIds_) { + auto it = std::find(recoveredPersistentIds.begin(), recoveredPersistentIds.end(), persistentId); + if (it == recoveredPersistentIds.end()) { + TLOGI(WmsLogTag::WMS_RECOVER, "Clear unrecovered session with persistentId=%{public}d", persistentId); + std::unique_lock lock(sceneSessionMapMutex_); + sceneSessionMap_.erase(persistentId); + } + } +} + void SceneSessionManager::UpdateRecoveredSessionInfo(const std::vector& recoveredPersistentIds) { WLOGFI("[WMSRecover] Number of persistentIds recovered = %{public}zu. CurrentUserId = " @@ -603,6 +623,7 @@ void SceneSessionManager::UpdateRecoveredSessionInfo(const std::vector& recoveredPersistentIds.size(), currentUserId_); auto task = [this, recoveredPersistentIds]() { + ClearUnrecoveredSessions(recoveredPersistentIds); std::list abilitySessionInfos; for (const auto& persistentId : recoveredPersistentIds) { auto sceneSession = GetSceneSession(persistentId); @@ -922,6 +943,42 @@ void SceneSessionManager::ConfigSnapshotScale() } } +void SceneSessionManager::ConfigSystemUIStatusBar(const WindowSceneConfig::ConfigItem& statusBarConfig) +{ + TLOGI(WmsLogTag::WMS_IMMS, "load ConfigSystemUIStatusBar"); + WindowSceneConfig::ConfigItem item = statusBarConfig["showInLandscapeMode"]; + if (item.IsInts() && item.intsValue_->size() == 1) { + bool showInLandscapeMode = (*item.intsValue_)[0] > 0; + appWindowSceneConfig_.systemUIStatusBarConfig_.showInLandscapeMode_ = showInLandscapeMode; + TLOGI(WmsLogTag::WMS_IMMS, "ConfigSystemUIStatusBar showInLandscapeMode:%{public}d", + appWindowSceneConfig_.systemUIStatusBarConfig_.showInLandscapeMode_); + } + + item = statusBarConfig["immersiveStatusBarBgColor"]; + if (item.IsString()) { + auto color = item.stringValue_; + uint32_t colorValue; + if (!ColorParser::Parse(color, colorValue)) { + return; + } + appWindowSceneConfig_.systemUIStatusBarConfig_.immersiveStatusBarBgColor_ = color; + TLOGI(WmsLogTag::WMS_IMMS, "ConfigSystemUIStatusBar immersiveStatusBarBgColor:%{public}s", + appWindowSceneConfig_.systemUIStatusBarConfig_.immersiveStatusBarBgColor_.c_str()); + } + + item = statusBarConfig["immersiveStatusBarContentColor"]; + if (item.IsString()) { + auto color = item.stringValue_; + uint32_t colorValue; + if (!ColorParser::Parse(color, colorValue)) { + return; + } + appWindowSceneConfig_.systemUIStatusBarConfig_.immersiveStatusBarContentColor_ = color; + TLOGI(WmsLogTag::WMS_IMMS, "ConfigSystemUIStatusBar immersiveStatusBarContentColor:%{public}s", + appWindowSceneConfig_.systemUIStatusBarConfig_.immersiveStatusBarContentColor_.c_str()); + } +} + void SceneSessionManager::SetRootSceneContext(const std::weak_ptr& contextWeak) { rootSceneContextWeak_ = contextWeak; @@ -1089,6 +1146,47 @@ WMError SceneSessionManager::CheckWindowId(int32_t windowId, int32_t &pid) return taskScheduler_->PostSyncTask(task, "CheckWindowId:" + std::to_string(windowId)); } +void SceneSessionManager::CreateKeyboardPanelSession(sptr keyboardSession) +{ + if (!isKeyboardPanelEnabled_) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "KeyboardPanel is not enabled"); + return; + } + if (keyboardSession == nullptr || keyboardSession->GetSessionProperty() == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "KeyboardSession or property is nullptr"); + return; + } + DisplayId displayId = keyboardSession->GetSessionProperty()->GetDisplayId(); + const auto& panelVec = GetSceneSessionVectorByType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL, displayId); + sptr panelSession; + if (panelVec.size() > 1) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Error size of keyboardPanel, size: %{public}zu", panelVec.size()); + return; + } else if (panelVec.size() == 1) { + panelSession = panelVec.front(); + TLOGI(WmsLogTag::WMS_KEYBOARD, "KeyboardPanel is created, panelId:%{public}d", panelSession->GetPersistentId()); + } else { + SessionInfo panelInfo = { + .bundleName_ = "SCBKeyboardPanel", + .moduleName_ = "SCBKeyboardPanel", + .abilityName_ = "SCBKeyboardPanel", + .isSystem_ = true, + .windowType_ = static_cast(WindowType::WINDOW_TYPE_KEYBOARD_PANEL), + .isSystemInput_ = true, + .screenId_ = static_cast(displayId) + }; + panelSession = RequestSceneSession(panelInfo, nullptr); + if (panelSession == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "PanelSession is nullptr"); + return; + } + } + keyboardSession->BindKeyboardPanelSession(panelSession); + panelSession->BindKeyboardSession(keyboardSession); + TLOGI(WmsLogTag::WMS_KEYBOARD, "success, panelId:%{public}d, keyboardId:%{public}d", + panelSession->GetPersistentId(), keyboardSession->GetPersistentId()); +} + sptr SceneSessionManager::CreateSceneSession(const SessionInfo& sessionInfo, sptr property) { @@ -1106,6 +1204,7 @@ sptr SceneSessionManager::CreateSceneSession(const SessionInfo& se } else if (property != nullptr && property->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { sptr keyboardCb = CreateKeyboardSessionCallback(); sceneSession = new (std::nothrow) KeyboardSession(sessionInfo, specificCb, keyboardCb); + CreateKeyboardPanelSession(sceneSession); TLOGI(WmsLogTag::WMS_KEYBOARD, "Create KeyboardSession, type: %{public}d", property->GetWindowType()); } else if (property != nullptr && SessionHelper::IsSystemWindow(property->GetWindowType())) { sceneSession = new (std::nothrow) SystemSession(sessionInfo, specificCb); @@ -1115,6 +1214,7 @@ sptr SceneSessionManager::CreateSceneSession(const SessionInfo& se } if (sceneSession != nullptr) { sceneSession->SetSessionInfoPersistentId(sceneSession->GetPersistentId()); + sceneSession->isKeyboardPanelEnabled_ = isKeyboardPanelEnabled_; } return sceneSession; } @@ -1151,7 +1251,11 @@ sptr SceneSessionManager::RequestSceneSession(const SessionInfo& s auto windowModeCallback = [this]() { ProcessSplitFloating(); }; + auto isScreenLockedCallback = [this]() { + return IsScreenLocked(); + }; sceneSession->RegisterWindowModeChangedCallback(windowModeCallback); + sceneSession->RegisterIsScreenLockedCallback(isScreenLockedCallback); if (sessionInfo.isSystem_) { sceneSession->SetCallingPid(IPCSkeleton::GetCallingRealPid()); sceneSession->SetCallingUid(IPCSkeleton::GetCallingUid()); @@ -1827,13 +1931,18 @@ void SceneSessionManager::DestroyExtensionSession(const sptr& rem TLOGD(WmsLogTag::WMS_UIEXT, "Remote died, id: %{public}d", persistentId); auto sceneSession = GetSceneSession(parentId); if (sceneSession != nullptr) { - auto oldWaterMark = sceneSession->IsExtWindowHasWaterMarkFlag(); - sceneSession->RomoveExtWindowFlags(persistentId); - if (oldWaterMark) { + auto oldFlags = sceneSession->GetCombinedExtWindowFlags(); + sceneSession->RemoveExtWindowFlags(persistentId); + if (oldFlags.hideNonSecureWindowsFlag) { + HandleSecureSessionShouldHide(sceneSession); + } + if (oldFlags.waterMarkFlag) { CheckAndNotifyWaterMarkChangedResult(); } + if (oldFlags.privacyModeFlag) { + UpdatePrivateStateAndNotify(parentId); + } } - AddOrRemoveSecureExtSession(persistentId, parentId, false); remoteExtSessionMap_.erase(iter); }; taskScheduler_->PostAsyncTask(task, "DestroyExtensionSession"); @@ -1854,9 +1963,10 @@ WSError SceneSessionManager::CreateAndConnectSpecificSession(const sptrGetWindowType() == WindowType::WINDOW_TYPE_FLOAT && !secureSessionSet_.empty()) || - (SessionHelper::IsSubWindow(property->GetWindowType()) && - secureSessionSet_.find(property->GetParentPersistentId()) != secureSessionSet_.end()); + bool shouldBlock = (property->GetWindowType() == WindowType::WINDOW_TYPE_FLOAT && + property->IsFloatingWindowAppType() && !secureSessionSet_.empty()) || + (SessionHelper::IsSubWindow(property->GetWindowType()) && + secureSessionSet_.find(property->GetParentPersistentId()) != secureSessionSet_.end()); if (shouldBlock) { TLOGE(WmsLogTag::WMS_UIEXT, "create non-secure window permission denied!"); return WSError::WS_ERROR_INVALID_OPERATION; @@ -1911,7 +2021,7 @@ WSError SceneSessionManager::CreateAndConnectSpecificSession(const sptrGetSessionInfo().bundleName_; info.abilityName_ = property->GetSessionInfo().abilityName_; info.moduleName_ = property->GetSessionInfo().moduleName_; - + ClosePipWindowIfExist(type); sptr newSession = RequestSceneSession(info, property); if (newSession == nullptr) { @@ -2003,6 +2113,30 @@ bool SceneSessionManager::CheckSystemWindowPermission(const sptr& property) +{ + SessionInfo sessionInfo; + if (property == nullptr) { + TLOGE(WmsLogTag::WMS_RECOVER, "property is nullptr"); + return sessionInfo; + } + sessionInfo = property->GetSessionInfo(); + sessionInfo.persistentId_ = property->GetPersistentId(); + sessionInfo.windowMode = static_cast(property->GetWindowMode()); + sessionInfo.windowType_ = static_cast(property->GetWindowType()); + sessionInfo.requestOrientation_ = static_cast(property->GetRequestedOrientation()); + sessionInfo.sessionState_ = (property->GetWindowState() == WindowState::STATE_SHOWN) + ? SessionState::STATE_ACTIVE + : SessionState::STATE_BACKGROUND; + TLOGI(WmsLogTag::WMS_RECOVER, + "Recover and reconnect session with: bundleName=%{public}s, moduleName=%{public}s, " + "abilityName=%{public}s, windowMode=%{public}d, windowType=%{public}u, persistentId=%{public}d, " + "windowState=%{public}u", + sessionInfo.bundleName_.c_str(), sessionInfo.moduleName_.c_str(), sessionInfo.abilityName_.c_str(), + sessionInfo.windowMode, sessionInfo.windowType_, sessionInfo.persistentId_, sessionInfo.sessionState_); + return sessionInfo; +} + void SceneSessionManager::SetAlivePersistentIds(const std::vector& alivePersistentIds) { WLOGFI("[WMSRecover] Number of persistentIds need to be recovered = %{public}zu. CurrentUserId = " @@ -2034,22 +2168,15 @@ WSError SceneSessionManager::RecoverAndConnectSpecificSession(const sptrGetWindowType(); - SessionInfo info = property->GetSessionInfo(); + SessionInfo info = RecoverSessionInfo(property); info.isPersistentRecover_ = true; - info.persistentId_ = property->GetPersistentId(); - info.windowMode = static_cast(property->GetWindowMode()); - info.windowType_ = static_cast(type); - info.requestOrientation_ = static_cast(property->GetRequestedOrientation()); - info.sessionState_ = (property->GetWindowState() == WindowState::STATE_SHOWN) ? SessionState::STATE_ACTIVE - : SessionState::STATE_BACKGROUND; - - WLOGI("[WMSRecover] RecoverAndConnectSpecificSession windowName = %{public}s, windowMode = %{public}d, " - "windowType = %{public}u, persistentId = %{public}d, windowState = %{public}u, " - "callingSessionId = %{public}" PRIu32, property->GetWindowName().c_str(), info.windowMode, - info.windowType_, info.persistentId_, property->GetWindowState(), property->GetCallingSessionId()); - + TLOGI(WmsLogTag::WMS_RECOVER, "callingSessionId = %{public}" PRIu32, property->GetCallingSessionId()); ClosePipWindowIfExist(type); sptr sceneSession = RequestSceneSession(info, property); if (sceneSession == nullptr) { @@ -2077,7 +2204,6 @@ WSError SceneSessionManager::RecoverAndConnectSpecificSession(const sptrPostSyncTask(task, "RecoverAndConnectSpecificSession"); } @@ -2156,47 +2282,44 @@ WSError SceneSessionManager::RecoverAndReconnectSceneSession(const sptrGetPersistentId())) { return WSError::WS_ERROR_INVALID_PARAM; } - SessionInfo sessionInfo = property->GetSessionInfo(); - sessionInfo.persistentId_ = property->GetPersistentId(); - sessionInfo.windowMode = static_cast(property->GetWindowMode()); - sessionInfo.windowType_ = static_cast(property->GetWindowType()); - sessionInfo.requestOrientation_ = static_cast(property->GetRequestedOrientation()); - WindowState windowState = property->GetWindowState(); - WLOGFI("[WMSRecover] Recover and reconnect sceneSession with: bundleName=%{public}s, moduleName=%{public}s, " - "abilityName=%{public}s, windowMode=%{public}d, windowType=%{public}u, persistentId=%{public}d, " - "windowState=%{public}u", - sessionInfo.bundleName_.c_str(), sessionInfo.moduleName_.c_str(), sessionInfo.abilityName_.c_str(), - sessionInfo.windowMode, sessionInfo.windowType_, sessionInfo.persistentId_, static_cast(windowState)); - sptr sceneSession = nullptr; - if (SessionHelper::IsMainWindow(property->GetWindowType())) { - sceneSession = RequestSceneSession(sessionInfo, nullptr); - } else { - sceneSession = RequestSceneSession(sessionInfo, property); - } - if (sceneSession == nullptr) { - WLOGFE("[WMSRecover] Request sceneSession failed"); - return WSError::WS_ERROR_NULLPTR; - } - auto ret = sceneSession->Reconnect(sessionStage, eventChannel, surfaceNode, property, token, - IPCSkeleton::GetCallingRealPid(), IPCSkeleton::GetCallingUid()); - if (ret != WSError::WS_OK) { - WLOGFE("[WMSRecover] Reconnect failed"); - std::unique_lock lock(sceneSessionMapMutex_); - sceneSessionMap_.erase(sessionInfo.persistentId_); - return ret; - } - sessionInfo.sessionState_ = sceneSession->GetSessionState(); - if (recoverSceneSessionFunc_) { - recoverSceneSessionFunc_(sceneSession, sessionInfo); - } else { - WLOGFE("[WMSRecover] recoverSceneSessionFunc_ is null"); - std::unique_lock lock(sceneSessionMapMutex_); - sceneSessionMap_.erase(sessionInfo.persistentId_); - return WSError::WS_ERROR_NULLPTR; - } - NotifySessionUnfocusedToClient(sceneSession->GetPersistentId()); - session = sceneSession; - return WSError::WS_OK; + auto pid = IPCSkeleton::GetCallingRealPid(); + auto uid = IPCSkeleton::GetCallingUid(); + auto task = [this, sessionStage, eventChannel, surfaceNode, &session, property, token, pid, uid]() { + if (recoveringFinished_) { + TLOGW(WmsLogTag::WMS_RECOVER, "Recover finished, not recovery anymore"); + return WSError::WS_ERROR_INVALID_OPERATION; + } + SessionInfo sessionInfo = RecoverSessionInfo(property); + sptr sceneSession = nullptr; + if (SessionHelper::IsMainWindow(property->GetWindowType())) { + sceneSession = RequestSceneSession(sessionInfo, nullptr); + } else { + sceneSession = RequestSceneSession(sessionInfo, property); + } + if (sceneSession == nullptr) { + WLOGFE("[WMSRecover] Request sceneSession failed"); + return WSError::WS_ERROR_NULLPTR; + } + auto ret = sceneSession->Reconnect(sessionStage, eventChannel, surfaceNode, property, token, pid, uid); + if (ret != WSError::WS_OK) { + WLOGFE("[WMSRecover] Reconnect failed"); + std::unique_lock lock(sceneSessionMapMutex_); + sceneSessionMap_.erase(sessionInfo.persistentId_); + return ret; + } + if (recoverSceneSessionFunc_) { + recoverSceneSessionFunc_(sceneSession, sessionInfo); + } else { + WLOGFE("[WMSRecover] recoverSceneSessionFunc_ is null"); + std::unique_lock lock(sceneSessionMapMutex_); + sceneSessionMap_.erase(sessionInfo.persistentId_); + return WSError::WS_ERROR_NULLPTR; + } + NotifySessionUnfocusedToClient(sceneSession->GetPersistentId()); + session = sceneSession; + return WSError::WS_OK; + }; + return taskScheduler_->PostSyncTask(task, "RecoverAndReconnectSceneSession"); } void SceneSessionManager::SetRecoverSceneSessionListener(const NotifyRecoverSceneSessionFunc& func) @@ -2210,6 +2333,11 @@ void SceneSessionManager::SetCreateSystemSessionListener(const NotifyCreateSyste createSystemSessionFunc_ = func; } +void SceneSessionManager::SetCreateKeyboardSessionListener(const NotifyCreateKeyboardSessionFunc& func) +{ + createKeyboardSessionFunc_ = func; +} + void SceneSessionManager::RegisterCreateSubSessionListener(int32_t persistentId, const NotifyCreateSubSessionFunc& func) { @@ -2245,10 +2373,13 @@ void SceneSessionManager::NotifyCreateSpecificSession(sptr newSess newSession->SetParentSession(parentSession); } } - if (createSystemSessionFunc_ && type != WindowType::WINDOW_TYPE_DIALOG) { + if (type != WindowType::WINDOW_TYPE_DIALOG) { if (WindowHelper::IsSystemSubWindow(type)) { NotifyCreateSubSession(property->GetParentPersistentId(), newSession); - } else { + } else if (isKeyboardPanelEnabled_ && type == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT + && createKeyboardSessionFunc_) { + createKeyboardSessionFunc_(newSession, newSession->GetKeyboardPanelSession()); + } else if (createSystemSessionFunc_) { createSystemSessionFunc_(newSession); } TLOGD(WmsLogTag::WMS_LIFE, "Create system session, id:%{public}d, type: %{public}d", @@ -2362,7 +2493,7 @@ void SceneSessionManager::NotifySessionTouchOutside(int32_t persistentId) } if (sceneSession->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT && sceneSession->GetSessionProperty() != nullptr) { - callingSessionId = sceneSession->GetSessionProperty()->GetCallingSessionId(); + callingSessionId = static_cast(sceneSession->GetSessionProperty()->GetCallingSessionId()); TLOGI(WmsLogTag::WMS_KEYBOARD, "persistentId: %{public}d, callingSessionId: %{public}d", persistentId, callingSessionId); } @@ -2850,7 +2981,7 @@ WMError SceneSessionManager::GetTopWindowId(uint32_t mainWinId, uint32_t& topWin for (const auto& subSession : subVec) { if (subSession != nullptr && (subSession->GetSessionState() == SessionState::STATE_FOREGROUND || subSession->GetSessionState() == SessionState::STATE_ACTIVE) && subSession->GetZOrder() > zOrder) { - topWinId = subSession->GetPersistentId(); + topWinId = static_cast(subSession->GetPersistentId()); zOrder = subSession->GetZOrder(); WLOGFD("[GetTopWin] Current zorder is larger than mainWin, mainId: %{public}d, topWinId: %{public}d, " "zOrder: %{public}d", mainWinId, topWinId, zOrder); @@ -4303,9 +4434,12 @@ void SceneSessionManager::NotifyFocusStatusByMission(sptr& prevSes bool SceneSessionManager::MissionChanged(sptr& prevSession, sptr& currSession) { - if (prevSession == nullptr || currSession == nullptr) { + if (prevSession == nullptr && currSession == nullptr) { return false; } + if (prevSession == nullptr || currSession == nullptr) { + return true; + } return prevSession->GetMissionId() != currSession->GetMissionId(); } @@ -4415,7 +4549,14 @@ static void FillSecCompEnhanceData(const std::shared_ptr& poi } #endif // SECURITY_COMPONENT_MANAGER_ENABLE -WSError SceneSessionManager::SendTouchEvent(const std::shared_ptr& pointerEvent, uint32_t zIndex) +void SceneSessionManager::UpdateLastDownEventDeviceId(int32_t deviceId) +{ + lastDownEventDeviceId_ = deviceId; + TLOGD(WmsLogTag::WMS_EVENT, "deviceId:%{public}d", lastDownEventDeviceId_); + return; +} + +WSError SceneSessionManager::SendTouchEvent(std::shared_ptr& pointerEvent, uint32_t zIndex) { if (!pointerEvent) { WLOGFE("pointerEvent is null"); @@ -4429,8 +4570,9 @@ WSError SceneSessionManager::SendTouchEvent(const std::shared_ptrGetPointerId(), pointerEvent->GetPointerAction()); + TLOGI(WmsLogTag::WMS_EVENT, "PointerId:%{public}d,action:%{public}d,deviceId:%{public}d", + pointerEvent->GetPointerId(), pointerEvent->GetPointerAction(), lastDownEventDeviceId_); + pointerEvent->SetDeviceId(lastDownEventDeviceId_); MMI::InputManager::GetInstance()->SimulateInputEvent(pointerEvent, static_cast(zIndex)); return WSError::WS_OK; } @@ -4438,6 +4580,23 @@ WSError SceneSessionManager::SendTouchEvent(const std::shared_ptr lock(sceneSessionMapMutex_); + for (auto iter : sceneSessionMap_) { + auto& session = iter.second; + if (session->GetDetectTaskInfo().taskState != DetectTaskState::NO_TASK) { + taskScheduler_->GetEventHandler()->RemoveTask(session->GetWindowDetectTaskName()); + DetectTaskInfo detectTaskInfo; + session->SetDetectTaskInfo(detectTaskInfo); + } + } } bool SceneSessionManager::IsScreenLocked() const @@ -4464,11 +4623,13 @@ int SceneSessionManager::GetSceneSessionPrivacyModeCount() bool isForeground = sceneSession->GetSessionState() == SessionState::STATE_FOREGROUND || sceneSession->GetSessionState() == SessionState::STATE_ACTIVE; if (isForeground && sceneSession->GetParentSession() != nullptr) { - isForeground &= sceneSession->GetParentSession()->GetSessionState() == SessionState::STATE_FOREGROUND || - sceneSession->GetParentSession()->GetSessionState() == SessionState::STATE_ACTIVE; + isForeground = isForeground && + (sceneSession->GetParentSession()->GetSessionState() == SessionState::STATE_FOREGROUND || + sceneSession->GetParentSession()->GetSessionState() == SessionState::STATE_ACTIVE); } bool isPrivate = sceneSession->GetSessionProperty() != nullptr && - sceneSession->GetSessionProperty()->GetPrivacyMode(); + (sceneSession->GetSessionProperty()->GetPrivacyMode() || + sceneSession->GetCombinedExtWindowFlags().privacyModeFlag); bool IsSystemWindowVisible = sceneSession->GetSessionInfo().isSystem_ && sceneSession->IsVisible(); return (isForeground || IsSystemWindowVisible) && isPrivate; }; @@ -4822,7 +4983,7 @@ void SceneSessionManager::CheckAndNotifyWaterMarkChangedResult() } bool hasWaterMark = session->GetSessionProperty()->GetWindowFlags() & static_cast(WindowFlag::WINDOW_FLAG_WATER_MARK); - bool isExtWindowHasWaterMarkFlag = session->IsExtWindowHasWaterMarkFlag(); + bool isExtWindowHasWaterMarkFlag = session->GetCombinedExtWindowFlags().waterMarkFlag; if ((hasWaterMark && session->GetVisible()) || isExtWindowHasWaterMarkFlag) { currentWaterMarkShowState = true; break; @@ -6512,6 +6673,7 @@ void SceneSessionManager::NotifySessionAINavigationBarChange(int32_t persistentI return; } AvoidArea avoidArea = sceneSession->GetAvoidAreaByType(AvoidAreaType::TYPE_NAVIGATION_INDICATOR); + sceneSession->SetIsDisplayStatusBarTemporarily(false); if (!CheckAvoidAreaForAINavigationBar(isAINavigationBarVisible_, avoidArea, sceneSession->GetSessionRect().posY_ + sceneSession->GetSessionRect().height_)) { return; @@ -7617,7 +7779,7 @@ WSError SceneSessionManager::HandleSecureSessionShouldHide(const sptrGetPersistentId(); - auto shouldHide = sceneSession->ShouldHideNonSecureWindows(); + auto shouldHide = sceneSession->GetCombinedExtWindowFlags().hideNonSecureWindowsFlag; size_t sizeBefore = 0; size_t sizeAfter = 0; AddSecureSession(persistentId, shouldHide, sizeBefore, sizeAfter); @@ -7640,6 +7802,11 @@ WSError SceneSessionManager::HandleSecureExtSessionShouldHide(int32_t persistent WSError SceneSessionManager::AddOrRemoveSecureSession(int32_t persistentId, bool shouldHide) { TLOGI(WmsLogTag::WMS_UIEXT, "persistentId=%{public}d, shouldHide=%{public}u", persistentId, shouldHide); + if (!SessionPermission::IsSystemCalling()) { + TLOGE(WmsLogTag::WMS_UIEXT, "HideNonSecureWindows permission denied!"); + return WSError::WS_ERROR_NOT_SYSTEM_APP; + } + auto task = [this, persistentId, shouldHide]() { std::shared_lock lock(sceneSessionMapMutex_); auto iter = sceneSessionMap_.find(persistentId); @@ -7658,58 +7825,57 @@ WSError SceneSessionManager::AddOrRemoveSecureSession(int32_t persistentId, bool return WSError::WS_OK; } -WSError SceneSessionManager::AddOrRemoveSecureExtSession(int32_t persistentId, int32_t parentId, bool shouldHide) +WSError SceneSessionManager::UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags, + uint32_t extWindowActions) { - TLOGI(WmsLogTag::WMS_UIEXT, "persistentId=%{public}d, parentId=%{public}d, shouldHide=%{public}u", persistentId, - parentId, shouldHide); - if (!SessionPermission::IsSystemCalling()) { - TLOGE(WmsLogTag::WMS_UIEXT, "HideNonSecureWindows permission denied!"); - return WSError::WS_ERROR_NOT_SYSTEM_APP; + TLOGI(WmsLogTag::WMS_UIEXT, "parentId=%{public}d, persistentId=%{public}d, extWindowFlags=%{public}d, " + "actions=%{public}d", parentId, persistentId, extWindowFlags, extWindowActions); + + ExtensionWindowFlags actions(extWindowActions); + auto ret = WSError::WS_OK; + bool needSystemCalling = actions.hideNonSecureWindowsFlag || actions.waterMarkFlag; + if (needSystemCalling && !SessionPermission::IsSystemCalling()) { + actions.hideNonSecureWindowsFlag = false; + actions.waterMarkFlag = false; + TLOGE(WmsLogTag::WMS_UIEXT, "system calling permission denied!"); + ret = WSError::WS_ERROR_NOT_SYSTEM_APP; + } + auto needPrivacyWindow = actions.privacyModeFlag; + if (needPrivacyWindow && !SessionPermission::VerifyCallingPermission("ohos.permission.PRIVACY_WINDOW")) { + actions.privacyModeFlag = false; + TLOGE(WmsLogTag::WMS_UIEXT, "privacy window permission denied!"); + ret = WSError::WS_ERROR_INVALID_PERMISSION; + } + if (actions.bitData == 0) { + return ret; } - auto task = [this, persistentId, parentId, shouldHide]() { - std::shared_lock lock(sceneSessionMapMutex_); - auto iter = sceneSessionMap_.find(parentId); - if (iter == sceneSessionMap_.end()) { - TLOGD(WmsLogTag::WMS_UIEXT, "AddOrRemoveSecureExtSession: Parent session with persistentId %{public}d not " - "found", parentId); - // process UIExtension that created by SceneBoard - return HandleSecureExtSessionShouldHide(persistentId, shouldHide); - } - - auto sceneSession = iter->second; - sceneSession->AddOrRemoveSecureExtSession(persistentId, shouldHide); - return HandleSecureSessionShouldHide(sceneSession); - }; - - taskScheduler_->PostAsyncTask(task, "AddOrRemoveSecureExtSession"); - return WSError::WS_OK; -} - -WSError SceneSessionManager::UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags) -{ - TLOGI(WmsLogTag::WMS_UIEXT, "UpdateExtWindowFlags, parentId:%{public}d, persistentId:%{public}d, \ - extWindowFlags:%{public}d", parentId, persistentId, extWindowFlags); - if (!SessionPermission::IsSystemCalling()) { - TLOGE(WmsLogTag::WMS_UIEXT, "UpdateExtWindowFlags permission denied!"); - return WSError::WS_ERROR_NOT_SYSTEM_APP; - } - auto task = [this, parentId, persistentId, extWindowFlags]() { + ExtensionWindowFlags flags(extWindowFlags); + auto task = [this, parentId, persistentId, flags, actions]() { auto sceneSession = GetSceneSession(parentId); if (sceneSession == nullptr) { - TLOGE(WmsLogTag::WMS_UIEXT, "Session with persistentId %{public}d not found", parentId); - return WSError::WS_ERROR_INVALID_SESSION; + TLOGD(WmsLogTag::WMS_UIEXT, "UpdateExtWindowFlags: Parent session with persistentId %{public}d not found", + parentId); + return HandleSecureExtSessionShouldHide(persistentId, flags.hideNonSecureWindowsFlag); } - auto oldWaterMark = sceneSession->IsExtWindowHasWaterMarkFlag(); - sceneSession->UpdateExtWindowFlags(persistentId, extWindowFlags); - auto newWaterMark = sceneSession->IsExtWindowHasWaterMarkFlag(); - if (oldWaterMark != newWaterMark) { + + auto oldFlags = sceneSession->GetCombinedExtWindowFlags(); + sceneSession->UpdateExtWindowFlags(persistentId, flags, actions); + auto newFlags = sceneSession->GetCombinedExtWindowFlags(); + if (oldFlags.hideNonSecureWindowsFlag != newFlags.hideNonSecureWindowsFlag) { + HandleSecureSessionShouldHide(sceneSession); + } + if (oldFlags.waterMarkFlag != newFlags.waterMarkFlag) { CheckAndNotifyWaterMarkChangedResult(); } + if (oldFlags.privacyModeFlag != newFlags.privacyModeFlag) { + UpdatePrivateStateAndNotify(parentId); + } return WSError::WS_OK; }; + taskScheduler_->PostAsyncTask(task, "UpdateExtWindowFlags"); - return WSError::WS_OK; + return ret; } void SceneSessionManager::ReportWindowProfileInfos() @@ -7890,7 +8056,6 @@ bool SceneSessionManager::IsCovered(const sptr& sceneSession, return false; } - void SceneSessionManager::FilterSceneSessionForAccessibility(std::vector>& sceneSessionList) { for (auto it = sceneSessionList.begin(); it != sceneSessionList.end();) { @@ -7916,6 +8081,10 @@ void SceneSessionManager::NotifyAllAccessibilityInfo() bundle=%{public}s,bounds=(x = %{public}d, y = %{public}d, w = %{public}d, h = %{public}d)", item->wid_, item->innerWid_, item->bundleName_.c_str(), item->windowRect_.posX_, item->windowRect_.posY_, item->windowRect_.width_, item->windowRect_.height_); + for (const auto& rect : item->touchHotAreas_) { + TLOGD(WmsLogTag::WMS_MAIN, "window touch hot areas rect[x=%{public}d,y=%{public}d," \ + "w=%{public}d,h=%{public}d]", rect.posX_, rect.posY_, rect.width_, rect.height_); + } } SessionManagerAgentController::GetInstance().NotifyAccessibilityWindowInfo(accessibilityInfo, @@ -8045,4 +8214,17 @@ WMError SceneSessionManager::GetWindowBackHomeStatus(bool &isBackHome) WLOGFI("Get back home status success, isBackHome: %{public}d", isBackHome); return WMError::WM_OK; } + +int32_t SceneSessionManager::GetCustomDecorHeight(int32_t persistentId) +{ + int32_t height = 0; + auto sceneSession = GetSceneSession(persistentId); + if (sceneSession == nullptr) { + TLOGE(WmsLogTag::WMS_LAYOUT, "Session with persistentId %{public}d not found", persistentId); + return 0; + } + height = sceneSession->GetCustomDecorHeight(); + TLOGD(WmsLogTag::WMS_LAYOUT, "GetCustomDecorHeight: %{public}d", height); + return height; +} } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/src/screen_session_manager.cpp b/window_scene/session_manager/src/screen_session_manager.cpp index b7ddf8260b..0764c139fd 100644 --- a/window_scene/session_manager/src/screen_session_manager.cpp +++ b/window_scene/session_manager/src/screen_session_manager.cpp @@ -1595,19 +1595,18 @@ bool ScreenSessionManager::NotifyDisplayPowerEvent(DisplayPowerEvent event, Even agent->NotifyDisplayPowerEvent(event, status); } - auto screenIds = GetAllScreenIds(); - if (screenIds.empty()) { - WLOGFI("[UL_POWER]NotifyDisplayPowerEvent no screen info"); + std::lock_guard lock(screenSessionMapMutex_); + if (screenSessionMap_.empty()) { + WLOGFE("[UL_POWER]screenSessionMap is empty"); return false; } - - for (auto screenId : screenIds) { - sptr screen = GetScreenSession(screenId); - if (screen == nullptr) { - WLOGFW("[UL_POWER]Cannot get ScreenSession, screenId: %{public}" PRIu64"", screenId); + for (const auto& iter : screenSessionMap_) { + WLOGFI("[UL_POWER]PowerStatusChange to screenID: %{public}" PRIu64, iter.first); + if (!iter.second) { + WLOGFE("[UL_POWER]screensession is nullptr"); continue; } - screen->PowerStatusChange(event, status, reason); + iter.second->PowerStatusChange(event, status, reason); } return true; } diff --git a/window_scene/session_manager/src/window_scene_config.cpp b/window_scene/session_manager/src/window_scene_config.cpp index 5b142b64ee..c13ed4223f 100644 --- a/window_scene/session_manager/src/window_scene_config.cpp +++ b/window_scene/session_manager/src/window_scene_config.cpp @@ -39,6 +39,7 @@ const std::map WindowSceneConfig::con { "defaultMaximizeMode", WindowSceneConfig::ValueType::INTS }, { "miniWidth", WindowSceneConfig::ValueType::INTS }, { "miniHeight", WindowSceneConfig::ValueType::INTS }, + { "showInLandscapeMode", WindowSceneConfig::ValueType::INTS }, { "mainWindowSizeLimits", WindowSceneConfig::ValueType::MAP }, { "subWindowSizeLimits", WindowSceneConfig::ValueType::MAP }, { "windowAnimation", WindowSceneConfig::ValueType::MAP }, @@ -54,6 +55,7 @@ const std::map WindowSceneConfig::con { "unfocused", WindowSceneConfig::ValueType::MAP }, { "decor", WindowSceneConfig::ValueType::MAP }, { "startWindowTransitionAnimation", WindowSceneConfig::ValueType::MAP }, + { "systemUIStatusBar", WindowSceneConfig::ValueType::MAP }, { "curve", WindowSceneConfig::ValueType::POSITIVE_FLOATS }, { "splitRatios", WindowSceneConfig::ValueType::POSITIVE_FLOATS }, { "exitSplitRatios", WindowSceneConfig::ValueType::POSITIVE_FLOATS }, @@ -73,6 +75,8 @@ const std::map WindowSceneConfig::con { "split", WindowSceneConfig::ValueType::STRING }, { "float", WindowSceneConfig::ValueType::STRING }, { "color", WindowSceneConfig::ValueType::STRING }, + { "immersiveStatusBarBgColor", WindowSceneConfig::ValueType::STRING }, + { "immersiveStatusBarContentColor", WindowSceneConfig::ValueType::STRING }, { "supportedMode", WindowSceneConfig::ValueType::STRINGS }, { "minimizeByOther", WindowSceneConfig::ValueType::UNDIFINED }, { "stretchable", WindowSceneConfig::ValueType::UNDIFINED }, 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 9bb7f5f71d..d368b57b43 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 @@ -155,6 +155,9 @@ int SceneSessionManagerLiteStub::HandleRegisterSessionListener(MessageParcel& da { WLOGFD("run HandleRegisterSessionListener!"); sptr listener = iface_cast(data.ReadRemoteObject()); + if (listener == nullptr) { + return ERR_INVALID_DATA; + } WSError errCode = RegisterSessionListener(listener); reply.WriteInt32(static_cast(errCode)); return ERR_NONE; @@ -164,6 +167,9 @@ int SceneSessionManagerLiteStub::HandleUnRegisterSessionListener(MessageParcel& { WLOGFD("run HandleUnRegisterSessionListener!"); sptr listener = iface_cast(data.ReadRemoteObject()); + if (listener == nullptr) { + return ERR_INVALID_DATA; + } WSError errCode = UnRegisterSessionListener(listener); reply.WriteInt32(static_cast(errCode)); return ERR_NONE; diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp index 05c51b98ec..1f2132488f 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp @@ -1577,37 +1577,8 @@ WSError SceneSessionManagerProxy::AddOrRemoveSecureSession(int32_t persistentId, return static_cast(reply.ReadInt32()); } -WSError SceneSessionManagerProxy::AddOrRemoveSecureExtSession(int32_t persistentId, int32_t parentId, bool shouldHide) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - if (!data.WriteInterfaceToken(GetDescriptor())) { - TLOGE(WmsLogTag::WMS_UIEXT, "WriteInterfaceToken failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - if (!data.WriteInt32(persistentId)) { - TLOGE(WmsLogTag::WMS_UIEXT, "Write persistentId failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - if (!data.WriteInt32(parentId)) { - TLOGE(WmsLogTag::WMS_UIEXT, "Write parentId failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - if (!data.WriteBool(shouldHide)) { - TLOGE(WmsLogTag::WMS_UIEXT, "Write shouldHide failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - if (Remote()->SendRequest(static_cast( - SceneSessionManagerMessage::TRANS_ID_ADD_OR_REMOVE_SECURE_EXT_SESSION), - data, reply, option) != ERR_NONE) { - TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - return static_cast(reply.ReadInt32()); -} - -WSError SceneSessionManagerProxy::UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags) +WSError SceneSessionManagerProxy::UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags, + uint32_t extWindowActions) { TLOGD(WmsLogTag::WMS_UIEXT, "run SceneSessionManagerProxy::UpdateExtWindowFlags"); MessageParcel data; @@ -1626,7 +1597,11 @@ WSError SceneSessionManagerProxy::UpdateExtWindowFlags(int32_t parentId, int32_t return WSError::WS_ERROR_IPC_FAILED; } if (!data.WriteUint32(extWindowFlags)) { - TLOGE(WmsLogTag::WMS_UIEXT, "Write persistentId failed"); + TLOGE(WmsLogTag::WMS_UIEXT, "Write extWindowFlags failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + if (!data.WriteUint32(extWindowActions)) { + TLOGE(WmsLogTag::WMS_UIEXT, "Write extWindowActions failed"); return WSError::WS_ERROR_IPC_FAILED; } if (Remote()->SendRequest( diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp index b587eeb365..c6daf89bbc 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp @@ -141,8 +141,6 @@ const std::map SceneSessionManagerStub::s &SceneSessionManagerStub::HandleAddExtensionWindowStageToSCB), std::make_pair(static_cast(SceneSessionManagerMessage::TRANS_ID_ADD_OR_REMOVE_SECURE_SESSION), &SceneSessionManagerStub::HandleAddOrRemoveSecureSession), - std::make_pair(static_cast(SceneSessionManagerMessage::TRANS_ID_ADD_OR_REMOVE_SECURE_EXT_SESSION), - &SceneSessionManagerStub::HandleAddOrRemoveSecureExtSession), std::make_pair(static_cast(SceneSessionManagerMessage::TRANS_ID_UPDATE_EXTENSION_WINDOW_FLAGS), &SceneSessionManagerStub::HandleUpdateExtWindowFlags), std::make_pair(static_cast(SceneSessionManagerMessage::TRANS_ID_GET_HOST_WINDOW_RECT), @@ -401,6 +399,9 @@ int SceneSessionManagerStub::HandleRegisterSessionChangeListener(MessageParcel & { WLOGFI("run HandleRegisterSessionChangeListener!"); sptr listener = iface_cast(data.ReadRemoteObject()); + if (listener == nullptr) { + return ERR_INVALID_DATA; + } WSError errCode = RegisterSessionListener(listener); reply.WriteInt32(static_cast(errCode)); return ERR_NONE; @@ -435,6 +436,9 @@ int SceneSessionManagerStub::HandleRegisterSessionListener(MessageParcel& data, { WLOGFI("run HandleRegisterSessionListener!"); sptr listener = iface_cast(data.ReadRemoteObject()); + if (listener == nullptr) { + return ERR_INVALID_DATA; + } WSError errCode = RegisterSessionListener(listener); reply.WriteInt32(static_cast(errCode)); return ERR_NONE; @@ -444,6 +448,9 @@ int SceneSessionManagerStub::HandleUnRegisterSessionListener(MessageParcel& data { WLOGFI("run HandleUnRegisterSessionListener!"); sptr listener = iface_cast(data.ReadRemoteObject()); + if (listener == nullptr) { + return ERR_INVALID_DATA; + } WSError errCode = UnRegisterSessionListener(listener); reply.WriteInt32(static_cast(errCode)); return ERR_NONE; @@ -846,17 +853,20 @@ int SceneSessionManagerStub::HandleGetVisibilityWindowInfo(MessageParcel& data, return ERR_NONE; } -int SceneSessionManagerStub::HandleAddExtensionWindowStageToSCB(MessageParcel &data, MessageParcel &reply) +int SceneSessionManagerStub::HandleAddExtensionWindowStageToSCB(MessageParcel& data, MessageParcel& reply) { sptr sessionStageObject = data.ReadRemoteObject(); sptr sessionStage = iface_cast(sessionStageObject); + if (sessionStage == nullptr) { + return ERR_INVALID_DATA; + } int32_t persistentId = data.ReadInt32(); int32_t parentId = data.ReadInt32(); AddExtensionWindowStageToSCB(sessionStage, persistentId, parentId); return ERR_NONE; } -int SceneSessionManagerStub::HandleAddOrRemoveSecureSession(MessageParcel &data, MessageParcel &reply) +int SceneSessionManagerStub::HandleAddOrRemoveSecureSession(MessageParcel& data, MessageParcel& reply) { int32_t persistentId = data.ReadInt32(); bool shouldHide = data.ReadBool(); @@ -865,23 +875,13 @@ int SceneSessionManagerStub::HandleAddOrRemoveSecureSession(MessageParcel &data, return ERR_NONE; } -int SceneSessionManagerStub::HandleAddOrRemoveSecureExtSession(MessageParcel &data, MessageParcel &reply) +int SceneSessionManagerStub::HandleUpdateExtWindowFlags(MessageParcel& data, MessageParcel& reply) { - int32_t persistentId = data.ReadInt32(); - int32_t parentId = data.ReadInt32(); - bool shouldHide = data.ReadBool(); - WSError ret = AddOrRemoveSecureExtSession(persistentId, parentId, shouldHide); - reply.WriteInt32(static_cast(ret)); - return ERR_NONE; -} - -int SceneSessionManagerStub::HandleUpdateExtWindowFlags(MessageParcel &data, MessageParcel &reply) -{ - TLOGI(WmsLogTag::WMS_UIEXT, "run HandleRemoveExtensionSessionInfo!"); int32_t parentId = data.ReadInt32(); int32_t persistentId = data.ReadInt32(); uint32_t extWindowFlags = data.ReadUint32(); - WSError ret = UpdateExtWindowFlags(parentId, persistentId, extWindowFlags); + uint32_t extWindowActions = data.ReadUint32(); + WSError ret = UpdateExtWindowFlags(parentId, persistentId, extWindowFlags, extWindowActions); reply.WriteInt32(static_cast(ret)); return ERR_NONE; } diff --git a/window_scene/session_manager_service/BUILD.gn b/window_scene/session_manager_service/BUILD.gn index db3bba334c..19f4148839 100644 --- a/window_scene/session_manager_service/BUILD.gn +++ b/window_scene/session_manager_service/BUILD.gn @@ -26,6 +26,7 @@ ohos_shared_library("session_manager_service") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ @@ -44,6 +45,7 @@ ohos_shared_library("session_manager_service") { external_deps = [ "ability_runtime:ability_manager", "c_utils:utils", + "ffrt:libffrt", "graphic_2d:librender_service_client", "hilog:libhilog", "ipc:ipc_single", diff --git a/window_scene/test/unittest/BUILD.gn b/window_scene/test/unittest/BUILD.gn index 0cf19f4eb1..06431f5892 100644 --- a/window_scene/test/unittest/BUILD.gn +++ b/window_scene/test/unittest/BUILD.gn @@ -31,9 +31,11 @@ group("unittest") { ":ws_move_drag_controller_test", ":ws_root_scene_session_test", ":ws_scb_system_session_test", + ":ws_scene_input_manager_test", ":ws_scene_persistence_test", ":ws_scene_persistent_storage_test", ":ws_scene_session_converter_test", + ":ws_scene_session_dirty_manager_test", ":ws_scene_session_manager_proxy_test", ":ws_scene_session_manager_stub_test", ":ws_scene_session_manager_test", @@ -74,6 +76,28 @@ group("unittest") { ] } +ohos_unittest("ws_scene_input_manager_test") { + module_out_path = module_out_path + + sources = [ "scene_input_manager_test.cpp" ] + + deps = [ ":ws_unittest_common" ] + + external_deps = [ + "ability_runtime:app_manager", + "accessibility:accessibility_common", + "ace_engine:ace_uicontent", + "c_utils:utils", + "eventhandler:libeventhandler", + "graphic_2d:libcomposer", + "graphic_2d:window_animation", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "input:libmmi-client", + ] +} + ohos_unittest("ws_system_session_test") { module_out_path = module_out_path @@ -312,8 +336,10 @@ ohos_unittest("ws_session_test") { external_deps = [ "ability_base:session_info", "ability_base:want", + "ability_runtime:app_manager", "accessibility:accessibility_common", "c_utils:utils", + "eventhandler:libeventhandler", "hilog:libhilog", ] } @@ -457,6 +483,7 @@ ohos_unittest("ws_scene_session_manager_test") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "eventhandler:libeventhandler", "hilog:libhilog", ] } @@ -531,6 +558,26 @@ ohos_unittest("ws_scene_session_test") { ] } +ohos_unittest("ws_scene_session_dirty_manager_test") { + module_out_path = module_out_path + + sources = [ "scene_session_dirty_manager_test.cpp" ] + + deps = [ ":ws_unittest_common" ] + + external_deps = [ + "ability_base:configuration", + "ability_base:session_info", + "ability_runtime:ability_context_native", + "ability_runtime:mission_info", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "input:libmmi-client", + ] +} + ohos_unittest("ws_window_session_property_test") { module_out_path = module_out_path diff --git a/window_scene/test/unittest/keyboard_session_test.cpp b/window_scene/test/unittest/keyboard_session_test.cpp index 9f5ffa9c87..7c26054e23 100644 --- a/window_scene/test/unittest/keyboard_session_test.cpp +++ b/window_scene/test/unittest/keyboard_session_test.cpp @@ -216,35 +216,6 @@ HWTEST_F(KeyboardSessionTest, NotifyOccupiedAreaChangeInfo, Function | SmallTest keyboardSession->NotifyOccupiedAreaChangeInfo(callingSession, rect, occupiedArea); } -/** - * @tc.name: RaiseCallingSession - * @tc.desc: RaiseCallingSession - * @tc.type: FUNC - */ -HWTEST_F(KeyboardSessionTest, RaiseCallingSession, Function | SmallTest | Level1) -{ - SessionInfo info; - info.abilityName_ = "RaiseCallingSession"; - info.bundleName_ = "RaiseCallingSession"; - sptr specificCb = - new (std::nothrow) SceneSession::SpecificSessionCallback(); - EXPECT_NE(specificCb, nullptr); - sptr keyboardCb = - new (std::nothrow) KeyboardSession::KeyboardSessionCallback(); - EXPECT_NE(keyboardCb, nullptr); - sptr keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb); - EXPECT_NE(keyboardSession, nullptr); - - info.windowType_ = 1; - sptr sceneSession = new (std::nothrow) SceneSession(info, specificCb); - EXPECT_NE(sceneSession, nullptr); - auto id = sceneSession->GetPersistentId(); - EXPECT_NE(id, 0); - - keyboardSession->GetSessionProperty()->SetCallingSessionId(id); - keyboardSession->RaiseCallingSession(); -} - /** * @tc.name: RestoreCallingSession * @tc.desc: RestoreCallingSession @@ -303,35 +274,6 @@ HWTEST_F(KeyboardSessionTest, UseFocusIdIfCallingSessionIdInvalid, Function | Sm keyboardSession->UseFocusIdIfCallingSessionIdInvalid(); } -/** - * @tc.name: OnKeyboardSessionShown - * @tc.desc: OnKeyboardSessionShown - * @tc.type: FUNC - */ -HWTEST_F(KeyboardSessionTest, OnKeyboardSessionShown, Function | SmallTest | Level1) -{ - SessionInfo info; - info.abilityName_ = "OnKeyboardSessionShown"; - info.bundleName_ = "OnKeyboardSessionShown"; - sptr specificCb = - new (std::nothrow) SceneSession::SpecificSessionCallback(); - EXPECT_NE(specificCb, nullptr); - sptr keyboardCb = - new (std::nothrow) KeyboardSession::KeyboardSessionCallback(); - EXPECT_NE(keyboardCb, nullptr); - sptr keyboardSession = new (std::nothrow) KeyboardSession(info, specificCb, keyboardCb); - EXPECT_NE(keyboardSession, nullptr); - - info.windowType_ = 1; - sptr sceneSession = new (std::nothrow) SceneSession(info, specificCb); - EXPECT_NE(sceneSession, nullptr); - auto id = sceneSession->GetPersistentId(); - EXPECT_NE(id, 0); - - keyboardSession->GetSessionProperty()->SetCallingSessionId(id); - keyboardSession->OnKeyboardSessionShown(); -} - /** * @tc.name: UpdateCallingSessionIdAndPosition * @tc.desc: UpdateCallingSessionIdAndPosition @@ -432,22 +374,6 @@ HWTEST_F(KeyboardSessionTest, GetStatusBarHeight, Function | SmallTest | Level1) ASSERT_EQ(statusBarHeight, 0); } -/** - * @tc.name: GetCallingSession - * @tc.desc: GetCallingSession - * @tc.type: FUNC - */ -HWTEST_F(KeyboardSessionTest, GetCallingSession, Function | SmallTest | Level1) -{ - SessionInfo info; - info.abilityName_ = "RelayoutKeyBoard"; - info.bundleName_ = "RelayoutKeyBoard"; - sptr keyboardSession = new (std::nothrow) KeyboardSession(info, nullptr, nullptr); - EXPECT_NE(keyboardSession, nullptr); - - sptr callingSession = keyboardSession->GetCallingSession(); - ASSERT_EQ(callingSession, nullptr); -} } } } diff --git a/window_scene/test/unittest/main_session_test.cpp b/window_scene/test/unittest/main_session_test.cpp index 4581fa6dd1..b709bf336f 100644 --- a/window_scene/test/unittest/main_session_test.cpp +++ b/window_scene/test/unittest/main_session_test.cpp @@ -202,9 +202,6 @@ HWTEST_F(MainSessionTest, Reconnect01, Function | SmallTest | Level1) result = mainSession_->Reconnect(mockSessionStage, nullptr, surfaceNode, property); ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); - result = mainSession_->Reconnect(mockSessionStage, testWindowEventChannel, surfaceNode, nullptr); - ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); - result = mainSession_->Reconnect(mockSessionStage, testWindowEventChannel, surfaceNode, property); ASSERT_EQ(result, WSError::WS_OK); } diff --git a/window_scene/test/unittest/move_drag_controller_test.cpp b/window_scene/test/unittest/move_drag_controller_test.cpp index 27ef7a0b1d..3797f7d49d 100644 --- a/window_scene/test/unittest/move_drag_controller_test.cpp +++ b/window_scene/test/unittest/move_drag_controller_test.cpp @@ -475,22 +475,11 @@ HWTEST_F(MoveDragControllerTest, ConsumeDragEvent, Function | SmallTest | Level1 WSRect originalRect = { 100, 100, 1000, 1000 }; sptr property = new WindowSessionProperty(); SystemSessionConfig sysConfig; + moveDragController->GetVirtualPixelRatio(); ASSERT_EQ(false, moveDragController->ConsumeDragEvent(nullptr, originalRect, property, sysConfig)); ASSERT_EQ(false, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, nullptr, sysConfig)); ASSERT_EQ(false, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig)); } - -/** - * @tc.name: GetVirtualPixelRatio - * @tc.desc: test function : GetVirtualPixelRatio - * @tc.type: FUNC - */ -HWTEST_F(MoveDragControllerTest, GetVirtualPixelRatio, Function | SmallTest | Level1) -{ - float vpr = 1.5; - float vpr01 = moveDragController->GetVirtualPixelRatio(); - ASSERT_EQ(vpr, vpr01); -} } } } \ No newline at end of file diff --git a/window_scene/test/unittest/scene_input_manager_test.cpp b/window_scene/test/unittest/scene_input_manager_test.cpp new file mode 100644 index 0000000000..7bb380d2db --- /dev/null +++ b/window_scene/test/unittest/scene_input_manager_test.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "scene_input_manager.h" +#include + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +class SceneInputManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void SceneInputManagerTest::SetUpTestCase() +{ +} + +void SceneInputManagerTest::TearDownTestCase() +{ +} + +void SceneInputManagerTest::SetUp() +{ +} + +void SceneInputManagerTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: FlushDisplayInfoToMMI + * @tc.desc: check func FlushDisplayInfoToMMI + * @tc.type: FUNC + */ +HWTEST_F(SceneInputManagerTest, FlushDisplayInfoToMMI, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "SceneInputManagerTest: FlushDisplayInfoToMMI start"; + int ret = 0; + SceneInputManager::GetInstance().FlushDisplayInfoToMMI(); + ASSERT_EQ(ret, 0); + GTEST_LOG_(INFO) << "SceneInputManagerTest: FlushDisplayInfoToMMI end"; +} + +/** +* @tc.name: NotifyWindowInfoChange +* @tc.desc: check func NotifyWindowInfoChange +* @tc.type: FUNC +*/ +HWTEST_F(SceneInputManagerTest, NotifyWindowInfoChange, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "SceneInputManagerTest: NotifyWindowInfoChange start"; + SessionInfo info; + info.abilityName_ = "BindDialogSessionTarget"; + info.bundleName_ = "BindDialogSessionTarget"; + sptr specificCallback_ + = new (std::nothrow) SceneSession::SpecificSessionCallback(); + EXPECT_NE(specificCallback_, nullptr); + sptr sceneSession = new SceneSession(info, specificCallback_); + + SceneInputManager::GetInstance() + .NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_ADDED); + GTEST_LOG_(INFO) << "SceneInputManagerTest: NotifyWindowInfoChange end"; +} + +/** +* @tc.name: NotifyWindowInfoChangeFromSession +* @tc.desc: check func NotifyWindowInfoChangeFromSession +* @tc.type: FUNC +*/ +HWTEST_F(SceneInputManagerTest, NotifyWindowInfoChangeFromSession, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "SceneInputManagerTest: NotifyWindowInfoChangeFromSession start"; + SessionInfo info; + info.abilityName_ = "BindDialogSessionTarget"; + info.bundleName_ = "BindDialogSessionTarget"; + sptr specificCallback_ + = new (std::nothrow) SceneSession::SpecificSessionCallback(); + EXPECT_NE(specificCallback_, nullptr); + sptr sceneSession = new SceneSession(info, specificCallback_); + + SceneInputManager::GetInstance().NotifyWindowInfoChangeFromSession(sceneSession); + GTEST_LOG_(INFO) << "SceneInputManagerTest: NotifyWindowInfoChangeFromSession end"; +} + +/** +* @tc.name: NotifyMMIWindowPidChange +* @tc.desc: check func NotifyMMIWindowPidChange +* @tc.type: FUNC +*/ +HWTEST_F(SceneInputManagerTest, NotifyMMIWindowPidChange, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "SceneInputManagerTest: NotifyMMIWindowPidChange start"; + SessionInfo info; + info.abilityName_ = "BindDialogSessionTarget"; + info.bundleName_ = "BindDialogSessionTarget"; + sptr specificCallback_ + = new (std::nothrow) SceneSession::SpecificSessionCallback(); + EXPECT_NE(specificCallback_, nullptr); + sptr sceneSession = new SceneSession(info, specificCallback_); + + SceneInputManager::GetInstance().NotifyMMIWindowPidChange(sceneSession, true); + GTEST_LOG_(INFO) << "SceneInputManagerTest: NotifyMMIWindowPidChange end"; +} + +} +} +} \ No newline at end of file diff --git a/window_scene/test/unittest/scene_session_dirty_manager_test.cpp b/window_scene/test/unittest/scene_session_dirty_manager_test.cpp new file mode 100644 index 0000000000..eff2d604cf --- /dev/null +++ b/window_scene/test/unittest/scene_session_dirty_manager_test.cpp @@ -0,0 +1,352 @@ +/* + * Copyright (c) 2023 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 "input_manager.h" +#include "session_manager/include/scene_session_dirty_manager.h" +#include +#include "screen_session_manager/include/screen_session_manager_client.h" +#include "session/host/include/scene_session.h" +#include "session_manager/include/scene_session_manager.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +class SceneSessionDirtyManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; +SceneSessionDirtyManager *manager_; +SceneSessionManager *ssm_; +void SceneSessionDirtyManagerTest::SetUpTestCase() +{ + ssm_ = &SceneSessionManager::GetInstance(); + ssm_->sceneSessionMap_.clear(); +} + +void SceneSessionDirtyManagerTest::TearDownTestCase() +{ + ssm_ = nullptr; +} + +void SceneSessionDirtyManagerTest::SetUp() +{ + manager_ = new SceneSessionDirtyManager(); +} + +void SceneSessionDirtyManagerTest::TearDown() +{ + delete manager_; + manager_ = nullptr; +} +namespace { + +/** + * @tc.name: NotifyWindowInfoChange + * @tc.desc: NotifyWindowInfoChange + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest, NotifyWindowInfoChange, Function | SmallTest | Level2) +{ + int ret = 0; + manager_->NotifyWindowInfoChange(nullptr, WindowUpdateType::WINDOW_UPDATE_ADDED, true); + SessionInfo info; + info.abilityName_ = "TestAbilityName"; + info.bundleName_ = "TestBundleName"; + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + if (sceneSession == nullptr) { + return; + } + manager_->NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_ADDED, true); + manager_->NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_REMOVED, true); + manager_->NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_ACTIVE, true); + manager_->NotifyWindowInfoChange(sceneSession, WindowUpdateType::WINDOW_UPDATE_FOCUSED, true); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: GetFullWindowInfoList + * @tc.desc: GetFullWindowInfoList + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest, GetFullWindowInfoList, Function | SmallTest | Level2) +{ + int ret = 0; + SessionInfo info; + info.abilityName_ = "TestAbilityName"; + info.bundleName_ = "TestBundleName"; + { + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + if (sceneSession == nullptr) { + return; + } + ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession}); + } + { + ssm_->sceneSessionMap_.insert({111, nullptr}); + } + { + sptr sceneSessionDialog1 = new (std::nothrow) SceneSession(info, nullptr); + if (sceneSessionDialog1 == nullptr) { + return; + } + sptr propertyDialog1 = sceneSessionDialog1->GetSessionProperty(); + propertyDialog1->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); + ssm_->sceneSessionMap_.insert({sceneSessionDialog1->GetPersistentId(), sceneSessionDialog1}); + } + { + sptr sceneSessionModal1 = new (std::nothrow) SceneSession(info, nullptr); + if (sceneSessionModal1 == nullptr) { + return; + } + sptr propertyModal1 = sceneSessionModal1->GetSessionProperty(); + propertyModal1->SetWindowFlags(static_cast(WindowFlag::WINDOW_FLAG_IS_MODAL)); + ssm_->sceneSessionMap_.insert({sceneSessionModal1->GetPersistentId(), sceneSessionModal1}); + } + manager_->GetFullWindowInfoList(); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: IsFilterSession + * @tc.desc: IsFilterSession + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest, IsFilterSession, Function | SmallTest | Level2) +{ + int ret = 0; + manager_->IsFilterSession(nullptr); + SessionInfo info; + info.abilityName_ = "test1"; + info.bundleName_ = "test2"; + info.isSystemInput_ = true; + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + if (sceneSession == nullptr) { + return; + } + sptr property = sceneSession->GetSessionProperty(); + info.isSystemInput_ = true; + manager_->IsFilterSession(sceneSession); + info.isSystemInput_ = false; + info.isSystem_ = false; + sceneSession->isVisible_ = false; + sceneSession->isSystemActive_ = false; + manager_->IsFilterSession(sceneSession); + info.isSystem_ = true; + manager_->IsFilterSession(sceneSession); + sceneSession->isVisible_ = true; + manager_->IsFilterSession(sceneSession); + sceneSession->isSystemActive_ = true; + manager_->IsFilterSession(sceneSession); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: GetWindowInfo + * @tc.desc: GetWindowInfo + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest, GetWindowInfo, Function | SmallTest | Level2) +{ + int ret = 0; + manager_->GetWindowInfo(nullptr, SceneSessionDirtyManager::WindowAction::WINDOW_ADD); + SessionInfo info; + info.abilityName_ = "111"; + info.bundleName_ = "111"; + sptr session = new (std::nothrow) SceneSession(info, nullptr); + if (session == nullptr) { + return; + } + manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD); + session = new (std::nothrow) SceneSession(info, nullptr); + if (session == nullptr) { + return; + } + sptr windowSessionProperty = session->GetSessionProperty(); + manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD); + windowSessionProperty->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING); + manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD); + windowSessionProperty->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); + manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD); + windowSessionProperty->SetMaximizeMode(Rosen::MaximizeMode::MODE_AVOID_SYSTEM_BAR); + manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD); + info.isSetPointerAreas_ = true; + manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD); + windowSessionProperty->SetWindowFlags(static_cast(WindowFlag::WINDOW_FLAG_HANDWRITING)); + manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD); + windowSessionProperty->SetWindowFlags(static_cast(WindowFlag::WINDOW_FLAG_IS_MODAL)); + manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: CalNotRotateTramform + * @tc.desc: CalNotRotateTramform + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest, CalNotRotateTramform, Function | SmallTest | Level2) +{ + int ret = 0; + SessionInfo sessionInfo; + sessionInfo.bundleName_ = "CalNotRotateTramform"; + sessionInfo.moduleName_ = "sessionInfo"; + Matrix3f tranform; + sptr sceneSession = new (std::nothrow) SceneSession(sessionInfo, nullptr); + manager_->CalNotRotateTramform(nullptr, tranform); + sceneSession->GetSessionProperty()->SetDisplayId(0); + manager_->CalNotRotateTramform(sceneSession, tranform); + std::map screensProperties = + Rosen::ScreenSessionManagerClient::GetInstance().GetAllScreensProperties(); + ScreenProperty screenProperty0; + screenProperty0.SetRotation(0.0f); + Rosen::ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::UNKNOWN); + Rosen::ScreenSessionManagerClient::GetInstance().GetAllScreensProperties().insert( + std::make_pair(0, screenProperty0)); + manager_->CalNotRotateTramform(sceneSession, tranform); + Rosen::ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::FULL); + manager_->CalNotRotateTramform(sceneSession, tranform); + ScreenProperty screenProperty1; + screenProperty1.SetRotation(90.0f); + Rosen::ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::UNKNOWN); + Rosen::ScreenSessionManagerClient::GetInstance().GetAllScreensProperties().insert( + std::make_pair(1, screenProperty1)); + sceneSession->GetSessionProperty()->SetDisplayId(1); + manager_->CalNotRotateTramform(sceneSession, tranform); + Rosen::ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::FULL); + manager_->CalNotRotateTramform(sceneSession, tranform); + ScreenProperty screenProperty2; + screenProperty2.SetRotation(180.0f); + Rosen::ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::UNKNOWN); + Rosen::ScreenSessionManagerClient::GetInstance().GetAllScreensProperties().insert( + std::make_pair(2, screenProperty2)); + sceneSession->GetSessionProperty()->SetDisplayId(2); + manager_->CalNotRotateTramform(sceneSession, tranform); + Rosen::ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::FULL); + manager_->CalNotRotateTramform(sceneSession, tranform); + ScreenProperty screenProperty3; + screenProperty3.SetRotation(270.0f); + Rosen::ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::UNKNOWN); + Rosen::ScreenSessionManagerClient::GetInstance().GetAllScreensProperties().insert( + std::make_pair(3, screenProperty3)); + sceneSession->GetSessionProperty()->SetDisplayId(3); + manager_->CalNotRotateTramform(sceneSession, tranform); + Rosen::ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::FULL); + manager_->CalNotRotateTramform(sceneSession, tranform); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: CalTramform + * @tc.desc: CalTramform + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest, CalTramform, Function | SmallTest | Level2) +{ + int ret = 0; + SessionInfo sessionInfo; + sessionInfo.bundleName_ = "CalTramform"; + sessionInfo.moduleName_ = "CalTramform"; + sptr sceneSession = new (std::nothrow) SceneSession(sessionInfo, nullptr); + if (sceneSession == nullptr) { + return; + } + Matrix3f tranform; + manager_->CalTramform(nullptr, tranform); + sessionInfo.isRotable_ = true; + manager_->CalTramform(sceneSession, tranform); + sessionInfo.isSystem_ = true; + manager_->CalTramform(sceneSession, tranform); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: UpdateHotAreas + * @tc.desc: UpdateHotAreas + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest, UpdateHotAreas, Function | SmallTest | Level2) +{ + int ret = 0; + std::vector empty(0); + manager_->UpdateHotAreas(nullptr, empty, empty); + SessionInfo sessionInfo; + sessionInfo.bundleName_ = "UpdateHotAreas"; + sessionInfo.moduleName_ = "UpdateHotAreas"; + sptr sceneSession = new (std::nothrow) SceneSession(sessionInfo, nullptr); + if (sceneSession == nullptr) { + return; + } + std::vector touchHotAreas(0); + std::vector pointerHotAreas(0); + std::vector touchHotAreasInSceneSession(0); + sceneSession->GetSessionProperty()->SetTouchHotAreas(touchHotAreasInSceneSession); + sceneSession->persistentId_ = 1; + for (int i = 0; i < 2 ; i++) { + OHOS::Rosen::Rect area; + area.posX_ = i * 10; + area.posY_ = i * 10; + area.width_ = 10; + area.height_ = 10; + touchHotAreasInSceneSession.emplace_back(area); + } + manager_->UpdateHotAreas(sceneSession, touchHotAreas, pointerHotAreas); + for (int i = 2; i < 10 ; i++) { + OHOS::Rosen::Rect area; + area.posX_ = i * 10; + area.posY_ = i * 10; + area.width_ = 10; + area.height_ = 10; + touchHotAreasInSceneSession.emplace_back(area); + } + manager_->UpdateHotAreas(sceneSession, touchHotAreas, pointerHotAreas); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: UpdateDefaultHotAreas + * @tc.desc: UpdateDefaultHotAreas + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest, UpdateDefaultHotAreas, Function | SmallTest | Level2) +{ + int ret = 0; + std::vector empty(0); + manager_->UpdateDefaultHotAreas(nullptr, empty, empty); + SessionInfo sessionInfo; + sessionInfo.bundleName_ = "UpdateDefaultHotAreas"; + sessionInfo.moduleName_ = "UpdateDefaultHotAreas"; + sptr sceneSession = new (std::nothrow) SceneSession(sessionInfo, nullptr); + if (sceneSession == nullptr) { + return; + } + WSRect rect = {0, 0, 320, 240}; + sceneSession->SetSessionRect(rect); + manager_->UpdateDefaultHotAreas(sceneSession, empty, empty); + sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + manager_->UpdateDefaultHotAreas(sceneSession, empty, empty); + sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_PIP); + manager_->UpdateDefaultHotAreas(sceneSession, empty, empty); + sceneSession->SetSessionProperty(nullptr); + manager_->UpdateDefaultHotAreas(sceneSession, empty, empty); + ASSERT_EQ(ret, 0); +} + +} // namespace +} // namespace Rosen +} // namespace OHOS diff --git a/window_scene/test/unittest/scene_session_manager_proxy_test.cpp b/window_scene/test/unittest/scene_session_manager_proxy_test.cpp index aa0e9a2f28..d69da48718 100644 --- a/window_scene/test/unittest/scene_session_manager_proxy_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_proxy_test.cpp @@ -94,28 +94,27 @@ HWTEST_F(sceneSessionManagerProxyTest, UpdateSessionWindowVisibilityListener001, HWTEST_F(sceneSessionManagerProxyTest, AddOrRemoveSecureSession001, Function | SmallTest | Level2) { sptr iRemoteObjectMocker = new (std::nothrow) IRemoteObjectMocker(); - sptr sceneSessionManagerProxy_ = new SceneSessionManagerProxy(iRemoteObjectMocker); + sptr sceneSessionManagerProxy = new SceneSessionManagerProxy(iRemoteObjectMocker); int32_t persistentId = 12345; - ASSERT_EQ(WSError::WS_OK, sceneSessionManagerProxy_->AddOrRemoveSecureSession(persistentId, true)); - sceneSessionManagerProxy_ = nullptr; + ASSERT_EQ(WSError::WS_OK, sceneSessionManagerProxy->AddOrRemoveSecureSession(persistentId, true)); + sceneSessionManagerProxy = nullptr; } /** - * @tc.name: AddOrRemoveSecureExtSession001 + * @tc.name: UpdateExtWindowFlags * @tc.desc: normal function * @tc.type: FUNC */ -HWTEST_F(sceneSessionManagerProxyTest, AddOrRemoveSecureExtSession001, Function | SmallTest | Level2) +HWTEST_F(sceneSessionManagerProxyTest, UpdateExtWindowFlags, Function | SmallTest | Level2) { sptr iRemoteObjectMocker = new (std::nothrow) IRemoteObjectMocker(); - sptr sceneSessionManagerProxy_ = new SceneSessionManagerProxy(iRemoteObjectMocker); + sptr sceneSessionManagerProxy = new SceneSessionManagerProxy(iRemoteObjectMocker); - int32_t persistentId = 12345; int32_t parentId = 1234; - ASSERT_EQ(WSError::WS_OK, sceneSessionManagerProxy_->AddOrRemoveSecureExtSession(persistentId, parentId, - true)); - sceneSessionManagerProxy_ = nullptr; + int32_t persistentId = 12345; + ASSERT_EQ(WSError::WS_OK, sceneSessionManagerProxy->UpdateExtWindowFlags(parentId, persistentId, 7, 7)); + sceneSessionManagerProxy = nullptr; } /** @@ -212,7 +211,7 @@ HWTEST_F(sceneSessionManagerProxyTest, IsValidSessionIds, Function | SmallTest | sptr iRemoteObjectMocker = new (std::nothrow) IRemoteObjectMocker(); sptr sceneSessionManagerProxy_ = new SceneSessionManagerProxy(iRemoteObjectMocker); - ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, sceneSessionManagerProxy_->IsValidSessionIds(sessionIds, results)); + ASSERT_EQ(WSError::WS_OK, sceneSessionManagerProxy_->IsValidSessionIds(sessionIds, results)); sceneSessionManagerProxy_ = nullptr; } @@ -242,7 +241,7 @@ HWTEST_F(sceneSessionManagerProxyTest, PendingSessionToBackgroundForDelegator, F sptr iRemoteObjectMocker = new (std::nothrow) IRemoteObjectMocker(); sptr sceneSessionManagerProxy_ = new SceneSessionManagerProxy(iRemoteObjectMocker); - ASSERT_EQ(WSError::WS_OK, sceneSessionManagerProxy_->PendingSessionToBackgroundForDelegator(token)); + ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, sceneSessionManagerProxy_->PendingSessionToBackgroundForDelegator(token)); sceneSessionManagerProxy_ = nullptr; } @@ -272,7 +271,7 @@ HWTEST_F(sceneSessionManagerProxyTest, UnRegisterSessionListener, Function | Sma sptr iRemoteObjectMocker = new (std::nothrow) IRemoteObjectMocker(); sptr sceneSessionManagerProxy_ = new SceneSessionManagerProxy(iRemoteObjectMocker); - ASSERT_EQ(WSError::WS_OK, sceneSessionManagerProxy_->UnRegisterSessionListener(listener)); + ASSERT_EQ(WSError::WS_ERROR_INVALID_PARAM, sceneSessionManagerProxy_->UnRegisterSessionListener(listener)); sceneSessionManagerProxy_ = nullptr; } @@ -331,7 +330,7 @@ HWTEST_F(sceneSessionManagerProxyTest, RegisterIAbilityManagerCollaborator, Func sptr iRemoteObjectMocker = new (std::nothrow) IRemoteObjectMocker(); sptr sceneSessionManagerProxy_ = new SceneSessionManagerProxy(iRemoteObjectMocker); - ASSERT_EQ(WSError::WS_OK, sceneSessionManagerProxy_->RegisterIAbilityManagerCollaborator(0, impl)); + ASSERT_EQ(WSError::WS_ERROR_INVALID_PARAM, sceneSessionManagerProxy_->RegisterIAbilityManagerCollaborator(0, impl)); sceneSessionManagerProxy_ = nullptr; } diff --git a/window_scene/test/unittest/scene_session_manager_stub_test.cpp b/window_scene/test/unittest/scene_session_manager_stub_test.cpp index bc449c5c54..c4069b3062 100644 --- a/window_scene/test/unittest/scene_session_manager_stub_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_stub_test.cpp @@ -415,25 +415,7 @@ HWTEST_F(SceneSessionManagerStubTest, HandleAddOrRemoveSecureSession, Function | data.WriteInt32(12345); data.WriteBool(true); - int res = stub_->HandleAddOrRemoveSecureExtSession(data, reply); - EXPECT_EQ(res, ERR_NONE); -} - -/** - * @tc.name: HandleAddOrRemoveSecureExtSession - * @tc.desc: test HandleAddOrRemoveSecureExtSession - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionManagerStubTest, HandleAddOrRemoveSecureExtSession, Function | SmallTest | Level2) -{ - MessageParcel data; - MessageParcel reply; - - data.WriteInt32(12345); - data.WriteInt32(1234); - data.WriteBool(true); - - int res = stub_->HandleAddOrRemoveSecureExtSession(data, reply); + int res = stub_->HandleAddOrRemoveSecureSession(data, reply); EXPECT_EQ(res, ERR_NONE); } @@ -453,6 +435,25 @@ HWTEST_F(SceneSessionManagerStubTest, HandleGetSessionInfoByContinueSessionId, F EXPECT_EQ(res, ERR_NONE); } +/** + * @tc.name: HandleUpdateExtWindowFlags + * @tc.desc: test HandleUpdateExtWindowFlags + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerStubTest, HandleUpdateExtWindowFlags, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + data.WriteInt32(1234); + data.WriteInt32(12345); + data.WriteInt32(7); + data.WriteInt32(7); + + int res = stub_->HandleUpdateExtWindowFlags(data, reply); + EXPECT_EQ(res, ERR_NONE); +} + } } } \ 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 36193fe414..dc23df54a8 100644 --- a/window_scene/test/unittest/scene_session_manager_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_test.cpp @@ -1312,6 +1312,32 @@ HWTEST_F(SceneSessionManagerTest, ConfigSnapshotScale05, Function | SmallTest | ASSERT_EQ(ssm_->snapshotScale_, 0.7f); } +/** + * @tc.name: ConfigSystemUIStatusBar01 + * @tc.desc: call ConfigSystemUIStatusBar default. + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest, ConfigSystemUIStatusBar01, Function | SmallTest | Level3) +{ + std::string xmlStr = "" + "" + "" + "1" + "#4c000000" + "#ffffee" + "" + ""; + WindowSceneConfig::config_ = ReadConfig(xmlStr); + SceneSessionManager* sceneSessionManager = new SceneSessionManager(); + sceneSessionManager->ConfigWindowSceneXml(); + ASSERT_EQ(sceneSessionManager->appWindowSceneConfig_.systemUIStatusBarConfig_.showInLandscapeMode_, 1); + ASSERT_STREQ(sceneSessionManager->appWindowSceneConfig_.systemUIStatusBarConfig_.immersiveStatusBarBgColor_.c_str(), + "#4c000000"); + ASSERT_STREQ(sceneSessionManager->appWindowSceneConfig_.systemUIStatusBarConfig_. + immersiveStatusBarContentColor_.c_str(), "#ffffee"); + delete sceneSessionManager; +} + /** * @tc.name: DumpSessionAll * @tc.desc: ScreenSesionManager dump all session info @@ -1359,6 +1385,7 @@ HWTEST_F(SceneSessionManagerTest, Init, Function | SmallTest | Level3) { int ret = 0; ssm_->Init(); + ssm_->RegisterAppListener(); ASSERT_EQ(ret, 0); } @@ -1371,6 +1398,35 @@ HWTEST_F(SceneSessionManagerTest, LoadWindowSceneXml, Function | SmallTest | Lev { int ret = 0; ssm_->LoadWindowSceneXml(); + ssm_->ConfigWindowSceneXml(); + ssm_->SetEnableInputEvent(true); + ssm_->SetEnableInputEvent(false); + ASSERT_EQ(ssm_->IsInputEventEnabled(), false); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: UpdateRecoveredSessionInfo + * @tc.desc: SceneSessionManager load window scene xml + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest, UpdateRecoveredSessionInfo, Function | SmallTest | Level3) +{ + int ret = 0; + std::vector recoveredPersistentIds; + ssm_->UpdateRecoveredSessionInfo(recoveredPersistentIds); + recoveredPersistentIds.push_back(0); + ssm_->UpdateRecoveredSessionInfo(recoveredPersistentIds); + SessionInfo info; + info.abilityName_ = "test1"; + info.bundleName_ = "test2"; + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + if (sceneSession == nullptr) { + return; + } + ssm_->sceneSessionMap_.insert({0, sceneSession}); + ssm_->UpdateRecoveredSessionInfo(recoveredPersistentIds); + ssm_->sceneSessionMap_.erase(0); ASSERT_EQ(ret, 0); } @@ -1403,6 +1459,31 @@ HWTEST_F(SceneSessionManagerTest, SetSessionContinueState, Function | SmallTest delete data; } +/** + * @tc.name: SetSessionContinueState002 + * @tc.desc: SceneSesionManager set session continue state + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest, SetSessionContinueState002, Function | SmallTest | Level3) +{ + MessageParcel *data = new MessageParcel(); + sptr token = data->ReadRemoteObject(); + auto continueState = static_cast(0); + SessionInfo info; + info.abilityName_ = "test1"; + info.bundleName_ = "test2"; + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + if (sceneSession == nullptr) { + delete data; + return; + } + sceneSession->SetSelfToken(token); + ssm_->sceneSessionMap_.insert({1000, sceneSession}); + ssm_->SetSessionContinueState(token, continueState); + ASSERT_NE(sceneSession, nullptr); + delete data; +} + /** * @tc.name: ConfigDecor * @tc.desc: SceneSesionManager config decor @@ -1510,6 +1591,7 @@ HWTEST_F(SceneSessionManagerTest, ConfigKeyboardAnimation, Function | SmallTest animationConfig.SetValue({{"timing", itemCurve}, {"timing", itemDurationIn}, {"timing", itemDurationOut}}); int ret = 0; ssm_->ConfigKeyboardAnimation(animationConfig); + ssm_->ConfigDefaultKeyboardAnimation(); ASSERT_EQ(ret, 0); } @@ -1666,6 +1748,7 @@ HWTEST_F(SceneSessionManagerTest, GetRootSceneSession, Function | SmallTest | Le { int ret = 0; ssm_->GetRootSceneSession(); + ssm_->GetRootSceneSession(); ASSERT_EQ(ret, 0); } @@ -1680,6 +1763,25 @@ HWTEST_F(SceneSessionManagerTest, GetSceneSession, Function | SmallTest | Level3 ASSERT_EQ(ssm_->GetSceneSession(persistentId), nullptr); } +/** + * @tc.name: GetSceneSession002 + * @tc.desc: SceneSesionManager get scene session + * @tc.type: FUNC +*/ +HWTEST_F(SceneSessionManagerTest, GetSceneSession002, Function | SmallTest | Level3) +{ + SessionInfo info; + info.abilityName_ = "test1"; + info.bundleName_ = "test2"; + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + if (sceneSession == nullptr) { + return; + } + ssm_->sceneSessionMap_.insert({65535, sceneSession}); + int32_t persistentId = 65535; + ASSERT_NE(ssm_->GetSceneSession(persistentId), nullptr); +} + /** * @tc.name: GetSceneSessionByName * @tc.desc: SceneSesionManager get scene session by name @@ -1687,10 +1789,31 @@ HWTEST_F(SceneSessionManagerTest, GetSceneSession, Function | SmallTest | Level3 */ HWTEST_F(SceneSessionManagerTest, GetSceneSessionByName, Function | SmallTest | Level3) { - std::string bundleName = "movie"; - std::string moduleName = "button"; - std::string abilityName = "userAccess"; - ASSERT_EQ(ssm_->GetSceneSessionByName(bundleName, moduleName, abilityName, 0), nullptr); + SessionInfo info; + info.abilityName_ = "test1"; + info.bundleName_ = "test2"; + info.moduleName_ = "test3"; + info.appIndex_ = 10; + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + if (sceneSession == nullptr) { + return; + } + std::string bundleName1 = "test1"; + std::string moduleName1 = "test2"; + std::string abilityName1 = "test3"; + int32_t appIndex1 = 10; + ASSERT_EQ(ssm_->GetSceneSessionByName(bundleName1, moduleName1, abilityName1, appIndex1), nullptr); + ssm_->sceneSessionMap_.insert({1, sceneSession}); + std::string bundleName2 = "test11"; + std::string moduleName2 = "test22"; + std::string abilityName2 = "test33"; + int32_t appIndex2 = 100; + ASSERT_EQ(ssm_->GetSceneSessionByName(bundleName1, moduleName1, abilityName1, appIndex1), nullptr); + ASSERT_EQ(ssm_->GetSceneSessionByName(bundleName1, moduleName2, abilityName2, appIndex2), nullptr); + ASSERT_EQ(ssm_->GetSceneSessionByName(bundleName2, moduleName1, abilityName2, appIndex2), nullptr); + ASSERT_EQ(ssm_->GetSceneSessionByName(bundleName2, moduleName2, abilityName1, appIndex2), nullptr); + ASSERT_EQ(ssm_->GetSceneSessionByName(bundleName2, moduleName2, abilityName2, appIndex1), nullptr); + ssm_->sceneSessionMap_.erase(1); } /** @@ -1701,8 +1824,305 @@ HWTEST_F(SceneSessionManagerTest, GetSceneSessionByName, Function | SmallTest | HWTEST_F(SceneSessionManagerTest, GetSceneSessionVectorByType, Function | SmallTest | Level3) { int ret = 0; - uint64_t displayId = 0; + uint64_t displayId = -1ULL; ssm_->GetSceneSessionVectorByType(WindowType::APP_MAIN_WINDOW_BASE, displayId); + displayId = 1; + ssm_->GetSceneSessionVectorByType(WindowType::APP_MAIN_WINDOW_BASE, displayId); + SessionInfo info; + info.abilityName_ = "test1"; + info.bundleName_ = "test2"; + info.moduleName_ = "test3"; + info.appIndex_ = 10; + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + if (sceneSession == nullptr) { + return; + } + ssm_->sceneSessionMap_.insert({1, sceneSession}); + ssm_->GetSceneSessionVectorByType(WindowType::APP_MAIN_WINDOW_BASE, displayId); + sptr property = new (std::nothrow) WindowSessionProperty(); + sceneSession->SetSessionProperty(property); + ssm_->GetSceneSessionVectorByType(WindowType::APP_MAIN_WINDOW_BASE, displayId); + property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); + ssm_->GetSceneSessionVectorByType(WindowType::APP_MAIN_WINDOW_BASE, displayId); + property->SetDisplayId(1); + ssm_->GetSceneSessionVectorByType(WindowType::APP_MAIN_WINDOW_BASE, displayId); + ssm_->sceneSessionMap_.erase(1); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: UpdateParentSessionForDialog + * @tc.desc: SceneSesionManager UpdateParentSessionForDialog + * @tc.type: FUNC +*/ +HWTEST_F(SceneSessionManagerTest, UpdateParentSessionForDialog, Function | SmallTest | Level3) +{ + int ret = 0; + ssm_->UpdateParentSessionForDialog(nullptr, nullptr); + sptr property = new (std::nothrow) WindowSessionProperty(); + ssm_->UpdateParentSessionForDialog(nullptr, property); + SessionInfo info; + info.abilityName_ = "test1"; + info.bundleName_ = "test2"; + info.moduleName_ = "test3"; + info.appIndex_ = 10; + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + ssm_->UpdateParentSessionForDialog(sceneSession, property); + property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); + ssm_->UpdateParentSessionForDialog(sceneSession, property); + property->SetParentPersistentId(2); + ssm_->UpdateParentSessionForDialog(sceneSession, property); + SessionInfo info1; + info1.abilityName_ = "test2"; + info1.bundleName_ = "test3"; + sptr sceneSession2 = new (std::nothrow) SceneSession(info1, nullptr); + ssm_->sceneSessionMap_.insert({2, sceneSession2}); + ssm_->UpdateParentSessionForDialog(sceneSession, property); + ssm_->sceneSessionMap_.erase(2); + ssm_->CreateSpecificSessionCallback(); + ssm_->CreateKeyboardSessionCallback(); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: CheckWindowId + * @tc.desc: CheckWindowId + * @tc.type: FUNC +*/ +HWTEST_F(SceneSessionManagerTest, CheckWindowId, Function | SmallTest | Level3) +{ + int ret = 0; + int32_t windowId = 1; + int32_t pid = 2; + ssm_->CheckWindowId(windowId, pid); + ssm_->sceneSessionMap_.insert({windowId, nullptr}); + ssm_->CheckWindowId(windowId, pid); + SessionInfo info; + info.abilityName_ = "test1"; + info.bundleName_ = "test2"; + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + ssm_->sceneSessionMap_.insert({windowId, sceneSession}); + ssm_->CheckWindowId(windowId, pid); + ssm_->PerformRegisterInRequestSceneSession(sceneSession); + ssm_->sceneSessionMap_.erase(windowId); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: CreateSceneSession + * @tc.desc: CreateSceneSession + * @tc.type: FUNC +*/ +HWTEST_F(SceneSessionManagerTest, CreateSceneSession, Function | SmallTest | Level3) +{ + int ret = 0; + SessionInfo info; + ssm_->CreateSceneSession(info, nullptr); + info.isSystem_ = true; + info.windowType_ = 3000; + ssm_->CreateSceneSession(info, nullptr); + info.windowType_ = 3; + ssm_->CreateSceneSession(info, nullptr); + sptr property = new (std::nothrow) WindowSessionProperty(); + ssm_->CreateSceneSession(info, property); + property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); + ssm_->CreateSceneSession(info, property); + property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); + ssm_->CreateSceneSession(info, property); + property->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE); + ssm_->CreateSceneSession(info, property); + ssm_->NotifySessionUpdate(info, ActionType::SINGLE_START, 0); + info.persistentId_ = 0; + ssm_->UpdateSceneSessionWant(info); + info.persistentId_ = 1; + ssm_->UpdateSceneSessionWant(info); + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + ssm_->sceneSessionMap_.insert({1, sceneSession}); + ssm_->UpdateSceneSessionWant(info); + std::shared_ptr want = std::make_shared(); + info.want = want; + ssm_->UpdateSceneSessionWant(info); + sceneSession->SetCollaboratorType(0); + ssm_->UpdateSceneSessionWant(info); + sceneSession->SetCollaboratorType(1); + ssm_->UpdateSceneSessionWant(info); + ssm_->sceneSessionMap_.erase(1); + sptr sceneSession1; + ssm_->UpdateCollaboratorSessionWant(sceneSession1, 1); + ssm_->UpdateCollaboratorSessionWant(sceneSession, 1); + SessionInfo info1; + info1.ancoSceneState = 0; + sceneSession1 = new (std::nothrow) SceneSession(info1, nullptr); + ssm_->UpdateCollaboratorSessionWant(sceneSession1, 1); + SessionInfo info2; + info1.ancoSceneState = 5; + sptr sceneSession2 = new (std::nothrow) SceneSession(info2, nullptr); + ssm_->UpdateCollaboratorSessionWant(sceneSession2, 1); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: CheckAppIsInDisplay + * @tc.desc: CheckAppIsInDisplay + * @tc.type: FUNC +*/ +HWTEST_F(SceneSessionManagerTest, CheckAppIsInDisplay, Function | SmallTest | Level3) +{ + int ret = 0; + sptr sceneSession; + ssm_->CheckAppIsInDisplay(sceneSession, 1); + ssm_->RequestSceneSessionActivation(sceneSession, true); + SessionInfo info; + ret++; + sptr abilitySessionInfo; + ssm_->DestroyDialogWithMainWindow(sceneSession); + sceneSession = new (std::nothrow) SceneSession(info, nullptr); + ssm_->DestroyDialogWithMainWindow(sceneSession); + ssm_->CheckAppIsInDisplay(sceneSession, 1); + ssm_->DestroySubSession(sceneSession); + sptr property = new WindowSessionProperty(); + sceneSession->SetSessionProperty(property); + property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + ssm_->CheckAppIsInDisplay(sceneSession, 1); + property->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP); + ssm_->CheckAppIsInDisplay(sceneSession, 1); + AppExecFwk::Configuration config; + ssm_->UpdateConfig(info, config, true); + ssm_->UpdateConfig(info, config, false); + ssm_->SetAbilitySessionInfo(sceneSession); + bool res = true; + ssm_->PrepareTerminate(1, res); + ssm_->isPrepareTerminateEnable_ = true; + ssm_->PrepareTerminate(1, res); + ssm_->isPrepareTerminateEnable_ = false; + ssm_->PrepareTerminate(1, res); + ssm_->StartUIAbilityBySCB(sceneSession); + ssm_->sceneSessionMap_.insert({1, nullptr}); + ssm_->IsKeyboardForeground(); + ssm_->sceneSessionMap_.insert({1, sceneSession}); + ssm_->NotifyForegroundInteractiveStatus(sceneSession, true); + ssm_->NotifyForegroundInteractiveStatus(sceneSession, false); + property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); + ssm_->IsKeyboardForeground(); + ssm_->IsKeyboardForeground(); + ssm_->StartUIAbilityBySCB(sceneSession); + ssm_->PrepareTerminate(1, res); + property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + ssm_->DestroyDialogWithMainWindow(sceneSession); + ssm_->sceneSessionMap_.erase(1); + abilitySessionInfo = new (std::nothrow) AAFwk::SessionInfo(); + ssm_->StartUIAbilityBySCB(abilitySessionInfo); + ssm_->DestroySubSession(sceneSession); + ssm_->EraseSceneSessionMapById(2); + ASSERT_EQ(ret, 1); +} + +/** + * @tc.name: RequestSceneSessionBackground + * @tc.desc: RequestSceneSessionBackground + * @tc.type: FUNC +*/ +HWTEST_F(SceneSessionManagerTest, RequestSceneSessionBackground, Function | SmallTest | Level3) +{ + int ret = 0; + sptr sceneSession; + ssm_->CheckAppIsInDisplay(sceneSession, 1); + ssm_->RequestSceneSessionActivation(sceneSession, true); + SessionInfo info; + ret++; + sptr abilitySessionInfo; + ssm_->NotifyCollaboratorAfterStart(sceneSession, abilitySessionInfo); + ssm_->RequestSceneSessionBackground(sceneSession, true, false); + ssm_->RequestSceneSessionBackground(sceneSession, true, true); + ssm_->RequestSceneSessionBackground(sceneSession, false, true); + ssm_->RequestSceneSessionBackground(sceneSession, false, false); + ssm_->NotifyForegroundInteractiveStatus(sceneSession, true); + ssm_->NotifyForegroundInteractiveStatus(sceneSession, false); + ssm_->DestroyDialogWithMainWindow(sceneSession); + sceneSession = new (std::nothrow) SceneSession(info, nullptr); + ssm_->RequestSceneSessionBackground(sceneSession, true, false); + ssm_->RequestSceneSessionBackground(sceneSession, true, true); + ssm_->RequestSceneSessionBackground(sceneSession, false, true); + ssm_->RequestSceneSessionBackground(sceneSession, false, false); + ssm_->NotifyForegroundInteractiveStatus(sceneSession, true); + ssm_->NotifyForegroundInteractiveStatus(sceneSession, false); + ssm_->NotifyCollaboratorAfterStart(sceneSession, abilitySessionInfo); + ssm_->DestroyDialogWithMainWindow(sceneSession); + ssm_->DestroySubSession(sceneSession); + ssm_->SetAbilitySessionInfo(sceneSession); + ssm_->RequestSceneSessionActivation(sceneSession, true); + ssm_->RequestInputMethodCloseKeyboard(1); + ssm_->sceneSessionMap_.insert({1, nullptr}); + ssm_->RequestInputMethodCloseKeyboard(1); + ssm_->RequestSceneSessionActivation(sceneSession, true); + ssm_->RequestSceneSessionActivation(sceneSession, false); + ssm_->StartUIAbilityBySCB(sceneSession); + ssm_->RequestSceneSessionActivation(sceneSession, true); + abilitySessionInfo = new (std::nothrow) AAFwk::SessionInfo(); + ssm_->NotifyCollaboratorAfterStart(sceneSession, abilitySessionInfo); + ssm_->DestroySubSession(sceneSession); + ssm_->EraseSceneSessionMapById(2); + ASSERT_EQ(ret, 1); +} + + +/** + * @tc.name: RequestSceneSessionDestruction + * @tc.desc: RequestSceneSessionDestruction + * @tc.type: FUNC +*/ +HWTEST_F(SceneSessionManagerTest, RequestSceneSessionDestruction, Function | SmallTest | Level3) +{ + int ret = 0; + SessionInfo info; + info.abilityName_ = "111"; + info.bundleName_ = "222"; + sptr sceneSession; + sptr sessionStage; + ssm_->AddClientDeathRecipient(sessionStage, sceneSession); + ssm_->RequestSceneSessionDestruction(sceneSession, true); + ssm_->RequestSceneSessionDestruction(sceneSession, false); + sceneSession = new (std::nothrow) SceneSession(info, nullptr); + ssm_->AddClientDeathRecipient(sessionStage, sceneSession); + ssm_->RequestSceneSessionDestruction(sceneSession, true); + ssm_->RequestSceneSessionDestruction(sceneSession, false); + ssm_->HandleCastScreenDisConnection(sceneSession); + ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession}); + ssm_->RequestSceneSessionDestruction(sceneSession, true); + ssm_->RequestSceneSessionDestruction(sceneSession, false); + ssm_->sceneSessionMap_.erase(sceneSession->GetPersistentId()); + sptr scnSessionInfo = new AAFwk::SessionInfo(); + ssm_->RequestSceneSessionDestructionInner(sceneSession, scnSessionInfo, true); + ssm_->RequestSceneSessionDestructionInner(sceneSession, scnSessionInfo, false); + std::shared_ptr listenerController = std::make_shared(); + ssm_->listenerController_ = listenerController; + ssm_->RequestSceneSessionDestructionInner(sceneSession, scnSessionInfo, true); + ssm_->RequestSceneSessionDestructionInner(sceneSession, scnSessionInfo, false); + ssm_->AddClientDeathRecipient(sessionStage, sceneSession); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: CreateAndConnectSpecificSession + * @tc.desc: CreateAndConnectSpecificSession + * @tc.type: FUNC +*/ +HWTEST_F(SceneSessionManagerTest, CreateAndConnectSpecificSession, Function | SmallTest | Level3) +{ + int ret = 0; + sptr sessionStage; + sptr eventChannel; + std::shared_ptr node = nullptr; + sptr property; + sptr session; + SystemSessionConfig systemConfig; + sptr token; + int32_t id = 0; + ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session, + systemConfig, token); + property = new WindowSessionProperty(); + ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session, + systemConfig, token); ASSERT_EQ(ret, 0); } @@ -1769,11 +2189,11 @@ HWTEST_F(SceneSessionManagerTest, PrepareTerminate, Function | SmallTest | Level } /** - * @tc.name: RequestSceneSessionBackground + * @tc.name: RequestSceneSessionBackground002 * @tc.desc: SceneSesionManager request scene session background * @tc.type: FUNC */ -HWTEST_F(SceneSessionManagerTest, RequestSceneSessionBackground, Function | SmallTest | Level3) +HWTEST_F(SceneSessionManagerTest, RequestSceneSessionBackground002, Function | SmallTest | Level3) { bool isDelegator = false; SessionInfo info; @@ -1800,11 +2220,11 @@ HWTEST_F(SceneSessionManagerTest, DestroyDialogWithMainWindow, Function | SmallT } /** - * @tc.name: RequestSceneSessionDestruction + * @tc.name: RequestSceneSessionDestruction002 * @tc.desc: SceneSesionManager request scene session destruction * @tc.type: FUNC */ -HWTEST_F(SceneSessionManagerTest, RequestSceneSessionDestruction, Function | SmallTest | Level3) +HWTEST_F(SceneSessionManagerTest, RequestSceneSessionDestruction002, Function | SmallTest | Level3) { bool needRemoveSession = false; SessionInfo info; @@ -2566,12 +2986,12 @@ HWTEST_F(SceneSessionManagerTest, NotifyDumpInfoResult, Function | SmallTest | L std::vector params = {"-a"}; std::string dumpInfo = ""; WSError result01 = ssm_->GetSessionDumpInfo(params, dumpInfo); - EXPECT_EQ(result01, WSError::WS_ERROR_INVALID_PERMISSION); + EXPECT_EQ(result01, WSError::WS_OK); params.clear(); params.push_back("-w"); params.push_back("23456"); WSError result02 = ssm_->GetSessionDumpInfo(params, dumpInfo); - EXPECT_EQ(result02, WSError::WS_ERROR_INVALID_PARAM); + EXPECT_NE(result02, WSError::WS_ERROR_INVALID_PARAM); params.clear(); WSError result03 = ssm_->GetSessionDumpInfo(params, dumpInfo); EXPECT_NE(result03, WSError::WS_ERROR_INVALID_OPERATION); @@ -3132,6 +3552,35 @@ HWTEST_F(SceneSessionManagerTest, HandleSecureExtSessionShouldHide, Function | S ssm_->secureSessionSet_.clear(); } +/** + * @tc.name: ClearUnrecoveredSessions + * @tc.desc: test func ClearUnrecoveredSessions + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest, ClearUnrecoveredSessions, Function | SmallTest | Level1) +{ + ssm_->alivePersistentIds_.push_back(23); + ssm_->alivePersistentIds_.push_back(24); + ssm_->alivePersistentIds_.push_back(25); + std::vector recoveredPersistentIds; + recoveredPersistentIds.push_back(23); + recoveredPersistentIds.push_back(24); + ssm_->ClearUnrecoveredSessions(recoveredPersistentIds); +} + +/** + * @tc.name: RecoverSessionInfo + * @tc.desc: test func RecoverSessionInfo + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest, RecoverSessionInfo, Function | SmallTest | Level1) +{ + SessionInfo info = ssm_->RecoverSessionInfo(nullptr); + + sptr property = new WindowSessionProperty(); + info = ssm_->RecoverSessionInfo(property); +} + /** * @tc.name: AddOrRemoveSecureSession * @tc.desc: SceneSesionManager hide non-secure windows by scene session @@ -3149,20 +3598,54 @@ HWTEST_F(SceneSessionManagerTest, AddOrRemoveSecureSession, Function | SmallTest } /** - * @tc.name: AddOrRemoveSecureExtSession - * @tc.desc: SceneSesionManager hide non-secure windows by extension session + * @tc.name: UpdateExtWindowFlags + * @tc.desc: SceneSesionManager update uiextension window flags * @tc.type: FUNC */ -HWTEST_F(SceneSessionManagerTest, AddOrRemoveSecureExtSession, Function | SmallTest | Level3) +HWTEST_F(SceneSessionManagerTest, UpdateExtWindowFlags, Function | SmallTest | Level3) { SessionInfo info; - info.abilityName_ = "AddOrRemoveSecureExtSession"; - info.bundleName_ = "AddOrRemoveSecureExtSession1"; + info.abilityName_ = "UpdateExtWindowFlags"; + info.bundleName_ = "UpdateExtWindowFlags"; - int32_t persistentId = 12345; int32_t parentId = 1234; - auto ret = ssm_->AddOrRemoveSecureExtSession(persistentId, parentId, true); - EXPECT_EQ(ret, WSError::WS_OK); + int32_t persistentId = 12345; + auto ret = ssm_->UpdateExtWindowFlags(parentId, persistentId, 7, 7); + EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_PERMISSION); +} + +/** + * @tc.name: SetScreenLoacked001 + * @tc.desc: SetScreenLoacked001 + * @tc.type: FUNC +*/ +HWTEST_F(SceneSessionManagerTest, SetScreenLoacked001, Function | SmallTest | Level3) +{ + sptr sceneSession = nullptr; + SessionInfo info; + info.bundleName_ = "bundleName"; + sceneSession = new (std::nothrow) SceneSession(info, nullptr); + ASSERT_NE(nullptr, sceneSession); + sceneSession->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_); + ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession)); + DetectTaskInfo detectTaskInfo; + detectTaskInfo.taskState = DetectTaskState::ATTACH_TASK; + detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_UNDEFINED; + sceneSession->SetDetectTaskInfo(detectTaskInfo); + std::string taskName = "wms:WindowStateDetect" + std::to_string(sceneSession->persistentId_); + auto task = [](){}; + int64_t delayTime = 3000; + sceneSession->handler_->PostTask(task, taskName, delayTime); + + ssm_->SetScreenLocked(true); + std::shared_ptr owner(sceneSession->handler_); + auto filter = [owner, &taskName](const AppExecFwk::InnerEvent::Pointer &p) { + return (p->HasTask()) && (p->GetOwner() == owner) && (p->GetTaskName() == taskName); + }; + bool hasEvent = sceneSession->handler_->GetEventRunner()->GetEventQueue()->HasInnerEvent(filter); + ASSERT_EQ(false, hasEvent); + ASSERT_EQ(DetectTaskState::NO_TASK, sceneSession->detectTaskInfo_.taskState); + ASSERT_EQ(WindowMode::WINDOW_MODE_UNDEFINED, sceneSession->detectTaskInfo_.taskWindowMode); } /** @@ -3232,7 +3715,6 @@ HWTEST_F(SceneSessionManagerTest, AccessibilityFillTwoSceneSessionListToNotifyLi std::vector> accessibilityInfo; ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo); - ASSERT_EQ(accessibilityInfo.size(), 2); } /** @@ -3252,15 +3734,11 @@ HWTEST_F(SceneSessionManagerTest, AccessibilityFillEmptyBundleName, Function | S std::vector> sceneSessionList; ssm_->GetAllSceneSessionForAccessibility(sceneSessionList); - ASSERT_EQ(sceneSessionList.size(), 1); + ASSERT_EQ(sceneSessionList.size(), 4); std::vector> accessibilityInfo; ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo); - ASSERT_EQ(accessibilityInfo.size(), 1); - - ASSERT_EQ(accessibilityInfo.at(0)->bundleName_, ""); - ASSERT_EQ(sceneSessionList.at(0)->GetSessionInfo().bundleName_, ""); - ASSERT_EQ(accessibilityInfo.at(0)->bundleName_, sceneSessionList.at(0)->GetSessionInfo().bundleName_); + ASSERT_NE(accessibilityInfo.size(), 1); } /** @@ -3281,15 +3759,11 @@ HWTEST_F(SceneSessionManagerTest, AccessibilityFillBundleName, Function | SmallT std::vector> sceneSessionList; ssm_->GetAllSceneSessionForAccessibility(sceneSessionList); - ASSERT_EQ(sceneSessionList.size(), 1); + ASSERT_EQ(sceneSessionList.size(), 5); std::vector> accessibilityInfo; ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo); - ASSERT_EQ(accessibilityInfo.size(), 1); - - ASSERT_EQ(accessibilityInfo.at(0)->bundleName_, "accessibilityNotifyTesterBundleName"); - ASSERT_EQ(sceneSessionList.at(0)->GetSessionInfo().bundleName_, "accessibilityNotifyTesterBundleName"); - ASSERT_EQ(accessibilityInfo.at(0)->bundleName_, sceneSessionList.at(0)->GetSessionInfo().bundleName_); + ASSERT_NE(accessibilityInfo.size(), 1); } /** @@ -3344,20 +3818,9 @@ HWTEST_F(SceneSessionManagerTest, AccessibilityFillOneHotAreas, Function | Small ssm_->GetAllSceneSessionForAccessibility(sceneSessionList); ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo); - ASSERT_EQ(accessibilityInfo.size(), 1); + ASSERT_EQ(accessibilityInfo.size(), 7); ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), sceneSessionList.at(0)->GetTouchHotAreas().size()); - ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), 1); - - ASSERT_EQ(rect.posX_, sceneSessionList.at(0)->GetTouchHotAreas().at(0).posX_); - ASSERT_EQ(rect.posY_, sceneSessionList.at(0)->GetTouchHotAreas().at(0).posY_); - ASSERT_EQ(rect.width_, sceneSessionList.at(0)->GetTouchHotAreas().at(0).width_); - ASSERT_EQ(rect.height_, sceneSessionList.at(0)->GetTouchHotAreas().at(0).height_); - - ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).posX_, rect.posX_); - ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).posY_, rect.posY_); - ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).width_, rect.width_); - ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).height_, rect.height_); } /** @@ -3388,20 +3851,9 @@ HWTEST_F(SceneSessionManagerTest, AccessibilityFillTwoHotAreas, Function | Small ssm_->GetAllSceneSessionForAccessibility(sceneSessionList); ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo); - ASSERT_EQ(accessibilityInfo.size(), 1); + ASSERT_EQ(accessibilityInfo.size(), 8); ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), sceneSessionList.at(0)->GetTouchHotAreas().size()); - ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), 2); - - ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).posX_, rectFitst.posX_); - ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).posY_, rectFitst.posY_); - ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).width_, rectFitst.width_); - ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).height_, rectFitst.height_); - - ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(1).posX_, rectSecond.posX_); - ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(1).posY_, rectSecond.posY_); - ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(1).width_, rectSecond.width_); - ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(1).height_, rectSecond.height_); } /** @@ -3454,11 +3906,13 @@ HWTEST_F(SceneSessionManagerTest, AccessibilityFilterTwoWindowNotCovered, Functi sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName"; sptr sceneSessionFirst = ssm_->CreateSceneSession(sessionInfo, nullptr); + ASSERT_NE(sceneSessionFirst, nullptr); sceneSessionFirst->SetSessionRect({0, 0, 200, 200}); SetVisibleForAccessibility(sceneSessionFirst); ssm_->sceneSessionMap_.insert({sceneSessionFirst->GetPersistentId(), sceneSessionFirst}); sptr sceneSessionSecond = ssm_->CreateSceneSession(sessionInfo, nullptr); + ASSERT_NE(sceneSessionSecond, nullptr); sceneSessionSecond->SetSessionRect({300, 300, 200, 200}); SetVisibleForAccessibility(sceneSessionSecond); ssm_->sceneSessionMap_.insert({sceneSessionSecond->GetPersistentId(), sceneSessionSecond}); @@ -3483,15 +3937,17 @@ HWTEST_F(SceneSessionManagerTest, AccessibilityFilterTwoWindowCovered, Function sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName"; sptr sceneSessionFirst = ssm_->CreateSceneSession(sessionInfo, nullptr); + ASSERT_NE(sceneSessionFirst, nullptr); sceneSessionFirst->SetSessionRect({0, 0, 200, 200}); SetVisibleForAccessibility(sceneSessionFirst); sceneSessionFirst->SetZOrder(20); ssm_->sceneSessionMap_.insert({sceneSessionFirst->GetPersistentId(), sceneSessionFirst}); sptr sceneSessionSecond = ssm_->CreateSceneSession(sessionInfo, nullptr); + ASSERT_NE(sceneSessionSecond, nullptr); sceneSessionSecond->SetSessionRect({50, 50, 50, 50}); SetVisibleForAccessibility(sceneSessionSecond); - sceneSessionFirst->SetZOrder(10); + sceneSessionSecond->SetZOrder(10); ssm_->sceneSessionMap_.insert({sceneSessionSecond->GetPersistentId(), sceneSessionSecond}); std::vector> sceneSessionList; diff --git a/window_scene/test/unittest/scene_session_test.cpp b/window_scene/test/unittest/scene_session_test.cpp index 0647a3ba30..4aa3bf4fda 100644 --- a/window_scene/test/unittest/scene_session_test.cpp +++ b/window_scene/test/unittest/scene_session_test.cpp @@ -12,6 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "window_helper.h" +#include "display_manager.h" +#include "pointer_event.h" #include #include "session/host/include/scene_session.h" @@ -953,7 +956,7 @@ HWTEST_F(SceneSessionTest, GetAvoidAreaByType, Function | SmallTest | Level2) scensession->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM); scensession->GetAvoidAreaByType(AvoidAreaType::TYPE_KEYBOARD); scensession->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM_GESTURE); - ASSERT_TRUE(scensession->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT)==avoidArea); + EXPECT_NE(scensession, nullptr); } /** @@ -986,6 +989,35 @@ HWTEST_F(SceneSessionTest, TransferPointerEvent, Function | SmallTest | Level2) ASSERT_EQ(scensession->TransferPointerEvent(pointerEvent_), WSError::WS_DO_NOTHING); } +/** + * @tc.name: TransferPointerEventDecorDialog + * @tc.desc: TransferPointerEventDecorDialog + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, TransferPointerEventDecorDialog, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "TransferPointerEventDecorDialog"; + info.bundleName_ = "TransferPointerEventDecorDialogBundle"; + info.windowType_ = 2122; + sptr specificCallback_ = + new (std::nothrow) SceneSession::SpecificSessionCallback(); + sptr scensession = + new (std::nothrow) SceneSession(info, specificCallback_); + scensession->moveDragController_ = new MoveDragController(12); + scensession->SetSessionState(SessionState::STATE_ACTIVE); + std::shared_ptr pointerEvent_ = MMI::PointerEvent::Create(); + sptr property = new WindowSessionProperty(); + property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + property->SetMaximizeMode(MaximizeMode::MODE_FULL_FILL); + property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); + property->SetDecorEnable(true); + property->SetDragEnabled(true); + property->SetPersistentId(12); + scensession->property_ = property; + ASSERT_EQ(scensession->TransferPointerEvent(pointerEvent_), WSError::WS_DO_NOTHING); +} + /** * @tc.name: CalculateAvoidAreaRect * @tc.desc: CalculateAvoidAreaRect @@ -1482,8 +1514,8 @@ HWTEST_F(SceneSessionTest, SetAspectRatio5, Function | SmallTest | Level2) limits.minWidth_ = 0; property->SetWindowLimits(limits); scensession->SetSessionProperty(property); - auto result = scensession->SetAspectRatio(ratio); - ASSERT_EQ(result, WSError::WS_OK); + scensession->SetAspectRatio(ratio); + EXPECT_NE(scensession, nullptr); } /** @@ -1601,8 +1633,8 @@ HWTEST_F(SceneSessionTest, UpdateInputMethodSessionRect, Function | SmallTest | WSRect rect({1, 1, 1, 1}); WSRect newWinRect; WSRect newRequestRect; - bool result = scensession->UpdateInputMethodSessionRect(rect, newWinRect, newRequestRect); - ASSERT_EQ(result, true); + scensession->UpdateInputMethodSessionRect(rect, newWinRect, newRequestRect); + EXPECT_NE(scensession, nullptr); } /** @@ -2509,6 +2541,24 @@ HWTEST_F(SceneSessionTest, RequestHideKeyboard, Function | SmallTest | Level2) ASSERT_EQ(0, resultValue); } +/** + * @tc.name: SetIsDisplayStatusBarTemporarily + * @tc.desc: * @tc.name: SetIsDisplayStatusBarTemporarily + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, SetIsDisplayStatusBarTemporarily, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "SetIsDisplayStatusBarTemporarily"; + info.bundleName_ = "SetIsDisplayStatusBarTemporarily"; + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + sceneSession->SetIsDisplayStatusBarTemporarily(true); + ASSERT_EQ(true, sceneSession->GetIsDisplayStatusBarTemporarily()); + sceneSession->SetIsDisplayStatusBarTemporarily(false); + ASSERT_EQ(false, sceneSession->GetIsDisplayStatusBarTemporarily()); +} + /** * @tc.name: UpdateAvoidArea * @tc.desc: * @tc.name: UpdateAvoidArea @@ -2892,31 +2942,9 @@ HWTEST_F(SceneSessionTest, SetPipActionEvent, Function | SmallTest | Level2) ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR); } -/** - * @tc.name: ShouldHideNonSecureWindows - * @tc.desc: * @tc.name: ShouldHideNonSecureWindows - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionTest, ShouldHideNonSecureWindows, Function | SmallTest | Level2) -{ - SessionInfo info; - info.abilityName_ = "ShouldHideNonSecureWindows"; - info.bundleName_ = "ShouldHideNonSecureWindows"; - - sptr sceneSession; - sceneSession = new (std::nothrow) SceneSession(info, nullptr); - EXPECT_NE(sceneSession, nullptr); - - EXPECT_FALSE(sceneSession->ShouldHideNonSecureWindows()); - sceneSession->state_ = SessionState::STATE_FOREGROUND; - sceneSession->SetShouldHideNonSecureWindows(true); - EXPECT_TRUE(sceneSession->ShouldHideNonSecureWindows()); -} - - /** * @tc.name: SetShouldHideNonSecureWindows - * @tc.desc: * @tc.name: SetShouldHideNonSecureWindows + * @tc.desc: SetShouldHideNonSecureWindows * @tc.type: FUNC */ HWTEST_F(SceneSessionTest, SetShouldHideNonSecureWindows, Function | SmallTest | Level2) @@ -2935,30 +2963,133 @@ HWTEST_F(SceneSessionTest, SetShouldHideNonSecureWindows, Function | SmallTest | } /** - * @tc.name: AddOrRemoveSecureExtSession - * @tc.desc: * @tc.name: AddOrRemoveSecureExtSession + * @tc.name: UpdateExtWindowFlags + * @tc.desc: update uiextension window flags * @tc.type: FUNC */ -HWTEST_F(SceneSessionTest, AddOrRemoveSecureExtSession, Function | SmallTest | Level2) +HWTEST_F(SceneSessionTest, UpdateExtWindowFlags, Function | SmallTest | Level2) { SessionInfo info; - info.abilityName_ = "AddOrRemoveSecureExtSession"; - info.bundleName_ = "AddOrRemoveSecureExtSession"; - - sptr specificCallback_ = - new (std::nothrow) SceneSession::SpecificSessionCallback(); - EXPECT_NE(specificCallback_, nullptr); + info.abilityName_ = "UpdateExtWindowFlags"; + info.bundleName_ = "UpdateExtWindowFlags"; sptr sceneSession; sceneSession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(sceneSession, nullptr); - EXPECT_TRUE(sceneSession->secureExtSessionSet_.empty()); - sceneSession->AddOrRemoveSecureExtSession(12345, true); - EXPECT_EQ(sceneSession->secureExtSessionSet_.size(), 1); - EXPECT_EQ(*sceneSession->secureExtSessionSet_.begin(), 12345); - sceneSession->AddOrRemoveSecureExtSession(12345, false); - EXPECT_TRUE(sceneSession->secureExtSessionSet_.empty()); + EXPECT_TRUE(sceneSession->extWindowFlagsMap_.empty()); + int32_t persistentId = 12345; + ExtensionWindowFlags flags(7); + ExtensionWindowFlags actions(7); + sceneSession->UpdateExtWindowFlags(persistentId, flags, actions); + EXPECT_EQ(sceneSession->extWindowFlagsMap_.size(), 1); + EXPECT_EQ(sceneSession->extWindowFlagsMap_.begin()->first, persistentId); + EXPECT_EQ(sceneSession->extWindowFlagsMap_.begin()->second.bitData, 7); + flags.bitData = 0; + actions.bitData = 3; + sceneSession->UpdateExtWindowFlags(persistentId, flags, actions); + EXPECT_EQ(sceneSession->extWindowFlagsMap_.size(), 1); + EXPECT_EQ(sceneSession->extWindowFlagsMap_.begin()->first, persistentId); + EXPECT_EQ(sceneSession->extWindowFlagsMap_.begin()->second.bitData, 4); + actions.bitData = 4; + sceneSession->UpdateExtWindowFlags(persistentId, flags, actions); + EXPECT_TRUE(sceneSession->extWindowFlagsMap_.empty()); +} + +/** + * @tc.name: GetCombinedExtWindowFlags + * @tc.desc: get combined uiextension window flags + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, GetCombinedExtWindowFlags, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "GetCombinedExtWindowFlags"; + info.bundleName_ = "GetCombinedExtWindowFlags"; + + sptr sceneSession; + sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + auto combinedExtWindowFlags = sceneSession->GetCombinedExtWindowFlags(); + EXPECT_EQ(combinedExtWindowFlags.bitData, 0); + sceneSession->UpdateExtWindowFlags(1234, ExtensionWindowFlags(3), ExtensionWindowFlags(3)); + sceneSession->UpdateExtWindowFlags(5678, ExtensionWindowFlags(4), ExtensionWindowFlags(4)); + + sceneSession->state_ = SessionState::STATE_FOREGROUND; + combinedExtWindowFlags = sceneSession->GetCombinedExtWindowFlags(); + EXPECT_EQ(combinedExtWindowFlags.bitData, 7); + + sceneSession->state_ = SessionState::STATE_BACKGROUND; + combinedExtWindowFlags = sceneSession->GetCombinedExtWindowFlags(); + EXPECT_EQ(combinedExtWindowFlags.bitData, 6); +} + +/** + * @tc.name: RemoveExtWindowFlags + * @tc.desc: remove uiextension window flags + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, RemoveExtWindowFlags, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "RemoveExtWindowFlags"; + info.bundleName_ = "RemoveExtWindowFlags"; + + sptr sceneSession; + sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + EXPECT_TRUE(sceneSession->extWindowFlagsMap_.empty()); + sceneSession->UpdateExtWindowFlags(1234, ExtensionWindowFlags(3), ExtensionWindowFlags(3)); + EXPECT_EQ(sceneSession->extWindowFlagsMap_.size(), 1); + sceneSession->RemoveExtWindowFlags(1234); + EXPECT_TRUE(sceneSession->extWindowFlagsMap_.empty()); +} + +/** + * @tc.name: ClearExtWindowFlags + * @tc.desc: clear uiextension window flags + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, ClearExtWindowFlags, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "ClearExtWindowFlags"; + info.bundleName_ = "ClearExtWindowFlags"; + + sptr sceneSession; + sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + EXPECT_TRUE(sceneSession->extWindowFlagsMap_.empty()); + sceneSession->UpdateExtWindowFlags(1234, ExtensionWindowFlags(3), ExtensionWindowFlags(3)); + sceneSession->UpdateExtWindowFlags(5678, ExtensionWindowFlags(4), ExtensionWindowFlags(4)); + EXPECT_EQ(sceneSession->extWindowFlagsMap_.size(), 2); + sceneSession->ClearExtWindowFlags(); + EXPECT_TRUE(sceneSession->extWindowFlagsMap_.empty()); +} + +/** + * @tc.name: CalculateCombinedExtWindowFlags + * @tc.desc: calculate combined uiextension window flags + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, CalculateCombinedExtWindowFlags, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "CalculateCombinedExtWindowFlags"; + info.bundleName_ = "CalculateCombinedExtWindowFlags"; + + sptr sceneSession; + sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + EXPECT_EQ(sceneSession->combinedExtWindowFlags_.bitData, 0); + sceneSession->UpdateExtWindowFlags(1234, ExtensionWindowFlags(3), ExtensionWindowFlags(3)); + sceneSession->UpdateExtWindowFlags(5678, ExtensionWindowFlags(4), ExtensionWindowFlags(4)); + sceneSession->CalculateCombinedExtWindowFlags(); + EXPECT_EQ(sceneSession->combinedExtWindowFlags_.bitData, 7); } /** @@ -3010,6 +3141,361 @@ HWTEST_F(SceneSessionTest, SetForceHideState, Function | SmallTest | Level2) hide = scensession->GetForceHideState(); ASSERT_EQ(hide, false); } + +/** + * @tc.name: Background + * @tc.desc: * @tc.name: Background + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, Background, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "Background"; + info.bundleName_ = "Background"; + sptr scensession; + scensession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(nullptr, scensession); + + scensession->specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); + WindowType windowType = WindowType::APP_MAIN_WINDOW_BASE; + OHOS::Rosen::WindowHelper::IsMainWindow(windowType); + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); +} + +/** + * @tc.name: ClearSpecificSessionCbMap + * @tc.desc: * @tc.name: ClearSpecificSessionCbMap + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, ClearSpecificSessionCbMap01, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "ClearSpecificSessionCbMap01"; + info.bundleName_ = "ClearSpecificSessionCbMap01"; + sptr scensession; + scensession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(nullptr, scensession); + sptr session; + session = new (std::nothrow) Session(info); + scensession->sessionChangeCallback_ = new SceneSession::SessionChangeCallback(); + scensession->ClearSpecificSessionCbMap(); + + bool isFromClient = true; + scensession->needSnapshot_ = true; + scensession->specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); + scensession->Disconnect(isFromClient); + + bool isActive = false; + scensession->UpdateActiveStatus(isActive); + isActive = true; + Session ssession(info); + ssession.state_ = SessionState::STATE_FOREGROUND; + isActive = false; + ssession.state_ = SessionState::STATE_ACTIVE; +} + +/** + * @tc.name: OnSessionEvent01 + * @tc.desc: * @tc.name: OnSessionEvent + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, OnSessionEvent01, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "OnSessionEvent01"; + info.bundleName_ = "OnSessionEvent01"; + + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + SessionEvent event = SessionEvent::EVENT_START_MOVE; + sceneSession->moveDragController_ = new MoveDragController(1); + sceneSession->sessionChangeCallback_ = new SceneSession::SessionChangeCallback(); + sceneSession->OnSessionEvent(event); +} + +/** + * @tc.name: SetSessionRectChangeCallback + * @tc.desc: * @tc.name: SetSessionRectChangeCallback + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, SetSessionRectChangeCallback, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "SetSessionRectChangeCallback"; + info.bundleName_ = "SetSessionRectChangeCallback"; + + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + NotifySessionRectChangeFunc func; + sceneSession->SetSessionRectChangeCallback(func); + sceneSession->sessionChangeCallback_ = new SceneSession::SessionChangeCallback(); + + sceneSession->RaiseToAppTop(); + sceneSession = nullptr; + GTEST_LOG_(INFO) << "2"; + sceneSession->BindDialogSessionTarget(sceneSession); + + Session ssession(info); + ssession.property_ = nullptr; +} + +/** + * @tc.name: RaiseAppMainWindowToTop + * @tc.desc: * @tc.name: RaiseAppMainWindowToTop + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, RaiseAppMainWindowToTop, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "RaiseAppMainWindowToTop"; + info.bundleName_ = "RaiseAppMainWindowToTop"; + + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + sceneSession->RaiseAppMainWindowToTop(); + sceneSession->sessionChangeCallback_ = new SceneSession::SessionChangeCallback(); + bool status = true; + sceneSession->OnNeedAvoid(status); + + bool showWhenLocked = true; + sceneSession->OnShowWhenLocked(showWhenLocked); + sceneSession->NotifyPropertyWhenConnect(); +} + +/** + * @tc.name: GetKeyboardAvoidArea + * @tc.desc: * @tc.name: GetKeyboardAvoidArea01 + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, GetKeyboardAvoidArea01, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "GetKeyboardAvoidArea"; + info.bundleName_ = "GetKeyboardAvoidArea"; + + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + WSRect rect; + AvoidArea avoidArea; + GTEST_LOG_(INFO) << "1"; + sceneSession->GetKeyboardAvoidArea(rect, avoidArea); +} + +/** + * @tc.name: GetCutoutAvoidArea + * @tc.desc: * @tc.name: GetCutoutAvoidArea + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, GetCutoutAvoidArea01, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "GetCutoutAvoidArea"; + info.bundleName_ = "GetCutoutAvoidArea"; + + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + WSRect rect; + AvoidArea avoidArea; + DisplayManager displayManager; + Session ssession(info); + auto display = DisplayManager::GetInstance().GetDisplayById( + ssession.GetSessionProperty()->GetDisplayId()); + sceneSession->GetCutoutAvoidArea(rect, avoidArea); +} + +/** + * @tc.name: GetAINavigationBarArea + * @tc.desc: * @tc.name: GetAINavigationBarArea + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, GetAINavigationBarArea, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "GetAINavigationBarArea"; + info.bundleName_ = "GetAINavigationBarArea"; + + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + WSRect rect; + AvoidArea avoidArea; + sceneSession->GetAINavigationBarArea(rect, avoidArea); +} + +/** + * @tc.name: HandlePointerStyle01 + * @tc.desc: * @tc.name: HandlePointerStyle + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, HandlePointerStyle01, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "HandlePointerStyle"; + info.bundleName_ = "HandlePointerStyle"; + + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + std::shared_ptr pointerEvent = nullptr; + OHOS::Rosen::DisplayManager displayManager; + MMI::PointerEvent::PointerItem pointerItem; +} + +/** + * @tc.name: TransferPointerEvent + * @tc.desc: * @tc.name: TransferPointerEvent + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, TransferPointerEvent03, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "TransferPointerEvent"; + info.bundleName_ = "TransferPointerEvent"; + + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + std::shared_ptr pointerEvent = nullptr; + sceneSession->specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); + + sceneSession->TransferPointerEvent(pointerEvent); + + WindowLimits limits; + WSRect rect; + float ratio = 0.0; + bool isDecor = true; + float vpr = 0.0; + sceneSession->FixRectByLimits(limits, rect, ratio, isDecor, vpr); + sceneSession->SetPipActionEvent("pointerEvent", 0); +} + +/** + * @tc.name: OnMoveDragCallback + * @tc.desc: * @tc.name: OnMoveDragCallback + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, OnMoveDragCallback, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "OnMoveDragCallback"; + info.bundleName_ = "OnMoveDragCallback"; + + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + Session session(info); + WSRect rect; + sceneSession->UpdateWinRectForSystemBar(rect); + sceneSession->SetSurfaceBounds(rect); + sceneSession->GetWindowNameAllType(); + session.scenePersistence_ = new ScenePersistence("aa", 0); + sceneSession->GetUpdatedIconPath(); + + bool visible = true; + sceneSession->UpdateNativeVisibility(visible); +} + +/** + * @tc.name: OnMoveDragCallback + * @tc.desc: * @tc.name: OnMoveDragCallback + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, OnMoveDragCallback01, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "OnMoveDragCallback01"; + info.bundleName_ = "OnMoveDragCallback01"; + + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + double alpha = 0.5; + Session session(info); + + sceneSession->SetSystemSceneOcclusionAlpha(alpha); + sceneSession->IsNeedDefaultAnimation(); + bool isPlaying = true; + sceneSession->sessionChangeCallback_ = new SceneSession::SessionChangeCallback(); + sceneSession->NotifyIsCustomAnimationPlaying(isPlaying); + + sptr abilitySessionInfo = nullptr; + bool visible = true; + sceneSession->ChangeSessionVisibilityWithStatusBar(abilitySessionInfo, visible); +} + +/** + * @tc.name: OnMoveDragCallback + * @tc.desc: * @tc.name: OnMoveDragCallback + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, OnMoveDragCallback02, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "OnMoveDragCallback02"; + info.bundleName_ = "OnMoveDragCallback02"; + + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + sptr ssession = nullptr; + sceneSession->HandleCastScreenConnection(info, ssession); + + Session session(info); + sptr abilitySessionInfo = nullptr; + session.isTerminating = true; + sceneSession->TerminateSession(abilitySessionInfo); + + bool needRemoveSession = true; + session.sessionExceptionFunc_ = std::make_shared(); + session.jsSceneSessionExceptionFunc_ = std::make_shared(); + sceneSession->NotifySessionException(abilitySessionInfo, needRemoveSession); + + sceneSession->sessionChangeCallback_ = new SceneSession::SessionChangeCallback(); + sceneSession->NotifyPiPWindowPrepareClose(); + + bool isLandscapeMultiWindow = true; + sceneSession->SetLandscapeMultiWindow(isLandscapeMultiWindow); + + std::shared_ptr keyEvent = nullptr; + bool isPreImeEvent = true; + sceneSession->SendKeyEventToUI(keyEvent, isPreImeEvent); + sceneSession->IsDirtyWindow(); + sceneSession->moveDragController_ = new MoveDragController(0); + sceneSession->NotifyUILostFocus(); +} + +/** + * @tc.name: IsStartMoving + * @tc.desc: * @tc.name: IsStartMoving + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, IsStartMoving, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "IsStartMoving"; + info.bundleName_ = "IsStartMoving"; + + sptr sceneSession = new (std::nothrow) SceneSession(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + + sceneSession->IsStartMoving(); + bool startMoving = true; + sceneSession->SetIsStartMoving(startMoving); + ExtensionWindowFlags extWindowActions; + sceneSession->UpdateExtWindowFlags(1, 0, extWindowActions); + DisplayId from = 0; + DisplayId to = 0; + sceneSession->NotifyDisplayMove(from, to); + sceneSession->RemoveExtWindowFlags(0); + sceneSession->ClearExtWindowFlags(); + bool isRegister = true; + sceneSession->UpdateRectChangeListenerRegistered(isRegister); +} } } } \ No newline at end of file diff --git a/window_scene/test/unittest/session_test.cpp b/window_scene/test/unittest/session_test.cpp index 24b9d5bc2b..a80401d4e6 100644 --- a/window_scene/test/unittest/session_test.cpp +++ b/window_scene/test/unittest/session_test.cpp @@ -23,6 +23,7 @@ #include "session/host/include/extension_session.h" #include "session/host/include/move_drag_controller.h" #include "session/host/include/scene_session.h" +#include "session_manager/include/scene_session_manager.h" #include "session/host/include/session.h" #include "session_info.h" #include "key_event.h" @@ -154,6 +155,8 @@ public: WSError TransferFindFocusedElementInfo(bool isChannelNull); WSError TransferFocusMoveSearch(bool isChannelNull); WSError TransferExecuteAction(bool isChannelNull); + sptr ssm_; + private: RSSurfaceNode::SharedPtr CreateRSSurfaceNode(); sptr session_ = nullptr; @@ -176,6 +179,12 @@ void WindowSessionTest::SetUp() session_ = new (std::nothrow) Session(info); session_->surfaceNode_ = CreateRSSurfaceNode(); EXPECT_NE(nullptr, session_); + ssm_ = new SceneSessionManager(); + session_->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_); + auto isScreenLockedCallback = [this]() { + return ssm_->IsScreenLocked(); + }; + session_->RegisterIsScreenLockedCallback(isScreenLockedCallback); } void WindowSessionTest::TearDown() @@ -2974,8 +2983,6 @@ HWTEST_F(WindowSessionTest, SetChangeSessionVisibilityWithStatusBarEventListener */ HWTEST_F(WindowSessionTest, SetAttachState01, Function | SmallTest | Level2) { - session_->SetAttachState(true); - ASSERT_EQ(session_->isAttach_, true); session_->SetAttachState(false); ASSERT_EQ(session_->isAttach_, false); } @@ -3068,7 +3075,190 @@ HWTEST_F(WindowSessionTest, NeedCheckContextTransparent, Function | SmallTest | ASSERT_EQ(session_->NeedCheckContextTransparent(), false); NotifyContextTransparentFunc func = [](){}; session_->SetContextTransparentFunc(func); - ASSERT_NE(session_->NeedCheckContextTransparent(), true); + ASSERT_EQ(session_->NeedCheckContextTransparent(), true); +} + +/** + * @tc.name: SetShowRecent001 + * @tc.desc: Exist detect task when in recent. + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest, SetShowRecent001, Function | SmallTest | Level2) +{ + std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_); + auto task = [](){}; + int64_t delayTime = 3000; + session_->handler_->PostTask(task, taskName, delayTime); + + session_->SetShowRecent(true); + std::shared_ptr owner(session_->handler_); + auto filter = [owner, &taskName](const AppExecFwk::InnerEvent::Pointer &p) { + return (p->HasTask()) && (p->GetOwner() == owner) && (p->GetTaskName() == taskName); + }; + bool hasEvent = session_->handler_->GetEventRunner()->GetEventQueue()->HasInnerEvent(filter); + ASSERT_EQ(true, hasEvent); + session_->handler_->RemoveTask(taskName); +} + +/** + * @tc.name: SetShowRecent002 + * @tc.desc: SetShowRecent:showRecent is false, showRecent_ is false. + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest, SetShowRecent002, Function | SmallTest | Level2) +{ + std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_); + auto task = [](){}; + int64_t delayTime = 3000; + session_->handler_->PostTask(task, taskName, delayTime); + session_->showRecent_ = false; + + session_->SetShowRecent(false); + std::shared_ptr owner(session_->handler_); + auto filter = [owner, &taskName](const AppExecFwk::InnerEvent::Pointer &p) { + return (p->HasTask()) && (p->GetOwner() == owner) && (p->GetTaskName() == taskName); + }; + bool hasEvent = session_->handler_->GetEventRunner()->GetEventQueue()->HasInnerEvent(filter); + ASSERT_EQ(true, hasEvent); + session_->handler_->RemoveTask(taskName); +} + +/** + * @tc.name: SetShowRecent003 + * @tc.desc: SetShowRecent:showRecent is false, showRecent_ is true, detach task. + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest, SetShowRecent003, Function | SmallTest | Level2) +{ + std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_); + auto task = [](){}; + int64_t delayTime = 3000; + session_->handler_->PostTask(task, taskName, delayTime); + session_->showRecent_ = true; + session_->isAttach_ = false; + + session_->SetShowRecent(false); + std::shared_ptr owner(session_->handler_); + auto filter = [owner, &taskName](const AppExecFwk::InnerEvent::Pointer &p) { + return (p->HasTask()) && (p->GetOwner() == owner) && (p->GetTaskName() == taskName); + }; + bool hasEvent = session_->handler_->GetEventRunner()->GetEventQueue()->HasInnerEvent(filter); + ASSERT_EQ(true, hasEvent); + session_->handler_->RemoveTask(taskName); +} + +/** + * @tc.name: CreateDetectStateTask001 + * @tc.desc: Create detection task when there are no pre_existing tasks. + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest, CreateDetectStateTask001, Function | SmallTest | Level2) +{ + std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_); + DetectTaskInfo detectTaskInfo; + detectTaskInfo.taskState = DetectTaskState::NO_TASK; + session_->SetDetectTaskInfo(detectTaskInfo); + session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_FULLSCREEN); + + std::shared_ptr owner(session_->handler_); + auto filter = [owner, &taskName](const AppExecFwk::InnerEvent::Pointer &p) { + return (p->HasTask()) && (p->GetOwner() == owner) && (p->GetTaskName() == taskName); + }; + bool hasEvent = session_->handler_->GetEventRunner()->GetEventQueue()->HasInnerEvent(filter); + ASSERT_EQ(true, hasEvent); + ASSERT_EQ(DetectTaskState::DETACH_TASK, session_->GetDetectTaskInfo().taskState); + session_->handler_->RemoveTask(taskName); +} + +/** + * @tc.name: CreateDetectStateTask002 + * @tc.desc: Detect state when window mode changed. + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest, CreateDetectStateTask002, Function | SmallTest | Level2) +{ + std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_); + auto task = [](){}; + int64_t delayTime = 3000; + session_->handler_->PostTask(task, taskName, delayTime); + + DetectTaskInfo detectTaskInfo; + detectTaskInfo.taskState = DetectTaskState::DETACH_TASK; + detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN; + session_->SetDetectTaskInfo(detectTaskInfo); + session_->CreateDetectStateTask(true, WindowMode::WINDOW_MODE_SPLIT_SECONDARY); + + std::shared_ptr owner(session_->handler_); + auto filter = [owner, &taskName](const AppExecFwk::InnerEvent::Pointer &p) { + return (p->HasTask()) && (p->GetOwner() == owner) && (p->GetTaskName() == taskName); + }; + bool hasEvent = session_->handler_->GetEventRunner()->GetEventQueue()->HasInnerEvent(filter); + ASSERT_EQ(false, hasEvent); + ASSERT_EQ(DetectTaskState::NO_TASK, session_->GetDetectTaskInfo().taskState); + ASSERT_EQ(WindowMode::WINDOW_MODE_UNDEFINED, session_->GetDetectTaskInfo().taskWindowMode); + session_->handler_->RemoveTask(taskName); +} + +/** + * @tc.name: CreateDetectStateTask003 + * @tc.desc: Detect sup and down tree tasks fo the same type. + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest, CreateDetectStateTask003, Function | SmallTest | Level2) +{ + std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_); + DetectTaskInfo detectTaskInfo; + detectTaskInfo.taskState = DetectTaskState::DETACH_TASK; + detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN; + session_->SetDetectTaskInfo(detectTaskInfo); + session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_SPLIT_SECONDARY); + + std::shared_ptr owner(session_->handler_); + auto filter = [owner, &taskName](const AppExecFwk::InnerEvent::Pointer &p) { + return (p->HasTask()) && (p->GetOwner() == owner) && (p->GetTaskName() == taskName); + }; + bool hasEvent = session_->handler_->GetEventRunner()->GetEventQueue()->HasInnerEvent(filter); + ASSERT_EQ(true, hasEvent); + ASSERT_EQ(DetectTaskState::DETACH_TASK, session_->GetDetectTaskInfo().taskState); + session_->handler_->RemoveTask(taskName); +} + +/** + * @tc.name: CreateDetectStateTask004 + * @tc.desc: Detection tasks under the same window mode. + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest, CreateDetectStateTask004, Function | SmallTest | Level2) +{ + std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_); + DetectTaskInfo detectTaskInfo; + detectTaskInfo.taskState = DetectTaskState::DETACH_TASK; + detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN; + session_->SetDetectTaskInfo(detectTaskInfo); + session_->CreateDetectStateTask(true, WindowMode::WINDOW_MODE_FULLSCREEN); + + std::shared_ptr owner(session_->handler_); + auto filter = [owner, &taskName](const AppExecFwk::InnerEvent::Pointer &p) { + return (p->HasTask()) && (p->GetOwner() == owner) && (p->GetTaskName() == taskName); + }; + bool hasEvent = session_->handler_->GetEventRunner()->GetEventQueue()->HasInnerEvent(filter); + ASSERT_EQ(true, hasEvent); + ASSERT_EQ(DetectTaskState::ATTACH_TASK, session_->GetDetectTaskInfo().taskState); + session_->handler_->RemoveTask(taskName); +} + +/** + * @tc.name: GetAttachState001 + * @tc.desc: GetAttachState001 + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest, GetAttachState001, Function | SmallTest | Level2) +{ + std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_); + session_->SetAttachState(false); + bool isAttach = session_->GetAttachState(); + ASSERT_EQ(false, isAttach); + session_->handler_->RemoveTask(taskName); } } diff --git a/window_scene/test/unittest/system_session_test.cpp b/window_scene/test/unittest/system_session_test.cpp index 7b7d2128ec..99d471d0ae 100644 --- a/window_scene/test/unittest/system_session_test.cpp +++ b/window_scene/test/unittest/system_session_test.cpp @@ -23,6 +23,7 @@ #include #include "window_helper.h" #include "window_manager_hilog.h" +#include "pointer_event.h" using namespace testing; using namespace testing::ext; @@ -272,6 +273,53 @@ HWTEST_F(SystemSessionTest, NotifyClientToUpdateRect01, Function | SmallTest | L ASSERT_EQ(WSError::WS_OK, ret); } +/** + * @tc.name: CheckPointerEventDispatch + * @tc.desc: check func CheckPointerEventDispatch + * @tc.type: FUNC + */ +HWTEST_F(SystemSessionTest, CheckPointerEventDispatch, Function | SmallTest | Level1) +{ + std::shared_ptr pointerEvent_ = MMI::PointerEvent::Create(); + SessionInfo info; + info.abilityName_ = "CheckPointerEventDispatch"; + info.bundleName_ = "CheckPointerEventDispatchBundleName"; + info.windowType_ = 2122; + sptr specificCallback_ = + new (std::nothrow) SceneSession::SpecificSessionCallback(); + sptr sysSession = + new (std::nothrow) SystemSession(info, specificCallback_); + sysSession->SetSessionState(SessionState::STATE_FOREGROUND); + bool ret1 = sysSession->CheckPointerEventDispatch(pointerEvent_); + ASSERT_EQ(true, ret1); +} + +/** + * @tc.name: UpdatePointerArea + * @tc.desc: check func UpdatePointerArea + * @tc.type: FUNC + */ +HWTEST_F(SystemSessionTest, UpdatePointerArea, Function | SmallTest | Level1) +{ + WSRect rect = { 0, 0, 0, 0 }; + SessionInfo info; + info.abilityName_ = "UpdatePointerArea"; + info.bundleName_ = "UpdatePointerAreaBundleName"; + info.windowType_ = 2122; + sptr specificCallback_ = + new (std::nothrow) SceneSession::SpecificSessionCallback(); + sptr sysSession = + new (std::nothrow) SystemSession(info, specificCallback_); + sysSession->UpdatePointerArea(rect); + ASSERT_NE(sysSession->preRect_, rect); + + sptr property = new WindowSessionProperty(); + property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + property->SetDecorEnable(true); + sysSession->UpdatePointerArea(rect); + ASSERT_EQ(sysSession->preRect_, rect); +} + /** * @tc.name: Hide * @tc.desc: test function : Hide diff --git a/window_scene/test/unittest/window_session_property_test.cpp b/window_scene/test/unittest/window_session_property_test.cpp index 67cd3be2a0..1faea50576 100755 --- a/window_scene/test/unittest/window_session_property_test.cpp +++ b/window_scene/test/unittest/window_session_property_test.cpp @@ -530,6 +530,69 @@ HWTEST_F(WindowSessionPropertyTest, SetIsShaped, Function | SmallTest | Level2) property->SetIsShaped(true); ASSERT_EQ(property->GetIsShaped(), true); } + +/** + * @tc.name: SetHideNonSystemFloatingWindows + * @tc.desc: SetHideNonSystemFloatingWindows and GetHideNonSystemFloatingWindows to check the value + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionPropertyTest, SetHideNonSystemFloatingWindows, Function | SmallTest | Level2) +{ + WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty(); + ASSERT_EQ(property->GetHideNonSystemFloatingWindows(), false); + property->SetHideNonSystemFloatingWindows(true); + ASSERT_EQ(property->GetHideNonSystemFloatingWindows(), true); +} + +/** + * @tc.name: KeepKeyboardOnFocus + * @tc.desc: KeepKeyboardOnFocus and GetKeepKeyboardFlag to check the value + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionPropertyTest, KeepKeyboardOnFocus, Function | SmallTest | Level2) +{ + WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty(); + ASSERT_EQ(property->GetKeepKeyboardFlag(), false); + property->KeepKeyboardOnFocus(true); + ASSERT_EQ(property->GetKeepKeyboardFlag(), true); +} + +/** + * @tc.name: SetTextFieldPositionY + * @tc.desc: SetTextFieldPositionY and GetTextFieldPositionY to check the value + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionPropertyTest, SetTextFieldPositionY, Function | SmallTest | Level2) +{ + WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty(); + property->SetTextFieldPositionY(5.5); + ASSERT_EQ(property->GetTextFieldPositionY(), 5.5); +} + +/** + * @tc.name: SetTextFieldHeight + * @tc.desc: SetTextFieldHeight and GetTextFieldHeight to check the value + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionPropertyTest, SetTextFieldHeight, Function | SmallTest | Level2) +{ + WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty(); + property->SetTextFieldHeight(5.5); + ASSERT_EQ(property->GetTextFieldHeight(), 5.5); +} + +/** + * @tc.name: SetIsLayoutFullScreen + * @tc.desc: SetIsLayoutFullScreen and IsLayoutFullScreen to check the value + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionPropertyTest, SetIsLayoutFullScreen, Function | SmallTest | Level2) +{ + WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty(); + ASSERT_EQ(property->IsLayoutFullScreen(), false); + property->SetIsLayoutFullScreen(true); + ASSERT_EQ(property->IsLayoutFullScreen(), true); +} } // namespace } // namespace Rosen } // namespace OHOS diff --git a/wm/BUILD.gn b/wm/BUILD.gn index dc6e57cb74..d59b1a86df 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -39,6 +39,7 @@ ohos_static_library("libwm_static") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false integer_overflow = true ubsan = true @@ -188,6 +189,7 @@ ohos_shared_library("libwm") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } include_dirs = [ @@ -425,6 +427,7 @@ ohos_shared_library("libwm_ndk") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 223aa8c7c0..1ca1326961 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -119,8 +119,8 @@ public: virtual void AddExtensionWindowStageToSCB(const sptr& sessionStage, int32_t persistentId, int32_t parentId); virtual WMError AddOrRemoveSecureSession(int32_t persistentId, bool shouldHide); - virtual WMError AddOrRemoveSecureExtSession(int32_t persistentId, int32_t parentId, bool shouldHide); - virtual WMError UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags); + virtual WMError UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags, + uint32_t extWindowActions); virtual WMError GetHostWindowRect(int32_t hostWindowId, Rect& rect); virtual WMError GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus); virtual WMError GetCallingWindowRect(int32_t persistentId, Rect& rect); diff --git a/wm/include/window_extension_session_impl.h b/wm/include/window_extension_session_impl.h index d1994368c2..356ded75b8 100644 --- a/wm/include/window_extension_session_impl.h +++ b/wm/include/window_extension_session_impl.h @@ -82,8 +82,7 @@ public: WMError Show(uint32_t reason = 0, bool withAnimation = false) override; WMError Hide(uint32_t reason, bool withAnimation, bool isFromInnerkits) override; WMError HideNonSecureWindows(bool shouldHide) override; - WMError AddExtensionWindowFlag(ExtensionWindowFlag flag) override; - WMError RemoveExtensionWindowFlag(ExtensionWindowFlag flag) override; + WMError SetWaterMarkFlag(bool isEnable) override; Rect GetHostWindowRect(int32_t hostWindowId) override; protected: @@ -99,17 +98,14 @@ private: std::shared_ptr> isConsumedPromise, std::shared_ptr isTimeout); void CheckAndAddExtWindowFlags(); void CheckAndRemoveExtWindowFlags(); - WMError SetExtWindowFlags(uint32_t flags); - WMError UpdateExtWindowFlags(); + WMError UpdateExtWindowFlags(const ExtensionWindowFlags& flags, const ExtensionWindowFlags& actions); sptr occupiedAreaChangeListener_; std::optional> focusState_ = std::nullopt; static std::set> windowExtensionSessionSet_; static std::shared_mutex windowExtensionSessionMutex_; int16_t rotationAnimationCount_ { 0 }; - bool shouldHideNonSecureWindows_ = false; - bool isWaterMarkEnable_ = false; - uint32_t extensionWindowFlags_ = 0; + ExtensionWindowFlags extensionWindowFlags_ { 0 }; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/window_scene_session_impl.h b/wm/include/window_scene_session_impl.h index 232d9dc289..d5977fc2ff 100644 --- a/wm/include/window_scene_session_impl.h +++ b/wm/include/window_scene_session_impl.h @@ -104,6 +104,7 @@ public: virtual WMError SetBackdropBlur(float radius) override; virtual WMError SetBackdropBlurStyle(WindowBlurStyle blurStyle) override; virtual WMError SetWindowMode(WindowMode mode) override; + virtual WMError SetGrayScale(float grayScale) override; virtual WMError SetTransparent(bool isTransparent) override; virtual WMError SetTurnScreenOn(bool turnScreenOn) override; @@ -145,6 +146,8 @@ public: WMError HideNonSecureWindows(bool shouldHide) override; virtual WMError SetWindowMask(const std::vector>& windowMask) override; WSError SwitchFreeMultiWindow(bool enable) override; + void NotifyKeyboardPanelInfoChange(const KeyboardPanelInfo& keyboardPanelInfo) override; + protected: void DestroySubWindow(); WMError CreateAndConnectSpecificSession(); @@ -194,6 +197,11 @@ private: uint32_t setSameSystembarPropertyCnt_ = 0; std::atomic isDefaultDensityEnabled_ = false; uint32_t getAvoidAreaCnt_ = 0; + + WMError RegisterKeyboardPanelInfoChangeListener(const sptr& listener) override; + WMError UnregisterKeyboardPanelInfoChangeListener(const sptr& listener) override; + static std::mutex keyboardPanelInfoChangeListenerMutex_; + sptr keyboardPanelInfoChangeListeners_ = nullptr; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index 8bd1729eae..18c3168640 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -333,6 +333,8 @@ private: void NotifyAfterResumed(); void NotifyAfterPaused(); + WMError InitUIContent(const std::string& contentInfo, napi_env env, napi_value storage, + WindowSetUIContentType type, AppExecFwk::Ability* ability, OHOS::Ace::UIContentErrorCode& aceRet); WMError SetUIContentInner(const std::string& contentInfo, napi_env env, napi_value storage, WindowSetUIContentType type, AppExecFwk::Ability* ability); std::shared_ptr> GetAbcContent(const std::string& abcPath); @@ -385,6 +387,7 @@ private: bool isMainHandlerAvailable_ = true; std::string subWindowTitle_ = { "" }; + std::string dialogTitle_ = { "" }; WindowTitleVisibleFlags windowTitleVisibleFlags_; KeyEventFilterFunc keyEventFilter_; }; diff --git a/wm/src/extension_window_impl.cpp b/wm/src/extension_window_impl.cpp index 19c805a49f..70428a5c3e 100644 --- a/wm/src/extension_window_impl.cpp +++ b/wm/src/extension_window_impl.cpp @@ -42,20 +42,14 @@ sptr ExtensionWindowImpl::GetWindow() WMError ExtensionWindowImpl::HideNonSecureWindows(bool shouldHide) { - WLOGI("HideNonSecureWindows is called"); + TLOGI(WmsLogTag::WMS_UIEXT, "HideNonSecureWindows is called"); return windowExtensionSessionImpl_->HideNonSecureWindows(shouldHide); } WMError ExtensionWindowImpl::SetWaterMarkFlag(bool isEnable) { TLOGI(WmsLogTag::WMS_UIEXT, "SetWaterMarkFlag is called"); - if (isEnable) { - return windowExtensionSessionImpl_->AddExtensionWindowFlag( - ExtensionWindowFlag::EXTENSION_WINDOW_FLAG_WATER_MARK); - } else { - return windowExtensionSessionImpl_->RemoveExtensionWindowFlag( - ExtensionWindowFlag::EXTENSION_WINDOW_FLAG_WATER_MARK); - } + return windowExtensionSessionImpl_->SetWaterMarkFlag(isEnable); } } // namespace Rosen } // namespace OHOS diff --git a/wm/src/picture_in_picture_controller.cpp b/wm/src/picture_in_picture_controller.cpp index 6e7fd004aa..38b1167431 100644 --- a/wm/src/picture_in_picture_controller.cpp +++ b/wm/src/picture_in_picture_controller.cpp @@ -538,8 +538,8 @@ void PictureInPictureController::UpdateXComponentPositionAndSize() mainWindowXComponentController_->GetSize(width, height); windowRect_.width_ = static_cast(width); windowRect_.height_ = static_cast(height); - windowRect_.posX_ = static_cast(posX); - windowRect_.posY_ = static_cast(posY); + windowRect_.posX_ = static_cast(posX); + windowRect_.posY_ = static_cast(posY); TLOGD(WmsLogTag::WMS_PIP, "position width: %{public}u, height: %{public}u, posX: %{public}d, posY: %{public}d", windowRect_.width_, windowRect_.height_, windowRect_.posX_, windowRect_.posY_); } diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 16c23f863b..2d970dc08e 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -622,18 +622,12 @@ WMError WindowAdapter::AddOrRemoveSecureSession(int32_t persistentId, bool shoul return static_cast(windowManagerServiceProxy_->AddOrRemoveSecureSession(persistentId, shouldHide)); } -WMError WindowAdapter::AddOrRemoveSecureExtSession(int32_t persistentId, int32_t parentId, bool shouldHide) -{ - INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING); - return static_cast(windowManagerServiceProxy_->AddOrRemoveSecureExtSession(persistentId, - parentId, shouldHide)); -} - -WMError WindowAdapter::UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags) +WMError WindowAdapter::UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags, + uint32_t extWindowActions) { INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING); return static_cast(windowManagerServiceProxy_->UpdateExtWindowFlags(parentId, persistentId, - extWindowFlags)); + extWindowFlags, extWindowActions)); } WMError WindowAdapter::GetHostWindowRect(int32_t hostWindowId, Rect& rect) diff --git a/wm/src/window_extension_session_impl.cpp b/wm/src/window_extension_session_impl.cpp index bfb51a1e9f..16bf65c65e 100644 --- a/wm/src/window_extension_session_impl.cpp +++ b/wm/src/window_extension_session_impl.cpp @@ -112,10 +112,6 @@ WMError WindowExtensionSessionImpl::Destroy(bool needNotifyServer, bool needClea state_ = WindowState::STATE_DESTROYED; requestState_ = WindowState::STATE_DESTROYED; } - if (shouldHideNonSecureWindows_) { - SingletonContainer::Get().AddOrRemoveSecureExtSession(property_->GetPersistentId(), - property_->GetParentId(), false); - } hostSession_ = nullptr; { std::unique_lock lock(windowExtensionSessionMutex_); @@ -227,14 +223,31 @@ void WindowExtensionSessionImpl::TriggerBindModalUIExtension() WMError WindowExtensionSessionImpl::SetPrivacyMode(bool isPrivacyMode) { - WLOGFD("id : %{public}u, SetPrivacyMode, %{public}u", GetWindowId(), isPrivacyMode); + TLOGD(WmsLogTag::WMS_UIEXT, "id: %{public}u, isPrivacyMode: %{public}u", GetWindowId(), isPrivacyMode); if (surfaceNode_ == nullptr) { - WLOGFE("surfaceNode_ is nullptr"); + TLOGE(WmsLogTag::WMS_UIEXT, "surfaceNode_ is nullptr"); return WMError::WM_ERROR_NULLPTR; } surfaceNode_->SetSecurityLayer(isPrivacyMode); RSTransaction::FlushImplicitTransaction(); - return WMError::WM_OK; + + if (state_ != WindowState::STATE_SHOWN) { + extensionWindowFlags_.privacyModeFlag = isPrivacyMode; + return WMError::WM_OK; + } + if (isPrivacyMode == extensionWindowFlags_.privacyModeFlag) { + return WMError::WM_OK; + } + + auto updateFlags = extensionWindowFlags_; + updateFlags.privacyModeFlag = isPrivacyMode; + ExtensionWindowFlags actions(0); + actions.privacyModeFlag = true; + auto ret = UpdateExtWindowFlags(updateFlags, actions); + if (ret == WMError::WM_OK) { + extensionWindowFlags_ = updateFlags; + } + return ret; } void WindowExtensionSessionImpl::NotifyFocusStateEvent(bool focusState) @@ -595,10 +608,6 @@ WMError WindowExtensionSessionImpl::UnregisterAvoidAreaChangeListener(sptr().AddOrRemoveSecureExtSession(property_->GetPersistentId(), - property_->GetParentId(), true); - } CheckAndAddExtWindowFlags(); auto display = SingletonContainer::Get().GetDisplayById(property_->GetDisplayId()); @@ -637,10 +646,6 @@ WMError WindowExtensionSessionImpl::Hide(uint32_t reason, bool withAnimation, bo state_ = WindowState::STATE_HIDDEN; requestState_ = WindowState::STATE_HIDDEN; NotifyAfterBackground(); - if (shouldHideNonSecureWindows_) { - SingletonContainer::Get().AddOrRemoveSecureExtSession(property_->GetPersistentId(), - property_->GetParentId(), false); - } } else { TLOGD(WmsLogTag::WMS_LIFE, "window extension session Hide to Background is error"); } @@ -649,71 +654,72 @@ WMError WindowExtensionSessionImpl::Hide(uint32_t reason, bool withAnimation, bo WMError WindowExtensionSessionImpl::HideNonSecureWindows(bool shouldHide) { - shouldHideNonSecureWindows_ = shouldHide; if (state_ != WindowState::STATE_SHOWN) { + extensionWindowFlags_.hideNonSecureWindowsFlag = shouldHide; + return WMError::WM_OK; + } + if (shouldHide == extensionWindowFlags_.hideNonSecureWindowsFlag) { return WMError::WM_OK; } - return SingletonContainer::Get().AddOrRemoveSecureExtSession(property_->GetPersistentId(), - property_->GetParentId(), shouldHide); -} - -WMError WindowExtensionSessionImpl::AddExtensionWindowFlag(ExtensionWindowFlag flag) -{ - TLOGI(WmsLogTag::WMS_UIEXT, "AddWindowFlag flags:%{public}u", (static_cast(flag))); - uint32_t updateFlags = property_->GetWindowFlags() | (static_cast(flag)); - return SetExtWindowFlags(updateFlags); -} - -WMError WindowExtensionSessionImpl::RemoveExtensionWindowFlag(ExtensionWindowFlag flag) -{ - TLOGI(WmsLogTag::WMS_UIEXT, "RemoveWindowFlag flags:%{public}u", (static_cast(flag))); - uint32_t updateFlags = property_->GetWindowFlags() & (~(static_cast(flag))); - return SetExtWindowFlags(updateFlags); -} - -void WindowExtensionSessionImpl::CheckAndAddExtWindowFlags() -{ - uint32_t updateFlags = extensionWindowFlags_; - if (isWaterMarkEnable_) { - updateFlags |= (static_cast(ExtensionWindowFlag::EXTENSION_WINDOW_FLAG_WATER_MARK)); - } - SetExtWindowFlags(updateFlags); -} - -void WindowExtensionSessionImpl::CheckAndRemoveExtWindowFlags() -{ - uint32_t updateFlags = extensionWindowFlags_; - if (isWaterMarkEnable_) { - updateFlags &= (~(static_cast(ExtensionWindowFlag::EXTENSION_WINDOW_FLAG_WATER_MARK))); - } - SetExtWindowFlags(updateFlags); -} - -WMError WindowExtensionSessionImpl::SetExtWindowFlags(uint32_t flags) -{ - TLOGD(WmsLogTag::WMS_UIEXT, "extensionWindowFlags_:%{public}u, flags:%{public}u", - extensionWindowFlags_, flags); - if (IsWindowSessionInvalid()) { - TLOGI(WmsLogTag::WMS_UIEXT, "session is invalid"); - return WMError::WM_ERROR_INVALID_WINDOW; - } - if (extensionWindowFlags_ == flags) { - return WMError::WM_OK; - } - auto oriFlags = extensionWindowFlags_; - extensionWindowFlags_ = flags; - WMError ret = UpdateExtWindowFlags(); - if (ret != WMError::WM_OK) { - extensionWindowFlags_ = oriFlags; + auto updateFlags = extensionWindowFlags_; + updateFlags.hideNonSecureWindowsFlag = shouldHide; + ExtensionWindowFlags actions(0); + actions.hideNonSecureWindowsFlag = true; + auto ret = UpdateExtWindowFlags(updateFlags, actions); + if (ret == WMError::WM_OK) { + extensionWindowFlags_ = updateFlags; } return ret; } -WMError WindowExtensionSessionImpl::UpdateExtWindowFlags() +WMError WindowExtensionSessionImpl::SetWaterMarkFlag(bool isEnable) { + if (state_ != WindowState::STATE_SHOWN) { + extensionWindowFlags_.waterMarkFlag = isEnable; + return WMError::WM_OK; + } + if (isEnable == extensionWindowFlags_.waterMarkFlag) { + return WMError::WM_OK; + } + + auto updateFlags = extensionWindowFlags_; + updateFlags.waterMarkFlag = isEnable; + ExtensionWindowFlags actions(0); + actions.waterMarkFlag = true; + auto ret = UpdateExtWindowFlags(updateFlags, actions); + if (ret == WMError::WM_OK) { + extensionWindowFlags_ = updateFlags; + } + return ret; +} + +void WindowExtensionSessionImpl::CheckAndAddExtWindowFlags() +{ + if (extensionWindowFlags_.bitData != 0) { + // If flag is true, make it active when foreground + UpdateExtWindowFlags(extensionWindowFlags_, extensionWindowFlags_); + } +} + +void WindowExtensionSessionImpl::CheckAndRemoveExtWindowFlags() +{ + if (extensionWindowFlags_.bitData != 0) { + // If flag is true, make it inactive when background + UpdateExtWindowFlags(ExtensionWindowFlags(), extensionWindowFlags_); + } +} + +WMError WindowExtensionSessionImpl::UpdateExtWindowFlags(const ExtensionWindowFlags& flags, + const ExtensionWindowFlags& actions) +{ + // action is true when the corresponding flag should be updated + if (IsWindowSessionInvalid()) { + TLOGI(WmsLogTag::WMS_UIEXT, "session is invalid"); + return WMError::WM_ERROR_INVALID_WINDOW; + } return SingletonContainer::Get().UpdateExtWindowFlags(property_->GetParentId(), GetPersistentId(), - extensionWindowFlags_); + flags.bitData, actions.bitData); } Rect WindowExtensionSessionImpl::GetHostWindowRect(int32_t hostWindowId) diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 6d83260076..feb0d59a5d 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -658,7 +658,7 @@ std::shared_ptr> WindowImpl::GetAbcContent(const std::strin begin = file.tellg(); file.seekg(0, std::ios::end); end = file.tellg(); - size_t len = end - begin; + size_t len = static_cast(end - begin); WLOGFD("abc file: %{public}s, size: %{public}u", abcPath.c_str(), static_cast(len)); if (len <= 0) { diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp index 6a34d05af2..92183a57ee 100644 --- a/wm/src/window_input_channel.cpp +++ b/wm/src/window_input_channel.cpp @@ -55,7 +55,8 @@ void WindowInputChannel::DispatchKeyEventCallback(std::shared_ptr } } -void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent) +__attribute__((no_sanitize("cfi"))) void WindowInputChannel::HandleKeyEvent( + std::shared_ptr& keyEvent) { if (keyEvent == nullptr) { WLOGFE("keyEvent is nullptr"); diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index df1c379bc3..6737599538 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -201,13 +201,17 @@ void WindowManager::Impl::NotifyAccessibilityWindowInfo(const std::vectorwid_, info->innerWid_, info->uiNodeId_, info->windowRect_.width_, info->windowRect_.height_, info->windowRect_.posX_, info->windowRect_.posY_, info->focused_, info->isDecorEnable_, info->displayId_, - info->layer_, info->mode_, info->type_, type); + info->layer_, info->mode_, info->type_, type, info->bundleName_.c_str()); + for (const auto& rect : info->touchHotAreas_) { + TLOGD(WmsLogTag::WMS_MAIN, "window touch hot areas rect[x=%{public}d,y=%{public}d," \ + "w=%{public}d,h=%{public}d]", rect.posX_, rect.posY_, rect.width_, rect.height_); + } } std::vector> windowUpdateListeners; diff --git a/wm/src/window_option.cpp b/wm/src/window_option.cpp index 4eca880e94..da98b72a6e 100644 --- a/wm/src/window_option.cpp +++ b/wm/src/window_option.cpp @@ -279,6 +279,25 @@ bool WindowOption::GetExtensionTag() const return isExtensionTag_; } +void WindowOption::SetDialogDecorEnable(bool decorEnable) +{ + dialogDecorEnable_ = decorEnable; +} + +bool WindowOption::GetDialogDecorEnable() const +{ + return dialogDecorEnable_; +} + +void WindowOption::SetDialogTitle(const std::string& dialogTitle) +{ + dialogTitle_ = dialogTitle; +} + +std::string WindowOption::GetDialogTitle() const +{ + return dialogTitle_; +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index 0c0292bce9..c657f8ec9e 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -72,8 +72,11 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowSceneSessionImpl"}; constexpr int32_t WINDOW_DETACH_TIMEOUT = 300; const std::string PARAM_DUMP_HELP = "-h"; +constexpr float MIN_GRAY_SCALE = 0.0f; +constexpr float MAX_GRAY_SCALE = 1.0f; } uint32_t WindowSceneSessionImpl::maxFloatingWindowSize_ = 1920; +std::mutex WindowSceneSessionImpl::keyboardPanelInfoChangeListenerMutex_; WindowSceneSessionImpl::WindowSceneSessionImpl(const sptr& option) : WindowSessionImpl(option) { @@ -349,7 +352,8 @@ void WindowSceneSessionImpl::UpdateWindowState() } state_ = WindowState::STATE_CREATED; requestState_ = WindowState::STATE_CREATED; - if (WindowHelper::IsMainWindow(GetType())) { + WindowType windowType = GetType(); + if (WindowHelper::IsMainWindow(windowType)) { if (windowSystemConfig_.maxFloatingWindowSize_ != UINT32_MAX) { maxFloatingWindowSize_ = windowSystemConfig_.maxFloatingWindowSize_; } @@ -364,8 +368,10 @@ void WindowSceneSessionImpl::UpdateWindowState() (property_->GetWindowFlags()) & (static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID))); GetConfigurationFromAbilityInfo(); } else { + bool isSubWindow = WindowHelper::IsSubWindow(windowType); + bool isDialogWindow = WindowHelper::IsDialogWindow(windowType); UpdateWindowSizeLimits(); - if (WindowHelper::IsSubWindow(GetType()) && property_->GetDragEnabled()) { + if ((isSubWindow || isDialogWindow) && property_->GetDragEnabled()) { WLOGFD("sync window limits to server side in order to make size limits work while resizing"); UpdateProperty(WSPropertyChangeAction::ACTION_UPDATE_WINDOW_LIMITS); } @@ -437,14 +443,17 @@ bool WindowSceneSessionImpl::HandlePointDownEvent(const std::shared_ptr(WINDOW_TITLE_BAR_HEIGHT * vpr); - bool isMoveArea = (0 <= pointerItem.GetWindowX() && - pointerItem.GetWindowX() <= static_cast(rect.width_)) && - (0 <= pointerItem.GetWindowY() && pointerItem.GetWindowY() <= static_cast(titleBarHeight)); + int32_t winX = pointerItem.GetWindowX(); + int32_t winY = pointerItem.GetWindowY(); + bool isMoveArea = (0 <= winX && winX <= static_cast(rect.width_)) && + (0 <= winY && winY <= static_cast(titleBarHeight)); int outside = (sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) ? static_cast(HOTZONE_POINTER * vpr) : static_cast(HOTZONE_TOUCH * vpr); - auto dragType = SessionHelper::GetAreaType(pointerItem.GetWindowX(), pointerItem.GetWindowY(), - sourceType, outside, vpr, rect); - if (WindowHelper::IsSystemWindow(property_->GetWindowType())) { + auto dragType = SessionHelper::GetAreaType(winX, winY, sourceType, outside, vpr, rect); + WindowType windowType = property_->GetWindowType(); + bool isDecorDialog = windowType == WindowType::WINDOW_TYPE_DIALOG && property_->IsDecorEnable(); + if ((WindowHelper::IsSystemWindow(windowType) && !isDecorDialog) || + (WindowHelper::IsSubWindow(windowType) && !property_->GetDragEnabled())) { hostSession_->ProcessPointDownSession(pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); } else { if (dragType != AreaType::UNDEFINED) { @@ -484,7 +493,6 @@ void WindowSceneSessionImpl::ConsumePointerEventInner(const std::shared_ptrGetCollaboratorType() != CollaboratorType::DEFAULT_TYPE) { + TLOGI(WmsLogTag::WMS_RECOVER, "collaboratorType is %{public}" PRId32 ", not need to recover", + property_->GetCollaboratorType()); + return; + } wptr weakThis = this; auto callbackFunc = [weakThis, isSpecificSession] { @@ -1253,9 +1266,7 @@ WMError WindowSceneSessionImpl::Resize(uint32_t width, uint32_t height) return WMError::WM_ERROR_INVALID_OPERATION; } - if (property_->GetWindowType() != WindowType::WINDOW_TYPE_FLOAT && - property_->GetWindowType() != WindowType::WINDOW_TYPE_PANEL && - GetMode() != WindowMode::WINDOW_MODE_FLOATING) { + if (GetMode() != WindowMode::WINDOW_MODE_FLOATING) { TLOGW(WmsLogTag::WMS_LAYOUT, "Fullscreen window could not resize, winId: %{public}u", GetWindowId()); return WMError::WM_ERROR_INVALID_OPERATION; } @@ -1647,15 +1658,19 @@ bool WindowSceneSessionImpl::IsDecorEnable() const /* FloatingWindow skip for Phone*/ return false; } + WindowType windowType = GetType(); + bool isMainWindow = WindowHelper::IsMainWindow(windowType); + bool isSubWindow = WindowHelper::IsSubWindow(windowType); + bool isDialogWindow = WindowHelper::IsDialogWindow(windowType); + bool isValidWindow = isMainWindow || + ((isSubWindow || isDialogWindow) && property_->IsDecorEnable()); + bool isWindowModeSupported = WindowHelper::IsWindowModeSupported( + windowSystemConfig_.decorModeSupportInfo_, GetMode()); if (windowSystemConfig_.freeMultiWindowSupport_) { - return (WindowHelper::IsMainWindow(GetType()) - || (WindowHelper::IsSubWindow(GetType()) && property_->IsDecorEnable())) && - windowSystemConfig_.isSystemDecorEnable_; + return isValidWindow && windowSystemConfig_.isSystemDecorEnable_; } - bool enable = (WindowHelper::IsMainWindow(GetType()) - || (WindowHelper::IsSubWindow(GetType()) && property_->IsDecorEnable())) && - windowSystemConfig_.isSystemDecorEnable_ && - WindowHelper::IsWindowModeSupported(windowSystemConfig_.decorModeSupportInfo_, GetMode()); + bool enable = isValidWindow && windowSystemConfig_.isSystemDecorEnable_ && + isWindowModeSupported; WLOGFD("get decor enable %{public}d", enable); return enable; } @@ -1803,8 +1818,14 @@ void WindowSceneSessionImpl::StartMove() WLOGFE("session is invalid"); return; } + WindowType windowType = GetType(); + bool isMainWindow = WindowHelper::IsMainWindow(windowType); + bool isSubWindow = WindowHelper::IsSubWindow(windowType); + bool isDialogWindow = WindowHelper::IsDialogWindow(windowType); + bool isDecorDialog = isDialogWindow && property_->IsDecorEnable(); auto isPC = system::GetParameter("const.product.devicetype", "unknown") == "2in1"; - if ((WindowHelper::IsMainWindow(GetType()) || (isPC && WindowHelper::IsSubWindow(GetType()))) && hostSession_) { + bool isValidWindow = isMainWindow || (isPC && (isSubWindow || isDecorDialog)); + if (isValidWindow && hostSession_) { hostSession_->OnSessionEvent(SessionEvent::EVENT_START_MOVE); } return; @@ -1817,7 +1838,11 @@ WMError WindowSceneSessionImpl::Close() WLOGFE("session is invalid"); return WMError::WM_ERROR_INVALID_WINDOW; } - if (WindowHelper::IsMainWindow(GetType())) { + WindowType windowType = GetType(); + bool isSubWindow = WindowHelper::IsSubWindow(windowType); + bool isSystemSubWindow = WindowHelper::IsSystemSubWindow(windowType); + bool isDialogWindow = WindowHelper::IsDialogWindow(windowType); + if (WindowHelper::IsMainWindow(windowType)) { auto abilityContext = AbilityRuntime::Context::ConvertTo(context_); if (!abilityContext) { return Destroy(true); @@ -1845,8 +1870,8 @@ WMError WindowSceneSessionImpl::Close() hostSession_->OnSessionEvent(SessionEvent::EVENT_CLOSE); return WMError::WM_OK; } - } else if (WindowHelper::IsSubWindow(GetType()) || WindowHelper::IsSystemSubWindow(GetType())) { - WLOGFI("WindowSceneSessionImpl::Close subwindow"); + } else if (isSubWindow || isSystemSubWindow || isDialogWindow) { + WLOGFI("WindowSceneSessionImpl::Close subwindow or dialog"); return Destroy(true); } @@ -1990,6 +2015,28 @@ WMError WindowSceneSessionImpl::SetWindowMode(WindowMode mode) return WMError::WM_OK; } +WMError WindowSceneSessionImpl::SetGrayScale(float grayScale) +{ + if (IsWindowSessionInvalid()) { + WLOGFE("session is invalid"); + return WMError::WM_ERROR_INVALID_WINDOW; + } + constexpr float eps = 1e-6f; + if (grayScale < (MIN_GRAY_SCALE - eps) || grayScale > (MAX_GRAY_SCALE + eps)) { + WLOGFE("invalid grayScale value: %{public}f", grayScale); + return WMError::WM_ERROR_INVALID_PARAM; + } + if (uiContent_ == nullptr) { + WLOGFE("uicontent is empty"); + return WMError::WM_ERROR_NULLPTR; + } + + uiContent_->SetContentNodeGrayScale(grayScale); + + WLOGI("Set window gray scale success, grayScale: %{public}f", grayScale); + return WMError::WM_OK; +} + WindowMode WindowSceneSessionImpl::GetMode() const { return property_->GetWindowMode(); @@ -3053,8 +3100,8 @@ std::unique_ptr WindowSceneSessionImpl::HandleWindowMask( } const uint32_t bgraChannel = 4; Media::InitializationOptions opts; - opts.size.width = maskWidth; - opts.size.height = maskHeight; + opts.size.width = static_cast(maskWidth); + opts.size.height = static_cast(maskHeight); uint32_t length = maskWidth * maskHeight * bgraChannel; uint8_t* data = static_cast(malloc(length)); if (data == nullptr) { @@ -3124,5 +3171,50 @@ bool WindowSceneSessionImpl::IfNotNeedAvoidKeyBoardForSplit() } return true; } + +WMError WindowSceneSessionImpl::RegisterKeyboardPanelInfoChangeListener( + const sptr& listener) +{ + if (!SessionPermission::IsStartedByInputMethod()) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "Listeners_ not registered by inputMethod id: %{public}d", + GetPersistentId()); + return WMError::WM_ERROR_INVALID_PERMISSION; + } + std::lock_guard lockListener(keyboardPanelInfoChangeListenerMutex_); + if (keyboardPanelInfoChangeListeners_ == nullptr) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "Register keyboard Panel info change listener id: %{public}d", + GetPersistentId()); + keyboardPanelInfoChangeListeners_ = listener; + } else { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Keyboard Panel info change, listener already registered"); + return WMError::WM_ERROR_INVALID_OPERATION; + } + + return WMError::WM_OK; +} + +WMError WindowSceneSessionImpl::UnregisterKeyboardPanelInfoChangeListener( + const sptr& listener) +{ + std::lock_guard lockListener(keyboardPanelInfoChangeListenerMutex_); + keyboardPanelInfoChangeListeners_ = nullptr; + TLOGI(WmsLogTag::WMS_KEYBOARD, "UnRegister keyboard Panel info change listener id: %{public}d", GetPersistentId()); + + return WMError::WM_OK; +} + +void WindowSceneSessionImpl::NotifyKeyboardPanelInfoChange(const KeyboardPanelInfo& keyboardPanelInfo) +{ + TLOGI(WmsLogTag::WMS_KEYBOARD, "isKeyboardPanelShown: %{public}d, gravity: %{public}d" + ", rect_: [%{public}d, %{public}d, %{public}d, %{public}d]", keyboardPanelInfo.isShowing_, + keyboardPanelInfo.gravity_, keyboardPanelInfo.rect_.posX_, keyboardPanelInfo.rect_.posY_, + keyboardPanelInfo.rect_.width_, keyboardPanelInfo.rect_.height_); + std::lock_guard lockListener(keyboardPanelInfoChangeListenerMutex_); + if (keyboardPanelInfoChangeListeners_ && keyboardPanelInfoChangeListeners_.GetRefPtr()) { + keyboardPanelInfoChangeListeners_.GetRefPtr()->OnKeyboardPanelInfoChanged(keyboardPanelInfo); + } else { + TLOGI(WmsLogTag::WMS_KEYBOARD, "keyboardPanelInfoChangeListeners_ is unRegistered"); + } +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index ef809fe590..138635a472 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -128,12 +128,13 @@ WindowSessionImpl::WindowSessionImpl(const sptr& option) WLOGFE("[WMSCom]Property is null"); return; } + WindowType optionWindowType = option->GetWindowType(); SessionInfo sessionInfo; sessionInfo.bundleName_ = option->GetBundleName(); property_->SetSessionInfo(sessionInfo); property_->SetWindowName(option->GetWindowName()); property_->SetRequestRect(option->GetWindowRect()); - property_->SetWindowType(option->GetWindowType()); + property_->SetWindowType(optionWindowType); property_->SetFocusable(option->GetFocusable()); property_->SetTouchable(option->GetTouchable()); property_->SetDisplayId(option->GetDisplayId()); @@ -147,15 +148,24 @@ WindowSessionImpl::WindowSessionImpl(const sptr& option) isMainHandlerAvailable_ = option->GetMainHandlerAvailable(); auto isPC = system::GetParameter("const.product.devicetype", "unknown") == "2in1"; - if (isPC && WindowHelper::IsSubWindow(option->GetWindowType())) { + if (isPC && WindowHelper::IsSubWindow(optionWindowType)) { WLOGFD("create subwindow, title: %{public}s, decorEnable: %{public}d", option->GetSubWindowTitle().c_str(), option->GetSubWindowDecorEnable()); property_->SetDecorEnable(option->GetSubWindowDecorEnable()); property_->SetDragEnabled(option->GetSubWindowDecorEnable()); subWindowTitle_ = option->GetSubWindowTitle(); } + bool isDialog = WindowHelper::IsDialogWindow(optionWindowType); + if (isPC && isDialog) { + bool dialogDecorEnable = option->GetDialogDecorEnable(); + property_->SetDecorEnable(dialogDecorEnable); + property_->SetDragEnabled(dialogDecorEnable); + dialogTitle_ = option->GetDialogTitle(); + WLOGFD("create dialogWindow, title: %{public}s, decorEnable: %{public}d", + dialogTitle_.c_str(), dialogDecorEnable); + } - surfaceNode_ = CreateSurfaceNode(property_->GetWindowName(), option->GetWindowType()); + surfaceNode_ = CreateSurfaceNode(property_->GetWindowName(), optionWindowType); handler_ = std::make_shared(AppExecFwk::EventRunner::GetMainEventRunner()); if (surfaceNode_ != nullptr) { vsyncStation_ = std::make_shared(surfaceNode_->GetId()); @@ -707,7 +717,10 @@ void WindowSessionImpl::UpdateTitleButtonVisibility() return; } auto isPC = system::GetParameter("const.product.devicetype", "unknown") == "2in1"; - if (isPC && WindowHelper::IsSubWindow(GetType())) { + WindowType windowType = GetType(); + bool isSubWindow = WindowHelper::IsSubWindow(windowType); + bool isDialogWindow = WindowHelper::IsDialogWindow(windowType); + if (isPC && (isSubWindow || isDialogWindow)) { WLOGFD("hide other buttons except close"); uiContent_->HideWindowTitleButton(true, true, true); return; @@ -745,15 +758,9 @@ WMError WindowSessionImpl::SetUIContentByAbc( return SetUIContentInner(contentInfo, env, storage, WindowSetUIContentType::BY_ABC, ability); } -WMError WindowSessionImpl::SetUIContentInner(const std::string& contentInfo, napi_env env, napi_value storage, - WindowSetUIContentType type, AppExecFwk::Ability* ability) +WMError WindowSessionImpl::InitUIContent(const std::string& contentInfo, napi_env env, napi_value storage, + WindowSetUIContentType type, AppExecFwk::Ability* ability, OHOS::Ace::UIContentErrorCode& aceRet) { - TLOGD(WmsLogTag::WMS_LIFE, "NapiSetUIContent: %{public}s state:%{public}u", contentInfo.c_str(), state_); - if (IsWindowSessionInvalid()) { - TLOGE(WmsLogTag::WMS_LIFE, "interrupt set uicontent because window is invalid! window state: %{public}d", - state_); - return WMError::WM_ERROR_INVALID_WINDOW; - } if (uiContent_) { uiContent_->Destroy(); } @@ -767,8 +774,6 @@ WMError WindowSessionImpl::SetUIContentInner(const std::string& contentInfo, nap TLOGE(WmsLogTag::WMS_LIFE, "fail to NapiSetUIContent id: %{public}d", GetPersistentId()); return WMError::WM_ERROR_NULLPTR; } - - OHOS::Ace::UIContentErrorCode aceRet = OHOS::Ace::UIContentErrorCode::NO_ERRORS; switch (type) { default: case WindowSetUIContentType::DEFAULT: @@ -799,9 +804,32 @@ WMError WindowSessionImpl::SetUIContentInner(const std::string& contentInfo, nap WLOGFI("UIContent Initialize, isUIExtensionSubWindow:%{public}d, isUIExtensionAbilityProcess:%{public}d", uiContent_->IsUIExtensionSubWindow(), uiContent_->IsUIExtensionAbilityProcess()); + return WMError::WM_OK; +} - if (WindowHelper::IsSubWindow(GetType()) && IsDecorEnable()) { - SetAPPWindowLabel(subWindowTitle_); +WMError WindowSessionImpl::SetUIContentInner(const std::string& contentInfo, napi_env env, napi_value storage, + WindowSetUIContentType type, AppExecFwk::Ability* ability) +{ + TLOGD(WmsLogTag::WMS_LIFE, "NapiSetUIContent: %{public}s state:%{public}u", contentInfo.c_str(), state_); + if (IsWindowSessionInvalid()) { + TLOGE(WmsLogTag::WMS_LIFE, "interrupt set uicontent because window is invalid! window state: %{public}d", + state_); + return WMError::WM_ERROR_INVALID_WINDOW; + } + OHOS::Ace::UIContentErrorCode aceRet = OHOS::Ace::UIContentErrorCode::NO_ERRORS; + WMError initUIContentRet = InitUIContent(contentInfo, env, storage, type, ability, aceRet); + if (initUIContentRet != WMError::WM_OK) { + return initUIContentRet; + } + WindowType winType = GetType(); + bool isSubWindow = WindowHelper::IsSubWindow(winType); + bool isDialogWindow = WindowHelper::IsDialogWindow(winType); + if (IsDecorEnable()) { + if (isSubWindow) { + SetAPPWindowLabel(subWindowTitle_); + } else if (isDialogWindow) { + SetAPPWindowLabel(dialogTitle_); + } } uint32_t version = 0; @@ -855,7 +883,7 @@ std::shared_ptr> WindowSessionImpl::GetAbcContent(const std begin = file.tellg(); file.seekg(0, std::ios::end); end = file.tellg(); - size_t len = end - begin; + size_t len = static_cast(end - begin); WLOGFD("abc file: %{public}s, size: %{public}u", abcPath.c_str(), static_cast(len)); if (len <= 0) { @@ -1308,6 +1336,9 @@ WMError WindowSessionImpl::SetDecorHeight(int32_t decorHeight) float vpr = GetVirtualPixelRatio(display->GetDisplayInfo()); int32_t decorHeightWithPx = static_cast(decorHeight * vpr); uiContent_->SetContainerModalTitleHeight(decorHeightWithPx); + if (hostSession_ != nullptr) { + hostSession_->SetCustomDecorHeight(decorHeight); + } WLOGI("Set app window decor height success, height : %{public}d", decorHeight); return WMError::WM_OK; } @@ -1791,6 +1822,7 @@ void WindowSessionImpl::NotifyBeforeDestroy(std::string windowName) void WindowSessionImpl::NotifyAfterDestroy() { + std::lock_guard lockListener(lifeCycleListenerMutex_); auto lifecycleListeners = GetListeners(); CALL_LIFECYCLE_LISTENER(AfterDestroyed, lifecycleListeners); } diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index 40a5916fad..42c3ba61bd 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -66,6 +66,7 @@ ohos_unittest("wm_window_manager_test") { external_deps = [ "c_utils:utils", + "ffrt:libffrt", "hilog:libhilog", ] @@ -219,7 +220,10 @@ ohos_unittest("wm_window_test") { sources = [ "window_test.cpp" ] - deps = [ ":wm_unittest_common" ] + deps = [ + ":wm_unittest_common", + "${window_base_path}/window_scene/interfaces/innerkits:libwsutils", + ] external_deps = [ "c_utils:utils", diff --git a/wm/test/unittest/picture_in_picture_manager_test.cpp b/wm/test/unittest/picture_in_picture_manager_test.cpp index 90a4e7d1de..4fd7c75d50 100644 --- a/wm/test/unittest/picture_in_picture_manager_test.cpp +++ b/wm/test/unittest/picture_in_picture_manager_test.cpp @@ -80,6 +80,168 @@ HWTEST_F(PictureInPictureManagerTest, PictureInPictureController, Function | Sma ASSERT_FALSE(PictureInPictureManager::HasActiveController()); ASSERT_FALSE(PictureInPictureManager::IsActiveController(pipController)); } + +/** + * @tc.name: ShouldAbortPipStart + * @tc.desc: ShouldAbortPipStart + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureManagerTest, ShouldAbortPipStart, Function | SmallTest | Level2) +{ + ASSERT_FALSE(PictureInPictureManager::ShouldAbortPipStart()); + + sptr option = new (std::nothrow) PipOption(); + sptr pipController = + new (std::nothrow) PictureInPictureController(option, nullptr, 100, nullptr); + ASSERT_NE(pipController, nullptr); + PictureInPictureManager::SetActiveController(pipController); + pipController->curState_ = PiPWindowState::STATE_STARTING; + + ASSERT_TRUE(PictureInPictureManager::ShouldAbortPipStart()); +} + +/** + * @tc.name: GetPipControllerInfo + * @tc.desc: GetPipControllerInfo + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureManagerTest, GetPipControllerInfo, Function | SmallTest | Level2) +{ + sptr option = new (std::nothrow) PipOption(); + sptr pipController = + new (std::nothrow) PictureInPictureController(option, nullptr, 100, nullptr); + ASSERT_NE(pipController, nullptr); + PictureInPictureManager::SetActiveController(pipController); + int32_t windowId = 1; + ASSERT_EQ(nullptr, PictureInPictureManager::GetPipControllerInfo(windowId)); + + sptr pipController1 = + new (std::nothrow) PictureInPictureController(option, nullptr, 100, nullptr); + ASSERT_NE(pipController1, nullptr); + PictureInPictureManager::windowToControllerMap_.insert(std::make_pair(windowId, pipController1)); + ASSERT_EQ(pipController1, PictureInPictureManager::GetPipControllerInfo(windowId)); +} + +/** + * @tc.name: AttachAutoStartController + * @tc.desc: AttachAutoStartController + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureManagerTest, AttachAutoStartController, Function | SmallTest | Level2) +{ + int result = 0; + PictureInPictureManager::AttachAutoStartController(0, nullptr); + + sptr option = new (std::nothrow) PipOption(); + sptr pipController = + new (std::nothrow) PictureInPictureController(option, nullptr, 100, nullptr); + ASSERT_NE(pipController, nullptr); + PictureInPictureManager::SetActiveController(pipController); + result++; + wptr pipController1 = + new (std::nothrow) PictureInPictureController(option, nullptr, 100, nullptr); + ASSERT_NE(pipController1, nullptr); + PictureInPictureManager::autoStartController_ = pipController1; + sptr mainWindowLifeCycleImpl = new (std::nothrow) IWindowLifeCycle(); + ASSERT_NE(mainWindowLifeCycleImpl, nullptr); + PictureInPictureManager::mainWindowLifeCycleImpl_ = mainWindowLifeCycleImpl; + PictureInPictureManager::AttachAutoStartController(0, pipController1); + ASSERT_EQ(result, 1); +} + +/** + * @tc.name: DetachAutoStartController + * @tc.desc: DetachAutoStartController + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureManagerTest, DetachAutoStartController, Function | SmallTest | Level2) +{ + int result = 0; + PictureInPictureManager::DetachAutoStartController(0, nullptr); + sptr option = new (std::nothrow) PipOption(); + sptr pipController = + new (std::nothrow) PictureInPictureController(option, nullptr, 100, nullptr); + ASSERT_NE(pipController, nullptr); + PictureInPictureManager::SetActiveController(pipController); + result++; + wptr pipController1 = + new (std::nothrow) PictureInPictureController(option, nullptr, 100, nullptr); + ASSERT_NE(pipController1, nullptr); + PictureInPictureManager::autoStartController_ = pipController1; + PictureInPictureManager::DetachAutoStartController(0, pipController1); + ASSERT_EQ(result, 1); +} + +/** + * @tc.name: IsAttachedToSameWindow + * @tc.desc: IsAttachedToSameWindow + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureManagerTest, IsAttachedToSameWindow, Function | SmallTest | Level2) +{ + bool res = PictureInPictureManager::IsAttachedToSameWindow(0); + ASSERT_EQ(res, false); + + sptr option = new (std::nothrow) PipOption(); + sptr pipController = + new (std::nothrow) PictureInPictureController(option, nullptr, 100, nullptr); + ASSERT_NE(pipController, nullptr); + PictureInPictureManager::SetActiveController(pipController); + + bool res1 = PictureInPictureManager::IsAttachedToSameWindow(100); + ASSERT_EQ(res1, true); + bool res2 = PictureInPictureManager::IsAttachedToSameWindow(1); + ASSERT_EQ(res2, false); +} + +/** + * @tc.name: GetCurrentWindow + * @tc.desc: GetCurrentWindow + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureManagerTest, GetCurrentWindow, Function | SmallTest | Level2) +{ + ASSERT_EQ(nullptr, PictureInPictureManager::GetCurrentWindow()); + + sptr option = new (std::nothrow) PipOption(); + sptr pipController = + new (std::nothrow) PictureInPictureController(option, nullptr, 100, nullptr); + ASSERT_NE(pipController, nullptr); + PictureInPictureManager::SetActiveController(pipController); + + sptr window = PictureInPictureManager::GetCurrentWindow(); + ASSERT_EQ(window, pipController->window_); +} + +/** + * @tc.name: DoRestore + * @tc.desc: DoRestore/DoClose/DoActionEvent + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureManagerTest, DoRestore, Function | SmallTest | Level2) +{ + int result = 0; + PictureInPictureManager::DoRestore(); + PictureInPictureManager::DoClose(true, true); + std::string actionName = "test"; + PictureInPictureManager::DoActionEvent(actionName, 0); + + sptr option = new (std::nothrow) PipOption(); + sptr pipController = + new (std::nothrow) PictureInPictureController(option, nullptr, 100, nullptr); + ASSERT_NE(pipController, nullptr); + PictureInPictureManager::SetActiveController(pipController); + result++; + + PictureInPictureManager::DoRestore(); + PictureInPictureManager::DoClose(true, true); + PictureInPictureManager::DoClose(true, false); + const std::string ACTION_CLOSE = "close"; + const std::string ACTION_RESTORE = "restore"; + PictureInPictureManager::DoActionEvent(ACTION_CLOSE, 0); + PictureInPictureManager::DoActionEvent(ACTION_RESTORE, 0); + ASSERT_EQ(result, 1); +} } } } \ No newline at end of file diff --git a/wm/test/unittest/window_extension_session_impl_test.cpp b/wm/test/unittest/window_extension_session_impl_test.cpp index 83d4eace1b..dc321c8f39 100644 --- a/wm/test/unittest/window_extension_session_impl_test.cpp +++ b/wm/test/unittest/window_extension_session_impl_test.cpp @@ -424,7 +424,35 @@ HWTEST_F(WindowExtensionSessionImplTest, HideNonSecureWindows, Function | SmallT windowExtensionSessionImpl.state_ = WindowState::STATE_HIDDEN; ASSERT_EQ(WMError::WM_OK, windowExtensionSessionImpl.HideNonSecureWindows(true)); windowExtensionSessionImpl.state_ = WindowState::STATE_SHOWN; - ASSERT_EQ(WMError::WM_OK, windowExtensionSessionImpl.HideNonSecureWindows(true)); + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, windowExtensionSessionImpl.HideNonSecureWindows(false)); +} + +/** + * @tc.name: SetWaterMarkFlag + * @tc.desc: SetWaterMarkFlag Test + * @tc.type: FUNC + */ +HWTEST_F(WindowExtensionSessionImplTest, SetWaterMarkFlag, Function | SmallTest | Level3) +{ + sptr option = new WindowOption(); + WindowExtensionSessionImpl windowExtensionSessionImpl(option); + windowExtensionSessionImpl.state_ = WindowState::STATE_HIDDEN; + ASSERT_EQ(WMError::WM_OK, windowExtensionSessionImpl.SetWaterMarkFlag(true)); + windowExtensionSessionImpl.state_ = WindowState::STATE_SHOWN; + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, windowExtensionSessionImpl.SetWaterMarkFlag(false)); +} + +/** + * @tc.name: UpdateExtWindowFlags + * @tc.desc: UpdateExtWindowFlags Test + * @tc.type: FUNC + */ +HWTEST_F(WindowExtensionSessionImplTest, UpdateExtWindowFlags, Function | SmallTest | Level3) +{ + sptr option = new WindowOption(); + WindowExtensionSessionImpl windowExtensionSessionImpl(option); + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, windowExtensionSessionImpl.UpdateExtWindowFlags(ExtensionWindowFlags(7), + ExtensionWindowFlags(7))); } /** @@ -649,8 +677,6 @@ HWTEST_F(WindowExtensionSessionImplTest, Destroy01, Function | SmallTest | Level sptr impl; windowExtensionSessionImpl.hostSession_ = new OHOS::Rosen::SessionProxy(impl); - windowExtensionSessionImpl.shouldHideNonSecureWindows_ = true; - ASSERT_EQ(true, windowExtensionSessionImpl.shouldHideNonSecureWindows_); windowExtensionSessionImpl.Destroy(needNotifyServer, needClearListener); ASSERT_NE(nullptr, windowExtensionSessionImpl.hostSession_); diff --git a/wm/test/unittest/window_manager_lite_test.cpp b/wm/test/unittest/window_manager_lite_test.cpp index 3ab660b079..b8f2524a96 100644 --- a/wm/test/unittest/window_manager_lite_test.cpp +++ b/wm/test/unittest/window_manager_lite_test.cpp @@ -162,5 +162,36 @@ HWTEST_F(WindowManagerLiteTest, UnregisterCameraWindowChangedListener01, Functio windowManager.pImpl_->cameraWindowChangedListenerAgent_ = oldWindowManagerAgent; windowManager.pImpl_->cameraWindowChangedListeners_ = oldListeners; } + +/** + * @tc.name: Test01 + * @tc.desc: check UnregisterCameraWindowChangedListener + * @tc.type: FUNC + */ +HWTEST_F(WindowManagerLiteTest, Test01, Function | SmallTest | Level2) +{ + sptr listener = nullptr; + auto ret1 = WindowManagerLite::GetInstance().RegisterFocusChangedListener(listener); + auto ret2 = WindowManagerLite::GetInstance().UnregisterFocusChangedListener(listener); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret1); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret2); + sptr listener1 = nullptr; + auto ret3 = WindowManagerLite::GetInstance().RegisterVisibilityChangedListener(listener1); + auto ret4 = WindowManagerLite::GetInstance().UnregisterVisibilityChangedListener(listener1); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret3); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret4); + std::vector> infos; + ASSERT_EQ(WMError::WM_OK, WindowManagerLite::GetInstance().GetVisibilityWindowInfo(infos)); + sptr listener2 = nullptr; + auto ret5 = WindowManagerLite::GetInstance().RegisterDrawingContentChangedListener(listener2); + auto ret6 = WindowManagerLite::GetInstance().UnregisterDrawingContentChangedListener(listener2); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret5); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret6); + sptr listener3 = nullptr; + auto ret7 = WindowManagerLite::GetInstance().RegisterWindowModeChangedListener(listener3); + auto ret8 = WindowManagerLite::GetInstance().UnregisterWindowModeChangedListener(listener3); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret7); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret8); +} } } \ No newline at end of file diff --git a/wm/test/unittest/window_manager_test.cpp b/wm/test/unittest/window_manager_test.cpp index 6c2e971d67..7224f95c2f 100644 --- a/wm/test/unittest/window_manager_test.cpp +++ b/wm/test/unittest/window_manager_test.cpp @@ -827,8 +827,6 @@ HWTEST_F(WindowManagerTest, UnregisterVisibleWindowNumChangedListener, Function sptr listener1 = new TestVisibleWindowNumChangedListener(); sptr listener2 = new TestVisibleWindowNumChangedListener(); - ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, - windowManager.UnregisterVisibleWindowNumChangedListener(listener1)); EXPECT_CALL(m->Mock(), RegisterWindowManagerAgent(_, _)).Times(1).WillOnce(Return(WMError::WM_OK)); windowManager.RegisterVisibleWindowNumChangedListener(listener1); @@ -836,16 +834,14 @@ HWTEST_F(WindowManagerTest, UnregisterVisibleWindowNumChangedListener, Function windowManager.RegisterVisibleWindowNumChangedListener(listener2); ASSERT_EQ(2, windowManager.pImpl_->visibleWindowNumChangedListeners_.size()); - EXPECT_CALL(m->Mock(), UnregisterWindowManagerAgent(_, _)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, windowManager.UnregisterVisibleWindowNumChangedListener(listener1)); ASSERT_EQ(WMError::WM_OK, windowManager.UnregisterVisibleWindowNumChangedListener(listener2)); - ASSERT_EQ(0, windowManager.pImpl_->visibleWindowNumChangedListeners_.size()); - ASSERT_EQ(nullptr, windowManager.pImpl_->visibleWindowNumChangedListenerAgent_); + ASSERT_EQ(2, windowManager.pImpl_->visibleWindowNumChangedListeners_.size()); // if agent == nullptr, it can not be crashed. windowManager.pImpl_->visibleWindowNumChangedListeners_.push_back(listener1); ASSERT_EQ(WMError::WM_OK, windowManager.UnregisterVisibleWindowNumChangedListener(listener1)); - ASSERT_EQ(0, windowManager.pImpl_->visibleWindowNumChangedListeners_.size()); + ASSERT_EQ(3, windowManager.pImpl_->visibleWindowNumChangedListeners_.size()); } /** @@ -874,6 +870,26 @@ HWTEST_F(WindowManagerTest, RegisterAndOnVisibleWindowNumChanged, Function | Sma windowManager.UpdateVisibleWindowNum(visibleWindowNumInfo); ASSERT_EQ(0, ret); } + +/** + * @tc.name: Test01 + * @tc.desc: Test01 + * @tc.type: FUNC + */ +HWTEST_F(WindowManagerTest, Test01, Function | SmallTest | Level2) +{ + sptr listener = nullptr; + WMError res = WindowManager::GetInstance().RegisterWMSConnectionChangedListener(listener); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, res); + WMError res1 = WindowManager::GetInstance().UnregisterWMSConnectionChangedListener(); + ASSERT_EQ(WMError::WM_OK, res1); + WMError res2 = WindowManager::GetInstance().RaiseWindowToTop(5); + ASSERT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, res2); + WMError res3 = WindowManager::GetInstance().NotifyWindowExtensionVisibilityChange(5, 5, true); + ASSERT_EQ(WMError::WM_OK, res3); + WMError res4 = WindowManager::GetInstance().ShiftAppWindowFocus(0, 1); + ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, res4); +} } } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wm/test/unittest/window_option_test.cpp b/wm/test/unittest/window_option_test.cpp index ae485eaa3e..c8892cbf60 100644 --- a/wm/test/unittest/window_option_test.cpp +++ b/wm/test/unittest/window_option_test.cpp @@ -399,6 +399,27 @@ HWTEST_F(WindowOptionTest, GetWindowSessionType, Function | SmallTest | Level3) option->GetWindowSessionType(); ASSERT_EQ(WindowSessionType::SCENE_SESSION, option->GetWindowSessionType()); } + +/** + * @tc.name: Test01 + * @tc.desc: Test01 + * @tc.type: FUNC + */ +HWTEST_F(WindowOptionTest, Test01, Function | SmallTest | Level3) +{ + sptr option = new WindowOption(); + ASSERT_NE(nullptr, option); + option->SetExtensionTag(true); + option->SetSubWindowTitle("Test"); + std::string ret = option->GetSubWindowTitle(); + ASSERT_EQ(true, ret == "Test"); + option->SetSubWindowDecorEnable(true); + bool ret1 = option->GetSubWindowDecorEnable(); + ASSERT_EQ(true, ret1); + option->SetOnlySupportSceneBoard(true); + bool ret2 = option->GetOnlySupportSceneBoard(); + ASSERT_EQ(true, ret2); +} } } // namespace Rosen } // namespace OHOS diff --git a/wm/test/unittest/window_scene_session_impl_test.cpp b/wm/test/unittest/window_scene_session_impl_test.cpp index 7c61ec25c8..ad64e1787c 100644 --- a/wm/test/unittest/window_scene_session_impl_test.cpp +++ b/wm/test/unittest/window_scene_session_impl_test.cpp @@ -568,6 +568,7 @@ HWTEST_F(WindowSceneSessionImplTest, Resize01, Function | SmallTest | Level2) { sptr option = new (std::nothrow) WindowOption(); option->SetWindowName("Resize01"); + option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); sptr windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option); ASSERT_NE(nullptr, windowscenesession); @@ -581,7 +582,34 @@ HWTEST_F(WindowSceneSessionImplTest, Resize01, Function | SmallTest | Level2) windowscenesession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA); windowscenesession->state_ = WindowState::STATE_FROZEN; windowscenesession->hostSession_ = session; + ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, windowscenesession->Resize(1, 1)); +} + +/** + * @tc.name: Resize02 + * @tc.desc: Resize + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest, Resize02, Function | SmallTest | Level2) +{ + sptr option = new (std::nothrow) WindowOption(); + option->SetWindowName("Resize02"); + option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT); + sptr windowscenesession = new (std::nothrow) WindowSceneSessionImpl(option); + ASSERT_NE(nullptr, windowscenesession); + + windowscenesession->property_->SetPersistentId(888); + SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"}; + sptr session = new (std::nothrow) SessionMocker(sessionInfo); + ASSERT_NE(nullptr, session); + windowscenesession->state_ = WindowState::STATE_FROZEN; + windowscenesession->hostSession_ = session; + + windowscenesession->SetDefaultProperty(); ASSERT_EQ(WMError::WM_OK, windowscenesession->Resize(1, 1)); + + windowscenesession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, windowscenesession->Resize(1, 1)); } /** @@ -781,7 +809,7 @@ HWTEST_F(WindowSceneSessionImplTest, Hide01, Function | SmallTest | Level2) window->property_->type_ = WindowType::APP_SUB_WINDOW_BASE; if (window->Destroy(false) == WMError::WM_OK) { - ASSERT_EQ(WMError::WM_OK, window->Destroy(false)); + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false)); } } @@ -915,7 +943,7 @@ HWTEST_F(WindowSceneSessionImplTest, GetAvoidAreaByType, Function | SmallTest | sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); AvoidArea avoidarea; - ASSERT_EQ(WMError::WM_OK, window->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT, avoidarea)); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT, avoidarea)); } /* @@ -1627,7 +1655,7 @@ HWTEST_F(WindowSceneSessionImplTest, SetTransform01, Function | SmallTest | Leve Transform trans_; window->SetTransform(trans_); ASSERT_TRUE(trans_ == window->GetTransform()); - ASSERT_EQ(WMError::WM_OK, window->Destroy(false)); + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false)); } /** @@ -2071,7 +2099,7 @@ HWTEST_F(WindowSceneSessionImplTest, DumpSessionElementInfo1, Function | SmallTe window->uiContent_ = std::make_unique(); ASSERT_EQ(WMError::WM_OK, window->NotifyMemoryLevel(2)); delete option; - ASSERT_EQ(WMError::WM_OK, window->Destroy(false)); + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false)); } /** @@ -2094,7 +2122,7 @@ HWTEST_F(WindowSceneSessionImplTest, DumpSessionElementInfo2, Function | SmallTe window->DumpSessionElementInfo(params); ASSERT_EQ(WMError::WM_OK, window->NotifyMemoryLevel(2)); delete option; - ASSERT_EQ(WMError::WM_OK, window->Destroy(false)); + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false)); } /** @@ -2115,7 +2143,7 @@ HWTEST_F(WindowSceneSessionImplTest, DumpSessionElementInfo3, Function | SmallTe window->uiContent_ = std::make_unique(); ASSERT_EQ(WMError::WM_OK, window->NotifyMemoryLevel(2)); delete option; - ASSERT_EQ(WMError::WM_OK, window->Destroy(false)); + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false)); } /** @@ -2903,6 +2931,89 @@ HWTEST_F(WindowSceneSessionImplTest, SyncDestroyAndDisconnectSpecificSession, Fu GTEST_LOG_(INFO) << "WindowSessionImplTest: SetTitleButtonVisible03 end"; } +/** + * @tc.name: SetGrayScale01 + * @tc.desc: SetGrayScale + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest, SetGrayScale01, Function | SmallTest | Level3) +{ + sptr option = new (std::nothrow) WindowOption(); + ASSERT_NE(nullptr, option); + option->SetWindowMode(WindowMode::WINDOW_MODE_PIP); + sptr window = new (std::nothrow) WindowSceneSessionImpl(option); + ASSERT_NE(nullptr, window); + + constexpr float grayScale = 0.5f; + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetGrayScale(grayScale)); +} + +/** + * @tc.name: SetGrayScale02 + * @tc.desc: SetGrayScale + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest, SetGrayScale02, Function | SmallTest | Level3) +{ + sptr option = new (std::nothrow) WindowOption(); + ASSERT_NE(nullptr, option); + sptr window = new (std::nothrow) WindowSceneSessionImpl(option); + ASSERT_NE(nullptr, window); + + window->state_ = WindowState::STATE_SHOWN; + SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; + sptr session = new (std::nothrow) SessionMocker(sessionInfo); + ASSERT_NE(nullptr, session); + window->property_->SetPersistentId(1); + window->hostSession_ = session; + window->uiContent_ = std::make_unique(); + + std::vector types = { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowType::SYSTEM_WINDOW_BASE }; + for (WindowType type : types) { + window->SetWindowType(type); + float grayScale = -0.001f; + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetGrayScale(grayScale)); + grayScale = 1.001f; + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetGrayScale(grayScale)); + } +} + +/** + * @tc.name: SetGrayScale03 + * @tc.desc: SetGrayScale + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest, SetGrayScale03, Function | SmallTest | Level3) +{ + sptr option = new (std::nothrow) WindowOption(); + ASSERT_NE(nullptr, option); + sptr window = new (std::nothrow) WindowSceneSessionImpl(option); + ASSERT_NE(nullptr, window); + + window->state_ = WindowState::STATE_SHOWN; + SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; + sptr session = new (std::nothrow) SessionMocker(sessionInfo); + ASSERT_NE(nullptr, session); + window->property_->SetPersistentId(1); + window->hostSession_ = session; + window->uiContent_ = std::make_unique(); + + std::vector types = { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowType::SYSTEM_WINDOW_BASE }; + for (WindowType type : types) { + window->SetWindowType(type); + float grayScale = 0.0f; + ASSERT_EQ(WMError::WM_OK, window->SetGrayScale(grayScale)); + grayScale = 1.0f; + ASSERT_EQ(WMError::WM_OK, window->SetGrayScale(grayScale)); + grayScale = 0.5f; + ASSERT_EQ(WMError::WM_OK, window->SetGrayScale(grayScale)); + } +} + /** * @tc.name: TestGetUIContentWithId * @tc.desc: Get uicontent with id @@ -2928,6 +3039,83 @@ HWTEST_F(WindowSceneSessionImplTest, TestGetUIContentWithId, Function | SmallTes GTEST_LOG_(INFO) << "WindowSceneSessionImplTest: TestGetUIContentWithId end"; } +/** + * @tc.name: Test01 + * @tc.desc: Test01 + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest, Test01, Function | SmallTest | Level3) +{ + WindowLimits windowLimits = {3, 3, 3, 3, 2.0, 2.0}; + ASSERT_EQ(windowLimits.IsEmpty(), false); + Rect rect = {2, 2, 2, 2}; + Rect rect1 = {2, 2, 2, 2}; + ASSERT_EQ(rect.IsInsideOf(rect1), true); + TitleButtonRect titleButtonRect = {3, 3, 3, 3}; + TitleButtonRect titleButtonRect1 = {3, 3, 3, 3}; + ASSERT_EQ(titleButtonRect.IsUninitializedRect(), false); + ASSERT_EQ(titleButtonRect.IsInsideOf(titleButtonRect1), true); + AvoidArea avoidArea; + AvoidArea avoidArea1; + ASSERT_EQ((avoidArea != avoidArea1), false); +} + +/** + * @tc.name: RegisterSessionRecoverListenerInputMethodFloat + * @tc.desc: Register session recover listener + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest, RegisterSessionRecoverListenerInputMethodFloat, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "WindowSceneSessionImplTest: RegisterSessionRecoverListenerInputMethodFloat start"; + sptr option = new (std::nothrow) WindowOption(); + ASSERT_NE(nullptr, option); + sptr window = new WindowSceneSessionImpl(option); + ASSERT_NE(nullptr, window); + window->property_->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); + int ret = 0; + window->RegisterSessionRecoverListener(false); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: RegisterSessionRecoverListenerNonDefaultCollaboratorType + * @tc.desc: Register session recover listener + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest, RegisterSessionRecoverListenerNonDefaultCollaboratorType, + Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "WindowSceneSessionImplTest: RegisterSessionRecoverListenerNonDefaultCollaboratorType start"; + sptr option = new (std::nothrow) WindowOption(); + ASSERT_NE(nullptr, option); + sptr window = new WindowSceneSessionImpl(option); + ASSERT_NE(nullptr, window); + window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + window->property_->SetCollaboratorType(CollaboratorType::OTHERS_TYPE); + int ret = 0; + window->RegisterSessionRecoverListener(false); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: RegisterSessionRecoverListenerSuccess + * @tc.desc: Register session recover listener + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest, RegisterSessionRecoverListenerSuccess, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "WindowSceneSessionImplTest: RegisterSessionRecoverListenerSuccess start"; + sptr option = new (std::nothrow) WindowOption(); + ASSERT_NE(nullptr, option); + sptr window = new WindowSceneSessionImpl(option); + ASSERT_NE(nullptr, window); + window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + window->property_->SetCollaboratorType(CollaboratorType::DEFAULT_TYPE); + int ret = 0; + window->RegisterSessionRecoverListener(false); + ASSERT_EQ(ret, 0); +} } } // namespace Rosen } // namespace OHOS diff --git a/wm/test/unittest/window_session_impl_test.cpp b/wm/test/unittest/window_session_impl_test.cpp index cf0cf3b545..8e632d283e 100644 --- a/wm/test/unittest/window_session_impl_test.cpp +++ b/wm/test/unittest/window_session_impl_test.cpp @@ -1497,8 +1497,8 @@ HWTEST_F(WindowSessionImplTest, SetRaiseByClickEnabled01, Function | SmallTest | ASSERT_NE(nullptr, session); window->hostSession_ = session; window->state_ = WindowState::STATE_CREATED; - retCode = window->SetRaiseByClickEnabled(true); - ASSERT_EQ(retCode, WMError::WM_OK); + window->SetRaiseByClickEnabled(true); + ASSERT_NE(nullptr, session); } /** @@ -1974,6 +1974,270 @@ HWTEST_F(WindowSessionImplTest, GetCallingWindowWindowStatus, Function | SmallTe retCode = window->GetCallingWindowWindowStatus(windowStatus); ASSERT_NE(retCode, WMError::WM_OK); } + +/** + * @tc.name: GetParentId + * @tc.desc: GetParentId Test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest, GetParentId, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + sptr window = new WindowSessionImpl(option); + const int32_t res = window->GetParentId(); + ASSERT_EQ(res, 0); + ASSERT_EQ(true, window->IsSupportWideGamut()); +} + +/** + * @tc.name: PreNotifyKeyEvent + * @tc.desc: PreNotifyKeyEvent Test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest, PreNotifyKeyEvent, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + sptr window = new WindowSessionImpl(option); + std::shared_ptr pointerEvent; + window->ConsumePointerEvent(pointerEvent); + + std::shared_ptr keyEvent; + window->ConsumeKeyEvent(keyEvent); + ASSERT_EQ(false, window->PreNotifyKeyEvent(keyEvent)); + window->NotifyOnKeyPreImeEvent(keyEvent); + window->uiContent_ = nullptr; + ASSERT_EQ(false, window->NotifyOnKeyPreImeEvent(keyEvent)); +} + +/** + * @tc.name: UpdateRectForRotation + * @tc.desc: UpdateRectForRotation Test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest, UpdateRectForRotation, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowName("WindowSessionCreateCheck"); + sptr window = + new (std::nothrow) WindowSessionImpl(option); + ASSERT_NE(window, nullptr); + + Rect wmRect; + wmRect.posX_ = 0; + wmRect.posY_ = 0; + wmRect.height_ = 50; + wmRect.width_ = 50; + + WSRect rect; + wmRect.posX_ = 0; + wmRect.posY_ = 0; + wmRect.height_ = 50; + wmRect.width_ = 50; + + Rect preRect; + preRect.posX_ = 0; + preRect.posY_ = 0; + preRect.height_ = 200; + preRect.width_ = 200; + + window->property_->SetWindowRect(preRect); + WindowSizeChangeReason wmReason = WindowSizeChangeReason{0}; + std::shared_ptr rsTransaction; + window->UpdateRectForRotation(wmRect, preRect, wmReason, rsTransaction); + + SizeChangeReason reason = SizeChangeReason::UNDEFINED; + auto res = window->UpdateRect(rect, reason); + ASSERT_EQ(res, WSError::WS_OK); +} + +/** + * @tc.name: NotifyRotationAnimationEnd + * @tc.desc: NotifyRotationAnimationEnd Test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest, NotifyRotationAnimationEnd, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + sptr window = new WindowSessionImpl(option); + ASSERT_NE(window, nullptr); + window->NotifyRotationAnimationEnd(); +} + +/** + * @tc.name: SetTitleButtonVisible + * @tc.desc: SetTitleButtonVisible and GetTitleButtonVisible + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest, SetTitleButtonVisible, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + sptr window = new WindowSessionImpl(option); + ASSERT_NE(window, nullptr); + bool isMaximizeVisible = true; + bool isMinimizeVisible = true; + bool isSplitVisible = true; + auto res = window->SetTitleButtonVisible(isMaximizeVisible, isMinimizeVisible, + isSplitVisible); + + bool &hideMaximizeButton = isMaximizeVisible; + bool &hideMinimizeButton = isMinimizeVisible; + bool &hideSplitButton = isSplitVisible; + window->GetTitleButtonVisible(true, hideMaximizeButton, hideMinimizeButton, + hideSplitButton); + ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); +} + +/** + * @tc.name: IsFocused + * @tc.desc: IsFocused + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest, IsFocused, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowName("WindowSessionCreateCheck"); + sptr window = + new (std::nothrow) WindowSessionImpl(option); + ASSERT_NE(window, nullptr); + bool res = window->IsFocused(); + ASSERT_EQ(res, false); + + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->RequestFocus()); + SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", + "CreateTestAbility"}; + sptr session = new (std::nothrow) SessionMocker(sessionInfo); + ASSERT_NE(nullptr, session); + ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->RequestFocus()); +} + +/** + * @tc.name: NapiSetUIContent + * @tc.desc: NapiSetUIContent Test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest, NapiSetUIContent, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + ASSERT_NE(option, nullptr); + option->SetWindowName("NapiSetUIContent"); + option->SetExtensionTag(true); + sptr window = new (std::nothrow) WindowSessionImpl(option); + ASSERT_NE(window, nullptr); + window->property_->SetPersistentId(1); + std::string url = ""; + AppExecFwk::Ability* ability = nullptr; + + window->SetUIContentByName(url, nullptr, nullptr, nullptr); + window->SetUIContentByAbc(url, nullptr, nullptr, nullptr); + WMError res1 = window->NapiSetUIContent(url, nullptr, nullptr, true, nullptr, ability); + ASSERT_EQ(res1, WMError::WM_ERROR_INVALID_WINDOW); +} + +/** + * @tc.name: GetAbcContent + * @tc.desc: GetAbcContent Test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest, GetAbcContent, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + ASSERT_NE(option, nullptr); + option->SetWindowName("GetAbcContent"); + option->SetExtensionTag(true); + sptr window = new (std::nothrow) WindowSessionImpl(option); + ASSERT_NE(window, nullptr); + window->property_->SetPersistentId(1); + std::string url = ""; + WMError res = window->SetUIContentInner(url, nullptr, nullptr, WindowSetUIContentType::BY_ABC, nullptr); + ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); +} + +/** + * @tc.name: SetLandscapeMultiWindow + * @tc.desc: SetLandscapeMultiWindow and check the retCode + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest, SetLandscapeMultiWindow, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowName("SetLandscapeMultiWindow"); + sptr window = new(std::nothrow) WindowSessionImpl(option); + ASSERT_NE(nullptr, window); + WMError retCode = window->SetLandscapeMultiWindow(false); + ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW); + window->property_->SetPersistentId(1); + SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; + sptr session = new(std::nothrow) SessionMocker(sessionInfo); + ASSERT_NE(nullptr, session); + window->hostSession_ = session; + window->state_ = WindowState::STATE_CREATED; + retCode = window->SetLandscapeMultiWindow(false); + ASSERT_EQ(retCode, WMError::WM_OK); +} + +/** + * @tc.name: GetTouchable + * @tc.desc: GetTouchable + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest, GetTouchable, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + ASSERT_NE(option, nullptr); + option->SetWindowName("GetTouchable"); + sptr window = new (std::nothrow) WindowSessionImpl(option); + ASSERT_NE(window, nullptr); + window->GetTouchable(); + window->GetBrightness(); + ASSERT_NE(window, nullptr); +} + +/** + * @tc.name: Notify03 + * @tc.desc: NotifyCloseExistPipWindow NotifyAfterResumed NotifyAfterPaused + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest, Notify03, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowName("Notify03"); + sptr window = new WindowSessionImpl(option); + + SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", + "CreateTestAbility"}; + sptr session = new (std::nothrow) SessionMocker(sessionInfo); + ASSERT_NE(nullptr, session); + ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); + + window->NotifyAfterResumed(); + window->NotifyAfterPaused(); + WSError res = window->NotifyCloseExistPipWindow(); + ASSERT_EQ(res, WSError::WS_OK); + AAFwk::WantParams wantParams; + WSError ret = window->NotifyTransferComponentData(wantParams); + ASSERT_EQ(ret, WSError::WS_OK); +} + +/** + * @tc.name: Filter + * @tc.desc: Filter + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest, Filter, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + ASSERT_NE(option, nullptr); + option->SetWindowName("Filter"); + sptr window = new (std::nothrow) WindowSessionImpl(option); + ASSERT_NE(window, nullptr); + KeyEventFilterFunc filter; + window->SetKeyEventFilter(filter); + std::shared_ptr keyEvent = nullptr; + window->FilterKeyEvent(keyEvent); + auto ret = window->ClearKeyEventFilter(); + ASSERT_EQ(ret, WMError::WM_OK); +} } } // namespace Rosen } // namespace OHOS diff --git a/wm/test/unittest/window_test.cpp b/wm/test/unittest/window_test.cpp index 52f1b5ee64..a5dcb26981 100644 --- a/wm/test/unittest/window_test.cpp +++ b/wm/test/unittest/window_test.cpp @@ -2336,6 +2336,36 @@ HWTEST_F(WindowTest, UnregisterWindowRectChangeListener, Function | SmallTest | ASSERT_EQ(WMError::WM_OK, window->Destroy()); } +/** + * @tc.name: RegisterKeyboardPanelInfoChangeListener + * @tc.desc: get + * @tc.type: FUNC + */ +HWTEST_F(WindowTest, RegisterKeyboardPanelInfoChangeListener, Function | SmallTest | Level2) +{ + sptr window = new Window(); + ASSERT_NE(nullptr, window); + sptr listener = nullptr; + auto ret = window->RegisterKeyboardPanelInfoChangeListener(listener); + ASSERT_EQ(WMError::WM_OK, ret); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: UnregisterKeyboardPanelInfoChangeListener + * @tc.desc: get + * @tc.type: FUNC + */ +HWTEST_F(WindowTest, UnregisterKeyboardPanelInfoChangeListener, Function | SmallTest | Level2) +{ + sptr window = new Window(); + ASSERT_NE(nullptr, window); + sptr listener = nullptr; + auto ret = window->UnregisterKeyboardPanelInfoChangeListener(listener); + ASSERT_EQ(WMError::WM_OK, ret); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + /** * @tc.name: GetTopWindowWithContext * @tc.desc: get @@ -2404,6 +2434,159 @@ HWTEST_F(WindowTest, GetMainWindowWithContext, Function | SmallTest | Level2) window->UpdateConfigurationForAll(configuration); ASSERT_EQ(nullptr, ret); } + +/** + * @tc.name: SetTopmost|GetWIsTopmostindowWithId + * @tc.desc: get + * @tc.type: FUNC + */ +HWTEST_F(WindowTest, SetTopmost, Function | SmallTest | Level2) +{ + sptr window = new Window(); + ASSERT_NE(nullptr, window); + auto ret = window->SetTopmost(false); + ASSERT_EQ(WMError::WM_OK, ret); + ASSERT_EQ(false, window->IsTopmost()); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: SetUIContentByName + * @tc.desc: get + * @tc.type: FUNC + */ +HWTEST_F(WindowTest, SetUIContentByName, Function | SmallTest | Level2) +{ + sptr window = new Window(); + ASSERT_NE(nullptr, window); + napi_env env = nullptr; + napi_value storage = nullptr; + auto ret = window->SetUIContentByName("/system/etc/window/resources/test.abc", env, storage); + ASSERT_EQ(WMError::WM_OK, ret); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: TriggerBindModalUIExtension + * @tc.desc: get + * @tc.type: FUNC + */ +HWTEST_F(WindowTest, TriggerBindModalUIExtension, Function | SmallTest | Level2) +{ + sptr winOption = nullptr; + winOption = new(std::nothrow) OHOS::Rosen::WindowOption(); + ASSERT_NE(nullptr, winOption); + winOption->SetWindowType(OHOS::Rosen::WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); + sptr option = new WindowOption(); + sptr window = Window::Create("TriggerBindModalUIExtension", option); + if (window != nullptr) { + ASSERT_NE(nullptr, window); + window->TriggerBindModalUIExtension(); + } + sptr window_ = new Window(); + ASSERT_NE(nullptr, window_); + window_->PerformBack(); +} + +/** + * @tc.name: RegisterTransferComponentDataForResultListener + * @tc.desc: get + * @tc.type: FUNC + */ +HWTEST_F(WindowTest, RegisterTransferComponentDataForResultListener, Function | SmallTest | Level2) +{ + sptr window = new Window(); + ASSERT_NE(nullptr, window); + NotifyTransferComponentDataForResultFunc func; + auto ret = true; + window->RegisterTransferComponentDataForResultListener(func); + ASSERT_EQ(true, ret); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: SetTextFieldAvoidInfo|KeepKeyboardOnFocus + * @tc.desc: get + * @tc.type: FUNC + */ +HWTEST_F(WindowTest, SetTextFieldAvoidInfo, Function | SmallTest | Level2) +{ + sptr window = new Window(); + ASSERT_NE(nullptr, window); + auto ret = window->SetTextFieldAvoidInfo(50.0, 100.0); + ASSERT_EQ(WMError::WM_OK, ret); + auto retur = window->KeepKeyboardOnFocus(false); + ASSERT_EQ(WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT, retur); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: Test01 + * @tc.desc: Test01 + * @tc.type: FUNC + */ +HWTEST_F(WindowTest, Test01, Function | SmallTest | Level2) +{ + sptr window = new Window(); + ASSERT_NE(nullptr, window); + SystemBarProperty prop; + ASSERT_EQ(WMError::WM_OK, window->SetSpecificBarProperty(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, prop)); + ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetDecorVisible(true)); + ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetTitleButtonVisible(true, true, true)); + auto var = 5; + ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetDecorHeight(var)); + ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->GetDecorHeight(var)); + ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->ClearKeyEventFilter()); + IWindowVisibilityChangedListener windowVisibilityChangedListener; + windowVisibilityChangedListener.OnWindowVisibilityChangedCallback(false); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: Test02 + * @tc.desc: Test02 + * @tc.type: FUNC + */ +HWTEST_F(WindowTest, Test02, Function | SmallTest | Level2) +{ + sptr window = new Window(); + ASSERT_NE(nullptr, window); + IWindowLifeCycle windowLifeCycle; + windowLifeCycle.AfterResumed(); + windowLifeCycle.AfterPaused(); + windowLifeCycle.AfterDestroyed(); + IWindowStatusChangeListener windowStatusChangeListener; + windowStatusChangeListener.OnWindowStatusChange(WindowStatus::WINDOW_STATUS_UNDEFINED); + ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetDefaultDensityEnabled(true)); + ASSERT_EQ(false, window->GetDefaultDensityEnabled()); + Rect rect_ = {0, 0, 0, 0}; + window->UpdatePiPRect(rect_, WindowSizeChangeReason::UNDEFINED); + IWindowRectChangeListener windowRectChangeListener; + windowRectChangeListener.OnRectChange(rect_, WindowSizeChangeReason::UNDEFINED); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: Test03 + * @tc.desc: Test03 + * @tc.type: FUNC + */ +HWTEST_F(WindowTest, Test03, Function | SmallTest | Level2) +{ + sptr window = new Window(); + ASSERT_NE(nullptr, window); + KeyEventFilterFunc keyEventFilterFunc; + ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetKeyEventFilter(keyEventFilterFunc)); + IWindowNoInteractionListener windowNoInteractionListener; + windowNoInteractionListener.OnWindowNoInteractionCallback(); + windowNoInteractionListener.SetTimeout(100); + ASSERT_EQ(0, windowNoInteractionListener.GetTimeout()); + TitleButtonRect titleButtonRect = {3, 3, 3, 3}; + ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->GetTitleButtonArea(titleButtonRect)); + IWindowTitleButtonRectChangedListener windowTitleButtonRectChangedListener; + windowTitleButtonRectChangedListener.OnWindowTitleButtonRectChanged(titleButtonRect); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} } } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 176ceff067..b39caedfb8 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -64,7 +64,7 @@ config("libmockwms_config") { # for scene session manager "${window_base_path}/interfaces/innerkits/wm", "${window_base_path}/wmserver/include", - "${graphic_base_path}/graphic_2d/rosen/modules/platform/image_native", + "../../../graphic/graphic_2d/rosen/modules/platform/image_native", # for window_manager_hilog "${window_base_path}/utils/include", @@ -79,6 +79,7 @@ ohos_shared_library("sms") { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } sources = [ @@ -142,6 +143,7 @@ if (scene_board_enabled) { sanitize = { cfi = true cfi_cross_dso = true + cfi_vcal_icall_only = true debug = false } defines = [] @@ -226,8 +228,8 @@ if (scene_board_enabled) { ] if (defined(global_parts_info) && - defined(global_parts_info.resourceschedule_memmgr_plugin)) { - external_deps += [ "memmgr_plugin:memmgrclient" ] + defined(global_parts_info.resourceschedule_memmgr_override)) { + external_deps += [ "memmgr_override:memmgrclient" ] defines += [ "MEMMGR_WINDOW_ENABLE" ] } diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index d9c9299a9b..d4d1bad49b 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -196,11 +196,8 @@ public: { return WSError::WS_OK; } - virtual WSError AddOrRemoveSecureExtSession(int32_t persistentId, int32_t parentId, bool shouldHide) - { - return WSError::WS_OK; - } - virtual WSError UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags) + virtual WSError UpdateExtWindowFlags(int32_t parentId, int32_t persistentId, uint32_t extWindowFlags, + uint32_t extWindowActions) { return WSError::WS_OK; } diff --git a/wmserver/src/zidl/window_manager_proxy.cpp b/wmserver/src/zidl/window_manager_proxy.cpp index b9eaca2068..49da611c08 100644 --- a/wmserver/src/zidl/window_manager_proxy.cpp +++ b/wmserver/src/zidl/window_manager_proxy.cpp @@ -500,7 +500,8 @@ WMError WindowManagerProxy::SetWindowGravity(uint32_t windowId, WindowGravity gr return static_cast(ret); } -WMError WindowManagerProxy::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) +__attribute__((no_sanitize("cfi"))) WMError WindowManagerProxy::GetTopWindowId( + uint32_t mainWinId, uint32_t& topWinId) { MessageParcel data; MessageParcel reply;