diff --git a/android_webview/java/src/org/chromium/android_webview/variations/FastVariationsSeedSafeModeAction.java b/android_webview/java/src/org/chromium/android_webview/variations/FastVariationsSeedSafeModeAction.java index c770768288388..7dee106886761 100644 --- a/android_webview/java/src/org/chromium/android_webview/variations/FastVariationsSeedSafeModeAction.java +++ b/android_webview/java/src/org/chromium/android_webview/variations/FastVariationsSeedSafeModeAction.java @@ -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. @@ -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 @@ -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. @@ -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());