1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.server.usb.hal.gadget; 17 18 import android.annotation.IntDef; 19 import android.hardware.usb.gadget.IUsbGadgetCallback; 20 import android.hardware.usb.IUsbOperationInternal; 21 import android.hardware.usb.UsbManager.UsbHalVersion; 22 import android.os.RemoteException; 23 import java.lang.annotation.Retention; 24 import java.lang.annotation.RetentionPolicy; 25 import java.lang.String; 26 27 /** 28 * @hide 29 */ 30 public interface UsbGadgetHal { 31 /** 32 * Power role: This USB port can act as a source (provide power). 33 * @hide 34 */ 35 public static final int HAL_POWER_ROLE_SOURCE = 1; 36 37 /** 38 * Power role: This USB port can act as a sink (receive power). 39 * @hide 40 */ 41 public static final int HAL_POWER_ROLE_SINK = 2; 42 43 @IntDef(prefix = { "HAL_POWER_ROLE_" }, value = { 44 HAL_POWER_ROLE_SOURCE, 45 HAL_POWER_ROLE_SINK 46 }) 47 @Retention(RetentionPolicy.SOURCE) 48 @interface HalUsbPowerRole{} 49 50 /** 51 * Data role: This USB port can act as a host (access data services). 52 * @hide 53 */ 54 public static final int HAL_DATA_ROLE_HOST = 1; 55 56 /** 57 * Data role: This USB port can act as a device (offer data services). 58 * @hide 59 */ 60 public static final int HAL_DATA_ROLE_DEVICE = 2; 61 62 @IntDef(prefix = { "HAL_DATA_ROLE_" }, value = { 63 HAL_DATA_ROLE_HOST, 64 HAL_DATA_ROLE_DEVICE 65 }) 66 @Retention(RetentionPolicy.SOURCE) 67 @interface HalUsbDataRole{} 68 69 /** 70 * This USB port can act as a downstream facing port (host). 71 * 72 * @hide 73 */ 74 public static final int HAL_MODE_DFP = 1; 75 76 /** 77 * This USB port can act as an upstream facing port (device). 78 * 79 * @hide 80 */ 81 public static final int HAL_MODE_UFP = 2; 82 @IntDef(prefix = { "HAL_MODE_" }, value = { 83 HAL_MODE_DFP, 84 HAL_MODE_UFP, 85 }) 86 @Retention(RetentionPolicy.SOURCE) 87 @interface HalUsbPortMode{} 88 89 /** 90 * UsbPortManager would call this when the system is done booting. 91 */ systemReady()92 public void systemReady(); 93 94 /** 95 * This function is used to query the USB functions included in the 96 * current USB configuration. 97 * 98 * @param transactionId Used for tracking the current request and is passed down to the HAL 99 * implementation as needed. 100 */ getCurrentUsbFunctions(long transactionId)101 public void getCurrentUsbFunctions(long transactionId); 102 103 /** 104 * The function is used to query current USB speed. 105 * 106 * @param transactionId Used for tracking the current request and is passed down to the HAL 107 * implementation as needed. 108 */ getUsbSpeed(long transactionId)109 public void getUsbSpeed(long transactionId); 110 111 /** 112 * This function is used to reset USB gadget driver. 113 * Performs USB data connection reset. The connection will disconnect and 114 * reconnect. 115 * 116 * @param transactionId Used for tracking the current request and is passed down to the HAL 117 * implementation as needed. 118 */ reset(long transactionId)119 public void reset(long transactionId); 120 121 /** 122 * Invoked to query the version of current gadget hal implementation. 123 */ getGadgetHalVersion()124 public @UsbHalVersion int getGadgetHalVersion() throws RemoteException; 125 126 /** 127 * This function is used to set the current USB gadget configuration. 128 * The USB gadget needs to be torn down if a USB configuration is already 129 * active. 130 * 131 * @param functions list of functions defined by GadgetFunction to be 132 * included in the gadget composition. 133 * @param timeout The maximum time (in milliseconds) within which the 134 * IUsbGadgetCallback needs to be returned. 135 * @param transactionId Used for tracking the current request and is passed down to the HAL 136 * implementation as needed. 137 */ setCurrentUsbFunctions(int request, long functions, boolean chargingFunctions, int timeout, long transactionId)138 public void setCurrentUsbFunctions(int request, long functions, 139 boolean chargingFunctions, int timeout, long transactionId); 140 } 141 142