From 005a1bac30d9e7402e9801f6c4726ed5fc2ee373 Mon Sep 17 00:00:00 2001 From: Emmanuel Garcia Date: Mon, 13 Sep 2021 13:56:48 -0700 Subject: [PATCH 1/2] Don't use rFD in pre-Q versions --- .../embedding/android/FlutterActivity.java | 11 +++-- .../android/FlutterActivityTest.java | 43 +++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java b/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java index 21033a84135ef..e4cc03465b12f 100644 --- a/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java +++ b/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java @@ -1093,10 +1093,13 @@ public void onFlutterTextureViewCreated(@NonNull FlutterTextureView flutterTextu @Override public void onFlutterUiDisplayed() { // Notifies Android that we're fully drawn so that performance metrics can be collected by - // Flutter performance tests. - // This was supported in KitKat (API 19), but has a bug around requiring - // permissions. See https://github.com/flutter/flutter/issues/46172 - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + // Flutter performance tests. A few considerations: + // * rFD was supported in KitKat (API 19), but has a bug around requiring + // permissions in some Android versions. + // * rFD behavior isn't tested on pre-Q versions. + // See https://github.com/flutter/flutter/issues/46172, and + // https://github.com/flutter/flutter/issues/88767. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { reportFullyDrawn(); } } diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java index 6abee827641ba..4fc2f827b6eec 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java @@ -438,6 +438,32 @@ public void itWithMetadataWithoutSplashScreenResourceKeyDoesNotProvideSplashScre assertNull(splashScreen); } + @Test + public void fullyDrawn() { + Intent intent = + FlutterActivityWithReportFullyDrawn.createDefaultIntent(RuntimeEnvironment.application); + ActivityController activityController = + Robolectric.buildActivity(FlutterActivityWithReportFullyDrawn.class, intent); + FlutterActivityWithReportFullyDrawn flutterActivity = activityController.get(); + + // See https://github.com/flutter/flutter/issues/46172, and + // https://github.com/flutter/flutter/issues/88767. + for (int version = Build.VERSION_CODES.JELLY_BEAN; version < Build.VERSION_CODES.Q; version++) { + TestUtils.setApiVersion(version); + flutterActivity.onFlutterUiDisplayed(); + assertFalse( + "reportFullyDrawn isn't used in API level " + version, flutterActivity.isFullyDrawn()); + } + + for (int version = Build.VERSION_CODES.Q; version < Build.VERSION_CODES.S; version++) { + TestUtils.setApiVersion(version); + flutterActivity.onFlutterUiDisplayed(); + assertTrue( + "reportFullyDrawn is used in API level " + version, flutterActivity.isFullyDrawn()); + flutterActivity.resetFullyDrawn(); + } + } + static class FlutterActivityWithProvidedEngine extends FlutterActivity { @Override @SuppressLint("MissingSuperCall") @@ -478,6 +504,23 @@ public RenderMode getRenderMode() { } } + private static class FlutterActivityWithReportFullyDrawn extends FlutterActivity { + private boolean fullyDrawn = false; + + @Override + public void reportFullyDrawn() { + fullyDrawn = true; + } + + public boolean isFullyDrawn() { + return fullyDrawn; + } + + public void resetFullyDrawn() { + fullyDrawn = false; + } + } + private static final class FakeFlutterPlugin implements FlutterPlugin, ActivityAware, From 2ee3a625f967e4dec54cf6a1570d0fd326e129d4 Mon Sep 17 00:00:00 2001 From: Emmanuel Garcia Date: Mon, 13 Sep 2021 14:24:11 -0700 Subject: [PATCH 2/2] Comments --- .../android/io/flutter/embedding/android/FlutterActivity.java | 4 ++-- .../io/flutter/embedding/android/FlutterActivityTest.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java b/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java index e4cc03465b12f..1202ddd4c45ca 100644 --- a/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java +++ b/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java @@ -1094,9 +1094,9 @@ public void onFlutterTextureViewCreated(@NonNull FlutterTextureView flutterTextu public void onFlutterUiDisplayed() { // Notifies Android that we're fully drawn so that performance metrics can be collected by // Flutter performance tests. A few considerations: - // * rFD was supported in KitKat (API 19), but has a bug around requiring + // * reportFullyDrawn was supported in KitKat (API 19), but has a bug around requiring // permissions in some Android versions. - // * rFD behavior isn't tested on pre-Q versions. + // * reportFullyDrawn behavior isn't tested on pre-Q versions. // See https://github.com/flutter/flutter/issues/46172, and // https://github.com/flutter/flutter/issues/88767. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java index 4fc2f827b6eec..8343a9122e186 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java @@ -21,6 +21,7 @@ import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; +import android.os.Build; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable;