From a2f78825f2dbdc0d48eb0a8015b1690a924c5566 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Fri, 17 Jun 2016 16:23:17 -0700 Subject: [PATCH] RN: Increase Time Drift Threshold Summary: Increases time drift threshold to reduce chance of false positives. Also, tweaked the error message to contain slightly more information. Reviewed By: frantic Differential Revision: D3450852 fbshipit-source-id: 7fbf3eb25543977f9767c7a57277db336006bd12 --- .../facebook/react/modules/core/Timing.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java b/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java index 01bf221bf..57ec14bdd 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java @@ -217,16 +217,27 @@ public final class Timing extends ReactContextBaseJavaModule implements Lifecycl final int duration, final double jsSchedulingTime, final boolean repeat) { + long deviceTime = SystemClock.currentTimeMillis(); + long remoteTime = (long) jsSchedulingTime; + // If the times on the server and device have drifted throw an exception to warn the developer // that things might not work or results may not be accurate. This is required only for // developer builds. - if (mDevSupportManager.getDevSupportEnabled() && Math.abs(jsSchedulingTime - System.currentTimeMillis()) > 1000) { - throw new RuntimeException("System and emulator/device times have drifted. Please correct this by running adb shell \"date `date +%m%d%H%M%Y.%S`\" on your dev machine"); + if (mDevSupportManager.getDevSupportEnabled()) { + long driftTime = Math.abs(remoteTime - deviceTime); + if (driftTime > 60000) { + throw new RuntimeException( + "Debugger and device times have drifted by " + driftTime + "ms. " + + "Please correct this by running adb shell " + + "\"date `date +%m%d%H%M%Y.%S`\" on your debugger machine.\n" + + "Debugger Time = " + remoteTime + "\n" + + "Device Time = " + deviceTime + ); + } } + // Adjust for the amount of time it took for native to receive the timer registration call - long adjustedDuration = (long) Math.max( - 0, - jsSchedulingTime - SystemClock.currentTimeMillis() + duration); + long adjustedDuration = Math.max(0, remoteTime - deviceTime + duration); if (duration == 0 && !repeat) { WritableArray timerToCall = Arguments.createArray(); timerToCall.pushInt(callbackID);