@@ -340,10 +340,15 @@ private UsbDeviceInfo getInfoForDevice(UsbDevice dev, UsbDeviceConnection devCon
340
340
ipDev .bDeviceClass = (byte ) dev .getDeviceClass ();
341
341
ipDev .bDeviceSubClass = (byte ) dev .getDeviceSubclass ();
342
342
ipDev .bDeviceProtocol = (byte ) dev .getDeviceProtocol ();
343
-
343
+
344
344
ipDev .bConfigurationValue = 0 ;
345
- ipDev .bNumConfigurations = 1 ;
346
-
345
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
346
+ ipDev .bNumConfigurations = (byte ) dev .getConfigurationCount ();
347
+ }
348
+ else {
349
+ ipDev .bNumConfigurations = 1 ;
350
+ }
351
+
347
352
ipDev .bNumInterfaces = (byte ) dev .getInterfaceCount ();
348
353
349
354
info .dev = ipDev ;
@@ -575,21 +580,29 @@ public void submitUrbRequest(Socket s, UsbIpSubmitUrb msg) {
575
580
context .activeMessages .add (msg );
576
581
577
582
int res ;
578
-
579
- do {
580
- res = XferUtils .doControlTransfer (devConn , requestType , request , value , index ,
581
- (requestType & 0x80 ) != 0 ? reply .inData : msg .outData , length , 1000 );
582
-
583
- if (context .requestPool .isShutdown ()) {
584
- // Bail if the queue is being torn down
585
- return ;
586
- }
587
-
588
- if (!context .activeMessages .contains (msg )) {
589
- // Somebody cancelled the URB, return without responding
590
- return ;
591
- }
592
- } while (res == -110 ); // ETIMEDOUT
583
+
584
+ // We have to handle certain control requests (SET_CONFIGURATION/SET_INTERFACE) by calling
585
+ // Android APIs rather than just submitting the URB directly to the device
586
+ if (!UsbControlHelper .handleInternalControlTransfer (dev , devConn , requestType , request , value , index )) {
587
+ do {
588
+ res = XferUtils .doControlTransfer (devConn , requestType , request , value , index ,
589
+ (requestType & 0x80 ) != 0 ? reply .inData : msg .outData , length , 1000 );
590
+
591
+ if (context .requestPool .isShutdown ()) {
592
+ // Bail if the queue is being torn down
593
+ return ;
594
+ }
595
+
596
+ if (!context .activeMessages .contains (msg )) {
597
+ // Somebody cancelled the URB, return without responding
598
+ return ;
599
+ }
600
+ } while (res == -110 ); // ETIMEDOUT
601
+ }
602
+ else {
603
+ // Handled the request internally
604
+ res = 0 ;
605
+ }
593
606
594
607
if (res < 0 ) {
595
608
reply .status = res ;
@@ -731,7 +744,7 @@ public boolean attachToDevice(Socket s, String busId) {
731
744
// Claim all interfaces since we don't know which one the client wants
732
745
for (int i = 0 ; i < dev .getInterfaceCount (); i ++) {
733
746
if (!devConn .claimInterface (dev .getInterface (i ), true )) {
734
- System .err .println ("Unabled to claim interface " +dev .getInterface (i ).getId ());
747
+ System .err .println ("Unable to claim interface " +dev .getInterface (i ).getId ());
735
748
}
736
749
}
737
750
0 commit comments