Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bluetooth] Fix disappearing bluetooth devices in Inbox #10187

Merged
merged 2 commits into from
Feb 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -294,6 +301,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