Revert "Selectively sinkhole in non filtering mode"

This reverts commit 57d40a479f.
This commit is contained in:
M66B 2021-02-21 15:21:25 +01:00
parent 98129bdecb
commit dd7b99807d
2 changed files with 13 additions and 48 deletions

View File

@ -43,7 +43,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
public class Rule {
private static final String TAG = "NetGuard.Rule";
@ -446,21 +445,6 @@ public class Rule {
updateChanged(default_wifi, default_other, default_roaming);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Rule) {
Rule other = (Rule) obj;
return (this.uid == other.uid &&
Objects.equals(this.packageName, other.packageName));
} else
return false;
}
@Override
public int hashCode() {
return (this.packageName == null ? this.uid : this.packageName.hashCode());
}
@Override
public String toString() {
// This is used in the port forwarding dialog application selector

View File

@ -1409,22 +1409,19 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
// Add list of allowed applications
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (last_connected && !filter) {
for (Rule rule : listRule)
if (!listAllowed.contains(rule))
try {
Log.i(TAG, "Sink=" + rule.packageName);
builder.addAllowedApplication(rule.packageName);
} catch (PackageManager.NameNotFoundException ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
} else if (filter) {
try {
builder.addDisallowedApplication(getPackageName());
} catch (PackageManager.NameNotFoundException ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
try {
builder.addDisallowedApplication(getPackageName());
} catch (PackageManager.NameNotFoundException ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
if (last_connected && !filter)
for (Rule rule : listAllowed)
try {
builder.addDisallowedApplication(rule.packageName);
} catch (PackageManager.NameNotFoundException ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
else if (filter)
for (Rule rule : listRule)
if (!rule.apply || (!system && rule.system))
try {
@ -1433,7 +1430,6 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
} catch (PackageManager.NameNotFoundException ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
}
}
// Build configure intent
@ -3073,7 +3069,6 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
private List<String> listAddress = new ArrayList<>();
private List<String> listRoute = new ArrayList<>();
private List<InetAddress> listDns = new ArrayList<>();
private List<String> listAllowed = new ArrayList<>();
private List<String> listDisallowed = new ArrayList<>();
private Builder() {
@ -3117,13 +3112,6 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
return this;
}
@Override
public Builder addAllowedApplication(String packageName) throws PackageManager.NameNotFoundException {
listAllowed.add(packageName);
super.addAllowedApplication(packageName);
return this;
}
@Override
public Builder addDisallowedApplication(String packageName) throws PackageManager.NameNotFoundException {
listDisallowed.add(packageName);
@ -3154,9 +3142,6 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
if (this.listDns.size() != other.listDns.size())
return false;
if (this.listAllowed.size() != other.listAllowed.size())
return false;
if (this.listDisallowed.size() != other.listDisallowed.size())
return false;
@ -3172,10 +3157,6 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
if (!other.listDns.contains(dns))
return false;
for (String pkg : this.listAllowed)
if (!other.listAllowed.contains(pkg))
return false;
for (String pkg : this.listDisallowed)
if (!other.listDisallowed.contains(pkg))
return false;