From ad1afd1e30ab858004497dc0ab0df6b02a7ef34c Mon Sep 17 00:00:00 2001 From: hfwang0318 Date: Mon, 28 Oct 2024 21:12:32 +0800 Subject: [PATCH] use vsync calc layout state Signed-off-by: hfwang0318 --- utils/include/vsync_station.h | 7 +++ utils/src/vsync_station.cpp | 5 ++ .../js_scene_session_manager.cpp | 56 ++++++++++++------- .../js_scene_session_manager.h | 2 + .../session/host/include/scene_session.h | 34 ++++++++--- .../session/host/src/scene_session.cpp | 44 +++++++++++++-- .../include/scene_session_manager.h | 27 ++++++--- .../src/scene_session_manager.cpp | 27 ++++++++- .../test/unittest/scene_session_test.cpp | 51 +++++++++++++++++ wm/include/root_scene.h | 2 + wm/src/root_scene.cpp | 12 ++++ 11 files changed, 228 insertions(+), 39 deletions(-) diff --git a/utils/include/vsync_station.h b/utils/include/vsync_station.h index c8f6d4325a..2aea71399e 100644 --- a/utils/include/vsync_station.h +++ b/utils/include/vsync_station.h @@ -16,6 +16,7 @@ #ifndef OHOS_VSYNC_STATION_H #define OHOS_VSYNC_STATION_H +#include #include #include @@ -48,6 +49,11 @@ public: void SetFrameRateLinkerEnable(bool enabled); void SetDisplaySoloistFrameRateLinkerEnable(bool enabled); void SetUiDvsyncSwitch(bool dvsyncSwitch); + void OnFlushUIParams(); + uint32_t GetRequestTimes() + { + return requestTimes_.load(); + } private: std::shared_ptr GetOrCreateVsyncReceiver(); @@ -65,6 +71,7 @@ private: bool isFirstVsyncBack_ = true; bool destroyed_ = false; bool hasRequestedVsync_ = false; + std::atomic requestTimes_; std::shared_ptr receiver_ = nullptr; std::shared_ptr frameRateLinker_ = nullptr; using Callbacks = std::unordered_set>; diff --git a/utils/src/vsync_station.cpp b/utils/src/vsync_station.cpp index 49cda79557..752ac1e1f9 100644 --- a/utils/src/vsync_station.cpp +++ b/utils/src/vsync_station.cpp @@ -141,6 +141,7 @@ __attribute__((no_sanitize("cfi"))) void VsyncStation::RequestVsync( vsyncHandler_->PostTask(task, vsyncTimeoutTaskName_, VSYNC_TIME_OUT_MILLISECONDS); } + requestTimes_++; WindowFrameTraceImpl::GetInstance()->VsyncStartFrameTrace(); auto task = [weakThis = weak_from_this()] (int64_t timestamp, int64_t frameCount, void* client) { @@ -263,5 +264,9 @@ void VsyncStation::SetUiDvsyncSwitch(bool dvsyncSwitch) } } +void VsyncStation::OnFlushUIParams() +{ + requestTimes_--; +} } // namespace Rosen } // namespace OHOS 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 8ddf167745..3bdd23e497 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 @@ -562,6 +562,41 @@ void JsSceneSessionManager::ProcessAbilityManagerCollaboratorRegistered() SceneSessionManager::GetInstance().SetAbilityManagerCollaboratorRegisteredFunc(func); } +void JsSceneSessionManager::ProcessSSMCallbackOnRootScene() +{ + RegisterDumpRootSceneElementInfoListener(); + RegisterVirtualPixelRatioChangeListener(); + RootSceneProcessBackEventFunc processBackEventFunc = [this]() { + TLOGD(WmsLogTag::WMS_EVENT, "rootScene BackEvent"); + this->OnRootSceneBackEvent(); + }; + SceneSessionManager::GetInstance().SetRootSceneProcessBackEventFunc(processBackEventFunc); + auto onFlushUIParamsFunc = []() { + RootScene::staticRootScene_->OnFlushUIParams(); + }; + SceneSessionManager::GetInstance().SetOnFlushUIParamsFunc(onFlushUIParamsFunc); + auto getIsLayoutFinishedFunc = []() { + return RootScene::staticRootScene_->IsLayoutFinished(); + }; + SceneSessionManager::GetInstance().SetGetIsLayoutFinishedFunc(getIsLayoutFinishedFunc); +} + +void JsSceneSessionManager::ProcessRootSceneCallbackOnSSM() +{ + rootScene_->SetGetSessionRectCallback([](AvoidAreaType type) { + return SceneSessionManager::GetInstance().GetRootSessionAvoidSessionRect(type); + }); + if (!Session::IsScbCoreEnabled()) { + rootScene_->SetFrameLayoutFinishCallback([]() { + SceneSessionManager::GetInstance().NotifyUpdateRectAfterLayout(); + SceneSessionManager::GetInstance().FlushWindowInfoToMMI(); + }); + } + RootScene::SetOnConfigurationUpdatedCallback([](const std::shared_ptr& configuration) { + SceneSessionManager::GetInstance().OnConfigurationUpdated(configuration); + }); +} + napi_value JsSceneSessionManager::RegisterCallback(napi_env env, napi_callback_info info) { WLOGFD("[NAPI]"); @@ -1463,31 +1498,14 @@ napi_value JsSceneSessionManager::OnGetRootSceneSession(napi_env env, napi_callb rootScene_ = sptr::MakeSptr(); } RootScene::staticRootScene_ = rootScene_; - RegisterDumpRootSceneElementInfoListener(); - RegisterVirtualPixelRatioChangeListener(); rootSceneSession->SetLoadContentFunc([rootScene = rootScene_] (const std::string& contentUrl, napi_env env, napi_value storage, AbilityRuntime::Context* context) { rootScene->LoadContent(contentUrl, env, storage, context); ScenePersistentStorage::InitDir(context->GetPreferencesDir()); SceneSessionManager::GetInstance().InitPersistentStorage(); }); - rootScene_->SetGetSessionRectCallback([](AvoidAreaType type) { - return SceneSessionManager::GetInstance().GetRootSessionAvoidSessionRect(type); - }); - if (!Session::IsScbCoreEnabled()) { - rootScene_->SetFrameLayoutFinishCallback([]() { - SceneSessionManager::GetInstance().NotifyUpdateRectAfterLayout(); - SceneSessionManager::GetInstance().FlushWindowInfoToMMI(); - }); - } - RootSceneProcessBackEventFunc processBackEventFunc = [this]() { - TLOGD(WmsLogTag::WMS_EVENT, "rootScene BackEvent"); - this->OnRootSceneBackEvent(); - }; - SceneSessionManager::GetInstance().SetRootSceneProcessBackEventFunc(processBackEventFunc); - RootScene::SetOnConfigurationUpdatedCallback([](const std::shared_ptr& configuration) { - SceneSessionManager::GetInstance().OnConfigurationUpdated(configuration); - }); + ProcessSSMCallbackOnRootScene(); + ProcessRootSceneCallbackOnSSM(); napi_value jsRootSceneSessionObj = JsRootSceneSession::Create(env, rootSceneSession); if (jsRootSceneSessionObj == nullptr) { WLOGFE("[NAPI]jsRootSceneSessionObj is nullptr"); 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 1b9776d35d..d308e1e775 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 @@ -221,6 +221,8 @@ private: std::shared_ptr GetJSCallback(const std::string& functionName); void ProcessAbilityManagerCollaboratorRegistered(); void OnAbilityManagerCollaboratorRegistered(); + void ProcessSSMCallbackOnRootScene(); + void ProcessRootSceneCallbackOnSSM(); napi_env env_; std::shared_mutex jsCbMapMutex_; diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index 01f1fb9575..628b0763fb 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -90,6 +90,7 @@ using NotifyMainWindowTopmostChangeFunc = std::function; using NotifyPrivacyModeChangeFunc = std::function; using UpdateGestureBackEnabledCallback = std::function; using NotifyVisibleChangeFunc = std::function; +using GetIsLayoutFinishedFunc = std::function; class SceneSession : public Session { public: @@ -283,11 +284,13 @@ public: WSError GetAllAvoidAreas(std::map& avoidAreas) override; WSError SetSystemBarProperty(WindowType type, SystemBarProperty systemBarProperty); void SetIsStatusBarVisible(bool isVisible); + WSError SetIsStatusBarVisibleTask(bool isVisible); WSError UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type) override; void UpdateRotationAvoidArea(); bool CheckGetAvoidAreaAvailable(AvoidAreaType type) override; bool GetIsDisplayStatusBarTemporarily() const; void SetIsDisplayStatusBarTemporarily(bool isTemporary); + void SetGetIsLayoutFinishedFunc(GetIsLayoutFinishedFunc&& getIsLayoutFinishedFunc); void SetAbilitySessionInfo(std::shared_ptr abilityInfo); void SetWindowDragHotAreaListener(const NotifyWindowDragHotAreaFunc& func); @@ -513,6 +516,10 @@ protected: bool NotifyServerToUpdateRect(const SessionUIParam& uiParam, SizeChangeReason reason); bool UpdateScaleInner(float scaleX, float scaleY, float pivotX, float pivotY); bool UpdateZOrderInner(uint32_t zOrder); + + /** + * Window Immersive + */ virtual void NotifyClientToUpdateAvoidArea(); bool PipelineNeedNotifyClientToUpdateAvoidArea(uint32_t dirty) const; @@ -527,6 +534,10 @@ protected: sptr keyboardSession_ = nullptr; NotifyKeyboardGravityChangeFunc keyboardGravityChangeFunc_; NotifyKeyboardLayoutAdjustFunc adjustKeyboardLayoutFunc_; + + /** + * Window Immersive + */ NotifySystemBarPropertyChangeFunc onSystemBarPropertyChange_; /* @@ -536,15 +547,19 @@ protected: private: void NotifyAccessibilityVisibilityChange(); - void CalculateAvoidAreaRect(WSRect& rect, WSRect& avoidRect, AvoidArea& avoidArea) const; - void GetSystemAvoidArea(WSRect& rect, AvoidArea& avoidArea); - void GetCutoutAvoidArea(WSRect& rect, AvoidArea& avoidArea); - void GetKeyboardAvoidArea(WSRect& rect, AvoidArea& avoidArea); void CalculateCombinedExtWindowFlags(); - void GetAINavigationBarArea(WSRect rect, AvoidArea& avoidArea) const; void HandleStyleEvent(MMI::WindowArea area) override; WSError HandleEnterWinwdowArea(int32_t windowX, int32_t windowY); + /** + * Window Immersive + */ + void CalculateAvoidAreaRect(WSRect &rect, WSRect &avoidRect, AvoidArea &avoidArea) const; + void GetSystemAvoidArea(WSRect &rect, AvoidArea &avoidArea); + void GetCutoutAvoidArea(WSRect &rect, AvoidArea &avoidArea); + void GetKeyboardAvoidArea(WSRect &rect, AvoidArea &avoidArea); + void GetAINavigationBarArea(WSRect rect, AvoidArea &avoidArea) const; + /* * Window Lifecycle */ @@ -676,7 +691,6 @@ private: SessionEventParam sessionEventParam_ = { 0, 0, 0, 0 }; std::atomic_bool isStartMoving_ { false }; std::atomic_bool isVisibleForAccessibility_ { true }; - std::atomic_bool isDisplayStatusBarTemporarily_ { false }; bool isSystemSpecificSession_ { false }; std::atomic_bool shouldHideNonSecureWindows_ { false }; std::shared_mutex combinedExtWindowFlagsMutex_; @@ -704,7 +718,6 @@ private: bool isScreenAngleMismatch_ = false; uint32_t targetScreenWidth_ = 0; uint32_t targetScreenHeight_ = 0; - bool isStatusBarVisible_ = true; // WMSPipeline-related: only accessed on SSM thread PostProcessFocusState postProcessFocusState_; @@ -740,6 +753,13 @@ private: * Window Visibility */ NotifyVisibleChangeFunc notifyVisibleChangeFunc_; + + /** + * Window Immersive + */ + std::atomic_bool isDisplayStatusBarTemporarily_ { false }; + bool isStatusBarVisible_ = true; + GetIsLayoutFinishedFunc getIsLayoutFinishedFunc_; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 916db66499..2245e3a800 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -1305,14 +1305,45 @@ WSError SceneSession::SetSystemBarProperty(WindowType type, SystemBarProperty sy } void SceneSession::SetIsStatusBarVisible(bool isVisible) +{ + auto task = [weakThis = wptr(this), isVisible]() { + sptr self = weakThis.promote(); + if (self == nullptr) { + TLOGNE(WmsLogTag::WMS_IMMS, "session is null"); + return; + } + self->SetIsStatusBarVisibleTask(isVisible); + }; + PostTask(task, __func__); +} + +WSError SceneSession::SetIsStatusBarVisibleTask(bool isVisible) { bool isNeedNotify = isStatusBarVisible_ != isVisible; - TLOGI(WmsLogTag::WMS_IMMS, "Window [%{public}d, %{public}s] status bar visible %{public}u, need notify %{public}u", - GetPersistentId(), GetWindowName().c_str(), isVisible, isNeedNotify); + TLOGI(WmsLogTag::WMS_IMMS, "Window [%{public}d, %{public}s] status bar visible %{public}u, " + "need notify %{public}u", GetPersistentId(), GetWindowName().c_str(), isVisible, isNeedNotify); isStatusBarVisible_ = isVisible; - if (isNeedNotify && specificCallback_ && specificCallback_->onUpdateAvoidAreaByType_) { - specificCallback_->onUpdateAvoidAreaByType_(GetPersistentId(), AvoidAreaType::TYPE_SYSTEM); + if (!isNeedNotify) { + return WSError::WS_OK; } + if (getIsLayoutFinishedFunc_ == nullptr) { + TLOGE(WmsLogTag::WMS_IMMS, "getIsLayoutFinishedFunc_ is null, id: %{public}d", GetPersistentId()); + return WSError::WS_ERROR_NULLPTR; + } + bool isLayoutFinished = false; + WSError ret = getIsLayoutFinishedFunc_(isLayoutFinished); + if (ret != WSError::WS_OK) { + TLOGE(WmsLogTag::WMS_IMMS, "getIsLayoutFinishedFunc_ failed: %{public}d", ret); + return ret; + } + if (isLayoutFinished) { + if (specificCallback_ && specificCallback_->onUpdateAvoidAreaByType_) { + specificCallback_->onUpdateAvoidAreaByType_(GetPersistentId(), AvoidAreaType::TYPE_SYSTEM); + } + } else { + dirtyFlags_ |= static_cast(SessionUIDirtyFlag::AVOID_AREA); + } + return WSError::WS_OK; } void SceneSession::NotifyPropertyWhenConnect() @@ -4663,6 +4694,11 @@ bool SceneSession::GetIsDisplayStatusBarTemporarily() const return isDisplayStatusBarTemporarily_.load(); } +void SceneSession::SetGetIsLayoutFinishedFunc(GetIsLayoutFinishedFunc&& getIsLayoutFinishedFunc) +{ + getIsLayoutFinishedFunc_ = std::move(getIsLayoutFinishedFunc); +} + void SceneSession::SetStartingWindowExitAnimationFlag(bool enable) { TLOGI(WmsLogTag::DEFAULT, "SetStartingWindowExitAnimationFlag %{public}d", enable); diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index e86d0b778f..bb9a1a2250 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -117,6 +117,8 @@ using DumpUITreeFunc = std::function; using RootSceneProcessBackEventFunc = std::function; using ProcessCloseTargetFloatWindowFunc = std::function; using AbilityManagerCollaboratorRegisteredFunc = std::function; +using OnFlushUIParamsFunc = std::function; +using GetIsLayoutFinishedOnRootSceneFunc = std::function; class AppAnrListener : public IRemoteStub { public: @@ -279,11 +281,9 @@ public: WSError GetBatchAbilityInfos(const std::vector& bundleNames, int32_t userId, std::vector& scbAbilityInfos); WSError PrepareTerminate(int32_t persistentId, bool& isPrepareTerminate); - WSError GetIsLayoutFullScreen(bool& isLayoutFullScreen); WSError TerminateSessionNew( const sptr info, bool needStartCaller, bool isFromBroker = false) override; - WSError UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener) override; WSError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener) override; WSError GetSessionSnapshot(const std::string& deviceId, int32_t persistentId, SessionSnapshot& snapshot, bool isLowResolution) override; @@ -364,10 +364,15 @@ public: /* * Window Immersive */ + WSError GetIsLayoutFullScreen(bool &isLayoutFullScreen); + WSError UpdateSessionAvoidAreaListener(int32_t &persistentId, bool haveListener) override; bool GetImmersiveState(ScreenId screenId); WSError NotifyStatusBarShowStatus(int32_t persistentId, bool isVisible); WSError NotifyAINavigationBarShowStatus(bool isVisible, WSRect barArea, uint64_t displayId); WSRect GetAINavigationBarArea(uint64_t displayId); + void ClearDisplayStatusBarTemporarilyFlags(); + void SetOnFlushUIParamsFunc(OnFlushUIParamsFunc&& func); + void SetGetIsLayoutFinishedFunc(GetIsLayoutFinishedOnRootSceneFunc&& func); WSError NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible) override; void DealwithVisibilityChange(const std::vector>& visibilityChangeInfos, @@ -416,7 +421,6 @@ public: WSError SwitchFreeMultiWindow(bool enable); WSError GetFreeMultiWindowEnableState(bool& enable) override; const SystemSessionConfig& GetSystemSessionConfig() const; - void ClearDisplayStatusBarTemporarilyFlags(); WSError NotifyEnterRecentTask(bool enterRecent); WMError GetMainWindowInfos(int32_t topNum, std::vector& topNInfo); WMError GetAllMainWindowInfos(std::vector& infos) const; @@ -614,6 +618,9 @@ private: void UpdateNormalSessionAvoidArea(const int32_t& persistentId, sptr& sceneSession, bool& needUpdate); void UpdateAvoidArea(int32_t persistentId); void UpdateAvoidAreaByType(int32_t persistentId, AvoidAreaType type); + WSError IsLayoutFinished(bool& isLayoutFinished); + void HandleSpecificSystemBarProperty(WindowType type, const sptr &property, + const sptr &sceneSession); sptr GetBundleManager(); std::shared_ptr GetResourceManager(const AppExecFwk::AbilityInfo& abilityInfo); @@ -636,8 +643,6 @@ private: WSError UpdateBrightness(int32_t persistentId); void SetDisplayBrightness(float brightness); float GetDisplayBrightness() const; - void HandleSpecificSystemBarProperty(WindowType type, const sptr& property, - const sptr& sceneSession); void HandleHideNonSystemFloatingWindows(const sptr& property, const sptr& sceneSession); void UpdateForceHideState(const sptr& sceneSession, const sptr& property, @@ -795,9 +800,6 @@ private: std::mutex privacyBundleMapMutex_; std::unordered_map> privacyBundleMap_; - bool isAINavigationBarVisible_ = false; - std::shared_mutex currAINavigationBarAreaMapMutex_; - std::map currAINavigationBarAreaMap_; WindowModeType lastWindowModeType_ { WindowModeType::WINDOW_MODE_OTHER }; // Multi User @@ -975,6 +977,15 @@ private: */ bool IsInSecondaryScreen(const sptr& sceneSession); + /** + * Window Immersive + */ + OnFlushUIParamsFunc onFlushUIParamsFunc_; + GetIsLayoutFinishedOnRootSceneFunc getIsLayoutFinishedOnRootSceneFunc_; + bool isAINavigationBarVisible_ = false; + std::shared_mutex currAINavigationBarAreaMapMutex_; + std::map currAINavigationBarAreaMap_; + struct SessionInfoList { int32_t uid_; std::string bundleName_; diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 9a2eaeb71c..1f0a3c8d25 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -1215,7 +1215,7 @@ WSRect SceneSessionManager::GetRootSessionAvoidSessionRect(AvoidAreaType type) const WSRect rect = session->GetSessionRect(); TLOGI(WmsLogTag::WMS_IMMS, "type: %{public}u, rect: %{public}s", type, rect.ToString().c_str()); return rect; - } +} return {}; } @@ -1526,6 +1526,9 @@ sptr SceneSessionManager::CreateSceneSession(const SessionInfo& se if (sceneSession->moveDragController_) { sceneSession->moveDragController_->SetIsPcWindow(systemConfig_.IsPcWindow()); } + sceneSession->SetGetIsLayoutFinishedFunc([this](bool& isLayoutFinished) { + return this->IsLayoutFinished(isLayoutFinished); + }); } return sceneSession; } @@ -4542,6 +4545,16 @@ void SceneSessionManager::SetDumpUITreeFunc(const DumpUITreeFunc& func) dumpUITreeFunc_ = func; } +void SceneSessionManager::SetOnFlushUIParamsFunc(OnFlushUIParamsFunc&& func) +{ + onFlushUIParamsFunc_ = std::move(func); +} + +void SceneSessionManager::SetGetIsLayoutFinishedFunc(GetIsLayoutFinishedOnRootSceneFunc&& func) +{ + getIsLayoutFinishedOnRootSceneFunc_ = std::move(func); +} + void FocusIDChange(int32_t persistentId, sptr& sceneSession) { // notify RS @@ -9194,6 +9207,9 @@ void SceneSessionManager::FlushUIParams(ScreenId screenId, std::unordered_map& return taskScheduler_->PostSyncTask(task, "GetDisplayIdByWindowId"); } +WSError SceneSessionManager::IsLayoutFinished(bool& isLayoutFinished) +{ + if (getIsLayoutFinishedOnRootSceneFunc_ == nullptr) { + TLOGE(WmsLogTag::WMS_IMMS, "getIsLayoutFinishedOnRootSceneFunc_ is null"); + return WSError::WS_ERROR_NULLPTR; + } + isLayoutFinished = getIsLayoutFinishedOnRootSceneFunc_(); + return WSError::WS_OK; +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/test/unittest/scene_session_test.cpp b/window_scene/test/unittest/scene_session_test.cpp index 47bb7d0b45..afb1a2b884 100644 --- a/window_scene/test/unittest/scene_session_test.cpp +++ b/window_scene/test/unittest/scene_session_test.cpp @@ -2173,6 +2173,57 @@ HWTEST_F(SceneSessionTest, SetSessionGlobalRect, Function | SmallTest | Level2) sceneSession->SetScbCoreEnabled(true); EXPECT_EQ(test, sceneSession->GetSessionGlobalRect()); } + +/** + * @tc.name: SetSessionGlobalRect/GetSessionGlobalRect + * @tc.desc: SetSessionGlobalRect + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest, SetIsStatusBarVisibleTask01, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "SetIsStatusBarVisibleTask01"; + info.bundleName_ = "SetIsStatusBarVisibleTask01"; + info.windowType_ = 1; + sptr session_; + sptr specificCallback_ = + sptr::MakeSptr(); + EXPECT_NE(specificCallback_, nullptr); + sptr sceneSession = sptr::MakeSptr(info, specificCallback_); + EXPECT_NE(sceneSession, nullptr); + sceneSession->isStatusBarVisible_ = true; + EXPECT_EQ(sceneSession->SetIsStatusBarVisibleTask(true), WSError::WS_OK); + EXPECT_EQ(sceneSession->SetIsStatusBarVisibleTask(false), WSError::WS_ERROR_NULLPTR); + + sceneSession->getIsLayoutFinishedFunc_ = [](bool& isLayoutFinished) { + return WSError::WS_ERROR_NULLPTR; + }; + sceneSession->isStatusBarVisible_ = true; + EXPECT_EQ(sceneSession->SetIsStatusBarVisibleTask(false), WSError::WS_ERROR_NULLPTR); + + sceneSession->getIsLayoutFinishedFunc_ = [](bool& isLayoutFinished) { + isLayoutFinished = false; + return WSError::WS_OK; + }; + sceneSession->isStatusBarVisible_ = true; + EXPECT_EQ(sceneSession->SetIsStatusBarVisibleTask(false), WSError::WS_OK); + + sceneSession->getIsLayoutFinishedFunc_ = [](bool& isLayoutFinished) { + isLayoutFinished = true; + return WSError::WS_OK; + } + sceneSession->isStatusBarVisible_ = true; + sceneSession->specificCallback_->onUpdateAvoidAreaByType_ = [](int32_t persistentId, AvoidAreaType type) { }; + EXPECT_EQ(sceneSession->SetIsStatusBarVisibleTask(false), WSError::WS_OK); + + sceneSession->specificCallback_ = nullptr; + sceneSession->isStatusBarVisible_ = true; + EXPECT_EQ(sceneSession->SetIsStatusBarVisibleTask(false), WSError::WS_OK); + + sceneSession->getIsLayoutFinishedFunc = nullptr; + sceneSession->isStatusBarVisible_ = true; + EXPECT_EQ(sceneSession->SetIsStatusBarVisibleTask(false), WSError::WS_OK); +} } // namespace } // Rosen } // OHOS \ No newline at end of file diff --git a/wm/include/root_scene.h b/wm/include/root_scene.h index 3c888f903d..68902ed14b 100644 --- a/wm/include/root_scene.h +++ b/wm/include/root_scene.h @@ -51,6 +51,8 @@ public: void RequestVsync(const std::shared_ptr& vsyncCallback) override; int64_t GetVSyncPeriod() override; void FlushFrameRate(uint32_t rate, int32_t animatorExpectedFrameRate, uint32_t rateType = 0) override; + bool IsLayoutFinished(); + bool OnFlushUIParams(); void OnBundleUpdated(const std::string& bundleName); static void SetOnConfigurationUpdatedCallback( diff --git a/wm/src/root_scene.cpp b/wm/src/root_scene.cpp index 77fc862df8..8ae4b91214 100644 --- a/wm/src/root_scene.cpp +++ b/wm/src/root_scene.cpp @@ -184,6 +184,18 @@ void RootScene::FlushFrameRate(uint32_t rate, int32_t animatorExpectedFrameRate, vsyncStation_->FlushFrameRate(rate, animatorExpectedFrameRate, rateType); } +bool RootScene::IsLayoutFinished() +{ + uint32_t requestTimes = vsyncStation_->GetRequestTimes(); + WLOGI("RootScene vsync request times: %{public}d", requestTimes); + return requestTimes == 0; +} + +void RootScene::OnFlushUIParams() +{ + vsyncStation_->OnFlushUIParams(); +} + void RootScene::OnBundleUpdated(const std::string& bundleName) { WLOGFD("bundle %{public}s updated", bundleName.c_str());