[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:
parent
71ffce707e
commit
cdf044c070
|
@ -133,6 +133,13 @@ public class BluetoothDiscoveryService extends AbstractDiscoveryService implemen
|
||||||
for (BluetoothAdapter adapter : adapters) {
|
for (BluetoothAdapter adapter : adapters) {
|
||||||
adapter.scanStop();
|
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());
|
removeOlderResults(getTimestampOfLastScan());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,6 +297,12 @@ public class BluetoothDiscoveryService extends AbstractDiscoveryService implemen
|
||||||
discoveryResults.put(adapter, results);
|
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) {
|
private void retractDiscoveryResult(BluetoothAdapter adapter, DiscoveryResult result) {
|
||||||
Set<DiscoveryResult> results = discoveryResults.remove(adapter);
|
Set<DiscoveryResult> results = discoveryResults.remove(adapter);
|
||||||
if (results != null) {
|
if (results != null) {
|
||||||
|
|
Loading…
Reference in New Issue