Skip to content

Commit

Permalink
WebView: Adding Fast Variations Seed SafeMode action Seed Age Logging
Browse files Browse the repository at this point in the history
In order to enable verification that the Fast Variations Seed SafeMode
action has successfully received a SafeMode variations seed instead
of the normal Variations seed, a log statement is added exclusively for
the SafeMode action when it executes.

(cherry picked from commit 7553023)

Test: Visual inspection of the logs via logcat on test devices
Bug: 1395513
Change-Id: Ib0abd2c576a1855ef5e84c83275ed7fccaad273d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4568131
Reviewed-by: Nate Fischer <ntfschr@chromium.org>
Commit-Queue: Adam Walls <avvall@google.com>
Cr-Original-Commit-Position: refs/heads/main@{#1152217}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4593924
Cr-Commit-Position: refs/branch-heads/5790@{#410}
Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
  • Loading branch information
avvall authored and Chromium LUCI CQ committed Jun 6, 2023
1 parent 5ba9fa6 commit 87ff796
Showing 1 changed file with 18 additions and 1 deletion.
Expand Up @@ -28,6 +28,8 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

/**
* A {@link SafeModeAction} to ensure the variations seed is distributed on an app's first run.
Expand Down Expand Up @@ -75,8 +77,12 @@ public boolean execute() {
sHasRun = true;
long currDateTime = new Date().getTime();
SeedParser parser = new SeedParser();

long stampTime = sSeedFile.lastModified();
long ageInMillis = currDateTime - stampTime;

if (sSeedFile.exists() && ageInMillis > 0) {
logSeedFileAge(ageInMillis);
}
// If we see that the local seed file has not exceeded the
// maximum seed age of 15 minutes, parse the local seed instead
// of requesting a new one from the ContentProvider
Expand All @@ -95,6 +101,16 @@ public boolean execute() {
}
}

private void logSeedFileAge(long ageInMillis) {
int seconds = (int) (ageInMillis / 1000) % 60;
int minutes = (int) (ageInMillis / TimeUnit.MINUTES.toMillis(1)) % 60;
int hrs = (int) (ageInMillis / TimeUnit.HOURS.toMillis(1));

String formattedAge =
String.format(Locale.US, "%02d:%02d:%02d (hh:mm:ss)", hrs, minutes, seconds);
Log.i(TAG, "Seed file age - " + formattedAge);
}

/**
* This class queries {@link SafeModeVariationsSeedContentProvider} for the
* latest variations seed.
Expand Down Expand Up @@ -211,6 +227,7 @@ private boolean writeToSeedFile() {
String filePath = sSeedFile.getPath();
try (FileOutputStream out = new FileOutputStream(filePath, false)) {
out.write(mProtoAsByteArray);
out.flush();
return true;
} catch (IOException e) {
Log.e(TAG, "Failed writing seed file: " + e.getMessage());
Expand Down

0 comments on commit 87ff796

Please sign in to comment.