@@ -397,7 +397,7 @@ public Task<Void> call() throws Exception {
397397 // We've fatally crashed, so write the marker file that indicates a crash occurred.
398398 crashMarker .create ();
399399
400- long timestampSeconds = time . getTime () / 1000 ;
400+ long timestampSeconds = getTimestampSeconds ( time ) ;
401401 reportingCoordinator .persistFatalEvent (ex , thread , timestampSeconds );
402402 writeFatal (thread , ex , timestampSeconds );
403403
@@ -648,7 +648,7 @@ void writeNonFatalException(final Thread thread, final Throwable ex) {
648648 @ Override
649649 public void run () {
650650 if (!isHandlingException ()) {
651- long timestampSeconds = time . getTime () / 1000 ;
651+ long timestampSeconds = getTimestampSeconds ( time ) ;
652652 reportingCoordinator .persistNonFatalEvent (ex , thread , timestampSeconds );
653653 doWriteNonFatal (thread , ex , timestampSeconds );
654654 }
@@ -802,7 +802,7 @@ boolean finalizeSessions(int maxCustomExceptionEvents) {
802802 * class.
803803 */
804804 private void doOpenSession () throws Exception {
805- final long startedAtSeconds = new Date (). getTime () / 1000 ;
805+ final long startedAtSeconds = getCurrentTimestampSeconds () ;
806806 final String sessionIdentifier = new CLSUUID (idManager ).toString ();
807807
808808 Logger .getLogger ().d ("Opening a new session with ID " + sessionIdentifier );
@@ -860,7 +860,7 @@ private void doCloseSessions(int maxCustomExceptionEvents, boolean includeCurren
860860
861861 closeOpenSessions (sessionBeginFiles , offset , maxCustomExceptionEvents );
862862
863- reportingCoordinator .finalizeSessions (new Date (). getTime () / 1000 );
863+ reportingCoordinator .finalizeSessions (getCurrentTimestampSeconds () );
864864 }
865865
866866 /**
@@ -1196,6 +1196,14 @@ private static void gzip(@NonNull byte[] bytes, @NonNull File path) throws IOExc
11961196 }
11971197 }
11981198
1199+ private static long getCurrentTimestampSeconds () {
1200+ return getTimestampSeconds (new Date ());
1201+ }
1202+
1203+ private static long getTimestampSeconds (Date date ) {
1204+ return date .getTime () / 1000 ;
1205+ }
1206+
11991207 /** Removes dashes in the Crashlytics session identifier to conform to Firebase constraints. */
12001208 private static String makeFirebaseSessionIdentifier (String sessionIdentifier ) {
12011209 return sessionIdentifier .replaceAll ("-" , "" );
@@ -1586,7 +1594,7 @@ private void synthesizeSessionFile(
15861594 Logger .getLogger ().d ("Collecting SessionStart data for session ID " + sessionId );
15871595 writeToCosFromFile (cos , sessionBeginFile );
15881596
1589- cos .writeUInt64 (4 , new Date (). getTime () / 1000 );
1597+ cos .writeUInt64 (4 , getCurrentTimestampSeconds () );
15901598 cos .writeBool (5 , hasFatal );
15911599
15921600 cos .writeUInt32 (11 , ANALYZER_VERSION );
0 commit comments