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

Commit fab5c95a authored by JW Wang's avatar JW Wang
Browse files

Don't extend Thread (1/n)

Per discussion of b/153696222#comment3, remove Thread from the super
class of Watchdog.

This prevents that some arbitrary code calls thread API like #interrupt
and causes unexpected trouble.

Bug: 153696222
Test: m
Change-Id: Ic3030ad9f83e508e0b747b0c22a1bcd3c6be329b
parent d2368f0d
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ import java.util.HashSet;
import java.util.List;

/** This class calls its monitor every minute. Killing this process if they don't return **/
public class Watchdog extends Thread {
public class Watchdog {
    static final String TAG = "Watchdog";

    /** Debug flag. */
@@ -131,6 +131,8 @@ public class Watchdog extends Thread {

    private static Watchdog sWatchdog;

    private final Thread mThread;

    /* This handler will be used to post message back onto the main thread */
    private final ArrayList<HandlerChecker> mHandlerCheckers = new ArrayList<>();
    private final HandlerChecker mMonitorChecker;
@@ -310,7 +312,7 @@ public class Watchdog extends Thread {
    }

    private Watchdog() {
        super("watchdog");
        mThread = new Thread(this::run, "watchdog");
        // Initialize handler checkers for each common thread we want to check.  Note
        // that we are not currently checking the background thread, since it can
        // potentially hold longer running operations with no guarantees about the timeliness
@@ -353,6 +355,13 @@ public class Watchdog extends Thread {
                DEFAULT_TIMEOUT > ZygoteConnectionConstants.WRAPPED_PID_TIMEOUT_MILLIS;
    }

    /**
     * Called by SystemServer to cause the internal thread to begin execution.
     */
    public void start() {
        mThread.start();
    }

    /**
     * Registers a {@link BroadcastReceiver} to listen to reboot broadcasts and trigger reboot.
     * Should be called during boot after the ActivityManagerService is up and registered
@@ -549,8 +558,7 @@ public class Watchdog extends Thread {
        return pids;
    }

    @Override
    public void run() {
    private void run() {
        boolean waitedHalf = false;
        while (true) {
            final List<HandlerChecker> blockedCheckers;