From 3577ed2643583f3da5b242c2c37fe7c3c50b67f7 Mon Sep 17 00:00:00 2001 From: Makoto Kato Date: Wed, 31 Aug 2022 14:31:14 +0000 Subject: [PATCH] Bug 1786449 - Revert overscroll support part of bug 1724480. r=geckoview-reviewers,calu To support overscroll drawing on old Andorid (9 or early), we use the reflection to access `Paint` object. But this is removed by bug 1724480. So I would like to revert overscroll part for Android 9 or early. I tested on old Galaxy S7 (Android 9). Differential Revision: https://phabricator.services.mozilla.com/D155716 --- .../geckoview/OverscrollEdgeEffect.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/OverscrollEdgeEffect.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/OverscrollEdgeEffect.java index f6e941ee97ac..1b48a5930cc0 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/OverscrollEdgeEffect.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/OverscrollEdgeEffect.java @@ -8,6 +8,9 @@ package org.mozilla.geckoview; import android.content.Context; import android.graphics.BlendMode; import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.os.Build; import android.widget.EdgeEffect; @@ -43,6 +46,25 @@ public final class OverscrollEdgeEffect { private void setBlendMode(final EdgeEffect edgeEffect) { if (Build.VERSION.SDK_INT < 29) { // setBlendMode is only supported on SDK_INT >= 29 and above. + + if (sPaintField == null) { + try { + sPaintField = EdgeEffect.class.getDeclaredField("mPaint"); + sPaintField.setAccessible(true); + } catch (final NoSuchFieldException e) { + // Cannot get the field, nothing we can do here + return; + } + } + + try { + final Paint paint = (Paint) sPaintField.get(edgeEffect); + final PorterDuffXfermode mode = new PorterDuffXfermode(PorterDuff.Mode.SRC); + paint.setXfermode(mode); + } catch (final IllegalAccessException ex) { + // Nothing we can do + } + return; }