@@ -416,7 +416,9 @@ def __setTransport(self, timeout=60):
416416 device = Device .factory (line [4 :])
417417 if device .status == 'device' :
418418 devices .append (device )
419+ # this looks like a bug, we skip serialno matching here
419420 found = True
421+ self .serialno = device .serialno
420422 break
421423 if found :
422424 break
@@ -437,12 +439,22 @@ def __setTransport(self, timeout=60):
437439 if len (devices ) == 0 :
438440 raise RuntimeError ("ERROR: There are no connected devices" )
439441 for device in devices :
440- if serialnoRE .match (device .serialno ) or device .has_qualifier (self .serialno ):
442+ if serialnoRE .match (device .serialno ):
443+ found = True
444+ # self.serialno could've been a regexp, we can't feed that to adb as a transport
445+ self .serialno = device .serialno
446+ break
447+ if device .has_qualifier (self .serialno ):
448+ # self.serialno is a proper transport value, it could be more specific than device.serialno
449+ # For instance devpath/usbpath specifies exactly one device, while serialno might be the same
450+ # for reflashed devices.
451+ # The only flipside here is that we fail to pick one (first/random) device from possibly many
452+ # having the same qualifier (product: model: or device:) if they have different serials.
453+ # This could be fixed by some custom logic or using host:transport-id: support in newer and.
441454 found = True
442455 break
443456 if not found :
444457 raise RuntimeError ("ERROR: couldn't find device that matches '%s' in %s" % (self .serialno , devices ))
445- self .serialno = device .serialno
446458 msg = 'host:transport:%s' % self .serialno
447459 if DEBUG :
448460 print >> sys .stderr , " __setTransport: msg=" , msg
0 commit comments