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

Commit 67f94c9d authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "AudioService: fix selection of unique device for volume control" into main

parents dafd39f3 44a25a3b
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -1134,6 +1134,9 @@ public class AudioSystem
    public static final Set<Integer> DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER_SET;
    /** @hide */
    public static final Set<Integer> DEVICE_OUT_ALL_BLE_SET;
    /** @hide */
    public static final Set<Integer> DEVICE_OUT_PICK_FOR_VOLUME_SET;

    static {
        DEVICE_OUT_ALL_SET = new HashSet<>();
        DEVICE_OUT_ALL_SET.add(DEVICE_OUT_EARPIECE);
@@ -1201,6 +1204,22 @@ public class AudioSystem
        DEVICE_OUT_ALL_BLE_SET.add(DEVICE_OUT_BLE_HEADSET);
        DEVICE_OUT_ALL_BLE_SET.add(DEVICE_OUT_BLE_SPEAKER);
        DEVICE_OUT_ALL_BLE_SET.add(DEVICE_OUT_BLE_BROADCAST);

        DEVICE_OUT_PICK_FOR_VOLUME_SET = new HashSet<>();
        DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_WIRED_HEADSET);
        DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_WIRED_HEADPHONE);
        DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_USB_DEVICE);
        DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_USB_HEADSET);
        DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLUETOOTH_A2DP);
        DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES);
        DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER);
        DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLUETOOTH_SCO);
        DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLUETOOTH_SCO_HEADSET);
        DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLUETOOTH_SCO_CARKIT);
        DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_HEARING_AID);
        DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLE_HEADSET);
        DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLE_SPEAKER);
        DEVICE_OUT_PICK_FOR_VOLUME_SET.add(DEVICE_OUT_BLE_BROADCAST);
    }

    // input devices
+4 −4
Original line number Diff line number Diff line
@@ -8030,11 +8030,11 @@ public class AudioService extends IAudioService.Stub
            } else if (deviceSet.contains(AudioSystem.DEVICE_OUT_SPDIF)) {
                return AudioSystem.DEVICE_OUT_SPDIF;
            } else {
                // At this point, deviceSet should contain exactly one A2DP device;
                // regardless, return the first A2DP device in numeric order.
                // If there is no A2DP device, this falls through to log an error.
                // At this point, deviceSet should contain exactly one removable device;
                // regardless, return the first removable device in numeric order.
                // If there is no removable device, this falls through to log an error.
                for (int deviceType : deviceSet) {
                    if (AudioSystem.DEVICE_OUT_ALL_A2DP_SET.contains(deviceType)) {
                    if (AudioSystem.DEVICE_OUT_PICK_FOR_VOLUME_SET.contains(deviceType)) {
                        return deviceType;
                    }
                }