From b47b6d41d8749a8887d3e2123039822baf3c05ee Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 24 Feb 2025 11:30:47 +0100 Subject: [PATCH] (Android) Changed system status polling to run on the main thread --- es-core/src/SystemStatus.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/es-core/src/SystemStatus.cpp b/es-core/src/SystemStatus.cpp index d287cbd20..9f7e3c771 100644 --- a/es-core/src/SystemStatus.cpp +++ b/es-core/src/SystemStatus.cpp @@ -49,20 +49,31 @@ SystemStatus::SystemStatus() noexcept , mHasBattery {false} , mBatteryCharging {false} , mBatteryCapacity {0} - { setCheckFlags(); + +#if defined(__ANDROID__) + // Polling the device status is very fast on Android and it's quite problematic to run + // these calls in a separate thread anyway. + getStatusBluetooth(); + getStatusWifi(); + getStatusCellular(); + getStatusBattery(); +#else mPollThread = std::make_unique(&SystemStatus::pollStatus, this); +#endif } SystemStatus::~SystemStatus() { +#if !defined(__ANDROID__) mExitPolling = true; if (mPollThread != nullptr && mPollThread->joinable()) { mPollThread->join(); mPollThread.reset(); } +#endif } SystemStatus& SystemStatus::getInstance() @@ -82,6 +93,10 @@ void SystemStatus::setCheckFlags() void SystemStatus::setPolling(const bool state) { +#if defined(__ANDROID__) + return; +#endif + if (state == false) { mExitPolling = true; if (mPollThread != nullptr && mPollThread->joinable()) { @@ -97,6 +112,13 @@ void SystemStatus::setPolling(const bool state) SystemStatus::Status SystemStatus::getStatus() { +#if defined(__ANDROID__) + getStatusBluetooth(); + getStatusWifi(); + getStatusCellular(); + getStatusBattery(); +#endif + mStatus.hasBluetooth = mHasBluetooth; mStatus.hasWifi = mHasWifi; mStatus.hasCellular = mHasCellular;