Move an orphaned analytics reference under a mutex

Bug: 167695677
Bug: 151644303
Test: poc from bugs
Merged-In: I75f29a6254c5eab5d4f524ee7a7ef59f93a0b405
Change-Id: I0a5a532e9e96baf95efc2b82dba07adc7baf4930
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
index 3f34046..000881b 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
@@ -553,7 +553,6 @@
     // getDuration() uses mLock
     int duration_ms = -1;
     getDuration(&duration_ms);
-    mAnalyticsItem->setInt64(kPlayerDuration, duration_ms);
 
     mPlayer->updateInternalTimers();
 
@@ -575,13 +574,14 @@
     // we also avoid any races within mAnalyticsItem machinery
     Mutex::Autolock autoLock(mMetricsLock);
 
+    mAnalyticsItem->setInt64(kPlayerDuration, duration_ms);
+
     mAnalyticsItem->setInt64(kPlayerPlaying, (playingTimeUs+500)/1000 );
 
     if (mRebufferingEvents != 0) {
         mAnalyticsItem->setInt64(kPlayerRebuffering, (rebufferingTimeUs+500)/1000 );
         mAnalyticsItem->setInt32(kPlayerRebufferingCount, rebufferingEvents);
         mAnalyticsItem->setInt32(kPlayerRebufferingAtExit, rebufferingAtExit);
-
      }
 
     mAnalyticsItem->setCString(kPlayerDataSourceType, mPlayer->getDataSourceType());