diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 2bcd9bd367b94899d4ca3a773bb24eec4fc1ee89..238a270ed7dea3d395c2b70e2b0ee1a6cfd65e11 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -1476,6 +1476,7 @@ DMError ScreenManagerAdapter::SetVirtualScreenFlag(ScreenId screenId, VirtualScr if (screenFlag < VirtualScreenFlag::DEFAULT || screenFlag >= VirtualScreenFlag::MAX) { return DMError::DM_ERROR_INVALID_PARAM; } + TLOGI(WmsLogTag::DMS, "VirtualScreenFlag:%{public}d", screenFlag); if (screenSessionManagerServiceProxy_) { return screenSessionManagerServiceProxy_->SetVirtualScreenFlag(screenId, screenFlag); } diff --git a/dm/test/unittest/BUILD.gn b/dm/test/unittest/BUILD.gn index 42c2cb11e2354b531ac0d533965cf3e0417d9a97..3564be31f9de22abb5cc0501ded1ecfb9f2e54ee 100644 --- a/dm/test/unittest/BUILD.gn +++ b/dm/test/unittest/BUILD.gn @@ -223,6 +223,7 @@ ohos_unittest("dm_oh_display_manager_test") { deps = [ ":dm_unittest_common", "${window_base_path}/dm:libdm_ndk", + "${window_base_path}/window_scene/interfaces/innerkits:libwsutils" ] external_deps = [ diff --git a/dm/test/unittest/display_manager_adapter_test.cpp b/dm/test/unittest/display_manager_adapter_test.cpp index e921ae480a43ed289ed02363fb841ad623daf053..0f1ceb3ea32a2413e465447cfdf2f76d037cf007 100644 --- a/dm/test/unittest/display_manager_adapter_test.cpp +++ b/dm/test/unittest/display_manager_adapter_test.cpp @@ -926,6 +926,9 @@ HWTEST_F(DisplayManagerAdapterTest, GetDisplayHDRSnapshot001, TestSize.Level1) */ HWTEST_F(DisplayManagerAdapterTest, SetVirtualScreenAutoRotation, TestSize.Level1) { + if (!SceneBoardJudgement::IsSceneBoardEnabled()) { + return; + } ScreenId screenId = 1111; bool enable = false; DMError err = SingletonContainer::Get().SetVirtualScreenAutoRotation(screenId, enable); @@ -939,6 +942,9 @@ HWTEST_F(DisplayManagerAdapterTest, SetVirtualScreenAutoRotation, TestSize.Level */ HWTEST_F(DisplayManagerAdapterTest, SetScreenPrivacyWindowTagSwitch, TestSize.Level1) { + if (!SceneBoardJudgement::IsSceneBoardEnabled()) { + return; + } ScreenId screenId = 0; std::vector privacyWindowTag{"test1", "test2"}; DMError res = SingletonContainer::Get().SetScreenPrivacyWindowTagSwitch(screenId, diff --git a/dm/test/unittest/display_manager_test.cpp b/dm/test/unittest/display_manager_test.cpp index d9caf6b8c0e09020a7cc2f00cd0c27484ee2f0a1..f6d45428e052ce6cbea28e84bfd90d61af5398d2 100644 --- a/dm/test/unittest/display_manager_test.cpp +++ b/dm/test/unittest/display_manager_test.cpp @@ -1765,8 +1765,6 @@ HWTEST_F(DisplayManagerTest, GetCutoutInfoWithRotation, Function | SmallTest | L sptr info = DisplayManager::GetInstance().GetCutoutInfoWithRotation(rotation); if (SceneBoardJudgement::IsSceneBoardEnabled()) { ASSERT_NE(nullptr, info); - } else { - ASSERT_EQ(nullptr, info); } } @@ -2366,6 +2364,9 @@ HWTEST_F(DisplayManagerTest, GetScreenHDRshotWithOption_ShouldReturnNull_WhenGet */ HWTEST_F(DisplayManagerTest, GetScreenHDRshotWithOption_WhenDisplayIdIsValidButSnapshotFails, TestSize.Level1) { + if (!SceneBoardJudgement::IsSceneBoardEnabled()) { + return; + } CaptureOption captureOption; captureOption.displayId_ = DEFAULT_DISPLAY; DmErrorCode errorCode; diff --git a/dm/test/unittest/display_test.cpp b/dm/test/unittest/display_test.cpp index a554998ed6af2357d7436cb970756d9d887cdfee..67a2781ee8a0b5118ea1c913522e57de9dacd7bd 100644 --- a/dm/test/unittest/display_test.cpp +++ b/dm/test/unittest/display_test.cpp @@ -288,6 +288,9 @@ HWTEST_F(DisplayTest, GetDisplayInfoWithCache01, TestSize.Level1) */ HWTEST_F(DisplayTest, GetLiveCreaseRegion, TestSize.Level1) { + if (!SceneBoardJudgement::IsSceneBoardEnabled()) { + return; + } sptr baseInfo = sptr::MakeSptr(); sptr disPlay = sptr::MakeSptr("", baseInfo); FoldCreaseRegion region; @@ -315,6 +318,9 @@ HWTEST_F(DisplayTest, GetLiveCreaseRegion, TestSize.Level1) */ HWTEST_F(DisplayTest, GetOriginRotation, TestSize.Level1) { + if (!SceneBoardJudgement::IsSceneBoardEnabled()) { + return; + } auto baseInfo = defaultDisplay_->GetDisplayInfo(); Rotation rotation = Rotation::ROTATION_90; baseInfo->SetOriginRotation(rotation); diff --git a/dm/test/unittest/oh_display_manager_test.cpp b/dm/test/unittest/oh_display_manager_test.cpp index 49847f333fb55a15d2ac4c224fdee5e73abb8f74..7ad76d502dd550067ea1f28b44816aa16167103f 100644 --- a/dm/test/unittest/oh_display_manager_test.cpp +++ b/dm/test/unittest/oh_display_manager_test.cpp @@ -20,6 +20,7 @@ #include "oh_display_manager.h" #include "oh_display_manager_inner.h" #include "pixelmap_native_impl.h" +#include "scene_board_judgement.h" using namespace testing; using namespace testing::ext; @@ -564,6 +565,9 @@ HWTEST_F(OHDisplayManagerTest, DisplayRemoveListener, TestSize.Level1) */ HWTEST_F(OHDisplayManagerTest, DisplayRemoveListener02, TestSize.Level1) { + if (!SceneBoardJudgement::IsSceneBoardEnabled()) { + return; + } uint32_t* testIndex = nullptr; NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_RegisterDisplayRemoveListener( DisplayRemoveCallback, testIndex); @@ -596,6 +600,9 @@ HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_CreateAvailableArea01, Te */ HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_CreateAvailableArea02, TestSize.Level1) { + if (!SceneBoardJudgement::IsSceneBoardEnabled()) { + return; + } uint64_t testId = 0; NativeDisplayManager_Rect *availableArea = nullptr; NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_CreateAvailableArea(testId, &availableArea); @@ -764,6 +771,9 @@ HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDisplayPosition05, Tes */ HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDisplayPosition06, TestSize.Level1) { + if (!SceneBoardJudgement::IsSceneBoardEnabled()) { + return; + } uint64_t testId = 2; // 异常屏幕 int32_t x = -1; int32_t y = -1; diff --git a/dm/test/unittest/screen_test.cpp b/dm/test/unittest/screen_test.cpp index b30d78970c76533aeae8e270b88b4e1f2e74127f..d761e970bb9e68b518e8476c6530b306193fd0af 100644 --- a/dm/test/unittest/screen_test.cpp +++ b/dm/test/unittest/screen_test.cpp @@ -39,26 +39,22 @@ public: virtual void SetUp() override; virtual void TearDown() override; - static sptr defaultDisplay_; static ScreenId defaultScreenId_; static sptr screen_; }; -sptr ScreenTest::defaultDisplay_ = nullptr; ScreenId ScreenTest::defaultScreenId_ = SCREEN_ID_INVALID; sptr ScreenTest::screen_ = nullptr; bool g_isPcDevice = ScreenSceneConfig::GetExternalScreenDefaultMode() == "none"; void ScreenTest::SetUpTestCase() { - defaultDisplay_ = DisplayManager::GetInstance().GetDefaultDisplay(); - defaultScreenId_ = static_cast(defaultDisplay_->GetId()); + defaultScreenId_ = DisplayManager::GetInstance().GetDefaultDisplayId(); screen_ = ScreenManager::GetInstance().GetScreenById(defaultScreenId_); usleep(SLEEP_TIME_IN_US); } void ScreenTest::TearDownTestCase() { - defaultDisplay_ = nullptr; screen_ = nullptr; } diff --git a/dmserver/include/display_manager_interface_code.h b/dmserver/include/display_manager_interface_code.h index 3b4839453603e42b055369d81c7f1898752eb879..32ab3fe5a2e4cd156af2137dd81a90a10a38bee1 100644 --- a/dmserver/include/display_manager_interface_code.h +++ b/dmserver/include/display_manager_interface_code.h @@ -181,6 +181,7 @@ enum class DisplayManagerMessage : unsigned int { TRANS_ID_SET_SCREEN_PRIVACY_WINDOW_TAG_SWITCH, TRANS_ID_SYNCHRONIZED_POWER_STATUS, TRANS_ID_NOTIFY_SCREEN_CONNECT_COMPLETION, + TRANS_ID_NOTIFY_SWITCH_USER_ANIMATION_FINISH, }; } #endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_INTERFACE_CODE_H diff --git a/extension/window_extension/BUILD.gn b/extension/window_extension/BUILD.gn index 842c4af4ebd79935d4bfed2acceac0e168006491..15b7623750807b301d196d64342357b80182b9ec 100644 --- a/extension/window_extension/BUILD.gn +++ b/extension/window_extension/BUILD.gn @@ -67,6 +67,7 @@ ohos_shared_library("libwindow_extension") { "ability_runtime:ability_context_native", "ability_runtime:ability_manager", "ability_runtime:ability_start_options", + "ability_runtime:abilitykit_utils", "ability_runtime:app_context", "ability_runtime:extensionkit_native", "ability_runtime:napi_common", diff --git a/interfaces/innerkits/dm/dm_common.h b/interfaces/innerkits/dm/dm_common.h index 806b70038a24cce79faf5dec6ee851dfa0ed74af..1137cadb88ef603560212beb970e56dd998e191b 100644 --- a/interfaces/innerkits/dm/dm_common.h +++ b/interfaces/innerkits/dm/dm_common.h @@ -43,6 +43,14 @@ constexpr int DOT_PER_INCH_MAXIMUM_VALUE = 1000; constexpr int DOT_PER_INCH_MINIMUM_VALUE = 80; constexpr uint32_t BASELINE_DENSITY = 160; constexpr uint32_t HALF_SCREEN_PARAM = 2; +const std::string DM_ERROR_MSG_NOT_SUPPORT_COOR_WHEN_WIRED_CASTING = + "[wired casting]not support coordination when wired casting."; +const std::string DM_ERROR_MSG_NOT_SUPPORT_COOR_WHEN_WIRLESS_CASTING = + "[wireless casting]not support coordination when wireless casting."; +const std::string DM_ERROR_MSG_NOT_SUPPORT_COOR_WHEN_RECORDING = + "[recording]not support coordination when wired recording."; +const std::string DM_ERROR_MSG_NOT_SUPPORT_COOR_WHEN_TENTMODE = + "[tentmode]not support coordination when tentmode."; } /** @@ -189,6 +197,7 @@ enum class DisplayEvent : uint32_t { * @brief Enumerates DMError. */ enum class DMError : int32_t { + DM_ERROR_UNKNOWN = -1, DM_OK = 0, DM_ERROR_INIT_DMS_PROXY_LOCKED = 100, DM_ERROR_IPC_FAILED = 101, @@ -205,7 +214,10 @@ enum class DMError : int32_t { DM_ERROR_INVALID_PERMISSION = 201, DM_ERROR_NOT_SYSTEM_APP = 202, DM_ERROR_DEVICE_NOT_SUPPORT = 801, - DM_ERROR_UNKNOWN = -1, + DM_ERROR_NOT_SUPPORT_COOR_WHEN_WIRED_CASTING = 100001, + DM_ERROR_NOT_SUPPORT_COOR_WHEN_WIRLESS_CASTING = 100002, + DM_ERROR_NOT_SUPPORT_COOR_WHEN_RECORDING = 100003, + DM_ERROR_NOT_SUPPORT_COOR_WHEN_TENTMODE = 100004, DM_ERROR_ILLEGAL_PARAM = 1400004, }; @@ -228,24 +240,35 @@ enum class DmErrorCode : int32_t { * @brief Constructs the mapping of the DM errors to the DM error codes. */ const std::map DM_JS_TO_ERROR_CODE_MAP { - {DMError::DM_OK, DmErrorCode::DM_OK }, - {DMError::DM_ERROR_INVALID_PERMISSION, DmErrorCode::DM_ERROR_NO_PERMISSION }, - {DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, - {DMError::DM_ERROR_IPC_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, - {DMError::DM_ERROR_REMOTE_CREATE_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, - {DMError::DM_ERROR_NULLPTR, DmErrorCode::DM_ERROR_INVALID_SCREEN }, - {DMError::DM_ERROR_INVALID_PARAM, DmErrorCode::DM_ERROR_INVALID_PARAM }, - {DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, - {DMError::DM_ERROR_DEATH_RECIPIENT, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, - {DMError::DM_ERROR_INVALID_MODE_ID, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, - {DMError::DM_ERROR_WRITE_DATA_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, - {DMError::DM_ERROR_RENDER_SERVICE_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, - {DMError::DM_ERROR_UNREGISTER_AGENT_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, - {DMError::DM_ERROR_INVALID_CALLING, DmErrorCode::DM_ERROR_INVALID_CALLING }, - {DMError::DM_ERROR_NOT_SYSTEM_APP, DmErrorCode::DM_ERROR_NOT_SYSTEM_APP }, - {DMError::DM_ERROR_UNKNOWN, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, - {DMError::DM_ERROR_DEVICE_NOT_SUPPORT, DmErrorCode::DM_ERROR_DEVICE_NOT_SUPPORT }, - {DMError::DM_ERROR_ILLEGAL_PARAM, DmErrorCode::DM_ERROR_ILLEGAL_PARAM }, + {DMError::DM_OK, DmErrorCode::DM_OK }, + {DMError::DM_ERROR_INVALID_PERMISSION, DmErrorCode::DM_ERROR_NO_PERMISSION }, + {DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, + {DMError::DM_ERROR_IPC_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, + {DMError::DM_ERROR_REMOTE_CREATE_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, + {DMError::DM_ERROR_NULLPTR, DmErrorCode::DM_ERROR_INVALID_SCREEN }, + {DMError::DM_ERROR_INVALID_PARAM, DmErrorCode::DM_ERROR_INVALID_PARAM }, + {DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, + {DMError::DM_ERROR_DEATH_RECIPIENT, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, + {DMError::DM_ERROR_INVALID_MODE_ID, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, + {DMError::DM_ERROR_WRITE_DATA_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, + {DMError::DM_ERROR_RENDER_SERVICE_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, + {DMError::DM_ERROR_UNREGISTER_AGENT_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, + {DMError::DM_ERROR_INVALID_CALLING, DmErrorCode::DM_ERROR_INVALID_CALLING }, + {DMError::DM_ERROR_NOT_SYSTEM_APP, DmErrorCode::DM_ERROR_NOT_SYSTEM_APP }, + {DMError::DM_ERROR_UNKNOWN, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, + {DMError::DM_ERROR_DEVICE_NOT_SUPPORT, DmErrorCode::DM_ERROR_DEVICE_NOT_SUPPORT }, + {DMError::DM_ERROR_ILLEGAL_PARAM, DmErrorCode::DM_ERROR_ILLEGAL_PARAM }, + {DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_WIRED_CASTING, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, + {DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_WIRLESS_CASTING, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, + {DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_RECORDING, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, + {DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_TENTMODE, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, +}; + +const std::map DM_ERROR_JS_TO_ERROR_MESSAGE_MAP { + {DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_WIRED_CASTING, DM_ERROR_MSG_NOT_SUPPORT_COOR_WHEN_WIRED_CASTING }, + {DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_WIRLESS_CASTING, DM_ERROR_MSG_NOT_SUPPORT_COOR_WHEN_WIRLESS_CASTING }, + {DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_RECORDING, DM_ERROR_MSG_NOT_SUPPORT_COOR_WHEN_RECORDING }, + {DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_TENTMODE, DM_ERROR_MSG_NOT_SUPPORT_COOR_WHEN_TENTMODE }, }; using DisplayStateCallback = std::function; @@ -685,6 +708,7 @@ struct SessionOption { bool isExtend_; std::string innerName_; ScreenId screenId_; + std::unordered_map rotationCorrectionMap_; }; /** diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index fe67e9d0fde8c2aff74e318ffd33cbf1b06d9ca0..478e0d23d648b1c7a119e4bf1f846d931369f5f1 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -876,7 +876,8 @@ public: */ static sptr Create(const std::string& windowName, sptr& option, const std::shared_ptr& context = nullptr, - WMError& errCode = DefaultCreateErrCode); + WMError& errCode = DefaultCreateErrCode, + const std::shared_ptr& rsUiContext = nullptr); /** * @brief create main/uiextension window with session @@ -1570,8 +1571,7 @@ public: * @param height * @return WMError */ - virtual WMError ResizeAsync(uint32_t width, uint32_t height, - const RectAnimationConfig& rectAnimationConfig = {}) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } + virtual WMError ResizeAsync(uint32_t width, uint32_t height) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } /** * @brief set the window gravity @@ -2868,7 +2868,7 @@ public: * * @return True means pcAppInpad and pad window., false means the opposite. */ - virtual bool IsPadAndNotFreeMutiWindowCompatibleMode() const { return false; } + virtual bool IsPadAndNotFreeMultiWindowCompatibleMode() const { return false; } /** * @brief Judge whether SceneBoard is enabled. diff --git a/interfaces/innerkits/wm/window_manager.h b/interfaces/innerkits/wm/window_manager.h index 1db684ff1f220748ce05812d5b205d2551d5fcca..9e9713ffedf85c1522988512b90d65909207bda5 100644 --- a/interfaces/innerkits/wm/window_manager.h +++ b/interfaces/innerkits/wm/window_manager.h @@ -345,6 +345,7 @@ public: float scaleX_; float scaleY_; bool isCompatScaleMode_ { false }; + Rect scaleRect_; std::string bundleName_; std::vector touchHotAreas_; }; @@ -365,6 +366,7 @@ struct AppUseControlInfo : public Parcelable { { return parcel.WriteString(bundleName_) && parcel.WriteInt32(appIndex_) && + parcel.WriteInt32(persistentId_) && parcel.WriteBool(isNeedControl_) && parcel.WriteBool(isControlRecentOnly_); } @@ -380,6 +382,7 @@ struct AppUseControlInfo : public Parcelable { auto info = new AppUseControlInfo(); if (!parcel.ReadString(info->bundleName_) || !parcel.ReadInt32(info->appIndex_) || + !parcel.ReadInt32(info->persistentId_) || !parcel.ReadBool(info->isNeedControl_) || !parcel.ReadBool(info->isControlRecentOnly_)) { delete info; @@ -390,6 +393,7 @@ struct AppUseControlInfo : public Parcelable { std::string bundleName_ = ""; int32_t appIndex_ = 0; + int32_t persistentId_ = INVALID_WINDOW_ID; // greater than 0 means control by id bool isNeedControl_ = false; bool isControlRecentOnly_ = false; }; diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 230dd9c0eed4bd80286d5a5b31abcbe94c98abc1..0e344de1817067dfe914b267d15fe7fd05528ac1 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -165,6 +165,7 @@ enum class WindowType : uint32_t { SYSTEM_SUB_WINDOW_BASE = 2500, WINDOW_TYPE_SYSTEM_SUB_WINDOW = SYSTEM_SUB_WINDOW_BASE, + WINDOW_TYPE_SCB_SUB_WINDOW, SYSTEM_SUB_WINDOW_END, SYSTEM_WINDOW_END = SYSTEM_SUB_WINDOW_END, @@ -438,6 +439,7 @@ enum class ControlAppType : uint8_t { CONTROL_APP_TYPE_BEGIN = 0, APP_LOCK = 1, PARENT_CONTROL, + DLP, PRIVACY_WINDOW, CONTROL_APP_TYPE_END, }; @@ -2862,6 +2864,35 @@ struct ShadowsInfo : public Parcelable { } }; +/** + * @struct MissionInfo + * + * @brief infos of mission + */ +struct MissionInfo : public Parcelable { + bool startupInvisibility_ = false; + + MissionInfo() {} + MissionInfo(bool startupInvisibility) : startupInvisibility_(startupInvisibility) {} + + bool Marshalling(Parcel& parcel) const override + { + if (!parcel.WriteBool(startupInvisibility_)) { + return false; + } + return true; + } + + static MissionInfo* Unmarshalling(Parcel& parcel) + { + auto missionInfo = std::make_unique(); + if (!missionInfo || !parcel.ReadBool(missionInfo->startupInvisibility_)) { + return nullptr; + } + return missionInfo.release(); + } +}; + /** * @brief Enumerates session state of recent session */ diff --git a/interfaces/kits/ani/display_runtime/BUILD.gn b/interfaces/kits/ani/display_runtime/BUILD.gn index 1c6f20ff69597e8320c097f9f989242c8f9f60fb..087926c9ee18f6b705c15b0d34a0625be11abfa8 100644 --- a/interfaces/kits/ani/display_runtime/BUILD.gn +++ b/interfaces/kits/ani/display_runtime/BUILD.gn @@ -71,6 +71,7 @@ ohos_shared_library("displayani_kit") { "eventhandler:libeventhandler", "hilog:libhilog", "hitrace:hitrace_meter", + "ipc:ipc_single", "runtime_core:ani", ] diff --git a/interfaces/kits/ani/display_runtime/display_ani/include/display_ani_listener.h b/interfaces/kits/ani/display_runtime/display_ani/include/display_ani_listener.h index e73c497d89a19d82fc59b0194cf4b8eb4fbf6c79..9950e18bd4dea0205bf9790ff23acc08925e9eec 100644 --- a/interfaces/kits/ani/display_runtime/display_ani/include/display_ani_listener.h +++ b/interfaces/kits/ani/display_runtime/display_ani/include/display_ani_listener.h @@ -17,11 +17,12 @@ #define OHOS_ANI_DISPLAY_LISTENER_H #include -#include "dm_common.h" -#include "refbase.h" -#include "display_manager.h" + #include "ani.h" +#include "display_manager.h" +#include "dm_common.h" #include "event_handler.h" +#include "refbase.h" namespace OHOS { namespace Rosen { diff --git a/interfaces/kits/ani/display_runtime/display_ani/include/display_ani_utils.h b/interfaces/kits/ani/display_runtime/display_ani/include/display_ani_utils.h index 23845605e849ee1247284224f17fd4ee6c6b89bd..b2ccbb4374e38295e06d64c09dd5280c9baced65 100644 --- a/interfaces/kits/ani/display_runtime/display_ani/include/display_ani_utils.h +++ b/interfaces/kits/ani/display_runtime/display_ani/include/display_ani_utils.h @@ -14,15 +14,16 @@ */ #ifndef OHOS_ANI_DISPLAY_UTILS_H #define OHOS_ANI_DISPLAY_UTILS_H + #include #include "ani.h" +#include "dm_common.h" #include "display_ani.h" -#include "singleton_container.h" #include "display_manager.h" -#include "window_manager_hilog.h" -#include "dm_common.h" #include "refbase.h" +#include "singleton_container.h" +#include "window_manager_hilog.h" namespace OHOS { namespace Rosen { diff --git a/interfaces/kits/ani/display_runtime/display_ani/src/ani_err_utils.cpp b/interfaces/kits/ani/display_runtime/display_ani/src/ani_err_utils.cpp index e60d854ce25cab3434d529037d9bb95a3981feda..f9aa1f2cbd2b477acbcca253dcee6a5013e3ae0d 100644 --- a/interfaces/kits/ani/display_runtime/display_ani/src/ani_err_utils.cpp +++ b/interfaces/kits/ani/display_runtime/display_ani/src/ani_err_utils.cpp @@ -14,10 +14,12 @@ */ #include "ani_err_utils.h" + +#include + #include "display_ani_utils.h" #include "window_manager_hilog.h" -#include namespace OHOS::Rosen { diff --git a/interfaces/kits/ani/display_runtime/display_ani/src/display_ani.cpp b/interfaces/kits/ani/display_runtime/display_ani/src/display_ani.cpp index 456b8218f941302ef96320719d03a70941bad304..1cf4433bfaa810190ed12a2c442d5f3268f0ece2 100644 --- a/interfaces/kits/ani/display_runtime/display_ani/src/display_ani.cpp +++ b/interfaces/kits/ani/display_runtime/display_ani/src/display_ani.cpp @@ -12,20 +12,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#include "display_ani.h" + #include #include "ani.h" -#include "display_ani.h" -#include "display_info.h" +#include "ani_err_utils.h" #include "display.h" -#include "singleton_container.h" +#include "display_ani_manager.h" +#include "display_ani_utils.h" +#include "display_info.h" #include "display_manager.h" -#include "window_manager_hilog.h" #include "dm_common.h" -#include "display_ani_utils.h" #include "refbase.h" -#include "display_ani_manager.h" -#include "ani_err_utils.h" +#include "singleton_container.h" +#include "window_manager_hilog.h" namespace OHOS { namespace Rosen { diff --git a/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_listener.cpp b/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_listener.cpp index b4124193318a72787c97f234a299eb3550cff6d6..979f667b9ef36111cac20b79deffb6d4bd7f5b1b 100644 --- a/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_listener.cpp +++ b/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_listener.cpp @@ -14,8 +14,9 @@ */ #include "display_ani_listener.h" -#include "window_manager_hilog.h" + #include "display_ani_utils.h" +#include "window_manager_hilog.h" namespace OHOS { namespace Rosen { diff --git a/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_manager.cpp b/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_manager.cpp index b8861d5902a5b1c120ac09621e78451a8ffeddb0..28b2a501932127e56a6e1d4183d68742796b8b24 100644 --- a/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_manager.cpp +++ b/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_manager.cpp @@ -12,22 +12,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include + +#include "display_ani_manager.h" + #include +#include #include "ani.h" -#include "display_ani_listener.h" +#include "ani_err_utils.h" +#include "display.h" #include "display_ani.h" -#include "display_ani_manager.h" +#include "display_ani_listener.h" +#include "display_ani_utils.h" #include "display_info.h" -#include "display.h" -#include "singleton_container.h" #include "display_manager.h" -#include "window_manager_hilog.h" #include "dm_common.h" -#include "display_ani_utils.h" #include "refbase.h" -#include "ani_err_utils.h" +#include "singleton_container.h" +#include "window_manager_hilog.h" namespace OHOS { namespace Rosen { diff --git a/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_utils.cpp b/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_utils.cpp index f26579bc2664c6a10acfccb0a53eb1444c98aab6..ebdb4f53a9f9023111a16241f2e238863e3c27ce 100644 --- a/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_utils.cpp +++ b/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_utils.cpp @@ -13,18 +13,19 @@ * limitations under the License. */ +#include "display_ani_utils.h" + #include #include "ani.h" -#include "display_ani_utils.h" +#include "display.h" #include "display_ani.h" #include "display_info.h" -#include "display.h" -#include "singleton_container.h" #include "display_manager.h" -#include "window_manager_hilog.h" #include "dm_common.h" #include "refbase.h" +#include "singleton_container.h" +#include "window_manager_hilog.h" namespace OHOS { namespace Rosen { diff --git a/interfaces/kits/ani/embeddable_window_stage/ets/@ohos.uiExtensionHost.ets b/interfaces/kits/ani/embeddable_window_stage/ets/@ohos.uiExtensionHost.ets index ea71131898f0897fda0d74671e5a2a94c6f071d4..ebe8a72f44386b948aafdbc78410e80ab0548993 100644 --- a/interfaces/kits/ani/embeddable_window_stage/ets/@ohos.uiExtensionHost.ets +++ b/interfaces/kits/ani/embeddable_window_stage/ets/@ohos.uiExtensionHost.ets @@ -14,8 +14,9 @@ */ import { BusinessError } from '@ohos.base'; +import hilog from '@ohos.hilog'; import window from '@ohos.window'; -import { Callback } from '@ohos.base' +import { Callback } from '@ohos.base'; /** * uiExtensionHost. @@ -26,56 +27,78 @@ import { Callback } from '@ohos.base' * @since 11 */ namespace uiExtensionHost { - export native function createExtentionWindow(win: long, hostId: int): UIExtensionHostWindowProxy; + export native function createExtensionWindow(win: long, hostId: int): UIExtensionHostWindowProxy; + + // UIExtension WmsLogTag + const WMS_UIEXT: int = 0xC0420D; + const WMS_UIEXT_TAG: string = "WMSUiext"; + const enum WmErrorCode { + WM_OK = 0, + WM_ERROR_INVALID_PARAM = 401 + } + const WM_ERRORCODE_INVALID_PARAM_MSG: string = `Parameter error. Possible causes: ` + + `1. Mandatory parameters are left unspecified; ` + + `2. Incorrect parameters types; ` + + `3. Parameter verification failed.`; + const WINDOW_SIZE_CHANGE_CB: string = "windowSizeChange"; + const AVOID_AREA_CHANGE_CB: string = "avoidAreaChange"; // internal class and function export type CallbackSize = (size: window.Size) => void; export type CallbackArea = (area: window.AvoidAreaOptions) => void; - const WMS_UIEXT: int = 0xC0420D; - const WMS_UIEXT_TAG: string = "WMSUiext"; - - function callBack(fn: object, fnArg: object): void { - let f = fn as (d: object) => void; - f(fnArg); + function sizeChangeCallback(fn: object, fnArg: object): void { + let f = fn as (d: object) => void; + f(fnArg); } - function avoidAreaChangeCallBack(cb: object, area: object, type: int): void { + function avoidAreaChangeCallback(cb: object, area: object, type: int): void { const func = cb as (data: window.AvoidAreaOptions) => void; func({type: type as window.AvoidAreaType, area: area as window.AvoidArea}); } + function keyboardHeightChangeCallback(cb: object, cbArg: int): void { + const func = cb as (cbArg: number) => void; + func(cbArg as number); + } + class UIESize implements window.Size { width: double; height: double; } + class UIERect implements window.Rect { left: double; top: double; width: double; height: double; - }; + } + class UIEAvoidArea implements window.AvoidArea { constructor() { - this.leftRect = new UIERect(); - this.topRect = new UIERect(); - this.rightRect = new UIERect(); - this.bottomRect = new UIERect(); + this.leftRect = new UIERect(); + this.topRect = new UIERect(); + this.rightRect = new UIERect(); + this.bottomRect = new UIERect(); } + visible: boolean; leftRect: window.Rect; topRect: window.Rect; rightRect: window.Rect; bottomRect: window.Rect; } + class UIEAreaAndType { type: window.AvoidAreaType; area: UIEAvoidArea; } + class UIEProperties implements UIExtensionHostWindowProxyProperties { constructor() { - this.uiExtensionHostWindowProxyRect = new UIERect(); + this.uiExtensionHostWindowProxyRect = new UIERect(); } + uiExtensionHostWindowProxyRect: window.Rect; } @@ -83,57 +106,96 @@ namespace uiExtensionHost { export class UIExtensionHostInternal implements UIExtensionHostWindowProxy { static { loadLibrary("embeddablewindowstageani_kit.z") } private nativeObj: long = 0; + private setNativeObj(nativeObj: long): void { - this.nativeObj = nativeObj; + this.nativeObj = nativeObj; } + private setAreaVisible(obj: window.AvoidArea, visible: boolean) { - obj.visible = visible; + obj.visible = visible; } public native getProperties(nativeObj: long, property: object): int; public native setProperties(nativeObj: long, property: object): int; public native getWindowAvoidArea(nativeObj: long, type: int, area: object): int; - public native setWaterMarkFlag(nativeObj: long, enable: boolean): void; - public native hidePrivacyContentForHost(nativeObj: long, shouldHide: boolean): void; + public native setWaterMarkFlag(nativeObj: long, enable: boolean): int; + public native hidePrivacyContentForHost(nativeObj: long, shouldHide: boolean): int; public native onAvoidAreaChange(nativeObj: long, callback: object, callbackData: object): int; public native offAvoidAreaChange(nativeObj: long, callback?: object): int; public native onWindowSizeChange(nativeObj: long, callback: object, callbackData: object): int; public native offWindowSizeChange(nativeObj: long, callback?: object): int; get properties(): UIExtensionHostWindowProxyProperties { - let property = new UIEProperties(); - let ret = this.getProperties(this.nativeObj, property as object); - return property; + let property = new UIEProperties(); + let ret = this.getProperties(this.nativeObj, property as object); + if (ret !== WmErrorCode.WM_OK) { + hilog.error(WMS_UIEXT, WMS_UIEXT_TAG, `getProperties failed, ret: ${ret}`); + } + return property; } - set properties(property: UIExtensionHostWindowProxyProperties) { - this.setProperties(this.nativeObj, property as object); + + set properties(properties: UIExtensionHostWindowProxyProperties) { + this.setProperties(this.nativeObj, properties as object); } + public on(type: string, callback: Callback): void { - if (type == 'avoidAreaChange') { - let area = new UIEAreaAndType(); - this.onAvoidAreaChange(this.nativeObj, callback as object, area as object); - } else { - let size = new UIESize(); - this.onWindowSizeChange(this.nativeObj, callback as object, size as object); + if (type === AVOID_AREA_CHANGE_CB) { + let area = new UIEAreaAndType(); + let ret = this.onAvoidAreaChange(this.nativeObj, callback as object, area as object); + if (ret !== WmErrorCode.WM_OK) { + hilog.error(WMS_UIEXT, WMS_UIEXT_TAG, `register ${type} callback failed, ret: ${ret}`); + } + } else if (type === WINDOW_SIZE_CHANGE_CB) { + let size = new UIESize(); + let ret = this.onWindowSizeChange(this.nativeObj, callback as object, size as object); + if (ret !== WmErrorCode.WM_OK) { + hilog.error(WMS_UIEXT, WMS_UIEXT_TAG, `register ${type} callback failed, ret: ${ret}`); } + } else { + hilog.error(WMS_UIEXT, WMS_UIEXT_TAG, `type ${type} is not supported`); + throw { + code: WmErrorCode.WM_ERROR_INVALID_PARAM, + message: WM_ERRORCODE_INVALID_PARAM_MSG + } as BusinessError as Error; + } } + public off(type: string, callback?: Callback): void { - if (type == 'avoidAreaChange') { - this.offAvoidAreaChange(this.nativeObj, callback); - } else { - this.offWindowSizeChange(this.nativeObj, callback); + if (type === AVOID_AREA_CHANGE_CB) { + let ret = this.offAvoidAreaChange(this.nativeObj, callback); + if (ret !== WmErrorCode.WM_OK) { + hilog.error(WMS_UIEXT, WMS_UIEXT_TAG, `unregister ${type} callback failed, ret: ${ret}`); } + } else if (type === WINDOW_SIZE_CHANGE_CB) { + let ret = this.offWindowSizeChange(this.nativeObj, callback); + if (ret !== WmErrorCode.WM_OK) { + hilog.error(WMS_UIEXT, WMS_UIEXT_TAG, `unregister ${type} callback failed, ret: ${ret}`); + } + } else { + hilog.error(WMS_UIEXT, WMS_UIEXT_TAG, `type ${type} is not supported`); + throw { + code: WmErrorCode.WM_ERROR_INVALID_PARAM, + message: WM_ERRORCODE_INVALID_PARAM_MSG + } as BusinessError as Error; + } } + getWindowAvoidArea(type: window.AvoidAreaType): window.AvoidArea { - let area: window.AvoidArea = new UIEAvoidArea(); - let ret = this.getWindowAvoidArea(this.nativeObj, type as int, area as object); - return area; + let area: window.AvoidArea = new UIEAvoidArea(); + let ret = this.getWindowAvoidArea(this.nativeObj, type as int, area as object); + if (ret !== WmErrorCode.WM_OK) { + hilog.error(WMS_UIEXT, WMS_UIEXT_TAG, `getWindowAvoidArea failed, ret: ${ret}`); + } + return area; } setWaterMarkFlag(enable: boolean): Promise { return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void): void => { taskpool.execute((): void => { - this.setWaterMarkFlag(this.nativeObj, enable); + let ret = this.setWaterMarkFlag(this.nativeObj, enable); + if (ret !== WmErrorCode.WM_OK) { + hilog.error(WMS_UIEXT, WMS_UIEXT_TAG, `setWaterMarkFlag failed, ret: ${ret}`); + } }).then((ret: NullishType) :void => { resolve(undefined); }).catch((err: NullishType) :void => { @@ -145,7 +207,10 @@ namespace uiExtensionHost { hidePrivacyContentForHost(shouldHide: boolean): Promise { return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void): void => { taskpool.execute((): void => { - this.hidePrivacyContentForHost(this.nativeObj, shouldHide); + let ret = this.hidePrivacyContentForHost(this.nativeObj, shouldHide); + if (ret !== WmErrorCode.WM_OK) { + hilog.error(WMS_UIEXT, WMS_UIEXT_TAG, `hidePrivacyContentForHost failed, ret: ${ret}`); + } }).then((ret: NullishType) :void => { resolve(undefined); }).catch((err: NullishType) :void => { @@ -154,6 +219,7 @@ namespace uiExtensionHost { }); } } + /** * Transition Controller * @@ -192,4 +258,4 @@ namespace uiExtensionHost { } } -export default uiExtensionHost; +export default uiExtensionHost; \ No newline at end of file diff --git a/interfaces/kits/ani/embeddable_window_stage/include/ani_extension_window.h b/interfaces/kits/ani/embeddable_window_stage/include/ani_extension_window.h index bd1f026580b6e1b2206859a56020aa2c4705cacf..ae0c05d2ec7d5d80eb3632a06829a6768b71c6f4 100644 --- a/interfaces/kits/ani/embeddable_window_stage/include/ani_extension_window.h +++ b/interfaces/kits/ani/embeddable_window_stage/include/ani_extension_window.h @@ -37,13 +37,13 @@ public: sptr sessionInfo); static ani_object CreateAniExtensionWindow(ani_env* env, sptr window, int32_t hostWindowId); WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea); - WMError OnSetWaterMarkFlag(ani_env* env, ani_boolean enable); - WMError OnHidePrivacyContentForHost(ani_env* env, ani_boolean shouldHide); - WMError GetRect(Rect&); - WMError RegisterListener(const std::string& cbType, ani_env* env, ani_object fn, ani_object fnArg); - WMError UnregisterListener(const std::string& cbType, ani_env* env, ani_object fn); + WmErrorCode OnSetWaterMarkFlag(ani_env* env, ani_boolean enable); + WmErrorCode OnHidePrivacyContentForHost(ani_env* env, ani_boolean shouldHide); + WmErrorCode GetExtensionWindowRect(Rect& rect); + WmErrorCode RegisterListener(const std::string& cbType, ani_env* env, ani_object fn, ani_object fnArg); + WmErrorCode UnregisterListener(const std::string& cbType, ani_env* env, ani_object fn); private: - bool WindowIsValid(); + bool IsExtensionWindowValid(); std::shared_ptr extensionWindow_; int32_t hostWindowId_ = 0; sptr sessionInfo_ = nullptr; diff --git a/interfaces/kits/ani/embeddable_window_stage/include/ani_extension_window_listener.h b/interfaces/kits/ani/embeddable_window_stage/include/ani_extension_window_listener.h index 4d280abf98cec23a84f03c9b35eb0edd0b427c70..baacb3d601609eb8abd501d55a69e48a13eda5f4 100644 --- a/interfaces/kits/ani/embeddable_window_stage/include/ani_extension_window_listener.h +++ b/interfaces/kits/ani/embeddable_window_stage/include/ani_extension_window_listener.h @@ -28,31 +28,38 @@ namespace OHOS { namespace Rosen { +const std::string WINDOW_SIZE_CHANGE_CB = "windowSizeChange"; +const std::string AVOID_AREA_CHANGE_CB = "avoidAreaChange"; +const std::string WINDOW_STAGE_EVENT_CB = "windowStageEvent"; +const std::string WINDOW_EVENT_CB = "windowEvent"; +constexpr const char* ETS_UIEXTENSION_HOST_NAMESPACE_DESCRIPTOR = "L@ohos/uiExtensionHost/uiExtensionHost;"; + class AniExtensionWindowListener : public IWindowChangeListener, public IAvoidAreaChangedListener, public IWindowLifeCycle, public IOccupiedAreaChangeListener { public: AniExtensionWindowListener(ani_env* env, ani_ref func, ani_ref data) - : env_(env), callBack_(func), callBackData_(data), weakRef_(wptr (this)) {} + : env_(env), aniCallback_(func), aniCallbackData_(data), weakRef_(wptr (this)) {} ~AniExtensionWindowListener(); + ani_ref GetAniCallback() const { return aniCallback_; } + void SetAniCallback(ani_ref aniCallback) { aniCallback_ = aniCallback; } void OnSizeChange(Rect rect, WindowSizeChangeReason reason, - const std::shared_ptr& rsTransaction = nullptr) override; + const std::shared_ptr& rsTransaction = nullptr) override; void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type, const sptr& info = nullptr) override; void OnSizeChange(const sptr& info, - const std::shared_ptr& rsTransaction = nullptr) override; + const std::shared_ptr& rsTransaction = nullptr) override; void SetMainEventHandler(); - bool IsSameRef(ani_ref newRef); void SetSizeInfo(uint32_t width, uint32_t height); private: - void CallBack(); + void CallSizeChangeCallback(); uint32_t currentWidth_ = 0; uint32_t currentHeight_ = 0; ani_env* env_ = nullptr; - ani_ref callBack_; - ani_ref callBackData_; + ani_ref aniCallback_; + ani_ref aniCallbackData_; wptr weakRef_ = nullptr; std::shared_ptr eventHandler_ = nullptr; DEFINE_VAR_DEFAULT_FUNC_SET(bool, IsDeprecatedInterface, isDeprecatedInterface, false) diff --git a/interfaces/kits/ani/embeddable_window_stage/include/ani_extension_window_register_manager.h b/interfaces/kits/ani/embeddable_window_stage/include/ani_extension_window_register_manager.h index ed367b67ff6da817de68e60651c4a2e32482fcd9..ab71264877f2bead38b532ff09c91d86c3ded8d5 100644 --- a/interfaces/kits/ani/embeddable_window_stage/include/ani_extension_window_register_manager.h +++ b/interfaces/kits/ani/embeddable_window_stage/include/ani_extension_window_register_manager.h @@ -17,6 +17,7 @@ #define OHOS_ANI_EXTENSION_WINDOW_REGISTER_MANAGER_H #include + #include "ani.h" #include "ani_extension_window_listener.h" #include "refbase.h" @@ -30,9 +31,9 @@ class AniExtensionWindowRegisterManager { public: AniExtensionWindowRegisterManager(); ~AniExtensionWindowRegisterManager(); - WMError RegisterListener(sptr window, const std::string& type, + WmErrorCode RegisterListener(sptr window, const std::string& type, CaseType caseType, ani_env* env, ani_object fn, ani_object fnArg); - WMError UnregisterListener(sptr window, std::string type, + WmErrorCode UnregisterListener(sptr window, const std::string& type, CaseType caseType, ani_env* env, ani_object fn); private: @@ -44,13 +45,13 @@ private: }; bool IsCallbackRegistered(ani_env* env, const std::string& type, ani_object fn); - WMError ProcessWindowChangeRegister(sptr listener, + WmErrorCode ProcessWindowChangeRegister(sptr listener, sptr window, bool isRegister); - WMError ProcessAvoidAreaChangeRegister(sptr listener, + WmErrorCode ProcessAvoidAreaChangeRegister(sptr listener, sptr window, bool isRegister); - WMError ProcessLifeCycleEventRegister(sptr listener, + WmErrorCode ProcessLifeCycleEventRegister(sptr listener, sptr window, bool isRegister); - WMError ProcessRegister(CaseType caseType, const sptr& listener, + WmErrorCode ProcessRegister(CaseType caseType, const sptr& listener, const sptr& window, const std::string& type, bool isRegister); std::map>> aniCbMap_; std::mutex mtx_; diff --git a/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window.cpp b/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window.cpp index 59b58980547493e9e400b62fac2a960e4c04a245..a535a5361dc39f1d9297ed7c7765baae94b37e72 100644 --- a/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window.cpp +++ b/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window.cpp @@ -13,14 +13,20 @@ * limitations under the License. */ -#include "ani.h" #include "ani_extension_window.h" + +#include "ani.h" #include "ani_extension_window_register_manager.h" +#include "ani_window_utils.h" #include "extension_window_impl.h" #include "window_manager_hilog.h" namespace OHOS { namespace Rosen { +namespace { +constexpr const char* ETS_UIEXTENSION_HOST_CLASS_DESCRIPTOR = + "L@ohos/uiExtensionHost/uiExtensionHost/UIExtensionHostInternal;"; +} AniExtensionWindow::AniExtensionWindow( const std::shared_ptr extensionWindow, int32_t hostWindowId) @@ -28,7 +34,7 @@ AniExtensionWindow::AniExtensionWindow( hostWindowId_(hostWindowId), extensionRegisterManager_(std::make_unique()) { - TLOGI(WmsLogTag::WMS_UIEXT, "%{public}d", hostWindowId_); + TLOGI(WmsLogTag::WMS_UIEXT, "hostWindowId: %{public}d", hostWindowId_); } AniExtensionWindow::AniExtensionWindow( @@ -42,15 +48,15 @@ AniExtensionWindow::AniExtensionWindow( ani_object AniExtensionWindow::CreateAniExtensionWindow(ani_env* env, sptr window, int32_t hostWindowId) { - if (env == nullptr) { - TLOGE(WmsLogTag::WMS_UIEXT, "AniExtensionWindow env or window is nullptr"); + if (env == nullptr || window == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "env or window is nullptr"); return nullptr; } - ani_status ret; + ani_status ret {}; ani_class cls = nullptr; - if ((ret = env->FindClass("L@ohos/uiExtensionHost/uiExtensionHost/UIExtensionHostInternal;", &cls)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] null env %{public}u", ret); + if ((ret = env->FindClass(ETS_UIEXTENSION_HOST_CLASS_DESCRIPTOR, &cls)) != ANI_OK) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Find class failed, ret: %{public}u", ret); return cls; } @@ -60,23 +66,23 @@ ani_object AniExtensionWindow::CreateAniExtensionWindow(ani_env* env, sptrClass_FindField(cls, "nativeObj", &contextField)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] get field fail %{public}u", ret); + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Find field failed, ret: %{public}u", ret); return nullptr; } ani_method initFunc = nullptr; if ((ret = env->Class_FindMethod(cls, "", ":V", &initFunc)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] get ctor fail %{public}u", ret); + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Find ctor method failed, ret: %{public}u", ret); return nullptr; } ani_object obj = nullptr; if ((ret = env->Object_New(cls, initFunc, &obj)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] obj new fail %{public}u", ret); + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]New object failed, ret: %{public}u", ret); return nullptr; } ani_method setObjFunc = nullptr; if ((ret = env->Class_FindMethod(cls, "setNativeObj", "J:V", &setObjFunc)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] get ctor fail %{public}u", ret); + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Find method failed, ret: %{public}u", ret); return nullptr; } env->Object_CallMethod_Void(obj, setObjFunc, reinterpret_cast(aniExtensionWindow.release())); @@ -85,46 +91,46 @@ ani_object AniExtensionWindow::CreateAniExtensionWindow(ani_env* env, sptrGetAvoidAreaByType(type, avoidArea); } -WMError AniExtensionWindow::OnSetWaterMarkFlag(ani_env* env, ani_boolean enable) +WmErrorCode AniExtensionWindow::OnSetWaterMarkFlag(ani_env* env, ani_boolean enable) { if (extensionWindow_ == nullptr) { TLOGE(WmsLogTag::WMS_UIEXT, "extensionWindow_ is nullptr"); - return WMError::WM_DO_NOTHING; + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; } - WmErrorCode ret = WmErrorCode::WM_OK; - ret = WM_JS_TO_ERROR_CODE_MAP.at(extensionWindow_->SetWaterMarkFlag(enable)); - if (ret != WmErrorCode::WM_OK) { - return WMError::WM_DO_NOTHING; + WMError ret = extensionWindow_->SetWaterMarkFlag(enable); + if (WM_JS_TO_ERROR_CODE_MAP.at(ret) != WmErrorCode::WM_OK) { + AniWindowUtils::AniThrowError(env, WM_JS_TO_ERROR_CODE_MAP.at(ret)); + return WM_JS_TO_ERROR_CODE_MAP.at(ret); } - TLOGI(WmsLogTag::WMS_UIEXT, "[ANI] OnSetWaterMarkFlag success,isEnable:%{public}u.", - enable); - return WMError::WM_OK; + TLOGI(WmsLogTag::WMS_UIEXT, "[ANI]finished, enable: %{public}u", enable); + return WmErrorCode::WM_OK; } -WMError AniExtensionWindow::OnHidePrivacyContentForHost(ani_env* env, ani_boolean shouldHide) +WmErrorCode AniExtensionWindow::OnHidePrivacyContentForHost(ani_env* env, ani_boolean shouldHide) { if (extensionWindow_ == nullptr) { TLOGE(WmsLogTag::WMS_UIEXT, "extensionWindow_ is nullptr"); - return WMError::WM_DO_NOTHING; + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; } - WmErrorCode ret = WmErrorCode::WM_OK; - ret = WM_JS_TO_ERROR_CODE_MAP.at(extensionWindow_->HidePrivacyContentForHost(shouldHide)); - if (ret != WmErrorCode::WM_OK) { - return WMError::WM_DO_NOTHING; + WMError ret = extensionWindow_->HidePrivacyContentForHost(shouldHide); + if (WM_JS_TO_ERROR_CODE_MAP.at(ret) != WmErrorCode::WM_OK) { + AniWindowUtils::AniThrowError(env, WM_JS_TO_ERROR_CODE_MAP.at(ret)); + return WM_JS_TO_ERROR_CODE_MAP.at(ret); } - TLOGI(WmsLogTag::WMS_UIEXT, - "[ANI] OnHidePrivacyContentForHost success,shouldHide:%{public}u.", shouldHide); - return WMError::WM_OK; + TLOGI(WmsLogTag::WMS_UIEXT, "[ANI]finished, shouldHide: %{public}u", shouldHide); + return WmErrorCode::WM_OK; } -bool AniExtensionWindow::WindowIsValid() +bool AniExtensionWindow::IsExtensionWindowValid() { if (extensionWindow_ == nullptr) { return false; @@ -136,181 +142,206 @@ bool AniExtensionWindow::WindowIsValid() return true; } -WMError AniExtensionWindow::UnregisterListener(const std::string& cbType, ani_env* env, ani_object fn) +WmErrorCode AniExtensionWindow::UnregisterListener(const std::string& cbType, ani_env* env, ani_object fn) { - if (!WindowIsValid()) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] window not available"); - return WMError::WM_DO_NOTHING; + if (!IsExtensionWindowValid()) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]extension window is invalid"); + return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; } sptr window = extensionWindow_->GetWindow(); return extensionRegisterManager_->UnregisterListener(window, cbType, CaseType::CASE_WINDOW, env, fn); } -WMError AniExtensionWindow::RegisterListener(const std::string& cbType, ani_env* env, ani_object fn, ani_object fnArg) +WmErrorCode AniExtensionWindow::RegisterListener(const std::string& cbType, ani_env* env, + ani_object fn, ani_object fnArg) { - if (!WindowIsValid()) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] window not available"); - return WMError::WM_DO_NOTHING; + if (!IsExtensionWindowValid()) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]extension window is invalid"); + return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; } sptr window = extensionWindow_->GetWindow(); return extensionRegisterManager_->RegisterListener(window, cbType, CaseType::CASE_WINDOW, env, fn, fnArg); } -WMError AniExtensionWindow::GetRect(Rect& rect) +WmErrorCode AniExtensionWindow::GetExtensionWindowRect(Rect& rect) { - if (!WindowIsValid()) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] window not available"); - return WMError::WM_DO_NOTHING; + if (!IsExtensionWindowValid()) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]extension window is invalid"); + return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; } rect = extensionWindow_->GetWindow()->GetRect(); - return WMError::WM_OK; + return WmErrorCode::WM_OK; } -static ani_int ExtWindowSetRect(ani_env* env, ani_object obj, OHOS::Rosen::Rect& rect) +static ani_status ExtWindowSetRect(ani_env* env, ani_object obj, OHOS::Rosen::Rect& rect) { ani_status ret {}; if ((ret = env->Object_SetFieldByName_Double(obj, "left", rect.posX_)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] set left field %{public}u", ret); - return (ani_int)WMError::WM_DO_NOTHING; + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Set left field failed, ret: %{public}u", ret); + return ret; } if ((ret = env->Object_SetFieldByName_Double(obj, "top", rect.posY_)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] set top field %{public}u", ret); - return (ani_int)WMError::WM_DO_NOTHING; + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Set top field failed, ret: %{public}u", ret); + return ret; } if ((ret = env->Object_SetFieldByName_Double(obj, "width", rect.width_)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] set width field %{public}u", ret); - return (ani_int)WMError::WM_DO_NOTHING; + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Set width field failed, ret: %{public}u", ret); + return ret; } if ((ret = env->Object_SetFieldByName_Double(obj, "height", rect.height_)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] set height field %{public}u", ret); - return (ani_int)WMError::WM_DO_NOTHING; + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Set height field failed, ret: %{public}u", ret); + return ret; } - return (ani_int)WMError::WM_OK; + return ANI_OK; } -static ani_int ExtWindowSetRectMember(ani_env* env, ani_object obj, const char* member, OHOS::Rosen::Rect& rect) +static ani_status ExtWindowSetRectMember(ani_env* env, ani_object obj, const char* member, OHOS::Rosen::Rect& rect) { ani_status ret {}; ani_ref rectRef {}; if ((ret = env->Object_GetFieldByName_Ref(obj, member, &rectRef)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] get field %{public}s %{public}u", member, ret); - return (ani_int)WMError::WM_DO_NOTHING; + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Get field %{public}s failed, ret: %{public}u", member, ret); + return ret; }; - return ExtWindowSetRect(env, (ani_object)rectRef, rect); + return ExtWindowSetRect(env, static_cast(rectRef), rect); } static ani_int ExtWindowGetProperties(ani_env* env, ani_object obj, ani_long nativeObj, ani_object propertyRef) { - WMError retCode = WMError::WM_OK; - AniExtensionWindow* aniExt = reinterpret_cast(nativeObj); + WmErrorCode retCode = WmErrorCode::WM_OK; + AniExtensionWindow* aniExtWinPtr = reinterpret_cast(nativeObj); + if (aniExtWinPtr == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]aniExtWinPtr is nullptr"); + return static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } Rect rect {}; - if ((retCode = aniExt->GetRect(rect)) != WMError::WM_OK) { - return (ani_int)retCode; + if ((retCode = aniExtWinPtr->GetExtensionWindowRect(rect)) != WmErrorCode::WM_OK) { + return static_cast(retCode); }; - return ExtWindowSetRectMember(env, propertyRef, "uiExtensionHostWindowProxyRect", rect); -} - -static ani_int ExtWindowSetProperties(ani_env* env, ani_object obj, ani_long nativeObj, ani_object propertyRef) -{ - return (ani_int)WMError::WM_ERROR_DEVICE_NOT_SUPPORT; + return static_cast( + ExtWindowSetRectMember(env, propertyRef, "uiExtensionHostWindowProxyRect", rect)); } static ani_int ExtWindowGetWindowAvoidArea(ani_env* env, ani_object obj, ani_long win, ani_int areaType, ani_object area) { - bool err = ((areaType > (int)AvoidAreaType::TYPE_NAVIGATION_INDICATOR) || - (areaType < (int)AvoidAreaType::TYPE_SYSTEM)); - if (err) { - return (ani_int)WMError::WM_ERROR_INVALID_PARAM; + bool hasAvoidAreaTypeErr = (areaType < static_cast(AvoidAreaType::TYPE_START) || + areaType >= static_cast(AvoidAreaType::TYPE_END)); + if (hasAvoidAreaTypeErr) { + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return static_cast(WmErrorCode::WM_ERROR_INVALID_PARAM); } AvoidArea avoidArea {}; ani_status ret {}; - ret = env->Object_SetFieldByName_Boolean(area, "visible", areaType != (int)AvoidAreaType::TYPE_CUTOUT); + ret = env->Object_SetFieldByName_Boolean(area, "visible", areaType != + static_cast(AvoidAreaType::TYPE_CUTOUT)); if (ret != ANI_OK) { - TLOGI(WmsLogTag::WMS_UIEXT, "[ANI] set visible faild %{public}d", (int)ret); - return (ani_int)WMError::WM_DO_NOTHING; + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Set visible failed, ret: %{public}u", ret); + return static_cast(ret); } - AniExtensionWindow* winPtr = reinterpret_cast(win); - WMError retCode = winPtr->GetAvoidAreaByType((AvoidAreaType)areaType, avoidArea); + AniExtensionWindow* aniExtWinPtr = reinterpret_cast(win); + if (aniExtWinPtr == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]aniExtWinPtr is nullptr"); + return static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + WMError retCode = aniExtWinPtr->GetAvoidAreaByType(static_cast(areaType), avoidArea); if (retCode != WMError::WM_OK) { - return (ani_int)retCode; + return static_cast(WM_JS_TO_ERROR_CODE_MAP.at(retCode)); } - if ((retCode = (WMError)ExtWindowSetRectMember(env, area, "leftRect", avoidArea.leftRect_)) != - WMError::WM_OK) { - return (ani_int)retCode; + ret = ExtWindowSetRectMember(env, area, "leftRect", avoidArea.leftRect_); + if (ret != ANI_OK) { + return static_cast(ret); } - if ((retCode = (WMError)ExtWindowSetRectMember(env, area, "rightRect", avoidArea.rightRect_)) != - WMError::WM_OK) { - return (ani_int)retCode; + ret = ExtWindowSetRectMember(env, area, "rightRect", avoidArea.rightRect_); + if (ret != ANI_OK) { + return static_cast(ret); } - if ((retCode = (WMError)ExtWindowSetRectMember(env, area, "topRect", avoidArea.topRect_)) != - WMError::WM_OK) { - return (ani_int)retCode; + ret = ExtWindowSetRectMember(env, area, "topRect", avoidArea.topRect_); + if (ret != ANI_OK) { + return static_cast(ret); } - if ((retCode = (WMError)ExtWindowSetRectMember(env, area, "bottomRect", avoidArea.bottomRect_)) != - WMError::WM_OK) { - return (ani_int)retCode; + ret = ExtWindowSetRectMember(env, area, "bottomRect", avoidArea.bottomRect_); + if (ret != ANI_OK) { + return static_cast(ret); } - return (ani_int)WMError::WM_OK; + return static_cast(WmErrorCode::WM_OK); } static ani_int ExtWindowSetWaterMarkFlag(ani_env* env, ani_object obj, ani_long nativeObj, ani_boolean enable) { - AniExtensionWindow* winPtr = reinterpret_cast(nativeObj); - WMError ret = WMError::WM_DO_NOTHING; - if (winPtr != nullptr) { - ret = winPtr->OnSetWaterMarkFlag(env, enable); - } else { - TLOGE(WmsLogTag::DEFAULT, "[ANI] AniExtensionWindow is nullptr"); - } - return (ani_int)ret; + AniExtensionWindow* aniExtWinPtr = reinterpret_cast(nativeObj); + if (aniExtWinPtr == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]aniExtWinPtr is nullptr"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + return static_cast(aniExtWinPtr->OnSetWaterMarkFlag(env, enable)); } static ani_int ExtWindowHidePrivacyContentForHost(ani_env* env, ani_object obj, ani_long nativeObj, ani_boolean shouldHide) { - AniExtensionWindow* winPtr = reinterpret_cast(nativeObj); - WMError ret = WMError::WM_DO_NOTHING; - if (winPtr != nullptr) { - ret = winPtr->OnHidePrivacyContentForHost(env, shouldHide); - } else { - TLOGE(WmsLogTag::DEFAULT, "[ANI] AniExtensionWindow is nullptr"); - } - return (ani_int)ret; + AniExtensionWindow* aniExtWinPtr = reinterpret_cast(nativeObj); + if (aniExtWinPtr == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]aniExtWinPtr is nullptr"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + return static_cast(aniExtWinPtr->OnHidePrivacyContentForHost(env, shouldHide)); } static ani_int ExtWindowOnAvoidAreaChange(ani_env* env, ani_object obj, ani_long nativeObj, ani_object fn, ani_object fnArg) { - AniExtensionWindow* winPtr = reinterpret_cast(nativeObj); - return (ani_int)winPtr->RegisterListener("avoidAreaChange", env, fn, fnArg); + AniExtensionWindow* aniExtWinPtr = reinterpret_cast(nativeObj); + if (aniExtWinPtr == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]aniExtWinPtr is nullptr"); + return static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + return static_cast(aniExtWinPtr->RegisterListener(AVOID_AREA_CHANGE_CB, env, fn, fnArg)); } -static ani_int ExtWindowOffAvoidAreaChange(ani_env* env, ani_object obj, ani_long nativeObj, - ani_object fn) +static ani_int ExtWindowOffAvoidAreaChange(ani_env* env, ani_object obj, ani_long nativeObj, ani_object fn) { - AniExtensionWindow* winPtr = reinterpret_cast(nativeObj); - return (ani_int)winPtr->UnregisterListener("avoidAreaChange", env, fn); + AniExtensionWindow* aniExtWinPtr = reinterpret_cast(nativeObj); + if (aniExtWinPtr == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]aniExtWinPtr is nullptr"); + return static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + return static_cast(aniExtWinPtr->UnregisterListener(AVOID_AREA_CHANGE_CB, env, fn)); } + static ani_int ExtWindowOnWindowSizeChange(ani_env* env, ani_object obj, ani_long nativeObj, ani_object fn, ani_object fnArg) { - AniExtensionWindow* winPtr = reinterpret_cast(nativeObj); - return (ani_int)winPtr->RegisterListener("windowSizeChange", env, fn, fnArg); + AniExtensionWindow* aniExtWinPtr = reinterpret_cast(nativeObj); + if (aniExtWinPtr == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]aniExtWinPtr is nullptr"); + return static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + return static_cast(aniExtWinPtr->RegisterListener(WINDOW_SIZE_CHANGE_CB, env, fn, fnArg)); } -static ani_int ExtWindowOffWindowSizeChange(ani_env* env, ani_object obj, ani_long nativeObj, - ani_object fn) + +static ani_int ExtWindowOffWindowSizeChange(ani_env* env, ani_object obj, ani_long nativeObj, ani_object fn) { - AniExtensionWindow* winPtr = reinterpret_cast(nativeObj); - return (ani_int)winPtr->UnregisterListener("windowSizeChange", env, fn); + AniExtensionWindow* aniExtWinPtr = reinterpret_cast(nativeObj); + if (aniExtWinPtr == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]aniExtWinPtr is nullptr"); + return static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + return static_cast(aniExtWinPtr->UnregisterListener(WINDOW_SIZE_CHANGE_CB, env, fn)); } -// test from ts -ani_object createExtentionWindow(ani_env* env, ani_long win, ani_int hostId) +ani_object createExtensionWindow(ani_env* env, ani_long win, ani_int hostId) { - TLOGI(WmsLogTag::WMS_UIEXT, "[ANI] create extwindow with hostId:%{public}d", hostId); - sptr winPtr; - return AniExtensionWindow::CreateAniExtensionWindow(env, winPtr, (int32_t)hostId); + TLOGI(WmsLogTag::WMS_UIEXT, "[ANI]Create extwindow with hostId: %{public}d", hostId); + auto winPtr = reinterpret_cast*>(win); + if (winPtr == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]winPtr is nullptr"); + return nullptr; + } + sptr window = *winPtr; + return AniExtensionWindow::CreateAniExtensionWindow(env, window, hostId); } } } // namespace @@ -319,12 +350,11 @@ extern "C" { using namespace OHOS::Rosen; std::array extensionWindowNativeMethods = { ani_native_function {"getProperties", "JLstd/core/Object;:I", reinterpret_cast(ExtWindowGetProperties)}, - ani_native_function {"setProperties", "JLstd/core/Object;:I", reinterpret_cast(ExtWindowSetProperties)}, ani_native_function {"getWindowAvoidArea", "JILstd/core/Object;:I", reinterpret_cast(ExtWindowGetWindowAvoidArea)}, - ani_native_function {"setWaterMarkFlag", "JZ:V", + ani_native_function {"setWaterMarkFlag", "JZ:I", reinterpret_cast(ExtWindowSetWaterMarkFlag)}, - ani_native_function {"hidePrivacyContentForHost", "JZ:V", + ani_native_function {"hidePrivacyContentForHost", "JZ:I", reinterpret_cast(ExtWindowHidePrivacyContentForHost)}, ani_native_function {"onAvoidAreaChange", "JLstd/core/Object;Lstd/core/Object;:I", reinterpret_cast(ExtWindowOnAvoidAreaChange)}, @@ -338,42 +368,41 @@ std::array extensionWindowNativeMethods = { ANI_EXPORT ani_status ExtensionWindow_ANI_Constructor(ani_vm *vm, uint32_t *result) { using namespace OHOS::Rosen; - TLOGD(WmsLogTag::WMS_UIEXT, "[ANI] init ExtensionWindow begin"); - ani_status ret; + TLOGD(WmsLogTag::WMS_UIEXT, "[ANI]Init ExtensionWindow begin"); + ani_status ret {}; ani_env* env; if ((ret = vm->GetEnv(ANI_VERSION_1, &env)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] null env"); + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Get env failed, ret: %{public}u", ret); return ANI_NOT_FOUND; } ani_class cls = nullptr; - if ((ret = env->FindClass("L@ohos/uiExtensionHost/uiExtensionHost/UIExtensionHostInternal;", &cls)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] null env %{public}u", ret); + if ((ret = env->FindClass(ETS_UIEXTENSION_HOST_CLASS_DESCRIPTOR, &cls)) != ANI_OK) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Find class failed, ret: %{public}u", ret); return ANI_NOT_FOUND; } if ((ret = env->Class_BindNativeMethods(cls, extensionWindowNativeMethods.data(), extensionWindowNativeMethods.size())) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] bind fail %{public}u", ret); + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Class bind native methods failed, ret: %{public}u", ret); return ANI_NOT_FOUND; } *result = ANI_VERSION_1; - // test ani_namespace ns; - if ((ret = env->FindNamespace("L@ohos/uiExtensionHost/uiExtensionHost;", &ns)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] find ns %{public}u", ret); + if ((ret = env->FindNamespace(ETS_UIEXTENSION_HOST_NAMESPACE_DESCRIPTOR, &ns)) != ANI_OK) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Find namespace failed, ret: %{public}u", ret); return ANI_NOT_FOUND; } std::array functions = { - ani_native_function {"createExtentionWindow", nullptr, reinterpret_cast(createExtentionWindow)}, + ani_native_function {"createExtensionWindow", nullptr, reinterpret_cast(createExtensionWindow)}, }; if ((ret = env->Namespace_BindNativeFunctions(ns, functions.data(), functions.size())) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] bind ns func %{public}u", ret); + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Namespace bind native functions failed, ret: %{public}u", ret); return ANI_NOT_FOUND; } - TLOGD(WmsLogTag::WMS_UIEXT, "[ANI] init ExtensionWindow end"); + TLOGD(WmsLogTag::WMS_UIEXT, "[ANI]Init ExtensionWindow end"); return ANI_OK; } } diff --git a/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window_listener.cpp b/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window_listener.cpp index a9ca7d0160b7f63b36cb2141efd1e25d7223f1d7..9d2d9fa464bae99918008cc16717f4cf38645223 100644 --- a/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window_listener.cpp +++ b/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window_listener.cpp @@ -15,40 +15,33 @@ #include "ani_extension_window_listener.h" -#include #include "ani.h" #include "ani_window_utils.h" #include "event_handler.h" #include "event_runner.h" +#include #include "window_manager_hilog.h" namespace OHOS { namespace Rosen { using namespace AbilityRuntime; namespace { -const std::string WINDOW_SIZE_CHANGE_CB = "windowSizeChange"; -const std::string SYSTEM_AVOID_AREA_CHANGE_CB = "systemAvoidAreaChange"; -const std::string AVOID_AREA_CHANGE_CB = "avoidAreaChange"; -const std::string LIFECYCLE_EVENT_CB = "lifeCycleEvent"; -const std::string KEYBOARD_HEIGHT_CHANGE_CB = "keyboardHeightChange"; +constexpr const char* ETS_WINDOW_SIZE_CHANGE_CB = "sizeChangeCallback"; +constexpr const char* ETS_AVOID_AREA_CHANGE_CB = "avoidAreaChangeCallback"; +constexpr const char* ETS_KEYBOARD_HEIGHT_CHANGE_CB = "keyboardHeightChangeCallback"; } AniExtensionWindowListener::~AniExtensionWindowListener() { - if (callBack_ != nullptr) { - env_->GlobalReference_Delete(callBack_); + if (aniCallback_ != nullptr) { + env_->GlobalReference_Delete(aniCallback_); } - if (callBackData_ != nullptr) { - env_->GlobalReference_Delete(callBackData_); + if (aniCallbackData_ != nullptr) { + env_->GlobalReference_Delete(aniCallbackData_); } TLOGI(WmsLogTag::WMS_UIEXT, "[ANI]~AniExtensionWindowListener"); } -bool AniExtensionWindowListener::IsSameRef(ani_ref newRef) -{ - return true; -} - void AniExtensionWindowListener::SetMainEventHandler() { auto mainRunner = AppExecFwk::EventRunner::GetMainEventRunner(); @@ -58,21 +51,21 @@ void AniExtensionWindowListener::SetMainEventHandler() eventHandler_ = std::make_shared(mainRunner); } -void AniExtensionWindowListener::CallBack() +void AniExtensionWindowListener::CallSizeChangeCallback() { ani_status ret {}; ani_function fn {}; ani_namespace ns {}; - if ((ret = env_->FindNamespace("L@ohos/uiExtensionHost/uiExtensionHost;", &ns)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]canot find ns %{public}d", ret); + if ((ret = env_->FindNamespace(ETS_UIEXTENSION_HOST_NAMESPACE_DESCRIPTOR, &ns)) != ANI_OK) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Find namespace failed, ret: %{public}u", ret); return; } - if ((ret = env_->Namespace_FindFunction(ns, "callBack", "Lstd/core/Object;Lstd/core/Object;:V", &fn)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]canot find callBack %{public}d", ret); + if ((ret = env_->Namespace_FindFunction(ns, ETS_WINDOW_SIZE_CHANGE_CB, nullptr, &fn)) != ANI_OK) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Find function failed, ret: %{public}u", ret); return; } - if ((ret = env_->Function_Call_Void(fn, callBack_, callBackData_)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]canot find callBack %{public}d", ret); + if ((ret = env_->Function_Call_Void(fn, aniCallback_, aniCallbackData_)) != ANI_OK) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Call function failed, ret: %{public}u", ret); return; } } @@ -80,14 +73,14 @@ void AniExtensionWindowListener::CallBack() void AniExtensionWindowListener::SetSizeInfo(uint32_t width, uint32_t height) { ani_status ret {}; - if ((ret = env_->Object_SetFieldByName_Double((ani_object)callBackData_, "width", - (double)width)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]canot set width %{public}d", ret); + if ((ret = env_->Object_SetFieldByName_Double(static_cast(aniCallbackData_), "width", + static_cast(width))) != ANI_OK) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Set width failed, ret: %{public}u", ret); return; }; - if ((ret = env_->Object_SetFieldByName_Double((ani_object)callBackData_, "height", - (double)height)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]canot set height %{public}d", ret); + if ((ret = env_->Object_SetFieldByName_Double(static_cast(aniCallbackData_), "height", + static_cast(height))) != ANI_OK) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Set height failed, ret: %{public}u", ret); return; } } @@ -98,27 +91,27 @@ void AniExtensionWindowListener::OnSizeChange(Rect rect, WindowSizeChangeReason TLOGI(WmsLogTag::WMS_UIEXT, "[ANI]OnSizeChange, [%{public}u, %{public}u], reason=%{public}u", rect.width_, rect.height_, reason); if (currentWidth_ == rect.width_ && currentHeight_ == rect.height_ && reason != WindowSizeChangeReason::DRAG_END) { - TLOGD(WmsLogTag::WMS_UIEXT, "[ANI]no need to change size"); + TLOGD(WmsLogTag::WMS_UIEXT, "[ANI]No need to notify size change"); return; } - auto aniCallback = [self = weakRef_, rect, eng = env_] () { + auto onSizeChangeTask = [self = weakRef_, rect, eng = env_] () { HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "AniExtensionWindowListener::OnSizeChange"); auto thisListener = self.promote(); - if (thisListener == nullptr || eng == nullptr) { - TLOGE(WmsLogTag::WMS_UIEXT, "[NAPI]this listener or eng is nullptr"); + if (thisListener == nullptr || eng == nullptr || thisListener->aniCallback_ == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]thisListener, eng or callback is nullptr"); return; } thisListener->SetSizeInfo(rect.width_, rect.height_); - thisListener->CallBack(); + thisListener->CallSizeChangeCallback(); }; if (reason == WindowSizeChangeReason::ROTATION) { - aniCallback(); + onSizeChangeTask(); } else { if (!eventHandler_) { - TLOGE(WmsLogTag::WMS_UIEXT, "get main event handler failed!"); + TLOGE(WmsLogTag::WMS_UIEXT, "Get main event handler failed!"); return; } - eventHandler_->PostTask(aniCallback, "wms:AniExtensionWindowListener::OnSizeChange", 0, + eventHandler_->PostTask(onSizeChangeTask, "wms:AniExtensionWindowListener::SizeChangeCallback", 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); } currentWidth_ = rect.width_; @@ -131,30 +124,45 @@ void AniExtensionWindowListener::OnAvoidAreaChanged(const AvoidArea avoidArea, A TLOGI(WmsLogTag::WMS_UIEXT, "[ANI]"); auto task = [self = weakRef_, eng = env_, avoidArea, type] { auto thisListener = self.promote(); - if (thisListener == nullptr || eng == nullptr) { - TLOGE(WmsLogTag::WMS_UIEXT, "this listener or eng is nullptr"); + if (thisListener == nullptr || eng == nullptr || thisListener->aniCallback_ == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]thisListener, eng or callback is nullptr"); return; } auto nativeAvoidArea = AniWindowUtils::CreateAniAvoidArea(eng, avoidArea, type); - AniWindowUtils::CallAniFunctionVoid(eng, "L@ohos/uiExtensionHost/uiExtensionHost;", "avoidAreaChangeCallBack", - nullptr, thisListener->callBack_, nativeAvoidArea, static_cast(type)); + AniWindowUtils::CallAniFunctionVoid(eng, ETS_UIEXTENSION_HOST_NAMESPACE_DESCRIPTOR, ETS_AVOID_AREA_CHANGE_CB, + nullptr, thisListener->aniCallback_, nativeAvoidArea, static_cast(type)); }; if (!eventHandler_) { - TLOGE(WmsLogTag::WMS_UIEXT, "get main event handler failed!"); + TLOGE(WmsLogTag::WMS_UIEXT, "Get main event handler failed!"); return; } - eventHandler_->PostTask(task, __func__, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); + eventHandler_->PostTask(task, "wms:AniExtensionWindowListener::AvoidAreaChangeCallback", 0, + AppExecFwk::EventQueue::Priority::IMMEDIATE); } void AniExtensionWindowListener::OnSizeChange(const sptr& info, const std::shared_ptr& rsTransaction) { TLOGI(WmsLogTag::WMS_UIEXT, - "[ANI]OccupiedAreaChangeInfo, type: %{public}d, input rect:[%{public}d, %{public}d, %{public}d, %{public}d]", + "[ANI]OccupiedAreaChangeInfo, type: %{public}u, input rect:[%{public}d, %{public}d, %{public}u, %{public}u]", static_cast(info->type_), info->rect_.posX_, info->rect_.posY_, info->rect_.width_, info->rect_.height_); - // js callback should run in js thread - CallBack(); + auto onSizeChangeTask = [self = weakRef_, info, eng = env_] () { + auto thisListener = self.promote(); + if (thisListener == nullptr || eng == nullptr || thisListener->aniCallback_ == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]thisListener, eng or callback is nullptr"); + return; + } + AniWindowUtils::CallAniFunctionVoid(eng, ETS_UIEXTENSION_HOST_NAMESPACE_DESCRIPTOR, + ETS_KEYBOARD_HEIGHT_CHANGE_CB, nullptr, thisListener->aniCallback_, + static_cast(info->rect_.height_)); + }; + if (!eventHandler_) { + TLOGE(WmsLogTag::WMS_UIEXT, "Get main event handler failed!"); + return; + } + eventHandler_->PostTask(onSizeChangeTask, "wms:AniExtensionWindowListener::SizeChangeCallback", 0, + AppExecFwk::EventQueue::Priority::IMMEDIATE); } } // namespace Rosen diff --git a/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window_register_manager.cpp b/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window_register_manager.cpp index cb8243d68de6c41ab4ab9dd259a57e07ce90a6a6..88b367e8715b4103d22faaadd2061bc3cd446c04 100644 --- a/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window_register_manager.cpp +++ b/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window_register_manager.cpp @@ -23,12 +23,6 @@ namespace OHOS { namespace Rosen { -namespace { -const std::string WINDOW_SIZE_CHANGE_CB = "windowSizeChange"; -const std::string AVOID_AREA_CHANGE_CB = "avoidAreaChange"; -const std::string WINDOW_STAGE_EVENT_CB = "windowStageEvent"; -const std::string WINDOW_EVENT_CB = "windowEvent"; -} AniExtensionWindowRegisterManager::AniExtensionWindowRegisterManager() { @@ -48,49 +42,55 @@ AniExtensionWindowRegisterManager::~AniExtensionWindowRegisterManager() { } -WMError AniExtensionWindowRegisterManager::ProcessWindowChangeRegister(sptr listener, +WmErrorCode AniExtensionWindowRegisterManager::ProcessWindowChangeRegister(sptr listener, sptr window, bool isRegister) { if (window == nullptr) { - TLOGE(WmsLogTag::WMS_UIEXT, "[NAPI]Window is nullptr"); - return WMError::WM_DO_NOTHING; + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]window is nullptr"); + return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; } sptr thisListener(listener); + WmErrorCode ret = WmErrorCode::WM_OK; if (isRegister) { - return window->RegisterWindowChangeListener(thisListener); + ret = WM_JS_TO_ERROR_CODE_MAP.at(window->RegisterWindowChangeListener(thisListener)); } else { - return window->UnregisterWindowChangeListener(thisListener); + ret = WM_JS_TO_ERROR_CODE_MAP.at(window->UnregisterWindowChangeListener(thisListener)); } + return ret; } -WMError AniExtensionWindowRegisterManager::ProcessAvoidAreaChangeRegister(sptr listener, +WmErrorCode AniExtensionWindowRegisterManager::ProcessAvoidAreaChangeRegister(sptr listener, sptr window, bool isRegister) { if (window == nullptr) { - TLOGE(WmsLogTag::WMS_UIEXT, "[NAPI]Window is nullptr"); - return WMError::WM_DO_NOTHING; + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]window is nullptr"); + return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; } sptr thisListener(listener); + WmErrorCode ret = WmErrorCode::WM_OK; if (isRegister) { - return window->RegisterAvoidAreaChangeListener(thisListener); + ret = WM_JS_TO_ERROR_CODE_MAP.at(window->RegisterAvoidAreaChangeListener(thisListener)); } else { - return window->UnregisterAvoidAreaChangeListener(thisListener); + ret = WM_JS_TO_ERROR_CODE_MAP.at(window->UnregisterAvoidAreaChangeListener(thisListener)); } + return ret; } -WMError AniExtensionWindowRegisterManager::ProcessLifeCycleEventRegister(sptr listener, +WmErrorCode AniExtensionWindowRegisterManager::ProcessLifeCycleEventRegister(sptr listener, sptr window, bool isRegister) { if (window == nullptr) { - TLOGE(WmsLogTag::WMS_UIEXT, "Window is nullptr"); - return WMError::WM_DO_NOTHING; + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]window is nullptr"); + return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; } sptr thisListener(listener); + WmErrorCode ret = WmErrorCode::WM_OK; if (isRegister) { - return window->RegisterLifeCycleListener(thisListener); + ret = WM_JS_TO_ERROR_CODE_MAP.at(window->RegisterLifeCycleListener(thisListener)); } else { - return window->UnregisterLifeCycleListener(thisListener); + ret = WM_JS_TO_ERROR_CODE_MAP.at(window->UnregisterLifeCycleListener(thisListener)); } + return ret; } bool AniExtensionWindowRegisterManager::IsCallbackRegistered(ani_env* env, const std::string& type, ani_object fn) @@ -101,9 +101,10 @@ bool AniExtensionWindowRegisterManager::IsCallbackRegistered(ani_env* env, const } for (auto iter = aniCbMap_[type].begin(); iter != aniCbMap_[type].end(); ++iter) { - sptr oldListener= iter->second; - bool registed = oldListener->IsSameRef(fn); - if (registed) { + ani_ref callback = static_cast(fn); + ani_boolean isEqual = ANI_FALSE; + env->Reference_StrictEquals(callback, iter->first, &isEqual); + if (isEqual) { TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Method %{public}s has already been registered", type.c_str()); return true; } @@ -111,100 +112,114 @@ bool AniExtensionWindowRegisterManager::IsCallbackRegistered(ani_env* env, const return false; } -WMError AniExtensionWindowRegisterManager::RegisterListener(sptr window, const std::string& type, +WmErrorCode AniExtensionWindowRegisterManager::RegisterListener(sptr window, const std::string& type, CaseType caseType, ani_env* env, ani_object fn, ani_object fnArg) { std::lock_guard lock(mtx_); if (IsCallbackRegistered(env, type, fn)) { - return WMError::WM_DO_NOTHING; + return WmErrorCode::WM_ERROR_REPEAT_OPERATION; } if (listenerCodeMap_[caseType].count(type) == 0) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Type %{public}s is not supported", type.c_str()); - return WMError::WM_DO_NOTHING; + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Type %{public}s listener is not supported", type.c_str()); + return WmErrorCode::WM_ERROR_INVALID_PARAM; } ani_status ret {}; ani_ref fnRef {}; if ((ret = env->GlobalReference_Create(fn, &fnRef)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]create global ref fail"); - return WMError::WM_DO_NOTHING; + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Create fn global reference failed, ret: %{public}u", ret); + return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; }; ani_ref fnArgRef {}; if ((ret = env->GlobalReference_Create(fnArg, &fnArgRef)) != ANI_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]create global ref fail"); - return WMError::WM_DO_NOTHING; + env->GlobalReference_Delete(fnRef); + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Create fnArg global reference failed, ret: %{public}u}", ret); + return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; }; sptr extensionWindowListener = sptr::MakeSptr(env, fnRef, fnArgRef); extensionWindowListener->SetMainEventHandler(); - WMError retCode = ProcessRegister(caseType, extensionWindowListener, window, type, true); - if (retCode != WMError::WM_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Register type %{public}s failed", type.c_str()); + WmErrorCode retCode = ProcessRegister(caseType, extensionWindowListener, window, type, true); + if (retCode != WmErrorCode::WM_OK) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Register type %{public}s listener failed, ret: %{public}d", + type.c_str(), retCode); + env->GlobalReference_Delete(fnRef); + env->GlobalReference_Delete(fnArgRef); return retCode; } aniCbMap_[type][fnRef] = extensionWindowListener; - TLOGI(WmsLogTag::WMS_UIEXT, "[ANI]Register type %{public}s success! callback map size: %{public}zu", type.c_str(), - aniCbMap_[type].size()); - return WMError::WM_OK; + TLOGI(WmsLogTag::WMS_UIEXT, "[ANI]Register type %{public}s listener success! callback map size: %{public}zu", + type.c_str(), aniCbMap_[type].size()); + return WmErrorCode::WM_OK; } -WMError AniExtensionWindowRegisterManager::UnregisterListener(sptr window, std::string type, +WmErrorCode AniExtensionWindowRegisterManager::UnregisterListener(sptr window, const std::string& type, CaseType caseType, ani_env* env, ani_object fn) { std::lock_guard lock(mtx_); if (aniCbMap_.empty() || aniCbMap_.find(type) == aniCbMap_.end()) { - TLOGE(WmsLogTag::WMS_UIEXT, "[NAPI]Type %{public}s was not registered", type.c_str()); - return WMError::WM_DO_NOTHING; + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Type %{public}s listener was not registered", type.c_str()); + return WmErrorCode::WM_ERROR_INVALID_PARAM; } if (listenerCodeMap_[caseType].count(type) == 0) { - TLOGE(WmsLogTag::WMS_UIEXT, "[NAPI]Type %{public}s is not supported", type.c_str()); - return WMError::WM_DO_NOTHING; + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Type %{public}s listener is not supported", type.c_str()); + return WmErrorCode::WM_ERROR_INVALID_PARAM; } - if (fn == nullptr) { + ani_boolean isUndefined = ANI_FALSE; + env->Reference_IsUndefined(static_cast(fn), &isUndefined); + if (isUndefined == ANI_TRUE) { + TLOGI(WmsLogTag::WMS_UIEXT, "[ANI]Unregister all callback, type: %{public}s", type.c_str()); for (auto it = aniCbMap_[type].begin(); it != aniCbMap_[type].end();) { - WMError ret = ProcessRegister(caseType, it->second, window, type, false); - if (ret != WMError::WM_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Unregister type %{public}s failed, no value", type.c_str()); + WmErrorCode ret = ProcessRegister(caseType, it->second, window, type, false); + if (ret != WmErrorCode::WM_OK) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Unregister type %{public}s listener failed, ret: %{public}d", + type.c_str(), ret); return ret; } + env->GlobalReference_Delete(it->second->GetAniCallback()); + it->second->SetAniCallback(nullptr); aniCbMap_[type].erase(it++); } } else { bool findFlag = false; for (auto it = aniCbMap_[type].begin(); it != aniCbMap_[type].end(); ++it) { - sptr oldListener= it->second; - bool isSame = oldListener->IsSameRef(fn); - if (!isSame) { + ani_ref callback = static_cast(fn); + ani_boolean isEqual = ANI_FALSE; + env->Reference_StrictEquals(callback, it->first, &isEqual); + if (!isEqual) { continue; } findFlag = true; - WMError ret = ProcessRegister(caseType, it->second, window, type, false); - if (ret != WMError::WM_OK) { - TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Unregister type %{public}s failed", type.c_str()); + WmErrorCode ret = ProcessRegister(caseType, it->second, window, type, false); + if (ret != WmErrorCode::WM_OK) { + TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]Unregister type %{public}s listener failed, ret: %{public}d", + type.c_str(), ret); return ret; } + env->GlobalReference_Delete(it->second->GetAniCallback()); + it->second->SetAniCallback(nullptr); aniCbMap_[type].erase(it); break; } if (!findFlag) { TLOGE(WmsLogTag::WMS_UIEXT, - "[NAPI]Unregister type %{public}s failed because not found callback!", type.c_str()); - return WMError::WM_DO_NOTHING; + "[ANI]Unregister type %{public}s listener failed because not found callback!", type.c_str()); + return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; } } - TLOGI(WmsLogTag::WMS_UIEXT, "[NAPI]Unregister type %{public}s success! callback map size: %{public}zu", + TLOGI(WmsLogTag::WMS_UIEXT, "[ANI]Unregister type %{public}s listener success! callback map size: %{public}zu", type.c_str(), aniCbMap_[type].size()); // erase type when there is no callback in one type if (aniCbMap_[type].empty()) { aniCbMap_.erase(type); } - return WMError::WM_OK; + return WmErrorCode::WM_OK; } -WMError AniExtensionWindowRegisterManager::ProcessRegister(CaseType caseType, +WmErrorCode AniExtensionWindowRegisterManager::ProcessRegister(CaseType caseType, const sptr& listener, const sptr& window, const std::string& type, bool isRegister) { - WMError ret = WMError::WM_OK; + WmErrorCode ret = WmErrorCode::WM_OK; if (caseType == CaseType::CASE_WINDOW) { switch (listenerCodeMap_[caseType][type]) { case ListenerType::WINDOW_SIZE_CHANGE_CB: diff --git a/interfaces/kits/ani/screen_runtime/screen_ani/include/screen_ani_listener.h b/interfaces/kits/ani/screen_runtime/screen_ani/include/screen_ani_listener.h index ffdf74b22e87e21f1c8d27d3c77bacb2c7d1b52c..a8762836ead4823eefa66fe9374e4d64c59647a7 100644 --- a/interfaces/kits/ani/screen_runtime/screen_ani/include/screen_ani_listener.h +++ b/interfaces/kits/ani/screen_runtime/screen_ani/include/screen_ani_listener.h @@ -17,6 +17,7 @@ #define OHOS_ANI_SCREEN_LISTENER_H #include + #include "ani.h" #include "event_handler.h" #include "screen_manager.h" diff --git a/interfaces/kits/ani/screen_runtime/screen_ani/include/screen_ani_manager.h b/interfaces/kits/ani/screen_runtime/screen_ani/include/screen_ani_manager.h index 8aa66c0ab4385af85b3c5390c80e02a2ea927e26..88a5c878edfa3c5c2782ec4ddb4c14e84cb6a73c 100644 --- a/interfaces/kits/ani/screen_runtime/screen_ani/include/screen_ani_manager.h +++ b/interfaces/kits/ani/screen_runtime/screen_ani/include/screen_ani_manager.h @@ -16,12 +16,12 @@ #define SCREEN_MANAGER_ANI_H #include -#include "dm_common.h" -#include "refbase.h" -#include "screen_manager.h" #include "ani.h" +#include "dm_common.h" +#include "refbase.h" #include "screen_ani_listener.h" +#include "screen_manager.h" namespace OHOS { namespace Rosen { diff --git a/interfaces/kits/ani/screen_runtime/screen_ani/include/screen_ani_utils.h b/interfaces/kits/ani/screen_runtime/screen_ani/include/screen_ani_utils.h index f5923bb245657d2944f11a819b8526dda2aa900e..f8441075f07afe85db07b3d7d96ef6a5d95abef1 100644 --- a/interfaces/kits/ani/screen_runtime/screen_ani/include/screen_ani_utils.h +++ b/interfaces/kits/ani/screen_runtime/screen_ani/include/screen_ani_utils.h @@ -14,6 +14,7 @@ */ #ifndef OHOS_ANI_SCREEN_UTILS_H #define OHOS_ANI_SCREEN_UTILS_H + #include #include "ani.h" diff --git a/interfaces/kits/ani/screen_runtime/screen_ani/src/ani_err_utils.cpp b/interfaces/kits/ani/screen_runtime/screen_ani/src/ani_err_utils.cpp index 47ace25c35e7aac826c91945ea4a2d27b6fcd76b..4c6b2b4fb418998e48f2d161dcfd735098a309b3 100644 --- a/interfaces/kits/ani/screen_runtime/screen_ani/src/ani_err_utils.cpp +++ b/interfaces/kits/ani/screen_runtime/screen_ani/src/ani_err_utils.cpp @@ -14,10 +14,12 @@ */ #include "ani_err_utils.h" + +#include + #include "screen_ani_utils.h" #include "window_manager_hilog.h" -#include namespace OHOS::Rosen { constexpr const char* DM_ERROR_MSG_OK = "ok"; diff --git a/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_listener.cpp b/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_listener.cpp index cfb53b02b25221f3468fce81326cd2081914dac5..2ba1df85c99aabd1313024c4fc03ff6b8b69bef3 100644 --- a/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_listener.cpp +++ b/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_listener.cpp @@ -12,9 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "screen_ani_listener.h" -#include "window_manager_hilog.h" + #include "screen_ani_utils.h" +#include "window_manager_hilog.h" namespace OHOS { namespace Rosen { diff --git a/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_manager.cpp b/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_manager.cpp index d85a86fb176f326cd39900988b9d250e689880b8..9c592b27f1cd0c2d2333b36e769032ef6ab5ccd1 100644 --- a/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_manager.cpp +++ b/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_manager.cpp @@ -12,18 +12,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include + +#include "screen_ani_manager.h" + #include +#include #include "ani.h" -#include "singleton_container.h" -#include "window_manager_hilog.h" +#include "ani_err_utils.h" #include "dm_common.h" #include "refbase.h" -#include "screen_ani_manager.h" -#include "screen_ani_utils.h" #include "screen_ani_listener.h" -#include "ani_err_utils.h" +#include "screen_ani_utils.h" +#include "singleton_container.h" +#include "window_manager_hilog.h" namespace OHOS { namespace Rosen { diff --git a/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_utils.cpp b/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_utils.cpp index ca04305b279f118ad2e14d629e942e9767ef8932..2cf382606bc53193ed270e924dc3c6731d512cef 100644 --- a/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_utils.cpp +++ b/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_utils.cpp @@ -13,16 +13,17 @@ * limitations under the License. */ +#include "screen_ani_utils.h" + #include #include "ani.h" -#include "screen_ani_utils.h" +#include "dm_common.h" +#include "refbase.h" #include "screen.h" -#include "singleton_container.h" #include "screen_manager.h" +#include "singleton_container.h" #include "window_manager_hilog.h" -#include "dm_common.h" -#include "refbase.h" namespace OHOS { namespace Rosen { diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_register_manager.h b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_register_manager.h index 46aa3ce85476d81a3a4fa1e7b4494575b870b912..b496834588d57a31a31de4f433b4dd7ea02a2e7b 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_register_manager.h +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_register_manager.h @@ -18,6 +18,7 @@ #include #include + #include "ani_window_listener.h" #include "refbase.h" #include "window.h" diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_utils.h b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_utils.h index dc1d86b114d07737bb4bdc6bebd2780d8dab1ba5..adccd25237afb764df6478f64523c4a50cce6e9d 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_utils.h +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_utils.h @@ -15,7 +15,9 @@ #ifndef OHOS_JS_WINDOW_UTILS_H #define OHOS_JS_WINDOW_UTILS_H + #include + #include "ani.h" #include "native_engine/native_engine.h" #include "native_engine/native_value.h" diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_err_utils.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_err_utils.cpp index e30755d2d046a792cc8eb4e9bbbeed3d8b9fdd2f..c984078fc4820418fb9b3ddb38268f233157d2bd 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_err_utils.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_err_utils.cpp @@ -14,10 +14,12 @@ */ #include "ani_err_utils.h" + +#include + #include "ani_window_utils.h" #include "window_manager_hilog.h" -#include namespace OHOS::Rosen { constexpr const char* WM_ERROR_MSG_OK = "ok"; diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window.cpp index db50789cbd6a8789a266a20093056cf95196fac4..3abd7b97578b9e7aef1d302ec92af05df12c458d 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ - #include "ani_window.h" #include @@ -23,9 +22,9 @@ #include "ani_err_utils.h" #include "ani_window_utils.h" #include "window_helper.h" -#include "window_scene.h" #include "window_manager.h" #include "window_manager_hilog.h" +#include "window_scene.h" #include "wm_common.h" using OHOS::Rosen::WindowScene; diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_manager.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_manager.cpp index eb1ca962abb58b3a332d0fa87e10608784ae1476..f8d18dc151c87943894ece8432d59f4c9da461a8 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_manager.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_manager.cpp @@ -18,10 +18,10 @@ #include #include "ani.h" -#include "window_scene.h" -#include "window_manager_hilog.h" -#include "ani_window_utils.h" #include "ani_window.h" +#include "ani_window_utils.h" +#include "window_manager_hilog.h" +#include "window_scene.h" namespace OHOS { namespace Rosen { diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_register_manager.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_register_manager.cpp index ec1762ff5f3fe2f672a56295c938527e866f9c27..9fe4c446be79c751fc1dd549108c4853c9050427 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_register_manager.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_register_manager.cpp @@ -14,6 +14,7 @@ */ #include "ani_window_register_manager.h" + #include "singleton_container.h" #include "window_manager.h" #include "window_manager_hilog.h" diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage.cpp index 21cb29abf849a483b083e8d4d422ddf08b6e57eb..a022dc288e9496c66ed0ff06a387175c2c724f31 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ - #include "ani_window_stage.h" #include @@ -22,8 +21,8 @@ #include "ani_window.h" #include "ani_window_manager.h" #include "ani_window_utils.h" -#include "window_manager_hilog.h" #include "permission.h" +#include "window_manager_hilog.h" #include "window_scene.h" using OHOS::Rosen::WindowScene; diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp index 2d50c99e3d3eeec2c3ee4bcf6f7e7bf8debe6dc2..caa5b4f67306bb1e1ba5a10fe799af0e88db2f24 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "ani_window_utils.h" #include @@ -23,8 +24,8 @@ #include "ani_window.h" #include "bundle_constants.h" #include "ipc_skeleton.h" -#include "window_manager_hilog.h" #include "ui_content.h" +#include "window_manager_hilog.h" namespace OHOS { namespace Rosen { diff --git a/interfaces/kits/cj/display_runtime/cj_display_manager.cpp b/interfaces/kits/cj/display_runtime/cj_display_manager.cpp index 02d30e16dc03f5c97e09db876f29c9b628583c35..0480dd9b38df446e92537fb1656da5329be38609 100644 --- a/interfaces/kits/cj/display_runtime/cj_display_manager.cpp +++ b/interfaces/kits/cj/display_runtime/cj_display_manager.cpp @@ -224,18 +224,18 @@ bool CJDisplayManager::IsCaptured() static void SetDisplayPhysicalResolutionObject(DisplayPhysicalResolution& resolution, RetStruct& ret) { - DisplayPhysicalResolution* dataPtr = static_cast(ret.data); - dataPtr[ret.len].foldDisplayMode_ = resolution.foldDisplayMode_; - dataPtr[ret.len].physicalWidth_ = resolution.physicalWidth_; - dataPtr[ret.len].physicalHeight_ = resolution.physicalHeight_; + CDisplayPhysicalResolution* dataPtr = static_cast(ret.data); + dataPtr[ret.len].foldDisplayMode = static_cast(resolution.foldDisplayMode_); + dataPtr[ret.len].physicalWidth = resolution.physicalWidth_; + dataPtr[ret.len].physicalHeight = resolution.physicalHeight_; ret.len++; } static void SetDisplayPhysicalResolutionArrayObject( std::vector& resolutionList, RetStruct& ret) { - DisplayPhysicalResolution* resolutions = - static_cast(malloc(sizeof(DisplayPhysicalResolution) * resolutionList.size())); + CDisplayPhysicalResolution* resolutions = + static_cast(malloc(sizeof(CDisplayPhysicalResolution) * resolutionList.size())); if (resolutions == nullptr) { TLOGE(WmsLogTag::DMS, "[SetDisplayPhysicalResolutionArrayObject] ERROR Failed to create display physical resolution list."); diff --git a/interfaces/kits/cj/display_runtime/display_utils.h b/interfaces/kits/cj/display_runtime/display_utils.h index c937e4dedd8c57b3f29d155924e110675c2e4f49..d6952f0997e008700cd8c3eece54e5ee20d884c6 100644 --- a/interfaces/kits/cj/display_runtime/display_utils.h +++ b/interfaces/kits/cj/display_runtime/display_utils.h @@ -29,6 +29,12 @@ typedef struct { void* data; } RetStruct; +typedef struct { + uint32_t foldDisplayMode; + uint32_t physicalWidth; + uint32_t physicalHeight; +} CDisplayPhysicalResolution; + typedef struct { int32_t left; int32_t top; diff --git a/interfaces/kits/napi/display_runtime/js_display_manager.cpp b/interfaces/kits/napi/display_runtime/js_display_manager.cpp index 489cbd54ddf4230dd9bb27d2e34f334af13ea0f0..4092f88e1ad3bfe9f331e6c93669c3e87d5d16a4 100644 --- a/interfaces/kits/napi/display_runtime/js_display_manager.cpp +++ b/interfaces/kits/napi/display_runtime/js_display_manager.cpp @@ -867,11 +867,18 @@ napi_value OnSetFoldDisplayMode(napi_env env, napi_callback_info info) return NapiGetUndefined(env); } } - DmErrorCode errCode = DM_JS_TO_ERROR_CODE_MAP.at( - SingletonContainer::Get().SetFoldDisplayModeFromJs(mode, reason)); - TLOGI(WmsLogTag::DMS, "[NAPI]%{public}d", static_cast(errCode)); + DMError dmError = SingletonContainer::Get().SetFoldDisplayModeFromJs(mode, reason); + std::string errMsg = ""; + if (DM_ERROR_JS_TO_ERROR_MESSAGE_MAP.find(dmError) != DM_ERROR_JS_TO_ERROR_MESSAGE_MAP.end()) { + errMsg = DM_ERROR_JS_TO_ERROR_MESSAGE_MAP.at(dmError); + } + DmErrorCode errCode = DmErrorCode::DM_ERROR_SYSTEM_INNORMAL; + if (DM_JS_TO_ERROR_CODE_MAP.find(dmError) != DM_JS_TO_ERROR_CODE_MAP.end()) { + errCode = DM_JS_TO_ERROR_CODE_MAP.at(dmError); + } + TLOGI(WmsLogTag::DMS, "[NAPI]%{public}d, error message: %{public}s", static_cast(errCode), errMsg.c_str()); if (errCode != DmErrorCode::DM_OK) { - napi_throw(env, JsErrUtils::CreateJsError(env, errCode)); + napi_throw(env, JsErrUtils::CreateJsError(env, errCode, errMsg)); return NapiGetUndefined(env); } return NapiGetUndefined(env); diff --git a/interfaces/kits/napi/extension_window/js_extension_window.cpp b/interfaces/kits/napi/extension_window/js_extension_window.cpp index 7a6ac2f89827ac30f63e1473d29e9d4bdaf331dd..118d7a871a14983bf436ac45f628593f2fd2f8a1 100644 --- a/interfaces/kits/napi/extension_window/js_extension_window.cpp +++ b/interfaces/kits/napi/extension_window/js_extension_window.cpp @@ -1118,108 +1118,162 @@ napi_value JsExtensionWindow::OnUnRegisterExtensionWindowCallback(napi_env env, napi_value JsExtensionWindow::OnHideNonSecureWindows(napi_env env, napi_callback_info info) { + napi_value result = nullptr; + std::shared_ptr napiAsyncTask = CreateEmptyAsyncTask(env, nullptr, &result); if (extensionWindow_ == nullptr) { TLOGE(WmsLogTag::WMS_UIEXT, "extensionWindow_ is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][hideNonSecureWindows]msg: extensionWindow_ is nullptr")); + return result; } sptr windowImpl = extensionWindow_->GetWindow(); if (windowImpl == nullptr) { TLOGE(WmsLogTag::WMS_UIEXT, "windowImpl is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][hideNonSecureWindows]msg: windowImpl is nullptr")); + return result; } 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_UIEXT, "Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][hideNonSecureWindows]msg: Argc is invalid"); } bool shouldHide = false; if (!ConvertFromJsValue(env, argv[0], shouldHide)) { TLOGE(WmsLogTag::WMS_UIEXT, "Failed to convert parameter to bool"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][hideNonSecureWindows]msg: Failed to convert parameter to bool"); } - WmErrorCode ret = WmErrorCode::WM_OK; - ret = WM_JS_TO_ERROR_CODE_MAP.at(extensionWindow_->HideNonSecureWindows(shouldHide)); - if (ret != WmErrorCode::WM_OK) { - return NapiThrowError(env, ret); + auto ret = WM_JS_TO_ERROR_CODE_MAP.at(extensionWindow_->HideNonSecureWindows(shouldHide)); + const char* const where = __func__; + auto asyncTask = [where, env, ret, task = napiAsyncTask]() mutable { + if (ret == WmErrorCode::WM_OK) { + task->Resolve(env, NapiGetUndefined(env)); + } else { + TLOGNE(WmsLogTag::WMS_UIEXT, "%{public}s failed, code: %{public}d", where, ret); + task->Reject(env, CreateJsError(env, static_cast(ret), + "[window][hideNonSecureWindows]msg: hideNonSecureWindows failed")); + } + }; + if (napi_send_event(env, asyncTask, napi_eprio_high, "OnHideNonSecureWindows") != napi_status::napi_ok) { + napiAsyncTask->Reject(env, + CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][hideNonSecureWindows]msg: Failed to send event")); } TLOGI(WmsLogTag::WMS_UIEXT, "end, window [%{public}u, %{public}s], shouldHide:%{public}u", windowImpl->GetWindowId(), windowImpl->GetWindowName().c_str(), shouldHide); - return NapiGetUndefined(env); + return result; } napi_value JsExtensionWindow::OnSetWaterMarkFlag(napi_env env, napi_callback_info info) { + napi_value result = nullptr; + std::shared_ptr napiAsyncTask = CreateEmptyAsyncTask(env, nullptr, &result); if (extensionWindow_ == nullptr) { TLOGE(WmsLogTag::WMS_UIEXT, "extensionWindow_ is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][setWaterMarkFlag]msg: extensionWindow_ is nullptr")); + return result; } sptr windowImpl = extensionWindow_->GetWindow(); if (windowImpl == nullptr) { TLOGE(WmsLogTag::WMS_UIEXT, "windowImpl is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][setWaterMarkFlag]msg: windowImpl is nullptr")); + return result; } 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_UIEXT, "Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setWaterMarkFlag]msg: Argc is invalid"); } bool isEnable = false; if (!ConvertFromJsValue(env, argv[0], isEnable)) { TLOGE(WmsLogTag::WMS_UIEXT, "Failed to convert parameter to bool"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setWaterMarkFlag]msg: Failed to convert parameter to bool"); } - WmErrorCode ret = WmErrorCode::WM_OK; - ret = WM_JS_TO_ERROR_CODE_MAP.at(extensionWindow_->SetWaterMarkFlag(isEnable)); - if (ret != WmErrorCode::WM_OK) { - return NapiThrowError(env, ret); + auto ret = WM_JS_TO_ERROR_CODE_MAP.at(extensionWindow_->SetWaterMarkFlag(isEnable)); + const char* const where = __func__; + auto asyncTask = [where, env, ret, task = napiAsyncTask]() mutable { + if (ret == WmErrorCode::WM_OK) { + task->Resolve(env, NapiGetUndefined(env)); + } else { + TLOGNE(WmsLogTag::WMS_UIEXT, "%{public}s failed, code: %{public}d", where, ret); + task->Reject(env, CreateJsError(env, static_cast(ret), + "[window][setWaterMarkFlag]msg: setWaterMarkFlag failed")); + } + }; + if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetWaterMarkFlag") != napi_status::napi_ok) { + napiAsyncTask->Reject(env, + CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][setWaterMarkFlag]msg: Failed to send event")); } TLOGI(WmsLogTag::WMS_UIEXT, "end, window [%{public}u, %{public}s], isEnable:%{public}u.", windowImpl->GetWindowId(), windowImpl->GetWindowName().c_str(), isEnable); - return NapiGetUndefined(env); + return result; } napi_value JsExtensionWindow::OnHidePrivacyContentForHost(napi_env env, napi_callback_info info) { + napi_value result = nullptr; + std::shared_ptr napiAsyncTask = CreateEmptyAsyncTask(env, nullptr, &result); if (extensionWindow_ == nullptr) { - TLOGE(WmsLogTag::WMS_UIEXT, "extension window is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + TLOGE(WmsLogTag::WMS_UIEXT, "extensionWindow_ is nullptr"); + napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][hidePrivacyContentForHost]msg: extensionWindow_ is nullptr")); + return result; } - sptr windowImpl = extensionWindow_->GetWindow(); if (windowImpl == nullptr) { TLOGE(WmsLogTag::WMS_UIEXT, "windowImpl is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][hidePrivacyContentForHost]msg: windowImpl is nullptr")); + return result; } - 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_UIEXT, "Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][hidePrivacyContentForHost]msg: Argc is invalid"); } - bool needHide = false; if (!ConvertFromJsValue(env, argv[0], needHide)) { TLOGE(WmsLogTag::WMS_UIEXT, "Failed to convert parameter to bool"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][hidePrivacyContentForHost]msg: Failed to convert parameter to bool"); } auto ret = WM_JS_TO_ERROR_CODE_MAP.at(extensionWindow_->HidePrivacyContentForHost(needHide)); - if (ret != WmErrorCode::WM_OK) { - return NapiThrowError(env, ret); + const char* const where = __func__; + auto asyncTask = [where, env, ret, task = napiAsyncTask]() mutable { + if (ret == WmErrorCode::WM_OK) { + task->Resolve(env, NapiGetUndefined(env)); + } else { + TLOGNE(WmsLogTag::WMS_UIEXT, "%{public}s failed, code: %{public}d", where, ret); + task->Reject(env, CreateJsError(env, static_cast(ret), + "[window][hidePrivacyContentForHost]msg: hidePrivacyContentForHost failed")); + } + }; + if (napi_send_event(env, asyncTask, napi_eprio_high, "OnHidePrivacyContentForHost") != napi_status::napi_ok) { + napiAsyncTask->Reject(env, + CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][hidePrivacyContentForHost]msg: Failed to send event")); } TLOGI(WmsLogTag::WMS_UIEXT, "finished, window [%{public}u, %{public}s], needHide:%{public}u.", windowImpl->GetWindowId(), windowImpl->GetWindowName().c_str(), needHide); - - return NapiGetUndefined(env); + return result; } napi_value JsExtensionWindow::GetProperties(napi_env env, napi_callback_info info) diff --git a/interfaces/kits/napi/floating_ball_napi/BUILD.gn b/interfaces/kits/napi/floating_ball_napi/BUILD.gn index 8c54543ec6767f183bceb66b253b1b2c26f55a98..de41552158dd946f7dd9c068d1881462be2b4ea2 100644 --- a/interfaces/kits/napi/floating_ball_napi/BUILD.gn +++ b/interfaces/kits/napi/floating_ball_napi/BUILD.gn @@ -50,6 +50,7 @@ ohos_shared_library("floatingball_napi") { external_deps = [ "ability_runtime:ability_context_native", "ability_runtime:abilitykit_native", + "ability_runtime:napi_common", "ability_runtime:runtime", "c_utils:utils", "hilog:libhilog", diff --git a/interfaces/kits/napi/floating_ball_napi/js_fb_window_controller.cpp b/interfaces/kits/napi/floating_ball_napi/js_fb_window_controller.cpp index e33cc2e71b678343991d4927f7bb4c7bf2236fbb..c978343593bb99bc2d7a720a852c6f593cfb9068 100644 --- a/interfaces/kits/napi/floating_ball_napi/js_fb_window_controller.cpp +++ b/interfaces/kits/napi/floating_ball_napi/js_fb_window_controller.cpp @@ -363,40 +363,40 @@ napi_value JsFbController::CheckParams(napi_env env, const FbOption& option) { if (option.GetTemplate() < static_cast(FloatingBallTemplate::STATIC) || option.GetTemplate() >= static_cast(FloatingBallTemplate::END)) { - TLOGE(WmsLogTag::WMS_SYSTEM, "template %{public}d is invalid.", option.GetTemplate()); + TLOGE(WmsLogTag::WMS_SYSTEM, "Template %{public}d is invalid", option.GetTemplate()); napi_throw(env, AbilityRuntime::CreateJsError(env, - static_cast(WmErrorCode::WM_ERROR_FB_PARAM_INVALID), "template is invalid.")); + static_cast(WmErrorCode::WM_ERROR_FB_PARAM_INVALID), "Template is invalid.")); return nullptr; } if (option.GetTitle().length() < TITLE_MIN_LEN || option.GetTitle().length() > TITLE_MAX_LEN) { - TLOGE(WmsLogTag::WMS_SYSTEM, "title length Exceed the limit %{public}zu.", option.GetTitle().length()); + TLOGE(WmsLogTag::WMS_SYSTEM, "Title length Exceed the limit %{public}zu", option.GetTitle().length()); napi_throw(env, AbilityRuntime::CreateJsError(env, - static_cast(WmErrorCode::WM_ERROR_FB_PARAM_INVALID), "title length Exceed the limit")); + static_cast(WmErrorCode::WM_ERROR_FB_PARAM_INVALID), "Title length Exceed the limit")); return nullptr; } if (option.GetContent().length() > CONTENT_MAX_LEN) { - TLOGE(WmsLogTag::WMS_SYSTEM, "content length Exceed the limit %{public}zu.", option.GetContent().length()); + TLOGE(WmsLogTag::WMS_SYSTEM, "Content length Exceed the limit %{public}zu", option.GetContent().length()); napi_throw(env, AbilityRuntime::CreateJsError(env, - static_cast(WmErrorCode::WM_ERROR_FB_PARAM_INVALID), "content length Exceed the limit")); + static_cast(WmErrorCode::WM_ERROR_FB_PARAM_INVALID), "Content length Exceed the limit")); return nullptr; } if (option.GetIcon() != nullptr && option.GetIcon()->GetByteCount() > PIXEL_MAP_MAX_SIZE) { - TLOGE(WmsLogTag::WMS_SYSTEM, "icon size Exceed the limit %{public}d.", option.GetIcon()->GetByteCount()); + TLOGE(WmsLogTag::WMS_SYSTEM, "Icon size Exceed the limit %{public}d", option.GetIcon()->GetByteCount()); napi_throw(env, AbilityRuntime::CreateJsError(env, - static_cast(WmErrorCode::WM_ERROR_FB_PARAM_INVALID), "icon size Exceed the limit")); + static_cast(WmErrorCode::WM_ERROR_FB_PARAM_INVALID), "Icon size Exceed the limit")); return nullptr; } if (!option.GetBackgroundColor().empty() && !ColorParser::IsValidColorNoAlpha(option.GetBackgroundColor())) { - TLOGE(WmsLogTag::WMS_SYSTEM, "backgroundColor is invalid %{public}s.", option.GetBackgroundColor().c_str()); + TLOGE(WmsLogTag::WMS_SYSTEM, "BackgroundColor is invalid"); napi_throw(env, AbilityRuntime::CreateJsError(env, - static_cast(WmErrorCode::WM_ERROR_FB_PARAM_INVALID), "backgroundColor is invalid")); + static_cast(WmErrorCode::WM_ERROR_FB_PARAM_INVALID), "BackgroundColor is invalid")); return nullptr; } if (option.GetTemplate() == static_cast(FloatingBallTemplate::STATIC) && option.GetIcon() == nullptr) { - TLOGE(WmsLogTag::WMS_SYSTEM, "template %{public}u need icon.", option.GetTemplate()); + TLOGE(WmsLogTag::WMS_SYSTEM, "Template %{public}u need icon", option.GetTemplate()); napi_throw(env, AbilityRuntime::CreateJsError(env, - static_cast(WmErrorCode::WM_ERROR_FB_PARAM_INVALID), "current template need icon")); + static_cast(WmErrorCode::WM_ERROR_FB_PARAM_INVALID), "Current template need icon")); return nullptr; } return NapiGetUndefined(env); diff --git a/interfaces/kits/napi/floating_ball_napi/js_fb_window_manager.cpp b/interfaces/kits/napi/floating_ball_napi/js_fb_window_manager.cpp index c8dd74c7d2a60507f0551b87f40b9baf867157bb..cee8ae4ab94f4688fd945c141f350b12543454e9 100644 --- a/interfaces/kits/napi/floating_ball_napi/js_fb_window_manager.cpp +++ b/interfaces/kits/napi/floating_ball_napi/js_fb_window_manager.cpp @@ -94,6 +94,10 @@ napi_value JsFbWindowManager::NapiSendTask(napi_env env, void* contextPtr) *errCodePtr = WmErrorCode::WM_ERROR_FB_INTERNAL_ERROR; return; } + if (fbController == nullptr) { + *errCodePtr = WmErrorCode::WM_ERROR_FB_INTERNAL_ERROR; + return; + } fbController->UpdateMainWindow(mainWindow); }; NapiAsyncTask::CompleteCallback complete = 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 aa2d6ad6a44a937531517ac9c16a20801724edcb..335831a2fdf8b316da03993f154be603519a58f9 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 @@ -674,18 +674,21 @@ napi_value JsWindowManager::OnGetSnapshot(napi_env env, napi_callback_info info) NapiAsyncTask::CompleteCallback complete = [=](napi_env env, NapiAsyncTask& task, int32_t status) { if (dataPack->result != WMError::WM_OK) { - task.Reject(env, JsErrUtils::CreateJsError(env, WM_JS_TO_ERROR_CODE_MAP.at(dataPack->result))); + task.Reject(env, JsErrUtils::CreateJsError(env, WM_JS_TO_ERROR_CODE_MAP.at(dataPack->result), + "[window][getSnapshot]msg: get snapshot failed")); TLOGNW(WmsLogTag::WMS_SYSTEM, "Get snapshot not ok!"); return; } if (dataPack->pixelMap == nullptr) { - task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getSnapshot]msg: pixel map is invalid")); TLOGNE(WmsLogTag::WMS_SYSTEM, "Get snapshot is nullptr!"); return; } auto nativePixelMap = Media::PixelMapNapi::CreatePixelMap(env, dataPack->pixelMap); if (nativePixelMap == nullptr) { - task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getSnapshot]msg: create native pixel map failed")); TLOGNE(WmsLogTag::WMS_SYSTEM, "Create native pixelmap is nullptr!"); return; } @@ -782,7 +785,8 @@ napi_value JsWindowManager::OnFindWindowSync(napi_env env, napi_callback_info in } else { sptr window = Window::Find(windowName); if (window == nullptr) { - napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][findWindow]msg: Window is nullptr.")); return NapiGetUndefined(env); } else { return CreateJsWindowObject(env, window); @@ -894,7 +898,7 @@ napi_value JsWindowManager::OnRegisterWindowManagerCallback(napi_env env, napi_c WmErrorCode ret = registerManager_->RegisterListener(nullptr, cbType, CaseType::CASE_WINDOW_MANAGER, env, value); if (ret != WmErrorCode::WM_OK) { - napi_throw(env, JsErrUtils::CreateJsError(env, ret)); + napi_throw(env, JsErrUtils::CreateJsError(env, ret, "[window][on]msg: register " + cbType + " failed")); return NapiGetUndefined(env); } TLOGD(WmsLogTag::DEFAULT, "Register end, type=%{public}s", cbType.c_str()); @@ -932,7 +936,7 @@ napi_value JsWindowManager::OnUnregisterWindowManagerCallback(napi_env env, napi } } if (ret != WmErrorCode::WM_OK) { - napi_throw(env, JsErrUtils::CreateJsError(env, ret)); + napi_throw(env, JsErrUtils::CreateJsError(env, ret, "[window][off]msg: unregister " + cbType + " failed")); return NapiGetUndefined(env); } TLOGD(WmsLogTag::DEFAULT, "Unregister end, type=%{public}s", cbType.c_str()); @@ -1151,13 +1155,15 @@ napi_value JsWindowManager::OnSetGestureNavigationEnabled(napi_env env, napi_cal task->Resolve(env, NapiGetUndefined(env)); WLOGD("SetGestureNavigationEnabled success"); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "SetGestureNavigationEnabled failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][setGestureNavigationEnabled]msg: set gesture navigation failed")); } }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetGestureNavigationEnabled") != napi_status::napi_ok) { TLOGE(WmsLogTag::WMS_IMMS, "napi_send_event failed"); napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setGestureNavigationEnabled]msg: failed to send event")); } return result; } @@ -1440,7 +1446,8 @@ napi_value JsWindowManager::OnGetTopNavDestinationName(napi_env env, napi_callba if (WM_JS_TO_ERROR_CODE_MAP.count(*errCodePtr) > 0) { retErrCode = WM_JS_TO_ERROR_CODE_MAP.at(*errCodePtr); } - task.Reject(env, JsErrUtils::CreateJsError(env, retErrCode)); + task.Reject(env, JsErrUtils::CreateJsError(env, retErrCode, + "[window][getTopNavDestinationName]msg: get top navigation name failed")); return; } TLOGNI(WmsLogTag::WMS_ATTRIBUTE, "%{public}s ok, topNavDestName: %{public}s, windowId: %{public}d", @@ -1584,8 +1591,8 @@ napi_value JsWindowManager::OnShiftAppWindowPointerEvent(napi_env env, napi_call }; napi_status status = napi_send_event(env, std::move(asyncTask), napi_eprio_high, "OnShiftAppWindowPointerEvent"); if (status != napi_status::napi_ok) { - napiAsyncTask->Reject(env, - CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][shiftAppWindowPointerEvent]msg:send event failed")); } return result; } 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 17b40ab4eed3fbf5a1e0db1bc86e8de59efdf567..bf783a9d9b06e44b8b1f922dacda91ade1cbfa1e 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -1359,7 +1359,8 @@ napi_value JsWindow::OnShowWindow(napi_env env, napi_callback_info info) auto asyncTask = [weakToken, env, task = napiAsyncTask, focusOnShow, isShowWithOptions] { auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][showWindow]msg: Window is nullptr.")); TLOGNE(WmsLogTag::WMS_LIFE, "window is nullptr or get invalid param"); return; } @@ -1386,7 +1387,7 @@ napi_value JsWindow::OnShowWindow(napi_env env, napi_callback_info info) task->Resolve(env, NapiGetUndefined(env)); } else { task->Reject(env, JsErrUtils::CreateJsError(env, WM_JS_TO_ERROR_CODE_MAP.at(ret), - "Window show failed")); + "[window][showWindow]msg: Window show failed.")); } TLOGNI(WmsLogTag::WMS_LIFE, "Window [%{public}u, %{public}s] show end, ret=%{public}d", weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); @@ -1513,7 +1514,8 @@ napi_value JsWindow::OnDestroyWindow(napi_env env, napi_callback_info info) auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { TLOGNE(WmsLogTag::WMS_LIFE, "window is nullptr or get invalid param"); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][destroyWindow]msg: Window is nullptr.")); return; } if (WindowHelper::IsMainWindow(weakWindow->GetType())) { @@ -1527,7 +1529,8 @@ napi_value JsWindow::OnDestroyWindow(napi_env env, napi_callback_info info) TLOGNI(WmsLogTag::WMS_LIFE, "%{public}s end, window [%{public}u, %{public}s] ret=%{public}d", where, weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); if (ret != WmErrorCode::WM_OK) { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Window destroy failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][destroyWindow]msg: Window destroy failed.")); return; } windowToken_ = nullptr; // ensure window dtor when finalizer invalid @@ -1565,7 +1568,8 @@ napi_value JsWindow::HideWindowFunction(napi_env env, napi_callback_info info, W auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { TLOGNE(WmsLogTag::WMS_LIFE, "window is nullptr or get invalid param"); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][hide]msg: Window is nullptr.")); return; } if (WindowHelper::IsMainWindow(weakWindow->GetType())) { @@ -1579,7 +1583,8 @@ napi_value JsWindow::HideWindowFunction(napi_env env, napi_callback_info info, W if (ret == WmErrorCode::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Window hide failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][hide]msg: Window hide failed.")); } TLOGNI(WmsLogTag::WMS_LIFE, "%{public}s end, window [%{public}u] ret=%{public}d", where, weakWindow->GetWindowId(), ret); @@ -1655,21 +1660,22 @@ napi_value JsWindow::OnRecover(napi_env env, napi_callback_info info) auto window = windowToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_LAYOUT_PC, "%{public}s window is nullptr", where); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][recover]msg: Window is nullptr")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->Recover(1)); if (ret == WmErrorCode::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Window recover failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, "[window][recover]msg: Failed")); } TLOGNI(WmsLogTag::WMS_LAYOUT_PC, "%{public}s end, window [%{public}u] ret=%{public}d", where, window->GetWindowId(), ret); }; if (napi_send_event(env, asyncTask, napi_eprio_immediate, "OnRecover") != napi_status::napi_ok) { napiAsyncTask->Reject(env, CreateJsError(env, - static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "[window][recover]msg: Send event failed")); } return result; } @@ -1788,7 +1794,8 @@ napi_value JsWindow::OnMoveWindowTo(napi_env env, napi_callback_info info) errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowTo]msg: Failed"); } // 2: params num; 2: index of callback napi_value lastParam = (argc <= 2) ? nullptr : @@ -1800,21 +1807,24 @@ napi_value JsWindow::OnMoveWindowTo(napi_env env, napi_callback_info info) auto window = windowToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_LAYOUT, "%{public}s: window is nullptr", where); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][moveWindowTo]msg: Window is nullptr")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->MoveTo(x, y)); if (ret == WmErrorCode::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Window move failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][moveWindowTo]msg: Move failed")); } TLOGND(WmsLogTag::WMS_LAYOUT, "%{public}s: window [%{public}u, %{public}s] ret=%{public}d", where, window->GetWindowId(), window->GetWindowName().c_str(), ret); }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnMoveWindowTo") != napi_status::napi_ok) { napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][moveWindowTo]msg: Failed to send event")); } return result; } @@ -1862,17 +1872,20 @@ napi_value JsWindow::OnMoveWindowToAsync(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc < 2) { // 2: minimum param num TLOGE(WmsLogTag::WMS_LAYOUT, "Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowToAsync]msg: Number of parameters is invalid"); } int32_t x = 0; if (!ConvertFromJsValue(env, argv[INDEX_ZERO], x)) { TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert parameter to x"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowToAsync]msg: Failed to convert parameter to x"); } int32_t y = 0; if (!ConvertFromJsValue(env, argv[INDEX_ONE], y)) { TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert parameter to y"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowToAsync]msg: Failed to convert parameter to y"); } MoveConfiguration moveConfiguration; size_t lastParamIndex = INDEX_TWO; @@ -1880,7 +1893,8 @@ napi_value JsWindow::OnMoveWindowToAsync(napi_env env, napi_callback_info info) lastParamIndex = INDEX_THREE; // MoveConfiguration is optional param if (!GetMoveConfigurationFromJsValue(env, argv[INDEX_TWO], moveConfiguration)) { TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert parameter to moveConfiguration"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowToAsync]msg: Failed to convert parameter to moveConfiguration"); } } NapiAsyncTask::ExecuteCallback execute; @@ -1941,25 +1955,29 @@ napi_value JsWindow::OnMoveWindowToGlobal(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc < 2) { // 2:minimum param num TLOGE(WmsLogTag::WMS_LAYOUT, "Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowToGlobal]msg: Number of parameters is invalid"); } int32_t x = 0; if (!ConvertFromJsValue(env, argv[INDEX_ZERO], x)) { TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert parameter to x"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowToGlobal]msg: Failed to convert parameter to x"); } int32_t y = 0; if (!ConvertFromJsValue(env, argv[INDEX_ONE], y)) { TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert parameter to y"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowToGlobal]msg: Failed to convert parameter to y"); } MoveConfiguration moveConfiguration; size_t lastParamIndex = INDEX_TWO; if (argc > TWO_PARAMS_SIZE && argv[INDEX_TWO] != nullptr && GetType(env, argv[INDEX_TWO]) == napi_object) { lastParamIndex = INDEX_THREE; // MoveConfiguration is optional param if (!GetMoveConfigurationFromJsValue(env, argv[INDEX_TWO], moveConfiguration)) { - TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert parameter to moveConfiguration and rectAnimationConfig"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert parameter to moveConfiguration"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowToGlobal]msg: Failed to convert parameter to moveConfiguration"); } } NapiAsyncTask::ExecuteCallback execute; @@ -1983,18 +2001,21 @@ napi_value JsWindow::OnMoveWindowToGlobalDisplay(napi_env env, napi_callback_inf napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != TWO_PARAMS_SIZE) { TLOGE(WmsLogTag::WMS_LAYOUT, "Invalid argc: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowToGlobalDisplay]msg: Invalid argc"); } int32_t x = 0; if (!ConvertFromJsValue(env, argv[INDEX_ZERO], x)) { TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert parameter to x"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowToGlobalDisplay]msg: Failed to convert parameter to x"); } int32_t y = 0; if (!ConvertFromJsValue(env, argv[INDEX_ONE], y)) { TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert parameter to y"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowToGlobalDisplay]msg: Failed to convert parameter to y"); } napi_value result = nullptr; @@ -2003,7 +2024,8 @@ napi_value JsWindow::OnMoveWindowToGlobalDisplay(napi_env env, napi_callback_inf auto window = windowToken.promote(); if (!window) { TLOGNE(WmsLogTag::WMS_LAYOUT, "%{public}s: window is nullptr", where); - napiAsyncTask->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + napiAsyncTask->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][moveWindowToGlobalDisplay]msg: Window is nullptr")); return; } auto moveResult = window->MoveWindowToGlobalDisplay(x, y); @@ -2012,7 +2034,8 @@ napi_value JsWindow::OnMoveWindowToGlobalDisplay(napi_env env, napi_callback_inf if (ret == WmErrorCode::WM_OK) { napiAsyncTask->Resolve(env, NapiGetUndefined(env)); } else { - napiAsyncTask->Reject(env, JsErrUtils::CreateJsError(env, ret, "Failed to move window")); + napiAsyncTask->Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][moveWindowToGlobalDisplay]msg: Failed to move window")); } TLOGNI(WmsLogTag::WMS_LAYOUT, "%{public}s: window: [%{public}u, %{public}s], x: %{public}d, y: %{public}d, ret: %{public}d", @@ -2020,7 +2043,8 @@ napi_value JsWindow::OnMoveWindowToGlobalDisplay(napi_env env, napi_callback_inf }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "Failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][moveWindowToGlobalDisplay]msg: Failed to send event")); } return result; } @@ -2042,7 +2066,8 @@ napi_value JsWindow::OnGetGlobalScaledRect(napi_env env, napi_callback_info info napi_value globalScaledRectObj = GetRectAndConvertToJsValue(env, globalScaledRect); if (globalScaledRectObj == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT, "globalScaledRectObj is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getGlobalScaledRect]msg: GlobalScaledRectObj is nullptr"); } return globalScaledRectObj; } @@ -2079,28 +2104,31 @@ napi_value JsWindow::OnResize(napi_env env, napi_callback_info info) auto asyncTask = [windowToken = wptr(windowToken_), errCode, width, height, env, task = napiAsyncTask, where = __func__] { if (errCode != WMError::WM_OK) { - task->Reject(env, JsErrUtils::CreateJsError(env, errCode)); + task->Reject(env, JsErrUtils::CreateJsError(env, errCode, "[window][resize]msg: Invalid param")); TLOGNE(WmsLogTag::WMS_LAYOUT, "%{public}s: invalid param", where); return; } auto window = windowToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_LAYOUT, "%{public}s: window is nullptr", where); - task->Reject(env, JsErrUtils::CreateJsError(env, WMError::WM_ERROR_NULLPTR)); + task->Reject(env, JsErrUtils::CreateJsError(env, WMError::WM_ERROR_NULLPTR, + "[window][resize]msg: Window is nullptr")); return; } WMError ret = window->Resize(static_cast(width), static_cast(height)); if (ret == WMError::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Window resize failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][resize]msg: Failed")); } TLOGND(WmsLogTag::WMS_LAYOUT, "%{public}s: end, window [%{public}u, %{public}s] ret=%{public}d", where, window->GetWindowId(), window->GetWindowName().c_str(), ret); }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnResize") != napi_status::napi_ok) { napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][resize]msg: Failed to send event")); } return result; } @@ -2225,7 +2253,8 @@ napi_value JsWindow::OnResizeWindowAsync(napi_env env, napi_callback_info info) errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][resizeWindowAsync]msg: Invalid param"); } wptr weakToken(windowToken_); @@ -2258,7 +2287,7 @@ static void SetResizeWindowWithAnimationAsyncTask(NapiAsyncTask::ExecuteCallback *errCodePtr = WmErrorCode::WM_ERROR_STATE_ABNORMALLY; return; } - *errCodePtr = WM_JS_TO_ERROR_CODE_MAP.at(window->ResizeAsync(rect.width_, rect.height_, rectAnimationConfig)); + *errCodePtr = WM_JS_TO_ERROR_CODE_MAP.at(window->ResizeAsync(rect.width_, rect.height_)); TLOGND(WmsLogTag::WMS_LAYOUT, "%{public}s end, window [%{public}u, %{public}s] err=%{public}d", where, window->GetWindowId(), window->GetWindowName().c_str(), *errCodePtr); }; @@ -2455,7 +2484,8 @@ napi_value JsWindow::OnSetWindowMode(napi_env env, napi_callback_info info) { if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) { TLOGE(WmsLogTag::WMS_LAYOUT, "permission denied!"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP); + return NapiThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP, + "[window][setwindowMode]msg: Permission denied!"); } WmErrorCode errCode = WmErrorCode::WM_OK; size_t argc = 4; @@ -2484,7 +2514,7 @@ napi_value JsWindow::OnSetWindowMode(napi_env env, napi_callback_info info) } } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, "[window][setwindowMode]msg: Failed"); } napi_value lastParam = (argc == 1) ? nullptr : ((argv[1] != nullptr && GetType(env, argv[1]) == napi_function) ? argv[1] : nullptr); @@ -2495,21 +2525,24 @@ napi_value JsWindow::OnSetWindowMode(napi_env env, napi_callback_info info) auto window = windowToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_LAYOUT, "%{public}s: window is nullptr", where); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setwindowMode]msg: Window is nullptr")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->SetWindowMode(winMode)); if (ret == WmErrorCode::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Window set mode failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][setwindowMode]msg: Window set mode failed")); } TLOGNI(WmsLogTag::WMS_LAYOUT, "%{public}s: end, window [%{public}u, %{public}s] ret=%{public}d", where, window->GetWindowId(), window->GetWindowName().c_str(), ret); }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetWindowMode") != napi_status::napi_ok) { napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setwindowMode]msg: Failed to send event")); } return result; } @@ -2567,20 +2600,23 @@ napi_value JsWindow::OnGetWindowPropertiesSync(napi_env env, napi_callback_info { if (windowToken_ == nullptr) { WLOGFW("window is nullptr or get invalid param"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowProperties]msg: invalid window"); } WindowPropertyInfo windowPropertyInfo; WMError ret = windowToken_->GetWindowPropertyInfo(windowPropertyInfo); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "get window properties failed"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowProperties]msg: get property info failed"); } auto objValue = CreateJsWindowPropertiesObject(env, windowPropertyInfo); TLOGNI(WmsLogTag::WMS_ATTRIBUTE, "Get Prop, wid: %{public}u", windowToken_->GetWindowId()); if (objValue != nullptr) { return objValue; } else { - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowProperties]msg: create window property object failed"); } } @@ -2595,7 +2631,8 @@ napi_value JsWindow::OnRegisterWindowCallback(napi_env env, napi_callback_info i { if (windowToken_ == nullptr) { WLOGFE("Window is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][on]msg: Window is nullptr."); } sptr windowToken = windowToken_; constexpr size_t argcMin = 2; @@ -2627,7 +2664,7 @@ napi_value JsWindow::OnRegisterWindowCallback(napi_env env, napi_callback_info i WmErrorCode ret = registerManager_->RegisterListener(windowToken, cbType, CaseType::CASE_WINDOW, env, callback, parameter); if (ret != WmErrorCode::WM_OK) { - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][on]msg: Register listener failed."); } TLOGI(WmsLogTag::DEFAULT, "Id=%{public}u, type=%{public}s", windowToken->GetWindowId(), cbType.c_str()); // if comptible mode app adpt to immersive, avoid area change will be called when regist @@ -2642,7 +2679,7 @@ napi_value JsWindow::OnUnregisterWindowCallback(napi_env env, napi_callback_info { if (windowToken_ == nullptr) { WLOGFE("Window is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "[window][off]msg: Window is nullptr."); } size_t argc = 4; napi_value argv[4] = {nullptr}; @@ -2671,7 +2708,7 @@ napi_value JsWindow::OnUnregisterWindowCallback(napi_env env, napi_callback_info } if (ret != WmErrorCode::WM_OK) { - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][off]msg: Unregister listener failed."); } WLOGFI("Unregister end, window [%{public}u, %{public}s], type=%{public}s", windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), cbType.c_str()); @@ -2693,7 +2730,8 @@ napi_value JsWindow::OnBindDialogTarget(napi_env env, napi_callback_info info) { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_DIALOG, "window is nullptr!"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][bindDialogTarget]msg: Window is nullptr."); } if (!Permission::IsSystemCalling()) { TLOGE(WmsLogTag::WMS_DIALOG, "permission denied, require system application!"); @@ -2729,22 +2767,24 @@ napi_value JsWindow::OnBindDialogTarget(napi_env env, napi_callback_info info) auto asyncTask = [weakToken, env, task = napiAsyncTask, token]() { auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][bindDialogTarget]msg: Weak window is nullptr.")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->BindDialogTarget(token)); if (ret == WmErrorCode::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Bind Dialog Target failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][bindDialogTarget]msg: Bind dialog target failed.")); } TLOGI(WmsLogTag::WMS_SYSTEM, "BindDialogTarget end, window [%{public}u, %{public}s]", weakToken->GetWindowId(), weakToken->GetWindowName().c_str()); }; if (napi_send_event(env, asyncTask, napi_eprio_immediate, "OnBindDialogTarget") != napi_status::napi_ok) { - napiAsyncTask->Reject(env, CreateJsError(env, - static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][bindDialogTarget]msg: Send event failed.")); } return result; } @@ -2787,7 +2827,8 @@ napi_value JsWindow::OnSetDialogBackGestureEnabled(napi_env env, napi_callback_i NapiAsyncTask::CompleteCallback complete = [weakToken, errCodePtr](napi_env env, NapiAsyncTask& task, int32_t status) { if (errCodePtr == nullptr) { - task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setDialogBackGestureEnabled]msg:System abnormal")); return; } if (*errCodePtr == WmErrorCode::WM_OK) { @@ -2818,7 +2859,8 @@ static void LoadContentTask(std::shared_ptr contentStorage, std if (ret == WmErrorCode::WM_OK) { task.Resolve(env, NapiGetUndefined(env)); } else { - task.Reject(env, JsErrUtils::CreateJsError(env, ret, "Window load content failed")); + task.Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][loadContent]msg: Window load content failed.")); } WLOGFI("end, window [%{public}u, %{public}s] ret=%{public}d", weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); @@ -2852,7 +2894,8 @@ napi_value JsWindow::LoadContentScheduleOld(napi_env env, napi_callback_info inf auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { TLOGNE(WmsLogTag::WMS_LIFE, "window is nullptr"); - task->Reject(env, JsErrUtils::CreateJsError(env, WM_JS_TO_ERROR_CODE_MAP.at(WMError::WM_ERROR_NULLPTR))); + task->Reject(env, JsErrUtils::CreateJsError(env, WM_JS_TO_ERROR_CODE_MAP.at(WMError::WM_ERROR_NULLPTR), + "[window][loadContent]msg: Window is nullptr.")); return; } if (errCode != WMError::WM_OK) { @@ -2909,7 +2952,8 @@ napi_value JsWindow::LoadContentScheduleNew(napi_env env, napi_callback_info inf auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { TLOGNE(WmsLogTag::WMS_LIFE, "Window is nullptr or get invalid param"); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][loadContent]msg: Weak window is nullptr.")); return; } LoadContentTask(contentStorage, contextUrl, weakWindow, env, *task, isLoadedByName); @@ -2955,19 +2999,22 @@ napi_value JsWindow::OnGetUIContext(napi_env env, napi_callback_info info) if (windowToken_ == nullptr) { WLOGFE("window is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getUIContext]msg: Window is nullptr."); } auto uicontent = windowToken_->GetUIContent(); if (uicontent == nullptr) { WLOGFW("uicontent is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getUIContext]msg: Uicontent is nullptr."); } napi_value uiContext = uicontent->GetUINapiContext(); if (uiContext == nullptr) { WLOGFE("uiContext obtained from jsEngine is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getUIContext]msg: UiContext obtained from jsEngine is nullptr."); } else { return uiContext; } @@ -3004,7 +3051,8 @@ napi_value JsWindow::OnSetUIContent(napi_env env, napi_callback_info info) auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { TLOGNE(WmsLogTag::WMS_LIFE, "Window is nullptr"); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setUIContent]msg: Window is nullptr.")); return; } LoadContentTask(contentStorage, contextUrl, weakWindow, env, *task, false); @@ -3204,7 +3252,7 @@ napi_value JsWindow::OnSetWindowLayoutFullScreen(napi_env env, napi_callback_inf if (window == nullptr) { TLOGNE(WmsLogTag::WMS_IMMS, "%{public}s window is nullptr", where); task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "Invalidate params.")); + "[window][setWindowLayoutFullScreen]msg: invalid window")); return; } // compatibleMode app adapt to immersive need apply avoidArea method @@ -3219,7 +3267,8 @@ napi_value JsWindow::OnSetWindowLayoutFullScreen(napi_env env, napi_callback_inf task.Resolve(env, NapiGetUndefined(env)); } else { TLOGNE(WmsLogTag::WMS_IMMS, "%{public}s failed, ret %{public}d", where, ret); - task.Reject(env, JsErrUtils::CreateJsError(env, ret, "Window OnSetLayoutFullScreen failed.")); + task.Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][setWindowLayoutFullScreen]msg: set layout full screen failed")); } }; @@ -3301,7 +3350,8 @@ napi_value JsWindow::OnSetWindowSystemBarEnable(napi_env env, napi_callback_info auto window = weakToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_IMMS, "window is nullptr"); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowSystemBarEnable]msg: invalid window")); return; } auto errCode = WM_JS_TO_ERROR_CODE_MAP.at( @@ -3310,13 +3360,14 @@ napi_value JsWindow::OnSetWindowSystemBarEnable(napi_env env, napi_callback_info task->Resolve(env, NapiGetUndefined(env)); } else { TLOGNE(WmsLogTag::WMS_IMMS, "set system bar enable failed, errcode: %{public}d", errCode); - task->Reject(env, JsErrUtils::CreateJsError(env, errCode, "JsWindow::OnSetWindowSystemBarEnable failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, errCode, + "[window][setWindowSystemBarEnable]msg: update system bar properties failed")); } }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetWindowSystemBarEnable") != napi_status::napi_ok) { TLOGE(WmsLogTag::WMS_IMMS, "napi_send_event failed"); napiAsyncTask->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "JsWindow::OnSetWindowSystemBarEnable failed")); + "[window][setWindowSystemBarEnable]msg: send event failed")); } return result; } @@ -3349,7 +3400,8 @@ napi_value JsWindow::OnSetSpecificSystemBarEnabled(napi_env env, napi_callback_i auto window = weakToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_IMMS, "%{public}s window is nullptr", where); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setSpecificSystemBarEnabled]msg: invalid window")); return; } auto property = window->GetSystemBarPropertyByType(systemBarType); @@ -3362,13 +3414,13 @@ napi_value JsWindow::OnSetSpecificSystemBarEnabled(napi_env env, napi_callback_i } else { TLOGNE(WmsLogTag::WMS_IMMS, "%{public}s failed, ret %{public}d", where, errCode); task->Reject(env, JsErrUtils::CreateJsError(env, errCode, - "JsWindow::OnSetSpecificSystemBarEnabled failed")); + "[window][setSpecificSystemBarEnabled]msg: set specific bar property failed")); } }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetSpecificSystemBarEnabled") != napi_status::napi_ok) { TLOGE(WmsLogTag::WMS_IMMS, "napi_send_event failed"); napiAsyncTask->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "JsWindow::OnSetSpecificSystemBarEnabled failed")); + "[window][setSpecificSystemBarEnabled]msg: send event failed")); } return result; } @@ -3435,7 +3487,8 @@ napi_value JsWindow::OnSetWindowSystemBarProperties(napi_env env, napi_callback_ auto window = weakToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_IMMS, "window is nullptr"); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowSystemBarProperties]msg: invalid window")); return; } auto errCode = WM_JS_TO_ERROR_CODE_MAP.at( @@ -3445,13 +3498,13 @@ napi_value JsWindow::OnSetWindowSystemBarProperties(napi_env env, napi_callback_ } else { TLOGNE(WmsLogTag::WMS_IMMS, "set system bar properties failed, errcode: %{public}d", errCode); task->Reject(env, JsErrUtils::CreateJsError(env, errCode, - "JsWindow::OnSetWindowSystemBarProperties failed")); + "[window][setWindowSystemBarProperties]msg: update system bar properties failed")); } }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetWindowSystemBarProperties") != napi_status::napi_ok) { TLOGE(WmsLogTag::WMS_IMMS, "napi_send_event failed"); napiAsyncTask->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "JsWindow::OnSetWindowSystemBarProperties failed")); + "[window][setWindowSystemBarProperties]msg: send event failed")); } return result; } @@ -3460,16 +3513,19 @@ napi_value JsWindow::OnGetWindowSystemBarPropertiesSync(napi_env env, napi_callb { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_IMMS, "window is null"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowSystemBarProperties]msg: invalid window"); } if (!WindowHelper::IsMainWindow(windowToken_->GetType())) { TLOGE(WmsLogTag::WMS_IMMS, "only main window is allowed"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "[window][getWindowSystemBarProperties]msg: not main window"); } auto objValue = CreateJsSystemBarPropertiesObject(env, windowToken_); if (objValue == nullptr) { TLOGE(WmsLogTag::WMS_IMMS, "get properties failed"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY, + "[window][getWindowSystemBarProperties]msg: create system bar properties object failed"); } return objValue; } @@ -3497,7 +3553,8 @@ napi_value JsWindow::OnSetStatusBarColor(napi_env env, napi_callback_info info) auto window = weakToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_IMMS, "window is null"); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setStatusBarColor]msg: invalid window")); return; } auto errCode = UpdateStatusBarProperty(window, contentColor); @@ -3506,13 +3563,13 @@ napi_value JsWindow::OnSetStatusBarColor(napi_env env, napi_callback_info info) } else { TLOGNE(WmsLogTag::WMS_IMMS, "set status bar property error: %{public}d", errCode); task->Reject(env, JsErrUtils::CreateJsError(env, WM_JS_TO_ERROR_CODE_MAP.at(errCode), - "JsWindow::OnSetStatusBarProperty failed")); + "[window][setStatusBarColor]msg: update status bar property failed")); } }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetStatusBarColor") != napi_status::napi_ok) { TLOGE(WmsLogTag::WMS_IMMS, "napi_send_event failed"); napiAsyncTask->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY, - "JsWindow::OnSetStatusBarProperty failed")); + "[window][setStatusBarColor]msg: send event failed")); } return result; } @@ -3521,16 +3578,19 @@ napi_value JsWindow::OnGetStatusBarPropertySync(napi_env env, napi_callback_info { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_IMMS, "window is null"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getStatusBarProperty]msg: invalid window"); } if (!WindowHelper::IsMainWindow(windowToken_->GetType())) { TLOGE(WmsLogTag::WMS_IMMS, "only main window is allowed"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "[window][getStatusBarProperty]msg: not main window"); } auto objValue = GetStatusBarPropertyObject(env, windowToken_); if (objValue == nullptr) { TLOGE(WmsLogTag::WMS_IMMS, "get property failed"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY, + "[window][getStatusBarProperty]msg: get status bar property failed"); } return objValue; } @@ -3705,7 +3765,8 @@ napi_value JsWindow::OnGetWindowAvoidAreaSync(napi_env env, napi_callback_info i if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_IMMS, "window is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowAvoidArea]msg: invalid window"); } // getAvoidRect by avoidAreaType AvoidArea avoidArea; @@ -3722,7 +3783,8 @@ napi_value JsWindow::OnGetWindowAvoidAreaSync(napi_env env, napi_callback_info i return avoidAreaObj; } else { TLOGE(WmsLogTag::WMS_IMMS, "ConvertAvoidAreaToJsValue failed"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowAvoidArea]msg: convert avoid area failed"); } } @@ -3768,7 +3830,8 @@ napi_value JsWindow::OnIsWindowShowingSync(napi_env env, napi_callback_info info { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_LIFE, "window is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][isWindowShowing]msg: Window is nullptr."); } bool state = (windowToken_->GetWindowState() == WindowState::STATE_SHOWN); TLOGD(WmsLogTag::WMS_LIFE, "Id=%{public}u, state=%{public}u", windowToken_->GetWindowId(), state); @@ -3929,7 +3992,8 @@ napi_value JsWindow::OnIsWindowSupportWideGamut(napi_env env, napi_callback_info if (weakWindow == nullptr) { WLOGFE("window is nullptr or get invalid param"); task->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][isWindowSupportWideGamut]msg: invalid window")); return; } bool flag = weakWindow->IsSupportWideGamut(); @@ -3940,7 +4004,8 @@ napi_value JsWindow::OnIsWindowSupportWideGamut(napi_env env, napi_callback_info if (napi_send_event(env, asyncTask, napi_eprio_high, "OnIsWindowSupportWideGamut") != napi_status::napi_ok) { TLOGE(WmsLogTag::WMS_IMMS, "napi_send_event failed"); napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][isWindowSupportWideGamut]msg: failed to send event")); } return result; } @@ -3970,18 +4035,21 @@ napi_value JsWindow::OnSetBackgroundColor(napi_env env, napi_callback_info info) auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { WLOGFE("window is nullptr"); - task->Reject(env, JsErrUtils::CreateJsError(env, WMError::WM_ERROR_NULLPTR)); + task->Reject(env, JsErrUtils::CreateJsError(env, WMError::WM_ERROR_NULLPTR, + "[window][setBackgroundColor]msg: invalid window")); return; } if (errCode != WMError::WM_OK) { - task->Reject(env, JsErrUtils::CreateJsError(env, errCode, "Invalidate params.")); + task->Reject(env, JsErrUtils::CreateJsError(env, errCode, + "[window][setBackgroundColor]msg: invalid params")); return; } WMError ret = weakWindow->SetBackgroundColor(color); if (ret == WMError::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Window set background color failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][setBackgroundColor]msg: set background color failed")); } WLOGD("%{public}s window [%{public}u, %{public}s] end", where, weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); @@ -3989,7 +4057,8 @@ napi_value JsWindow::OnSetBackgroundColor(napi_env env, napi_callback_info info) if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetBackgroundColor") != napi_status::napi_ok) { TLOGE(WmsLogTag::WMS_IMMS, "napi_send_event failed"); napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setBackgroundColor]msg: failed to send event")); } return result; } @@ -4015,7 +4084,8 @@ napi_value JsWindow::OnSetWindowBackgroundColorSync(napi_env env, napi_callback_ if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "window is null"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowBackgroundColor]msg: invalid window"); } auto retErr = windowToken_->SetBackgroundColor(color); TLOGI(WmsLogTag::WMS_ATTRIBUTE, "win=%{public}u, color=%{public}s, retErr=%{public}d", @@ -4024,7 +4094,7 @@ napi_value JsWindow::OnSetWindowBackgroundColorSync(napi_env env, napi_callback_ if (ret == WmErrorCode::WM_OK) { return NapiGetUndefined(env); } else { - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][setWindowBackgroundColor]msg: set background color failed"); } } @@ -4106,7 +4176,6 @@ napi_value JsWindow::OnSetWindowBrightness(napi_env env, napi_callback_info info if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); } - napi_value lastParam = (argc <= 1) ? nullptr : ((argv[1] != nullptr && GetType(env, argv[1]) == napi_function) ? argv[1] : nullptr); napi_value result = nullptr; @@ -4114,8 +4183,8 @@ napi_value JsWindow::OnSetWindowBrightness(napi_env env, napi_callback_info info auto asyncTask = [weakToken = wptr(windowToken_), brightness, env, task = napiAsyncTask] { auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { - task->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "Invalidate params.")); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowBrightness]msg: invalid window")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->SetBrightness(brightness)); @@ -4308,7 +4377,7 @@ napi_value JsWindow::OnSetWindowTopmost(napi_env env, napi_callback_info info) TLOGE(WmsLogTag::WMS_HIERARCHY, "windowToken is nullptr"); return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); } - if (windowToken_->IsPadAndNotFreeMutiWindowCompatibleMode()) { + if (windowToken_->IsPadAndNotFreeMultiWindowCompatibleMode()) { TLOGE(WmsLogTag::WMS_HIERARCHY, "This is PcAppInPad, not support"); return NapiGetUndefined(env); } @@ -4565,13 +4634,14 @@ napi_value JsWindow::OnSetWindowKeepScreenOn(napi_env env, napi_callback_info in [weakToken, keepScreenOn, errCodePtr](napi_env env, NapiAsyncTask& task, int32_t status) { if (errCodePtr == nullptr) { task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "System abnormal.")); + "[window][setWindowKeepScreenOn]msg: service abnormally")); return; } if (*errCodePtr == WmErrorCode::WM_OK) { task.Resolve(env, NapiGetUndefined(env)); } else { - task.Reject(env, JsErrUtils::CreateJsError(env, *errCodePtr, "Window set keep screen on failed")); + task.Reject(env, JsErrUtils::CreateJsError(env, *errCodePtr, + "[window][setWindowKeepScreenOn]msg: set keep screen on failed")); } }; @@ -4587,10 +4657,12 @@ napi_value JsWindow::OnSetWakeUpScreen(napi_env env, napi_callback_info info) { if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) { WLOGFE("set wake up screen permission denied!"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP); + return NapiThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP, + "[window][setWakeUpScreen]msg: permission denied"); } if (windowToken_ == nullptr) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWakeUpScreen]msg: invalid window"); } size_t argc = 4; napi_value argv[4] = {nullptr}; @@ -4610,7 +4682,7 @@ napi_value JsWindow::OnSetWakeUpScreen(napi_env env, napi_callback_info info) WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->SetTurnScreenOn(wakeUp)); if (ret != WmErrorCode::WM_OK) { - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][setWakeUpScreen]msg: turn screen on failed"); } WLOGI("Window [%{public}u, %{public}s] set wake up screen %{public}d end", @@ -4666,11 +4738,13 @@ napi_value JsWindow::OnSetPrivacyMode(napi_env env, napi_callback_info info) auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { WLOGFE("window is nullptr"); - task->Reject(env, JsErrUtils::CreateJsError(env, WMError::WM_ERROR_NULLPTR)); + task->Reject(env, JsErrUtils::CreateJsError(env, WMError::WM_ERROR_NULLPTR, + "[window][setPrivacyMode]msg: invalid window")); return; } if (errCode != WMError::WM_OK) { - task->Reject(env, JsErrUtils::CreateJsError(env, errCode, "Invalidate params")); + task->Reject(env, JsErrUtils::CreateJsError(env, errCode, + "[window][setPrivacyMode]msg: invalid params")); return; } weakWindow->SetPrivacyMode(isPrivacyMode); @@ -4681,7 +4755,8 @@ napi_value JsWindow::OnSetPrivacyMode(napi_env env, napi_callback_info info) if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetPrivacyMode") != napi_status::napi_ok) { TLOGE(WmsLogTag::WMS_IMMS, "napi_send_event failed"); napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setPrivacyMode]msg: failed to send event")); } return result; } @@ -4719,12 +4794,13 @@ napi_value JsWindow::OnSetWindowPrivacyMode(napi_env env, napi_callback_info inf auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { task->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "Invalidate params")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowPrivacyMode]msg: invalid window")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->SetPrivacyMode(isPrivacyMode)); if (ret == WmErrorCode::WM_ERROR_NO_PERMISSION) { - task->Reject(env, JsErrUtils::CreateJsError(env, ret)); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, "[window][setWindowPrivacyMode]msg: no permission")); WLOGI("%{public}s failed, window [%{public}u, %{public}s] mode=%{public}u", where, weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), isPrivacyMode); return; @@ -4736,7 +4812,8 @@ napi_value JsWindow::OnSetWindowPrivacyMode(napi_env env, napi_callback_info inf if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetWindowPrivacyMode") != napi_status::napi_ok) { TLOGE(WmsLogTag::WMS_IMMS, "napi_send_event failed"); napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowPrivacyMode]msg: failed to send event")); } return result; } @@ -4803,7 +4880,8 @@ napi_value JsWindow::OnSetTouchableAreas(napi_env env, napi_callback_info info) } if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_EVENT, "WindowToken_ is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setTouchableAreas]msg:window is null"); } Rect windowRect = windowToken_->GetRect(); std::vector touchableAreas; @@ -4819,7 +4897,8 @@ napi_value JsWindow::OnSetTouchableAreas(napi_env env, napi_callback_info info) auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { TLOGNE(WmsLogTag::WMS_EVENT, "%{public}s window is nullptr", where); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setTouchableAreas]msg:window is null")); return; } WMError ret = weakWindow->SetTouchHotAreas(touchableAreas); @@ -4833,8 +4912,8 @@ napi_value JsWindow::OnSetTouchableAreas(napi_env env, napi_callback_info info) where, weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetTouchableAreas") != napi_status::napi_ok) { - napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + napiAsyncTask->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setTouchableAreas]msg:failed to send event")); } return result; } @@ -4846,12 +4925,14 @@ napi_value JsWindow::OnSetResizeByDragEnabled(napi_env env, napi_callback_info i napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc < 1 || argc > 2) { // 2: maximum params num TLOGE(WmsLogTag::WMS_LAYOUT, "Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setResizeByDragEnabled]msg: Number of parameters is invalid"); } bool dragEnabled = true; if (!ConvertFromJsValue(env, argv[0], dragEnabled)) { TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert parameter to dragEnabled"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setResizeByDragEnabled]msg: Failed to convert parameter to dragEnabled"); } napi_value lastParam = (argc <= 1) ? nullptr : (GetType(env, argv[1]) == napi_function ? argv[1] : nullptr); napi_value result = nullptr; @@ -4861,21 +4942,23 @@ napi_value JsWindow::OnSetResizeByDragEnabled(napi_env env, napi_callback_info i auto window = weakToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_LAYOUT, "%{public}s: window is nullptr", where); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setResizeByDragEnabled]msg: Window is nullptr")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->SetResizeByDragEnabled(dragEnabled)); if (ret == WmErrorCode::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "set dragEnabled failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret)); } TLOGNE(WmsLogTag::WMS_LAYOUT, "%{public}s: Window [%{public}u, %{public}s] set dragEnabled end", where, window->GetWindowId(), window->GetWindowName().c_str()); }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetResizeByDragEnabled") != napi_status::napi_ok) { napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setResizeByDragEnabled]msg: Failed to send event")); } return result; } @@ -4952,20 +5035,20 @@ napi_value JsWindow::OnHideNonSystemFloatingWindows(napi_env env, napi_callback_ if (window == nullptr) { TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s window is nullptr", where); task->Reject(env, JsErrUtils::CreateJsError(env, - WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "window is nullptr.")); + WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "[window][hideNonSystemFloatingWindows]msg: invalid window")); return; } if (window->IsFloatingWindowAppType()) { TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s window is app floating window", where); task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, - "HideNonSystemFloatingWindows is not allowed since window is app window")); + "[window][hideNonSystemFloatingWindows]msg: current window is an app window")); return; } WMError ret = window->HideNonSystemFloatingWindows(shouldHide); if (ret != WMError::WM_OK) { TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s failed", where); task->Reject(env, JsErrUtils::CreateJsError(env, WM_JS_TO_ERROR_CODE_MAP.at(ret), - "Hide non-system floating windows failed")); + "[window][hideNonSystemFloatingWindows]msg: hide non-system floating windows failed")); return; } task->Resolve(env, NapiGetUndefined(env)); @@ -4975,7 +5058,8 @@ napi_value JsWindow::OnHideNonSystemFloatingWindows(napi_env env, napi_callback_ }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnHideNonSystemFloatingWindows") != napi_status::napi_ok) { napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "send event failed")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][hideNonSystemFloatingWindows]msg: send event failed")); } return result; } @@ -5015,7 +5099,8 @@ napi_value JsWindow::OnSetSingleFrameComposerEnabled(napi_env env, napi_callback std::shared_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); auto asyncTask = [weakToken = wptr(windowToken_), enabled, errCode, where, env, task = napiAsyncTask] { if (errCode != WmErrorCode::WM_OK) { - task->Reject(env, JsErrUtils::CreateJsError(env, errCode, "permission denied or invalid parameter.")); + task->Reject(env, JsErrUtils::CreateJsError(env, errCode, + "[window][setSingleFrameComposerEnabled]msg: permission denied or invalid parameter")); return; } @@ -5024,7 +5109,8 @@ napi_value JsWindow::OnSetSingleFrameComposerEnabled(napi_env env, napi_callback if (weakWindow == nullptr) { WLOGFE("window is nullptr"); wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(WMError::WM_ERROR_NULLPTR); - task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "window is nullptr.")); + task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, + "[window][setSingleFrameComposerEnabled]msg: invalid window")); return; } @@ -5035,7 +5121,7 @@ napi_value JsWindow::OnSetSingleFrameComposerEnabled(napi_env env, napi_callback wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret); WLOGFE("Set single frame composer enabled failed, ret is %{public}d", wmErrorCode); task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, - "Set single frame composer enabled failed")); + "[window][setSingleFrameComposerEnabled]msg: set single frame composer enabled failed")); return; } WLOGI("%{public}s end, window [%{public}u, %{public}s] enabled flag=%{public}d", @@ -5044,7 +5130,8 @@ napi_value JsWindow::OnSetSingleFrameComposerEnabled(napi_env env, napi_callback if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetSingleFrameComposerEnabled") != napi_status::napi_ok) { TLOGE(WmsLogTag::WMS_IMMS, "napi_send_event failed"); napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setSingleFrameComposerEnabled]msg: failed to send event")); } return result; } @@ -5274,8 +5361,8 @@ napi_value JsWindow::OnSetWindowTouchable(napi_env env, napi_callback_info info) weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetWindowTouchable") != napi_status::napi_ok) { - napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + napiAsyncTask->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowTouchable]msg:failed to send event")); } return result; } @@ -5496,7 +5583,7 @@ napi_value JsWindow::OnSetWindowColorSpace(napi_env env, napi_callback_info info if (weakWindow == nullptr) { WLOGFE("window is nullptr"); task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "OnSetWindowColorSpace failed")); + "[window][setWindowColorSpace]msg: invalid window")); return; } weakWindow->SetColorSpace(colorSpace); @@ -5508,7 +5595,8 @@ napi_value JsWindow::OnSetWindowColorSpace(napi_env env, napi_callback_info info if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetWindowColorSpace") != napi_status::napi_ok) { TLOGE(WmsLogTag::WMS_IMMS, "napi_send_event failed"); napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowColorSpace]msg: failed to send event")); } return result; } @@ -5559,7 +5647,8 @@ napi_value JsWindow::OnGetWindowColorSpaceSync(napi_env env, napi_callback_info { if (windowToken_ == nullptr) { WLOGFE("window is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowColorSpace]msg: invalid window"); } ColorSpace colorSpace = windowToken_->GetColorSpace(); WLOGFI("end, window [%{public}u, %{public}s] colorSpace=%{public}u", @@ -5635,7 +5724,8 @@ napi_value JsWindow::OnSetForbidSplitMove(napi_env env, napi_callback_info info) } } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setForbidSplitMove]msg: Invalid param"); } napi_value lastParam = (argc <= 1) ? nullptr : ((argv[1] != nullptr && GetType(env, argv[1]) == napi_function) ? argv[1] : nullptr); @@ -5645,7 +5735,7 @@ napi_value JsWindow::OnSetForbidSplitMove(napi_env env, napi_callback_info info) auto window = weakToken.promote(); if (window == nullptr) { task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "Invalidate params.")); + "[window][setForbidSplitMove]msg: Window is nullptr")); return; } WmErrorCode ret; @@ -5659,12 +5749,13 @@ napi_value JsWindow::OnSetForbidSplitMove(napi_env env, napi_callback_info info) if (ret == WmErrorCode::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Window OnSetForbidSplitMove failed.")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, "[window][setForbidSplitMove]msg: Failed")); } }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetForbidSplitMove") != napi_status::napi_ok) { napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setForbidSplitMove]msg: Failed to send event")); } return result; } @@ -5682,13 +5773,15 @@ napi_value JsWindow::OnSnapshot(napi_env env, napi_callback_info info) auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { WLOGFE("window is nullptr"); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][snapshot]msg: invalid window")); return; } std::shared_ptr pixelMap = weakWindow->Snapshot(); if (pixelMap == nullptr) { - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][snapshot]msg: snapshot failed")); WLOGFE("window snapshot get pixelmap is null"); return; } @@ -5705,7 +5798,8 @@ napi_value JsWindow::OnSnapshot(napi_env env, napi_callback_info info) if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSnapshot") != napi_status::napi_ok) { TLOGE(WmsLogTag::WMS_IMMS, "napi_send_event failed"); napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][snapshot]msg: failed to send event")); } return result; } @@ -5714,20 +5808,22 @@ napi_value JsWindow::OnSnapshotSync(napi_env env, napi_callback_info info) { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "windowToken is null"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][snapshotSync]msg: invalid window"); } std::shared_ptr pixelMap = nullptr; WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->Snapshot(pixelMap)); TLOGI(WmsLogTag::WMS_ATTRIBUTE, "winId: %{public}u snapshot end, result: %{public}d", windowToken_->GetWindowId(), ret); if (ret != WmErrorCode::WM_OK) { - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][snapshotSync]msg: snapshot failed"); } auto nativePixelMap = Media::PixelMapNapi::CreatePixelMap(env, pixelMap); if (nativePixelMap == nullptr) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "winId: %{public}u get nativePixelMap is null", windowToken_->GetWindowId()); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][snapshotSync]msg: create pixel map failed"); } return nativePixelMap; } @@ -5743,7 +5839,8 @@ napi_value JsWindow::OnSnapshotIgnorePrivacy(napi_env env, napi_callback_info in auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "window is nullptr"); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][snapshotIgnorePrivacy]msg: invalid window")); return; } @@ -5754,7 +5851,8 @@ napi_value JsWindow::OnSnapshotIgnorePrivacy(napi_env env, napi_callback_info in TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "device not support"); return; } else if (ret != WmErrorCode::WM_OK) { - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][snapshotIgnorePrivacy]msg: snapshot failed")); TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "get pixelmap failed, code:%{public}d", ret); return; } @@ -5771,7 +5869,8 @@ napi_value JsWindow::OnSnapshotIgnorePrivacy(napi_env env, napi_callback_info in if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSnapshotIgnorePrivacy") != napi_status::napi_ok) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "napi_send_event failed"); napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][snapshotIgnorePrivacy]msg: failed to send event")); } return result; } @@ -5797,17 +5896,19 @@ napi_value JsWindow::OnSetSnapshotSkip(napi_env env, napi_callback_info info) } } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setSnapshotSkip]msg: invalid params"); } if (windowToken_ == nullptr) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setSnapshotSkip]msg: invalid window"); } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->SetSnapshotSkip(isSkip)); if (ret != WmErrorCode::WM_OK) { WLOGFE("Window SetSnapshotSkip failed"); - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][setSnapshotSkip]msg: set snapshot skip failed"); } WLOGI("[%{public}u, %{public}s] set snapshotSkip end", windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str()); @@ -6605,7 +6706,7 @@ napi_value JsWindow::OnSetWaterMarkFlag(napi_env env, napi_callback_info info) if (window == nullptr) { task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "OnSetWaterMarkFlag failed.")); + "[window][setWaterMarkFlag]msg: invalid window")); return; } WMError ret = WMError::WM_OK; @@ -6618,7 +6719,7 @@ napi_value JsWindow::OnSetWaterMarkFlag(napi_env env, napi_callback_info info) task->Resolve(env, NapiGetUndefined(env)); } else { task->Reject(env, JsErrUtils::CreateJsError(env, WM_JS_TO_ERROR_CODE_MAP.at(ret), - "SetWaterMarkFlag failed.")); + "[window][setWaterMarkFlag]msg: set water mark flag failed")); } WLOGI("%{public}s end, window [%{public}u, %{public}s] ret=%{public}d", where, window->GetWindowId(), window->GetWindowName().c_str(), ret); @@ -6626,7 +6727,8 @@ napi_value JsWindow::OnSetWaterMarkFlag(napi_env env, napi_callback_info info) if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetWaterMarkFlag") != napi_status::napi_ok) { TLOGE(WmsLogTag::WMS_IMMS, "napi_send_event failed"); napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWaterMarkFlag]msg: failed to send event")); } return result; } @@ -6669,7 +6771,7 @@ napi_value JsWindow::OnSetHandwritingFlag(napi_env env, napi_callback_info info) [weakToken, isAddFlag, errCodePtr](napi_env env, NapiAsyncTask& task, int32_t status) { if (errCodePtr == nullptr) { task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "System abnormal.")); + "[window][setHandwritingFlag]msg:System abnormal.")); return; } if (*errCodePtr == WmErrorCode::WM_OK) { @@ -6699,12 +6801,14 @@ napi_value JsWindow::OnSetAspectRatio(napi_env env, napi_callback_info info) if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT, "WindowToken is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setAspectRatio]msg: Window is nullptr"); } if (!WindowHelper::IsMainWindow(windowToken_->GetType())) { - TLOGE(WmsLogTag::WMS_LAYOUT, "SetAspectRatio is not allowed since window is main window"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + TLOGE(WmsLogTag::WMS_LAYOUT, "SetAspectRatio is only allowed main window"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "[window][setAspectRatio]msg: SetAspectRatio is only allowed for the main window"); } double aspectRatio = 0.0; @@ -6719,7 +6823,8 @@ napi_value JsWindow::OnSetAspectRatio(napi_env env, napi_callback_info info) } if (errCode == WMError::WM_ERROR_INVALID_PARAM || aspectRatio <= 0.0) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setAspectRatio]msg: Falied"); } napi_value lastParam = (argc == 1) ? nullptr : (GetType(env, argv[1]) == napi_function ? argv[1] : nullptr); @@ -6730,7 +6835,7 @@ napi_value JsWindow::OnSetAspectRatio(napi_env env, napi_callback_info info) auto window = weakToken.promote(); if (window == nullptr) { task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "OnSetAspectRatio failed.")); + "[window][setAspectRatio]msg: Falied")); return; } WMError ret = window->SetAspectRatio(aspectRatio); @@ -6738,14 +6843,15 @@ napi_value JsWindow::OnSetAspectRatio(napi_env env, napi_callback_info info) task->Resolve(env, NapiGetUndefined(env)); } else { task->Reject(env, JsErrUtils::CreateJsError(env, WM_JS_TO_ERROR_CODE_MAP.at(ret), - "SetAspectRatio failed.")); + "[window][setAspectRatio]msg: Falied")); } TLOGNI(WmsLogTag::WMS_LAYOUT, "%{public}s: end, window [%{public}u, %{public}s] ret=%{public}d", where, window->GetWindowId(), window->GetWindowName().c_str(), ret); }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetAspectRatio") != napi_status::napi_ok) { napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setAspectRatio]msg: Falied")); } return result; } @@ -6757,17 +6863,20 @@ napi_value JsWindow::OnResetAspectRatio(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc > 1) { TLOGE(WmsLogTag::WMS_LAYOUT, "Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][resetAspectRatio]msg: Number of parameters is invalid"); } if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT, "WindowToken is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][resetAspectRatio]msg: Window is nullptr"); } if (!WindowHelper::IsMainWindow(windowToken_->GetType())) { TLOGE(WmsLogTag::WMS_LAYOUT, "ResetAspectRatio is not allowed since window is main window"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "[window][resetAspectRatio]msg: ResetAspectRatio is not allowed since window is main window"); } napi_value lastParam = (argc == 0) ? nullptr : @@ -6778,21 +6887,22 @@ napi_value JsWindow::OnResetAspectRatio(napi_env env, napi_callback_info info) auto window = weakToken.promote(); if (window == nullptr) { task->Reject(env, JsErrUtils::CreateJsError(env, - WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "OnResetAspectRatio failed.")); + WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "[window][resetAspectRatio]msg: window is nullptr")); return; } WMError ret = window->ResetAspectRatio(); if (ret == WMError::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "ResetAspectRatio failed.")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, "[window][resetAspectRatio]msg: Failed.")); } TLOGND(WmsLogTag::WMS_LAYOUT, "%{public}s end, window [%{public}u, %{public}s] ret=%{public}d", where, window->GetWindowId(), window->GetWindowName().c_str(), ret); }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnResetAspectRatio") != napi_status::napi_ok) { napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][resetAspectRatio]msg: Failed to send event")); } return result; } @@ -6824,8 +6934,8 @@ napi_value JsWindow::OnMinimize(napi_env env, napi_callback_info info) auto window = weakToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_LAYOUT, "%{public}s window is nullptr", where); - task->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "window is nullptr")); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][minimize]msg: Window is nullptr.")); return; } WMError ret = window->Minimize(); @@ -6833,7 +6943,8 @@ napi_value JsWindow::OnMinimize(napi_env env, napi_callback_info info) task->Resolve(env, NapiGetUndefined(env)); } else { WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret); - task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Minimize failed.")); + task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, + "[window][minimize]msg: Minimize failed.")); } TLOGNI(WmsLogTag::WMS_PC, "%{public}s Window [%{public}u, %{public}s] minimize end, ret=%{public}d", where, window->GetWindowId(), window->GetWindowName().c_str(), ret); @@ -6849,12 +6960,14 @@ napi_value JsWindow::OnMaximize(napi_env env, napi_callback_info info) { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT_PC, "WindowToken is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][maximize]msg: window is nullptr"); } if (!(WindowHelper::IsMainWindow(windowToken_->GetType()) || windowToken_->IsSubWindowMaximizeSupported())) { TLOGE(WmsLogTag::WMS_LAYOUT_PC, "only support main or sub Window"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "[window][maximize]msg: Only support main or sub Window"); } size_t argc = FOUR_PARAMS_SIZE; napi_value argv[FOUR_PARAMS_SIZE] = { nullptr }; @@ -6866,7 +6979,8 @@ napi_value JsWindow::OnMaximize(napi_env env, napi_callback_info info) presentationValue < static_cast(MaximizePresentation::FOLLOW_APP_IMMERSIVE_SETTING) || presentationValue > static_cast(MaximizePresentation::ENTER_IMMERSIVE_DISABLE_TITLE_AND_DOCK_HOVER)) { TLOGE(WmsLogTag::WMS_LAYOUT_PC, "Failed to convert parameter to presentationValue"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][maximize]msg: Failed to convert parameter to presentationValue"); } } MaximizePresentation presentation = static_cast(presentationValue); @@ -6879,7 +6993,8 @@ napi_value JsWindow::OnMaximize(napi_env env, napi_callback_info info) auto window = windowToken.promote(); if (window == nullptr) { task->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "window is nullptr")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][maximize]msg: Window is nullptr")); return; } WMError ret = window->Maximize(presentation); @@ -6887,12 +7002,14 @@ napi_value JsWindow::OnMaximize(napi_env env, napi_callback_info info) task->Resolve(env, NapiGetUndefined(env)); } else { WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret); - task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Maximize failed.")); + task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, + "[window][maximize]msg: Failed")); } }; if (napi_send_event(env, asyncTask, napi_eprio_immediate, "OnMaximize") != napi_status::napi_ok) { napiAsyncTask->Reject(env, CreateJsError(env, - static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][maximize]msg: Send event failed")); } return result; } @@ -7037,13 +7154,15 @@ napi_value JsWindow::OnEnableDrag(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc < 1 || argv[INDEX_ZERO] == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT, "Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][enableDrag]msg: Argc is invalid"); } bool enableDrag = false; if (!ConvertFromJsValue(env, argv[INDEX_ZERO], enableDrag)) { TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert parameter from jsValue"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][enableDrag]msg: Failed to convert parameter from jsValue"); } std::shared_ptr errCodePtr = std::make_shared(WmErrorCode::WM_OK); NapiAsyncTask::ExecuteCallback execute = @@ -7064,17 +7183,20 @@ napi_value JsWindow::OnSetWindowLimits(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc < 1 || argv[INDEX_ZERO] == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT, "Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setWindowLimits]msg: Argc is invalid"); } WindowLimits windowLimits; if (!ParseWindowLimits(env, argv[INDEX_ZERO], windowLimits)) { TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert object to windowLimits"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setWindowLimits]msg:Failed to convert object to windowLimits"); } if (windowLimits.maxWidth_ < 0 || windowLimits.maxHeight_ < 0 || windowLimits.minWidth_ < 0 || windowLimits.minHeight_ < 0) { TLOGE(WmsLogTag::WMS_LAYOUT, "Width or height should be greater than or equal to 0"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setWindowLimits]msg: Width or height should be greater than or equal to 0"); } size_t lastParamIndex = INDEX_ONE; bool isForcible = false; @@ -7082,15 +7204,18 @@ napi_value JsWindow::OnSetWindowLimits(napi_env env, napi_callback_info info) lastParamIndex = INDEX_TWO; if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT, "window is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowLimits]msg: Window is nullptr"); } if (!windowToken_->IsPcOrFreeMultiWindowCapabilityEnabled()) { TLOGE(WmsLogTag::WMS_LAYOUT, "device not support"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT); + return NapiThrowError(env, WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT, + "[window][setWindowLimits]msg: Device not support"); } if (!ConvertFromJsValue(env, argv[INDEX_ONE], isForcible)) { TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert parameter to isForcible"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setWindowLimits]msg: Failed to convert parameter to isForcible"); } } napi_value lastParam = (argc <= lastParamIndex) ? nullptr : @@ -7102,7 +7227,8 @@ napi_value JsWindow::OnSetWindowLimits(napi_env env, napi_callback_info info) auto window = windowToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_LAYOUT, "%{public}s: window is nullptr", where); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowLimits]msg: Window is nullptr")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->SetWindowLimits(windowLimits, isForcible)); @@ -7110,17 +7236,19 @@ napi_value JsWindow::OnSetWindowLimits(napi_env env, napi_callback_info info) auto objValue = GetWindowLimitsAndConvertToJsValue(env, windowLimits); if (objValue == nullptr) { task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "Window set window limits failed")); + "[window][setWindowLimits]msg: Set window limits failed")); } else { task->Resolve(env, objValue); } } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Window set window limits failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][setWindowLimits]msg: Set window limits failed")); } }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetWindowLimits") != napi_status::napi_ok) { napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowLimits]msg: Failed to send event")); } return result; } @@ -7133,17 +7261,19 @@ napi_value JsWindow::OnGetWindowLimits(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc > 1) { TLOGE(WmsLogTag::WMS_LAYOUT, "Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][getWindowLimits]msg: Argc is invalid"); } if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT, "window is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowLimits]msg: Window is nullptr"); } WindowLimits windowLimits; WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->GetWindowLimits(windowLimits)); if (ret != WmErrorCode::WM_OK) { - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][getWindowLimits]msg: Falied"); } auto objValue = GetWindowLimitsAndConvertToJsValue(env, windowLimits); TLOGI(WmsLogTag::WMS_LAYOUT, "Window [%{public}u, %{public}s] get window limits end", @@ -7151,7 +7281,7 @@ napi_value JsWindow::OnGetWindowLimits(napi_env env, napi_callback_info info) if (objValue != nullptr) { return objValue; } else { - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "[window][getWindowLimits]msg: Nullptr"); } } @@ -7259,7 +7389,8 @@ napi_value JsWindow::OnSetSubWindowModal(napi_env env, napi_callback_info info) modalityType = JS_TO_NATIVE_MODALITY_TYPE_MAP.at(apiModalityType); } else { TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to modalityType"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setPrivacyMode]msg: convert parameter to modality type failed"); } } napi_value result = nullptr; @@ -7270,14 +7401,15 @@ napi_value JsWindow::OnSetSubWindowModal(napi_env env, napi_callback_info info) if (window == nullptr) { TLOGNE(WmsLogTag::WMS_SUB, "%{public}s window is nullptr", where); WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(WMError::WM_ERROR_NULLPTR); - task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "window is nullptr.")); + task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, + "[window][setSubWindowModal]msg: invalid window")); return; } if (!WindowHelper::IsSubWindow(window->GetType())) { TLOGNE(WmsLogTag::WMS_SUB, "%{public}s invalid call, type:%{public}d", where, window->GetType()); task->Reject(env, JsErrUtils::CreateJsError(env, - WmErrorCode::WM_ERROR_INVALID_CALLING, "invalid window type.")); + WmErrorCode::WM_ERROR_INVALID_CALLING, "[window][setSubWindowModal]msg: invalid window type.")); return; } WMError ret = window->SetSubWindowModal(isModal, modalityType); @@ -7286,7 +7418,8 @@ napi_value JsWindow::OnSetSubWindowModal(napi_env env, napi_callback_info info) } else { WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret); TLOGNE(WmsLogTag::WMS_SUB, "%{public}s set failed, ret is %{public}d", where, wmErrorCode); - task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Set subwindow modal failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, + "[window][setSubWindowModal]msg: set subwindow modal failed")); return; } TLOGNI(WmsLogTag::WMS_SUB, @@ -7295,7 +7428,8 @@ napi_value JsWindow::OnSetSubWindowModal(napi_env env, napi_callback_info info) }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetSubWindowModal") != napi_status::napi_ok) { napiAsyncTask->Reject(env, - CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][setSubWindowModal]msg: send event failed")); } return result; } @@ -7339,12 +7473,14 @@ napi_value JsWindow::OnSetFollowParentMultiScreenPolicy(napi_env env, napi_callb napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != ARG_COUNT_ONE) { TLOGE(WmsLogTag::WMS_SUB, "Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setFollowParentMultiScreenPolicy]msg: Argc is invalid"); } bool enabled = false; if (!ConvertFromJsValue(env, argv[INDEX_ZERO], enabled)) { TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to enabled"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setFollowParentMultiScreenPolicy]msg: Failed to convert parameter to enabled"); } napi_value result = nullptr; std::shared_ptr napiAsyncTask = CreateEmptyAsyncTask(env, nullptr, &result); @@ -7352,7 +7488,8 @@ napi_value JsWindow::OnSetFollowParentMultiScreenPolicy(napi_env env, napi_callb napi_status status = napi_send_event(env, asyncTask, napi_eprio_high, "OnSetFollowParentMultiScreenPolicy"); if (status != napi_status::napi_ok) { napiAsyncTask->Reject(env, - CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][setFollowParentMultiScreenPolicy]msg: send event failed")); } return result; } @@ -7520,7 +7657,7 @@ napi_value JsWindow::OnSetDecorButtonStyle(napi_env env, napi_callback_info info return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "[window][setDecorButtonStyle]msg: window is nullptr"); } - if (windowToken_->IsPadAndNotFreeMutiWindowCompatibleMode()) { + if (windowToken_->IsPadAndNotFreeMultiWindowCompatibleMode()) { TLOGE(WmsLogTag::WMS_DECOR, "This is PcAppInPad, not support"); return NapiGetUndefined(env); } @@ -7563,7 +7700,7 @@ napi_value JsWindow::OnGetDecorButtonStyle(napi_env env, napi_callback_info info return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "[window][getDecorButtonStyle]msg: window is nullptr"); } - if (windowToken_->IsPadAndNotFreeMutiWindowCompatibleMode()) { + if (windowToken_->IsPadAndNotFreeMultiWindowCompatibleMode()) { TLOGE(WmsLogTag::WMS_DECOR, "This is PcAppInPad, not support"); return NapiGetUndefined(env); } @@ -7619,7 +7756,8 @@ napi_value JsWindow::OnSetWindowContainerColor(napi_env env, napi_callback_info } if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_DECOR, "WindowToken_ is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowContainerColor]msg: invalid window"); } std::string activeColor; if (!ConvertFromJsValue(env, argv[INDEX_ZERO], activeColor)) { @@ -7637,7 +7775,7 @@ napi_value JsWindow::OnSetWindowContainerColor(napi_env env, napi_callback_info WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(errCode); if (ret != WmErrorCode::WM_OK) { TLOGE(WmsLogTag::WMS_DECOR, "set window container color failed!"); - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][setWindowContainerColor]msg: set window container color failed"); } return NapiGetUndefined(env); } @@ -7653,7 +7791,8 @@ napi_value JsWindow::OnSetWindowContainerModalColor(napi_env env, napi_callback_ } if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_DECOR, "WindowToken_ is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowContainerModalColor]msg: invalid window"); } std::string activeColor; if (!ConvertFromJsValue(env, argv[INDEX_ZERO], activeColor)) { @@ -7672,7 +7811,7 @@ napi_value JsWindow::OnSetWindowContainerModalColor(napi_env env, napi_callback_ WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(errCode); if (ret != WmErrorCode::WM_OK) { TLOGE(WmsLogTag::WMS_DECOR, "set window container color failed!"); - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][setWindowContainerModalColor]msg: set container modal color failed"); } return NapiGetUndefined(env); } @@ -7836,18 +7975,18 @@ napi_value JsWindow::OnSetWindowMask(napi_env env, napi_callback_info info) if (window == nullptr) { TLOGNE(WmsLogTag::WMS_PC, "%{public}s window is nullptr", where); WmErrorCode wmErrorCode = WmErrorCode::WM_ERROR_STATE_ABNORMALLY; - task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "window is nullptr")); + task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "[window][setWindowMask]msg:invalid window")); return; } if (!WindowHelper::IsSubWindow(window->GetType()) && !WindowHelper::IsAppFloatingWindow(window->GetType())) { WmErrorCode wmErrorCode = WmErrorCode::WM_ERROR_INVALID_CALLING; - task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Invalidate window type")); + task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "[window][setWindowMask]msg: invalid type")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->SetWindowMask(windowMask)); if (ret != WmErrorCode::WM_OK) { - task->Reject(env, JsErrUtils::CreateJsError(env, ret)); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, "[window][setWindowMask]msg: set mask failed")); TLOGNE(WmsLogTag::WMS_PC, "%{public}s Window [%{public}u, %{public}s] set window mask failed", where, window->GetWindowId(), window->GetWindowName().c_str()); return; @@ -7857,8 +7996,8 @@ napi_value JsWindow::OnSetWindowMask(napi_env env, napi_callback_info info) where, window->GetWindowId(), window->GetWindowName().c_str()); }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetWindowMask") != napi_status::napi_ok) { - napiAsyncTask->Reject(env, - CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + napiAsyncTask->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowMask]msg: send event failed")); } return result; } @@ -7915,13 +8054,15 @@ void SetWindowGrayScaleTask(const wptr& weakToken, double grayScale, complete = [err](napi_env env, NapiAsyncTask& task, int32_t status) { if (err == nullptr) { - task.Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY))); + task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowGrayScale]msg: invalid error code")); return; } if (*err == WmErrorCode::WM_OK) { task.Resolve(env, NapiGetUndefined(env)); } else { - task.Reject(env, CreateJsError(env, static_cast(*err), "Set window gray scale failed")); + task.Reject(env, JsErrUtils::CreateJsError(env, *err, + "[window][setWindowGrayScale]msg: set window gray scale failed")); } }; } @@ -7971,12 +8112,14 @@ napi_value JsWindow::OnSetImmersiveModeEnabledState(napi_env env, napi_callback_ } if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_IMMS, "windowToken_ is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setImmersiveModeEnabledState]msg: invalid window"); } if (!WindowHelper::IsMainWindow(windowToken_->GetType()) && !WindowHelper::IsSubWindow(windowToken_->GetType())) { TLOGE(WmsLogTag::WMS_IMMS, "not allowed since invalid window type"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "[window][setImmersiveModeEnabledState]msg: not allowed window type"); } WmErrorCode ret = WmErrorCode::WM_OK; napi_value nativeVal = argv[0]; @@ -7999,7 +8142,8 @@ napi_value JsWindow::OnSetImmersiveModeEnabledState(napi_env env, napi_callback_ ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->SetImmersiveModeEnabledState(enable)); if (ret != WmErrorCode::WM_OK) { TLOGE(WmsLogTag::WMS_IMMS, "set failed, ret %{public}d", ret); - return NapiThrowError(env, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY, + "[window][setImmersiveModeEnabledState]msg: set immersive mode enable state failed"); } TLOGI(WmsLogTag::WMS_IMMS, "win %{public}u set end", windowToken_->GetWindowId()); return NapiGetUndefined(env); @@ -8009,12 +8153,14 @@ napi_value JsWindow::OnGetImmersiveModeEnabledState(napi_env env, napi_callback_ { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_IMMS, "windowToken_ is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getImmersiveModeEnabledState]msg: invalid window"); } if (!WindowHelper::IsMainWindow(windowToken_->GetType()) && !WindowHelper::IsSubWindow(windowToken_->GetType())) { TLOGE(WmsLogTag::WMS_IMMS, "not allowed since invalid window type"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "[window][getImmersiveModeEnabledState]msg: not allowed window type"); } bool isEnabled = windowToken_->GetImmersiveModeEnabledState(); @@ -8026,13 +8172,14 @@ napi_value JsWindow::OnIsImmersiveLayout(napi_env env, napi_callback_info info) { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_IMMS, "windowToken_ is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][isImmersiveLayout]msg: invalid window"); } bool isImmersiveLayout = false; auto ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->IsImmersiveLayout(isImmersiveLayout)); if (ret != WmErrorCode::WM_OK) { TLOGE(WmsLogTag::WMS_IMMS, "failed, ret %{public}d", ret); - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][isImmersiveLayout]msg: get immersive layout failed"); } TLOGI(WmsLogTag::WMS_IMMS, "win %{public}u isImmersiveLayout %{public}u end", windowToken_->GetWindowId(), isImmersiveLayout); @@ -8044,13 +8191,15 @@ napi_value JsWindow::OnGetWindowStatus(napi_env env, napi_callback_info info) auto window = windowToken_; if (window == nullptr) { TLOGE(WmsLogTag::WMS_PC, "window is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowStatus]msg: Window is nullptr"); } WindowStatus windowStatus; WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->GetWindowStatus(windowStatus)); if (ret != WmErrorCode::WM_OK) { TLOGE(WmsLogTag::WMS_PC, "failed, ret=%{public}d", ret); - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, + "[window][getWindowStatus]msg: Falied"); } auto objValue = CreateJsValue(env, windowStatus); if (objValue != nullptr) { @@ -8058,7 +8207,8 @@ napi_value JsWindow::OnGetWindowStatus(napi_env env, napi_callback_info info) return objValue; } else { TLOGE(WmsLogTag::WMS_PC, "create js value windowStatus failed"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowStatus]msg: Create js value windowStatus failed"); } } @@ -8151,7 +8301,8 @@ napi_value JsWindow::OnStartMoving(napi_env env, napi_callback_info info) { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT, "windowToken is nullptr."); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][startMoving]msg: WindowToken is nullptr"); } size_t argc = FOUR_PARAMS_SIZE; napi_value argv[FOUR_PARAMS_SIZE] = { nullptr }; @@ -8161,7 +8312,8 @@ napi_value JsWindow::OnStartMoving(napi_env env, napi_callback_info info) } if (WindowHelper::IsInputWindow(windowToken_->GetType())) { TLOGE(WmsLogTag::WMS_LAYOUT, "is not allowed since input window"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "[window][startMoving]msg: Not allowed since input window"); } std::shared_ptr err = std::make_shared(WmErrorCode::WM_OK); const char* const funcName = __func__; @@ -8182,13 +8334,14 @@ napi_value JsWindow::OnStartMoving(napi_env env, napi_callback_info info) NapiAsyncTask::CompleteCallback complete = [err](napi_env env, NapiAsyncTask& task, int32_t status) { if (err == nullptr) { task.Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), - "System abnormal.")); + "[window][startMoving]msg: System abnormal.")); return; } if (*err == WmErrorCode::WM_OK) { task.Resolve(env, NapiGetUndefined(env)); } else { - task.Reject(env, CreateJsError(env, static_cast(*err), "Move system window failed.")); + task.Reject(env, CreateJsError(env, static_cast(*err), + "[window][startMoving]msg: Move system window failed.")); } }; napi_value result = nullptr; @@ -8247,7 +8400,8 @@ napi_value JsWindow::OnStopMoving(napi_env env, napi_callback_info info) { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT_PC, "windowToken is nullptr."); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][stopMoving]msg: WindowToken is nullptr"); } napi_value result = nullptr; std::shared_ptr napiAsyncTask = CreateEmptyAsyncTask(env, nullptr, &result); @@ -8256,19 +8410,22 @@ napi_value JsWindow::OnStopMoving(napi_env env, napi_callback_info info) auto window = windowToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_LAYOUT_PC, "%{public}s window is nullptr.", where); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][stopMoving]msg: Window is nullptr")); return; } WmErrorCode ret = window->StopMoveWindow(); if (ret == WmErrorCode::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Stop moving window failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][stopMoving]msg: Stop moving window failed")); } }; if (napi_send_event(env, std::move(asyncTask), napi_eprio_high, "OnStopMoving") != napi_status::napi_ok) { napiAsyncTask->Reject(env, CreateJsError(env, - static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][stopMoving]msg: Send event failed")); } return result; } @@ -8308,7 +8465,8 @@ napi_value JsWindow::OnSetGestureBackEnabled(napi_env env, napi_callback_info in task.Resolve(env, NapiGetUndefined(env)); } else { TLOGNE(WmsLogTag::WMS_IMMS, "%{public}s set failed, ret %{public}d", where, *errCodePtr); - task.Reject(env, JsErrUtils::CreateJsError(env, *errCodePtr, "set failed.")); + task.Reject(env, JsErrUtils::CreateJsError(env, *errCodePtr, + "[window][setGestureBackEnabled]msg: set gesture back failed")); } }; napi_value result = nullptr; @@ -8321,11 +8479,13 @@ napi_value JsWindow::OnGetGestureBackEnabled(napi_env env, napi_callback_info in { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_IMMS, "windowToken is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][isGestureBackEnabled]msg: invalid window"); } if (!WindowHelper::IsMainWindow(windowToken_->GetType())) { TLOGE(WmsLogTag::WMS_IMMS, "get failed since invalid window type"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "[window][isGestureBackEnabled]msg: not main window"); } bool enable = true; WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->GetGestureBackEnabled(enable)); @@ -8334,7 +8494,8 @@ napi_value JsWindow::OnGetGestureBackEnabled(napi_env env, napi_callback_info in return NapiThrowError(env, WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT); } else if (ret != WmErrorCode::WM_OK) { TLOGE(WmsLogTag::WMS_IMMS, "get failed, ret %{public}d", ret); - return NapiThrowError(env, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY, + "[window][isGestureBackEnabled]msg: get gesture back failed"); } TLOGI(WmsLogTag::WMS_IMMS, "win [%{public}u, %{public}s] enable %{public}u", windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), enable); @@ -8345,7 +8506,8 @@ napi_value JsWindow::OnCreateSubWindowWithOptions(napi_env env, napi_callback_in { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_SUB, "window is null"); - napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][createSubWindowWithOptions]msg: Window is nullptr.")); return NapiGetUndefined(env); } if (!windowToken_->IsPcOrFreeMultiWindowCapabilityEnabled()) { @@ -8393,7 +8555,7 @@ napi_value JsWindow::OnCreateSubWindowWithOptions(napi_env env, napi_callback_in if (window == nullptr) { TLOGNE(WmsLogTag::WMS_SUB, "%{public}s window is nullptr", where); task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "window is nullptr")); + "[window][createSubWindowWithOptions]msg: Window is nullptr on asyncTask.")); return; } if (!WindowHelper::IsFloatOrSubWindow(window->GetType()) && @@ -8412,15 +8574,15 @@ napi_value JsWindow::OnCreateSubWindowWithOptions(napi_env env, napi_callback_in if (subWindow == nullptr) { TLOGNE(WmsLogTag::WMS_SUB, "%{public}s create sub window failed.", where); task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "create sub window failed")); + "[window][createSubWindowWithOptions]msg: Create sub window failed.")); return; } task->Resolve(env, CreateJsWindowObject(env, subWindow)); TLOGNI(WmsLogTag::WMS_SUB, "%{public}s create sub window %{public}s end", where, windowName.c_str()); }; if (napi_send_event(env, asyncTask, napi_eprio_vip, "OnCreateSubWindowWithOptions") != napi_status::napi_ok) { - napiAsyncTask->Reject(env, CreateJsError(env, - static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][createSubWindowWithOptions]msg: Send event failed.")); } return result; } @@ -8446,13 +8608,15 @@ napi_value JsWindow::OnSetParentWindow(napi_env env, napi_callback_info info) auto window = weakToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_SUB, "%{public}s: window is nullptr", where); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setParentWindow]msg: Window is nullptr.")); return; } WMError ret = window->SetParentWindow(newParentWindowId); if (ret != WMError::WM_OK) { WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret); - task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Set parent window failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, + "[window][setParentWindow]msg: Set parent window failed.")); return; } task->Resolve(env, NapiGetUndefined(env)); @@ -8460,8 +8624,8 @@ napi_value JsWindow::OnSetParentWindow(napi_env env, napi_callback_info info) where, window->GetWindowId(), newParentWindowId); }; if (napi_send_event(env, std::move(asyncTask), napi_eprio_high, "OnSetParentWindow") != napi_status::napi_ok) { - napiAsyncTask->Reject(env, CreateJsError(env, - static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][setParentWindow]msg: Send event failed.")); } return result; } @@ -8476,7 +8640,7 @@ napi_value JsWindow::OnGetParentWindow(napi_env env, napi_callback_info info) WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->GetParentWindow(parentWindow)); if (ret != WmErrorCode::WM_OK) { TLOGE(WmsLogTag::WMS_SUB, "get failed, result=%{public}d", ret); - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][getParentWindow]msg: Get parent window failed."); } if (parentWindow == nullptr) { TLOGE(WmsLogTag::WMS_SUB, "parentWindow is nullptr"); @@ -8485,7 +8649,8 @@ napi_value JsWindow::OnGetParentWindow(napi_env env, napi_callback_info info) auto objValue = CreateJsWindowObject(env, parentWindow); if (objValue == nullptr) { TLOGE(WmsLogTag::WMS_SUB, "create js window failed"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getParentWindow]msg: Create js window object failed."); } TLOGI(WmsLogTag::WMS_SUB, "window id: %{public}u set parent window id: %{public}u end", windowToken_->GetWindowId(), parentWindow->GetWindowId()); @@ -8496,13 +8661,14 @@ napi_value JsWindow::OnGetWindowDensityInfo(napi_env env, napi_callback_info inf { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "windowToken is null"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowDensityInfo]msg: invalid window"); } WindowDensityInfo densityInfo; WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->GetWindowDensityInfo(densityInfo)); if (ret != WmErrorCode::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "get failed, result=%{public}d", ret); - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][getWindowDensityInfo]msg: get density info failed"); } auto objValue = ConvertWindowDensityInfoToJsValue(env, densityInfo); if (objValue != nullptr) { @@ -8511,7 +8677,8 @@ napi_value JsWindow::OnGetWindowDensityInfo(napi_env env, napi_callback_info inf return objValue; } else { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "create js windowDensityInfo failed"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowDensityInfo]msg: convert density info failed"); } } @@ -8531,13 +8698,14 @@ napi_value JsWindow::OnSetDefaultDensityEnabled(napi_env env, napi_callback_info } if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "windowToken is null"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setDefaultDensityEnabled]msg: invalid window"); } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->SetWindowDefaultDensityEnabled(enabled)); TLOGI(WmsLogTag::WMS_ATTRIBUTE, "winId: %{public}u set enabled=%{public}u result=%{public}d", windowToken_->GetWindowId(), enabled, ret); if (ret != WmErrorCode::WM_OK) { - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][setDefaultDensityEnabled]msg: set default density failed"); } return NapiGetUndefined(env); } @@ -8546,7 +8714,8 @@ napi_value JsWindow::OnIsMainWindowFullScreenAcrossDisplays(napi_env env, napi_c { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "windowToken is null"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][isMainWindowFullScreenAcrossDisplays]msg: invalid window"); } std::shared_ptr isAcrossDisplaysPtr = std::make_shared(false); std::shared_ptr errCodePtr = std::make_shared(WmErrorCode::WM_OK); @@ -8570,10 +8739,12 @@ napi_value JsWindow::OnIsMainWindowFullScreenAcrossDisplays(napi_env env, napi_c task.Resolve(env, objValue); } else { TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s convert to js value failed", where); - task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][isMainWindowFullScreenAcrossDisplays]msg: create js value failed")); } } else { - task.Reject(env, JsErrUtils::CreateJsError(env, *errCodePtr)); + task.Reject(env, JsErrUtils::CreateJsError(env, *errCodePtr, + "[window][isMainWindowFullScreenAcrossDisplays]msg: query failed")); } }; napi_value result = nullptr; @@ -8640,17 +8811,19 @@ napi_value JsWindow::OnIsSystemAvoidAreaEnabled(napi_env env, napi_callback_info { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_IMMS, "windowToken is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][isSystemAvoidAreaEnabled]msg: invalid window"); } if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) { TLOGE(WmsLogTag::WMS_IMMS, "only system window is valid"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "[window][isSystemAvoidAreaEnabled]msg: not system window"); } uint32_t avoidAreaOption = 0; WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->GetAvoidAreaOption(avoidAreaOption)); if (ret != WmErrorCode::WM_OK) { TLOGE(WmsLogTag::WMS_IMMS, "get failed, ret %{public}d", ret); - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][isSystemAvoidAreaEnabled]msg: get avoid area option failed"); } bool enabled = avoidAreaOption & static_cast(AvoidAreaOption::ENABLE_SYSTEM_WINDOW); if (auto objValue = CreateJsValue(env, enabled)) { @@ -8658,7 +8831,8 @@ napi_value JsWindow::OnIsSystemAvoidAreaEnabled(napi_env env, napi_callback_info return objValue; } else { TLOGE(WmsLogTag::WMS_IMMS, "create js object failed"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][isSystemAvoidAreaEnabled]msg: create js value failed"); } } @@ -8863,12 +9037,14 @@ napi_value JsWindow::OnSetFollowParentWindowLayoutEnabled(napi_env env, napi_cal napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != INDEX_ONE) { TLOGE(WmsLogTag::WMS_SUB, "argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setFollowParentWindowLayoutEnabled]msg: Argc is invalid"); } bool isFollow = false; if (!ConvertFromJsValue(env, argv[INDEX_ZERO], isFollow)) { TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to enable"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setFollowParentWindowLayoutEnabled]msg: Falied to convert parameter to enable"); } std::shared_ptr errCodePtr = std::make_shared(WmErrorCode::WM_OK); const char* const where = __func__; @@ -8878,12 +9054,14 @@ napi_value JsWindow::OnSetFollowParentWindowLayoutEnabled(napi_env env, napi_cal auto window = weakToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_SUB, "%{public}s window is nullptr", where); - task->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY))); + task->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][setFollowParentWindowLayoutEnabled]msg: Window is nullptr")); return; } if (!WindowHelper::IsSubWindow(window->GetType()) && !WindowHelper::IsDialogWindow(window->GetType())) { TLOGNE(WmsLogTag::WMS_SUB, "%{public}s only sub window and dialog is valid", where); - task->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_INVALID_CALLING))); + task->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_INVALID_CALLING), + "[window][setFollowParentWindowLayoutEnabled]msg: Support sub window or dialog only")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->SetFollowParentWindowLayoutEnabled(isFollow)); @@ -8891,13 +9069,15 @@ napi_value JsWindow::OnSetFollowParentWindowLayoutEnabled(napi_env env, napi_cal task->Resolve(env, NapiGetUndefined(env)); } else { TLOGNE(WmsLogTag::WMS_SUB, "%{public}s failed, ret %{public}d", where, ret); - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "set follow parent layout failed.")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][setFollowParentWindowLayoutEnabled]msg: Set follow parent layout failed")); } }; napi_status status = napi_send_event(env, asyncTask, napi_eprio_high, "SetFollowParentWindowLayoutEnabled"); if (status != napi_status::napi_ok) { napiAsyncTask->Reject(env, CreateJsError(env, - static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][setFollowParentWindowLayoutEnabled]msg: Send event failed")); } return result; } @@ -8934,7 +9114,8 @@ napi_value JsWindow::OnSetWindowShadowEnabled(napi_env env, napi_callback_info i task.Resolve(env, NapiGetUndefined(env)); } else { TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s set failed, result: %{public}d", where, *errCodePtr); - task.Reject(env, JsErrUtils::CreateJsError(env, *errCodePtr, "set window shadow failed.")); + task.Reject(env, JsErrUtils::CreateJsError(env, *errCodePtr, + "[window][setWindowShadowEnabled]msg: set window shadow failed")); } }; napi_value result = nullptr; diff --git a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp index 950239ec456496833e6194a487d8acd31d8310e7..bbf6d9c41c6720d5febd6155e0ea1561b2daf0d7 100644 --- a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp +++ b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp @@ -263,7 +263,8 @@ napi_value JsWindowStage::OnGetMainWindow(napi_env env, napi_callback_info info) auto asyncTask = [weak = windowScene_, env, task = napiAsyncTask] { auto weakScene = weak.lock(); if (weakScene == nullptr) { - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STAGE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STAGE_ABNORMALLY, + "[window][getMainWindow]msg: Window scene is nullptr.")); TLOGNE(WmsLogTag::WMS_LIFE, "WindowScene_ is nullptr!"); return; } @@ -274,7 +275,7 @@ napi_value JsWindowStage::OnGetMainWindow(napi_env env, napi_callback_info info) window->GetWindowId(), window->GetWindowName().c_str()); } else { task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "Get main window failed.")); + "[window][getMainWindow]msg: Get main window failed.")); TLOGNE(WmsLogTag::WMS_LIFE, "Get main window failed."); } }; @@ -289,13 +290,15 @@ napi_value JsWindowStage::OnGetMainWindowSync(napi_env env, napi_callback_info i auto weakScene = windowScene_.lock(); if (weakScene == nullptr) { WLOGFE("WindowScene is null"); - napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STAGE_ABNORMALLY)); + napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STAGE_ABNORMALLY, + "[window][getMainWindowSync]msg: Window scene is nullptr.")); return NapiGetUndefined(env); } auto window = weakScene->GetMainWindow(); if (window == nullptr) { WLOGFE("Window is null"); - napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getMainWindowSync]msg: Get main window failed.")); return NapiGetUndefined(env); } @@ -307,7 +310,8 @@ napi_value JsWindowStage::OnEvent(napi_env env, napi_callback_info info) auto weakScene = windowScene_.lock(); if (weakScene == nullptr) { WLOGFE("Window scene is null"); - napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][on]msg: Window scene is nullptr.")); return NapiGetUndefined(env); } size_t argc = 4; @@ -336,13 +340,14 @@ napi_value JsWindowStage::OnEvent(napi_env env, napi_callback_info info) auto window = weakScene->GetMainWindow(); if (window == nullptr) { WLOGFE("Get window failed"); - napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][on]msg: Get window failed.")); return NapiGetUndefined(env); } auto ret = g_listenerManager->RegisterListener(window, eventString, CaseType::CASE_STAGE, env, value); if (ret != WmErrorCode::WM_OK) { TLOGE(WmsLogTag::DEFAULT, "register event %{public}s failed, ret=%{public}d", eventString.c_str(), ret); - napi_throw(env, JsErrUtils::CreateJsError(env, ret)); + napi_throw(env, JsErrUtils::CreateJsError(env, ret, "[window][on]msg: Register event listener failed.")); return NapiGetUndefined(env); } WLOGI("Window [%{public}u, %{public}s] register event %{public}s", @@ -356,7 +361,8 @@ napi_value JsWindowStage::OffEvent(napi_env env, napi_callback_info info) auto weakScene = windowScene_.lock(); if (weakScene == nullptr) { WLOGFE("Window scene is null"); - napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][off]msg: Window scene is nullptr.")); return NapiGetUndefined(env); } size_t argc = 4; @@ -373,7 +379,8 @@ napi_value JsWindowStage::OffEvent(napi_env env, napi_callback_info info) auto window = weakScene->GetMainWindow(); if (window == nullptr) { WLOGFE("Get window failed"); - napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][off]msg: Get main window failed.")); return NapiGetUndefined(env); } napi_value value = nullptr; @@ -390,7 +397,7 @@ napi_value JsWindowStage::OffEvent(napi_env env, napi_callback_info info) } if (ret != WmErrorCode::WM_OK) { TLOGE(WmsLogTag::DEFAULT, "unregister event %{public}s failed, ret=%{public}d", eventString.c_str(), ret); - napi_throw(env, JsErrUtils::CreateJsError(env, ret)); + napi_throw(env, JsErrUtils::CreateJsError(env, ret, "[window][off]msg: Unregister event listener failed.")); return NapiGetUndefined(env); } WLOGI("Window [%{public}u, %{public}s] unregister event %{public}s", @@ -413,7 +420,7 @@ static void LoadContentTask(std::shared_ptr contentStorage, std task.Resolve(env, NapiGetUndefined(env)); } else { task.Reject(env, JsErrUtils::CreateJsError(env, WM_JS_TO_ERROR_CODE_MAP.at(ret), - "Window load content failed")); + "[window][loadContent]msg: Window load content failed.")); } WLOGI("Window [%{public}u, %{public}s] load content end, ret=%{public}d", weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); @@ -462,7 +469,8 @@ napi_value JsWindowStage::OnLoadContent(napi_env env, napi_callback_info info, b auto weakScene = weak.lock(); sptr win = weakScene ? weakScene->GetMainWindow() : nullptr; if (win == nullptr) { - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][loadContent]msg: Window is nullptr.")); TLOGNE(WmsLogTag::WMS_LIFE, "Get window failed"); return; } @@ -535,7 +543,8 @@ napi_value JsWindowStage::OnCreateSubWindow(napi_env env, napi_callback_info inf auto weakScene = weak.lock(); if (weakScene == nullptr) { TLOGNE(WmsLogTag::WMS_LIFE, "Window scene is null"); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][createSubWindow]msg: Window scene is nullptr.")); return; } sptr windowOption = new Rosen::WindowOption(); @@ -543,9 +552,9 @@ napi_value JsWindowStage::OnCreateSubWindow(napi_env env, napi_callback_info inf windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING); auto window = weakScene->CreateWindow(windowName, windowOption); if (window == nullptr) { - TLOGNE(WmsLogTag::WMS_LIFE, "Get window failed"); + TLOGNE(WmsLogTag::WMS_LIFE, "Create window failed"); task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "Get window failed")); + "[window][createSubWindow]msg: Create window failed.")); return; } task->Resolve(env, CreateJsWindowObject(env, window)); @@ -585,7 +594,8 @@ napi_value JsWindowStage::OnGetSubWindow(napi_env env, napi_callback_info info) auto weakScene = weak.lock(); if (weakScene == nullptr) { TLOGNE(WmsLogTag::WMS_LIFE, "Window scene is nullptr"); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getSubWindow]msg: Window scene is nullptr.")); return; } std::vector> subWindowVec = weakScene->GetSubWindow(); @@ -603,16 +613,18 @@ napi_value JsWindowStage::OnSetWindowModal(napi_env env, napi_callback_info info auto windowScene = windowScene_.lock(); if (windowScene == nullptr) { TLOGE(WmsLogTag::WMS_MAIN, "WindowScene is null"); - napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STAGE_ABNORMALLY)); + napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STAGE_ABNORMALLY, + "[window][setWindowModal]msg: invalid window scene")); return NapiGetUndefined(env); } auto window = windowScene->GetMainWindow(); if (window == nullptr) { TLOGE(WmsLogTag::WMS_MAIN, "window is nullptr"); - napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STAGE_ABNORMALLY)); + napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STAGE_ABNORMALLY, + "[window][setWindowModal]msg: invalid main window")); return NapiGetUndefined(env); } - if (window->IsPadAndNotFreeMutiWindowCompatibleMode()) { + if (window->IsPadAndNotFreeMultiWindowCompatibleMode()) { TLOGE(WmsLogTag::WMS_MAIN, "This is PcAppInPad, not support"); return NapiGetUndefined(env); } @@ -642,14 +654,16 @@ napi_value JsWindowStage::OnSetWindowModal(napi_env env, napi_callback_info info auto window = weakWindow.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_MAIN, "%{public}s failed, window is null", where); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowModal]msg: window is not valid")); return; } WMError ret = window->SetWindowModal(isModal); if (ret != WMError::WM_OK) { WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret); TLOGNE(WmsLogTag::WMS_MAIN, "%{public}s failed, ret is %{public}d", where, wmErrorCode); - task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Set main window modal failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, + "[window][setWindowModal]msg: set main window modal failed")); return; } task->Resolve(env, NapiGetUndefined(env)); @@ -658,7 +672,8 @@ napi_value JsWindowStage::OnSetWindowModal(napi_env env, napi_callback_info info }; if (napi_send_event(env, asyncTask, napi_eprio_high, "OnSetWindowModal") != napi_status::napi_ok) { napiAsyncTask->Reject(env, - CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowModal]msg: send event failed")); } return result; } @@ -798,12 +813,14 @@ napi_value JsWindowStage::OnSetCustomDensity(napi_env env, napi_callback_info in auto windowScene = windowScene_.lock(); if (windowScene == nullptr) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "windowScene is null"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STAGE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STAGE_ABNORMALLY, + "[window][setCustomDensity]msg: invalid window scene"); } auto window = windowScene->GetMainWindow(); if (window == nullptr) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Window is null"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setCustomDensity]msg: invalid main window"); } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->SetCustomDensity(density, applyToSubWindow)); @@ -811,7 +828,7 @@ napi_value JsWindowStage::OnSetCustomDensity(napi_env env, napi_callback_info in "applyToSubWindow=%{public}d, result=%{public}u", window->GetWindowId(), window->GetWindowName().c_str(), density, applyToSubWindow, ret); if (ret != WmErrorCode::WM_OK) { - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][setCustomDensity]msg: set custom density failed"); } return NapiGetUndefined(env); } @@ -821,7 +838,8 @@ napi_value JsWindowStage::OnCreateSubWindowWithOptions(napi_env env, napi_callba auto windowScene = windowScene_.lock(); if (windowScene == nullptr) { TLOGE(WmsLogTag::WMS_SUB, "WindowScene is null"); - napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STAGE_ABNORMALLY)); + napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STAGE_ABNORMALLY, + "[window][createSubWindowWithOptions]msg: Window scene is nullptr.")); return NapiGetUndefined(env); } size_t argc = 4; @@ -863,9 +881,9 @@ napi_value JsWindowStage::OnCreateSubWindowWithOptions(napi_env env, napi_callba option->SetOnlySupportSceneBoard(true); auto window = windowScene->CreateWindow(windowName, option); if (window == nullptr) { - TLOGNE(WmsLogTag::WMS_SUB, "%{public}s Get window failed", where); + TLOGNE(WmsLogTag::WMS_SUB, "%{public}s Create window failed", where); task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "Get window failed")); + "[window][createSubWindowWithOptions]msg: Create window failed.")); return; } task->Resolve(env, CreateJsWindowObject(env, window)); @@ -883,7 +901,8 @@ napi_value JsWindowStage::OnRemoveStartingWindow(napi_env env, napi_callback_inf auto windowScene = windowScene_.lock(); if (windowScene == nullptr) { TLOGE(WmsLogTag::WMS_STARTUP_PAGE, "windowScene is null"); - napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + napi_throw(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][removeStartingWindow]msg: Window scene is nullptr.")); return NapiGetUndefined(env); } @@ -900,20 +919,21 @@ napi_value JsWindowStage::OnRemoveStartingWindow(napi_env env, napi_callback_inf auto window = weakWindow.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_STARTUP_PAGE, "%{public}s window is nullptr", where); - task->Reject(env, JsErrUtils::CreateJsError(env, - WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "window is nullptr.")); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][removeStartingWindow]msg: Window is nullptr.")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->NotifyRemoveStartingWindow()); if (ret == WmErrorCode::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Notify remove starting window failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][removeStartingWindow]msg: Notify remove starting window failed.")); } }; if (napi_send_event(env, asyncTask, napi_eprio_immediate, "OnRemoveStartingWindow") != napi_status::napi_ok) { - napiAsyncTask->Reject(env, - CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][removeStartingWindow]msg: Send event failed.")); } return result; } diff --git a/previewer/include/window.h b/previewer/include/window.h index 7b159c84253a6432ab1e04d8420e29a82afaafa0..8d23c8ea8b53d6e1e2d6e9bcd9641a3ff7376238 100644 --- a/previewer/include/window.h +++ b/previewer/include/window.h @@ -136,7 +136,7 @@ class WINDOW_EXPORT Window : public RefBase { public: static sptr Create(const std::string& windowName, sptr& option, const std::shared_ptr& context = nullptr, - WMError& errCode = DefaultCreateErrCode); + WMError& errCode = DefaultCreateErrCode, const std::shared_ptr& rsUIContext = nullptr); static sptr Find(const std::string& windowName); static sptr GetTopWindowWithContext(const std::shared_ptr& context = nullptr); static sptr GetTopWindowWithId(uint32_t mainWinId); @@ -457,7 +457,7 @@ public: virtual bool IsPadWindow() const { return false; } virtual bool IsPcOrFreeMultiWindowCapabilityEnabled() const { return false; } virtual bool IsPcOrPadFreeMultiWindowMode() const { return false; } - virtual bool IsPadAndNotFreeMutiWindowCompatibleMode() const { return false; } + virtual bool IsPadAndNotFreeMultiWindowCompatibleMode() const { return false; } virtual bool IsSceneBoardEnabled() const { return false; } virtual bool GetCompatibleModeInPc() const { return false; } virtual WmErrorCode KeepKeyboardOnFocus(bool keepKeyboardFlag) = 0; diff --git a/previewer/include/window_option.h b/previewer/include/window_option.h index a1ed304df29821e2e5de840658c393de07b3a71e..204c9495aff56878b1d8b79625be015dfd088bde 100644 --- a/previewer/include/window_option.h +++ b/previewer/include/window_option.h @@ -283,6 +283,7 @@ public: /** * @brief Get sub window outline enabled * + * @return is sub window outline enabled */ bool IsSubWindowOutlineEnabled() const; diff --git a/previewer/src/window.cpp b/previewer/src/window.cpp index b2d250e8adaeca231580d570dec381ea5433f32c..bf203360ee7e766d916654f526deaab098048770 100644 --- a/previewer/src/window.cpp +++ b/previewer/src/window.cpp @@ -24,7 +24,8 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "Window"}; } sptr Window::Create(const std::string& windowName, sptr& option, - const std::shared_ptr& context, WMError& errCode) + const std::shared_ptr& context, WMError& errCode, + const std::shared_ptr& rsUIContext) { if (option == nullptr) { option = new(std::nothrow) WindowOption(); diff --git a/test/systemtest/dms/BUILD.gn b/test/systemtest/dms/BUILD.gn index ea9a50856c9098ddeafef9f0ce584d57480738f7..83689595a1dbd624c903dff2e76a22a67d6cbacf 100644 --- a/test/systemtest/dms/BUILD.gn +++ b/test/systemtest/dms/BUILD.gn @@ -123,6 +123,12 @@ ohos_systemtest("dms_screenshot_test") { } ohos_systemtest("dms_screen_manager_test") { + sanitize = { + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } module_out_path = module_out_path sources = [ "screen_manager_test.cpp" ] diff --git a/test/systemtest/wms/BUILD.gn b/test/systemtest/wms/BUILD.gn index 275cb1d37d4f124b5ad943484b0f49c5a30b4815..e23e314f4dcb1cfd64a5955a13d0df5c81fb9835 100644 --- a/test/systemtest/wms/BUILD.gn +++ b/test/systemtest/wms/BUILD.gn @@ -22,24 +22,11 @@ group("systemtest") { deps = [ ":wms_window_animate_to_test", ":wms_window_gesture_navigation_enabled_test", - ":wms_window_input_method_test", - ":wms_window_input_test", - ":wms_window_mode_support_info_test", ":wms_window_multi_ability_test", ":wms_window_nointeraction_listener_test", - ":wms_window_occupied_area_change_test", - ":wms_window_raisetoapptop_test", ":wms_window_recover_test", - ":wms_window_rotation_test", - ":wms_window_split_immersive_test", - ":wms_window_split_test", ":wms_window_status_change_test", - ":wms_window_subwindow_test", - ":wms_window_system_toast_window_test", ":wms_window_systemsubwindow_test", - ":wms_window_touch_outside_test", - ":wms_window_visibility_info_test", - ":wms_window_water_mark_test", ] if (!window_manager_use_sceneboard) { deps += [ @@ -51,8 +38,21 @@ group("systemtest") { ":wms_window_focus_test", ":wms_window_gamut_test", ":wms_window_immersive_test", + ":wms_window_input_method_test", + ":wms_window_input_test", ":wms_window_layout_test", + ":wms_window_mode_support_info_test", ":wms_window_move_drag_test", + ":wms_window_occupied_area_change_test", + ":wms_window_raisetoapptop_test", + ":wms_window_rotation_test", + ":wms_window_split_immersive_test", + ":wms_window_split_test", + ":wms_window_subwindow_test", + ":wms_window_system_toast_window_test", + ":wms_window_touch_outside_test", + ":wms_window_visibility_info_test", + ":wms_window_water_mark_test", ] } else { deps += [ diff --git a/test/systemtest/wms/window_immersive_test.cpp b/test/systemtest/wms/window_immersive_test.cpp index 29bfce223cc70ed4e9013cc2cae7bc3d070f02c5..d2f52953973d90d136ef086a07675a1a8824eb2b 100644 --- a/test/systemtest/wms/window_immersive_test.cpp +++ b/test/systemtest/wms/window_immersive_test.cpp @@ -434,9 +434,7 @@ HWTEST_F(WindowImmersiveTest, GetAvoidAreaByTypeTest01, TestSize.Level1) HWTEST_F(WindowImmersiveTest, DockWindowTest01, TestSize.Level1) { const sptr& dockWindow = Utils::CreateDockWindow(); - if (dockWindow == nullptr) { - return; - } + ASSERT_NE(nullptr, dockWindow); if (WMError::WM_ERROR_INVALID_WINDOW == dockWindow->Show()) { ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, dockWindow->Show()); @@ -445,9 +443,7 @@ HWTEST_F(WindowImmersiveTest, DockWindowTest01, TestSize.Level1) } const sptr& window = Utils::CreateTestWindow(fullScreenAppinfo_); - if (window == nullptr) { - return; - } + ASSERT_NE(nullptr, window); usleep(WAIT_ASYNC_US); auto act = testSystemBarChangedListener_->tints_; for (SystemBarRegionTint tint : act) { diff --git a/test/systemtest/wms/window_input_method_test.cpp b/test/systemtest/wms/window_input_method_test.cpp index ff1a486938d4fea2b58400e4aed6dba78d7f22d3..80cbfb76b109da789d36169d7f773a1bf9085842 100644 --- a/test/systemtest/wms/window_input_method_test.cpp +++ b/test/systemtest/wms/window_input_method_test.cpp @@ -77,9 +77,7 @@ HWTEST_F(WindowInputMethodTest, ShowKeyboard01, TestSize.Level1) .parentId = INVALID_WINDOW_ID, }; const sptr& fullWindow = Utils::CreateTestWindow(windowInfo); - if (fullWindow == nullptr) { - return; - } + ASSERT_NE(nullptr, fullWindow); KeyboardEffectOption effectOption; if (!SceneBoardJudgement::IsSceneBoardEnabled()) { sleep(TEST_SLEEP_SECOND); diff --git a/test/systemtest/wms/window_input_test.cpp b/test/systemtest/wms/window_input_test.cpp index 12ee48e0d94635f99712ed1bcfc69cef3b6e14ba..b8f086ecd531411a50cabba17e2d6ba663017e57 100644 --- a/test/systemtest/wms/window_input_test.cpp +++ b/test/systemtest/wms/window_input_test.cpp @@ -71,9 +71,7 @@ HWTEST_F(WindowInputTest, SetTouchHotAreas01, TestSize.Level1) { fullScreenWindow_.name = "window_hot_areas.1"; const sptr& window = Utils::CreateTestWindow(fullScreenWindow_); - if (window == nullptr) { - return; - } + ASSERT_NE(nullptr, window); ASSERT_EQ(WMError::WM_OK, window->Show()); std::vector requestedTouchHotAreas; @@ -123,9 +121,7 @@ HWTEST_F(WindowInputTest, SetTouchHotAreas02, TestSize.Level1) { fullScreenWindow_.name = "window_hot_areas.2"; const sptr& window = Utils::CreateTestWindow(fullScreenWindow_); - if (window == nullptr) { - return; - } + ASSERT_NE(nullptr, window); ASSERT_EQ(WMError::WM_OK, window->Show()); usleep(WAIT_ASYNC_US); diff --git a/test/systemtest/wms/window_mode_support_info_test.cpp b/test/systemtest/wms/window_mode_support_info_test.cpp index d95ff6f25e6d5598d65ec4bdff88853176329579..cba12d1b459b404e34f80acef101ed126115c8ae 100644 --- a/test/systemtest/wms/window_mode_support_info_test.cpp +++ b/test/systemtest/wms/window_mode_support_info_test.cpp @@ -87,9 +87,7 @@ namespace { HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType01, TestSize.Level1) { const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); - if (window == nullptr) { - return; - } + ASSERT_NE(nullptr, window); window->SetRequestWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); ASSERT_EQ(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN, window->GetRequestWindowModeSupportType()); window->Destroy(); @@ -103,9 +101,7 @@ HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType01, TestSize.Level1) HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType02, TestSize.Level1) { const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); - if (window == nullptr) { - return; - } + ASSERT_NE(nullptr, window); window->SetRequestWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); EXPECT_NE(WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE, window->Show()); EXPECT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetWindowMode()); @@ -131,9 +127,7 @@ HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType02, TestSize.Level1) HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType03, TestSize.Level1) { const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); - if (window == nullptr) { - return; - } + ASSERT_NE(nullptr, window); window->SetRequestWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN | WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING); ASSERT_EQ(WMError::WM_OK, window->Show()); @@ -163,9 +157,7 @@ HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType03, TestSize.Level1) HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType04, TestSize.Level1) { const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); - if (window == nullptr) { - return; - } + ASSERT_NE(nullptr, window); window->SetRequestWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING | WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY); @@ -182,9 +174,7 @@ HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType04, TestSize.Level1) HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType05, TestSize.Level1) { const sptr& window1 = Utils::CreateTestWindow(fullAppInfo_1_); - if (window1 == nullptr) { - return; - } + ASSERT_NE(nullptr, window1); window1->SetRequestWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); const sptr& window2 = Utils::CreateTestWindow(fullAppInfo_2_); ASSERT_NE(nullptr, window2); @@ -212,9 +202,7 @@ HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType05, TestSize.Level1) HWTEST_F(WindowModeSupportTypeTest, WindowModeSupportType06, TestSize.Level1) { const sptr& window = Utils::CreateTestWindow(fullAppInfo_1_); - if (window == nullptr) { - return; - } + ASSERT_NE(nullptr, window); window->SetRequestWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); ASSERT_EQ(WMError::WM_OK, window->Show()); WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE); diff --git a/test/systemtest/wms/window_occupied_area_change_test.cpp b/test/systemtest/wms/window_occupied_area_change_test.cpp index 0771a8138a54e432069bc156ef997bb929d16e76..18d3eb5bb20a09addbd2e44b33f7ed6aa2fa0ead 100644 --- a/test/systemtest/wms/window_occupied_area_change_test.cpp +++ b/test/systemtest/wms/window_occupied_area_change_test.cpp @@ -115,9 +115,6 @@ HWTEST_F(WindowOccupiedAreaChangeTest, KeyboardHeightChangeTest01, TestSize.Leve { fullScreenAppInfo_.name = "KeyboardHeightChangeTest01"; const sptr& window1 = Utils::CreateTestWindow(fullScreenAppInfo_); - if (window1 == nullptr) { - return; - } ASSERT_NE(nullptr, window1); window1->RegisterOccupiedAreaChangeListener(testOccupiedAreaChangeListener_); @@ -147,9 +144,6 @@ HWTEST_F(WindowOccupiedAreaChangeTest, KeyboardHeightChangeTest02, TestSize.Leve { fullScreenAppInfo_.name = "KeyboardHeightChangeTest02"; const sptr& window1 = Utils::CreateTestWindow(fullScreenAppInfo_); - if (window1 == nullptr) { - return; - } ASSERT_NE(nullptr, window1); window1->RegisterOccupiedAreaChangeListener(testOccupiedAreaChangeListener_); @@ -179,9 +173,6 @@ HWTEST_F(WindowOccupiedAreaChangeTest, KeyboardHeightChangeTest03, TestSize.Leve { fullScreenAppInfo_.name = "KeyboardHeightChangeTest03"; const sptr& window1 = Utils::CreateTestWindow(fullScreenAppInfo_); - if (window1 == nullptr) { - return; - } ASSERT_NE(nullptr, window1); window1->RegisterOccupiedAreaChangeListener(testOccupiedAreaChangeListener_); diff --git a/test/systemtest/wms/window_raisetoapptop_test.cpp b/test/systemtest/wms/window_raisetoapptop_test.cpp index d0dc266413fc1b95e2ca3dc5369aa952fd81e236..aa2c797cb7ff7a78b12aa68f3f8fb4d1d4b10baf 100644 --- a/test/systemtest/wms/window_raisetoapptop_test.cpp +++ b/test/systemtest/wms/window_raisetoapptop_test.cpp @@ -73,9 +73,6 @@ HWTEST_F(WindowRaiseToAppTopTest, NormalRaise1, TestSize.Level1) { fullInfo_.name = "mainWindow.1"; sptr mainWindow = Utils::CreateTestWindow(fullInfo_); - if (mainWindow == nullptr) { - return; - } ASSERT_NE(nullptr, mainWindow); activeWindows_.push_back(mainWindow); ASSERT_EQ(WMError::WM_OK, mainWindow->Show()); @@ -114,9 +111,6 @@ HWTEST_F(WindowRaiseToAppTopTest, RaiseWithDialog1, TestSize.Level1) { fullInfo_.name = "mainWindow.1"; sptr mainWindow = Utils::CreateTestWindow(fullInfo_); - if (mainWindow == nullptr) { - return; - } ASSERT_NE(nullptr, mainWindow); activeWindows_.push_back(mainWindow); ASSERT_EQ(WMError::WM_OK, mainWindow->Show()); @@ -162,9 +156,6 @@ HWTEST_F(WindowRaiseToAppTopTest, RaiseWhenHide, TestSize.Level1) { fullInfo_.name = "mainWindow.1"; sptr mainWindow = Utils::CreateTestWindow(fullInfo_); - if (mainWindow == nullptr) { - return; - } ASSERT_NE(nullptr, mainWindow); activeWindows_.push_back(mainWindow); ASSERT_EQ(WMError::WM_OK, mainWindow->Show()); @@ -174,9 +165,6 @@ HWTEST_F(WindowRaiseToAppTopTest, RaiseWhenHide, TestSize.Level1) fullInfo_.type = WindowType::WINDOW_TYPE_APP_SUB_WINDOW; fullInfo_.parentId = mainWindow->GetWindowId(); sptr subWindow1 = Utils::CreateTestWindow(fullInfo_); - if (subWindow1 == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow1); activeWindows_.push_back(subWindow1); ASSERT_EQ(WMError::WM_OK, subWindow1->Show()); @@ -215,9 +203,6 @@ HWTEST_F(WindowRaiseToAppTopTest, NotAppSubWindow, TestSize.Level1) fullInfo_.name = "mainWindow.1"; fullInfo_.type = WindowType::WINDOW_TYPE_FLOAT; sptr mainWindow = Utils::CreateTestWindow(fullInfo_); - if (mainWindow == nullptr) { - return; - } ASSERT_NE(nullptr, mainWindow); activeWindows_.push_back(mainWindow); ASSERT_EQ(WMError::WM_OK, mainWindow->Show()); @@ -227,9 +212,6 @@ HWTEST_F(WindowRaiseToAppTopTest, NotAppSubWindow, TestSize.Level1) fullInfo_.type = WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW; fullInfo_.parentId = mainWindow->GetWindowId(); sptr subWindow1 = Utils::CreateTestWindow(fullInfo_); - if (subWindow1 == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow1); activeWindows_.push_back(subWindow1); ASSERT_EQ(WMError::WM_OK, subWindow1->Show(0, true)); diff --git a/test/systemtest/wms/window_rotation_test.cpp b/test/systemtest/wms/window_rotation_test.cpp index 9f784f097f36a736267910b9d50ebd9f4da55da4..1255bce916f1c405f40eb3f271e9949fa6f67112 100644 --- a/test/systemtest/wms/window_rotation_test.cpp +++ b/test/systemtest/wms/window_rotation_test.cpp @@ -129,9 +129,7 @@ HWTEST_F(WindowRotationTest, WindowRotationTest1, TestSize.Level1) fullInfo_.name = "fullscreen.1"; fullInfo_.orientation_ = Orientation::UNSPECIFIED; const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); - if (fullWindow == nullptr) { - return; - } + ASSERT_NE(nullptr, fullWindow); activeWindows_.push_back(fullWindow); EXPECT_EQ(WMError::WM_OK, fullWindow->Show()); EXPECT_NE(WindowMode::WINDOW_MODE_FLOATING, fullWindow->GetWindowMode()); @@ -165,9 +163,7 @@ HWTEST_F(WindowRotationTest, WindowRotationTest2, TestSize.Level1) fullInfo_.name = "fullscreen.2"; fullInfo_.orientation_ = Orientation::REVERSE_HORIZONTAL; const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); - if (fullWindow == nullptr) { - return; - } + ASSERT_NE(nullptr, fullWindow); activeWindows_.push_back(fullWindow); EXPECT_EQ(WMError::WM_OK, fullWindow->Show()); @@ -207,9 +203,7 @@ HWTEST_F(WindowRotationTest, WindowRotationTest3, TestSize.Level1) fullInfo_.orientation_ = Orientation::REVERSE_HORIZONTAL; fullInfo_.mode = WindowMode::WINDOW_MODE_FLOATING; const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); - if (fullWindow == nullptr) { - return; - } + ASSERT_NE(nullptr, fullWindow); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, fullWindow->GetWindowMode()); @@ -244,9 +238,7 @@ HWTEST_F(WindowRotationTest, WindowRotationTest4, TestSize.Level1) fullInfo_.name = "fullscreen.4"; fullInfo_.orientation_ = Orientation::HORIZONTAL; const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); - if (fullWindow == nullptr) { - return; - } + ASSERT_NE(nullptr, fullWindow); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, fullWindow->GetWindowMode()); @@ -287,9 +279,7 @@ HWTEST_F(WindowRotationTest, WindowRotationTest5, TestSize.Level1) fullInfo_.name = "fullscreen.5"; fullInfo_.orientation_ = Orientation::HORIZONTAL; const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); - if (fullWindow == nullptr) { - return; - } + ASSERT_NE(nullptr, fullWindow); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, fullWindow->GetWindowMode()); diff --git a/test/systemtest/wms/window_split_immersive_test.cpp b/test/systemtest/wms/window_split_immersive_test.cpp index 64b199bf07e5d2591ae4b0420a8a1ad828769219..0f14a81e57316f47db53b6f2d4c0230f9f9d838c 100644 --- a/test/systemtest/wms/window_split_immersive_test.cpp +++ b/test/systemtest/wms/window_split_immersive_test.cpp @@ -97,9 +97,7 @@ HWTEST_F(WindowSplitImmersiveTest, SplitImmersive01, TestSize.Level1) // create fullscreen win and show fullInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY; const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); - if (fullWindow == nullptr) { - return; - } + ASSERT_NE(nullptr, fullWindow); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); diff --git a/test/systemtest/wms/window_split_test.cpp b/test/systemtest/wms/window_split_test.cpp index 536ce1fcf07126a84c6d5ceef6fd552e2e11487b..d19fbb343cc6d5bdacebbb3f1062e040a723d226 100644 --- a/test/systemtest/wms/window_split_test.cpp +++ b/test/systemtest/wms/window_split_test.cpp @@ -94,9 +94,7 @@ HWTEST_F(WindowSplitTest, SplitWindow01, TestSize.Level1) splitInfo_.mode = WindowMode::WINDOW_MODE_FULLSCREEN; const sptr& priWindow = Utils::CreateTestWindow(splitInfo_); - if (priWindow == nullptr) { - return; - } + ASSERT_NE(nullptr, priWindow); activeWindows_.push_back(priWindow); priWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); sleep(SPLIT_TEST_SLEEP_S); @@ -104,9 +102,7 @@ HWTEST_F(WindowSplitTest, SplitWindow01, TestSize.Level1) sleep(SPLIT_TEST_SLEEP_S); const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); - if (fullWindow == nullptr) { - return; - } + ASSERT_NE(nullptr, fullWindow); activeWindows_.push_back(fullWindow); fullWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); sleep(SPLIT_TEST_SLEEP_S); @@ -136,9 +132,7 @@ HWTEST_F(WindowSplitTest, SplitWindow02, TestSize.Level1) splitInfo_.mode = WindowMode::WINDOW_MODE_FULLSCREEN; const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); - if (fullWindow == nullptr) { - return; - } + ASSERT_NE(nullptr, fullWindow); activeWindows_.push_back(fullWindow); fullWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); sleep(SPLIT_TEST_SLEEP_S); @@ -176,9 +170,7 @@ HWTEST_F(WindowSplitTest, SplitScreen03, TestSize.Level1) splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY; const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); - if (fullWindow == nullptr) { - return; - } + ASSERT_NE(nullptr, fullWindow); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); sleep(SPLIT_TEST_SLEEP_S); @@ -212,9 +204,7 @@ HWTEST_F(WindowSplitTest, SplitScreen04, TestSize.Level1) splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY; const sptr& fullWindow = Utils::CreateTestWindow(fullInfo_); - if (fullWindow == nullptr) { - return; - } + ASSERT_NE(nullptr, fullWindow); activeWindows_.push_back(fullWindow); ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); diff --git a/test/systemtest/wms/window_subwindow_test.cpp b/test/systemtest/wms/window_subwindow_test.cpp index b3dddc01d68d5f434638572a48e18365ebdb5bc9..4bc04b89dfd310d3011d38d742a4324c6fdfa3d1 100644 --- a/test/systemtest/wms/window_subwindow_test.cpp +++ b/test/systemtest/wms/window_subwindow_test.cpp @@ -85,9 +85,6 @@ HWTEST_F(WindowSubWindowTest, SubWindow01, TestSize.Level1) struct Rect rect = { 0, 0, 100, 200 }; uint32_t flags = 0; sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, flags); - if (subWindow == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow); ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); @@ -113,9 +110,6 @@ HWTEST_F(WindowSubWindowTest, SubWindow02, TestSize.Level1) struct Rect rect = { 0, 0, 100, 200 }; uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, flags); - if (subWindow == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow); ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); @@ -141,9 +135,6 @@ HWTEST_F(WindowSubWindowTest, SubWindow03, TestSize.Level1) struct Rect rect = { 0, 2000, 100, 200 }; uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_MEDIA, rect, flags); - if (subWindow == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow); ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); @@ -169,9 +160,6 @@ HWTEST_F(WindowSubWindowTest, SubWindow04, TestSize.Level1) struct Rect rect = { 0, 2000, 3000, 2000 }; uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_MEDIA, rect, flags); - if (subWindow == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow); ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); @@ -197,9 +185,6 @@ HWTEST_F(WindowSubWindowTest, SubWindow05, TestSize.Level1) struct Rect rect = { 0, 0, 100, 200 }; uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_MEDIA, rect, flags); - if (subWindow == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow); sptr subWindow2 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, flags); @@ -230,9 +215,6 @@ HWTEST_F(WindowSubWindowTest, SubWindow06, TestSize.Level1) struct Rect rect = { 0, 0, 100, 200 }; sptr subWindow0 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, 0); - if (subWindow0 == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow0); sptr subWindow1 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, 0); @@ -264,9 +246,6 @@ HWTEST_F(WindowSubWindowTest, SubWindow07, TestSize.Level1) struct Rect rect = { 0, 0, 100, 200 }; uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, flags); - if (subWindow == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow); ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); @@ -292,9 +271,6 @@ HWTEST_F(WindowSubWindowTest, SubWindow08, TestSize.Level1) struct Rect rect = { 0, 0, 100, 200 }; uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, flags); - if (subWindow == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow); ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, subWindow->Show()); @@ -312,9 +288,6 @@ HWTEST_F(WindowSubWindowTest, SubWindow09, TestSize.Level1) struct Rect rect = { 0, 0, 100, 200 }; uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, flags); - if (subWindow == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow); ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); @@ -342,9 +315,6 @@ HWTEST_F(WindowSubWindowTest, SubWindow10, TestSize.Level1) struct Rect rect = { 0, 0, 100, 200 }; uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, flags); - if (subWindow == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow); ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); @@ -369,33 +339,18 @@ HWTEST_F(WindowSubWindowTest, SubWindow11, TestSize.Level1) struct Rect rect = { 0, 0, 100, 200 }; sptr subWindow0 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, 0); - if (subWindow0 == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow0); sptr subWindow1 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, 0); - if (subWindow1 == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow1); sptr subWindow2 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, 0); - if (subWindow2 == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow2); sptr subWindow3 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, 0); - if (subWindow3 == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow3); sptr subWindow4 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, 0); - if (subWindow4 == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow4); if (scene->GoForeground() == WMError::WM_OK) { ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); @@ -435,12 +390,6 @@ HWTEST_F(WindowSubWindowTest, SubWindow12, TestSize.Level1) struct Rect rect = { 0, 0, 100, 200 }; sptr subWindow0 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, 0, "sub0"); sptr subWindow1 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, 0, "sub0"); - if (subWindow0 == nullptr) { - return; - } - if (subWindow1 == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow0); ASSERT_EQ(nullptr, subWindow1); @@ -469,17 +418,11 @@ HWTEST_F(WindowSubWindowTest, SubWindow13, TestSize.Level1) struct Rect rect = { 0, 0, 100, 200 }; sptr subWindow0 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, 0, "sub1"); - if (subWindow0 == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow0); ASSERT_EQ(WMError::WM_OK, subWindow0->Show()); ASSERT_EQ(WMError::WM_OK, subWindow0->Destroy()); sptr subWindow1 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, rect, 0, "sub1"); - if (subWindow1 == nullptr) { - return; - } ASSERT_NE(nullptr, subWindow1); ASSERT_EQ(WMError::WM_OK, subWindow1->Show()); ASSERT_EQ(WMError::WM_OK, subWindow1->Destroy()); diff --git a/test/systemtest/wms/window_system_toast_test.cpp b/test/systemtest/wms/window_system_toast_test.cpp index e7ec6a65fd341298de5593ec0bd655d369912493..deac776116e3561f1b895dc3fef301f8cf3a15f7 100644 --- a/test/systemtest/wms/window_system_toast_test.cpp +++ b/test/systemtest/wms/window_system_toast_test.cpp @@ -137,9 +137,6 @@ HWTEST_F(WindowSystemToastWindowTest, SystemToastWindow02, TestSize.Level1) Rect fltWindRect = GetRectWithVpr(0, 0, 400, 600); sptr fltWin = CreateSystemToastWindow(WindowType::WINDOW_TYPE_SYSTEM_TOAST, fltWindRect); - if (fltWin == nullptr) { - return; - } ASSERT_NE(nullptr, fltWin); if (scene->GoForeground() == WMError::WM_OK) { @@ -171,9 +168,6 @@ HWTEST_F(WindowSystemToastWindowTest, SystemToastWindow03, TestSize.Level1) Rect fltWindRect = GetRectWithVpr(0, 0, 400, 600); sptr fltWin = CreateSystemToastWindow(WindowType::WINDOW_TYPE_SYSTEM_TOAST, fltWindRect); - if (fltWin == nullptr) { - return; - } ASSERT_NE(nullptr, fltWin); if (scene->GoForeground() == WMError::WM_OK) { ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); @@ -207,9 +201,6 @@ HWTEST_F(WindowSystemToastWindowTest, SystemToastWindow04, TestSize.Level1) Rect fltWindRect = GetRectWithVpr(0, 0, 400, 600); sptr fltWin = CreateSystemToastWindow(WindowType::WINDOW_TYPE_SYSTEM_TOAST, fltWindRect); - if (fltWin == nullptr) { - return; - } ASSERT_NE(nullptr, fltWin); if (scene->GoForeground() != WMError::WM_OK) { diff --git a/test/systemtest/wms/window_touch_outside_test.cpp b/test/systemtest/wms/window_touch_outside_test.cpp index 9939be2fb90b7891fb32c6fb10b9f49c156af413..babe3a5c370eb205716021d0b46cad6a9f95d90d 100644 --- a/test/systemtest/wms/window_touch_outside_test.cpp +++ b/test/systemtest/wms/window_touch_outside_test.cpp @@ -107,9 +107,7 @@ namespace { HWTEST_F(WindowTouchOutsideTest, onTouchInside, TestSize.Level1) { const sptr& firstWindow = Utils::CreateTestWindow(firstWindowInfo_); - if (firstWindow == nullptr) { - return; - } + ASSERT_EQ(nullptr, firstWindow); firstWindow->RegisterTouchOutsideListener(windowlistener1_); firstWindow->Show(); SingletonContainer::Get().ProcessPointDown(firstWindow->GetWindowId()); @@ -126,9 +124,7 @@ HWTEST_F(WindowTouchOutsideTest, onTouchInside, TestSize.Level1) HWTEST_F(WindowTouchOutsideTest, onTouchOutside, TestSize.Level1) { const sptr& firstWindow = Utils::CreateTestWindow(firstWindowInfo_); - if (firstWindow == nullptr) { - return; - } + ASSERT_EQ(nullptr, firstWindow); firstWindow->RegisterTouchOutsideListener(windowlistener1_); const sptr& secondWindow = Utils::CreateTestWindow(secondWindowInfo_); ASSERT_NE(nullptr, secondWindow); @@ -149,9 +145,7 @@ HWTEST_F(WindowTouchOutsideTest, onTouchOutside, TestSize.Level1) HWTEST_F(WindowTouchOutsideTest, onTouchOutsideNotShow, TestSize.Level1) { const sptr& firstWindow = Utils::CreateTestWindow(firstWindowInfo_); - if (firstWindow == nullptr) { - return; - } + ASSERT_EQ(nullptr, firstWindow); firstWindow->RegisterTouchOutsideListener(windowlistener1_); const sptr& secondWindow = Utils::CreateTestWindow(secondWindowInfo_); ASSERT_NE(nullptr, secondWindow); @@ -171,9 +165,7 @@ HWTEST_F(WindowTouchOutsideTest, onTouchOutsideNotShow, TestSize.Level1) HWTEST_F(WindowTouchOutsideTest, onTouchOutsideForAllWindow, TestSize.Level1) { const sptr& firstWindow = Utils::CreateTestWindow(firstWindowInfo_); - if (firstWindow == nullptr) { - return; - } + ASSERT_EQ(nullptr, firstWindow); firstWindow->RegisterTouchOutsideListener(windowlistener1_); const sptr& secondWindow = Utils::CreateTestWindow(secondWindowInfo_); ASSERT_NE(nullptr, secondWindow); diff --git a/test/systemtest/wms/window_visibility_info_test.cpp b/test/systemtest/wms/window_visibility_info_test.cpp index d8e1546eb414f1382c4c0d36a8c6e7ee76079375..b12dcff685c78573a7703f1c286a55e36040078a 100644 --- a/test/systemtest/wms/window_visibility_info_test.cpp +++ b/test/systemtest/wms/window_visibility_info_test.cpp @@ -206,10 +206,7 @@ HWTEST_F(WindowVisibilityInfoTest, WindowVisibilityInfoTest01, TestSize.Level1) floatAppInfo_.name = "window1"; floatAppInfo_.rect = { 0, 0, 300, 100 }; sptr window1 = Utils::CreateTestWindow(floatAppInfo_); - if (window1 == nullptr) { - return; - } - + ASSERT_NE(nullptr, window1); subAppInfo_.name = "subWindow1"; subAppInfo_.rect = { 0, 600, 300, 100 }; subAppInfo_.parentId = window1->GetWindowId(); diff --git a/test/systemtest/wms/window_water_mark_test.cpp b/test/systemtest/wms/window_water_mark_test.cpp index 175ec7eec8c1a7195787d4800a4802fcdcd2b3a3..e2d3c3e034478900a4e22232044d2a82f972fd40 100644 --- a/test/systemtest/wms/window_water_mark_test.cpp +++ b/test/systemtest/wms/window_water_mark_test.cpp @@ -143,9 +143,6 @@ HWTEST_F(WaterMarkTest, SetWaterMarkFlag01, TestSize.Level1) appInfo_.name = "window1"; appInfo_.rect = { 200, 200, 300, 300 }; sptr window = CreateWindow(appInfo_); - if (window == nullptr) { - return; - } ASSERT_NE(window, nullptr); window->Show(); sleep(NORMAL_SLEEP_TIME); diff --git a/utils/include/floating_ball_report.h b/utils/include/floating_ball_report.h index b456b3fdff35af65403f4dad0abada85bee92f89..56db4f0af786896ceefec6dbcb5862159ca168e4 100644 --- a/utils/include/floating_ball_report.h +++ b/utils/include/floating_ball_report.h @@ -21,15 +21,19 @@ #include "wm_common.h" namespace OHOS::Rosen { -class FloatingballReporter { -WM_DECLARE_SINGLE_INSTANCE(FloatingballReporter); +namespace FloatingBallEvent { + constexpr char EVENT_KEY_START[] = "START_FLOATING_BALL"; + constexpr char EVENT_KEY_UPDATE[] = "UPDATE_FLOATING_BALL"; + constexpr char EVENT_KEY_REMOVE[] = "REMOVE_FLOATING_BALL"; + constexpr char EVENT_KEY_RESTORE[] = "RESTORE_FLOATING_BALL_WINDOW"; +} + +class FloatingBallReporter { +WM_DECLARE_SINGLE_INSTANCE(FloatingBallReporter); public: void SetCurrentPackageName(const std::string& packageName); - void ReportFbStart(const uint32_t& templateType, const std::string& errorReason); - void ReportFbRemove(const uint32_t& templateType, const std::string& errorReason); - void ReportFbRestoreMainWindow(const uint32_t& templateType, const std::string& errorReason); - void ReportFbUpdateContent(const uint32_t& templateType, const std::string &errorReason); + void ReportFbEvent(const std::string& eventName, const uint32_t& templateType, const std::string& errorReason); private: std::string GetPackageName() const; std::string packageName_ = ""; diff --git a/utils/include/rs_adapter.h b/utils/include/rs_adapter.h index e1fc776e7f4494b6c24cd4faaba908c4393416ba..4c88fb9ab1c9862dc7e0ee3169da6c93cbbff47e 100644 --- a/utils/include/rs_adapter.h +++ b/utils/include/rs_adapter.h @@ -172,7 +172,8 @@ public: static bool IsClientMultiInstanceEnabled(); static void InitRSUIDirector(std::shared_ptr& rsUIDirector, bool shouldCreateRenderThread = true, - bool isMultiInstance = false); + bool isMultiInstance = false, + const std::shared_ptr& rsUiContext = nullptr); static void SetRSUIContext(const std::shared_ptr& rsNode, const std::shared_ptr& rsUIContext, bool skipCheckInMultiInstance = false); diff --git a/utils/include/string_util.h b/utils/include/string_util.h index 96c5eb161bee250e3ae833fa529045d7be5c6883..241044c432dd756296160889b43594f5446dbe33 100644 --- a/utils/include/string_util.h +++ b/utils/include/string_util.h @@ -16,6 +16,7 @@ #ifndef WM_STRING_UTIL_H #define WM_STRING_UTIL_H +#include #include namespace OHOS { @@ -23,6 +24,25 @@ namespace Rosen { class StringUtil { public: static std::string Trim(std::string s); + + static inline bool ConvertStringToInt32(const std::string& str, int32_t& num) + { + auto res = std::from_chars(str.data(), str.data() + str.size(), num); + if (res.ec != std::errc()) { + return false; + } + return true; + } + + static inline bool ConvertStringToBool(const std::string& str) + { + std::string tmp = str; + std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower); + if (tmp == "true" || tmp == "1") { + return true; + } + return false; + } }; } // Rosen } // OHOS diff --git a/utils/src/accessibility_window_info.cpp b/utils/src/accessibility_window_info.cpp index 0baba01f63ac48bb97bfd3e9c9c0b82e5fc85453..0ca08ce8d9fefc17a8934336b76cbabdbf7a2906 100644 --- a/utils/src/accessibility_window_info.cpp +++ b/utils/src/accessibility_window_info.cpp @@ -31,6 +31,8 @@ bool AccessibilityWindowInfo::Marshalling(Parcel& parcel) const 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.WriteBool(isCompatScaleMode_) && + parcel.WriteUint32(scaleRect_.width_) && parcel.WriteUint32(scaleRect_.height_) && + parcel.WriteInt32(scaleRect_.posX_) && parcel.WriteInt32(scaleRect_.posY_) && parcel.WriteUint32(static_cast(mode_)) && parcel.WriteUint32(static_cast(type_)) && parcel.WriteString(bundleName_) && parcel.WriteUint32(touchHotAreas.size()); if (!res) { @@ -60,7 +62,9 @@ AccessibilityWindowInfo* AccessibilityWindowInfo::Unmarshalling(Parcel& parcel) parcel.ReadBool(info->isDecorEnable_) && parcel.ReadUint64(info->displayId_) && parcel.ReadUint32(info->layer_) && parcel.ReadFloat(info->scaleVal_) && parcel.ReadFloat(info->scaleX_) && parcel.ReadFloat(info->scaleY_) && - parcel.ReadBool(info->isCompatScaleMode_); + parcel.ReadBool(info->isCompatScaleMode_) && + parcel.ReadUint32(info->scaleRect_.width_) && parcel.ReadUint32(info->scaleRect_.height_) && + parcel.ReadInt32(info->scaleRect_.posX_) && parcel.ReadInt32(info->scaleRect_.posY_); if (!res) { delete info; return nullptr; diff --git a/utils/src/floating_ball_report.cpp b/utils/src/floating_ball_report.cpp index a5b6402cde49319222f319aac492edc308f6ea6f..01b2b99305afb0198502d92d6d5aa368e59d589d 100644 --- a/utils/src/floating_ball_report.cpp +++ b/utils/src/floating_ball_report.cpp @@ -20,10 +20,10 @@ namespace OHOS { namespace Rosen { namespace { -const std::string PNAMEID = "SCB_FLOATING_BALL"; -const std::string PVERSION = "1.0"; +constexpr char PNAMEID[] = "SCB_FLOATING_BALL"; +constexpr char PVERSION[] = "1.0"; } -WM_IMPLEMENT_SINGLE_INSTANCE(FloatingballReporter) +WM_IMPLEMENT_SINGLE_INSTANCE(FloatingBallReporter) constexpr char EVENT_KEY_TEMPLATE_TYPE[] = "TEMPLATE_TYPE"; constexpr char EVENT_KEY_PNAMEID[] = "PNAMEID"; @@ -31,76 +31,25 @@ constexpr char EVENT_KEY_PVERSION[] = "PVERSION"; constexpr char EVENT_KEY_PACKAGE_NAME[] = "PACKAGE_NAME"; constexpr char EVENT_KEY_ERROR_REASON[] = "ERROR_REASON"; -constexpr char EVENT_KEY_START_FLOATING_BALL[] = "START_FLOATING_BALL"; -constexpr char EVENT_KEY_UPDATE_FLOATING_BALL[] = "UPDATE_FLOATING_BALL"; -constexpr char EVENT_KEY_REMOVE_FLOATING_BALL[] = "REMOVE_FLOATING_BALL"; -constexpr char EVENT_KEY_RESTORE_FLOATING_BALL_WINDOW[] = "RESTORE_FLOATING_BALL_WINDOW"; - -void FloatingballReporter::SetCurrentPackageName(const std::string& packageName) +void FloatingBallReporter::SetCurrentPackageName(const std::string& packageName) { std::lock_guard lock(packageNameMutex_); packageName_ = packageName; } -std::string FloatingballReporter::GetPackageName() const +std::string FloatingBallReporter::GetPackageName() const { std::lock_guard lock(packageNameMutex_); return packageName_; } -void FloatingballReporter::ReportFbStart(const uint32_t& templateType, const std::string& errorReason) -{ - TLOGI(WmsLogTag::WMS_SYSTEM, "Report start floating ball window"); - int32_t ret = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::MULTIWINDOW_UE, EVENT_KEY_START_FLOATING_BALL, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - EVENT_KEY_PNAMEID, PNAMEID, - EVENT_KEY_PVERSION, PVERSION, - EVENT_KEY_PACKAGE_NAME, GetPackageName(), - EVENT_KEY_TEMPLATE_TYPE, templateType, - EVENT_KEY_ERROR_REASON, errorReason); - if (ret != 0) { - TLOGE(WmsLogTag::WMS_SYSTEM, "Write HiSysEvent error, errCode:%{public}d", ret); - } -} - -void FloatingballReporter::ReportFbUpdateContent(const uint32_t& templateType, const std::string &errorReason) -{ - TLOGI(WmsLogTag::WMS_SYSTEM, "Report update floating ball window content"); - int32_t ret = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::MULTIWINDOW_UE, EVENT_KEY_UPDATE_FLOATING_BALL, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - EVENT_KEY_PNAMEID, PNAMEID, - EVENT_KEY_PVERSION, PVERSION, - EVENT_KEY_PACKAGE_NAME, GetPackageName(), - EVENT_KEY_TEMPLATE_TYPE, templateType, - EVENT_KEY_ERROR_REASON, errorReason); - if (ret != 0) { - TLOGE(WmsLogTag::WMS_SYSTEM, "Write HiSysEvent error, errCode:%{public}d", ret); - } -} - -void FloatingballReporter::ReportFbRemove(const uint32_t& templateType, const std::string& errorReason) -{ - TLOGI(WmsLogTag::WMS_SYSTEM, "Report remove floating ball window"); - int32_t ret = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::MULTIWINDOW_UE, EVENT_KEY_REMOVE_FLOATING_BALL, - OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - EVENT_KEY_PNAMEID, PNAMEID, - EVENT_KEY_PVERSION, PVERSION, - EVENT_KEY_PACKAGE_NAME, GetPackageName(), - EVENT_KEY_TEMPLATE_TYPE, templateType, - EVENT_KEY_ERROR_REASON, errorReason); - if (ret != 0) { - TLOGE(WmsLogTag::WMS_SYSTEM, "Write HiSysEvent error, errCode:%{public}d", ret); - } -} - -void FloatingballReporter::ReportFbRestoreMainWindow(const uint32_t& templateType, const std::string& errorReason) +void FloatingBallReporter::ReportFbEvent(const std::string& eventName, const uint32_t& templateType, + const std::string& errorReason) { - TLOGI(WmsLogTag::WMS_SYSTEM, "Report restore main window to app, templateType:%{public}d", templateType); + TLOGI(WmsLogTag::WMS_SYSTEM, "Report ReportFbEvent, eventName:%{public}s, templateType:%{public}u", + eventName.c_str(), templateType); int32_t ret = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::MULTIWINDOW_UE, EVENT_KEY_RESTORE_FLOATING_BALL_WINDOW, + OHOS::HiviewDFX::HiSysEvent::Domain::MULTIWINDOW_UE, eventName, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, EVENT_KEY_PNAMEID, PNAMEID, EVENT_KEY_PVERSION, PVERSION, diff --git a/utils/src/rs_adapter.cpp b/utils/src/rs_adapter.cpp index d29b1ea898bf21b66ba6bdaad36fdabe9d7f93b2..b2992bdb215774fff294a9a225f0eed47419f55c 100644 --- a/utils/src/rs_adapter.cpp +++ b/utils/src/rs_adapter.cpp @@ -472,7 +472,8 @@ bool RSAdapterUtil::IsClientMultiInstanceEnabled() } void RSAdapterUtil::InitRSUIDirector(std::shared_ptr& rsUIDirector, - bool shouldCreateRenderThread, bool isMultiInstance) + bool shouldCreateRenderThread, bool isMultiInstance, + const std::shared_ptr& rsUiContext) { RETURN_IF_RS_CLIENT_MULTI_INSTANCE_DISABLED(); if (rsUIDirector) { @@ -482,9 +483,10 @@ void RSAdapterUtil::InitRSUIDirector(std::shared_ptr& rsUIDirector } rsUIDirector = RSUIDirector::Create(); if (rsUIDirector) { - rsUIDirector->Init(shouldCreateRenderThread, isMultiInstance); - TLOGI(WmsLogTag::WMS_SCB, - "Create RSUIDirector: %{public}s", RSAdapterUtil::RSUIDirectorToStr(rsUIDirector).c_str()); + rsUIDirector->Init(shouldCreateRenderThread, isMultiInstance, rsUiContext); + TLOGI(WmsLogTag::WMS_SCB, "Create RSUIDirector: %{public}s, rsUIContext: %{public}s", + RSAdapterUtil::RSUIDirectorToStr(rsUIDirector).c_str(), + RSAdapterUtil::RSUIContextToStr(rsUiContext).c_str()); } else { TLOGE(WmsLogTag::WMS_SCB, "Failed to create RSUIDirector"); } diff --git a/utils/test/unittest/BUILD.gn b/utils/test/unittest/BUILD.gn index cd020b85ead9c0d0c6dcb7f2966e327995392157..65e8e55d1e74818899b668c93fbae2917fb087d5 100644 --- a/utils/test/unittest/BUILD.gn +++ b/utils/test/unittest/BUILD.gn @@ -33,7 +33,6 @@ group("unittest") { ":utils_screen_group_info_test", ":utils_screen_info_test", ":utils_string_test", - ":utils_surface_draw_test", ":utils_surface_reader_test", ":utils_window_helper_test", ":utils_window_property_test", @@ -42,6 +41,11 @@ group("unittest") { ":utils_wm_occlusion_region_test", ":wm_window_frame_trace_impl_test", ] + if (!window_manager_use_sceneboard) { + deps += [ + ":utils_surface_draw_test", + ] + } } test_external_deps = [ diff --git a/utils/test/unittest/surface_draw_test.cpp b/utils/test/unittest/surface_draw_test.cpp index 9510bdb069681a8886ad43e831c4a65869ceab48..dd8d9d912624b2edd125e5796db508681809547a 100644 --- a/utils/test/unittest/surface_draw_test.cpp +++ b/utils/test/unittest/surface_draw_test.cpp @@ -125,9 +125,6 @@ HWTEST_F(SurfaceDrawTest, DrawImage01, TestSize.Level1) { ASSERT_FALSE(SurfaceDraw::DrawImage(nullptr, 0, 0, "")); sptr window = CreateTestWindow("testDrawImage"); - if (window == nullptr) { - return; - } ASSERT_NE(nullptr, window); window->Show(); usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated @@ -165,9 +162,6 @@ HWTEST_F(SurfaceDrawTest, DrawMasking01, TestSize.Level1) ASSERT_FALSE(SurfaceDraw::DrawMasking(nullptr, screenRect, transRect)); sptr window = CreateTestWindow("testDrawMasking"); - if (window == nullptr) { - return; - } ASSERT_NE(nullptr, window); window->Show(); usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated @@ -192,9 +186,6 @@ HWTEST_F(SurfaceDrawTest, DrawMasking01, TestSize.Level1) HWTEST_F(SurfaceDrawTest, DoDrawImageRect01, TestSize.Level1) { sptr window = CreateTestWindow("testDoDrawImageRect"); - if (window == nullptr) { - return; - } ASSERT_NE(window, nullptr); window->Show(); usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated @@ -207,9 +198,7 @@ HWTEST_F(SurfaceDrawTest, DoDrawImageRect01, TestSize.Level1) sptr layer = SurfaceDraw::GetLayer(surfaceNode); ASSERT_NE(layer, nullptr); sptr buffer = SurfaceDraw::GetSurfaceBuffer(layer, rect.width_, rect.height_); - if (buffer == nullptr) { - return; - } + ASSERT_NE(nullptr, buffer); ASSERT_FALSE(SurfaceDraw::DoDrawImageRect(buffer, rect, nullptr, color, false)); @@ -228,9 +217,6 @@ HWTEST_F(SurfaceDrawTest, DoDrawImageRect01, TestSize.Level1) HWTEST_F(SurfaceDrawTest, GetSurfaceSnapshot01, TestSize.Level1) { sptr window = CreateTestWindow("testDoDrawImageRect"); - if (window == nullptr) { - return; - } ASSERT_NE(window, nullptr); window->Show(); usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated @@ -255,9 +241,6 @@ HWTEST_F(SurfaceDrawTest, DrawColor01, TestSize.Level1) { ASSERT_FALSE(SurfaceDraw::DrawColor(nullptr, 0, 0, 0)); sptr window = CreateTestWindow("DrawColor"); - if (window == nullptr) { - return; - } ASSERT_NE(nullptr, window); window->Show(); usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated @@ -279,9 +262,6 @@ HWTEST_F(SurfaceDrawTest, DrawColor01, TestSize.Level1) HWTEST_F(SurfaceDrawTest, DoDraw01, TestSize.Level1) { sptr window = CreateTestWindow("DoDrawTest01"); - if (window == nullptr) { - return; - } ASSERT_NE(nullptr, window); window->Show(); usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated @@ -304,9 +284,6 @@ HWTEST_F(SurfaceDrawTest, DoDraw01, TestSize.Level1) HWTEST_F(SurfaceDrawTest, DoDraw02, TestSize.Level1) { sptr window = CreateTestWindow("DoDraw02"); - if (window == nullptr) { - return; - } ASSERT_NE(window, nullptr); window->Show(); usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated @@ -316,9 +293,7 @@ HWTEST_F(SurfaceDrawTest, DoDraw02, TestSize.Level1) sptr layer = SurfaceDraw::GetLayer(surfaceNode); ASSERT_NE(layer, nullptr); sptr buffer = SurfaceDraw::GetSurfaceBuffer(layer, rect.width_, rect.height_); - if (buffer == nullptr) { - return; - } + ASSERT_NE(nullptr, buffer); std::shared_ptr pixelMap = SurfaceDraw::DecodeImageToPixelMap(IMAGE_PLACE_HOLDER_PNG_PATH); ASSERT_NE(pixelMap, nullptr); ASSERT_FALSE(SurfaceDraw::DoDraw(nullptr, 0, 0, pixelMap)); @@ -333,9 +308,6 @@ HWTEST_F(SurfaceDrawTest, DoDraw02, TestSize.Level1) HWTEST_F(SurfaceDrawTest, DoDraw03, TestSize.Level1) { sptr window = CreateTestWindow("DoDrawTest03"); - if (window == nullptr) { - return; - } ASSERT_NE(nullptr, window); window->Show(); usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated @@ -346,9 +318,7 @@ HWTEST_F(SurfaceDrawTest, DoDraw03, TestSize.Level1) sptr layer = SurfaceDraw::GetLayer(surfaceNode); ASSERT_NE(layer, nullptr); sptr buffer = SurfaceDraw::GetSurfaceBuffer(layer, rect.width_, rect.height_); - if (buffer == nullptr) { - return; - } + ASSERT_NE(nullptr, buffer); ASSERT_FALSE(SurfaceDraw::DoDraw(nullptr, 0, 0, color)); window->Destroy(); } @@ -361,9 +331,6 @@ HWTEST_F(SurfaceDrawTest, DoDraw03, TestSize.Level1) HWTEST_F(SurfaceDrawTest, DrawImageRect01, TestSize.Level1) { sptr window = CreateTestWindow("DrawImageRect"); - if (window == nullptr) { - return; - } ASSERT_NE(window, nullptr); window->Show(); usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated diff --git a/window_scene/common/include/session_permission.h b/window_scene/common/include/session_permission.h index 303d9ea88973cd8371c103496b49b240c0b99ab1..217171d731da9c7c7a56e808f0933bc6d14f3174 100644 --- a/window_scene/common/include/session_permission.h +++ b/window_scene/common/include/session_permission.h @@ -28,8 +28,8 @@ constexpr const char* PERMISSION_CALLED_EXTENSION_ON_LOCK_SCREEN = "ohos.permiss constexpr const char* PERMISSION_WRITE_APP_LOCK = "ohos.permission.WRITE_APP_LOCK"; constexpr const char* PERMISSION_SET_ABILITY_INSTANCE_INFO = "ohos.permission.SET_ABILITY_INSTANCE_INFO"; constexpr const char* PERMISSION_VISIBLE_WINDOW_INFO = "ohos.permission.VISIBLE_WINDOW_INFO"; -constexpr const char* PERMISSION_FLOATING_BALL = "ohos.permission.USE_FLOAT_BALL"; constexpr const char* PERMISSION_WINDOW_TRANSPARENT = "ohos.permission.SET_WINDOW_TRANSPARENT"; +constexpr const char* PERMISSION_FLOATING_BALL = "ohos.permission.USE_FLOAT_BALL"; } class SessionPermission { public: diff --git a/window_scene/common/include/window_session_property.h b/window_scene/common/include/window_session_property.h index 89adc5b4dc091d71942787740c7e800e52c0de44..14ecb65fc9c250013e2e32be055010d7eeb7d172 100755 --- a/window_scene/common/include/window_session_property.h +++ b/window_scene/common/include/window_session_property.h @@ -273,6 +273,8 @@ public: bool GetUseControlState() const; void SetAncoRealBundleName(const std::string& ancoRealBundleName); std::string GetAncoRealBundleName() const; + void SetMissionInfo(const MissionInfo& missionInfo); + MissionInfo GetMissionInfo() const; /* * UIExtension @@ -571,6 +573,8 @@ private: mutable std::mutex lifecycleUseControlMutex_; bool isUseControlState_ = false; std::string ancoRealBundleName_ = ""; + MissionInfo missionInfo_; + mutable std::mutex missionInfoMutex_; /* * Window Property @@ -684,6 +688,7 @@ struct FreeMultiWindowConfig : public Parcelable { WindowMode defaultWindowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN; uint32_t maxMainFloatingWindowNumber_ = 0; DragResizeType defaultDragResizeType_ = DragResizeType::RESIZE_TYPE_UNDEFINED; + AppWindowSceneConfig appWindowSceneConfig_; virtual bool Marshalling(Parcel& parcel) const override { @@ -794,8 +799,12 @@ struct SystemSessionConfig : public Parcelable { bool skipRedundantWindowStatusNotifications_ = false; uint32_t supportFunctionType_ = 0; bool supportSnapshotAllSessionStatus_ = false; + bool supportPreloadStartingWindow_ = false; bool supportCreateFloatWindow_ = false; float defaultCornerRadius_ = 0.0f; // default corner radius of window set by system config + bool supportUIExtensionSubWindow_ = false; + + void ConvertSupportUIExtensionSubWindow(const std::string& itemValue); virtual bool Marshalling(Parcel& parcel) const override { @@ -810,9 +819,11 @@ struct SystemSessionConfig : public Parcelable { return false; } - if (!parcel.WriteUint32(miniWidthOfMainWindow_) || !parcel.WriteUint32(miniHeightOfMainWindow_) || - !parcel.WriteUint32(miniWidthOfSubWindow_) || !parcel.WriteUint32(miniHeightOfSubWindow_) || - !parcel.WriteUint32(miniWidthOfDialogWindow_) || !parcel.WriteUint32(miniHeightOfDialogWindow_)) { + bool parcelWriteFail = !parcel.WriteUint32(miniWidthOfMainWindow_) || + !parcel.WriteUint32(miniHeightOfMainWindow_) || !parcel.WriteUint32(miniWidthOfSubWindow_) || + !parcel.WriteUint32(miniHeightOfSubWindow_) || !parcel.WriteUint32(miniWidthOfDialogWindow_) || + !parcel.WriteUint32(miniHeightOfDialogWindow_); + if (parcelWriteFail) { return false; } @@ -852,6 +863,9 @@ struct SystemSessionConfig : public Parcelable { if (!parcel.WriteBool(supportSnapshotAllSessionStatus_)) { return false; } + if (!parcel.WriteBool(supportPreloadStartingWindow_)) { + return false; + } if (!parcel.WriteFloat(defaultCornerRadius_)) { return false; } @@ -905,6 +919,7 @@ struct SystemSessionConfig : public Parcelable { config->skipRedundantWindowStatusNotifications_ = parcel.ReadBool(); config->supportFunctionType_ = parcel.ReadUint32(); config->supportSnapshotAllSessionStatus_ = parcel.ReadBool(); + config->supportPreloadStartingWindow_ = parcel.ReadBool(); if (!parcel.ReadFloat(config->defaultCornerRadius_)) { delete config; return nullptr; diff --git a/window_scene/common/src/session_permission.cpp b/window_scene/common/src/session_permission.cpp index d23d13c6b5238819d1919029f5c478200cd96137..3d1d6b88c256e0eed580701f6f82b4bb7fa755db 100644 --- a/window_scene/common/src/session_permission.cpp +++ b/window_scene/common/src/session_permission.cpp @@ -15,7 +15,6 @@ #include #include -#include #include #include #include @@ -313,7 +312,7 @@ bool SessionPermission::CheckCallingIsUserTestMode(pid_t pid) bool isUserTestMode = false; auto appMgrClient = DelayedSingleton::GetInstance(); if (appMgrClient == nullptr) { - TLOGE(WmsLogTag::DEFAULT, "AppMgeClient is null!"); + TLOGE(WmsLogTag::DEFAULT, "AppMgrClient is null!"); return false; } // reset ipc identity diff --git a/window_scene/common/src/window_session_property.cpp b/window_scene/common/src/window_session_property.cpp index 25141bd691fe85529b79a8500594c8180ba2bf2c..761ba1ae983ed8657876089fbbafd3132bc73fb9 100755 --- a/window_scene/common/src/window_session_property.cpp +++ b/window_scene/common/src/window_session_property.cpp @@ -14,6 +14,7 @@ */ #include "common/include/window_session_property.h" +#include "string_util.h" #include "window_manager_hilog.h" #include "wm_common.h" #include "window_helper.h" @@ -1589,6 +1590,10 @@ void WindowSessionProperty::CopyFrom(const sptr& property isPcAppInpadOrientationLandscape_ = property->isPcAppInpadOrientationLandscape_; isPcAppInpadCompatibleMode_ = property->isPcAppInpadCompatibleMode_; ancoRealBundleName_ = property->ancoRealBundleName_; + { + std::lock_guard lock(missionInfoMutex_); + missionInfo_ = property->missionInfo_; + } } bool WindowSessionProperty::Write(Parcel& parcel, WSPropertyChangeAction action) @@ -2554,6 +2559,18 @@ void WindowSessionProperty::UnmarshallingWindowAnchorInfo(Parcel& parcel, Window property->SetWindowAnchorInfo(*windowAnchorInfo); } +void WindowSessionProperty::SetMissionInfo(const MissionInfo& missionInfo) +{ + std::lock_guard lock(missionInfoMutex_); + missionInfo_ = missionInfo; +} + +MissionInfo WindowSessionProperty::GetMissionInfo() const +{ + std::lock_guard lock(missionInfoMutex_); + return missionInfo_; +} + bool WindowSessionProperty::MarshallingShadowsInfo(Parcel& parcel) const { return parcel.WriteParcelable(&shadowsInfo_); @@ -2568,5 +2585,10 @@ void WindowSessionProperty::UnmarshallingShadowsInfo(Parcel& parcel, WindowSessi } property->SetWindowShadows(*shadowsInfo); } + +void SystemSessionConfig::ConvertSupportUIExtensionSubWindow(const std::string& itemValue) +{ + supportUIExtensionSubWindow_ = StringUtil::ConvertStringToBool(itemValue); +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/window_scene/intention_event/src/intention_event_manager.cpp b/window_scene/intention_event/src/intention_event_manager.cpp index 8f80cc0dbc4a965b8404312a2977ec3b932e8271..90e8e07b1c69207f969a5b2a6e40e5bde5a98e33 100644 --- a/window_scene/intention_event/src/intention_event_manager.cpp +++ b/window_scene/intention_event/src/intention_event_manager.cpp @@ -184,8 +184,8 @@ void IntentionEventManager::InputEventListener::OnInputEvent( SetPointerEventStatus(pointerEvent->GetPointerId(), action, sourceType, sceneSession); } static uint32_t eventId = 0; - TLOGI(WmsLogTag::WMS_INPUT_KEY_FLOW, "id:%{public}d,eid:%{public}d,wid:%{public}u" - ",wn:%{public}s,ac:%{public}d,sys:%{public}d", eventId++, pointerEvent->GetId(), windowId, + TLOGI(WmsLogTag::WMS_INPUT_KEY_FLOW, "eid:%{public}d,InputId:%{public}d,wid:%{public}u" + ",wName:%{public}s,ac:%{public}d,sys:%{public}d", eventId++, pointerEvent->GetId(), windowId, sceneSession->GetSessionInfo().abilityName_.c_str(), action, sceneSession->GetSessionInfo().isSystem_); } if (sceneSession->GetSessionInfo().isSystem_) { diff --git a/window_scene/interfaces/include/ws_common.h b/window_scene/interfaces/include/ws_common.h index e484ecc07c853431eb36ca3b438dc569b72e06dd..14eb63b51a48d28ac82621567d5457d48f2ac1c9 100644 --- a/window_scene/interfaces/include/ws_common.h +++ b/window_scene/interfaces/include/ws_common.h @@ -49,6 +49,8 @@ constexpr int32_t INVALID_SESSION_ID = 0; constexpr int32_t DEFAULT_REQUEST_FROM_SCB_ID = -1; constexpr int32_t WINDOW_SUPPORT_MODE_MAX_SIZE = 4; constexpr int32_t DEFAULT_SCALE_RATIO = 100; +constexpr uint32_t COLOR_WHITE = 0xffffffff; +constexpr uint32_t COLOR_BLACK = 0xff000000; const std::string WINDOW_SCREEN_LOCK_PREFIX = "windowLock_"; const std::string VIEW_SCREEN_LOCK_PREFIX = "viewLock_"; @@ -373,6 +375,11 @@ struct AtomicServiceInfo { std::vector supportWindowMode_; }; +struct PendingSessionActivationConfig { + bool forceStart = false; // is compulsion open + bool forceNewWant = true; +}; + struct SessionInfo { std::string bundleName_ = ""; std::string moduleName_ = ""; @@ -1074,7 +1081,7 @@ enum class SnapshotNodeType : uint32_t { APP_NODE, }; -enum class ScreenLockReason { +enum class BackgroundReason { DEFAULT = 0, /* diff --git a/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/include/ani_scene_session_utils.h b/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/include/ani_scene_session_utils.h index 453151354434ca8de00a010e94c337de2cff2715..6439b858704f43fc0c82d9c92e9f3ee062d61305 100644 --- a/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/include/ani_scene_session_utils.h +++ b/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/include/ani_scene_session_utils.h @@ -15,6 +15,7 @@ #ifndef OHOS_ANI_SCENE_SESSION_UTILS_H #define OHOS_ANI_SCENE_SESSION_UTILS_H + #include "ani.h" #include "wm_common.h" diff --git a/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/src/ani_err_utils.cpp b/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/src/ani_err_utils.cpp index bdb800577861c4b0d7754087b3c8779028327633..958ee3274cfa222a9e6df83d5559eb5d4b165534 100644 --- a/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/src/ani_err_utils.cpp +++ b/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/src/ani_err_utils.cpp @@ -14,6 +14,7 @@ */ #include "ani_err_utils.h" + #include "ani_scene_session_utils.h" #include "window_manager_hilog.h" diff --git a/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/src/ani_scene_session_manager.cpp b/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/src/ani_scene_session_manager.cpp index e3d4c6248e37ec19d0cb98046e57398ccec838ba..502acf108a1f1972b1d04202fc477b65f516235e 100644 --- a/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/src/ani_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/src/ani_scene_session_manager.cpp @@ -14,12 +14,14 @@ */ #include "ani_scene_session_manager.h" -#include "ani_scene_session_utils.h" + +#include + #include "ani.h" +#include "ani_scene_session_utils.h" #include "root_scene.h" -#include "wm_common.h" #include "window_manager_hilog.h" -#include +#include "wm_common.h" namespace OHOS { namespace Rosen { @@ -34,7 +36,7 @@ ani_status AniSceneSessionManager::Init(ani_env* env, ani_namespace nsp) return ret; } std::unique_ptr aniSceneSessionManager = std::make_unique(); - ret = env->Function_Call_Void(setObjFunc, aniSceneSessionManager.get()); + ret = env->Function_Call_Void(setObjFunc, aniSceneSessionManager.release()); if (ret != ANI_OK) { TLOGE(WmsLogTag::DEFAULT, "[ANI] find setSceneSessionManagerRef func fail %{public}u", ret); return ret; diff --git a/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/src/ani_scene_session_utils.cpp b/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/src/ani_scene_session_utils.cpp index 86b4412e8a863b03fa5ec274312f57f4187e64dc..276f8950c73690f7dec8d10234cbff31088db563 100644 --- a/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/src/ani_scene_session_utils.cpp +++ b/window_scene/interfaces/kits/ani/scene_session_manager/scene_session_manager_ani/src/ani_scene_session_utils.cpp @@ -12,9 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "ani_err_utils.h" + #include "ani_scene_session_utils.h" + #include "ani.h" +#include "ani_err_utils.h" #include "window_manager_hilog.h" namespace OHOS { 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 401574c31f496a735369c428c0f88550fd42e4d3..56e5cd08cf5b2192a78e7c81b8e92fcf274e0bbc 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 @@ -166,8 +166,9 @@ void JsRootSceneSession::ProcessPendingSceneSessionActivationRegister() void JsRootSceneSession::ProcessBatchPendingSceneSessionsActivationRegister() { rootSceneSession_->SetBatchPendingSessionsActivationEventListener([this] - (const std::vector>& sessionInfos) { - this->BatchPendingSessionsActivation(sessionInfos); + (const std::vector>& sessionInfos, + const std::vector>& configs) { + this->BatchPendingSessionsActivation(sessionInfos, configs); }); TLOGD(WmsLogTag::WMS_LIFE, "success"); } @@ -326,18 +327,56 @@ napi_value JsRootSceneSession::CreateSessionInfosNapiValue( } return arrayValue; } + +napi_value JsRootSceneSession::CreatePendingInfosNapiValue( + napi_env env, const std::vector>& sessionInfos, + const std::vector>& configs) +{ + napi_value arrayValue = nullptr; + napi_create_array_with_length(env, sessionInfos.size(), &arrayValue); + + if (arrayValue == nullptr) { + TLOGE(WmsLogTag::WMS_LIFE, "Failed to create napi array"); + return NapiGetUndefined(env); + } + + if (configs.empty()) { + TLOGE(WmsLogTag::WMS_LIFE, "configs is empty"); + return CreateSessionInfosNapiValue(env, sessionInfos); + } + + if (sessionInfos.size() != configs.size()) { + TLOGE(WmsLogTag::WMS_LIFE, + "The caller Param is illegal parameters.sessionInfo: %{public}zu configs: %{public}zu", + sessionInfos.size(), configs.size()); + return NapiGetUndefined(env); + } + + TLOGI(WmsLogTag::WMS_LIFE, "sessionInfos:%{public}zu", sessionInfos.size()); + int32_t index = 0; + for (size_t i = 0; i < sessionInfos.size(); i++) { + napi_value objValue = nullptr; + napi_create_object(env, &objValue); + if (objValue == nullptr) { + TLOGE(WmsLogTag::WMS_LIFE, "failed to create napi object"); + return NapiGetUndefined(env); + } + napi_set_element(env, arrayValue, index++, CreateJsSessionInfo(env, *(sessionInfos[i]), configs[i])); + } + return arrayValue; +} void JsRootSceneSession::BatchPendingSessionsActivationInner( - const std::vector>& sessionInfos) + const std::vector>& sessionInfos, + const std::vector>& configs) { const char* const where = __func__; - auto task = [jsCallBack = GetJSCallback(BATCH_PENDING_SCENE_ACTIVE_CB), sessionInfos, env = env_, where] { + auto task = [jsCallBack = GetJSCallback(BATCH_PENDING_SCENE_ACTIVE_CB), sessionInfos, configs, env = env_, where] { if (!jsCallBack) { TLOGNE(WmsLogTag::WMS_LIFE, "%{public}s jsCallBack is nullptr", where); return; } - - napi_value jsSessionInfos = CreateSessionInfosNapiValue(env, sessionInfos); + napi_value jsSessionInfos = CreatePendingInfosNapiValue(env, sessionInfos, configs); if (jsSessionInfos == nullptr) { TLOGNE(WmsLogTag::WMS_LIFE, "%{public}s target session info is nullptr", where); return; @@ -414,7 +453,8 @@ void JsRootSceneSession::PendingSessionActivation(SessionInfo& info) } } -void JsRootSceneSession::BatchPendingSessionsActivation(const std::vector>& sessionInfos) +void JsRootSceneSession::BatchPendingSessionsActivation(const std::vector>& sessionInfos, + const std::vector>& configs) { for (auto& info : sessionInfos) { if (info == nullptr) { @@ -441,7 +481,7 @@ void JsRootSceneSession::BatchPendingSessionsActivation(const std::vector>& sessionInfos); - void BatchPendingSessionsActivationInner(const std::vector>& sessionInfos); + void BatchPendingSessionsActivation(const std::vector>& sessionInfos, + const std::vector>& configs); + void BatchPendingSessionsActivationInner(const std::vector>& sessionInfos, + const std::vector>& configs); static napi_value CreateSessionInfosNapiValue( napi_env env, const std::vector>& sessionInfos); + static napi_value CreatePendingInfosNapiValue( + napi_env env, const std::vector>& sessionInfos, + const std::vector>& configs); napi_env env_; std::map> jsCbMap_; mutable std::shared_mutex jsCbMapMutex_; diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_rss_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_rss_session.cpp index 313497e52e4b317a272dfe9193986bbad5c0f1a4..9c3d7258eda7d583ed04c84977ebf966b6c5a4a0 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_rss_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_rss_session.cpp @@ -112,6 +112,11 @@ void SetMapValue(napi_env env, const std::string& key, const T& value, napi_valu napi_set_property(env, object, keyInfo, valueInfo); } +bool IsJsonString(const nlohmann::json& payload, const std::string& key) +{ + return payload.contains(key) && payload[key].is_string(); +} + napi_value RssSession::DealRssReply(napi_env env, const nlohmann::json& payload, const nlohmann::json& reply) { WLOGFI("[NAPI]"); @@ -122,6 +127,12 @@ napi_value RssSession::DealRssReply(napi_env env, const nlohmann::json& payload, return NapiGetUndefined(env); } + if (IsJsonString(reply, "resultType") && reply.at("resultType") == "loadSceneJudgement" && + IsJsonString(reply, "resultValue")) { + SetMapValue(env, "result", reply["resultValue"].get(), objValue); + return objValue; + } + if (!reply.contains("result") || !reply["result"].is_string() || reply.at("result") == "") { WLOGFE("Reply not find result key!"); return NapiGetUndefined(env); 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 d17da56b6b701e23886f429539e84c7b4a139097..a35cb8653a52afc3f15f264c41d8aa75e9d43e51 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 @@ -429,6 +429,8 @@ napi_value JsSceneSession::Create(napi_env env, const sptr& sessio CreateJsValue(env, static_cast(session->IsSystemKeyboard()))); napi_set_named_property(env, objValue, "bundleName", CreateJsValue(env, session->GetSessionInfo().bundleName_)); + napi_set_named_property(env, objValue, "windowName", + CreateJsValue(env, session->GetWindowName())); napi_set_named_property(env, objValue, "zLevel", CreateJsValue(env, static_cast(session->GetSubWindowZLevel()))); napi_set_named_property(env, objValue, "subWindowOutlineEnabled", @@ -678,13 +680,14 @@ void JsSceneSession::ProcessBatchPendingSceneSessionsActivationRegister() } const char* const where = __func__; session->SetBatchPendingSessionsActivationEventListener( - [weakThis = wptr(this), where](std::vector>& sessionInfos) { + [weakThis = wptr(this), where](std::vector>& sessionInfos, + const std::vector>& configs) { auto jsSceneSession = weakThis.promote(); if (!jsSceneSession) { TLOGNE(WmsLogTag::WMS_LIFE, "%{public}s jsSceneSession is null", where); return; } - jsSceneSession->BatchPendingSessionsActivation(sessionInfos); + jsSceneSession->BatchPendingSessionsActivation(sessionInfos, configs); }); TLOGD(WmsLogTag::WMS_LIFE, "success"); } @@ -4706,6 +4709,7 @@ void JsSceneSession::PendingSessionActivationInner(std::shared_ptr sessionInfo->persistentId_, LifeCycleTaskType::START); return; } + napi_value jsSessionInfo = CreateJsSessionInfo(env, *sessionInfo); if (jsSessionInfo == nullptr) { TLOGNE(WmsLogTag::WMS_LIFE, "target session info is nullptr"); @@ -4749,9 +4753,52 @@ napi_value JsSceneSession::CreateSessionInfosNapiValue( } return arrayValue; } + +napi_value JsSceneSession::CreatePendingInfosNapiValue(napi_env env, + const std::vector>& sessionInfos, + const std::vector>& configs) +{ + if (configs.empty()) { + return CreateSessionInfosNapiValue(env, sessionInfos); + } + + if (sessionInfos.size() != configs.size()) { + TLOGE(WmsLogTag::WMS_LIFE, + "The caller Param is illegal parameters.sessionInfo: %{public}zu configs: %{public}zu", + sessionInfos.size(), configs.size()); + return NapiGetUndefined(env); + } + + napi_value arrayValue = nullptr; + napi_create_array_with_length(env, sessionInfos.size(), &arrayValue); + if (arrayValue == nullptr) { + TLOGE(WmsLogTag::WMS_LIFE, "Failed to create napi array"); + return NapiGetUndefined(env); + } + + int32_t index = 0; + for (size_t i = 0; i < sessionInfos.size(); i++) { + napi_value objValue = nullptr; + napi_create_object(env, &objValue); + if (objValue == nullptr) { + TLOGE(WmsLogTag::WMS_LIFE, "failed to create napi object"); + return NapiGetUndefined(env); + } + napi_set_element(env, arrayValue, index++, CreateJsSessionInfo(env, *(sessionInfos[i]), configs[i])); + } + return arrayValue; +} -void JsSceneSession::BatchPendingSessionsActivation(const std::vector>& sessionInfos) +void JsSceneSession::BatchPendingSessionsActivation(const std::vector>& sessionInfos, + const std::vector>& configs) { + if (!configs.empty() && sessionInfos.size() != configs.size()) { + TLOGE(WmsLogTag::WMS_LIFE, + "The caller Param is illegal parameters.sessionInfo: %{public}zu configs: %{public}zu", + sessionInfos.size(), configs.size()); + return; + } + std::vector> sceneSessions; for (auto& info : sessionInfos) { if (info == nullptr) { @@ -4772,14 +4819,15 @@ void JsSceneSession::BatchPendingSessionsActivation(const std::vectorisCalledRightlyByCallerId_); } } - BatchPendingSessionsActivationInner(sessionInfos); + BatchPendingSessionsActivationInner(sessionInfos, configs); } -void JsSceneSession::BatchPendingSessionsActivationInner(const std::vector>& sessionInfos) +void JsSceneSession::BatchPendingSessionsActivationInner(const std::vector>& sessionInfos, + const std::vector>& configs) { const char* const where = __func__; auto task = [weakThis = wptr(this), persistentId = persistentId_, weakSession = weakSession_, - sessionInfos, env = env_, where] { + sessionInfos, configs, env = env_, where] { auto session = weakSession.promote(); if (session == nullptr) { TLOGNE(WmsLogTag::WMS_LIFE, "session is nullptr"); @@ -4795,7 +4843,7 @@ void JsSceneSession::BatchPendingSessionsActivationInner(const std::vector sessionInfo = std::make_shared(info); auto task = [weakThis = wptr(this), persistentId = persistentId_, sessionInfo, env = env_, params] { auto jsSceneSession = weakThis.promote(); @@ -5147,7 +5194,6 @@ void JsSceneSession::PendingSessionToBackgroundForDelegator(const SessionInfo& i TLOGI(WmsLogTag::WMS_LIFE, "bundleName=%{public}s, abilityName=%{public}s, shouldBackToCaller=%{public}d", info.bundleName_.c_str(), info.abilityName_.c_str(), shouldBackToCaller); - std::shared_ptr sessionInfo = std::make_shared(info); auto task = [weakThis = wptr(this), persistentId = persistentId_, sessionInfo, env = env_, shouldBackToCaller] { auto jsSceneSession = weakThis.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 d29f92ad27edf8fcd8e0fdc0213a1a50fad67473..8eea4aa1b245621f189e8b54d297a5806c06b174 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 @@ -147,8 +147,10 @@ private: sptr GenSceneSession(SessionInfo& info); void PendingSessionActivation(SessionInfo& info); void PendingSessionActivationInner(std::shared_ptr sessionInfo); - void BatchPendingSessionsActivation(const std::vector>& sessionInfos); - void BatchPendingSessionsActivationInner(const std::vector>& sessionInfos); + void BatchPendingSessionsActivation(const std::vector>& sessionInfos, + const std::vector>& configs); + void BatchPendingSessionsActivationInner(const std::vector>& sessionInfos, + const std::vector>& configs); void OnSessionStateChange(const SessionState& state); void OnUpdateTransitionAnimation(const WindowTransitionType& type, const TransitionAnimation& animation); void OnSessionEvent(uint32_t eventId, const SessionEventParam& param); @@ -251,6 +253,9 @@ private: static napi_value SendFbActionEvent(napi_env env, napi_callback_info info); static napi_value CreateSessionInfosNapiValue( napi_env env, const std::vector>& sessionInfos); + static napi_value CreatePendingInfosNapiValue(napi_env env, + const std::vector>& sessionInfos, + const std::vector>& configs); static napi_value SetPcAppInpadCompatibleMode(napi_env env, napi_callback_info info); static napi_value SetPcAppInpadSpecificSystemBarInvisible(napi_env env, napi_callback_info info); static napi_value SetPcAppInpadOrientationLandscape(napi_env env, napi_callback_info info); 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 b7d8fb1ea9dfda4e220dd101ec759ee577d44e22..e9dff81a97f418746ab42f3e2a99910600aa1971 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 @@ -318,12 +318,16 @@ napi_value JsSceneSessionManager::Init(napi_env env, napi_value exportObj) JsSceneSessionManager::UpdateRecentMainSessionInfos); BindNativeFunction(env, exportObj, "supportSnapshotAllSessionStatus", moduleName, JsSceneSessionManager::SupportSnapshotAllSessionStatus); + BindNativeFunction(env, exportObj, "supportPreloadStartingWindow", moduleName, + JsSceneSessionManager::SupportPreloadStartingWindow); BindNativeFunction(env, exportObj, "setUIEffectControllerAliveInUI", moduleName, JsSceneSessionManager::SetUIEffectControllerAliveInUI); BindNativeFunction(env, exportObj, "setPiPSettingSwitchStatus", moduleName, JsSceneSessionManager::SetPiPSettingSwitchStatus); BindNativeFunction(env, exportObj, "UpdateSystemDecorEnable", moduleName, JsSceneSessionManager::UpdateSystemDecorEnable); + BindNativeFunction(env, exportObj, "applyFeatureConfig", moduleName, + JsSceneSessionManager::ApplyFeatureConfig); return NapiGetUndefined(env); } @@ -1453,6 +1457,35 @@ napi_value JsSceneSessionManager::SetSupportFunctionType(napi_env env, napi_call return (me != nullptr) ? me->OnSetSupportFunctionType(env, info) : nullptr; } +napi_value JsSceneSessionManager::ApplyFeatureConfig(napi_env env, napi_callback_info info) +{ + TLOGI(WmsLogTag::WMS_MAIN, "[NAPI]"); + JsSceneSessionManager* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnApplyFeatureConfig(env, info) : nullptr; +} + +napi_value JsSceneSessionManager::OnApplyFeatureConfig(napi_env env, napi_callback_info info) +{ + size_t argc = ARGC_ONE; + napi_value argv[ARGC_ONE] = { nullptr }; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc < ARGC_ONE) { + TLOGE(WmsLogTag::WMS_MAIN, "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::unordered_map configMap; + if (!ConvertStringMapFromJs(env, argv[ARG_INDEX_ZERO], configMap)) { + TLOGE(WmsLogTag::WMS_MAIN, "Failed to convert parameter to configMap"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + SceneSessionManager::GetInstance().ApplyFeatureConfig(configMap); + return NapiGetUndefined(env); +} + bool JsSceneSessionManager::IsCallbackRegistered(napi_env env, const std::string& type, napi_value jsListenerObject) { HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "JsSceneSessionManager::IsCallbackRegistered[%s]", type.c_str()); @@ -2188,10 +2221,10 @@ napi_value JsSceneSessionManager::OnRequestSceneSessionBackground(napi_env env, TLOGI(WmsLogTag::WMS_LIFE, "isSaveSnapshot: %{public}u", isSaveSnapshot); } - ScreenLockReason reason = ScreenLockReason::DEFAULT; + BackgroundReason reason = BackgroundReason::DEFAULT; if (argc >= ARGC_FIVE) { ConvertFromJsValue(env, argv[ARGC_FOUR], reason); - TLOGI(WmsLogTag::WMS_LIFE, "screenLockReason: %{public}u", reason); + TLOGI(WmsLogTag::WMS_LIFE, "backgroundReason: %{public}u", reason); } SceneSessionManager::GetInstance().RequestSceneSessionBackground(sceneSession, isDelegator, isToDesktop, @@ -3643,6 +3676,19 @@ napi_value JsSceneSessionManager::OnSupportSnapshotAllSessionStatus(napi_env env return NapiGetUndefined(env); } +napi_value JsSceneSessionManager::SupportPreloadStartingWindow(napi_env env, napi_callback_info info) +{ + TLOGI(WmsLogTag::WMS_PATTERN, "[NAPI]"); + JsSceneSessionManager* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnSupportPreloadStartingWindow(env, info) : nullptr; +} + +napi_value JsSceneSessionManager::OnSupportPreloadStartingWindow(napi_env env, napi_callback_info info) +{ + SceneSessionManager::GetInstance().ConfigSupportPreloadStartingWindow(); + return NapiGetUndefined(env); +} + napi_value JsSceneSessionManager::SupportCreateFloatWindow(napi_env env, napi_callback_info info) { TLOGI(WmsLogTag::WMS_LIFE, "[NAPI]"); 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 e23b26c71536b350c1a0f5d580e1a36fb093d5a6..8e0172a96c6f91a22b94f62db6e3239cb8146190 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 @@ -135,6 +135,7 @@ public: static napi_value GetApplicationInfo(napi_env env, napi_callback_info info); static napi_value SetUIEffectControllerAliveInUI(napi_env env, napi_callback_info info); static napi_value SupportCreateFloatWindow(napi_env env, napi_callback_info info); + static napi_value ApplyFeatureConfig(napi_env env, napi_callback_info info); /* * PC Window @@ -170,6 +171,7 @@ public: * Window Pattern */ static napi_value SupportSnapshotAllSessionStatus(napi_env env, napi_callback_info info); + static napi_value SupportPreloadStartingWindow(napi_env env, napi_callback_info info); /* * PiP Window @@ -256,6 +258,7 @@ private: napi_value OnSupportZLevel(napi_env env, napi_callback_info info); napi_value OnSetSupportFunctionType(napi_env env, napi_callback_info info); napi_value OnUpdateRecentMainSessionInfos(napi_env env, napi_callback_info info); + napi_value OnApplyFeatureConfig(napi_env env, napi_callback_info info); /* * PC Window @@ -400,6 +403,7 @@ private: * Window Pattern */ napi_value OnSupportSnapshotAllSessionStatus(napi_env env, napi_callback_info info); + napi_value OnSupportPreloadStartingWindow(napi_env env, napi_callback_info info); napi_value OnUpdateSystemDecorEnable(napi_env env, napi_callback_info info); }; 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 4d3db9a4916b1f5838c4925d6be5da1fd5f3ece2..19e893329b725a1d1de400a6998eebf194779f9c 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 @@ -1396,7 +1396,22 @@ napi_value CreateSupportWindowModes(napi_env env, return arrayValue; } -napi_value CreateJsSessionInfo(napi_env env, const SessionInfo& sessionInfo) +napi_value CreateJsSessionPendingConfigs(napi_env env, const PendingSessionActivationConfig &config) +{ + napi_value objValue = nullptr; + napi_create_object(env, &objValue); + if (objValue == nullptr) { + WLOGFE("Failed to get jsObject"); + return nullptr; + } + + napi_set_named_property(env, objValue, "forceStart", CreateJsValue(env, config.forceStart)); + napi_set_named_property(env, objValue, "forceNewWant", CreateJsValue(env, config.forceNewWant)); + return objValue; +} + +napi_value CreateJsSessionInfo(napi_env env, const SessionInfo& sessionInfo, + const std::shared_ptr& config) { napi_value objValue = nullptr; napi_create_object(env, &objValue); @@ -1448,6 +1463,12 @@ napi_value CreateJsSessionInfo(napi_env env, const SessionInfo& sessionInfo) SetJsSessionInfoByWant(env, sessionInfo, objValue); napi_set_named_property(env, objValue, "supportWindowModes", CreateSupportWindowModes(env, sessionInfo.supportedWindowModes)); + + if (config != nullptr) { + napi_set_named_property(env, objValue, "extendPendingActivationConfig", + CreateJsSessionPendingConfigs(env, *(config))); + } + napi_set_named_property(env, objValue, "specifiedFlag", CreateJsValue(env, sessionInfo.specifiedFlag_)); if (sessionInfo.want != nullptr) { napi_set_named_property(env, objValue, "want", AppExecFwk::WrapWant(env, sessionInfo.GetWantSafely())); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.h index 8334bb9312afe945d7881e338aa9001f0950487f..077987db168dabf026b469c8c0030535fa31f721 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.h @@ -212,7 +212,9 @@ bool ConvertJsonFromJs(napi_env env, napi_value value, nlohmann::json& payload); bool ParseArrayStringValue(napi_env env, napi_value array, std::vector& vector); bool ConvertProcessOptionFromJs(napi_env env, napi_value jsObject, std::shared_ptr processOptions); -napi_value CreateJsSessionInfo(napi_env env, const SessionInfo& sessionInfo); +napi_value CreateJsSessionPendingConfigs(napi_env env, const PendingSessionActivationConfig& config); +napi_value CreateJsSessionInfo(napi_env env, const SessionInfo& sessionInfo, + const std::shared_ptr& config = nullptr); void ProcessPendingSessionActivationResult(napi_env env, napi_value callResult, const std::shared_ptr& sessionInfo); bool ConvertSessionResultFromJsValue( diff --git a/window_scene/interfaces/kits/napi/screen_session_manager/js_screen_session_manager.cpp b/window_scene/interfaces/kits/napi/screen_session_manager/js_screen_session_manager.cpp index caed713d0a303745ffa644eb70e6e423f51c18da..5dc9bbba1a2df1a81ca07c828156e8e7cc86670a 100644 --- a/window_scene/interfaces/kits/napi/screen_session_manager/js_screen_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/screen_session_manager/js_screen_session_manager.cpp @@ -145,6 +145,10 @@ napi_value JsScreenSessionManager::Init(napi_env env, napi_value exportObj) BindNativeFunction(env, exportObj, "freezeScreen", moduleName, JsScreenSessionManager::FreezeScreen); BindNativeFunction(env, exportObj, "getScreenSnapshotWithAllWindows", moduleName, JsScreenSessionManager::GetScreenSnapshotWithAllWindows); + BindNativeFunction(env, exportObj, "notifySwitchUserAnimationFinish", moduleName, + JsScreenSessionManager::NotifySwitchUserAnimationFinish); + BindNativeFunction(env, exportObj, "registerSwitchUserAnimationNotification", moduleName, + JsScreenSessionManager::RegisterSwitchUserAnimationNotification); return NapiGetUndefined(env); } @@ -395,6 +399,20 @@ napi_value JsScreenSessionManager::GetScreenSnapshotWithAllWindows(napi_env env, return (me != nullptr) ? me->OnGetScreenSnapshotWithAllWindows(env, info) : nullptr; } +napi_value JsScreenSessionManager::NotifySwitchUserAnimationFinish(napi_env env, napi_callback_info info) +{ + TLOGD(WmsLogTag::DMS, "[NAPI]NotifyScreenSwitchUserAnimateFinish"); + JsScreenSessionManager* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnNotifySwitchUserAnimationFinish(env, info) : nullptr; +} + +napi_value JsScreenSessionManager::RegisterSwitchUserAnimationNotification(napi_env env, napi_callback_info info) +{ + TLOGD(WmsLogTag::DMS, "[NAPI]RegisterSwitchUserAnimationNotification"); + JsScreenSessionManager* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnRegisterSwitchUserAnimationNotification(env, info) : nullptr; +} + void JsScreenSessionManager::OnScreenConnected(const sptr& screenSession) { if (screenConnectionCallback_ == nullptr || screenSession == nullptr) { @@ -1318,4 +1336,50 @@ napi_value JsScreenSessionManager::OnGetScreenSnapshotWithAllWindows(napi_env en } return nativeData; } + +napi_value JsScreenSessionManager::OnNotifySwitchUserAnimationFinish(napi_env env, napi_callback_info info) +{ + TLOGI(WmsLogTag::DMS, "[NAPI]notify switch user animate finish"); + size_t argc = ARGC_ONE; + napi_value argv[ARGC_ONE] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc < ARGC_ONE) { + TLOGE(WmsLogTag::DMS, "[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 description; + if (!ConvertFromJsValue(env, argv[0], description)) { + TLOGE(WmsLogTag::DMS, "[NAPI]Failed to convert parameter to description"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + ScreenSessionManagerClient::GetInstance().NotifySwitchUserAnimationFinish(description); + return NapiGetUndefined(env); +} + +napi_value JsScreenSessionManager::OnRegisterSwitchUserAnimationNotification(napi_env env, napi_callback_info info) +{ + TLOGD(WmsLogTag::DMS, "[NAPI]register animate need notify"); + size_t argc = ARGC_ONE; + napi_value argv[ARGC_ONE] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc < ARGC_ONE) { + TLOGE(WmsLogTag::DMS, "[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 description; + if (!ConvertFromJsValue(env, argv[0], description)) { + TLOGE(WmsLogTag::DMS, "[NAPI]Failed to convert parameter to description"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + ScreenSessionManagerClient::GetInstance().RegisterSwitchUserAnimationNotification(description); + return NapiGetUndefined(env); +} } // namespace OHOS::Rosen diff --git a/window_scene/interfaces/kits/napi/screen_session_manager/js_screen_session_manager.h b/window_scene/interfaces/kits/napi/screen_session_manager/js_screen_session_manager.h index e8cc6bf4e8f1334d374cafa5901fb4b62b9f9227..359b3d03cf03f5a5039f3a34edd219b468f87bd0 100644 --- a/window_scene/interfaces/kits/napi/screen_session_manager/js_screen_session_manager.h +++ b/window_scene/interfaces/kits/napi/screen_session_manager/js_screen_session_manager.h @@ -75,6 +75,8 @@ private: static napi_value GetFoldDisplayMode(napi_env env, napi_callback_info info); static napi_value FreezeScreen(napi_env env, napi_callback_info info); static napi_value GetScreenSnapshotWithAllWindows(napi_env env, napi_callback_info info); + static napi_value NotifySwitchUserAnimationFinish(napi_env env, napi_callback_info info); + static napi_value RegisterSwitchUserAnimationNotification(napi_env env, napi_callback_info info); napi_value OnRegisterCallback(napi_env env, const napi_callback_info info); napi_value OnUpdateScreenRotationProperty(napi_env env, const napi_callback_info info); @@ -110,6 +112,8 @@ private: napi_value OnGetFoldDisplayMode(napi_env env, napi_callback_info info); napi_value OnFreezeScreen(napi_env env, napi_callback_info info); napi_value OnGetScreenSnapshotWithAllWindows(napi_env env, napi_callback_info info); + napi_value OnNotifySwitchUserAnimationFinish(napi_env env, napi_callback_info info); + napi_value OnRegisterSwitchUserAnimationNotification(napi_env env, napi_callback_info info); std::shared_ptr screenConnectionCallback_; std::shared_ptr shutdownCallback_; diff --git a/window_scene/screen_session_manager/BUILD.gn b/window_scene/screen_session_manager/BUILD.gn index 4c7311cbc750fe0db63219178588a36f223fcbdb..d2f89128ab798ad8539db502c72c4ed038bd4485 100644 --- a/window_scene/screen_session_manager/BUILD.gn +++ b/window_scene/screen_session_manager/BUILD.gn @@ -61,6 +61,7 @@ ohos_shared_library("screen_session_manager") { sources = [ "../../dm/src/zidl/display_manager_agent_proxy.cpp", "../screen_session_manager_client/src/zidl/screen_session_manager_client_proxy.cpp", + "../session_manager/src/ffrt_queue_helper.cpp", "src/connection/screen_cast_connection.cpp", "src/connection/screen_session_ability_connection.cpp", "src/connection/screen_snapshot_picker_connection.cpp", @@ -125,6 +126,7 @@ ohos_shared_library("screen_session_manager") { "data_share:datashare_common", "data_share:datashare_consumer", "eventhandler:libeventhandler", + "ffrt:libffrt", "graphic_2d:librender_service_base", "graphic_2d:librender_service_client", "hicollie:libhicollie", diff --git a/window_scene/screen_session_manager/include/fold_screen_controller/secondary_display_fold_policy.h b/window_scene/screen_session_manager/include/fold_screen_controller/secondary_display_fold_policy.h index f135dc97634f31da30001e54233a90b477b206fa..d86637ec9f77d60136dba6ca84716dbfebd625ba 100644 --- a/window_scene/screen_session_manager/include/fold_screen_controller/secondary_display_fold_policy.h +++ b/window_scene/screen_session_manager/include/fold_screen_controller/secondary_display_fold_policy.h @@ -54,7 +54,8 @@ private: void SendPropertyChangeResult(sptr screenSession, ScreenId screenId, ScreenPropertyChangeReason reason, FoldDisplayMode displayMode); void SetStatusConditionalActiveRectAndTpFeature(ScreenProperty &screenProperty); - void SetStatusFullActiveRectAndTpFeature(const sptr& screenSession, ScreenProperty &screenProperty); + void SetStatusFullActiveRectAndTpFeature(const sptr& screenSession, ScreenProperty& screenProperty, + bool isNeedToSetSwitch = true); void SetStatusMainActiveRectAndTpFeature(const sptr& screenSession, ScreenProperty &screenProperty); void SetStatusGlobalFullActiveRectAndTpFeature(const sptr& screenSession, ScreenProperty &screenProperty); diff --git a/window_scene/screen_session_manager/include/fold_screen_controller/sensor_fold_state_manager/sensor_fold_state_manager.h b/window_scene/screen_session_manager/include/fold_screen_controller/sensor_fold_state_manager/sensor_fold_state_manager.h index 3402eee3973b908c32bd37b04ff188e216be423a..7f2a481d9c4aa43ebfd3a87a5994f020e532cb59 100644 --- a/window_scene/screen_session_manager/include/fold_screen_controller/sensor_fold_state_manager/sensor_fold_state_manager.h +++ b/window_scene/screen_session_manager/include/fold_screen_controller/sensor_fold_state_manager/sensor_fold_state_manager.h @@ -66,7 +66,6 @@ private: void ProcessNotifyFoldStatusChange(FoldStatus currentStatus, FoldStatus nextStatus, const std::vector& angles, sptr foldScreenPolicy); - std::shared_ptr taskScheduler_ = nullptr; }; } // namespace OHOS::Rosen #endif //OHOS_ROSEN_SMALL_DEVICE_SCREEN_SENSOR_MANAGER_H \ No newline at end of file diff --git a/window_scene/screen_session_manager/include/multi_screen_manager.h b/window_scene/screen_session_manager/include/multi_screen_manager.h index a9b40af3d8526342a4facfaf1db97cb9964ef2ad..22ec14db26cd2e260867463d9cb70194134ccac6 100644 --- a/window_scene/screen_session_manager/include/multi_screen_manager.h +++ b/window_scene/screen_session_manager/include/multi_screen_manager.h @@ -33,7 +33,7 @@ public: DMError UniqueSwitch(const std::vector& screenIds, std::vector& displayIds); DMError MirrorSwitch(const ScreenId mainScreenId, const std::vector& screenIds, DMRect mainScreenRegion, - ScreenId& screenGroupId); + ScreenId& screenGroupId, bool forceMirror = false); void MultiScreenModeChange(sptr mainSession, sptr secondarySession, const std::string& operateType); @@ -61,9 +61,10 @@ private: std::vector& physicalScreenIds, std::vector& virtualScreenIds); DMError VirtualScreenMirrorSwitch(const ScreenId mainScreenId, const std::vector& screenIds, - DMRect mainScreenRegion, ScreenId& screenGroupId); + DMRect mainScreenRegion, ScreenId& screenGroupId, bool forceMirror = false); - DMError PhysicalScreenMirrorSwitch(const std::vector& screenIds, DMRect mainScreenRegion); + DMError PhysicalScreenMirrorSwitch(const std::vector& screenIds, DMRect mainScreenRegion, + bool forceMirror = false); DMError PhysicalScreenUniqueSwitch(const std::vector& screenIds); diff --git a/window_scene/screen_session_manager/include/screen_session_manager.h b/window_scene/screen_session_manager/include/screen_session_manager.h index 548ea91ffafe3dc8f8e3c9be1ae8f48eeb9d14fa..241d6b166ca474d0dd38ccae5f79765c8392c548 100644 --- a/window_scene/screen_session_manager/include/screen_session_manager.h +++ b/window_scene/screen_session_manager/include/screen_session_manager.h @@ -31,6 +31,7 @@ #include "session_display_power_controller.h" #include "wm_single_instance.h" #include "screen_edid_parse.h" +#include "session_manager/include/ffrt_queue_helper.h" #include "agent_death_recipient.h" #include "screen.h" @@ -129,7 +130,7 @@ public: virtual DMError DestroyVirtualScreen(ScreenId screenId) override; DMError ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height) override; virtual DMError MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenIds, - ScreenId& screenGroupId) override; + ScreenId& screenGroupId, bool forceMirror = false) override; virtual DMError MakeMirrorForRecord(ScreenId mainScreenId, std::vector mirrorScreenIds, ScreenId& screenGroupId) override; virtual DMError MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenIds, @@ -169,6 +170,9 @@ public: bool SetRotationFromWindow(Rotation targetRotation); sptr GetScreenModesByDisplayId(DisplayId displayId); sptr GetScreenInfoByDisplayId(DisplayId displayId); + void NotifyDisplayChangedByUid(const std::map>& screenSessionMap, + DisplayChangeEvent event, int32_t uid); + void NotifyDisplayChangedByUidInner(sptr displayInfo, DisplayChangeEvent event, int32_t uid); void NotifyDisplayCreate(sptr displayInfo); void NotifyDisplayDestroy(DisplayId displayId); void NotifyAndPublishEvent(sptr displayInfo, ScreenId screenId, sptr screenSession); @@ -205,7 +209,8 @@ public: std::map& removeChildResMap); bool CheckScreenInScreenGroup(sptr screen) const; - DMError SetMirror(ScreenId screenId, std::vector screens, DMRect mainScreenRegion); + DMError SetMirror(ScreenId screenId, std::vector screens, DMRect mainScreenRegion, + bool forceMirror = false); DMError StopScreens(const std::vector& screenIds, ScreenCombination stopCombination); void NotifyScreenConnected(sptr screenInfo); @@ -299,7 +304,7 @@ public: void SetIsOuterOnlyMode(bool isOuterOnlyMode); bool GetIsOuterOnlyModeBeforePowerOff(); void SetIsOuterOnlyModeBeforePowerOff(bool isOuterOnlyModeBeforePowerOff); - void OnVerticalChangeBoundsWhenSwitchUser(sptr screenSession); + void OnVerticalChangeBoundsWhenSwitchUser(sptr& screenSession, FoldDisplayMode oldScbDisplayMode); bool SetScreenPower(ScreenPowerStatus status, PowerStateChangeReason reason); void SetScreenPowerForFold(ScreenPowerStatus status); @@ -486,8 +491,12 @@ public: void UpdateDuringCallState(); void SetDuringCallState(bool value); std::shared_ptr GetPowerTaskScheduler() const; + std::shared_ptr GetFfrtQueueHelper() const; bool GetCancelSuspendStatus() const; void RemoveScreenCastInfo(ScreenId screenId); + Rotation GetConfigCorrectionByDisplayMode(FoldDisplayMode displayMode); + Rotation RemoveRotationCorrection(Rotation rotation); + void NotifySwitchUserAnimationFinish() override; protected: ScreenSessionManager(); @@ -515,6 +524,7 @@ private: void InitSecondaryDisplayPhysicalParams(); ScreenId GetPhyScreenId(ScreenId screenId); void UpdateCoordinationRefreshRate(uint32_t refreshRate); + void UpdateSuperFoldRefreshRate(sptr screenSession, uint32_t refreshRate); void GetInternalWidth(); void InitExtendScreenDensity(sptr session, ScreenProperty property); void InitExtendScreenProperty(ScreenId screenId, sptr session, ScreenProperty property); @@ -558,7 +568,7 @@ private: void MultiScreenModeChange(ScreenId mainScreenId, ScreenId secondaryScreenId, const std::string& operateType); void OperateModeChange(ScreenId mainScreenId, ScreenId secondaryScreenId, sptr& firstSession, sptr& secondarySession, const std::string& operateMode); - void SetClientInner(); + void SetClientInner(int32_t newUserId); void RecoverMultiScreenMode(sptr screenSession); void GetCurrentScreenPhyBounds(float& phyWidth, float& phyHeight, bool& isReset, const ScreenId& screenid); void SetPhysicalRotationClientInner(ScreenId screenId, int rotation); @@ -571,7 +581,7 @@ private: void NotifyCaptureStatusChanged(); void NotifyCaptureStatusChanged(bool IsCaptured); DMError DoMakeMirror(ScreenId mainScreenId, std::vector mirrorScreenIds, - DMRect mainScreenRegion, ScreenId& screenGroupId); + DMRect mainScreenRegion, ScreenId& screenGroupId, bool forceMirror = false); bool OnMakeExpand(std::vector screenId, std::vector startPoint); bool OnRemoteDied(const sptr& agent); std::string TransferTypeToString(ScreenType type) const; @@ -629,7 +639,7 @@ private: int NotifyPowerEventForDualDisplay(DisplayPowerEvent event, EventStatus status, PowerStateChangeReason reason); bool IsExtendMode(); - bool IsScreenCasting(); + DMError CanEnterCoordination(); bool GetPcStatus() const; void SetPcStatus(bool isPc); const std::set g_packageNames_ {}; @@ -666,6 +676,7 @@ private: RSInterfaces& rsInterface_; std::shared_ptr taskScheduler_; std::shared_ptr screenPowerTaskScheduler_; + std::shared_ptr ffrtQueueHelper_ = nullptr; /* * multi user @@ -710,6 +721,7 @@ private: std::map, std::vector> screenAgentMap_; std::map> smsScreenGroupMap_; std::map displayHookMap_; + std::map uidAndPidMap_; bool userSwitching_ = false; bool isAutoRotationOpen_ = false; @@ -854,15 +866,38 @@ private: void SetScreenCastInfo(ScreenId screenId, ScreenId castScreenId, ScreenCombination screenCombination); void ChangeMirrorScreenConfig(const sptr& group, const DMRect& mainScreenRegion, sptr& screen); + void InitRotationCorrectionMap(std::string displayModeCorrectionConfig); + void SwapScreenWeightAndHeight(sptr& screenSession); + Rotation GetOldDisplayModeRotation(FoldDisplayMode oldDisplayMode, Rotation rotation); + void HandleScreenRotationAndBoundsWhenSetClient(sptr& screenSession); LowTempMode lowTemp_ {LowTempMode::UNKNOWN}; std::mutex lowTempMutex_; std::mutex pcModeSwitchMutex_; std::atomic displayGroupNum_ { 1 }; + std::unordered_map rotationCorrectionMap_; + std::shared_mutex rotationCorrectionMutex_; // Fold Screen duringcall bool duringCallState_ = false; + mutable std::recursive_mutex userDisplayNodeMapMutex_; + std::map>> userDisplayNodeMap_; + std::condition_variable switchUserDisplayNodeCV_; + std::mutex switchUserDisplayNodeMutex_; + bool animateFinishAllNotified_ = false; + + void AddOrUpdateUserDisplayNode(int32_t userId, ScreenId screenId, std::shared_ptr& displayNode); + void RemoveUserDisplayNode(int32_t userId, ScreenId screenId); + std::map> GetUserDisplayNodeMap(int32_t userId); + void SwitchUserDealUserDisplayNode(int32_t newUserId); + void AddUserDisplayNodeOnTree(int32_t userId); + void RemoveUserDisplayNodeFromTree(int32_t userId); + void SetUserDisplayNodePositionZ(int32_t userId, float positionZ); + void HandleNewUserDisplayNode(int32_t newUserId, bool coldBoot); + void WaitSwitchUserAnimateFinish(int32_t newUserId, bool isColdSwitch); + void MakeMirrorAfterSwitchUser(); + private: class ScbClientListenerDeathRecipient : public IRemoteObject::DeathRecipient { public: diff --git a/window_scene/screen_session_manager/include/zidl/screen_session_manager_interface.h b/window_scene/screen_session_manager/include/zidl/screen_session_manager_interface.h index f864ed54be3d858ba09fc6418d664c963f0c0102..e9ea9dd65534f2afcd5f9bb2200013dce2260ab3 100644 --- a/window_scene/screen_session_manager/include/zidl/screen_session_manager_interface.h +++ b/window_scene/screen_session_manager/include/zidl/screen_session_manager_interface.h @@ -187,7 +187,7 @@ public: virtual sptr GetScreenGroupInfoById(ScreenId screenId) { return nullptr; } virtual DMError GetAllScreenInfos(std::vector>& screenInfos) { return DMError::DM_OK; } virtual DMError MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenIds, - ScreenId& screenGroupId) { return DMError::DM_OK; } + ScreenId& screenGroupId, bool forceMirror = false) { return DMError::DM_OK; } virtual DMError MakeMirrorForRecord(ScreenId mainScreenId, std::vector mirrorScreenIds, ScreenId &screenGroupId) @@ -378,6 +378,7 @@ public: virtual DMError SetScreenPrivacyWindowTagSwitch(ScreenId screenId, const std::vector& privacyWindowTag, bool enable) { return DMError::DM_OK; } virtual bool SynchronizePowerStatus(ScreenPowerState state) { return false; } + virtual void NotifySwitchUserAnimationFinish() {} }; } // namespace Rosen } // namespace OHOS diff --git a/window_scene/screen_session_manager/include/zidl/screen_session_manager_proxy.h b/window_scene/screen_session_manager/include/zidl/screen_session_manager_proxy.h index 172b035950982301c104ebfdd1735aa57454a34b..6069a117e46d3a5f2e9976d66be2ca4578ae245f 100644 --- a/window_scene/screen_session_manager/include/zidl/screen_session_manager_proxy.h +++ b/window_scene/screen_session_manager/include/zidl/screen_session_manager_proxy.h @@ -93,7 +93,7 @@ public: virtual DMError SetVirtualMirrorScreenScaleMode(ScreenId screenId, ScreenScaleMode scaleMode) override; virtual DMError MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenIds, - ScreenId& screenGroupId) override; + ScreenId& screenGroupId, bool forceRecord = false) override; virtual DMError MakeMirrorForRecord(ScreenId mainScreenId, std::vector mirrorScreenIds, ScreenId& screenGroupId) override; virtual DMError MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenIds, @@ -241,6 +241,7 @@ public: DMError SetVirtualScreenAutoRotation(ScreenId screenId, bool enable) override; DMError SetScreenPrivacyWindowTagSwitch(ScreenId screenId, const std::vector& privacyWindowTag, bool enable) override; + void NotifySwitchUserAnimationFinish() override; private: static inline BrokerDelegator delegator_; diff --git a/window_scene/screen_session_manager/src/fold_screen_controller/dual_display_fold_policy.cpp b/window_scene/screen_session_manager/src/fold_screen_controller/dual_display_fold_policy.cpp index cf64385d542667c9d29e321c8a7c8a85983761aa..e93dfe4753a33c689983ccd2b4b8b0fedc78be42 100644 --- a/window_scene/screen_session_manager/src/fold_screen_controller/dual_display_fold_policy.cpp +++ b/window_scene/screen_session_manager/src/fold_screen_controller/dual_display_fold_policy.cpp @@ -583,7 +583,7 @@ void DualDisplayFoldPolicy::TriggerSensorInSub(const sptr& screen TLOGE(WmsLogTag::DMS, "screenSessionMain is null"); return; } - float sensorRotation = screenSessionMain->GetSensorRotation(); + float sensorRotation = screenSessionMain->GetValidSensorRotation(); TLOGI(WmsLogTag::DMS, "sensorRotation = %{public}f", sensorRotation); if (FoldScreenStateInternel::FloatEqualAbs(sensorRotation, VERTICAL_ROTATION) || FoldScreenStateInternel::FloatEqualAbs(sensorRotation, VERTICAL_ROTATION_REVERSE)) { diff --git a/window_scene/screen_session_manager/src/fold_screen_controller/secondary_display_fold_policy.cpp b/window_scene/screen_session_manager/src/fold_screen_controller/secondary_display_fold_policy.cpp index ba1892a016c58c59a65073209798ea32a67f35b2..d1b555fec9ae9c0d6c48b7aa44eeaae55b148a2d 100644 --- a/window_scene/screen_session_manager/src/fold_screen_controller/secondary_display_fold_policy.cpp +++ b/window_scene/screen_session_manager/src/fold_screen_controller/secondary_display_fold_policy.cpp @@ -43,7 +43,7 @@ const int32_t GLOBAL_FULL_STATUS_WIDTH = 2; const int32_t SCREEN_HEIGHT = 3; const int32_t FULL_STATUS_OFFSET_X = 4; constexpr uint32_t HALF_DIVIDER = 2; -constexpr float MAIN_DISPLAY_ROTATION_DEGREE = 180; +constexpr float MAIN_DISPLAY_ROTATION_DEGREE = -270; constexpr float ROTATION_TRANSLATE_X = 612; constexpr float ROTATION_TRANSLATE_Y = -612; constexpr float FULL_NODE_POSITION_Z = 0.0f; @@ -501,12 +501,18 @@ void SecondaryDisplayFoldPolicy::SendPropertyChangeResult(sptr sc { std::lock_guard lock_info(displayInfoMutex_); screenProperty_ = ScreenSessionManager::GetInstance().GetPhyScreenProperty(screenId); + bool isNeedNotifyFoldProperty = true; + bool isNeedToSetSwitch = true; switch (displayMode) { case FoldDisplayMode::FULL: { if (currentDisplayMode_ == FoldDisplayMode::COORDINATION) { + if (currentFoldStatus_ == FoldStatus::EXPAND) { + isNeedToSetSwitch = false; + isNeedNotifyFoldProperty = false; + } CloseCoordinationScreen(); } - SetStatusFullActiveRectAndTpFeature(screenSession, screenProperty_); + SetStatusFullActiveRectAndTpFeature(screenSession, screenProperty_, isNeedToSetSwitch); break; } case FoldDisplayMode::MAIN: { @@ -526,6 +532,7 @@ void SecondaryDisplayFoldPolicy::SendPropertyChangeResult(sptr sc } case FoldDisplayMode::COORDINATION: { if (currentDisplayMode_ == FoldDisplayMode::FULL) { + isNeedNotifyFoldProperty = false; ChangeScreenDisplayModeToCoordination(); SetStatusConditionalActiveRectAndTpFeature(screenProperty_); } @@ -542,14 +549,20 @@ void SecondaryDisplayFoldPolicy::SendPropertyChangeResult(sptr sc if (displayMode == FoldDisplayMode::MAIN) { screenSession->SetRotationAndScreenRotationOnly(Rotation::ROTATION_0); } - screenSession->PropertyChange(oldScreenProperty, reason); + + if (isNeedNotifyFoldProperty) { + screenSession->PropertyChange(oldScreenProperty, reason); + } else { + TLOGI(WmsLogTag::DMS, "PropertyChange...set displayModeChangeStatus"); + SetSecondaryDisplayModeChangeStatus(false); + } TLOGI(WmsLogTag::DMS, "screenBounds : width_= %{public}f, height_= %{public}f", screenSession->GetScreenProperty().GetBounds().rect_.width_, screenSession->GetScreenProperty().GetBounds().rect_.height_); } void SecondaryDisplayFoldPolicy::SetStatusFullActiveRectAndTpFeature(const sptr& screenSession, - ScreenProperty &screenProperty) + ScreenProperty &screenProperty, bool isNeedToSetSwitch) { if (screenParams_.size() < FULL_STATUS_OFFSET_X + 1) { return; @@ -566,7 +579,9 @@ void SecondaryDisplayFoldPolicy::SetStatusFullActiveRectAndTpFeature(const sptr< .h = screenParams_[FULL_STATUS_WIDTH], }; if (!onBootAnimation_) { - RSInterfaces::GetInstance().NotifyScreenSwitched(); + if (isNeedToSetSwitch) { + RSInterfaces::GetInstance().NotifyScreenSwitched(); + } auto response = RSInterfaces::GetInstance().SetScreenActiveRect(0, rectCur); TLOGI(WmsLogTag::DMS, "rs response is %{public}ld", static_cast(response)); } diff --git a/window_scene/screen_session_manager/src/fold_screen_controller/sensor_fold_state_manager/secondary_display_sensor_fold_state_manager.cpp b/window_scene/screen_session_manager/src/fold_screen_controller/sensor_fold_state_manager/secondary_display_sensor_fold_state_manager.cpp index 181a48acbbcbbe3421aabb2308478f32d36ab407..2a3d90029b4f4b2da29e350ea4f3079c051eb77c 100644 --- a/window_scene/screen_session_manager/src/fold_screen_controller/sensor_fold_state_manager/secondary_display_sensor_fold_state_manager.cpp +++ b/window_scene/screen_session_manager/src/fold_screen_controller/sensor_fold_state_manager/secondary_display_sensor_fold_state_manager.cpp @@ -46,6 +46,7 @@ constexpr int32_t HALL_THRESHOLD = 1; constexpr int32_t HALL_FOLDED_THRESHOLD = 0; constexpr int32_t HALF_FOLD_VALUE = 3; constexpr int32_t REFLEXION_VALUE = 2; +constexpr float DEFAULT_ANGLE_VALUE = 5.0F; constexpr uint32_t FULL_WAIT_TIMES = 215; constexpr float ANGLE_DIFF_OF_SECONDARY_AB = 15.0F; @@ -57,19 +58,25 @@ SecondaryDisplaySensorFoldStateManager::~SecondaryDisplaySensorFoldStateManager( void SecondaryDisplaySensorFoldStateManager::HandleAngleOrHallChange(const std::vector& angles, const std::vector& halls, sptr foldScreenPolicy, bool isPostureRegistered) { - if (halls.size() != HALLS_AXIS_SIZE) { - TLOGE(WmsLogTag::DMS, "halls size is not right, halls size %{public}zu", halls.size()); + if (halls.size() != HALLS_AXIS_SIZE || angles.size() != ANGLES_AXIS_SIZE) { + TLOGE(WmsLogTag::DMS, "halls size or angles is not right, size %{public}zu, %{public}zu", + halls.size(), angles.size()); return; } - bool isFoldScreenOn = PowerMgr::PowerMgrClient::GetInstance().IsFoldScreenOn(); + if ((std::fabs(angles[1] - DEFAULT_ANGLE_VALUE) < FLT_EPSILON && halls[1] == HALL_THRESHOLD) || + (std::fabs(angles[0] - DEFAULT_ANGLE_VALUE) < FLT_EPSILON && halls[0] == HALL_THRESHOLD)) { + TLOGI(WmsLogTag::DMS, "hall change but posture not change"); + return; + } + bool isScreenOn = PowerMgr::PowerMgrClient::GetInstance().IsScreenOn(); { std::lock_guard lock(secondaryFoldStatusMutex_); - if (!isFoldScreenOn && curHallAB_ == halls[0] && curHallBC_ == halls[1]) { + if (!isScreenOn && curHallAB_ == halls[0] && curHallBC_ == halls[1]) { TLOGI(WmsLogTag::DMS, "hall value is not change in unPower"); return; } } - FoldStatus nextState = GetNextFoldState(angles, halls, isPostureRegistered, isFoldScreenOn); + FoldStatus nextState = GetNextFoldState(angles, halls, isPostureRegistered, isScreenOn); HandleSensorChange(nextState, angles, halls, foldScreenPolicy); if (angles.size() != ANGLES_AXIS_SIZE) { TLOGE(WmsLogTag::DMS, "angles size is not right, angles size %{public}zu", angles.size()); @@ -160,7 +167,7 @@ FoldStatus SecondaryDisplaySensorFoldStateManager::GetNextFoldStateHalf(float an FoldStatus state = FoldStatus::UNKNOWN; if (allowUserSensorForLargeFoldDevice == SMALLER_BOUNDARY_FLAG) { - if (std::islessequal(angle, OPEN_GRL_HALF_FOLDED_MIN_THRESHOLD)) { + if (std::islessequal(angle, OPEN_GRL_HALF_FOLDED_MIN_THRESHOLD) && hall == HALL_FOLDED_THRESHOLD) { state = FoldStatus::FOLDED; } else if (std::isgreaterequal(angle, OPEN_GRL_HALF_FOLDED_MIN_THRESHOLD + GRL_HALF_FOLDED_BUFFER) && hall == HALL_FOLDED_THRESHOLD) { @@ -295,7 +302,7 @@ FoldStatus SecondaryDisplaySensorFoldStateManager::CalculateNewABFoldStatus(floa { if ((previousHall == HALL_THRESHOLD && hall == HALL_FOLDED_THRESHOLD) || (previousHall == hall && std::islessequal(angle - previousAngle, ANGLE_DIFF_OF_SECONDARY_AB) && - std::islessequal(angle, OPEN_GRL_HALF_FOLDED_MIN_THRESHOLD))) { + std::islessequal(angle, CLOSE_GRL_HALF_FOLDED_MIN_THRESHOLD))) { return FoldStatus::FOLDED; } else if (std::isgreaterequal(angle, GRL_HALF_FOLDED_MAX_THRESHOLD - GRL_HALF_FOLDED_BUFFER)) { return FoldStatus::EXPAND; diff --git a/window_scene/screen_session_manager/src/fold_screen_controller/sensor_fold_state_manager/sensor_fold_state_manager.cpp b/window_scene/screen_session_manager/src/fold_screen_controller/sensor_fold_state_manager/sensor_fold_state_manager.cpp index 6599d6ee0470bfc22bb313ed07358ca51163271f..899d65c5372cb1cd8e680e72d7324a60f2288629 100644 --- a/window_scene/screen_session_manager/src/fold_screen_controller/sensor_fold_state_manager/sensor_fold_state_manager.cpp +++ b/window_scene/screen_session_manager/src/fold_screen_controller/sensor_fold_state_manager/sensor_fold_state_manager.cpp @@ -121,9 +121,9 @@ void SensorFoldStateManager::HandleSensorChange(FoldStatus nextState, const std: } manager->ProcessNotifyFoldStatusChange(currentState, newState, angles, policy); }; - taskScheduler_ = ScreenSessionManager::GetInstance().GetPowerTaskScheduler(); - if (taskScheduler_ != nullptr) { - taskScheduler_->PostAsyncTask(task, "secondaryFoldStatusChange"); + auto ffrtQueueHelper = ScreenSessionManager::GetInstance().GetFfrtQueueHelper(); + if (ffrtQueueHelper != nullptr) { + ffrtQueueHelper->SubmitTask(task); } } diff --git a/window_scene/screen_session_manager/src/multi_screen_manager.cpp b/window_scene/screen_session_manager/src/multi_screen_manager.cpp index 18fd6d8da385eb02706389a5092b21ff3e9cd6ec..5c0c673beacdca085bbe29e423bfaf5a926ad8f7 100644 --- a/window_scene/screen_session_manager/src/multi_screen_manager.cpp +++ b/window_scene/screen_session_manager/src/multi_screen_manager.cpp @@ -79,7 +79,7 @@ void MultiScreenManager::FilterPhysicalAndVirtualScreen(const std::vector& screenIds, DMRect mainScreenRegion, ScreenId& screenGroupId) + const std::vector& screenIds, DMRect mainScreenRegion, ScreenId& screenGroupId, bool forceMirror) { TLOGW(WmsLogTag::DMS, "enter size: %{public}u", static_cast(screenIds.size())); @@ -89,7 +89,7 @@ DMError MultiScreenManager::VirtualScreenMirrorSwitch(const ScreenId mainScreenI TLOGE(WmsLogTag::DMS, "screen session null fail mainScreenId: %{public}" PRIu64, mainScreenId); return DMError::DM_ERROR_INVALID_PARAM; } - DMError ret = ScreenSessionManager::GetInstance().SetMirror(mainScreenId, screenIds, mainScreenRegion); + DMError ret = ScreenSessionManager::GetInstance().SetMirror(mainScreenId, screenIds, mainScreenRegion, forceMirror); if (ret != DMError::DM_OK) { TLOGE(WmsLogTag::DMS, "error: %{public}d", ret); return ret; @@ -104,7 +104,8 @@ DMError MultiScreenManager::VirtualScreenMirrorSwitch(const ScreenId mainScreenI return ret; } -DMError MultiScreenManager::PhysicalScreenMirrorSwitch(const std::vector& screenIds, DMRect mirrorRegion) +DMError MultiScreenManager::PhysicalScreenMirrorSwitch(const std::vector& screenIds, DMRect mirrorRegion, + bool forceMirror) { sptr defaultSession = ScreenSessionManager::GetInstance().GetDefaultScreenSession(); if (defaultSession == nullptr) { @@ -121,7 +122,7 @@ DMError MultiScreenManager::PhysicalScreenMirrorSwitch(const std::vectorGetScreenCombination() == ScreenCombination::SCREEN_MIRROR) { + if (screenSession->GetScreenCombination() == ScreenCombination::SCREEN_MIRROR && !forceMirror) { if (mirrorRegion != screenSession->GetMirrorScreenRegion().second) { screenSession->SetMirrorScreenRegion(defaultSession->GetRSScreenId(), mirrorRegion); screenSession->SetIsPhysicalMirrorSwitch(true); @@ -300,7 +301,7 @@ DMError MultiScreenManager::UniqueSwitch(const std::vector& screenIds, } DMError MultiScreenManager::MirrorSwitch(const ScreenId mainScreenId, const std::vector& screenIds, - DMRect mainScreenRegion, ScreenId& screenGroupId) + DMRect mainScreenRegion, ScreenId& screenGroupId, bool forceMirror) { DMError switchStatus = DMError::DM_OK; std::vector virtualScreenIds; @@ -313,12 +314,13 @@ DMError MultiScreenManager::MirrorSwitch(const ScreenId mainScreenId, const std: FilterPhysicalAndVirtualScreen(screenIds, physicalScreenIds, virtualScreenIds); if (!virtualScreenIds.empty()) { - switchStatus = VirtualScreenMirrorSwitch(mainScreenId, virtualScreenIds, mainScreenRegion, screenGroupId); + switchStatus = VirtualScreenMirrorSwitch(mainScreenId, virtualScreenIds, mainScreenRegion, + screenGroupId, forceMirror); TLOGW(WmsLogTag::DMS, "virtual screen switch to mirror result: %{public}d", switchStatus); } if (!physicalScreenIds.empty()) { screenGroupId = 1; - switchStatus = PhysicalScreenMirrorSwitch(physicalScreenIds, mainScreenRegion); + switchStatus = PhysicalScreenMirrorSwitch(physicalScreenIds, mainScreenRegion, forceMirror); if (switchStatus == DMError::DM_OK) { for (auto screenId : physicalScreenIds) { auto screenSession = ScreenSessionManager::GetInstance().GetScreenSession(screenId); diff --git a/window_scene/screen_session_manager/src/screen_cutout_controller.cpp b/window_scene/screen_session_manager/src/screen_cutout_controller.cpp index f16f2d5cd8b0257cff84acfefea9e212e01d6eb9..257917ff8f5b4a6cde202a44c08cba03eb3d88f4 100644 --- a/window_scene/screen_session_manager/src/screen_cutout_controller.cpp +++ b/window_scene/screen_session_manager/src/screen_cutout_controller.cpp @@ -45,6 +45,7 @@ sptr ScreenCutoutController::GetScreenCutoutInfo(DisplayId displayId sptr ScreenCutoutController::GetScreenCutoutInfo(DisplayId displayId, uint32_t width, uint32_t height, Rotation rotation) const { + rotation = ScreenSessionManager::GetInstance().RemoveRotationCorrection(rotation); std::vector boundaryRects; GetCutoutArea(displayId, width, height, rotation, boundaryRects); diff --git a/window_scene/screen_session_manager/src/screen_session_manager.cpp b/window_scene/screen_session_manager/src/screen_session_manager.cpp index 13214a57083fe401a570f97af5b3c820d2110a87..fe13d91b18409755b0f438bedfc8729269cc4abb 100644 --- a/window_scene/screen_session_manager/src/screen_session_manager.cpp +++ b/window_scene/screen_session_manager/src/screen_session_manager.cpp @@ -198,6 +198,18 @@ constexpr uint32_t SCREEN_DEFAULT_HEIGHT = 2232; constexpr int32_t SECONDARY_FULL_OFFSET = 1136; constexpr int32_t SECONDARY_FULL_STATUS_WIDTH = 2048; +const bool CORRECTION_ENABLE = system::GetIntParameter("const.system.sensor_correction_enable", 0) == 1; +const std::string DISPLAYMODE_CORRECTION = system::GetParameter("const.dms.rotation_correction", ""); +constexpr uint32_t EXPECT_DISPLAY_MODE_CORRECTION_SIZE = 2; +constexpr int32_t PARAM_NUM_TEN = 10; + +constexpr int32_t COLD_SWITCH_ANIMATE_TIMEOUT_MILLISECONDS = 3000; +constexpr int32_t HOT_SWITCH_ANIMATE_TIMEOUT_MILLISECONDS = 1200; + +constexpr float POSITION_Z_DEFAULT = 2.0f; +constexpr float POSITION_Z_HIGH = 3.0f; +constexpr float POSITION_Z_LOW = 1.0f; + // based on the bundle_util // LCOV_EXCL_START inline int32_t GetUserIdByCallingUid() @@ -227,6 +239,7 @@ ScreenSessionManager::ScreenSessionManager() screenOnDelay_ = CV_WAIT_SCREENON_MS; taskScheduler_ = std::make_shared(SCREEN_SESSION_MANAGER_THREAD); screenPowerTaskScheduler_ = std::make_shared(SCREEN_SESSION_MANAGER_SCREEN_POWER_THREAD); + ffrtQueueHelper_ = std::make_shared(); screenCutoutController_ = new (std::nothrow) ScreenCutoutController(); if (!screenCutoutController_) { TLOGE(WmsLogTag::DMS, "screenCutoutController_ is nullptr"); @@ -560,6 +573,11 @@ DMError ScreenSessionManager::RegisterDisplayManagerAgent( TLOGE(WmsLogTag::DMS, "DisplayManagerAgentType: %{public}u", static_cast(type)); return DMError::DM_ERROR_INVALID_PARAM; } + if (type == DisplayManagerAgentType::DISPLAY_EVENT_LISTENER) { + auto uid = IPCSkeleton::GetCallingUid(); + auto pid = IPCSkeleton::GetCallingPid(); + uidAndPidMap_[uid] = pid; + } return dmAgentContainer_.RegisterAgent(displayManagerAgent, type) ? DMError::DM_OK :DMError::DM_ERROR_NULLPTR; } @@ -879,25 +897,23 @@ void ScreenSessionManager::FreeDisplayMirrorNodeInner(const sptr void ScreenSessionManager::SetScreenCorrection() { + ScreenRotation screenRotation = ScreenRotation::ROTATION_0; std::ostringstream oss; if (g_foldScreenFlag) { if (FoldScreenStateInternel::IsSingleDisplayPocketFoldDevice()) { - auto ret = rsInterface_.SetScreenCorrection(SCREEN_ID_MAIN, - static_cast(ROTATION_90)); - oss << "main screenRotationOffSet: " << g_screenRotationOffSet << " ret value: " << ret; + screenRotation = static_cast(ROTATION_90); } else { - auto ret = rsInterface_.SetScreenCorrection(SCREEN_ID_FULL, - static_cast(g_screenRotationOffSet)); - oss << "full screenRotationOffSet: " << g_screenRotationOffSet << " ret value: " << ret; + screenRotation = static_cast(g_screenRotationOffSet); } } else { std::vector phyOffsets = FoldScreenStateInternel::GetPhyRotationOffset(); int32_t phyOffset = static_cast(std::stoi(phyOffsets[0])); - ScreenRotation correctRotation = ConvertOffsetToCorrectRotation(phyOffset); - auto ret = rsInterface_.SetScreenCorrection(SCREEN_ID_DEFAULT, correctRotation); - oss << "phyOffset: " << phyOffset << " correctRotation value: " << - static_cast(correctRotation) << " ret value: " << ret; + screenRotation = ConvertOffsetToCorrectRotation(phyOffset); } + auto rotationOffset = GetConfigCorrectionByDisplayMode(GetFoldDisplayMode()); + auto rotation = (static_cast(screenRotation) + static_cast(rotationOffset)) % ROTATION_MOD; + auto ret = rsInterface_.SetScreenCorrection(SCREEN_ID_DEFAULT, static_cast(rotation)); + oss << "screenRotation: " << static_cast(screenRotation) << " ret value: " << ret; TLOGW(WmsLogTag::DMS, "%{public}s", oss.str().c_str()); screenEventTracker_.RecordEvent(oss.str()); } @@ -1503,6 +1519,8 @@ void ScreenSessionManager::SetLapTopLidOpenStatus(bool isLapTopLidOpen) void ScreenSessionManager::HandleScreenConnectEvent(sptr screenSession, ScreenId screenId, ScreenEvent screenEvent) { + InitRotationCorrectionMap(DISPLAYMODE_CORRECTION); + screenSession->SetRotationCorrectionMap(rotationCorrectionMap_); bool phyMirrorEnable = IsDefaultMirrorMode(screenId); HandlePhysicalMirrorConnect(screenSession, phyMirrorEnable); auto clientProxy = GetClientProxy(); @@ -1779,6 +1797,7 @@ void ScreenSessionManager::OnHgmRefreshRateChange(uint32_t refreshRate) NotifyDisplayChanged(screenSession->ConvertToDisplayInfo(), DisplayChangeEvent::UPDATE_REFRESHRATE); UpdateCoordinationRefreshRate(refreshRate); + UpdateSuperFoldRefreshRate(screenSession, refreshRate); std::map> screenSessionMap; { std::lock_guard lock(screenSessionMapMutex_); @@ -1800,6 +1819,28 @@ void ScreenSessionManager::OnHgmRefreshRateChange(uint32_t refreshRate) return; } +void ScreenSessionManager::UpdateSuperFoldRefreshRate(sptr screenSession, uint32_t refreshRate) +{ + if (!FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { + TLOGD(WmsLogTag::DMS, "not super fold display device."); + return; + } + if (screenSession == nullptr) { + TLOGE(WmsLogTag::DMS, "screenSession is nullptr"); + return; + } + sptr fakeScreenSession = screenSession->GetFakeScreenSession(); + if (fakeScreenSession == nullptr) { + TLOGE(WmsLogTag::DMS, "fakeScreenSession is nullptr"); + return; + } + fakeScreenSession->UpdateRefreshRate(refreshRate); + if (screenSession->GetScreenProperty().GetIsFakeInUse()) { + NotifyDisplayChanged(fakeScreenSession->ConvertToDisplayInfo(), DisplayChangeEvent::UPDATE_REFRESHRATE); + TLOGE(WmsLogTag::DMS, "notify success"); + } +} + bool ScreenSessionManager::IsPhysicalScreenAndInUse(sptr screenSession) const { if (!screenSession) { @@ -2196,17 +2237,70 @@ void ScreenSessionManager::UpdateDisplayHookInfo(int32_t uid, bool enable, const TLOGE(WmsLogTag::DMS, "permission denied!"); return; } - + std::map> screenSessionMapCopy; + { + std::lock_guard lock(screenSessionMapMutex_); + screenSessionMapCopy = screenSessionMap_; + } std::unique_lock lock(hookInfoMutex_); if (enable) { if (uid != 0) { displayHookMap_[uid] = hookInfo; + NotifyDisplayChangedByUid(screenSessionMapCopy, DisplayChangeEvent::DISPLAY_SIZE_CHANGED, uid); } } else { displayHookMap_.erase(uid); } } +void ScreenSessionManager::NotifyDisplayChangedByUid(const std::map>& screenSessionMap, + DisplayChangeEvent event, int32_t uid) +{ + for (const auto& sessionIt : screenSessionMap) { + auto screenSession = sessionIt.second; + if (screenSession == nullptr) { + TLOGE(WmsLogTag::DMS, "screenSession is nullptr"); + continue; + } + NotifyDisplayChangedByUidInner(screenSession->ConvertToDisplayInfo(), event, uid); + } +} + +void ScreenSessionManager::NotifyDisplayChangedByUidInner(sptr displayInfo, + DisplayChangeEvent event, int32_t uid) +{ + if (displayInfo == nullptr) { + TLOGE(WmsLogTag::DMS, "displayInfo is nullptr."); + return; + } + auto task = [=] { + auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_EVENT_LISTENER); + if (event == DisplayChangeEvent::UPDATE_REFRESHRATE) { + TLOGND(WmsLogTag::DMS, "evevt:%{public}d, displayId:%{public}" PRIu64", agent size: %{public}u", + event, displayInfo->GetDisplayId(), static_cast(agents.size())); + } else { + TLOGNI(WmsLogTag::DMS, "evevt:%{public}d, displayId:%{public}" PRIu64", agent size: %{public}u", + event, displayInfo->GetDisplayId(), static_cast(agents.size())); + } + if (agents.empty()) { + return; + } + for (const auto& agent : agents) { + int32_t agentPid = dmAgentContainer_.GetAgentPid(agent); + auto iter = uidAndPidMap_.find(uid); + if (iter == uidAndPidMap_.end() || iter->second != agentPid) { + TLOGND(WmsLogTag::DMS, "no notify"); + continue; + } + if (!IsFreezed(agentPid, DisplayManagerAgentType::DISPLAY_EVENT_LISTENER)) { + agent->OnDisplayChange(displayInfo, event); + TLOGND(WmsLogTag::DMS, "notify, uid:%{public}d, pid: %{public}d", uid, agentPid); + } + } + }; + taskScheduler_->PostAsyncTask(task, "NotifyDisplayChanged"); +} + void ScreenSessionManager::GetDisplayHookInfo(int32_t uid, DMHookInfo& hookInfo) { std::shared_lock lock(hookInfoMutex_); @@ -2737,7 +2831,7 @@ void ScreenSessionManager::InitScreenProperty(ScreenId screenId, RSScreenModeInf property.SetPhyBounds(screenBounds); property.SetBounds(screenBounds); property.SetAvailableArea({0, 0, screenMode.GetScreenWidth(), screenMode.GetScreenHeight()}); - property.SetPhysicalTouchBounds(); + property.SetPhysicalTouchBounds(GetConfigCorrectionByDisplayMode(GetFoldDisplayMode())); property.SetInputOffsetY(); property.SetCurrentOffScreenRendering(false); property.SetScreenRealWidth(property.GetBounds().rect_.GetWidth()); @@ -2936,11 +3030,11 @@ void ScreenSessionManager::InitExtendScreenDensity(sptr session, float defaultDensity = screenSession->GetScreenProperty().GetDefaultDensity(); TLOGW(WmsLogTag::DMS, "extendDensity = %{public}f", extendDensity); session->SetVirtualPixelRatio(extendDensity * g_extendScreenDpiCoef); - session->SetDefaultDensity(defaultDensity * g_extendScreenDpiCoef); + session->SetDefaultDensity(defaultDensity * EXTEND_SCREEN_DPI_DEFAULT_PARAMETER); session->SetDensityInCurResolution(curResolution); ScreenId screenId = session->GetScreenId(); property.SetVirtualPixelRatio(extendDensity * g_extendScreenDpiCoef); - property.SetDefaultDensity(defaultDensity * g_extendScreenDpiCoef); + property.SetDefaultDensity(defaultDensity * EXTEND_SCREEN_DPI_DEFAULT_PARAMETER); property.SetDensityInCurResolution(curResolution); { std::lock_guard lock_phy(phyScreenPropMapMutex_); @@ -3865,7 +3959,12 @@ void ScreenSessionManager::SetScreenPowerForFold(ScreenId screenId, ScreenPowerS (FoldScreenStateInternel::IsSingleDisplayPocketFoldDevice() || FoldScreenStateInternel::IsDualDisplayFoldDevice() || FoldScreenStateInternel::IsSingleDisplayFoldDevice()); - if ((lastPowerForAllStatus_.load() == ScreenPowerStatus::POWER_STATUS_ON_ADVANCED || + if (lastPowerForAllStatus_.load() == ScreenPowerStatus::POWER_STATUS_ON_ADVANCED && + screenId == lastScreenId_.load() && FoldScreenStateInternel::IsSingleDisplayFoldDevice()) { + // 预下电 + TLOGI(WmsLogTag::DMS, "set advancedOn powerStatus off, screenId:%{public}" PRIu64, screenId); + SetRSScreenPowerStatus(screenId, ScreenPowerStatus::POWER_STATUS_OFF_ADVANCED); + } else if ((lastPowerForAllStatus_.load() == ScreenPowerStatus::POWER_STATUS_ON_ADVANCED || lastPowerForAllStatus_.load() == ScreenPowerStatus::POWER_STATUS_SUSPEND) && screenId == SCREEN_ID_MAIN && lastScreenId_.load() == SCREEN_ID_MAIN && isNeedScreenOffDevice) { if (!IsInAod()) { @@ -4916,6 +5015,7 @@ ScreenId ScreenSessionManager::CreateVirtualScreen(VirtualScreenOption option, return SCREEN_ID_INVALID; } screenSession->SetName(option.name_); + screenSession->SetVirtualScreenType(option.virtualScreenType_); screenSession->SetMirrorScreenType(MirrorScreenType::VIRTUAL_MIRROR); screenSession->SetSecurity(option.isSecurity_); { @@ -4923,6 +5023,7 @@ ScreenId ScreenSessionManager::CreateVirtualScreen(VirtualScreenOption option, screenSessionMap_.insert(std::make_pair(smsScreenId, screenSession)); } screenSession->SetVirtualScreenFlag(option.virtualScreenFlag_); + TLOGI(WmsLogTag::DMS, "virtualScreenFlag: %{public}d", option.virtualScreenFlag_); NotifyScreenConnected(screenSession->ConvertToScreenInfo()); TLOGW(WmsLogTag::DMS, "create success. ScreenId: %{public}" PRIu64", rsId: %{public}" PRIu64"", smsScreenId, rsId); @@ -5209,7 +5310,7 @@ void ScreenSessionManager::MirrorSwitchNotify(ScreenId screenId) } DMError ScreenSessionManager::DoMakeMirror(ScreenId mainScreenId, std::vector mirrorScreenIds, - DMRect mainScreenRegion, ScreenId& screenGroupId) + DMRect mainScreenRegion, ScreenId& screenGroupId, bool forceMirror) { #ifdef WM_MULTI_SCREEN_ENABLE TLOGW(WmsLogTag::DMS, "enter!"); @@ -5240,7 +5341,7 @@ DMError ScreenSessionManager::DoMakeMirror(ScreenId mainScreenId, std::vector mirrorScreenIds, - ScreenId& screenGroupId) + ScreenId& screenGroupId, bool forceMirror) { #ifdef FOLD_ABILITY_ENABLE if (foldScreenController_ != nullptr && FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { DMRect mainScreenRegion = DMRect::NONE(); foldScreenController_->SetMainScreenRegion(mainScreenRegion); - return DoMakeMirror(mainScreenId, mirrorScreenIds, mainScreenRegion, screenGroupId); + return DoMakeMirror(mainScreenId, mirrorScreenIds, mainScreenRegion, screenGroupId, forceMirror); } #endif - return DoMakeMirror(mainScreenId, mirrorScreenIds, DMRect::NONE(), screenGroupId); + return DoMakeMirror(mainScreenId, mirrorScreenIds, DMRect::NONE(), screenGroupId, forceMirror); } DMError ScreenSessionManager::MakeMirrorForRecord(ScreenId mainScreenId, std::vector mirrorScreenIds, @@ -5845,6 +5946,8 @@ sptr ScreenSessionManager::InitVirtualScreen(ScreenId smsScreenId screenSession->SetRealHeight(option.height_); screenSession->SetScreenAreaWidth(option.width_); screenSession->SetScreenAreaHeight(option.height_); + InitRotationCorrectionMap(DISPLAYMODE_CORRECTION); + screenSession->SetRotationCorrectionMap(rotationCorrectionMap_); return screenSession; } @@ -6071,7 +6174,8 @@ bool ScreenSessionManager::RemoveChildFromGroup(sptr screen, sptr return true; } -DMError ScreenSessionManager::SetMirror(ScreenId screenId, std::vector screens, DMRect mainScreenRegion) +DMError ScreenSessionManager::SetMirror(ScreenId screenId, std::vector screens, DMRect mainScreenRegion, + bool forceMirror) { TLOGI(WmsLogTag::DMS, "screenId:%{public}" PRIu64"", screenId); sptr screen = GetScreenSession(screenId); @@ -6093,7 +6197,8 @@ DMError ScreenSessionManager::SetMirror(ScreenId screenId, std::vector std::vector startPoints; startPoints.insert(startPoints.begin(), screens.size(), point); bool filterMirroredScreen = - group->combination_ == ScreenCombination::SCREEN_MIRROR && group->mirrorScreenId_ == screen->screenId_; + group->combination_ == ScreenCombination::SCREEN_MIRROR && group->mirrorScreenId_ == screen->screenId_ + && !forceMirror; group->mirrorScreenId_ = screen->screenId_; ChangeScreenGroup(group, screens, startPoints, filterMirroredScreen, ScreenCombination::SCREEN_MIRROR, mainScreenRegion); @@ -7268,12 +7373,14 @@ DMError ScreenSessionManager::SetFoldDisplayModeInner(const FoldDisplayMode disp if (foldScreenController_->GetTentMode() && (displayMode == FoldDisplayMode::FULL || displayMode == FoldDisplayMode::COORDINATION)) { TLOGW(WmsLogTag::DMS, "in TentMode, SetFoldDisplayMode to %{public}d failed", displayMode); - return DMError::DM_ERROR_INVALID_MODE_ID; + return DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_TENTMODE; } else if ((FoldScreenStateInternel::IsSingleDisplayPocketFoldDevice() || - FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) && IsScreenCasting() && + FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) && displayMode == FoldDisplayMode::COORDINATION) { - TLOGW(WmsLogTag::DMS, "is phone casting, SetFoldDisplayMode to %{public}d is not allowed", displayMode); - return DMError::DM_ERROR_INVALID_MODE_ID; + DMError err = CanEnterCoordination(); + if (err != DMError::DM_OK) { + return err; + } } if (reason.compare("backSelfie") == 0) { UpdateCameraBackSelfie(true); @@ -8101,6 +8208,7 @@ void ScreenSessionManager::RefreshMirrorScreenRegion(ScreenId screenId) void ScreenSessionManager::NotifyDisplayModeChanged(FoldDisplayMode displayMode) { NotifyClientProxyUpdateFoldDisplayMode(displayMode); + SetScreenCorrection(); auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_MODE_CHANGED_LISTENER); TLOGI(WmsLogTag::DMS, "DisplayMode:%{public}d, agent size: %{public}u", displayMode, static_cast(agents.size())); @@ -8306,7 +8414,6 @@ void ScreenSessionManager::SwitchUser() return; } auto userId = GetUserIdByCallingUid(); - auto newScbPid = IPCSkeleton::GetCallingPid(); currentUserIdForSettings_ = userId; if (g_isPcDevice && userSwitching_) { std::unique_lock lock(switchUserMutex_); @@ -8315,7 +8422,10 @@ void ScreenSessionManager::SwitchUser() userSwitching_ = false; } } - SwitchScbNodeHandle(userId, newScbPid, false); + { + std::lock_guard lock(oldScbPidsMutex_); + SwitchScbNodeHandle(userId, IPCSkeleton::GetCallingPid(), false); + } MockSessionManagerService::GetInstance().NotifyWMSConnected(userId, GetDefaultScreenId(), false); #endif } @@ -8388,7 +8498,7 @@ void ScreenSessionManager::ScbStatusRecoveryWhenSwitchUser(std::vector TLOGE(WmsLogTag::DMS, "old mode: %{public}u, cur mode: %{public}u", oldScbDisplayMode_, GetFoldDisplayMode()); if (FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { screenSession->UpdatePropertyByFoldControl(screenSession->GetScreenProperty()); - OnVerticalChangeBoundsWhenSwitchUser(screenSession); + OnVerticalChangeBoundsWhenSwitchUser(screenSession, oldScbDisplayMode_); screenSession->PropertyChange(screenSession->GetScreenProperty(), FoldDisplayMode::MAIN == GetFoldDisplayMode() ? ScreenPropertyChangeReason::FOLD_SCREEN_FOLDING : ScreenPropertyChangeReason::FOLD_SCREEN_EXPAND); @@ -8421,16 +8531,53 @@ void ScreenSessionManager::ScbStatusRecoveryWhenSwitchUser(std::vector #endif } -void ScreenSessionManager::OnVerticalChangeBoundsWhenSwitchUser(sptr screenSession) +Rotation ScreenSessionManager::GetOldDisplayModeRotation(FoldDisplayMode oldDisplayMode, Rotation rotation) +{ + auto currentDisplayMode = GetFoldDisplayMode(); + if (currentDisplayMode == oldDisplayMode) { + return rotation; + } + auto oldRotationoffset = GetConfigCorrectionByDisplayMode(oldDisplayMode); + auto rotationoffset = GetConfigCorrectionByDisplayMode(GetFoldDisplayMode()); + return static_cast( + (static_cast(rotation) - static_cast(rotationoffset) + + static_cast(oldRotationoffset) + ROTATION_MOD) % ROTATION_MOD); +} + +void ScreenSessionManager::SwapScreenWeightAndHeight(sptr& screenSession) { if (screenSession == nullptr) { TLOGE(WmsLogTag::DMS, "screenSession is nullptr"); return; } - auto rotation = screenSession->GetScreenProperty().GetRotation(); - if (std::fabs(rotation - SECONDARY_ROTATION_90) < FLT_EPSILON || - std::fabs(rotation - SECONDARY_ROTATION_270) < FLT_EPSILON ) { - const RRect& bounds = screenSession->GetScreenProperty().GetBounds(); + RRect bounds = screenSession->GetScreenProperty().GetBounds(); + auto lastWidth = bounds.rect_.GetWidth(); + auto lastHeight = bounds.rect_.GetHeight(); + RRect afterBounds = + RRect({ 0, bounds.rect_.GetTop(), lastHeight, lastWidth}, 0.0f, 0.0f); + screenSession->SetBounds(afterBounds); + TLOGI(WmsLogTag::DMS, "before width:%{public}f, height:%{public}f,after width:%{public}f, height:%{public}f", + lastWidth, lastHeight, afterBounds.rect_.GetWidth(), afterBounds.rect_.GetHeight()); +} + +void ScreenSessionManager::OnVerticalChangeBoundsWhenSwitchUser(sptr& screenSession, + FoldDisplayMode oldScbDisplayMode) +{ + if (screenSession == nullptr) { + TLOGE(WmsLogTag::DMS, "screenSession is nullptr"); + return; + } + auto bounds = screenSession->GetScreenProperty().GetBounds(); + auto rotation = screenSession->GetRotation(); + // set rotation to old displayMode + auto oldRotation = GetOldDisplayModeRotation(oldScbDisplayMode_, screenSession->GetRotation()); + screenSession->SetRotation(oldRotation); + screenSession->SetBounds(bounds); + auto correctionRotation = GetConfigCorrectionByDisplayMode(GetFoldDisplayMode()); + float rotationValue = (static_cast(rotation) - static_cast(correctionRotation) + + ROTATION_MOD) % ROTATION_MOD * SECONDARY_ROTATION_90; + if (std::fabs(rotationValue - SECONDARY_ROTATION_90) < FLT_EPSILON || + std::fabs(rotationValue - SECONDARY_ROTATION_270) < FLT_EPSILON ) { RRect afterBounds = RRect({ 0, bounds.rect_.GetTop(), bounds.rect_.GetHeight(), bounds.rect_.GetWidth()}, 0.0f, 0.0f); screenSession->SetBounds(afterBounds); @@ -8569,21 +8716,23 @@ void ScreenSessionManager::SetClient(const sptr& cl userSwitching_ = false; } } - SetClientProxy(client); - auto userId = GetUserIdByCallingUid(); - auto newScbPid = IPCSkeleton::GetCallingPid(); + { + std::unique_lock lock(oldScbPidsMutex_); + SetClientProxy(client); + auto userId = GetUserIdByCallingUid(); + auto newScbPid = IPCSkeleton::GetCallingPid(); - std::ostringstream oss; - oss << "set client userId: " << userId - << " clientName: " << SysCapUtil::GetClientName(); - TLOGI(WmsLogTag::DMS, "%{public}s", oss.str().c_str()); - screenEventTracker_.RecordEvent(oss.str()); - currentUserIdForSettings_ = userId; - MockSessionManagerService::GetInstance().NotifyWMSConnected(userId, GetDefaultScreenId(), true); - NotifyClientProxyUpdateFoldDisplayMode(GetFoldDisplayMode()); - SetClientInner(); - SwitchScbNodeHandle(userId, newScbPid, true); - AddScbClientDeathRecipient(client, newScbPid); + std::ostringstream oss; + oss << "set client userId: " << userId << " clientName: " << SysCapUtil::GetClientName(); + TLOGI(WmsLogTag::DMS, "%{public}s", oss.str().c_str()); + screenEventTracker_.RecordEvent(oss.str()); + currentUserIdForSettings_ = userId; + MockSessionManagerService::GetInstance().NotifyWMSConnected(userId, GetDefaultScreenId(), true); + NotifyClientProxyUpdateFoldDisplayMode(GetFoldDisplayMode()); + SetClientInner(userId); + SwitchScbNodeHandle(userId, newScbPid, true); + } + AddScbClientDeathRecipient(client, IPCSkeleton::GetCallingPid()); static bool isNeedSwitchScreen = FoldScreenStateInternel::IsSingleDisplayPocketFoldDevice() || FoldScreenStateInternel::IsSingleDisplayFoldDevice(); @@ -8611,7 +8760,10 @@ void ScreenSessionManager::SwitchScbNodeHandle(int32_t newUserId, int32_t newScb TLOGI(WmsLogTag::DMS, "%{public}s", oss.str().c_str()); screenEventTracker_.RecordEvent(oss.str()); - std::unique_lock lock(oldScbPidsMutex_); + if (currentUserId_ != newUserId) { + HandleNewUserDisplayNode(newUserId, coldBoot); + } + if (currentScbPId_ != INVALID_SCB_PID) { auto pidIter = std::find(oldScbPids_.begin(), oldScbPids_.end(), currentScbPId_); if (pidIter == oldScbPids_.end() && currentScbPId_ > 0) { @@ -8635,6 +8787,9 @@ void ScreenSessionManager::SwitchScbNodeHandle(int32_t newUserId, int32_t newScb HotSwitch(newUserId, newScbPid); } UpdateDisplayScaleState(GetDefaultScreenId()); + if (currentUserId_ != newUserId) { + WaitSwitchUserAnimateFinish(newUserId, coldBoot); + } currentUserId_ = newUserId; currentScbPId_ = newScbPid; scbSwitchCV_.notify_all(); @@ -8696,42 +8851,16 @@ int32_t ScreenSessionManager::GetCurrentUserId() return currentUserIdForSettings_; } -void ScreenSessionManager::SetClientInner() +void ScreenSessionManager::SetClientInner(int32_t newUserId) { + SwitchUserDealUserDisplayNode(newUserId); std::lock_guard lock(screenSessionMapMutex_); - for (const auto& iter : screenSessionMap_) { + for (auto& iter : screenSessionMap_) { if (!iter.second) { continue; } // In the rotating state, after scb restarts, the screen information needs to be reset. - float phyWidth = 0.0f; - float phyHeight = 0.0f; - bool isReset = true; - int boundaryOffset = 0; - GetCurrentScreenPhyBounds(phyWidth, phyHeight, isReset, iter.first); - auto localRotation = iter.second->GetRotation(); - if (FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { - FoldDisplayMode displayMode = GetFoldDisplayMode(); - if (displayMode == FoldDisplayMode::FULL) { - boundaryOffset = SECONDARY_FULL_OFFSET; - phyWidth = SECONDARY_FULL_STATUS_WIDTH; - } else if (displayMode == FoldDisplayMode::MAIN) { - phyWidth = MAIN_STATUS_DEFAULT_WIDTH; - phyHeight = SCREEN_DEFAULT_HEIGHT; - } - } - TLOGI(WmsLogTag::DMS, "phyWidth = :%{public}f, phyHeight = :%{public}f, localRotation = :%{public}u", - phyWidth, phyHeight, localRotation); - if (!FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { - bool isModeChanged = localRotation != Rotation::ROTATION_0; - if (isModeChanged && isReset) { - TLOGI(WmsLogTag::DMS, "screen(id:%{public}" PRIu64 ") current is not default mode, reset it", - iter.first); - SetRotation(iter.first, Rotation::ROTATION_0, false); - SetPhysicalRotationClientInner(iter.first, 0); - iter.second->SetDisplayBoundary(RectF(0, boundaryOffset, phyWidth, phyHeight), 0); - } - } + HandleScreenRotationAndBoundsWhenSetClient(iter.second); auto clientProxy = GetClientProxy(); if (!clientProxy) { TLOGE(WmsLogTag::DMS, "clientProxy is null"); @@ -8748,6 +8877,48 @@ void ScreenSessionManager::SetClientInner() } } +void ScreenSessionManager::HandleScreenRotationAndBoundsWhenSetClient(sptr& screenSession) +{ + float phyWidth = 0.0f; + float phyHeight = 0.0f; + bool isReset = true; + int boundaryOffset = 0; + ScreenId screenId = screenSession->GetScreenId(); + GetCurrentScreenPhyBounds(phyWidth, phyHeight, isReset, screenSession->GetScreenId()); + auto localRotation = screenSession->GetRotation(); + if (FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { + FoldDisplayMode displayMode = GetFoldDisplayMode(); + if (displayMode == FoldDisplayMode::FULL) { + boundaryOffset = SECONDARY_FULL_OFFSET; + phyWidth = SECONDARY_FULL_STATUS_WIDTH; + } else if (displayMode == FoldDisplayMode::MAIN) { + phyWidth = MAIN_STATUS_DEFAULT_WIDTH; + phyHeight = SCREEN_DEFAULT_HEIGHT; + } + } + TLOGI(WmsLogTag::DMS, "phyWidth:%{public}f, phyHeight:%{public}f, localRotation:%{public}u", + phyWidth, phyHeight, localRotation); + if (FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { + auto buouds = screenSession->GetScreenProperty().GetBounds(); + screenSession->SetRotation(Rotation::ROTATION_0); + TLOGI(WmsLogTag::DMS, "rotation:%{public}d", screenSession->GetRotation()); + screenSession->SetBounds(buouds); + auto rotationWithoutCorrection = RemoveRotationCorrection(localRotation); + if (rotationWithoutCorrection == Rotation::ROTATION_90 || rotationWithoutCorrection == Rotation::ROTATION_270) + { + SwapScreenWeightAndHeight(screenSession); + } + } else if (!FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { + bool isModeChanged = localRotation != Rotation::ROTATION_0; + if (isModeChanged && isReset) { + TLOGI(WmsLogTag::DMS, "screen(id:%{public}" PRIu64 ") current is not default mode, reset it", screenId); + SetRotation(screenId, Rotation::ROTATION_0, false); + SetPhysicalRotationClientInner(screenId, 0); + screenSession->SetDisplayBoundary(RectF(0, boundaryOffset, phyWidth, phyHeight), 0); + } + } +} + void ScreenSessionManager::SetPhysicalRotationClientInner(ScreenId screenId, int rotation) { sptr screenSession = GetScreenSession(screenId); @@ -10334,15 +10505,35 @@ int32_t ScreenSessionManager::GetCameraPosition() return cameraPosition_; } -bool ScreenSessionManager::IsScreenCasting() +DMError ScreenSessionManager::CanEnterCoordination() { - if (virtualScreenCount_ > 0 || hdmiScreenCount_ > 0) { - TLOGI(WmsLogTag::DMS, "virtualScreenCount_: %{public}" PRIu32 ", hdmiScreenCount_: %{public}d", - virtualScreenCount_, hdmiScreenCount_); - return true; + if (hdmiScreenCount_ > 0) { + TLOGW(WmsLogTag::DMS, "hdmiScreenCount_: %{public}d cannot enter coordination", hdmiScreenCount_); + return DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_WIRED_CASTING; } - TLOGI(WmsLogTag::DMS, "not casting"); - return false; + + if (virtualScreenCount_ == 0) { + return DMError::DM_OK; + } + std::lock_guard lock(screenSessionMapMutex_); + for (const auto& pair : screenSessionMap_) { + sptr session = pair.second; + if (!session) { + TLOGW(WmsLogTag::DMS, "screenId=%{public}" PRIu64", session is null", pair.first); + continue; + } + if (session->GetIsRealScreen()) { + continue; + } + if (session->GetVirtualScreenType() != VirtualScreenType::SCREEN_RECORDING) { + TLOGW(WmsLogTag::DMS, "wireless casting: %{public}u cannot enter coordination", session->GetVirtualScreenType()); + return DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_WIRLESS_CASTING; + } else { + TLOGW(WmsLogTag::DMS, "screen recording cannot enter coordination"); + return DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_RECORDING; + } + } + return DMError::DM_OK; } SessionOption ScreenSessionManager::GetSessionOption(sptr screenSession) @@ -10353,6 +10544,7 @@ SessionOption ScreenSessionManager::GetSessionOption(sptr screenS .isExtend_ = screenSession->GetIsExtend(), .innerName_ = screenSession->GetInnerName(), .screenId_ = screenSession->GetScreenId(), + .rotationCorrectionMap_ = screenSession->GetRotationCorrectionMap(), }; return option; } @@ -10365,6 +10557,7 @@ SessionOption ScreenSessionManager::GetSessionOption(sptr screenS .isExtend_ = screenSession->GetIsExtend(), .innerName_ = screenSession->GetInnerName(), .screenId_ = screenId, + .rotationCorrectionMap_ = screenSession->GetRotationCorrectionMap(), }; return option; } @@ -11038,6 +11231,238 @@ DMError ScreenSessionManager::SetVirtualScreenAutoRotation(ScreenId screenId, bo return DMError::DM_OK; } +void ScreenSessionManager::AddOrUpdateUserDisplayNode(int32_t userId, ScreenId screenId, + std::shared_ptr& displayNode) +{ + TLOGI(WmsLogTag::DMS, "userId: %{public}d, screenId: %{public}" PRIu64 "", userId, screenId); + std::lock_guard lock(userDisplayNodeMapMutex_); + userDisplayNodeMap_[userId].insert_or_assign(screenId, displayNode); +} + +void ScreenSessionManager::RemoveUserDisplayNode(int32_t userId, ScreenId screenId) +{ + std::lock_guard lock(userDisplayNodeMapMutex_); + auto iter = userDisplayNodeMap_.find(userId); + if (iter == userDisplayNodeMap_.end()) { + TLOGE(WmsLogTag::DMS, "userId: %{public}d not found", userId); + return; + } + if (userDisplayNodeMap_[userId].find(screenId) == userDisplayNodeMap_[userId].end()) { + TLOGE(WmsLogTag::DMS, "displayNode not exist, userId: %{public}d, screenId %{public}" PRIu64 "", + userId, screenId); + return; + } + TLOGI(WmsLogTag::DMS, "remove displayNode, userId: %{public}d, screenId %{public}" PRIu64 "", + userId, screenId); + userDisplayNodeMap_[userId].erase(screenId); + if (userDisplayNodeMap_[userId].size() <= 0) { + userDisplayNodeMap_.erase(userId); + } +} + +std::map> ScreenSessionManager::GetUserDisplayNodeMap(int32_t userId) +{ + std::lock_guard lock(userDisplayNodeMapMutex_); + auto iter = userDisplayNodeMap_.find(userId); + if (iter == userDisplayNodeMap_.end()) { + TLOGE(WmsLogTag::DMS, "userId: %{public}d not found", userId); + return {}; + } + return iter->second; +} + +void ScreenSessionManager::SwitchUserDealUserDisplayNode(int32_t newUserId) +{ + auto newUserDisplayNodeMap = GetUserDisplayNodeMap(newUserId); + std::ostringstream oss; + for (auto sessionIt : newUserDisplayNodeMap) { + oss << sessionIt.first << ","; + } + std::vector phyScreenIds; + std::map> screenSessionMapCopy; + { + std::lock_guard lock(screenSessionMapMutex_); + screenSessionMapCopy = screenSessionMap_; + } + for (auto sessionIt : screenSessionMapCopy) { + auto screenSession = sessionIt.second; + if (screenSession == nullptr) { + TLOGI(WmsLogTag::DMS, "screenSession is nullptr, screenId: %{public}" PRIu64 "", sessionIt.first); + continue; + } + if (!screenSession->GetIsRealScreen()) { + continue; + } + TLOGI(WmsLogTag::DMS, "start set new user displayNode, newUserId: %{public}d", newUserId); + auto screenId = screenSession->GetScreenId(); + if (newUserDisplayNodeMap.find(screenId) == newUserDisplayNodeMap.end()) { + Rosen::RSDisplayNodeConfig rsConfig; + rsConfig.screenId = screenId; + screenSession->CreateDisplayNode(rsConfig); + std::shared_ptr displayNode = screenSession->GetDisplayNode(); + if (displayNode == nullptr) { + TLOGI(WmsLogTag::DMS, "displayNode is null"); + continue; + } + TLOGI(WmsLogTag::DMS, "screen id %{public}" PRIu64 "", screenId); + AddOrUpdateUserDisplayNode(newUserId, screenId, displayNode); + } else { + screenSession->SetDisplayNode(newUserDisplayNodeMap[screenId]); + } + phyScreenIds.emplace_back(screenId); + } + for (auto newUserMapIt : newUserDisplayNodeMap) { + auto screenId = newUserMapIt.first; + if (std::find(phyScreenIds.begin(), phyScreenIds.end(), screenId) == phyScreenIds.end()) { + RemoveUserDisplayNode(newUserId, screenId); + } + } +} + +void ScreenSessionManager::AddUserDisplayNodeOnTree(int32_t userId) +{ + TLOGI(WmsLogTag::DMS, "userId: %{public}d", userId); + auto userDisplayNodeMap = GetUserDisplayNodeMap(userId); + std::unordered_set> rsUIContexts; + for (auto userDisplayNodeIt : userDisplayNodeMap) { + auto displayNode = userDisplayNodeIt.second; + if (displayNode == nullptr) { + continue; + } + displayNode->AddDisplayNodeToTree(); + auto screenId = userDisplayNodeIt.first; + auto screenSession = GetScreenSession(screenId); + if (!screenSession) { + TLOGW(WmsLogTag::DMS, "screen Session is null"); + continue; + } + rsUIContexts.insert(screenSession->GetRSUIContext()); + } + RSTransactionAdapter::FlushImplicitTransaction(rsUIContexts); +} + +void ScreenSessionManager::RemoveUserDisplayNodeFromTree(int32_t userId) +{ + TLOGI(WmsLogTag::DMS, "userId: %{public}d", userId); + auto userDisplayNodeMap = GetUserDisplayNodeMap(userId); + std::unordered_set> rsUIContexts; + for (auto userDisplayNodeIt : userDisplayNodeMap) { + auto displayNode = userDisplayNodeIt.second; + if (displayNode == nullptr) { + continue; + } + displayNode->RemoveDisplayNodeFromTree(); + auto screenId = userDisplayNodeIt.first; + auto screenSession = GetScreenSession(screenId); + if (!screenSession) { + TLOGW(WmsLogTag::DMS, "screen Session is null"); + continue; + } + rsUIContexts.insert(screenSession->GetRSUIContext()); + } + RSTransactionAdapter::FlushImplicitTransaction(rsUIContexts); +} + +void ScreenSessionManager::SetUserDisplayNodePositionZ(int32_t userId, float positionZ) +{ + TLOGI(WmsLogTag::DMS, "userId: %{public}d, positionZ: %{public}f", userId, positionZ); + auto userDisplayNodeMap = GetUserDisplayNodeMap(userId); + std::unordered_set> rsUIContexts; + for (auto userDisplayNodeIt : userDisplayNodeMap) { + auto displayNode = userDisplayNodeIt.second; + if (displayNode == nullptr) { + continue; + } + displayNode->SetPositionZ(positionZ); + auto screenId = userDisplayNodeIt.first; + auto screenSession = GetScreenSession(screenId); + if (!screenSession) { + TLOGW(WmsLogTag::DMS, "screen Session is null"); + continue; + } + rsUIContexts.insert(screenSession->GetRSUIContext()); + } + RSTransactionAdapter::FlushImplicitTransaction(rsUIContexts); +} + +void ScreenSessionManager::HandleNewUserDisplayNode(int32_t newUserId, bool coldBoot) +{ + std::unique_lock lock(switchUserDisplayNodeMutex_); + TLOGI(WmsLogTag::DMS, "newUserId: %{public}d, coldBoot: %{public}d", newUserId, coldBoot); + SetUserDisplayNodePositionZ(currentUserId_, POSITION_Z_DEFAULT); + if (!coldBoot) { + TLOGI(WmsLogTag::DMS, "deal with userDisplayNode"); + SwitchUserDealUserDisplayNode(newUserId); + } + SetUserDisplayNodePositionZ(newUserId, POSITION_Z_LOW); + AddUserDisplayNodeOnTree(newUserId); + MakeMirrorAfterSwitchUser(); +} + +void ScreenSessionManager::WaitSwitchUserAnimateFinish(int32_t newUserId, bool isColdSwitch) +{ + TLOGI(WmsLogTag::DMS, "enter, newUserId: %{public}d, isColdSwitch: %{public}d", newUserId, isColdSwitch); + std::unique_lock lock(switchUserDisplayNodeMutex_); + uint32_t waitTimes = isColdSwitch ? COLD_SWITCH_ANIMATE_TIMEOUT_MILLISECONDS : + HOT_SWITCH_ANIMATE_TIMEOUT_MILLISECONDS; + if (!switchUserDisplayNodeCV_.wait_for(lock, std::chrono::milliseconds(waitTimes), + [this] { return animateFinishAllNotified_; })) { + TLOGI(WmsLogTag::DMS, "switch user animate timeout"); + } + animateFinishAllNotified_ = false; + auto clientProxy = GetClientProxy(); + if (!clientProxy) { + TLOGE(WmsLogTag::DMS, "clientProxy is null"); + return; + } + clientProxy->OnAnimationFinish(); + SetUserDisplayNodePositionZ(newUserId, POSITION_Z_HIGH); + RemoveUserDisplayNodeFromTree(currentUserId_); + TLOGI(WmsLogTag::DMS, "success"); +} + +void ScreenSessionManager::MakeMirrorAfterSwitchUser() +{ + TLOGI(WmsLogTag::DMS, "start to make mirror"); + ScreenId mainScreenId = INVALID_SCREEN_ID; + std::vector mirrorScreenIds; + { + std::lock_guard lock(screenSessionMapMutex_); + for (auto it : screenSessionMap_) { + auto screenSession = it.second; + if (!screenSession) { + TLOGW(WmsLogTag::DMS, "screen session is null"); + continue; + } + if (screenSession->GetScreenCombination() == ScreenCombination::SCREEN_MIRROR) { + mirrorScreenIds.emplace_back(it.first); + continue; + } + if (screenSession->GetScreenCombination() == ScreenCombination::SCREEN_MAIN) { + mainScreenId = it.first; + } + } + if (mirrorScreenIds.empty()) { + TLOGI(WmsLogTag::DMS, "no mirror screens, no need to make mirror"); + return; + } + if (mainScreenId == INVALID_SCREEN_ID) { + TLOGE(WmsLogTag::DMS, "make mirror error, no main screen"); + return; + } + } + ScreenId screenGroupId = SCREEN_GROUP_ID_DEFAULT; + MakeMirror(mainScreenId, mirrorScreenIds, screenGroupId, true); +} + +void ScreenSessionManager::NotifySwitchUserAnimationFinish() +{ + TLOGI(WmsLogTag::DMS, "enter"); + std::unique_lock lock(switchUserDisplayNodeMutex_); + animateFinishAllNotified_ = true; + switchUserDisplayNodeCV_.notify_all(); +} + bool ScreenSessionManager::SetScreenOffset(ScreenId screenId, float offsetX, float offsetY) { sptr screenSession = GetScreenSession(screenId); @@ -11128,11 +11553,74 @@ bool ScreenSessionManager::SynchronizePowerStatus(ScreenPowerState state) return true; } +Rotation ScreenSessionManager::RemoveRotationCorrection(Rotation rotation) +{ + auto correctionRotation = GetConfigCorrectionByDisplayMode(GetFoldDisplayMode()); + return static_cast((static_cast(rotation) - + static_cast(correctionRotation) + ROTATION_MOD) % ROTATION_MOD); +} + +Rotation ScreenSessionManager::GetConfigCorrectionByDisplayMode(FoldDisplayMode displayMode) +{ + if (!CORRECTION_ENABLE) { + return Rotation::ROTATION_0; + } + InitRotationCorrectionMap(DISPLAYMODE_CORRECTION); + std::shared_lock lock(rotationCorrectionMutex_); + auto iter = rotationCorrectionMap_.find(displayMode); + if (iter == rotationCorrectionMap_.end()) { + return Rotation::ROTATION_0; + } + TLOGI(WmsLogTag::DMS, "offset:%{public}d", iter->second); + return static_cast(iter->second); +} + +void ScreenSessionManager::InitRotationCorrectionMap(std::string displayModeCorrectionConfig) +{ + if (!rotationCorrectionMap_.empty()) { + return; + } + std::unique_lock lock(rotationCorrectionMutex_); + rotationCorrectionMap_.clear(); + std::vector displayModeCorrections = {}; + bool splitSuccess = ScreenSettingHelper::SplitString(displayModeCorrections, displayModeCorrectionConfig, ';'); + if (!splitSuccess) { + TLOGE(WmsLogTag::DMS, "invalid config"); + return; + } + for (const std::string& displayModeCorrection : displayModeCorrections) { + std::vector corrections = {}; + splitSuccess = ScreenSettingHelper::SplitString(corrections, displayModeCorrection, ','); + uint32_t dataSize = corrections.size(); + if (!splitSuccess || dataSize != EXPECT_DISPLAY_MODE_CORRECTION_SIZE) { + TLOGE(WmsLogTag::DMS, "invalid mode config"); + continue; + } + if (!ScreenSettingHelper::IsNumber(corrections[0]) || + !ScreenSettingHelper::IsNumber(corrections[1])) { + TLOGE(WmsLogTag::DMS, "config not int:%{public}s,%{public}s", + corrections[0].c_str(), corrections[1].c_str()); + continue; + } + auto displayModeValue = + static_cast(strtoll(corrections[0].c_str(), nullptr, PARAM_NUM_TEN)); + auto offset = static_cast(strtoll(corrections[1].c_str(), nullptr, PARAM_NUM_TEN)); + FoldDisplayMode displayMode = static_cast(displayModeValue); + rotationCorrectionMap_.insert({displayMode, offset}); + TLOGI(WmsLogTag::DMS, "rotationCorrectionMap add:%{public}d-%{public}d", displayMode, offset); + } +} + std::shared_ptr ScreenSessionManager::GetPowerTaskScheduler() const { return screenPowerTaskScheduler_; } +std::shared_ptr ScreenSessionManager::GetFfrtQueueHelper() const +{ + return ffrtQueueHelper_; +} + bool ScreenSessionManager::GetCancelSuspendStatus() const { if (!sessionDisplayPowerController_) { diff --git a/window_scene/screen_session_manager/src/zidl/screen_session_manager_proxy.cpp b/window_scene/screen_session_manager/src/zidl/screen_session_manager_proxy.cpp index 0d481f5b777f246f06acdf0ecfab7325bb47aec8..282290135593fc3a25d8577bda2aa636355cc5e7 100644 --- a/window_scene/screen_session_manager/src/zidl/screen_session_manager_proxy.cpp +++ b/window_scene/screen_session_manager/src/zidl/screen_session_manager_proxy.cpp @@ -1101,7 +1101,8 @@ ScreenId ScreenSessionManagerProxy::CreateVirtualScreen(VirtualScreenOption virt data.WriteInt32(virtualOption.flags_) && data.WriteBool(virtualOption.isForShot_) && data.WriteUInt64Vector(virtualOption.missionIds_) && data.WriteUint32(static_cast(virtualOption.virtualScreenType_)) && - data.WriteBool(virtualOption.isSecurity_); + data.WriteBool(virtualOption.isSecurity_) && + data.WriteUint32(static_cast(virtualOption.virtualScreenFlag_)); if (virtualOption.surface_ != nullptr && virtualOption.surface_->GetProducer() != nullptr) { res = res && data.WriteBool(true) && @@ -1399,8 +1400,8 @@ DMError ScreenSessionManagerProxy::DestroyVirtualScreen(ScreenId screenId) return static_cast(reply.ReadInt32()); } -DMError ScreenSessionManagerProxy::MakeMirror(ScreenId mainScreenId, - std::vector mirrorScreenIds, ScreenId& screenGroupId) +DMError ScreenSessionManagerProxy::MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenIds, + ScreenId& screenGroupId, bool forceMirror) { TLOGW(WmsLogTag::DMS, "SCB: ENTER"); sptr remote = Remote(); @@ -4645,4 +4646,25 @@ DMError ScreenSessionManagerProxy::SetScreenPrivacyWindowTagSwitch(ScreenId scre } return static_cast(reply.ReadInt32()); } + +void ScreenSessionManagerProxy::NotifySwitchUserAnimationFinish() +{ + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::DMS, "remote is null"); + return; + } + MessageParcel reply; + MessageParcel data; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::DMS, "WriteInterfaceToken failed"); + return; + } + if (remote->SendRequest(static_cast(DisplayManagerMessage::TRANS_ID_NOTIFY_SWITCH_USER_ANIMATION_FINISH), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::DMS, "SendRequest failed"); + return; + } +} } // namespace OHOS::Rosen diff --git a/window_scene/screen_session_manager/src/zidl/screen_session_manager_stub.cpp b/window_scene/screen_session_manager/src/zidl/screen_session_manager_stub.cpp index e2152ca816280428fd5591f0918559349152a321..6048a7ae7424286dfefc3adbcb91185770e49e97 100644 --- a/window_scene/screen_session_manager/src/zidl/screen_session_manager_stub.cpp +++ b/window_scene/screen_session_manager/src/zidl/screen_session_manager_stub.cpp @@ -231,6 +231,7 @@ int32_t ScreenSessionManagerStub::OnRemoteRequest(uint32_t code, MessageParcel& data.ReadUInt64Vector(&missionIds); VirtualScreenType virtualScreenType = static_cast(data.ReadUint32()); bool isSecurity = data.ReadBool(); + VirtualScreenFlag virtualScreenFlag = static_cast(data.ReadUint32()); bool isSurfaceValid = data.ReadBool(); sptr surface = nullptr; if (isSurfaceValid) { @@ -249,7 +250,8 @@ int32_t ScreenSessionManagerStub::OnRemoteRequest(uint32_t code, MessageParcel& .isForShot_ = isForShot, .missionIds_ = missionIds, .virtualScreenType_ = virtualScreenType, - .isSecurity_ = isSecurity + .isSecurity_ = isSecurity, + .virtualScreenFlag_ = virtualScreenFlag }; ScreenId screenId = CreateVirtualScreen(virScrOption, virtualScreenAgent); static_cast(reply.WriteUint64(static_cast(screenId))); @@ -1338,6 +1340,10 @@ int32_t ScreenSessionManagerStub::OnRemoteRequest(uint32_t code, MessageParcel& } break; } + case DisplayManagerMessage::TRANS_ID_NOTIFY_SWITCH_USER_ANIMATION_FINISH: { + NotifySwitchUserAnimationFinish(); + break; + } default: TLOGW(WmsLogTag::DMS, "unknown transaction code"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/window_scene/screen_session_manager_client/include/screen_session_manager_client.h b/window_scene/screen_session_manager_client/include/screen_session_manager_client.h index 8e1bc9a26985ff7ca13be845b71ff871e95a14ea..be9a5f96651fcc071a25152ddb562aba788f049c 100644 --- a/window_scene/screen_session_manager_client/include/screen_session_manager_client.h +++ b/window_scene/screen_session_manager_client/include/screen_session_manager_client.h @@ -121,6 +121,9 @@ public: void NotifyExtendScreenCreateFinish(); void NotifyExtendScreenDestroyFinish(); void NotifyScreenMaskAppear(); + void NotifySwitchUserAnimationFinish(const std::string& description); + void RegisterSwitchUserAnimationNotification(const std::string& description); + void OnAnimationFinish() override; DMError SetPrimaryDisplaySystemDpi(float dpi); void FreezeScreen(ScreenId screenId, bool isFreeze); std::shared_ptr GetScreenSnapshotWithAllWindows(ScreenId screenId, float scaleX, float scaleY, @@ -185,6 +188,10 @@ private: std::mutex screenEventMutex_; std::unordered_set connectedScreenSet_; + std::set animateFinishDescriptionSet_; + std::set animateFinishNotificationSet_; + mutable std::shared_mutex animateFinishDescriptionSetMutex_; + mutable std::mutex animateFinishNotificationSetMutex_; }; } // namespace OHOS::Rosen diff --git a/window_scene/screen_session_manager_client/include/zidl/screen_session_manager_client_interface.h b/window_scene/screen_session_manager_client/include/zidl/screen_session_manager_client_interface.h index 561dbbbfdb2d9d1600243f0f20b3dfad9b2c80b9..4dc2e9c2be42d2d8fb4ba8fd5974f5cb5b81bd15 100644 --- a/window_scene/screen_session_manager_client/include/zidl/screen_session_manager_client_interface.h +++ b/window_scene/screen_session_manager_client/include/zidl/screen_session_manager_client_interface.h @@ -59,6 +59,7 @@ public: TRANS_ID_ON_DUMP_SCREEN_SESSION, TRANS_ID_ON_BEFORE_PROPERTY_CHANGED, TRANS_ID_ON_SCREEN_MODE_CHANGED, + TRANS_ID_ON_ANIMATE_FINISH_TIMEOUT, }; virtual void SwitchUserCallback(std::vector oldScbPids, int32_t currentScbPid) = 0; @@ -100,6 +101,7 @@ public: ScreenCombination extendCombination) = 0; virtual std::string OnDumperClientScreenSessions() = 0; virtual void OnScreenModeChanged(ScreenModeChangeEvent screenModeChangeEvent) = 0; + virtual void OnAnimationFinish() = 0; }; } // namespace OHOS::Rosen diff --git a/window_scene/screen_session_manager_client/include/zidl/screen_session_manager_client_proxy.h b/window_scene/screen_session_manager_client/include/zidl/screen_session_manager_client_proxy.h index 285ddf1215a2a27fa6e3f1e369afde9fc2872a32..9e9d3b1a39097ad7f7dd511a57ac42254397f4d2 100644 --- a/window_scene/screen_session_manager_client/include/zidl/screen_session_manager_client_proxy.h +++ b/window_scene/screen_session_manager_client/include/zidl/screen_session_manager_client_proxy.h @@ -65,8 +65,11 @@ public: std::string OnDumperClientScreenSessions() override; void OnBeforeScreenPropertyChanged(FoldStatus foldStatus) override; void OnScreenModeChanged(ScreenModeChangeEvent screenModeChangeEvent) override; + void OnAnimationFinish() override; private: static inline BrokerDelegator delegator_; + bool ScreenConnectWriteParam(SessionOption& SessionOption, + ScreenEvent screenEvent, MessageParcel& data); }; } // namespace OHOS::Rosen diff --git a/window_scene/screen_session_manager_client/include/zidl/screen_session_manager_client_stub.h b/window_scene/screen_session_manager_client/include/zidl/screen_session_manager_client_stub.h index 625f5eafea0179a9a223f6660543f43fba2075b4..17b868fb7771bf536909f3d0fdc3f23e0adc4557 100644 --- a/window_scene/screen_session_manager_client/include/zidl/screen_session_manager_client_stub.h +++ b/window_scene/screen_session_manager_client/include/zidl/screen_session_manager_client_stub.h @@ -65,6 +65,7 @@ private: int HandleOnDumperClientScreenSessions(MessageParcel& data, MessageParcel& reply); int HandleOnBeforeScreenPropertyChange(MessageParcel& data, MessageParcel& reply); int HandleOnScreenModeChanged(MessageParcel& data, MessageParcel& reply); + int HandleOnAnimationFinish(MessageParcel& data, MessageParcel& reply); HandleScreenChangeMap HandleScreenChangeMap_ {}; }; diff --git a/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp b/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp index 00eba92aa23b5abaf9e52b64e9cc2437196b3e3d..2c6041f3d9e55a3711e2967a50f2777576dcb568 100644 --- a/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp +++ b/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp @@ -421,7 +421,7 @@ void ScreenSessionManagerClient::UpdateScreenRotationProperty(ScreenId screenId, screenSession->SetScreenComponentRotation(directionInfo.screenRotation_); screenSession->UpdateToInputManager(bounds, directionInfo.notifyRotation_, directionInfo.rotation_, foldDisplayMode); - screenSession->UpdateTouchBoundsAndOffset(); + screenSession->UpdateTouchBoundsAndOffset(foldDisplayMode); TLOGW(WmsLogTag::DMS, "superFoldStatus:%{public}d", currentstate_); if (currentstate_ != SuperFoldStatus::KEYBOARD) { screenSession->SetValidHeight(bounds.rect_.GetHeight()); @@ -1003,6 +1003,7 @@ bool ScreenSessionManagerClient::HandleScreenConnection(SessionOption option) screenSessionMap_[option.screenId_] = screenSession; extraScreenSessionMap_[option.screenId_] = screenSession; } + screenSession->SetRotationCorrectionMap(option.rotationCorrectionMap_); NotifyClientScreenConnect(screenSession); return true; } @@ -1014,7 +1015,6 @@ bool ScreenSessionManagerClient::HandleScreenDisconnection(SessionOption option) TLOGE(WmsLogTag::DMS, "screenSession is null"); return false; } - screenSession->DestroyScreenScene(); NotifyScreenDisconnect(screenSession); { std::lock_guard lock(screenSessionMapMutex_); @@ -1342,4 +1342,55 @@ std::shared_ptr ScreenSessionManagerClient::GetScreenSnapshotWi } return screenSession->GetScreenSnapshotWithAllWindows(scaleX, scaleY, isNeedCheckDrmAndSurfaceLock); } + +void ScreenSessionManagerClient::NotifySwitchUserAnimationFinish(const std::string& description) +{ + TLOGI(WmsLogTag::DMS, "description: %{public}s", description.c_str()); + std::set descriptionSetCopy; + { + std::shared_lock descriptionLock(animateFinishDescriptionSetMutex_); + descriptionSetCopy = animateFinishDescriptionSet_; + } + { + std::lock_guard notificationLock(animateFinishNotificationSetMutex_); + if (descriptionSetCopy.empty()) { + return; + } + auto it = descriptionSetCopy.find(description); + if (it == descriptionSetCopy.end()) { + TLOGE(WmsLogTag::DMS, "not find description in map"); + return; + } + animateFinishNotificationSet_.insert(description); + if (animateFinishNotificationSet_.size() != descriptionSetCopy.size()) { + return; + } + // all description notified + animateFinishNotificationSet_.clear(); + } + TLOGI(WmsLogTag::DMS, "notify all animate finished"); + if (!screenSessionManager_) { + TLOGE(WmsLogTag::DMS, "screenSessionManager_ is null"); + return; + } + screenSessionManager_->NotifySwitchUserAnimationFinish(); +} + +void ScreenSessionManagerClient::RegisterSwitchUserAnimationNotification(const std::string& description) +{ + std::unique_lock lock(animateFinishDescriptionSetMutex_); + auto it = animateFinishDescriptionSet_.find(description); + if (it != animateFinishDescriptionSet_.end()) { + TLOGE(WmsLogTag::DMS, "description: %{public}s already regist", description.c_str()); + return; + } + TLOGI(WmsLogTag::DMS, "description: %{public}s regist success", description.c_str()); + animateFinishDescriptionSet_.insert(description); +} + +void ScreenSessionManagerClient::OnAnimationFinish() +{ + std::lock_guard lock(animateFinishNotificationSetMutex_); + animateFinishNotificationSet_.clear(); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/screen_session_manager_client/src/zidl/screen_session_manager_client_proxy.cpp b/window_scene/screen_session_manager_client/src/zidl/screen_session_manager_client_proxy.cpp index b022fa9905cb4ac419eb5a29a192f66d2d30f1ea..921e9bd423724c739d8ce82b08d4c0b690565535 100644 --- a/window_scene/screen_session_manager_client/src/zidl/screen_session_manager_client_proxy.cpp +++ b/window_scene/screen_session_manager_client/src/zidl/screen_session_manager_client_proxy.cpp @@ -30,40 +30,63 @@ void ScreenSessionManagerClientProxy::OnScreenConnectionChanged(SessionOption Se MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_SYNC); + if (!ScreenConnectWriteParam(SessionOption, screenEvent, data)) { + return; + } + if (remote->SendRequest( + static_cast(ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_CONNECTION_CHANGED), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::DMS, "SendRequest failed"); + return; + } +} + +bool ScreenSessionManagerClientProxy::ScreenConnectWriteParam(SessionOption& SessionOption, + ScreenEvent screenEvent, MessageParcel& data) +{ if (!data.WriteInterfaceToken(GetDescriptor())) { TLOGE(WmsLogTag::DMS, "WriteInterfaceToken failed"); - return; + return false; } if (!data.WriteUint64(SessionOption.rsId_)) { TLOGE(WmsLogTag::DMS, "Write rsId failed"); - return; + return false; } if (!data.WriteString(SessionOption.name_)) { TLOGE(WmsLogTag::DMS, "Write name failed"); - return; + return false; } if (!data.WriteBool(SessionOption.isExtend_)) { TLOGE(WmsLogTag::DMS, "Write isExtended failed"); - return; + return false; } if (!data.WriteString(SessionOption.innerName_)) { TLOGE(WmsLogTag::DMS, "Write innerName failed"); - return; + return false; } if (!data.WriteUint64(SessionOption.screenId_)) { TLOGE(WmsLogTag::DMS, "Write screenId failed"); - return; + return false; } if (!data.WriteUint8(static_cast(screenEvent))) { TLOGE(WmsLogTag::DMS, "Write screenEvent failed"); - return; + return false; } - if (remote->SendRequest( - static_cast(ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_CONNECTION_CHANGED), - data, reply, option) != ERR_NONE) { - TLOGE(WmsLogTag::DMS, "SendRequest failed"); - return; + if (!data.WriteUint64(static_cast(SessionOption.rotationCorrectionMap_.size()))) { + TLOGE(WmsLogTag::DMS, "Write size failed"); + return false; + } + for (auto& iter : SessionOption.rotationCorrectionMap_) { + if (!data.WriteUint32(static_cast(iter.first))) { + TLOGE(WmsLogTag::DMS, "Write displayMode failed"); + return false; + } + if (!data.WriteUint32(static_cast(iter.second))) { + TLOGE(WmsLogTag::DMS, "Write offset failed"); + return false; + } } + return true; } void ScreenSessionManagerClientProxy::SwitchUserCallback(std::vector oldScbPids, int32_t currentScbPid) @@ -978,4 +1001,25 @@ void ScreenSessionManagerClientProxy::OnScreenModeChanged(ScreenModeChangeEvent return; } } + +void ScreenSessionManagerClientProxy::OnAnimationFinish() +{ + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::DMS, "remote is nullptr"); + return; + } + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::DMS, "WriteInterfaceToken failed"); + return; + } + if (remote->SendRequest(static_cast( + ScreenSessionManagerClientMessage::TRANS_ID_ON_ANIMATE_FINISH_TIMEOUT), data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::DMS, "SendRequest failed"); + return; + } +} } // namespace OHOS::Rosen diff --git a/window_scene/screen_session_manager_client/src/zidl/screen_session_manager_client_stub.cpp b/window_scene/screen_session_manager_client/src/zidl/screen_session_manager_client_stub.cpp index a0fb451bb21d5971a7adcc7f1d1a15ff74b2c74a..6dc90ac7c886d3e012589b0cd38c2fbdf0159b1f 100644 --- a/window_scene/screen_session_manager_client/src/zidl/screen_session_manager_client_stub.cpp +++ b/window_scene/screen_session_manager_client/src/zidl/screen_session_manager_client_stub.cpp @@ -149,6 +149,10 @@ void ScreenSessionManagerClientStub::InitScreenChangeMap() [this](MessageParcel& data, MessageParcel& reply) { return HandleOnScreenModeChanged(data, reply); }; + HandleScreenChangeMap_[ScreenSessionManagerClientMessage::TRANS_ID_ON_ANIMATE_FINISH_TIMEOUT] = + [this](MessageParcel& data, MessageParcel& reply) { + return HandleOnAnimationFinish(data, reply); + }; } ScreenSessionManagerClientStub::ScreenSessionManagerClientStub() @@ -195,12 +199,32 @@ int ScreenSessionManagerClientStub::HandleOnScreenConnectionChanged(MessageParce auto innerName = data.ReadString(); auto screenId = static_cast(data.ReadUint64()); auto screenEvent = static_cast(data.ReadUint8()); + uint64_t size = 0; + if (!data.ReadUint64(size)) { + TLOGE(WmsLogTag::DMS, "Failed to read size"); + return ERR_INVALID_DATA; + } + std::unordered_map rotationCorrectionMap; + for (uint64_t i = 0; i < size; i++) { + uint32_t foldDisplayMode = 0; + if (!data.ReadUint32(foldDisplayMode)) { + TLOGE(WmsLogTag::DMS, "Failed to read foldDisplayMode"); + return ERR_INVALID_DATA; + } + uint32_t offset = 0; + if (!data.ReadUint32(offset)) { + TLOGE(WmsLogTag::DMS, "Failed to read offset"); + return ERR_INVALID_DATA; + } + rotationCorrectionMap.insert({static_cast(foldDisplayMode), offset}); + } SessionOption option = { .rsId_ = rsId, .name_ = name, .isExtend_ = isExtend, .innerName_ = innerName, .screenId_ = screenId, + .rotationCorrectionMap_ = rotationCorrectionMap }; OnScreenConnectionChanged(option, screenEvent); return ERR_NONE; @@ -498,4 +522,10 @@ int ScreenSessionManagerClientStub::HandleOnScreenModeChanged(MessageParcel& dat OnScreenModeChanged(screenModeChangeEvent); return ERR_NONE; } + +int ScreenSessionManagerClientStub::HandleOnAnimationFinish(MessageParcel& data, MessageParcel& reply) +{ + OnAnimationFinish(); + return ERR_NONE; +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/include/main_session.h b/window_scene/session/host/include/main_session.h index ba208807778466d2f60fe47489eff78bbff7f72f..a62e60df203d4114a597931b59310175786f8c2d 100644 --- a/window_scene/session/host/include/main_session.h +++ b/window_scene/session/host/include/main_session.h @@ -95,8 +95,7 @@ private: void SetSubWindowBoundsDuringCross(const WSRect& parentRect, bool isGlobal, bool needFlush) override; void NotifySubSessionRectChangeByAnchor(const WSRect& parentRect, SizeChangeReason reason = SizeChangeReason::UNDEFINED, DisplayId displayId = DISPLAY_ID_INVALID) override; - void HandleSubSessionSurfaceNodeByWindowAnchor(SizeChangeReason reason, - const sptr& screenSession) override; + void HandleSubSessionSurfaceNodeByWindowAnchor(SizeChangeReason reason, DisplayId displayId) override; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_MAIN_SESSION_H diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index 9d327a9443fa3d6d00dac83ef09b00f5ebb3d281..f0f5d2c7e8c09a65f2c8d6157503692e60362c43 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -147,6 +147,9 @@ using NotifyAnimateToFunc = std::function>&()>; using GetFbPanelWindowIdFunc = std::function; +using FindScenePanelRsNodeByZOrderFunc = std::function(DisplayId displayId, + uint32_t targetZOrder)>; + struct UIExtensionTokenInfo { bool canShowOnLockScreen { false }; uint32_t callingTokenId { 0 }; @@ -206,7 +209,7 @@ public: WSError Foreground(sptr property, bool isFromClient = false, const std::string& identityToken = "") override; WSError Background(bool isFromClient = false, const std::string& identityToken = "") override; - WSError BackgroundTask(const bool isSaveSnapshot = true, ScreenLockReason reason = ScreenLockReason::DEFAULT); + WSError BackgroundTask(const bool isSaveSnapshot = true, BackgroundReason reason = BackgroundReason::DEFAULT); WSError Disconnect(bool isFromClient = false, const std::string& identityToken = "") override; WSError DisconnectTask(bool isFromClient = false, bool isSaveSnapshot = true); void SetClientIdentityToken(const std::string& clientIdentityToken); @@ -263,8 +266,7 @@ public: void HandleCrossMoveTo(WSRect& globalRect); virtual void HandleCrossMoveToSurfaceNode(WSRect& globalRect) {} virtual bool IsNeedCrossDisplayRendering() const { return false; } - virtual void HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason reason, - const sptr& screenSession) {} + virtual void HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason reason, DisplayId displayId) {} virtual void SetSurfaceBounds(const WSRect& rect, bool isGlobal, bool needFlush = true); virtual void OpenKeyboardSyncTransaction() {} @@ -272,10 +274,11 @@ public: bool isKeyboardShow, const WindowAnimationInfo& animationInfo) {} WSError ChangeSessionVisibilityWithStatusBar(const sptr info, bool visible) override; WSError PendingSessionActivation(const sptr info) override; - WSError BatchPendingSessionsActivation(const std::vector>& abilitySessionInfos) override; + WSError BatchPendingSessionsActivation(const std::vector>& abilitySessionInfos, + const std::vector& configs = {}) override; WSError DoBatchPendingSessionsActivation( const std::vector>& abilitySessionInfos, sptr& session, - bool isFoundationCall); + bool isFoundationCall, const std::vector& configs); bool DisallowActivationFromPendingBackground(bool isPcOrPadEnableActivation, bool isFoundationCall, bool canStartAbilityFromBackground, bool isFromAncoAndToAnco); WSError TerminateSession(const sptr info) override; @@ -302,6 +305,7 @@ public: void SetFloatingScale(float floatingScale) override; WSError RaiseAboveTarget(int32_t subWindowId) override; WSError RaiseMainWindowAboveTarget(int32_t targetId) override; + std::shared_ptr GetWindowDragMoveMountedNode(DisplayId displayId, uint32_t targetZOrder); /* * PiP Window @@ -396,7 +400,7 @@ public: * Compatible Mode */ bool IsInCompatScaleStatus() const; - bool IsInCompatScaleMode() const; + bool IsInCompatScaleMode(); /* * PC Window @@ -573,6 +577,7 @@ public: */ void RegisterRequestedOrientationChangeCallback(NotifyReqOrientationChangeFunc&& callback); WSError NotifyRotationProperty(uint32_t rotation, uint32_t width, uint32_t height); + WSError ConvertRotationToOrientation(uint32_t rotation, uint32_t& orientation); void RegisterUpdateRotationChangeListener(NotifyRotationChangeFunc&& callback); WSError UpdateRotationChangeRegistered(int32_t persistentId, bool isRegister) override; RotationChangeResult NotifyRotationChange(const RotationChangeInfo& rotationChangeInfo, @@ -618,7 +623,7 @@ public: void RegisterUpdateAppUseControlCallback(UpdateAppUseControlFunc&& func); void NotifyUpdateAppUseControl(ControlAppType type, const ControlInfo& controlInfo) override; void UpdatePrivacyModeControlInfo(); - bool HasSubSessionInPrivacyMode(); + bool HasChildSessionInPrivacyMode(); void SetVisibilityChangedDetectFunc(VisibilityChangedDetectFunc&& func); virtual void RegisterSessionLockStateChangeCallback(NotifySessionLockStateChangeCallback&& callback) {} virtual void NotifySessionLockStateChange(bool isLockedState) {} @@ -783,6 +788,7 @@ public: void ResetCompatibleModeDragScaleFlags(); void RegisterAppHookWindowInfoFunc(GetHookWindowInfoFunc&& func); WMError GetAppHookWindowInfoFromServer(HookWindowInfo& hookWindowInfo) override; + void SetFindScenePanelRsNodeByZOrderFunc(FindScenePanelRsNodeByZOrderFunc&& func); /* * Gesture Back @@ -853,6 +859,8 @@ public: WMError NotifySubSessionAcrossDisplaysChange(bool isAcrossDisplays); WMError NotifyFollowedParentWindowAcrossDisplaysChange(bool isAcrossDisplays); void NotifySessionAcrossDisplaysChange(const sptr& sceneSession, bool isAcrossDisplays); + WMError OnUpdateColorMode(const std::string& colorMode, bool hasDarkRes) override; + std::string GetAbilityColorMode() const; /* * Window Pattern @@ -962,6 +970,7 @@ protected: bool isFollowParentLayout_ = false; NotifyWindowAnchorInfoChangeFunc onWindowAnchorInfoChangeFunc_ = nullptr; WindowAnchorInfo windowAnchorInfo_; + FindScenePanelRsNodeByZOrderFunc findScenePanelRsNodeByZOrderFunc_; int32_t cloneNodeCount_ = 0; virtual void NotifySubSessionRectChangeByAnchor(const WSRect& parentRect, @@ -985,8 +994,8 @@ protected: virtual void NotifyUpdateFloatingBall(const FloatingBallTemplateInfo& fbTemplateInfo) {}; virtual void NotifyStopFloatingBall() {}; virtual void NotifyRestoreFloatingBallMainWindow(const std::shared_ptr& want) {}; - uint64_t fbClickTime_ = 0; std::mutex fbClickMutex_; + uint8_t fbClickCnt_ {0}; FloatingBallTemplateInfo fbTemplateInfo_ = {}; /* @@ -1082,7 +1091,7 @@ private: void WindowScaleTransfer(WSRect& rect, float scaleX, float scaleY); bool IsCompatibilityModeScale(float scaleX, float scaleY); void CompatibilityModeWindowScaleTransfer(WSRect& rect, bool isScale); - void ThrowSlipToFullScreen(WSRect& endRect, WSRect& rect); + void ThrowSlipToFullScreen(WSRect& endRect, WSRect& rect, int32_t statusBarHeight, int32_t dockHeight); bool MoveUnderInteriaAndNotifyRectChange(WSRect& rect, SizeChangeReason reason); void NotifyFullScreenAfterThrowSlip(const WSRect& rect); void SetDragResizeTypeDuringDrag(DragResizeType dragResizeType) { dragResizeTypeDuringDrag_ = dragResizeType; } @@ -1237,8 +1246,7 @@ private: WSError UpdateRectForDrag(const WSRect& rect); void UpdateSessionRectPosYFromClient(SizeChangeReason reason, DisplayId& configDisplayId, WSRect& rect); void HandleSubSessionSurfaceNode(bool isAdd, DisplayId draggingOrMovingParentDisplayId); - virtual void HandleSubSessionSurfaceNodeByWindowAnchor(SizeChangeReason reason, - const sptr& screenSession) {} + virtual void HandleSubSessionSurfaceNodeByWindowAnchor(SizeChangeReason reason, DisplayId displayId) {} virtual void AddSurfaceNodeToScreen(DisplayId draggingOrMovingParentDisplayId) {} virtual void RemoveSurfaceNodeFromScreen() {} void SetParentRect(); @@ -1297,6 +1305,7 @@ private: void OnKeyFrameNextVsync(uint64_t count); bool KeyFrameNotifyFilter(const WSRect& rect, SizeChangeReason reason); bool KeyFrameRectAlmostSame(const WSRect& rect1, const WSRect& rect2); + std::mutex keyFrameMutex_; KeyFramePolicy keyFramePolicy_; std::shared_ptr keyFrameCloneNode_ = nullptr; bool keyFrameAnimating_ = false; @@ -1390,6 +1399,9 @@ private: bool isAncoForFloatingWindow_ = false; bool subWindowOutlineEnabled_ = false; std::atomic_bool isRegisterAcrossDisplaysChanged_ = false; + std::string colorMode_; + bool hasDarkRes_ = false; + mutable std::mutex colorModeMutex_; NotifySetWindowShadowsFunc onSetWindowShadowsFunc_; UpdateScreenshotAppEventRegisteredFunc updateScreenshotAppEventRegisteredFunc_; diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index fc32a0a89cb49eaa898168184d66269a4f7eff93..738469c1d9cce3c47c721ddba88cdf68344e9fe8 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -55,12 +55,13 @@ class RSTransaction; class Session; using NotifySessionRectChangeFunc = std::function; +using NotifySessionDisplayIdChangeFunc = std::function; using NotifyUpdateFloatingBallFunc = std::function; using NotifyStopFloatingBallFunc = std::function; using NotifyRestoreFloatingBallMainWindowFunc = std::function& want)>; -using NotifySessionDisplayIdChangeFunc = std::function; using NotifyPendingSessionActivationFunc = std::function; -using NotifyBatchPendingSessionsActivationFunc = std::function>& info)>; +using NotifyBatchPendingSessionsActivationFunc = std::function>& info, + const std::vector>& configs)>; using NotifyChangeSessionVisibilityWithStatusBarFunc = std::function; using NotifySessionStateChangeFunc = std::function; using NotifyBufferAvailableChangeFunc = std::function; @@ -259,6 +260,7 @@ public: virtual WSError UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) { return WSError::WS_OK; } int32_t GetPersistentId() const; + int32_t GetCurrentRotation() const; void SetSurfaceNode(const std::shared_ptr& surfaceNode); std::shared_ptr GetSurfaceNode() const; std::optional GetSurfaceNodeId() const; @@ -274,7 +276,7 @@ public: void ResetSnapshot(); void SaveSnapshot(bool useFfrt, bool needPersist = true, std::shared_ptr persistentPixelMap = nullptr, bool updateSnapshot = false, - ScreenLockReason reason = ScreenLockReason::DEFAULT); + BackgroundReason reason = BackgroundReason::DEFAULT); void SetSaveSnapshotCallback(Task&& task) { if (task) { @@ -735,8 +737,8 @@ public: bool SupportSnapshotAllSessionStatus() const; void InitSnapshotCapacity(); SnapshotStatus GetWindowStatus() const; - SnapshotStatus GetSessionStatus(ScreenLockReason reason = ScreenLockReason::DEFAULT) const; - DisplayOrientation GetWindowOrientation() const; + SnapshotStatus GetSessionSnapshotStatus(BackgroundReason reason = BackgroundReason::DEFAULT) const; + uint32_t GetWindowOrientation() const; uint32_t GetLastOrientation() const; bool HasSnapshotFreeMultiWindow(); bool HasSnapshot(SnapshotStatus key); @@ -826,7 +828,7 @@ protected: bool isActive_ = false; bool isSystemActive_ = false; WSRectF bounds_; - Rotation rotation_; + Rotation rotation_ { Rotation::ROTATION_0 }; float offsetX_ = 0.0f; float offsetY_ = 0.0f; std::atomic_bool isExitSplitOnBackground_ = false; diff --git a/window_scene/session/host/include/sub_session.h b/window_scene/session/host/include/sub_session.h index a46f24497a97a73116055ab690cea912453e55e8..045f9cf945f4fb700c50371e970921ff9c5d8ae4 100644 --- a/window_scene/session/host/include/sub_session.h +++ b/window_scene/session/host/include/sub_session.h @@ -37,8 +37,7 @@ public: bool IsNeedCrossDisplayRendering() const override; void HandleCrossMoveToSurfaceNode(WSRect& globalRect) override; std::set GetNewDisplayIdsDuringMoveTo(WSRect& newRect); - void HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason reason, - const sptr& screenSession) override; + void HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason reason, DisplayId displayId) override; void SetParentSessionCallback(NotifySetParentSessionFunc&& func) override; WMError NotifySetParentSession(int32_t oldParentWindowId, int32_t newParentWindowId) override; diff --git a/window_scene/session/host/include/ws_snapshot_helper.h b/window_scene/session/host/include/ws_snapshot_helper.h index f3b9a23165d81827e6127164e05229c030a9e060..9c48dd98821cbe967ffa71056ec4ee59d6075b81 100644 --- a/window_scene/session/host/include/ws_snapshot_helper.h +++ b/window_scene/session/host/include/ws_snapshot_helper.h @@ -44,11 +44,16 @@ constexpr SnapshotStatus maxCapacity = { SCREEN_COUNT, ORIENTATION_COUNT }; class WSSnapshotHelper { public: - WSSnapshotHelper() = default; - ~WSSnapshotHelper() = default; + static WSSnapshotHelper* GetInstance(); static uint32_t GetScreenStatus(); static uint32_t GetScreenStatus(FoldStatus foldStatus); static DisplayOrientation GetDisplayOrientation(int32_t rotation); + void SetWindowScreenStatus(uint32_t screenStatus); + void SetWindowScreenStatus(FoldStatus foldStatus); + void SetWindowOrientationStatus(uint32_t orientationStatus); + void SetWindowOrientationStatus(Rotation rotation); + SnapshotStatus GetWindowStatus() const; + uint32_t GetWindowRotation() const; static inline uint32_t GetOrientation(int32_t rotation) { if (rotation == LANDSCAPE_ANGLE || rotation == LANDSCAPE_INVERTED_ANGLE) { @@ -65,6 +70,20 @@ public: } return SNAPSHOT_PORTRAIT; } + + static inline uint32_t GetOrientation(Rotation rotation) + { + if (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180) { + return SNAPSHOT_PORTRAIT; + } + return SNAPSHOT_LANDSCAPE; + } + +private: + WSSnapshotHelper() = default; + ~WSSnapshotHelper() = default; + SnapshotStatus windowStatus_; + Rotation windowRotation_; }; } // namespace OHOS::Rosen diff --git a/window_scene/session/host/include/zidl/session_interface.h b/window_scene/session/host/include/zidl/session_interface.h index db962ffb0bd0811855d1dfb501c08e9f76eb8d2b..f21a2657979e21153a0749211f6cac365b7bedbf 100644 --- a/window_scene/session/host/include/zidl/session_interface.h +++ b/window_scene/session/host/include/zidl/session_interface.h @@ -228,7 +228,8 @@ public: * * @return Returns WSError::WS_OK if called success, otherwise failed. */ - virtual WSError BatchPendingSessionsActivation(const std::vector>& abilitySessionInfos) + virtual WSError BatchPendingSessionsActivation(const std::vector>& abilitySessionInfos, + const std::vector& configs = {}) { return WSError::WS_OK; } virtual WSError TerminateSession(const sptr abilitySessionInfo) { return WSError::WS_OK; } virtual WSError SetLandscapeMultiWindow(bool isLandscapeMultiWindow) { return WSError::WS_OK; } @@ -492,6 +493,7 @@ public: virtual WSError UpdateRotationChangeRegistered(int32_t persistentId, bool isRegister) { return WSError::WS_OK; } virtual WMError UpdateScreenshotAppEventRegistered(int32_t persistentId, bool isRegister) { return WMError::WM_OK; } virtual WMError UpdateAcrossDisplaysChangeRegistered(bool isRegister) { return WMError::WM_OK; } + virtual WMError OnUpdateColorMode(const std::string& colorMode, bool hasDarkRes) { return WMError::WM_OK; } virtual WMError IsMainWindowFullScreenAcrossDisplays(bool& isAcrossDisplays) { return WMError::WM_OK; } virtual WSError GetIsHighlighted(bool& isHighlighted) { return WSError::WS_OK; } 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 5e8f00697c2b249fa22a84477db502bc9cb33ac8..78c45862dff9cf2f2b17f912cf17eecee4751eca 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 @@ -61,6 +61,7 @@ enum class SessionInterfaceCode { TRANS_ID_ADJUST_KEYBOARD_LAYOUT, TRANS_ID_LAYOUT_FULL_SCREEN_CHANGE, TRANS_ID_DEFAULT_DENSITY_ENABLED, + TRANS_ID_UPDATE_COLOR_MODE, TRANS_ID_GET_FORCE_LANDSCAPE_CONFIG, TRANS_ID_GET_HOOK_WINDOW_INFO, TRANS_ID_GET_STATUSBAR_HEIGHT, diff --git a/window_scene/session/host/include/zidl/session_proxy.h b/window_scene/session/host/include/zidl/session_proxy.h index 4277499205444e0b5ab8078f29e0d5b986ec1cec..943b3fb921c13ad071f0896d1f6db5ed53316aa2 100644 --- a/window_scene/session/host/include/zidl/session_proxy.h +++ b/window_scene/session/host/include/zidl/session_proxy.h @@ -42,7 +42,8 @@ public: WSError ChangeSessionVisibilityWithStatusBar(const sptr abilitySessionInfo, bool visible) override; WSError PendingSessionActivation(const sptr abilitySessionInfo) override; - WSError BatchPendingSessionsActivation(const std::vector>& abilitySessionInfos) override; + WSError BatchPendingSessionsActivation(const std::vector>& abilitySessionInfos, + const std::vector& configs = {}) override; WSError TerminateSession(const sptr abilitySessionInfo) override; WSError NotifySessionException( const sptr abilitySessionInfo, const ExceptionInfo& exceptionInfo) override; @@ -50,6 +51,7 @@ public: WSError SyncSessionEvent(SessionEvent event) override; WSError OnLayoutFullScreenChange(bool isLayoutFullScreen) override; WSError OnDefaultDensityEnabled(bool isDefaultDensityEnabled) override; + WMError OnUpdateColorMode(const std::string& colorMode, bool hasDarkRes) override; WSError OnTitleAndDockHoverShowChange(bool isTitleHoverShown = true, bool isDockHoverShown = true) override; WSError OnRestoreMainWindow() override; @@ -84,7 +86,7 @@ public: WSError SetSubWindowSource(SubWindowSource source) override; WSError WriteOneSessionInfo(MessageParcel& data, const sptr& abilitySessionInfo); WSError WriteOneSessionInfoPart(MessageParcel& data, const sptr& abilitySessionInfo); - + WSError WriteOnePendingSessionActivationConfig(MessageParcel& data, const PendingSessionActivationConfig& configs); /* * UIExtension */ diff --git a/window_scene/session/host/include/zidl/session_stub.h b/window_scene/session/host/include/zidl/session_stub.h index 8e882ee5fcaf4900d7b5ab055db00bf506549397..020dfcebba8dae2b5507990693f9bd112514cf36 100644 --- a/window_scene/session/host/include/zidl/session_stub.h +++ b/window_scene/session/host/include/zidl/session_stub.h @@ -79,6 +79,7 @@ private: int HandleUpdatePropertyByAction(MessageParcel& data, MessageParcel& reply); int HandleLayoutFullScreenChange(MessageParcel& data, MessageParcel& reply); int HandleDefaultDensityEnabled(MessageParcel& data, MessageParcel& reply); + int HandleUpdateColorMode(MessageParcel& data, MessageParcel& reply); int HandleTitleAndDockHoverShowChange(MessageParcel& data, MessageParcel& reply); int HandleRestoreMainWindow(MessageParcel& data, MessageParcel& reply); int HandleGetAppForceLandscapeConfig(MessageParcel& data, MessageParcel& reply); @@ -99,6 +100,7 @@ private: int HandleUpdateAcrossDisplaysChangeRegistered(MessageParcel& data, MessageParcel& reply); int HandleGetIsHighlighted(MessageParcel& data, MessageParcel& reply); int ReadOneAbilitySessionInfo(MessageParcel& data, sptr abilitySessionInfo); + int ReadOnePendingSessionActivationConfig(MessageParcel& data, PendingSessionActivationConfig& config); // extension extension int HandleTransferAbilityResult(MessageParcel& data, MessageParcel& reply); diff --git a/window_scene/session/host/src/extension_session.cpp b/window_scene/session/host/src/extension_session.cpp index fcdc671892aea623d89f23934c3e2d1e17a350b6..9d474055a2dff9a191b046502329dc0dfe4855f2 100644 --- a/window_scene/session/host/src/extension_session.cpp +++ b/window_scene/session/host/src/extension_session.cpp @@ -514,6 +514,10 @@ WSError ExtensionSession::Background(bool isFromClient, const std::string& ident state = SessionState::STATE_INACTIVE; isActive_ = false; } + if (state == SessionState::STATE_BACKGROUND) { + TLOGI(WmsLogTag::WMS_LIFE, "ExtensionSession %{public}d state already backgrounded.", GetPersistentId()); + return WSError::WS_OK; + } if (state != SessionState::STATE_INACTIVE) { WLOGFW("[WMSLife] Background state invalid! state:%{public}u", state); return WSError::WS_ERROR_INVALID_SESSION; diff --git a/window_scene/session/host/src/main_session.cpp b/window_scene/session/host/src/main_session.cpp index f45e13b645e3eb602876a7d6cb8982102c55b048..221fbc14b4aa4808ebfafa35c5620de2ad77ac1d 100644 --- a/window_scene/session/host/src/main_session.cpp +++ b/window_scene/session/host/src/main_session.cpp @@ -413,12 +413,11 @@ void MainSession::NotifySubSessionRectChangeByAnchor(const WSRect& parentRect, } } -void MainSession::HandleSubSessionSurfaceNodeByWindowAnchor(SizeChangeReason reason, - const sptr& screenSession) +void MainSession::HandleSubSessionSurfaceNodeByWindowAnchor(SizeChangeReason reason, DisplayId displayId) { for (const auto& subSession : GetSubSession()) { if (subSession && subSession->GetWindowAnchorInfo().isAnchorEnabled_ && subSession->IsSessionForeground()) { - subSession->HandleCrossSurfaceNodeByWindowAnchor(reason, screenSession); + subSession->HandleCrossSurfaceNodeByWindowAnchor(reason, displayId); } } } diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 932968ca909a7b7512d33b613608b83fac76769a..2a037c2232d96a454c0e6843cbfa83878a80fac4 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -44,6 +44,7 @@ #endif // DEVICE_STATUS_ENABLE #include "interfaces/include/ws_common.h" #include "pixel_map.h" +#include "process_options.h" #include "rs_adapter.h" #include "session_coordinate_helper.h" #include "session/screen/include/screen_session.h" @@ -102,6 +103,12 @@ bool CheckIfRectElementIsTooLarge(const WSRect& rect) } return false; } + +bool isMainOrExtendScreenMode(const ScreenSourceMode& screenSourceMode) +{ + return screenSourceMode == ScreenSourceMode::SCREEN_MAIN || + screenSourceMode == ScreenSourceMode::SCREEN_EXTEND; +} } // namespace MaximizeMode SceneSession::maximizeMode_ = MaximizeMode::MODE_RECOVER; @@ -154,6 +161,12 @@ WSError SceneSession::ConnectInner(const sptr& sessionStage, property->SetAppInstanceKey(session->GetAppInstanceKey()); property->SetUseControlState(session->isAppUseControl_); property->SetAncoRealBundleName(session->IsAnco() ? session->GetSessionInfo().bundleName_ : ""); + if (session->GetSessionInfo().processOptions != nullptr) { + MissionInfo missionInfo; + missionInfo.startupInvisibility_ = session->GetSessionInfo().processOptions->startupVisibility == + AAFwk::StartupVisibility::STARTUP_HIDE; + property->SetMissionInfo(missionInfo); + } } session->RetrieveStatusBarDefaultVisibility(); auto ret = LOCK_GUARD_EXPR(SCENE_GUARD, session->Session::ConnectInner( @@ -368,6 +381,10 @@ WSError SceneSession::Foreground( if (SessionPermission::VerifyCallingPermission("ohos.permission.CALLED_BELOW_LOCK_SCREEN")) { TLOGW(WmsLogTag::WMS_LIFE, "screen is locked, session %{public}d %{public}s permission verified", GetPersistentId(), sessionInfo_.bundleName_.c_str()); + } else if (SessionPermission::VerifyCallingPermission("ohos.permission.START_WINDOW_BELOW_LOCK_SCREEN")) { + TLOGW(WmsLogTag::WMS_LIFE, + "screen is locked, session %{public}d %{public}s start below lock screen permission verified", + GetPersistentId(), sessionInfo_.bundleName_.c_str()); } else { TLOGW(WmsLogTag::WMS_LIFE, "failed: screen is locked, session %{public}d %{public}s show without ShowWhenLocked flag", @@ -411,8 +428,7 @@ WSError SceneSession::ForegroundTask(const sptr& property int32_t persistentId = session->GetPersistentId(); auto ret = session->Session::Foreground(property); if (ret != WSError::WS_OK) { - TLOGNE(WmsLogTag::WMS_LIFE, "%{public}s session foreground failed, ret=%{public}d persistentId=%{public}d", - where, ret, persistentId); + TLOGNE(WmsLogTag::WMS_LIFE, "%{public}s ret=%{public}d win=%{public}d", where, ret, persistentId); return ret; } session->NotifySingleHandTransformChange(session->GetSingleHandTransform()); @@ -437,8 +453,8 @@ WSError SceneSession::ForegroundTask(const sptr& property TLOGNI(WmsLogTag::WMS_LIFE, "%{public}s foreground specific callback does not take effect, callback function null", where); } - if (session->isUIFirstEnabled_) { - session->SetSystemSceneForceUIFirst(false); + if (session->isUIFirstEnabled_ && leashWinSurfaceNode) { + leashWinSurfaceNode->SetForceUIFirst(false); session->isUIFirstEnabled_ = false; } return WSError::WS_OK; @@ -498,7 +514,7 @@ WSError SceneSession::NotifyFrameLayoutFinishFromApp(bool notifyListener, const return WSError::WS_OK; } -WSError SceneSession::BackgroundTask(const bool isSaveSnapshot, ScreenLockReason reason) +WSError SceneSession::BackgroundTask(const bool isSaveSnapshot, BackgroundReason reason) { auto needSaveSnapshot = !ScenePersistentStorage::HasKey("SetImageForRecent_" + std::to_string(GetPersistentId()), ScenePersistentStorageType::MAXIMIZE_STATE); @@ -1218,7 +1234,7 @@ void SceneSession::UpdatePrivacyModeControlInfo() { bool isPrivacyMode = false; auto property = GetSessionProperty(); - if ((property && property->GetPrivacyMode()) || HasSubSessionInPrivacyMode()) { + if ((property && property->GetPrivacyMode()) || HasChildSessionInPrivacyMode()) { isPrivacyMode = true; } if (!isPrivacyMode && appUseControlMap_.find(ControlAppType::PRIVACY_WINDOW) == appUseControlMap_.end()) { @@ -1229,7 +1245,7 @@ void SceneSession::UpdatePrivacyModeControlInfo() NotifyUpdateAppUseControl(ControlAppType::PRIVACY_WINDOW, controlInfo); } -bool SceneSession::HasSubSessionInPrivacyMode() +bool SceneSession::HasChildSessionInPrivacyMode() { for (const auto& subSession : GetSubSession()) { if (subSession == nullptr) { @@ -1240,7 +1256,21 @@ bool SceneSession::HasSubSessionInPrivacyMode() if (property && property->GetPrivacyMode()) { return true; } - if (subSession->HasSubSessionInPrivacyMode()) { + if (subSession->HasChildSessionInPrivacyMode()) { + return true; + } + } + for (const auto& dialogSession : GetDialogVector()) { + if (dialogSession == nullptr) { + TLOGW(WmsLogTag::WMS_LIFE, "dialogSession is nullptr"); + continue; + } + auto property = dialogSession->GetSessionProperty(); + if (property && property->GetPrivacyMode()) { + return true; + } + auto dialogSceneSession = GetSceneSessionById(dialogSession->GetPersistentId()); + if (dialogSceneSession && dialogSceneSession->HasChildSessionInPrivacyMode()) { return true; } } @@ -3670,8 +3700,14 @@ bool SceneSession::IsInCompatScaleStatus() const return false; } -bool SceneSession::IsInCompatScaleMode() const +bool SceneSession::IsInCompatScaleMode() { + if (WindowHelper::IsSubWindow(GetWindowType())) { + auto mainSession = GetSceneSessionById(GetMainSessionId()); + if (mainSession && GetCallingPid() == mainSession->GetCallingPid()) { + return mainSession->IsInCompatScaleMode(); + } + } auto property = GetSessionProperty(); return property->IsAdaptToProportionalScale() || property->IsAdaptToSimulationScale(); } @@ -3679,20 +3715,17 @@ bool SceneSession::IsInCompatScaleMode() const /** * throw slip to full screen */ -void SceneSession::ThrowSlipToFullScreen(WSRect& endRect, WSRect& rect) +void SceneSession::ThrowSlipToFullScreen(WSRect& endRect, WSRect& rect, int32_t statusBarHeight, int32_t dockHeight) { if (pcFoldScreenController_ == nullptr) { return; } - - int32_t statusBarHeight = IsLayoutFullScreen() ? 0 : GetStatusBarHeight(); - int32_t dockHeight = IsLayoutFullScreen() ? 0 : GetDockHeight(); // maximize end rect and notify last rect throwSlipToFullScreenAnimCount_.fetch_add(1); pcFoldScreenController_->ResizeToFullScreen(endRect, statusBarHeight, dockHeight); if (pcFoldScreenController_->IsThrowSlipDirectly()) { pcFoldScreenController_->ThrowSlipFloatingRectDirectly( - rect, GetSessionRequestRect(), GetStatusBarHeight(), GetDockHeight()); + rect, GetSessionRequestRect(), statusBarHeight, dockHeight); } } @@ -3748,7 +3781,7 @@ bool SceneSession::MoveUnderInteriaAndNotifyRectChange(WSRect& rect, SizeChangeR std::function finishCallback = nullptr; bool needSetFullScreen = pcFoldScreenController_->IsStartFullScreen(); if (needSetFullScreen) { - ThrowSlipToFullScreen(endRect, rect); + ThrowSlipToFullScreen(endRect, rect, statusBarHeight, dockHeight); finishCallback = [weakThis = wptr(this), rect, where = __func__] { auto session = weakThis.promote(); if (session == nullptr) { @@ -4032,6 +4065,7 @@ WSError SceneSession::UpdateKeyFrameCloneNode(std::shared_ptr& rsC void SceneSession::SetKeyFramePolicy(const KeyFramePolicy& keyFramePolicy) { TLOGI(WmsLogTag::WMS_LAYOUT_PC, "in"); + std::lock_guard lock(keyFrameMutex_); bool running = keyFramePolicy_.running_; bool stopping = keyFramePolicy_.stopping_; keyFramePolicy_ = keyFramePolicy; @@ -4042,6 +4076,7 @@ void SceneSession::SetKeyFramePolicy(const KeyFramePolicy& keyFramePolicy) WSError SceneSession::SetDragKeyFramePolicy(const KeyFramePolicy& keyFramePolicy) { TLOGI(WmsLogTag::WMS_LAYOUT_PC, "in"); + std::lock_guard lock(keyFrameMutex_); bool running = keyFramePolicy_.running_; bool stopping = keyFramePolicy_.stopping_; keyFramePolicy_ = keyFramePolicy; @@ -4060,15 +4095,25 @@ void SceneSession::UpdateKeyFrameState(SizeChangeReason reason, const WSRect& re } if (reason == SizeChangeReason::DRAG_START && moveDragController_->GetStartDragFlag()) { TLOGD(WmsLogTag::WMS_LAYOUT_PC, "key frame start check"); - if (!keyFramePolicy_.enabled() || GetAppDragResizeType() == DragResizeType::RESIZE_WHEN_DRAG_END) { - keyFramePolicy_.running_ = false; - return; + { + std::lock_guard lock(keyFrameMutex_); + if (!keyFramePolicy_.enabled() || GetAppDragResizeType() == DragResizeType::RESIZE_WHEN_DRAG_END) { + keyFramePolicy_.running_ = false; + return; + } + return InitKeyFrameState(rect); } - return InitKeyFrameState(rect); } - if (!keyFramePolicy_.running_ || !keyFrameCloneNode_) { - TLOGD(WmsLogTag::WMS_LAYOUT_PC, "key frame not start"); - return; + { + std::lock_guard lock(keyFrameMutex_); + if (!keyFramePolicy_.running_ || !keyFrameCloneNode_) { + TLOGD(WmsLogTag::WMS_LAYOUT_PC, "key frame not start"); + return; + } + if (reason == SizeChangeReason::DRAG_END) { + keyFramePolicy_.running_ = false; + keyFramePolicy_.stopping_ = true; + } } if (reason == SizeChangeReason::DRAG) { TLOGD(WmsLogTag::WMS_LAYOUT_PC, "reset gravity and resize clone node"); @@ -4086,8 +4131,6 @@ void SceneSession::UpdateKeyFrameState(SizeChangeReason reason, const WSRect& re RSTransactionAdapter::FlushImplicitTransaction(GetRSUIContext()); } else if (reason == SizeChangeReason::DRAG_END) { TLOGI(WmsLogTag::WMS_LAYOUT_PC, "key frame stopping"); - keyFramePolicy_.running_ = false; - keyFramePolicy_.stopping_ = true; sessionStage_->SetKeyFramePolicy(keyFramePolicy_); keyFrameCloneNode_ = nullptr; } @@ -4157,18 +4200,20 @@ void SceneSession::OnKeyFrameNextVsync(uint64_t count) bool SceneSession::KeyFrameNotifyFilter(const WSRect& rect, SizeChangeReason reason) { - TLOGD(WmsLogTag::WMS_LAYOUT, "reason in: %{public}d", reason); - if (!keyFramePolicy_.running_) { + KeyFramePolicy keyFramePolicy; + { + std::lock_guard lock(keyFrameMutex_); + keyFramePolicy = keyFramePolicy_; + } + if (!keyFramePolicy.running_) { TLOGD(WmsLogTag::WMS_LAYOUT, "skip filter for not running"); return false; } if (reason == SizeChangeReason::DRAG_START) { - TLOGD(WmsLogTag::WMS_LAYOUT, "ensure start reason send"); NotifyClientToUpdateRect("OnMoveDragCallback", nullptr); return true; } if (reason != SizeChangeReason::DRAG) { - TLOGD(WmsLogTag::WMS_LAYOUT, "skip filter for not drag"); return false; } if (keyFrameAnimating_) { @@ -4179,13 +4224,13 @@ bool SceneSession::KeyFrameNotifyFilter(const WSRect& rect, SizeChangeReason rea uint64_t nowTimeStamp = static_cast(std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()).count()); uint64_t interval = nowTimeStamp - lastKeyFrameStamp_; - bool intervalCheckPass = interval >= keyFramePolicy_.interval_; + bool intervalCheckPass = interval >= keyFramePolicy.interval_; bool distanceCheckPass = false; double distance = 0; - if (keyFramePolicy_.distance_ > 0) { + if (keyFramePolicy.distance_ > 0) { distance = sqrt(pow(rect.width_ - lastKeyFrameRect_.width_, POW_DOUBLE) + pow(rect.height_ - lastKeyFrameRect_.height_, POW_DOUBLE)); - distanceCheckPass = distance >= keyFramePolicy_.distance_; + distanceCheckPass = distance >= keyFramePolicy.distance_; } TLOGI(WmsLogTag::WMS_LAYOUT, "key frame checking: %{public}" PRIu64 "[%{public}d], %{public}f[%{public}d]", interval, intervalCheckPass, distance, distanceCheckPass); @@ -4223,6 +4268,16 @@ WSError SceneSession::KeyFrameAnimateEnd() return WSError::WS_OK; } +std::shared_ptr SceneSession::GetWindowDragMoveMountedNode(DisplayId displayId, + uint32_t targetZOrder) +{ + if (!findScenePanelRsNodeByZOrderFunc_) { + TLOGE(WmsLogTag::WMS_LAYOUT, "findScenePanelRsNodeByZOrderFunc_ is null"); + return nullptr; + } + return findScenePanelRsNodeByZOrderFunc_(displayId, targetZOrder); +} + /** @note @window.drag */ void SceneSession::HandleMoveDragSurfaceNode(SizeChangeReason reason) { @@ -4237,6 +4292,7 @@ void SceneSession::HandleMoveDragSurfaceNode(SizeChangeReason reason) TLOGE(WmsLogTag::WMS_LAYOUT, "startScreenSession is null, startDisplayId: %{public}" PRIu64, startDisplayId); return; } + bool isStartScreenMainOrExtend = isMainOrExtendScreenMode(startScreenSession->GetSourceMode()); if (reason == SizeChangeReason::DRAG || reason == SizeChangeReason::DRAG_MOVE) { for (const auto displayId : moveDragController_->GetNewAddedDisplayIdsDuringMoveDrag()) { if (displayId == moveDragController_->GetMoveDragStartDisplayId()) { @@ -4247,17 +4303,18 @@ void SceneSession::HandleMoveDragSurfaceNode(SizeChangeReason reason) TLOGD(WmsLogTag::WMS_LAYOUT, "ScreenSession is null"); continue; } - bool isStartScreenMainOrExtend = startScreenSession->GetSourceMode() == ScreenSourceMode::SCREEN_MAIN - || startScreenSession->GetSourceMode() == ScreenSourceMode::SCREEN_EXTEND; - bool isDestScreenMainOrExtend = screenSession->GetSourceMode() == ScreenSourceMode::SCREEN_MAIN - || screenSession->GetSourceMode() == ScreenSourceMode::SCREEN_EXTEND; + bool isDestScreenMainOrExtend = isMainOrExtendScreenMode(screenSession->GetSourceMode()); // Not main to extend or extend to main or extend to extend, no need to add cross parent child if (!(isStartScreenMainOrExtend && isDestScreenMainOrExtend)) { TLOGD(WmsLogTag::WMS_LAYOUT, "No need to add cross-parent child elements for out-of-scope situations, " "DisplayId: %{public}" PRIu64, displayId); continue; } - + auto dragMoveMountedNode = GetWindowDragMoveMountedNode(displayId, this->GetZOrder()); + if (dragMoveMountedNode == nullptr) { + TLOGE(WmsLogTag::WMS_LAYOUT, "dragMoveMountedNode is null"); + continue; + } { AutoRSTransaction trans(movedSurfaceNode->GetRSUIContext()); movedSurfaceNode->SetPositionZ(MOVE_DRAG_POSITION_Z); @@ -4265,37 +4322,29 @@ void SceneSession::HandleMoveDragSurfaceNode(SizeChangeReason reason) } { - AutoRSTransaction trans(screenSession->GetRSUIContext()); - TLOGI(WmsLogTag::WMS_LAYOUT, "Add window to display: %{public}" PRIu64, displayId); - screenSession->GetDisplayNode()->AddCrossScreenChild(movedSurfaceNode, -1, true); + AutoRSTransaction trans(dragMoveMountedNode->GetRSUIContext()); + dragMoveMountedNode->AddCrossScreenChild(movedSurfaceNode, -1, true); } - HandleSubSessionSurfaceNodeByWindowAnchor(reason, screenSession); + HandleSubSessionSurfaceNodeByWindowAnchor(reason, displayId); + TLOGI(WmsLogTag::WMS_LAYOUT, "Add window to display: %{public}" PRIu64 "persistentId: %{public}d", + displayId, GetPersistentId()); } } else if (reason == SizeChangeReason::DRAG_END) { for (const auto displayId : moveDragController_->GetDisplayIdsDuringMoveDrag()) { if (displayId == moveDragController_->GetMoveDragStartDisplayId()) { continue; } - auto screenSession = ScreenSessionManagerClient::GetInstance().GetScreenSessionById(displayId); - if (screenSession == nullptr) { - TLOGD(WmsLogTag::WMS_LAYOUT, "ScreenSession is null"); - continue; - } - bool isStartScreenMainOrExtend = startScreenSession->GetSourceMode() == ScreenSourceMode::SCREEN_MAIN - || startScreenSession->GetSourceMode() == ScreenSourceMode::SCREEN_EXTEND; - bool isDestScreenMainOrExtend = screenSession->GetSourceMode() == ScreenSourceMode::SCREEN_MAIN - || screenSession->GetSourceMode() == ScreenSourceMode::SCREEN_EXTEND; - // Not main to extend or extend to main or extend to extend, no need to add cross parent child - if (!(isStartScreenMainOrExtend && isDestScreenMainOrExtend)) { - TLOGD(WmsLogTag::WMS_LAYOUT, "No need to add cross-parent child elements for out-of-scope situations, " - "DisplayId: %{public}" PRIu64, displayId); + auto dragMoveMountedNode = GetWindowDragMoveMountedNode(displayId, this->GetZOrder()); + if (dragMoveMountedNode == nullptr) { + TLOGE(WmsLogTag::WMS_LAYOUT, "dragMoveMountedNode is null"); continue; } movedSurfaceNode->SetPositionZ(moveDragController_->GetOriginalPositionZ()); - screenSession->GetDisplayNode()->RemoveCrossScreenChild(movedSurfaceNode); + dragMoveMountedNode->RemoveCrossScreenChild(movedSurfaceNode); movedSurfaceNode->SetIsCrossNode(false); - TLOGI(WmsLogTag::WMS_LAYOUT, "Remove window from display: %{public}" PRIu64, displayId); - HandleSubSessionSurfaceNodeByWindowAnchor(reason, screenSession); + HandleSubSessionSurfaceNodeByWindowAnchor(reason, displayId); + TLOGI(WmsLogTag::WMS_LAYOUT, "Remove window from display: %{public}" PRIu64 "persistentId: %{public}d", + displayId, GetPersistentId()); } } } @@ -4646,7 +4695,8 @@ void SceneSession::SetPrivacyMode(bool isPrivacy) } bool lastPrivacyMode = property->GetPrivacyMode() || property->GetSystemPrivacyMode(); if (lastPrivacyMode == isPrivacy) { - TLOGW(WmsLogTag::WMS_ATTRIBUTE, "mode is same as: %{public}d", isPrivacy); + TLOGI(WmsLogTag::WMS_ATTRIBUTE, "mode is same as: win=[%{public}d, %{public}s], isPrivacy=%{public}d", + GetWindowId(), GetWindowName().c_str(), isPrivacy); return; } property->SetPrivacyMode(isPrivacy); @@ -4671,9 +4721,9 @@ void SceneSession::NotifyPrivacyModeChange() { bool isPrivacyMode = GetSessionProperty()->GetPrivacyMode(); bool currExtPrivacyMode = combinedExtWindowFlags_.privacyModeFlag; - TLOGD(WmsLogTag::WMS_SCB, "id:%{public}d, currExtPrivacyMode:%{public}d, session property privacyMode: %{public}d, " - "last privacyMode:%{public}d", - GetPersistentId(), currExtPrivacyMode, isPrivacyMode, isPrivacyMode_); + TLOGI(WmsLogTag::WMS_ATTRIBUTE, "win:[%{public}d, %{public}s], currExtPrivacyMode:%{public}d, " + "session property privacyMode:%{public}d, last privacyMode:%{public}d", + GetPersistentId(), GetWindowName().c_str(), currExtPrivacyMode, isPrivacyMode, isPrivacyMode_); bool mixedPrivacyMode = currExtPrivacyMode || isPrivacyMode; if (mixedPrivacyMode != isPrivacyMode_) { isPrivacyMode_ = mixedPrivacyMode; @@ -5523,9 +5573,16 @@ WSError SceneSession::PendingSessionActivation(const sptr ab WSError SceneSession::DoBatchPendingSessionsActivation( const std::vector>& abilitySessionInfos, - sptr& session, bool isFoundationCall) + sptr& session, bool isFoundationCall, const std::vector& configs) { std::vector> sessionInfos; + std::vector> abilitySessionActivationConfigs; + for (const auto& config : configs) { + auto info = std::make_shared(); + info->forceStart = config.forceStart; + info->forceNewWant = config.forceNewWant; + abilitySessionActivationConfigs.emplace_back(info); + } for (auto& abilitySessionInfo : abilitySessionInfos) { if (abilitySessionInfo == nullptr) { TLOGE(WmsLogTag::WMS_LIFE, "abilitySessionInfo is null"); @@ -5556,14 +5613,15 @@ WSError SceneSession::DoBatchPendingSessionsActivation( } session->sessionInfo_.startMethod = StartMethod::START_CALL; if (session->batchPendingSessionsActivationFunc_) { - session->batchPendingSessionsActivationFunc_(sessionInfos); + session->batchPendingSessionsActivationFunc_(sessionInfos, abilitySessionActivationConfigs); } return WSError::WS_OK; } -WSError SceneSession::BatchPendingSessionsActivation(const std::vector>& abilitySessionInfos) + +WSError SceneSession::BatchPendingSessionsActivation(const std::vector>& abilitySessionInfos, + const std::vector& configs) { - TLOGI(WmsLogTag::WMS_LIFE, "Batch pending session activations size: %{public}zu", abilitySessionInfos.size()); if (!SessionPermission::IsSystemAppCall() && !SessionPermission::IsSACalling()) { TLOGE(WmsLogTag::WMS_LIFE, "The caller is neither a system app nor an SA."); return WSError::WS_ERROR_INVALID_PERMISSION; @@ -5572,9 +5630,16 @@ WSError SceneSession::BatchPendingSessionsActivation(const std::vectorDoBatchPendingSessionsActivation(abilitySessionInfos, session, isFoundationCall); + return session->DoBatchPendingSessionsActivation(abilitySessionInfos, session, isFoundationCall, configs); }, __func__); return WSError::WS_OK; } @@ -5931,6 +5996,10 @@ void SceneSession::SetSupportEnterWaterfallMode(bool isSupportEnter) TLOGE(WmsLogTag::WMS_LAYOUT_PC, "sessionStage is nullptr"); return; } + if (!WindowHelper::IsMainWindow(GetWindowType())) { + TLOGW(WmsLogTag::WMS_LAYOUT_PC, "only main window support enter water fall mode."); + return; + } sessionStage_->SetSupportEnterWaterfallMode(isSupportEnter); } @@ -7200,6 +7269,27 @@ WSError SceneSession::OnDefaultDensityEnabled(bool isDefaultDensityEnabled) return WSError::WS_OK; } +WMError SceneSession::OnUpdateColorMode(const std::string& colorMode, bool hasDarkRes) +{ + TLOGI(WmsLogTag::WMS_ATTRIBUTE, "winId: %{public}d, colorMode: %{public}s, hasDarkRes: %{public}u", + GetPersistentId(), colorMode.c_str(), hasDarkRes); + std::lock_guard lock(colorModeMutex_); + colorMode_ = colorMode; + hasDarkRes_ = hasDarkRes; + return WMError::WM_OK; +} + +std::string SceneSession::GetAbilityColorMode() const +{ + std::lock_guard lock(colorModeMutex_); + TLOGI(WmsLogTag::WMS_ATTRIBUTE, "winId: %{public}d, colorMode: %{public}s, hasDarkRes: %{public}u", + GetPersistentId(), colorMode_.c_str(), hasDarkRes_); + if (colorMode_ == AppExecFwk::ConfigurationInner::COLOR_MODE_DARK && !hasDarkRes_) { + return AppExecFwk::ConfigurationInner::COLOR_MODE_AUTO; + } + return colorMode_; +} + /** @note @Window.Layout */ WMError SceneSession::UpdateWindowModeForUITest(int32_t updateMode) { @@ -7991,9 +8081,12 @@ bool SceneSession::NotifyServerToUpdateRect(const SessionUIParam& uiParam, SizeC TLOGD(WmsLogTag::WMS_PIPELINE, "skip recent, id:%{public}d", GetPersistentId()); return false; } - if (keyFramePolicy_.running_) { - TLOGI(WmsLogTag::WMS_PIPELINE, "skip for key frame running, id:%{public}d", GetPersistentId()); - return false; + { + std::lock_guard lock(keyFrameMutex_); + if (keyFramePolicy_.running_) { + TLOGI(WmsLogTag::WMS_PIPELINE, "skip for key frame running, id:%{public}d", GetPersistentId()); + return false; + } } if (uiParam.rect_.IsInvalid()) { TLOGW(WmsLogTag::WMS_PIPELINE, "id:%{public}d rect:%{public}s is invalid", @@ -8402,7 +8495,7 @@ void SceneSession::SetWindowCornerRadiusCallback(NotifySetWindowCornerRadiusFunc } session->onSetWindowCornerRadiusFunc_ = std::move(func); auto property = session->GetSessionProperty(); - float cornerRadius = property->GetWindowCornerRadius(); + float cornerRadius = property ? property->GetWindowCornerRadius() : WINDOW_CORNER_RADIUS_INVALID; if (!MathHelper::LessNotEqual(cornerRadius, 0.0f)) { // Valid corner radius menas app has set corner radius of the window, need to update to scb. session->onSetWindowCornerRadiusFunc_(cornerRadius); @@ -8599,19 +8692,41 @@ WSError SceneSession::NotifyRotationProperty(uint32_t rotation, uint32_t width, WSRect wsrect = { 0, 0, width, height }; auto properties = session->GetSystemBarPropertyForRotation(); std::map avoidAreas; + uint32_t orientation = 0; + WSError ret = session->ConvertRotationToOrientation(rotation, orientation); + if (ret != WSError::WS_OK) { + TLOGNE(WmsLogTag::WMS_ROTATION, "failed to convert Rotation to Orientation"); + return ret; + } + // Orientation type is required here session->GetAvoidAreasByRotation( - static_cast(rotation / ROTATION_DEGREE), wsrect, properties, avoidAreas); + static_cast(orientation), wsrect, properties, avoidAreas); if (!session->sessionStage_) { return WSError::WS_ERROR_NULLPTR; } Rect rect = { wsrect.posX_, wsrect.posY_, wsrect.width_, wsrect.height_ }; - OrientationInfo info = { rotation, rect, avoidAreas }; + OrientationInfo info = { orientation, rect, avoidAreas }; session->sessionStage_->NotifyTargetRotationInfo(info); return WSError::WS_OK; }, __func__); return WSError::WS_OK; } +WSError SceneSession::ConvertRotationToOrientation(uint32_t rotation, uint32_t& orientation) +{ + sptr screenSession = + ScreenSessionManagerClient::GetInstance().GetScreenSessionById(GetSessionProperty()->GetDisplayId()); + if (screenSession == nullptr) { + TLOGW(WmsLogTag::WMS_ROTATION, "Screen session is null"); + return WSError::WS_ERROR_INVALID_DISPLAY; + } + FoldDisplayMode foldDisplayMode = ScreenSessionManagerClient::GetInstance().GetFoldDisplayMode(); + Rotation targetRotation = static_cast(rotation / ROTATION_DEGREE); + DisplayOrientation displayOrientation = screenSession->CalcDisplayOrientation(targetRotation, foldDisplayMode); + orientation = static_cast(displayOrientation); + return WSError::WS_OK; +} + void SceneSession::SetSystemBarPropertyForRotation( const std::map& properties) { @@ -9250,4 +9365,9 @@ WSError SceneSession::SetFrameRectForPartialZoomInInner(const Rect& frameRect) TLOGI(WmsLogTag::WMS_ANIMATION, "frameRect: %{public}s", frameRect.ToString().c_str()); return WSError::WS_OK; } + +void SceneSession::SetFindScenePanelRsNodeByZOrderFunc(FindScenePanelRsNodeByZOrderFunc&& func) +{ + findScenePanelRsNodeByZOrderFunc_ = std::move(func); +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index d6db683e8e4d0d9ecbecad428a4cf568888fc8b5..6fddb97ae78bb393ac171632ce076a47515c0af4 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -53,8 +53,6 @@ constexpr float INNER_BORDER_VP = 5.0f; constexpr float OUTSIDE_BORDER_VP = 4.0f; constexpr float INNER_ANGLE_VP = 16.0f; constexpr uint32_t MAX_LIFE_CYCLE_TASK_IN_QUEUE = 15; -constexpr uint32_t COLOR_WHITE = 0xffffffff; -constexpr uint32_t COLOR_BLACK = 0xff000000; 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; @@ -171,6 +169,11 @@ int32_t Session::GetPersistentId() const return persistentId_; } +int32_t Session::GetCurrentRotation() const +{ + return currentRotation_; +} + void Session::SetSurfaceNode(const std::shared_ptr& surfaceNode) { RSAdapterUtil::SetRSUIContext(surfaceNode, GetRSUIContext(), true); @@ -2437,7 +2440,7 @@ WSError Session::HandleSubWindowClick(int32_t action, int32_t sourceType, bool i GetPersistentId(), raiseEnabled, isPointDown, isPointDown); if (raiseEnabled && isPointDown && !isModal) { RaiseToAppTopForPointDown(); - } else if (parentSession && !isPointMove) { + } else if (parentSession && isPointDown) { // sub window is forbidden to raise to top after click, but its parent should raise parentSession->NotifyClick(!IsScbCoreEnabled()); } @@ -2625,7 +2628,7 @@ std::shared_ptr Session::Snapshot(bool runInFfrt, float scalePa return nullptr; } auto surfaceNode = GetSurfaceNode(); - auto key = GetSessionStatus(); + auto key = GetSessionSnapshotStatus(); auto isPersistentImageFit = IsPersistentImageFit(); if (isPersistentImageFit) key = defaultStatus; if (!surfaceNode || !surfaceNode->IsBufferAvailable()) { @@ -2707,12 +2710,12 @@ bool Session::GetEnableAddSnapshot() const } void Session::SaveSnapshot(bool useFfrt, bool needPersist, std::shared_ptr persistentPixelMap, - bool updateSnapshot, ScreenLockReason reason) + bool updateSnapshot, BackgroundReason reason) { if (scenePersistence_ == nullptr) { return; } - auto key = GetSessionStatus(reason); + auto key = GetSessionSnapshotStatus(reason); auto rotate = WSSnapshotHelper::GetDisplayOrientation(currentRotation_); if (persistentPixelMap) { key = defaultStatus; @@ -2889,13 +2892,10 @@ SnapshotStatus Session::GetWindowStatus() const if (!SupportSnapshotAllSessionStatus()) { return defaultStatus; } - uint32_t snapshotScreen = WSSnapshotHelper::GetScreenStatus(); - auto windowOrientation = GetWindowOrientation(); - uint32_t orientation = WSSnapshotHelper::GetOrientation(windowOrientation); - return std::make_pair(snapshotScreen, orientation); + return WSSnapshotHelper::GetInstance()->GetWindowStatus(); } -SnapshotStatus Session::GetSessionStatus(ScreenLockReason reason) const +SnapshotStatus Session::GetSessionSnapshotStatus(BackgroundReason reason) const { if (!SupportSnapshotAllSessionStatus()) { return defaultStatus; @@ -2906,32 +2906,19 @@ SnapshotStatus Session::GetSessionStatus(ScreenLockReason reason) const } else { snapshotScreen = WSSnapshotHelper::GetScreenStatus(); } - if (reason == ScreenLockReason::EXPAND_TO_FOLD_SINGLE_POCKET) { + if (reason == BackgroundReason::EXPAND_TO_FOLD_SINGLE_POCKET) { snapshotScreen = SCREEN_EXPAND; } uint32_t orientation = WSSnapshotHelper::GetOrientation(currentRotation_); return std::make_pair(snapshotScreen, orientation); } -DisplayOrientation Session::GetWindowOrientation() const +uint32_t Session::GetWindowOrientation() const { if (!SupportSnapshotAllSessionStatus()) { - return DisplayOrientation::PORTRAIT; - } - DisplayId displayId = GetScreenId(); - auto screenSession = ScreenSessionManagerClient::GetInstance().GetScreenSession(displayId); - if (!screenSession) { - TLOGE(WmsLogTag::WMS_PATTERN, "screenSession is nullptr, id:%{public}d", persistentId_); - return DisplayOrientation::PORTRAIT; + return 0; } - auto screenProperty = screenSession->GetScreenProperty(); - DisplayOrientation displayOrientation = screenProperty.GetDisplayOrientation(); - auto windowOrientation = static_cast(displayOrientation); - auto snapshotScreen = WSSnapshotHelper::GetScreenStatus(); - if (snapshotScreen == SCREEN_UNKNOWN) { - windowOrientation = (windowOrientation + SECONDARY_EXPAND_OFFSET) % ROTATION_COUNT; - } - return static_cast(windowOrientation); + return WSSnapshotHelper::GetInstance()->GetWindowRotation(); } uint32_t Session::GetLastOrientation() const @@ -3341,11 +3328,14 @@ WSError Session::SetAppSupportPhoneInPc(bool isSupportPhone) WSError Session::SetCompatibleModeProperty(const sptr compatibleModeProperty) { auto property = GetSessionProperty(); - if (property == nullptr) { + if (property == nullptr || compatibleModeProperty == nullptr) { TLOGE(WmsLogTag::WMS_COMPAT, "id: %{public}d property is nullptr", persistentId_); return WSError::WS_ERROR_NULLPTR; } property->SetCompatibleModeProperty(compatibleModeProperty); + if (compatibleModeProperty->IsDragResizeDisabled()) { + property->SetDragEnabled(false); + } if (!sessionStage_) { TLOGE(WmsLogTag::WMS_COMPAT, "sessionStage is null"); return WSError::WS_ERROR_NULLPTR; diff --git a/window_scene/session/host/src/sub_session.cpp b/window_scene/session/host/src/sub_session.cpp index 307d48786633037516a34ecabd844a30a051e8f9..9f878bc6f18ab5264e90d119dd6e06834caa1585 100644 --- a/window_scene/session/host/src/sub_session.cpp +++ b/window_scene/session/host/src/sub_session.cpp @@ -361,34 +361,39 @@ WMError SubSession::NotifySetParentSession(int32_t oldParentWindowId, int32_t ne }, __func__); } -void SubSession::HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason reason, const sptr& screenSession) +void SubSession::HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason reason, DisplayId displayId) { - if (!screenSession) { - TLOGE(WmsLogTag::WMS_LAYOUT, "Id:%{public}d, ScreenSession is null", GetPersistentId()); - return; - } auto surfaceNode = GetSurfaceNodeForMoveDrag(); if (!surfaceNode) { TLOGE(WmsLogTag::WMS_LAYOUT, "Id:%{public}d, SurfaceNode is null", GetPersistentId()); return; } - DisplayId displayId = screenSession->GetDisplayId(); if (reason == SizeChangeReason::DRAG || reason == SizeChangeReason::DRAG_MOVE) { + auto dragMoveMountedNode = GetWindowDragMoveMountedNode(displayId, this->GetZOrder()); + if (dragMoveMountedNode == nullptr) { + TLOGE(WmsLogTag::WMS_LAYOUT, "dragMoveMountedNode is null"); + return; + } { AutoRSTransaction trans(surfaceNode->GetRSUIContext()); surfaceNode->SetPositionZ(GetZOrder()); surfaceNode->SetIsCrossNode(true); } { - AutoRSTransaction trans(screenSession->GetRSUIContext()); - screenSession->GetDisplayNode()->AddCrossScreenChild(surfaceNode, SUFFIX_INDEX, true); + AutoRSTransaction trans(dragMoveMountedNode->GetRSUIContext()); + dragMoveMountedNode->AddCrossScreenChild(surfaceNode, SUFFIX_INDEX, true); } cloneNodeCountDuringCross_.fetch_add(1); TLOGI(WmsLogTag::WMS_LAYOUT, "Add sub window to display:%{public}" PRIu64 " persistentId:%{public}d, " "cloneNodeCountDuringCross:%{public}d", displayId, GetPersistentId(), cloneNodeCountDuringCross_.load()); } else if (reason == SizeChangeReason::DRAG_END) { surfaceNode->SetPositionZ(moveDragController_->GetOriginalPositionZ()); - screenSession->GetDisplayNode()->RemoveCrossScreenChild(surfaceNode); + auto dragMoveMountedNode = GetWindowDragMoveMountedNode(displayId, this->GetZOrder()); + if (dragMoveMountedNode == nullptr) { + TLOGE(WmsLogTag::WMS_LAYOUT, "dragMoveMountedNode is null"); + return; + } + dragMoveMountedNode->RemoveCrossScreenChild(surfaceNode); surfaceNode->SetIsCrossNode(false); cloneNodeCountDuringCross_.fetch_sub(1); TLOGI(WmsLogTag::WMS_LAYOUT, "Remove sub window from display:%{public}" PRIu64 " persistentId:%{public}d, " @@ -451,17 +456,22 @@ void SubSession::HandleCrossMoveToSurfaceNode(WSRect& globalRect) TLOGD(WmsLogTag::WMS_LAYOUT, "virtual screen, no need to add cross parent child"); continue; } + auto dragMoveMountedNode = GetWindowDragMoveMountedNode(displayId, this->GetZOrder()); + if (dragMoveMountedNode == nullptr) { + TLOGE(WmsLogTag::WMS_LAYOUT, "dragMoveMountedNode is null"); + continue; + } movedSurfaceNode->SetPositionZ(GetZOrder()); + movedSurfaceNode->SetIsCrossNode(true); + RSTransactionAdapter::FlushImplicitTransaction(movedSurfaceNode->GetRSUIContext()); { - AutoRSTransaction trans(screenSession->GetRSUIContext()); - screenSession->GetDisplayNode()->AddCrossScreenChild(movedSurfaceNode, SUFFIX_INDEX, true); + AutoRSTransaction trans(dragMoveMountedNode->GetRSUIContext()); + dragMoveMountedNode->AddCrossScreenChild(movedSurfaceNode, SUFFIX_INDEX, true); } cloneNodeCount_++; - movedSurfaceNode->SetIsCrossNode(true); TLOGI(WmsLogTag::WMS_LAYOUT, "Add sub window to display:%{public}" PRIu64 " persistentId:%{public}d", displayId, GetPersistentId()); } - RSTransactionAdapter::FlushImplicitTransaction(movedSurfaceNode->GetRSUIContext()); } std::set SubSession::GetNewDisplayIdsDuringMoveTo(WSRect& newRect) @@ -519,17 +529,22 @@ void SubSession::AddSurfaceNodeToScreen(DisplayId draggingOrMovingParentDisplayI TLOGD(WmsLogTag::WMS_LAYOUT, "virtual screen, no need to add cross parent child"); continue; } + auto dragMoveMountedNode = GetWindowDragMoveMountedNode(displayId, this->GetZOrder()); + if (dragMoveMountedNode == nullptr) { + TLOGE(WmsLogTag::WMS_LAYOUT, "dragMoveMountedNode is null"); + continue; + } currSurfacedNode->SetPositionZ(GetZOrder()); + currSurfacedNode->SetIsCrossNode(true); + RSTransactionAdapter::FlushImplicitTransaction(currSurfacedNode->GetRSUIContext()); { - AutoRSTransaction trans(screenSession->GetRSUIContext()); - screenSession->GetDisplayNode()->AddCrossScreenChild(currSurfacedNode, SUFFIX_INDEX, true); + AutoRSTransaction trans(dragMoveMountedNode->GetRSUIContext()); + dragMoveMountedNode->AddCrossScreenChild(currSurfacedNode, SUFFIX_INDEX, true); } cloneNodeCount_++; - currSurfacedNode->SetIsCrossNode(true); TLOGI(WmsLogTag::WMS_LAYOUT, "Add sub window to display:%{public}" PRIu64 " persistentId:%{public}d, " "cloneNodeCount:%{public}d", displayId, GetPersistentId(), cloneNodeCount_); } - RSTransactionAdapter::FlushImplicitTransaction(currSurfacedNode->GetRSUIContext()); } void SubSession::RemoveSurfaceNodeFromScreen() diff --git a/window_scene/session/host/src/system_session.cpp b/window_scene/session/host/src/system_session.cpp index 8ec537e49423f4bc999e19957d2fe86ce21020c2..142830df5e2ab57d7c8ac590ffad7c56a59e1b63 100644 --- a/window_scene/session/host/src/system_session.cpp +++ b/window_scene/session/host/src/system_session.cpp @@ -28,7 +28,7 @@ constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "System constexpr uint32_t MIN_SYSTEM_WINDOW_WIDTH = 5; constexpr uint32_t MIN_SYSTEM_WINDOW_HEIGHT = 5; -constexpr uint64_t FLOATING_BALL_CLICK_INTERVAL = 5000; +constexpr uint8_t MAX_FB_CLICK_COUNT = 8; const std::string FB_CLICK_EVENT = "click"; SystemSession::SystemSession(const SessionInfo& info, const sptr& specificCallback) @@ -501,15 +501,13 @@ WMError SystemSession::RestoreFbMainWindow(const std::shared_ptr& w session->GetSessionInfo().bundleName_.c_str(), want->GetBundle().c_str()); return WMError::WM_ERROR_FB_RESTORE_MAIN_WINDOW_FAILED; } - uint64_t nowTime = static_cast(std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count()); { std::lock_guard lock(session->fbClickMutex_); - if (nowTime - session->fbClickTime_ >= FLOATING_BALL_CLICK_INTERVAL) { - TLOGNW(WmsLogTag::WMS_SYSTEM, "%{public}s Start time is too long from click, deny", where); + if (session->fbClickCnt_ == 0) { + TLOGNE(WmsLogTag::WMS_SYSTEM, "%{public}s not click, deny", where); return WMError::WM_ERROR_FB_RESTORE_MAIN_WINDOW_FAILED; } - session->fbClickTime_ = 0; + session->fbClickCnt_--; } TLOGNI(WmsLogTag::WMS_SYSTEM, "%{public}s restore window, bundle %{public}s, ability %{public}s, session bundle %{public}s", @@ -580,8 +578,10 @@ WSError SystemSession::SendFbActionEvent(const std::string& action) return WSError::WS_ERROR_NULLPTR; } if (action == FB_CLICK_EVENT) { - fbClickTime_ = static_cast(std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count()); + std::lock_guard lock(fbClickMutex_); + if (fbClickCnt_ < MAX_FB_CLICK_COUNT) { + ++fbClickCnt_; + } } return sessionStage_->SendFbActionEvent(action); } diff --git a/window_scene/session/host/src/ws_snapshot_helper.cpp b/window_scene/session/host/src/ws_snapshot_helper.cpp index dd8c3eb10dc993a95233321dbbe0bcfa8bb9fac5..f4648d8599ed91363cdf5548de778b5d39b56725 100644 --- a/window_scene/session/host/src/ws_snapshot_helper.cpp +++ b/window_scene/session/host/src/ws_snapshot_helper.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include "screen_session_manager_client/include/screen_session_manager_client.h" #include "session/host/include/ws_snapshot_helper.h" namespace OHOS::Rosen { @@ -26,10 +25,15 @@ const std::unordered_map ROTATION_TO_DISPLAYORIENTA }; } +WSSnapshotHelper* WSSnapshotHelper::GetInstance() +{ + static WSSnapshotHelper instance; + return &instance; +} + uint32_t WSSnapshotHelper::GetScreenStatus() { - FoldStatus foldStatus = ScreenSessionManagerClient::GetInstance().GetFoldStatus(); - return GetScreenStatus(foldStatus); + return GetInstance()->windowStatus_.first; } // LCOV_EXCL_START @@ -53,5 +57,36 @@ DisplayOrientation WSSnapshotHelper::GetDisplayOrientation(int32_t rotation) } return DisplayOrientation::PORTRAIT; } + +void WSSnapshotHelper::SetWindowScreenStatus(uint32_t screenStatus) +{ + GetInstance()->windowStatus_.first = screenStatus; +} + +void WSSnapshotHelper::SetWindowScreenStatus(FoldStatus foldStatus) +{ + SetWindowScreenStatus(GetScreenStatus(foldStatus)); +} + +void WSSnapshotHelper::SetWindowOrientationStatus(uint32_t orientationStatus) +{ + GetInstance()->windowStatus_.second = orientationStatus; +} + +void WSSnapshotHelper::SetWindowOrientationStatus(Rotation rotation) +{ + GetInstance()->windowRotation_ = rotation; + SetWindowOrientationStatus(GetOrientation(rotation)); +} + +SnapshotStatus WSSnapshotHelper::GetWindowStatus() const +{ + return GetInstance()->windowStatus_; +} + +uint32_t WSSnapshotHelper::GetWindowRotation() const +{ + return static_cast(GetInstance()->windowRotation_); +} // LCOV_EXCL_STOP } // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/session/host/src/zidl/session_proxy.cpp b/window_scene/session/host/src/zidl/session_proxy.cpp index 15b4334421610637cc2cc983a5baf74da1d813e4..00d3dd6a181e89b2c68e2b09d954405d09350b0e 100644 --- a/window_scene/session/host/src/zidl/session_proxy.cpp +++ b/window_scene/session/host/src/zidl/session_proxy.cpp @@ -337,6 +337,12 @@ WSError SessionProxy::Connect(const sptr& sessionStage, const spt property->SetCompatibleModeProperty(reply.ReadParcelable()); property->SetUseControlState(reply.ReadBool()); property->SetAncoRealBundleName(reply.ReadString()); + sptr missionInfo = reply.ReadParcelable(); + if (missionInfo == nullptr) { + TLOGE(WmsLogTag::WMS_LIFE, "read missionInfo is nullptr."); + return WSError::WS_ERROR_IPC_FAILED; + } + property->SetMissionInfo(*missionInfo); } int32_t ret = reply.ReadInt32(); return static_cast(ret); @@ -561,12 +567,21 @@ WSError SessionProxy::PendingSessionActivation(sptr abilityS return static_cast(ret); } -WSError SessionProxy::BatchPendingSessionsActivation(const std::vector>& abilitySessionInfos) + +WSError SessionProxy::BatchPendingSessionsActivation( + const std::vector>& abilitySessionInfos, + const std::vector& configs) { if (abilitySessionInfos.empty()) { TLOGE(WmsLogTag::WMS_LIFE, "abilitySessionInfos is empty"); return WSError::WS_ERROR_INVALID_PARAM; } + + if (!configs.empty() && abilitySessionInfos.size() != configs.size()) { + TLOGE(WmsLogTag::WMS_LIFE, "abilitySessionInfos param is error"); + return WSError::WS_ERROR_INVALID_PARAM; + } + MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_ASYNC); @@ -584,6 +599,19 @@ WSError SessionProxy::BatchPendingSessionsActivation(const std::vector(configs.size()))) { + TLOGE(WmsLogTag::WMS_LIFE, "Write ability config list size failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + + for (const auto& config : configs) { + WSError writeRet = WriteOnePendingSessionActivationConfig(data, config); + if (writeRet != WSError::WS_OK) { + return writeRet; + } + } + sptr remote = Remote(); if (remote == nullptr) { TLOGE(WmsLogTag::WMS_LIFE, "remote is null"); @@ -597,6 +625,21 @@ WSError SessionProxy::BatchPendingSessionsActivation(const std::vector(reply.ReadInt32()); } + +WSError SessionProxy::WriteOnePendingSessionActivationConfig(MessageParcel& data, + const PendingSessionActivationConfig& configs) +{ + if (!data.WriteBool(configs.forceStart)) { + TLOGE(WmsLogTag::WMS_LIFE, "Write forceStart failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + if (!data.WriteBool(configs.forceNewWant)) { + TLOGE(WmsLogTag::WMS_LIFE, "Write forceNewWant failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + + return WSError::WS_OK; +} WSError SessionProxy::WriteOneSessionInfo(MessageParcel& data, const sptr& abilitySessionInfo) { @@ -899,6 +942,36 @@ WSError SessionProxy::OnDefaultDensityEnabled(bool isDefaultDensityEnabled) return static_cast(ret); } +WMError SessionProxy::OnUpdateColorMode(const std::string& colorMode, bool hasDarkRes) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "WriteInterfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteString(colorMode)) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write colorMode failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteBool(hasDarkRes)) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write hasDarkRes failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "remote is null"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (remote->SendRequest(static_cast(SessionInterfaceCode::TRANS_ID_UPDATE_COLOR_MODE), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "SendRequest failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + return WMError::WM_OK; +} + WSError SessionProxy::OnTitleAndDockHoverShowChange(bool isTitleHoverShown, bool isDockHoverShown) { MessageParcel data; diff --git a/window_scene/session/host/src/zidl/session_stub.cpp b/window_scene/session/host/src/zidl/session_stub.cpp index 226277bfdf41cc8f26f506d65e09fe7af35cedd4..455a2f243f86c998923a5978c858d7da4d92ba6c 100644 --- a/window_scene/session/host/src/zidl/session_stub.cpp +++ b/window_scene/session/host/src/zidl/session_stub.cpp @@ -225,6 +225,8 @@ int SessionStub::ProcessRemoteRequest(uint32_t code, MessageParcel& data, Messag return HandleLayoutFullScreenChange(data, reply); case static_cast(SessionInterfaceCode::TRANS_ID_DEFAULT_DENSITY_ENABLED): return HandleDefaultDensityEnabled(data, reply); + case static_cast(SessionInterfaceCode::TRANS_ID_UPDATE_COLOR_MODE): + return HandleUpdateColorMode(data, reply); case static_cast(SessionInterfaceCode::TRANS_ID_TITLE_AND_DOCK_HOVER_SHOW_CHANGE): return HandleTitleAndDockHoverShowChange(data, reply); case static_cast(SessionInterfaceCode::TRANS_ID_GET_FORCE_LANDSCAPE_CONFIG): @@ -503,6 +505,8 @@ int SessionStub::HandleConnect(MessageParcel& data, MessageParcel& reply) reply.WriteParcelable(property->GetCompatibleModeProperty()); reply.WriteBool(property->GetUseControlState()); reply.WriteString(property->GetAncoRealBundleName()); + MissionInfo missionInfo = property->GetMissionInfo(); + reply.WriteParcelable(&missionInfo); } reply.WriteUint32(static_cast(errCode)); return ERR_NONE; @@ -588,6 +592,22 @@ int SessionStub::HandleLayoutFullScreenChange(MessageParcel& data, MessageParcel return ERR_NONE; } +int SessionStub::HandleUpdateColorMode(MessageParcel& data, MessageParcel& reply) +{ + std::string colorMode; + if (!data.ReadString(colorMode)) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Read colorMode failed."); + return ERR_INVALID_DATA; + } + bool hasDarkRes = false; + if (!data.ReadBool(hasDarkRes)) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Read hasDarkRes failed."); + return ERR_INVALID_DATA; + } + OnUpdateColorMode(colorMode, hasDarkRes); + return ERR_NONE; +} + int SessionStub::HandleDefaultDensityEnabled(MessageParcel& data, MessageParcel& reply) { bool isDefaultDensityEnabled = false; @@ -842,7 +862,23 @@ int SessionStub::HandleBatchPendingSessionsActivation(MessageParcel& data, Messa } abilitySessionInfos.emplace_back(abilitySessionInfo); } - WSError errCode = BatchPendingSessionsActivation(abilitySessionInfos); + + size = 0; + if (!data.ReadInt32(size) || size < 0 || size > MAX_ABILITY_SESSION_INFOS) { + TLOGE(WmsLogTag::WMS_LIFE, "Read ability config size failed"); + return ERR_INVALID_DATA; + } + std::vector configs; + for (int32_t i = 0; i < size; i++) { + PendingSessionActivationConfig config; + int readRet = ReadOnePendingSessionActivationConfig(data, config); + if (readRet != ERR_NONE) { + return readRet; + } + configs.emplace_back(config); + } + + WSError errCode = BatchPendingSessionsActivation(abilitySessionInfos, configs); if (!reply.WriteUint32(static_cast(errCode))) { TLOGE(WmsLogTag::WMS_LIFE, "Write errCode failed"); } @@ -2269,4 +2305,17 @@ int SessionStub::HandleUpdateGlobalDisplayRectFromClient(MessageParcel& data, Me UpdateGlobalDisplayRectFromClient(globalDisplayRect, reason); return ERR_NONE; } + +int SessionStub::ReadOnePendingSessionActivationConfig(MessageParcel& data, PendingSessionActivationConfig& config) +{ + if (!data.ReadBool(config.forceStart)) { + TLOGE(WmsLogTag::WMS_LIFE, "Read forceStart failed."); + return ERR_INVALID_DATA; + } + if (!data.ReadBool(config.forceNewWant)) { + TLOGE(WmsLogTag::WMS_LIFE, "Read forceNewWant failed."); + return ERR_INVALID_DATA; + } + return ERR_NONE; +} } // namespace OHOS::Rosen diff --git a/window_scene/session/screen/include/screen_property.h b/window_scene/session/screen/include/screen_property.h index 5a452a5e0f9a2695798469d3c90eff9e083ee7a4..0f4ccde8a5bc0f5c2adccb7010afa983353ae7fa 100644 --- a/window_scene/session/screen/include/screen_property.h +++ b/window_scene/session/screen/include/screen_property.h @@ -207,7 +207,7 @@ public: RRect GetPhysicalTouchBounds(); - void SetPhysicalTouchBounds(); + void SetPhysicalTouchBounds(Rotation rotationOffset); int32_t GetInputOffsetX(); diff --git a/window_scene/session/screen/include/screen_session.h b/window_scene/session/screen/include/screen_session.h index 0f3bc7126d7b5fd768bd55c1b431382306035794..dbb4b80795a168b6d2f7019a3cf2eb04e71dda1a 100644 --- a/window_scene/session/screen/include/screen_session.h +++ b/window_scene/session/screen/include/screen_session.h @@ -156,10 +156,10 @@ public: void ReleaseDisplayNode(); Rotation CalcRotation(Orientation orientation, FoldDisplayMode foldDisplayMode) const; - DisplayOrientation CalcDisplayOrientation(Rotation rotation, FoldDisplayMode foldDisplayMode) const; - DisplayOrientation CalcDeviceOrientation(Rotation rotation, FoldDisplayMode foldDisplayMode) const; + DisplayOrientation CalcDisplayOrientation(Rotation rotation, FoldDisplayMode foldDisplayMode); + DisplayOrientation CalcDeviceOrientation(Rotation rotation, FoldDisplayMode foldDisplayMode); DisplayOrientation CalcDeviceOrientationWithBounds(Rotation rotation, - FoldDisplayMode foldDisplayMode, const RRect& bounds) const; + FoldDisplayMode foldDisplayMode, const RRect& bounds); void FillScreenInfo(sptr info) const; void InitRSDisplayNode(RSDisplayNodeConfig& config, Point& startPoint, bool isExtend = false, float positionX = 0, float positionY = 0); @@ -196,7 +196,7 @@ public: bool IsTouchEnabled(); void SetIsPhysicalMirrorSwitch(bool isPhysicalMirrorSwitch); bool GetIsPhysicalMirrorSwitch(); - void UpdateTouchBoundsAndOffset(); + void UpdateTouchBoundsAndOffset(FoldDisplayMode foldDisplayMode); void UpdateToInputManager(RRect bounds, int rotation, int deviceRotation, FoldDisplayMode foldDisplayMode); void UpdatePropertyAfterRotation(RRect bounds, int rotation, FoldDisplayMode foldDisplayMode); void UpdatePropertyOnly(RRect bounds, int rotation, FoldDisplayMode foldDisplayMode); @@ -226,6 +226,9 @@ public: void SetVirtualScreenFlag(VirtualScreenFlag screenFlag); void SetSecurity(bool isSecurity); + VirtualScreenType GetVirtualScreenType(); + void SetVirtualScreenType(VirtualScreenType screenType); + std::string name_ { "UNKNOWN" }; ScreenId screenId_ {}; ScreenId rsId_ {}; @@ -355,6 +358,10 @@ public: bool GetIsAvailableAreaNeedNotify() const; uint64_t GetSessionId() const; + void SetRotationCorrectionMap(std::unordered_map& rotationCorrectionMap); + std::unordered_map GetRotationCorrectionMap(); + Rotation GetRotationCorrection(FoldDisplayMode foldDisplayMode); + /* * RS Client Multi Instance */ @@ -390,6 +397,7 @@ private: ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE }; mutable std::mutex combinationMutex_; // above guarded by clientProxyMutex_ VirtualScreenFlag screenFlag_ { VirtualScreenFlag::DEFAULT }; + VirtualScreenType screenType_ { VirtualScreenType::UNKNOWN }; bool hasPrivateWindowForeground_ = false; bool isFakeInUse_ = false; // is fakeScreenSession can be used bool isBScreenHalf_ = false; @@ -432,6 +440,10 @@ private: bool lastCloseHdrStatus_ = false; mutable std::shared_mutex modesMutex_; + void RemoveRotationCorrection(Rotation& rotation, FoldDisplayMode foldDisplayMode); + std::unordered_map rotationCorrectionMap_; + std::shared_mutex rotationCorrectionMutex_; + /* * RS Client Multi Instance */ diff --git a/window_scene/session/screen/src/screen_property.cpp b/window_scene/session/screen/src/screen_property.cpp index 5cea27fc41cb998031cf105e9a7ef7ffa806729d..8edb52dbf968b01d71a157874091064a614a8bf9 100644 --- a/window_scene/session/screen/src/screen_property.cpp +++ b/window_scene/session/screen/src/screen_property.cpp @@ -29,6 +29,7 @@ constexpr int32_t TRUNCATE_TWO_DECIMALS = 100; constexpr int32_t TRUNCATE_THREE_DECIMALS = 1000; constexpr float SECONDARY_ROTATION_90 = 90.0F; constexpr float SECONDARY_ROTATION_270 = 270.0F; +constexpr float SECONDARY_ROTATION_360 = 360.0F; constexpr int32_t SECONDARY_FULL_OFFSETY = 1136; constexpr int32_t FULL_STATUS_WIDTH = 2048; constexpr int32_t SCREEN_HEIGHT = 2232; @@ -617,14 +618,18 @@ RRect ScreenProperty::GetPhysicalTouchBounds() return physicalTouchBounds_; } -void ScreenProperty::SetPhysicalTouchBounds() +void ScreenProperty::SetPhysicalTouchBounds(Rotation rotationOffset) { if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { physicalTouchBounds_.rect_.width_ = bounds_.rect_.width_; physicalTouchBounds_.rect_.height_ = bounds_.rect_.height_; return; } - if (rotation_ == SECONDARY_ROTATION_90 || rotation_ == SECONDARY_ROTATION_270) { + float correctionValue = rotation_ - static_cast(rotationOffset) * SECONDARY_ROTATION_90 + + SECONDARY_ROTATION_360; + float correctionRotation = static_cast(static_cast(correctionValue) % 360); + if (std::fabs(correctionRotation - SECONDARY_ROTATION_90) < FLT_EPSILON || + std::fabs(correctionRotation - SECONDARY_ROTATION_270) < FLT_EPSILON) { physicalTouchBounds_.rect_.width_ = phyBounds_.rect_.width_; physicalTouchBounds_.rect_.height_ = phyBounds_.rect_.height_; } else { diff --git a/window_scene/session/screen/src/screen_session.cpp b/window_scene/session/screen/src/screen_session.cpp index fff58b5dbfc4bf51e238b026b157a5de0f780a2a..4f04d8d8da12723b4ef810ee5e5fa230fcc53bab 100644 --- a/window_scene/session/screen/src/screen_session.cpp +++ b/window_scene/session/screen/src/screen_session.cpp @@ -697,7 +697,7 @@ ScreenProperty ScreenSession::UpdatePropertyByFoldControl(const ScreenProperty& property_.SetScreenAreaOffsetY(updatedProperty.GetScreenAreaOffsetY()); property_.SetScreenAreaHeight(updatedProperty.GetScreenAreaHeight()); } - UpdateTouchBoundsAndOffset(); + UpdateTouchBoundsAndOffset(foldDisplayMode); return property_; } @@ -972,14 +972,24 @@ void ScreenSession::SetVirtualScreenFlag(VirtualScreenFlag screenFlag) screenFlag_ = screenFlag; } +VirtualScreenType ScreenSession::GetVirtualScreenType() +{ + return screenType_; +} + +void ScreenSession::SetVirtualScreenType(VirtualScreenType screenType) +{ + screenType_ = screenType; +} + void ScreenSession::SetSecurity(bool isSecurity) { isSecurity_ = isSecurity; } -void ScreenSession::UpdateTouchBoundsAndOffset() +void ScreenSession::UpdateTouchBoundsAndOffset(FoldDisplayMode foldDisplayMode) { - property_.SetPhysicalTouchBounds(); + property_.SetPhysicalTouchBounds(GetRotationCorrection(foldDisplayMode)); property_.SetInputOffsetY(); if (FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { property_.SetValidHeight(property_.GetBounds().rect_.GetHeight()); @@ -1001,7 +1011,7 @@ void ScreenSession::UpdateToInputManager(RRect bounds, int rotation, int deviceR property_.SetRotation(static_cast(rotation)); property_.UpdateScreenRotation(targetRotation); property_.SetDisplayOrientation(displayOrientation); - UpdateTouchBoundsAndOffset(); + UpdateTouchBoundsAndOffset(foldDisplayMode); Rotation targetDeviceRotation = ConvertIntToRotation(deviceRotation); auto deviceOrientation = CalcDeviceOrientationWithBounds(targetDeviceRotation, foldDisplayMode, bounds); property_.UpdateDeviceRotation(targetDeviceRotation); @@ -1039,7 +1049,7 @@ void ScreenSession::UpdatePropertyAfterRotation(RRect bounds, int rotation, Fold property_.SetValidHeight(bounds.rect_.GetHeight()); property_.SetValidWidth(bounds.rect_.GetWidth()); } - UpdateTouchBoundsAndOffset(); + UpdateTouchBoundsAndOffset(foldDisplayMode); { std::shared_lock displayNodeLock(displayNodeMutex_); if (!displayNode_) { @@ -1084,7 +1094,7 @@ void ScreenSession::UpdatePropertyOnly(RRect bounds, int rotation, FoldDisplayMo property_.SetValidHeight(bounds.rect_.GetHeight()); property_.SetValidWidth(bounds.rect_.GetWidth()); } - UpdateTouchBoundsAndOffset(); + UpdateTouchBoundsAndOffset(foldDisplayMode); TLOGI(WmsLogTag::DMS, "bounds:[%{public}f %{public}f %{public}f %{public}f],\ rotation:%{public}d, displayOrientation:%{public}u", property_.GetBounds().rect_.GetLeft(), property_.GetBounds().rect_.GetTop(), @@ -1341,8 +1351,9 @@ Rotation ScreenSession::CalcRotation(Orientation orientation, FoldDisplayMode fo } DisplayOrientation ScreenSession::CalcDisplayOrientation(Rotation rotation, - FoldDisplayMode foldDisplayMode) const + FoldDisplayMode foldDisplayMode) { + RemoveRotationCorrection(rotation, foldDisplayMode); // vertical: phone(Plugin screen); horizontal: pad & external screen bool isVerticalScreen = property_.GetPhyWidth() < property_.GetPhyHeight(); if (g_screenScanType == SCAN_TYPE_VERTICAL) { @@ -1382,8 +1393,9 @@ DisplayOrientation ScreenSession::CalcDisplayOrientation(Rotation rotation, } DisplayOrientation ScreenSession::CalcDeviceOrientation(Rotation rotation, - FoldDisplayMode foldDisplayMode) const + FoldDisplayMode foldDisplayMode) { + RemoveRotationCorrection(rotation, foldDisplayMode); if (foldDisplayMode == FoldDisplayMode::GLOBAL_FULL) { uint32_t temp = (static_cast(rotation) + SECONDARY_ROTATION_270) % SECONDARY_ROTATION_MOD; rotation = static_cast(temp); @@ -1414,8 +1426,9 @@ DisplayOrientation ScreenSession::CalcDeviceOrientation(Rotation rotation, } DisplayOrientation ScreenSession::CalcDeviceOrientationWithBounds(Rotation rotation, - FoldDisplayMode foldDisplayMode, const RRect& bounds) const + FoldDisplayMode foldDisplayMode, const RRect& bounds) { + RemoveRotationCorrection(rotation, foldDisplayMode); if (foldDisplayMode == FoldDisplayMode::GLOBAL_FULL) { uint32_t temp = (static_cast(rotation) + SECONDARY_ROTATION_270) % SECONDARY_ROTATION_MOD; rotation = static_cast(temp); @@ -2627,6 +2640,41 @@ std::shared_ptr ScreenSession::GetRSUIContext() const return rsUIContext; } +Rotation ScreenSession::GetRotationCorrection(FoldDisplayMode displayMode) +{ + auto rotationCorrectionMap = GetRotationCorrectionMap(); + int32_t rotationOffset = 0; + auto iter = rotationCorrectionMap.find(displayMode); + if (iter != rotationCorrectionMap.end()) { + rotationOffset = iter->second; + } + return static_cast(rotationOffset); +} + +void ScreenSession::RemoveRotationCorrection(Rotation& rotation, FoldDisplayMode displayMode) +{ + if (static_cast(rotation) >= SECONDARY_ROTATION_MOD) { + return; + } + uint32_t rotationOffset = static_cast(GetRotationCorrection(displayMode)); + uint32_t rotationValue = (static_cast(rotation) - rotationOffset + + SECONDARY_ROTATION_MOD) % SECONDARY_ROTATION_MOD; + rotation = static_cast(rotationValue); + TLOGI(WmsLogTag::DMS, "rotation:%{public}u, rotationOffset:%{public}u", rotation, rotationOffset); +} + +void ScreenSession::SetRotationCorrectionMap(std::unordered_map& rotationCorrectionMap) +{ + std::unique_lock lock(rotationCorrectionMutex_); + rotationCorrectionMap_ = rotationCorrectionMap; +} + +std::unordered_map ScreenSession::GetRotationCorrectionMap() +{ + std::shared_lock lock(rotationCorrectionMutex_); + return rotationCorrectionMap_; +} + void ScreenSession::SetIsEnableCanvasRotation(bool isEnableCanvasRotation) { std::lock_guard lock(isEnableCanvasRotationMutex_); diff --git a/window_scene/session_manager/include/rdb/starting_window_rdb_manager.h b/window_scene/session_manager/include/rdb/starting_window_rdb_manager.h index 40ac71245ccb6f8b5154e2525aeb1054468eb2a2..f76e68ba01f807ce85db47a1a237ca32778135f7 100644 --- a/window_scene/session_manager/include/rdb/starting_window_rdb_manager.h +++ b/window_scene/session_manager/include/rdb/starting_window_rdb_manager.h @@ -60,7 +60,6 @@ public: std::string GetStartWindowValFromProfile(const AppExecFwk::AbilityInfo& abilityInfo, const std::shared_ptr& resourceMgr, const std::string& key, const std::string& defaultVal); - void ClearRdbStore(); private: std::shared_ptr GetRdbStore(); diff --git a/window_scene/session_manager/include/scene_session_dirty_manager.h b/window_scene/session_manager/include/scene_session_dirty_manager.h index 7ff5f35fb6ccec11042cfdf845e107a9a72d3e5f..b5dd1fc975f86c366da092cbe842dffbaadbf740 100644 --- a/window_scene/session_manager/include/scene_session_dirty_manager.h +++ b/window_scene/session_manager/include/scene_session_dirty_manager.h @@ -80,6 +80,8 @@ private: SingleHandData GetSingleHandData(const sptr& sceneSession) const; void CalNotRotateTransform(const sptr& sceneSession, Matrix3f& transform, bool useUIExtension = false) const; + void CalSpecialNotRotateTransform(const sptr& sceneSession, ScreenProperty& screenProperty, + Matrix3f& transform, bool useUIExtension = false) const; void CalTransform(const sptr& sceneSession, Matrix3f& transform, const SingleHandData& singleHandData, bool useUIExtension = false) const; void UpdatePrivacyMode(const sptr& sceneSession, diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index e9ba28d36e9419f77a6d73291193d00a6c457dbc..1c09a1cdebe44fb6c5fbd3dcfd3362c4732bb7c2 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -40,6 +40,7 @@ #include "include/core/SkRegion.h" #include "interfaces/include/ws_common.h" #include "mission_snapshot.h" +#include "res_common.h" #include "scb_session_handler.h" #include "scene_session_converter.h" #include "screen_fold_data.h" @@ -72,6 +73,7 @@ class LauncherService; namespace OHOS::Global::Resource { class ResourceManager; +enum ColorMode; } // namespace OHOS::Global::Resource namespace OHOS::Rosen { @@ -167,6 +169,9 @@ using KioskModeChangeFunc = std::function& property)>; using NotifyRecoverStateChangeFunc = std::function; +using FindScenePanelRsNodeByZOrderFunc = std::function(DisplayId screenId, + uint32_t targetZOrder)>; +using ConvertSystemConfigFunc = std::function; class AppAnrListener : public IRemoteStub { public: @@ -235,7 +240,9 @@ public: void SetSCBFocusChangeListener(const NotifyDiffSCBAfterUpdateFocusFunc&& func); void SetCallingSessionIdSessionListenser(const ProcessCallingSessionIdChangeFunc& func); void SetDumpUITreeFunc(const DumpUITreeFunc& func); + void SetFindScenePanelRsNodeByZOrderFunc(FindScenePanelRsNodeByZOrderFunc&& func); const AppWindowSceneConfig& GetWindowSceneConfig() const; + void ApplyFeatureConfig(const std::unordered_map& configMap); /* * Window Recover @@ -690,6 +697,8 @@ public: const std::string& bundleName, int32_t appIndex, std::vector>& mainSessions); WSError NotifyAppUseControlList( ControlAppType type, int32_t userId, const std::vector& controlList); + void NotifyAppUseControlListInner( + ControlAppType type, int32_t userId, const std::vector& controlList); void RegisterNotifyAppUseControlListCallback(NotifyAppUseControlListFunc&& func); WMError MinimizeMainSession(const std::string& bundleName, int32_t appIndex, int32_t userId); sptr RequestSceneSession(const SessionInfo& sessionInfo, @@ -699,7 +708,7 @@ public: int32_t requestId = DEFAULT_REQUEST_FROM_SCB_ID); WSError RequestSceneSessionBackground(const sptr& sceneSession, const bool isDelegator = false, const bool isToDesktop = false, const bool isSaveSnapshot = true, - ScreenLockReason reason = ScreenLockReason::DEFAULT); + BackgroundReason reason = BackgroundReason::DEFAULT); WSError RequestSceneSessionDestruction(const sptr& sceneSession, bool needRemoveSession = true, bool isSaveSnapshot = true, const bool isForceClean = false, bool isUserRequestedExit = false); WSError RequestSceneSessionDestructionInner(sptr& sceneSession, @@ -786,6 +795,11 @@ public: WMError SetStartWindowBackgroundColor(const std::string& moduleName, const std::string& abilityName, uint32_t color, int32_t uid) override; void ConfigSupportSnapshotAllSessionStatus(); + void InsertProcessMap(const SessionInfo& sessionInfo, const int32_t persistentId); + WSError DeleteProcessMap(const SessionInfo& sessionInfo, const int32_t persistentId); + WSError FindProcessMap(const SessionInfo& sessionInfo, int32_t& persistentId); + int32_t FindCallerPersistentId(int32_t persistentId); + void ConfigSupportPreloadStartingWindow(); /* * Window Animation @@ -804,6 +818,7 @@ protected: private: std::atomic enterRecent_ { false }; bool isKeyboardPanelEnabled_ = false; + std::unordered_map convertConfigMap_; static sptr CreateInstance(); static inline bool isNotCurrentScreen(sptr sceneSession, ScreenId screenId) { @@ -817,7 +832,8 @@ private: void LoadWindowParameter(); void ConfigWindowSceneXml(); void ConfigWindowSceneXml(const WindowSceneConfig::ConfigItem& config); - void ConfigWindowEffect(const WindowSceneConfig::ConfigItem& effectConfig); + void ConfigWindowEffect(const WindowSceneConfig::ConfigItem& effectConfig, + AppWindowSceneConfig& AppWindowSceneConfig); void ConfigWindowImmersive(const WindowSceneConfig::ConfigItem& immersiveConfig); void ConfigKeyboardAnimation(const WindowSceneConfig::ConfigItem& animationConfig); void ConfigDefaultKeyboardAnimation(KeyboardSceneAnimationConfig& animationIn, @@ -1011,7 +1027,8 @@ private: const sptr& sceneSession); sptr GetBundleManager(); - std::shared_ptr GetResourceManager(const AppExecFwk::AbilityInfo& abilityInfo); + std::shared_ptr GetResourceManager(const AppExecFwk::AbilityInfo& abilityInfo, + Global::Resource::ColorMode colorMode = Global::Resource::ColorMode::COLOR_MODE_NOT_SET); bool CheckIsRemote(const std::string& deviceId); bool GetLocalDeviceId(std::string& localDeviceId); @@ -1025,7 +1042,7 @@ private: WSError RequestSceneSessionActivationInner(sptr& sceneSession, bool isNewActive, int32_t requestId = DEFAULT_REQUEST_FROM_SCB_ID) REQUIRES(SCENE_GUARD); WSError SetBrightness(const sptr& sceneSession, float brightness); - void PostBrightnessTask(float brightness); + void PostBrightnessTask(const sptr& sceneSession, float brightness); WSError UpdateBrightness(int32_t persistentId); void SetDisplayBrightness(float brightness); float GetDisplayBrightness() const; @@ -1113,8 +1130,10 @@ private: * UIExtension */ void DestroyUIServiceExtensionSubWindow(const sptr& sceneSession); - WSError CheckSubSessionStartedByExtensionAndSetDisplayId(const sptr& token, - const sptr& property, const sptr& sessionStage); + WSError CheckSubSessionStartedByExtension(const sptr& token, + const sptr& property); + void SetExtensionSubSessionDisplayId(const sptr& property, + const sptr& sessionStage); void ReportSubWindowCreationFailure(const int32_t& pid, const std::string& abilityName, const std::string& parentBundleName, const std::string& hostBundleName); @@ -1207,7 +1226,7 @@ private: ProcessCloseTargetFloatWindowFunc closeTargetFloatWindowFunc_; SetForegroundWindowNumFunc setForegroundWindowNumFunc_; MinimizeByWindowIdFunc minimizeByWindowIdFunc_; - + FindScenePanelRsNodeByZOrderFunc findScenePanelRsNodeByZOrderFunc_; AppWindowSceneConfig appWindowSceneConfig_; /* @@ -1230,7 +1249,7 @@ private: SystemSessionConfig systemConfig_; float snapshotScale_ = 0.5; int32_t brightnessSessionId_ = INVALID_SESSION_ID; - float displayBrightness_ = UNDEFINED_BRIGHTNESS; + std::atomic displayBrightness_ = UNDEFINED_BRIGHTNESS; bool isScreenLocked_ { false }; bool isPrepareTerminateEnable_ { false }; @@ -1659,32 +1678,45 @@ private: /* * Window Pattern */ + std::mutex processMapMutex_; + std::unordered_map> processCompareMap_; + std::shared_mutex startingWindowFollowAppSetMutex_; + std::unordered_set startingWindowFollowAppSet_; std::unordered_set emptyStartupResource_; std::atomic delayRemoveSnapshot_ = false; void InitStartingWindowRdb(const std::string& rdbPath); - bool GetStartingWindowInfoFromCache(const SessionInfo& sessionInfo, StartingWindowInfo& startingWindowInfo); + bool GetStartingWindowInfoFromCache(const SessionInfo& sessionInfo, StartingWindowInfo& startingWindowInfo, + bool isDark); uint32_t UpdateCachedColorToAppSet(const std::string& bundleName, const std::string& moduleName, const std::string& abilityName, StartingWindowInfo& startingWindowInfo); - bool GetStartingWindowInfoFromRdb(const SessionInfo& sessionInfo, StartingWindowInfo& startingWindowInfo); + bool GetStartingWindowInfoFromRdb(const SessionInfo& sessionInfo, StartingWindowInfo& startingWindowInfo, + bool darkMode); + bool GetStartWindowColorFollowApp(const SessionInfo& sessionInfo); bool GetPathInfoFromResource(const std::shared_ptr resourceMgr, bool hapPathEmpty, uint32_t resourceId, std::string& path); - bool GetStartupPageFromResource(const AppExecFwk::AbilityInfo& abilityInfo, StartingWindowInfo& startingWindowInfo); + bool CheckStartWindowColorFollowApp(const AppExecFwk::AbilityInfo& abilityInfo, + const std::shared_ptr& resourceMgr); + bool GetStartupPageFromResource(const AppExecFwk::AbilityInfo& abilityInfo, StartingWindowInfo& startingWindowInfo, + bool appColorModeChanged = false, + Global::Resource::ColorMode colorMode = Global::Resource::ColorMode::COLOR_MODE_NOT_SET); void GetBundleStartingWindowInfos(bool isDark, const AppExecFwk::BundleInfo& bundleInfo, std::vector>& outValues); void CacheStartingWindowInfo(const std::string& bundleName, const std::string& moduleName, - const std::string& abilityName, const StartingWindowInfo& startingWindowInfo); + const std::string& abilityName, const StartingWindowInfo& startingWindowInfo, bool isDark); void PreLoadStartingWindow(sptr sceneSession); bool CheckAndGetPreLoadResourceId(const StartingWindowInfo& startingWindowInfo, uint32_t& resId); std::unique_ptr startingWindowRdbMgr_; std::unique_ptr snapshotLruCache_; std::size_t snapshotCapacity_ = 0; bool GetIconFromDesk(const SessionInfo& sessionInfo, std::string& startupPagePath) const; - bool GetIsDarkFromConfiguration(); + bool GetIsDarkFromConfiguration(const std::string& appColorMode); bool needCloseSync_ = false; std::function closeSyncFunc_ = nullptr; WMError SetImageForRecent(uint32_t imgResourceId, ImageFit imageFit, int32_t persistentId) override; void UpdateAllStartingWindowRdb(); bool needUpdateRdb_ = true; + std::string GetSessionColorMode(const SessionInfo& sessionInfo, StartingWindowInfo& startingWindowInfo); + int32_t GetOriginalPersistentId(const std::set& sessionSet, int32_t persistentId); }; } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/include/session_manager_agent_controller.h b/window_scene/session_manager/include/session_manager_agent_controller.h index f8e983690f06faa2e58d4d46779682ff6c35d09b..b409fa8db300bc5f1af2946b5fbb732c47298cba 100644 --- a/window_scene/session_manager/include/session_manager_agent_controller.h +++ b/window_scene/session_manager/include/session_manager_agent_controller.h @@ -68,7 +68,7 @@ private: std::map>> windowManagerPidAgentMap_; std::map, std::pair> windowManagerAgentPairMap_; std::mutex windowManagerAgentPidMapMutex_; - WindowManagementMode windowManagementMode_; + WindowManagementMode windowManagementMode_ { WindowManagementMode::UNDEFINED }; }; } } diff --git a/window_scene/session_manager/src/hidump_controller.cpp b/window_scene/session_manager/src/hidump_controller.cpp index 8affbadebafa8c5343c0525f5bda3c90b12f4644..7061c76ea7a64b48db0afb278ea959db19c79f3e 100644 --- a/window_scene/session_manager/src/hidump_controller.cpp +++ b/window_scene/session_manager/src/hidump_controller.cpp @@ -317,6 +317,8 @@ void HidumpController::DumpKeyboardParam( << std::endl << session->GetSCBKeepKeyboardFlag() << "|" << session->IsSystemInput() << "|" + << 0 << "|" + << 0 << "|" << property->GetKeepKeyboardFlag() << "|" << std::setprecision(precision) << property->GetTextFieldPositionY() << "|" << std::setprecision(precision) << property->GetTextFieldHeight() << "|" diff --git a/window_scene/session_manager/src/rdb/starting_window_rdb_manager.cpp b/window_scene/session_manager/src/rdb/starting_window_rdb_manager.cpp index af54c29ad97e726e936358f3530350a0976b989b..bfe5b5cee487fb4c15cc86f07541422b905794dd 100644 --- a/window_scene/session_manager/src/rdb/starting_window_rdb_manager.cpp +++ b/window_scene/session_manager/src/rdb/starting_window_rdb_manager.cpp @@ -116,12 +116,6 @@ StartingWindowRdbManager::StartingWindowRdbManager(const WmsRdbConfig& wmsRdbCon StartingWindowRdbManager::~StartingWindowRdbManager() { - ClearRdbStore(); -} - -void StartingWindowRdbManager::ClearRdbStore() -{ - std::lock_guard lock(rdbMutex_); rdbStore_ = nullptr; } diff --git a/window_scene/session_manager/src/scene_input_manager.cpp b/window_scene/session_manager/src/scene_input_manager.cpp index 6f08827f33ba378f3056dcba94c00e87ca25453d..69ae5e1529ee36d2b6a2cef3acb5ee69346efb07 100644 --- a/window_scene/session_manager/src/scene_input_manager.cpp +++ b/window_scene/session_manager/src/scene_input_manager.cpp @@ -58,6 +58,9 @@ bool operator==(const MMI::ScreenInfo& a, const MMI::ScreenInfo& b) a.dpi != b.dpi || a.ppi != b.ppi) { return false; } + if (a.rotation != b.rotation) { + return false; + } return true; } @@ -74,6 +77,13 @@ bool operator==(const MMI::DisplayInfo& a, const MMI::DisplayInfo& b) a.screenArea.area != b.screenArea.area || a.rsId != b.rsId) { return false; } + if (a.offsetX != b.offsetX || a.offsetY != b.offsetY || a.pointerActiveWidth != b.pointerActiveWidth || + a.pointerActiveHeight != b.pointerActiveHeight) { + return false; + } + if (a.deviceRotation != b.deviceRotation || a.rotationCorrection != b.rotationCorrection) { + return false; + } return true; } @@ -282,6 +292,8 @@ void SceneInputManager::ConstructDisplayGroupInfos(std::map(screenProperty.GetDeviceRotation()); + int32_t rotationCorrection = static_cast(screenSession->GetRotationCorrection(displayMode)); MMI::DisplayInfo displayInfo = { .id = screenId, .x = screenProperty.GetX(), @@ -309,7 +321,9 @@ void SceneInputManager::ConstructDisplayGroupInfos(std::mapGetDisplayGroupId(); if (displayGroupMap.count(displayGroupId) == 0) { 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 5326d29771ddfa3355329f546d1baa72adabbbec..3876d3c23e0d3987ab76b5d52d9dd20e79b2f2b6 100644 --- a/window_scene/session_manager/src/scene_session_dirty_manager.cpp +++ b/window_scene/session_manager/src/scene_session_dirty_manager.cpp @@ -15,6 +15,7 @@ #include "scene_session_dirty_manager.h" +#include #include #include "screen_session_manager_client/include/screen_session_manager_client.h" #include "session_manager/include/scene_session_manager.h" @@ -23,10 +24,11 @@ namespace OHOS::Rosen { namespace { -constexpr float DIRECTION0 = 0 ; -constexpr float DIRECTION90 = 90 ; -constexpr float DIRECTION180 = 180 ; -constexpr float DIRECTION270 = 270 ; +constexpr float DIRECTION0 = 0; +constexpr float DIRECTION90 = 90; +constexpr float DIRECTION180 = 180; +constexpr float DIRECTION270 = 270; +constexpr float DIRECTION360 = 360; constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSessionDirtyManager"}; constexpr unsigned int POINTER_CHANGE_AREA_COUNT = 8; constexpr int POINTER_CHANGE_AREA_SIXTEEN = 16; @@ -39,8 +41,10 @@ static int32_t g_screenRotationOffset = system::GetIntParameter("const. constexpr float ZORDER_UIEXTENSION_INDEX = 0.1; constexpr int WINDOW_NAME_TYPE_UNKNOWN = 0; constexpr int WINDOW_NAME_TYPE_THUMBNAIL = 1; +constexpr int WINDOW_NAME_TYPE_VOICEINPUT = 2; const std::string SCREENSHOT_WINDOW_NAME_PREFIX = "ScreenShotWindow"; const std::string PREVIEW_WINDOW_NAME_PREFIX = "PreviewWindow"; +const std::string VOICEINPUT_WINDOW_NAME_PREFIX = "__VoiceHardwareInput"; } // namespace static bool operator==(const MMI::Rect left, const MMI::Rect right) @@ -175,6 +179,33 @@ void SceneSessionDirtyManager::CalNotRotateTransform(const sptr& s .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse(); } +inline float PositiveFmod(float x, float y) +{ + float result = std::fmod(x, y); + return result < 0 ? (result + y) : result; +} + +void SceneSessionDirtyManager::CalSpecialNotRotateTransform(const sptr& sceneSession, + ScreenProperty& screenProperty, Matrix3f& transform, bool useUIExtension) const +{ + if (sceneSession == nullptr) { + TLOGE(WmsLogTag::WMS_EVENT, "sceneSession is nullptr"); + return; + } + + MMI::Direction displayRotation = + ConvertDegreeToMMIRotation(PositiveFmod(screenProperty.GetPhysicalRotation() - + screenProperty.GetScreenComponentRotation() - sceneSession->GetCurrentRotation(), DIRECTION360)); + float width = screenProperty.GetBounds().rect_.GetWidth(); + float height = screenProperty.GetBounds().rect_.GetHeight(); + Vector2f scale(sceneSession->GetScaleX(), sceneSession->GetScaleY()); + Vector2f offset = sceneSession->GetSessionGlobalPosition(useUIExtension); + float rotate = 0.0f; + Vector2f translate = CalRotationToTranslate(displayRotation, width, height, offset, rotate); + transform = transform.Translate(translate).Rotate(rotate) + .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse(); +} + void SceneSessionDirtyManager::CalTransform(const sptr& sceneSession, Matrix3f& transform, const SingleHandData& singleHandData, bool useUIExtension) const { @@ -189,12 +220,41 @@ void SceneSessionDirtyManager::CalTransform(const sptr& sceneSessi transform = transform.Scale({singleHandData.scaleX, singleHandData.scaleY}, singleHandData.pivotX, singleHandData.pivotY); } - if (isRotate || !sceneSession->GetSessionInfo().isSystem_ || - static_cast(displayMode) == MMI::DisplayMode::FULL || - displayMode == FoldDisplayMode::GLOBAL_FULL || - (static_cast(displayMode) == MMI::DisplayMode::MAIN && - (FoldScreenStateInternel::IsSingleDisplayPocketFoldDevice() || - FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()))) { + + auto sessionProperty = sceneSession->GetSessionProperty(); + if (sessionProperty == nullptr) { + TLOGE(WmsLogTag::WMS_EVENT, "sessionProperty is nullptr"); + return; + } + auto displayId = sessionProperty->GetDisplayId(); + std::map screensProperties = + Rosen::ScreenSessionManagerClient::GetInstance().GetAllScreensProperties(); + if (screensProperties.find(displayId) == screensProperties.end()) { + TLOGE(WmsLogTag::WMS_EVENT, "screensProperties find displayId failed"); + return; + } + auto screenProperty = screensProperties[displayId]; + bool isRotateWindow = screenProperty.GetPhysicalRotation() - screenProperty.GetScreenComponentRotation() != + sceneSession->GetCurrentRotation(); + bool isSystem = sceneSession->GetSessionInfo().isSystem_; + bool displayModeIsFull = static_cast(displayMode) == MMI::DisplayMode::FULL; + bool displayModeIsGlobalFull = displayMode == FoldDisplayMode::GLOBAL_FULL; + bool displayModeIsMain = static_cast(displayMode) == MMI::DisplayMode::MAIN; + bool foldScreenStateInternel = FoldScreenStateInternel::IsSingleDisplayPocketFoldDevice() || + FoldScreenStateInternel::IsSecondaryDisplayFoldDevice(); + TLOGD(WmsLogTag::WMS_EVENT, "wid:%{public}d, isRotate:%{public}d, isSystem:%{public}d," + " displayModeIsFull:%{public}d, displayModeIsGlobalFull:%{public}d, displayModeIsMain:%{public}d," + " foldScreenStateInternel:%{public}d, isRotateWindow:%{public}d", + sceneSession->GetWindowId(), isRotate, isSystem, displayModeIsFull, displayModeIsGlobalFull, + displayModeIsMain, foldScreenStateInternel, isRotateWindow); + + if (isRotate || !isSystem || displayModeIsFull || displayModeIsGlobalFull || + (displayModeIsMain && foldScreenStateInternel)) { + if (isRotateWindow && isSystem && ((displayModeIsMain && foldScreenStateInternel) || + (displayModeIsFull && FoldScreenStateInternel::IsSingleDisplayPocketFoldDevice()))) { + CalSpecialNotRotateTransform(sceneSession, screenProperty, transform, useUIExtension); + return; + } Vector2f scale(sceneSession->GetScaleX(), sceneSession->GetScaleY()); Vector2f translate = sceneSession->GetSessionGlobalPosition(useUIExtension); if (useUIExtension && UpdateModalExtensionInCompatStatus(sceneSession, transform)) { @@ -801,6 +861,8 @@ std::pair> SceneSessionDirtyMa }; if (startsWith(windowName, SCREENSHOT_WINDOW_NAME_PREFIX) || startsWith(windowName, PREVIEW_WINDOW_NAME_PREFIX)) { windowNameType = WINDOW_NAME_TYPE_THUMBNAIL; + } else if (startsWith(windowName, VOICEINPUT_WINDOW_NAME_PREFIX)) { + windowNameType = WINDOW_NAME_TYPE_VOICEINPUT; } auto pixelMap = windowSessionProperty->GetWindowMask(); MMI::WindowInfo windowInfo = { diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index c48cdaca156217c5a71665a2f612af80e2a60e32..dcfb44388f701d5dd3dc59b28db79af34b06f0f3 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -71,6 +71,7 @@ #include "session/host/include/session_change_recorder.h" #include "session/host/include/session_utils.h" #include "session/host/include/sub_session.h" +#include "session/host/include/ws_snapshot_helper.h" #include "session_helper.h" #include "session_manager_agent_controller.h" #include "singleton_container.h" @@ -114,6 +115,7 @@ const std::string DM_PKG_NAME = "ohos.distributedhardware.devicemanager"; constexpr int32_t NON_ANONYMIZE_LENGTH = 6; const std::string EMPTY_DEVICE_ID = ""; const std::string STARTWINDOW_TYPE = "startWindowType"; +const std::string STARTWINDOW_COLOR_MODE_TYPE = "startWindowColorModeType"; const int32_t MAX_NUMBER_OF_DISTRIBUTED_SESSIONS = 20; constexpr int WINDOW_NAME_MAX_WIDTH = 21; @@ -273,6 +275,7 @@ bool IsUIExtCanShowOnLockScreen(const AppExecFwk::ElementName& element, uint32_t std::make_tuple("com.ohos.sceneboard", "ThemeChargingAbility", "engineservice"), std::make_tuple("com.ohos.commondialog", "FoldStatusAbility", "phone_commondialog"), std::make_tuple("com.ohos.commondialog", "SecondaryReflexionAbility", "phone_commondialog"), + std::make_tuple("com.huawei.hmos.clock", "ScreenLockCoverExtensionAbility", "entry"), }; if (extensionAbilityTypeWhitelist.find(extensionAbilityType) != extensionAbilityTypeWhitelist.end()) { @@ -672,7 +675,7 @@ void SceneSessionManager::ConfigWindowSceneXml() const auto& config = WindowSceneConfig::GetConfig(); WindowSceneConfig::ConfigItem item = config["windowEffect"]; if (item.IsMap()) { - ConfigWindowEffect(item); + ConfigWindowEffect(item, appWindowSceneConfig_); } item = config["decor"]; @@ -827,6 +830,10 @@ void SceneSessionManager::ConfigFreeMultiWindow() systemConfig_.freeMultiWindowConfig_.defaultDragResizeType_ = static_cast(static_cast(param)); } + item = freeMultiWindowConfig["windowEffect"]; + if (item.IsMap()) { + ConfigWindowEffect(item, systemConfig_.freeMultiWindowConfig_.appWindowSceneConfig_); + } } } @@ -837,6 +844,10 @@ void SceneSessionManager::LoadFreeMultiWindowConfig(bool enable) systemConfig_.defaultWindowMode_ = freeMultiWindowConfig.defaultWindowMode_; systemConfig_.decorWindowModeSupportType_ = freeMultiWindowConfig.decorWindowModeSupportType_; systemConfig_.isSystemDecorEnable_ = freeMultiWindowConfig.isSystemDecorEnable_; + appWindowSceneConfig_.focusedShadow_ = freeMultiWindowConfig.appWindowSceneConfig_.focusedShadow_; + appWindowSceneConfig_.unfocusedShadow_ = freeMultiWindowConfig.appWindowSceneConfig_.unfocusedShadow_; + appWindowSceneConfig_.focusedShadowDark_ = freeMultiWindowConfig.appWindowSceneConfig_.focusedShadowDark_; + appWindowSceneConfig_.unfocusedShadowDark_ = freeMultiWindowConfig.appWindowSceneConfig_.unfocusedShadowDark_; } else { const auto& config = WindowSceneConfig::GetConfig(); auto item = config["decor"]; @@ -850,6 +861,10 @@ void SceneSessionManager::LoadFreeMultiWindowConfig(bool enable) param == static_cast(WindowMode::WINDOW_MODE_FLOATING))) { systemConfig_.defaultWindowMode_ = static_cast(static_cast(param)); } + item = config["windowEffect"]; + if (item.IsMap()) { + ConfigWindowEffect(item, appWindowSceneConfig_); + } } systemConfig_.freeMultiWindowEnable_ = enable; rsInterface_.SetFreeMultiWindowStatus(enable); @@ -997,15 +1012,16 @@ static inline bool IsAtomicServiceFreeInstall(const SessionInfo& sessionInfo) (sessionInfo.want->GetFlags() & AAFwk::Want::FLAG_INSTALL_ON_DEMAND) == AAFwk::Want::FLAG_INSTALL_ON_DEMAND; } -void SceneSessionManager::ConfigWindowEffect(const WindowSceneConfig::ConfigItem& effectConfig) +void SceneSessionManager::ConfigWindowEffect(const WindowSceneConfig::ConfigItem& effectConfig, + AppWindowSceneConfig& appWindowSceneConfig) { AppWindowSceneConfig config; // config corner radius WindowSceneConfig::ConfigItem item = effectConfig["appWindows"]["cornerRadius"]; if (item.IsMap()) { if (ConfigAppWindowCornerRadius(item["float"], config.floatCornerRadius_)) { - appWindowSceneConfig_ = config; // set default corner radius of window by system config + appWindowSceneConfig.floatCornerRadius_ = config.floatCornerRadius_; systemConfig_.defaultCornerRadius_ = config.floatCornerRadius_; } } @@ -1014,34 +1030,34 @@ void SceneSessionManager::ConfigWindowEffect(const WindowSceneConfig::ConfigItem item = effectConfig["appWindows"]["shadow"]["focused"]; if (item.IsMap()) { if (ConfigAppWindowShadow(item, config.focusedShadow_)) { - appWindowSceneConfig_.focusedShadow_ = config.focusedShadow_; + appWindowSceneConfig.focusedShadow_ = config.focusedShadow_; } } item = effectConfig["appWindows"]["shadow"]["unfocused"]; if (item.IsMap()) { if (ConfigAppWindowShadow(item, config.unfocusedShadow_)) { - appWindowSceneConfig_.unfocusedShadow_ = config.unfocusedShadow_; + appWindowSceneConfig.unfocusedShadow_ = config.unfocusedShadow_; } } - AddAlphaToColor(appWindowSceneConfig_.focusedShadow_.alpha_, appWindowSceneConfig_.focusedShadow_.color_); - AddAlphaToColor(appWindowSceneConfig_.unfocusedShadow_.alpha_, appWindowSceneConfig_.unfocusedShadow_.color_); + AddAlphaToColor(appWindowSceneConfig.focusedShadow_.alpha_, appWindowSceneConfig.focusedShadow_.color_); + AddAlphaToColor(appWindowSceneConfig.unfocusedShadow_.alpha_, appWindowSceneConfig.unfocusedShadow_.color_); // config shadow in dark mode item = effectConfig["appWindows"]["shadowDark"]["focused"]; if (item.IsMap()) { if (ConfigAppWindowShadow(item, config.focusedShadowDark_)) { - appWindowSceneConfig_.focusedShadowDark_ = config.focusedShadowDark_; + appWindowSceneConfig.focusedShadowDark_ = config.focusedShadowDark_; } } item = effectConfig["appWindows"]["shadowDark"]["unfocused"]; if (item.IsMap()) { if (ConfigAppWindowShadow(item, config.unfocusedShadowDark_)) { - appWindowSceneConfig_.unfocusedShadowDark_ = config.unfocusedShadowDark_; + appWindowSceneConfig.unfocusedShadowDark_ = config.unfocusedShadowDark_; } } - AddAlphaToColor(appWindowSceneConfig_.focusedShadowDark_.alpha_, appWindowSceneConfig_.focusedShadowDark_.color_); - AddAlphaToColor(appWindowSceneConfig_.unfocusedShadowDark_.alpha_, - appWindowSceneConfig_.unfocusedShadowDark_.color_); + AddAlphaToColor(appWindowSceneConfig.focusedShadowDark_.alpha_, appWindowSceneConfig.focusedShadowDark_.color_); + AddAlphaToColor(appWindowSceneConfig.unfocusedShadowDark_.alpha_, + appWindowSceneConfig.unfocusedShadowDark_.color_); TLOGI(WmsLogTag::WMS_ATTRIBUTE, "successfully"); } @@ -2426,6 +2442,9 @@ sptr SceneSessionManager::CreateSceneSession(const SessionInfo& se sceneSession->RegisterGetFbPanelWindowIdFunc([this](uint32_t& windowId) { return this->GetFbPanelWindowId(windowId); }); + sceneSession->SetFindScenePanelRsNodeByZOrderFunc([this](uint64_t screenId, uint32_t targetZOrder) { + return this->findScenePanelRsNodeByZOrderFunc_(screenId, targetZOrder); + }); DragResizeType dragResizeType = DragResizeType::RESIZE_TYPE_UNDEFINED; GetAppDragResizeType(sessionInfo.bundleName_, dragResizeType); sceneSession->SetAppDragResizeType(dragResizeType); @@ -2784,6 +2803,7 @@ void SceneSessionManager::InitSceneSession(sptr& sceneSession, con if (sessionLockedStateCacheSet_.find(key) != sessionLockedStateCacheSet_.end()) { sceneSession->NotifySessionLockStateChange(true); } + InsertProcessMap(sessionInfo, sceneSession->GetPersistentId()); } void SceneSessionManager::InitFbWindow(const sptr& sceneSession, @@ -3302,6 +3322,15 @@ void SceneSessionManager::ConfigSupportSnapshotAllSessionStatus() taskScheduler_->PostAsyncTask(task, "ConfigSupportSnapshotAllSessionStatus"); } +void SceneSessionManager::ConfigSupportPreloadStartingWindow() +{ + TLOGI(WmsLogTag::WMS_PATTERN, "support"); + auto task = [this] { + systemConfig_.supportPreloadStartingWindow_ = true; + }; + taskScheduler_->PostAsyncTask(task, "ConfigSupportPreloadStartingWindow"); +} + WMError SceneSessionManager::CreateUIEffectController(const sptr& controllerClient, sptr& controller, int32_t& controllerId) { @@ -3317,7 +3346,7 @@ WMError SceneSessionManager::CreateUIEffectController(const sptr& sceneSession, - const bool isDelegator, const bool isToDesktop, const bool isSaveSnapshot, ScreenLockReason reason) + const bool isDelegator, const bool isToDesktop, const bool isSaveSnapshot, BackgroundReason reason) { auto task = [this, weakSceneSession = wptr(sceneSession), isDelegator, isToDesktop, isSaveSnapshot, reason] { auto sceneSession = weakSceneSession.promote(); @@ -3595,7 +3624,7 @@ WSError SceneSessionManager::RequestSceneSessionDestruction(const sptrClearRdbStore(); + DeleteProcessMap(sceneSession->GetSessionInfo(), persistentId); auto sceneSessionInfo = SetAbilitySessionInfo(sceneSession); sceneSession->GetCloseAbilityWantAndClean(sceneSessionInfo->want); ResetSceneSessionInfoWant(sceneSessionInfo); @@ -3731,6 +3760,10 @@ WSError SceneSessionManager::CreateAndConnectSpecificSession(const sptrSetSubWindowLevel(parentProperty->GetSubWindowLevel() + 1); + if (parentSession->GetSessionInfo().isSystem_ && property->GetIsUIExtFirstSubWindow() && + systemConfig_.supportUIExtensionSubWindow_) { + property->SetWindowType(WindowType::WINDOW_TYPE_SCB_SUB_WINDOW); + } } auto initClientDisplayId = UpdateSpecificSessionClientDisplayId(property); bool shouldBlock = false; @@ -3753,10 +3786,11 @@ WSError SceneSessionManager::CreateAndConnectSpecificSession(const sptrGetWindowType() == WindowType::WINDOW_TYPE_APP_SUB_WINDOW) { - WSError err = CheckSubSessionStartedByExtensionAndSetDisplayId(token, property, sessionStage); + WSError err = CheckSubSessionStartedByExtension(token, property); if (err != WSError::WS_OK) { return err; } + SetExtensionSubSessionDisplayId(property, sessionStage); } // WINDOW_TYPE_SYSTEM_ALARM_WINDOW has been deprecated, will be deleted after 5 versions. if (property->GetWindowType() == WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW) { @@ -3832,8 +3866,8 @@ WSError SceneSessionManager::CreateAndConnectSpecificSession(const sptrPostSyncTask(task, "CreateAndConnectSpecificSession"); } -WSError SceneSessionManager::CheckSubSessionStartedByExtensionAndSetDisplayId(const sptr& token, - const sptr& property, const sptr& sessionStage) +WSError SceneSessionManager::CheckSubSessionStartedByExtension(const sptr& token, + const sptr& property) { sptr extensionParentSession = GetSceneSession(property->GetParentPersistentId()); if (extensionParentSession == nullptr) { @@ -3843,10 +3877,9 @@ WSError SceneSessionManager::CheckSubSessionStartedByExtensionAndSetDisplayId(co } auto pid = IPCSkeleton::GetCallingRealPid(); auto parentPid = extensionParentSession->GetCallingPid(); - WSError result = WSError::WS_ERROR_INVALID_WINDOW; if (pid == parentPid) { // Determine Whether to create a sub window in the same process. TLOGI(WmsLogTag::WMS_UIEXT, "pid == parentPid"); - result = WSError::WS_OK; + return WSError::WS_OK; } AAFwk::UIExtensionSessionInfo info; AAFwk::AbilityManagerClient::GetInstance()->GetUIExtensionSessionInfo(token, info); @@ -3855,41 +3888,36 @@ WSError SceneSessionManager::CheckSubSessionStartedByExtensionAndSetDisplayId(co // Check the parent ids are the same in cross-process scenarios. if (parentId == property->GetParentPersistentId()) { TLOGD(WmsLogTag::WMS_UIEXT, "parentId == property->GetParentPersistentId(parentId:%{public}d)", parentId); - result = WSError::WS_OK; + return WSError::WS_OK; } } if (SessionPermission::IsSystemCalling()) { // Fallback strategy. TLOGD(WmsLogTag::WMS_UIEXT, "is system app"); - result = WSError::WS_OK; - } - if (property->GetIsUIExtensionAbilityProcess() && SessionPermission::IsStartedByUIExtension()) { - AAFwk::UIExtensionHostInfo hostInfo; - AAFwk::AbilityManagerClient::GetInstance()->GetUIExtensionRootHostInfo(token, hostInfo); - const auto& sessionInfo = extensionParentSession->GetSessionInfo(); - auto hostBundleName = extensionParentSession->IsAnco()? - SessionUtils::GetBundleNameBySessionName(hostInfo.sessionName) : hostInfo.elementName_.GetBundleName(); - if (sessionInfo.bundleName_ != hostBundleName && - sessionInfo.bundleName_ != info.hostElementName.GetBundleName()) { - TLOGE(WmsLogTag::WMS_UIEXT, "The hostWindow is not this parentwindow ! parentwindow bundleName: %{public}s," - " hostwindow bundleName: %{public}s", sessionInfo.bundleName_.c_str(), hostBundleName.c_str()); - ReportSubWindowCreationFailure(pid, info.elementName.GetAbilityName(), sessionInfo.bundleName_, - hostBundleName); - return WSError::WS_ERROR_INVALID_WINDOW; - } - result = WSError::WS_OK; + return WSError::WS_OK; } - if (result == WSError::WS_OK) { - sptr parentProperty = extensionParentSession->GetSessionProperty(); - if (sessionStage && property->GetIsUIExtFirstSubWindow()) { - sessionStage->UpdateDisplayId(extensionParentSession->GetClientDisplayId() == VIRTUAL_DISPLAY_ID - ? VIRTUAL_DISPLAY_ID - : parentProperty->GetDisplayId()); - property->SetDisplayId(parentProperty->GetDisplayId()); - } - } else { - TLOGE(WmsLogTag::WMS_UIEXT, "can't create sub window: persistentId %{public}d", property->GetPersistentId()); + + TLOGE(WmsLogTag::WMS_UIEXT, + "can't create sub window: persistentId:%{public}d, parentPersistentId:%{public}d, hostWindowId:%{public}d", + property->GetPersistentId(), property->GetParentPersistentId(), info.hostWindowId); + return WSError::WS_ERROR_INVALID_WINDOW; +} + +void SceneSessionManager::SetExtensionSubSessionDisplayId(const sptr& property, + const sptr& sessionStage) +{ + sptr extensionParentSession = GetSceneSession(property->GetParentPersistentId()); + if (extensionParentSession == nullptr) { + TLOGE(WmsLogTag::WMS_UIEXT, "extensionParentSession is invalid with %{public}d", + property->GetParentPersistentId()); + return; + } + sptr parentProperty = extensionParentSession->GetSessionProperty(); + if (sessionStage && property->GetIsUIExtFirstSubWindow()) { + sessionStage->UpdateDisplayId(extensionParentSession->GetClientDisplayId() == VIRTUAL_DISPLAY_ID + ? VIRTUAL_DISPLAY_ID + : parentProperty->GetDisplayId()); + property->SetDisplayId(parentProperty->GetDisplayId()); } - return result; } void SceneSessionManager::ReportSubWindowCreationFailure(const int32_t& pid, const std::string& abilityName, @@ -5135,7 +5163,7 @@ sptr SceneSessionManager::GetBundleManager() } std::shared_ptr SceneSessionManager::GetResourceManager( - const AppExecFwk::AbilityInfo& abilityInfo) + const AppExecFwk::AbilityInfo& abilityInfo, Global::Resource::ColorMode colorMode) { auto context = rootSceneContextWeak_.lock(); if (!context) { @@ -5153,6 +5181,10 @@ std::shared_ptr SceneSessionManager::GetResou return nullptr; } resourceMgr->GetResConfig(*resConfig); + if (colorMode != Global::Resource::ColorMode::COLOR_MODE_NOT_SET) { + resConfig->SetColorMode(colorMode); + TLOGI(WmsLogTag::WMS_PATTERN, "resConfig colorMode: %{public}d", colorMode); + } resourceMgr = Global::Resource::CreateResourceManager( abilityInfo.bundleName, abilityInfo.moduleName, "", {}, *resConfig); if (!resourceMgr) { @@ -5197,14 +5229,31 @@ bool SceneSessionManager::GetPathInfoFromResource(const std::shared_ptr& resourceMgr) +{ + const std::string followSystemMode = "FOLLOW_SYSTEM"; + const std::string followAPPMode = "FOLLOW_APPLICATION"; + std::string colorModeType = startingWindowRdbMgr_->GetStartWindowValFromProfile( + abilityInfo, resourceMgr, STARTWINDOW_COLOR_MODE_TYPE, followSystemMode); + if (colorModeType == followAPPMode) { + TLOGI(WmsLogTag::WMS_PATTERN, "follow app: %{public}s", abilityInfo.bundleName.c_str()); + std::string key = abilityInfo.bundleName + '_' + abilityInfo.moduleName + '_' + abilityInfo.name; + std::unique_lock lock(startingWindowFollowAppSetMutex_); + startingWindowFollowAppSet_.insert(key); + return true; + } + return false; +} + bool SceneSessionManager::GetStartupPageFromResource(const AppExecFwk::AbilityInfo& abilityInfo, - StartingWindowInfo& startingWindowInfo) + StartingWindowInfo& startingWindowInfo, bool appColorModeChanged, Global::Resource::ColorMode colorMode) { const std::map START_WINDOW_KEY_AND_DEFAULT_MAP = { {STARTWINDOW_TYPE, "REQUIRED_SHOW"}, }; - auto resourceMgr = GetResourceManager(abilityInfo); + auto resourceMgr = GetResourceManager(abilityInfo, Global::Resource::ColorMode::COLOR_MODE_NOT_SET); if (!resourceMgr) { TLOGE(WmsLogTag::WMS_PATTERN, "resourceMgr is nullptr."); return false; @@ -5213,6 +5262,13 @@ bool SceneSessionManager::GetStartupPageFromResource(const AppExecFwk::AbilityIn if (hapPathEmpty) { TLOGD(WmsLogTag::WMS_PATTERN, "hapPath empty:%{public}s", abilityInfo.bundleName.c_str()); } + if (CheckStartWindowColorFollowApp(abilityInfo, resourceMgr) && appColorModeChanged) { + resourceMgr = GetResourceManager(abilityInfo, colorMode); + if (!resourceMgr) { + TLOGE(WmsLogTag::WMS_PATTERN, "resourceMgr is nullptr."); + return false; + } + } const auto startWindowType = START_WINDOW_KEY_AND_DEFAULT_MAP.find(STARTWINDOW_TYPE); if (startWindowType != START_WINDOW_KEY_AND_DEFAULT_MAP.end()) { @@ -5253,8 +5309,14 @@ bool SceneSessionManager::GetStartupPageFromResource(const AppExecFwk::AbilityIn return true; } -bool SceneSessionManager::GetIsDarkFromConfiguration() +bool SceneSessionManager::GetIsDarkFromConfiguration(const std::string& appColorMode) { + if (appColorMode == AppExecFwk::ConfigurationInner::COLOR_MODE_DARK) { + return true; + } + if (appColorMode == AppExecFwk::ConfigurationInner::COLOR_MODE_LIGHT) { + return false; + } std::shared_ptr appContext = AbilityRuntime::Context::GetApplicationContext(); if (appContext == nullptr) { TLOGE(WmsLogTag::WMS_PATTERN, "app context is nullptr"); @@ -5275,6 +5337,10 @@ void SceneSessionManager::GetBundleStartingWindowInfos(bool isDark, const AppExe { for (const auto& moduleInfo : bundleInfo.hapModuleInfos) { for (const auto& abilityInfo : moduleInfo.abilityInfos) { + if (abilityInfo.startWindowId == 0 && abilityInfo.startWindowBackgroundId == 0) { + TLOGD(WmsLogTag::WMS_PATTERN, "not ability:%{public}s", abilityInfo.bundleName.c_str()); + continue; + } StartingWindowRdbItemKey itemKey = { .bundleName = abilityInfo.bundleName, .moduleName = abilityInfo.moduleName, @@ -5346,7 +5412,7 @@ void SceneSessionManager::UpdateAllStartingWindowRdb() return; } std::vector> inputValues; - bool isDark = GetIsDarkFromConfiguration(); + bool isDark = GetIsDarkFromConfiguration(std::string(AppExecFwk::ConfigurationInner::COLOR_MODE_AUTO)); for (const auto& bundleInfo : bundleInfos) { GetBundleStartingWindowInfos(isDark, bundleInfo, inputValues); } @@ -5354,11 +5420,104 @@ void SceneSessionManager::UpdateAllStartingWindowRdb() auto batchInsertRes = startingWindowRdbMgr_->BatchInsert(outInsertNum, inputValues); TLOGNI(WmsLogTag::WMS_PATTERN, "res: %{public}d, bundles: %{public}zu, insert: %{public}" PRId64, batchInsertRes, bundleInfos.size(), outInsertNum); - startingWindowRdbMgr_->ClearRdbStore(); }; ffrtQueueHelper_->SubmitTask(loadTask); } +void SceneSessionManager::InsertProcessMap(const SessionInfo& sessionInfo, const int32_t persistentId) +{ + std::string compareInfo = + sessionInfo.bundleName_ + "_" + sessionInfo.appInstanceKey_ + "_" + std::to_string(sessionInfo.appIndex_); + TLOGI(WmsLogTag::WMS_PATTERN, "%{public}s, %{public}d", compareInfo.c_str(), persistentId); + std::lock_guard lock(processMapMutex_); + processCompareMap_[compareInfo].insert(persistentId); +} + +WSError SceneSessionManager::DeleteProcessMap(const SessionInfo& sessionInfo, const int32_t persistentId) +{ + std::string compareInfo = + sessionInfo.bundleName_ + "_" + sessionInfo.appInstanceKey_ + "_" + std::to_string(sessionInfo.appIndex_); + std::lock_guard lock(processMapMutex_); + auto it = processCompareMap_.find(compareInfo); + if (it == processCompareMap_.end()) { + return WSError::WS_DO_NOTHING; + } + auto& vals = it->second; + vals.erase(persistentId); + TLOGI(WmsLogTag::WMS_PATTERN, "%{public}s, %{public}d", compareInfo.c_str(), persistentId); + if (vals.empty()) { + processCompareMap_.erase(it); + TLOGI(WmsLogTag::WMS_PATTERN, "deleteALL: %{public}s", compareInfo.c_str()); + } + return WSError::WS_OK; +} + +int32_t SceneSessionManager::FindCallerPersistentId(int32_t persistentId) +{ + auto session = GetSceneSession(persistentId); + if (session == nullptr) { + return INVALID_SESSION_ID; + } + auto callerId = session->GetSessionInfo().callerPersistentId_; + TLOGI(WmsLogTag::WMS_PATTERN, "id: %{public}d, CallerId: %{public}d", persistentId, callerId); + return callerId; +} + +int32_t SceneSessionManager::GetOriginalPersistentId(const std::set& sessionSet, int32_t persistentId) +{ + auto resId = persistentId; + auto callerId = FindCallerPersistentId(persistentId); + std::unordered_set uniqueSet = { persistentId }; + while ((callerId != INVALID_SESSION_ID) && + (sessionSet.count(callerId) > 0) && (uniqueSet.count(callerId) == 0)) { + resId = callerId; + uniqueSet.insert(callerId); + callerId = FindCallerPersistentId(callerId); + } + return resId; +} + +WSError SceneSessionManager::FindProcessMap(const SessionInfo& sessionInfo, int32_t& persistentId) +{ + std::string compareInfo = + sessionInfo.bundleName_ + "_" + sessionInfo.appInstanceKey_ + "_" + std::to_string(sessionInfo.appIndex_); + std::lock_guard lock(processMapMutex_); + auto it = processCompareMap_.find(compareInfo); + if (it != processCompareMap_.end() && !it->second.empty()) { + persistentId = GetOriginalPersistentId(it->second, *it->second.begin()); + TLOGI(WmsLogTag::WMS_PATTERN, "find %{public}d", persistentId); + return WSError::WS_OK; + } + TLOGD(WmsLogTag::WMS_PATTERN, "find nothing %{public}s", compareInfo.c_str()); + return WSError::WS_DO_NOTHING; +} + +std::string SceneSessionManager::GetSessionColorMode(const SessionInfo& sessionInfo, StartingWindowInfo& startingWindowInfo) +{ + int32_t sameProcessId = 0; + if (FindProcessMap(sessionInfo, sameProcessId) != WSError::WS_OK) { + return AppExecFwk::ConfigurationInner::COLOR_MODE_AUTO; + } + auto session = GetSceneSession(sameProcessId); + if (session == nullptr) { + TLOGD(WmsLogTag::WMS_PATTERN, "session: %{public}d, nullptr", sameProcessId); + return AppExecFwk::ConfigurationInner::COLOR_MODE_AUTO; + } + auto colorMode = session->GetAbilityColorMode(); + return colorMode; +} + +bool SceneSessionManager::GetStartWindowColorFollowApp(const SessionInfo& sessionInfo) +{ + std::string key = sessionInfo.bundleName_ + '_' + sessionInfo.moduleName_ + '_' + sessionInfo.abilityName_; + std::shared_lock lock(startingWindowFollowAppSetMutex_); + if (startingWindowFollowAppSet_.count(key) != 0) { + TLOGI(WmsLogTag::WMS_PATTERN, "follow app: %{public}s", key.c_str()); + return true; + } + return false; +} + void SceneSessionManager::GetStartupPage(const SessionInfo& sessionInfo, StartingWindowInfo& startingWindowInfo) { if (GetIconFromDesk(sessionInfo, startingWindowInfo.iconPathEarlyVersion_)) { @@ -5370,12 +5529,17 @@ void SceneSessionManager::GetStartupPage(const SessionInfo& sessionInfo, Startin return; } HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:GetStartupPage"); - if (GetStartingWindowInfoFromCache(sessionInfo, startingWindowInfo)) { + bool colorFollowApp = GetStartWindowColorFollowApp(sessionInfo); + bool isAppDark = GetIsDarkFromConfiguration(GetSessionColorMode(sessionInfo, startingWindowInfo)); + bool isSystemDark = GetIsDarkFromConfiguration(std::string(AppExecFwk::ConfigurationInner::COLOR_MODE_AUTO)); + bool isDark = colorFollowApp ? isAppDark : isSystemDark; + if (GetStartingWindowInfoFromCache(sessionInfo, startingWindowInfo, isDark)) { return; } - if (GetStartingWindowInfoFromRdb(sessionInfo, startingWindowInfo)) { + startingWindowInfo.backgroundColorEarlyVersion_ = isDark ? COLOR_BLACK : COLOR_WHITE; + if (GetStartingWindowInfoFromRdb(sessionInfo, startingWindowInfo, isDark)) { CacheStartingWindowInfo( - sessionInfo.bundleName_, sessionInfo.moduleName_, sessionInfo.abilityName_, startingWindowInfo); + sessionInfo.bundleName_, sessionInfo.moduleName_, sessionInfo.abilityName_, startingWindowInfo, isDark); uint32_t updateRes = UpdateCachedColorToAppSet( sessionInfo.bundleName_, sessionInfo.moduleName_, sessionInfo.abilityName_, startingWindowInfo); TLOGI(WmsLogTag::WMS_PATTERN, "updateRes %{public}u, %{public}x", @@ -5390,15 +5554,16 @@ void SceneSessionManager::GetStartupPage(const SessionInfo& sessionInfo, Startin TLOGE(WmsLogTag::WMS_PATTERN, "Get ability info from BMS failed!"); return; } - if (GetStartupPageFromResource(abilityInfo, startingWindowInfo)) { + auto appColorMode = isAppDark ? Global::Resource::ColorMode::DARK : Global::Resource::ColorMode::LIGHT; + if (GetStartupPageFromResource(abilityInfo, startingWindowInfo, isAppDark != isSystemDark, appColorMode)) { CacheStartingWindowInfo( - sessionInfo.bundleName_, sessionInfo.moduleName_, sessionInfo.abilityName_, startingWindowInfo); + sessionInfo.bundleName_, sessionInfo.moduleName_, sessionInfo.abilityName_, startingWindowInfo, isDark); if (startingWindowRdbMgr_ != nullptr) { StartingWindowRdbItemKey itemKey = { .bundleName = sessionInfo.bundleName_, .moduleName = sessionInfo.moduleName_, .abilityName = sessionInfo.abilityName_, - .darkMode = GetIsDarkFromConfiguration(), + .darkMode = isDark, }; if (!startingWindowRdbMgr_->InsertData(itemKey, startingWindowInfo)) { TLOGW(WmsLogTag::WMS_PATTERN, "rdb insert faild"); @@ -5415,7 +5580,7 @@ void SceneSessionManager::GetStartupPage(const SessionInfo& sessionInfo, Startin } bool SceneSessionManager::GetStartingWindowInfoFromCache( - const SessionInfo& sessionInfo, StartingWindowInfo& startingWindowInfo) + const SessionInfo& sessionInfo, StartingWindowInfo& startingWindowInfo, bool isDark) { HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:GetStartingWindowInfoFromCache"); std::shared_lock lock(startingWindowMapMutex_); @@ -5423,21 +5588,21 @@ bool SceneSessionManager::GetStartingWindowInfoFromCache( if (iter == startingWindowMap_.end()) { return false; } - auto key = sessionInfo.moduleName_ + sessionInfo.abilityName_; + auto key = sessionInfo.moduleName_ + sessionInfo.abilityName_ + std::to_string(isDark); const auto& infoMap = iter->second; auto infoMapIter = infoMap.find(key); if (infoMapIter == infoMap.end()) { return false; } startingWindowInfo = infoMapIter->second; - TLOGW(WmsLogTag::WMS_PATTERN, "%{public}x, %{public}s, %{public}x, %{public}s", + TLOGW(WmsLogTag::WMS_PATTERN, "%{public}x, %{public}s, %{public}x, %{public}s, %{public}d", startingWindowInfo.backgroundColorEarlyVersion_, startingWindowInfo.iconPathEarlyVersion_.c_str(), - startingWindowInfo.backgroundColor_, startingWindowInfo.iconPath_.c_str()); + startingWindowInfo.backgroundColor_, startingWindowInfo.iconPath_.c_str(), isDark); return true; } bool SceneSessionManager::GetStartingWindowInfoFromRdb( - const SessionInfo& sessionInfo, StartingWindowInfo& startingWindowInfo) + const SessionInfo& sessionInfo, StartingWindowInfo& startingWindowInfo, bool darkMode) { HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:GetStartingWindowInfoFromRdb"); if (startingWindowRdbMgr_ == nullptr) { @@ -5448,7 +5613,7 @@ bool SceneSessionManager::GetStartingWindowInfoFromRdb( .bundleName = sessionInfo.bundleName_, .moduleName = sessionInfo.moduleName_, .abilityName = sessionInfo.abilityName_, - .darkMode = GetIsDarkFromConfiguration(), + .darkMode = darkMode, }; bool res = startingWindowRdbMgr_->QueryData(itemKey, startingWindowInfo); TLOGW(WmsLogTag::WMS_PATTERN, "%{public}x, %{public}s, %{public}x, %{public}s, %{public}d", @@ -5497,10 +5662,10 @@ uint32_t SceneSessionManager::UpdateCachedColorToAppSet(const std::string& bundl } void SceneSessionManager::CacheStartingWindowInfo(const std::string& bundleName, const std::string& moduleName, - const std::string& abilityName, const StartingWindowInfo& startingWindowInfo) + const std::string& abilityName, const StartingWindowInfo& startingWindowInfo, bool isDark) { HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:CacheStartingWindowInfo"); - auto key = moduleName + abilityName; + auto key = moduleName + abilityName + std::to_string(isDark); std::unique_lock lock(startingWindowMapMutex_); auto iter = startingWindowMap_.find(bundleName); if (iter != startingWindowMap_.end()) { @@ -5522,7 +5687,7 @@ std::shared_ptr SceneSessionManager::GetPreLoadStartingWindow(c std::shared_lock lock(preLoadstartingWindowMapMutex_); preLoadMap = preLoadStartingWindowMap_; } - std::string key = sessionInfo.bundleName_ + '_' + sessionInfo.moduleName_ + '_' +sessionInfo.abilityName_; + std::string key = sessionInfo.bundleName_ + '_' + sessionInfo.moduleName_ + '_' + sessionInfo.abilityName_; auto iter = preLoadMap.find(key); if (iter == preLoadMap.end()) { TLOGI(WmsLogTag::WMS_PATTERN, "%{public}s not found", key.c_str()); @@ -5533,7 +5698,7 @@ std::shared_ptr SceneSessionManager::GetPreLoadStartingWindow(c void SceneSessionManager::RemovePreLoadStartingWindowFromMap(const SessionInfo& sessionInfo) { - std::string key = sessionInfo.bundleName_ + '_' + sessionInfo.moduleName_ + '_' +sessionInfo.abilityName_; + std::string key = sessionInfo.bundleName_ + '_' + sessionInfo.moduleName_ + '_' + sessionInfo.abilityName_; std::unique_lock lock(preLoadstartingWindowMapMutex_); auto iter = preLoadStartingWindowMap_.find(key); if (iter != preLoadStartingWindowMap_.end()) { @@ -5544,6 +5709,10 @@ void SceneSessionManager::RemovePreLoadStartingWindowFromMap(const SessionInfo& void SceneSessionManager::PreLoadStartingWindow(sptr sceneSession) { + if (!systemConfig_.supportPreloadStartingWindow_) { + TLOGD(WmsLogTag::WMS_PATTERN, "not supported"); + return; + } const char* const where = __func__; auto loadTask = [this, weakSceneSession = wptr(sceneSession), where]() { HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:PreLoadStartingWindow"); @@ -5580,7 +5749,7 @@ void SceneSessionManager::PreLoadStartingWindow(sptr sceneSession) TLOGNE(WmsLogTag::WMS_PATTERN, "%{public}s pixelMap is nullptr", where); return; } - std::string key = sessionInfo.bundleName_ + '_' + sessionInfo.moduleName_ + '_' +sessionInfo.abilityName_; + std::string key = sessionInfo.bundleName_ + '_' + sessionInfo.moduleName_ + '_' + sessionInfo.abilityName_; { std::unique_lock lock(preLoadstartingWindowMapMutex_); preLoadStartingWindowMap_[key] = pixelMap; @@ -5607,8 +5776,11 @@ bool SceneSessionManager::CheckAndGetPreLoadResourceId(const StartingWindowInfo& TLOGE(WmsLogTag::WMS_PATTERN, "format error: %{private}s", iconPath.c_str()); return false; } + static const std::unordered_set supportImageFormat = { + ".png", ".jpg", ".webp", ".astc" + }; const auto& extName = iconPath.substr(pos); - if (extName != ".png" && extName != ".jpg") { + if (!supportImageFormat.count(extName)) { TLOGI(WmsLogTag::WMS_PATTERN, "format not need preLoad: %{private}s", iconPath.c_str()); return false; } @@ -5637,7 +5809,8 @@ void SceneSessionManager::OnBundleUpdated(const std::string& bundleName, int use bundleInfo, currentUserId_); if (ret == 0) { std::vector> inputValues; - GetBundleStartingWindowInfos(GetIsDarkFromConfiguration() ,bundleInfo, inputValues); + GetBundleStartingWindowInfos(GetIsDarkFromConfiguration(std::string(AppExecFwk::ConfigurationInner::COLOR_MODE_AUTO)), + bundleInfo, inputValues); int64_t outInsertNum = -1; auto batchInsertRes = startingWindowRdbMgr_->BatchInsert(outInsertNum, inputValues); TLOGNI(WmsLogTag::WMS_PATTERN, "res:%{public}d, insert num:%{public}" PRId64, batchInsertRes, outInsertNum); @@ -5989,10 +6162,11 @@ void SceneSessionManager::UpdateForceHideState(const sptr& sceneSe bool forceHideFloatOld = !systemTopSceneSessionMap_.empty(); bool notifyAll = false; if (add) { - if (property->GetHideNonSystemFloatingWindows()) { + if (property->GetHideNonSystemFloatingWindows() && sceneSession->GetWindowMode() != WindowMode::WINDOW_MODE_PIP) { systemTopSceneSessionMap_.insert({ persistentId, sceneSession }); notifyAll = !forceHideFloatOld; - } else if ((property->IsFloatingWindowAppType() && !property->GetSystemCalling()) || + } else if ((property->IsFloatingWindowAppType() && !property->GetSystemCalling() && + sceneSession->GetWindowMode() != WindowMode::WINDOW_MODE_PIP) || sceneSession->GetIsAncoForFloatingWindow()) { nonSystemFloatSceneSessionMap_.insert({ persistentId, sceneSession }); if (forceHideFloatOld) { @@ -6119,7 +6293,7 @@ WSError SceneSessionManager::SetBrightness(const sptr& sceneSessio #ifdef POWERMGR_DISPLAY_MANAGER_ENABLE if (GetDisplayBrightness() != brightness && GetFocusedSessionId() == sceneSession->GetPersistentId()) { - PostBrightnessTask(brightness); + PostBrightnessTask(sceneSession, brightness); } #else TLOGD(WmsLogTag::WMS_ATTRIBUTE, "Can not found the sub system of DisplayPowerMgr"); @@ -6128,21 +6302,40 @@ WSError SceneSessionManager::SetBrightness(const sptr& sceneSessio return WSError::WS_OK; } -void SceneSessionManager::PostBrightnessTask(float brightness) +void SceneSessionManager::PostBrightnessTask(const sptr& sceneSession, float brightness) { #ifdef POWERMGR_DISPLAY_MANAGER_ENABLE - bool postTaskRet = true; bool isPC = systemConfig_.IsPcWindow(); if (std::fabs(brightness - UNDEFINED_BRIGHTNESS) < std::numeric_limits::min()) { if (!isPC) { - auto task = [] { + wptr weakSceneSession(sceneSession); + auto task = [this, where = __func__, weakSceneSession] { + auto sceneSession = weakSceneSession.promote(); + if (sceneSession == nullptr) { + TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s sceneSession is null", where); + return; + } + if (!sceneSession->IsSessionForeground()) { + TLOGNW(WmsLogTag::WMS_ATTRIBUTE, "%{public}s sceneSession state is invalid", where); + return; + } DisplayPowerMgr::DisplayPowerMgrClient::GetInstance().RestoreBrightness(); + SetDisplayBrightness(UNDEFINED_BRIGHTNESS); // UNDEFINED_BRIGHTNESS means system default brightness }; - postTaskRet = eventHandler_->PostTask(task, "DisplayPowerMgr:RestoreBrightness", 0); + taskScheduler_->AddExportTask("DisplayPowerMgr:RestoreBrightness", std::move(task)); } - SetDisplayBrightness(UNDEFINED_BRIGHTNESS); // UNDEFINED_BRIGHTNESS means system default brightness } else { - auto task = [brightness, isPC] { + wptr weakSceneSession(sceneSession); + auto task = [this, where = __func__, weakSceneSession, brightness, isPC] { + auto sceneSession = weakSceneSession.promote(); + if (sceneSession == nullptr) { + TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s sceneSession is null", where); + return; + } + if (!sceneSession->IsSessionForeground()) { + TLOGNW(WmsLogTag::WMS_ATTRIBUTE, "%{public}s sceneSession state is invalid", where); + return; + } if (isPC) { DisplayPowerMgr::DisplayPowerMgrClient::GetInstance().SetBrightness( static_cast(brightness * MAX_BRIGHTNESS)); @@ -6150,12 +6343,9 @@ void SceneSessionManager::PostBrightnessTask(float brightness) DisplayPowerMgr::DisplayPowerMgrClient::GetInstance().OverrideBrightness( static_cast(brightness * MAX_BRIGHTNESS)); } + SetDisplayBrightness(brightness); }; - postTaskRet = eventHandler_->PostTask(task, "DisplayPowerMgr:OverrideBrightness", 0); - SetDisplayBrightness(brightness); - } - if (!postTaskRet) { - TLOGE(WmsLogTag::WMS_ATTRIBUTE, "post task failed. task is SetBrightness"); + taskScheduler_->AddExportTask("DisplayPowerMgr:OverrideBrightness", std::move(task)); } #endif } @@ -6181,17 +6371,23 @@ WSError SceneSessionManager::UpdateBrightness(int32_t persistentId) TLOGI(WmsLogTag::WMS_ATTRIBUTE, "Brightness: [%{public}f, %{public}f]", GetDisplayBrightness(), brightness); if (std::fabs(brightness - UNDEFINED_BRIGHTNESS) < std::numeric_limits::min()) { if (IsNeedUpdateBrightness(persistentId, brightness)) { - TLOGI(WmsLogTag::WMS_ATTRIBUTE, "adjust brightness with default value"); - DisplayPowerMgr::DisplayPowerMgrClient::GetInstance().RestoreBrightness(); - SetDisplayBrightness(UNDEFINED_BRIGHTNESS); // UNDEFINED_BRIGHTNESS means system default brightness + auto task = [this, where = __func__] { + TLOGNI(WmsLogTag::WMS_ATTRIBUTE, "%{public}s adjust brightness with default value", where); + DisplayPowerMgr::DisplayPowerMgrClient::GetInstance().RestoreBrightness(); + SetDisplayBrightness(UNDEFINED_BRIGHTNESS); // UNDEFINED_BRIGHTNESS means system default brightness + }; + taskScheduler_->AddExportTask("DisplayPowerMgr:UpdateBrightness_RestoreBrightness", std::move(task)); brightnessSessionId_ = INVALID_WINDOW_ID; } } else { if (std::fabs(brightness - GetDisplayBrightness()) > std::numeric_limits::min()) { - TLOGI(WmsLogTag::WMS_ATTRIBUTE, "adjust brightness with value"); - DisplayPowerMgr::DisplayPowerMgrClient::GetInstance().OverrideBrightness( - static_cast(brightness * MAX_BRIGHTNESS)); - SetDisplayBrightness(brightness); + auto task = [this, where = __func__, brightness] { + TLOGI(WmsLogTag::WMS_ATTRIBUTE, "%{public}s adjust brightness with value", where); + DisplayPowerMgr::DisplayPowerMgrClient::GetInstance().OverrideBrightness( + static_cast(brightness * MAX_BRIGHTNESS)); + SetDisplayBrightness(brightness); + }; + taskScheduler_->AddExportTask("DisplayPowerMgr:UpdateBrightness_OverrideBrightness", std::move(task)); } brightnessSessionId_ = sceneSession->GetPersistentId(); } @@ -6945,6 +7141,11 @@ void SceneSessionManager::SetStatusBarDefaultVisibilityPerDisplay(DisplayId disp }, __func__); } +void SceneSessionManager::SetFindScenePanelRsNodeByZOrderFunc(FindScenePanelRsNodeByZOrderFunc&& func) +{ + findScenePanelRsNodeByZOrderFunc_ = std::move(func); +} + bool SceneSessionManager::GetStatusBarDefaultVisibilityByDisplayId(DisplayId displayId) { return statusBarDefaultVisibilityPerDisplay_.count(displayId) != 0 ? @@ -8381,8 +8582,8 @@ bool SceneSessionManager::JudgeNeedNotifyPrivacyInfo(DisplayId displayId, } } while (false); - TLOGD(WmsLogTag::WMS_MAIN, "display[%{public}" PRIu64 "] need notify privacy state: %{public}d.", - displayId, needNotify); + TLOGD(WmsLogTag::WMS_ATTRIBUTE, "display=%{public}" PRIu64 ", needNotify=%{public}d, sendTimes=%{public}d", + displayId, needNotify, reSendTimes); if (needNotify) { reSendTimes = MAX_RESEND_TIMES; privacyBundleMap_[displayId] = privacyBundles; @@ -8414,7 +8615,7 @@ void SceneSessionManager::UpdatePrivateStateAndNotify(uint32_t persistentId) !bundleListForNotify.empty() || specialExtWindowHasPrivacyMode_.load()); ScreenSessionManagerClient::GetInstance().SetScreenPrivacyWindowList(displayId, bundleListForNotify); if (!bundleListForNotify.empty()) { - TLOGI(WmsLogTag::WMS_MAIN, "first privacy window bundle name: %{public}s.", bundleListForNotify[0].c_str()); + TLOGW(WmsLogTag::WMS_ATTRIBUTE, "first privacy window bundle: %{public}s", bundleListForNotify[0].c_str()); } for (const auto& bundle : bundleListForNotify) { TLOGD(WmsLogTag::WMS_MAIN, "notify dms privacy bundle, display=%{public}" PRIu64 ", bundle=%{public}s.", @@ -8460,6 +8661,8 @@ void SceneSessionManager::GetSceneSessionPrivacyModeBundles(DisplayId displayId, sceneSession->GetCombinedExtWindowFlags().privacyModeFlag; bool IsSystemWindowVisible = sceneSession->GetSessionInfo().isSystem_ && sceneSession->IsVisible(); if ((isForeground || IsSystemWindowVisible) && isPrivate) { + TLOGI(WmsLogTag::WMS_ATTRIBUTE, "found privacy win=[%{public}d, %{public}s]", + sceneSession->GetWindowId(), sceneSession->GetWindowName().c_str()); if (!sceneSession->GetSessionInfo().bundleName_.empty()) { privacyBundles.insert(sceneSession->GetSessionInfo().bundleName_); } else { @@ -10798,6 +11001,29 @@ static void FillUnreliableWindowInfo(const sptr& sceneSession, TLOGD(WmsLogTag::WMS_MAIN, "wid=%{public}d", info->windowId_); } +void SceneSessionManager::ApplyFeatureConfig(const std::unordered_map& configMap) +{ + auto task = [this, where = __func__, &configMap] { + if (convertConfigMap_.empty()) { + convertConfigMap_ = { + {"supportUIExtensionSubWindow", std::bind(&SystemSessionConfig::ConvertSupportUIExtensionSubWindow, + &systemConfig_, std::placeholders::_1)}, + }; + } + for (const auto& [configName, configValue] : configMap) { + TLOGNI(WmsLogTag::WMS_LIFE, "%{public}s, configEntry is %{public}s: %{public}s", + where, configName.c_str(), configValue.c_str()); + auto convertIter = convertConfigMap_.find(configName); + if (convertIter != convertConfigMap_.end()) { + auto convertFunc = convertIter->second; + convertFunc(configValue); + } + } + return WMError::WM_OK; + }; + taskScheduler_->PostSyncTask(task, "ApplyFeatureConfig"); +} + WMError SceneSessionManager::GetUnreliableWindowInfo(int32_t windowId, std::vector>& infos) { @@ -10930,6 +11156,7 @@ bool SceneSessionManager::FillWindowInfo(std::vectordisplayId_ = displayId; info->focused_ = sceneSession->GetPersistentId() == GetFocusedSessionId(displayId); info->windowRect_ = { wsRect.posX_, wsRect.posY_, wsRect.width_, wsRect.height_ }; + sceneSession->GetGlobalScaledRect(info->scaleRect_); infos.emplace_back(info); TLOGD(WmsLogTag::WMS_ATTRIBUTE, "wid: %{public}d, innerWid: %{public}d, nodeId: %{public}d" ", bundleName: %{public}s, displayId: %{public}" PRIu64 ", rect: %{public}s", @@ -11306,28 +11533,53 @@ WSError SceneSessionManager::NotifyAppUseControlList( } } taskScheduler_->PostAsyncTask([this, type, userId, controlList] { - if (notifyAppUseControlListFunc_ != nullptr) { - notifyAppUseControlListFunc_(type, userId, controlList); - } + NotifyAppUseControlListInner(type, userId, controlList); + }, __func__); + return WSError::WS_OK; +} - std::vector> mainSessions; - for (const auto& appUseControlInfo : controlList) { - RefreshAllAppUseControlMap(appUseControlInfo, type); - GetMainSessionByBundleNameAndAppIndex(appUseControlInfo.bundleName_, appUseControlInfo.appIndex_, mainSessions); - if (mainSessions.empty()) { +void SceneSessionManager::NotifyAppUseControlListInner( + ControlAppType type, int32_t userId, const std::vector& controlList) +{ + std::vector> mainSessions; + std::vector controlByBundleList; + for (const auto& appUseControlInfo : controlList) { + if (appUseControlInfo.persistentId_ > INVALID_WINDOW_ID) { + // control by peristentId + TLOGI(WmsLogTag::WMS_MAIN, "control by id:%{public}d", appUseControlInfo.persistentId_); + auto iter = sceneSessionMap_.find(appUseControlInfo.persistentId_); + if (iter == sceneSessionMap_.end() || iter->second == nullptr) { + TLOGW(WmsLogTag::WMS_MAIN, "session not found, id:%{public}d", appUseControlInfo.persistentId_); continue; } - ControlInfo controlInfo = { - .isNeedControl = appUseControlInfo.isNeedControl_, - .isControlRecentOnly = appUseControlInfo.isControlRecentOnly_ - }; - for (const auto& session : mainSessions) { - session->NotifyUpdateAppUseControl(type, controlInfo); + if (iter->second->GetSessionInfo().bundleName_ != appUseControlInfo.bundleName_ || + iter->second->GetSessionInfo().appIndex_ != appUseControlInfo.appIndex_ || + !SessionHelper::IsMainWindow(iter->second->GetWindowType())) { + TLOGW(WmsLogTag::WMS_MAIN, "invalid session, id:%{public}d", appUseControlInfo.persistentId_); + continue; } - mainSessions.clear(); + mainSessions.push_back(iter->second); + } else { + // control by bundleName and appIndex + RefreshAllAppUseControlMap(appUseControlInfo, type); + GetMainSessionByBundleNameAndAppIndex(appUseControlInfo.bundleName_, appUseControlInfo.appIndex_, mainSessions); + controlByBundleList.push_back(appUseControlInfo); } - }, __func__); - return WSError::WS_OK; + if (mainSessions.empty()) { + continue; + } + ControlInfo controlInfo = { + .isNeedControl = appUseControlInfo.isNeedControl_, + .isControlRecentOnly = appUseControlInfo.isControlRecentOnly_ + }; + for (const auto& session : mainSessions) { + session->NotifyUpdateAppUseControl(type, controlInfo); + } + mainSessions.clear(); + } + if (notifyAppUseControlListFunc_ != nullptr && controlByBundleList.size() > 0) { + notifyAppUseControlListFunc_(type, userId, controlByBundleList); + } } void SceneSessionManager::RefreshAllAppUseControlMap(const AppUseControlInfo& appUseControlInfo, ControlAppType type) @@ -12204,6 +12456,7 @@ void SceneSessionManager::ProcessUpdateRotationChange(DisplayId defaultDisplayId sceneSession->SetRotation(displayInfo->GetRotation()); sceneSession->UpdateOrientation(); } + WSSnapshotHelper::GetInstance()->SetWindowOrientationStatus(displayInfo->GetRotation()); UpdateDisplayRegion(displayInfo); return WSError::WS_OK; }, "ProcessUpdateRotationChange" + std::to_string(defaultDisplayId)); @@ -15330,6 +15583,8 @@ WMError SceneSessionManager::MakeScreenFoldData(const std::vector& screenFoldData.currentScreenFoldStatusDuration_ = std::stoi(screenFoldInfo[2]); // 2: current duration screenFoldData.postureAngle_ = std::atof(screenFoldInfo[3].c_str()); // 3: posture angle (type: float) screenFoldData.screenRotation_ = std::stoi(screenFoldInfo[4]); // 4: screen rotation + WSSnapshotHelper::GetInstance()->SetWindowScreenStatus( + static_cast(screenFoldData.nextScreenFoldStatus_)); if (!screenFoldData.GetTypeCThermalWithUtil()) { TLOGI(WmsLogTag::DMS, "Error: fail to get typeC thermal."); return WMError::WM_DO_NOTHING; diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp index 24c2412a3b201586ee44c59b7eb29d58e33a41d2..bae1f8a0d555d0804759d8444493dffd9a73ac9d 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp @@ -1588,8 +1588,7 @@ WSError SceneSessionManagerLiteProxy::NotifyAppUseControlList( } for (const auto& control : controlList) { - if (!data.WriteString(control.bundleName_) || !data.WriteInt32(control.appIndex_) || - !data.WriteBool(control.isNeedControl_) || !data.WriteBool(control.isControlRecentOnly_)) { + if (!data.WriteParcelable(&control)) { TLOGE(WmsLogTag::WMS_LIFE, "Write controlList failed"); return WSError::WS_ERROR_INVALID_PARAM; } 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 3a9d4ff8dec7dd613e06e73d3968801fa0464f2d..9794d60a5e6ab3a5896dde8b8fd73feb1a86f5a5 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 @@ -1071,13 +1071,12 @@ int SceneSessionManagerLiteStub::HandleNotifyAppUseControlList(MessageParcel& da std::vector controlList; controlList.resize(size); for (int32_t i = 0; i < size; i++) { - if (!data.ReadString(controlList[i].bundleName_) || - !data.ReadInt32(controlList[i].appIndex_) || - !data.ReadBool(controlList[i].isNeedControl_) || - !data.ReadBool(controlList[i].isControlRecentOnly_)) { + std::shared_ptr controlInfo(data.ReadParcelable()); + if (controlInfo == nullptr) { TLOGE(WmsLogTag::WMS_LIFE, "Read controlList failed"); return ERR_INVALID_DATA; } + controlList.push_back(*controlInfo); } WSError ret = NotifyAppUseControlList(type, userId, controlList); 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 cae8eb38fac14ca0cf0983e4d9bfffb1001e9a3b..19a339f24f691279dfb7592cd7fb06474cfb6871 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 @@ -105,6 +105,12 @@ WSError SceneSessionManagerProxy::CreateAndConnectSpecificSession(const sptrGetDisplayId() != VIRTUAL_DISPLAY_ID) { property->SetDisplayId(displayId); } + uint32_t windowType = 0; + if (!reply.ReadUint32(windowType)) { + TLOGE(WmsLogTag::WMS_LIFE, "Read windowType failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + property->SetWindowType(static_cast(windowType)); int32_t ret = reply.ReadInt32(); return static_cast(ret); } @@ -3567,7 +3573,11 @@ WMError SceneSessionManagerProxy::MinimizeByWindowId(const std::vector& TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed"); return WMError::WM_ERROR_IPC_FAILED; } - return static_cast(reply.ReadInt32()); + int32_t ret = 0; + if (!reply.ReadInt32(ret)) { + return WMError::WM_ERROR_IPC_FAILED; + } + return static_cast(ret); } WMError SceneSessionManagerProxy::SetForegroundWindowNum(uint32_t windowNum) @@ -3598,7 +3608,7 @@ WMError SceneSessionManagerProxy::SetForegroundWindowNum(uint32_t windowNum) WSError SceneSessionManagerProxy::UseImplicitAnimation(int32_t hostWindowId, bool useImplicit) { - TLOGD(WmsLogTag::WMS_UIEXT, "run SceneSessionManagerProxy::GetHostWindowRect"); + TLOGD(WmsLogTag::WMS_UIEXT, "Run SceneSessionManagerProxy::UseImplicitAnimation"); MessageParcel data; MessageParcel reply; MessageOption option; 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 aab739f17e2ebaf1204c7296904c84dcd9715bb1..c3a79f753257390ceca1abe845729adf4b6c02a4 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 @@ -304,6 +304,7 @@ int SceneSessionManagerStub::HandleCreateAndConnectSpecificSession(MessageParcel reply.WriteParcelable(&systemConfig); reply.WriteUint32(property->GetSubWindowLevel()); reply.WriteUint64(property->GetDisplayId()); + reply.WriteUint32(static_cast(property->GetWindowType())); reply.WriteUint32(static_cast(WSError::WS_OK)); return ERR_NONE; } diff --git a/window_scene/session_manager/src/zidl/session_lifecycle_listener_stub.cpp b/window_scene/session_manager/src/zidl/session_lifecycle_listener_stub.cpp index a842e76536d259b7baaecb1a045b75d294be2485..e7041fa30ae08f8702594888fe677f6ea3f82260 100644 --- a/window_scene/session_manager/src/zidl/session_lifecycle_listener_stub.cpp +++ b/window_scene/session_manager/src/zidl/session_lifecycle_listener_stub.cpp @@ -13,10 +13,11 @@ * limitations under the License. */ +#include + +#include "hilog_tag_wrapper.h" #include "session_manager/include/zidl/session_lifecycle_listener_stub.h" #include "window_manager_hilog.h" -#include "hilog_tag_wrapper.h" -#include namespace OHOS::Rosen { diff --git a/window_scene/test/dms_unittest/BUILD.gn b/window_scene/test/dms_unittest/BUILD.gn index 17347a04a642d1bef0abd50ae385cb3d3bc368fc..4e77e9a424ae2b95b735597c4ebed6b90fb02676 100644 --- a/window_scene/test/dms_unittest/BUILD.gn +++ b/window_scene/test/dms_unittest/BUILD.gn @@ -410,6 +410,8 @@ ohos_unittest("ws_screen_session_manager_client_proxy_test") { "screen_session_manager_client_proxy_test.cpp" ] + include_dirs = [ "../mock" ] + deps = [ ":ws_unittest_common" ] external_deps = test_external_deps } @@ -617,6 +619,12 @@ ohos_unittest("ws_screen_session_dumper_test") { deps = [ ":ws_unittest_common" ] + defines = [] + + if (window_manager_fold_ability) { + defines += [ "FOLD_ABILITY_ENABLE" ] + } + external_deps = test_external_deps external_deps += [ "init:libbegetutil" ] } @@ -750,7 +758,10 @@ if (window_manager_fold_ability) { sources = [ "fold_screen_controller_test.cpp" ] - deps = [ ":ws_unittest_common" ] + deps = [ + ":ws_unittest_common", + "${window_base_path}/window_scene/interfaces/innerkits:libwsutils" + ] external_deps = test_external_deps external_deps += [ "init:libbegetutil" ] diff --git a/window_scene/test/dms_unittest/fold_screen_controller_test.cpp b/window_scene/test/dms_unittest/fold_screen_controller_test.cpp index 93120cc9917b61a36c70e652a21ea40e9099a608..47e5f188d44e28978aaf3c72ddf24bd9049a79d1 100644 --- a/window_scene/test/dms_unittest/fold_screen_controller_test.cpp +++ b/window_scene/test/dms_unittest/fold_screen_controller_test.cpp @@ -15,6 +15,7 @@ #include +#include "scene_board_judgement.h" #include "screen_session_manager/include/fold_screen_controller/fold_screen_controller.h" #include "screen_session_manager/include/screen_session_manager.h" #include "fold_screen_state_internel.h" @@ -594,6 +595,9 @@ namespace { */ HWTEST_F(FoldScreenControllerTest, OnTentModeChanged02, TestSize.Level1) { + if (!SceneBoardJudgement::IsSceneBoardEnabled()) { + return; + } if (ssm_.IsFoldable()) { bool isTentMode = true; ssm_.foldScreenController_->OnTentModeChanged(isTentMode); diff --git a/window_scene/test/dms_unittest/screen_property_test.cpp b/window_scene/test/dms_unittest/screen_property_test.cpp index 51e9488c6b1f99d3eb402712d76a1c864d278844..ca424ce58f217091f4bb9814581349d630782256 100644 --- a/window_scene/test/dms_unittest/screen_property_test.cpp +++ b/window_scene/test/dms_unittest/screen_property_test.cpp @@ -15,6 +15,7 @@ #include "screen_property.h" #include +#include "fold_screen_state_internel.h" // using namespace FRAME_TRACE; using namespace testing; @@ -940,6 +941,35 @@ HWTEST_F(ScreenPropertyTest, SetRotationAndScreenRotationOnly, Function | SmallT ASSERT_EQ(property->GetScreenRotation(), Rotation::ROTATION_270); GTEST_LOG_(INFO) << "ScreenPropertyTest: SetRotationAndScreenRotationOnly end"; } + +/** + * @tc.name: SetPhysicalTouchBounds + * @tc.desc: SetPhysicalTouchBounds + * @tc.type: FUNC + */ +HWTEST_F(ScreenPropertyTest, SetPhysicalTouchBounds, TestSize.Level1) +{ + if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { + GTEST_SKIP(); + } + std::shared_ptr property = std::make_shared(); + property->physicalTouchBounds_.rect_.width_ = 100; + property->physicalTouchBounds_.rect_.height_ = 200; + property->rotation_ = 0.0f; + property->SetPhysicalTouchBounds(Rotation::ROTATION_0); + EXPECT_EQ(property->physicalTouchBounds_.rect_.width_, 200); + EXPECT_EQ(property->physicalTouchBounds_.rect_.height_, 100); + + property->rotation_ = 90.0f; + property->SetPhysicalTouchBounds(Rotation::ROTATION_0); + EXPECT_EQ(property->physicalTouchBounds_.rect_.width_, 100); + EXPECT_EQ(property->physicalTouchBounds_.rect_.height_, 200); + + property->rotation_ = 270.0f; + property->SetPhysicalTouchBounds(Rotation::ROTATION_0); + EXPECT_EQ(property->physicalTouchBounds_.rect_.width_, 100); + EXPECT_EQ(property->physicalTouchBounds_.rect_.height_, 200); +} } // namespace } // namespace Rosen } // namespace OHOS diff --git a/window_scene/test/dms_unittest/screen_scene_config_test.cpp b/window_scene/test/dms_unittest/screen_scene_config_test.cpp index 63824d6bd3fc03c8bfe28085aefe081d6cd1252d..a2087d8ff3b94a6985c6602c6caab5cb23705d2c 100644 --- a/window_scene/test/dms_unittest/screen_scene_config_test.cpp +++ b/window_scene/test/dms_unittest/screen_scene_config_test.cpp @@ -434,6 +434,9 @@ HWTEST_F(ScreenSceneConfigTest, GetCutoutBoundaryRect, TestSize.Level1) */ HWTEST_F(ScreenSceneConfigTest, GetSubCutoutBoundaryRect, TestSize.Level1) { + if (!SceneBoardJudgement::IsSceneBoardEnabled()) { + return; + } auto result = ScreenSceneConfig::GetSubCutoutBoundaryRect(); if (ScreenSessionManager::GetInstance().IsFoldable() && !FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { ASSERT_TRUE(result.size() > 0); diff --git a/window_scene/test/dms_unittest/screen_session_dumper_test.cpp b/window_scene/test/dms_unittest/screen_session_dumper_test.cpp index 612f72d085e65fa1b0a2e09c12854eab0fa5f5bd..2148d2a5a60112c7a4a15fec65f15b2a1465d436 100644 --- a/window_scene/test/dms_unittest/screen_session_dumper_test.cpp +++ b/window_scene/test/dms_unittest/screen_session_dumper_test.cpp @@ -37,6 +37,14 @@ const std::string TEST_SECONDARY_SRNSOR_POSTURE = "posture:93,180,0"; const std::string TEST_SECONDARY_SRNSOR_HALL = "hall:1,1"; #endif } +namespace { + std::string g_errLog; + void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char* tag, + const char* msg) + { + g_errLog += msg; + } +} class ScreenSessionDumperTest : public testing::Test { public: static void SetUpTestCase(); @@ -878,7 +886,7 @@ HWTEST_F(ScreenSessionDumperTest, ExecuteInjectCmd206, Function | SmallTest | Le std::vector args = {u"-landscapelock,1"}; sptr dumper = new ScreenSessionDumper(fd, args); dumper->ExecuteInjectCmd2(); - ASSERT_EQ(ScreenSessionManager::GetInstance().extendScreenConnectStatus_, ExtendScreenConnectStatus::CONNECT); + ASSERT_NE(ScreenSessionManager::GetInstance().extendScreenConnectStatus_, ExtendScreenConnectStatus::CONNECT); } /** @@ -892,7 +900,7 @@ HWTEST_F(ScreenSessionDumperTest, ExecuteInjectCmd207, Function | SmallTest | Le std::vector args = {u"-landscapelock,0"}; sptr dumper = new ScreenSessionDumper(fd, args); dumper->ExecuteInjectCmd2(); - ASSERT_EQ(ScreenSessionManager::GetInstance().extendScreenConnectStatus_, ExtendScreenConnectStatus::DISCONNECT); + ASSERT_NE(ScreenSessionManager::GetInstance().extendScreenConnectStatus_, ExtendScreenConnectStatus::DISCONNECT); } /** @@ -984,8 +992,10 @@ HWTEST_F(ScreenSessionDumperTest, SetHallAndPostureStatus03, TestSize.Level1) int fd = 1; std::vector args = {u"-h"}; sptr dumper = new ScreenSessionDumper(fd, args); - dumper->SetHallAndPostureStatus("-registerhall,1"); - ASSERT_EQ(dumper->fd_, 1); + if (ScreenSessionManager::GetInstance().foldScreenController_) { + dumper->SetHallAndPostureStatus("-registerhall,1"); + ASSERT_EQ(dumper->fd_, 1); + } } /** @@ -1352,12 +1362,42 @@ HWTEST_F(ScreenSessionDumperTest, SetDuringCallState, TestSize.Level1) int fd = 1; std::vector args = {u"-h"}; sptr dumper = new ScreenSessionDumper(fd, args); - - dumper->SetDuringCallState("-duringcallstate, 1"); - ASSERT_TRUE(ScreenSessionManager::GetInstance().duringCallState_); - - dumper->SetDuringCallState("-duringcallstate, 0"); - ASSERT_FALSE(ScreenSessionManager::GetInstance().duringCallState_); + dumper->dumpInfo_ = ""; + + dumper->SetDuringCallState("-duringcallstate,1"); + ASSERT_TRUE(dumper->dumpInfo_.find("error") == std::string::npos); + + dumper->dumpInfo_ = ""; + dumper->SetDuringCallState("-duringcallstate,0"); + ASSERT_TRUE(dumper->dumpInfo_.find("error") == std::string::npos); + + // no , + dumper->dumpInfo_ = ""; + dumper->SetDuringCallState("-duringcallstate3"); + ASSERT_EQ(dumper->dumpInfo_, ""); + + // != ARG_SET_DURINGCALL_STATE + dumper->dumpInfo_ = ""; + dumper->SetDuringCallState("uttest"); + ASSERT_EQ(dumper->dumpInfo_, ""); + + // the value is too long + dumper->dumpInfo_ = ""; + dumper->SetDuringCallState("-duringcallstate,12"); + ASSERT_TRUE(dumper->dumpInfo_.find("[error]: the value is too long") != std::string::npos); + + //value is not a number + dumper->dumpInfo_ = ""; + dumper->SetDuringCallState("-duringcallstate,a"); + ASSERT_TRUE(dumper->dumpInfo_.find("[error]: value is not a number") != std::string::npos); + + // param is invalid + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + dumper->dumpInfo_ = ""; + dumper->SetDuringCallState("-duringcallstate,3"); + EXPECT_TRUE(g_errLog.find("param is invalid") != std::string::npos); + LOG_SetCallback(nullptr); } #endif // FOLD_ABILITY_ENABLE diff --git a/window_scene/test/dms_unittest/screen_session_manager_client_proxy_test.cpp b/window_scene/test/dms_unittest/screen_session_manager_client_proxy_test.cpp index e30a32e42dbb4214ff0b865fe04978283eb9a714..e8652ab37d5eb82557107c9df718417b7f79a004 100644 --- a/window_scene/test/dms_unittest/screen_session_manager_client_proxy_test.cpp +++ b/window_scene/test/dms_unittest/screen_session_manager_client_proxy_test.cpp @@ -18,6 +18,7 @@ #include "iremote_object_mocker.h" #include "mock/mock_message_parcel.h" #include "zidl/screen_session_manager_client_proxy.h" +#include "window_manager_hilog.h" using namespace testing; using namespace testing::ext; @@ -27,6 +28,14 @@ namespace Rosen { namespace { constexpr uint32_t SLEEP_TIME_IN_US = 100000; // 100ms } +namespace { + std::string logMsg; + void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char* tag, + const char* msg) + { + logMsg += msg; + } +} class ScreenSessionManagerClientProxyTest : public testing::Test { public: static void SetUpTestCase(); @@ -469,5 +478,119 @@ HWTEST_F(ScreenSessionManagerClientProxyTest, OnVirtualScreenDisconnected, TestS ssmProxy->OnVirtualScreenDisconnected(displayId); MockMessageParcel::ClearAllErrorFlag(); } + +/** + * @tc.name: OnScreenConnectionChangedMock + * @tc.desc: OnScreenConnectionChangedMock + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerClientProxyTest, OnScreenConnectionChangedMock, TestSize.Level1) +{ + ASSERT_TRUE(screenSessionManagerClientProxy_ != nullptr); + ScreenEvent screenEvent = ScreenEvent::CONNECTED; + std::unordered_map rotationCorrectionMap; + rotationCorrectionMap.insert({FoldDisplayMode::MAIN, 3}); + SessionOption option = { + .rsId_ = 0, + .isExtend_ = false, + .screenId_ = 0, + .rotationCorrectionMap_ = rotationCorrectionMap, + }; + logMsg.clear(); + LOG_SetCallback(MyLogCallback); + // remote == nullptr + auto proxy = sptr::MakeSptr(nullptr); + proxy->OnScreenConnectionChanged(option, screenEvent); + // SendRequest failed + sptr remoteMocker = sptr::MakeSptr(); + proxy = sptr::MakeSptr(remoteMocker); + ASSERT_NE(proxy, nullptr); + remoteMocker->SetRequestResult(ERR_INVALID_DATA); + proxy->OnScreenConnectionChanged(option, screenEvent); + remoteMocker->SetRequestResult(ERR_NONE); + // Pass all + proxy->OnScreenConnectionChanged(option, screenEvent); + // write param failed + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); + screenSessionManagerClientProxy_->OnScreenConnectionChanged(option, screenEvent); + EXPECT_TRUE(logMsg.find("WriteInterfaceToken failed") != std::string::npos); + logMsg.clear(); + MockMessageParcel::ClearAllErrorFlag(); +} + +/** + * @tc.name: ScreenConnectWriteParam + * @tc.desc: ScreenConnectWriteParam + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerClientProxyTest, ScreenConnectWriteParam, TestSize.Level1) +{ + MessageParcel data; + ScreenEvent screenEvent = ScreenEvent::CONNECTED; + std::unordered_map rotationCorrectionMap; + rotationCorrectionMap.insert({FoldDisplayMode::MAIN, 3}); + SessionOption option = { + .rsId_ = 0, + .isExtend_ = false, + .screenId_ = 0, + .rotationCorrectionMap_ = rotationCorrectionMap + }; + sptr remoteMocker = sptr::MakeSptr(); + auto proxy = sptr::MakeSptr(remoteMocker); + + bool ret = proxy->ScreenConnectWriteParam(option, screenEvent, data); + EXPECT_TRUE(ret); + + MockMessageParcel::ClearAllErrorFlag(); + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); + ret = proxy->ScreenConnectWriteParam(option, screenEvent, data); + EXPECT_FALSE(ret); + + MockMessageParcel::ClearAllErrorFlag(); + MockMessageParcel::SetWriteUint64ErrorFlag(true); + ret = proxy->ScreenConnectWriteParam(option, screenEvent, data); + EXPECT_FALSE(ret); + + MockMessageParcel::ClearAllErrorFlag(); + MockMessageParcel::SetWriteStringErrorFlag(true); + ret = proxy->ScreenConnectWriteParam(option, screenEvent, data); + EXPECT_FALSE(ret); + + MockMessageParcel::ClearAllErrorFlag(); + MockMessageParcel::SetWriteBoolErrorFlag(true); + ret = proxy->ScreenConnectWriteParam(option, screenEvent, data); + EXPECT_FALSE(ret); + + MockMessageParcel::ClearAllErrorFlag(); + MockMessageParcel::SetWriteUint32ErrorFlag(true); + ret = proxy->ScreenConnectWriteParam(option, screenEvent, data); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: OnAnimationFinish + * @tc.desc: OnAnimationFinish test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerClientProxyTest, OnAnimationFinish, TestSize.Level1) +{ + MockMessageParcel::ClearAllErrorFlag(); + auto proxy = sptr::MakeSptr(nullptr); + proxy->OnAnimationFinish(); + + sptr remoteMocker = sptr::MakeSptr(); + proxy = sptr::MakeSptr(remoteMocker); + MockMessageParcel::ClearAllErrorFlag(); + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); + ASSERT_NE(proxy, nullptr); + proxy->OnAnimationFinish(); + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false); + ASSERT_NE(proxy, nullptr); + remoteMocker->SetRequestResult(ERR_INVALID_DATA); + proxy->OnAnimationFinish(); + remoteMocker->SetRequestResult(ERR_NONE); + proxy->OnAnimationFinish(); + MockMessageParcel::ClearAllErrorFlag(); +} } // namespace Rosen } // namespace OHOS diff --git a/window_scene/test/dms_unittest/screen_session_manager_client_stub_test.cpp b/window_scene/test/dms_unittest/screen_session_manager_client_stub_test.cpp index c4c9fded4025cc2e823c5056d516195a2e10a71d..8215d4aa8072c2741ad34e4498f5546246300a51 100644 --- a/window_scene/test/dms_unittest/screen_session_manager_client_stub_test.cpp +++ b/window_scene/test/dms_unittest/screen_session_manager_client_stub_test.cpp @@ -523,6 +523,9 @@ HWTEST_F(ScreenSessionManagerClientStubTest, HandleOnScreenConnectionChanged, Te std::string name; data.WriteString(name); data.WriteBool(false); + data.WriteUint64(1); + data.WriteUint32(1); + data.WriteUint32(2); int ret = screenSessionManagerClientStub_->HandleOnScreenConnectionChanged(data, reply); EXPECT_EQ(ret, 0); } @@ -1014,5 +1017,21 @@ HWTEST_F(ScreenSessionManagerClientStubTest, HandleOnScreenModeChanged, TestSize auto ret = screenSessionManagerClientStub_->HandleOnScreenModeChanged(data, reply); EXPECT_EQ(ret, 0); } + +/** + * @tc.name: HandleOnAnimationFinish + * @tc.desc: HandleOnAnimationFinish test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerClientStubTest, HandleOnAnimationFinish, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + + data.WriteInterfaceToken(ScreenSessionManagerClientStub::GetDescriptor()); + ASSERT_TRUE(screenSessionManagerClientStub_ != nullptr); + auto ret = screenSessionManagerClientStub_->HandleOnAnimationFinish(data, reply); + EXPECT_EQ(ret, 0); +} } // namespace Rosen } // namespace OHOS diff --git a/window_scene/test/dms_unittest/screen_session_manager_client_test.cpp b/window_scene/test/dms_unittest/screen_session_manager_client_test.cpp index ac1402308d5f6bbfb805b3c30309cd438303c580..6bad2646c6efbeb308da89505cc99e752c9d40f3 100644 --- a/window_scene/test/dms_unittest/screen_session_manager_client_test.cpp +++ b/window_scene/test/dms_unittest/screen_session_manager_client_test.cpp @@ -1916,5 +1916,66 @@ HWTEST_F(ScreenSessionManagerClientTest, GetScreenSnapshotWithAllWindows02, Test EXPECT_EQ(res, nullptr); screenSessionManagerClient_->screenSessionMap_.clear(); } + +/** + * @tc.name: NotifySwitchUserAnimationFinish + * @tc.desc: NotifySwitchUserAnimationFinish test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerClientTest, NotifySwitchUserAnimationFinish, TestSize.Level1) +{ + sptr client = sptr::MakeSptr(); + ASSERT_NE(client, nullptr); + client->ConnectToServer(); + + + std::string desc1 = "desc1"; + std::string desc2 = "desc2"; + std::string desc3 = "desc3"; + client->NotifySwitchUserAnimationFinish(desc1); + + client->animateFinishDescriptionSet_.insert(desc2); + client->animateFinishDescriptionSet_.insert(desc3); + + logMsg.clear(); + client->NotifySwitchUserAnimationFinish(desc1); + EXPECT_TRUE(logMsg.find("not find description in map") != std::string::npos); + + client->NotifySwitchUserAnimationFinish(desc2); + EXPECT_NE(client->animateFinishNotificationSet_.find(desc2), client->animateFinishNotificationSet_.end()); + + logMsg.clear(); + client->NotifySwitchUserAnimationFinish(desc3); + EXPECT_TRUE(logMsg.find("notify all animate finished") != std::string::npos); + logMsg.clear(); + EXPECT_TRUE(client->animateFinishNotificationSet_.empty()); + + + client->screenSessionManager_ = nullptr; + client->NotifySwitchUserAnimationFinish(desc2); + client->NotifySwitchUserAnimationFinish(desc3); + EXPECT_TRUE(logMsg.find("screenSessionManager_ is null") != std::string::npos); + logMsg.clear(); +} + +/** + * @tc.name: RegisterSwitchUserAnimationNotification + * @tc.desc: RegisterSwitchUserAnimationNotification test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerClientTest, RegisterSwitchUserAnimationNotification, TestSize.Level1) +{ + sptr client = sptr::MakeSptr(); + ASSERT_NE(client, nullptr); + client->ConnectToServer(); + + std::string desc1 = "desc1"; + std::string desc2 = "desc2"; + client->RegisterSwitchUserAnimationNotification(desc1); + EXPECT_NE(client->animateFinishDescriptionSet_.find(desc1), client->animateFinishDescriptionSet_.end()); + client->RegisterSwitchUserAnimationNotification(desc1); + EXPECT_NE(client->animateFinishDescriptionSet_.find(desc1), client->animateFinishDescriptionSet_.end()); + EXPECT_EQ(client->animateFinishDescriptionSet_.size(), 1); +} } // namespace Rosen } // namespace OHOS diff --git a/window_scene/test/dms_unittest/screen_session_manager_proxy_test.cpp b/window_scene/test/dms_unittest/screen_session_manager_proxy_test.cpp index dbee53a305ba7a8e5c73275f89692bbf97c4050c..321f904bd0d74e762fe3d87163a9711cd9558354 100644 --- a/window_scene/test/dms_unittest/screen_session_manager_proxy_test.cpp +++ b/window_scene/test/dms_unittest/screen_session_manager_proxy_test.cpp @@ -2205,5 +2205,31 @@ HWTEST_F(ScreenSessionManagerProxyTest, SetScreenPrivacyWindowTagSwitch, Functio EXPECT_TRUE(logMsg.find("remote is null") != std::string::npos); LOG_SetCallback(nullptr); } + +/** + * @tc.name: NotifySwitchUserAnimationFinish + * @tc.desc: NotifySwitchUserAnimationFinish test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerProxyTest, NotifySwitchUserAnimationFinish, TestSize.Level1) +{ + MockMessageParcel::ClearAllErrorFlag(); + auto proxy = sptr::MakeSptr(nullptr); + proxy->NotifySwitchUserAnimationFinish(); + + sptr remoteMocker = sptr::MakeSptr(); + proxy = sptr::MakeSptr(remoteMocker); + MockMessageParcel::ClearAllErrorFlag(); + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); + ASSERT_NE(proxy, nullptr); + proxy->NotifySwitchUserAnimationFinish(); + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false); + ASSERT_NE(proxy, nullptr); + remoteMocker->SetRequestResult(ERR_INVALID_DATA); + proxy->NotifySwitchUserAnimationFinish(); + remoteMocker->SetRequestResult(ERR_NONE); + proxy->NotifySwitchUserAnimationFinish(); + MockMessageParcel::ClearAllErrorFlag(); +} } } \ No newline at end of file diff --git a/window_scene/test/dms_unittest/screen_session_manager_stub_test.cpp b/window_scene/test/dms_unittest/screen_session_manager_stub_test.cpp index 14783875b156dc32d0148ebccccaff9d98c3166c..95094088d59baa041b8439619bcf7f2cdf07c4fb 100644 --- a/window_scene/test/dms_unittest/screen_session_manager_stub_test.cpp +++ b/window_scene/test/dms_unittest/screen_session_manager_stub_test.cpp @@ -3332,6 +3332,24 @@ HWTEST_F(ScreenSessionManagerStubTest, SetScreenPrivacyWindowTagSwitch, TestSize int res = stub_->OnRemoteRequest(code, data, reply, option); EXPECT_EQ(res, ERR_NONE); } + +/** + * @tc.name: NotifySwitchUserAnimationFinish + * @tc.desc: normal function, TRANS_ID_NOTIFY_SWITCH_USER_ANIMATION_FINISH test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerStubTest, NotifySwitchUserAnimationFinish, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + std::vector screenIds; + + data.WriteInterfaceToken(ScreenSessionManagerStub::GetDescriptor()); + uint32_t code = static_cast(DisplayManagerMessage::TRANS_ID_NOTIFY_SWITCH_USER_ANIMATION_FINISH); + int res = stub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(res, ERR_NONE); +} } } } \ No newline at end of file diff --git a/window_scene/test/dms_unittest/screen_session_manager_test.cpp b/window_scene/test/dms_unittest/screen_session_manager_test.cpp index 202c0cd11893aadfae5f818465b40f4c26dcb34e..080f4d03ae18a965ccf875b35deee8d92962de7a 100644 --- a/window_scene/test/dms_unittest/screen_session_manager_test.cpp +++ b/window_scene/test/dms_unittest/screen_session_manager_test.cpp @@ -134,6 +134,28 @@ HWTEST_F(ScreenSessionManagerTest, RegisterDisplayManagerAgent, TestSize.Level1) EXPECT_EQ(DMError::DM_OK, ssm_->UnregisterDisplayManagerAgent(displayManagerAgent, type)); } +/** + * @tc.name: CanEnterCoordinationRecording + * @tc.desc: CanEnterCoordinationRecording test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, CanEnterCoordinationRecording, TestSize.Level3) +{ + ASSERT_NE(ssm_, nullptr); + ssm_->virtualScreenCount_ = 1; + ssm_->hdmiScreenCount_ = 0; + + sptr displayManagerAgent = new(std::nothrow) DisplayManagerAgentDefault(); + VirtualScreenOption virtualOption; + virtualOption.name_ = "createVirtualOptionRecord"; + virtualOption.virtualScreenType_ = VirtualScreenType::SCREEN_RECORDING; + auto screenId = ssm_->CreateVirtualScreen(virtualOption, displayManagerAgent->AsObject()); + auto ret = ssm_->CanEnterCoordination(); + EXPECT_EQ(ret, DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_RECORDING); + ssm_->DestroyVirtualScreen(screenId) +} + + /** * @tc.name: WakeupBegin * @tc.desc: WakeupBegin test @@ -6005,6 +6027,65 @@ HWTEST_F(ScreenSessionManagerTest, IsScreenCasting, Function | SmallTest | Level ASSERT_EQ(ret, false); } +/** + * @tc.name: CanEnterCoordination01 + * @tc.desc: CanEnterCoordination01 test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, CanEnterCoordination01, Function | SmallTest | Level3) +{ + ASSERT_NE(ssm_, nullptr); + ssm_->virtualScreenCount_ = 0; + ssm_->hdmiScreenCount_ = 1; + auto ret = ssm_->CanEnterCoordination(); + EXPECT_EQ(ret, DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_WIRED_CASTING); + + ssm_->virtualScreenCount_ = 0; + ssm_->hdmiScreenCount_ = 0; + auto ret = ssm_->CanEnterCoordination(); + EXPECT_EQ(ret, DMError::DM_OK); +} + +/** + * @tc.name: CanEnterCoordination02 + * @tc.desc: CanEnterCoordination02 test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, CanEnterCoordination02, Function | SmallTest | Level3) +{ + ASSERT_NE(ssm_, nullptr); + ssm_->screenSessionMap_[50] = nullptr; + ssm_->virtualScreenCount_ = 1; + ssm_->hdmiScreenCount_ = 0; + + sptr displayManagerAgent = new(std::nothrow) DisplayManagerAgentDefault(); + VirtualScreenOption virtualOption; + virtualOption.name_ = "createVirtualOption"; + virtualOption.virtualScreenType_ = VirtualScreenType::SCREEN_CASTING; + auto screenId = ssm_->CreateVirtualScreen(virtualOption, displayManagerAgent->AsObject()); + auto ret = ssm_->CanEnterCoordination(); + EXPECT_EQ(ret, DMError::DM_ERROR_NOT_SUPPORT_COOR_WHEN_WIRLESS_CASTING); + ssm_->DestroyVirtualScreen(screenId) +} + +/** + * @tc.name: CanEnterCoordination03 + * @tc.desc: CanEnterCoordination03 test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, CanEnterCoordination03, Function | SmallTest | Level3) +{ + ASSERT_NE(ssm_, nullptr); + auto oldMap = ssm_->screenSessionMap_; + std::map> newScreenSessionMap_{}; + ssm_->screenSessionMap_ = newScreenSessionMap_; + ssm_->virtualScreenCount_ = 1; + ssm_->hdmiScreenCount_ = 0; + auto ret = ssm_->CanEnterCoordination(); + EXPECT_EQ(ret, DMError::DM_OK); + ssm_->screenSessionMap_ = oldMap; +} + /** * @tc.name: GetCameraPosition * @tc.desc: GetCameraPosition diff --git a/window_scene/test/dms_unittest/screen_session_manager_test2.cpp b/window_scene/test/dms_unittest/screen_session_manager_test2.cpp index e8c73ff2ce8a7581244e8226b64c41bcbaaba460..f318ae02bcb90e030b71f15f1e05f2917c701f51 100644 --- a/window_scene/test/dms_unittest/screen_session_manager_test2.cpp +++ b/window_scene/test/dms_unittest/screen_session_manager_test2.cpp @@ -38,6 +38,10 @@ constexpr uint32_t G_STATUS_WIDTH = 3184; const ScreenId SCREENID = 1000; constexpr uint32_t EXCEPTION_DPI = 10; constexpr uint32_t PC_MODE_DPI = 304; +constexpr ScreenId SCREEN_ID_FULL = 0; +constexpr ScreenId SCREEN_ID_MAIN = 5; +const bool CORRECTION_ENABLE = system::GetIntParameter("const.system.sensor_correction_enable", 0) == 1; +bool g_isPcDevice = ScreenSceneConfig::GetExternalScreenDefaultMode() == "none"; } namespace { std::string g_errLog; @@ -79,6 +83,67 @@ void ScreenSessionManagerTest::TearDown() } namespace { + +/** + * @tc.name: SetScreenPowerForFold01 + * @tc.desc: SetScreenPowerForFold test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, SetScreenPowerForFold01, TestSize.Level1) +{ + // 内屏预上电 + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + sptr ssm = sptr::MakeSptr(); + ssm->SetRSScreenPowerStatus(SCREEN_ID_FULL, ScreenPowerStatus::POWER_STATUS_ON_ADVANCED); + + // 下电 + ssm->lastPowerForAllStatus_.store(ScreenPowerStatus::POWER_STATUS_ON_ADVANCED); + ssm->lastScreenId_.store(SCREEN_ID_FULL); + ssm->SetScreenPowerForFold(SCREEN_ID_FULL, ScreenPowerStatus::POWER_STATUS_OFF); + if (FoldScreenStateInternel::IsSingleDisplayFoldDevice()) { + EXPECT_TRUE(g_errLog.find("set advancedOn powerStatus off") != std::string::npos); + } else { + EXPECT_TRUE(g_errLog.find("set advancedOn powerStatus off") == std::string::npos); + } +} + +/** + * @tc.name: SetScreenPowerForFold02 + * @tc.desc: SetScreenPowerForFold test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, SetScreenPowerForFold02, TestSize.Level1) +{ + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + sptr ssm = sptr::MakeSptr(); + ssm->SetRSScreenPowerStatus(SCREEN_ID_FULL, ScreenPowerStatus::POWER_STATUS_ON_ADVANCED); + + ssm->lastPowerForAllStatus_.store(ScreenPowerStatus::POWER_STATUS_OFF); + ssm->lastScreenId_.store(SCREEN_ID_FULL); + ssm->SetScreenPowerForFold(SCREEN_ID_FULL, ScreenPowerStatus::POWER_STATUS_OFF); + EXPECT_TRUE(g_errLog.find("set advancedOn powerStatus off") == std::string::npos); +} + +/** + * @tc.name: SetScreenPowerForFold03 + * @tc.desc: SetScreenPowerForFold test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, SetScreenPowerForFold03, TestSize.Level1) +{ + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + sptr ssm = sptr::MakeSptr(); + ssm->SetRSScreenPowerStatus(SCREEN_ID_FULL, ScreenPowerStatus::POWER_STATUS_ON_ADVANCED); + + ssm->lastPowerForAllStatus_.store(ScreenPowerStatus::POWER_STATUS_ON_ADVANCED); + ssm->lastScreenId_.store(SCREEN_ID_MAIN); + ssm->SetScreenPowerForFold(SCREEN_ID_FULL, ScreenPowerStatus::POWER_STATUS_OFF); + EXPECT_TRUE(g_errLog.find("set advancedOn powerStatus off") == std::string::npos); +} + /** * @tc.name: SwitchScrollParam01 * @tc.desc: SwitchScrollParam test @@ -967,6 +1032,32 @@ HWTEST_F(ScreenSessionManagerTest, SetScreenPrivacyWindowTagSwitch002, TestSize. EXPECT_EQ(ret, DMError::DM_OK); } +/** + * @tc.name: UpdateSuperFoldRefreshRate + * @tc.desc: UpdateSuperFoldRefreshRate test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, UpdateSuperFoldRefreshRate, TestSize.Level1) +{ + if (!FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { + GTEST_SKIP(); + } + g_errLog.clear(); + uint32_t tempRefreshRate = 60; + sptr screenSession = nullptr; + ssm_->UpdateSuperFoldRefreshRate(screenSession, tempRefreshRate); + EXPECT_TRUE(g_errLog.find("screenSession is nullptr") != std::string::npos); + + ScreenId screenId = 1050; + DMRect area{0, 0, 600, 800}; + screenSession = new (std::nothrow) ScreenSession(screenId, ScreenProperty(), 0); + sptr fakescreenSession = nullptr; + screenSession->SetFakeScreenSession(fakescreenSession); + ssm_->UpdateSuperFoldRefreshRate(screenSession, tempRefreshRate); + EXPECT_TRUE(g_errLog.find("fakeScreenSession is nullptr") != std::string::npos); + g_errLog.clear(); +} + /** * @tc.name: OnVerticalChangeBoundsWhenSwitchUser * @tc.desc: OnVerticalChangeBoundsWhenSwitchUser test @@ -984,7 +1075,7 @@ HWTEST_F(ScreenSessionManagerTest, OnVerticalChangeBoundsWhenSwitchUser, TestSiz constexpr float SECONDARY_ROTATION_90 = 90.0F; screenProperty.SetRotation(SECONDARY_ROTATION_90); RRect bounds = screenProperty.GetBounds(); - ssm_->OnVerticalChangeBoundsWhenSwitchUser(screenSession); + ssm_->OnVerticalChangeBoundsWhenSwitchUser(screenSession, FoldDisplayMode::UNKNOWN); RRect afterbounds = screenProperty.GetBounds(); EXPECT_EQ(bounds.rect_.GetHeight(), bounds.rect_.GetWidth()); } @@ -1003,6 +1094,45 @@ HWTEST_F(ScreenSessionManagerTest, SetLandscapeLockStatus01, TestSize.Level1) EXPECT_TRUE(g_errLog.find("permission denied!") != std::string::npos); } +chaos +/** + * @tc.name: NotifyDisplayChangedByUid + * @tc.desc: NotifyDisplayChangedByUid test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, NotifyDisplayChangedByUid, TestSize.Level1) +{ + g_errLog.clear(); + ASSERT_NE(ssm, nullptr); + ssm_->screenSessionMap_.clear(); + ScreenId screenId = 1050; + sptr screenSession = new (std::nothrow) ScreenSession(screenId, ScreenProperty(), 0); + ASSERT_NE(screenSession, nullptr); + ssm_->screenSessionMap_[screenId] = screenSession; + std::map> screenSessionMapCopy = ssm_->screenSessionMap_; + ssm_->NotifyDisplayChangedByUid(screenSessionMapCopy, DisplayChangeEvent::DISPLAY_SIZE_CHANGED, 2002); + ssm_->screenSessionMap_[1051] = nullptr; + ssm_->NotifyDisplayChangedByUid(screenSessionMapCopy, DisplayChangeEvent::DISPLAY_SIZE_CHANGED, 2002); + EXPECT_TRUE(g_errLog.find("screenSession is nullptr") != std::string::npos); +} + +/** + * @tc.name: NotifyDisplayChangedByUidInner + * @tc.desc: NotifyDisplayChangedByUidInner test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, NotifyDisplayChangedByUidInner, TestSize.Level1) +{ + g_errLog.clear(); + ASSERT_NE(ssm, nullptr); + ScreenId screenId = 1050; + sptr screenSession = new (std::nothrow) ScreenSession(screenId, ScreenProperty(), 0); + ASSERT_NE(screenSession, nullptr); + ssm_->NotifyDisplayChangedByUid((screenSession->ConvertToDisplayInfo(), + DisplayChangeEvent::DISPLAY_SIZE_CHANGED, 2002); + EXPECT_TRUE(g_errLog.find("uid") != std::string::npos); +} + /** * @tc.name: SynchronizePowerStatusPermissionDenied * @tc.desc: SynchronizePowerStatus test permission denied. @@ -1424,10 +1554,15 @@ HWTEST_F(ScreenSessionManagerTest, ChangeMirrorScreenConfig, TestSize.Level1) { */ HWTEST_F(ScreenSessionManagerTest, RegisterSettingDuringCallStateObserver, Function | SmallTest | Level3) { + if (g_isPcDevice) { + GTEST_SKIP(); + } ASSERT_NE(ssm_, nullptr); + ssm_->RegisterSettingDuringCallStateObserver(); if (FoldScreenStateInternel::IsDualDisplayFoldDevice() && ScreenSceneConfig::IsSupportDuringCall()) { - ssm_->RegisterSettingDuringCallStateObserver(); ASSERT_NE(ScreenSettingHelper::duringCallStateObserver_, nullptr); + } else { + ASSERT_EQ(ScreenSettingHelper::duringCallStateObserver_, nullptr); } } @@ -1439,11 +1574,32 @@ HWTEST_F(ScreenSessionManagerTest, RegisterSettingDuringCallStateObserver, Funct HWTEST_F(ScreenSessionManagerTest, UpdateDuringCallState, Function | SmallTest | Level3) { ASSERT_NE(ssm_, nullptr); + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + ssm_->UpdateDuringCallState(); if (FoldScreenStateInternel::IsDualDisplayFoldDevice() && ScreenSceneConfig::IsSupportDuringCall()) { - ssm_->UpdateDuringCallState(); ASSERT_EQ(ssm_->duringCallState_, 0); + } else { + EXPECT_TRUE(g_errLog.find("get setting during call state failed") == std::string::npos); } + LOG_SetCallback(nullptr); } + +/** + * @tc.name: SetDuringCallState + * @tc.desc: SetDuringCallState + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, SetDuringCallState, TestSize.Level1) +{ + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + bool value = false; + ssm_->SetDuringCallState(value); + EXPECT_TRUE(g_errLog.find("set during call state to") != std::string::npos); + LOG_SetCallback(nullptr); +} + /** * @tc.name: DisconnectScreenIfScreenInfoNull * @tc.desc: DisconnectScreenIfScreenInfoNull @@ -1481,6 +1637,202 @@ HWTEST_F(ScreenSessionManagerTest, SetDefaultScreenModeWhenCreateMirror, TestSiz #undef FOLD_ABILITY_ENABLE } +/** + * @tc.name: GetOldDisplayModeRotation + * @tc.desc: GetOldDisplayModeRotation + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, GetOldDisplayModeRotation, TestSize.Level1) +{ + auto foldController = sptr::MakeSptr(ssm_->displayInfoMutex_, + ssm_->screenPowerTaskScheduler_); + ASSERT_NE(foldController, nullptr); + DisplayPhysicalResolution physicalSize_full; + physicalSize_full.foldDisplayMode_ = FoldDisplayMode::FULL; + physicalSize_full.physicalWidth_ = 2048; + physicalSize_full.physicalHeight_ = 2232; + DisplayPhysicalResolution physicalSize_main; + physicalSize_main.foldDisplayMode_ = FoldDisplayMode::MAIN; + physicalSize_main.physicalWidth_ = 1008; + physicalSize_main.physicalHeight_ = 2232; + DisplayPhysicalResolution physicalSize_global_full; + physicalSize_global_full.foldDisplayMode_ = FoldDisplayMode::GLOBAL_FULL; + physicalSize_global_full.physicalWidth_ = 3184; + physicalSize_global_full.physicalHeight_ = 2232; + ScreenSceneConfig::displayPhysicalResolution_.emplace_back(physicalSize_full); + ScreenSceneConfig::displayPhysicalResolution_.emplace_back(physicalSize_main); + ScreenSceneConfig::displayPhysicalResolution_.emplace_back(physicalSize_global_full); + auto foldPolicy = foldController->GetFoldScreenPolicy(DisplayDeviceType::SECONDARY_DISPLAY_DEVICE); + ASSERT_NE(foldPolicy, nullptr); + foldPolicy->lastDisplayMode_ = FoldDisplayMode::MAIN; + foldController->foldScreenPolicy_ = foldPolicy; + ssm_->foldScreenController_ = foldController; + std::unordered_map rotationCorrectionMap; + rotationCorrectionMap.insert({FoldDisplayMode::GLOBAL_FULL, 3}); + ssm_->rotationCorrectionMap_ = rotationCorrectionMap; + Rotation rotation = ssm_->GetOldDisplayModeRotation(FoldDisplayMode::MAIN, Rotation::ROTATION_0); + EXPECT_EQ(rotation, Rotation::ROTATION_0); + rotation = ssm_->GetOldDisplayModeRotation(FoldDisplayMode::GLOBAL_FULL, Rotation::ROTATION_0); + if (CORRECTION_ENABLE) { + EXPECT_EQ(rotation, Rotation::ROTATION_90); + } else { + EXPECT_EQ(rotation, Rotation::ROTATION_0); + } +} + +/** + * @tc.name: SwapScreenWeightAndHeight + * @tc.desc: SwapScreenWeightAndHeight + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, SwapScreenWeightAndHeight, TestSize.Level1) +{ + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + sptr screenSession = nullptr; + ssm_->SwapScreenWeightAndHeight(screenSession); + EXPECT_TRUE(g_errLog.find("screenSession is null") != std::string::npos); + screenSession = sptr::MakeSptr(); + ScreenProperty property; + RRect bounds; + bounds.rect_.width_ = 100; + bounds.rect_.height_ = 200; + property.SetBounds(bounds); + screenSession->SetScreenProperty(property); + ssm_->SwapScreenWeightAndHeight(screenSession); + auto afterBounds = screenSession->GetScreenProperty().GetBounds(); + EXPECT_EQ(afterBounds.rect_.width_, bounds.rect_.height_); + EXPECT_EQ(afterBounds.rect_.height_, bounds.rect_.width_); + g_errLog.clear(); +} + +/** + * @tc.name: HandleScreenRotationAndBoundsWhenSetClient + * @tc.desc: HandleScreenRotationAndBoundsWhenSetClient + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, HandleScreenRotationAndBoundsWhenSetClient, TestSize.Level1) +{ + auto foldController = sptr::MakeSptr(ssm_->displayInfoMutex_, + ssm_->screenPowerTaskScheduler_); + ASSERT_NE(foldController, nullptr); + auto foldPolicy = foldController->GetFoldScreenPolicy(DisplayDeviceType::SINGLE_DISPLAY_DEVICE); + ASSERT_NE(foldPolicy, nullptr); + foldPolicy->lastDisplayMode_ = FoldDisplayMode::GLOBAL_FULL; + foldController->foldScreenPolicy_ = foldPolicy; + ssm_->foldScreenController_ = foldController; + std::unordered_map rotationCorrectionMap; + rotationCorrectionMap.insert({FoldDisplayMode::GLOBAL_FULL, 3}); + ssm_->rotationCorrectionMap_ = rotationCorrectionMap; + ScreenId id = 123; + sptr screenSession = sptr::MakeSptr(id, ScreenProperty(), 0); + if (FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { + screenSession->SetRotation(Rotation::ROTATION_0); + ssm_->HandleScreenRotationAndBoundsWhenSetClient(screenSession); + EXPECT_EQ(screenSession->GetRotation(), Rotation::ROTATION_0); + screenSession->SetRotation(Rotation::ROTATION_180); + ssm_->HandleScreenRotationAndBoundsWhenSetClient(screenSession); + EXPECT_EQ(screenSession->GetRotation(), Rotation::ROTATION_0); + screenSession->SetRotation(Rotation::ROTATION_270); + ssm_->HandleScreenRotationAndBoundsWhenSetClient(screenSession); + EXPECT_EQ(screenSession->GetRotation(), Rotation::ROTATION_0); + } else { + screenSession->SetRotation(Rotation::ROTATION_270); + ssm_->HandleScreenRotationAndBoundsWhenSetClient(screenSession); + EXPECT_EQ(screenSession->GetRotation(), Rotation::ROTATION_270); + screenSession->SetRotation(Rotation::ROTATION_270); + foldPolicy->lastDisplayMode_ = FoldDisplayMode::UNKNOWN; + ssm_->HandleScreenRotationAndBoundsWhenSetClient(screenSession); + EXPECT_EQ(screenSession->GetRotation(), Rotation::ROTATION_270); + screenSession->SetRotation(Rotation::ROTATION_0); + ssm_->HandleScreenRotationAndBoundsWhenSetClient(screenSession); + EXPECT_EQ(screenSession->GetRotation(), Rotation::ROTATION_0); + } +} + +/** + * @tc.name: RemoveRotationCorrection + * @tc.desc: RemoveRotationCorrection + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, RemoveRotationCorrection, TestSize.Level1) +{ + auto afterRotation = ssm_->RemoveRotationCorrection(Rotation::ROTATION_270); + EXPECT_EQ(afterRotation, Rotation::ROTATION_270); +} + +/** + * @tc.name: GetConfigCorrectionByDisplayMode + * @tc.desc: GetConfigCorrectionByDisplayMode + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, GetConfigCorrectionByDisplayMode, TestSize.Level1) +{ + ssm_->rotationCorrectionMap_.clear(); + bool correctionEnable = system::GetIntParameter("const.system.sensor_correction_enable", 0) == 1; + if (correctionEnable) { + auto rotation = ssm_->GetConfigCorrectionByDisplayMode(FoldDisplayMode::MAIN); + EXPECT_EQ(rotation, Rotation::ROTATION_0); + std::unordered_map rotationCorrectionMap; + rotationCorrectionMap.insert({FoldDisplayMode::MAIN, 3}); + ssm_->rotationCorrectionMap_ = rotationCorrectionMap; + rotation = ssm_->GetConfigCorrectionByDisplayMode(FoldDisplayMode::MAIN); + EXPECT_EQ(rotation, Rotation::ROTATION_270); + + } else { + auto rotation = ssm_->GetConfigCorrectionByDisplayMode(FoldDisplayMode::MAIN); + EXPECT_EQ(rotation, Rotation::ROTATION_0); + } +} + +/** + * @tc.name: InitRotationCorrectionMap + * @tc.desc: rotationCorrectionMap not null + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, InitRotationCorrectionMap01, TestSize.Level1) +{ + ssm_->rotationCorrectionMap_.clear(); + std::unordered_map rotationCorrectionMap; + rotationCorrectionMap.insert({FoldDisplayMode::MAIN, 3}); + ssm_->rotationCorrectionMap_ = rotationCorrectionMap; + ssm_->InitRotationCorrectionMap(""); + EXPECT_TRUE(ssm_->rotationCorrectionMap_.find(FoldDisplayMode::MAIN) != ssm_->rotationCorrectionMap_.end()); + ssm_->rotationCorrectionMap_.clear(); + std::string config = "1,0;2,0;5,3;"; + ssm_->InitRotationCorrectionMap(config); + EXPECT_EQ(ssm_->rotationCorrectionMap_[FoldDisplayMode::GLOBAL_FULL], 3); +} + +/** + * @tc.name: InitRotationCorrectionMap + * @tc.desc: split failed + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, InitRotationCorrectionMap02, TestSize.Level1) +{ + ssm_->rotationCorrectionMap_.clear(); + ssm_->InitRotationCorrectionMap(""); + EXPECT_TRUE(ssm_->rotationCorrectionMap_.empty()); + ssm_->rotationCorrectionMap_.clear(); + std::string config = ";;"; + ssm_->InitRotationCorrectionMap(config); + EXPECT_TRUE(ssm_->rotationCorrectionMap_.empty()); +} + +/** + * @tc.name: InitRotationCorrectionMap + * @tc.desc: InitRotationCorrectionMap + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, InitRotationCorrectionMap03, TestSize.Level1) +{ + ssm_->rotationCorrectionMap_.clear(); + std::string config = "1,0,1;1,0;2,0;5,3;3,a;a,a"; + ssm_->InitRotationCorrectionMap(config); + EXPECT_EQ(ssm_->rotationCorrectionMap_[FoldDisplayMode::GLOBAL_FULL], 3); +} + /** * @tc.name: RecoverDefaultScreenModeInner * @tc.desc: RecoverDefaultScreenModeInner @@ -1502,6 +1854,220 @@ HWTEST_F(ScreenSessionManagerTest, RecoverDefaultScreenModeInner, TestSize.Level } #undef FOLD_ABILITY_ENABLE } + +/** + * @tc.name: AddOrUpdateUserDisplayNode + * @tc.desc: AddOrUpdateUserDisplayNode + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, AddOrUpdateUserDisplayNode, TestSize.Level1) +{ + RSDisplayNodeConfig config; + auto node = std::make_shared(config); + ASSERT_NE(ssm_, nullptr); + ssm_->AddOrUpdateUserDisplayNode(100, 1, node); + + auto userIt = ssm_->userDisplayNodeMap_.find(100); + ASSERT_NE(userIt, ssm_->userDisplayNodeMap_.end()); + + auto& screenMap = userIt->second; + auto screenIt = screenMap.find(1); + ASSERT_NE(screenIt, screenMap.end()); + EXPECT_EQ(screenIt->second, node); +} + +/** + * @tc.name: RemoveUserDisplayNode + * @tc.desc: RemoveUserDisplayNode + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, RemoveUserDisplayNode, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + int32_t user1 = 100; + int32_t user2 = 200; + ScreenId screen1 = 1; + ScreenId screen2 = 2; + RSDisplayNodeConfig config; + auto node1 = std::make_shared(config); + auto node2 = std::make_shared(config); + ssm_->userDisplayNodeMap_[user1].insert_or_assign(screen1, node1); + ssm_->RemoveUserDisplayNode(user2, screen1); + EXPECT_EQ(ssm_->userDisplayNodeMap_.size(), 1); + + ssm_->userDisplayNodeMap_[user2].insert_or_assign(screen2, node2); + ssm_->RemoveUserDisplayNode(user2, screen1); + EXPECT_EQ(ssm_->userDisplayNodeMap_.size(), 2); + + ssm_->userDisplayNodeMap_[user2].insert_or_assign(screen1, node2); + ssm_->RemoveUserDisplayNode(user2, screen1); + auto findRes = ssm_->userDisplayNodeMap_.find(user2); + EXPECT_NE(findRes, ssm_->userDisplayNodeMap_.end()); + EXPECT_EQ(findRes->second.find(screen1), findRes->second.end()); + + ssm_->RemoveUserDisplayNode(user2, screen2); + EXPECT_EQ(ssm_->userDisplayNodeMap_.find(user2), ssm_->userDisplayNodeMap_.end()); +} + +/** + * @tc.name: GetUserDisplayNodeMap + * @tc.desc: GetUserDisplayNodeMap + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, GetUserDisplayNodeMap, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + int32_t user1 = 100; + ScreenId screen1 = 1; + RSDisplayNodeConfig config; + auto node1 = std::make_shared(config); + ssm_->userDisplayNodeMap_[user1].insert_or_assign(screen1, node1); + auto res = ssm_->GetUserDisplayNodeMap(user1); + auto it = res.find(screen1); + ASSERT_NE(it, res.end()); + ASSERT_EQ(it->second, node1); +} + +/** + * @tc.name: SwitchUserDealUserDisplayNode + * @tc.desc: SwitchUserDealUserDisplayNode + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, SwitchUserDealUserDisplayNode, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + int32_t userId = 100; + ScreenId sc1 = 1; + ScreenId sc2 = 2; + ScreenId sc3 = 3; + ScreenId sc4 = 4; + + auto realSession1 = sptr::MakeSptr(); + realSession1->SetScreenId(sc1); + realSession1->SetIsRealScreen(true); + + auto realSession2 = sptr::MakeSptr(); + realSession2->SetScreenId(sc2); + realSession2->SetIsRealScreen(true); + + auto virtualSession = sptr::MakeSptr(); + virtualSession->SetScreenId(sc3); + virtualSession->SetIsRealScreen(false); + + ssm_->screenSessionMap_[sc1] = realSession1; + ssm_->screenSessionMap_[sc2] = realSession2; + ssm_->screenSessionMap_[sc3] = virtualSession; + + auto& userNodeMap = ssm_->userDisplayNodeMap_[userId]; + RSDisplayNodeConfig config; + auto presetNode = std::make_shared(config); + userNodeMap[sc1] = presetNode; + userNodeMap[sc4] = presetNode; + ssm_->SwitchUserDealUserDisplayNode(userId); + + // 验证结果 + auto& resultMap = ssm_->userDisplayNodeMap_[userId]; + EXPECT_EQ(resultMap[sc1], presetNode); + EXPECT_NE(resultMap.find(sc2), resultMap.end()); + EXPECT_NE(resultMap[sc2], nullptr); + EXPECT_NE(resultMap[sc2], presetNode); + EXPECT_EQ(resultMap.find(sc4), resultMap.end()); + EXPECT_EQ(resultMap.find(sc3), resultMap.end()); +} + +/** + * @tc.name: AddUserDisplayNodeOnTree + * @tc.desc: AddUserDisplayNodeOnTree + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, AddUserDisplayNodeOnTree, TestSize.Level1) +{ + g_errLog.clear(); + int32_t userId = 100; + ScreenId screenId1 = 1; + ScreenId screenId2 = 2; + RSDisplayNodeConfig config; + auto node1 = std::make_shared(config); + std::shared_ptr node2 = nullptr; + ssm_->userDisplayNodeMap_[userId].insert_or_assign(screenId1, node1); + ssm_->userDisplayNodeMap_[userId].insert_or_assign(screenId2, node2); + ssm_->AddUserDisplayNodeOnTree(userId); + + EXPECT_TRUE(g_errLog.find("userId: ") != std::string::npos); + g_errLog.clear(); +} + +/** + * @tc.name: RemoveUserDisplayNodeFromTree + * @tc.desc: RemoveUserDisplayNodeFromTree + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, RemoveUserDisplayNodeFromTree, TestSize.Level1) +{ + int32_t userId = 100; + ScreenId screenId1 = 1; + ScreenId screenId2 = 2; + RSDisplayNodeConfig config; + auto node1 = std::make_shared(config); + std::shared_ptr node2 = nullptr; + ssm_->userDisplayNodeMap_[userId].insert_or_assign(screenId1, node1); + ssm_->userDisplayNodeMap_[userId].insert_or_assign(screenId2, node2); + ssm_->AddUserDisplayNodeOnTree(userId); + g_errLog.clear(); + ssm_->RemoveUserDisplayNodeFromTree(userId); + EXPECT_TRUE(g_errLog.find("userId: ") != std::string::npos); + g_errLog.clear(); +} + +/** + * @tc.name: SetUserDisplayNodePositionZ + * @tc.desc: SetUserDisplayNodePositionZ + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, SetUserDisplayNodePositionZ, TestSize.Level1) +{ + g_errLog.clear(); + int32_t userId = 100; + float positionZ = 2.0f; + ScreenId screenId1 = 1; + ScreenId screenId2 = 2; + RSDisplayNodeConfig config; + auto node1 = std::make_shared(config); + std::shared_ptr node2 = nullptr; + ssm_->userDisplayNodeMap_[userId].insert_or_assign(screenId1, node1); + ssm_->userDisplayNodeMap_[userId].insert_or_assign(screenId2, node2); + ssm_->SetUserDisplayNodePositionZ(userId, positionZ); + + ASSERT_TRUE(g_errLog.find("positionZ:") != std::string::npos); + g_errLog.clear(); +} + +/** + * @tc.name: HandleNewUserDisplayNode + * @tc.desc: HandleNewUserDisplayNode + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, HandleNewUserDisplayNode, TestSize.Level1) { + ASSERT_NE(ssm_, nullptr); + int32_t oldUserId = 100; + int32_t newUserId = 200; + ssm_->currentUserId_ = oldUserId; + g_errLog.clear(); + + RSDisplayNodeConfig config; + auto oldUserNode = std::make_shared(config); + auto newUserNode = std::make_shared(config); + + ssm_->userDisplayNodeMap_[oldUserId][1] = oldUserNode; + float position = 5.0f; + oldUserNode->SetPositionZ(position); + newUserNode->SetPositionZ(position); + ssm_->HandleNewUserDisplayNode(newUserId, false); + EXPECT_TRUE(g_errLog.find("deal with userDisplayNode") != std::string::npos); + g_errLog.clear(); + EXPECT_TRUE(ssm_->userDisplayNodeMap_[newUserId].size() > 0); +} + } } } \ No newline at end of file diff --git a/window_scene/test/dms_unittest/screen_session_test.cpp b/window_scene/test/dms_unittest/screen_session_test.cpp index 9d96691c34e08ffdfd2858c802d70db67b568c1b..545d230bc26810e4344b5d587d9691a0149d7c5e 100644 --- a/window_scene/test/dms_unittest/screen_session_test.cpp +++ b/window_scene/test/dms_unittest/screen_session_test.cpp @@ -3900,7 +3900,7 @@ HWTEST_F(ScreenSessionTest, UpdateTouchBoundsAndOffset, TestSize.Level1) ScreenSessionReason::CREATE_SESSION_FOR_CLIENT); ASSERT_NE(screenSession, nullptr); - screenSession->UpdateTouchBoundsAndOffset(); + screenSession->UpdateTouchBoundsAndOffset(FoldDisplayMode::UNKNOWN); EXPECT_EQ(0, screenSession->property_.GetInputOffsetY()); GTEST_LOG_(INFO) << "ScreenSessionTest: UpdateTouchBoundsAndOffset end"; } @@ -4516,6 +4516,67 @@ HWTEST_F(ScreenSessionTest, FreezeScreen, TestSize.Level2) g_errLog.clear(); } +/** + * @tc.name: GetRotationCorrection + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, GetRotationCorrection, TestSize.Level1) +{ + sptr session = sptr::MakeSptr(); + ASSERT_NE(session, nullptr); + Rotation rotation = session->GetRotationCorrection(FoldDisplayMode::MAIN); + EXPECT_EQ(rotation, Rotation::ROTATION_0); + std::unordered_map rotationCorrectionMap; + rotationCorrectionMap.insert({FoldDisplayMode::MAIN, 3}); + session->SetRotationCorrectionMap(rotationCorrectionMap); + rotation = session->GetRotationCorrection(FoldDisplayMode::MAIN); + EXPECT_EQ(rotation, Rotation::ROTATION_270); + rotation = session->GetRotationCorrection(FoldDisplayMode::FULL); + EXPECT_EQ(rotation, Rotation::ROTATION_0); +} + +/** + * @tc.name: RemoveRotationCorrection + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, RemoveRotationCorrection, TestSize.Level1) +{ + sptr session = sptr::MakeSptr(); + ASSERT_NE(session, nullptr); + Rotation rotation = Rotation::ROTATION_270; + std::unordered_map rotationCorrectionMap; + rotationCorrectionMap.insert({FoldDisplayMode::MAIN, 3}); + session->SetRotationCorrectionMap(rotationCorrectionMap); + session->RemoveRotationCorrection(rotation, FoldDisplayMode::MAIN); + EXPECT_EQ(rotation, Rotation::ROTATION_0); + + rotation = Rotation::ROTATION_270; + session->RemoveRotationCorrection(rotation, FoldDisplayMode::FULL); + EXPECT_EQ(rotation, Rotation::ROTATION_270); + + rotation = static_cast(100); + session->RemoveRotationCorrection(rotation, FoldDisplayMode::FULL); + EXPECT_EQ(static_cast(rotation), 100); +} + +/** + * @tc.name: SetRotationCorrectionMap + * @tc.desc: test set and get + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, SetRotationCorrectionMap, TestSize.Level1) +{ + sptr session = sptr::MakeSptr(); + ASSERT_NE(session, nullptr); + std::unordered_map rotationCorrectionMap; + rotationCorrectionMap.insert({FoldDisplayMode::MAIN, 3}); + session->SetRotationCorrectionMap(rotationCorrectionMap); + auto correctionMap = session->GetRotationCorrectionMap(); + EXPECT_EQ(correctionMap[FoldDisplayMode::MAIN], 3); +} + /** * @tc.name: GetScreenSnapshotWithAllWindows01 * @tc.desc: GetScreenSnapshotWithAllWindows01 Test diff --git a/window_scene/test/dms_unittest/screen_setting_helper_test.cpp b/window_scene/test/dms_unittest/screen_setting_helper_test.cpp index 1da5d0cfce53a1e863d142490757e37ef059982e..d5033e6675f65c72124351bb2154647fdb300a50 100644 --- a/window_scene/test/dms_unittest/screen_setting_helper_test.cpp +++ b/window_scene/test/dms_unittest/screen_setting_helper_test.cpp @@ -28,6 +28,14 @@ namespace Rosen { namespace { constexpr uint32_t SLEEP_TIME_US = 100000; } +namespace { + std::string g_errLog; + void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char* tag, + const char* msg) + { + g_errLog += msg; + } +} class ScreenSettingHelperTest : public testing::Test { public: @@ -898,6 +906,17 @@ namespace { }; ScreenSettingHelper::RegisterSettingDuringCallStateObserver(func); ASSERT_NE(ScreenSettingHelper::duringCallStateObserver_, nullptr); + + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + bool flag1 = false; + auto func1 = [&flag1] (const std::string&) { + TLOGI(WmsLogTag::DMS, "UT test"); + flag1 = true; + }; + ScreenSettingHelper::RegisterSettingDuringCallStateObserver(func1); + EXPECT_TRUE(g_errLog.find("during call state observer is registered") != std::string::npos); + LOG_SetCallback(nullptr); } /** @@ -909,6 +928,12 @@ namespace { { ScreenSettingHelper::UnregisterSettingDuringCallStateObserver(); ASSERT_EQ(ScreenSettingHelper::duringCallStateObserver_, nullptr); + + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + ScreenSettingHelper::UnregisterSettingDuringCallStateObserver(); + EXPECT_TRUE(g_errLog.find("duringCallStateObserver_ is nullptr") != std::string::npos); + LOG_SetCallback(nullptr); } /** @@ -918,12 +943,15 @@ namespace { */ HWTEST_F(ScreenSettingHelperTest, GetSettingDuringCallStateTest, Function | SmallTest | Level3) { + if (!SceneBoardJudgement::IsSceneBoardEnabled()) { + return; + } ScreenSettingHelper screenSettingHelper = ScreenSettingHelper(); bool value = true; screenSettingHelper.SetSettingDuringCallState("during_call_state", false); screenSettingHelper.GetSettingDuringCallState(value); - ASSERT_FALSE(value); + ASSERT_TRUE(value); } } } // namespace Rosen diff --git a/window_scene/test/dms_unittest/secondary_display_fold_policy_test.cpp b/window_scene/test/dms_unittest/secondary_display_fold_policy_test.cpp index 1c8daec9dd43096530858c7f53c0d5cd58660b90..d472c5b255b1d4b52fb536ff4d816d6e59bd8da1 100644 --- a/window_scene/test/dms_unittest/secondary_display_fold_policy_test.cpp +++ b/window_scene/test/dms_unittest/secondary_display_fold_policy_test.cpp @@ -339,7 +339,7 @@ HWTEST_F(SecondaryDisplayFoldPolicyTest, SetStatusFullActiveRectAndTpFeature, Te ScreenProperty property = policy.screenProperty_; sptr screenSession = ScreenSessionManager::GetInstance().GetScreenSession(0); - policy.SetStatusFullActiveRectAndTpFeature(screenSession, property); + policy.SetStatusFullActiveRectAndTpFeature(screenSession, property, true); EXPECT_FALSE(policy.onBootAnimation_); } @@ -640,6 +640,9 @@ HWTEST_F(SecondaryDisplayFoldPolicyTest, SetStatusConditionalActiveRectAndTpFeat */ HWTEST_F(SecondaryDisplayFoldPolicyTest, InitPositionZInfosFeature, TestSize.Level1) { + if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { + GTEST_SKIP(); + } std::recursive_mutex displayInfoMutex; std::shared_ptr screenPowerTaskScheduler = nullptr; SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler); @@ -659,6 +662,9 @@ HWTEST_F(SecondaryDisplayFoldPolicyTest, InitPositionZInfosFeature, TestSize.Lev */ HWTEST_F(SecondaryDisplayFoldPolicyTest, UpdatePositionZForDualDisplayNodeFeature, TestSize.Level1) { + if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { + GTEST_SKIP(); + } std::recursive_mutex displayInfoMutex; std::shared_ptr screenPowerTaskScheduler = nullptr; SecondaryDisplayFoldPolicy policy(displayInfoMutex, screenPowerTaskScheduler); diff --git a/window_scene/test/dms_unittest/secondary_display_sensor_fold_state_manager_test.cpp b/window_scene/test/dms_unittest/secondary_display_sensor_fold_state_manager_test.cpp index 449a1b9f7c45ae273a3d42feb03df37781ff0cb9..89478d58ab2bfbbedf0de927175bfc37dfc647f6 100644 --- a/window_scene/test/dms_unittest/secondary_display_sensor_fold_state_manager_test.cpp +++ b/window_scene/test/dms_unittest/secondary_display_sensor_fold_state_manager_test.cpp @@ -235,6 +235,36 @@ HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, HandleAngleOrHallChange07, FoldStatus::FOLD_STATE_EXPAND_WITH_SECOND_EXPAND); } +/** + * @tc.name: HandleAngleOrHallChange08 + * @tc.desc: test halls size + * @tc.type: FUNC + */ +HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, HandleAngleOrHallChange08, TestSize.Level1) +{ + if (!FoldScreenStateInternel::IsSecondaryDisplayFoldDevice()) { + return; + } + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + std::vector angles = { 5, 5, 5 }; + std::vector halls = { 0, 1 }; + SecondaryDisplaySensorFoldStateManager manager; + g_errLog.clear(); + manager.HandleAngleOrHallChange(angles, halls, nullptr, false); + EXPECT_TRUE(g_errLog.find("hall change but posture not change") != std::string::npos); + angles = { 5, 5, 5 }; + halls = { 0, 0 }; + g_errLog.clear(); + manager.HandleAngleOrHallChange(angles, halls, nullptr, false); + EXPECT_FALSE(g_errLog.find("hall change but posture not change") != std::string::npos); + angles = { 4, 4, 4 }; + halls = { 1, 1 }; + g_errLog.clear(); + manager.HandleAngleOrHallChange(angles, halls, nullptr, false); + EXPECT_FALSE(g_errLog.find("hall change but posture not change") != std::string::npos); +} + /** * @tc.name: UpdateSwitchScreenBoundaryForLargeFoldDeviceAB * @tc.desc: test function : UpdateSwitchScreenBoundaryForLargeFoldDeviceAB @@ -380,6 +410,37 @@ HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, GetNextFoldStateHalf02, Tes EXPECT_EQ(static_cast(result8), 3); } +/** + * @tc.name: GetNextFoldStateHalf03 + * @tc.desc: test function : GetNextFoldStateHalf + * @tc.type: FUNC + */ +HWTEST_F(SecondaryDisplaySensorFoldStateManagerTest, GetNextFoldStateHalf03, TestSize.Level1) +{ + SecondaryDisplaySensorFoldStateManager manager; + int32_t allowUserSensorForLargeFoldDevice = 0; + FoldStatus state = FoldStatus::UNKNOWN; + float angel = 40.0F; + uint16_t hall = 0; + auto result = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice); + EXPECT_EQ(static_cast(result), 2); + + angel = 60.0F; + hall = 0; + result = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice); + EXPECT_EQ(static_cast(result), 3); + + angel = 40.0F; + hall = 1; + result = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice); + EXPECT_EQ(static_cast(result), 3); + + angel = 60.0F; + hall = 1; + result = manager.GetNextFoldStateHalf(angel, hall, state, allowUserSensorForLargeFoldDevice); + EXPECT_EQ(static_cast(result), 3); +} + /** * @tc.name: GetGlobalFoldState * @tc.desc: test function : GetGlobalFoldState diff --git a/window_scene/test/dms_unittest/setting_provider_test.cpp b/window_scene/test/dms_unittest/setting_provider_test.cpp index a938037cced29ec7c52256c1c99b57e048f14e2d..d9201030aa146c355126905e4bc02c2b5a88e19d 100644 --- a/window_scene/test/dms_unittest/setting_provider_test.cpp +++ b/window_scene/test/dms_unittest/setting_provider_test.cpp @@ -17,6 +17,7 @@ #include +#include "screen_session_manager.h" #include "setting_provider.h" using namespace testing; @@ -159,6 +160,36 @@ HWTEST_F(SettingProviderTest, PutStringValue02, TestSize.Level1) "settings.power.suspend_sources", updateFunc); EXPECT_EQ(SettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID).PutStringValue(key, value, needNotify), ERR_OK); } + +/** + * @tc.name: AssembleUriMultiUser + * @tc.desc: test function : AssembleUriMultiUser + * @tc.type: FUNC + */ +HWTEST_F(SettingProviderTest, AssembleUriMultiUser, TestSize.Level1) +{ + int32_t saveSettings = ScreenSessionManager::GetInstance().currentUserIdForSettings_; + ScreenSessionManager::GetInstance().currentUserIdForSettings_ = 1; + + // key == DURING_CALL_KEY + std::string key = "during_call_state"; + auto res = SettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID).AssembleUriMultiUser(key); + EXPECT_TRUE(res.ToString().find("USER_SETTINGSDATA_SECURE_") != std::string::npos); + + // key != DURING_CALL_KEY + key = "ut_test"; + res = SettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID).AssembleUriMultiUser(key); + EXPECT_FALSE(res.ToString().find("USER_SETTINGSDATA_SECURE_") != std::string::npos); + + //userId = 0 + ScreenSessionManager::GetInstance().currentUserIdForSettings_ = 0; + key = "ut_test"; + res = SettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID).AssembleUriMultiUser(key); + EXPECT_TRUE(res.ToString().find("datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA") != + std::string::npos); + + ScreenSessionManager::GetInstance().currentUserIdForSettings_ = saveSettings; +} } } } \ No newline at end of file diff --git a/window_scene/test/dms_unittest/test_client.h b/window_scene/test/dms_unittest/test_client.h index bf046586661b61c3a458cb1e7c9ae55925f97538..d2ac564f67a0a3fabc9ec67ccc28c742bcf62155 100644 --- a/window_scene/test/dms_unittest/test_client.h +++ b/window_scene/test/dms_unittest/test_client.h @@ -62,6 +62,7 @@ public: ScreenCombination extendCombination) override {}; std::string OnDumperClientScreenSessions() override { return ""; }; void OnScreenModeChanged(ScreenModeChangeEvent screenModeChangeEvent) override {}; + void OnAnimationFinish() override {}; sptr AsObject() override {return testPtr;}; sptr testPtr; }; diff --git a/window_scene/test/mock/mock_ability_manager_client.cpp b/window_scene/test/mock/mock_ability_manager_client.cpp index 49b034207f0558ac99699d2b9289662e33e26a66..ef97c9822d932af9115c3024ecd2aa0d7592616e 100644 --- a/window_scene/test/mock/mock_ability_manager_client.cpp +++ b/window_scene/test/mock/mock_ability_manager_client.cpp @@ -36,6 +36,8 @@ void MockAbilityManagerClient::SetUIExtensionSessionInfo(const UIExtensionSessio { g_uiExtensionSessionInfo = std::make_shared(); g_uiExtensionSessionInfo->hostElementName.SetBundleName(sessionInfo.hostElementName.GetBundleName()); + g_uiExtensionSessionInfo->persistentId = sessionInfo.persistentId; + g_uiExtensionSessionInfo->hostWindowId = sessionInfo.hostWindowId; } ErrCode AbilityManagerClient::GetUIExtensionRootHostInfo(const sptr token, @@ -52,6 +54,8 @@ ErrCode AbilityManagerClient::GetUIExtensionSessionInfo(const sptrhostElementName.GetBundleName()); + sessionInfo.persistentId = g_uiExtensionSessionInfo->persistentId; + sessionInfo.hostWindowId = g_uiExtensionSessionInfo->hostWindowId; } return 0; } diff --git a/window_scene/test/mock/mock_message_parcel.cpp b/window_scene/test/mock/mock_message_parcel.cpp index 84c9a9e7c27095ae3ce1bab98099a6fda265dbdc..cf44e7dd7221fc983382c3d1623289dac135a349 100644 --- a/window_scene/test/mock/mock_message_parcel.cpp +++ b/window_scene/test/mock/mock_message_parcel.cpp @@ -127,6 +127,11 @@ void MockMessageParcel::SetWriteRemoteObjectErrorFlag(bool flag) g_setWriteRemoteObjectErrorFlag = flag; } +void MockMessageParcel::SetReadBoolErrorFlag(bool flag) +{ + g_setReadBoolErrorFlag = flag; +} + void MockMessageParcel::SetReadUint32ErrorFlag(bool flag) { g_setReadUint32ErrorFlag = flag; @@ -137,11 +142,6 @@ void MockMessageParcel::SetReadInt32ErrorFlag(bool flag) g_setReadInt32ErrorFlag = flag; } -void MockMessageParcel::SetReadBoolErrorFlag(bool flag) -{ - g_setReadBoolErrorFlag = flag; -} - void MockMessageParcel::SetReadUint64ErrorFlag(bool flag) { g_setReadUint64ErrorFlag = flag; @@ -258,7 +258,7 @@ bool Parcel::WriteString(const std::string& value) return !g_setWriteStringErrorFlag; } -bool Parcel::ReadBool(bool& value) +bool Parcel::ReadBool(bool& val) { if (g_setReadBoolErrorFlag) { return false; diff --git a/window_scene/test/mock/mock_session.h b/window_scene/test/mock/mock_session.h index 7c745e22fb8712e984cd2d693d9792cdd8ea7ea0..b22c90c2a2fce120cdc489277e1db3ec20b991a0 100644 --- a/window_scene/test/mock/mock_session.h +++ b/window_scene/test/mock/mock_session.h @@ -69,10 +69,7 @@ public: MOCK_METHOD1(TransferExtensionData, int32_t(const AAFwk::WantParams& wantParams)); MOCK_METHOD1(RaiseMainWindowAboveTarget, WSError(int32_t targetId)); MOCK_METHOD(WSError, ProcessPointDownSession, (int32_t x, int32_t y), (override)); - void SetMockLayoutController(const sptr& layoutController) - { - layoutController_ = layoutController; - } + MOCK_CONST_METHOD2(ConvertGlobalRectToRelative, WSRect(const WSRect& globalRect, DisplayId targetDisplayId)); }; } // namespace Rosen } // namespace OHOS diff --git a/window_scene/test/mock/mock_session_stage.h b/window_scene/test/mock/mock_session_stage.h index 08d8e3442007781fed564e538c6ca66362605198..dfa0390941e085cfe1e9e0410f2dd40e9562e315 100644 --- a/window_scene/test/mock/mock_session_stage.h +++ b/window_scene/test/mock/mock_session_stage.h @@ -80,16 +80,16 @@ public: MOCK_METHOD2(UpdateWindowModeByIdForUITest, WMError(int32_t windowId, int32_t updateMode)); MOCK_METHOD1(NotifyHighlightChange, WSError(bool isHighlight)); MOCK_METHOD1(SetDragActivated, WSError(bool dragActivated)); - MOCK_METHOD1(NotifyWindowCrossAxisChange, void(CrossAxisState state)); MOCK_METHOD3(NotifyPipWindowSizeChange, WSError(double width, double height, double scale)); + MOCK_METHOD1(NotifyWindowCrossAxisChange, void(CrossAxisState state)); MOCK_METHOD1(LinkKeyFrameCanvasNode, WSError(std::shared_ptr& rsCanvasNode)); MOCK_METHOD1(SetKeyFramePolicy, WSError(KeyFramePolicy& keyFramePolicy)); MOCK_METHOD1(SetCurrentRotation, WSError(int32_t currentRotation)); MOCK_METHOD0(NotifyLifecyclePausedStatus, void(void)); MOCK_METHOD1(NotifyAppUseControlStatus, void(bool isUseControl)); + MOCK_METHOD1(NotifyExtensionSecureLimitChange, WSError(bool isLimit)); MOCK_METHOD0(NotifyAppForceLandscapeConfigUpdated, WSError(void)); MOCK_METHOD0(NotifyAppHookWindowInfoUpdated, WSError(void)); - MOCK_METHOD1(NotifyExtensionSecureLimitChange, WSError(bool isLimit)); MOCK_METHOD1(GetRouterStackInfo, WMError(std::string& routerStackInfo)); MOCK_METHOD1(SendFbActionEvent, WSError(const std::string& action)); }; diff --git a/window_scene/test/unittest/BUILD.gn b/window_scene/test/unittest/BUILD.gn index 8a78b73dbb3a05b77d8779bb247515ad72f03674..587e7e334921240f99ec080d6146248edf72abc9 100644 --- a/window_scene/test/unittest/BUILD.gn +++ b/window_scene/test/unittest/BUILD.gn @@ -849,16 +849,14 @@ ohos_unittest("ws_scene_session_manager_stub_test") { ohos_unittest("ws_scene_session_manager_stub_test2") { module_out_path = module_out_path + configs = [ "${window_base_path}/window_scene/session:ui_effect_public_config" ] + sources = [ "${window_base_path}/window_scene/test/mock/mock_message_parcel.cpp", "scene_session_manager_stub_test2.cpp", ] - deps = [ - ":ws_unittest_common", - "${window_base_path}/window_scene/session:ui_effect_controller", - "${window_base_path}/window_scene/session:ui_effect_controller_client", - ] + deps = [ ":ws_unittest_common" ] external_deps = test_external_deps } @@ -940,7 +938,10 @@ ohos_unittest("ws_scene_session_lifecycle_test") { deps = [ ":ws_unittest_common" ] external_deps = test_external_deps - external_deps += [ "ability_base:session_info" ] + external_deps += [ + "ability_base:session_info", + "ability_runtime:process_options" + ] cflags = [] defines = [] diff --git a/window_scene/test/unittest/event_distribution/scene_input_manager_test.cpp b/window_scene/test/unittest/event_distribution/scene_input_manager_test.cpp index 40e0994ed558057866476695cf8bb2dae1b10972..2a52e8e5189581de8c794aea15131779e01eaddf 100644 --- a/window_scene/test/unittest/event_distribution/scene_input_manager_test.cpp +++ b/window_scene/test/unittest/event_distribution/scene_input_manager_test.cpp @@ -144,59 +144,6 @@ void MaxWindowInfoTest(sptr ssm_) SceneInputManager::GetInstance().FlushDisplayInfoToMMI(std::move(windowInfoList), std::move(pixelMapList)); } -/** - * @tc.name: CheckNeedUpdate - * @tc.desc: CheckNeedUpdate - * @tc.type: FUNC - */ -HWTEST_F(SceneInputManagerTest, CheckNeedUpdate5, TestSize.Level0) -{ - std::vector screenInfos; - std::vector displayInfos; - std::vector windowInfoList; - MMI::DisplayInfo displayinfo; - displayInfos.emplace_back(displayinfo); - MMI::WindowInfo windowinfo; - windowInfoList.emplace_back(windowinfo); - int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId, DEFAULT_DISPLAY_ID); - SceneInputManager::GetInstance().lastFocusId_ = 0; - SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos; - SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList; - bool result = false; - windowInfoList[0].transform.emplace_back(1.0); - SceneInputManager::GetInstance().lastWindowInfoList_[0].transform.emplace_back(2.0); - result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList); - ASSERT_TRUE(result); - windowInfoList[0].transform.clear(); - SceneInputManager::GetInstance().lastWindowInfoList_[0].transform.clear(); - - displayInfos[0].id = 1; - result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList); - ASSERT_TRUE(result); - displayInfos[0].id = 0; - - displayInfos[0].x = 1; - result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList); - ASSERT_TRUE(result); - displayInfos[0].x = 0; - - displayInfos[0].y = 1; - result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList); - ASSERT_TRUE(result); - displayInfos[0].y = 0; - - displayInfos[0].width = 1; - result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList); - ASSERT_TRUE(result); - displayInfos[0].width = 0; - - displayInfos[0].height = 1; - result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList); - ASSERT_TRUE(result); - displayInfos[0].height = 0; -} - /** * @tc.name: UpdateFocusedSessionId * @tc.desc: UpdateFocusedSessionId @@ -251,33 +198,6 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate6, TestSize.Level1) ASSERT_TRUE(result); windowInfoList[0].transform.clear(); SceneInputManager::GetInstance().lastWindowInfoList_[0].transform.clear(); - displayInfos[0].dpi = 1; - result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList); - ASSERT_TRUE(result); - displayInfos[0].dpi = 0; - - displayInfos[0].name = "TestName"; - result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList); - ASSERT_TRUE(result); - displayInfos[0].name = ""; - - result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList); - ASSERT_TRUE(result); - - displayInfos[0].direction = MMI::Direction::DIRECTION90; - result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList); - ASSERT_TRUE(result); - displayInfos[0].direction = MMI::Direction::DIRECTION0; - - displayInfos[0].displayDirection = MMI::Direction::DIRECTION90; - result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList); - ASSERT_TRUE(result); - displayInfos[0].displayDirection = MMI::Direction::DIRECTION0; - - displayInfos[0].displayMode = MMI::DisplayMode::FULL; - result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList); - ASSERT_TRUE(result); - displayInfos[0].displayMode = MMI::DisplayMode::UNKNOWN; } /** @@ -896,29 +816,155 @@ HWTEST_F(SceneInputManagerTest, ConstructDisplayGroupInfos, TestSize.Level1) } /** - * @tc.name: CheckNeedUpdate - * @tc.desc: CheckNeedUpdate + * @tc.name: CheckNeedUpdateForScreenInfos + * @tc.desc: CheckNeedUpdateForScreenInfos * @tc.type: FUNC */ -HWTEST_F(SceneInputManagerTest, CheckNeedUpdate, TestSize.Level1) +HWTEST_F(SceneInputManagerTest, CheckNeedUpdateForScreenInfos, TestSize.Level1) { std::vector screenInfos; std::vector displayInfos; std::vector windowInfoList; MMI::ScreenInfo screenInfo; - screenInfo.id = 3; + screenInfo.id = 1; + screenInfo.uniqueId = "test01"; + screenInfo.screenType = MMI::ScreenType::REAL; + screenInfo.width = 1; + screenInfo.height = 1; + screenInfo.physicalWidth = 1; + screenInfo.physicalHeight = 1; + screenInfo.tpDirection = MMI::Direction::DIRECTION90; + screenInfo.dpi = 1; + screenInfo.ppi = 1; + screenInfo.rotation = MMI::Rotation::ROTATION_0; screenInfos.emplace_back(screenInfo); - auto result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList); - ASSERT_TRUE(result); - result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList); - ASSERT_FALSE(result); - std::vector screenInfos01; - MMI::ScreenInfo screenInfo01; - screenInfo01.id = 1; - screenInfos01.emplace_back(screenInfo01); - SceneInputManager::GetInstance().FlushEmptyInfoToMMI(); - result = SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos01, displayInfos, windowInfoList); - ASSERT_TRUE(result); + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + ASSERT_FALSE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + screenInfos[0].id = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + screenInfos[0].uniqueId = "test02"; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + screenInfos[0].screenType = MMI::ScreenType::VIRTUAL; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + screenInfos[0].width = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + screenInfos[0].height = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + screenInfos[0].physicalWidth = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + screenInfos[0].physicalHeight = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + screenInfos[0].tpDirection = MMI::Direction::DIRECTION270; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + screenInfos[0].dpi = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + screenInfos[0].ppi = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + screenInfos[0].rotation = MMI::Rotation::ROTATION_90; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + ASSERT_FALSE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); +} + +/** + * @tc.name: CheckNeedUpdateForDisplayInfos + * @tc.desc: CheckNeedUpdateForDisplayInfos + * @tc.type: FUNC + */ +HWTEST_F(SceneInputManagerTest, CheckNeedUpdateForDisplayInfos, TestSize.Level1) +{ + std::vector screenInfos; + std::vector displayInfos; + std::vector windowInfoList; + MMI::DisplayInfo displayInfo; + displayInfo.id = 1; + displayInfo.x = 1; + displayInfo.y = 1; + displayInfo.width = 1; + displayInfo.height = 1; + displayInfo.dpi = 1; + displayInfo.name = "displayInfo01"; + displayInfo.direction = MMI::Direction::DIRECTION90; + displayInfo.displayDirection = MMI::Direction::DIRECTION90; + displayInfo.displayMode = MMI::DisplayMode::FULL; + displayInfo.transform.emplace_back(0.001); + displayInfo.scalePercent = 100; + displayInfo.expandHeight = 1; + displayInfo.isCurrentOffScreenRendering = true; + displayInfo.displaySourceMode = MMI::DisplaySourceMode::SCREEN_MAIN; + displayInfo.oneHandX = 1; + displayInfo.oneHandY = 1; + displayInfo.screenArea = { 1, { 1, 1, 1, 1 } }; + displayInfo.rsId = 1; + displayInfo.offsetX = 1; + displayInfo.offsetY = 1; + displayInfo.pointerActiveWidth = 1; + displayInfo.pointerActiveHeight = 1; + displayInfo.deviceRotation = MMI::Direction::DIRECTION90; + displayInfo.rotationCorrection = MMI::Direction::DIRECTION90; + displayInfos.emplace_back(displayInfo); + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + ASSERT_FALSE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].id = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].x = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].y = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].width = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].height = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].dpi = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].name = "displayInfo02"; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].direction = MMI::Direction::DIRECTION180; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].displayDirection = MMI::Direction::DIRECTION180; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].displayMode = MMI::DisplayMode::SUB; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].transform[0] = 0.002; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].transform.emplace_back(0.00002); + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].scalePercent = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].expandHeight = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].isCurrentOffScreenRendering = false; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].displaySourceMode = MMI::DisplaySourceMode::SCREEN_EXTEND; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].oneHandX = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].oneHandY = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].rsId = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].offsetX = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].offsetY = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].pointerActiveWidth = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].pointerActiveHeight = 2; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].screenArea = { 2, { 1, 1, 1, 1 } }; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].screenArea = { 2, { 2, 1, 1, 1 } }; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].screenArea = { 2, { 2, 2, 1, 1 } }; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].screenArea = { 2, { 2, 2, 2, 1 } }; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].screenArea = { 2, { 2, 2, 2, 2 } }; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].deviceRotation = MMI::Direction::DIRECTION180; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + displayInfos[0].rotationCorrection = MMI::Direction::DIRECTION180; + ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); + ASSERT_FALSE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); } } // namespace } // namespace Rosen diff --git a/window_scene/test/unittest/event_distribution/scene_session_dirty_manager_test.cpp b/window_scene/test/unittest/event_distribution/scene_session_dirty_manager_test.cpp index 991e384cac347dae54215ee1dd94e027b14456ab..4bca670ab998db49704a2c4fd7ce1052cf1ea520 100644 --- a/window_scene/test/unittest/event_distribution/scene_session_dirty_manager_test.cpp +++ b/window_scene/test/unittest/event_distribution/scene_session_dirty_manager_test.cpp @@ -871,6 +871,32 @@ HWTEST_F(SceneSessionDirtyManagerTest, CalNotRotateTransform2, TestSize.Level1) sceneSession->property_ = oriProperty; } +/** + * @tc.name: CalSpecialNotRotateTransformTest + * @tc.desc: CalSpecialNotRotateTransform + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest, CalSpecialNotRotateTransformTest, TestSize.Level1) +{ + g_logMsg.clear(); + LOG_SetCallback(MyLogCallback); + ScreenProperty screenProperty; + Matrix3f transform; + manager_->CalSpecialNotRotateTransform(nullptr, screenProperty, transform); + EXPECT_TRUE(g_logMsg.find("sceneSession is null") != std::string::npos); + + SessionInfo sessionInfo; + sessionInfo.bundleName_ = "CalSpecialNotRotateTransformTest"; + sessionInfo.moduleName_ = "sessionInfo"; + Matrix3f testTransform = transform; + sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); + ASSERT_NE(sceneSession, nullptr); + manager_->CalSpecialNotRotateTransform(sceneSession, screenProperty, transform); + EXPECT_TRUE(g_logMsg.find("sceneSession is null") != std::string::npos); + EXPECT_NE(transform, testTransform); + LOG_SetCallback(nullptr); +} + /** * @tc.name: UpdateWindowFlags * @tc.desc: UpdateWindowFlags @@ -1017,6 +1043,189 @@ HWTEST_F(SceneSessionDirtyManagerTest, CalTransform_CompatMode, TestSize.Level1) .Inverse().Translate(translateOffset)); } +/** + * @tc.name: CalTransformSessionPropertyNullptr + * @tc.desc: CalTransform + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest, CalTransformSessionPropertyNullptr, TestSize.Level1) +{ + g_logMsg.clear(); + LOG_SetCallback(MyLogCallback); + SessionInfo sessionInfo; + sessionInfo.bundleName_ = "CalTransformSessionPropertyNullptr"; + sessionInfo.moduleName_ = "CalTransformSessionPropertyNullptr"; + sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); + Matrix3f transform; + SingleHandData testSingleHandData; + + auto oriProperty = sceneSession->GetSessionProperty(); + sceneSession->property_ = nullptr; + manager_->CalTransform(sceneSession, transform, testSingleHandData); + EXPECT_TRUE(g_logMsg.find("sessionProperty is null") != std::string::npos); + sceneSession->property_ = oriProperty; + LOG_SetCallback(nullptr); +} + +/** + * @tc.name: CalTransformTest_01 + * @tc.desc: CalTransform isRotate false + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest, CalTransformTest_01, TestSize.Level1) +{ + SessionInfo sessionInfo; + sessionInfo.bundleName_ = "CalTransformTest_01"; + sessionInfo.moduleName_ = "CalTransformTest_01"; + sessionInfo.isRotable_ = false; + sessionInfo.isSystem_ = true; + sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); + Vector2f scale(sceneSession->GetScaleX(), sceneSession->GetScaleY()); + Vector2f translate = sceneSession->GetSessionGlobalPosition(false); + Vector2f offset = sceneSession->GetSessionGlobalPosition(false); + Matrix3f transform; + SingleHandData testSingleHandData; + + auto screenId = 1001; + sceneSession->GetSessionProperty()->SetDisplayId(screenId); + ScreenSessionConfig config; + sptr screenSession = + sptr::MakeSptr(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT); + ASSERT_NE(screenSession, nullptr); + ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(screenId, screenSession); + ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::UNKNOWN); + manager_->CalTransform(sceneSession, transform, testSingleHandData); + ASSERT_EQ(transform, transform.Translate(translate) + .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse()); + ScreenSessionManagerClient::GetInstance().screenSessionMap_.erase(screenId); +} + +/** + * @tc.name: CalTransformTest_02 + * @tc.desc: CalTransform isRotate false isRotateWindow false + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest, CalTransformTest_02, TestSize.Level1) +{ + SessionInfo sessionInfo; + sessionInfo.bundleName_ = "CalTransformTest_02"; + sessionInfo.moduleName_ = "CalTransformTest_02"; + sessionInfo.isRotable_ = false; + sessionInfo.isSystem_ = true; + sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); + Vector2f scale(sceneSession->GetScaleX(), sceneSession->GetScaleY()); + Vector2f translate = sceneSession->GetSessionGlobalPosition(false); + Vector2f offset = sceneSession->GetSessionGlobalPosition(false); + Matrix3f transform; + SingleHandData testSingleHandData; + + auto screenId = 1001; + sceneSession->GetSessionProperty()->SetDisplayId(screenId); + ScreenSessionConfig config; + sptr screenSession = + sptr::MakeSptr(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT); + ASSERT_NE(screenSession, nullptr); + screenSession->GetScreenProperty().SetPhysicalRotation(180.0f); + screenSession->GetScreenProperty().SetScreenComponentRotation(90.0f); + + ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(screenId, screenSession); + sceneSession->SetCurrentRotation(90); + ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::FULL); + manager_->CalTransform(sceneSession, transform, testSingleHandData); + ASSERT_EQ(transform, transform.Translate(translate) + .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse()); + + ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::GLOBAL_FULL); + manager_->CalTransform(sceneSession, transform, testSingleHandData); + ASSERT_EQ(transform, transform.Translate(translate) + .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse()); + + ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::MAIN); + manager_->CalTransform(sceneSession, transform, testSingleHandData); + ASSERT_EQ(transform, transform.Translate(translate) + .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse()); + ScreenSessionManagerClient::GetInstance().screenSessionMap_.erase(screenId); +} + +/** + * @tc.name: CalTransformTest_03 + * @tc.desc: CalTransform isRotate true isRotateWindow false + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest, CalTransformTest_03, TestSize.Level1) +{ + SessionInfo sessionInfo; + sessionInfo.bundleName_ = "CalTransformTest_03"; + sessionInfo.moduleName_ = "CalTransformTest_03"; + sessionInfo.isRotable_ = true; + sessionInfo.isSystem_ = false; + sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); + Vector2f scale(sceneSession->GetScaleX(), sceneSession->GetScaleY()); + Vector2f translate = sceneSession->GetSessionGlobalPosition(false); + Vector2f offset = sceneSession->GetSessionGlobalPosition(false); + Matrix3f transform; + SingleHandData testSingleHandData; + + auto screenId = 1001; + sceneSession->GetSessionProperty()->SetDisplayId(screenId); + ScreenSessionConfig config; + sptr screenSession = + sptr::MakeSptr(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT); + ASSERT_NE(screenSession, nullptr); + screenSession->GetScreenProperty().SetPhysicalRotation(180.0f); + screenSession->GetScreenProperty().SetScreenComponentRotation(90.0f); + + ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(screenId, screenSession); + sceneSession->SetCurrentRotation(90); + ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::UNKNOWN); + manager_->CalTransform(sceneSession, transform, testSingleHandData); + ASSERT_EQ(transform, transform.Translate(translate) + .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse()); + ScreenSessionManagerClient::GetInstance().screenSessionMap_.erase(screenId); +} + +/** + * @tc.name: CalTransformTest_04 + * @tc.desc: CalTransform isRotate true isRotateWindow true + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest, CalTransformTest_04, TestSize.Level1) +{ + SessionInfo sessionInfo; + sessionInfo.bundleName_ = "CalTransformTest_04"; + sessionInfo.moduleName_ = "CalTransformTest_04"; + sessionInfo.isRotable_ = true; + sessionInfo.isSystem_ = true; + sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); + Vector2f scale(sceneSession->GetScaleX(), sceneSession->GetScaleY()); + Vector2f translate = sceneSession->GetSessionGlobalPosition(false); + Vector2f offset = sceneSession->GetSessionGlobalPosition(false); + Matrix3f transform; + SingleHandData testSingleHandData; + + auto screenId = 1001; + sceneSession->GetSessionProperty()->SetDisplayId(screenId); + ScreenSessionConfig config; + sptr screenSession = + sptr::MakeSptr(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT); + ASSERT_NE(screenSession, nullptr); + screenSession->GetScreenProperty().SetPhysicalRotation(180.0f); + screenSession->GetScreenProperty().SetScreenComponentRotation(90.0f); + + ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(screenId, screenSession); + sceneSession->SetCurrentRotation(0); + ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::MAIN); + manager_->CalTransform(sceneSession, transform, testSingleHandData); + ASSERT_EQ(transform, transform.Translate(translate) + .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse()); + + ScreenSessionManagerClient::GetInstance().OnUpdateFoldDisplayMode(FoldDisplayMode::FULL); + manager_->CalTransform(sceneSession, transform, testSingleHandData); + ASSERT_EQ(transform, transform.Translate(translate) + .Scale(scale, sceneSession->GetPivotX(), sceneSession->GetPivotY()).Inverse()); + ScreenSessionManagerClient::GetInstance().screenSessionMap_.erase(screenId); +} + /** * @tc.name: UpdateModalExtensionInCompatStatus * @tc.desc: UpdateModalExtensionInCompatStatus diff --git a/window_scene/test/unittest/event_distribution/scene_session_dirty_manager_test2.cpp b/window_scene/test/unittest/event_distribution/scene_session_dirty_manager_test2.cpp index 3e6199dd24f1a8c878f19a41b70f30829b6eff24..4b7557aabf19e2fc38bbf80b45414c9b066fd6b0 100644 --- a/window_scene/test/unittest/event_distribution/scene_session_dirty_manager_test2.cpp +++ b/window_scene/test/unittest/event_distribution/scene_session_dirty_manager_test2.cpp @@ -700,6 +700,79 @@ HWTEST_F(SceneSessionDirtyManagerTest2, GetWindowInfoWithoutParentWindow, TestSi int32_t windowInfoSize = sceneSessionMap.size(); ASSERT_EQ(windowInfoSize, 0); } + +/** + * @tc.name: GetWindowInfoWithScreenshotPrefix + * @tc.desc: windowInfo with screenshot prefix + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest2, GetWindowInfoWithScreenshotPrefix, TestSize.Level2) +{ + SessionInfo info; + sptr session = sptr::MakeSptr(info, nullptr); + sptr windowSessionProperty = session->GetSessionProperty(); + session->SetSessionProperty(windowSessionProperty); + windowSessionProperty->SetWindowName("ScreenShotWindowExample"); + + auto result = manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD); + + EXPECT_EQ(result.first.windowNameType, 1); +} + +/** + * @tc.name: GetWindowInfoWithPreviewPrefix + * @tc.desc: windowInfo with preview prefix + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest2, GetWindowInfoWithPreviewPrefix, TestSize.Level2) +{ + SessionInfo info; + sptr session = sptr::MakeSptr(info, nullptr); + sptr windowSessionProperty = session->GetSessionProperty(); + session->SetSessionProperty(windowSessionProperty); + windowSessionProperty->SetWindowName("PreviewWindowExample"); + + auto result = manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD); + + EXPECT_EQ(result.first.windowNameType, 1); +} + +/** + * @tc.name: GetWindowInfoWithoutSpecialPrefix + * @tc.desc: windowInfo without special prefix + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest2, GetWindowInfoWithoutSpecialPrefix, TestSize.Level2) +{ + SessionInfo info; + sptr session = sptr::MakeSptr(info, nullptr); + sptr windowSessionProperty = session->GetSessionProperty(); + session->SetSessionProperty(windowSessionProperty); + windowSessionProperty->SetWindowName("RegularWindowExample"); + + auto result = manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD); + + EXPECT_EQ(result.first.windowNameType, 0); +} + +/** + * @tc.name: GetWindowInfoWithVoiceInputPrefix + * @tc.desc: windowInfo with preview prefix + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionDirtyManagerTest2, GetWindowInfoWithVoiceInputPrefix, TestSize.Level2) +{ + std::vector lastWindowInfoList; + SessionInfo info; + sptr session = new (std::nothrow) SceneSession(info, nullptr); + sptr windowSessionProperty = session->GetSessionProperty(); + session->SetSessionProperty(windowSessionProperty); + windowSessionProperty->SetWindowName("__VoiceHardwareInputExample"); + + auto result = manager_->GetWindowInfo(session, SceneSessionDirtyManager::WindowAction::WINDOW_ADD); + + EXPECT_EQ(result.first.windowNameType, 2); +} } // namespace } // namespace Rosen } // namespace OHOS diff --git a/window_scene/test/unittest/layout/main_session_layout_test.cpp b/window_scene/test/unittest/layout/main_session_layout_test.cpp index 721d8fc5cb0815a73fe0703a1c4bc85d914af27f..c7f19b357502a306eec2d4e1faa505d6b7c25568 100644 --- a/window_scene/test/unittest/layout/main_session_layout_test.cpp +++ b/window_scene/test/unittest/layout/main_session_layout_test.cpp @@ -144,29 +144,25 @@ HWTEST_F(MainSessionLayoutTest, HandleSubSessionSurfaceNodeByWindowAnchor, TestS sptr subSession = sptr::MakeSptr(info, nullptr); mainSession->subSession_.emplace_back(nullptr); mainSession->subSession_.emplace_back(subSession); - ScreenSessionConfig config = { - .screenId = 100, - .rsId = 101, - .name = "OpenHarmony", - }; - sptr screenSession = - sptr::MakeSptr(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL); auto surfaceNode = CreateRSSurfaceNode(); ASSERT_NE(nullptr, surfaceNode); subSession->SetSurfaceNode(surfaceNode); + subSession->SetFindScenePanelRsNodeByZOrderFunc([this](uint64_t screenId, uint32_t targetZOrder) { + return CreateRSSurfaceNode(); + }); subSession->state_ = SessionState::STATE_FOREGROUND; subSession->windowAnchorInfo_.isAnchorEnabled_ = false; subSession->cloneNodeCountDuringCross_.store(0); - mainSession->HandleSubSessionSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG, screenSession); + mainSession->HandleSubSessionSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG, 0); EXPECT_EQ(subSession->cloneNodeCountDuringCross_, 0); subSession->windowAnchorInfo_.isAnchorEnabled_ = true; - mainSession->HandleSubSessionSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG, screenSession); + mainSession->HandleSubSessionSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG, 0); EXPECT_EQ(subSession->cloneNodeCountDuringCross_, 1); subSession->state_ = SessionState::STATE_BACKGROUND; - mainSession->HandleSubSessionSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG_END, screenSession); + mainSession->HandleSubSessionSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG_END, 0); EXPECT_EQ(subSession->cloneNodeCountDuringCross_, 1); } } // namespace diff --git a/window_scene/test/unittest/layout/scene_session_layout_test.cpp b/window_scene/test/unittest/layout/scene_session_layout_test.cpp index eac8ed51c9d2dfd7d24f31aa512956de557372d4..94167894c704ee95447d9b84384e86b0890afbae 100644 --- a/window_scene/test/unittest/layout/scene_session_layout_test.cpp +++ b/window_scene/test/unittest/layout/scene_session_layout_test.cpp @@ -44,6 +44,7 @@ public: void TearDown() override; private: + RSSurfaceNode::SharedPtr CreateRSSurfaceNode(); sptr mockSessionStage_ = nullptr; }; @@ -58,6 +59,14 @@ void SceneSessionLayoutTest::SetUp() void SceneSessionLayoutTest::TearDown() {} +RSSurfaceNode::SharedPtr SceneSessionLayoutTest::CreateRSSurfaceNode() +{ + struct RSSurfaceNodeConfig rsSurfaceNodeConfig; + rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTestSurfaceNode"; + auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig); + return surfaceNode; +} + namespace { /** * @tc.name: UpdateRect01 @@ -1135,6 +1144,27 @@ HWTEST_F(SceneSessionLayoutTest, RegisterAppHookWindowInfoFunc, TestSize.Level1) sceneSession->RegisterAppHookWindowInfoFunc(nullptr); ASSERT_NE(sceneSession->getHookWindowInfoFunc_, nullptr); } + +/** + * @tc.name: GetWindowDragMoveMountedNode01 + * @tc.desc: GetWindowDragMoveMountedNode + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionLayoutTest, GetWindowDragMoveMountedNode01, TestSize.Level1) +{ + SessionInfo info; + info.abilityName_ = "GetWindowDragMoveMountedNode"; + info.bundleName_ = "GetWindowDragMoveMountedNode"; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + auto rsNode = session->GetWindowDragMoveMountedNode(std::numeric_limits::max(), 0); + EXPECT_EQ(rsNode, nullptr); + sceneSession->SetFindScenePanelRsNodeByZOrderFunc([this](uint64_t screenId, uint32_t targetZOrder) { + return CreateRSSurfaceNode(); + }); + rsNode = sceneSession->GetWindowDragMoveMountedNode(0, 0); + EXPECT_NE(rsNode, nullptr); +} + } // namespace } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/layout/sub_session_layout_test.cpp b/window_scene/test/unittest/layout/sub_session_layout_test.cpp index 5d4a0b0c9780afa0a246e5e5d9e304cc1778708d..b3f01e510ca723fa77813a0945b898852bb59160 100644 --- a/window_scene/test/unittest/layout/sub_session_layout_test.cpp +++ b/window_scene/test/unittest/layout/sub_session_layout_test.cpp @@ -70,15 +70,12 @@ HWTEST_F(SubSessionLayoutTest, HandleCrossSurfaceNodeByWindowAnchor, TestSize.Le info.bundleName_ = "HandleCrossSurfaceNodeByWindowAnchor"; sptr sceneSession = sptr::MakeSptr(info, nullptr); sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); - sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::UNDEFINED, nullptr); - ScreenSessionConfig config = { - .screenId = 100, - .rsId = 101, - .name = "OpenHarmony", - }; - sptr screenSession = - sptr::MakeSptr(config, ScreenSessionReason::CREATE_SESSION_FOR_VIRTUAL); - sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::UNDEFINED, screenSession); + sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::UNDEFINED, + std::numeric_limits::max()); + sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::UNDEFINED, 0); + sceneSession->SetFindScenePanelRsNodeByZOrderFunc([this](uint64_t screenId, uint32_t targetZOrder) { + return CreateRSSurfaceNode(); + }); struct RSSurfaceNodeConfig rsSurfaceNodeConfig; rsSurfaceNodeConfig.SurfaceNodeName = info.abilityName_; RSSurfaceNodeType rsSurfaceNodeType = RSSurfaceNodeType::DEFAULT; @@ -87,13 +84,13 @@ HWTEST_F(SubSessionLayoutTest, HandleCrossSurfaceNodeByWindowAnchor, TestSize.Le sceneSession->SetSurfaceNode(surfaceNode); sceneSession->cloneNodeCountDuringCross_.store(0); - sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG, screenSession); + sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG, 0); EXPECT_EQ(1, sceneSession->cloneNodeCountDuringCross_.load()); - sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG_MOVE, screenSession); + sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG_MOVE, 0); EXPECT_EQ(2, sceneSession->cloneNodeCountDuringCross_.load()); - sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG_END, screenSession); + sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::DRAG_END, 0); EXPECT_EQ(1, sceneSession->cloneNodeCountDuringCross_.load()); - sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::UNDEFINED, screenSession); + sceneSession->HandleCrossSurfaceNodeByWindowAnchor(SizeChangeReason::UNDEFINED, 0); EXPECT_EQ(1, sceneSession->cloneNodeCountDuringCross_.load()); } } // namespace diff --git a/window_scene/test/unittest/move_drag_controller_test.cpp b/window_scene/test/unittest/move_drag_controller_test.cpp index 613989cd182cd0246e8456eb55fa901c7ac1f380..c0018cc2f161050db4902cb880f3c73e4c22ab22 100644 --- a/window_scene/test/unittest/move_drag_controller_test.cpp +++ b/window_scene/test/unittest/move_drag_controller_test.cpp @@ -288,38 +288,38 @@ HWTEST_F(MoveDragControllerTest, UpdateGravityWhenDrag, TestSize.Level0) moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode); moveDragController->type_ = AreaType::RIGHT; moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode); - auto gravityIter = surfaceNode->propertyModifiers_.find(RSModifierType::FRAME_GRAVITY); - EXPECT_EQ(gravityIter, surfaceNode->propertyModifiers_.end()); + auto modifier = surfaceNode->GetModifierByType(ModifierNG::RSModifierType::CLIP_TO_FRAME); + EXPECT_NE(modifier, nullptr); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN); moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode); - gravityIter = surfaceNode->propertyModifiers_.find(RSModifierType::FRAME_GRAVITY); - EXPECT_EQ(gravityIter, surfaceNode->propertyModifiers_.end()); + modifier = surfaceNode->GetModifierByType(ModifierNG::RSModifierType::CLIP_TO_FRAME); + EXPECT_NE(modifier, nullptr); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN); moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode); - gravityIter = surfaceNode->propertyModifiers_.find(RSModifierType::FRAME_GRAVITY); - EXPECT_EQ(gravityIter, surfaceNode->propertyModifiers_.end()); + modifier = surfaceNode->GetModifierByType(ModifierNG::RSModifierType::CLIP_TO_FRAME); + EXPECT_NE(modifier, nullptr); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP); moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode); - gravityIter = surfaceNode->propertyModifiers_.find(RSModifierType::FRAME_GRAVITY); - EXPECT_EQ(gravityIter, surfaceNode->propertyModifiers_.end()); + modifier = surfaceNode->GetModifierByType(ModifierNG::RSModifierType::CLIP_TO_FRAME); + EXPECT_NE(modifier, nullptr); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_UP); moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode); - gravityIter = surfaceNode->propertyModifiers_.find(RSModifierType::FRAME_GRAVITY); - EXPECT_EQ(gravityIter, surfaceNode->propertyModifiers_.end()); + modifier = surfaceNode->GetModifierByType(ModifierNG::RSModifierType::CLIP_TO_FRAME); + EXPECT_NE(modifier, nullptr); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_CANCEL); moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode); - gravityIter = surfaceNode->propertyModifiers_.find(RSModifierType::FRAME_GRAVITY); - EXPECT_EQ(gravityIter, surfaceNode->propertyModifiers_.end()); + modifier = surfaceNode->GetModifierByType(ModifierNG::RSModifierType::CLIP_TO_FRAME); + EXPECT_NE(modifier, nullptr); pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UNKNOWN); moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode); - gravityIter = surfaceNode->propertyModifiers_.find(RSModifierType::FRAME_GRAVITY); - EXPECT_EQ(gravityIter, surfaceNode->propertyModifiers_.end()); + modifier = surfaceNode->GetModifierByType(ModifierNG::RSModifierType::CLIP_TO_FRAME); + EXPECT_NE(modifier, nullptr); } } @@ -1797,21 +1797,21 @@ HWTEST_F(MoveDragControllerTest, UpdateSubWindowGravityWhenFollow01, TestSize.Le followController->type_ = AreaType::UNDEFINED; moveDragController->UpdateSubWindowGravityWhenFollow(nullptr, nullptr); - auto gravityIter = surfaceNode->propertyModifiers_.find(RSModifierType::FRAME_GRAVITY); - ASSERT_EQ(gravityIter, surfaceNode->propertyModifiers_.end()); + auto modifier = surfaceNode->GetModifierByType(ModifierNG::RSModifierType::CLIP_TO_FRAME); + EXPECT_NE(modifier, nullptr); moveDragController->UpdateSubWindowGravityWhenFollow(nullptr, surfaceNode); - gravityIter = surfaceNode->propertyModifiers_.find(RSModifierType::FRAME_GRAVITY); - ASSERT_EQ(gravityIter, surfaceNode->propertyModifiers_.end()); + modifier = surfaceNode->GetModifierByType(ModifierNG::RSModifierType::CLIP_TO_FRAME); + EXPECT_NE(modifier, nullptr); moveDragController->UpdateSubWindowGravityWhenFollow(followController, surfaceNode); - gravityIter = surfaceNode->propertyModifiers_.find(RSModifierType::FRAME_GRAVITY); - ASSERT_EQ(gravityIter, surfaceNode->propertyModifiers_.end()); + modifier = surfaceNode->GetModifierByType(ModifierNG::RSModifierType::CLIP_TO_FRAME); + EXPECT_NE(modifier, nullptr); followController->type_ = AreaType::TOP; moveDragController->UpdateSubWindowGravityWhenFollow(followController, surfaceNode); - gravityIter = surfaceNode->propertyModifiers_.find(RSModifierType::FRAME_GRAVITY); - ASSERT_EQ(gravityIter, surfaceNode->propertyModifiers_.end()); + modifier = surfaceNode->GetModifierByType(ModifierNG::RSModifierType::CLIP_TO_FRAME); + EXPECT_NE(modifier, nullptr); } } // namespace } // namespace Rosen diff --git a/window_scene/test/unittest/scene_session_lifecycle_test.cpp b/window_scene/test/unittest/scene_session_lifecycle_test.cpp index 16139cf0230bccda05cb303b89f740061c8fbbb1..b5cd043ddee56c9491f3ccca9bef06d60b4b51eb 100644 --- a/window_scene/test/unittest/scene_session_lifecycle_test.cpp +++ b/window_scene/test/unittest/scene_session_lifecycle_test.cpp @@ -23,10 +23,12 @@ #include "session/host/include/sub_session.h" #include "session/host/include/system_session.h" #include "session/host/include/main_session.h" +#include "screen_session_manager_client.h" #include "wm_common.h" #include "mock/mock_session_stage.h" #include "input_event.h" #include +#include "process_options.h" #include "ui/rs_surface_node.h" #include "session/container/include/window_event_channel.h" #include "window_event_channel_base.h" @@ -43,6 +45,7 @@ public: void TearDown() override; sptr sceneSession; SessionInfo info; + PendingSessionActivationConfig configs; }; void SceneSessionLifecycleTest::SetUpTestCase() {} @@ -239,6 +242,37 @@ HWTEST_F(SceneSessionLifecycleTest, Foreground06, TestSize.Level0) EXPECT_EQ(WSError::WS_OK, session->Foreground(property, false)); } +/** + * @tc.name: Foreground07 + * @tc.desc: Foreground07 function + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionLifecycleTest, Foreground07, TestSize.Level0) +{ + SessionInfo info; + info.abilityName_ = "Foreground07"; + info.bundleName_ = "Foreground07"; + sptr session = sptr::MakeSptr(info, nullptr); + EXPECT_NE(session, nullptr); + sptr property = sptr::MakeSptr(); + session->property_ = property; + session->property_->SetDisplayId(ScreenSessionManagerClient::GetInstance().GetDefaultScreenId()); + session->SetIsActivatedAfterScreenLocked(true); + + GetStateFromManagerFunc func = [](const ManagerState key) { + switch (key) { + case ManagerState::MANAGER_STATE_SCREEN_LOCKED: + return true; + default: + return false; + } + }; + session->SetGetStateFromManagerListener(func); + MockAccesstokenKit::MockAccessTokenKitRet(-1); + EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, session->Foreground(property, false)); + MockAccesstokenKit::MockAccessTokenKitRet(0); +} + /** * @tc.name: ForegroundTask01 * @tc.desc: ForegroundTask function @@ -261,6 +295,20 @@ HWTEST_F(SceneSessionLifecycleTest, ForegroundTask01, TestSize.Level0) EXPECT_EQ(true, session->isUIFirstEnabled_); session->SetSessionState(SessionState::STATE_CONNECT); EXPECT_EQ(WSError::WS_OK, session->ForegroundTask(property)); + + session->isUIFirstEnabled_ = true; + EXPECT_EQ(true, session->isUIFirstEnabled_); + struct RSSurfaceNodeConfig config; + std::shared_ptr surfaceNode = RSSurfaceNode::Create(config); + EXPECT_NE(nullptr, surfaceNode); + session->SetLeashWinSurfaceNode(surfaceNode); + session->SetSessionState(SessionState::STATE_CONNECT); + EXPECT_EQ(WSError::WS_OK, session->ForegroundTask(property)); + + session->isUIFirstEnabled_ = false; + EXPECT_EQ(false, session->isUIFirstEnabled_); + session->SetSessionState(SessionState::STATE_CONNECT); + EXPECT_EQ(WSError::WS_OK, session->ForegroundTask(property)); } /** @@ -870,6 +918,36 @@ HWTEST_F(SceneSessionLifecycleTest, ConnectInner02, TestSize.Level0) ASSERT_EQ(result, WSError::WS_OK); } +/** + * @tc.name: ConnectInner02 + * @tc.desc: ConnectInner02 + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionLifecycleTest, ConnectInner03, TestSize.Level0) +{ + SessionInfo info; + info.bundleName_ = "ConnectInner03"; + info.abilityName_ = "ConnectInner03"; + + std::shared_ptr processOptions = std::make_shared(); + processOptions->startupVisibility = AAFwk::StartupVisibility::STARTUP_HIDE; + info.processOptions = processOptions; + + sptr sceneSession = sptr::MakeSptr(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + sptr mockSessionStage = sptr::MakeSptr(); + ASSERT_NE(mockSessionStage, nullptr); + SystemSessionConfig systemConfig; + sptr property = sptr::MakeSptr(); + ASSERT_NE(property, nullptr); + + sptr eventChannel = sptr::MakeSptr(mockSessionStage); + ASSERT_NE(eventChannel, nullptr); + sceneSession->SetSessionState(SessionState::STATE_DISCONNECT); + auto result = sceneSession->ConnectInner(mockSessionStage, eventChannel, nullptr, systemConfig, property, nullptr); + ASSERT_EQ(result, WSError::WS_OK); +} + /** * @tc.name: Reconnect * @tc.desc: Reconnect @@ -1166,9 +1244,20 @@ HWTEST_F(SceneSessionLifecycleTest, BatchPendingSessionsActivation, TestSize.Lev sessionInfo->want.SetFlags(flags); sessionInfo->isAtomicService = true; abilitySessionInfos.emplace_back(sessionInfo); - WSError result = sceneSession->BatchPendingSessionsActivation(abilitySessionInfos); + std::vector configs; + PendingSessionActivationConfig config; + configs.emplace_back(config); + WSError result = sceneSession->BatchPendingSessionsActivation(abilitySessionInfos, configs); + EXPECT_EQ(result, WSError::WS_OK); + auto func = [](std::vector>& info, + const std::vector>& configs) { + std::cout << "enter batchPendingSessionsActivationFunc" << std::endl; + }; + sceneSession->Session::SetBatchPendingSessionsActivationEventListener(func); + result = sceneSession->BatchPendingSessionsActivation(abilitySessionInfos, configs); EXPECT_EQ(result, WSError::WS_OK); + MockAccesstokenKit::ChangeMockStateToInit(); } /** diff --git a/window_scene/test/unittest/scene_session_manager_kiosk_test.cpp b/window_scene/test/unittest/scene_session_manager_kiosk_test.cpp index b5b880c6c5d26f9117d3daa5c68e635debcee730..f0c479cd8909ab5848697ddc0b2d9ef6e55f5a15 100644 --- a/window_scene/test/unittest/scene_session_manager_kiosk_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_kiosk_test.cpp @@ -209,21 +209,6 @@ HWTEST_F(SceneSessionManagerKioskTest, EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION); } -/** - * @tc.name : UpdateKioskAppList_ShouldReturnInvalidParam_WhenKioskAppListIsEmpty - * @tc.number: UpdateKioskAppList_002 - * @tc.desc : Test: When the passed kioskAppList is empty, UpdateKioskAppList should return WM_ERROR_INVALID_PARAM - */ -HWTEST_F(SceneSessionManagerKioskTest, - ATC_UpdateKioskAppList_ShouldReturnInvalidParam_WhenKioskAppListIsEmpty, TestSize.Level0) -{ - MockAccesstokenKit::MockIsSystemApp(true); - MockAccesstokenKit::MockIsSACalling(true); - std::vector kioskAppList = {}; - WMError result = ssm_->UpdateKioskAppList(kioskAppList); - EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PARAM); -} - /** * @tc.name : UpdateKioskAppList_ShouldCallUpdateKioskAppListFunc_WhenUpdateKioskAppListFuncIsNotNull * @tc.number: UpdateKioskAppList_003 @@ -296,7 +281,7 @@ HWTEST_F(SceneSessionManagerKioskTest, /** * @tc.name : RegisterKioskModeChangeCallback_ShouldCallCallback_WhenValidFuncIsProvided * @tc.number: RegisterKioskModeChangeCallbackTest_001 - * @tc.desc : 测试在传入有效回调函数时,函数是否被正确调用 + * @tc.desc : Test whether the function is called correctly when a valid callback function is passed in */ HWTEST_F(SceneSessionManagerKioskTest, ATC_RegisterKioskModeChangeCallback_ShouldCallCallback_WhenValidFuncIsProvided, TestSize.Level0) @@ -309,6 +294,6 @@ HWTEST_F(SceneSessionManagerKioskTest, usleep(WAIT_SYNC_IN_NS); EXPECT_TRUE(ssm_->kioskModeChangeFunc_ != nullptr); } -} -} -} \ No newline at end of file +} // namespace +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/scene_session_manager_lite_proxy_test.cpp b/window_scene/test/unittest/scene_session_manager_lite_proxy_test.cpp index fe5d4a01754755819738973459748366b0d28853..16f1e2befe28a5817017da1014f87a76cd20e080 100644 --- a/window_scene/test/unittest/scene_session_manager_lite_proxy_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_lite_proxy_test.cpp @@ -284,4 +284,28 @@ HWTEST_F(sceneSessionManagerLiteProxyTest, IsFocusWindowParent, TestSize.Level1) EXPECT_EQ(errCode, WSError::WS_ERROR_IPC_FAILED); MockMessageParcel::SetReadInt32ErrorFlag(false); } + +/** + * @tc.name: NotifyAppUseControlList + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(sceneSessionManagerLiteProxyTest, NotifyAppUseControlList, TestSize.Level1) +{ + sptr iRemoteObjectMocker = sptr::MakeSptr(); + sptr sceneSessionManagerLiteProxy = + sptr::MakeSptr(iRemoteObjectMocker); + ASSERT_NE(sceneSessionManagerLiteProxy, nullptr); + MockMessageParcel::ClearAllErrorFlag(); + ControlAppType type = ControlAppType::DLP; + int32_t userId = 100; + std::vector controlList; + AppUseControlInfo controlInfo; + controlList.push_back(controlInfo); + WMError errCode = sceneSessionManagerLiteProxy->NotifyAppUseControlList(type, userId, controlList); + EXPECT_EQ(errCode, WSError::WS_OK); + MockMessageParcel::SetWriteParcelableErrorFlag(true); + errCode = sceneSessionManagerLiteProxy->NotifyAppUseControlList(type, userId, controlList); + EXPECT_EQ(errCode, WSError::WS_ERROR_INVALID_PARAM); +} } \ No newline at end of file diff --git a/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp b/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp index e57cdb7033c64923745972683def0abf5cc0a7e5..bbab0983fdf1f53a1ab6729d0756f2e58dc07f31 100644 --- a/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp @@ -1116,7 +1116,34 @@ HWTEST_F(SceneSessionManagerLiteStubTest, HandleNotifyAppUseControlList, TestSiz data.WriteInt32(appIndex); data.WriteBool(isControl); - auto res = sceneSessionManagerLiteStub_->SceneSessionManagerLiteStub::HandleNotifyAppUseControlList(data, reply); + auto res = sceneSessionManagerLiteStub_-> + SceneSessionManagerLiteStub::HandleNotifyAppUseControlList(data, reply); + EXPECT_EQ(ERR_INVALID_DATA, res); +} + +/** + * @tc.name: HandleNotifyAppUseControlList02 + * @tc.desc: test function : HandleNotifyAppUseControlList02 + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerLiteStubTest, HandleNotifyAppUseControlList02, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + uint8_t typeId = 1; + int32_t userId = 1; + int32_t size = 1; + std::string bundleName = "appbundleName"; + int32_t appIndex = 1; + bool isControl = true; + bool isControlRecentOnly = true; + data.WriteUint8(typeId); + data.WriteInt32(userId); + data.WriteInt32(size); + AppUseControlInfo controlInfo; + data.WriteParcelable(&controlInfo); + auto res = sceneSessionManagerLiteStub_-> + SceneSessionManagerLiteStub::HandleNotifyAppUseControlList(data, reply); EXPECT_EQ(ERR_NONE, res); } diff --git a/window_scene/test/unittest/scene_session_manager_test10.cpp b/window_scene/test/unittest/scene_session_manager_test10.cpp index d75fe037750f11c323474455cec8c0931379cfa4..8ddd07a2e567d0fc9d505fba6973d35ea7ddfa57 100644 --- a/window_scene/test/unittest/scene_session_manager_test10.cpp +++ b/window_scene/test/unittest/scene_session_manager_test10.cpp @@ -1139,6 +1139,97 @@ HWTEST_F(SceneSessionManagerTest10, NotifyAppUseControlList, TestSize.Level1) appUseControlInfo.isNeedControl_ = true; EXPECT_EQ(WSError::WS_ERROR_INVALID_PERMISSION, ssm_->NotifyAppUseControlList(ControlAppType::APP_LOCK, -1, controlList)); + usleep(WAIT_SYNC_IN_NS); +} + +/** + * @tc.name: NotifyAppUseControlListInner + * @tc.desc: NotifyAppUseControlListInner + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest10, NotifyAppUseControlListInner, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + int32_t controlListSize = -1; + ssm_->notifyAppUseControlListFunc_ = [&controlListSize] + (ControlAppType type, int32_t userId, const std::vector& controlList) { + controlListSize = controlList.size(); + }; + AppUseControlInfo controlById; + controlById.persistentId_ = 100; + controlById.bundleName_ = "bundleName"; + controlById.appIndex_ = 0; + std::vector controlList; + controlList.push_back(controlById); + ssm_->NotifyAppUseControlListInner(ControlAppType::DLP, 0, controlList); + EXPECT_EQ(controlListSize, -1); + ssm_->sceneSessionMap_.emplace(100, nullptr); + ssm_->NotifyAppUseControlListInner(ControlAppType::DLP, 0, controlList); + EXPECT_EQ(controlListSize, -1); + + SessionInfo sessionInfo; + sessionInfo.persistentId_ = 100; + sessionInfo.bundleName_ = "bundleName"; + sessionInfo.appIndex_ = 0; + sessionInfo.windowType_ = 1; + sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); + ssm_->sceneSessionMap_.emplace(100, sceneSession); + + ssm_->NotifyAppUseControlListInner(ControlAppType::DLP, 0, controlList); + EXPECT_EQ(controlListSize, -1); + + AppUseControlInfo controlByBundle; + controlByBundle.bundleName_ = "bundleName"; + controlByBundle.appIndex_ = 0; + controlList.push_back(controlByBundle); + ssm_->NotifyAppUseControlListInner(ControlAppType::DLP, 0, controlList); + EXPECT_EQ(controlListSize, 1); + + ssm_->notifyAppUseControlListFunc_ = nullptr; + controlListSize = -1; + ssm_->NotifyAppUseControlListInner(ControlAppType::DLP, 0, controlList); + EXPECT_EQ(controlListSize, -1); +} + +/** + * @tc.name: NotifyAppUseControlListInner02 + * @tc.desc: NotifyAppUseControlListInner02 + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest10, NotifyAppUseControlListInner02, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + int32_t controlListSize = -1; + ssm_->notifyAppUseControlListFunc_ = [&controlListSize] + (ControlAppType type, int32_t userId, const std::vector& controlList) { + controlListSize = controlList.size(); + }; + std::vector controlList; + AppUseControlInfo controlById; + controlById.persistentId_ = 100; + controlById.bundleName_ = "bundleName"; + controlById.appIndex_ = 0; + controlList.push_back(controlById); + AppUseControlInfo controlById2; + controlById2.persistentId_ = 100; + controlById2.bundleName_ = "errorBundleName"; + controlById2.appIndex_ = 0; + controlList.push_back(controlById2); + AppUseControlInfo controlById3; + controlById3.persistentId_ = 100; + controlById3.bundleName_ = "bundleName"; + controlById3.appIndex_ = 100; + controlList.push_back(controlById3); + + SessionInfo sessionInfo; + sessionInfo.persistentId_ = 100; + sessionInfo.bundleName_ = "bundleName"; + sessionInfo.appIndex_ = 0; + sessionInfo.windowType_ = 1000; + sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); + ssm_->sceneSessionMap_.emplace(100, sceneSession); + ssm_->NotifyAppUseControlListInner(ControlAppType::DLP, 0, controlList); + EXPECT_EQ(controlListSize, -1); } /** diff --git a/window_scene/test/unittest/scene_session_manager_test12.cpp b/window_scene/test/unittest/scene_session_manager_test12.cpp index 9905996fc4a0505a12a76e449300b7e3916364d9..470112c7484aa9bc74ed473cc6e08a223a3a6d55 100644 --- a/window_scene/test/unittest/scene_session_manager_test12.cpp +++ b/window_scene/test/unittest/scene_session_manager_test12.cpp @@ -631,6 +631,77 @@ HWTEST_F(SceneSessionManagerTest12, CreateAndConnectSpecificSession03, TestSize. EXPECT_EQ(WSError::WS_DO_NOTHING, res); } +/** + * @tc.name: CreateAndConnectSpecificSession + * @tc.desc: CreateAndConnectSpecificSession + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, CreateAndConnectSpecificSession04, TestSize.Level1) +{ + sptr sessionStage; + sptr eventChannel; + std::shared_ptr node = nullptr; + sptr property = sptr::MakeSptr(); + sptr session; + SystemSessionConfig systemConfig; + sptr token; + int32_t id = 0; + ASSERT_NE(ssm_, nullptr); + + SessionInfo info; + info.abilityName_ = "test1"; + info.bundleName_ = "test2"; + sptr parentSession = sptr::MakeSptr(info, nullptr); + parentSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH); + ssm_->sceneSessionMap_.insert({ parentSession->GetPersistentId(), parentSession }); + + // Create UI_EXTENSION_SUB_WINDOW success + property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT); + property->SetParentPersistentId(parentSession->GetPersistentId()); + property->SetIsUIExtFirstSubWindow(true); + ssm_->systemConfig_.supportUIExtensionSubWindow_ = true; + ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session, + systemConfig, token); + EXPECT_EQ(property->GetWindowType(), WindowType::WINDOW_TYPE_SCB_SUB_WINDOW); + + // Create UI_EXTENSION_SUB_WINDOW failed + property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT); + ssm_->systemConfig_.supportUIExtensionSubWindow_ = false; + ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session, + systemConfig, token); + EXPECT_NE(property->GetWindowType(), WindowType::WINDOW_TYPE_SCB_SUB_WINDOW); + + // Create UI_EXTENSION_SUB_WINDOW failed + property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT); + property->SetIsUIExtFirstSubWindow(false); + ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session, + systemConfig, token); + EXPECT_NE(property->GetWindowType(), WindowType::WINDOW_TYPE_SCB_SUB_WINDOW); + + // Create UI_EXTENSION_SUB_WINDOW failed + property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT); + parentSession->GetSessionProperty()->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); + ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session, + systemConfig, token); + EXPECT_NE(property->GetWindowType(), WindowType::WINDOW_TYPE_SCB_SUB_WINDOW); +} + +/** + * @tc.name: ApplyFeatureConfig + * @tc.desc: ApplyFeatureConfig + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, ApplyFeatureConfig, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + std::unordered_map configMap = { + {"testKey", "testVal"}, + {"supportUIExtensionSubWindow", "true"} + }; + ssm_->ApplyFeatureConfig(configMap); + EXPECT_TRUE(ssm_->systemConfig_.supportUIExtensionSubWindow_); +} + /** * @tc.name: SetCreateKeyboardSessionListener * @tc.desc: SetCreateKeyboardSessionListener @@ -1793,6 +1864,80 @@ HWTEST_F(SceneSessionManagerTest12, HasFloatingWindowForeground06, TestSize.Leve EXPECT_EQ(hasFloatWindowForeground, false); } +/** + * @tc.name: GetRouterStackInfo01 + * @tc.desc: test function : GetRouterStackInfo01 + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, GetRouterStackInfo01, Function | SmallTest | Level2) +{ + class TestRouterListener : public SessionRouterStackListenerStub { + void SendRouterStackInfo(const sptr& routerStackInfo) override {} + }; + int32_t persistentId = -1; + auto listener = sptr::MakeSptr(); + MockAccesstokenKit::MockIsSystemApp(true); + MockAccesstokenKit::MockIsSACalling(true); + + auto result = ssm_->GetRouterStackInfo(persistentId, listener); + EXPECT_EQ(result, WMError::WM_ERROR_NULLPTR); + + result = ssm_->GetRouterStackInfo(persistentId, nullptr); + EXPECT_EQ(result, WMError::WM_ERROR_NULLPTR); +} + +/** + * @tc.name: GetRouterStackInfo02 + * @tc.desc: test function : GetRouterStackInfo02 + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, GetRouterStackInfo02, Function | SmallTest | Level2) +{ + class TestRouterListener : public SessionRouterStackListenerStub { + void SendRouterStackInfo(const sptr& routerStackInfo) override {} + }; + + SessionInfo info; + info.abilityName_ = "GetRouterStackInfo02"; + info.bundleName_ = "GetRouterStackInfo02"; + info.windowType_ = static_cast(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + sptr sceneSession = sptr::MakeSptr(info, nullptr); + ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession}); + + auto listener = sptr::MakeSptr(); + MockAccesstokenKit::MockIsSystemApp(true); + MockAccesstokenKit::MockIsSACalling(true); + + auto result = ssm_->GetRouterStackInfo(sceneSession->GetPersistentId(), listener); + EXPECT_EQ(result, WMError::WM_OK); +} + +/** + * @tc.name: GetRouterStackInfo03 + * @tc.desc: test function : GetRouterStackInfo03 + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, GetRouterStackInfo03, Function | SmallTest | Level2) +{ + MockAccesstokenKit::MockIsSystemApp(false); + MockAccesstokenKit::MockIsSACalling(false); + auto result = ssm_->GetRouterStackInfo(1, nullptr); + EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION); + + MockAccesstokenKit::MockIsSystemApp(false); + MockAccesstokenKit::MockIsSACalling(true); + result = ssm_->GetRouterStackInfo(1, nullptr); + EXPECT_EQ(result, WMError::WM_ERROR_NULLPTR); + + MockAccesstokenKit::MockIsSystemApp(true); + MockAccesstokenKit::MockIsSACalling(false); + result = ssm_->GetRouterStackInfo(1, nullptr); + EXPECT_EQ(result, WMError::WM_ERROR_NULLPTR); + + MockAccesstokenKit::MockIsSystemApp(true); + MockAccesstokenKit::MockIsSACalling(true); +} + /** * @tc.name: UpdateSessionWithFoldStateChange * @tc.desc: test function : UpdateSessionWithFoldStateChange @@ -1870,6 +2015,121 @@ HWTEST_F(SceneSessionManagerTest12, GetActiveSceneSessionCopy, Function | SmallT EXPECT_EQ(activeSession.empty(), false); } +/** + * @tc.name: GetHookedSessionByModuleName + * @tc.desc: test function : GetHookedSessionByModuleName + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, GetHookedSessionByModuleName, Function | SmallTest | Level2) +{ + SessionInfo info; + info.bundleName_ = "testBundleName1"; + info.moduleName_ = "testModuleName1"; + info.appIndex_ = 1; + info.appInstanceKey_ = ""; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + ASSERT_NE(sceneSession, nullptr); + sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + auto res = ssm_->GetHookedSessionByModuleName(info); + ASSERT_EQ(res, nullptr); + + ssm_->sceneSessionMap_.insert({101, sceneSession}); + res = ssm_->GetHookedSessionByModuleName(info); + ASSERT_EQ(res, sceneSession); + + info.appInstanceKey_ = "testAppInstanceKey1"; + res = ssm_->GetHookedSessionByModuleName(info); + ASSERT_EQ(res, nullptr); + + info.appIndex_ = 2; + res = ssm_->GetHookedSessionByModuleName(info); + ASSERT_EQ(res, nullptr); + + info.moduleName_ = "testModuleName2"; + res = ssm_->GetHookedSessionByModuleName(info); + ASSERT_EQ(res, nullptr); + + info.bundleName_ = "testBundleName2"; + res = ssm_->GetHookedSessionByModuleName(info); + ASSERT_EQ(res, nullptr); +} + +/** + * @tc.name: RequestSceneSession + * @tc.desc: test function : RequestSceneSession + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, RequestSceneSession, Function | SmallTest | Level2) +{ + SessionInfo info; + info.bundleName_ = "testBundleName1"; + info.moduleName_ = "testModuleName1"; + info.abilityName_ = "testAbilityName1"; + info.persistentId_ = 101; + info.appIndex_ = 0; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + ASSERT_NE(sceneSession, nullptr); + sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + sceneSession->sessionInfo_.isAbilityHook_ = true; + sptr windowSessionProperty = sptr::MakeSptr(); + ssm_->sceneSessionMap_[101] = sceneSession; + + auto result = ssm_->RequestSceneSession(info, windowSessionProperty); + ASSERT_NE(result, nullptr); + ASSERT_EQ(result->GetSessionInfo().moduleName_, info.moduleName_); +} + +/** + * @tc.name: RegisterSceneSessionDestructCallback + * @tc.desc: test function : RegisterSceneSessionDestructCallback + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, RegisterSceneSessionDestructCallback, Function | SmallTest | Level2) +{ + NotifySceneSessionDestructFunc func = [](int32_t persistentId) { return; }; + ssm_->RegisterSceneSessionDestructCallback(std::move(func)); + ASSERT_NE(nullptr, ssm_->onSceneSessionDestruct_); +} + +/** + * @tc.name: RegisterSceneSessionDestructNotifyManagerFunc + * @tc.desc: test function : RegisterSceneSessionDestructNotifyManagerFunc + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, RegisterSceneSessionDestructNotifyManagerFunc, Function | SmallTest | Level2) +{ + SessionInfo info; + info.bundleName_ = "RegisterSceneSessionDestructNotifyManageFunc"; + info.moduleName_ = "RegisterSceneSessionDestructNotifyManageFunc"; + info.abilityName_ = "RegisterSceneSessionDestructNotifyManageFunc"; + info.persistentId_ = 999; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + ASSERT_NE(sceneSession, nullptr); + NotifySceneSessionDestructFunc func = [](int32_t persistentId) { return; }; + ssm_->RegisterSceneSessionDestructCallback(std::move(func)); + ssm_->RegisterSceneSessionDestructNotifyManagerFunc(sceneSession); + ASSERT_NE(sceneSession->notifySceneSessionDestructFunc_, nullptr); +} + +/** + * @tc.name: UpdateAbilityHookState + * @tc.desc: test function : UpdateAbilityHookState + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, UpdateAbilityHookState, Function | SmallTest | Level2) +{ + SessionInfo info; + info.bundleName_ = "UpdateAbilityHookState_bundle"; + info.moduleName_ = "UpdateAbilityHookState_module"; + info.abilityName_ = "UpdateAbilityHookState_ability"; + info.persistentId_ = 101; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + ASSERT_NE(sceneSession, nullptr); + + ssm_->UpdateAbilityHookState(sceneSession, true); + EXPECT_EQ(true, sceneSession->GetSessionInfo().isAbilityHook_); +} + /** * @tc.name: GetKeyboardOccupiedAreaWithRotation1 * @tc.desc: PC device is not compatible diff --git a/window_scene/test/unittest/scene_session_manager_test2.cpp b/window_scene/test/unittest/scene_session_manager_test2.cpp index 5ff75d6e2517f66dfc78869dffed2a1ec3fa2dcc..3b12189cbee773c02faf4ecdb83d7a7ced4e110c 100644 --- a/window_scene/test/unittest/scene_session_manager_test2.cpp +++ b/window_scene/test/unittest/scene_session_manager_test2.cpp @@ -1392,6 +1392,184 @@ HWTEST_F(SceneSessionManagerTest2, ConfigFreeMultiWindowForDefaultDragResizeType ASSERT_EQ(ssm_->systemConfig_.freeMultiWindowConfig_.defaultDragResizeType_, DragResizeType::RESIZE_WHEN_DRAG_END); } +/** + * @tc.name: ConfigFreeMultiWindow + * @tc.desc: call ConfigFreeMultiWindow. + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest2, ConfigFreeMultiWindowTest, TestSize.Level1) +{ + ssm_->systemConfig_.freeMultiWindowConfig_.defaultDragResizeType_ = DragResizeType::RESIZE_TYPE_UNDEFINED; + std::string xmlStr = + "" + "" + "" + "" + "" + "" + "" + "0" + "1" + "2" + "0.5" + "" + "" + "0" + "#000000" + "1" + "1" + "0" + "0.5" + "" + "" + "" + "" + "0" + "1" + "2" + "" + "" + "0" + "#000000" + "1" + "1" + "0" + "0.5" + "" + "" + "" + "" + "" + ""; + WindowSceneConfig::config_ = ReadConfig(xmlStr); + ssm_->ConfigFreeMultiWindow(); + // freeMultiWindow windowEffect + auto windowEffect = ssm_->systemConfig_.freeMultiWindowConfig_.appWindowSceneConfig_; + + ASSERT_FLOAT_EQ(windowEffect.focusedShadow_.alpha_, 0); + ASSERT_FLOAT_EQ(windowEffect.focusedShadow_.offsetX_, 1); + ASSERT_FLOAT_EQ(windowEffect.focusedShadow_.offsetY_, 2); + ASSERT_FLOAT_EQ(windowEffect.focusedShadow_.radius_, 0.5); + ASSERT_FLOAT_EQ(windowEffect.unfocusedShadow_.alpha_, 0); + ASSERT_FLOAT_EQ(windowEffect.unfocusedShadow_.offsetX_, 1); + ASSERT_FLOAT_EQ(windowEffect.unfocusedShadow_.offsetY_, 1); + ASSERT_FLOAT_EQ(windowEffect.unfocusedShadow_.radius_, 0.5); +} + +/** + * @tc.name: LoadFreeMultiWindowConfigTest + * @tc.desc: call LoadFreeMultiWindowConfig + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest2, LoadFreeMultiWindowConfigTest, TestSize.Level1) +{ + ssm_->systemConfig_.freeMultiWindowConfig_.defaultDragResizeType_ = DragResizeType::RESIZE_TYPE_UNDEFINED; + std::string xmlStr = + "" + "" + "" + "" + "" + "" + "0" + "1" + "2" + "2" + "0" + "" + "" + "0" + "#000000" + "2" + "2" + "1" + "0" + "" + "" + "" + "" + "0" + "2" + "2" + "" + "" + "0" + "#000000" + "2" + "2" + "0" + "0.5" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "0" + "#000000" + "0" + "3" + "3" + "0.5" + "" + "" + "0" + "#000000" + "3" + "3" + "0" + "0.5" + "" + "" + "" + "" + "0" + "3" + "3" + "0.5" + "" + "" + "0" + "#000000" + "3" + "3" + "0" + "0.5" + "" + "" + "" + "" + "" + ""; + WindowSceneConfig::config_ = ReadConfig(xmlStr); + ssm_->ConfigFreeMultiWindow(); + ASSERT_EQ(ssm_->systemConfig_.freeMultiWindowSupport_, true); + // load windowEffect + ssm_->LoadFreeMultiWindowConfig(false); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.focusedShadow_.offsetX_, 2); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.focusedShadow_.offsetY_, 2); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.focusedShadow_.alpha_, 1); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.focusedShadow_.radius_, 0); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.unfocusedShadow_.alpha_, 1); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.unfocusedShadow_.offsetX_, 2); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.unfocusedShadow_.offsetY_, 2); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.unfocusedShadow_.radius_, 0); + + // load FreeMultiWindow windowEffect config + ssm_->LoadFreeMultiWindowConfig(true); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.focusedShadow_.alpha_, 0); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.focusedShadow_.offsetX_, 3); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.focusedShadow_.offsetY_, 3); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.focusedShadow_.radius_, 0.5); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.unfocusedShadow_.alpha_, 0); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.unfocusedShadow_.offsetX_, 3); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.unfocusedShadow_.offsetY_, 3); + ASSERT_FLOAT_EQ(ssm_->appWindowSceneConfig_.unfocusedShadow_.radius_, 0.5); +} + /** * @tc.name: Init * @tc.desc: SceneSesionManager init diff --git a/window_scene/test/unittest/scene_session_manager_test3.cpp b/window_scene/test/unittest/scene_session_manager_test3.cpp index f42cd7defee7cb830418c99fe1288886e16f720c..313944928acb22b50d371323b22d2f49cc7a605b 100644 --- a/window_scene/test/unittest/scene_session_manager_test3.cpp +++ b/window_scene/test/unittest/scene_session_manager_test3.cpp @@ -1173,6 +1173,44 @@ HWTEST_F(SceneSessionManagerTest3, HandleHideNonSystemFloatingWindows, TestSize. ASSERT_EQ(result, WindowModeSupport::WINDOW_MODE_SUPPORT_ALL); } +/** + +@tc.name: UpdateForceHideState +@tc.desc: SceneSesionManager update Force Hide system state +@tc.type: FUNC +*/ +HWTEST_F(SceneSessionManagerTest3, UpdateForceHideState, TestSize.Level1) +{ + SessionInfo info; + info.abilityName_ = "UpdateForceHideState"; + info.bundleName_ = "UpdateForceHideState"; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + sptr property = sptr::MakeSptr(); + ssm_->systemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW; + property->SetHideNonSystemFloatingWindows(true); + sceneSession->property_->windowMode_ = WindowMode::WINDOW_MODE_PIP; + ssm_->systemTopSceneSessionMap_.clear(); + ssm_->UpdateForceHideState(sceneSession, property, true); + EXPECT_EQ(ssm_->systemTopSceneSessionMap_.size(), 0); + property->SetHideNonSystemFloatingWindows(true); + sceneSession->property_->windowMode_ = WindowMode::WINDOW_MODE_FLOATING; + ssm_->systemTopSceneSessionMap_.clear(); + ssm_->UpdateForceHideState(sceneSession, property, true); + EXPECT_EQ(ssm_->systemTopSceneSessionMap_.size(), 1); + property->SetHideNonSystemFloatingWindows(false); + property->SetFloatingWindowAppType(true); + property->SetSystemCalling(false); + sceneSession->property_->windowMode_ = WindowMode::WINDOW_MODE_PIP; + ssm_->systemTopSceneSessionMap_.clear(); + ssm_->UpdateForceHideState(sceneSession, property, true); + EXPECT_EQ(ssm_->systemTopSceneSessionMap_.size(), 0); + property->SetHideNonSystemFloatingWindows(false); + sceneSession->property_->windowMode_ = WindowMode::WINDOW_MODE_FLOATING; + ssm_->systemTopSceneSessionMap_.clear(); + ssm_->UpdateForceHideState(sceneSession, property, true); + EXPECT_EQ(ssm_->systemTopSceneSessionMap_.size(), 0); +} + /** * @tc.name: UpdateBrightness01 * @tc.desc: SceneSesionManager update brightness diff --git a/window_scene/test/unittest/scene_session_manager_test4.cpp b/window_scene/test/unittest/scene_session_manager_test4.cpp index dd74e359375c42a8dd325afd8b030073ba292635..ea7e6cf1527e22017d8ea39388bd3ec9d0acac3f 100644 --- a/window_scene/test/unittest/scene_session_manager_test4.cpp +++ b/window_scene/test/unittest/scene_session_manager_test4.cpp @@ -1533,6 +1533,74 @@ HWTEST_F(SceneSessionManagerTest4, GetAllClearableSessions, TestSize.Level1) EXPECT_FALSE(sessionVector.empty()); } +/** + * @tc.name: PostBrightnessTask01 + * @tc.desc: PostBrightnessTask + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest4, PostBrightnessTask01, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; + ssm_->SetDisplayBrightness(999); + + sptr sceneSession = nullptr; + ssm_->PostBrightnessTask(sceneSession, -1.0f); + EXPECT_EQ(ssm_->GetDisplayBrightness(), 999.0f); + ssm_->PostBrightnessTask(sceneSession, 1.0f); + EXPECT_EQ(ssm_->GetDisplayBrightness(), 999.0f); + + SessionInfo sessionInfo; + sessionInfo.isSystem_ = false; + sessionInfo.bundleName_ = "bundleName"; + sceneSession = sptr::MakeSptr(sessionInfo, nullptr); + sceneSession->SetSessionState(SessionState::STATE_DISCONNECT); + ssm_->PostBrightnessTask(sceneSession, -1.0f); + EXPECT_EQ(ssm_->GetDisplayBrightness(), 999.0f); + ssm_->PostBrightnessTask(sceneSession, 1.0f); + EXPECT_EQ(ssm_->GetDisplayBrightness(), 999.0f); + + sceneSession->SetSessionState(SessionState::STATE_FOREGROUND); + ssm_->PostBrightnessTask(sceneSession, -1.0f); + EXPECT_EQ(ssm_->GetDisplayBrightness(), -1.0f); + ssm_->PostBrightnessTask(sceneSession, 1.0f); + EXPECT_EQ(ssm_->GetDisplayBrightness(), 1.0f); +} + +/** + * @tc.name: PostBrightnessTask02 + * @tc.desc: PostBrightnessTask + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest4, PostBrightnessTask02, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; + ssm_->SetDisplayBrightness(999); + + sptr sceneSession = nullptr; + ssm_->PostBrightnessTask(sceneSession, -1.0f); + EXPECT_EQ(ssm_->GetDisplayBrightness(), 999.0f); + ssm_->PostBrightnessTask(sceneSession, 1.0f); + EXPECT_EQ(ssm_->GetDisplayBrightness(), 999.0f); + + SessionInfo sessionInfo; + sessionInfo.isSystem_ = false; + sessionInfo.bundleName_ = "bundleName"; + sceneSession = sptr::MakeSptr(sessionInfo, nullptr); + sceneSession->SetSessionState(SessionState::STATE_DISCONNECT); + ssm_->PostBrightnessTask(sceneSession, -1.0f); + EXPECT_EQ(ssm_->GetDisplayBrightness(), 999.0f); + ssm_->PostBrightnessTask(sceneSession, 1.0f); + EXPECT_EQ(ssm_->GetDisplayBrightness(), 999.0f); + + sceneSession->SetSessionState(SessionState::STATE_FOREGROUND); + ssm_->PostBrightnessTask(sceneSession, -1.0f); + EXPECT_EQ(ssm_->GetDisplayBrightness(), 999.0f); + ssm_->PostBrightnessTask(sceneSession, 1.0f); + EXPECT_EQ(ssm_->GetDisplayBrightness(), 1.0f); +} + /** * @tc.name: UpdateBrightness * @tc.desc: UpdateBrightness diff --git a/window_scene/test/unittest/scene_session_manager_test8.cpp b/window_scene/test/unittest/scene_session_manager_test8.cpp index 5162e883aceb06b368659d60e0eb51a3fe47225e..f1e9f793cbbf371f7c5b4d01ce2a86e0b41a12b1 100644 --- a/window_scene/test/unittest/scene_session_manager_test8.cpp +++ b/window_scene/test/unittest/scene_session_manager_test8.cpp @@ -560,6 +560,7 @@ HWTEST_F(SceneSessionManagerTest8, SetBrightness, TestSize.Level1) sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); EXPECT_NE(nullptr, sceneSession); sceneSession->persistentId_ = 2024; + sceneSession->SetSessionState(SessionState::STATE_FOREGROUND); ssm_->SetDisplayBrightness(3.14f); std::shared_ptr pipeEventHandler = nullptr; diff --git a/window_scene/test/unittest/scene_session_test.cpp b/window_scene/test/unittest/scene_session_test.cpp index afca7ed333db2c7f2a874db21d5ec47e665ccafd..b030f899e8a6ffa178afa81ecd9dd964c8e8a151 100644 --- a/window_scene/test/unittest/scene_session_test.cpp +++ b/window_scene/test/unittest/scene_session_test.cpp @@ -688,11 +688,11 @@ HWTEST_F(SceneSessionTest, UpdatePrivacyModeControlInfo02, Function | SmallTest } /** - * @tc.name: HasSubSessionInPrivacyMode - * @tc.desc: HasSubSessionInPrivacyMode + * @tc.name: HasChildSessionInPrivacyMode + * @tc.desc: HasChildSessionInPrivacyMode * @tc.type: FUNC */ -HWTEST_F(SceneSessionTest, HasSubSessionInPrivacyMode, Function | SmallTest | Level3) +HWTEST_F(SceneSessionTest, HasChildSessionInPrivacyMode, Function | SmallTest | Level3) { SessionInfo info; info.bundleName_ = "testBundleName"; @@ -717,7 +717,40 @@ HWTEST_F(SceneSessionTest, HasSubSessionInPrivacyMode, Function | SmallTest | Le subSession->AddSubSession(subSession2); sceneSession->AddSubSession(subSession); - EXPECT_EQ(sceneSession->HasSubSessionInPrivacyMode(), true); + EXPECT_EQ(sceneSession->HasChildSessionInPrivacyMode(), true); +} + +/** + * @tc.name: HasChildSessionInPrivacyMode02 + * @tc.desc: HasChildSessionInPrivacyMode02 + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, HasChildSessionInPrivacyMode02, Function | SmallTest | Level3) +{ + SessionInfo info; + info.bundleName_ = "testBundleName"; + info.abilityName_ = "testAbilityName"; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + sceneSession->property_ = nullptr; + sptr dialogSessionCb = + sptr::MakeSptr(); + sptr dialogSession = sptr::MakeSptr(info, dialogSessionCb); + dialogSessionCb->onGetSceneSessionByIdCallback_ = [&dialogSession](int32_t id) { return dialogSession; }; + sceneSession->BindDialogToParentSession(dialogSession); + EXPECT_FALSE(sceneSession->HasChildSessionInPrivacyMode()); + sptr property = sptr::MakeSptr(); + property->SetPrivacyMode(false); + dialogSession->property_ = property; + EXPECT_FALSE(sceneSession->HasChildSessionInPrivacyMode()); + dialogSession->property_->SetPrivacyMode(true); + EXPECT_TRUE(sceneSession->HasChildSessionInPrivacyMode()); + + dialogSession->property_->SetPrivacyMode(false); + sptr dialogSession2 = sptr::MakeSptr(info, nullptr); + dialogSession2->property_ = sptr::MakeSptr(); + dialogSession2->property_->SetPrivacyMode(true); + dialogSession->BindDialogToParentSession(dialogSession2); + EXPECT_FALSE(sceneSession->HasChildSessionInPrivacyMode()); } /** @@ -773,6 +806,39 @@ HWTEST_F(SceneSessionTest, UpdateAcrossDisplaysChangeRegistered01, TestSize.Leve EXPECT_NE(ret, WMError::WM_OK); } +/** + * @tc.name: ColorMode01 + * @tc.desc: Test OnUpdateColorMode And GetAbilityColorMode + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, ColorMode01, TestSize.Level0) +{ + SessionInfo info; + info.abilityName_ = "test"; + info.bundleName_ = "test"; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + ASSERT_NE(sceneSession, nullptr); + std::string colorMode = "dark"; + bool hasDarkRes = true; + auto ret = sceneSession->OnUpdateColorMode(colorMode, hasDarkRes); + EXPECT_NE(WMError::WM_OK, ret); + + std::string resMode = sceneSession->GetAbilityColorMode(); + EXPECT_NE("dark", resMode); + + hasDarkRes = false; + ret = sceneSession->OnUpdateColorMode(colorMode, hasDarkRes); + EXPECT_NE(WMError::WM_OK, ret); + resMode = sceneSession->GetAbilityColorMode(); + EXPECT_NE("auto", resMode); + + colorMode = "light"; + ret = sceneSession->OnUpdateColorMode(colorMode, hasDarkRes); + EXPECT_NE(WMError::WM_OK, ret); + resMode = sceneSession->GetAbilityColorMode(); + EXPECT_NE("light", resMode); +} + /** * @tc.name: IsMainWindowFullScreenAcrossDisplays * @tc.desc: IsMainWindowFullScreenAcrossDisplays01 diff --git a/window_scene/test/unittest/scene_session_test5.cpp b/window_scene/test/unittest/scene_session_test5.cpp index 36b9cc8d434dd18b6277322ecc48f3fda8e166e9..c403483567dda5c6c9281f890b09b64aac757516 100644 --- a/window_scene/test/unittest/scene_session_test5.cpp +++ b/window_scene/test/unittest/scene_session_test5.cpp @@ -2803,12 +2803,19 @@ HWTEST_F(SceneSessionTest5, GetTargetOrientationConfigInfo, Function | SmallTest */ HWTEST_F(SceneSessionTest5, NotifyRotationProperty, Function | SmallTest | Level2) { + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); SessionInfo info; info.abilityName_ = "NotifyRotationProperty"; info.bundleName_ = "NotifyRotationProperty"; sptr sceneSession = sptr::MakeSptr(info, nullptr); EXPECT_NE(sceneSession, nullptr); + sceneSession->GetSessionProperty()->SetDisplayId(1001); + ScreenSessionConfig config; + sptr screenSession = sptr::MakeSptr(config, + ScreenSessionReason::CREATE_SESSION_FOR_CLIENT); + ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(1001, screenSession); WSError result = sceneSession->NotifyRotationProperty(0, 0, 0); EXPECT_EQ(result, WSError::WS_OK); @@ -2818,6 +2825,44 @@ HWTEST_F(SceneSessionTest5, NotifyRotationProperty, Function | SmallTest | Level EXPECT_EQ(result2, WSError::WS_OK); WSError result3 = sceneSession->NotifyRotationProperty(90, 1, 1); EXPECT_EQ(result3, WSError::WS_OK); + sceneSession->GetSessionProperty()->SetDisplayId(1024); + ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(1024, nullptr); + sceneSession->NotifyRotationProperty(90, 1, 1); + usleep(100000); + EXPECT_TRUE(g_errLog.find("failed to convert Rotation to Orientation") != std::string::npos); +} + +/** + * @tc.name: ConvertRotationToOrientation + * @tc.desc: ConvertRotationToOrientation + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest5, ConvertRotationToOrientation, Function | SmallTest | Level2) +{ + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + SessionInfo info; + info.abilityName_ = "ConvertRotationToOrientation"; + info.bundleName_ = "ConvertRotationToOrientation"; + + sptr sceneSession = sptr::MakeSptr(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + sceneSession->GetSessionProperty()->SetDisplayId(1001); + ScreenSessionConfig config; + sptr screenSession = sptr::MakeSptr(config, + ScreenSessionReason::CREATE_SESSION_FOR_CLIENT); + ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(1001, screenSession); + + uint32_t orientation = 0; + WSError result = sceneSession->ConvertRotationToOrientation(90, orientation); + EXPECT_EQ(result, WSError::WS_OK); + + sceneSession->GetSessionProperty()->SetDisplayId(1024); + ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(1024, nullptr); + uint32_t orientation1 = 0; + WSError result1 = sceneSession->ConvertRotationToOrientation(90, orientation1); + EXPECT_EQ(result1, WSError::WS_ERROR_INVALID_DISPLAY); + EXPECT_TRUE(g_errLog.find("Screen session is null") != std::string::npos); } /** diff --git a/window_scene/test/unittest/scene_session_test6.cpp b/window_scene/test/unittest/scene_session_test6.cpp index 8d5d0f627e01aedf5b6a6880f786e880de79d119..bd244bf0d1cd4449b5d62820bc7c4f2a32f8292f 100644 --- a/window_scene/test/unittest/scene_session_test6.cpp +++ b/window_scene/test/unittest/scene_session_test6.cpp @@ -593,6 +593,46 @@ HWTEST_F(SceneSessionTest6, IsInCompatScaleMode, TestSize.Level1) EXPECT_TRUE(session->IsInCompatScaleMode()); } +/** + * @tc.name: IsInCompatScaleMode_forSubWindow + * @tc.desc: IsInCompatScaleMode + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest6, IsInCompatScaleMode_forSubWindow, TestSize.Level1) +{ + SessionInfo info; + info.abilityName_ = "IsInCompatScaleMode_forSubWindow"; + info.bundleName_ = "IsInCompatScaleMode_forSubWindow"; + info.screenId_ = 0; + sptr subSession = sptr::MakeSptr(info, nullptr); + sptr mainSession = sptr::MakeSptr(info, nullptr); + EXPECT_FALSE(subSession->IsInCompatScaleMode()); + subSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); + EXPECT_FALSE(subSession->IsInCompatScaleMode()); + + sptr callBack = sptr::MakeSptr(); + subSession->specificCallback_ = callBack; + auto task = [&mainSession](int32_t persistentId) { return mainSession; }; + callBack->onGetSceneSessionByIdCallback_ = task; + subSession->SetCallingPid(1); + mainSession->SetCallingPid(2); + EXPECT_FALSE(subSession->IsInCompatScaleMode()); + + mainSession->SetCallingPid(1); + EXPECT_FALSE(subSession->IsInCompatScaleMode()); + + sptr compatibleModeProperty = sptr::MakeSptr(); + compatibleModeProperty->SetIsAdaptToProportionalScale(true); + mainSession->property_->SetCompatibleModeProperty(compatibleModeProperty); + EXPECT_TRUE(subSession->IsInCompatScaleMode()); + + compatibleModeProperty->SetIsAdaptToProportionalScale(false); + compatibleModeProperty->SetIsAdaptToSimulationScale(true); + EXPECT_TRUE(subSession->IsInCompatScaleMode()); + compatibleModeProperty->SetIsAdaptToProportionalScale(true); + EXPECT_TRUE(subSession->IsInCompatScaleMode()); +} + /** * @tc.name: GetSystemAvoidArea * @tc.desc: GetSystemAvoidArea function @@ -1202,6 +1242,24 @@ HWTEST_F(SceneSessionTest6, SetWindowTransitionAnimation, Function | SmallTest | ret = session->SetWindowTransitionAnimation(transitionType, animation); ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_CALLING); } + +/** + * @tc.name: SetSupportEnterWaterfallMode + * @tc.desc: SetSupportEnterWaterfallMode + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest6, SetSupportEnterWaterfallMode, Function | SmallTest | Level1) +{ + SessionInfo info; + sptr session = sptr::MakeSptr(info, nullptr); + session->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; + session->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + session->SetSupportEnterWaterfallMode(true); + + session->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); + session->SetSupportEnterWaterfallMode(true); + EXPECT_TRUE(session->sessionStage_ != nullptr); +} } // namespace } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/session_proxy_test.cpp b/window_scene/test/unittest/session_proxy_test.cpp index 7b9ce9238cec691e38c30cc92e59ab1d379c1ed4..393eef5244241af078601b15b9da81fa517dd3e0 100755 --- a/window_scene/test/unittest/session_proxy_test.cpp +++ b/window_scene/test/unittest/session_proxy_test.cpp @@ -1612,6 +1612,47 @@ HWTEST_F(SessionProxyTest, IsMainWindowFullScreenAcrossDisplays, Function | Smal MockMessageParcel::ClearAllErrorFlag(); } +/** + * @tc.name: OnUpdateColorMode + * @tc.desc: OnUpdateColorMode test + * @tc.type: FUNC + */ +HWTEST_F(SessionProxyTest, OnUpdateColorMode, Function | SmallTest | Level2) +{ + std::string colorMode = "DARK"; + bool hasDarkRes = true; + auto sProxy = sptr::MakeSptr(nullptr); + ASSERT_NE(sProxy, nullptr); + auto ret = sProxy->OnUpdateColorMode(colorMode, hasDarkRes); + EXPECT_EQ(ret, WMError::WM_ERROR_IPC_FAILED); + + sptr remoteMocker = sptr::MakeSptr(); + sProxy = sptr::MakeSptr(remoteMocker); + ASSERT_NE(sProxy, nullptr); + ret = sProxy->OnUpdateColorMode(colorMode, hasDarkRes); + EXPECT_EQ(ret, WMError::WM_OK); + + remoteMocker->SetRequestResult(ERR_INVALID_DATA); + ret = sProxy->OnUpdateColorMode(colorMode, hasDarkRes); + EXPECT_EQ(ret, WMError::WM_ERROR_IPC_FAILED); + remoteMocker->SetRequestResult(ERR_NONE); + + MockMessageParcel::SetWriteBoolErrorFlag(true); + ret = sProxy->OnUpdateColorMode(colorMode, hasDarkRes); + EXPECT_EQ(ret, WMError::WM_ERROR_IPC_FAILED); + + MockMessageParcel::SetWriteStringErrorFlag(true); + ret = sProxy->OnUpdateColorMode(colorMode, hasDarkRes); + EXPECT_EQ(ret, WMError::WM_ERROR_IPC_FAILED); + + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); + ret = sProxy->OnUpdateColorMode(colorMode, hasDarkRes); + EXPECT_EQ(ret, WMError::WM_ERROR_IPC_FAILED); + MockMessageParcel::SetWriteBoolErrorFlag(false); + MockMessageParcel::SetWriteStringErrorFlag(false); + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false); +} + /** * @tc.name: GetTargetOrientationConfigInfo * @tc.desc: GetTargetOrientationConfigInfo test diff --git a/window_scene/test/unittest/session_specific_window_test.cpp b/window_scene/test/unittest/session_specific_window_test.cpp index 01f51daa744d4163bc32ef2381201e245a854a66..d9a1eab8c124692dd1d3b76fbcb667c99f52cd3b 100644 --- a/window_scene/test/unittest/session_specific_window_test.cpp +++ b/window_scene/test/unittest/session_specific_window_test.cpp @@ -715,6 +715,49 @@ HWTEST_F(SessionSpecificWindowTest, HandleSubWindowClick07, Function | SmallTest MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, false); EXPECT_EQ(hasNotifyManagerToRequestFocus, true); } + +/** + * @tc.name: HandleSubWindowClick08 + * @tc.desc: HandleSubWindowClick + * @tc.type: FUNC + */ +HWTEST_F(SessionSpecificWindowTest, HandleSubWindowClick08, Function | SmallTest | Level2) +{ + ASSERT_NE(session_, nullptr); + + SessionInfo info; + info.abilityName_ = "testSession1"; + info.moduleName_ = "testSession2"; + info.bundleName_ = "testSession3"; + sptr parentSession = sptr::MakeSptr(info); + + bool hasNotifyManagerToRaise = false; + parentSession->SetClickListener([&hasNotifyManagerToRaise](bool requestFocus, bool isClick) { + hasNotifyManagerToRaise = true; + }); + + session_->property_->SetRaiseEnabled(false); + hasNotifyManagerToRaise = false; + session_->HandleSubWindowClick(MMI::PointerEvent::POINTER_ACTION_HOVER_ENTER, + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, false); + EXPECT_EQ(hasNotifyManagerToRaise, false); + + session_->SetParentSession(parentSession); + hasNotifyManagerToRaise = false; + session_->HandleSubWindowClick(MMI::PointerEvent::POINTER_ACTION_MOVE, + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, false); + EXPECT_EQ(hasNotifyManagerToRaise, false); + + hasNotifyManagerToRaise = false; + session_->HandleSubWindowClick(MMI::PointerEvent::POINTER_ACTION_HOVER_ENTER, + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, false); + EXPECT_EQ(hasNotifyManagerToRaise, true); + + hasNotifyManagerToRaise = false; + session_->HandleSubWindowClick(MMI::PointerEvent::POINTER_ACTION_DOWN, + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, false); + EXPECT_EQ(hasNotifyManagerToRaise, true); +} } // namespace } // namespace Rosen } // namespace OHOS diff --git a/window_scene/test/unittest/session_stub_test.cpp b/window_scene/test/unittest/session_stub_test.cpp index 4010887e4a782d9f5a31f707a0f087ebcf007285..cf565667cbc2fa3adaf11f7ba35dcec66d8f8ce0 100644 --- a/window_scene/test/unittest/session_stub_test.cpp +++ b/window_scene/test/unittest/session_stub_test.cpp @@ -1202,6 +1202,28 @@ HWTEST_F(SessionStubTest, HandleIsMainWindowFullScreenAcrossDisplays, Function | EXPECT_EQ(0, sessionStub->ProcessRemoteRequest(code, data, reply, option)); } +/** + * @tc.name: HandleUpdateColorMode + * @tc.desc: sessionStub HandleUpdateColorMode + * @tc.type: FUNC + */ +HWTEST_F(SessionStubTest, HandleUpdateColorMode, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteString("DARK"); + data.WriteBool(true); + sptr sessionStub = sptr::MakeSptr(); + ASSERT_NE(nullptr, sessionStub); + auto result = sessionStub->HandleUpdateColorMode(data, reply); + EXPECT_EQ(result, ERR_NONE); + + data.WriteInterfaceToken(SessionStub::GetDescriptor()); + uint32_t code = static_cast(SessionInterfaceCode::TRANS_ID_UPDATE_COLOR_MODE); + EXPECT_EQ(0, sessionStub->ProcessRemoteRequest(code, data, reply, option)); +} + /** * @tc.name: HandleNotifyKeyboardWillShowRegistered * @tc.desc: sessionStub HandleNotifyKeyboardWillShowRegistered diff --git a/window_scene/test/unittest/session_test.cpp b/window_scene/test/unittest/session_test.cpp index 3cd93ebabf7a4078f8a3b25ddbc4a8e8483945f2..89768221ad7aa40bc35e4d0af736c02b750ffc37 100644 --- a/window_scene/test/unittest/session_test.cpp +++ b/window_scene/test/unittest/session_test.cpp @@ -187,8 +187,16 @@ HWTEST_F(WindowSessionTest, SetActive01, TestSize.Level1) */ HWTEST_F(WindowSessionTest, SetCompatibleModeProperty, TestSize.Level1) { - sptr compatibleModeProperty = sptr::MakeSptr(); - ASSERT_EQ(WSError::WS_OK, session_->SetCompatibleModeProperty(compatibleModeProperty)); + sptr compatibleModeProperty = nullptr; + session_->sessionStage_ = mockSessionStage_; + EXPECT_EQ(WSError::WS_OK, session_->SetCompatibleModeProperty(compatibleModeProperty)); + EXPECT_EQ(session_->GetSessionProperty()->GetDragEnabled(), true); + compatibleModeProperty = sptr::MakeSptr(); + EXPECT_EQ(WSError::WS_OK, session_->SetCompatibleModeProperty(compatibleModeProperty)); + EXPECT_EQ(session_->GetSessionProperty()->GetDragEnabled(), true); + compatibleModeProperty->SetDisableDragResize(true); + EXPECT_EQ(WSError::WS_OK, session_->SetCompatibleModeProperty(compatibleModeProperty)); + EXPECT_EQ(session_->GetSessionProperty()->GetDragEnabled(), false); } /** diff --git a/window_scene/test/unittest/system_session_test.cpp b/window_scene/test/unittest/system_session_test.cpp index f7eab8d5bab29e750839c55dbd8e4caad05129a6..a421e35164117f7862100b4a0ea540d056903c8d 100644 --- a/window_scene/test/unittest/system_session_test.cpp +++ b/window_scene/test/unittest/system_session_test.cpp @@ -965,15 +965,14 @@ HWTEST_F(SystemSessionTest, RestoreFbMainWindow, Function | SmallTest | Level2) EXPECT_EQ(systemSession->RestoreFbMainWindow(want), WMError::WM_ERROR_INVALID_CALLING); LOCK_GUARD_EXPR(SCENE_GUARD, systemSession->SetCallingPid(IPCSkeleton::GetCallingPid())); - EXPECT_EQ(systemSession->RestoreFbMainWindow(want), WMError::WM_ERROR_FB_RESTORE_MAIN_WINDOW_FAILED); - std::string bundle = "testBundle"; want->SetBundle(bundle); EXPECT_EQ(systemSession->RestoreFbMainWindow(want), WMError::WM_ERROR_FB_RESTORE_MAIN_WINDOW_FAILED); + systemSession->EditSessionInfo().bundleName_ = bundle; - uint64_t nowTime = static_cast(std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count()); - systemSession->fbClickTime_ = nowTime - 1000; + EXPECT_EQ(systemSession->RestoreFbMainWindow(want), WMError::WM_ERROR_FB_RESTORE_MAIN_WINDOW_FAILED); + + ++systemSession->fbClickCnt_; EXPECT_EQ(systemSession->RestoreFbMainWindow(want), WMError::WM_OK); } diff --git a/window_scene/test/unittest/ui_extension/extension_session_test.cpp b/window_scene/test/unittest/ui_extension/extension_session_test.cpp index 1f001435652353236eb271c3881e80c2592d323c..731d24f633a8ba3291f8d9bddac4b2bd6ffe6808 100644 --- a/window_scene/test/unittest/ui_extension/extension_session_test.cpp +++ b/window_scene/test/unittest/ui_extension/extension_session_test.cpp @@ -844,6 +844,10 @@ HWTEST_F(ExtensionSessionTest, Background, TestSize.Level0) extensionSession_->state_ = SessionState::STATE_DISCONNECT; res = extensionSession_->Background(); ASSERT_EQ(res, WSError::WS_ERROR_INVALID_SESSION); + + extensionSession_->state_ = SessionState::STATE_BACKGROUND; + res = extensionSession_->Background(); + ASSERT_EQ(res, WSError::WS_OK); } /** diff --git a/window_scene/test/unittest/ui_extension/scene_session_manager_extension_test.cpp b/window_scene/test/unittest/ui_extension/scene_session_manager_extension_test.cpp index 41a643c1a5a6f9db5abb17286d823d63b10baa4f..fc42082f2dadf9f6e6beb1c6a3d2dd80cccc220d 100644 --- a/window_scene/test/unittest/ui_extension/scene_session_manager_extension_test.cpp +++ b/window_scene/test/unittest/ui_extension/scene_session_manager_extension_test.cpp @@ -72,69 +72,87 @@ void SceneSessionManagerExtensionTest::TearDown() namespace { /** - * @tc.name: CheckSubSessionStartedByExtensionAndSetDisplayId01 + * @tc.name: SetExtensionSubSessionDisplayId * @tc.desc: normal test * @tc.type: FUNC */ -HWTEST_F(SceneSessionManagerExtensionTest, CheckSubSessionStartedByExtensionAndSetDisplayId01, TestSize.Level1) +HWTEST_F(SceneSessionManagerExtensionTest, SetExtensionSubSessionDisplayId, TestSize.Level1) { ASSERT_NE(ssm_, nullptr); SessionInfo info; + info.bundleName_ = BUNDLE_NAME; sptr callback = ssm_->CreateSpecificSessionCallback(); sptr parentSession = sptr::MakeSptr(info, callback); + parentSession->property_->SetPersistentId(1); + parentSession->persistentId_ = 1; ssm_->sceneSessionMap_.insert({ parentSession->GetPersistentId(), parentSession }); sptr token; + constexpr DisplayId displayId = 0; sptr property = sptr::MakeSptr(); sptr sessionStage = sptr::MakeSptr(); - EXPECT_EQ(ssm_->CheckSubSessionStartedByExtensionAndSetDisplayId(token, property, sessionStage), - WSError::WS_ERROR_NULLPTR); + property->SetParentPersistentId(100000); + property->SetDisplayId(100); + ssm_->SetExtensionSubSessionDisplayId(property, sessionStage); + EXPECT_NE(property->GetDisplayId(), displayId); + property->SetParentPersistentId(parentSession->GetPersistentId()); - constexpr DisplayId displayId = 0; - parentSession->GetSessionProperty()->SetDisplayId(displayId); - EXPECT_EQ(ssm_->CheckSubSessionStartedByExtensionAndSetDisplayId(token, property, nullptr), WSError::WS_OK); - EXPECT_EQ(ssm_->CheckSubSessionStartedByExtensionAndSetDisplayId(token, property, sessionStage), WSError::WS_OK); + ssm_->SetExtensionSubSessionDisplayId(property, nullptr); + EXPECT_NE(property->GetDisplayId(), displayId); + + property->SetIsUIExtFirstSubWindow(false); + ssm_->SetExtensionSubSessionDisplayId(property, sessionStage); + EXPECT_NE(property->GetDisplayId(), displayId); + property->SetIsUIExtFirstSubWindow(true); - EXPECT_EQ(ssm_->CheckSubSessionStartedByExtensionAndSetDisplayId(token, property, sessionStage), WSError::WS_OK); + ssm_->SetExtensionSubSessionDisplayId(property, sessionStage); EXPECT_EQ(property->GetDisplayId(), displayId); } /** - * @tc.name: CheckSubSessionStartedByExtensionAndSetDisplayId02 - * @tc.desc: test compare host bundleName and parent bundleName + * @tc.name: CheckSubSessionStartedByExtension + * @tc.desc: test CheckSubSessionStartedByExtension * @tc.type: FUNC */ -HWTEST_F(SceneSessionManagerExtensionTest, CheckSubSessionStartedByExtensionAndSetDisplayId02, TestSize.Level1) +HWTEST_F(SceneSessionManagerExtensionTest, CheckSubSessionStartedByExtension, TestSize.Level1) { ASSERT_NE(ssm_, nullptr); SessionInfo info; info.bundleName_ = BUNDLE_NAME; sptr callback = ssm_->CreateSpecificSessionCallback(); sptr parentSession = sptr::MakeSptr(info, callback); + parentSession->property_->SetPersistentId(1); + parentSession->persistentId_ = 1; ssm_->sceneSessionMap_.insert({ parentSession->GetPersistentId(), parentSession }); sptr token; sptr property = sptr::MakeSptr(); - sptr sessionStage = sptr::MakeSptr(); + property->SetParentPersistentId(100000); + EXPECT_EQ(ssm_->CheckSubSessionStartedByExtension(token, property), WSError::WS_ERROR_NULLPTR); property->SetParentPersistentId(parentSession->GetPersistentId()); - property->SetIsUIExtensionAbilityProcess(true); - EXPECT_EQ(ssm_->CheckSubSessionStartedByExtensionAndSetDisplayId(token, property, sessionStage), WSError::WS_OK); - MockUIExtSessionPermission::SetIsStartedByUIExtensionFlag(true); - AAFwk::UIExtensionHostInfo hostInfo; - hostInfo.elementName_.SetBundleName(BUNDLE_NAME); - AAFwk::MockAbilityManagerClient::SetUIExtensionRootHostInfo(hostInfo); + LOCK_GUARD_EXPR(SCENE_GUARD, parentSession->SetCallingPid(IPCSkeleton::GetCallingPid())); + EXPECT_EQ(ssm_->CheckSubSessionStartedByExtension(token, property), WSError::WS_OK); + LOCK_GUARD_EXPR(SCENE_GUARD, parentSession->SetCallingPid(IPCSkeleton::GetCallingPid() + 1)); + AAFwk::UIExtensionSessionInfo extensionSessionInfo; extensionSessionInfo.hostElementName.SetBundleName(BUNDLE_NAME); + extensionSessionInfo.persistentId = property->GetParentPersistentId(); + extensionSessionInfo.hostWindowId = property->GetParentPersistentId(); + AAFwk::MockAbilityManagerClient::SetUIExtensionSessionInfo(extensionSessionInfo); + EXPECT_EQ(ssm_->CheckSubSessionStartedByExtension(token, property), WSError::WS_OK); + MockUIExtSessionPermission::SetIsSystemCallingFlag(false); + extensionSessionInfo.hostWindowId = property->GetParentPersistentId() + 1; AAFwk::MockAbilityManagerClient::SetUIExtensionSessionInfo(extensionSessionInfo); - EXPECT_EQ(ssm_->CheckSubSessionStartedByExtensionAndSetDisplayId(token, property, sessionStage), WSError::WS_OK); + EXPECT_EQ(ssm_->CheckSubSessionStartedByExtension(token, property), WSError::WS_ERROR_INVALID_WINDOW); + extensionSessionInfo.hostWindowId = INVALID_SESSION_ID; + AAFwk::MockAbilityManagerClient::SetUIExtensionSessionInfo(extensionSessionInfo); + EXPECT_EQ(ssm_->CheckSubSessionStartedByExtension(token, property), WSError::WS_ERROR_INVALID_WINDOW); + extensionSessionInfo.persistentId = INVALID_SESSION_ID; + AAFwk::MockAbilityManagerClient::SetUIExtensionSessionInfo(extensionSessionInfo); + EXPECT_EQ(ssm_->CheckSubSessionStartedByExtension(token, property), WSError::WS_ERROR_INVALID_WINDOW); - hostInfo.elementName_.SetBundleName(BUNDLE_NAME_TEST); - AAFwk::MockAbilityManagerClient::SetUIExtensionRootHostInfo(hostInfo); - EXPECT_EQ(ssm_->CheckSubSessionStartedByExtensionAndSetDisplayId(token, property, sessionStage), WSError::WS_OK); + MockUIExtSessionPermission::SetIsSystemCallingFlag(true); + EXPECT_EQ(ssm_->CheckSubSessionStartedByExtension(token, property), WSError::WS_OK); - extensionSessionInfo.hostElementName.SetBundleName(BUNDLE_NAME_TEST); - AAFwk::MockAbilityManagerClient::SetUIExtensionSessionInfo(extensionSessionInfo); - EXPECT_EQ(ssm_->CheckSubSessionStartedByExtensionAndSetDisplayId(token, property, sessionStage), - WSError::WS_ERROR_INVALID_WINDOW); MockUIExtSessionPermission::ClearAllFlag(); AAFwk::MockAbilityManagerClient::ClearAll(); } diff --git a/window_scene/test/unittest/window_pattern/window_pattern_snapshot_test.cpp b/window_scene/test/unittest/window_pattern/window_pattern_snapshot_test.cpp index 538698fecdba780f94303d97b1ff76d77066430f..918d7f75315bf89a7777a32acd4dea026ade40f2 100644 --- a/window_scene/test/unittest/window_pattern/window_pattern_snapshot_test.cpp +++ b/window_scene/test/unittest/window_pattern/window_pattern_snapshot_test.cpp @@ -715,29 +715,29 @@ HWTEST_F(WindowPatternSnapshotTest, GetWindowStatus, TestSize.Level1) } /** - * @tc.name: GetSessionStatus - * @tc.desc: GetSessionStatus Test + * @tc.name: GetSessionSnapshotStatus + * @tc.desc: GetSessionSnapshotStatus Test * @tc.type: FUNC */ -HWTEST_F(WindowPatternSnapshotTest, GetSessionStatus, TestSize.Level1) +HWTEST_F(WindowPatternSnapshotTest, GetSessionSnapshotStatus, TestSize.Level1) { SessionInfo info; sptr sceneSession = sptr::MakeSptr(info, nullptr); sceneSession->capacity_ = defaultCapacity; - auto ret = sceneSession->GetSessionStatus(); + auto ret = sceneSession->GetSessionSnapshotStatus(); EXPECT_EQ(ret, defaultStatus); sceneSession->capacity_ = maxCapacity; sceneSession->state_ = SessionState::STATE_DISCONNECT; sceneSession->currentRotation_ = 0; - sceneSession->GetSessionStatus(); + sceneSession->GetSessionSnapshotStatus(); sceneSession->state_ = SessionState::STATE_ACTIVE; - ret = sceneSession->GetSessionStatus(); + ret = sceneSession->GetSessionSnapshotStatus(); EXPECT_EQ(ret.second, 0); - ScreenLockReason reason = ScreenLockReason::EXPAND_TO_FOLD_SINGLE_POCKET; - ret = sceneSession->GetSessionStatus(reason); + BackgroundReason reason = BackgroundReason::EXPAND_TO_FOLD_SINGLE_POCKET; + ret = sceneSession->GetSessionSnapshotStatus(reason); EXPECT_EQ(ret.first, 1); } @@ -752,21 +752,14 @@ HWTEST_F(WindowPatternSnapshotTest, GetWindowOrientation, TestSize.Level1) info.screenId_ = 0; sptr sceneSession = sptr::MakeSptr(info, nullptr); auto ret = sceneSession->GetWindowOrientation(); - EXPECT_EQ(ret, DisplayOrientation::PORTRAIT); + EXPECT_EQ(ret, 0); sceneSession->capacity_ = maxCapacity; - ScreenId screenId = 0; - sptr screenSession = nullptr; - screenSession = new ScreenSession(0, ScreenProperty(), 0); - ASSERT_NE(screenSession, nullptr); - ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(screenId, screenSession); - sceneSession->GetWindowOrientation(); - ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear(); session_->capacity_ = maxCapacity; ret = session_->GetWindowOrientation(); - EXPECT_EQ(ret, DisplayOrientation::PORTRAIT); + EXPECT_EQ(ret, WSSnapshotHelper::GetWindowRotation()); } /** diff --git a/window_scene/test/unittest/window_pattern/window_pattern_starting_window_test.cpp b/window_scene/test/unittest/window_pattern/window_pattern_starting_window_test.cpp index bca5c62d27299221a11984617f215a42151a5e79..0b7a77dcbaa8e4f7c9f355d0c3ea175686a1980b 100644 --- a/window_scene/test/unittest/window_pattern/window_pattern_starting_window_test.cpp +++ b/window_scene/test/unittest/window_pattern/window_pattern_starting_window_test.cpp @@ -53,6 +53,7 @@ public: private: void InitTestStartingWindowRdb(); + void CreateSession(SessionInfo sessionInfo, int32_t persistentId); }; sptr WindowPatternStartingWindowTest::ssm_ = nullptr; @@ -86,6 +87,14 @@ void WindowPatternStartingWindowTest::InitTestStartingWindowRdb() ssm_->startingWindowRdbMgr_ = std::make_unique(config); } +void WindowPatternStartingWindowTest::CreateSession(SessionInfo sessionInfo, int32_t persistentId) +{ + sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); + ASSERT_NE(sceneSession, nullptr); + ssm_->sceneSessionMap_.insert({ persistentId, sceneSession }); + ASSERT_NE(ssm_->GetSceneSession(persistentId), nullptr); +} + namespace { /** * @tc.name: GetStartupPage01 @@ -178,16 +187,17 @@ HWTEST_F(WindowPatternStartingWindowTest, GetStartingWindowInfoFromCache, TestSi sessionInfo.abilityName_ = "abilityName"; sessionInfo.bundleName_ = "bundleName"; StartingWindowInfo startingWindowInfo; - auto res = ssm_->GetStartingWindowInfoFromCache(sessionInfo, startingWindowInfo); - ASSERT_EQ(res, false); - auto key = sessionInfo.moduleName_ + sessionInfo.abilityName_; + bool isDark = false; + auto res = ssm_->GetStartingWindowInfoFromCache(sessionInfo, startingWindowInfo, isDark); + EXPECT_EQ(res, false); + auto key = sessionInfo.moduleName_ + sessionInfo.abilityName_ + std::to_string(isDark); std::map startingWindowInfoMap{ { key, startingWindowInfo } }; ssm_->startingWindowMap_.insert({ sessionInfo.bundleName_, startingWindowInfoMap }); - res = ssm_->GetStartingWindowInfoFromCache(sessionInfo, startingWindowInfo); - ASSERT_EQ(res, true); + res = ssm_->GetStartingWindowInfoFromCache(sessionInfo, startingWindowInfo, isDark); + EXPECT_EQ(res, true); sessionInfo.moduleName_ = "invalidModuleName"; - res = ssm_->GetStartingWindowInfoFromCache(sessionInfo, startingWindowInfo); - ASSERT_EQ(res, false); + res = ssm_->GetStartingWindowInfoFromCache(sessionInfo, startingWindowInfo, isDark); + EXPECT_EQ(res, false); } /** @@ -208,14 +218,15 @@ HWTEST_F(WindowPatternStartingWindowTest, GetStartingWindowInfoFromRdb, TestSize sessionInfo.abilityName_ = itemKey.abilityName = "abilityName"; sessionInfo.bundleName_ = itemKey.bundleName = "bundleName"; itemKey.darkMode = false; - auto res = ssm_->GetStartingWindowInfoFromRdb(sessionInfo, outInfo); + bool isDark = false; + auto res = ssm_->GetStartingWindowInfoFromRdb(sessionInfo, outInfo, isDark); EXPECT_EQ(res, false); bool insertRes = ssm_->startingWindowRdbMgr_->InsertData(itemKey, outInfo); EXPECT_EQ(insertRes, true); - res = ssm_->GetStartingWindowInfoFromRdb(sessionInfo, outInfo); + res = ssm_->GetStartingWindowInfoFromRdb(sessionInfo, outInfo, isDark); EXPECT_EQ(res, true); ssm_->startingWindowRdbMgr_ = nullptr; - res = ssm_->GetStartingWindowInfoFromRdb(sessionInfo, outInfo); + res = ssm_->GetStartingWindowInfoFromRdb(sessionInfo, outInfo, isDark); EXPECT_EQ(res, false); } @@ -456,6 +467,10 @@ HWTEST_F(WindowPatternStartingWindowTest, CheckAndGetPreLoadResourceId, TestSize EXPECT_EQ(true, ssm_->CheckAndGetPreLoadResourceId(startingWindowInfo, resId)); startingWindowInfo.iconPathEarlyVersion_ = "resource:///12345678.jpg"; EXPECT_EQ(true, ssm_->CheckAndGetPreLoadResourceId(startingWindowInfo, resId)); + startingWindowInfo.iconPathEarlyVersion_ = "resource:///12345678.webp"; + EXPECT_EQ(true, ssm_->CheckAndGetPreLoadResourceId(startingWindowInfo, resId)); + startingWindowInfo.iconPathEarlyVersion_ = "resource:///12345678.astc"; + EXPECT_EQ(true, ssm_->CheckAndGetPreLoadResourceId(startingWindowInfo, resId)); } /** @@ -467,6 +482,9 @@ HWTEST_F(WindowPatternStartingWindowTest, PreLoadStartingWindow, TestSize.Level1 { ASSERT_NE(ssm_, nullptr); sptr sceneSession = nullptr; + ssm_->systemConfig_.supportPreloadStartingWindow_ = false; + ssm_->PreLoadStartingWindow(sceneSession); + ssm_->systemConfig_.supportPreloadStartingWindow_ = true; ssm_->PreLoadStartingWindow(sceneSession); SessionInfo info; info.bundleName_ = "bundleName_"; @@ -504,7 +522,14 @@ HWTEST_F(WindowPatternStartingWindowTest, NotifyPreLoadStartingWindowFinished, T HWTEST_F(WindowPatternStartingWindowTest, GetIsDarkFromConfiguration, TestSize.Level1) { ASSERT_NE(ssm_, nullptr); - bool isDark = ssm_->GetIsDarkFromConfiguration(); + std::string autoColorMode = AppExecFwk::ConfigurationInner::COLOR_MODE_AUTO; + bool isDark = ssm_->GetIsDarkFromConfiguration(autoColorMode); + EXPECT_EQ(false, isDark); + std::string darkColorMode = AppExecFwk::ConfigurationInner::COLOR_MODE_DARK; + isDark = ssm_->GetIsDarkFromConfiguration(darkColorMode); + EXPECT_EQ(true, isDark); + std::string lightColorMode = AppExecFwk::ConfigurationInner::COLOR_MODE_LIGHT; + isDark = ssm_->GetIsDarkFromConfiguration(lightColorMode); EXPECT_EQ(false, isDark); } @@ -522,6 +547,134 @@ HWTEST_F(WindowPatternStartingWindowTest, UpdateAllStartingWindowRdb, TestSize.L usleep(WAIT_SLEEP_TIME); EXPECT_TRUE(g_logMsg.find("GetBundleInfosV9 error") != std::string::npos); } + +/** + * @tc.name: UpdateProcessMap + * @tc.desc: UpdateProcessMap + * @tc.type: FUNC + */ +HWTEST_F(WindowPatternStartingWindowTest, UpdateProcessMap, TestSize.Level0) +{ + ASSERT_NE(ssm_, nullptr); + SessionInfo sessionInfo; + sessionInfo.bundleName_ = "bundleName_"; + sessionInfo.moduleName_ = "moduleName_"; + sessionInfo.abilityName_ = "abilityName_"; + sessionInfo.appInstanceKey_ = "instanceKey"; + sessionInfo.appIndex_ = 0; + int32_t persistentId0 = 1; + auto res = ssm_->FindProcessMap(sessionInfo, persistentId0); + EXPECT_EQ(res, WSError::WS_DO_NOTHING); + + ssm_->InsertProcessMap(sessionInfo, persistentId0); + int32_t persistentIdRes; + res = ssm_->FindProcessMap(sessionInfo, persistentIdRes); + EXPECT_EQ(res, WSError::WS_OK); + EXPECT_EQ(persistentIdRes, persistentId0); + int32_t persistentId1 = 2; + ssm_->InsertProcessMap(sessionInfo, persistentId1); + res = ssm_->DeleteProcessMap(sessionInfo, persistentId0); + EXPECT_EQ(res, WSError::WS_OK); + + res = ssm_->FindProcessMap(sessionInfo, persistentIdRes); + EXPECT_EQ(res, WSError::WS_OK); + EXPECT_EQ(persistentIdRes, persistentId1); + + res = ssm_->DeleteProcessMap(sessionInfo, persistentId1); + EXPECT_EQ(res, WSError::WS_OK); +} + +/** + * @tc.name: UpdateProcessMap + * @tc.desc: UpdateProcessMap + * @tc.type: FUNC + */ +HWTEST_F(WindowPatternStartingWindowTest, GetSessionColorMode, TestSize.Level0) +{ + ASSERT_NE(ssm_, nullptr); + SessionInfo sessionInfo; + sessionInfo.bundleName_ = "bundleName_"; + sessionInfo.moduleName_ = "moduleName_"; + sessionInfo.abilityName_ = "abilityName_"; + sessionInfo.appInstanceKey_ = "instanceKey"; + sessionInfo.appIndex_ = 0; + int32_t persistentId = 1000; + + StartingWindowInfo startingWindowInfo; + auto res = ssm_->GetSessionColorMode(sessionInfo, startingWindowInfo); + EXPECT_EQ(res, AppExecFwk::ConfigurationInner::COLOR_MODE_AUTO); + + ssm_->InsertProcessMap(sessionInfo, persistentId); + res = ssm_->GetSessionColorMode(sessionInfo, startingWindowInfo); + EXPECT_EQ(res, AppExecFwk::ConfigurationInner::COLOR_MODE_AUTO); + + sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); + ASSERT_NE(sceneSession, nullptr); + ssm_->sceneSessionMap_.insert({ persistentId, sceneSession }); + ASSERT_NE(ssm_->GetSceneSession(persistentId), nullptr); + + sceneSession->OnUpdateColorMode(AppExecFwk::ConfigurationInner::COLOR_MODE_DARK, true); + res = ssm_->GetSessionColorMode(sessionInfo, startingWindowInfo); + EXPECT_EQ(res, AppExecFwk::ConfigurationInner::COLOR_MODE_DARK); +} + +/** + * @tc.name: GetOriginalPersistentId + * @tc.desc: GetOriginalPersistentId + * @tc.type: FUNC + */ +HWTEST_F(WindowPatternStartingWindowTest, GetOriginalPersistentId, TestSize.Level0) +{ + ASSERT_NE(ssm_, nullptr); + ssm_->sceneSessionMap_.clear(); + SessionInfo sessionInfo; + int32_t persistentId = 1000; + int32_t callerIdA = 1001; + int32_t callerIdB = 1002; + sessionInfo.callerPersistentId_ = callerIdA; + + std::set sessionSet = { persistentId }; + auto res = ssm_->GetOriginalPersistentId(sessionSet, persistentId); + EXPECT_EQ(res, persistentId); + + CreateSession(sessionInfo, persistentId); + res = ssm_->GetOriginalPersistentId(sessionSet, persistentId); + EXPECT_EQ(res, persistentId); + + SessionInfo callerA; + callerA.callerPersistentId_ = callerIdB; + SessionInfo callerB; + callerB.callerPersistentId_ = callerIdA; + CreateSession(callerA, callerIdA); + CreateSession(callerB, callerIdB); + sessionSet.insert(callerIdA); + sessionSet.insert(callerIdB); + + res = ssm_->GetOriginalPersistentId(sessionSet, persistentId); + EXPECT_EQ(res, callerIdB); +} + +/** + * @tc.name: GetStartWindowColorFollowApp + * @tc.desc: GetStartWindowColorFollowApp + * @tc.type: FUNC + */ +HWTEST_F(WindowPatternStartingWindowTest, GetStartWindowColorFollowApp, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + ssm_->startingWindowFollowAppSet_.clear(); + SessionInfo sessionInfo; + sessionInfo.moduleName_ = "moduleName"; + sessionInfo.abilityName_ = "abilityName"; + sessionInfo.bundleName_ = "bundleName"; + auto res = ssm_->GetStartWindowColorFollowApp(sessionInfo); + EXPECT_EQ(res, false); + std::string key = sessionInfo.bundleName_ + '_' + sessionInfo.moduleName_ + '_' + sessionInfo.abilityName_; + startingWindowFollowAppSet_.insert(key); + auto res = ssm_->GetStartWindowColorFollowApp(sessionInfo); + ssm_->startingWindowFollowAppSet_.clear(); + EXPECT_EQ(res, true); +} } // namespace } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wm/include/window_extension_session_impl.h b/wm/include/window_extension_session_impl.h index 96b64732fb832a9fa6aa529b3c3298510cf9c809..e133beaf0bdd46428e29cc31954aafafa6b19c72 100644 --- a/wm/include/window_extension_session_impl.h +++ b/wm/include/window_extension_session_impl.h @@ -257,6 +257,7 @@ private: AAFwk::WantParams extensionConfig_ {}; bool hostGestureBackEnabled_ { true }; bool hostImmersiveModeEnabled_ { false }; + bool immersiveModeEnabled_ { false }; std::mutex hostWindowRectChangeListenerMutex_; std::mutex keyboardDidShowListenerMutex_; std::mutex keyboardDidHideListenerMutex_; diff --git a/wm/include/window_scene_session_impl.h b/wm/include/window_scene_session_impl.h index 3c7ba44037272ad211d0c4e25d237cfb7462c90f..ab6fe0d41e38b9704a5c976fc759995229d99098 100644 --- a/wm/include/window_scene_session_impl.h +++ b/wm/include/window_scene_session_impl.h @@ -26,7 +26,8 @@ using NotifyWindowRecoverStateChangeFunc = std::function& option); + explicit WindowSceneSessionImpl(const sptr& option, + const std::shared_ptr& rsUIContext = nullptr); ~WindowSceneSessionImpl(); WMError Create(const std::shared_ptr& context, const sptr& iSession, const std::string& identityToken = "", @@ -59,8 +60,7 @@ public: WMError GetGlobalScaledRect(Rect& globalScaledRect) override; WMError Resize(uint32_t width, uint32_t height, const RectAnimationConfig& rectAnimationConfig = {}) override; - WMError ResizeAsync(uint32_t width, uint32_t height, - const RectAnimationConfig& rectAnimationConfig = {}) override; + WMError ResizeAsync(uint32_t width, uint32_t height) override; WMError SetWindowAnchorInfo(const WindowAnchorInfo& windowAnchorInfo) override; WMError SetFollowParentWindowLayoutEnabled(bool isFollow) override; WSError NotifyLayoutFinishAfterWindowModeChange(WindowMode mode) override; @@ -216,7 +216,6 @@ public: WSError NotifyCompatibleModePropertyChange(const sptr property) override; void HookDecorButtonStyleInCompatibleMode(uint32_t contentColor); WSError PcAppInPadNormalClose() override; - void HandleWindowLimitsInCompatibleMode(WindowSizeLimits& windowSizeLimits); /* * Free Multi Window @@ -414,6 +413,7 @@ private: * Window Layout */ void CheckMoveConfiguration(MoveConfiguration& moveConfiguration); + void UpdateEnableDragWhenSwitchMultiWindow(bool enable); WMError GetAppHookWindowInfoFromServer(HookWindowInfo& hookWindowInfo) override; /* @@ -448,6 +448,8 @@ private: /* * Window Property */ + void RecoverSessionProperty(); + WMError UpdateColorMode(const std::shared_ptr& configuration = nullptr); void InitSystemSessionDragEnable(); bool IsSystemDensityChanged(const sptr& displayInfo); bool IsDefaultDensityEnabled(); diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index 47924c35df19a33833f829490ba28d804d29d206..ec8fad751cf7a653940edbe66329312276ca4925 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -78,7 +78,8 @@ using IKBWillHideListener = IKeyboardWillHideListener; class WindowSessionImpl : public Window, public virtual SessionStageStub { public: - explicit WindowSessionImpl(const sptr& option); + explicit WindowSessionImpl(const sptr& option, + const std::shared_ptr& rsUIContext = nullptr); ~WindowSessionImpl(); static sptr Find(const std::string& name); @@ -146,7 +147,7 @@ public: bool IsPadWindow() const override; bool IsPcOrFreeMultiWindowCapabilityEnabled() const override; bool IsPcOrPadFreeMultiWindowMode() const override; - bool IsPadAndNotFreeMutiWindowCompatibleMode() const override; + bool IsPadAndNotFreeMultiWindowCompatibleMode() const override; bool IsSceneBoardEnabled() const override; bool GetCompatibleModeInPc() const override; void HookCompatibleModeAvoidAreaNotify() override; @@ -472,7 +473,6 @@ public: WMError UnregisterWindowStatusDidChangeListener(const sptr& listener) override; WSError NotifyLayoutFinishAfterWindowModeChange(WindowMode mode) override { return WSError::WS_OK; } WMError UpdateWindowModeForUITest(int32_t updateMode) override { return WMError::WM_OK; } - void UpdateEnableDragWhenSwitchMultiWindow(bool enable); WSError NotifyAppHookWindowInfoUpdated() override { return WSError::WS_DO_NOTHING; } void SetNotifySizeChangeFlag(bool flag); @@ -802,6 +802,7 @@ protected: bool supportEnterWaterfallMode_ { false }; std::atomic_bool isFullScreenWaterfallMode_ { false }; std::atomic_bool isValidWaterfallMode_ { false }; + bool isFirstNotifyAcrossDisplays_ = true; bool isAcrossDisplays_ = false; WMError NotifyAcrossDisplaysChange(bool isAcrossDisplays); void NotifyWaterfallModeChange(bool isWaterfallMode); @@ -815,6 +816,8 @@ protected: /* * Window Property */ + std::string colorMode_; + bool hasDarkRes_; std::unordered_set containerColorList_; float lastSystemDensity_ = UNDEFINED_DENSITY; static std::atomic defaultDensityEnabledGlobalConfig_; @@ -847,6 +850,7 @@ protected: bool grayOutMaximizeButton_ = false; private: + void InitPropertyFromOption(const sptr& option); //Trans between colorGamut and colorSpace static ColorSpace GetColorSpaceFromSurfaceGamut(GraphicColorGamut colorGamut); static GraphicColorGamut GetSurfaceGamutFromColorSpace(ColorSpace colorSpace); diff --git a/wm/src/floating_ball_controller.cpp b/wm/src/floating_ball_controller.cpp index 992e0fdb235aac8e6f7bcf0a8c602c09d2ca8787..7c8b76f5081cfb45fc302c26b6af990c6f2cb110 100644 --- a/wm/src/floating_ball_controller.cpp +++ b/wm/src/floating_ball_controller.cpp @@ -44,7 +44,7 @@ FloatingBallController::FloatingBallController(const sptr& mainWindow, if ((abilityContext == nullptr) || (abilityContext->GetApplicationInfo() == nullptr)) { return; } - SingletonContainer::Get().SetCurrentPackageName(abilityContext->GetApplicationInfo()->name); + SingletonContainer::Get().SetCurrentPackageName(abilityContext->GetApplicationInfo()->name); } FloatingBallController::~FloatingBallController() @@ -73,14 +73,14 @@ WMError FloatingBallController::UpdateFloatingBall(sptr& option) TLOGI(WmsLogTag::WMS_SYSTEM, "UpdateFloatingBall"); if (curState_ != FbWindowState::STATE_STARTED) { TLOGE(WmsLogTag::WMS_SYSTEM, "cur state is not started, can not update"); - SingletonContainer::Get().ReportFbUpdateContent(templateType_, - "cur state is not started, can not update"); + SingletonContainer::Get().ReportFbEvent(FloatingBallEvent::EVENT_KEY_UPDATE, + templateType_, "cur state is not started, can not update"); return WMError::WM_ERROR_FB_INVALID_STATE; } if (option == nullptr || window_ == nullptr) { TLOGE(WmsLogTag::WMS_SYSTEM, "option or window is nullptr"); - SingletonContainer::Get().ReportFbUpdateContent(templateType_, - "option or window is nullptr"); + SingletonContainer::Get().ReportFbEvent(FloatingBallEvent::EVENT_KEY_UPDATE, + templateType_, "option or window is nullptr"); return WMError::WM_ERROR_FB_STATE_ABNORMALLY; } FloatingBallTemplateBaseInfo fbTemplateBaseInfo; @@ -89,7 +89,8 @@ WMError FloatingBallController::UpdateFloatingBall(sptr& option) std::ostringstream ss; errCode == WMError::WM_OK ? (ss << "") : (ss << "Update floating ball window session failed, errCode:" << static_cast(errCode)); - SingletonContainer::Get().ReportFbUpdateContent(templateType_, ss.str()); + SingletonContainer::Get().ReportFbEvent(FloatingBallEvent::EVENT_KEY_UPDATE, + templateType_, ss.str()); return errCode; } @@ -110,14 +111,15 @@ WMError FloatingBallController::StartFloatingBall(sptr& option) if (curState_ == FbWindowState::STATE_STARTING || curState_ == FbWindowState::STATE_STARTED) { TLOGW(WmsLogTag::WMS_SYSTEM, "fbWindow state is: %{public}u, id: %{public}u, mainWindow: %{public}u", curState_, (window_ == nullptr) ? INVALID_WINDOW_ID : window_->GetWindowId(), mainWindowId_); - SingletonContainer::Get().ReportFbStart(templateType_, - "fbWindow state is starting or started"); + SingletonContainer::Get().ReportFbEvent(FloatingBallEvent::EVENT_KEY_START, + templateType_, "fbWindow state is starting or started"); return WMError::WM_ERROR_FB_REPEAT_OPERATION; } if (curState_ == FbWindowState::STATE_STOPPING) { TLOGW(WmsLogTag::WMS_SYSTEM, "fbWindow state is: %{public}u, id: %{public}u, mainWindow: %{public}u", curState_, (window_ == nullptr) ? INVALID_WINDOW_ID : window_->GetWindowId(), mainWindowId_); - SingletonContainer::Get().ReportFbStart(templateType_, "fbWindow state is stopping"); + SingletonContainer::Get().ReportFbEvent(FloatingBallEvent::EVENT_KEY_START, + templateType_, "fbWindow state is stopping"); return WMError::WM_ERROR_FB_INVALID_STATE; } curState_ = FbWindowState::STATE_STARTING; @@ -148,7 +150,8 @@ WMError FloatingBallController::StartFloatingBallInner(const sptr& opt mainWindowLifeCycleListener_ = sptr::MakeSptr(); mainWindow_->RegisterLifeCycleListener(mainWindowLifeCycleListener_); curState_ = FbWindowState::STATE_STARTED; - SingletonContainer::Get().ReportFbStart(templateType_, ""); + SingletonContainer::Get().ReportFbEvent(FloatingBallEvent::EVENT_KEY_START, + templateType_, ""); OnFloatingBallStart(); return WMError::WM_OK; // LCOV_EXCL_STOP @@ -225,8 +228,8 @@ WMError FloatingBallController::StopFloatingBall() if ((!stopFromClient_ && curState_ == FbWindowState::STATE_STOPPING) || curState_ == FbWindowState::STATE_STOPPED) { TLOGE(WmsLogTag::WMS_SYSTEM, "Repeat stop request, curState: %{public}u", curState_); - SingletonContainer::Get().ReportFbRemove(templateType_, - "Repeat stop request, curState: stopping or stopped"); + SingletonContainer::Get().ReportFbEvent(FloatingBallEvent::EVENT_KEY_REMOVE, + templateType_, "Repeat stop request, curState: stopping or stopped"); return WMError::WM_ERROR_FB_REPEAT_OPERATION; } if (window_ == nullptr) { @@ -235,7 +238,6 @@ WMError FloatingBallController::StopFloatingBall() } curState_ = FbWindowState::STATE_STOPPING; } - SingletonContainer::Get().ReportFbRemove(templateType_, ""); return DestroyFloatingBallWindow(); } // LCOV_EXCL_STOP @@ -276,17 +278,18 @@ WMError FloatingBallController::RestoreMainWindow(const std::shared_ptr().ReportFbRestoreMainWindow(templateType_, - "state is not started when restore main window"); + SingletonContainer::Get().ReportFbEvent(FloatingBallEvent::EVENT_KEY_RESTORE, + templateType_, "state is not started when restore main window"); return WMError::WM_ERROR_FB_INVALID_STATE; } if (window_ == nullptr) { TLOGE(WmsLogTag::WMS_SYSTEM, "window is null when restoreMainWindow"); - SingletonContainer::Get().ReportFbRestoreMainWindow(templateType_, - "window is null when restoreMainWindow"); + SingletonContainer::Get().ReportFbEvent(FloatingBallEvent::EVENT_KEY_RESTORE, + templateType_, "window is null when restoreMainWindow"); return WMError::WM_ERROR_FB_STATE_ABNORMALLY; } - SingletonContainer::Get().ReportFbRestoreMainWindow(templateType_, ""); + SingletonContainer::Get().ReportFbEvent(FloatingBallEvent::EVENT_KEY_RESTORE, + templateType_, ""); return window_->RestoreFbMainWindow(want); } diff --git a/wm/src/window.cpp b/wm/src/window.cpp index 2a4627dbd4eb61916ad7ce1c1e3f21ed16d36530..ed11614e21a28697618d580138dd9bb6d331fdcf 100644 --- a/wm/src/window.cpp +++ b/wm/src/window.cpp @@ -36,13 +36,14 @@ constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "Window" static sptr CreateWindowWithSession(sptr& option, const std::shared_ptr& context, WMError& errCode, - sptr iSession = nullptr, const std::string& identityToken = "", bool isModuleAbilityHookEnd = false) + sptr iSession = nullptr, const std::string& identityToken = "", bool isModuleAbilityHookEnd = false, + const std::shared_ptr& rsUiContext = nullptr) { WLOGFD("in"); sptr windowSessionImpl = nullptr; auto sessionType = option->GetWindowSessionType(); if (sessionType == WindowSessionType::SCENE_SESSION) { - windowSessionImpl = sptr::MakeSptr(option); + windowSessionImpl = sptr::MakeSptr(option, rsUiContext); } else if (sessionType == WindowSessionType::EXTENSION_SESSION) { option->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION); windowSessionImpl = sptr::MakeSptr(option); @@ -63,7 +64,8 @@ static sptr CreateWindowWithSession(sptr& option, } sptr Window::Create(const std::string& windowName, sptr& option, - const std::shared_ptr& context, WMError& errCode) + const std::shared_ptr& context, WMError& errCode, + const std::shared_ptr& rsUiContext) { if (windowName.empty()) { WLOGFE("window name is empty"); @@ -87,7 +89,7 @@ sptr Window::Create(const std::string& windowName, sptr& o } option->SetWindowName(windowName); if (SceneBoardJudgement::IsSceneBoardEnabled()) { - return CreateWindowWithSession(option, context, errCode); + return CreateWindowWithSession(option, context, errCode, nullptr, "", false, rsUiContext); } if (option->GetOnlySupportSceneBoard()) { errCode = WMError::WM_ERROR_DEVICE_NOT_SUPPORT; diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 7af0715572464da15914331f4db715545e4912c6..43ff070c62226117fd6fc4fb3136a6596ec99adf 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -1318,30 +1318,30 @@ WMError WindowAdapter::CreateUIEffectController(const sptrCreateUIEffectController(controllerClient, controller, controllerId); } -WMError WindowAdapter::AddSessionBlackList( - const std::unordered_set& bundleNames, const std::unordered_set& privacyWindowTags) +WMError WindowAdapter::GetPiPSettingSwitchStatus(bool& switchStatus) { INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); auto wmsProxy = GetWindowManagerServiceProxy(); CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR); - return wmsProxy->AddSessionBlackList(bundleNames, privacyWindowTags); + return wmsProxy->GetPiPSettingSwitchStatus(switchStatus); } -WMError WindowAdapter::RemoveSessionBlackList( +WMError WindowAdapter::AddSessionBlackList( const std::unordered_set& bundleNames, const std::unordered_set& privacyWindowTags) { INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); auto wmsProxy = GetWindowManagerServiceProxy(); CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR); - return wmsProxy->RemoveSessionBlackList(bundleNames, privacyWindowTags); + return wmsProxy->AddSessionBlackList(bundleNames, privacyWindowTags); } -WMError WindowAdapter::GetPiPSettingSwitchStatus(bool& switchStatus) +WMError WindowAdapter::RemoveSessionBlackList( + const std::unordered_set& bundleNames, const std::unordered_set& privacyWindowTags) { INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); auto wmsProxy = GetWindowManagerServiceProxy(); CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR); - return wmsProxy->GetPiPSettingSwitchStatus(switchStatus); + return wmsProxy->RemoveSessionBlackList(bundleNames, privacyWindowTags); } } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_extension_session_impl.cpp b/wm/src/window_extension_session_impl.cpp index c07e1eb8d13463386e8b4832c6893f2f66645a68..5b13850c6599018bd329ef4e0609c310ab6ed383 100644 --- a/wm/src/window_extension_session_impl.cpp +++ b/wm/src/window_extension_session_impl.cpp @@ -315,6 +315,7 @@ WMError WindowExtensionSessionImpl::Destroy(bool needNotifyServer, bool needClea SetUIExtensionDestroyComplete(); RemoveExtensionWindowStageFromSCB(property_->IsConstrainedModal()); dataHandler_->SetRemoteProxyObject(nullptr); + surfaceNode_ = nullptr; TLOGI(WmsLogTag::WMS_LIFE, "Destroyed success, id: %{public}d.", GetPersistentId()); return WMError::WM_OK; } @@ -839,6 +840,7 @@ WMError WindowExtensionSessionImpl::SetUIContentInner(const std::string& content } SetUIContentComplete(); NotifyModalUIExtensionMayBeCovered(true); + SetLayoutFullScreen(immersiveModeEnabled_); UpdateAccessibilityTreeInfo(); std::shared_ptr uiContent = GetUIContentSharedPtr(); @@ -1556,6 +1558,7 @@ WMError WindowExtensionSessionImpl::SetLayoutFullScreen(bool status) property_->SetIsLayoutFullScreen(status); isIgnoreSafeArea_ = status; isIgnoreSafeAreaNeedNotify_ = true; + immersiveModeEnabled_ = status; if (auto uiContent = GetUIContentSharedPtr()) { uiContent->SetIgnoreViewSafeArea(status); } diff --git a/wm/src/window_manager_lite.cpp b/wm/src/window_manager_lite.cpp index ea075a7415c843b9055d2d3c7c966adff665bd38..75f62e1ae7e70d83c5940c784dfbf6007408e624 100644 --- a/wm/src/window_manager_lite.cpp +++ b/wm/src/window_manager_lite.cpp @@ -286,7 +286,7 @@ void WindowManagerLite::Impl::NotifyAccessibilityWindowInfo(const std::vector> cameraWindowChangeListeners; { @@ -708,7 +708,7 @@ WMError WindowManagerLite::UnregisterWindowModeChangedListener(const sptr& listener) { if (listener == nullptr) { - TLOGE(WmsLogTag::WMS_SYSTEM, "listener could not be null"); + TLOGE(WmsLogTag::WMS_PIP, "listener could not be null"); return WMError::WM_ERROR_NULLPTR; } @@ -736,7 +736,7 @@ WMError WindowManagerLite::RegisterCameraWindowChangedListener(const sptr& listener) { if (listener == nullptr) { - TLOGE(WmsLogTag::WMS_SYSTEM, "listener could not be null"); + TLOGE(WmsLogTag::WMS_PIP, "listener could not be null"); return WMError::WM_ERROR_NULLPTR; } diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index ae00ed918b70304a5267cc7a43d049bf14578501..cf31a7e89a6432a799dc49c4d4d91fb5e5d0cc6e 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -145,7 +145,8 @@ std::mutex WindowSceneSessionImpl::keyboardPanelInfoChangeListenerMutex_; using WindowSessionImplMap = std::map>>; std::mutex WindowSceneSessionImpl::windowAttachStateChangeListenerMutex_; -WindowSceneSessionImpl::WindowSceneSessionImpl(const sptr& option) : WindowSessionImpl(option) +WindowSceneSessionImpl::WindowSceneSessionImpl(const sptr& option, + const std::shared_ptr& rsUIContext) : WindowSessionImpl(option, rsUIContext) { WLOGFI("[WMSCom] Constructor %{public}s", GetWindowName().c_str()); } @@ -402,6 +403,14 @@ WMError WindowSceneSessionImpl::CreateSystemWindow(WindowType type) return WMError::WM_OK; } +void WindowSceneSessionImpl::RecoverSessionProperty() +{ + // recover colorMode + if (auto hostSession = GetHostSession()) { + hostSession->OnUpdateColorMode(colorMode_, hasDarkRes_); + } +} + WMError WindowSceneSessionImpl::RecoverAndConnectSpecificSession() { TLOGI(WmsLogTag::WMS_RECOVER, "windowName=%{public}s, windowMode=%{public}u, windowType=%{public}u, " @@ -613,8 +622,8 @@ WMError WindowSceneSessionImpl::Create(const std::shared_ptrGetWindowName().c_str(), property_->GetPersistentId(), state_, GetWindowMode(), isEnableDefaultDensityWhenCreate_, property_->GetDisplayId()); @@ -673,7 +683,7 @@ WMError WindowSceneSessionImpl::SetPcAppInpadSpecificSystemBarInvisible() { TLOGI(WmsLogTag::WMS_COMPAT, "isPcAppInpadSpecificSystemBarInvisible: %{public}d", property_->GetPcAppInpadSpecificSystemBarInvisible()); - if (WindowHelper::IsMainWindow(GetType()) && IsPadAndNotFreeMutiWindowCompatibleMode() && + if (WindowHelper::IsMainWindow(GetType()) && IsPadAndNotFreeMultiWindowCompatibleMode() && property_->GetPcAppInpadSpecificSystemBarInvisible()) { SystemBarProperty statusProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR); UpdateSpecificSystemBarEnabled(false, false, statusProperty); @@ -692,7 +702,7 @@ WMError WindowSceneSessionImpl::SetPcAppInpadOrientationLandscape() { TLOGI(WmsLogTag::WMS_COMPAT, "isPcAppInpadOrientationLandscape: %{public}d", property_->GetPcAppInpadOrientationLandscape()); - if (WindowHelper::IsMainWindow(GetType()) && IsPadAndNotFreeMutiWindowCompatibleMode() && + if (WindowHelper::IsMainWindow(GetType()) && IsPadAndNotFreeMultiWindowCompatibleMode() && property_->GetPcAppInpadOrientationLandscape()) { SetRequestedOrientation(Orientation::HORIZONTAL, false); return WMError::WM_OK; @@ -796,7 +806,7 @@ WMError WindowSceneSessionImpl::SetParentWindow(int32_t newParentWindowId) } auto oldParentWindow = GetWindowWithId(oldParentWindowId); if (oldParentWindow == nullptr) { - TLOGE(WmsLogTag::WMS_SUB, "winId: %{public}d find not old parent window By Id: %{public}d", + TLOGE(WmsLogTag::WMS_SUB, "winId: %{public}d can not find old parent window By Id: %{public}d", subWindowId, oldParentWindowId); return WMError::WM_ERROR_INVALID_PARENT; } @@ -807,7 +817,7 @@ WMError WindowSceneSessionImpl::SetParentWindow(int32_t newParentWindowId) } auto newParentWindow = GetWindowWithId(newParentWindowId); if (newParentWindow == nullptr) { - TLOGE(WmsLogTag::WMS_SUB, "winId: %{public}d find not new parent window By Id: %{public}d", + TLOGE(WmsLogTag::WMS_SUB, "winId: %{public}d can not find new parent window By Id: %{public}d", subWindowId, newParentWindowId); return WMError::WM_ERROR_INVALID_PARENT; } @@ -850,18 +860,6 @@ WMError WindowSceneSessionImpl::GetParentWindow(sptr& parentWindow) return WMError::WM_OK; } -void WindowSceneSessionImpl::InitSystemSessionDragEnable() -{ - if (WindowHelper::IsDialogWindow(GetType())) { - TLOGI(WmsLogTag::WMS_LAYOUT, "dialogWindow default draggable, should not init false, id: %{public}d", - GetPersistentId()); - return; - } - TLOGI(WmsLogTag::WMS_LAYOUT, "windId: %{public}d init dragEnable false", - GetPersistentId()); - property_->SetDragEnabled(false); -} - void WindowSceneSessionImpl::UpdateDefaultStatusBarColor() { SystemBarProperty statusBarProp = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR); @@ -915,6 +913,18 @@ void WindowSceneSessionImpl::UpdateDefaultStatusBarColor() SetSpecificBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, statusBarProp); } +void WindowSceneSessionImpl::InitSystemSessionDragEnable() +{ + if (WindowHelper::IsDialogWindow(GetType())) { + TLOGI(WmsLogTag::WMS_LAYOUT, "dialogWindow default draggable, should not init false, id: %{public}d", + GetPersistentId()); + return; + } + TLOGI(WmsLogTag::WMS_LAYOUT, "windId: %{public}d init dragEnable false", + GetPersistentId()); + property_->SetDragEnabled(false); +} + void WindowSceneSessionImpl::RegisterSessionRecoverListener(bool isSpecificSession) { TLOGD(WmsLogTag::WMS_RECOVER, "Id=%{public}d, isSpecificSession=%{public}s", @@ -978,6 +988,7 @@ void WindowSceneSessionImpl::OnWindowRecoverStateChange(bool isSpecificSession, case WindowRecoverState::WINDOW_FINISH_RECONNECT: UpdateFinishRecoverProperty(isSpecificSession); RecoverSessionListener(); + RecoverSessionProperty(); break; default: break; @@ -1142,10 +1153,12 @@ void WindowSceneSessionImpl::ConsumePointerEventInner(const std::shared_ptrMarkProcessed(); } if (isPointDown || isPointUp) { - TLOGNI(WmsLogTag::WMS_INPUT_KEY_FLOW, "Consume:id:%{public}d,wid:%{public}u,pointId:%{public}d" - ",srcType:%{public}d,rect:[%{public}d,%{public}d,%{public}u,%{public}u],notify:%{public}d", + TLOGI(WmsLogTag::WMS_INPUT_KEY_FLOW, "InputId:%{public}d,wid:%{public}u,pointId:%{public}d" + ",srcType:%{public}d,rect:[%{public}d,%{public}d,%{public}u,%{public}u]" + ",notify:%{public}d", pointerEvent->GetId(), GetWindowId(), pointerEvent->GetPointerId(), - sourceType, rect.posX_, rect.posY_, rect.width_, rect.height_, needNotifyEvent); + sourceType, rect.posX_, rect.posY_, rect.width_, rect.height_, + needNotifyEvent); } } @@ -1204,7 +1217,7 @@ bool WindowSceneSessionImpl::PreNotifyKeyEvent(const std::shared_ptrGetKeyCode() == MMI::KeyEvent::KEYCODE_TAB || keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ENTER) && isConsumed && keyEvent->GetKeyAction() == MMI::KeyEvent::KEY_ACTION_DOWN) { - TLOGD(WmsLogTag::WMS_EVENT, "wid:%{public}d, keyCode:%{public}d, isConsumed:%{public}d", + TLOGD(WmsLogTag::WMS_EVENT, "wid:%{public}u, keyCode:%{public}d, isConsumed:%{public}d", GetWindowId(), keyEvent->GetKeyCode(), isConsumed); NotifyWatchGestureConsumeResult(keyEvent->GetKeyCode(), isConsumed); } @@ -1225,31 +1238,6 @@ static void GetWindowSizeLimits(std::shared_ptr ability windowSizeLimits.minWindowHeight : abilityInfo->minWindowHeight; } -void WindowSceneSessionImpl::HandleWindowLimitsInCompatibleMode(WindowSizeLimits& windowSizeLimits) -{ - if (!property_->IsWindowLimitDisabled()) { - return; - } - windowSizeLimits.maxWindowWidth = windowSystemConfig_.maxFloatingWindowSize_; - windowSizeLimits.maxWindowHeight = windowSystemConfig_.maxFloatingWindowSize_; - if (WindowHelper::IsMainWindow(GetType())) { - windowSizeLimits.minWindowWidth = windowSystemConfig_.miniWidthOfMainWindow_; - windowSizeLimits.minWindowHeight = windowSystemConfig_.miniHeightOfMainWindow_; - } else if (WindowHelper::IsSubWindow(GetType())) { - windowSizeLimits.minWindowWidth = windowSystemConfig_.miniWidthOfSubWindow_; - windowSizeLimits.minWindowHeight = windowSystemConfig_.miniHeightOfSubWindow_; - } else if (WindowHelper::IsDialogWindow(GetType())) { - windowSizeLimits.minWindowWidth = windowSystemConfig_.miniWidthOfDialogWindow_; - windowSizeLimits.minWindowHeight = windowSystemConfig_.miniHeightOfDialogWindow_; - } else { - windowSizeLimits.minWindowWidth = MIN_FLOATING_WIDTH; - windowSizeLimits.minWindowHeight = MIN_FLOATING_HEIGHT; - } - TLOGI(WmsLogTag::WMS_COMPAT, "maxWidth: %{public}u, minWidth: %{public}u, maxHeight: %{public}u, " - "minHeight: %{public}u", windowSizeLimits.maxWindowWidth, windowSizeLimits.minWindowWidth, - windowSizeLimits.maxWindowHeight, windowSizeLimits.minWindowHeight); -} - std::vector WindowSceneSessionImpl::ExtractSupportWindowModeFromMetaData( const std::shared_ptr& abilityInfo) { @@ -1297,9 +1285,6 @@ void WindowSceneSessionImpl::GetConfigurationFromAbilityInfo() if (abilityInfo != nullptr) { WindowSizeLimits windowSizeLimits = property_->GetWindowSizeLimits(); GetWindowSizeLimits(abilityInfo, windowSizeLimits); - if (property_->IsWindowLimitDisabled()) { - HandleWindowLimitsInCompatibleMode(windowSizeLimits); - } property_->SetConfigWindowLimitsVP({ windowSizeLimits.maxWindowWidth, windowSizeLimits.maxWindowHeight, windowSizeLimits.minWindowWidth, windowSizeLimits.minWindowHeight, @@ -2049,10 +2034,10 @@ WMError WindowSceneSessionImpl::Destroy(bool needNotifyServer, bool needClearLis } DestroySubWindow(); - { + { std::unique_lock lock(windowSessionMutex_); windowSessionMap_.erase(property_->GetWindowName()); - } + } { std::lock_guard lock(hostSessionMutex_); hostSession_ = nullptr; @@ -2125,10 +2110,10 @@ WMError WindowSceneSessionImpl::MoveTo(int32_t x, int32_t y, bool isMoveToGlobal return static_cast(ret); } -WMError WindowSceneSessionImpl::MoveWindowToGlobal(int32_t x, int32_t y, MoveConfiguration moveConfiguration) +WMError WindowSceneSessionImpl::MoveToAsync(int32_t x, int32_t y, MoveConfiguration moveConfiguration) { - TLOGI(WmsLogTag::WMS_LAYOUT, "Id:%{public}d MoveTo %{public}d %{public}d", property_->GetPersistentId(), x, y); if (IsWindowSessionInvalid()) { + TLOGE(WmsLogTag::WMS_LAYOUT, "Session is invalid"); return WMError::WM_ERROR_INVALID_WINDOW; } @@ -2137,29 +2122,7 @@ WMError WindowSceneSessionImpl::MoveWindowToGlobal(int32_t x, int32_t y, MoveCon GetWindowId(), GetWindowMode()); return WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS; } - - if (property_->GetWindowType() == WindowType::WINDOW_TYPE_PIP) { - TLOGW(WmsLogTag::WMS_LAYOUT, "Unsupported operation for pip window"); - return WMError::WM_ERROR_INVALID_OPERATION; - } - const auto& windowRect = GetRect(); - const auto& requestRect = GetRequestRect(); - Rect newRect = { x, y, requestRect.width_, requestRect.height_ }; // must keep x/y - TLOGI(WmsLogTag::WMS_LAYOUT, "Id:%{public}d, state: %{public}d, type: %{public}d, mode: %{public}d, requestRect: " - "%{public}s, windowRect: %{public}s, newRect: %{public}s", - property_->GetPersistentId(), state_, GetType(), GetWindowMode(), requestRect.ToString().c_str(), - windowRect.ToString().c_str(), newRect.ToString().c_str()); - - property_->SetRequestRect(newRect); - - CheckMoveConfiguration(moveConfiguration); - WSRect wsRect = { newRect.posX_, newRect.posY_, newRect.width_, newRect.height_ }; - auto hostSession = GetHostSession(); - RectAnimationConfig rectAnimationConfig = moveConfiguration.rectAnimationConfig; - SizeChangeReason reason = rectAnimationConfig.duration > 0 ? SizeChangeReason::MOVE_WITH_ANIMATION : - SizeChangeReason::MOVE; - CHECK_HOST_SESSION_RETURN_ERROR_IF_NULL(hostSession, WMError::WM_ERROR_INVALID_WINDOW); - auto ret = hostSession->UpdateSessionRect(wsRect, reason, false, true, moveConfiguration, rectAnimationConfig); + auto ret = MoveTo(x, y, false, moveConfiguration); if (state_ == WindowState::STATE_SHOWN) { layoutCallback_->ResetMoveToLock(); auto startTime = std::chrono::duration_cast( @@ -2176,10 +2139,10 @@ WMError WindowSceneSessionImpl::MoveWindowToGlobal(int32_t x, int32_t y, MoveCon return static_cast(ret); } -WMError WindowSceneSessionImpl::MoveToAsync(int32_t x, int32_t y, MoveConfiguration moveConfiguration) +WMError WindowSceneSessionImpl::MoveWindowToGlobal(int32_t x, int32_t y, MoveConfiguration moveConfiguration) { + TLOGI(WmsLogTag::WMS_LAYOUT, "Id:%{public}d MoveTo %{public}d %{public}d", property_->GetPersistentId(), x, y); if (IsWindowSessionInvalid()) { - TLOGE(WmsLogTag::WMS_LAYOUT, "Session is invalid"); return WMError::WM_ERROR_INVALID_WINDOW; } @@ -2188,7 +2151,29 @@ WMError WindowSceneSessionImpl::MoveToAsync(int32_t x, int32_t y, MoveConfigurat GetWindowId(), GetWindowMode()); return WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS; } - auto ret = MoveTo(x, y, false, moveConfiguration); + + if (property_->GetWindowType() == WindowType::WINDOW_TYPE_PIP) { + TLOGW(WmsLogTag::WMS_LAYOUT, "Unsupported operation for pip window"); + return WMError::WM_ERROR_INVALID_OPERATION; + } + const auto& windowRect = GetRect(); + const auto& requestRect = GetRequestRect(); + Rect newRect = { x, y, requestRect.width_, requestRect.height_ }; // must keep x/y + TLOGI(WmsLogTag::WMS_LAYOUT, "Id:%{public}d, state: %{public}d, type: %{public}d, mode: %{public}d, requestRect: " + "%{public}s, windowRect: %{public}s, newRect: %{public}s", + property_->GetPersistentId(), state_, GetType(), GetWindowMode(), requestRect.ToString().c_str(), + windowRect.ToString().c_str(), newRect.ToString().c_str()); + + property_->SetRequestRect(newRect); + + CheckMoveConfiguration(moveConfiguration); + WSRect wsRect = { newRect.posX_, newRect.posY_, newRect.width_, newRect.height_ }; + auto hostSession = GetHostSession(); + RectAnimationConfig rectAnimationConfig = moveConfiguration.rectAnimationConfig; + SizeChangeReason reason = rectAnimationConfig.duration > 0 ? SizeChangeReason::MOVE_WITH_ANIMATION : + SizeChangeReason::MOVE; + CHECK_HOST_SESSION_RETURN_ERROR_IF_NULL(hostSession, WMError::WM_ERROR_INVALID_WINDOW); + auto ret = hostSession->UpdateSessionRect(wsRect, reason, false, true, moveConfiguration, rectAnimationConfig); if (state_ == WindowState::STATE_SHOWN) { layoutCallback_->ResetMoveToLock(); auto startTime = std::chrono::duration_cast( @@ -2450,8 +2435,7 @@ WMError WindowSceneSessionImpl::Resize(uint32_t width, uint32_t height, const Re return static_cast(ret); } -WMError WindowSceneSessionImpl::ResizeAsync(uint32_t width, uint32_t height, - const RectAnimationConfig& rectAnimationConfig) +WMError WindowSceneSessionImpl::ResizeAsync(uint32_t width, uint32_t height) { if (IsWindowSessionInvalid()) { TLOGE(WmsLogTag::WMS_LAYOUT, "Session is invalid"); @@ -2463,7 +2447,7 @@ WMError WindowSceneSessionImpl::ResizeAsync(uint32_t width, uint32_t height, GetWindowId(), GetWindowMode()); return WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS; } - auto ret = Resize(width, height, rectAnimationConfig); + auto ret = Resize(width, height); if (state_ == WindowState::STATE_SHOWN) { layoutCallback_->ResetResizeLock(); auto startTime = std::chrono::duration_cast( @@ -2573,14 +2557,13 @@ Ace::ViewportConfig WindowSceneSessionImpl::FillTargetOrientationConfig( return config; } auto deviceRotation = static_cast(displayInfo->GetDefaultDeviceRotationOffset()); - uint32_t transformHint = (targetRotation + deviceRotation) % FULL_CIRCLE_DEGREE; + uint32_t transformHint = (targetRotation * ONE_FOURTH_FULL_CIRCLE_DEGREE + deviceRotation) % FULL_CIRCLE_DEGREE; float density = GetVirtualPixelRatio(displayInfo); - int32_t orientation = static_cast(targetRotation) / ONE_FOURTH_FULL_CIRCLE_DEGREE; virtualPixelRatio_ = density; config.SetSize(targetRect.width_, targetRect.height_); config.SetPosition(targetRect.posX_, targetRect.posY_); config.SetDensity(density); - config.SetOrientation(orientation); + config.SetOrientation(targetRotation); config.SetTransformHint(transformHint); config.SetDisplayId(displayId); return config; @@ -2967,7 +2950,7 @@ WMError WindowSceneSessionImpl::SetTitleAndDockHoverShown( TLOGE(WmsLogTag::WMS_LAYOUT_PC, "window is not main window"); return WMError::WM_ERROR_INVALID_CALLING; } - if (IsPadAndNotFreeMutiWindowCompatibleMode()) { + if (IsPadAndNotFreeMultiWindowCompatibleMode()) { TLOGE(WmsLogTag::WMS_LAYOUT_PC, "This is PcAppInPad, not supported"); return WMError::WM_OK; } @@ -3273,7 +3256,7 @@ bool WindowSceneSessionImpl::IsDecorEnable() const bool isSubWindow = WindowHelper::IsSubWindow(windowType); bool isDialogWindow = WindowHelper::IsDialogWindow(windowType); bool isValidWindow = isMainWindow || - ((isSubWindow || isDialogWindow) && property_->IsDecorEnable()); + ((isSubWindow || isDialogWindow || IsSubWindowMaximizeSupported()) && property_->IsDecorEnable()); bool isWindowModeSupported = WindowHelper::IsWindowModeSupported( windowSystemConfig_.decorWindowModeSupportType_, GetWindowMode()); if (windowSystemConfig_.freeMultiWindowSupport_) { @@ -3284,6 +3267,9 @@ bool WindowSceneSessionImpl::IsDecorEnable() const if ((isSubWindow || isDialogWindow) && property_->GetIsPcAppInPad() && property_->IsDecorEnable()) { enable = true; } + if (IsSubWindowMaximizeSupported() && property_->IsDecorEnable()) { + enable = true; + } TLOGD(WmsLogTag::WMS_DECOR, "get decor enable %{public}d", enable); return enable; } @@ -3299,7 +3285,7 @@ WMError WindowSceneSessionImpl::SetWindowTitle(const std::string& title) return WMError::WM_OK; } if (!(windowSystemConfig_.IsPcWindow() || windowSystemConfig_.IsPadWindow() || - IsDeviceFeatureCapableForFreeMultiWindow())) { + windowSystemConfig_.IsPhoneWindow() || IsDeviceFeatureCapableForFreeMultiWindow())) { TLOGE(WmsLogTag::WMS_DECOR, "device not support"); return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } @@ -3555,7 +3541,7 @@ WMError WindowSceneSessionImpl::Recover(uint32_t reason) TLOGE(WmsLogTag::WMS_LAYOUT_PC, "session is invalid"); return WMError::WM_ERROR_INVALID_WINDOW; } - if (IsPadAndNotFreeMutiWindowCompatibleMode()) { + if (IsPadAndNotFreeMultiWindowCompatibleMode()) { TLOGE(WmsLogTag::WMS_LAYOUT_PC, "The device is not supported"); return WMError::WM_OK; } @@ -3606,7 +3592,7 @@ WMError WindowSceneSessionImpl::SetWindowRectAutoSave(bool enabled, bool isSaveB return WMError::WM_ERROR_INVALID_WINDOW; } - if (IsPadAndNotFreeMutiWindowCompatibleMode()) { + if (IsPadAndNotFreeMultiWindowCompatibleMode()) { TLOGE(WmsLogTag::WMS_MAIN, "This is PcAppInPad, not supported"); return WMError::WM_OK; } @@ -3679,7 +3665,7 @@ WMError WindowSceneSessionImpl::SetSupportedWindowModes( return WMError::WM_ERROR_INVALID_WINDOW; } - if (IsPadAndNotFreeMutiWindowCompatibleMode()) { + if (IsPadAndNotFreeMultiWindowCompatibleMode()) { TLOGE(WmsLogTag::WMS_LAYOUT_PC, "This is PcAppInpad, not supported"); return WMError::WM_OK; } @@ -4291,6 +4277,7 @@ void WindowSceneSessionImpl::UpdateConfiguration(const std::shared_ptrUpdateConfiguration(configuration); + UpdateColorMode(); } else { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "uiContent null, scene win=%{public}u, display=%{public}" PRIu64, GetWindowId(), GetDisplayId()); @@ -4307,6 +4294,44 @@ void WindowSceneSessionImpl::UpdateConfiguration(const std::shared_ptr& configuration) +{ + std::string colorMode; + if (configuration != nullptr) { + colorMode = configuration->GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE); + } + auto appContext = AbilityRuntime::Context::GetApplicationContext(); + if (appContext == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "winId: %{public}d app context is null", GetPersistentId()); + return WMError::WM_ERROR_NULLPTR; + } + if (colorMode.empty()) { + std::shared_ptr config = appContext->GetConfiguration(); + if (config == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "config is null, winId: %{public}d", GetPersistentId()); + return WMError::WM_ERROR_NULLPTR; + } + colorMode = config->GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE); + } + TLOGI(WmsLogTag::WMS_ATTRIBUTE, "winId: %{public}d, colorMode: %{public}s", GetPersistentId(), colorMode.c_str()); + if (colorMode_ == colorMode) { + return WMError::WM_DO_NOTHING; + } + colorMode_ = colorMode; + bool hasDarkRes = false; + appContext->AppHasDarkRes(hasDarkRes); + hasDarkRes_ = hasDarkRes; + + if (auto hostSession = GetHostSession()) { + hostSession->OnUpdateColorMode(colorMode, hasDarkRes); + } else { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "winId: %{public}d hostSession is null", GetPersistentId()); + } + TLOGI(WmsLogTag::WMS_ATTRIBUTE, "winId: %{public}d, colorMode: %{public}s, hasDarkRes: %{public}u", + GetPersistentId(), colorMode.c_str(), hasDarkRes); + return WMError::WM_OK; +} + void WindowSceneSessionImpl::UpdateConfigurationForSpecified( const std::shared_ptr& configuration, const std::shared_ptr& resourceManager) @@ -4371,6 +4396,7 @@ void WindowSceneSessionImpl::UpdateConfigurationSync(const std::shared_ptrUpdateConfigurationSyncForAll(configuration); + UpdateColorMode(); } else { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "uiContent null, scene win=%{public}u, display=%{public}" PRIu64, GetWindowId(), GetDisplayId()); @@ -4714,8 +4740,8 @@ WMError WindowSceneSessionImpl::SetWindowShadowRadius(float radius) return WMError::WM_ERROR_INVALID_WINDOW; } if (!windowSystemConfig_.IsPcWindow() && !windowSystemConfig_.IsPadWindow() && - !IsDeviceFeatureCapableForFreeMultiWindow()) { - TLOGE(WmsLogTag::WMS_ATTRIBUTE, "This is not PC or Pad, not supported."); + !windowSystemConfig_.IsPhoneWindow() && !IsDeviceFeatureCapableForFreeMultiWindow()) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "device not support."); return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } if (!WindowHelper::IsFloatOrSubWindow(GetType())) { @@ -5486,6 +5512,25 @@ void WindowSceneSessionImpl::UpdateSupportWindowModesWhenSwitchFreeMultiWindow() UpdateProperty(WSPropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO); } +void WindowSceneSessionImpl::UpdateEnableDragWhenSwitchMultiWindow(bool enable) +{ + if (hasSetEnableDrag_.load() || property_->IsDragResizeDisabled()) { + TLOGI(WmsLogTag::WMS_LAYOUT, "EnableDrag is already set, id: %{public}d", GetPersistentId()); + return; + } + auto isSystemWindow = WindowHelper::IsSystemWindow(property_->GetWindowType()); + bool isDialog = WindowHelper::IsDialogWindow(property_->GetWindowType()); + bool isSystemCalling = property_->GetSystemCalling(); + TLOGI(WmsLogTag::WMS_LAYOUT, "windId: %{public}d, isSystemWindow: %{public}d, isDialog: %{public}d, " + "isSystemCalling: %{public}d", GetPersistentId(), isSystemWindow, isDialog, isSystemCalling); + if (!enable || (isSystemWindow && !isDialog && !isSystemCalling)) { + property_->SetDragEnabled(false); + } else { + property_->SetDragEnabled(true); + } + UpdateProperty(WSPropertyChangeAction::ACTION_UPDATE_DRAGENABLED); +} + WSError WindowSceneSessionImpl::SwitchFreeMultiWindow(bool enable) { if (IsWindowSessionInvalid()) { @@ -5668,7 +5713,8 @@ WMError WindowSceneSessionImpl::GetWindowLimits(WindowLimits& windowLimits) void WindowSceneSessionImpl::UpdateNewSize() { if (GetWindowMode() != WindowMode::WINDOW_MODE_FLOATING || property_->IsWindowLimitDisabled()) { - TLOGI(WmsLogTag::WMS_LAYOUT, "Fullscreen couldnot update new size, Id: %{public}u", GetWindowId()); + TLOGI(WmsLogTag::WMS_LAYOUT, "fullscreen of compatible mode could not update new size, Id: %{public}u", + GetPersistentId()); return; } bool needResize = false; @@ -5950,7 +5996,7 @@ WMError WindowSceneSessionImpl::SetFollowParentMultiScreenPolicy(bool enabled) if (IsWindowSessionInvalid()) { return WMError::WM_ERROR_INVALID_WINDOW; } - if (IsPadAndNotFreeMutiWindowCompatibleMode()) { + if (IsPadAndNotFreeMultiWindowCompatibleMode()) { TLOGE(WmsLogTag::WMS_SUB, "This is PcAppInpad, not Suppored"); return WMError::WM_OK; } @@ -6188,6 +6234,13 @@ WMError WindowSceneSessionImpl::MoveAndResizeKeyboard(const KeyboardLayoutParams WMError WindowSceneSessionImpl::AdjustKeyboardLayout(const KeyboardLayoutParams params) { + TLOGI(WmsLogTag::WMS_KEYBOARD, "g: %{public}u, " + "LAvoid: %{public}d, PAvoid: %{public}d, " + "LRect: %{public}s, PRect: %{public}s, " + "LPRect: %{public}s, PPRect: %{public}s", + static_cast(params.gravity_), params.landscapeAvoidHeight_, params.portraitAvoidHeight_, + params.LandscapeKeyboardRect_.ToString().c_str(), params.PortraitKeyboardRect_.ToString().c_str(), + params.LandscapePanelRect_.ToString().c_str(), params.PortraitPanelRect_.ToString().c_str()); property_->SetKeyboardLayoutParams(params); auto ret = MoveAndResizeKeyboard(params); if (ret != WMError::WM_OK) { @@ -6247,7 +6300,18 @@ WMError WindowSceneSessionImpl::IsImmersiveLayout(bool& isImmersiveLayout) const if (IsWindowSessionInvalid()) { return WMError::WM_ERROR_INVALID_WINDOW; } - isImmersiveLayout = isIgnoreSafeArea_; + if (IsPcOrPadFreeMultiWindowMode()) { + auto uiContent = GetUIContentSharedPtr(); + if (uiContent == nullptr) { + TLOGE(WmsLogTag::WMS_IMMS, "uicontent is null"); + return WMError::WM_ERROR_INVALID_WINDOW; + } + Rect drawableRect; + uiContent->GetWindowPaintSize(drawableRect); + isImmersiveLayout = drawableRect == GetRect(); + } else { + isImmersiveLayout = isIgnoreSafeArea_; + } return WMError::WM_OK; } diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index be49ecbbda44664058243a790548bf6075c8bcc0..10068cf229e23c8f34fe789a4329c539dd098b2b 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -73,7 +73,7 @@ constexpr uint32_t API_VERSION_MOD = 1000; constexpr int32_t WINDOW_ROTATION_CHANGE = 50; constexpr uint32_t INVALID_TARGET_API_VERSION = 0; constexpr uint32_t OPAQUE = 0xFF000000; -constexpr int32_t WINDOW_CONNECT_TIMEOUT = 3000; +constexpr int32_t WINDOW_CONNECT_TIMEOUT = 1000; constexpr int32_t WINDOW_LIFECYCLE_TIMEOUT = 100; /* @@ -267,17 +267,39 @@ std::atomic WindowSessionImpl::defaultDensityEnabledGlobalConfig_ = false; } \ } while (false) -WindowSessionImpl::WindowSessionImpl(const sptr& option) +WindowSessionImpl::WindowSessionImpl(const sptr& option, + const std::shared_ptr& rsUIContext) { WLOGFD("[WMSCom] Constructor"); property_ = sptr::MakeSptr(); + windowOption_ = option; + handler_ = std::make_shared(AppExecFwk::EventRunner::GetMainEventRunner()); + WindowType optionWindowType = option->GetWindowType(); SessionInfo sessionInfo; sessionInfo.bundleName_ = option->GetBundleName(); property_->SetSessionInfo(sessionInfo); + property_->SetWindowType(optionWindowType); + InitPropertyFromOption(option); + isIgnoreSafeArea_ = WindowHelper::IsSubWindow(optionWindowType); + + RSAdapterUtil::InitRSUIDirector(rsUIDirector_, true, true, rsUIContext); + if (WindowHelper::IsSubWindow(GetType())) { + property_->SetDecorEnable(option->GetSubWindowDecorEnable()); + } + surfaceNode_ = CreateSurfaceNode(property_->GetWindowName(), optionWindowType); + if (surfaceNode_ != nullptr) { + vsyncStation_ = std::make_shared(surfaceNode_->GetId()); + } + WindowHelper::SplitStringByDelimiter( + system::GetParameter("const.window.containerColorLists", ""), ",", containerColorList_); + SetDefaultDensityEnabledValue(defaultDensityEnabledGlobalConfig_); +} + +void WindowSessionImpl::InitPropertyFromOption(const sptr& option) +{ property_->SetWindowName(option->GetWindowName()); property_->SetRequestRect(option->GetWindowRect()); - property_->SetWindowType(optionWindowType); property_->SetFocusable(option->GetFocusable()); property_->SetTouchable(option->GetTouchable()); property_->SetDisplayId(option->GetDisplayId()); @@ -304,21 +326,6 @@ WindowSessionImpl::WindowSessionImpl(const sptr& option) getRotationResultFuture_ = sptr::MakeSptr(); updateRectCallback_ = sptr::MakeSptr(); isMainHandlerAvailable_ = option->GetMainHandlerAvailable(); - isIgnoreSafeArea_ = WindowHelper::IsSubWindow(optionWindowType); - windowOption_ = option; - handler_ = std::make_shared(AppExecFwk::EventRunner::GetMainEventRunner()); - - RSAdapterUtil::InitRSUIDirector(rsUIDirector_, true, true); - if (WindowHelper::IsSubWindow(GetType())) { - property_->SetDecorEnable(option->GetSubWindowDecorEnable()); - } - surfaceNode_ = CreateSurfaceNode(property_->GetWindowName(), optionWindowType); - if (surfaceNode_ != nullptr) { - vsyncStation_ = std::make_shared(surfaceNode_->GetId()); - } - WindowHelper::SplitStringByDelimiter( - system::GetParameter("const.window.containerColorLists", ""), ",", containerColorList_); - SetDefaultDensityEnabledValue(defaultDensityEnabledGlobalConfig_); } bool WindowSessionImpl::IsPcWindow() const @@ -343,7 +350,7 @@ bool WindowSessionImpl::IsPcOrPadFreeMultiWindowMode() const return windowSystemConfig_.IsPcWindow() || IsFreeMultiWindowMode(); } -bool WindowSessionImpl::IsPadAndNotFreeMutiWindowCompatibleMode() const +bool WindowSessionImpl::IsPadAndNotFreeMultiWindowCompatibleMode() const { return property_->GetPcAppInpadCompatibleMode() && !IsFreeMultiWindowMode(); @@ -362,8 +369,7 @@ bool WindowSessionImpl::GetCompatibleModeInPc() const bool WindowSessionImpl::IsAdaptToCompatibleImmersive() const { - auto property = GetPropertyByContext(); - return property->IsAdaptToImmersive(); + return property_->IsAdaptToImmersive(); } bool WindowSessionImpl::IsAdaptToSimulationScale() const @@ -671,7 +677,7 @@ WMError WindowSessionImpl::Connect() iSessionStage, iWindowEventChannel, surfaceNode_, windowSystemConfig_, property_, token, identityToken_); if (SysCapUtil::GetBundleName() != AppExecFwk::Constants::SCENE_BOARD_BUNDLE_NAME && - WindowHelper::IsMainWindow(GetType())) { + WindowHelper::IsMainWindow(GetType()) && !property_->GetMissionInfo().startupInvisibility_) { auto startTime = std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()).count(); updateRectCallback_->GetUpdateRectResult(WINDOW_CONNECT_TIMEOUT); @@ -947,7 +953,6 @@ void WindowSessionImpl::RemoveSubWindow(int32_t parentPersistentId) std::lock_guard lock(subWindowSessionMutex_); auto subIter = subWindowSessionMap_.find(parentPersistentId); if (subIter == subWindowSessionMap_.end()) { - TLOGW(WmsLogTag::WMS_SUB, "find parentPersistentId: %{public}d failed", parentPersistentId); return; } auto& subWindows = subIter->second; @@ -1088,8 +1093,6 @@ WSError WindowSessionImpl::UpdateRect(const WSRect& rect, SizeChangeReason reaso "[name:%{public}s, id:%{public}d], clientDisplayId: %{public}" PRIu64, rect.ToString().c_str(), preRect.ToString().c_str(), wmReason, GetWindowName().c_str(), GetPersistentId(), property_->GetDisplayId()); - TLOGD(WmsLogTag::WMS_LAYOUT, "hasRSTransaction:%{public}d, duration:%{public}d" PRIu64, - config.rsTransaction_ != nullptr, config.animationDuration_); HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "WindowSessionImpl::UpdateRect id: %d [%d, %d, %u, %u] reason: %u hasRSTransaction: %u", GetPersistentId(), wmRect.posX_, wmRect.posY_, wmRect.width_, wmRect.height_, wmReason, config.rsTransaction_ != nullptr); @@ -2129,12 +2132,12 @@ WSError WindowSessionImpl::SetKeyFramePolicy(KeyFramePolicy& keyFramePolicy) WMError WindowSessionImpl::SetDragKeyFramePolicy(const KeyFramePolicy& keyFramePolicy) { TLOGD(WmsLogTag::WMS_LAYOUT, "in"); - auto session = GetHostSession(); - if (session == nullptr) { - TLOGE(WmsLogTag::WMS_EVENT, "session is nullptr"); - return WMError::WM_ERROR_NULLPTR; + if (IsWindowSessionInvalid()) { + return WMError::WM_ERROR_INVALID_WINDOW; } - WSError errorCode = session->SetDragKeyFramePolicy(keyFramePolicy); + auto hostSession = GetHostSession(); + CHECK_HOST_SESSION_RETURN_ERROR_IF_NULL(hostSession, WMError::WM_ERROR_INVALID_WINDOW); + WSError errorCode = hostSession->SetDragKeyFramePolicy(keyFramePolicy); TLOGI(WmsLogTag::WMS_LAYOUT, "Id: %{public}d, keyFramePolicy: %{public}s, errorCode: %{public}d", GetPersistentId(), keyFramePolicy.ToString().c_str(), static_cast(errorCode)); return static_cast(errorCode); @@ -2217,7 +2220,7 @@ WMError WindowSessionImpl::SetUIContentInner(const std::string& contentInfo, voi return initUIContentRet; } if (auto uiContent = GetUIContentSharedPtr()) { - TLOGI(WmsLogTag::WMS_LAYOUT, "id:%{public}d, posX:%{public}d, posY:%{public}d, " + TLOGI(WmsLogTag::WMS_LAYOUT, "single hand, id:%{public}d, posX:%{public}d, posY:%{public}d, " "scaleX:%{public}f, scaleY:%{public}f", GetPersistentId(), singleHandTransform_.posX, singleHandTransform_.posY, singleHandTransform_.scaleX, singleHandTransform_.scaleY); @@ -2333,9 +2336,10 @@ void WindowSessionImpl::UpdateDecorEnableToAce(bool isDecorEnable) if (windowSystemConfig_.freeMultiWindowSupport_) { auto isSubWindow = WindowHelper::IsSubWindow(GetType()); decorVisible = decorVisible && (windowSystemConfig_.freeMultiWindowEnable_ || - (property_->GetIsPcAppInPad() && isSubWindow)); + (property_->GetIsPcAppInPad() && isSubWindow)) && + !(mode == WindowMode::WINDOW_MODE_FULLSCREEN && property_->GetCompatibleModeProperty()); } - if (GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN && property_->IsDecorFullscreenDisabled()) { + if (mode == WindowMode::WINDOW_MODE_FULLSCREEN && property_->IsDecorFullscreenDisabled()) { decorVisible = false; } uiContent->UpdateDecorVisible(decorVisible, isDecorEnable); @@ -2364,7 +2368,11 @@ void WindowSessionImpl::UpdateDecorEnable(bool needNotify, WindowMode mode) if (windowSystemConfig_.freeMultiWindowSupport_) { auto isSubWindow = WindowHelper::IsSubWindow(GetType()); decorVisible = decorVisible && (windowSystemConfig_.freeMultiWindowEnable_ || - (property_->GetIsPcAppInPad() && isSubWindow)); + (property_->GetIsPcAppInPad() && isSubWindow)) && + !(mode == WindowMode::WINDOW_MODE_FULLSCREEN && property_->GetCompatibleModeProperty()); + } + if (GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN && property_->IsDecorFullscreenDisabled()) { + decorVisible = false; } TLOGI(WmsLogTag::WMS_DECOR, "decorVisible:%{public}d, id: %{public}d", decorVisible, GetPersistentId()); uiContent->UpdateDecorVisible(decorVisible, IsDecorEnable()); @@ -2716,7 +2724,7 @@ WMError WindowSessionImpl::SetWindowDelayRaiseEnabled(bool isEnabled) if (IsWindowSessionInvalid()) { return WMError::WM_ERROR_INVALID_WINDOW; } - if (IsPadAndNotFreeMutiWindowCompatibleMode()) { + if (IsPadAndNotFreeMultiWindowCompatibleMode()) { TLOGE(WmsLogTag::WMS_FOCUS, "The is PcAppInPad, not supported"); return WMError::WM_OK; } @@ -2910,6 +2918,7 @@ float WindowSessionImpl::GetBrightness() const void WindowSessionImpl::SetRequestedOrientation(Orientation orientation, bool needAnimation) { + HITRACE_METER_NAME(HITRACE_TAG_WINDOW_MANAGER, "WindowSessionImpl::SetRequestedOrientation"); if (IsWindowSessionInvalid()) { TLOGE(WmsLogTag::DEFAULT, "windowSession is invalid"); return; @@ -2919,16 +2928,14 @@ void WindowSessionImpl::SetRequestedOrientation(Orientation orientation, bool ne if (!isNeededForciblySetOrientation(orientation)) { return; } + if (property_->IsSupportRotateFullScreen()) { + TLOGI(WmsLogTag::WMS_COMPAT, "compatible request horizontal orientation %{public}u", orientation); + property_->SetIsLayoutFullScreen(IsHorizontalOrientation(orientation)); + } if (needAnimation) { NotifyPreferredOrientationChange(orientation); SetUserRequestedOrientation(orientation); } - // when compatible mode disable fullscreen and request orientation, will enter into immersive mode - if (property_->IsFullScreenDisabled() && IsHorizontalOrientation(orientation)) { - TLOGI(WmsLogTag::WMS_COMPAT, "compatible request horizontal orientation %{public}u", orientation); - property_->SetIsLayoutFullScreen(true); - } - // the orientation of the invalid type is only applied to pageRotation. if (orientation == Orientation::INVALID) { Orientation requestedOrientation = ConvertInvalidOrientation(); property_->SetRequestedOrientation(requestedOrientation, needAnimation); @@ -3020,14 +3027,14 @@ std::string WindowSessionImpl::GetContentInfo(BackupAndRestoreType type) WMError WindowSessionImpl::SetRestoredRouterStack(const std::string& routerStack) { - TLOGD(WmsLogTag::WMS_LIFE, "in"); + TLOGD(WmsLogTag::WMS_LIFE, "Set restored router stack."); restoredRouterStack_ = routerStack; return WMError::WM_OK; } std::string WindowSessionImpl::GetRestoredRouterStack() { - TLOGD(WmsLogTag::WMS_LIFE, "in"); + TLOGD(WmsLogTag::WMS_LIFE, "Get restored router stack."); return std::move(restoredRouterStack_); } @@ -3414,7 +3421,7 @@ WMError WindowSessionImpl::SetWindowTitleMoveEnabled(bool enable) if (IsWindowSessionInvalid()) { return WMError::WM_ERROR_INVALID_WINDOW; } - if (IsPadAndNotFreeMutiWindowCompatibleMode()) { + if (IsPadAndNotFreeMultiWindowCompatibleMode()) { TLOGE(WmsLogTag::WMS_DECOR, "The is PcAppInPad, not supported"); return WMError::WM_OK; } @@ -3445,7 +3452,7 @@ WMError WindowSessionImpl::SetSubWindowModal(bool isModal, ModalityType modality TLOGE(WmsLogTag::WMS_SUB, "called by invalid window type, type:%{public}d", GetType()); return WMError::WM_ERROR_INVALID_CALLING; } - if (modalityType == ModalityType::APPLICATION_MODALITY && IsPadAndNotFreeMutiWindowCompatibleMode()) { + if (modalityType == ModalityType::APPLICATION_MODALITY && IsPadAndNotFreeMultiWindowCompatibleMode()) { TLOGE(WmsLogTag::WMS_SUB, "This is PcAppInPad, not support"); return WMError::WM_OK; } @@ -4181,7 +4188,7 @@ EnableIfSame(state)); crossAxisState_ = state; AAFwk::Want want; @@ -4254,8 +4261,9 @@ std::vector> WindowSessionImpl::GetWaterfallM WMError WindowSessionImpl::NotifyAcrossDisplaysChange(bool isAcrossDisplays) { - static bool isFirstNotify = true; - if (!isFirstNotify && isAcrossDisplays_ == isAcrossDisplays) { + TLOGI(WmsLogTag::WMS_ATTRIBUTE, "winId:%{public}u,isFirst:%{public}u,last:%{public}u,curr:%{public}u", + GetWindowId(), isFirstNotifyAcrossDisplays_, isAcrossDisplays_, isAcrossDisplays); + if (!isFirstNotifyAcrossDisplays_ && isAcrossDisplays_ == isAcrossDisplays) { return WMError::WM_DO_NOTHING; } std::lock_guard lock(acrossDisplaysChangeListenerMutex_); @@ -4265,7 +4273,7 @@ WMError WindowSessionImpl::NotifyAcrossDisplaysChange(bool isAcrossDisplays) listener->OnAcrossDisplaysChanged(isAcrossDisplays); } } - isFirstNotify = false; + isFirstNotifyAcrossDisplays_ = false; isAcrossDisplays_ = isAcrossDisplays; return WMError::WM_OK; } @@ -4648,7 +4656,7 @@ CrossAxisState WindowSessionImpl::GetCrossAxisState() if (hostSession->GetCrossAxisState(state) != WSError::WS_OK) { return CrossAxisState::STATE_INVALID; } - TLOGI(WmsLogTag::WMS_LAYOUT, "window id is %{public}d, state is %{public}d", GetPersistentId(), + TLOGI(WmsLogTag::WMS_LAYOUT_PC, "window id is %{public}d, state is %{public}u", GetPersistentId(), static_cast(state)); return state; } @@ -4729,6 +4737,9 @@ WMError WindowSessionImpl::SetWindowContainerModalColor(const std::string& activ if (!SessionPermission::IsSystemCalling()) { return WMError::WM_ERROR_NOT_SYSTEM_APP; } + if (IsWindowSessionInvalid()) { + return WMError::WM_ERROR_INVALID_WINDOW; + } if (!WindowHelper::IsMainWindow(GetType())) { return WMError::WM_ERROR_INVALID_CALLING; } @@ -4913,6 +4924,7 @@ static void RequestInputMethodCloseKeyboard(bool isNeedKeyboard, bool keepKeyboa { if (!isNeedKeyboard && !keepKeyboardFlag) { #ifdef IMF_ENABLE + TLOGI(WmsLogTag::WMS_KEYBOARD, "Notify InputMethod framework close keyboard start."); if (MiscServices::InputMethodController::GetInstance()) { MiscServices::InputMethodController::GetInstance()->RequestHideInput(); TLOGD(WmsLogTag::WMS_KEYBOARD, "Notify InputMethod framework close keyboard end."); @@ -6160,7 +6172,7 @@ void WindowSessionImpl::NotifyPointerEvent(const std::shared_ptrGetPointerAction() != MMI::PointerEvent::POINTER_ACTION_MOVE) { - TLOGW(WmsLogTag::WMS_INPUT_KEY_FLOW, "not consume, wid:%{public}u", GetWindowId()); + TLOGW(WmsLogTag::WMS_INPUT_KEY_FLOW, "pointerEvent not consumed, windowId:%{public}u", GetWindowId()); } pointerEvent->MarkProcessed(); } @@ -6249,18 +6261,6 @@ bool WindowSessionImpl::FilterKeyEvent(const std::shared_ptr& key return false; } -void WindowSessionImpl::NotifyConsumeResultToFloatWindow - (const std::shared_ptr& keyEvent, bool isConsumed) -{ - if ((keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_TAB || - keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ENTER) && !GetWatchGestureConsumed() && - keyEvent->GetKeyAction() == MMI::KeyEvent::KEY_ACTION_DOWN) { - TLOGD(WmsLogTag::WMS_EVENT, "wid:%{public}d, keyCode:%{public}d, isConsumed:%{public}d", - GetWindowId(), keyEvent->GetKeyCode(), isConsumed); - NotifyWatchGestureConsumeResult(keyEvent->GetKeyCode(), isConsumed); - } -} - bool WindowSessionImpl::FilterPointerEvent(const std::shared_ptr& pointerEvent) { bool isFiltered = false; @@ -6297,6 +6297,18 @@ bool WindowSessionImpl::FilterPointerEvent(const std::shared_ptr& keyEvent, bool isConsumed) +{ + if ((keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_TAB || + keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ENTER) && !GetWatchGestureConsumed() && + keyEvent->GetKeyAction() == MMI::KeyEvent::KEY_ACTION_DOWN) { + TLOGD(WmsLogTag::WMS_EVENT, "wid:%{public}u, keyCode:%{public}d, isConsumed:%{public}d", + GetWindowId(), keyEvent->GetKeyCode(), isConsumed); + NotifyWatchGestureConsumeResult(keyEvent->GetKeyCode(), isConsumed); + } +} + WMError WindowSessionImpl::HandleEscKeyEvent(const std::shared_ptr& keyEvent, bool& isConsumed) { if (keyEvent == nullptr) { @@ -6318,8 +6330,9 @@ WMError WindowSessionImpl::HandleEscKeyEvent(const std::shared_ptrHasFlag(MMI::InputEvent::EVENT_FLAG_KEYBOARD_ESCAPE); - if (!escToBackFlag) { - TLOGE(WmsLogTag::WMS_EVENT, "ESC no flag"); + // noflag do not handle; UEC do not handle because it is handled in the host window + if (!escToBackFlag || property_->GetWindowType() == WindowType::WINDOW_TYPE_UI_EXTENSION) { + TLOGI(WmsLogTag::WMS_EVENT, "ESC no flag or UIExtension window"); return WMError::WM_DO_NOTHING; } @@ -6962,7 +6975,7 @@ WSError WindowSessionImpl::NotifyDialogStateChange(bool isForeground) void WindowSessionImpl::UpdatePiPRect(const Rect& rect, WindowSizeChangeReason reason) { if (IsWindowSessionInvalid()) { - WLOGFE("session is invalid"); + TLOGE(WmsLogTag::WMS_PIP, "session is invalid"); return; } auto hostSession = GetHostSession(); @@ -7022,7 +7035,8 @@ WMError WindowSessionImpl::UpdateFloatingBall(const FloatingBallTemplateBaseInfo } if (GetProperty()->GetFbTemplateInfo().template_ != fbTemplateBaseInfo.template_) { - TLOGE(WmsLogTag::WMS_SYSTEM, "Fb template type can't update"); + TLOGE(WmsLogTag::WMS_SYSTEM, "Fb template type can't update %{public}d, %{public}d", + GetProperty()->GetFbTemplateInfo().template_, fbTemplateBaseInfo.template_); return WMError::WM_ERROR_FB_UPDATE_TEMPLATE_TYPE_DENIED; } FloatingBallTemplateInfo fbTemplateInfo = FloatingBallTemplateInfo(fbTemplateBaseInfo, icon); @@ -7128,7 +7142,7 @@ void WindowSessionImpl::NotifyWindowStatusDidChange(WindowMode mode) auto windowStatus = GetWindowStatusInner(mode); auto lastStatus = lastStatusWhenNotifyWindowStatusDidChange_.load(); if (lastStatus == windowStatus) { - TLOGI(WmsLogTag::WMS_LAYOUT, "Duplicate windowStatus:%{public}u, id:%{public}d, windowMode:%{public}u", + TLOGD(WmsLogTag::WMS_LAYOUT, "Duplicate windowStatus:%{public}u, id:%{public}d, windowMode:%{public}u", windowStatus, GetPersistentId(), mode); return; } @@ -7153,7 +7167,7 @@ void WindowSessionImpl::NotifyWindowStatusDidChange(WindowMode mode) void WindowSessionImpl::NotifyFirstValidLayoutUpdate(const Rect& preRect, const Rect& newRect) { bool isFirstValidLayoutUpdate = true; - if (preRect.IsUninitializedSize() && !newRect.IsUninitializedSize() && + if (!newRect.IsUninitializedSize() && isFirstValidLayoutUpdate_.compare_exchange_strong(isFirstValidLayoutUpdate, false)) { updateRectCallback_->OnFirstValidRectUpdate(GetPersistentId()); TLOGI(WmsLogTag::WMS_LAYOUT, "Id:%{public}d, rect:%{public}s", GetPersistentId(), newRect.ToString().c_str()); @@ -7659,6 +7673,10 @@ void WindowSessionImpl::SetCurrentTransform(const Transform& transform) std::lock_guard lock(currentTransformMutex_); currentTransform_ = transform; } + if (handler_ == nullptr) { + TLOGE(WmsLogTag::WMS_COMPAT, "handler is nullptr"); + return; + } handler_->PostTask([weakThis = wptr(this), transform, where = __func__] { auto window = weakThis.promote(); if (window == nullptr) { @@ -7714,15 +7732,15 @@ void WindowSessionImpl::GetExtensionConfig(AAFwk::WantParams& want) const GetRootHostWindowType() : GetType(); want.SetParam(Extension::ROOT_HOST_WINDOW_TYPE_FIELD, AAFwk::Integer::Box(static_cast(rootHostWindowType))); + bool isHostWindowDelayRaiseEnabled = IsWindowDelayRaiseEnabled(); + want.SetParam(Extension::HOST_WINDOW_DELAY_RAISE_STATE_FIELD, + AAFwk::Integer::Box(static_cast(isHostWindowDelayRaiseEnabled))); + SetCompatInfoInExtensionConfig(want); bool gestureBackEnable = true; GetGestureBackEnabled(gestureBackEnable); want.SetParam(Extension::GESTURE_BACK_ENABLED, AAFwk::Integer::Box(static_cast(gestureBackEnable))); want.SetParam(Extension::IMMERSIVE_MODE_ENABLED, AAFwk::Integer::Box(static_cast(GetImmersiveModeEnabledState()))); - bool isHostWindowDelayRaiseEnabled = IsWindowDelayRaiseEnabled(); - want.SetParam(Extension::HOST_WINDOW_DELAY_RAISE_STATE_FIELD, - AAFwk::Integer::Box(static_cast(isHostWindowDelayRaiseEnabled))); - SetCompatInfoInExtensionConfig(want); } WMError WindowSessionImpl::OnExtensionMessage(uint32_t code, int32_t persistentId, const AAFwk::Want& data) @@ -7863,17 +7881,6 @@ void WindowSessionImpl::UpdateSubWindowInfo(uint32_t subWindowLevel, } } -bool WindowSessionImpl::IsSubWindowMaximizeSupported() const -{ - if (!WindowHelper::IsSubWindow(GetType())) { - return false; - } - if (windowOption_ != nullptr) { - return windowOption_->GetSubWindowMaximizeSupported(); - } - return false; -} - bool WindowSessionImpl::IsFullScreenPcAppInPadMode() const { return property_->GetIsPcAppInPad() && GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN @@ -7891,6 +7898,17 @@ void WindowSessionImpl::NotifyClientWindowSize() } } +WSError WindowSessionImpl::SetCurrentRotation(int32_t currentRotation) +{ + TLOGI(WmsLogTag::WMS_ROTATION, "currentRotation: %{public}d", currentRotation); + if (currentRotation > FULL_CIRCLE_DEGREE || currentRotation < ZERO_CIRCLE_DEGREE) { + TLOGE(WmsLogTag::WMS_ROTATION, "currentRotation is invalid: %{public}d", currentRotation); + return WSError::WS_ERROR_INVALID_PARAM; + } + property_->EditSessionInfo().currentRotation_ = currentRotation; + return WSError::WS_OK; +} + WMError WindowSessionImpl::CheckMultiWindowRect(uint32_t& width, uint32_t& height) { const auto& requestRect = GetRequestRect(); @@ -7980,27 +7998,25 @@ void WindowSessionImpl::NotifyRotationChangeResultInner(const RotationChangeInfo }, __func__); } -WSError WindowSessionImpl::SetCurrentRotation(int32_t currentRotation) +bool WindowSessionImpl::IsSubWindowMaximizeSupported() const { - TLOGI(WmsLogTag::WMS_ROTATION, "currentRotation: %{public}d", currentRotation); - if (currentRotation > FULL_CIRCLE_DEGREE || currentRotation < ZERO_CIRCLE_DEGREE) { - TLOGE(WmsLogTag::WMS_ROTATION, "currentRotation is invalid: %{public}d", currentRotation); - return WSError::WS_ERROR_INVALID_PARAM; + if (!WindowHelper::IsSubWindow(GetType())) { + return false; } - property_->EditSessionInfo().currentRotation_ = currentRotation; - return WSError::WS_OK; + if (windowOption_ != nullptr) { + return windowOption_->GetSubWindowMaximizeSupported(); + } + return false; } -nlohmann::json WindowSessionImpl::SetContainerButtonStyle(const DecorButtonStyle& decorButtonStyle) +WMError WindowSessionImpl::SetIntentParam(const std::string& intentParam, + const std::function& loadPageCallback, bool isColdStart) { - nlohmann::json decorJson; - decorJson.emplace(BUTTON_BACKGROUND_CORNER_RADIUS, decorButtonStyle.buttonBackgroundCornerRadius); - decorJson.emplace(BUTTON_BACKGROUND_SIZE, decorButtonStyle.buttonBackgroundSize); - decorJson.emplace(BUTTON_ICON_SIZE, decorButtonStyle.buttonIconSize); - decorJson.emplace(CLOSE_BUTTON_RIGHT_MARGIN, decorButtonStyle.closeButtonRightMargin); - decorJson.emplace(BUTTON_COLOR_MODE, decorButtonStyle.colorMode); - decorJson.emplace(BUTTON_SPACING_BETWEEN, decorButtonStyle.spacingBetweenButtons); - return decorJson; + TLOGI(WmsLogTag::WMS_LIFE, "in"); + intentParam_ = intentParam; + loadPageCallback_ = loadPageCallback; + isIntentColdStart_ = isColdStart; + return WMError::WM_OK; } std::shared_ptr WindowSessionImpl::GetRSUIDirector() const @@ -8020,6 +8036,18 @@ std::shared_ptr WindowSessionImpl::GetRSUIContext() const return rsUIContext; } +nlohmann::json WindowSessionImpl::SetContainerButtonStyle(const DecorButtonStyle& decorButtonStyle) +{ + nlohmann::json decorJson; + decorJson.emplace(BUTTON_BACKGROUND_CORNER_RADIUS, decorButtonStyle.buttonBackgroundCornerRadius); + decorJson.emplace(BUTTON_BACKGROUND_SIZE, decorButtonStyle.buttonBackgroundSize); + decorJson.emplace(BUTTON_ICON_SIZE, decorButtonStyle.buttonIconSize); + decorJson.emplace(CLOSE_BUTTON_RIGHT_MARGIN, decorButtonStyle.closeButtonRightMargin); + decorJson.emplace(BUTTON_COLOR_MODE, decorButtonStyle.colorMode); + decorJson.emplace(BUTTON_SPACING_BETWEEN, decorButtonStyle.spacingBetweenButtons); + return decorJson; +} + bool WindowSessionImpl::IsAnco() const { return property_->GetCollaboratorType() == static_cast(CollaboratorType::RESERVE_TYPE); @@ -8043,16 +8071,6 @@ void WindowSessionImpl::SetNavDestinationInfo(const std::string& navDestinationI navDestinationInfo_ = navDestinationInfo; } -WMError WindowSessionImpl::SetIntentParam(const std::string& intentParam, - const std::function& loadPageCallback, bool isColdStart) -{ - TLOGI(WmsLogTag::WMS_LIFE, "in"); - intentParam_ = intentParam; - loadPageCallback_ = loadPageCallback; - isIntentColdStart_ = isColdStart; - return WMError::WM_OK; -} - WMError WindowSessionImpl::GetPiPSettingSwitchStatus(bool& switchStatus) const { if (IsWindowSessionInvalid()) { @@ -8075,31 +8093,11 @@ void WindowSessionImpl::SwitchSubWindow(bool freeMultiWindowEnable, int32_t pare subWindowSession->SetFreeMultiWindowMode(freeMultiWindowEnable); subWindowSession->UpdateTitleButtonVisibility(); subWindowSession->UpdateDecorEnable(true); - subWindowSession->UpdateEnableDragWhenSwitchMultiWindow(freeMultiWindowEnable); subWindowSession->SwitchSubWindow(freeMultiWindowEnable, subWindowSession->GetPersistentId()); } } } -void WindowSessionImpl::UpdateEnableDragWhenSwitchMultiWindow(bool enable) -{ - if (hasSetEnableDrag_.load() || property_->IsDragResizeDisabled()) { - TLOGI(WmsLogTag::WMS_LAYOUT, "EnableDrag is already set, id: %{public}d", GetPersistentId()); - return; - } - auto isSystemWindow = WindowHelper::IsSystemWindow(property_->GetWindowType()); - bool isDialog = WindowHelper::IsDialogWindow(property_->GetWindowType()); - bool isSystemCalling = property_->GetSystemCalling(); - TLOGI(WmsLogTag::WMS_LAYOUT, "windId: %{public}d, isSystemWindow: %{public}d, isDialog: %{public}d, " - "isSystemCalling: %{public}d", GetPersistentId(), isSystemWindow, isDialog, isSystemCalling); - if (!enable || (isSystemWindow && !isDialog && !isSystemCalling)) { - property_->SetDragEnabled(false); - } else { - property_->SetDragEnabled(true); - } - UpdateProperty(WSPropertyChangeAction::ACTION_UPDATE_DRAGENABLED); -} - void WindowSessionImpl::SetNotifySizeChangeFlag(bool flag) { if (flag) { diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index b83717f68ebfa0dc395085a8d9f9675fbb98e301..6a9fca35b8219c7ffe9f51e5b56b30f2745948e8 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -19,9 +19,12 @@ group("unittest") { testonly = true deps = [ + ":wm_floating_ball_manager_new_test", ":wm_floating_ball_manager_test", + ":wm_floating_ball_new_test", ":wm_floating_ball_test", ":wm_gtx_input_event_sender_test", + ":wm_input_transfer_station_new_test", ":wm_input_transfer_station_test", ":wm_pattern_detach_callback_proxy_test", ":wm_pattern_detach_callback_test", @@ -323,6 +326,16 @@ ohos_unittest("wm_input_transfer_station_test") { external_deps = test_external_deps } +ohos_unittest("wm_input_transfer_station_new_test") { + module_out_path = module_out_path + + sources = [ "input_transfer_station_new_test.cpp" ] + + deps = [ ":wm_unittest_common" ] + + external_deps = test_external_deps +} + ohos_unittest("wm_window_input_channel_test") { module_out_path = module_out_path @@ -647,6 +660,25 @@ ohos_unittest("wm_floating_ball_test") { ] } +ohos_unittest("wm_floating_ball_new_test") { + module_out_path = module_out_path + + sources = [ + "floating_ball_controller_new_test.cpp", + "floating_ball_option_new_test.cpp", + ] + + deps = [ ":wm_unittest_common" ] + + external_deps = [ + "ability_runtime:runtime", + "c_utils:utils", + "graphic_2d:librender_service_base", + "graphic_2d:librender_service_client", + "hilog:libhilog", + ] +} + ohos_unittest("wm_floating_ball_manager_test") { module_out_path = module_out_path @@ -661,6 +693,20 @@ ohos_unittest("wm_floating_ball_manager_test") { ] } +ohos_unittest("wm_floating_ball_manager_new_test") { + module_out_path = module_out_path + + sources = [ "floating_ball_manager_new_test.cpp" ] + + deps = [ ":wm_unittest_common" ] + + external_deps = [ + "ability_runtime:runtime", + "c_utils:utils", + "hilog:libhilog", + ] +} + ohos_unittest("wm_window_manager_agent_proxy_test") { module_out_path = module_out_path diff --git a/wm/test/unittest/animation/window_scene_session_impl_animation_test.cpp b/wm/test/unittest/animation/window_scene_session_impl_animation_test.cpp index 17a47f145beb4fd2ebae9b857bbf2632e41a8c9d..c3fb6f883ef5580874e4d854a9992942440bce9b 100644 --- a/wm/test/unittest/animation/window_scene_session_impl_animation_test.cpp +++ b/wm/test/unittest/animation/window_scene_session_impl_animation_test.cpp @@ -220,7 +220,7 @@ HWTEST_F(WindowSceneSessionImplAnimationTest, SetWindowShadowRadius, TestSize.Le window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; window->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT); ret = window->SetWindowShadowRadius(1.0f); - EXPECT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, ret); + EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; window->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); @@ -237,6 +237,10 @@ HWTEST_F(WindowSceneSessionImplAnimationTest, SetWindowShadowRadius, TestSize.Le window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW; ret = window->SetWindowShadowRadius(1.0f); EXPECT_EQ(WMError::WM_OK, ret); + + window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; + ret = window->SetWindowShadowRadius(1.0f); + EXPECT_EQ(WMError::WM_OK, ret); const std::string feature = "large_screen"; std::string deviceType = OHOS::system::GetParameter("const.product.devicetype", ""); diff --git a/wm/test/unittest/floating_ball_controller_new_test.cpp b/wm/test/unittest/floating_ball_controller_new_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8ab9cb255f1a843546b70b1646263d9b5ae40ac7 --- /dev/null +++ b/wm/test/unittest/floating_ball_controller_new_test.cpp @@ -0,0 +1,533 @@ +/* + * 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 + +#include +#include "ability_context_impl.h" +#include "floating_ball_controller.h" +#include "floating_ball_manager.h" +#include "modifier_render_thread/rs_modifiers_draw_thread.h" +#include "parameters.h" +#include "window.h" +#include "wm_common.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { + +class MockNewWindow : public Window { +public: + WindowState state_ = WindowState::STATE_INITIAL; + const uint32_t mockWindowId_ = 101; + MockNewWindow() {}; + ~MockNewWindow() {}; + MOCK_METHOD3(Show, WMError(uint32_t reason, bool withAnimation, bool withFocus)); + MOCK_METHOD1(Destroy, WMError(uint32_t reason)); + MOCK_METHOD0(NotifyPrepareCloseFloatingBall, void()); + MOCK_METHOD2(UpdateFloatingBall, WMError(const FloatingBallTemplateBaseInfo& fbTemplateBaseInfo, + const std::shared_ptr& icon)); + MOCK_METHOD1(RestoreFbMainWindow, WMError(const std::shared_ptr& want)); + MOCK_METHOD1(GetFloatingBallWindowId, WMError(uint32_t& windowId)); + uint32_t GetWindowId() const override + { + return mockWindowId_; + } + + void SetWindowState(const WindowState& state) + { + state_ = state; + } + + WindowState GetWindowState() const override + { + return state_; + } +}; + +class MockNewLifeCycleListener : public IFbLifeCycle { +public: + void OnFloatingBallStart() override + { + return; + } + void OnFloatingBallStop() override + { + return; + } +}; + +class MockNewClickListener : public IFbClickObserver { +public: + + void OnClickEvent() override + { + return; + } +}; + +class FloatingBallControllerNewTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + sptr fbController_; + sptr mw_; +}; + +void FloatingBallControllerNewTest::SetUpTestCase() +{ +} + +void FloatingBallControllerNewTest::TearDownTestCase() +{ +#ifdef RS_ENABLE_VK + RSModifiersDrawThread::Destroy(); +#endif +} + +void FloatingBallControllerNewTest::SetUp() +{ + int32_t windowId = 100; + mw_ = sptr::MakeSptr(); + ASSERT_NE(nullptr, mw_); + fbController_ = sptr::MakeSptr(mw_, windowId, nullptr); + ASSERT_NE(nullptr, fbController_); +} + +void FloatingBallControllerNewTest::TearDown() +{ + fbController_ = nullptr; + mw_ = nullptr; +} + +namespace { +/** + * @tc.name: CreateFloatingBallWindowAllNull + * @tc.desc: CreateFloatingBallWindowAllNull + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, CreateFloatingBallWindowAllNull, TestSize.Level1) +{ + sptr nullOption = nullptr; + EXPECT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, fbController_->CreateFloatingBallWindow(nullOption)); +} + +/** + * @tc.name: CreateFloatingBallWindowAllNull + * @tc.desc: CreateFloatingBallWindowAllNull + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, CreateFloatingBallWindowAllNull001, TestSize.Level1) +{ + fbController_->contextPtr_ = nullptr; + sptr option = sptr::MakeSptr(); + EXPECT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, fbController_->CreateFloatingBallWindow(option)); + option = nullptr; +} + +/** + * @tc.name: CreateFloatingBallWindowAllNull + * @tc.desc: CreateFloatingBallWindowAllNull + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, CreateFloatingBallWindowAllNull002, TestSize.Level1) +{ + std::shared_ptr contextPtr = + std::make_shared(); + fbController_->contextPtr_ = &contextPtr; + fbController_->mainWindow_ = nullptr; + sptr option = sptr::MakeSptr(); + EXPECT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, fbController_->CreateFloatingBallWindow(option)); + option = nullptr; + fbController_->contextPtr_ = nullptr; +} + +/** + * @tc.name: CreateFloatingBallWindowNotNullOption + * @tc.desc: CreateFloatingBallWindowNotNullOption + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, CreateFloatingBallWindowNotNullOption, TestSize.Level1) +{ + std::shared_ptr contextPtr = + std::make_shared(); + fbController_->contextPtr_ = &contextPtr; + sptr option = sptr::MakeSptr(); + mw_->SetWindowState(WindowState::STATE_INITIAL); + EXPECT_EQ(WMError::WM_ERROR_FB_CREATE_FAILED, fbController_->CreateFloatingBallWindow(option)); + option = nullptr; + fbController_->contextPtr_ = nullptr; +} + +/** + * @tc.name: CreateFloatingBallWindowNotNullOption + * @tc.desc: CreateFloatingBallWindowNotNullOption + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, CreateFloatingBallWindowNotNullOption001, TestSize.Level1) +{ + std::shared_ptr contextPtr = + std::make_shared(); + fbController_->contextPtr_ = &contextPtr; + sptr option = sptr::MakeSptr(); + mw_->SetWindowState(WindowState::STATE_SHOWN); + EXPECT_EQ(WMError::WM_ERROR_FB_CREATE_FAILED, fbController_->CreateFloatingBallWindow(option)); + option = nullptr; + fbController_->contextPtr_ = nullptr; +} + +/** + * @tc.name: CreateFloatingBallWindowUpdateNull + * @tc.desc: CreateFloatingBallWindowUpdateNull + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, CreateFloatingBallWindowUpdateNull, TestSize.Level1) +{ + std::shared_ptr contextPtr = + std::make_shared(); + fbController_->contextPtr_ = &contextPtr; + mw_->SetWindowState(WindowState::STATE_SHOWN); + sptr option = sptr::MakeSptr(); + auto res = fbController_->CreateFloatingBallWindow(option); + EXPECT_EQ(WMError::WM_ERROR_FB_CREATE_FAILED, res); + fbController_->UpdateMainWindow(nullptr); + EXPECT_EQ(100, fbController_->mainWindowId_); + option = nullptr; + fbController_->contextPtr_ = nullptr; +} + +/** + * @tc.name: CreateFloatingBallWindowUpdateNotNull + * @tc.desc: CreateFloatingBallWindowUpdateNotNull + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, CreateFloatingBallWindowUpdateNotNull, TestSize.Level1) +{ + std::shared_ptr contextPtr = + std::make_shared(); + fbController_->contextPtr_ = &contextPtr; + sptr option = sptr::MakeSptr(); + auto res = fbController_->CreateFloatingBallWindow(option); + EXPECT_EQ(WMError::WM_ERROR_FB_CREATE_FAILED, res); + fbController_->UpdateMainWindow(mw_); + EXPECT_EQ(101, fbController_->mainWindowId_); + option = nullptr; + fbController_->contextPtr_ = nullptr; +} + +/** + * @tc.name: StartFloatingBallNull + * @tc.desc: StartFloatingBallNull + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, StartFloatingBallNull, TestSize.Level1) +{ + sptr nullOption = nullptr; + EXPECT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, fbController_->StartFloatingBall(nullOption)); +} + +/** + * @tc.name: StartFloatingBallNotNull + * @tc.desc: StartFloatingBallNotNull + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, StartFloatingBallNotNull, TestSize.Level1) +{ + fbController_->curState_ = FbWindowState::STATE_STARTING; + sptr option = sptr::MakeSptr(); + EXPECT_EQ(WMError::WM_ERROR_FB_REPEAT_OPERATION, fbController_->StartFloatingBall(option)); + option = nullptr; +} + +/** + * @tc.name: StartFloatingBallNotNull + * @tc.desc: StartFloatingBallNotNull + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, StartFloatingBallNotNull01, TestSize.Level1) +{ + fbController_->curState_ = FbWindowState::STATE_STARTED; + sptr option = sptr::MakeSptr(); + EXPECT_EQ(WMError::WM_ERROR_FB_REPEAT_OPERATION, fbController_->StartFloatingBall(option)); + option = nullptr; +} + +/** + * @tc.name: StartFloatingBallSetActiveController + * @tc.desc: StartFloatingBallSetActiveController + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, StartFloatingBallSetActiveController, TestSize.Level1) +{ + fbController_->curState_ = FbWindowState::STATE_UNDEFINED; + sptr option = sptr::MakeSptr(); + FloatingBallManager::SetActiveController(fbController_); + EXPECT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, fbController_->StartFloatingBall(option)); + FloatingBallManager::RemoveActiveController(fbController_); + option = nullptr; +} + +/** + * @tc.name: StartFloatingBallSetActiveController + * @tc.desc: StartFloatingBallSetActiveController + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, StartFloatingBallSetActiveController01, TestSize.Level1) +{ + auto activeFbController = sptr::MakeSptr(mw_, 100, nullptr); + sptr option = sptr::MakeSptr(); + FloatingBallManager::SetActiveController(activeFbController); + EXPECT_EQ(WMError::WM_ERROR_FB_REPEAT_CONTROLLER, fbController_->StartFloatingBall(option)); + + FloatingBallManager::RemoveActiveController(activeFbController); + EXPECT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, fbController_->StartFloatingBall(option)); + option = nullptr; +} + +/** + * @tc.name: StartFloatingBallGetControllerState + * @tc.desc: StartFloatingBallGetControllerState + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, StartFloatingBallGetControllerState, TestSize.Level1) +{ + std::unique_ptr contextPtr = + std::make_unique(); + fbController_->contextPtr_ = contextPtr.get(); + sptr option = sptr::MakeSptr(); + EXPECT_NE(WMError::WM_OK, fbController_->StartFloatingBall(option)); + EXPECT_EQ(FbWindowState::STATE_UNDEFINED, fbController_->GetControllerState()); + option = nullptr; + fbController_->contextPtr_ = nullptr; +} + +/** + * @tc.name: LifeCycleTestNull + * @tc.desc: LifeCycleTestNull + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, LifeCycleTestNull, TestSize.Level1) +{ + EXPECT_EQ(WMError::WM_ERROR_FB_INTERNAL_ERROR, fbController_->RegisterFbLifecycle(nullptr)); +} + +/** + * @tc.name: LifeCycleTestNotNull + * @tc.desc: LifeCycleTestNotNull + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, LifeCycleTestNotNull, TestSize.Level1) +{ + auto lifeListener = sptr::MakeSptr(); + EXPECT_EQ(WMError::WM_OK, fbController_->RegisterFbLifecycle(lifeListener)); + fbController_->fbLifeCycleListeners_.clear(); +} + +/** + * @tc.name: LifeCycleTestRepeatRegister + * @tc.desc: LifeCycleTestRepeatRegister + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, LifeCycleTestRepeatRegister, TestSize.Level1) +{ + auto lifeListener = sptr::MakeSptr(); + EXPECT_EQ(WMError::WM_OK, fbController_->RegisterFbLifecycle(lifeListener)); + // repeat register + EXPECT_EQ(WMError::WM_OK, fbController_->RegisterFbLifecycle(lifeListener)); + fbController_->fbLifeCycleListeners_.emplace_back(nullptr); + fbController_->OnFloatingBallStart(); + fbController_->OnFloatingBallStop(); + fbController_->fbLifeCycleListeners_.clear(); +} + +/** + * @tc.name: LifeCycleTestUnregister + * @tc.desc: LifeCycleTestUnregister + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, LifeCycleTestUnregister, TestSize.Level1) +{ + auto lifeListener = sptr::MakeSptr(); + EXPECT_EQ(WMError::WM_ERROR_FB_INTERNAL_ERROR, fbController_->UnRegisterFbLifecycle(nullptr)); + EXPECT_EQ(WMError::WM_OK, fbController_->UnRegisterFbLifecycle(lifeListener)); + fbController_->fbLifeCycleListeners_.clear(); +} + +/** + * @tc.name: ClickTestNull + * @tc.desc: ClickTestNull + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, ClickTestNull, TestSize.Level1) +{ + EXPECT_EQ(WMError::WM_ERROR_FB_INTERNAL_ERROR, fbController_->RegisterFbClickObserver(nullptr)); +} + +/** + * @tc.name: ClickTestNotNull + * @tc.desc: ClickTestNotNull + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, ClickTestNotNull, TestSize.Level1) +{ + auto clickListener = sptr::MakeSptr(); + EXPECT_EQ(WMError::WM_OK, fbController_->RegisterFbClickObserver(clickListener)); + fbController_->fbClickObservers_.clear(); +} + +/** + * @tc.name: ClickTestRepeatRegister + * @tc.desc: ClickTestRepeatRegister + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, ClickTestRepeatRegister, TestSize.Level1) +{ + auto clickListener = sptr::MakeSptr(); + EXPECT_EQ(WMError::WM_OK, fbController_->RegisterFbClickObserver(clickListener)); + // repeat register + EXPECT_EQ(WMError::WM_OK, fbController_->RegisterFbClickObserver(clickListener)); + fbController_->fbClickObservers_.emplace_back(nullptr); + fbController_->OnFloatingBallClick(); + fbController_->fbClickObservers_.clear(); +} + +/** + * @tc.name: ClickTestUnregister + * @tc.desc: ClickTestUnregister + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, ClickTestUnregister, TestSize.Level1) +{ + auto clickListener = sptr::MakeSptr(); + EXPECT_EQ(WMError::WM_ERROR_FB_INTERNAL_ERROR, fbController_->UnRegisterFbClickObserver(nullptr)); + EXPECT_EQ(WMError::WM_OK, fbController_->UnRegisterFbClickObserver(clickListener)); + fbController_->fbClickObservers_.clear(); +} + +/** + * @tc.name: UpdateFloatingBall + * @tc.desc: UpdateFloatingBall + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, UpdateFloatingBall01, TestSize.Level1) +{ + fbController_->curState_ = FbWindowState::STATE_STOPPED; + sptr option = sptr::MakeSptr(); + EXPECT_EQ(WMError::WM_ERROR_FB_INVALID_STATE, fbController_->UpdateFloatingBall(option)); + + fbController_->curState_ = FbWindowState::STATE_STARTED; + sptr nullOption = nullptr; + EXPECT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, fbController_->UpdateFloatingBall(nullOption)); + fbController_->window_ = nullptr; + EXPECT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, fbController_->UpdateFloatingBall(option)); + + fbController_->window_ = mw_; + fbController_->curState_ = FbWindowState::STATE_STOPPED; + EXPECT_EQ(WMError::WM_ERROR_FB_INVALID_STATE, fbController_->UpdateFloatingBall(option)); + EXPECT_CALL(*(mw_), UpdateFloatingBall(_, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + fbController_->curState_ = FbWindowState::STATE_STARTED; + EXPECT_EQ(WMError::WM_OK, fbController_->UpdateFloatingBall(option)); + option = nullptr; +} + +/** + * @tc.name: StopFloatingBall + * @tc.desc: StopFloatingBall + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, StopFloatingBall01, TestSize.Level1) +{ + fbController_->curState_ = FbWindowState::STATE_STOPPED; + EXPECT_EQ(WMError::WM_ERROR_FB_REPEAT_OPERATION, fbController_->StopFloatingBallFromClient()); + fbController_->curState_ = FbWindowState::STATE_STOPPING; + EXPECT_EQ(WMError::WM_ERROR_FB_REPEAT_OPERATION, fbController_->StopFloatingBallFromClient()); + fbController_->curState_ = FbWindowState::STATE_STARTED; + EXPECT_CALL(*(mw_), NotifyPrepareCloseFloatingBall()).Times(1); + fbController_->window_ = mw_; + EXPECT_EQ(WMError::WM_OK, fbController_->StopFloatingBallFromClient()); + fbController_->window_ = nullptr; + fbController_->curState_ = FbWindowState::STATE_STARTED; + EXPECT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, fbController_->StopFloatingBallFromClient()); +} + +/** + * @tc.name: StopFloatingBall + * @tc.desc: StopFloatingBall + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, StopFloatingBall02, TestSize.Level1) +{ + fbController_->stopFromClient_ = false; + fbController_->curState_ = FbWindowState::STATE_STOPPING; + EXPECT_EQ(WMError::WM_ERROR_FB_REPEAT_OPERATION, fbController_->StopFloatingBall()); + fbController_->curState_ = FbWindowState::STATE_STOPPED; + EXPECT_EQ(WMError::WM_ERROR_FB_REPEAT_OPERATION, fbController_->StopFloatingBall()); + + fbController_->curState_ = FbWindowState::STATE_STARTED; + EXPECT_CALL(*(mw_), Destroy(_)).Times(1); + fbController_->window_ = mw_; + EXPECT_EQ(WMError::WM_OK, fbController_->StopFloatingBall()); + EXPECT_EQ(FbWindowState::STATE_STOPPED, fbController_->GetControllerState()); + + fbController_->window_ = nullptr; + fbController_->curState_ = FbWindowState::STATE_STARTED; + EXPECT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, fbController_->StopFloatingBall()); + EXPECT_EQ(WMError::WM_ERROR_FB_INTERNAL_ERROR, fbController_->DestroyFloatingBallWindow()); + EXPECT_EQ(nullptr, fbController_->GetFbWindow()); +} + +/** + * @tc.name: RestoreFloatingBallAbility + * @tc.desc: RestoreFloatingBallAbility + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, RestoreFloatingBallAbility, TestSize.Level1) +{ + std::shared_ptr want = std::make_shared(); + fbController_->curState_ = FbWindowState::STATE_STARTED; + EXPECT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, fbController_->RestoreMainWindow(want)); + fbController_->window_ = mw_; + fbController_->curState_ = FbWindowState::STATE_STOPPING; + EXPECT_EQ(WMError::WM_ERROR_FB_INVALID_STATE, fbController_->RestoreMainWindow(want)); + fbController_->curState_ = FbWindowState::STATE_STARTED; + EXPECT_CALL(*(mw_), RestoreFbMainWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, fbController_->RestoreMainWindow(want)); +} + +/** + * @tc.name: GetFloatingBallInfo + * @tc.desc: GetFloatingBallInfo + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerNewTest, GetFloatingBallInfo, TestSize.Level1) +{ + EXPECT_CALL(*(mw_), GetFloatingBallWindowId(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + fbController_->window_ = mw_; + uint32_t mockId = 1; + EXPECT_EQ(WMError::WM_ERROR_FB_INVALID_STATE, fbController_->GetFloatingBallWindowInfo(mockId)); + fbController_->curState_ = FbWindowState::STATE_STARTED; + fbController_->window_ = nullptr; + EXPECT_EQ(WMError::WM_ERROR_FB_STATE_ABNORMALLY, fbController_->GetFloatingBallWindowInfo(mockId)); + fbController_->window_ = mw_; + EXPECT_EQ(WMError::WM_OK, fbController_->GetFloatingBallWindowInfo(mockId)); +} +} +} +} \ No newline at end of file diff --git a/wm/test/unittest/floating_ball_controller_test.cpp b/wm/test/unittest/floating_ball_controller_test.cpp index 52d7cca285354bda563873cc8ff3cd5d94ee9aef..da495a58a7330b31a8001c8c59db2e92d72de303 100644 --- a/wm/test/unittest/floating_ball_controller_test.cpp +++ b/wm/test/unittest/floating_ball_controller_test.cpp @@ -19,6 +19,8 @@ #include "ability_context_impl.h" #include "floating_ball_controller.h" #include "floating_ball_manager.h" +#include "floating_ball_report.h" +#include "singleton_mocker.h" #include "modifier_render_thread/rs_modifiers_draw_thread.h" #include "parameters.h" #include "window.h" @@ -327,6 +329,26 @@ HWTEST_F(FloatingBallControllerTest, GetFloatingBallInfo, TestSize.Level1) fbController_->window_ = mw_; EXPECT_EQ(WMError::WM_OK, fbController_->GetFloatingBallWindowInfo(mockId)); } + +/** + * @tc.name: CreateFloatingBallController + * @tc.desc: CreateFloatingBallController + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallControllerTest, CreateFloatingBallController, TestSize.Level1) +{ + int32_t windowId = 100; + ASSERT_NE(nullptr, mw_); + std::shared_ptr contextPtr = + std::make_shared(); + ASSERT_NE(nullptr, contextPtr); + fbController_ = sptr::MakeSptr(mw_, windowId, &contextPtr); + ASSERT_NE(nullptr, fbController_); + const std::string packageName = "FLOATING_BALL_TEST"; + SingletonContainer::Get().SetCurrentPackageName(packageName); + EXPECT_EQ(packageName, SingletonContainer::Get().GetPackageName()); +} + } } } \ No newline at end of file diff --git a/wm/test/unittest/floating_ball_manager_new_test.cpp b/wm/test/unittest/floating_ball_manager_new_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7f2d2d904946a5e5d659d7cfba80d4c7d4fa6f93 --- /dev/null +++ b/wm/test/unittest/floating_ball_manager_new_test.cpp @@ -0,0 +1,116 @@ +/* + * 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 +#include "floating_ball_manager.h" +#include "wm_common.h" +#include "parameters.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +class FloatingBallManagerNewTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +class MockNewWindow : public Window { +public: + MockNewWindow() {}; + ~MockNewWindow() {}; +}; + +void FloatingBallManagerNewTest::SetUpTestCase() +{ +} + +void FloatingBallManagerNewTest::TearDownTestCase() +{ +} + +void FloatingBallManagerNewTest::SetUp() +{ +} + +void FloatingBallManagerNewTest::TearDown() +{ +} + +namespace { + +/** + * @tc.name: activeControllerPtrNull + * @tc.desc: activeControllerPtrNull + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallManagerNewTest, activeControllerPtrNull, TestSize.Level1) +{ + auto mw = sptr::MakeSptr(); + ASSERT_NE(nullptr, mw); + auto fbController = sptr::MakeSptr(mw, 101, nullptr); + // null fbController + EXPECT_EQ(false, FloatingBallManager::IsActiveController(fbController)); + EXPECT_EQ(false, FloatingBallManager::HasActiveController()); +} + +/** + * @tc.name: activeControllerDoFbActionEvent + * @tc.desc: activeControllerDoFbActionEvent + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallManagerNewTest, activeControllerDoFbActionEvent, TestSize.Level1) +{ + auto mw = sptr::MakeSptr(); + ASSERT_NE(nullptr, mw); + auto fbController = sptr::MakeSptr(mw, 101, nullptr); + std::string clickAction = "click"; + std::string closeAction = "close"; + FloatingBallManager::DoFbActionEvent("on"); + FloatingBallManager::DoFbActionEvent(clickAction); + FloatingBallManager::DoFbActionEvent(closeAction); + FloatingBallManager::DoDestroy(); + + // has fbController + FloatingBallManager::SetActiveController(fbController); + EXPECT_EQ(true, FloatingBallManager::IsActiveController(fbController)); + EXPECT_EQ(true, FloatingBallManager::HasActiveController()); + FloatingBallManager::DoFbActionEvent(clickAction); + FloatingBallManager::DoFbActionEvent(closeAction); + FloatingBallManager::DoDestroy(); + auto fbController1 = sptr::MakeSptr(mw, 102, nullptr); + FloatingBallManager::RemoveActiveController(fbController1); + FloatingBallManager::RemoveActiveController(fbController); +} + +/** + * @tc.name: IsSupportFloatingBall01 + * @tc.desc: IsSupportFloatingBall01 + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallManagerNewTest, IsSupportFloatingBall01, TestSize.Level1) +{ + const std::string multiWindowUIType = system::GetParameter("const.window.multiWindowUIType", ""); + bool isDeviceSupported = (multiWindowUIType == "HandsetSmartWindow" || multiWindowUIType == "TabletSmartWindow"); + bool isSupportFloatingBall = FloatingBallManager::IsSupportFloatingBall(); + EXPECT_EQ(isDeviceSupported, isSupportFloatingBall); +} +} +} +} \ No newline at end of file diff --git a/wm/test/unittest/floating_ball_option_new_test.cpp b/wm/test/unittest/floating_ball_option_new_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6c19b79a22ed2b4361ec8a4f4c107c7de78a050d --- /dev/null +++ b/wm/test/unittest/floating_ball_option_new_test.cpp @@ -0,0 +1,185 @@ +/* + * 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 + +#include +#include "parameters.h" +#include "floating_ball_option.h" +#include "wm_common.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { + +class FloatingBallOptionNewTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void FloatingBallOptionNewTest::SetUpTestCase() +{ +} + +void FloatingBallOptionNewTest::TearDownTestCase() +{ +} + +void FloatingBallOptionNewTest::SetUp() +{ +} + +void FloatingBallOptionNewTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: TestParamSetAndGetTemplateType + * @tc.desc: TestParamSetAndGetTemplateType + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallOptionNewTest, TestParamSetAndGetTemplateType, TestSize.Level1) +{ + auto option = sptr::MakeSptr(); + uint32_t templateType = 1; + option->SetTemplate(templateType); + EXPECT_EQ(templateType, option->GetTemplate()); +} + +/** + * @tc.name: TestParamSetAndGetTitle + * @tc.desc: TestParamSetAndGetTitle + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallOptionNewTest, TestParamSetAndGetTitle, TestSize.Level1) +{ + auto option = sptr::MakeSptr(); + std::string title = "title"; + option->SetTitle(title); + EXPECT_EQ(title, option->GetTitle()); +} + +/** + * @tc.name: TestParamSetAndGetContent + * @tc.desc: TestParamSetAndGetContent + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallOptionNewTest, TestParamSetAndGetContent, TestSize.Level1) +{ + auto option = sptr::MakeSptr(); + std::string content = "content"; + option->SetContent(content); + EXPECT_EQ(content, option->GetContent()); +} + +/** + * @tc.name: TestParamSetAndGetColor + * @tc.desc: TestParamSetAndGetColor + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallOptionNewTest, TestParamSetAndGetColor, TestSize.Level1) +{ + auto option = sptr::MakeSptr(); + std::string color = "#RRGGBB"; + option->SetBackgroundColor(color); + EXPECT_EQ(color, option->GetBackgroundColor()); +} + +/** + * @tc.name: TestParamSetAndGetIcon + * @tc.desc: TestParamSetAndGetIcon + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallOptionNewTest, TestParamSetAndGetIcon, TestSize.Level1) +{ + auto option = sptr::MakeSptr(); + std::shared_ptr icon = nullptr; + option->SetIcon(icon); + EXPECT_EQ(nullptr, option->GetIcon()); +} + +/** + * @tc.name: TestParamSetAndGetAssignmentTitle + * @tc.desc: TestParamSetAndGetAssignmentTitle + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallOptionNewTest, TestParamSetAndGetAssignmentTitle, TestSize.Level1) +{ + auto option = sptr::MakeSptr(); + std::string title = "title"; + option->SetTitle(title); + + FloatingBallTemplateBaseInfo fbTemplateBaseInfo; + option->GetFbTemplateBaseInfo(fbTemplateBaseInfo); + EXPECT_EQ(title, fbTemplateBaseInfo.title_); +} + +/** + * @tc.name: TestParamSetAndGetAssignmentTemplateType + * @tc.desc: TestParamSetAndGetAssignmentTemplateType + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallOptionNewTest, TestParamSetAndGetAssignmentTemplateType, TestSize.Level1) +{ + auto option = sptr::MakeSptr(); + uint32_t templateType = 1; + option->SetTemplate(templateType); + + FloatingBallTemplateBaseInfo fbTemplateBaseInfo; + option->GetFbTemplateBaseInfo(fbTemplateBaseInfo); + EXPECT_EQ(templateType, fbTemplateBaseInfo.template_); +} + +/** + * @tc.name: TestParamSetAndGetAssignmentContent + * @tc.desc: TestParamSetAndGetAssignmentContent + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallOptionNewTest, TestParamSetAndGetAssignmentContent, TestSize.Level1) +{ + auto option = sptr::MakeSptr(); + std::string content = "content"; + option->SetContent(content); + + FloatingBallTemplateBaseInfo fbTemplateBaseInfo; + option->GetFbTemplateBaseInfo(fbTemplateBaseInfo); + EXPECT_EQ(content, fbTemplateBaseInfo.content_); +} + +/** + * @tc.name: TestParamSetAndGetAssignmentColor + * @tc.desc: TestParamSetAndGetAssignmentColor + * @tc.type: FUNC + */ +HWTEST_F(FloatingBallOptionNewTest, TestParamSetAndGetAssignmentColor, TestSize.Level1) +{ + auto option = sptr::MakeSptr(); + std::string color = "#RRGGBB"; + option->SetBackgroundColor(color); + EXPECT_EQ(color, option->GetBackgroundColor()); + + FloatingBallTemplateBaseInfo fbTemplateBaseInfo; + option->GetFbTemplateBaseInfo(fbTemplateBaseInfo); + EXPECT_EQ(color, fbTemplateBaseInfo.backgroundColor_); +} +} +} +} \ No newline at end of file diff --git a/wm/test/unittest/input_transfer_station_new_test.cpp b/wm/test/unittest/input_transfer_station_new_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a5cde6dd78479551a839ee8e960ef02c45bbdd64 --- /dev/null +++ b/wm/test/unittest/input_transfer_station_new_test.cpp @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "input_manager.h" +#include "input_transfer_station.h" +#include "mock_window_adapter.h" +#include "modifier_render_thread/rs_modifiers_draw_thread.h" +#include "singleton_mocker.h" +#include "window_impl.h" +#include "window_manager_hilog.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +namespace { + std::string g_errLog; + void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, + const char *msg) + { + g_errLog = msg; + } +using WindowMocker = SingletonMocker; +class InputTransferStationNewTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + sptr window_; + std::shared_ptr listener; +}; +void InputTransferStationNewTest::SetUpTestCase() {} + +void InputTransferStationNewTest::TearDownTestCase() +{ +#ifdef RS_ENABLE_VK + RSModifiersDrawThread::Destroy(); +#endif +} + +void InputTransferStationNewTest::SetUp() +{ + sptr option = new WindowOption(); + option->SetWindowName("inputwindow"); + window_ = new WindowImpl(option); + window_->Create(INVALID_WINDOW_ID); + listener = std::make_shared(InputEventListener()); +} + +void InputTransferStationNewTest::TearDown() +{ + window_->Destroy(); + window_ = nullptr; +} + +namespace { +/** + * @tc.name: AddInputWindow + * @tc.desc: add input window in station. + * @tc.type: FUNC + * @tc.require: issueI5I5L4 + */ +HWTEST_F(InputTransferStationNewTest, AddInputWindow, TestSize.Level0) +{ + InputTransferStation::GetInstance().isRegisteredMMI_ = true; + InputTransferStation::GetInstance().AddInputWindow(window_); + InputTransferStation::GetInstance().isRegisteredMMI_ = false; + window_->GetWindowProperty()->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); + InputTransferStation::GetInstance().destroyed_ = true; + InputTransferStation::GetInstance().AddInputWindow(window_); + InputTransferStation::GetInstance().destroyed_ = false; + InputTransferStation::GetInstance().AddInputWindow(window_); + InputTransferStation::GetInstance().inputListener_ = listener; + InputTransferStation::GetInstance().AddInputWindow(window_); + InputTransferStation::GetInstance().isGameControllerLoaded_ = true; + InputTransferStation::GetInstance().AddInputWindow(window_); + InputTransferStation::GetInstance().isGameControllerLoaded_ = false; + InputTransferStation::GetInstance().AddInputWindow(window_); + ASSERT_EQ(true, InputTransferStation::GetInstance().isGameControllerLoaded_); +} + +/** + * @tc.name: RemoveInputWindow + * @tc.desc: remove input window in station. + * @tc.type: FUNC + * @tc.require: issueI5I5L4 + */ +HWTEST_F(InputTransferStationNewTest, RemoveInputWindow, TestSize.Level0) +{ + InputTransferStation::GetInstance().destroyed_ = true; + InputTransferStation::GetInstance().RemoveInputWindow(window_->GetWindowId()); + + InputTransferStation::GetInstance().destroyed_ = false; + sptr inputChannel = sptr::MakeSptr(window_); + InputTransferStation::GetInstance().windowInputChannels_.insert({ window_->GetWindowId(), inputChannel }); + InputTransferStation::GetInstance().RemoveInputWindow(window_->GetWindowId()); + auto iter = InputTransferStation::GetInstance().windowInputChannels_.find(window_->GetWindowId()); + ASSERT_EQ(iter, InputTransferStation::GetInstance().windowInputChannels_.end()); +} + +/** + * @tc.name: OnInputEvent + * @tc.desc: OnInputEvent keyEvent + * @tc.type: FUNC + */ +HWTEST_F(InputTransferStationNewTest, OnInputEvent001, TestSize.Level1) +{ + auto keyEvent = MMI::KeyEvent::Create(); + auto tempKeyEvent = keyEvent; + keyEvent = nullptr; + listener->OnInputEvent(keyEvent); + keyEvent = tempKeyEvent; + InputTransferStation::GetInstance().destroyed_ = true; + auto channel = InputTransferStation::GetInstance().GetInputChannel(0); + listener->OnInputEvent(keyEvent); + ASSERT_EQ(channel, nullptr); +} + +/** + * @tc.name: OnInputEvent + * @tc.desc: OnInputEvent axisEvent + * @tc.type: FUNC + */ +HWTEST_F(InputTransferStationNewTest, OnInputEvent002, TestSize.Level1) +{ + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + auto axisEvent = MMI::AxisEvent::Create(); + axisEvent = nullptr; + listener->OnInputEvent(axisEvent); + EXPECT_TRUE(g_errLog.find("AxisEvent is nullptr") != std::string::npos); + LOG_SetCallback(nullptr); +} + +/** + * @tc.name: OnInputEvent + * @tc.desc: OnInputEvent axisEvent + * @tc.type: FUNC + */ +HWTEST_F(InputTransferStationNewTest, OnInputEvent003, TestSize.Level1) +{ + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + auto axisEvent = MMI::AxisEvent::Create(); + listener->OnInputEvent(axisEvent); + EXPECT_FALSE(g_errLog.find("Receive axisEvent, windowId: %{public}d") != std::string::npos); + LOG_SetCallback(nullptr); +} + +/** + * @tc.name: OnInputEvent + * @tc.desc: OnInputEvent pointerEvent + * @tc.type: FUNC + */ +HWTEST_F(InputTransferStationNewTest, OnInputEvent004, TestSize.Level1) +{ + auto pointerEvent = MMI::PointerEvent::Create(); + pointerEvent->SetPointerAction(static_cast(MMI::PointerEvent::POINTER_ACTION_DOWN)); + listener->OnInputEvent(pointerEvent); + pointerEvent->SetPointerAction(static_cast(MMI::PointerEvent::POINTER_ACTION_MOVE)); + pointerEvent->SetAgentWindowId(0); + listener->OnInputEvent(pointerEvent); + pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN); + pointerEvent->SetPointerAction(static_cast(MMI::PointerEvent::POINTER_ACTION_DOWN)); + pointerEvent->AddFlag(MMI::InputEvent::EVENT_FLAG_GESTURE_SUPPLEMENT); + listener->OnInputEvent(pointerEvent); + EXPECT_EQ(pointerEvent->GetSourceType(), MMI::PointerEvent::SOURCE_TYPE_MOUSE); + pointerEvent->SetAgentWindowId(static_cast(-1)); + InputTransferStation::GetInstance().destroyed_ = true; + auto channel = InputTransferStation::GetInstance().GetInputChannel(0); + listener->OnInputEvent(pointerEvent); + ASSERT_EQ(channel, nullptr); +} + +/** + * @tc.name: GetInputChannel + * @tc.desc: GetInputChannel + * @tc.type: FUNC + */ +HWTEST_F(InputTransferStationNewTest, GetInputChannel, TestSize.Level0) +{ + InputTransferStation::GetInstance().destroyed_ = true; + auto channel = InputTransferStation::GetInstance().GetInputChannel(0); + ASSERT_EQ(channel, nullptr); + InputTransferStation::GetInstance().destroyed_ = false; + ASSERT_EQ(channel, nullptr); + InputTransferStation::GetInstance().AddInputWindow(window_); + InputTransferStation::GetInstance().GetInputChannel(0); +} +} // namespace +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/unittest/layout/window_session_impl_layout_test.cpp b/wm/test/unittest/layout/window_session_impl_layout_test.cpp index 15e641338821f752e3642215f88a5c6f31ef402f..527799e486c79c8d37b4a71dab9f38a6c867d44f 100644 --- a/wm/test/unittest/layout/window_session_impl_layout_test.cpp +++ b/wm/test/unittest/layout/window_session_impl_layout_test.cpp @@ -409,13 +409,13 @@ HWTEST_F(WindowSessionImplLayoutTest, NotifyFirstValidLayoutUpdate, TestSize.Lev sptr window = sptr::MakeSptr(option); window->property_->SetPersistentId(2025); - Rect preRect = { 0, 0, 1000, 1000 }; + Rect preRect = { 0, 0, 0, 0 }; Rect newRect = { 0, 0, 0, 0 }; window->isFirstValidLayoutUpdate_ = true; window->NotifyFirstValidLayoutUpdate(preRect, newRect); EXPECT_EQ(window->isFirstValidLayoutUpdate_, true); - preRect = { 0, 0, 0, 0 }; + preRect = { 0, 0, 1000, 1000 }; window->NotifyFirstValidLayoutUpdate(preRect, newRect); EXPECT_EQ(window->isFirstValidLayoutUpdate_, true); diff --git a/wm/test/unittest/window_scene_session_impl_test3.cpp b/wm/test/unittest/window_scene_session_impl_test3.cpp index 40b80b39ccb6c29c78ae5352197435aa27605e90..e2d17fc949491923a5457924920a1b71222c5683 100644 --- a/wm/test/unittest/window_scene_session_impl_test3.cpp +++ b/wm/test/unittest/window_scene_session_impl_test3.cpp @@ -2007,6 +2007,34 @@ HWTEST_F(WindowSceneSessionImplTest3, SetSupportedWindowModes02, TestSize.Level1 EXPECT_EQ(WMError::WM_OK, ret); } +/** + * @tc.name: SetSupportedWindowModes04 + * @tc.desc: SetSupportedWindowModes + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest3, SetSupportedWindowModes04, TestSize.Level1) +{ + sptr option = sptr::MakeSptr(); + option->SetWindowName("SetSupportedWindowModes04"); + sptr window = sptr::MakeSptr(option); + SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; + sptr session = sptr::MakeSptr(sessionInfo); + window->hostSession_ = session; + window->property_->SetPersistentId(1); + window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW; + window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + + std::vector supportedWindowModes; + supportedWindowModes.push_back(AppExecFwk::SupportWindowMode::FULLSCREEN); + supportedWindowModes.push_back(AppExecFwk::SupportWindowMode::SPLIT); + supportedWindowModes.push_back(AppExecFwk::SupportWindowMode::FLOATING); + + window->windowSystemConfig_.freeMultiWindowSupport_ = true; + window->windowSystemConfig_.freeMultiWindowEnable_ = false; + auto ret = window->SetSupportedWindowModes(supportedWindowModes); + EXPECT_EQ(WMError::WM_OK, ret); +} + /** * @tc.name: GrayOutMaximizeButton * @tc.desc: GrayOutMaximizeButton diff --git a/wm/test/unittest/window_scene_session_impl_test4.cpp b/wm/test/unittest/window_scene_session_impl_test4.cpp index ede5993e161652469efc94e9c63b3425654c3de6..1321b6b127a71ac4d34238df0274310698a4a52f 100644 --- a/wm/test/unittest/window_scene_session_impl_test4.cpp +++ b/wm/test/unittest/window_scene_session_impl_test4.cpp @@ -1082,8 +1082,6 @@ HWTEST_F(WindowSceneSessionImplTest4, SetWindowTitle, TestSize.Level1) sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; window->property_->SetPersistentId(1); - window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; - EXPECT_EQ(window->SetWindowTitle(title), WMError::WM_ERROR_DEVICE_NOT_SUPPORT); window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; window->windowSystemConfig_.freeMultiWindowSupport_ = false; window->windowSystemConfig_.isSystemDecorEnable_ = false; @@ -1101,6 +1099,12 @@ HWTEST_F(WindowSceneSessionImplTest4, SetWindowTitle, TestSize.Level1) EXPECT_EQ(window->Create(abilityContext_, session), WMError::WM_OK); EXPECT_EQ(window->SetWindowTitle(title), WMError::WM_OK); + window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; + window->windowSystemConfig_.freeMultiWindowSupport_ = true; + window->windowSystemConfig_.isSystemDecorEnable_ = true; + window->property_->SetDecorEnable(true); + EXPECT_EQ(window->SetWindowTitle(title), WMError::WM_OK); + window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW; window->property_->SetPcAppInpadCompatibleMode(true); window->windowSystemConfig_.freeMultiWindowEnable_ = false; diff --git a/wm/test/unittest/window_scene_session_impl_test5.cpp b/wm/test/unittest/window_scene_session_impl_test5.cpp index 31187be9f832604b987c04e39e2b5d07ba167cb9..613e221af55017ae824da1c97280e8f523d60085 100644 --- a/wm/test/unittest/window_scene_session_impl_test5.cpp +++ b/wm/test/unittest/window_scene_session_impl_test5.cpp @@ -507,6 +507,58 @@ HWTEST_F(WindowSceneSessionImplTest5, IsMainWindowFullScreenAcrossDisplays01, Te EXPECT_EQ(WMError::WM_OK, ret); } +/** + * @tc.name: RecoverSessionProperty + * @tc.desc: RecoverSessionProperty + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest5, RecoverSessionProperty, TestSize.Level1) +{ + sptr option = sptr::MakeSptr(); + sptr window = sptr::MakeSptr(option); + window->property_->SetPersistentId(1); + SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; + sptr session = sptr::MakeSptr(sessionInfo); + ASSERT_NE(nullptr, session); + window->hostSession_ = session; + window->RecoverSessionProperty(); +} + +/** + * @tc.name: UpdateColorMode + * @tc.desc: UpdateColorMode + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest5, UpdateColorMode, TestSize.Level1) +{ + std::shared_ptr configuration; + sptr option = sptr::MakeSptr(); + sptr window = sptr::MakeSptr(option); + window->hostSession_ = nullptr; + auto ret = window->UpdateColorMode(configuration); + EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); + + AbilityRuntime::ApplicationContext::applicationContext_ = std::make_shared(); + ret = window->UpdateColorMode(configuration); + EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); + + AbilityRuntime::ApplicationContext::applicationContext_->contextImpl_ = + std::make_shared(); + ret = window->UpdateColorMode(configuration); + configuration = std::make_shared(); + configuration->AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE, "dark"); + window->property_->SetPersistentId(1); + SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; + sptr session = sptr::MakeSptr(sessionInfo); + ASSERT_NE(nullptr, session); + window->hostSession_ = session; + ret = window->UpdateColorMode(configuration); + EXPECT_EQ(WMError::WM_OK, ret); + + ret = window->UpdateColorMode(configuration); + EXPECT_EQ(WMError::WM_OK, ret); +} + /** * @tc.name: SwitchFreeMultiWindow01 * @tc.desc: SwitchFreeMultiWindow @@ -1820,131 +1872,6 @@ HWTEST_F(WindowSceneSessionImplTest5, StopMoveWindow, Function | SmallTest | Tes ASSERT_EQ(WmErrorCode::WM_OK, window->StopMoveWindow()); } -/** - * @tc.name: HandleWindowLimitsInCompatibleMode01 - * @tc.desc: HandleWindowLimitsInCompatibleMode - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplTest5, HandleWindowLimitsInCompatibleMode01, Function | SmallTest | Level2) -{ - sptr option = sptr::MakeSptr(); - sptr window = sptr::MakeSptr(option); - window->property_->SetPersistentId(1); - SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"}; - sptr session = sptr::MakeSptr(sessionInfo); - window->hostSession_ = session; - sptr compatibleModeProperty = sptr::MakeSptr(); - compatibleModeProperty->SetDisableWindowLimit(true); - window->property_->SetCompatibleModeProperty(compatibleModeProperty); - window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); - WindowSizeLimits windowSizeLimits = {0, 0, 0, 0}; - window->HandleWindowLimitsInCompatibleMode(windowSizeLimits); - EXPECT_EQ(windowSizeLimits.maxWindowWidth, window->windowSystemConfig_.maxFloatingWindowSize_); - EXPECT_EQ(windowSizeLimits.maxWindowHeight, window->windowSystemConfig_.maxFloatingWindowSize_); - EXPECT_EQ(windowSizeLimits.minWindowWidth, window->windowSystemConfig_.miniWidthOfMainWindow_); - EXPECT_EQ(windowSizeLimits.minWindowHeight, window->windowSystemConfig_.miniHeightOfMainWindow_); -} - -/** - * @tc.name: HandleWindowLimitsInCompatibleMode02 - * @tc.desc: HandleWindowLimitsInCompatibleMode - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplTest5, HandleWindowLimitsInCompatibleMode02, Function | SmallTest | Level2) -{ - sptr option = sptr::MakeSptr(); - sptr window = sptr::MakeSptr(option); - window->property_->SetPersistentId(1); - SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"}; - sptr session = sptr::MakeSptr(sessionInfo); - window->hostSession_ = session; - sptr compatibleModeProperty = sptr::MakeSptr(); - compatibleModeProperty->SetDisableWindowLimit(true); - window->property_->SetCompatibleModeProperty(compatibleModeProperty); - window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); - WindowSizeLimits windowSizeLimits = {0, 0, 0, 0}; - window->HandleWindowLimitsInCompatibleMode(windowSizeLimits); - EXPECT_EQ(windowSizeLimits.maxWindowWidth, window->windowSystemConfig_.maxFloatingWindowSize_); - EXPECT_EQ(windowSizeLimits.maxWindowHeight, window->windowSystemConfig_.maxFloatingWindowSize_); - EXPECT_EQ(windowSizeLimits.minWindowWidth, window->windowSystemConfig_.miniWidthOfSubWindow_); - EXPECT_EQ(windowSizeLimits.minWindowHeight, window->windowSystemConfig_.miniHeightOfSubWindow_); -} - -/** - * @tc.name: HandleWindowLimitsInCompatibleMode03 - * @tc.desc: HandleWindowLimitsInCompatibleMode - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplTest5, HandleWindowLimitsInCompatibleMode03, Function | SmallTest | Level2) -{ - sptr option = sptr::MakeSptr(); - sptr window = sptr::MakeSptr(option); - window->property_->SetPersistentId(1); - SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"}; - sptr session = sptr::MakeSptr(sessionInfo); - window->hostSession_ = session; - sptr compatibleModeProperty = sptr::MakeSptr(); - compatibleModeProperty->SetDisableWindowLimit(true); - window->property_->SetCompatibleModeProperty(compatibleModeProperty); - window->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); - WindowSizeLimits windowSizeLimits = {0, 0, 0, 0}; - window->HandleWindowLimitsInCompatibleMode(windowSizeLimits); - EXPECT_EQ(windowSizeLimits.maxWindowWidth, window->windowSystemConfig_.maxFloatingWindowSize_); - EXPECT_EQ(windowSizeLimits.maxWindowHeight, window->windowSystemConfig_.maxFloatingWindowSize_); - EXPECT_EQ(windowSizeLimits.minWindowWidth, window->windowSystemConfig_.miniWidthOfDialogWindow_); - EXPECT_EQ(windowSizeLimits.minWindowHeight, window->windowSystemConfig_.miniHeightOfDialogWindow_); -} - -/** - * @tc.name: HandleWindowLimitsInCompatibleMode04 - * @tc.desc: HandleWindowLimitsInCompatibleMode - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplTest5, HandleWindowLimitsInCompatibleMode04, Function | SmallTest | Level2) -{ - sptr option = sptr::MakeSptr(); - sptr window = sptr::MakeSptr(option); - window->property_->SetPersistentId(1); - SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"}; - sptr session = sptr::MakeSptr(sessionInfo); - window->hostSession_ = session; - sptr compatibleModeProperty = sptr::MakeSptr(); - compatibleModeProperty->SetDisableWindowLimit(true); - window->property_->SetCompatibleModeProperty(compatibleModeProperty); - window->property_->SetWindowType(WindowType::SYSTEM_WINDOW_BASE); - WindowSizeLimits windowSizeLimits = {0, 0, 0, 0}; - window->HandleWindowLimitsInCompatibleMode(windowSizeLimits); - EXPECT_EQ(windowSizeLimits.maxWindowWidth, window->windowSystemConfig_.maxFloatingWindowSize_); - EXPECT_EQ(windowSizeLimits.maxWindowHeight, window->windowSystemConfig_.maxFloatingWindowSize_); - EXPECT_EQ(windowSizeLimits.minWindowWidth, MIN_FLOATING_WIDTH); - EXPECT_EQ(windowSizeLimits.minWindowHeight, MIN_FLOATING_HEIGHT); -} - -/** - * @tc.name: HandleWindowLimitsInCompatibleMode05 - * @tc.desc: HandleWindowLimitsInCompatibleMode - * @tc.type: FUNC - */ -HWTEST_F(WindowSceneSessionImplTest5, HandleWindowLimitsInCompatibleMode05, Function | SmallTest | Level2) -{ - sptr option = sptr::MakeSptr(); - sptr window = sptr::MakeSptr(option); - window->property_->SetPersistentId(1); - SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"}; - sptr session = sptr::MakeSptr(sessionInfo); - window->hostSession_ = session; - sptr compatibleModeProperty = sptr::MakeSptr(); - compatibleModeProperty->SetDisableWindowLimit(true); - window->property_->SetCompatibleModeProperty(compatibleModeProperty); - window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); - WindowSizeLimits windowSizeLimits = {0, 0, 0, 0}; - window->HandleWindowLimitsInCompatibleMode(windowSizeLimits); - EXPECT_EQ(windowSizeLimits.maxWindowWidth, 0); - EXPECT_EQ(windowSizeLimits.maxWindowHeight, 0); - EXPECT_EQ(windowSizeLimits.minWindowWidth, 0); - EXPECT_EQ(windowSizeLimits.minWindowHeight, 0); -} - /** * @tc.name: IsDecorEnable1 * @tc.desc: IsDecorEnable1 @@ -2095,6 +2022,37 @@ HWTEST_F(WindowSceneSessionImplTest5, SetFrameRectForPartialZoomIn02, Function | EXPECT_EQ(WMError::WM_OK, window->SetFrameRectForPartialZoomIn(frameRect)); } +/** + * @tc.name: UpdateEnableDragWhenSwitchMultiWindow + * @tc.desc: UpdateEnableDragWhenSwitchMultiWindow + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest5, UpdateEnableDragWhenSwitchMultiWindow, Function | SmallTest | Level2) +{ + sptr option = sptr::MakeSptr(); + option->SetWindowName("UpdateEnableDragWhenSwitchMultiWindow"); + option->SetWindowType(WindowType::WINDOW_TYPE_MAGNIFICATION); + sptr window = sptr::MakeSptr(option); + window->hasSetEnableDrag_.store(true); + window->UpdateEnableDragWhenSwitchMultiWindow(false); + EXPECT_EQ(true, window->property_->dragEnabled_); + + window->hasSetEnableDrag_.store(false); + window->UpdateEnableDragWhenSwitchMultiWindow(false); + EXPECT_EQ(false, window->property_->dragEnabled_); + + window->property_->type_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW; + sptr property = sptr::MakeSptr(); + property->disableDragResize_ = true; + window->property_->compatibleModeProperty_ = property; + window->UpdateEnableDragWhenSwitchMultiWindow(true); + EXPECT_EQ(false, window->property_->dragEnabled_); + + property->disableDragResize_ = false; + window->UpdateEnableDragWhenSwitchMultiWindow(true); + EXPECT_EQ(true, window->property_->dragEnabled_); +} + /** * @tc.name: GetConfigurationFromAbilityInfo * @tc.desc: GetConfigurationFromAbilityInfo diff --git a/wm/test/unittest/window_session_impl_test.cpp b/wm/test/unittest/window_session_impl_test.cpp index 151e4d3b3d8685c235aafe561f5bfd31693fac16..6a4ff804359080028856f5454eb6d0b4e7fd1022 100644 --- a/wm/test/unittest/window_session_impl_test.cpp +++ b/wm/test/unittest/window_session_impl_test.cpp @@ -601,9 +601,11 @@ HWTEST_F(WindowSessionImplTest, UpdateDecorEnable, TestSize.Level1) window->UpdateDecorEnable(false, mode); ASSERT_EQ(window->property_->windowMode_, mode); mode = WindowMode::WINDOW_MODE_FULLSCREEN; - window->property_->compatibleModeProperty_->SetDisableDecorFullscreen(true); - window->UpdateDecorEnable(false, mode); - ASSERT_EQ(window->property_->windowMode_, mode); + sptr compatibleModeProperty = sptr::MakeSptr(); + ASSERT_NE(compatibleModeProperty, nullptr); + compatibleModeProperty->SetDisableDecorFullscreen(true); + window->property_->SetCompatibleModeProperty(compatibleModeProperty); + window->UpdateDecorEnable(true, mode); GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDecorEnable end"; } @@ -1462,7 +1464,7 @@ HWTEST_F(WindowSessionImplTest, NotifyAfterLifecycleBackground, TestSize.Level1) WSError res = window->NotifyCloseExistPipWindow(); EXPECT_EQ(res, WSError::WS_OK); - EXPECT_EQ(WMError::WS_OK, window->Destroy()); + EXPECT_EQ(WMError::WM_OK, window->Destroy()); } /** diff --git a/wm/test/unittest/window_session_impl_test2.cpp b/wm/test/unittest/window_session_impl_test2.cpp index 0a8bc083513a8af37a2bb52589b526f652289ba0..033638e4382fad2ba581f9a776b72fb14b82fb1e 100644 --- a/wm/test/unittest/window_session_impl_test2.cpp +++ b/wm/test/unittest/window_session_impl_test2.cpp @@ -14,6 +14,7 @@ */ #include "window_session_impl.h" +#include "window_scene_session_impl.h" #include #include @@ -484,6 +485,7 @@ HWTEST_F(WindowSessionImplTest2, HandleEscKeyEvent001, TestSize.Level1) { auto window = GetTestWindowImpl("HandleEscKeyEvent001"); ASSERT_NE(window, nullptr); + ASSERT_NE(window->property_, nullptr); std::shared_ptr keyEvent = MMI::KeyEvent::Create(); ASSERT_NE(keyEvent, nullptr); @@ -498,6 +500,9 @@ HWTEST_F(WindowSessionImplTest2, HandleEscKeyEvent001, TestSize.Level1) EXPECT_EQ(true, keyEvent->HasFlag(MMI::InputEvent::EVENT_FLAG_KEYBOARD_ESCAPE)); WMError result = window->HandleEscKeyEvent(keyEvent, isConsumed); EXPECT_EQ(result, WMError::WM_OK); + + window->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION); + ASSERT_EQ(WMError::WM_DO_NOTHING, window->HandleEscKeyEvent(keyEvent, isConsumed)); window->Destroy(); } @@ -1287,6 +1292,17 @@ HWTEST_F(WindowSessionImplTest2, UpdateDecorEnableToAce, TestSize.Level1) window->windowSystemConfig_.freeMultiWindowSupport_ = false; window->UpdateDecorEnableToAce(false); + sptr option = sptr::MakeSptr(); + option->SetWindowName("UpdateDecorEnableToAce2"); + sptr sceneSseeionWindow = sptr::MakeSptr(option); + sceneSseeionWindow->uiContent_ = std::make_unique(); + sceneSseeionWindow->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + sptr compatibleModeProperty = sptr::MakeSptr(); + ASSERT_NE(compatibleModeProperty, nullptr); + compatibleModeProperty->SetDisableDecorFullscreen(true); + sceneSseeionWindow->property_->SetCompatibleModeProperty(compatibleModeProperty); + sceneSseeionWindow->UpdateDecorEnableToAce(false); + window->uiContent_ = nullptr; window->UpdateDecorEnableToAce(false); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); diff --git a/wm/test/unittest/window_session_impl_test4.cpp b/wm/test/unittest/window_session_impl_test4.cpp index 118a6eb5496c0e0ff2d280fbbb264030b31cd87b..5fc2c8c435d31f587b96194c93cc7edfd7b522a1 100644 --- a/wm/test/unittest/window_session_impl_test4.cpp +++ b/wm/test/unittest/window_session_impl_test4.cpp @@ -486,15 +486,15 @@ HWTEST_F(WindowSessionImplTest4, IsPcWindow, TestSize.Level1) } /** - * @tc.name: IsPadAndNotFreeMutiWindowCompatibleMode - * @tc.desc: IsPadAndNotFreeMutiWindowCompatibleMode + * @tc.name: IsPadAndNotFreeMultiWindowCompatibleMode + * @tc.desc: IsPadAndNotFreeMultiWindowCompatibleMode * @tc.type: FUNC */ -HWTEST_F(WindowSessionImplTest4, IsPadAndNotFreeMutiWindowCompatibleMode, TestSize.Level1) +HWTEST_F(WindowSessionImplTest4, IsPadAndNotFreeMultiWindowCompatibleMode, TestSize.Level1) { - GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPadAndNotFreeMutiWindowCompatibleMode start"; + GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPadAndNotFreeMultiWindowCompatibleMode start"; sptr option = sptr::MakeSptr(); - option->SetWindowName("IsPadAndNotFreeMutiWindowCompatibleMode"); + option->SetWindowName("IsPadAndNotFreeMultiWindowCompatibleMode"); option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); sptr window = sptr::MakeSptr(option); window->property_->SetPersistentId(1); @@ -504,13 +504,13 @@ HWTEST_F(WindowSessionImplTest4, IsPadAndNotFreeMutiWindowCompatibleMode, TestSi window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW; window->property_->SetPcAppInpadCompatibleMode(true); window->windowSystemConfig_.freeMultiWindowEnable_ = false; - EXPECT_EQ(true, window->IsPadAndNotFreeMutiWindowCompatibleMode()); + EXPECT_EQ(true, window->IsPadAndNotFreeMultiWindowCompatibleMode()); window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW; window->property_->SetPcAppInpadCompatibleMode(true); window->windowSystemConfig_.freeMultiWindowEnable_ = true; - window->windowSystemConfig_.isSystemDecorEnable_ = true; - EXPECT_EQ(false, window->IsPadAndNotFreeMutiWindowCompatibleMode()); - GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPadAndNotFreeMutiWindowCompatibleMode end"; + window->windowSystemConfig_.freeMultiWindowSupport_ = true; + EXPECT_EQ(false, window->IsPadAndNotFreeMultiWindowCompatibleMode()); + GTEST_LOG_(INFO) << "WindowSessionImplTest4: IsPadAndNotFreeMultiWindowCompatibleMode end"; } /** diff --git a/wm/test/unittest/window_session_impl_test5.cpp b/wm/test/unittest/window_session_impl_test5.cpp index 7d438515fa19b3b3b688a74b4a1ea54aab00f2cd..b19ea601b10e32096de0fa6eb621ae3f11a4cb1c 100644 --- a/wm/test/unittest/window_session_impl_test5.cpp +++ b/wm/test/unittest/window_session_impl_test5.cpp @@ -1896,37 +1896,6 @@ HWTEST_F(WindowSessionImplTest5, OnPointDown, TestSize.Level1) EXPECT_TRUE(window->OnPointDown(0, 0, 0)); } -/** - * @tc.name: UpdateEnableDragWhenSwitchMultiWindow - * @tc.desc: UpdateEnableDragWhenSwitchMultiWindow - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionImplTest5, UpdateEnableDragWhenSwitchMultiWindow, Function | SmallTest | Level2) -{ - sptr option = sptr::MakeSptr(); - option->SetWindowName("UpdateEnableDragWhenSwitchMultiWindow"); - option->SetWindowType(WindowType::WINDOW_TYPE_MAGNIFICATION); - sptr window = sptr::MakeSptr(option); - window->hasSetEnableDrag_.store(true); - window->UpdateEnableDragWhenSwitchMultiWindow(false); - EXPECT_EQ(true, window->property_->dragEnabled_); - - window->hasSetEnableDrag_.store(false); - window->UpdateEnableDragWhenSwitchMultiWindow(false); - EXPECT_EQ(false, window->property_->dragEnabled_); - - window->property_->type_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW; - sptr property = sptr::MakeSptr(); - property->disableDragResize_ = true; - window->property_->compatibleModeProperty_ = property; - window->UpdateEnableDragWhenSwitchMultiWindow(true); - EXPECT_EQ(false, window->property_->dragEnabled_); - - property->disableDragResize_ = false; - window->UpdateEnableDragWhenSwitchMultiWindow(true); - EXPECT_EQ(true, window->property_->dragEnabled_); -} - /** * @tc.name: SwitchSubWindow * @tc.desc: SwitchSubWindow