Commit 3c786f5f authored by Leonid Baraz's avatar Leonid Baraz Committed by Commit Bot

Fix for missing activity reports on certain devices.

It was observed on Fievel device.
When ActivityStorage::LocalTimeToUtcDayStart is called with
parameter being base::Time::Max(), it returns timestamp
like 1939-01-12 08:00:00.000 UTC, and all activity intervals
referring to year 2020 are filtered out.

It looks like in certain SDK timestamp.LocalMidnight() does not
work correctly, when timestamp.is_max().

As a workaround, the code will no longer call it for Max timestamp.
This can never happen to actual intervals, only to a report
threshold.

Bug: 1104428
Change-Id: I1704e6fe43f7c42517653c007f293aa7c3b0eb56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2293264Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Commit-Queue: Leonid Baraz <lbaraz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#787797}
parent 1db22fc2
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/base64.h" #include "base/base64.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/check.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/values.h" #include "base/values.h"
...@@ -39,6 +40,7 @@ ActivityStorage::ActivityStorage(PrefService* pref_service, ...@@ -39,6 +40,7 @@ ActivityStorage::ActivityStorage(PrefService* pref_service,
ActivityStorage::~ActivityStorage() = default; ActivityStorage::~ActivityStorage() = default;
base::Time ActivityStorage::GetBeginningOfDay(base::Time timestamp) const { base::Time ActivityStorage::GetBeginningOfDay(base::Time timestamp) const {
DCHECK(!timestamp.is_max());
return timestamp.LocalMidnight() + day_start_offset_; return timestamp.LocalMidnight() + day_start_offset_;
} }
...@@ -157,6 +159,8 @@ void ActivityStorage::AddActivityPeriod(base::Time start, ...@@ -157,6 +159,8 @@ void ActivityStorage::AddActivityPeriod(base::Time start,
base::Time end, base::Time end,
const std::string& activity_id) { const std::string& activity_id) {
DCHECK(start <= end); DCHECK(start <= end);
DCHECK(!start.is_max());
DCHECK(!end.is_max());
DictionaryPrefUpdate update(pref_service_, pref_name_); DictionaryPrefUpdate update(pref_service_, pref_name_);
base::Value* activity_times = update.Get(); base::Value* activity_times = update.Get();
...@@ -198,6 +202,14 @@ void ActivityStorage::SetActivityPeriods( ...@@ -198,6 +202,14 @@ void ActivityStorage::SetActivityPeriods(
} }
int64_t ActivityStorage::LocalTimeToUtcDayStart(base::Time timestamp) const { int64_t ActivityStorage::LocalTimeToUtcDayStart(base::Time timestamp) const {
if (timestamp.is_max()) {
// If timestamp is base::Time::Max(), trying to calculate day start
// is not needed, just keep it as is. timestamp like this cannot be part
// of an actual activity interval, it only happens as a threshold for
// activities report.
return timestamp.ToJavaTime();
}
base::Time::Exploded exploded; base::Time::Exploded exploded;
base::Time day_start = GetBeginningOfDay(timestamp); base::Time day_start = GetBeginningOfDay(timestamp);
// TODO(crbug.com/827386): directly test this time change. Currently it is // TODO(crbug.com/827386): directly test this time change. Currently it is
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment