From c626fcbe656ee7da8543464a59d4f9c541e41aa2 Mon Sep 17 00:00:00 2001 From: Jia Hao Date: Tue, 13 Sep 2022 19:10:36 +0800 Subject: [PATCH] Revert "Avoid vsync scheduling delay" (flutter/engine#36091) --- .../ci/licenses_golden/licenses_flutter | 1 - .../flutter/shell/platform/android/BUILD.gn | 1 - .../engine/dart/PlatformTaskQueue.java | 5 +-- .../engine/loader/FlutterLoader.java | 3 +- .../io/flutter/util/HandlerCompat.java | 35 ------------------- .../io/flutter/util/HandlerCompatTest.java | 29 --------------- .../flutter/tools/android_lint/project.xml | 1 - 7 files changed, 2 insertions(+), 73 deletions(-) delete mode 100644 engine/src/flutter/shell/platform/android/io/flutter/util/HandlerCompat.java delete mode 100644 engine/src/flutter/shell/platform/android/test/io/flutter/util/HandlerCompatTest.java diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index b8c5efd95c..4b4bff000f 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -1645,7 +1645,6 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/Platfor FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/SingleViewPresentation.java FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java -FILE: ../../../flutter/shell/platform/android/io/flutter/util/HandlerCompat.java FILE: ../../../flutter/shell/platform/android/io/flutter/util/PathUtils.java FILE: ../../../flutter/shell/platform/android/io/flutter/util/Preconditions.java FILE: ../../../flutter/shell/platform/android/io/flutter/util/Predicate.java diff --git a/engine/src/flutter/shell/platform/android/BUILD.gn b/engine/src/flutter/shell/platform/android/BUILD.gn index 3a91161dc2..f4792e314a 100644 --- a/engine/src/flutter/shell/platform/android/BUILD.gn +++ b/engine/src/flutter/shell/platform/android/BUILD.gn @@ -289,7 +289,6 @@ android_java_sources = [ "io/flutter/plugin/platform/PlatformViewsController.java", "io/flutter/plugin/platform/SingleViewPresentation.java", "io/flutter/plugin/platform/VirtualDisplayController.java", - "io/flutter/util/HandlerCompat.java", "io/flutter/util/PathUtils.java", "io/flutter/util/Preconditions.java", "io/flutter/util/Predicate.java", diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/PlatformTaskQueue.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/PlatformTaskQueue.java index 82d022a439..e90ab89e62 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/PlatformTaskQueue.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/PlatformTaskQueue.java @@ -7,13 +7,10 @@ package io.flutter.embedding.engine.dart; import android.os.Handler; import android.os.Looper; import androidx.annotation.NonNull; -import io.flutter.util.HandlerCompat; /** A BinaryMessenger.TaskQueue that posts to the platform thread (aka main thread). */ public class PlatformTaskQueue implements DartMessenger.DartMessengerTaskQueue { - // Use an async handler because the default is subject to vsync synchronization and can result - // in delays when dispatching tasks. - @NonNull private final Handler handler = HandlerCompat.createAsyncHandler(Looper.getMainLooper()); + @NonNull private final Handler handler = new Handler(Looper.getMainLooper()); @Override public void dispatch(@NonNull Runnable runnable) { diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java index b09be89e4b..629984600d 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java @@ -23,7 +23,6 @@ import io.flutter.BuildConfig; import io.flutter.FlutterInjector; import io.flutter.Log; import io.flutter.embedding.engine.FlutterJNI; -import io.flutter.util.HandlerCompat; import io.flutter.util.PathUtils; import io.flutter.util.TraceSection; import io.flutter.view.VsyncWaiter; @@ -386,7 +385,7 @@ public class FlutterLoader { Log.e(TAG, "Flutter initialization failed.", e); throw new RuntimeException(e); } - HandlerCompat.createAsyncHandler(Looper.getMainLooper()) + new Handler(Looper.getMainLooper()) .post( () -> { ensureInitializationComplete(applicationContext.getApplicationContext(), args); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/util/HandlerCompat.java b/engine/src/flutter/shell/platform/android/io/flutter/util/HandlerCompat.java deleted file mode 100644 index de391419a9..0000000000 --- a/engine/src/flutter/shell/platform/android/io/flutter/util/HandlerCompat.java +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.util; - -import android.os.Build; -import android.os.Handler; -import android.os.Looper; - -/** Compatability wrapper over {@link Handler}. */ -public final class HandlerCompat { - /** - * Create a new Handler whose posted messages and runnables are not subject to synchronization - * barriers such as display vsync. - * - *

Messages sent to an async handler are guaranteed to be ordered with respect to one another, - * but not necessarily with respect to messages from other Handlers. Compatibility behavior: - * - *

- * - * @param looper the Looper that the new Handler should be bound to - * @return a new async Handler instance - * @see Handler#createAsync(Looper) - */ - public static Handler createAsyncHandler(Looper looper) { - if (Build.VERSION.SDK_INT >= 28) { - return Handler.createAsync(looper); - } - return new Handler(looper); - } -} diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/util/HandlerCompatTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/util/HandlerCompatTest.java deleted file mode 100644 index df1352aee6..0000000000 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/util/HandlerCompatTest.java +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.util; - -import static org.junit.Assert.assertTrue; - -import android.os.Handler; -import android.os.Looper; -import android.os.Message; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.annotation.Config; - -@RunWith(RobolectricTestRunner.class) -public class HandlerCompatTest { - @Test - @Config(sdk = 28) - public void createAsync_createsAnAsyncHandler() { - Handler handler = Handler.createAsync(Looper.getMainLooper()); - - Message message = Message.obtain(); - handler.sendMessageAtTime(message, 0); - - assertTrue(message.isAsynchronous()); - } -} diff --git a/engine/src/flutter/tools/android_lint/project.xml b/engine/src/flutter/tools/android_lint/project.xml index af48aa0b7c..18ba2775c9 100644 --- a/engine/src/flutter/tools/android_lint/project.xml +++ b/engine/src/flutter/tools/android_lint/project.xml @@ -23,7 +23,6 @@ -