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

Commit d3a35ef3 authored by jiabin's avatar jiabin
Browse files

Use atomic boolean for stop jack detection.

This can help avoid deadlock between jack detection thread and the
device detection thread.

Bug: 410458709
Test: make
Flag: EXEMPT bugfix
Change-Id: I335ee036e943ae3fb412657fb7c127eba6dc9809
parent 734bc03e
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.usb;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Detects and reports ALSA jack state and events.
 */
@@ -27,7 +29,7 @@ public final class UsbAlsaJackDetector implements Runnable {
    private native boolean nativeOutputJackConnected(int card);
    private native boolean nativeInputJackConnected(int card);

    private boolean mStopJackDetect = false;
    private AtomicBoolean mStopJackDetect = new AtomicBoolean(false);
    private UsbAlsaDevice mAlsaDevice;

    /* use startJackDetect to create a UsbAlsaJackDetector */
@@ -67,9 +69,7 @@ public final class UsbAlsaJackDetector implements Runnable {
     * locking issues), but will cause the thread to exit at the next safe opportunity.
     */
    public void pleaseStop() {
        synchronized (this) {
            mStopJackDetect = true;
        }
        mStopJackDetect.set(true);
    }

    /**
@@ -78,7 +78,7 @@ public final class UsbAlsaJackDetector implements Runnable {
     */
    public boolean jackDetectCallback() {
        synchronized (this) {
            if (mStopJackDetect) {
            if (mStopJackDetect.get()) {
                return false;
            }
            mAlsaDevice.updateOutputWiredDeviceConnectionState(true);