Skip to content

Linux + iPhone Continuity / iMessage / SMS

fix: airpods faster linux reclaim

Zack Bartel076100628b87
diff --git a/src/core/include/tether/bluetooth/connection.hpp b/src/core/include/tether/bluetooth/connection.hpp
index 05aa401..0568bb5 100644
--- a/src/core/include/tether/bluetooth/connection.hpp
+++ b/src/core/include/tether/bluetooth/connection.hpp
@@ -68,6 +68,8 @@ namespace tether::bluetooth {
bool call_action(const std::string& path, const std::string& action, std::string& err);
bool call_tones(const std::string& tones, std::string& err);
nlohmann::json calls() const;
+ // Whether the phone has Hands-Free up.
+ bool calls_available() const;
nlohmann::json notifications(size_t limit = 50) const;
~ConnectionManager();
diff --git a/src/core/src/bluetooth/connection.cpp b/src/core/src/bluetooth/connection.cpp
index caacac0..5931b0f 100644
--- a/src/core/src/bluetooth/connection.cpp
+++ b/src/core/src/bluetooth/connection.cpp
@@ -1483,6 +1483,11 @@ namespace tether::bluetooth {
return client->send_tones(tones, err);
}
+ bool ConnectionManager::calls_available() const {
+ auto client = state_->calls_client();
+ return client && client->available();
+ }
+
nlohmann::json ConnectionManager::calls() const {
auto client = state_->calls_client();
if (!client)
diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp
index 10af28c..0b565be 100644
--- a/src/daemon/main.cpp
+++ b/src/daemon/main.cpp
@@ -294,7 +294,7 @@ int main(int argc, char** argv) {
// worker, the call handler, and the end of each handoff thread, so deciding and marking busy
// is one step.
std::function<void(const tether::bluetooth::AirPodsState&)> run_ownership;
- run_ownership = [handoff, phone_busy, &run_ownership](const tether::bluetooth::AirPodsState& state) {
+ run_ownership = [handoff, phone_busy, &connections, &run_ownership](const tether::bluetooth::AirPodsState& state) {
const auto config = tether::bluetooth::load_config();
const bool busy_now = phone_busy(state);
@@ -348,10 +348,11 @@ int main(int argc, char** argv) {
return;
}
- std::thread([handoff, phone_busy, &run_ownership] {
+ std::thread([handoff, phone_busy, &connections, &run_ownership] {
bool reclaimed = false;
for (int attempt = 0; attempt < HANDOFF_RECLAIM_ATTEMPTS && !reclaimed; ++attempt) {
- std::this_thread::sleep_for(std::chrono::seconds(HANDOFF_GUARD_SECONDS));
+ if (attempt > 0 || !connections.calls_available())
+ std::this_thread::sleep_for(std::chrono::seconds(HANDOFF_GUARD_SECONDS));
if (!tether::bluetooth::g_airpods)
break;
if (phone_busy(tether::bluetooth::g_airpods->state()))