@@ -192,10 +192,12 @@ public IBinder onBind(Intent intent) {
192
192
private final static int FLAG_POSSIBLE_SPEED_LOW = 0x01 ;
193
193
private final static int FLAG_POSSIBLE_SPEED_FULL = 0x02 ;
194
194
private final static int FLAG_POSSIBLE_SPEED_HIGH = 0x04 ;
195
+ private final static int FLAG_POSSIBLE_SPEED_SUPER = 0x08 ;
195
196
private int detectSpeed (UsbDevice dev , UsbDeviceDescriptor devDesc ) {
196
197
int possibleSpeeds = FLAG_POSSIBLE_SPEED_LOW |
197
198
FLAG_POSSIBLE_SPEED_FULL |
198
- FLAG_POSSIBLE_SPEED_HIGH ;
199
+ FLAG_POSSIBLE_SPEED_HIGH |
200
+ FLAG_POSSIBLE_SPEED_SUPER ;
199
201
200
202
for (int i = 0 ; i < dev .getInterfaceCount (); i ++) {
201
203
UsbInterface iface = dev .getInterface (i );
@@ -216,6 +218,10 @@ private int detectSpeed(UsbDevice dev, UsbDeviceDescriptor devDesc) {
216
218
// High speed devices can't use control transfer sizes smaller than 64 bytes
217
219
possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_HIGH ;
218
220
}
221
+ if (endpoint .getMaxPacketSize () < 512 ) {
222
+ // Super speed devices can't use control transfer sizes smaller than 512 bytes
223
+ possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_SUPER ;
224
+ }
219
225
}
220
226
else if (endpoint .getType () == UsbConstants .USB_ENDPOINT_XFER_INT ) {
221
227
if (endpoint .getMaxPacketSize () > 8 ) {
@@ -226,23 +232,27 @@ else if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_INT) {
226
232
// Full speed devices can't use interrupt transfer sizes larger than 64 bytes
227
233
possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_FULL ;
228
234
}
235
+ if (endpoint .getMaxPacketSize () > 512 ) {
236
+ // High speed devices can't use interrupt transfer sizes larger than 512 bytes
237
+ possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_HIGH ;
238
+ }
229
239
}
230
240
else if (endpoint .getType () == UsbConstants .USB_ENDPOINT_XFER_BULK ) {
231
241
// A bulk endpoint alone can accurately distiniguish between
232
- // full and high speed devices
233
- if (endpoint .getMaxPacketSize () == 512 ) {
234
- // High speed devices can only use 512 byte bulk transfers
235
- possibleSpeeds = FLAG_POSSIBLE_SPEED_HIGH ;
236
- }
237
- else {
238
- // Otherwise it must be full speed
239
- possibleSpeeds = FLAG_POSSIBLE_SPEED_FULL ;
240
- }
241
- }
242
- else if ( endpoint . getType () == UsbConstants . USB_ENDPOINT_XFER_ISOC ) {
243
- // If the transfer size is 1024, it must be high speed
244
- if ( endpoint . getMaxPacketSize () == 1024 ) {
245
- possibleSpeeds = FLAG_POSSIBLE_SPEED_HIGH ;
242
+ // full, high, and super speed devices
243
+ switch (endpoint .getMaxPacketSize ()) {
244
+ case 512 :
245
+ // High speed devices can only use 512 byte bulk transfers
246
+ possibleSpeeds = FLAG_POSSIBLE_SPEED_HIGH ;
247
+ break ;
248
+ case 1024 :
249
+ // Super speed devices can only use 1024 byte bulk transfers
250
+ possibleSpeeds = FLAG_POSSIBLE_SPEED_SUPER ;
251
+ break ;
252
+ default :
253
+ // Otherwise it must be full speed
254
+ possibleSpeeds = FLAG_POSSIBLE_SPEED_FULL ;
255
+ break ;
246
256
}
247
257
}
248
258
}
@@ -253,6 +263,10 @@ else if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_ISOC) {
253
263
// High speed only supported on USB 2.0 or higher
254
264
possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_HIGH ;
255
265
}
266
+ if (devDesc .bcdUSB < 0x300 ) {
267
+ // Super speed only supported on USB 3.0 or higher
268
+ possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_SUPER ;
269
+ }
256
270
}
257
271
258
272
// Return the lowest speed that we're compatible with
@@ -268,6 +282,9 @@ else if ((possibleSpeeds & FLAG_POSSIBLE_SPEED_FULL) != 0) {
268
282
else if ((possibleSpeeds & FLAG_POSSIBLE_SPEED_HIGH ) != 0 ) {
269
283
return UsbIpDevice .USB_SPEED_HIGH ;
270
284
}
285
+ else if ((possibleSpeeds & FLAG_POSSIBLE_SPEED_SUPER ) != 0 ) {
286
+ return UsbIpDevice .USB_SPEED_SUPER ;
287
+ }
271
288
else {
272
289
// Something went very wrong in speed detection
273
290
return UsbIpDevice .USB_SPEED_UNKNOWN ;
0 commit comments