From bd8ea8943afb473785f9f9623ebdc399645e325c Mon Sep 17 00:00:00 2001 From: Adrian Muzyka Date: Thu, 7 Nov 2024 13:42:36 +0100 Subject: [PATCH] RDK-53686 Analytics: Fix SystemTime deadlock Parse TimeZone on request and out of lock scope --- .../Implementation/SystemTime/SystemTime.cpp | 33 ++++++++----------- .../Implementation/SystemTime/SystemTime.h | 2 -- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/Analytics/Implementation/SystemTime/SystemTime.cpp b/Analytics/Implementation/SystemTime/SystemTime.cpp index 36aee1d97..06d6e64b6 100644 --- a/Analytics/Implementation/SystemTime/SystemTime.cpp +++ b/Analytics/Implementation/SystemTime/SystemTime.cpp @@ -40,8 +40,6 @@ namespace WPEFramework mTimeQuality(TIME_QUALITY_STALE), mTimeZone(), mTimeZoneAccuracyString(), - mTimeZoneAccuracy(ACC_UNDEFINED), - mTimeZoneOffsetSec(0), mTransitionMap(), mIsSystemTimeAvailable(false), mShell(shell) @@ -98,20 +96,28 @@ namespace WPEFramework } } - LOGINFO("IsSystemTimeAvailable: %d", isAvailable); return isAvailable; } SystemTime::TimeZoneAccuracy SystemTime::GetTimeZoneOffset(int32_t &offsetSec) { - SystemTime::TimeZoneAccuracy accuracy = ACC_UNDEFINED; + std::string tz; + std::string accuracyString; + bool isTimeAvailable = false; { std::lock_guard guard(mLock); - offsetSec = mTimeZoneOffsetSec; - accuracy = mTimeZoneAccuracy; + tz = mTimeZone; + accuracyString = mTimeZoneAccuracyString; + isTimeAvailable = mIsSystemTimeAvailable; } - return accuracy; + if (isTimeAvailable) + { + std::pair tzParsed = ParseTimeZone(tz, accuracyString); + offsetSec = tzParsed.second; + return tzParsed.first; + } + return ACC_UNDEFINED; } void SystemTime::onTimeStatusChanged(const JsonObject& parameters) @@ -231,11 +237,8 @@ namespace WPEFramework std::lock_guard guard(mLock); if (mTimeZone != tz || mTimeZoneAccuracyString != accuracy) { - std::pair tzParsed = ParseTimeZone(tz, accuracy); mTimeZone = tz; mTimeZoneAccuracyString = accuracy; - mTimeZoneAccuracy = tzParsed.first; - mTimeZoneOffsetSec = tzParsed.second; } } } @@ -264,7 +267,6 @@ namespace WPEFramework if (timeZone == "Universal") { result.second = 0; - LOGINFO("timeZoneOff: %d", result.second); return result; } @@ -282,13 +284,11 @@ namespace WPEFramework if (currentTimeEndItr != mTransitionMap.end()) { result.second = currentTimeEndItr->second; - LOGINFO("timeZoneOff: %d", result.second); } else if (mTransitionMap.empty() == false) { currentTimeEndItr--; // take the last transition when all transitions are from past result.second = currentTimeEndItr->second; - LOGINFO("timeZoneOff: %d", result.second); } else { @@ -398,10 +398,6 @@ namespace WPEFramework LOGERR("v_secure_popen of zdump -v %s failed", mTimeZone.c_str()); } } - else - { - LOGINFO("No update required"); - } } @@ -467,11 +463,8 @@ namespace WPEFramework std::lock_guard guard(mLock); if (mTimeZone != tz || mTimeZoneAccuracyString != accuracy) { - std::pair tzParsed = ParseTimeZone(tz, accuracy); mTimeZone = tz; mTimeZoneAccuracyString = accuracy; - mTimeZoneAccuracy = tzParsed.first; - mTimeZoneOffsetSec = tzParsed.second; } } } diff --git a/Analytics/Implementation/SystemTime/SystemTime.h b/Analytics/Implementation/SystemTime/SystemTime.h index 8b4022a41..a0c1e80e4 100644 --- a/Analytics/Implementation/SystemTime/SystemTime.h +++ b/Analytics/Implementation/SystemTime/SystemTime.h @@ -87,8 +87,6 @@ namespace WPEFramework std::string mTimeQuality; std::string mTimeZone; std::string mTimeZoneAccuracyString; - TimeZoneAccuracy mTimeZoneAccuracy; - int32_t mTimeZoneOffsetSec; std::map mTransitionMap; bool mIsSystemTimeAvailable; PluginHost::IShell *mShell;