Skip to content

Commit

Permalink
RDK-53686 Analytics: Fix SystemTime deadlock
Browse files Browse the repository at this point in the history
Parse TimeZone on request and out of lock scope
  • Loading branch information
adrianM27 committed Nov 7, 2024
1 parent 80305b0 commit 3ead567
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
33 changes: 13 additions & 20 deletions Analytics/Implementation/SystemTime/SystemTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ namespace WPEFramework
mTimeQuality(TIME_QUALITY_STALE),
mTimeZone(),
mTimeZoneAccuracyString(),
mTimeZoneAccuracy(ACC_UNDEFINED),
mTimeZoneOffsetSec(0),
mTransitionMap(),
mIsSystemTimeAvailable(false),
mShell(shell)
Expand Down Expand Up @@ -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<std::mutex> guard(mLock);
offsetSec = mTimeZoneOffsetSec;
accuracy = mTimeZoneAccuracy;
tz = mTimeZone;
accuracyString = mTimeZoneAccuracyString;
isTimeAvailable = mIsSystemTimeAvailable;
}

return accuracy;
if (isTimeAvailable)
{
std::pair<SystemTime::TimeZoneAccuracy, int32_t> tzParsed = ParseTimeZone(tz, accuracyString);
offsetSec = tzParsed.second;
return tzParsed.first;
}
return ACC_UNDEFINED;
}

void SystemTime::onTimeStatusChanged(const JsonObject& parameters)
Expand Down Expand Up @@ -231,11 +237,8 @@ namespace WPEFramework
std::lock_guard<std::mutex> guard(mLock);
if (mTimeZone != tz || mTimeZoneAccuracyString != accuracy)
{
std::pair<SystemTime::TimeZoneAccuracy, int32_t> tzParsed = ParseTimeZone(tz, accuracy);
mTimeZone = tz;
mTimeZoneAccuracyString = accuracy;
mTimeZoneAccuracy = tzParsed.first;
mTimeZoneOffsetSec = tzParsed.second;
}
}
}
Expand Down Expand Up @@ -264,7 +267,6 @@ namespace WPEFramework
if (timeZone == "Universal")
{
result.second = 0;
LOGINFO("timeZoneOff: %d", result.second);
return result;
}

Expand All @@ -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
{
Expand Down Expand Up @@ -398,10 +398,6 @@ namespace WPEFramework
LOGERR("v_secure_popen of zdump -v %s failed", mTimeZone.c_str());
}
}
else
{
LOGINFO("No update required");
}
}


Expand Down Expand Up @@ -467,11 +463,8 @@ namespace WPEFramework
std::lock_guard<std::mutex> guard(mLock);
if (mTimeZone != tz || mTimeZoneAccuracyString != accuracy)
{
std::pair<SystemTime::TimeZoneAccuracy, int32_t> tzParsed = ParseTimeZone(tz, accuracy);
mTimeZone = tz;
mTimeZoneAccuracyString = accuracy;
mTimeZoneAccuracy = tzParsed.first;
mTimeZoneOffsetSec = tzParsed.second;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions Analytics/Implementation/SystemTime/SystemTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ namespace WPEFramework
std::string mTimeQuality;
std::string mTimeZone;
std::string mTimeZoneAccuracyString;
TimeZoneAccuracy mTimeZoneAccuracy;
int32_t mTimeZoneOffsetSec;
std::map<time_t, int32_t> mTransitionMap;
bool mIsSystemTimeAvailable;
PluginHost::IShell *mShell;
Expand Down

0 comments on commit 3ead567

Please sign in to comment.