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
This commit is contained in:
Tim Yung 2016-06-17 16:23:17 -07:00 committed by Facebook Github Bot 3
parent 8ca3a0c91c
commit a2f78825f2
1 changed files with 16 additions and 5 deletions

View File

@ -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);