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

Commit 86f10baf authored by Alexei Nicoara's avatar Alexei Nicoara Committed by Android (Google) Code Review
Browse files

Merge "Making RescueParty reboot and factory reset synchronous." into main

parents 83666295 abd3b061
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) {