From aeaadb899cb065242859f0368688d8e46edf0807 Mon Sep 17 00:00:00 2001 From: ColdPaleLight Date: Sat, 9 Oct 2021 06:59:10 +0800 Subject: [PATCH] Ensure that frameTimeNanos passed to VsyncWaiterAndroid is not greater than System.nanoTime --- shell/platform/android/io/flutter/view/VsyncWaiter.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/shell/platform/android/io/flutter/view/VsyncWaiter.java b/shell/platform/android/io/flutter/view/VsyncWaiter.java index 89ff20dbee951..933309d594ae7 100644 --- a/shell/platform/android/io/flutter/view/VsyncWaiter.java +++ b/shell/platform/android/io/flutter/view/VsyncWaiter.java @@ -31,6 +31,13 @@ public void asyncWaitForVsync(long cookie) { new Choreographer.FrameCallback() { @Override public void doFrame(long frameTimeNanos) { + // Some device is calling doFrame with a timestamp that is greater than + // System.nanoTime. We should ensure that frameTimeNanos passed to + // VsyncWaiterAndroid is not greater than System.nanoTime. + long now = System.nanoTime(); + if (frameTimeNanos > now) { + frameTimeNanos = now; + } long refreshPeriodNanos = (long) (1000000000.0 / fps); FlutterJNI.nativeOnVsync( frameTimeNanos, frameTimeNanos + refreshPeriodNanos, cookie);