floss: Abort freshness_check JoinHandle before dropping.
Dropping the handle doesn't abort the future job. This CL aborts the
future job properly to prevent from creating duplicate recurring tasks.
Bug: 244510343
Tag: #floss
Test: build.py --target test
Change-Id: I9d13ed4b54011de2532365ddfec802a719c8389f
diff --git a/system/gd/rust/linux/stack/src/bluetooth.rs b/system/gd/rust/linux/stack/src/bluetooth.rs
index ca42af9..a85ee79 100644
--- a/system/gd/rust/linux/stack/src/bluetooth.rs
+++ b/system/gd/rust/linux/stack/src/bluetooth.rs
@@ -476,8 +476,11 @@
/// Check whether found devices are still fresh. If they're outside the
/// freshness window, send a notification to clear the device from clients.
pub(crate) fn trigger_freshness_check(&mut self) {
- // Drop previous joinhandle
- self.freshness_check = None;
+ if let Some(ref handle) = self.freshness_check {
+ // Abort and drop the previous JoinHandle.
+ handle.abort();
+ self.freshness_check = None;
+ }
// A found device is considered fresh if:
// * It was last seen less than |FOUND_DEVICE_FRESHNESS| ago.