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

Commit 6701bd7c authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Synchronize calls to mAbsoluteDeviceInfoMap" into main am: afddcaf9

parents 4685a424 afddcaf9
Loading
Loading
Loading
Loading
+40 −17
Original line number Diff line number Diff line
@@ -787,9 +787,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<>();
    /**
@@ -3729,9 +3731,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);
@@ -3798,7 +3799,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);
            }
@@ -4801,7 +4802,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);
        }
@@ -7603,7 +7604,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) {
@@ -7763,9 +7765,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)) {
@@ -11806,11 +11810,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();
@@ -14301,16 +14307,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
@@ -14421,8 +14439,10 @@ public class AudioService extends IAudioService.Stub
                    + AudioDeviceVolumeManager.volumeBehaviorName(info.mDeviceVolumeBehavior)
            );
        }
        synchronized (mAbsoluteVolumeDeviceInfoMapLock) {
            mAbsoluteVolumeDeviceInfoMap.put(audioSystemDeviceOut, info);
        }
    }
    private AbsoluteVolumeDeviceInfo removeAudioSystemDeviceOutFromAbsVolumeDevices(
            int audioSystemDeviceOut) {
@@ -14430,8 +14450,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