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

Commit 69136366 authored by Jeremy Wu's avatar Jeremy Wu
Browse files

UsbAlsaManager: support MULTI_DEV_MULTI_CONN_MODE

Currently, only one active connection can be recognized in the
framework, and thus when multiple eligible devices exist, the new one
has to take place of the previous one.

This CL supports all such devices to be connected simultaneously,
without maintaining the "active connection" concept, behind the flag.

Bug: 367117623
Test: m
Flag: EXEMPT sysprop ro.audio.same_type_multi_device_allowed
Change-Id: I6798fe92757ed535a368bb4cb898e3a0886890da
parent 998fc295
Loading
Loading
Loading
Loading
+31 −15
Original line number Diff line number Diff line
@@ -56,9 +56,15 @@ public final class UsbAlsaManager {

    // Flag to turn on/off multi-peripheral select mode
    // Set to true to have multi-devices mode
    private static final boolean IS_MULTI_MODE = SystemProperties.getBoolean(
    private static final boolean IS_MULTI_DEV_SINGLE_CONN_MODE = SystemProperties.getBoolean(
            "ro.audio.multi_usb_mode", false /*def*/);

    // Set to true to allow multiple usb audio connections simultaneously.
    // Note `IS_MULTI_DEV_SINGLE_CONN_MODE` allows multiple devices under ONE active connection.
    // This will override `IS_MULTI_DEV_SINGLE_CONN_MODE` if set to true.
    private static final boolean IS_MULTI_DEV_MULTI_CONN_MODE = SystemProperties.getBoolean(
            "ro.audio.same_type_multi_device_allowed", false /*def*/);

    private static final String ALSA_DIRECTORY = "/dev/snd/";

    private static final int ALSA_DEVICE_TYPE_UNKNOWN = 0;
@@ -357,7 +363,11 @@ public final class UsbAlsaManager {
                                      isInputHeadset, isOutputHeadset, isDock);
            alsaDevice.setDeviceNameAndDescription(
                    usbDevice.getProductName(), cardRec.getCardDescription());
            if (IS_MULTI_MODE) {

            // Deselect the current active audio connection to allow the new
            // device to kick in, unless multiple connections is supported.
            if (!IS_MULTI_DEV_MULTI_CONN_MODE) {
                if (IS_MULTI_DEV_SINGLE_CONN_MODE) {
                    deselectCurrentDevice(alsaDevice.getInputDeviceType());
                    deselectCurrentDevice(alsaDevice.getOutputDeviceType());
                } else {
@@ -366,6 +376,8 @@ public final class UsbAlsaManager {
                        deselectAlsaDevice(mAlsaDevices.get(0));
                    }
                }
            }

            addAlsaDevice(alsaDevice);
            selectAlsaDevice(alsaDevice);
        }
@@ -442,7 +454,10 @@ public final class UsbAlsaManager {
                waitForAlsaDevice(alsaDevice.getCardNum(), false /*isAdded*/);
            }
            deselectAlsaDevice(alsaDevice);
            if (IS_MULTI_MODE) {
            // Update the "single" active audio connection when multiple connections
            // is not supported, with the new default device.
            if (!IS_MULTI_DEV_MULTI_CONN_MODE) {
                if (IS_MULTI_DEV_SINGLE_CONN_MODE) {
                    selectDefaultDevice(alsaDevice.getOutputDeviceType());
                    selectDefaultDevice(alsaDevice.getInputDeviceType());
                } else {
@@ -452,6 +467,7 @@ public final class UsbAlsaManager {
                    }
                }
            }
        }

        // MIDI
        UsbAlsaMidiDevice midiDevice = mMidiDevices.remove(deviceAddress);