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

Commit 3af7ee5c authored by Ryan Shih's avatar Ryan Shih Committed by Jan Altensen
Browse files

Remove redundant broadcasts when adjusting volume on single volume devices

Bug: b/165476835
Bug: b/249452979
Bug: b/289987890

Test: Adjust volume while playing Netflix stream

Change-Id: Iedbd02e28786c5585836de1e706d72e36d8a1bbb
Merged-In: Iedbd02e28786c5585836de1e706d72e36d8a1bbb
parent b2a98be7
Loading
Loading
Loading
Loading
+28 −8
Original line number Diff line number Diff line
@@ -4575,6 +4575,17 @@ public class AudioService extends IAudioService.Stub
        return UserHandle.USER_SYSTEM;
    }
    private void sendVolumeChangedIntent(Intent intent, int streamType, int oldIndex, int index) {
        intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, streamType);
        intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, index);
        intent.putExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, oldIndex);
        intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE_ALIAS,
                mStreamVolumeAlias[streamType]);
        AudioService.sVolumeLogger.log(new VolChangedBroadcastEvent(
                streamType, mStreamVolumeAlias[streamType], index));
        sendBroadcastToAll(intent);
    }
    // UI update and Broadcast Intent
    protected void sendVolumeUpdate(int streamType, int oldIndex, int index, int flags, int device)
    {
@@ -4584,6 +4595,20 @@ public class AudioService extends IAudioService.Stub
            flags &= ~AudioManager.FLAG_SHOW_UI;
        }
        mVolumeController.postVolumeChanged(streamType, flags);
        if (mIsSingleVolume) {
            if ((flags & AudioManager.FLAG_FIXED_VOLUME) == 0) {
                oldIndex = (oldIndex + 5) / 10;
                index = (index + 5) / 10;
                // log base stream changes to the event log
                if (mStreamVolumeAlias[streamType] == streamType) {
                    EventLogTags.writeVolumeChanged(streamType, oldIndex, index,
                            MAX_STREAM_VOLUME[streamType], "isSingleVolume=true");
                }
                Intent intent = new Intent(AudioManager.VOLUME_CHANGED_ACTION);
                sendVolumeChangedIntent(intent, streamType, oldIndex, index);
            }
        }
    }
    // Don't show volume UI when:
@@ -8312,7 +8337,8 @@ public class AudioService extends IAudioService.Stub
                    }
                }
            }
            if (changed) {
            if (changed && !mIsSingleVolume) {
                // If associated to volume group, update group cache
                updateVolumeGroupIndex(device, /* forceMuteState= */ false);
@@ -8329,13 +8355,7 @@ public class AudioService extends IAudioService.Stub
                // fire changed intents for all streams, but only when the device it changed on
                // is the current device
                if ((index != oldIndex) && isCurrentDevice) {
                    mVolumeChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, index);
                    mVolumeChanged.putExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, oldIndex);
                    mVolumeChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE_ALIAS,
                            mStreamVolumeAlias[mStreamType]);
                    AudioService.sVolumeLogger.log(new VolChangedBroadcastEvent(
                            mStreamType, mStreamVolumeAlias[mStreamType], index));
                    sendBroadcastToAll(mVolumeChanged);
                    sendVolumeChangedIntent(mVolumeChanged, mStreamType, oldIndex, index);
                }
            }
            return changed;