Updating ad server list, removing unnecessary code in adblock

This commit is contained in:
Anthony Restaino 2016-08-06 17:41:00 -04:00
parent d5c8479a41
commit 4539536eb5
2 changed files with 356 additions and 35 deletions

File diff suppressed because it is too large Load Diff

View File

@ -37,7 +37,6 @@ public class AdBlock {
private static final String EMPTY = ""; private static final String EMPTY = "";
private final Set<String> mBlockedDomainsList = new HashSet<>(); private final Set<String> mBlockedDomainsList = new HashSet<>();
private boolean mBlockAds; private boolean mBlockAds;
private static final Locale mLocale = Locale.getDefault();
@Inject PreferenceManager mPreferenceManager; @Inject PreferenceManager mPreferenceManager;
@ -64,14 +63,14 @@ public class AdBlock {
try { try {
//noinspection IOResourceOpenedButNotSafelyClosed //noinspection IOResourceOpenedButNotSafelyClosed
reader = new BufferedReader(new InputStreamReader( reader = new BufferedReader(new InputStreamReader(
asset.open(BLOCKED_DOMAINS_LIST_FILE_NAME))); asset.open(BLOCKED_DOMAINS_LIST_FILE_NAME)));
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
mBlockedDomainsList.add(line.trim().toLowerCase(mLocale)); mBlockedDomainsList.add(line.trim());
} }
} catch (IOException e) { } catch (IOException e) {
Log.wtf(TAG, "Reading blocked domains list from file '" Log.wtf(TAG, "Reading blocked domains list from file '"
+ BLOCKED_DOMAINS_LIST_FILE_NAME + "' failed.", e); + BLOCKED_DOMAINS_LIST_FILE_NAME + "' failed.", e);
} finally { } finally {
Utils.close(reader); Utils.close(reader);
} }
@ -99,7 +98,7 @@ public class AdBlock {
return false; return false;
} }
boolean isOnBlacklist = mBlockedDomainsList.contains(domain.toLowerCase(mLocale)); boolean isOnBlacklist = mBlockedDomainsList.contains(domain);
if (isOnBlacklist) { if (isOnBlacklist) {
Log.d(TAG, "URL '" + url + "' is an ad"); Log.d(TAG, "URL '" + url + "' is an ad");
} }
@ -148,14 +147,14 @@ public class AdBlock {
try { try {
//noinspection IOResourceOpenedButNotSafelyClosed //noinspection IOResourceOpenedButNotSafelyClosed
reader = new BufferedReader(new InputStreamReader( reader = new BufferedReader(new InputStreamReader(
asset.open(BLOCKED_DOMAINS_LIST_FILE_NAME))); asset.open(BLOCKED_DOMAINS_LIST_FILE_NAME)));
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
if (!line.isEmpty() && !line.startsWith(COMMENT)) { if (!line.isEmpty() && !line.startsWith(COMMENT)) {
line = line.replace(LOCAL_IP_V4, EMPTY) line = line.replace(LOCAL_IP_V4, EMPTY)
.replace(LOCAL_IP_V4_ALT, EMPTY) .replace(LOCAL_IP_V4_ALT, EMPTY)
.replace(LOCAL_IP_V6, EMPTY) .replace(LOCAL_IP_V6, EMPTY)
.replace(TAB, EMPTY); .replace(TAB, EMPTY);
int comment = line.indexOf(COMMENT); int comment = line.indexOf(COMMENT);
if (comment >= 0) { if (comment >= 0) {
line = line.substring(0, comment); line = line.substring(0, comment);
@ -174,7 +173,7 @@ public class AdBlock {
} }
} catch (IOException e) { } catch (IOException e) {
Log.wtf(TAG, "Reading blocked domains list from file '" Log.wtf(TAG, "Reading blocked domains list from file '"
+ BLOCKED_DOMAINS_LIST_FILE_NAME + "' failed.", e); + BLOCKED_DOMAINS_LIST_FILE_NAME + "' failed.", e);
} finally { } finally {
Utils.close(reader); Utils.close(reader);
} }