Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider adding that there are vendor-specific bugs.

How confident are we that this API works on all vendors after Q?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only know that a CTS test was added. Vendors should be running these tests, but we don't really know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
reportFullyDrawn();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -438,6 +439,32 @@ public void itWithMetadataWithoutSplashScreenResourceKeyDoesNotProvideSplashScre
assertNull(splashScreen);
}

@Test
public void fullyDrawn() {
Intent intent =
FlutterActivityWithReportFullyDrawn.createDefaultIntent(RuntimeEnvironment.application);
ActivityController<FlutterActivityWithReportFullyDrawn> 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")
Expand Down Expand Up @@ -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,
Expand Down