Repository: flutter/flutter
File: engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java (Java)

Code before:
 *
 * <p>{@code FlutterRenderer} manages textures for rendering, and forwards some Java calls to native
 * Flutter code via JNI. The corresponding {@link RenderSurface} provides the Android {@link
 * Surface} that this renderer paints.
 *
 * <p>{@link io.flutter.embedding.android.FlutterSurfaceView} and {@link
 * io.flutter.embedding.android.FlutterTextureView} are implementations of {@link RenderSurface}.
 */
public class FlutterRenderer implements TextureRegistry {
  /**
   * Whether to always use GL textures for {@link FlutterRenderer#createSurfaceProducer()}.
   *
   * <p>This is a debug-only API intended for local development. For example, when using a newer
   * Android device (that normally would use {@link ImageReaderSurfaceProducer}, but wanting to test
   * the OpenGLES/{@link SurfaceTextureSurfaceProducer} code branch. This flag has undefined
   * behavior if set to true while running in a Vulkan (Impeller) context.
   */
  @VisibleForTesting public static boolean debugForceSurfaceProducerGlTextures = false;

  /**
   * Returns true if this device has a known {@link android.hardware.HardwareBuffer} defect.
   *
   * <p>Huawei devices on API 29 or below have {@link android.media.ImageReader} issues that cause
   * video playback failures due to defective HardwareBuffer implementations.
   *
   * @see <a href="https://github.com/flutter/flutter/issues/166481">#166481</a>
   */
  private static boolean hasAndroidHardwareBufferDefect() {
    return Build.VERSION.SDK_INT <= API_LEVELS.API_29
        && "HUAWEI".equalsIgnoreCase(Build.MANUFACTURER);
  }

  /** Whether to disable clearing of the Surface used to render platform views. */
  @VisibleForTesting public static boolean debugDisableSurfaceClear = false;

  private static final String TAG = "FlutterRenderer";

  @NonNull private final FlutterJNI flutterJNI;
  @NonNull private final AtomicLong nextTextureId = new AtomicLong(0L);
  @Nullable private Surface surface;
  private boolean isDisplayingFlutterUi = false;
  private final Handler handler = new Handler();

  @NonNull
  private final Set<WeakReference<TextureRegistry.OnTrimMemoryListener>> onTrimMemoryListeners =
      new HashSet<>();

  @NonNull private final List<ImageReaderSurfaceProducer> imageReaderProducers = new ArrayList<>();

  @NonNull
  private final FlutterUiDisplayListener flutterUiDisplayListener =

Review comment (suggestion):
```suggestion
   * @see <a href="https://github.com/flutter/flutter/issues/166481">#166481</a>
   * See <a href="https://github.com/flutter/flutter/issues/156459">#156459</a>
   * See <a href="https://github.com/flutter/flutter/issues/154068">#154068</a>
   * See <a href="https://github.com/flutter/engine/pull/54879">engine pr #54879</a>
```

Code after:
 *
 * <p>{@code FlutterRenderer} manages textures for rendering, and forwards some Java calls to native
 * Flutter code via JNI. The corresponding {@link RenderSurface} provides the Android {@link
 * Surface} that this renderer paints.
 *
 * <p>{@link io.flutter.embedding.android.FlutterSurfaceView} and {@link
 * io.flutter.embedding.android.FlutterTextureView} are implementations of {@link RenderSurface}.
 */
public class FlutterRenderer implements TextureRegistry {
  /**
   * Whether to always use GL textures for {@link FlutterRenderer#createSurfaceProducer()}.
   *
   * <p>This is a debug-only API intended for local development. For example, when using a newer
   * Android device (that normally would use {@link ImageReaderSurfaceProducer}, but wanting to test
   * the OpenGLES/{@link SurfaceTextureSurfaceProducer} code branch. This flag has undefined
   * behavior if set to true while running in a Vulkan (Impeller) context.
   */
  @VisibleForTesting public static boolean debugForceSurfaceProducerGlTextures = false;

  /**
   * Returns true if this device has a known {@link android.hardware.HardwareBuffer} defect.
   *
   * <p>Huawei devices on API 29 or below have {@link android.media.ImageReader} issues that cause
   * video playback failures due to defective HardwareBuffer implementations.
   *
   * @see <a href="https://github.com/flutter/flutter/issues/166481">#166481</a> See <a
   *     href="https://github.com/flutter/flutter/issues/156459">#156459</a> See <a
   *     href="https://github.com/flutter/flutter/issues/154068">#154068</a> See <a
   *     href="https://github.com/flutter/engine/pull/54879">engine pr #54879</a>
   */
  private static boolean hasAndroidHardwareBufferDefect() {
    // To test if some device should be added from this list app developers first should attempt to
    // play a video and see a failure in the logs.
    /// ```E/ACodec: Failed to allocate buffers after transitioning to IDLE state (error 0xfffffc0e)
    /// W/ACodec: [OMX.hisi.video.decoder.avc] setting nBufferCountActual to 12 failed: -1010
    // E/MediaCodecVideoRenderer: Video codec error```
    /// Then try setting `FlutterRenderer.debugForceSurfaceProducerGlTextures = true` in an example
    // app.
    /// If the video plays then that is a strong signal that this method should be updated to
    // include the tested device.
    return Build.VERSION.SDK_INT <= API_LEVELS.API_29
        && "HUAWEI".equalsIgnoreCase(Build.MANUFACTURER);
  }

  /** Whether to disable clearing of the Surface used to render platform views. */
  @VisibleForTesting public static boolean debugDisableSurfaceClear = false;

  private static final String TAG = "FlutterRenderer";

  @NonNull private final FlutterJNI flutterJNI;
  @NonNull private final AtomicLong nextTextureId = new AtomicLong(0L);