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

Commit abd3b061 authored by Alexei Nicoara's avatar Alexei Nicoara
Browse files

Making RescueParty reboot and factory reset synchronous.

PackageWatchdog.dump() waits on a lock which is held when RescueParty attempts remediation, making the dump not use the lock in those cases.

Bug: 328203835
Change-Id: I69aa3ef11a435d10479b8a63060699ff01647ebc
Test: presubmit
Flag: android.crashrecovery.flags.synchronous_reboot_in_rescue_party
parent 3f77dcd6
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -39,3 +39,10 @@ flag {
    bug: "289203818"
    is_fixed_read_only: true
}

flag {
    name: "synchronous_reboot_in_rescue_party"
    namespace: "modularization"
    description: "Makes reboot and factory reset synchronous in RescueParty"
    bug: "328203835"
}
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
@@ -1292,6 +1292,16 @@ public class PackageWatchdog {

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

    private void dumpInternal(@NonNull PrintWriter pw) {
        IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "  ");
        ipw.println("Package Watchdog status");
        ipw.increaseIndent();
+37 −15
Original line number Diff line number Diff line
@@ -631,6 +631,17 @@ public class RescueParty {
        // Request the reboot from a separate thread to avoid deadlock on PackageWatchdog
        // when device shutting down.
        setRebootProperty(true);

        if (Flags.synchronousRebootInRescueParty()) {
            try {
                PowerManager pm = context.getSystemService(PowerManager.class);
                if (pm != null) {
                    pm.reboot(TAG);
                }
            } catch (Throwable t) {
                logRescueException(level, failedPackage, t);
            }
        } else {
            Runnable runnable = () -> {
                try {
                    PowerManager pm = context.getSystemService(PowerManager.class);
@@ -644,6 +655,7 @@ public class RescueParty {
            Thread thread = new Thread(runnable);
            thread.start();
        }
    }

    private static void executeFactoryReset(Context context, int level,
            @Nullable String failedPackage) {
@@ -655,11 +667,20 @@ public class RescueParty {
        setFactoryResetProperty(true);
        long now = System.currentTimeMillis();
        setLastFactoryResetTimeMs(now);

        if (Flags.synchronousRebootInRescueParty()) {
            try {
                RecoverySystem.rebootPromptAndWipeUserData(context, TAG + "," + failedPackage);
            } catch (Throwable t) {
                logRescueException(level, failedPackage, t);
            }
        } else {
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    try {
                    RecoverySystem.rebootPromptAndWipeUserData(context, TAG + "," + failedPackage);
                        RecoverySystem.rebootPromptAndWipeUserData(context,
                            TAG + "," + failedPackage);
                    } catch (Throwable t) {
                        logRescueException(level, failedPackage, t);
                    }
@@ -668,6 +689,7 @@ public class RescueParty {
            Thread thread = new Thread(runnable);
            thread.start();
        }
    }


    private static String getCompleteMessage(Throwable t) {