From 24757146d1a70f3f483b660a2d20bbdd71152782 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Mon, 10 Apr 2017 11:45:05 -0700 Subject: [PATCH] Ensure the system boots with a halfway sane time/date Just in case the kernel or vendor glue don't initialize the system time sensibly, we now make sure the current time at boot is at least up to the build time of the system disk image. Bug 36736983 Test: manual Change-Id: I46f776300ca4f5ad01396fc17c83fc833e1713f9 --- .../java/com/android/server/AlarmManagerService.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/services/core/java/com/android/server/AlarmManagerService.java b/services/core/java/com/android/server/AlarmManagerService.java index 8b32c16acb42c..21dae4f2139a1 100644 --- a/services/core/java/com/android/server/AlarmManagerService.java +++ b/services/core/java/com/android/server/AlarmManagerService.java @@ -36,6 +36,7 @@ import android.database.ContentObserver; import android.net.Uri; import android.os.Binder; import android.os.Bundle; +import android.os.Environment; import android.os.Handler; import android.os.IBinder; import android.os.Message; @@ -949,6 +950,16 @@ class AlarmManagerService extends SystemService { // because kernel doesn't keep this after reboot setTimeZoneImpl(SystemProperties.get(TIMEZONE_PROPERTY)); + // Also sure that we're booting with a halfway sensible current time + if (mNativeData != 0) { + final long systemBuildTime = Environment.getRootDirectory().lastModified(); + if (System.currentTimeMillis() < systemBuildTime) { + Slog.i(TAG, "Current time only " + System.currentTimeMillis() + + ", advancing to build time " + systemBuildTime); + setKernelTime(mNativeData, systemBuildTime); + } + } + PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*alarm*");