Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cb9dead

Browse files
Disable cleaning up ImageReaders in memory pressure callback (#51391)
We originally added this cleanup code to work around a Samsung-specific Android 14 bug where after resuming an application any ImageReaders are busted. According to the Android team what Samsung is doing is a violation of the "spec". The fix ended up breaking VirtualDisplay platform views after a suspend/resume because the surface we pass to the VirtualDisplay is no longer valid after the resume and we have no way of fixing that. This PR removes the Samsung-specific hacky fix, restoring the behaviour of VirtualDisplay backed platform views. We have an internal bug with Samsung to address the root cause.
1 parent d29383c commit cb9dead

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@ final class ImageReaderSurfaceProducer
414414
// Flip when debugging to see verbose logs.
415415
private static final boolean VERBOSE_LOGS = false;
416416

417+
// If we cleanup the ImageReaders on memory pressure it breaks VirtualDisplay
418+
// backed platform views. Disable for now as this is only necessary to work
419+
// around a Samsung-specific Android 14 bug.
420+
private static final boolean CLEANUP_ON_MEMORY_PRESSURE = false;
421+
417422
private final long id;
418423

419424
private boolean released;
@@ -649,6 +654,9 @@ PerImage dequeueImage() {
649654

650655
@Override
651656
public void onTrimMemory(int level) {
657+
if (!CLEANUP_ON_MEMORY_PRESSURE) {
658+
return;
659+
}
652660
cleanup();
653661
createNewReader = true;
654662
}

shell/platform/android/test/io/flutter/embedding/engine/renderer/FlutterRendererTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,11 +648,12 @@ public void ImageReaderSurfaceProducerTrimMemoryCallback() {
648648
assertEquals(1, texture.numImages());
649649

650650
// Invoke the onTrimMemory callback.
651+
// This should do nothing.
651652
texture.onTrimMemory(0);
652653
shadowOf(Looper.getMainLooper()).idle();
653654

654-
assertEquals(0, texture.numImageReaders());
655-
assertEquals(0, texture.numImages());
655+
assertEquals(1, texture.numImageReaders());
656+
assertEquals(1, texture.numImages());
656657
}
657658

658659
// A 0x0 ImageReader is a runtime error.

0 commit comments

Comments
 (0)