diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index a6424554ae4d04e92fb6ba7bea10852595552e63..808653ec89177315b60c576d7eb7f2b1aacd7b19 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -81,6 +81,8 @@ constexpr int32_t UI_HALF = 2; const std::string NOTIFICATION_ANS_CHECK_SA_PERMISSION = "notification.ans.check.sa.permission"; +std::atomic dialogManagerInit(false); + } // namespace sptr AdvancedNotificationService::instance_; @@ -1571,14 +1573,29 @@ void AdvancedNotificationService::TriggerAutoDelete(const std::string &hashCode, bool AdvancedNotificationService::CreateDialogManager() { - static std::mutex dialogManagerMutex_; - std::lock_guard lock(dialogManagerMutex_); - if (dialogManager_ == nullptr) { - dialogManager_ = std::make_unique(*this); - if (!dialogManager_->Init()) { - dialogManager_ = nullptr; - return false; + ANS_LOGD("Enter"); + { + static std::mutex dialogManagerMutex_; + std::lock_guard lock(dialogManagerMutex_); + if (dialogManager_ == nullptr) { + ANS_LOGI("create dialogManagerMutex_"); + dialogManager_ = std::make_unique(*this); + } + } + if (dialogManager_ != nullptr) { + if (!dialogManagerInit.load()) { + ANS_LOGI("dialogManager_ Init"); + dialogManagerInit.store(true); + if (!dialogManager_->Init()) { + dialogManager_ = nullptr; + dialogManagerInit.store(false); + return false; + } else { + ANS_LOGI("dialogManager_ Init success"); + } } + } else { + ANS_LOGW("dialogManagerMutex_ is nullptr"); } return true; }