| 381 | } |
| 382 | |
| 383 | void UsageStats::EnterBackground() |
| 384 | { |
| 385 | uint64_t const currTime = TimeSinceEpoch(); |
| 386 | |
| 387 | // Safe check if something wrong with device's time. |
| 388 | ASSERT_GREATER_OR_EQUAL(currTime, m_enterForegroundTime, ()); |
| 389 | if (currTime < m_enterForegroundTime) |
| 390 | return; |
| 391 | |
| 392 | // Safe check if uninitialized. Possible when entering background on DownloadResourcesLegacyActivity. |
| 393 | // ASSERT(m_enterForegroundTime > 0, ()); |
| 394 | if (m_enterForegroundTime == 0) |
| 395 | return; |
| 396 | |
| 397 | // Save first launch. |
| 398 | std::string dummy; |
| 399 | if (!m_ss.GetValue(m_firstLaunch, dummy)) |
| 400 | m_ss.SetValue(m_firstLaunch, ToString(m_enterForegroundTime)); |
| 401 | |
| 402 | // Save last background. |
| 403 | m_ss.SetValue(m_lastBackground, ToString(currTime)); |
| 404 | |
| 405 | // Aggregate foreground duration. |
| 406 | m_totalForegroundTime += (currTime - m_enterForegroundTime); |
| 407 | m_ss.SetValue(m_totalForeground, ToString(m_totalForegroundTime)); |
| 408 | |
| 409 | // Aggregate sessions count. |
| 410 | ++m_sessionsCount; |
| 411 | m_ss.SetValue(m_sessions, ToString(m_sessionsCount)); |
| 412 | } |
| 413 | |
| 414 | bool UsageStats::IsLoyalUser() const |
| 415 | { |