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

Commit 9de2881d authored by RD Babiera's avatar RD Babiera
Browse files

Usb DisplayPort alt mode frameworks api

Adds getDisplayPortAltModeInfo() to UsbPortStatus as well as implementation
for DisplayPortAltModeInfo.
Adds registerDisplayPortAltModeListener() to UsbManager in addition to
DisplayPortAltModeInfoListener and DisplayPortAltModeInfoListener.aidl
Adds isAltModeSupported() to UsbPort.
Provides necessary pipeline to bubble up information from HAL layer to
frameworks level.

Adds AltMode support to simulated ports within UsbService.

Bug: 253534975
Test: atest CtsUsbManagerTestCases
Change-Id: Ie0b302ea79d0870b95f600cf3077023302a04a1d
parent 613dc260
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -5766,6 +5766,19 @@ package android.hardware.soundtrigger {
package android.hardware.usb {
  public final class DisplayPortAltModeInfo implements android.os.Parcelable {
    method public int describeContents();
    method public int getCableStatus();
    method public int getNumberOfLanes();
    method public int getPartnerSinkStatus();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.hardware.usb.DisplayPortAltModeInfo> CREATOR;
    field public static final int DISPLAYPORT_ALT_MODE_STATUS_CAPABLE = 2; // 0x2
    field public static final int DISPLAYPORT_ALT_MODE_STATUS_ENABLED = 3; // 0x3
    field public static final int DISPLAYPORT_ALT_MODE_STATUS_NOT_CAPABLE = 1; // 0x1
    field public static final int DISPLAYPORT_ALT_MODE_STATUS_UNKNOWN = 0; // 0x0
  }
  public class UsbDeviceConnection {
    method public boolean resetDevice();
  }
@@ -5774,8 +5787,10 @@ package android.hardware.usb {
    method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public long getCurrentFunctions();
    method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_USB) public java.util.List<android.hardware.usb.UsbPort> getPorts();
    method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public void grantPermission(android.hardware.usb.UsbDevice, String);
    method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public boolean registerDisplayPortAltModeInfoListener(@NonNull java.util.concurrent.Executor, @NonNull android.hardware.usb.UsbManager.DisplayPortAltModeInfoListener);
    method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public void resetUsbGadget();
    method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public void setCurrentFunctions(long);
    method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public void unregisterDisplayPortAltModeInfoListener(@NonNull android.hardware.usb.UsbManager.DisplayPortAltModeInfoListener);
    field @RequiresPermission(android.Manifest.permission.MANAGE_USB) public static final String ACTION_USB_ACCESSORY_HANDSHAKE = "android.hardware.usb.action.USB_ACCESSORY_HANDSHAKE";
    field @RequiresPermission(android.Manifest.permission.MANAGE_USB) public static final String ACTION_USB_PORT_CHANGED = "android.hardware.usb.action.USB_PORT_CHANGED";
    field @RequiresPermission(android.Manifest.permission.MANAGE_USB) public static final String ACTION_USB_PORT_COMPLIANCE_CHANGED = "android.hardware.usb.action.USB_PORT_COMPLIANCE_CHANGED";
@@ -5799,11 +5814,16 @@ package android.hardware.usb {
    field public static final String USB_FUNCTION_RNDIS = "rndis";
  }
  public static interface UsbManager.DisplayPortAltModeInfoListener {
    method public void onDisplayPortAltModeInfoChanged(@NonNull String, @NonNull android.hardware.usb.DisplayPortAltModeInfo);
  }
  public final class UsbPort {
    method @CheckResult @RequiresPermission(android.Manifest.permission.MANAGE_USB) public int enableLimitPowerTransfer(boolean);
    method @CheckResult @RequiresPermission(android.Manifest.permission.MANAGE_USB) public int enableUsbData(boolean);
    method @CheckResult @RequiresPermission(android.Manifest.permission.MANAGE_USB) public int enableUsbDataWhileDocked();
    method @Nullable @RequiresPermission(android.Manifest.permission.MANAGE_USB) public android.hardware.usb.UsbPortStatus getStatus();
    method public boolean isAltModeSupported(int);
    method @CheckResult @RequiresPermission(android.Manifest.permission.MANAGE_USB) public void resetUsbPort(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Integer>);
    method @RequiresPermission(android.Manifest.permission.MANAGE_USB) public void setRoles(int, int);
    method @CheckResult @RequiresPermission(android.Manifest.permission.MANAGE_USB) public boolean supportsComplianceWarnings();
@@ -5823,6 +5843,7 @@ package android.hardware.usb {
    field public static final int ENABLE_USB_DATA_WHILE_DOCKED_ERROR_OTHER = 5; // 0x5
    field public static final int ENABLE_USB_DATA_WHILE_DOCKED_ERROR_PORT_MISMATCH = 3; // 0x3
    field public static final int ENABLE_USB_DATA_WHILE_DOCKED_SUCCESS = 0; // 0x0
    field public static final int FLAG_ALT_MODE_TYPE_DISPLAYPORT = 1; // 0x1
    field public static final int RESET_USB_PORT_ERROR_INTERNAL = 1; // 0x1
    field public static final int RESET_USB_PORT_ERROR_NOT_SUPPORTED = 2; // 0x2
    field public static final int RESET_USB_PORT_ERROR_OTHER = 4; // 0x4
@@ -5836,6 +5857,8 @@ package android.hardware.usb {
    method public int getCurrentDataRole();
    method public int getCurrentMode();
    method public int getCurrentPowerRole();
    method @Nullable public android.hardware.usb.DisplayPortAltModeInfo getDisplayPortAltModeInfo();
    method public int getPlugState();
    method public int getPowerBrickConnectionStatus();
    method public int getSupportedRoleCombinations();
    method public int getUsbDataStatus();
@@ -5865,6 +5888,11 @@ package android.hardware.usb {
    field public static final int MODE_DFP = 2; // 0x2
    field public static final int MODE_NONE = 0; // 0x0
    field public static final int MODE_UFP = 1; // 0x1
    field public static final int PLUG_STATE_PLUGGED_ORIENTATION_FLIPPED = 4; // 0x4
    field public static final int PLUG_STATE_PLUGGED_ORIENTATION_NORMAL = 3; // 0x3
    field public static final int PLUG_STATE_PLUGGED_ORIENTATION_UNKNOWN = 2; // 0x2
    field public static final int PLUG_STATE_UNKNOWN = 0; // 0x0
    field public static final int PLUG_STATE_UNPLUGGED = 1; // 0x1
    field public static final int POWER_BRICK_STATUS_CONNECTED = 1; // 0x1
    field public static final int POWER_BRICK_STATUS_DISCONNECTED = 2; // 0x2
    field public static final int POWER_BRICK_STATUS_UNKNOWN = 0; // 0x0
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.usb;

parcelable DisplayPortAltModeInfo;
 No newline at end of file
+206 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.usb;

import android.Manifest;
import android.annotation.CheckResult;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;

/**
 * Holds information related to DisplayPort Alt Mode statuses
 *
 * @hide
 */
@SystemApi
public final class DisplayPortAltModeInfo implements Parcelable {
    private final @DisplayPortAltModeStatus int mPartnerSinkStatus;
    private final @DisplayPortAltModeStatus int mCableStatus;
    private final int mNumLanes;

    /**
     * Port Partners:
     * The port partner status is currently unknown for one of the following reasons:
     *     <ul>
     *     <li> No port partner is connected to the device
     *     <li> The USB Power Delivery Discover Identity command has not been issued to the port
     *     partner via SOP messaging.
     *     </ul>
     * <p>
     * Cables:
     * The cable’s capabilities are not yet known to the device, or no cable is plugged in.
     */
    public static final int DISPLAYPORT_ALT_MODE_STATUS_UNKNOWN = 0;

    /**
     * Port Partners:
     * The current port partner does not list DisplayPort as one of its Alt Modes, or does not list
     * the capability to act as a DisplayPort Source or Sink device, or a compatible configuration
     * could not be established.
     * <p>
     * Cables:
     * The cable/adapter’s capabilities do not list DisplayPort as one of its Alt Modes, or a
     * compatible configuration could not be established.
     */
    public static final int DISPLAYPORT_ALT_MODE_STATUS_NOT_CAPABLE = 1;

    /**
     * Port Partners:
     * The current port partner lists compatible DisplayPort capabilities with the device, however
     * may not yet have entered DisplayPort Alt Mode or has configured its port for data
     * transmission.
     * <p>
     * Cables:
     * The Type-C cable/adapter’s capabilities have been discovered and list DisplayPort Alt Mode
     * as one of its capabilities, however may not yet have entered DisplayPort Alt Mode or has been
     * configured for data transmission.
     */
    public static final int DISPLAYPORT_ALT_MODE_STATUS_CAPABLE = 2;

    /**
     * Port Partners:
     * The port partner and device are both configured for DisplayPort Alt Mode.
     * <p>
     * Cables:
     * The Type-C cable/adapter is configured for DisplayPort Alt Mode.
     */
    public static final int DISPLAYPORT_ALT_MODE_STATUS_ENABLED = 3;

    /** @hide */
    @IntDef(prefix = { "DISPLAYPORT_ALT_MODE_STATUS_" }, value = {
            DISPLAYPORT_ALT_MODE_STATUS_UNKNOWN,
            DISPLAYPORT_ALT_MODE_STATUS_NOT_CAPABLE,
            DISPLAYPORT_ALT_MODE_STATUS_CAPABLE,
            DISPLAYPORT_ALT_MODE_STATUS_ENABLED,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface DisplayPortAltModeStatus {}

    /** @hide */
    public DisplayPortAltModeInfo() {
        mPartnerSinkStatus = DISPLAYPORT_ALT_MODE_STATUS_UNKNOWN;
        mCableStatus = DISPLAYPORT_ALT_MODE_STATUS_UNKNOWN;
        mNumLanes = 0;
    }

    /** @hide */
    public DisplayPortAltModeInfo(int partnerSinkStatus, int cableStatus,
            int numLanes) {
        mPartnerSinkStatus = partnerSinkStatus;
        mCableStatus = cableStatus;
        mNumLanes = numLanes;
    }

    /**
     * Returns the DisplayPort Alt Mode Status for a port partner acting as a sink.
     *
     * @return {@link #DISPLAYPORT_ALT_MODE_STATUS_UNKNOWN}
     *        or {@link #DISPLAYPORT_ALT_MODE_STATUS_NOT_CAPABLE}
     *        or {@link #DISPLAYPORT_ALT_MODE_STATUS_CAPABLE}
     *        or {@link #DISPLAYPORT_ALT_MODE_STATUS_ENABLED}
     */
    public @DisplayPortAltModeStatus int getPartnerSinkStatus() {
        return mPartnerSinkStatus;
    }

    /**
     * Returns the DisplayPort Alt Mode Status for the attached cable
     *
     * @return {@link #DISPLAYPORT_ALT_MODE_STATUS_UNKNOWN}
     *        or {@link #DISPLAYPORT_ALT_MODE_STATUS_NOT_CAPABLE}
     *        or {@link #DISPLAYPORT_ALT_MODE_STATUS_CAPABLE}
     *        or {@link #DISPLAYPORT_ALT_MODE_STATUS_ENABLED}
     */
    public @DisplayPortAltModeStatus int getCableStatus() {
        return mCableStatus;
    }

    /**
     * Returns the number of lanes used to transmit display data.
     *
     */
    public int getNumberOfLanes() {
        return mNumLanes;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeInt(mPartnerSinkStatus);
        dest.writeInt(mCableStatus);
        dest.writeInt(mNumLanes);
    }

    @NonNull
    @Override
    public String toString() {
        return "DisplayPortAltModeInfo{partnerSink="
                + mPartnerSinkStatus
                + " cable="
                + mCableStatus
                + " numLanes="
                + mNumLanes
                + "}";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof DisplayPortAltModeInfo)) {
            return false;
        }
        DisplayPortAltModeInfo other = (DisplayPortAltModeInfo) o;
        return this.mPartnerSinkStatus == other.mPartnerSinkStatus
                && this.mCableStatus == other.mCableStatus
                && this.mNumLanes == other.mNumLanes;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mPartnerSinkStatus, mCableStatus, mNumLanes);
    }

    public static final @NonNull Parcelable.Creator<DisplayPortAltModeInfo> CREATOR =
            new Parcelable.Creator<DisplayPortAltModeInfo>() {
        @Override
        public DisplayPortAltModeInfo createFromParcel(Parcel in) {
            int partnerSinkStatus = in.readInt();
            int cableStatus = in.readInt();
            int numLanes = in.readInt();
            return new DisplayPortAltModeInfo(partnerSinkStatus, cableStatus, numLanes);
        }

        @Override
        public DisplayPortAltModeInfo[] newArray(int size) {
            return new DisplayPortAltModeInfo[size];
        }
    };
}
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.usb;

import android.hardware.usb.DisplayPortAltModeInfo;

/**
 * @hide
 */
oneway interface IDisplayPortAltModeInfoListener {
    void onDisplayPortAltModeInfoChanged(in String portId,
            in DisplayPortAltModeInfo DisplayPortAltModeInfo);
}
 No newline at end of file
+12 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.hardware.usb;

import android.app.PendingIntent;
import android.content.ComponentName;
import android.hardware.usb.IDisplayPortAltModeInfoListener;
import android.hardware.usb.IUsbOperationInternal;
import android.hardware.usb.UsbAccessory;
import android.hardware.usb.UsbDevice;
@@ -184,4 +185,15 @@ interface IUsbManager

    /* Sets USB device connection handler. */
    void setUsbDeviceConnectionHandler(in ComponentName usbDeviceConnectionHandler);

    /* Registers callback for Usb events */
    @JavaPassthrough(annotation=
            "@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_USB)")
    boolean registerForDisplayPortEvents(IDisplayPortAltModeInfoListener listener);

    /* Unregisters Usb event callback */
    @JavaPassthrough(annotation=
            "@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_USB)")
    void unregisterForDisplayPortEvents(IDisplayPortAltModeInfoListener listener);

}
Loading