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

Commit 084877b1 authored by Mingming Yin's avatar Mingming Yin Committed by Steve Kondik
Browse files

audio: Manage audio focus for QCHAT

- Cherry-picked from the commit with commit ID:
c14c6156e879ec1c3f83f6a2cc31dac1d22147a2
- FR-fixed: 8965

Change-Id: I51c554b82c6177b7d3e845bdc8970825b5d1198a
parent 737ff0b2
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -4690,6 +4690,25 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        return true;
    }

    /* Constant to identify focus stack entry that is used to hold the audio focus for QCHAT client
     */
    private static final String CLIENT_ID_QCHAT = "QCHAT";

    /**
     * Helper function:
     * Returns true if the system is in a state where the focus can be reevaluated, false otherwise.
     */
    private boolean canReassignAudioFocusFromQchat(int streamType, String clientId) {
        // Focus request is rejected for Music Player and for QChat client if the focus is already
        // acquired by a QChat client
        if (!mFocusStack.isEmpty() &&
            mFocusStack.peek().mClientId.contains(CLIENT_ID_QCHAT) &&
            (clientId.contains(CLIENT_ID_QCHAT) || (streamType == AudioManager.STREAM_MUSIC))) {
            return false;
        }
        return true;
    }

    /**
     * Inner class to monitor audio focus client deaths, and remove them from the audio focus
     * stack if necessary.
@@ -4731,6 +4750,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
            if (!canReassignAudioFocusTo(clientId)) {
                return AudioManager.AUDIOFOCUS_REQUEST_FAILED;
            }
            if (!canReassignAudioFocusFromQchat(mainStreamType, clientId)) {
                return AudioManager.AUDIOFOCUS_REQUEST_FAILED;
            }

            // handle the potential premature death of the new holder of the focus
            // (premature death == death before abandoning focus)