From a04025b8d057e31f8e8b9634461fd7a6e7f2ef0f Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 1 May 2022 13:46:06 +0200 Subject: [PATCH] Fixed temp memory leak --- .../java/eu/faircode/email/ActivityMain.java | 8 ++-- .../email/FragmentOptionsPrivacy.java | 47 ++++++++++--------- .../main/java/eu/faircode/email/Helper.java | 15 ++++-- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityMain.java b/app/src/main/java/eu/faircode/email/ActivityMain.java index caf84742c9..393cc3b275 100644 --- a/app/src/main/java/eu/faircode/email/ActivityMain.java +++ b/app/src/main/java/eu/faircode/email/ActivityMain.java @@ -246,9 +246,9 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack if (Helper.shouldAuthenticate(this, false)) Helper.authenticate(ActivityMain.this, ActivityMain.this, null, - new Runnable() { + new RunnableEx("auth:succeeded") { @Override - public void run() { + public void delegate() { Intent intent = getIntent(); Bundle args = new Bundle(); if (intent.hasExtra("intent")) @@ -256,9 +256,9 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack boot.execute(ActivityMain.this, args, "main:accounts"); } }, - new Runnable() { + new RunnableEx("auth:cancelled") { @Override - public void run() { + public void delegate() { try { finish(); } catch (Throwable ex) { diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java b/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java index 7be23a96e7..774454cbf2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsPrivacy.java @@ -259,29 +259,30 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer public void onClick(View v) { final boolean biometrics = prefs.getBoolean("biometrics", false); - Helper.authenticate(getActivity(), getViewLifecycleOwner(), biometrics, new Runnable() { - @Override - public void run() { - try { - boolean pro = ActivityBilling.isPro(getContext()); - if (pro) { - SharedPreferences.Editor editor = prefs.edit(); - if (!biometrics) - editor.remove("pin"); - editor.putBoolean("biometrics", !biometrics); - editor.apply(); - } else - startActivity(new Intent(getContext(), ActivityBilling.class)); - } catch (Throwable ex) { - Log.w(ex); - } - } - }, new Runnable() { - @Override - public void run() { - // Do nothing - } - }); + Helper.authenticate(getActivity(), getViewLifecycleOwner(), biometrics, + new RunnableEx("auth:setup") { + @Override + public void delegate() { + try { + boolean pro = ActivityBilling.isPro(getContext()); + if (pro) { + SharedPreferences.Editor editor = prefs.edit(); + if (!biometrics) + editor.remove("pin"); + editor.putBoolean("biometrics", !biometrics); + editor.apply(); + } else + startActivity(new Intent(getContext(), ActivityBilling.class)); + } catch (Throwable ex) { + Log.w(ex); + } + } + }, new RunnableEx("auth:nothing") { + @Override + public void delegate() { + // Do nothing + } + }); } }); diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index ea7a68c1a0..b94c9a72a1 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -2293,9 +2293,9 @@ public class Helper { } if (!isCancelled(errorCode)) - ApplicationEx.getMainHandler().post(new Runnable() { + ApplicationEx.getMainHandler().post(new RunnableEx("auth:error") { @Override - public void run() { + public void delegate() { ToastEx.makeText(activity, "Error " + errorCode + ": " + errString, Toast.LENGTH_LONG).show(); @@ -2335,9 +2335,9 @@ public class Helper { prompt.authenticate(info.build()); - final Runnable cancelPrompt = new Runnable() { + final Runnable cancelPrompt = new RunnableEx("auth:cancelprompt") { @Override - public void run() { + public void delegate() { try { prompt.cancelAuthentication(); } catch (Throwable ex) { @@ -2352,7 +2352,12 @@ public class Helper { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void onDestroy() { Log.i("Authenticate destroyed"); - ApplicationEx.getMainHandler().post(cancelPrompt); + ApplicationEx.getMainHandler().removeCallbacks(cancelPrompt); + try { + prompt.cancelAuthentication(); + } catch (Throwable ex) { + Log.e(ex); + } owner.getLifecycle().removeObserver(this); } });