From b3cc164eef03b07365f7c3c447a71d1443df101d Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 7 Jul 2024 16:59:23 +0200 Subject: [PATCH] Fixed runnable memory leaks --- .../faircode/email/FixedConstraintLayout.java | 45 ------------ .../email/FixedCoordinatorLayout.java | 45 ------------ .../eu/faircode/email/FixedFrameLayout.java | 45 ------------ .../eu/faircode/email/FixedLinearLayout.java | 46 ------------- .../eu/faircode/email/FixedRecyclerView.java | 69 ------------------- .../faircode/email/FixedRelativeLayout.java | 47 ------------- .../eu/faircode/email/FixedScrollView.java | 47 ------------- 7 files changed, 344 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FixedConstraintLayout.java b/app/src/main/java/eu/faircode/email/FixedConstraintLayout.java index 2eb0faee27..d8e36d932c 100644 --- a/app/src/main/java/eu/faircode/email/FixedConstraintLayout.java +++ b/app/src/main/java/eu/faircode/email/FixedConstraintLayout.java @@ -27,9 +27,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; -import java.util.Map; -import java.util.WeakHashMap; - public class FixedConstraintLayout extends ConstraintLayout { public FixedConstraintLayout(@NonNull Context context) { super(context); @@ -122,46 +119,4 @@ public class FixedConstraintLayout extends ConstraintLayout { return false; } } - - private Map mapRunnable = null; - - @NonNull - private Map getMapRunnable() { - if (mapRunnable == null) - mapRunnable = new WeakHashMap<>(); - return mapRunnable; - } - - @Override - public boolean post(Runnable action) { - Runnable wrapped = new RunnableEx("post") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - return super.post(wrapped); - } - - @Override - public boolean postDelayed(Runnable action, long delayMillis) { - Runnable wrapped = new RunnableEx("postDelayed") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - return super.postDelayed(wrapped, delayMillis); - } - - @Override - public boolean removeCallbacks(Runnable action) { - Runnable wrapped = getMapRunnable().get(action); - if (wrapped == null) - return super.removeCallbacks(action); - else - return super.removeCallbacks(wrapped); - } } diff --git a/app/src/main/java/eu/faircode/email/FixedCoordinatorLayout.java b/app/src/main/java/eu/faircode/email/FixedCoordinatorLayout.java index f03249c462..c43b40ad38 100644 --- a/app/src/main/java/eu/faircode/email/FixedCoordinatorLayout.java +++ b/app/src/main/java/eu/faircode/email/FixedCoordinatorLayout.java @@ -27,9 +27,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import java.util.Map; -import java.util.WeakHashMap; - public class FixedCoordinatorLayout extends CoordinatorLayout { public FixedCoordinatorLayout(@NonNull Context context) { super(context); @@ -62,46 +59,4 @@ public class FixedCoordinatorLayout extends CoordinatorLayout { return false; } } - - private Map mapRunnable = null; - - @NonNull - private Map getMapRunnable() { - if (mapRunnable == null) - mapRunnable = new WeakHashMap<>(); - return mapRunnable; - } - - @Override - public boolean post(Runnable action) { - Runnable wrapped = new RunnableEx("post") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - return super.post(wrapped); - } - - @Override - public boolean postDelayed(Runnable action, long delayMillis) { - Runnable wrapped = new RunnableEx("postDelayed") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - return super.postDelayed(wrapped, delayMillis); - } - - @Override - public boolean removeCallbacks(Runnable action) { - Runnable wrapped = getMapRunnable().get(action); - if (wrapped == null) - return super.removeCallbacks(action); - else - return super.removeCallbacks(wrapped); - } } diff --git a/app/src/main/java/eu/faircode/email/FixedFrameLayout.java b/app/src/main/java/eu/faircode/email/FixedFrameLayout.java index 8204b9e1d9..83dcda3910 100644 --- a/app/src/main/java/eu/faircode/email/FixedFrameLayout.java +++ b/app/src/main/java/eu/faircode/email/FixedFrameLayout.java @@ -27,9 +27,6 @@ import android.widget.FrameLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import java.util.Map; -import java.util.WeakHashMap; - public class FixedFrameLayout extends FrameLayout { public FixedFrameLayout(@NonNull Context context) { super(context); @@ -75,46 +72,4 @@ public class FixedFrameLayout extends FrameLayout { return false; } } - - private Map mapRunnable = null; - - @NonNull - private Map getMapRunnable() { - if (mapRunnable == null) - mapRunnable = new WeakHashMap<>(); - return mapRunnable; - } - - @Override - public boolean post(Runnable action) { - Runnable wrapped = new RunnableEx("post") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - return super.post(wrapped); - } - - @Override - public boolean postDelayed(Runnable action, long delayMillis) { - Runnable wrapped = new RunnableEx("postDelayed") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - return super.postDelayed(wrapped, delayMillis); - } - - @Override - public boolean removeCallbacks(Runnable action) { - Runnable wrapped = getMapRunnable().get(action); - if (wrapped == null) - return super.removeCallbacks(action); - else - return super.removeCallbacks(wrapped); - } } diff --git a/app/src/main/java/eu/faircode/email/FixedLinearLayout.java b/app/src/main/java/eu/faircode/email/FixedLinearLayout.java index ce55dc1181..7f3405e3bf 100644 --- a/app/src/main/java/eu/faircode/email/FixedLinearLayout.java +++ b/app/src/main/java/eu/faircode/email/FixedLinearLayout.java @@ -24,12 +24,8 @@ import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.LinearLayout; -import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import java.util.Map; -import java.util.WeakHashMap; - public class FixedLinearLayout extends LinearLayout { public FixedLinearLayout(Context context) { super(context); @@ -56,46 +52,4 @@ public class FixedLinearLayout extends LinearLayout { return false; } } - - private Map mapRunnable = null; - - @NonNull - private Map getMapRunnable() { - if (mapRunnable == null) - mapRunnable = new WeakHashMap<>(); - return mapRunnable; - } - - @Override - public boolean post(Runnable action) { - Runnable wrapped = new RunnableEx("post") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - return super.post(wrapped); - } - - @Override - public boolean postDelayed(Runnable action, long delayMillis) { - Runnable wrapped = new RunnableEx("postDelayed") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - return super.postDelayed(wrapped, delayMillis); - } - - @Override - public boolean removeCallbacks(Runnable action) { - Runnable wrapped = getMapRunnable().get(action); - if (wrapped == null) - return super.removeCallbacks(action); - else - return super.removeCallbacks(wrapped); - } } diff --git a/app/src/main/java/eu/faircode/email/FixedRecyclerView.java b/app/src/main/java/eu/faircode/email/FixedRecyclerView.java index b1f403b5b3..080bad8a33 100644 --- a/app/src/main/java/eu/faircode/email/FixedRecyclerView.java +++ b/app/src/main/java/eu/faircode/email/FixedRecyclerView.java @@ -32,9 +32,6 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.FastScrollerEx; import androidx.recyclerview.widget.RecyclerView; -import java.util.Map; -import java.util.WeakHashMap; - public class FixedRecyclerView extends RecyclerView { public FixedRecyclerView(@NonNull Context context) { super(context); @@ -210,70 +207,4 @@ public class FixedRecyclerView extends RecyclerView { */ } } - - private Map mapRunnable = null; - - @NonNull - private Map getMapRunnable() { - if (mapRunnable == null) - mapRunnable = new WeakHashMap<>(); - return mapRunnable; - } - - @Override - public boolean post(Runnable action) { - Runnable wrapped = new RunnableEx("post") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - return super.post(wrapped); - } - - @Override - public boolean postDelayed(Runnable action, long delayMillis) { - Runnable wrapped = new RunnableEx("postDelayed") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - return super.postDelayed(wrapped, delayMillis); - } - - @Override - public void postOnAnimation(Runnable action) { - Runnable wrapped = new RunnableEx("postOnAnimation") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - super.postOnAnimation(wrapped); - } - - @Override - public void postOnAnimationDelayed(Runnable action, long delayMillis) { - Runnable wrapped = new RunnableEx("postOnAnimationDelayed") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - super.postOnAnimationDelayed(wrapped, delayMillis); - } - - @Override - public boolean removeCallbacks(Runnable action) { - Runnable wrapped = getMapRunnable().get(action); - if (wrapped == null) - return super.removeCallbacks(action); - else - return super.removeCallbacks(wrapped); - } } diff --git a/app/src/main/java/eu/faircode/email/FixedRelativeLayout.java b/app/src/main/java/eu/faircode/email/FixedRelativeLayout.java index d6a94cd90d..0ca756054b 100644 --- a/app/src/main/java/eu/faircode/email/FixedRelativeLayout.java +++ b/app/src/main/java/eu/faircode/email/FixedRelativeLayout.java @@ -24,11 +24,6 @@ import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.RelativeLayout; -import androidx.annotation.NonNull; - -import java.util.Map; -import java.util.WeakHashMap; - public class FixedRelativeLayout extends RelativeLayout { public FixedRelativeLayout(Context context) { super(context); @@ -55,46 +50,4 @@ public class FixedRelativeLayout extends RelativeLayout { return false; } } - - private Map mapRunnable = null; - - @NonNull - private Map getMapRunnable() { - if (mapRunnable == null) - mapRunnable = new WeakHashMap<>(); - return mapRunnable; - } - - @Override - public boolean post(Runnable action) { - Runnable wrapped = new RunnableEx("post") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - return super.post(wrapped); - } - - @Override - public boolean postDelayed(Runnable action, long delayMillis) { - Runnable wrapped = new RunnableEx("postDelayed") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - return super.postDelayed(wrapped, delayMillis); - } - - @Override - public boolean removeCallbacks(Runnable action) { - Runnable wrapped = getMapRunnable().get(action); - if (wrapped == null) - return super.removeCallbacks(action); - else - return super.removeCallbacks(wrapped); - } } diff --git a/app/src/main/java/eu/faircode/email/FixedScrollView.java b/app/src/main/java/eu/faircode/email/FixedScrollView.java index cae89125ea..90401f569e 100644 --- a/app/src/main/java/eu/faircode/email/FixedScrollView.java +++ b/app/src/main/java/eu/faircode/email/FixedScrollView.java @@ -5,11 +5,6 @@ import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.ScrollView; -import androidx.annotation.NonNull; - -import java.util.Map; -import java.util.WeakHashMap; - /* This file is part of FairEmail. @@ -134,46 +129,4 @@ public class FixedScrollView extends ScrollView { return false; } } - - private Map mapRunnable = null; - - @NonNull - private Map getMapRunnable() { - if (mapRunnable == null) - mapRunnable = new WeakHashMap<>(); - return mapRunnable; - } - - @Override - public boolean post(Runnable action) { - Runnable wrapped = new RunnableEx("post") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - return super.post(wrapped); - } - - @Override - public boolean postDelayed(Runnable action, long delayMillis) { - Runnable wrapped = new RunnableEx("postDelayed") { - @Override - protected void delegate() { - action.run(); - } - }; - getMapRunnable().put(action, wrapped); - return super.postDelayed(wrapped, delayMillis); - } - - @Override - public boolean removeCallbacks(Runnable action) { - Runnable wrapped = getMapRunnable().get(action); - if (wrapped == null) - return super.removeCallbacks(action); - else - return super.removeCallbacks(wrapped); - } }