diff --git a/map/framework.cpp b/map/framework.cpp index 19a1a1970f..30e3d359dc 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1307,6 +1307,7 @@ void Framework::EnterBackground() SaveViewport(); m_trafficManager.OnEnterBackground(); + m_trackingReporter.SetAllowSendingPoints(false); ms::LatLon const ll = MercatorBounds::ToLatLon(GetViewportCenter()); alohalytics::Stats::Instance().LogEvent("Framework::EnterBackground", {{"zoom", strings::to_string(GetDrawScale())}, @@ -1328,6 +1329,7 @@ void Framework::EnterForeground() CallDrapeFunction(bind(&df::DrapeEngine::SetTimeInBackground, _1, time)); m_trafficManager.OnEnterForeground(); + m_trackingReporter.SetAllowSendingPoints(true); } bool Framework::GetCurrentPosition(double & lat, double & lon) const diff --git a/tracking/connection.cpp b/tracking/connection.cpp index 1042457e60..15e6750041 100644 --- a/tracking/connection.cpp +++ b/tracking/connection.cpp @@ -46,6 +46,14 @@ bool Connection::Reconnect() return true; } +void Connection::Shutdown() +{ + if (!m_socket) + return; + + m_socket->Close(); +} + // TODO: implement historical bool Connection::Send(boost::circular_buffer const & points) { diff --git a/tracking/connection.hpp b/tracking/connection.hpp index c72578cdbf..1ff04cc121 100644 --- a/tracking/connection.hpp +++ b/tracking/connection.hpp @@ -24,6 +24,7 @@ public: Connection(unique_ptr socket, string const & host, uint16_t port, bool isHistorical); bool Reconnect(); + void Shutdown(); bool Send(boost::circular_buffer const & points); private: diff --git a/tracking/reporter.cpp b/tracking/reporter.cpp index 5050002065..48f7174988 100644 --- a/tracking/reporter.cpp +++ b/tracking/reporter.cpp @@ -92,6 +92,16 @@ void Reporter::Run() bool Reporter::SendPoints() { + if (!m_allowSendingPoints) + { + if (m_wasConnected) + { + m_realtimeSender.Shutdown(); + m_wasConnected = false; + } + return true; + } + if (m_points.empty()) return true; diff --git a/tracking/reporter.hpp b/tracking/reporter.hpp index 380a3cd460..c013bc021a 100644 --- a/tracking/reporter.hpp +++ b/tracking/reporter.hpp @@ -37,12 +37,15 @@ public: void AddLocation(location::GpsInfo const & info); + void SetAllowSendingPoints(bool allow) { m_allowSendingPoints = allow; } + inline void SetIdleFunc(function fn) { m_idleFn = fn; } private: void Run(); bool SendPoints(); + bool m_allowSendingPoints = true; Connection m_realtimeSender; milliseconds m_pushDelay; bool m_wasConnected = false;