1111import java .util .ArrayList ;
1212import java .util .Collections ;
1313import java .util .HashMap ;
14+ import java .util .HashSet ;
1415import java .util .List ;
1516import java .util .Map ;
1617
@@ -68,8 +69,8 @@ abstract class AbstractDevice implements UsbDevice
6869 /** The number of the currently active configuration. */
6970 private byte activeConfigurationNumber = 0 ;
7071
71- /** The number of the currently claimed interface. */
72- private Byte claimedInterfaceNumber = null ;
72+ /** The numbers of the currently claimed interface. */
73+ private HashSet < Byte > claimedInterfaceNumbers = new HashSet < Byte >() ;
7374
7475 /** The port this device is connected to. */
7576 private UsbPort port ;
@@ -371,7 +372,7 @@ final void setActiveUsbConfigurationNumber(final byte number)
371372 {
372373 if (number != this .activeConfigurationNumber )
373374 {
374- if (this .claimedInterfaceNumber != null )
375+ if (! this .claimedInterfaceNumbers . isEmpty () )
375376 throw new UsbException ("Can't change configuration while an "
376377 + "interface is still claimed" );
377378
@@ -396,7 +397,7 @@ final void setActiveUsbConfigurationNumber(final byte number)
396397 final void claimInterface (final byte number , final boolean force )
397398 throws UsbException
398399 {
399- if (this .claimedInterfaceNumber != null )
400+ if (this .claimedInterfaceNumbers . contains ( number ) )
400401 throw new UsbClaimException ("An interface is already claimed" );
401402
402403 final DeviceHandle handle = open ();
@@ -422,7 +423,7 @@ final void claimInterface(final byte number, final boolean force)
422423 if (result < 0 )
423424 throw new LibUsbException ("Unable to claim interface" ,
424425 result );
425- this .claimedInterfaceNumber = number ;
426+ this .claimedInterfaceNumbers . add ( number ) ;
426427 }
427428
428429 /**
@@ -435,9 +436,9 @@ final void claimInterface(final byte number, final boolean force)
435436 */
436437 final void releaseInterface (final byte number ) throws UsbException
437438 {
438- if (this .claimedInterfaceNumber == null )
439+ if (this .claimedInterfaceNumbers . isEmpty () )
439440 throw new UsbClaimException ("No interface is claimed" );
440- if (!Byte . valueOf ( number ). equals ( this . claimedInterfaceNumber ))
441+ if (!this . claimedInterfaceNumbers . contains ( number ))
441442 throw new UsbClaimException ("Interface not claimed" );
442443
443444 final DeviceHandle handle = open ();
@@ -452,7 +453,7 @@ final void releaseInterface(final byte number) throws UsbException
452453 "Uanble to re-attach kernel driver" , result );
453454 }
454455
455- this .claimedInterfaceNumber = null ;
456+ this .claimedInterfaceNumbers . remove ( number ) ;
456457 }
457458
458459 /**
@@ -464,7 +465,7 @@ final void releaseInterface(final byte number) throws UsbException
464465 */
465466 final boolean isInterfaceClaimed (final byte number )
466467 {
467- return Byte . valueOf ( number ). equals ( this . claimedInterfaceNumber );
468+ return this . claimedInterfaceNumbers . contains ( number );
468469 }
469470
470471 @ Override
0 commit comments