Skip to content

Commit

Permalink
Update adb devices in the registry when their status changes.
Browse files Browse the repository at this point in the history
If a device's status changes in adb, this change will cause it to be
removed from the registry and re-added, in order to keep the device
configuration information up-to-date. When a device is added to the
registry, it's configuration is queried, which fails if the device is not
online and the device is added with empty/incomplete information. With
this change, such a device is updated once it becomes online. This is
especially needed for devices needing user authorization, since we're
likely to see the un-authorized device long before the user can give
permissions in the dialog.

Fixes #1445
  • Loading branch information
pmuetschard authored and ben-clayton committed Dec 5, 2017
1 parent 7ef86a2 commit e90a78a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions core/os/android/adb/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,22 +194,25 @@ func scanDevices(ctx context.Context) error {
defer cacheMutex.Unlock()

for serial, status := range parsed {
device, ok := cache[serial]
if !ok {
device, err = newDevice(ctx, serial, status)
cached, ok := cache[serial]
if !ok || status != cached.Status() {
device, err := newDevice(ctx, serial, status)
if err != nil {
return err
}
if ok {
registry.RemoveDevice(ctx, cached)
}
cache[serial] = device
registry.AddDevice(ctx, device)
}
}

// Remove cached results for removed devices.
for serial, device := range cache {
for serial, cached := range cache {
if _, found := parsed[serial]; !found {
delete(cache, serial)
registry.RemoveDevice(ctx, device)
registry.RemoveDevice(ctx, cached)
}
}

Expand Down

0 comments on commit e90a78a

Please sign in to comment.