diff --git a/3party/Alohalytics/src/location.h b/3party/Alohalytics/src/location.h index 713a214524..abddc91fd1 100644 --- a/3party/Alohalytics/src/location.h +++ b/3party/Alohalytics/src/location.h @@ -29,6 +29,7 @@ #error "This code does not support serialization on Big Endian archs (see TODOs below)." #endif +#include #include #include #include @@ -161,6 +162,17 @@ class Location { Location() = default; + // Helper function, useful if location source is different from GPS. + static Location FromLatLon(double latitude_deg, double longitude_deg, bool needs_timestamp = false) { + using namespace std::chrono; + uint64_t ts = 0; + if (needs_timestamp) { + // TODO(AlexZ): Use common timestamp method here and in AlohalyticsBaseEvent. + ts = duration_cast(system_clock::now().time_since_epoch()).count(); + } + return Location().SetLatLon(ts, latitude_deg, longitude_deg, 1); + } + enum Source : std::uint8_t { UNKNOWN = 0, GPS = 1, NETWORK = 2, PASSIVE = 3 } source_; bool HasLatLon() const { return valid_values_mask_ & HAS_LATLON; } diff --git a/map/framework.cpp b/map/framework.cpp index a02b4e3fd0..8f4b336348 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1016,8 +1016,14 @@ void Framework::MemoryWarning() void Framework::EnterBackground() { + const ms::LatLon ll = MercatorBounds::ToLatLon(GetViewportCenter()); + alohalytics::Stats::Instance().LogEvent("Framework::EnterBackground", {{"zoom", strings::to_string(GetDrawScale())}, + {"foregroundSeconds", strings::to_string( + static_cast(my::Timer::LocalTime() - m_startForegroundTime))}}, + alohalytics::Location::FromLatLon(ll.lat, ll.lon)); // Do not clear caches for Android. This function is called when main activity is paused, // but at the same time search activity (for example) is enabled. + // TODO(AlexZ): Use onStart/onStop on Android to correctly detect app background and remove #ifndef. #ifndef OMIM_OS_ANDROID ClearAllCaches(); #endif @@ -1025,7 +1031,7 @@ void Framework::EnterBackground() void Framework::EnterForeground() { - m_StartForegroundTime = my::Timer::LocalTime(); + m_startForegroundTime = my::Timer::LocalTime(); } void Framework::ShowAll() diff --git a/map/framework.hpp b/map/framework.hpp index 5150898850..13e5898b25 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -118,7 +118,7 @@ protected: unique_ptr m_cpuDrawer; - double m_StartForegroundTime; + double m_startForegroundTime; bool m_queryMaxScaleMode;