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

Commit 01ae5f68 authored by Danny Baumann's avatar Danny Baumann
Browse files

Properly handle changes in phone audio focus.

Change-Id: I921651684f4369a47aa83e93010266c40be71a41
parent 0644dac1
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -4183,10 +4183,11 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
    private void notifyTopOfAudioFocusStack() {
        // notify the top of the stack it gained focus
        if (!mFocusStack.empty() && (mFocusStack.peek().mFocusDispatcher != null)) {
            if (canReassignAudioFocus()) {
            String clientId = mFocusStack.peek().mClientId;
            if (canReassignAudioFocusTo(clientId)) {
                try {
                    mFocusStack.peek().mFocusDispatcher.dispatchAudioFocusChange(
                            AudioManager.AUDIOFOCUS_GAIN, mFocusStack.peek().mClientId);
                            AudioManager.AUDIOFOCUS_GAIN, clientId);
                } catch (RemoteException e) {
                    Log.e(TAG, "Failure to signal gain of audio control focus due to "+ e);
                    e.printStackTrace();
@@ -4334,9 +4335,12 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
     * Helper function:
     * Returns true if the system is in a state where the focus can be reevaluated, false otherwise.
     */
    private boolean canReassignAudioFocus() {
    private boolean canReassignAudioFocusTo(String clientId) {
        // focus requests are rejected during a phone call or when the phone is ringing
        // this is equivalent to IN_VOICE_COMM_FOCUS_ID having the focus
        if (IN_VOICE_COMM_FOCUS_ID.equals(clientId)) {
            return true;
        }
        if (!mFocusStack.isEmpty() && IN_VOICE_COMM_FOCUS_ID.equals(mFocusStack.peek().mClientId)) {
            return false;
        }
@@ -4381,7 +4385,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        }

        synchronized(mAudioFocusLock) {
            if (!canReassignAudioFocus()) {
            if (!canReassignAudioFocusTo(clientId)) {
                return AudioManager.AUDIOFOCUS_REQUEST_FAILED;
            }