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

Commit 89d0c849 authored by jiabin's avatar jiabin
Browse files

Update logic for determining if an USB device is a headset or not.

Update the function of calculating likelihood of being an output
headset.
1. Change the function name from probability to likelihood. It is fine
   to have the value be negative or greater than 1.0f.
2. If there is an output terminal with type as HEADPHONES or
   BIDIR_HEADSET, likelihood += 0.75, goto 5. Otherwise, goto 2.
3. If there is an output terminal with type as SPEAKER,
   likelihood += 0.5. Goto 3.
4. If there is associated input terminal for an output terminal exists,
   likelihood += 0.25. Goto 4.
5. If multiple channels are supported, likelihood -= 0.25. Goto 5.
6. If there is an output terminal with type as SPEAKER, HEADPHONES or
   BIDIR_HEADSET and there is HID interface, likelihood += 0.25.

Test: connect USB devices and check the reported device type.
Bug: 231973571
Change-Id: I98e433b5333f8bb317b6ae89bd65fee2c42236eb
parent f749b885
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import com.android.server.usb.descriptors.report.ReportCanvas;
 * An audio class-specific Input Terminal interface.
 * see audio10.pdf section 4.3.2.1
 */
public final class Usb10ACInputTerminal extends UsbACTerminal {
public final class Usb10ACInputTerminal extends UsbACTerminal implements UsbAudioChannelCluster {
    private static final String TAG = "Usb10ACInputTerminal";

    private byte mNrChannels;       // 7:1 1 Channel (0x01)
@@ -36,14 +36,17 @@ public final class Usb10ACInputTerminal extends UsbACTerminal {
        super(length, type, subtype, subclass);
    }

    public byte getNrChannels() {
    @Override
    public byte getChannelCount() {
        return mNrChannels;
    }

    @Override
    public int getChannelConfig() {
        return mChannelConfig;
    }

    @Override
    public byte getChannelNames() {
        return mChannelNames;
    }
@@ -69,9 +72,7 @@ public final class Usb10ACInputTerminal extends UsbACTerminal {
        super.report(canvas);

        canvas.openList();
        canvas.writeListItem("Associated Terminal: "
                + ReportCanvas.getHexString(getAssocTerminal()));
        canvas.writeListItem("" + getNrChannels() + " Chans. Config: "
        canvas.writeListItem("" + getChannelCount() + " Chans. Config: "
                + ReportCanvas.getHexString(getChannelConfig()));
        canvas.closeList();
    }
+9 −2
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import com.android.server.usb.descriptors.report.ReportCanvas;
 * An audio class-specific Mixer Interface.
 * see audio10.pdf section 4.3.2.3
 */
public final class Usb10ACMixerUnit extends UsbACMixerUnit {
public final class Usb10ACMixerUnit extends UsbACMixerUnit implements UsbAudioChannelCluster {
    private static final String TAG = "Usb10ACMixerUnit";

    private int mChannelConfig; // Spatial location of output channels
@@ -34,11 +34,18 @@ public final class Usb10ACMixerUnit extends UsbACMixerUnit {
        super(length, type, subtype, subClass);
    }

    @Override
    public byte getChannelCount() {
        return mNumOutputs;
    }

    @Override
    public int getChannelConfig() {
        return mChannelConfig;
    }

    public byte getChanNameID() {
    @Override
    public byte getChannelNames() {
        return mChanNameID;
    }

+12 −5
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import com.android.server.usb.descriptors.report.ReportCanvas;
 * An audio class-specific Input Terminal interface.
 * see Audio20.pdf section 3.13.2 Input Terminal
 */
public final class Usb20ACInputTerminal extends UsbACTerminal {
public final class Usb20ACInputTerminal extends UsbACTerminal implements UsbAudioChannelCluster {
    private static final String TAG = "Usb20ACInputTerminal";

    // See Audio20.pdf - Table 4-9
@@ -47,14 +47,21 @@ public final class Usb20ACInputTerminal extends UsbACTerminal {
        return mClkSourceID;
    }

    public byte getNumChannels() {
    @Override
    public byte getChannelCount() {
        return mNumChannels;
    }

    public int getChanConfig() {
    @Override
    public int getChannelConfig() {
        return mChanConfig;
    }

    @Override
    public byte getChannelNames() {
        return mChanNames;
    }

    public int getControls() {
        return mControls;
    }
@@ -79,8 +86,8 @@ public final class Usb20ACInputTerminal extends UsbACTerminal {

        canvas.openList();
        canvas.writeListItem("Clock Source: " + getClkSourceID());
        canvas.writeListItem("" + getNumChannels() + " Channels. Config: "
                + ReportCanvas.getHexString(getChanConfig()));
        canvas.writeListItem("" + getChannelCount() + " Channels. Config: "
                + ReportCanvas.getHexString(getChannelConfig()));
        canvas.closeList();
    }
}
+16 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ package com.android.server.usb.descriptors;
 * An audio class-specific Mixer Unit interface.
 * see Audio20.pdf section 4.7.2.6 Mixer Unit Descriptor
 */
public final class Usb20ACMixerUnit extends UsbACMixerUnit {
public final class Usb20ACMixerUnit extends UsbACMixerUnit implements UsbAudioChannelCluster {
    private static final String TAG = "Usb20ACMixerUnit";

    private int mChanConfig;    // 6+p:4 Describes the spatial location of the
@@ -37,6 +37,21 @@ public final class Usb20ACMixerUnit extends UsbACMixerUnit {
        super(length, type, subtype, subClass);
    }

    @Override
    public byte getChannelCount() {
        return mNumOutputs;
    }

    @Override
    public int getChannelConfig() {
        return mChanConfig;
    }

    @Override
    public byte getChannelNames() {
        return mChanNames;
    }

    @Override
    public int parseRawDescriptors(ByteStream stream) {
        super.parseRawDescriptors(stream);
+1 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ public final class Usb20ACOutputTerminal extends UsbACTerminal {
        super.report(canvas);

        canvas.openList();
        canvas.writeListItem("Source ID:" + getSourceID());
        canvas.writeListItem("Clock Source ID: " + getClkSourceID());
        canvas.writeListItem("Controls: " + ReportCanvas.getHexString(getControls()));
        canvas.writeListItem("Terminal Name ID: " + getTerminalID());
Loading