diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java b/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java index c57d90f0162c1..d55b0a6b7ce7f 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformViewWrapper.java @@ -9,10 +9,10 @@ import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; -import android.graphics.BlendMode; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; +import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.SurfaceTexture; import android.os.Build; @@ -169,11 +169,7 @@ public void setTexture(@Nullable SurfaceTexture newTx) { // to the user until the platform view draws its first frame. final Canvas canvas = surface.lockHardwareCanvas(); try { - if (Build.VERSION.SDK_INT >= 29) { - canvas.drawColor(Color.TRANSPARENT, BlendMode.CLEAR); - } else { - canvas.drawColor(Color.TRANSPARENT); - } + canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); onFrameProduced(); } finally { surface.unlockCanvasAndPost(canvas); @@ -305,11 +301,7 @@ public void draw(Canvas canvas) { try { // Clear the current pixels in the canvas. // This helps when a WebView renders an HTML document with transparent background. - if (Build.VERSION.SDK_INT >= 29) { - surfaceCanvas.drawColor(Color.TRANSPARENT, BlendMode.CLEAR); - } else { - surfaceCanvas.drawColor(Color.TRANSPARENT); - } + surfaceCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); super.draw(surfaceCanvas); onFrameProduced(); } finally { diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewWrapperTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewWrapperTest.java index 2893df22834f5..630504f9aaeef 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewWrapperTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewWrapperTest.java @@ -7,9 +7,9 @@ import android.annotation.TargetApi; import android.content.Context; -import android.graphics.BlendMode; import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.PorterDuff; import android.graphics.SurfaceTexture; import android.view.Surface; import android.view.View; @@ -65,7 +65,7 @@ protected Surface createSurface(@NonNull SurfaceTexture tx) { // Verify. verify(surface, times(1)).lockHardwareCanvas(); verify(surface, times(1)).unlockCanvasAndPost(canvas); - verify(canvas, times(1)).drawColor(Color.TRANSPARENT, BlendMode.CLEAR); + verify(canvas, times(1)).drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); verifyNoMoreInteractions(surface); verifyNoMoreInteractions(canvas); } @@ -112,7 +112,7 @@ public void draw(Canvas canvas) { wrapper.draw(new Canvas()); // Verify. - verify(canvas, times(1)).drawColor(Color.TRANSPARENT, BlendMode.CLEAR); + verify(canvas, times(1)).drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); verify(surface, times(1)).isValid(); verify(surface, times(1)).lockHardwareCanvas(); verify(surface, times(1)).unlockCanvasAndPost(canvas);