Browse Source

Add logging

master
Miłosz Sieradzki 11 years ago
parent
commit
d85019ec72
  1. 14
      src/acr/browser/lightning/AdBlock.java

14
src/acr/browser/lightning/AdBlock.java

@ -3,6 +3,7 @@ package acr.browser.lightning; @@ -3,6 +3,7 @@ package acr.browser.lightning;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.util.Log;
import java.io.BufferedReader;
import java.io.IOException;
@ -14,6 +15,8 @@ import java.util.Set; @@ -14,6 +15,8 @@ import java.util.Set;
public class AdBlock {
private static final String TAG = "AdBlock";
private static final String BLOCKED_DOMAINS_LIST_FILE_NAME = "hosts.txt";
private static final Set<String> mBlockedDomainsList = new HashSet<String>();
@ -51,7 +54,8 @@ public class AdBlock { @@ -51,7 +54,8 @@ public class AdBlock {
mBlockedDomainsList.add(line.trim().toLowerCase());
}
} catch (IOException e) {
e.printStackTrace();
Log.wtf(TAG, "Reading blocked domains list from file '" +
BLOCKED_DOMAINS_LIST_FILE_NAME + "' failed.", e);
}
}
});
@ -67,11 +71,15 @@ public class AdBlock { @@ -67,11 +71,15 @@ public class AdBlock {
try {
domain = getDomainName(url);
} catch (URISyntaxException e) {
e.printStackTrace();
Log.e(TAG, "URL '" + url + "' is invalid", e);
return false;
}
return mBlockedDomainsList.contains(domain.toLowerCase());
boolean isOnBlacklist = mBlockedDomainsList.contains(domain.toLowerCase());
if (isOnBlacklist) {
Log.d(TAG, "URL '" + url + "' is an ad");
}
return isOnBlacklist;
}
private static String getDomainName(String url) throws URISyntaxException {

Loading…
Cancel
Save