From 6bacdcd42edd525183aa147d12de74090b70ce94 Mon Sep 17 00:00:00 2001 From: Gavin Corkery Date: Fri, 17 Apr 2020 00:56:38 +0100 Subject: Ensure userspace reboot is supported before logging Ensure that userspace reboot is supported before performing any actions. Any call into UserspaceRebootLogger in the case that userspace reboot is not supported should be a no-op. It is unexpected to call into this class on an unsupported device, so log with ASSERT priority in this case. Test: atest UserspaceRebootHostTest Bug: 153648276 Change-Id: Ic3041ff3abe0d2641d3d99fc8e816f1f5c491a34 Merged-In: Ic3041ff3abe0d2641d3d99fc8e816f1f5c491a34 (cherry picked from commit eb52a694445a7fd5d9267d400995ebf2e53bbc67) --- .../com/android/server/UserspaceRebootLogger.java | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/services/core/java/com/android/server/UserspaceRebootLogger.java b/services/core/java/com/android/server/UserspaceRebootLogger.java index 9a9374ce1822..2403b637581f 100644 --- a/services/core/java/com/android/server/UserspaceRebootLogger.java +++ b/services/core/java/com/android/server/UserspaceRebootLogger.java @@ -24,6 +24,7 @@ import static com.android.internal.util.FrameworkStatsLog.USERSPACE_REBOOT_REPOR import static com.android.internal.util.FrameworkStatsLog.USERSPACE_REBOOT_REPORTED__USER_ENCRYPTION_STATE__LOCKED; import static com.android.internal.util.FrameworkStatsLog.USERSPACE_REBOOT_REPORTED__USER_ENCRYPTION_STATE__UNLOCKED; +import android.os.PowerManager; import android.os.SystemClock; import android.os.SystemProperties; import android.text.TextUtils; @@ -53,8 +54,15 @@ public final class UserspaceRebootLogger { /** * Modifies internal state to note that {@code UserspaceRebootReported} atom needs to be * logged on the next successful boot. + * + *

This call should only be made on devices supporting userspace reboot. */ public static void noteUserspaceRebootWasRequested() { + if (!PowerManager.isRebootingUserspaceSupportedImpl()) { + Slog.wtf(TAG, "Userspace reboot is not supported."); + return; + } + SystemProperties.set(USERSPACE_REBOOT_SHOULD_LOG_PROPERTY, "1"); SystemProperties.set(USERSPACE_REBOOT_LAST_STARTED_PROPERTY, String.valueOf(SystemClock.elapsedRealtime())); @@ -64,16 +72,30 @@ public final class UserspaceRebootLogger { * Updates internal state on boot after successful userspace reboot. * *

Should be called right before framework sets {@code sys.boot_completed} property. + * + *

This call should only be made on devices supporting userspace reboot. */ public static void noteUserspaceRebootSuccess() { + if (!PowerManager.isRebootingUserspaceSupportedImpl()) { + Slog.wtf(TAG, "Userspace reboot is not supported."); + return; + } + SystemProperties.set(USERSPACE_REBOOT_LAST_FINISHED_PROPERTY, String.valueOf(SystemClock.elapsedRealtime())); } /** * Returns {@code true} if {@code UserspaceRebootReported} atom should be logged. + * + *

This call should only be made on devices supporting userspace reboot. */ public static boolean shouldLogUserspaceRebootEvent() { + if (!PowerManager.isRebootingUserspaceSupportedImpl()) { + Slog.wtf(TAG, "Userspace reboot is not supported."); + return false; + } + return SystemProperties.getBoolean(USERSPACE_REBOOT_SHOULD_LOG_PROPERTY, false); } @@ -83,8 +105,15 @@ public final class UserspaceRebootLogger { *

Should be called in the end of {@link * com.android.server.am.ActivityManagerService#finishBooting()} method, after framework have * tried to proactivelly unlock storage of the primary user. + * + *

This call should only be made on devices supporting userspace reboot. */ public static void logEventAsync(boolean userUnlocked, Executor executor) { + if (!PowerManager.isRebootingUserspaceSupportedImpl()) { + Slog.wtf(TAG, "Userspace reboot is not supported."); + return; + } + final int outcome = computeOutcome(); final long durationMillis; if (outcome == USERSPACE_REBOOT_REPORTED__OUTCOME__SUCCESS) { -- cgit v1.2.3-59-g8ed1b