• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.port;
17 
18 import android.annotation.IntDef;
19 import android.hardware.usb.IUsbOperationInternal;
20 import android.hardware.usb.UsbManager.UsbHalVersion;
21 import android.os.RemoteException;
22 import java.lang.annotation.Retention;
23 import java.lang.annotation.RetentionPolicy;
24 import java.lang.String;
25 
26 /**
27  * @hide
28  */
29 public interface UsbPortHal {
30     /**
31      * Power role: This USB port can act as a source (provide power).
32      * @hide
33      */
34     public static final int HAL_POWER_ROLE_SOURCE = 1;
35 
36     /**
37      * Power role: This USB port can act as a sink (receive power).
38      * @hide
39      */
40     public static final int HAL_POWER_ROLE_SINK = 2;
41 
42     @IntDef(prefix = { "HAL_POWER_ROLE_" }, value = {
43             HAL_POWER_ROLE_SOURCE,
44             HAL_POWER_ROLE_SINK
45     })
46     @Retention(RetentionPolicy.SOURCE)
47     @interface HalUsbPowerRole{}
48 
49     /**
50      * Data role: This USB port can act as a host (access data services).
51      * @hide
52      */
53     public static final int HAL_DATA_ROLE_HOST = 1;
54 
55     /**
56      * Data role: This USB port can act as a device (offer data services).
57      * @hide
58      */
59     public static final int HAL_DATA_ROLE_DEVICE = 2;
60 
61     @IntDef(prefix = { "HAL_DATA_ROLE_" }, value = {
62             HAL_DATA_ROLE_HOST,
63             HAL_DATA_ROLE_DEVICE
64     })
65     @Retention(RetentionPolicy.SOURCE)
66     @interface HalUsbDataRole{}
67 
68     /**
69      * This USB port can act as a downstream facing port (host).
70      *
71      * @hide
72      */
73     public static final int HAL_MODE_UFP = 1;
74 
75     /**
76      * This USB port can act as an upstream facing port (device).
77      *
78      * @hide
79      */
80     public static final int HAL_MODE_DFP = 2;
81     @IntDef(prefix = { "HAL_MODE_" }, value = {
82             HAL_MODE_UFP,
83             HAL_MODE_DFP,
84     })
85     @Retention(RetentionPolicy.SOURCE)
86     @interface HalUsbPortMode{}
87 
88     /**
89      * UsbPortManager would call this when the system is done booting.
90      */
systemReady()91     public void systemReady();
92 
93     /**
94      * Invoked to enable/disable contaminant presence detection on the USB port.
95      *
96      * @param portName Port Identifier.
97      * @param enable Enable contaminant presence detection when true.
98      *               Disable when false.
99      * @param transactionId Used for tracking the current request and is passed down to the HAL
100      *                      implementation as needed.
101      */
enableContaminantPresenceDetection(String portName, boolean enable, long transactionId)102     public void enableContaminantPresenceDetection(String portName, boolean enable,
103             long transactionId);
104 
105     /**
106      * Invoked to query port status of all the ports.
107      *
108      * @param transactionId Used for tracking the current request and is passed down to the HAL
109      *                      implementation as needed.
110      */
queryPortStatus(long transactionId)111     public void queryPortStatus(long transactionId);
112 
113     /**
114      * Invoked to switch USB port mode.
115      *
116      * @param portName Port Identifier.
117      * @param mode New mode that the port is switching into.
118      * @param transactionId Used for tracking the current request and is passed down to the HAL
119      *                      implementation as needed.
120      */
switchMode(String portName, @HalUsbPortMode int mode, long transactionId)121     public void switchMode(String portName, @HalUsbPortMode int mode, long transactionId);
122 
123     /**
124      * Invoked to switch USB port power role.
125      *
126      * @param portName Port Identifier.
127      * @param powerRole New power role that the port is switching into.
128      * @param transactionId Used for tracking the current request and is passed down to the HAL
129      *                      implementation as needed.
130      */
switchPowerRole(String portName, @HalUsbPowerRole int powerRole, long transactionId)131     public void switchPowerRole(String portName, @HalUsbPowerRole int powerRole,
132             long transactionId);
133 
134     /**
135      * Invoked to switch USB port data role.
136      *
137      * @param portName Port Identifier.
138      * @param dataRole New data role that the port is switching into.
139      * @param transactionId Used for tracking the current request and is passed down to the HAL
140      *                      implementation as needed.
141      */
switchDataRole(String portName, @HalUsbDataRole int dataRole, long transactionId)142     public void switchDataRole(String portName, @HalUsbDataRole int dataRole, long transactionId);
143 
144     /**
145      * Invoked to query the version of current hal implementation.
146      */
getUsbHalVersion()147     public @UsbHalVersion int getUsbHalVersion() throws RemoteException;
148 
149     /**
150      * Invoked to enable/disable UsbData on the specified port.
151      *
152      * @param portName Port Identifier.
153      * @param enable Enable USB data when true.
154      *               Disable when false.
155      * @param transactionId Used for tracking the current request and is passed down to the HAL
156      *                      implementation as needed.
157      * @param callback callback object to be invoked to invoke the status of the operation upon
158      *                 completion.
159      * @param callback callback object to be invoked when the operation is complete.
160      * @return True when the operation is asynchronous. The caller of
161      *         {@link UsbOperationInternal} must therefore call
162      *         {@link UsbOperationInternal#waitForOperationComplete} for processing
163      *         the result.
164      *         False when the operation is synchronous. Caller can proceed reading the result
165      *         through {@link UsbOperationInternal#getStatus}
166      */
enableUsbData(String portName, boolean enable, long transactionId, IUsbOperationInternal callback)167     public boolean enableUsbData(String portName, boolean enable, long transactionId,
168             IUsbOperationInternal callback);
169 
170     /**
171      * Invoked to enable  UsbData when disabled due to docking event.
172      *
173      * @param portName Port Identifier.
174      * @param transactionId Used for tracking the current request and is passed down to the HAL
175      *                      implementation as needed.
176      * @param callback callback object to be invoked to invoke the status of the operation upon
177      *                 completion.
178      */
enableUsbDataWhileDocked(String portName, long transactionId, IUsbOperationInternal callback)179     public void enableUsbDataWhileDocked(String portName, long transactionId,
180             IUsbOperationInternal callback);
181 
182     /**
183      * Invoked to enableLimitPowerTransfer on the specified port.
184      *
185      * @param portName Port Identifier.
186      * @param limit limit power transfer when true. Port wouldn't charge or power USB accessoried
187      *              when set.
188      *              Lift power transfer restrictions when false.
189      * @param transactionId Used for tracking the current request and is passed down to the HAL
190      *                      implementation as needed.
191      * @param callback callback object to be invoked to invoke the status of the operation upon
192      *                 completion.
193      */
enableLimitPowerTransfer(String portName, boolean limit, long transactionId, IUsbOperationInternal callback)194     public void enableLimitPowerTransfer(String portName, boolean limit, long transactionId,
195             IUsbOperationInternal callback);
196 
197     /**
198      * Invoked to reset UsbData on the specified port.
199      *
200      * @param portName Port Identifier.
201      * @param transactionId Used for tracking the current request and is passed down to the HAL
202      *                      implementation as needed.
203      * @param callback callback object to be invoked to invoke the status of the operation upon
204      *                 completion.
205      */
resetUsbPort(String portName, long transactionId, IUsbOperationInternal callback)206     public void resetUsbPort(String portName, long transactionId,
207             IUsbOperationInternal callback);
208 }
209