From 4b03c07cc70690aff6383fc4e8794b151c00b561 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Thu, 21 Nov 2019 17:30:03 +0000 Subject: [PATCH] Remove dead code from SystemServer Remove dead code from SystemServer that obstensively protects devices from negative (< 1970) system clock times, but does not. In reality, SystemServer calls SystemClock.setCurrentTimeMillis(), which calls through to the AlarmManager.setTime() binder call. When the code runs the system server hasn't started any services yet, so this would always fail. AlarmManager has similar protections in place that do work: if the device is earlier than a "build time", then the device's clock is forced forward. That provides the protection that the code being removed from SystemServer was trying to achieve. Test: Added logging to SystemClock to prove AlarmManager is null / manual debugging Change-Id: I87dca1062829bc1a10202804fa7ee31e0a6f03a3 --- core/java/android/os/SystemClock.java | 1 + services/java/com/android/server/SystemServer.java | 9 --------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/core/java/android/os/SystemClock.java b/core/java/android/os/SystemClock.java index 64effb8fa0cca..210f5d7b5dab4 100644 --- a/core/java/android/os/SystemClock.java +++ b/core/java/android/os/SystemClock.java @@ -154,6 +154,7 @@ public final class SystemClock { final IAlarmManager mgr = IAlarmManager.Stub .asInterface(ServiceManager.getService(Context.ALARM_SERVICE)); if (mgr == null) { + Slog.e(TAG, "Unable to set RTC: mgr == null"); return false; } diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 16c60ca3997ae..8f58d4ba49411 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -383,15 +383,6 @@ public final class SystemServer { EventLog.writeEvent(EventLogTags.SYSTEM_SERVER_START, mStartCount, mRuntimeStartUptime, mRuntimeStartElapsedTime); - // If a device's clock is before 1970 (before 0), a lot of - // APIs crash dealing with negative numbers, notably - // java.io.File#setLastModified, so instead we fake it and - // hope that time from cell towers or NTP fixes it shortly. - if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) { - Slog.w(TAG, "System clock is before 1970; setting to 1970."); - SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME); - } - // // Default the timezone property to GMT if not set. //