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

Commit e41dc596 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Yell if NDC callers are holding bad locks.

The current MountService design heavily depends on down-callers not
holding any locks, since the vast majority of events are unsolicited
and bubble up to the framework.

This simple API gives us an easy way to track down people calling
while holding a lock they shouldn't be.

Bug: 25443096
Change-Id: Ifcbda95f00d5be8c1b88d58ca67927e76c713c3e
parent 5a9bb745
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1440,6 +1440,7 @@ class MountService extends IMountService.Stub
        mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG, 25,
                null);
        mConnector.setDebug(true);
        mConnector.setLockWarning(mLock);

        Thread thread = new Thread(mConnector, VOLD_TAG);
        thread.start();
+14 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.os.Message;
import android.os.PowerManager;
import android.os.SystemClock;
import android.util.LocalLog;
import android.util.Log;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
@@ -57,6 +58,7 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo
    private LocalLog mLocalLog;

    private volatile boolean mDebug = false;
    private volatile Object mLockWarning;

    private final ResponseQueue mResponseQueue;

@@ -107,6 +109,14 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo
        mDebug = debug;
    }

    /**
     * Yell loudly if someone tries making future {@link #execute(Command)} calls while holding a
     * lock on the given object.
     */
    public void setLockWarning(Object lockWarning) {
        mLockWarning = lockWarning;
    }

    @Override
    public void run() {
        mCallbackHandler = new Handler(mLooper, this);
@@ -394,6 +404,10 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo
     */
    public NativeDaemonEvent[] executeForList(long timeoutMs, String cmd, Object... args)
            throws NativeDaemonConnectorException {
        if (mLockWarning != null && Thread.holdsLock(mLockWarning)) {
            Log.wtf(TAG, "Calling thread is holding lock " + mLockWarning, new Throwable());
        }

        final long startTime = SystemClock.elapsedRealtime();

        final ArrayList<NativeDaemonEvent> events = Lists.newArrayList();