From bd6e2548fc5c2280287cf9d9ecd46561cfc45081 Mon Sep 17 00:00:00 2001 From: Eugene Makar Date: Fri, 27 May 2022 09:29:50 +0300 Subject: [PATCH] fix leaking MethodChannel through anonymous class --- .../ServiceWorkerManager.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ServiceWorkerManager.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ServiceWorkerManager.java index ac2a654f..b9ff2958 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ServiceWorkerManager.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ServiceWorkerManager.java @@ -168,13 +168,7 @@ public class ServiceWorkerManager implements MethodChannel.MethodCallHandler { } private ServiceWorkerClientCompat dummyServiceWorkerClientCompat() { - return new ServiceWorkerClientCompat() { - @Nullable - @Override - public WebResourceResponse shouldInterceptRequest(@NonNull WebResourceRequest request) { - return null; - } - }; + return DummyServiceWorkerClientCompat.INSTANCE; } public void dispose() { @@ -185,4 +179,14 @@ public class ServiceWorkerManager implements MethodChannel.MethodCallHandler { } plugin = null; } + + private static final class DummyServiceWorkerClientCompat extends ServiceWorkerClientCompat { + static final ServiceWorkerClientCompat INSTANCE = new DummyServiceWorkerClientCompat(); + + @Nullable + @Override + public WebResourceResponse shouldInterceptRequest(@NonNull WebResourceRequest request) { + return null; + } + } }