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

Commit ca6cce5a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix deadlock between TRMS lock and Tuner.mLnbLock" into main

parents eff334da 6c77eb3c
Loading
Loading
Loading
Loading
+20 −16
Original line number Diff line number Diff line
@@ -264,6 +264,25 @@ public class Lnb implements AutoCloseable {
        }
    }

    /* package */ void closeInternal() {
        synchronized (mLock) {
            if (mIsClosed) {
                return;
            }
            int res = nativeClose();
            if (res != Tuner.RESULT_SUCCESS) {
                TunerUtils.throwExceptionForResult(res, "Failed to close LNB");
            } else {
                mIsClosed = true;
                if (mOwner != null) {
                    mOwner.releaseLnb();
                    mOwner = null;
                }
                mCallbackMap.clear();
            }
        }
    }

    /**
     * Sets the LNB's power voltage.
     *
@@ -330,22 +349,7 @@ public class Lnb implements AutoCloseable {
    public void close() {
        acquireTRMSLock("close()");
        try {
            synchronized (mLock) {
                if (mIsClosed) {
                    return;
                }
                int res = nativeClose();
                if (res != Tuner.RESULT_SUCCESS) {
                    TunerUtils.throwExceptionForResult(res, "Failed to close LNB");
                } else {
                    mIsClosed = true;
                    if (mOwner != null) {
                        mOwner.releaseLnb();
                        mOwner = null;
                    }
                    mCallbackMap.clear();
                }
            }
            closeInternal();
        } finally {
            releaseTRMSLock();
        }
+5 −4
Original line number Diff line number Diff line
@@ -919,7 +919,7 @@ public class Tuner implements AutoCloseable {
                if (DEBUG) {
                    Log.d(TAG, "calling mLnb.close() : " + mClientId);
                }
                mLnb.close();
                mLnb.closeInternal();
            } else {
                if (DEBUG) {
                    Log.d(TAG, "NOT calling mLnb.close() : " + mClientId);
@@ -2353,6 +2353,7 @@ public class Tuner implements AutoCloseable {
    @Nullable
    public Lnb openLnbByName(@NonNull String name, @CallbackExecutor @NonNull Executor executor,
            @NonNull LnbCallback cb) {
        acquireTRMSLock("openLnbByName");
        mLnbLock.lock();
        try {
            Objects.requireNonNull(name, "LNB name must not be null");
@@ -2361,7 +2362,7 @@ public class Tuner implements AutoCloseable {
            Lnb newLnb = nativeOpenLnbByName(name);
            if (newLnb != null) {
                if (mLnb != null) {
                    mLnb.close();
                    mLnb.closeInternal();
                    mLnbHandle = null;
                }
                mLnb = newLnb;
@@ -2372,6 +2373,7 @@ public class Tuner implements AutoCloseable {
            }
            return mLnb;
        } finally {
            releaseTRMSLock();
            mLnbLock.unlock();
        }
    }
@@ -2789,8 +2791,8 @@ public class Tuner implements AutoCloseable {
        }
    }

    // Must be called while TRMS lock is being held
    /* package */ void releaseLnb() {
        acquireTRMSLock("releaseLnb()");
        mLnbLock.lock();
        try {
            if (mLnbHandle != null) {
@@ -2807,7 +2809,6 @@ public class Tuner implements AutoCloseable {
            }
            mLnb = null;
        } finally {
            releaseTRMSLock();
            mLnbLock.unlock();
        }
    }