Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5f5161f6 authored by Harshit Mahajan's avatar Harshit Mahajan Committed by Android (Google) Code Review
Browse files

Merge "Return detailed codes while executing mitigations" into main

parents 559895c2 96ce823a
Loading
Loading
Loading
Loading
+85 −8
Original line number Diff line number Diff line
@@ -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.
@@ -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);


@@ -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?
+9 −7
Original line number Diff line number Diff line
@@ -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;
@@ -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: "
@@ -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;
            }
        }

@@ -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;
@@ -813,7 +815,7 @@ public class RescueParty {
                level = getRescueLevel(mitigationCount, mayPerformReboot);
            }
            executeRescueLevel(mContext, /*failedPackage=*/ null, level);
            return true;
            return MITIGATION_RESULT_SUCCESS;
        }

        @Override
+9 −7
Original line number Diff line number Diff line
@@ -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;
@@ -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: "
@@ -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(
@@ -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);
@@ -210,7 +212,7 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve
        }

        // Assume rollbacks executed successfully
        return true;
        return MITIGATION_RESULT_SUCCESS;
    }

    @Override
@@ -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
+93 −9
Original line number Diff line number Diff line
@@ -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
@@ -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);


@@ -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?
+9 −7
Original line number Diff line number Diff line
@@ -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;
@@ -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: "
@@ -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;
            }
        }

@@ -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;
@@ -944,7 +946,7 @@ public class RescueParty {
                level = getRescueLevel(mitigationCount, mayPerformReboot);
            }
            executeRescueLevel(mContext, /*failedPackage=*/ null, level);
            return true;
            return MITIGATION_RESULT_SUCCESS;
        }

        @Override
Loading