mirror of https://github.com/M66B/NetGuard.git
Sinkhole not allowed apps in non-filtering mode
This commit is contained in:
parent
439a39004a
commit
f806ea2162
|
@ -1430,19 +1430,31 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
||||||
|
|
||||||
// Add list of allowed applications
|
// Add list of allowed applications
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
try {
|
if (last_connected && !filter) {
|
||||||
builder.addDisallowedApplication(getPackageName());
|
Map<String, Rule> mapDisallowed = new HashMap<>();
|
||||||
} catch (PackageManager.NameNotFoundException ex) {
|
for (Rule rule : listRule)
|
||||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
mapDisallowed.put(rule.packageName, rule);
|
||||||
}
|
|
||||||
if (last_connected && !filter)
|
|
||||||
for (Rule rule : listAllowed)
|
for (Rule rule : listAllowed)
|
||||||
|
mapDisallowed.remove(rule.packageName);
|
||||||
|
for (String packageName : mapDisallowed.keySet())
|
||||||
try {
|
try {
|
||||||
builder.addDisallowedApplication(rule.packageName);
|
builder.addAllowedApplication(packageName);
|
||||||
|
Log.i(TAG, "Sinkhole " + packageName);
|
||||||
} catch (PackageManager.NameNotFoundException ex) {
|
} catch (PackageManager.NameNotFoundException ex) {
|
||||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||||
}
|
}
|
||||||
else if (filter)
|
if (mapDisallowed.size() == 0)
|
||||||
|
try {
|
||||||
|
builder.addAllowedApplication(getPackageName());
|
||||||
|
} 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));
|
||||||
|
}
|
||||||
for (Rule rule : listRule)
|
for (Rule rule : listRule)
|
||||||
if (!rule.apply || (!system && rule.system))
|
if (!rule.apply || (!system && rule.system))
|
||||||
try {
|
try {
|
||||||
|
@ -1451,6 +1463,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
||||||
} catch (PackageManager.NameNotFoundException ex) {
|
} catch (PackageManager.NameNotFoundException ex) {
|
||||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build configure intent
|
// Build configure intent
|
||||||
|
@ -3212,6 +3225,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
||||||
private List<String> listAddress = new ArrayList<>();
|
private List<String> listAddress = new ArrayList<>();
|
||||||
private List<String> listRoute = new ArrayList<>();
|
private List<String> listRoute = new ArrayList<>();
|
||||||
private List<InetAddress> listDns = new ArrayList<>();
|
private List<InetAddress> listDns = new ArrayList<>();
|
||||||
|
private List<String> listAllowed = new ArrayList<>();
|
||||||
private List<String> listDisallowed = new ArrayList<>();
|
private List<String> listDisallowed = new ArrayList<>();
|
||||||
|
|
||||||
private Builder() {
|
private Builder() {
|
||||||
|
@ -3255,6 +3269,12 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VpnService.Builder addAllowedApplication(String packageName) throws PackageManager.NameNotFoundException {
|
||||||
|
listAllowed.add(packageName);
|
||||||
|
return super.addAllowedApplication(packageName);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder addDisallowedApplication(String packageName) throws PackageManager.NameNotFoundException {
|
public Builder addDisallowedApplication(String packageName) throws PackageManager.NameNotFoundException {
|
||||||
listDisallowed.add(packageName);
|
listDisallowed.add(packageName);
|
||||||
|
@ -3285,6 +3305,9 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
||||||
if (this.listDns.size() != other.listDns.size())
|
if (this.listDns.size() != other.listDns.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (this.listAllowed.size() != other.listAllowed.size())
|
||||||
|
return false;
|
||||||
|
|
||||||
if (this.listDisallowed.size() != other.listDisallowed.size())
|
if (this.listDisallowed.size() != other.listDisallowed.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -3300,6 +3323,10 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
|
||||||
if (!other.listDns.contains(dns))
|
if (!other.listDns.contains(dns))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
for (String pkg : this.listAllowed)
|
||||||
|
if (!other.listAllowed.contains(pkg))
|
||||||
|
return false;
|
||||||
|
|
||||||
for (String pkg : this.listDisallowed)
|
for (String pkg : this.listDisallowed)
|
||||||
if (!other.listDisallowed.contains(pkg))
|
if (!other.listDisallowed.contains(pkg))
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue