!5165 修复ui侧焦点回调多线程问题

Merge pull request !5165 from slarkwayne/remote_uiFocusLock0226
This commit is contained in:
openharmony_ci 2024-03-04 15:17:55 +00:00 committed by Gitee
commit 27ec938705
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 7 additions and 0 deletions

View File

@ -529,6 +529,9 @@ private:
mutable std::shared_mutex propertyMutex_;
sptr<WindowSessionProperty> property_;
mutable std::shared_mutex uiRequestFocusMutex_;
mutable std::shared_mutex uiLostFocusMutex_;
bool showRecent_ = false;
bool bufferAvailable_ = false;
WSRect preRect_;

View File

@ -1829,11 +1829,13 @@ void Session::SetRequestFocusStatusNotifyManagerListener(const NotifyRequestFocu
void Session::SetNotifyUIRequestFocusFunc(const NotifyUIRequestFocusFunc& func)
{
std::unique_lock<std::shared_mutex> lock(uiRequestFocusMutex_);
requestFocusFunc_ = func;
}
void Session::SetNotifyUILostFocusFunc(const NotifyUILostFocusFunc& func)
{
std::unique_lock<std::shared_mutex> lock(uiLostFocusMutex_);
lostFocusFunc_ = func;
}
@ -1930,6 +1932,7 @@ bool Session::GetStateFromManager(const ManagerState key)
void Session::NotifyUIRequestFocus()
{
WLOGFD("NotifyUIRequestFocus id: %{public}d", GetPersistentId());
std::shared_lock<std::shared_mutex> lock(uiRequestFocusMutex_);
if (requestFocusFunc_) {
requestFocusFunc_();
}
@ -1938,6 +1941,7 @@ void Session::NotifyUIRequestFocus()
void Session::NotifyUILostFocus()
{
WLOGFD("NotifyUILostFocus id: %{public}d", GetPersistentId());
std::shared_lock<std::shared_mutex> lock(uiLostFocusMutex_);
if (lostFocusFunc_) {
lostFocusFunc_();
}