0
0
mirror of https://github.com/TrianguloY/UrlChecker.git synced 2024-09-19 20:02:16 +02:00

Fix rejected detection

- Check referrer to detect rejected apps
- Ignore if not a view action (like share)
- Allow to disable

Fixes #305
This commit is contained in:
TrianguloY 2024-03-09 13:04:17 +01:00
parent b756ddf556
commit 8b8ad9d804
5 changed files with 34 additions and 6 deletions

View File

@ -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));
}

View File

@ -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) {

View File

@ -92,4 +92,11 @@
android:layout_marginTop="@dimen/smallPadding"
android:text="@string/mOpen_noReferrer" />
<Switch
android:id="@+id/rejected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/smallPadding"
android:text="@string/mOpen_rejected" />
</LinearLayout>

View File

@ -143,6 +143,7 @@ Hay algunos enlaces cuyo único propósito es redirigirte a otro enlace. Si el e
<string name="mOpen_closeShare">Cierra la ventana después de compartir</string>
<string name="mOpen_perDomain">Ordenar diferentes dominios de forma independiente</string>
<string name="mOpen_noReferrer">Ocultar la aplicación de origen (referrer)</string>
<string name="mOpen_rejected">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.</string>
<string name="mOpen_with">Abrir con %s</string>
<string name="mOpen_open">Abrir</string>
<string name="mOpen_share">Compartir</string>

View File

@ -190,6 +190,7 @@ Note: if you edit the patterns, new built-in patterns from app updates will not
<string name="mOpen_closeCopy">Close dialog after copying</string>
<string name="mOpen_perDomain">Sort different domains independently</string>
<string name="mOpen_noReferrer">Hide the source app (referrer)</string>
<string name="mOpen_rejected">Hide app if rejected url (an app that immediately requested to open the same url it was opened with). Don\'t affect sharing</string>
<string name="mOpen_mergeCopy">Merge Copy and Share buttons (long press to copy)</string>
<string name="mOpen_with">Open with %s</string>
<string name="mOpen_open">Open</string>