diff --git a/previewer/include/window_impl.h b/previewer/include/window_impl.h index 59a39d59f1..917761cc7f 100644 --- a/previewer/include/window_impl.h +++ b/previewer/include/window_impl.h @@ -228,7 +228,7 @@ public: virtual WMError UpdateSystemBarProperty(bool status); private: - static sptr FindWindowById(uint32_t WinId); + static sptr FindWindowById(uint32_t windowId); template using EnableIfSame = typename std::enable_if, Ret>::type; template WMError RegisterListener(std::vector>& holder, const sptr& listener); @@ -274,6 +274,7 @@ private: void NotifySystemBarChange(WindowType type, const SystemBarProperty& property); void NotifySetIgnoreSafeArea(bool value); void NotifyAvoidAreaChange(const sptr& avoidArea, AvoidAreaType type); + static std::mutex globalMutex_; static std::map>> windowMap_; static std::map>> subWindowMap_; static std::map>> systemBarEnableListeners_; @@ -296,8 +297,8 @@ private: bool isIgnoreSafeArea_ = false; uint32_t windowId_ = 0; WindowMode windowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN; - static std::mutex globalMutex_; sptr property_; + mutable std::mutex mutex_; std::unordered_map sysBarPropMap_ { { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty(true, 0x00FFFFFF, 0xFF000000) }, { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty(true, 0x00FFFFFF, 0xFF000000) }, diff --git a/previewer/mock/js_window_listener.h b/previewer/mock/js_window_listener.h index 3c23aecee7..4fb1363a26 100644 --- a/previewer/mock/js_window_listener.h +++ b/previewer/mock/js_window_listener.h @@ -36,7 +36,7 @@ const std::string AVOID_AREA_CHANGE_CB = "avoidAreaChange"; class JsWindowListener : public IAvoidAreaChangedListener { public: JsWindowListener(napi_env env, std::shared_ptr callback) - : env_(env), jsCallBack_(callback), weakRef_(wptr (this)) {} + : env_(env), jsCallBack_(callback), weakRef_(wptr(this)) {} ~JsWindowListener(); void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) override; void CallJsMethod(const char* methodName, napi_value const* argv = nullptr, size_t argc = 0); diff --git a/previewer/src/window_impl.cpp b/previewer/src/window_impl.cpp index f04d1629ed..4a243ea98a 100644 --- a/previewer/src/window_impl.cpp +++ b/previewer/src/window_impl.cpp @@ -79,7 +79,7 @@ const std::shared_ptr WindowImpl::GetContext() const return nullptr; } -sptr WindowImpl::FindWindowById(uint32_t WinId) +sptr WindowImpl::FindWindowById(uint32_t windowId) { std::lock_guard lock(globalMutex_); if (windowMap_.empty()) { @@ -87,8 +87,8 @@ sptr WindowImpl::FindWindowById(uint32_t WinId) return nullptr; } for (auto iter = windowMap_.begin(); iter != windowMap_.end(); iter++) { - if (WinId == iter->second.first) { - WLOGI("FindWindow id: %{public}u", WinId); + if (windowId == iter->second.first) { + WLOGI("FindWindow id: %{public}u", windowId); return iter->second.second; } } @@ -202,6 +202,7 @@ bool WindowImpl::IsMainHandlerAvailable() const SystemBarProperty WindowImpl::GetSystemBarPropertyByType(WindowType type) const { + std::lock_guard lock(mutex_); auto it = sysBarPropMap_.find(type); if (it == sysBarPropMap_.end()) { return SystemBarProperty(false, 0x0, 0x0); @@ -211,7 +212,7 @@ SystemBarProperty WindowImpl::GetSystemBarPropertyByType(WindowType type) const WMError WindowImpl::GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) { - std::lock_guard lock(globalMutex_); + std::lock_guard lock(mutex_); auto avoidAreaPtr = avoidAreaMap_[type]; if (avoidAreaPtr == nullptr) { return WMError::WM_OK; @@ -347,14 +348,17 @@ WMError WindowImpl::SetSystemBarProperty(WindowType type, const SystemBarPropert WMError WindowImpl::SetSpecificBarProperty(WindowType type, const SystemBarProperty& property) { - WLOGI("Window %{public}u type %{public}u enable:%{public}u, bgColor:%{public}x, Color:%{public}x ", + WLOGI("Window %{public}u type %{public}u enable:%{public}u, bgColor:%{public}x, Color:%{public}x", GetWindowId(), static_cast(type), property.enable_, property.backgroundColor_, property.contentColor_); if (GetSystemBarPropertyByType(type) == property) { return WMError::WM_OK; } - sysBarPropMap_[type] = property; + { + std::lock_guard lock(mutex_); + sysBarPropMap_[type] = property; + } NotifySystemBarChange(type, property); UpdateViewportConfig(); return WMError::WM_OK; @@ -829,7 +833,7 @@ void WindowImpl::UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType avoidArea->bottomRect_.height_); { - std::lock_guard lock(globalMutex_); + std::lock_guard lock(mutex_); avoidAreaMap_[type] = avoidArea; } NotifyAvoidAreaChange(avoidArea, type);