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

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

Merge "Synchronize calls to mAbsoluteDeviceInfoMap" into main

parents 7e9f598c 114f113d
Loading
Loading
Loading
Loading
+40 −17
Original line number Diff line number Diff line
@@ -783,9 +783,11 @@ public class AudioService extends IAudioService.Stub
            AudioSystem.DEVICE_OUT_HDMI_EARC
    ));
    private final Object mAbsoluteVolumeDeviceInfoMapLock = new Object();
    // Devices where the framework sends a full scale audio signal, and controls the volume of
    // the external audio system separately.
    // For possible volume behaviors, see {@link AudioManager.AbsoluteDeviceVolumeBehavior}.
    @GuardedBy("mAbsoluteVolumeDeviceInfoMapLock")
    Map<Integer, AbsoluteVolumeDeviceInfo> mAbsoluteVolumeDeviceInfoMap = new ArrayMap<>();
    /**
@@ -3715,9 +3717,8 @@ public class AudioService extends IAudioService.Stub
        int oldIndex = mStreamStates[streamType].getIndex(device);
        // Check if the volume adjustment should be handled by an absolute volume controller instead
        if (isAbsoluteVolumeDevice(device)
                && (flags & AudioManager.FLAG_ABSOLUTE_VOLUME) == 0) {
            AbsoluteVolumeDeviceInfo info = mAbsoluteVolumeDeviceInfoMap.get(device);
        if (isAbsoluteVolumeDevice(device) && (flags & AudioManager.FLAG_ABSOLUTE_VOLUME) == 0) {
            final AbsoluteVolumeDeviceInfo info = getAbsoluteVolumeDeviceInfo(device);
            if (info.mHandlesVolumeAdjustment) {
                dispatchAbsoluteVolumeAdjusted(streamType, info, oldIndex, direction,
                        keyEventMode);
@@ -3784,7 +3785,7 @@ public class AudioService extends IAudioService.Stub
                mDeviceBroker.postSetAvrcpAbsoluteVolumeIndex(newIndex / 10);
            } else if (isAbsoluteVolumeDevice(device)
                    && (flags & AudioManager.FLAG_ABSOLUTE_VOLUME) == 0) {
                AbsoluteVolumeDeviceInfo info = mAbsoluteVolumeDeviceInfoMap.get(device);
                final AbsoluteVolumeDeviceInfo info = getAbsoluteVolumeDeviceInfo(device);
                dispatchAbsoluteVolumeChanged(streamType, info, newIndex);
            }
@@ -4787,7 +4788,7 @@ public class AudioService extends IAudioService.Stub
            mDeviceBroker.postSetAvrcpAbsoluteVolumeIndex(index / 10);
        } else if (isAbsoluteVolumeDevice(device)
                && ((flags & AudioManager.FLAG_ABSOLUTE_VOLUME) == 0)) {
            AbsoluteVolumeDeviceInfo info = mAbsoluteVolumeDeviceInfoMap.get(device);
            final AbsoluteVolumeDeviceInfo info = getAbsoluteVolumeDeviceInfo(device);
            dispatchAbsoluteVolumeChanged(streamType, info, index);
        }
@@ -7575,7 +7576,8 @@ public class AudioService extends IAudioService.Stub
        if (register) {
            AbsoluteVolumeDeviceInfo info = new AbsoluteVolumeDeviceInfo(
                    device, volumes, cb, handlesVolumeAdjustment, deviceVolumeBehavior);
            AbsoluteVolumeDeviceInfo oldInfo = mAbsoluteVolumeDeviceInfoMap.get(deviceOut);
            final AbsoluteVolumeDeviceInfo oldInfo = getAbsoluteVolumeDeviceInfo(deviceOut);
            boolean volumeBehaviorChanged = (oldInfo == null)
                    || (oldInfo.mDeviceVolumeBehavior != deviceVolumeBehavior);
            if (volumeBehaviorChanged) {
@@ -7735,9 +7737,11 @@ public class AudioService extends IAudioService.Stub
        if (mAbsVolumeMultiModeCaseDevices.contains(audioSystemDeviceOut)) {
            return AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE_MULTI_MODE;
        }
        synchronized (mAbsoluteVolumeDeviceInfoMapLock) {
            if (mAbsoluteVolumeDeviceInfoMap.containsKey(audioSystemDeviceOut)) {
                return mAbsoluteVolumeDeviceInfoMap.get(audioSystemDeviceOut).mDeviceVolumeBehavior;
            }
        }
        if (isA2dpAbsoluteVolumeDevice(audioSystemDeviceOut)
                || AudioSystem.isLeAudioDeviceType(audioSystemDeviceOut)) {
@@ -11774,11 +11778,13 @@ public class AudioService extends IAudioService.Stub
    }
    private Set<Integer> getAbsoluteVolumeDevicesWithBehavior(int behavior) {
        synchronized (mAbsoluteVolumeDeviceInfoMapLock) {
            return mAbsoluteVolumeDeviceInfoMap.entrySet().stream()
                    .filter(entry -> entry.getValue().mDeviceVolumeBehavior == behavior)
                    .map(Map.Entry::getKey)
                    .collect(Collectors.toSet());
        }
    }
    private String dumpDeviceTypes(@NonNull Set<Integer> deviceTypes) {
        Iterator<Integer> it = deviceTypes.iterator();
@@ -14269,16 +14275,28 @@ public class AudioService extends IAudioService.Stub
        return mFullVolumeDevices.contains(deviceType);
    }
    /**
     * Returns the input device which uses absolute volume behavior, including its variants,
     * or {@code null} if there is no mapping for the device type
     */
    @Nullable
    private AbsoluteVolumeDeviceInfo getAbsoluteVolumeDeviceInfo(int deviceType) {
        synchronized (mAbsoluteVolumeDeviceInfoMapLock) {
            return mAbsoluteVolumeDeviceInfoMap.get(deviceType);
        }
    }
    /**
     * Returns whether the input device uses absolute volume behavior, including its variants.
     * For included volume behaviors, see {@link AudioManager.AbsoluteDeviceVolumeBehavior}.
     *
     * This is distinct from Bluetooth A2DP absolute volume behavior
     * <p>This is distinct from Bluetooth A2DP absolute volume behavior
     * ({@link #isA2dpAbsoluteVolumeDevice}).
     */
    private boolean isAbsoluteVolumeDevice(int deviceType) {
        synchronized (mAbsoluteVolumeDeviceInfoMapLock) {
            return mAbsoluteVolumeDeviceInfoMap.containsKey(deviceType);
        }
    }
    /**
     * Returns whether the input device is a Bluetooth A2dp device that uses absolute volume
@@ -14389,8 +14407,10 @@ public class AudioService extends IAudioService.Stub
                    + AudioDeviceVolumeManager.volumeBehaviorName(info.mDeviceVolumeBehavior)
            );
        }
        synchronized (mAbsoluteVolumeDeviceInfoMapLock) {
            mAbsoluteVolumeDeviceInfoMap.put(audioSystemDeviceOut, info);
        }
    }
    private AbsoluteVolumeDeviceInfo removeAudioSystemDeviceOutFromAbsVolumeDevices(
            int audioSystemDeviceOut) {
@@ -14398,8 +14418,11 @@ public class AudioService extends IAudioService.Stub
            Log.d(TAG, "Removing DeviceType: 0x" + Integer.toHexString(audioSystemDeviceOut)
                    + " from mAbsoluteVolumeDeviceInfoMap");
        }
        synchronized (mAbsoluteVolumeDeviceInfoMapLock) {
            return mAbsoluteVolumeDeviceInfoMap.remove(audioSystemDeviceOut);
        }
    }
    //====================
    // Helper functions for app ops