diff --git a/flutter/shell/platform/tizen/channels/app_control.h b/flutter/shell/platform/tizen/channels/app_control.h index c15fb90..2bf79e4 100644 --- a/flutter/shell/platform/tizen/channels/app_control.h +++ b/flutter/shell/platform/tizen/channels/app_control.h @@ -120,8 +120,13 @@ class AppControlManager { return instance; } - void Insert(std::unique_ptr app_control) { - map_.insert({app_control->id(), std::move(app_control)}); + // Returns a pointer to the inserted element if successful, otherwise nullptr. + AppControl* Insert(std::unique_ptr app_control) { + auto iter = map_.emplace(app_control->id(), std::move(app_control)); + if (iter.second) { + return iter.first->second.get(); + } + return nullptr; } void Remove(int32_t id) { map_.erase(id); } diff --git a/flutter/shell/platform/tizen/channels/app_control_channel.cc b/flutter/shell/platform/tizen/channels/app_control_channel.cc index e3ce744..058b739 100644 --- a/flutter/shell/platform/tizen/channels/app_control_channel.cc +++ b/flutter/shell/platform/tizen/channels/app_control_channel.cc @@ -58,13 +58,18 @@ void AppControlChannel::NotifyAppControl(void* handle) { FT_LOG(Error) << "Could not create an instance of AppControl."; return; } + AppControl* app_control_ptr = + AppControlManager::GetInstance().Insert(std::move(app_control)); + if (!app_control_ptr) { + FT_LOG(Error) << "The handle already exists."; + return; + } if (event_sink_) { - SendAppControlEvent(app_control.get()); + SendAppControlEvent(app_control_ptr); } else { FT_LOG(Info) << "No event channel has been set up."; - queue_.push(app_control.get()); + queue_.push(app_control_ptr); } - AppControlManager::GetInstance().Insert(std::move(app_control)); } void AppControlChannel::HandleMethodCall(