From 8b8ad9d804c2344af56b6e9c7fbf2b9793c290d1 Mon Sep 17 00:00:00 2001 From: TrianguloY Date: Sat, 9 Mar 2024 13:04:17 +0100 Subject: [PATCH] Fix rejected detection - Check referrer to detect rejected apps - Ignore if not a view action (like share) - Allow to disable Fixes #305 --- .../urlchecker/modules/list/OpenModule.java | 13 +++++++++++-- .../utilities/wrappers/RejectionDetector.java | 18 ++++++++++++++---- app/src/main/res/layout/config_open.xml | 7 +++++++ app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/trianguloy/urlchecker/modules/list/OpenModule.java b/app/src/main/java/com/trianguloy/urlchecker/modules/list/OpenModule.java index 636cf97..1fe422d 100644 --- a/app/src/main/java/com/trianguloy/urlchecker/modules/list/OpenModule.java +++ b/app/src/main/java/com/trianguloy/urlchecker/modules/list/OpenModule.java @@ -49,6 +49,10 @@ public class OpenModule extends AModuleData { return new GenericPref.Bool("open_noReferrer", false, cntx); } + public static GenericPref.Bool REJECTED_PREF(Context cntx) { + return new GenericPref.Bool("open_rejected", true, cntx); + } + public static GenericPref.Bool MERGECOPY_PREF(Context cntx) { return new GenericPref.Bool("open_mergeCopy", false, cntx); } @@ -80,6 +84,7 @@ class OpenDialog extends AModuleDialog { private final GenericPref.Bool closeSharePref; private final GenericPref.Bool closeCopyPref; private final GenericPref.Bool noReferrerPref; + private final GenericPref.Bool rejectedPref; private final GenericPref.Bool mergeCopyPref; private final LastOpened lastOpened; @@ -104,6 +109,7 @@ class OpenDialog extends AModuleDialog { closeSharePref = OpenModule.CLOSESHARE_PREF(dialog); closeCopyPref = OpenModule.CLOSECOPY_PREF(dialog); noReferrerPref = OpenModule.NOREFERRER_PREF(dialog); + rejectedPref = OpenModule.REJECTED_PREF(dialog); mergeCopyPref = OpenModule.MERGECOPY_PREF(dialog); } @@ -176,9 +182,11 @@ class OpenDialog extends AModuleDialog { packages.remove(AndroidUtils.getReferrer(getActivity())); } - // remove rejected + // remove rejected if desired (and is not a non-view action, like share) // note: this will be called each time, so a rejected package will not be rejected again if the user changes the url and goes back. This is expected - packages.remove(rejectionDetector.getPrevious(url)); + if (rejectedPref.get() && Intent.ACTION_VIEW.equals(getActivity().getIntent().getAction())) { + packages.remove(rejectionDetector.getPrevious(url)); + } // check no apps if (packages.isEmpty()) { @@ -316,6 +324,7 @@ class OpenConfig extends AModuleConfig { OpenModule.CLOSESHARE_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.closeshare_pref)); OpenModule.CLOSECOPY_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.closecopy_pref)); OpenModule.NOREFERRER_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.noReferrer)); + OpenModule.REJECTED_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.rejected)); LastOpened.PERDOMAIN_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.perDomain)); OpenModule.MERGECOPY_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.mergeCopy_pref)); } diff --git a/app/src/main/java/com/trianguloy/urlchecker/utilities/wrappers/RejectionDetector.java b/app/src/main/java/com/trianguloy/urlchecker/utilities/wrappers/RejectionDetector.java index affc9dc..e4daeb2 100644 --- a/app/src/main/java/com/trianguloy/urlchecker/utilities/wrappers/RejectionDetector.java +++ b/app/src/main/java/com/trianguloy/urlchecker/utilities/wrappers/RejectionDetector.java @@ -1,8 +1,9 @@ package com.trianguloy.urlchecker.utilities.wrappers; -import android.content.Context; +import android.app.Activity; import com.trianguloy.urlchecker.utilities.generics.GenericPref; +import com.trianguloy.urlchecker.utilities.methods.AndroidUtils; import java.util.Collections; import java.util.List; @@ -16,9 +17,11 @@ public class RejectionDetector { private static final int TIMEFRAME = 5000; private final GenericPref.LstStr rejectLast; // [openedTimeMillis, package, url] + private final Activity cntx; - public RejectionDetector(Context cntx) { + public RejectionDetector(Activity cntx) { rejectLast = new GenericPref.LstStr("reject_last", "\n", 3, Collections.emptyList(), cntx); + this.cntx = cntx; } /** @@ -29,16 +32,23 @@ public class RejectionDetector { } /** - * returns the last package that opened the url if it happened in a short amount of time, null otherwise + * returns the last package that opened the url if + * - it happened in a short amount of time + * - (and) the url is the same + * - (and) the referrer app is the same + * null otherwise */ public String getPrevious(String url) { + try { var data = rejectLast.get(); - // return the saved package if the time is less than the timeframe and the url is the same return !data.isEmpty() + // checks && System.currentTimeMillis() - Long.parseLong(data.get(0)) < TIMEFRAME && Objects.equals(data.get(2), url) + && Objects.equals(AndroidUtils.getReferrer(cntx), data.get(1)) + ? data.get(1) : null; } catch (Exception ignore) { diff --git a/app/src/main/res/layout/config_open.xml b/app/src/main/res/layout/config_open.xml index d4c4323..539cb21 100644 --- a/app/src/main/res/layout/config_open.xml +++ b/app/src/main/res/layout/config_open.xml @@ -92,4 +92,11 @@ android:layout_marginTop="@dimen/smallPadding" android:text="@string/mOpen_noReferrer" /> + + \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index bf759f4..97f776b 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -143,6 +143,7 @@ Hay algunos enlaces cuyo único propósito es redirigirte a otro enlace. Si el e Cierra la ventana después de compartir Ordenar diferentes dominios de forma independiente Ocultar la aplicación de origen (referrer) + Ocultar la aplicación si ha rechazado el enlace (aplicación que pide abrir inmediatamente el mismo enlace que se le pidió abrir). No afecta a compartir. Abrir con %s Abrir Compartir diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f59343d..b706811 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -190,6 +190,7 @@ Note: if you edit the patterns, new built-in patterns from app updates will not Close dialog after copying Sort different domains independently Hide the source app (referrer) + Hide app if rejected url (an app that immediately requested to open the same url it was opened with). Don\'t affect sharing Merge Copy and Share buttons (long press to copy) Open with %s Open