Skip to content

Commit

Permalink
[bluetooth] Fix disappearing bluetooth devices in Inbox (#10187)
Browse files Browse the repository at this point in the history
* [bluetooth] Notify things again when they are removed from listeners like Inbox
* [bluetooth] Add javadoc on retractDiscoveryResult()

Signed-off-by: Peter Rosenberg <prosenb.dev@gmail.com>
  • Loading branch information
PRosenb authored Feb 25, 2021
1 parent 71ffce7 commit cdf044c
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ public void stopScan() {
for (BluetoothAdapter adapter : adapters) {
adapter.scanStop();
}

// The method `removeOlderResults()` removes the Things from listeners like `Inbox`.
// We therefore need to reset `latestSnapshot` so that the Things are notified again next time.
// Results newer than `getTimestampOfLastScan()` will also be notified again but do not lead to duplicates.
discoveryCaches.values().forEach(discoveryCache -> {
discoveryCache.latestSnapshot.putValue(null);
});
removeOlderResults(getTimestampOfLastScan());
}

Expand Down Expand Up @@ -290,6 +297,12 @@ private void publishDiscoveryResult(BluetoothAdapter adapter, DiscoveryResult re
discoveryResults.put(adapter, results);
}

/**
* Called when a new discovery is published and thus requires the old discovery to be removed first.
*
* @param adapter to get the results to be removed
* @param result unused
*/
private void retractDiscoveryResult(BluetoothAdapter adapter, DiscoveryResult result) {
Set<DiscoveryResult> results = discoveryResults.remove(adapter);
if (results != null) {
Expand Down

0 comments on commit cdf044c

Please sign in to comment.