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

Unverified Commit b8ead3d8 authored by Vignesh Kulothungan's avatar Vignesh Kulothungan Committed by Michael Bestas
Browse files

WiredAccessoryManager: support for multiple display ports

Add support to connect more than one display port.
Map device index to stream and cable index to controller for
display ports.

CRs-Fixed: 2504389
Change-Id: I43b0478e0b21d1f36b71476d4cdb4029897ee7b8
parent 70a8d83e
Loading
Loading
Loading
Loading
+43 −5
Original line number Original line Diff line number Diff line
@@ -87,6 +87,7 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
    private final AudioManager mAudioManager;
    private final AudioManager mAudioManager;


    private int mHeadsetState;
    private int mHeadsetState;
    private int mDpCount;


    private int mSwitchValues;
    private int mSwitchValues;


@@ -210,6 +211,9 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
     * results in support for the last one plugged in. Similarly, unplugging either is seen as
     * results in support for the last one plugged in. Similarly, unplugging either is seen as
     * unplugging all.
     * unplugging all.
     *
     *
     * For Display port allow up to two connections.
     * Block display port request if HDMI already connected and vice versa.
     *
     * @param newName  One of the NAME_xxx variables defined above.
     * @param newName  One of the NAME_xxx variables defined above.
     * @param newState 0 or one of the BIT_xxx variables defined above.
     * @param newState 0 or one of the BIT_xxx variables defined above.
     * @param isSynchronous boolean to determine whether should happen sync or async
     * @param isSynchronous boolean to determine whether should happen sync or async
@@ -218,19 +222,23 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
            boolean isSynchronous) {
            boolean isSynchronous) {
        // Retain only relevant bits
        // Retain only relevant bits
        int headsetState = newState & SUPPORTED_HEADSETS;
        int headsetState = newState & SUPPORTED_HEADSETS;
        int newDpState = newState & BIT_HDMI_AUDIO;
        int usb_headset_anlg = headsetState & BIT_USB_HEADSET_ANLG;
        int usb_headset_anlg = headsetState & BIT_USB_HEADSET_ANLG;
        int usb_headset_dgtl = headsetState & BIT_USB_HEADSET_DGTL;
        int usb_headset_dgtl = headsetState & BIT_USB_HEADSET_DGTL;
        int h2w_headset = headsetState & (BIT_HEADSET | BIT_HEADSET_NO_MIC | BIT_LINEOUT);
        int h2w_headset = headsetState & (BIT_HEADSET | BIT_HEADSET_NO_MIC | BIT_LINEOUT);
        boolean h2wStateChange = true;
        boolean h2wStateChange = true;
        boolean usbStateChange = true;
        boolean usbStateChange = true;
        boolean dpBitState = (mHeadsetState & BIT_HDMI_AUDIO) > 0;
        boolean dpCountState = mDpCount != 0;
        if (LOG) {
        if (LOG) {
            Slog.v(TAG, "newName=" + newName
            Slog.v(TAG, "newName=" + newName
                    + " newState=" + newState
                    + " newState=" + newState
                    + " headsetState=" + headsetState
                    + " headsetState=" + headsetState
                    + " prev headsetState=" + mHeadsetState);
                    + " prev headsetState=" + mHeadsetState
                    + " num of active dp conns= " + mDpCount);
        }
        }


        if (mHeadsetState == headsetState) {
        if (mHeadsetState == headsetState && !newName.startsWith(NAME_DP_AUDIO)) {
            Log.e(TAG, "No state change.");
            Log.e(TAG, "No state change.");
            return;
            return;
        }
        }
@@ -253,14 +261,44 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
            return;
            return;
        }
        }


        if (newName.startsWith(NAME_DP_AUDIO)) {
            if ((newDpState > 0) && (mDpCount < DP_AUDIO_CONNS.length)
                    && (dpBitState == dpCountState)) {
                // Allow DP0 if no HDMI previously connected.
                // Allow second request only if DP connected previously.
                mDpCount++;
            } else if ((newDpState == 0) && (mDpCount > 0)) {
                mDpCount--;
            } else {
                Log.e(TAG, "No state change for DP.");
                return;
            }
        }

        if (isSynchronous) {
        if (isSynchronous) {
            setDevicesState(headsetState, mHeadsetState, "");
            setDevicesState(headsetState, mHeadsetState, "");
        } else {
        } else {
            mWakeLock.acquire();
            mWakeLock.acquire();
            Log.i(TAG, "MSG_NEW_DEVICE_STATE");
            Log.i(TAG, "MSG_NEW_DEVICE_STATE");
            // Send a combined name, address string separated by |
            // Send a combined name, address string separated by |
            Message msg = mHandler.obtainMessage(MSG_NEW_DEVICE_STATE, headsetState,
            Message msg;
            if (newName.startsWith(NAME_DP_AUDIO)) {
                int pseudoHeadsetState = mHeadsetState;
                if (dpBitState && (newDpState != 0)) {
                    // One DP already connected, so allow request to connect second.
                    pseudoHeadsetState = mHeadsetState & (~BIT_HDMI_AUDIO);
                }
                msg = mHandler.obtainMessage(MSG_NEW_DEVICE_STATE, headsetState,
                        pseudoHeadsetState, NAME_DP_AUDIO + "/" + address);

                if ((headsetState == 0) && (mDpCount != 0)) {
                    // Atleast one DP is connected, so keep mHeadsetState's DP bit set.
                    headsetState = headsetState | BIT_HDMI_AUDIO;
                }
            } else {
                msg = mHandler.obtainMessage(MSG_NEW_DEVICE_STATE, headsetState,
                        mHeadsetState, newName + "/" + address);
                        mHeadsetState, newName + "/" + address);
            }
            mHandler.sendMessage(msg);
            mHandler.sendMessage(msg);
        }
        }


@@ -570,7 +608,7 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
                        assert(idx2 != -1);
                        assert(idx2 != -1);
                        int dev = Integer.parseInt(mDevName.substring(idx + 1, idx2));
                        int dev = Integer.parseInt(mDevName.substring(idx + 1, idx2));
                        int cable = Integer.parseInt(mDevName.substring(idx2 + 1));
                        int cable = Integer.parseInt(mDevName.substring(idx2 + 1));
                        mDevAddress = "controller=" + dev + ";stream=" + cable;
                        mDevAddress = "controller=" + cable + ";stream=" + dev;
                        if (LOG) {
                        if (LOG) {
                            Slog.v(TAG, "UEvent dev address " + mDevAddress);
                            Slog.v(TAG, "UEvent dev address " + mDevAddress);
                        }
                        }