diff --git a/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java b/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java index 21033a84135ef..1202ddd4c45ca 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: + // * reportFullyDrawn was supported in KitKat (API 19), but has a bug around requiring + // permissions in some Android 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) { 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..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; @@ -438,6 +439,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 +505,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,