From 558f0c88428face4371a9a24a7e620eaf33c2e6a Mon Sep 17 00:00:00 2001 From: Mohammad Samiul Islam Date: Wed, 12 Aug 2020 15:15:48 +0100 Subject: [PATCH] Improve logging for why a staged session was reverted mFailureReason gets populated with actual reason when we try to resume the staged session in checkpointing mode. But, if the device has a native crash due to which the device reboots even before we attempt to "resume" staged session, then it will never get populated. As such, during boot loops that occur earlier than "resume" of staged session, we end up logging nothing. In this CL, we improve on the scenario by falling back to using mNativeFailureReason if mFailureReason is empty. But this only works if our staged session contains APEX package in it. For apk-only staged sessions, we will still be logging blanks. Bug: 163787002 Test: atest ApexRollbackTests#testReasonForRevertIsLoggedDuringBootloop Change-Id: I5cd1733d66aa0b30855803b95eb9818dc81aa0d7 Merged-In: I5cd1733d66aa0b30855803b95eb9818dc81aa0d7 (cherry picked from commit a4cb493bdb69488a9b94aae627545aa91db55083) --- .../server/pm/PackageManagerShellCommand.java | 4 +++- .../com/android/server/pm/StagingManager.java | 23 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java index b571a9c5ce130..bb5a953d3a8f4 100644 --- a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java +++ b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java @@ -1060,7 +1060,9 @@ class PackageManagerShellCommand extends ShellCommand { + "; isStaged = " + session.isStaged() + "; isReady = " + session.isStagedSessionReady() + "; isApplied = " + session.isStagedSessionApplied() - + "; isFailed = " + session.isStagedSessionFailed() + ";"); + + "; isFailed = " + session.isStagedSessionFailed() + + "; errorMsg = " + session.getStagedSessionErrorMessage() + + ";"); } private Intent parseIntentAndUser() throws URISyntaxException { diff --git a/services/core/java/com/android/server/pm/StagingManager.java b/services/core/java/com/android/server/pm/StagingManager.java index 0c96f592c0dbb..33433db1a448f 100644 --- a/services/core/java/com/android/server/pm/StagingManager.java +++ b/services/core/java/com/android/server/pm/StagingManager.java @@ -605,13 +605,14 @@ public class StagingManager { // If checkpoint is supported, then we only resume sessions if we are in checkpointing // mode. If not, we fail all sessions. if (supportsCheckpoint() && !needsCheckpoint()) { - String errorMsg = "Reverting back to safe state. Marking " + session.sessionId - + " as failed"; - if (!TextUtils.isEmpty(mFailureReason)) { - errorMsg = errorMsg + ": " + mFailureReason; + String revertMsg = "Reverting back to safe state. Marking " + + session.sessionId + " as failed."; + final String reasonForRevert = getReasonForRevert(); + if (!TextUtils.isEmpty(reasonForRevert)) { + revertMsg += " Reason for revert: " + reasonForRevert; } - Slog.d(TAG, errorMsg); - session.setStagedSessionFailed(SessionInfo.STAGED_SESSION_UNKNOWN, errorMsg); + Slog.d(TAG, revertMsg); + session.setStagedSessionFailed(SessionInfo.STAGED_SESSION_UNKNOWN, revertMsg); return; } } catch (RemoteException e) { @@ -715,6 +716,16 @@ public class StagingManager { } } + private String getReasonForRevert() { + if (!TextUtils.isEmpty(mFailureReason)) { + return mFailureReason; + } + if (!TextUtils.isEmpty(mNativeFailureReason)) { + return "Session reverted due to crashing native process: " + mNativeFailureReason; + } + return ""; + } + private List findAPKsInDir(File stageDir) { List ret = new ArrayList<>(); if (stageDir != null && stageDir.exists()) {