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

Commit 97f476b0 authored by Vlad Popa's avatar Vlad Popa Committed by Android (Google) Code Review
Browse files

Merge "Add mute state to the absolute volume callback" into main

parents 1eb4fff8 e79af72c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1473,7 +1473,7 @@ public class AudioDeviceBroker {
    }

    /*package*/ int getVolumeForDeviceIgnoreMute(int streamType, int device) {
        return mAudioService.getVolumeForDeviceIgnoreMute(streamType, device);
        return mAudioService.getVolumeForDevice(streamType, device).first;
    }

    /*package*/ int getMaxVssVolumeForStream(int streamType) {
+28 −16
Original line number Diff line number Diff line
@@ -246,6 +246,7 @@ import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.IntArray;
import android.util.Log;
import android.util.Pair;
import android.util.PrintWriterPrinter;
import android.util.Slog;
import android.util.SparseArray;
@@ -542,9 +543,13 @@ public class AudioService extends IAudioService.Stub
     */
    private InputDeviceVolumeHelper mInputDeviceVolumeHelper;
    /*package*/ int getVolumeForDeviceIgnoreMute(int stream, int device) {
    /** Returns a pair of volume and mute state for the given stream and device. */
    /*package*/ Pair<Integer, Boolean> getVolumeForDevice(int stream, int device) {
        final VolumeStreamState streamState = mStreamStates.get(stream);
        return streamState != null ? streamState.getIndex(device) : -1;
        if (streamState == null) {
            return new Pair<>(-1, false);
        }
        return new Pair<>(streamState.getIndex(device), streamState.mIsMuted);
    }
    /**
@@ -4260,9 +4265,9 @@ public class AudioService extends IAudioService.Stub
                        0);
            }
            handleAbsoluteVolume(streamType, streamTypeAlias, deviceAttr,
                    getVssForStreamOrDefault(streamType).getIndex(deviceType),
                    flags);
            final boolean muted = streamState.mIsMuted;
            final int index = streamState.getIndex(deviceType);
            handleAbsoluteVolume(streamType, streamTypeAlias, deviceAttr, index, muted, flags);
        }
        final int newIndex = getVssForStreamOrDefault(streamType).getIndex(deviceType);
@@ -4336,7 +4341,7 @@ public class AudioService extends IAudioService.Stub
    }
    private boolean handleAbsoluteVolume(int streamType, int streamTypeAlias,
            @NonNull AudioDeviceAttributes ada, int newIndex, int flags) {
            @NonNull AudioDeviceAttributes ada, int newIndex, boolean muted, int flags) {
            // Check if volume update should be handled by an external volume controller
        boolean registeredAsAbsoluteVolume = false;
        boolean volumeHandled = false;
@@ -4351,7 +4356,7 @@ public class AudioService extends IAudioService.Stub
                info = getAbsoluteVolumeDeviceInfo(deviceType);
            }
            if (info != null) {
                dispatchAbsoluteVolumeChanged(streamType, info, newIndex);
                dispatchAbsoluteVolumeChanged(streamType, info, newIndex, muted);
                registeredAsAbsoluteVolume = true;
                volumeHandled = true;
            }
@@ -5344,8 +5349,10 @@ public class AudioService extends IAudioService.Stub
        final AudioDeviceAttributes device = absVolumeDevices.toArray(
                new AudioDeviceAttributes[0])[0];
        final int index = (getVolumeForDeviceIgnoreMute(streamType, device.getInternalType()) + 5)
                / 10;
        final Pair<Integer, Boolean> volumePair = getVolumeForDevice(streamType,
                device.getInternalType());
        final int index = (volumePair.first + 5) / 10;
        final boolean muted = volumePair.second;
        if (DEBUG_VOL) {
            Slog.i(TAG, "onUpdateContextualVolumes streamType: " + streamType
@@ -5355,7 +5362,8 @@ public class AudioService extends IAudioService.Stub
        final int streamTypeAlias = sStreamVolumeAlias.get(streamType, /*valueIfKeyNotFound*/
                streamType);
        if (!handleAbsoluteVolume(streamType, streamTypeAlias, device, index * 10, /*flags=*/0)) {
        if (!handleAbsoluteVolume(streamType, streamTypeAlias, device, index * 10, muted, /*flags=*/
                0)) {
            return;
        }
@@ -5446,16 +5454,17 @@ public class AudioService extends IAudioService.Stub
            }
        }
        final boolean muted = streamState.mIsMuted;
        if (!mSoundDoseHelper.willDisplayWarningAfterCheckVolume(streamType, index,
                deviceType, flags)) {
            onSetStreamVolume(streamType, index, flags, deviceType, caller, hasModifyAudioSettings,
                    // ada is non-null when called from setDeviceVolume,
                    // which shouldn't update the mute state
                    canChangeMuteAndUpdateController /*canChangeMute*/);
            index = getVssForStreamOrDefault(streamType).getIndex(deviceType);
            index = streamState.getIndex(deviceType);
        }
        handleAbsoluteVolume(streamType, streamTypeAlias, deviceAttr, index, flags);
        handleAbsoluteVolume(streamType, streamTypeAlias, deviceAttr, index, muted, flags);
        synchronized (mHdmiClientLock) {
            if (streamTypeAlias == AudioSystem.STREAM_MUSIC
@@ -5471,14 +5480,17 @@ public class AudioService extends IAudioService.Stub
    }
    private void dispatchAbsoluteVolumeChanged(int streamType, AbsoluteVolumeDeviceInfo deviceInfo,
            int index) {
            int index, boolean muted) {
        VolumeInfo volumeInfo = deviceInfo.getMatchingVolumeInfoForStream(streamType);
        if (volumeInfo != null) {
            try {
                VolumeInfo.Builder volInfoBuilder = new VolumeInfo.Builder(volumeInfo)
                        .setVolumeIndex(rescaleIndex(index, streamType, volumeInfo));
                if (unifyAbsoluteVolumeManagement()) {
                    volInfoBuilder.setMuted(muted);
                }
                deviceInfo.mCallback.dispatchDeviceVolumeChanged(deviceInfo.mDevice,
                        new VolumeInfo.Builder(volumeInfo)
                                .setVolumeIndex(rescaleIndex(index, streamType, volumeInfo))
                                .build());
                        volInfoBuilder.build());
            } catch (RemoteException e) {
                Log.w(TAG, "Couldn't dispatch absolute volume behavior volume change");
            }
+4 −2
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.util.MathUtils;
import android.util.Pair;
import android.util.SparseIntArray;

import com.android.internal.R;
@@ -724,8 +725,9 @@ public class SoundDoseHelper {
                int device = mAudioService.getDeviceForStream(AudioSystem.STREAM_MUSIC);
                if (safeDevicesContains(device) && isStreamActive) {
                    scheduleMusicActiveCheck();
                    int index = mAudioService.getVolumeForDeviceIgnoreMute(AudioSystem.STREAM_MUSIC,
                            device);
                    final Pair<Integer, Boolean> volumePair = mAudioService.getVolumeForDevice(
                            AudioSystem.STREAM_MUSIC, device);
                    final int index = volumePair.second ? 0 : volumePair.first;
                    if (index > safeMediaVolumeIndex(device)) {
                        // Approximate cumulative active music time
                        long curTimeMs = SystemClock.elapsedRealtime();
+3 −2
Original line number Diff line number Diff line
@@ -253,7 +253,7 @@ public class AbsoluteVolumeBehaviorTest {

        // Dispatched volume index is scaled to the range in the initial VolumeInfo
        verify(mMockDispatcher).dispatchDeviceVolumeChanged(DEVICE_SPEAKER_OUT,
                new VolumeInfo.Builder(volumeInfo).setVolumeIndex(250).build());
                new VolumeInfo.Builder(volumeInfo).setVolumeIndex(250).setMuted(false).build());
    }

    @Test
@@ -401,6 +401,7 @@ public class AbsoluteVolumeBehaviorTest {
        verify(mMockDispatcher, never()).dispatchDeviceVolumeChanged(eq(DEVICE_SPEAKER_OUT), any());
        // Volume changed dispatched for adjust-only absolute volume listener
        verify(mMockAdjustOnlyAbsoluteVolumeDispatcher).dispatchDeviceVolumeChanged(
                DEVICE_SPEAKER_OUT, new VolumeInfo.Builder(volumeInfo).setVolumeIndex(250).build());
                DEVICE_SPEAKER_OUT, new VolumeInfo.Builder(volumeInfo).setVolumeIndex(250).setMuted(
                        false).build());
    }
}