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

Commit 211e0301 authored by Haofan Wang's avatar Haofan Wang
Browse files

[0001] Fix segfault from double tuner closure

The JNI nativeClose() does not support closing twice. The tuner SP is
set to null. On the second usage, it derefs it. Although the app
shouldn't close the tuner twice, it solves the double close() issue from
the CTS.

Bug: 356779633
Test: atest android.media.tv.tuner.cts.TunerTest on cuttlefish
Flag: EXEMPT bugfix

(cherry picked from https://android-review.googlesource.com/q/commit:394903a386df2289c8320e9566f7396730a16c12)
Merged-In: Ie4abdc5bf6cdcc6265383a76cfa671e06accc1a2
Change-Id: Ie4abdc5bf6cdcc6265383a76cfa671e06accc1a2
parent cdd46583
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -288,6 +288,7 @@ public class Tuner implements AutoCloseable {
    private static int sTunerVersion = TunerVersionChecker.TUNER_VERSION_UNKNOWN;
    private DemuxInfo mDesiredDemuxInfo = new DemuxInfo(Filter.TYPE_UNDEFINED);

    private boolean mClosed = false;
    private Frontend mFrontend;
    private EventHandler mHandler;
    @Nullable
@@ -813,6 +814,9 @@ public class Tuner implements AutoCloseable {
     */
    @Override
    public void close() {
        if (mClosed) {
            return;
        }
        acquireTRMSLock("close()");
        try {
            releaseAll();
@@ -820,6 +824,7 @@ public class Tuner implements AutoCloseable {
            TunerUtils.throwExceptionForResult(nativeClose(), "failed to close tuner");
        } finally {
            releaseTRMSLock();
            mClosed = true;
        }
    }