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

Commit 051c99dc authored by Danny Baumann's avatar Danny Baumann
Browse files

Update ringer audio focus if ringer volume is changed during ringing.

AudioService only grabs the audio focus for the phone if the ringer
volume is set to something audible. If e.g. ascending ringtone is
enabled and starts at 0, the audio focus wouldn't be grabbed for the
whole ring period, leading to a mixture of played music and the
ringtone. Fix that by grabbing the audio focus if the volume is set away
from 0 while ringing.

Also attenuate music during ringing even when using silent ringtone.
Makes it more obvious to the user that something is going on.
parent 94cd3e4c
Loading
Loading
Loading
Loading
+29 −7
Original line number Diff line number Diff line
@@ -506,6 +506,15 @@ public class AudioService extends IAudioService.Stub {
            }
            index = streamState.mIndex;
        }

        if (streamType == AudioSystem.STREAM_RING) {
            synchronized(mRingingLock) {
                if (mIsRinging) {
                    updateRingingAudioFocus();
                }
            }
        }

        // UI
        showVolumeChangeUi(streamType, flags);
        // Broadcast Intent
@@ -524,6 +533,14 @@ public class AudioService extends IAudioService.Stub {

        index = (streamState.muteCount() != 0) ? streamState.mLastAudibleIndex : streamState.mIndex;

        if (streamType == AudioSystem.STREAM_RING) {
            synchronized(mRingingLock) {
                if (mIsRinging) {
                    updateRingingAudioFocus();
                }
            }
        }

        // UI, etc.
        showVolumeChangeUi(streamType, flags);
        // Broadcast Intent
@@ -2155,13 +2172,7 @@ public class AudioService extends IAudioService.Stub {
                synchronized(mRingingLock) {
                    mIsRinging = true;
                }
                int ringVolume = AudioService.this.getStreamVolume(AudioManager.STREAM_RING);
                if (ringVolume > 0) {
                    requestAudioFocus(AudioManager.STREAM_RING,
                                AudioManager.AUDIOFOCUS_GAIN_TRANSIENT,
                                null, null /* both allowed to be null only for this clientId */,
                                IN_VOICE_COMM_FOCUS_ID /*clientId*/);
                }
                updateRingingAudioFocus();
            } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
                //Log.v(TAG, " CALL_STATE_OFFHOOK");
                synchronized(mRingingLock) {
@@ -2181,6 +2192,17 @@ public class AudioService extends IAudioService.Stub {
        }
    };

    private void updateRingingAudioFocus() {
        int ringVolume = getStreamVolume(AudioManager.STREAM_RING);
        int hint = ringVolume > 0
                ? AudioManager.AUDIOFOCUS_GAIN_TRANSIENT
                : AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK;

        requestAudioFocus(AudioManager.STREAM_RING, hint,
                null, null /* both allowed to be null only for this clientId */,
                IN_VOICE_COMM_FOCUS_ID /*clientId*/);
    }

    private void notifyTopOfAudioFocusStack() {
        // notify the top of the stack it gained focus
        if (!mFocusStack.empty() && (mFocusStack.peek().mFocusDispatcher != null)) {