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

Commit f604fc6a authored by Harshit Mahajan's avatar Harshit Mahajan
Browse files

Remove observer specific logic in PackageWatchdog

PackageWatchdog should not directly call RescueParty APIs.
Moving isRecoveryTriggeredReboot API to PackageWatchdog, as it can
return true even if RollbackPackageHealthObserver triggers reboot.

Bug: 289203818
Test: TH
Flag: android.crashrecovery.flags.synchronous_reboot_in_rescue_party
Change-Id: I26efd6731bad1419ccdbeba461b64c36b054425e
parent 55fc3d50
Loading
Loading
Loading
Loading
+19 −1
Original line number Original line Diff line number Diff line
@@ -1297,7 +1297,7 @@ public class PackageWatchdog {


    /** Dump status of every observer in mAllObservers. */
    /** Dump status of every observer in mAllObservers. */
    public void dump(@NonNull PrintWriter pw) {
    public void dump(@NonNull PrintWriter pw) {
        if (Flags.synchronousRebootInRescueParty() && RescueParty.isRecoveryTriggeredReboot()) {
        if (Flags.synchronousRebootInRescueParty() && isRecoveryTriggeredReboot()) {
            dumpInternal(pw);
            dumpInternal(pw);
        } else {
        } else {
            synchronized (mLock) {
            synchronized (mLock) {
@@ -1306,6 +1306,24 @@ public class PackageWatchdog {
        }
        }
    }
    }


    /**
     * Check if we're currently attempting to reboot during mitigation. This method must return
     * true if triggered reboot early during a boot loop, since the device will not be fully booted
     * at this time.
     * @hide
     */
    public static boolean isRecoveryTriggeredReboot() {
        return isFactoryResetPropertySet() || isRebootPropertySet();
    }

    private static boolean isFactoryResetPropertySet() {
        return CrashRecoveryProperties.attemptingFactoryReset().orElse(false);
    }

    private static boolean isRebootPropertySet() {
        return CrashRecoveryProperties.attemptingReboot().orElse(false);
    }

    private void dumpInternal(@NonNull PrintWriter pw) {
    private void dumpInternal(@NonNull PrintWriter pw) {
        IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "  ");
        IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "  ");
        ipw.println("Package Watchdog status");
        ipw.println("Package Watchdog status");