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

Commit 4bdbe063 authored by JW Wang's avatar JW Wang Committed by Android (Google) Code Review
Browse files

Merge "Revert "Give Watchdog a lock (1/n)""

parents e21b79f5 cec994af
Loading
Loading
Loading
Loading
+13 −15
Original line number Diff line number Diff line
@@ -131,8 +131,6 @@ public class Watchdog extends Thread {

    private static Watchdog sWatchdog;

    private final Object mLock = new Object();

    /* This handler will be used to post message back onto the main thread */
    private final ArrayList<HandlerChecker> mHandlerCheckers = new ArrayList<>();
    private final HandlerChecker mMonitorChecker;
@@ -242,13 +240,13 @@ public class Watchdog extends Thread {
            // point we have completed execution of this method.
            final int size = mMonitors.size();
            for (int i = 0 ; i < size ; i++) {
                synchronized (mLock) {
                synchronized (Watchdog.this) {
                    mCurrentMonitor = mMonitors.get(i);
                }
                mCurrentMonitor.monitor();
            }

            synchronized (mLock) {
            synchronized (Watchdog.this) {
                mCompleted = true;
                mCurrentMonitor = null;
            }
@@ -379,7 +377,7 @@ public class Watchdog extends Thread {
    public void processStarted(String processName, int pid) {
        if (isInterestingJavaProcess(processName)) {
            Slog.i(TAG, "Interesting Java process " + processName + " started. Pid " + pid);
            synchronized (mLock) {
            synchronized (this) {
                mInterestingJavaPids.add(pid);
            }
        }
@@ -391,26 +389,26 @@ public class Watchdog extends Thread {
    public void processDied(String processName, int pid) {
        if (isInterestingJavaProcess(processName)) {
            Slog.i(TAG, "Interesting Java process " + processName + " died. Pid " + pid);
            synchronized (mLock) {
            synchronized (this) {
                mInterestingJavaPids.remove(Integer.valueOf(pid));
            }
        }
    }

    public void setActivityController(IActivityController controller) {
        synchronized (mLock) {
        synchronized (this) {
            mController = controller;
        }
    }

    public void setAllowRestart(boolean allowRestart) {
        synchronized (mLock) {
        synchronized (this) {
            mAllowRestart = allowRestart;
        }
    }

    public void addMonitor(Monitor monitor) {
        synchronized (mLock) {
        synchronized (this) {
            mMonitorChecker.addMonitorLocked(monitor);
        }
    }
@@ -420,7 +418,7 @@ public class Watchdog extends Thread {
    }

    public void addThread(Handler thread, long timeoutMillis) {
        synchronized (mLock) {
        synchronized (this) {
            final String name = thread.getLooper().getThread().getName();
            mHandlerCheckers.add(new HandlerChecker(thread, name, timeoutMillis));
        }
@@ -440,7 +438,7 @@ public class Watchdog extends Thread {
     * pauses have been resumed.
     */
    public void pauseWatchingCurrentThread(String reason) {
        synchronized (mLock) {
        synchronized (this) {
            for (HandlerChecker hc : mHandlerCheckers) {
                if (Thread.currentThread().equals(hc.getThread())) {
                    hc.pauseLocked(reason);
@@ -462,7 +460,7 @@ public class Watchdog extends Thread {
     * as many times as the calls to pause.
     */
    public void resumeWatchingCurrentThread(String reason) {
        synchronized (mLock) {
        synchronized (this) {
            for (HandlerChecker hc : mHandlerCheckers) {
                if (Thread.currentThread().equals(hc.getThread())) {
                    hc.resumeLocked(reason);
@@ -559,7 +557,7 @@ public class Watchdog extends Thread {
            final String subject;
            final boolean allowRestart;
            int debuggerWasConnected = 0;
            synchronized (mLock) {
            synchronized (this) {
                long timeout = CHECK_INTERVAL;
                // Make sure we (re)spin the checkers that have become idle within
                // this wait-and-check interval
@@ -582,7 +580,7 @@ public class Watchdog extends Thread {
                        debuggerWasConnected = 2;
                    }
                    try {
                        mLock.wait(timeout);
                        wait(timeout);
                        // Note: mHandlerCheckers and mMonitorChecker may have changed after waiting
                    } catch (InterruptedException e) {
                        Log.wtf(TAG, e);
@@ -680,7 +678,7 @@ public class Watchdog extends Thread {
            } catch (InterruptedException ignored) {}

            IActivityController controller;
            synchronized (mLock) {
            synchronized (this) {
                controller = mController;
            }
            if (controller != null) {