Loading packages/CrashRecovery/services/module/java/com/android/server/PackageWatchdog.java +85 −8 Original line number Diff line number Diff line Loading @@ -766,6 +766,70 @@ public class PackageWatchdog { return mPackagesExemptFromImpactLevelThreshold; } /** * Indicates that the result of a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} is unknown. */ public static final int MITIGATION_RESULT_UNKNOWN = ObserverMitigationResult.MITIGATION_RESULT_UNKNOWN; /** * Indicates that a mitigation was successfully triggered or executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation}. */ public static final int MITIGATION_RESULT_SUCCESS = ObserverMitigationResult.MITIGATION_RESULT_SUCCESS; /** * Indicates that a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} was skipped. */ public static final int MITIGATION_RESULT_SKIPPED = ObserverMitigationResult.MITIGATION_RESULT_SKIPPED; /** * Indicates that a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} failed, * but the failure is potentially retryable. */ public static final int MITIGATION_RESULT_FAILURE_RETRYABLE = ObserverMitigationResult.MITIGATION_RESULT_FAILURE_RETRYABLE; /** * Indicates that a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} failed, * and the failure is not retryable. */ public static final int MITIGATION_RESULT_FAILURE_NON_RETRYABLE = ObserverMitigationResult.MITIGATION_RESULT_FAILURE_NON_RETRYABLE; /** * Possible return values of the for mitigations executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} and * {@link PackageHealthObserver#onExecuteBootLoopMitigation}. * @hide */ @Retention(SOURCE) @IntDef(prefix = "MITIGATION_RESULT_", value = { ObserverMitigationResult.MITIGATION_RESULT_UNKNOWN, ObserverMitigationResult.MITIGATION_RESULT_SUCCESS, ObserverMitigationResult.MITIGATION_RESULT_SKIPPED, ObserverMitigationResult.MITIGATION_RESULT_FAILURE_RETRYABLE, ObserverMitigationResult.MITIGATION_RESULT_FAILURE_NON_RETRYABLE, }) public @interface ObserverMitigationResult { int MITIGATION_RESULT_UNKNOWN = 0; int MITIGATION_RESULT_SUCCESS = 1; int MITIGATION_RESULT_SKIPPED = 2; int MITIGATION_RESULT_FAILURE_RETRYABLE = 3; int MITIGATION_RESULT_FAILURE_NON_RETRYABLE = 4; } /** * The minimum value that can be returned by any observer. * It represents that no mitigations were available. Loading Loading @@ -856,9 +920,16 @@ public class PackageWatchdog { * @param failureReason the type of failure that is occurring. * @param mitigationCount the number of times mitigation has been called for this package * (including this time). * @return {@code true} if action was executed successfully, {@code false} otherwise * @return {@link #MITIGATION_RESULT_SUCCESS} if the mitigation was successful, * {@link #MITIGATION_RESULT_FAILURE_RETRYABLE} if the mitigation failed but can be * retried, * {@link #MITIGATION_RESULT_FAILURE_NON_RETRYABLE} if the mitigation failed and * cannot be retried, * {@link #MITIGATION_RESULT_UNKNOWN} if the result of the mitigation is unknown, * or {@link #MITIGATION_RESULT_SKIPPED} if the mitigation was skipped. */ boolean onExecuteHealthCheckMitigation(@Nullable VersionedPackage versionedPackage, @ObserverMitigationResult int onExecuteHealthCheckMitigation( @Nullable VersionedPackage versionedPackage, @FailureReasons int failureReason, int mitigationCount); Loading @@ -885,10 +956,16 @@ public class PackageWatchdog { * @param mitigationCount the number of times mitigation has been attempted for this * boot loop (including this time). * * @return {@code true} if action was executed successfully, {@code false} otherwise * @return {@link #MITIGATION_RESULT_SUCCESS} if the mitigation was successful, * {@link #MITIGATION_RESULT_FAILURE_RETRYABLE} if the mitigation failed but can be * retried, * {@link #MITIGATION_RESULT_FAILURE_NON_RETRYABLE} if the mitigation failed and * cannot be retried, * {@link #MITIGATION_RESULT_UNKNOWN} if the result of the mitigation is unknown, * or {@link #MITIGATION_RESULT_SKIPPED} if the mitigation was skipped. */ default boolean onExecuteBootLoopMitigation(int mitigationCount) { return false; default @ObserverMitigationResult int onExecuteBootLoopMitigation(int mitigationCount) { return ObserverMitigationResult.MITIGATION_RESULT_SKIPPED; } // TODO(b/120598832): Ensure uniqueness? Loading packages/CrashRecovery/services/module/java/com/android/server/RescueParty.java +9 −7 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server; import static com.android.server.PackageWatchdog.MITIGATION_RESULT_SKIPPED; import static com.android.server.PackageWatchdog.MITIGATION_RESULT_SUCCESS; import static com.android.server.crashrecovery.CrashRecoveryUtils.logCrashRecoveryEvent; import android.annotation.IntDef; Loading Loading @@ -728,10 +730,10 @@ public class RescueParty { } @Override public boolean onExecuteHealthCheckMitigation(@Nullable VersionedPackage failedPackage, public int onExecuteHealthCheckMitigation(@Nullable VersionedPackage failedPackage, @FailureReasons int failureReason, int mitigationCount) { if (isDisabled()) { return false; return MITIGATION_RESULT_SKIPPED; } Slog.i(TAG, "Executing remediation." + " failedPackage: " Loading @@ -753,9 +755,9 @@ public class RescueParty { } executeRescueLevel(mContext, failedPackage == null ? null : failedPackage.getPackageName(), level); return true; return MITIGATION_RESULT_SUCCESS; } else { return false; return MITIGATION_RESULT_SKIPPED; } } Loading Loading @@ -796,9 +798,9 @@ public class RescueParty { } @Override public boolean onExecuteBootLoopMitigation(int mitigationCount) { public int onExecuteBootLoopMitigation(int mitigationCount) { if (isDisabled()) { return false; return MITIGATION_RESULT_SKIPPED; } boolean mayPerformReboot = !shouldThrottleReboot(); final int level; Loading @@ -813,7 +815,7 @@ public class RescueParty { level = getRescueLevel(mitigationCount, mayPerformReboot); } executeRescueLevel(mContext, /*failedPackage=*/ null, level); return true; return MITIGATION_RESULT_SUCCESS; } @Override Loading packages/CrashRecovery/services/module/java/com/android/server/rollback/RollbackPackageHealthObserver.java +9 −7 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server.rollback; import static com.android.server.PackageWatchdog.MITIGATION_RESULT_SKIPPED; import static com.android.server.PackageWatchdog.MITIGATION_RESULT_SUCCESS; import static com.android.server.crashrecovery.CrashRecoveryUtils.logCrashRecoveryEvent; import android.annotation.AnyThread; Loading Loading @@ -172,7 +174,7 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve } @Override public boolean onExecuteHealthCheckMitigation(@Nullable VersionedPackage failedPackage, public int onExecuteHealthCheckMitigation(@Nullable VersionedPackage failedPackage, @FailureReasons int rollbackReason, int mitigationCount) { Slog.i(TAG, "Executing remediation." + " failedPackage: " Loading @@ -183,7 +185,7 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve List<RollbackInfo> availableRollbacks = getAvailableRollbacks(); if (rollbackReason == PackageWatchdog.FAILURE_REASON_NATIVE_CRASH) { mHandler.post(() -> rollbackAllLowImpact(availableRollbacks, rollbackReason)); return true; return MITIGATION_RESULT_SUCCESS; } List<RollbackInfo> lowImpactRollbacks = getRollbacksAvailableForImpactLevel( Loading @@ -198,7 +200,7 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve } else { if (rollbackReason == PackageWatchdog.FAILURE_REASON_NATIVE_CRASH) { mHandler.post(() -> rollbackAll(rollbackReason)); return true; return MITIGATION_RESULT_SUCCESS; } RollbackInfo rollback = getAvailableRollback(failedPackage); Loading @@ -210,7 +212,7 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve } // Assume rollbacks executed successfully return true; return MITIGATION_RESULT_SUCCESS; } @Override Loading @@ -226,15 +228,15 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve } @Override public boolean onExecuteBootLoopMitigation(int mitigationCount) { public int onExecuteBootLoopMitigation(int mitigationCount) { if (Flags.recoverabilityDetection()) { List<RollbackInfo> availableRollbacks = getAvailableRollbacks(); triggerLeastImpactLevelRollback(availableRollbacks, PackageWatchdog.FAILURE_REASON_BOOT_LOOP); return true; return MITIGATION_RESULT_SUCCESS; } return false; return MITIGATION_RESULT_SKIPPED; } @Override Loading packages/CrashRecovery/services/platform/java/com/android/server/PackageWatchdog.java +93 −9 Original line number Diff line number Diff line Loading @@ -752,6 +752,70 @@ public class PackageWatchdog { return mPackagesExemptFromImpactLevelThreshold; } /** * Indicates that the result of a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} is unknown. */ public static final int MITIGATION_RESULT_UNKNOWN = ObserverMitigationResult.MITIGATION_RESULT_UNKNOWN; /** * Indicates that a mitigation was successfully triggered or executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation}. */ public static final int MITIGATION_RESULT_SUCCESS = ObserverMitigationResult.MITIGATION_RESULT_SUCCESS; /** * Indicates that a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} was skipped. */ public static final int MITIGATION_RESULT_SKIPPED = ObserverMitigationResult.MITIGATION_RESULT_SKIPPED; /** * Indicates that a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} failed, * but the failure is potentially retryable. */ public static final int MITIGATION_RESULT_FAILURE_RETRYABLE = ObserverMitigationResult.MITIGATION_RESULT_FAILURE_RETRYABLE; /** * Indicates that a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} failed, * and the failure is not retryable. */ public static final int MITIGATION_RESULT_FAILURE_NON_RETRYABLE = ObserverMitigationResult.MITIGATION_RESULT_FAILURE_NON_RETRYABLE; /** * Possible return values of the for mitigations executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} and * {@link PackageHealthObserver#onExecuteBootLoopMitigation}. * @hide */ @Retention(SOURCE) @IntDef(prefix = "MITIGATION_RESULT_", value = { ObserverMitigationResult.MITIGATION_RESULT_UNKNOWN, ObserverMitigationResult.MITIGATION_RESULT_SUCCESS, ObserverMitigationResult.MITIGATION_RESULT_SKIPPED, ObserverMitigationResult.MITIGATION_RESULT_FAILURE_RETRYABLE, ObserverMitigationResult.MITIGATION_RESULT_FAILURE_NON_RETRYABLE, }) public @interface ObserverMitigationResult { int MITIGATION_RESULT_UNKNOWN = 0; int MITIGATION_RESULT_SUCCESS = 1; int MITIGATION_RESULT_SKIPPED = 2; int MITIGATION_RESULT_FAILURE_RETRYABLE = 3; int MITIGATION_RESULT_FAILURE_NON_RETRYABLE = 4; } /** Possible severity values of the user impact of a * {@link PackageHealthObserver#onExecuteHealthCheckMitigation}. * @hide Loading Loading @@ -809,16 +873,25 @@ public class PackageWatchdog { int mitigationCount); /** * Executes mitigation for {@link #onHealthCheckFailed}. * This would be called after {@link #onHealthCheckFailed}. * This is called only if current observer returned least impact mitigation for failed * health check. * * @param versionedPackage the package that is failing. This may be null if a native * service is crashing. * @param failureReason the type of failure that is occurring. * @param mitigationCount the number of times mitigation has been called for this package * (including this time). * @return {@code true} if action was executed successfully, {@code false} otherwise * @return {@link #MITIGATION_RESULT_SUCCESS} if the mitigation was successful, * {@link #MITIGATION_RESULT_FAILURE_RETRYABLE} if the mitigation failed but can be * retried, * {@link #MITIGATION_RESULT_FAILURE_NON_RETRYABLE} if the mitigation failed and * cannot be retried, * {@link #MITIGATION_RESULT_UNKNOWN} if the result of the mitigation is unknown, * or {@link #MITIGATION_RESULT_SKIPPED} if the mitigation was skipped. */ boolean onExecuteHealthCheckMitigation(@Nullable VersionedPackage versionedPackage, @ObserverMitigationResult int onExecuteHealthCheckMitigation( @Nullable VersionedPackage versionedPackage, @FailureReasons int failureReason, int mitigationCount); Loading @@ -834,12 +907,23 @@ public class PackageWatchdog { } /** * Executes mitigation for {@link #onBootLoop} * This would be called after {@link #onBootLoop}. * This is called only if current observer returned least impact mitigation for fixing * boot loop. * * @param mitigationCount the number of times mitigation has been attempted for this * boot loop (including this time). * * @return {@link #MITIGATION_RESULT_SUCCESS} if the mitigation was successful, * {@link #MITIGATION_RESULT_FAILURE_RETRYABLE} if the mitigation failed but can be * retried, * {@link #MITIGATION_RESULT_FAILURE_NON_RETRYABLE} if the mitigation failed and * cannot be retried, * {@link #MITIGATION_RESULT_UNKNOWN} if the result of the mitigation is unknown, * or {@link #MITIGATION_RESULT_SKIPPED} if the mitigation was skipped. */ default boolean onExecuteBootLoopMitigation(int mitigationCount) { return false; default @ObserverMitigationResult int onExecuteBootLoopMitigation(int mitigationCount) { return ObserverMitigationResult.MITIGATION_RESULT_SKIPPED; } // TODO(b/120598832): Ensure uniqueness? Loading packages/CrashRecovery/services/platform/java/com/android/server/RescueParty.java +9 −7 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.server; import static android.provider.DeviceConfig.Properties; import static com.android.server.PackageWatchdog.MITIGATION_RESULT_SKIPPED; import static com.android.server.PackageWatchdog.MITIGATION_RESULT_SUCCESS; import static com.android.server.crashrecovery.CrashRecoveryUtils.logCrashRecoveryEvent; import android.annotation.IntDef; Loading Loading @@ -859,10 +861,10 @@ public class RescueParty { } @Override public boolean onExecuteHealthCheckMitigation(@Nullable VersionedPackage failedPackage, public int onExecuteHealthCheckMitigation(@Nullable VersionedPackage failedPackage, @FailureReasons int failureReason, int mitigationCount) { if (isDisabled()) { return false; return MITIGATION_RESULT_SKIPPED; } Slog.i(TAG, "Executing remediation." + " failedPackage: " Loading @@ -884,9 +886,9 @@ public class RescueParty { } executeRescueLevel(mContext, failedPackage == null ? null : failedPackage.getPackageName(), level); return true; return MITIGATION_RESULT_SUCCESS; } else { return false; return MITIGATION_RESULT_SKIPPED; } } Loading Loading @@ -927,9 +929,9 @@ public class RescueParty { } @Override public boolean onExecuteBootLoopMitigation(int mitigationCount) { public int onExecuteBootLoopMitigation(int mitigationCount) { if (isDisabled()) { return false; return MITIGATION_RESULT_SKIPPED; } boolean mayPerformReboot = !shouldThrottleReboot(); final int level; Loading @@ -944,7 +946,7 @@ public class RescueParty { level = getRescueLevel(mitigationCount, mayPerformReboot); } executeRescueLevel(mContext, /*failedPackage=*/ null, level); return true; return MITIGATION_RESULT_SUCCESS; } @Override Loading Loading
packages/CrashRecovery/services/module/java/com/android/server/PackageWatchdog.java +85 −8 Original line number Diff line number Diff line Loading @@ -766,6 +766,70 @@ public class PackageWatchdog { return mPackagesExemptFromImpactLevelThreshold; } /** * Indicates that the result of a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} is unknown. */ public static final int MITIGATION_RESULT_UNKNOWN = ObserverMitigationResult.MITIGATION_RESULT_UNKNOWN; /** * Indicates that a mitigation was successfully triggered or executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation}. */ public static final int MITIGATION_RESULT_SUCCESS = ObserverMitigationResult.MITIGATION_RESULT_SUCCESS; /** * Indicates that a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} was skipped. */ public static final int MITIGATION_RESULT_SKIPPED = ObserverMitigationResult.MITIGATION_RESULT_SKIPPED; /** * Indicates that a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} failed, * but the failure is potentially retryable. */ public static final int MITIGATION_RESULT_FAILURE_RETRYABLE = ObserverMitigationResult.MITIGATION_RESULT_FAILURE_RETRYABLE; /** * Indicates that a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} failed, * and the failure is not retryable. */ public static final int MITIGATION_RESULT_FAILURE_NON_RETRYABLE = ObserverMitigationResult.MITIGATION_RESULT_FAILURE_NON_RETRYABLE; /** * Possible return values of the for mitigations executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} and * {@link PackageHealthObserver#onExecuteBootLoopMitigation}. * @hide */ @Retention(SOURCE) @IntDef(prefix = "MITIGATION_RESULT_", value = { ObserverMitigationResult.MITIGATION_RESULT_UNKNOWN, ObserverMitigationResult.MITIGATION_RESULT_SUCCESS, ObserverMitigationResult.MITIGATION_RESULT_SKIPPED, ObserverMitigationResult.MITIGATION_RESULT_FAILURE_RETRYABLE, ObserverMitigationResult.MITIGATION_RESULT_FAILURE_NON_RETRYABLE, }) public @interface ObserverMitigationResult { int MITIGATION_RESULT_UNKNOWN = 0; int MITIGATION_RESULT_SUCCESS = 1; int MITIGATION_RESULT_SKIPPED = 2; int MITIGATION_RESULT_FAILURE_RETRYABLE = 3; int MITIGATION_RESULT_FAILURE_NON_RETRYABLE = 4; } /** * The minimum value that can be returned by any observer. * It represents that no mitigations were available. Loading Loading @@ -856,9 +920,16 @@ public class PackageWatchdog { * @param failureReason the type of failure that is occurring. * @param mitigationCount the number of times mitigation has been called for this package * (including this time). * @return {@code true} if action was executed successfully, {@code false} otherwise * @return {@link #MITIGATION_RESULT_SUCCESS} if the mitigation was successful, * {@link #MITIGATION_RESULT_FAILURE_RETRYABLE} if the mitigation failed but can be * retried, * {@link #MITIGATION_RESULT_FAILURE_NON_RETRYABLE} if the mitigation failed and * cannot be retried, * {@link #MITIGATION_RESULT_UNKNOWN} if the result of the mitigation is unknown, * or {@link #MITIGATION_RESULT_SKIPPED} if the mitigation was skipped. */ boolean onExecuteHealthCheckMitigation(@Nullable VersionedPackage versionedPackage, @ObserverMitigationResult int onExecuteHealthCheckMitigation( @Nullable VersionedPackage versionedPackage, @FailureReasons int failureReason, int mitigationCount); Loading @@ -885,10 +956,16 @@ public class PackageWatchdog { * @param mitigationCount the number of times mitigation has been attempted for this * boot loop (including this time). * * @return {@code true} if action was executed successfully, {@code false} otherwise * @return {@link #MITIGATION_RESULT_SUCCESS} if the mitigation was successful, * {@link #MITIGATION_RESULT_FAILURE_RETRYABLE} if the mitigation failed but can be * retried, * {@link #MITIGATION_RESULT_FAILURE_NON_RETRYABLE} if the mitigation failed and * cannot be retried, * {@link #MITIGATION_RESULT_UNKNOWN} if the result of the mitigation is unknown, * or {@link #MITIGATION_RESULT_SKIPPED} if the mitigation was skipped. */ default boolean onExecuteBootLoopMitigation(int mitigationCount) { return false; default @ObserverMitigationResult int onExecuteBootLoopMitigation(int mitigationCount) { return ObserverMitigationResult.MITIGATION_RESULT_SKIPPED; } // TODO(b/120598832): Ensure uniqueness? Loading
packages/CrashRecovery/services/module/java/com/android/server/RescueParty.java +9 −7 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server; import static com.android.server.PackageWatchdog.MITIGATION_RESULT_SKIPPED; import static com.android.server.PackageWatchdog.MITIGATION_RESULT_SUCCESS; import static com.android.server.crashrecovery.CrashRecoveryUtils.logCrashRecoveryEvent; import android.annotation.IntDef; Loading Loading @@ -728,10 +730,10 @@ public class RescueParty { } @Override public boolean onExecuteHealthCheckMitigation(@Nullable VersionedPackage failedPackage, public int onExecuteHealthCheckMitigation(@Nullable VersionedPackage failedPackage, @FailureReasons int failureReason, int mitigationCount) { if (isDisabled()) { return false; return MITIGATION_RESULT_SKIPPED; } Slog.i(TAG, "Executing remediation." + " failedPackage: " Loading @@ -753,9 +755,9 @@ public class RescueParty { } executeRescueLevel(mContext, failedPackage == null ? null : failedPackage.getPackageName(), level); return true; return MITIGATION_RESULT_SUCCESS; } else { return false; return MITIGATION_RESULT_SKIPPED; } } Loading Loading @@ -796,9 +798,9 @@ public class RescueParty { } @Override public boolean onExecuteBootLoopMitigation(int mitigationCount) { public int onExecuteBootLoopMitigation(int mitigationCount) { if (isDisabled()) { return false; return MITIGATION_RESULT_SKIPPED; } boolean mayPerformReboot = !shouldThrottleReboot(); final int level; Loading @@ -813,7 +815,7 @@ public class RescueParty { level = getRescueLevel(mitigationCount, mayPerformReboot); } executeRescueLevel(mContext, /*failedPackage=*/ null, level); return true; return MITIGATION_RESULT_SUCCESS; } @Override Loading
packages/CrashRecovery/services/module/java/com/android/server/rollback/RollbackPackageHealthObserver.java +9 −7 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server.rollback; import static com.android.server.PackageWatchdog.MITIGATION_RESULT_SKIPPED; import static com.android.server.PackageWatchdog.MITIGATION_RESULT_SUCCESS; import static com.android.server.crashrecovery.CrashRecoveryUtils.logCrashRecoveryEvent; import android.annotation.AnyThread; Loading Loading @@ -172,7 +174,7 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve } @Override public boolean onExecuteHealthCheckMitigation(@Nullable VersionedPackage failedPackage, public int onExecuteHealthCheckMitigation(@Nullable VersionedPackage failedPackage, @FailureReasons int rollbackReason, int mitigationCount) { Slog.i(TAG, "Executing remediation." + " failedPackage: " Loading @@ -183,7 +185,7 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve List<RollbackInfo> availableRollbacks = getAvailableRollbacks(); if (rollbackReason == PackageWatchdog.FAILURE_REASON_NATIVE_CRASH) { mHandler.post(() -> rollbackAllLowImpact(availableRollbacks, rollbackReason)); return true; return MITIGATION_RESULT_SUCCESS; } List<RollbackInfo> lowImpactRollbacks = getRollbacksAvailableForImpactLevel( Loading @@ -198,7 +200,7 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve } else { if (rollbackReason == PackageWatchdog.FAILURE_REASON_NATIVE_CRASH) { mHandler.post(() -> rollbackAll(rollbackReason)); return true; return MITIGATION_RESULT_SUCCESS; } RollbackInfo rollback = getAvailableRollback(failedPackage); Loading @@ -210,7 +212,7 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve } // Assume rollbacks executed successfully return true; return MITIGATION_RESULT_SUCCESS; } @Override Loading @@ -226,15 +228,15 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve } @Override public boolean onExecuteBootLoopMitigation(int mitigationCount) { public int onExecuteBootLoopMitigation(int mitigationCount) { if (Flags.recoverabilityDetection()) { List<RollbackInfo> availableRollbacks = getAvailableRollbacks(); triggerLeastImpactLevelRollback(availableRollbacks, PackageWatchdog.FAILURE_REASON_BOOT_LOOP); return true; return MITIGATION_RESULT_SUCCESS; } return false; return MITIGATION_RESULT_SKIPPED; } @Override Loading
packages/CrashRecovery/services/platform/java/com/android/server/PackageWatchdog.java +93 −9 Original line number Diff line number Diff line Loading @@ -752,6 +752,70 @@ public class PackageWatchdog { return mPackagesExemptFromImpactLevelThreshold; } /** * Indicates that the result of a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} is unknown. */ public static final int MITIGATION_RESULT_UNKNOWN = ObserverMitigationResult.MITIGATION_RESULT_UNKNOWN; /** * Indicates that a mitigation was successfully triggered or executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation}. */ public static final int MITIGATION_RESULT_SUCCESS = ObserverMitigationResult.MITIGATION_RESULT_SUCCESS; /** * Indicates that a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} was skipped. */ public static final int MITIGATION_RESULT_SKIPPED = ObserverMitigationResult.MITIGATION_RESULT_SKIPPED; /** * Indicates that a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} failed, * but the failure is potentially retryable. */ public static final int MITIGATION_RESULT_FAILURE_RETRYABLE = ObserverMitigationResult.MITIGATION_RESULT_FAILURE_RETRYABLE; /** * Indicates that a mitigation executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} or * {@link PackageHealthObserver#onExecuteBootLoopMitigation} failed, * and the failure is not retryable. */ public static final int MITIGATION_RESULT_FAILURE_NON_RETRYABLE = ObserverMitigationResult.MITIGATION_RESULT_FAILURE_NON_RETRYABLE; /** * Possible return values of the for mitigations executed during * {@link PackageHealthObserver#onExecuteHealthCheckMitigation} and * {@link PackageHealthObserver#onExecuteBootLoopMitigation}. * @hide */ @Retention(SOURCE) @IntDef(prefix = "MITIGATION_RESULT_", value = { ObserverMitigationResult.MITIGATION_RESULT_UNKNOWN, ObserverMitigationResult.MITIGATION_RESULT_SUCCESS, ObserverMitigationResult.MITIGATION_RESULT_SKIPPED, ObserverMitigationResult.MITIGATION_RESULT_FAILURE_RETRYABLE, ObserverMitigationResult.MITIGATION_RESULT_FAILURE_NON_RETRYABLE, }) public @interface ObserverMitigationResult { int MITIGATION_RESULT_UNKNOWN = 0; int MITIGATION_RESULT_SUCCESS = 1; int MITIGATION_RESULT_SKIPPED = 2; int MITIGATION_RESULT_FAILURE_RETRYABLE = 3; int MITIGATION_RESULT_FAILURE_NON_RETRYABLE = 4; } /** Possible severity values of the user impact of a * {@link PackageHealthObserver#onExecuteHealthCheckMitigation}. * @hide Loading Loading @@ -809,16 +873,25 @@ public class PackageWatchdog { int mitigationCount); /** * Executes mitigation for {@link #onHealthCheckFailed}. * This would be called after {@link #onHealthCheckFailed}. * This is called only if current observer returned least impact mitigation for failed * health check. * * @param versionedPackage the package that is failing. This may be null if a native * service is crashing. * @param failureReason the type of failure that is occurring. * @param mitigationCount the number of times mitigation has been called for this package * (including this time). * @return {@code true} if action was executed successfully, {@code false} otherwise * @return {@link #MITIGATION_RESULT_SUCCESS} if the mitigation was successful, * {@link #MITIGATION_RESULT_FAILURE_RETRYABLE} if the mitigation failed but can be * retried, * {@link #MITIGATION_RESULT_FAILURE_NON_RETRYABLE} if the mitigation failed and * cannot be retried, * {@link #MITIGATION_RESULT_UNKNOWN} if the result of the mitigation is unknown, * or {@link #MITIGATION_RESULT_SKIPPED} if the mitigation was skipped. */ boolean onExecuteHealthCheckMitigation(@Nullable VersionedPackage versionedPackage, @ObserverMitigationResult int onExecuteHealthCheckMitigation( @Nullable VersionedPackage versionedPackage, @FailureReasons int failureReason, int mitigationCount); Loading @@ -834,12 +907,23 @@ public class PackageWatchdog { } /** * Executes mitigation for {@link #onBootLoop} * This would be called after {@link #onBootLoop}. * This is called only if current observer returned least impact mitigation for fixing * boot loop. * * @param mitigationCount the number of times mitigation has been attempted for this * boot loop (including this time). * * @return {@link #MITIGATION_RESULT_SUCCESS} if the mitigation was successful, * {@link #MITIGATION_RESULT_FAILURE_RETRYABLE} if the mitigation failed but can be * retried, * {@link #MITIGATION_RESULT_FAILURE_NON_RETRYABLE} if the mitigation failed and * cannot be retried, * {@link #MITIGATION_RESULT_UNKNOWN} if the result of the mitigation is unknown, * or {@link #MITIGATION_RESULT_SKIPPED} if the mitigation was skipped. */ default boolean onExecuteBootLoopMitigation(int mitigationCount) { return false; default @ObserverMitigationResult int onExecuteBootLoopMitigation(int mitigationCount) { return ObserverMitigationResult.MITIGATION_RESULT_SKIPPED; } // TODO(b/120598832): Ensure uniqueness? Loading
packages/CrashRecovery/services/platform/java/com/android/server/RescueParty.java +9 −7 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.server; import static android.provider.DeviceConfig.Properties; import static com.android.server.PackageWatchdog.MITIGATION_RESULT_SKIPPED; import static com.android.server.PackageWatchdog.MITIGATION_RESULT_SUCCESS; import static com.android.server.crashrecovery.CrashRecoveryUtils.logCrashRecoveryEvent; import android.annotation.IntDef; Loading Loading @@ -859,10 +861,10 @@ public class RescueParty { } @Override public boolean onExecuteHealthCheckMitigation(@Nullable VersionedPackage failedPackage, public int onExecuteHealthCheckMitigation(@Nullable VersionedPackage failedPackage, @FailureReasons int failureReason, int mitigationCount) { if (isDisabled()) { return false; return MITIGATION_RESULT_SKIPPED; } Slog.i(TAG, "Executing remediation." + " failedPackage: " Loading @@ -884,9 +886,9 @@ public class RescueParty { } executeRescueLevel(mContext, failedPackage == null ? null : failedPackage.getPackageName(), level); return true; return MITIGATION_RESULT_SUCCESS; } else { return false; return MITIGATION_RESULT_SKIPPED; } } Loading Loading @@ -927,9 +929,9 @@ public class RescueParty { } @Override public boolean onExecuteBootLoopMitigation(int mitigationCount) { public int onExecuteBootLoopMitigation(int mitigationCount) { if (isDisabled()) { return false; return MITIGATION_RESULT_SKIPPED; } boolean mayPerformReboot = !shouldThrottleReboot(); final int level; Loading @@ -944,7 +946,7 @@ public class RescueParty { level = getRescueLevel(mitigationCount, mayPerformReboot); } executeRescueLevel(mContext, /*failedPackage=*/ null, level); return true; return MITIGATION_RESULT_SUCCESS; } @Override Loading