[bluetooth] Fix disappearing bluetooth devices in Inbox (#10187)

* [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>
This commit is contained in:
Pete 2021-02-25 23:51:34 +01:00 committed by GitHub
parent 71ffce707e
commit cdf044c070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -133,6 +133,13 @@ public class BluetoothDiscoveryService extends AbstractDiscoveryService implemen
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());
}
@ -290,6 +297,12 @@ public class BluetoothDiscoveryService extends AbstractDiscoveryService implemen
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) {