mirror of
https://github.com/M66B/NetGuard.git
synced 2025-02-25 07:32:46 +00:00
Reload hosts file when needed only
This commit is contained in:
parent
dbe4414501
commit
1c5a7a188e
1 changed files with 40 additions and 30 deletions
|
@ -98,6 +98,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
private Object subscriptionsChangedListener = null;
|
||||
private ParcelFileDescriptor vpn = null;
|
||||
|
||||
private long last_hosts_modified = 0;
|
||||
private Map<String, Boolean> mapHostsBlocked = new HashMap<>();
|
||||
private Map<Integer, Boolean> mapUidAllowed = new HashMap<>();
|
||||
private Map<Integer, Integer> mapUidKnown = new HashMap<>();
|
||||
|
@ -943,11 +944,21 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SinkholeService.this);
|
||||
boolean use_hosts = prefs.getBoolean("filter_allowed", false) && prefs.getBoolean("use_hosts", false);
|
||||
File hosts = new File(getFilesDir(), "hosts.txt");
|
||||
Log.i(TAG, hosts + "=" + use_hosts);
|
||||
if (!use_hosts || !hosts.exists() || !hosts.canRead()) {
|
||||
Log.i(TAG, "Hosts file use=" + use_hosts + " exists=" + hosts.exists());
|
||||
mapHostsBlocked.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean changed = (hosts.lastModified() != last_hosts_modified);
|
||||
if (!changed && mapHostsBlocked.size() > 0) {
|
||||
Log.i(TAG, "Hosts file unchanged");
|
||||
return;
|
||||
}
|
||||
last_hosts_modified = hosts.lastModified();
|
||||
|
||||
mapHostsBlocked.clear();
|
||||
|
||||
if (use_hosts && hosts.exists() && hosts.canRead()) {
|
||||
int count = 0;
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
|
@ -979,7 +990,6 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareUidIPFilters() {
|
||||
Map<Long, Map<InetAddress, Boolean>> map = new HashMap<>();
|
||||
|
|
Loading…
Reference in a new issue