From b56a64a37ed1ef10b932a489927ac2ad3d3d71e1 Mon Sep 17 00:00:00 2001 From: Josep del Rio Date: Tue, 28 Feb 2023 10:25:39 +0000 Subject: [PATCH] Improve event time crash logging We got a report that system server is crashing due to receiving some events with a time set in the future. From the error message it is not possible to determine if the event time is a bit further or if it's just uninitialized garbage (the second is a lot more plausible). This CL will add some extra logging when this occurs so we have a better idea of what is happening. Bug: 269510424 Test: builds, passes presubmit Change-Id: I47a924f182444dcdefea5b2cda76f7d2d8de1cf0 --- .../android/server/power/PowerManagerService.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index bf8cbeac30c8c..2e8a150f2b6d4 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -5693,6 +5693,7 @@ public final class PowerManagerService extends SystemService } if (eventTime > now) { + Slog.e(TAG, "Event time " + eventTime + " cannot be newer than " + now); throw new IllegalArgumentException("event time must not be in the future"); } @@ -5708,7 +5709,9 @@ public final class PowerManagerService extends SystemService @Override // Binder call public void wakeUp(long eventTime, @WakeReason int reason, String details, String opPackageName) { - if (eventTime > mClock.uptimeMillis()) { + final long now = mClock.uptimeMillis(); + if (eventTime > now) { + Slog.e(TAG, "Event time " + eventTime + " cannot be newer than " + now); throw new IllegalArgumentException("event time must not be in the future"); } @@ -5760,7 +5763,9 @@ public final class PowerManagerService extends SystemService @Override // Binder call public void nap(long eventTime) { - if (eventTime > mClock.uptimeMillis()) { + final long now = mClock.uptimeMillis(); + if (eventTime > now) { + Slog.e(TAG, "Event time " + eventTime + " cannot be newer than " + now); throw new IllegalArgumentException("event time must not be in the future"); } @@ -6525,7 +6530,9 @@ public final class PowerManagerService extends SystemService @Override // Binder call public void boostScreenBrightness(long eventTime) { + final long now = mClock.uptimeMillis(); if (eventTime > mClock.uptimeMillis()) { + Slog.e(TAG, "Event time " + eventTime + " cannot be newer than " + now); throw new IllegalArgumentException("event time must not be in the future"); } @@ -6684,7 +6691,9 @@ public final class PowerManagerService extends SystemService @RequiresPermission(android.Manifest.permission.DEVICE_POWER) private void goToSleepInternal(IntArray groupIds, long eventTime, int reason, int flags) { - if (eventTime > mClock.uptimeMillis()) { + final long now = mClock.uptimeMillis(); + if (eventTime > now) { + Slog.e(TAG, "Event time " + eventTime + " cannot be newer than " + now); throw new IllegalArgumentException("event time must not be in the future"); }