Skip to content

Commit b7c2e6e

Browse files
adrianM27goruklu
authored andcommitted
RDK-53686 Analytics: Fix SystemTime deadlock
Parse TimeZone on request and out of lock scope
1 parent 60c3e2e commit b7c2e6e

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

Analytics/Implementation/SystemTime/SystemTime.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ namespace WPEFramework
4040
mTimeQuality(TIME_QUALITY_STALE),
4141
mTimeZone(),
4242
mTimeZoneAccuracyString(),
43-
mTimeZoneAccuracy(ACC_UNDEFINED),
44-
mTimeZoneOffsetSec(0),
4543
mTransitionMap(),
4644
mIsSystemTimeAvailable(false),
4745
mShell(shell)
@@ -98,20 +96,28 @@ namespace WPEFramework
9896
}
9997
}
10098

101-
LOGINFO("IsSystemTimeAvailable: %d", isAvailable);
10299
return isAvailable;
103100
}
104101

105102
SystemTime::TimeZoneAccuracy SystemTime::GetTimeZoneOffset(int32_t &offsetSec)
106103
{
107-
SystemTime::TimeZoneAccuracy accuracy = ACC_UNDEFINED;
104+
std::string tz;
105+
std::string accuracyString;
106+
bool isTimeAvailable = false;
108107
{
109108
std::lock_guard<std::mutex> guard(mLock);
110-
offsetSec = mTimeZoneOffsetSec;
111-
accuracy = mTimeZoneAccuracy;
109+
tz = mTimeZone;
110+
accuracyString = mTimeZoneAccuracyString;
111+
isTimeAvailable = mIsSystemTimeAvailable;
112112
}
113113

114-
return accuracy;
114+
if (isTimeAvailable)
115+
{
116+
std::pair<SystemTime::TimeZoneAccuracy, int32_t> tzParsed = ParseTimeZone(tz, accuracyString);
117+
offsetSec = tzParsed.second;
118+
return tzParsed.first;
119+
}
120+
return ACC_UNDEFINED;
115121
}
116122

117123
void SystemTime::onTimeStatusChanged(const JsonObject& parameters)
@@ -231,11 +237,8 @@ namespace WPEFramework
231237
std::lock_guard<std::mutex> guard(mLock);
232238
if (mTimeZone != tz || mTimeZoneAccuracyString != accuracy)
233239
{
234-
std::pair<SystemTime::TimeZoneAccuracy, int32_t> tzParsed = ParseTimeZone(tz, accuracy);
235240
mTimeZone = tz;
236241
mTimeZoneAccuracyString = accuracy;
237-
mTimeZoneAccuracy = tzParsed.first;
238-
mTimeZoneOffsetSec = tzParsed.second;
239242
}
240243
}
241244
}
@@ -264,7 +267,6 @@ namespace WPEFramework
264267
if (timeZone == "Universal")
265268
{
266269
result.second = 0;
267-
LOGINFO("timeZoneOff: %d", result.second);
268270
return result;
269271
}
270272

@@ -282,13 +284,11 @@ namespace WPEFramework
282284
if (currentTimeEndItr != mTransitionMap.end())
283285
{
284286
result.second = currentTimeEndItr->second;
285-
LOGINFO("timeZoneOff: %d", result.second);
286287
}
287288
else if (mTransitionMap.empty() == false)
288289
{
289290
currentTimeEndItr--; // take the last transition when all transitions are from past
290291
result.second = currentTimeEndItr->second;
291-
LOGINFO("timeZoneOff: %d", result.second);
292292
}
293293
else
294294
{
@@ -398,10 +398,6 @@ namespace WPEFramework
398398
LOGERR("v_secure_popen of zdump -v %s failed", mTimeZone.c_str());
399399
}
400400
}
401-
else
402-
{
403-
LOGINFO("No update required");
404-
}
405401
}
406402

407403

@@ -467,11 +463,8 @@ namespace WPEFramework
467463
std::lock_guard<std::mutex> guard(mLock);
468464
if (mTimeZone != tz || mTimeZoneAccuracyString != accuracy)
469465
{
470-
std::pair<SystemTime::TimeZoneAccuracy, int32_t> tzParsed = ParseTimeZone(tz, accuracy);
471466
mTimeZone = tz;
472467
mTimeZoneAccuracyString = accuracy;
473-
mTimeZoneAccuracy = tzParsed.first;
474-
mTimeZoneOffsetSec = tzParsed.second;
475468
}
476469
}
477470
}

Analytics/Implementation/SystemTime/SystemTime.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ namespace WPEFramework
8787
std::string mTimeQuality;
8888
std::string mTimeZone;
8989
std::string mTimeZoneAccuracyString;
90-
TimeZoneAccuracy mTimeZoneAccuracy;
91-
int32_t mTimeZoneOffsetSec;
9290
std::map<time_t, int32_t> mTransitionMap;
9391
bool mIsSystemTimeAvailable;
9492
PluginHost::IShell *mShell;

0 commit comments

Comments
 (0)