diff options
Diffstat (limited to 'vibrator/common/StatsBase.cpp')
-rw-r--r-- | vibrator/common/StatsBase.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/vibrator/common/StatsBase.cpp b/vibrator/common/StatsBase.cpp index 68b8a2dc..a0402b4e 100644 --- a/vibrator/common/StatsBase.cpp +++ b/vibrator/common/StatsBase.cpp @@ -129,21 +129,22 @@ void StatsBase::uploadDiagnostics() { uploadErrorAtoms(); } -void StatsBase::waitForStatsService() const { +std::shared_ptr<IStats> StatsBase::waitForStatsService() const { STATS_TRACE("waitForStatsService()"); if (!AServiceManager_isDeclared(kStatsInstanceName.c_str())) { ALOGE("IStats service '%s' is not registered.", kStatsInstanceName.c_str()); - return; + return nullptr; } ALOGI("Waiting for IStats service '%s' to come up.", kStatsInstanceName.c_str()); - const std::shared_ptr<IStats> statsClient = IStats::fromBinder( + std::shared_ptr<IStats> client = IStats::fromBinder( ndk::SpAIBinder(AServiceManager_waitForService(kStatsInstanceName.c_str()))); - if (!statsClient) { + if (!client) { ALOGE("Failed to get IStats service '%s'.", kStatsInstanceName.c_str()); - return; + return nullptr; } ALOGI("IStats service online."); + return client; } void StatsBase::runReporterThread() { @@ -152,8 +153,6 @@ void StatsBase::runReporterThread() { auto nextUpload = clock::now() + UPLOAD_INTERVAL; auto status = std::cv_status::no_timeout; - waitForStatsService(); - while (!mTerminateReporterThread) { drainAtomQueue(); { @@ -178,15 +177,14 @@ void StatsBase::drainAtomQueue() { std::swap(mAtomQueue, tempQueue); } - std::shared_ptr<IStats> statsClient = IStats::fromBinder( - ndk::SpAIBinder(AServiceManager_waitForService(kStatsInstanceName.c_str()))); - if (!statsClient) { + std::shared_ptr<IStats> client = waitForStatsService(); + if (!client) { ALOGE("Failed to get IStats service. Atoms are dropped."); return; } for (const VendorAtom &atom : tempQueue) { - reportVendorAtom(statsClient, atom); + reportVendorAtom(client, atom); } } |