mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-27 00:51:35 +00:00
fix: half display
Signed-off-by: xuedong <xuedong@huawei.com>
This commit is contained in:
commit
cb0bf418fa
@ -47,6 +47,8 @@ public:
|
||||
DMError UnregisterFoldStatusListener(sptr<IFoldStatusListener> listener);
|
||||
DMError RegisterDisplayModeListener(sptr<IDisplayModeListener> listener);
|
||||
DMError UnregisterDisplayModeListener(sptr<IDisplayModeListener> listener);
|
||||
DMError RegisterScreenMagneticStateListener(sptr<IScreenMagneticStateListener> listener);
|
||||
DMError UnregisterScreenMagneticStateListener(sptr<IScreenMagneticStateListener> listener);
|
||||
void OnRemoteDied();
|
||||
sptr<DisplayLite> GetDisplayById(DisplayId displayId);
|
||||
/*
|
||||
@ -84,6 +86,10 @@ private:
|
||||
*/
|
||||
class DisplayManagerAgent;
|
||||
sptr<DisplayManagerAgent> displayStateAgent_;
|
||||
void NotifyScreenMagneticStateChanged(bool isMagneticState);
|
||||
std::set<sptr<IScreenMagneticStateListener>> screenMagneticStateListeners_;
|
||||
class DisplayManagerScreenMagneticStateAgent;
|
||||
sptr<DisplayManagerScreenMagneticStateAgent> screenMagneticStateListenerAgent_;
|
||||
};
|
||||
|
||||
class DisplayManagerLite::Impl::DisplayManagerListener : public DisplayManagerAgentDefault {
|
||||
@ -185,6 +191,21 @@ private:
|
||||
sptr<Impl> pImpl_;
|
||||
};
|
||||
|
||||
class DisplayManagerLite::Impl::DisplayManagerScreenMagneticStateAgent : public DisplayManagerAgentDefault {
|
||||
public:
|
||||
explicit DisplayManagerScreenMagneticStateAgent(sptr<Impl> impl) : pImpl_(impl)
|
||||
{
|
||||
}
|
||||
~DisplayManagerScreenMagneticStateAgent() = default;
|
||||
|
||||
virtual void NotifyScreenMagneticStateChanged(bool isMagneticState) override
|
||||
{
|
||||
pImpl_->NotifyScreenMagneticStateChanged(isMagneticState);
|
||||
}
|
||||
private:
|
||||
sptr<Impl> pImpl_;
|
||||
};
|
||||
|
||||
/*
|
||||
* used by powermgr
|
||||
*/
|
||||
@ -672,6 +693,75 @@ void DisplayManagerLite::Impl::ClearDisplayStateCallback()
|
||||
}
|
||||
}
|
||||
|
||||
DMError DisplayManagerLite::RegisterScreenMagneticStateListener(sptr<IScreenMagneticStateListener> listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
WLOGFE("IScreenMagneticStateListener listener is nullptr.");
|
||||
return DMError::DM_ERROR_NULLPTR;
|
||||
}
|
||||
return pImpl_->RegisterScreenMagneticStateListener(listener);
|
||||
}
|
||||
|
||||
DMError DisplayManagerLite::Impl::RegisterScreenMagneticStateListener(sptr<IScreenMagneticStateListener> listener)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
DMError ret = DMError::DM_OK;
|
||||
if (screenMagneticStateListenerAgent_ == nullptr) {
|
||||
screenMagneticStateListenerAgent_ = new DisplayManagerScreenMagneticStateAgent(this);
|
||||
ret = SingletonContainer::Get<DisplayManagerAdapterLite>().RegisterDisplayManagerAgent(
|
||||
screenMagneticStateListenerAgent_,
|
||||
DisplayManagerAgentType::SCREEN_MAGNETIC_STATE_CHANGED_LISTENER);
|
||||
}
|
||||
if (ret != DMError::DM_OK) {
|
||||
WLOGFW("RegisterScreenMagneticStateListener failed !");
|
||||
screenMagneticStateListenerAgent_ = nullptr;
|
||||
} else {
|
||||
WLOGD("IScreenMagneticStateListener register success");
|
||||
screenMagneticStateListeners_.insert(listener);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
DMError DisplayManagerLite::UnregisterScreenMagneticStateListener(sptr<IScreenMagneticStateListener> listener)
|
||||
{
|
||||
if (listener == nullptr) {
|
||||
WLOGFE("UnregisterScreenMagneticStateListener listener is nullptr.");
|
||||
return DMError::DM_ERROR_NULLPTR;
|
||||
}
|
||||
return pImpl_->UnregisterScreenMagneticStateListener(listener);
|
||||
}
|
||||
|
||||
DMError DisplayManagerLite::Impl::UnregisterScreenMagneticStateListener(sptr<IScreenMagneticStateListener> listener)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
auto iter = std::find(screenMagneticStateListeners_.begin(), screenMagneticStateListeners_.end(), listener);
|
||||
if (iter == screenMagneticStateListeners_.end()) {
|
||||
WLOGFE("could not find this listener");
|
||||
return DMError::DM_ERROR_NULLPTR;
|
||||
}
|
||||
screenMagneticStateListeners_.erase(iter);
|
||||
DMError ret = DMError::DM_OK;
|
||||
if (screenMagneticStateListeners_.empty() && screenMagneticStateListenerAgent_ != nullptr) {
|
||||
ret = SingletonContainer::Get<DisplayManagerAdapterLite>().UnregisterDisplayManagerAgent(
|
||||
screenMagneticStateListenerAgent_,
|
||||
DisplayManagerAgentType::SCREEN_MAGNETIC_STATE_CHANGED_LISTENER);
|
||||
screenMagneticStateListenerAgent_ = nullptr;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void DisplayManagerLite::Impl::NotifyScreenMagneticStateChanged(bool isMagneticState)
|
||||
{
|
||||
std::set<sptr<IScreenMagneticStateListener>> screenMagneticStateListeners;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
screenMagneticStateListeners = screenMagneticStateListeners_;
|
||||
}
|
||||
for (auto& listener : screenMagneticStateListeners) {
|
||||
listener->OnScreenMagneticStateChanged(isMagneticState);
|
||||
}
|
||||
}
|
||||
|
||||
bool DisplayManagerLite::TryToCancelScreenOff()
|
||||
{
|
||||
WLOGFD("[UL_POWER]TryToCancelScreenOff start");
|
||||
|
@ -661,6 +661,70 @@ HWTEST_F(DisplayManagerTest, GetVirtualScreenFlag, Function | SmallTest | Level1
|
||||
ASSERT_EQ(ret, VirtualScreenFlag::DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RegisterScreenMagneticStateListener
|
||||
* @tc.desc: RegisterScreenMagneticStateListener fun
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayManagerTest, RegisterScreenMagneticStateListener, Function | SmallTest | Level1)
|
||||
{
|
||||
sptr<DisplayManagerLite::IScreenMagneticStateListener> listener;
|
||||
auto ret = DisplayManagerLite::GetInstance().RegisterScreenMagneticStateListener(listener);
|
||||
ASSERT_EQ(ret, DMError::DM_ERROR_NULLPTR);
|
||||
listener = new DisplayManagerLite::IScreenMagneticStateListener();
|
||||
ret = DisplayManagerLite::GetInstance().RegisterScreenMagneticStateListener(listener);
|
||||
ASSERT_EQ(ret, DisplayManagerLite::GetInstance().pImpl_->RegisterScreenMagneticStateListener(listener));
|
||||
listener.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ImplRegisterScreenMagneticStateListener
|
||||
* @tc.desc: ImplRegisterScreenMagneticStateListener fun
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayManagerTest, ImplRegisterScreenMagneticStateListener, Function | SmallTest | Level1)
|
||||
{
|
||||
sptr<DisplayManagerLite::IScreenMagneticStateListener> listener;
|
||||
DisplayManagerLite::GetInstance().pImpl_->screenMagneticStateListenerAgent_ = nullptr;
|
||||
sptr<DisplayManagerLite::Impl> impl_;
|
||||
sptr<DisplayManagerLite::Impl::DisplayManagerScreenMagneticStateAgent> screenMagneticStateListenerAgent =
|
||||
new DisplayManagerLite::Impl::DisplayManagerScreenMagneticStateAgent(impl_);
|
||||
auto ret = DisplayManagerLite::GetInstance().pImpl_->RegisterScreenMagneticStateListener(listener);
|
||||
ASSERT_EQ(ret, SingletonContainer::Get<DisplayManagerAdapterLite>().RegisterDisplayManagerAgent(
|
||||
screenMagneticStateListenerAgent,
|
||||
DisplayManagerAgentType::SCREEN_MAGNETIC_STATE_CHANGED_LISTENER));
|
||||
listener.clear();
|
||||
screenMagneticStateListenerAgent.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UnregisterScreenMagneticStateListener
|
||||
* @tc.desc: UnregisterScreenMagneticStateListener fun
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayManagerTest, UnregisterScreenMagneticStateListener, Function | SmallTest | Level1)
|
||||
{
|
||||
sptr<DisplayManagerLite::IScreenMagneticStateListener> listener;
|
||||
auto ret = DisplayManagerLite::GetInstance().UnregisterScreenMagneticStateListener(listener);
|
||||
ASSERT_EQ(ret, DMError::DM_ERROR_NULLPTR);
|
||||
listener = new DisplayManagerLite::IScreenMagneticStateListener();
|
||||
ret = DisplayManagerLite::GetInstance().UnregisterScreenMagneticStateListener(listener);
|
||||
ASSERT_EQ(ret, DisplayManagerLite::GetInstance().pImpl_->UnregisterScreenMagneticStateListener(listener));
|
||||
listener.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ImplUnregisterScreenMagneticStateListener
|
||||
* @tc.desc: ImplUnregisterScreenMagneticStateListener fun
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayManagerTest, ImplUnregisterScreenMagneticStateListener, Function | SmallTest | Level1)
|
||||
{
|
||||
sptr<DisplayManagerLite::IScreenMagneticStateListener> listener;
|
||||
auto ret = DisplayManagerLite::GetInstance().pImpl_->UnregisterScreenMagneticStateListener(listener);
|
||||
ASSERT_EQ(ret, DMError::DM_OK);
|
||||
listener.clear();
|
||||
}
|
||||
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -67,6 +67,16 @@ public:
|
||||
virtual void OnDisplayModeChanged([[maybe_unused]]FoldDisplayMode displayMode) {}
|
||||
};
|
||||
|
||||
class IScreenMagneticStateListener : public virtual RefBase {
|
||||
public:
|
||||
/**
|
||||
* @brief Notify listeners when screen magnetic state changed.
|
||||
*
|
||||
* @param screenMagneticState ScreenMagneticState.
|
||||
*/
|
||||
virtual void OnScreenMagneticStateChanged([[maybe_unused]]bool isMagneticState) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Register a display listener.
|
||||
*
|
||||
@ -115,6 +125,22 @@ public:
|
||||
*/
|
||||
DMError UnregisterDisplayModeListener(sptr<IDisplayModeListener> listener);
|
||||
|
||||
/**
|
||||
* @brief Register a listener for the event of screen magnetic state changed.
|
||||
*
|
||||
* @param listener IScreenMagneticStateListener.
|
||||
* @return DM_OK means register success, others means register failed.
|
||||
*/
|
||||
DMError RegisterScreenMagneticStateListener(sptr<IScreenMagneticStateListener> listener);
|
||||
|
||||
/**
|
||||
* @brief Unregister an existed listener for the event of screen magnetic state changed.
|
||||
*
|
||||
* @param listener IScreenMagneticStateListener.
|
||||
* @return DM_OK means unregister success, others means unregister failed.
|
||||
*/
|
||||
DMError UnregisterScreenMagneticStateListener(sptr<IScreenMagneticStateListener> listener);
|
||||
|
||||
/**
|
||||
* @brief Get the default display object.
|
||||
*
|
||||
@ -225,7 +251,7 @@ public:
|
||||
* @return State of display.
|
||||
*/
|
||||
DisplayState GetDisplayState(DisplayId displayId);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Try to cancel screenoff action before display power off.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user