X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fhelpers%2FBlockListHelper.java;h=3337a96ecbf7a8f04c81bf8a56688579c445ceae;hb=1aa252f44922127b9053655a43b0df4e479438ed;hp=62ca537af240763cbcefcccab9ff1d1bd1e9b510;hpb=49e94a767e452d451a722bbb068e46458e404ed9;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/helpers/BlockListHelper.java b/app/src/main/java/com/stoutner/privacybrowser/helpers/BlockListHelper.java index 62ca537a..3337a96e 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/helpers/BlockListHelper.java +++ b/app/src/main/java/com/stoutner/privacybrowser/helpers/BlockListHelper.java @@ -1,5 +1,5 @@ /* - * Copyright © 2018 Soren Stoutner . + * Copyright © 2018-2019 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -20,47 +20,84 @@ package com.stoutner.privacybrowser.helpers; import android.content.res.AssetManager; -import android.net.Uri; -import android.util.Log; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import java.util.regex.Pattern; public class BlockListHelper { + // Describe the schema of the string array in each entry of the resource requests array list. + public final static int REQUEST_DISPOSITION = 0; + public final static int REQUEST_URL = 1; + public final static int REQUEST_BLOCKLIST = 2; + public final static int REQUEST_SUBLIST = 3; + public final static int REQUEST_BLOCKLIST_ENTRIES = 4; + public final static int REQUEST_BLOCKLIST_ORIGINAL_ENTRY = 5; + + // The request disposition options. + public final static String REQUEST_DEFAULT = "0"; + public final static String REQUEST_ALLOWED = "1"; + public final static String REQUEST_THIRD_PARTY = "2"; + public final static String REQUEST_BLOCKED = "3"; + + // The whitelists. + public final static String MAIN_WHITELIST = "1"; + public final static String FINAL_WHITELIST = "2"; + public final static String DOMAIN_WHITELIST = "3"; + public final static String DOMAIN_INITIAL_WHITELIST = "4"; + public final static String DOMAIN_FINAL_WHITELIST = "5"; + public final static String THIRD_PARTY_WHITELIST = "6"; + public final static String THIRD_PARTY_DOMAIN_WHITELIST = "7"; + public final static String THIRD_PARTY_DOMAIN_INITIAL_WHITELIST = "8"; + + // The blacklists. + public final static String MAIN_BLACKLIST = "9"; + public final static String INITIAL_BLACKLIST = "10"; + public final static String FINAL_BLACKLIST = "11"; + public final static String DOMAIN_BLACKLIST = "12"; + public final static String DOMAIN_INITIAL_BLACKLIST = "13"; + public final static String DOMAIN_FINAL_BLACKLIST = "14"; + public final static String DOMAIN_REGULAR_EXPRESSION_BLACKLIST = "15"; + public final static String THIRD_PARTY_BLACKLIST = "16"; + public final static String THIRD_PARTY_INITIAL_BLACKLIST = "17"; + public final static String THIRD_PARTY_DOMAIN_BLACKLIST = "18"; + public final static String THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST = "19"; + public final static String THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST = "20"; + public final static String THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST = "21"; + public final static String REGULAR_EXPRESSION_BLACKLIST = "22"; + public ArrayList> parseBlockList(AssetManager assets, String blockListName) { // Initialize the header list. - List headers = new LinkedList<>(); - - // Initialize the white lists. - List mainWhiteList = new LinkedList<>(); - List finalWhiteList = new LinkedList<>(); - List domainWhiteList = new LinkedList<>(); - List domainInitialWhiteList = new LinkedList<>(); - List domainFinalWhiteList = new LinkedList<>(); - List thirdPartyWhiteList = new LinkedList<>(); - List thirdPartyDomainWhiteList = new LinkedList<>(); - List thirdPartyDomainInitialWhiteList = new LinkedList<>(); - - // Initialize the black lists - List mainBlackList = new LinkedList<>(); - List initialBlackList = new LinkedList<>(); - List finalBlackList = new LinkedList<>(); - List domainBlackList = new LinkedList<>(); - List domainInitialBlackList = new LinkedList<>(); - List domainFinalBlackList = new LinkedList<>(); - List thirdPartyBlackList = new LinkedList<>(); - List thirdPartyInitialBlackList = new LinkedList<>(); - List thirdPartyDomainBlackList = new LinkedList<>(); - List thirdPartyDomainInitialBlackList = new LinkedList<>(); - List regularExpressionBlackList = new LinkedList<>(); - List domainRegularExpressionBlackList = new LinkedList<>(); - List thirdPartyRegularExpressionBlackList = new LinkedList<>(); - List thirdPartyDomainRegularExpressionBlackList = new LinkedList<>(); + List headers = new ArrayList<>(); // 0. + + // Initialize the whitelists. + List mainWhiteList = new ArrayList<>(); // 1. + List finalWhiteList = new ArrayList<>(); // 2. + List domainWhiteList = new ArrayList<>(); // 3. + List domainInitialWhiteList = new ArrayList<>(); // 4. + List domainFinalWhiteList = new ArrayList<>(); // 5. + List thirdPartyWhiteList = new ArrayList<>(); // 6. + List thirdPartyDomainWhiteList = new ArrayList<>(); // 7. + List thirdPartyDomainInitialWhiteList = new ArrayList<>(); // 8. + + // Initialize the blacklists + List mainBlackList = new ArrayList<>(); // 9. + List initialBlackList = new ArrayList<>(); // 10. + List finalBlackList = new ArrayList<>(); // 11. + List domainBlackList = new ArrayList<>(); // 12. + List domainInitialBlackList = new ArrayList<>(); // 13. + List domainFinalBlackList = new ArrayList<>(); // 14. + List domainRegularExpressionBlackList = new ArrayList<>(); // 15. + List thirdPartyBlackList = new ArrayList<>(); // 16. + List thirdPartyInitialBlackList = new ArrayList<>(); // 17. + List thirdPartyDomainBlackList = new ArrayList<>(); // 18. + List thirdPartyDomainInitialBlackList = new ArrayList<>(); // 19. + List regularExpressionBlackList = new ArrayList<>(); // 20. + List thirdPartyRegularExpressionBlackList = new ArrayList<>(); // 21. + List thirdPartyDomainRegularExpressionBlackList = new ArrayList<>(); // 22. // Populate the block lists. The `try` is required by `InputStreamReader`. @@ -73,6 +110,7 @@ public class BlockListHelper { // Parse the block list. while ((blockListEntry = bufferedReader.readLine()) != null) { + // Store the original block list entry. String originalBlockListEntry = blockListEntry; // Remove any `^` from the block list entry. Privacy Browser does not process them in the interest of efficiency. @@ -84,6 +122,16 @@ public class BlockListHelper { // Do nothing. Privacy Browser does not currently use these entries. //Log.i("BlockLists", "Not added: " + blockListEntry); + } else //noinspection StatementWithEmptyBody + if (blockListEntry.contains("$csp=script-src")) { // Ignore entries that contain `$csp=script-src`. + // Do nothing. It is uncertain what this directive is even supposed to mean, and it is blocking entire websites like androidcentral.com. https://redmine.stoutner.com/issues/306. + + //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry); + } else //noinspection StatementWithEmptyBody + if (blockListEntry.contains("$websocket") || blockListEntry.contains("$third-party,websocket") || blockListEntry.contains("$script,websocket")) { // Ignore entries with `websocket`. + // Do nothing. Privacy Browser does not differentiate between websocket requests and other requests and these entries cause a lot of false positives. + + //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry); } else if (blockListEntry.startsWith("!")) { // Comment entries. if (blockListEntry.startsWith("! Version:")) { // Get the list version number. @@ -163,7 +211,7 @@ public class BlockListHelper { String secondEntry = entry.substring(wildcardIndex + 1); // Create an entry string array. - String[] domainDoubleEntry = {domain, firstEntry, secondEntry}; + String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the white list. thirdPartyDomainInitialWhiteList.add(domainDoubleEntry); @@ -172,7 +220,7 @@ public class BlockListHelper { // " - " + originalBlockListEntry); } else { // Process a third-party domain initial white list single entry. // Create a domain entry string array. - String[] domainEntry = {domain, entry}; + String[] domainEntry = {domain, entry, originalBlockListEntry}; // Add the entry to the third party domain initial white list. thirdPartyDomainInitialWhiteList.add(domainEntry); @@ -211,7 +259,7 @@ public class BlockListHelper { String secondEntry = entry.substring(wildcardIndex + 1); // Create an entry string array. - String[] domainDoubleEntry = {domain, firstEntry, secondEntry}; + String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the white list. thirdPartyDomainWhiteList.add(domainDoubleEntry); @@ -220,7 +268,7 @@ public class BlockListHelper { // originalBlockListEntry); } else { // Process a third-party domain single entry. // Create an entry string array. - String[] domainEntry = {domain, entry}; + String[] domainEntry = {domain, entry, originalBlockListEntry}; // Add the entry to the white list. thirdPartyDomainWhiteList.add(domainEntry); @@ -266,7 +314,7 @@ public class BlockListHelper { String fifthEntry = fourthEntry.substring(fourthWildcardIndex + 1); // Create an entry string array. - String[] quintupleEntry = {firstEntry, realSecondEntry, realThirdEntry, realFourthEntry, fifthEntry}; + String[] quintupleEntry = {firstEntry, realSecondEntry, realThirdEntry, realFourthEntry, fifthEntry, originalBlockListEntry}; // Add the entry to the white list. thirdPartyWhiteList.add(quintupleEntry); @@ -275,7 +323,7 @@ public class BlockListHelper { // realFourthEntry + " , " + fifthEntry + " - " + originalBlockListEntry); } else { // Process a third-party white list quadruple entry. // Create an entry string array. - String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry}; + String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry}; // Add the entry to the white list. thirdPartyWhiteList.add(quadrupleEntry); @@ -285,7 +333,7 @@ public class BlockListHelper { } } else { // Process a third-party white list triple entry. // Create an entry string array. - String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry}; + String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry}; // Add the entry to the white list. thirdPartyWhiteList.add(tripleEntry); @@ -295,7 +343,7 @@ public class BlockListHelper { } } else { // Process a third-party white list double entry. // Create an entry string array. - String[] doubleEntry = {firstEntry, secondEntry}; + String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the white list. thirdPartyWhiteList.add(doubleEntry); @@ -304,7 +352,7 @@ public class BlockListHelper { } } else { // Process a third-party white list single entry. // Create an entry string array. - String[] singleEntry = {entry}; + String[] singleEntry = {entry, originalBlockListEntry}; // Add the entry to the white list. thirdPartyWhiteList.add(singleEntry); @@ -360,7 +408,7 @@ public class BlockListHelper { String thirdEntry = secondEntry.substring(secondWildcardIndex + 1); // Create an entry string array. - String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry}; + String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry}; // Add the entry to the white list. domainInitialWhiteList.add(domainTripleEntry); @@ -369,7 +417,7 @@ public class BlockListHelper { // thirdEntry + " - " + originalBlockListEntry); } else { // Process a domain initial double entry. // Create an entry string array. - String[] domainDoubleEntry = {domain, firstEntry, secondEntry}; + String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the white list. domainInitialWhiteList.add(domainDoubleEntry); @@ -379,7 +427,7 @@ public class BlockListHelper { } } else { // Process a domain initial single entry. // Create an entry string array. - String[] domainEntry = {domain, entry}; + String[] domainEntry = {domain, entry, originalBlockListEntry}; // Add the entry to the white list. domainInitialWhiteList.add(domainEntry); @@ -416,7 +464,7 @@ public class BlockListHelper { String secondEntry = entry.substring(wildcardIndex + 1); // Create an entry string array. - String[] domainDoubleEntry = {domain, firstEntry, secondEntry}; + String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the white list. domainFinalWhiteList.add(domainDoubleEntry); @@ -425,7 +473,7 @@ public class BlockListHelper { // originalBlockListEntry); } else { // Process a domain final white list single entry. // create an entry string array. - String[] domainEntry = {domain, entry}; + String[] domainEntry = {domain, entry, originalBlockListEntry}; // Add the entry to the white list. domainFinalWhiteList.add(domainEntry); @@ -481,7 +529,7 @@ public class BlockListHelper { String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1); // Create an entry string array. - String[] domainQuadrupleEntry = {domain, firstEntry, realSecondEntry, realThirdEntry, fourthEntry}; + String[] domainQuadrupleEntry = {domain, firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry}; // Add the entry to the white list. domainWhiteList.add(domainQuadrupleEntry); @@ -490,7 +538,7 @@ public class BlockListHelper { // realThirdEntry + " , " + fourthEntry + " - " + originalBlockListEntry); } else { // Process a domain white list triple entry. // Create an entry string array. - String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry}; + String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry}; // Add the entry to the white list. domainWhiteList.add(domainTripleEntry); @@ -500,7 +548,7 @@ public class BlockListHelper { } } else { // Process a domain white list double entry. // Create an entry string array. - String[] domainDoubleEntry = {domain, firstEntry, secondEntry}; + String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the white list. domainWhiteList.add(domainDoubleEntry); @@ -510,7 +558,7 @@ public class BlockListHelper { } } else { // Process a domain white list single entry. // Create an entry string array. - String[] domainEntry = {domain, entry}; + String[] domainEntry = {domain, entry, originalBlockListEntry}; // Add the entry to the white list. domainWhiteList.add(domainEntry); @@ -534,7 +582,7 @@ public class BlockListHelper { String secondEntry = entry.substring(wildcardIndex + 1); // Create an entry string array. - String[] doubleEntry = {firstEntry, secondEntry}; + String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the white list. finalWhiteList.add(doubleEntry); @@ -542,7 +590,7 @@ public class BlockListHelper { //Log.i("BlockLists", headers.get(1)[0] + " final white list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry); } else { // Process a final white list single entry. // Create an entry string array. - String[] singleEntry = {entry}; + String[] singleEntry = {entry, originalBlockListEntry}; // Add the entry to the white list. finalWhiteList.add(singleEntry); @@ -567,7 +615,7 @@ public class BlockListHelper { String thirdEntry = secondEntry.substring(secondWildcardIndex + 1); // Create an entry string array. - String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry}; + String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry}; // Add the entry to the white list. mainWhiteList.add(tripleEntry); @@ -575,7 +623,7 @@ public class BlockListHelper { //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " + originalBlockListEntry); } else { // Process a main white list double entry. // Create an entry string array. - String[] doubleEntry = {firstEntry, secondEntry}; + String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the white list. mainWhiteList.add(doubleEntry); @@ -584,7 +632,7 @@ public class BlockListHelper { } } else { // Process a main white list single entry. // Create an entry string array. - String[] singleEntry = {blockListEntry}; + String[] singleEntry = {blockListEntry, originalBlockListEntry}; // Add the entry to the white list. mainWhiteList.add(singleEntry); @@ -610,7 +658,7 @@ public class BlockListHelper { String secondEntry = entry.substring(wildcardIndex + 1); // Create an entry string array. - String[] doubleEntry = {firstEntry, secondEntry}; + String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the black list. finalBlackList.add(doubleEntry); @@ -618,7 +666,7 @@ public class BlockListHelper { //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry); } else { // Process a final black list single entry. // create an entry string array. - String[] singleEntry = {entry}; + String[] singleEntry = {entry, originalBlockListEntry}; // Add the entry to the black list. finalBlackList.add(singleEntry); @@ -686,7 +734,7 @@ public class BlockListHelper { String thirdEntry = secondEntry.substring(secondWildcardIndex + 1); // Create an entry string array. - String[] tripleDomainEntry = {domain, firstEntry, realSecondEntry, thirdEntry}; + String[] tripleDomainEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry}; // Add the entry to the black list. thirdPartyDomainInitialBlackList.add(tripleDomainEntry); @@ -695,7 +743,7 @@ public class BlockListHelper { // " , " + thirdEntry + " - " + originalBlockListEntry); } else { // Process a third-party domain initial black list double entry. // Create an entry string array. - String[] doubleDomainEntry = {domain, firstEntry, secondEntry}; + String[] doubleDomainEntry = {domain, firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the black list. thirdPartyDomainInitialBlackList.add(doubleDomainEntry); @@ -705,7 +753,7 @@ public class BlockListHelper { } } else { // Process a third-party domain initial black list single entry. // Create an entry string array. - String[] singleEntry = {domain, entry}; + String[] singleEntry = {domain, entry, originalBlockListEntry}; // Add the entry to the black list. thirdPartyDomainInitialBlackList.add(singleEntry); @@ -736,7 +784,7 @@ public class BlockListHelper { } // Create an entry string array. - String[] domainEntry = {domain, entry}; + String[] domainEntry = {domain, entry, originalBlockListEntry}; // Add the entry to the black list. thirdPartyDomainRegularExpressionBlackList.add(domainEntry); @@ -789,7 +837,7 @@ public class BlockListHelper { String secondEntry = entry.substring(wildcardIndex + 1); // Create an entry string array. - String[] domainDoubleEntry = {domain, firstEntry, secondEntry}; + String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the white list. thirdPartyDomainWhiteList.add(domainDoubleEntry); @@ -798,7 +846,7 @@ public class BlockListHelper { // originalBlockListEntry); } else { // Process a third-party domain white list single entry. // Create an entry string array. - String[] domainEntry = {domain, entry}; + String[] domainEntry = {domain, entry, originalBlockListEntry}; // Add the entry to the white list. thirdPartyDomainWhiteList.add(domainEntry); @@ -815,7 +863,7 @@ public class BlockListHelper { String secondEntry = entry.substring(wildcardIndex + 1); // Create an entry string array. - String[] domainDoubleEntry = {domain, firstEntry, secondEntry}; + String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the black list thirdPartyDomainBlackList.add(domainDoubleEntry); @@ -824,7 +872,7 @@ public class BlockListHelper { // originalBlockListEntry); } else { // Process a third-party domain black list single entry. // Create an entry string array. - String[] domainEntry = {domain, entry}; + String[] domainEntry = {domain, entry, originalBlockListEntry}; // Add the entry to the black list. thirdPartyDomainBlackList.add(domainEntry); @@ -845,7 +893,7 @@ public class BlockListHelper { String secondEntry = entry.substring(wildcardIndex + 1); // Create an entry string array. - String[] doubleEntry = {firstEntry, secondEntry}; + String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the black list. thirdPartyBlackList.add(doubleEntry); @@ -853,7 +901,7 @@ public class BlockListHelper { //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry); } else { // Process a third-party black list single entry. // Create an entry string array. - String[] singleEntry = {entry}; + String[] singleEntry = {entry, originalBlockListEntry}; // Add an entry to the black list. thirdPartyBlackList.add(singleEntry); @@ -878,7 +926,7 @@ public class BlockListHelper { String secondEntry = entry.substring(wildcardIndex + 1); // Create an entry string array. - String[] thirdPartyDoubleEntry = {firstEntry, secondEntry}; + String[] thirdPartyDoubleEntry = {firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the black list. thirdPartyInitialBlackList.add(thirdPartyDoubleEntry); @@ -886,7 +934,7 @@ public class BlockListHelper { //Log.i("BlockLists", headers.get(1)[0] + " third-party initial black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry); } else { // Process a third-party initial black list single entry. // Create an entry string array. - String[] singleEntry = {entry}; + String[] singleEntry = {entry, originalBlockListEntry}; // Add the entry to the black list. thirdPartyInitialBlackList.add(singleEntry); @@ -905,7 +953,7 @@ public class BlockListHelper { } // Create an entry string array. - String[] singleEntry = {entry}; + String[] singleEntry = {entry, originalBlockListEntry}; // Add the entry to the black list. thirdPartyRegularExpressionBlackList.add(singleEntry); @@ -920,7 +968,7 @@ public class BlockListHelper { entry = entry.substring(0, entry.length() - 1); // Create an entry string array. - String[] singleEntry = {entry}; + String[] singleEntry = {entry, originalBlockListEntry}; // Add the entry to the black list. thirdPartyBlackList.add(singleEntry); @@ -951,7 +999,7 @@ public class BlockListHelper { String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1); // Create an entry string array. - String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry}; + String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry}; // Add the entry to the black list. thirdPartyBlackList.add(quadrupleEntry); @@ -960,7 +1008,7 @@ public class BlockListHelper { // fourthEntry + " - " + originalBlockListEntry); } else { // Process a third-party black list triple entry. // Create an entry string array. - String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry}; + String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry}; // Add the entry to the black list. thirdPartyBlackList.add(tripleEntry); @@ -970,7 +1018,7 @@ public class BlockListHelper { } } else { // Process a third-party black list double entry. // Create an entry string array. - String[] doubleEntry = {firstEntry, secondEntry}; + String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the black list. thirdPartyBlackList.add(doubleEntry); @@ -983,7 +1031,7 @@ public class BlockListHelper { String entry = blockListEntry.substring(0, blockListEntry.indexOf("$")); // Create an entry string array. - String[] singleEntry = {entry}; + String[] singleEntry = {entry, originalBlockListEntry}; // Add the entry to the black list. thirdPartyBlackList.add(singleEntry); @@ -1037,7 +1085,7 @@ public class BlockListHelper { String thirdEntry = secondEntry.substring((secondWildcardIndex + 1)); // Create an entry string array. - String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry}; + String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry}; // Add the entry to the white list. domainWhiteList.add(domainTripleEntry); @@ -1046,7 +1094,7 @@ public class BlockListHelper { // " - " + originalBlockListEntry); } else { // Process a domain white list double entry. // Create an entry string array. - String[] domainDoubleEntry = {domain, firstEntry, secondEntry}; + String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the white list. domainWhiteList.add(domainDoubleEntry); @@ -1055,7 +1103,7 @@ public class BlockListHelper { } } else { // Process a domain white list single entry. // Create an entry string array. - String[] domainEntry = {domain, entry}; + String[] domainEntry = {domain, entry, originalBlockListEntry}; // Add the entry to the white list. domainWhiteList.add(domainEntry); @@ -1098,7 +1146,7 @@ public class BlockListHelper { //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry); } else { // Process a domain initial black list entry // Create an entry string array. - String[] domainEntry = {domain, entryBase}; + String[] domainEntry = {domain, entryBase, originalBlockListEntry}; // Add the entry to the black list. domainInitialBlackList.add(domainEntry); @@ -1118,7 +1166,7 @@ public class BlockListHelper { String secondEntry = entryBase.substring(wildcardIndex + 1); // Create an entry string array. - String[] domainDoubleEntry = {domain, firstEntry, secondEntry}; + String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the black list. domainFinalBlackList.add(domainDoubleEntry); @@ -1127,7 +1175,7 @@ public class BlockListHelper { // originalBlockListEntry); } else { // Process a domain final black list single entry. // Create an entry string array. - String[] domainEntry = {domain, entryBase}; + String[] domainEntry = {domain, entryBase, originalBlockListEntry}; // Add the entry to the black list. domainFinalBlackList.add(domainEntry); @@ -1136,7 +1184,7 @@ public class BlockListHelper { } } else if (entry.contains("\\")) { // Process a domain regular expression black list entry. // Create an entry string array. - String[] domainEntry = {domain, entry}; + String[] domainEntry = {domain, entry, originalBlockListEntry}; // Add the entry to the black list. domainRegularExpressionBlackList.add(domainEntry); @@ -1159,7 +1207,7 @@ public class BlockListHelper { String thirdEntry = secondEntry.substring(secondWildcardIndex + 1); // Create an entry string array. - String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry}; + String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry}; // Add the entry to the black list. domainBlackList.add(domainTripleEntry); @@ -1168,7 +1216,7 @@ public class BlockListHelper { // " - " + originalBlockListEntry); } else { // Process a domain black list double entry. // Create an entry string array. - String[] domainDoubleEntry = {domain, firstEntry, secondEntry}; + String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the black list. domainBlackList.add(domainDoubleEntry); @@ -1178,7 +1226,7 @@ public class BlockListHelper { } } else { // Process a domain black list single entry. // Create an entry string array. - String[] domainEntry = {domain, entry}; + String[] domainEntry = {domain, entry, originalBlockListEntry}; // Add the entry to the black list. domainBlackList.add(domainEntry); @@ -1206,7 +1254,7 @@ public class BlockListHelper { String secondEntry = blockListEntry.substring(wildcardIndex + 1); // Create an entry string array. - String[] doubleEntry = {firstEntry, secondEntry}; + String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the white list. mainWhiteList.add(doubleEntry); @@ -1214,7 +1262,7 @@ public class BlockListHelper { //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry); } else { // Process a white list single entry. // Create an entry string array. - String[] singleEntry = {blockListEntry}; + String[] singleEntry = {blockListEntry, originalBlockListEntry}; // Add the entry to the white list. mainWhiteList.add(singleEntry); @@ -1226,7 +1274,7 @@ public class BlockListHelper { blockListEntry = blockListEntry.substring(0, blockListEntry.indexOf("$")); // Create an entry string array. - String[] singleEntry = {blockListEntry}; + String[] singleEntry = {blockListEntry, originalBlockListEntry}; // Add the entry to the black list. regularExpressionBlackList.add(singleEntry); @@ -1256,7 +1304,7 @@ public class BlockListHelper { String secondEntry = entry.substring(wildcardIndex + 1); // Create an entry string array. - String[] doubleEntry = {firstEntry, secondEntry}; + String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the black list. initialBlackList.add(doubleEntry); @@ -1264,7 +1312,7 @@ public class BlockListHelper { //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry); } else { // Process an initial black list single entry. // Create an entry string array. - String[] singleEntry = {entry}; + String[] singleEntry = {entry, originalBlockListEntry}; // Add the entry to the black list. initialBlackList.add(singleEntry); @@ -1294,7 +1342,7 @@ public class BlockListHelper { String thirdEntry = secondEntry.substring(secondWildcardIndex + 1); // Create an entry string array. - String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry}; + String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry}; // Add the entry to the black list. finalBlackList.add(tripleEntry); @@ -1303,7 +1351,7 @@ public class BlockListHelper { // originalBlockListEntry); } else { // Process a final black list double entry. // Create an entry string array. - String[] doubleEntry = {firstEntry, secondEntry}; + String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the black list. finalBlackList.add(doubleEntry); @@ -1312,7 +1360,7 @@ public class BlockListHelper { } } else { // Process a final black list single entry. // Create an entry sting array. - String[] singleEntry = {entry}; + String[] singleEntry = {entry, originalBlockListEntry}; // Add the entry to the black list. finalBlackList.add(singleEntry); @@ -1337,7 +1385,7 @@ public class BlockListHelper { String thirdEntry = secondEntry.substring(secondWildcardIndex + 1); // Create an entry string array. - String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry}; + String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry}; // Add the entry to the black list. mainBlackList.add(tripleEntry); @@ -1345,7 +1393,7 @@ public class BlockListHelper { //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + " - " + originalBlockListEntry); } else { // Process a main black list double entry. // Create an entry string array. - String[] doubleEntry = {firstEntry, secondEntry}; + String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the black list. mainBlackList.add(doubleEntry); @@ -1354,7 +1402,7 @@ public class BlockListHelper { } } else { // Process a main black list single entry. // Create an entry string array. - String[] singleEntry = {blockListEntry}; + String[] singleEntry = {blockListEntry, originalBlockListEntry}; // Add the entry to the black list. mainBlackList.add(singleEntry); @@ -1391,7 +1439,7 @@ public class BlockListHelper { String secondEntry = entry.substring(wildcardIndex + 1); // Create an entry string array. - String[] doubleEntry = {firstEntry, secondEntry}; + String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the black list. initialBlackList.add(doubleEntry); @@ -1399,7 +1447,7 @@ public class BlockListHelper { //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + firstEntry + " , " + secondEntry + " - " + originalBlockListEntry); } else { // Process an initial black list single entry. // Create an entry string array. - String[] singleEntry = {entry}; + String[] singleEntry = {entry, originalBlockListEntry}; // Add the entry to the black list. initialBlackList.add(singleEntry); @@ -1427,7 +1475,7 @@ public class BlockListHelper { String thirdEntry = secondEntry.substring(secondWildcardIndex + 1); // Create an entry string array. - String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry}; + String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry}; // Add the entry to the black list. finalBlackList.add(tripleEntry); @@ -1436,7 +1484,7 @@ public class BlockListHelper { // originalBlockListEntry); } else { // Process a final black list double entry. // Create an entry string array. - String[] doubleEntry = {firstEntry, secondEntry}; + String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the black list. finalBlackList.add(doubleEntry); @@ -1445,7 +1493,7 @@ public class BlockListHelper { } } else { // Process a final black list single entry. // Create an entry string array. - String[] singleEntry = {entry}; + String[] singleEntry = {entry, originalBlockListEntry}; // Add the entry to the black list. finalBlackList.add(singleEntry); @@ -1486,7 +1534,7 @@ public class BlockListHelper { String fifthEntry = fourthEntry.substring(fourthWildcardIndex + 1); // Create an entry string array. - String[] quintupleEntry = {firstEntry, realSecondEntry, realThirdEntry, realFourthEntry, fifthEntry}; + String[] quintupleEntry = {firstEntry, realSecondEntry, realThirdEntry, realFourthEntry, fifthEntry, originalBlockListEntry}; // Add the entry to the black list. mainBlackList.add(quintupleEntry); @@ -1495,7 +1543,7 @@ public class BlockListHelper { // realFourthEntry + " , " + fifthEntry + " - " + originalBlockListEntry); } else { // Process a main black list quadruple entry. // Create an entry string array. - String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry}; + String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry}; // Add the entry to the black list. mainBlackList.add(quadrupleEntry); @@ -1505,7 +1553,7 @@ public class BlockListHelper { } } else { // Process a main black list triple entry. // Create an entry string array. - String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry}; + String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry}; // Add the entry to the black list. mainBlackList.add(tripleEntry); @@ -1514,7 +1562,7 @@ public class BlockListHelper { } } else { // Process a main black list double entry. // Create an entry string array. - String[] doubleEntry = {firstEntry, secondEntry}; + String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry}; // Add the entry to the black list. mainBlackList.add(doubleEntry); @@ -1523,7 +1571,7 @@ public class BlockListHelper { } } else { // Process a main black list single entry. // Create an entry string array. - String[] singleEntry = {blockListEntry}; + String[] singleEntry = {blockListEntry, originalBlockListEntry}; // Add the entry to the black list. mainBlackList.add(singleEntry); @@ -1574,72 +1622,54 @@ public class BlockListHelper { return combinedLists; } - public boolean isBlocked(String currentUrl, String resourceUrl, ArrayList> blockList) { - // Get the list title. - String blockListTitle = blockList.get(0).get(1)[0]; - - Uri currentUri = Uri.parse(currentUrl); - String currentDomain = currentUri.getHost(); - - Uri resourceUri = Uri.parse(resourceUrl); - String resourceDomain = resourceUri.getHost(); - - boolean thirdPartyRequest = false; + public String[] checkBlocklist(String currentDomain, String resourceUrl, boolean isThirdPartyRequest, ArrayList> blockList) { + // Get the blocklist name. + String BLOCK_LIST_NAME_STRING = blockList.get(0).get(1)[0]; - // If one of the domains is `about:blank` it will throw a null object reference on the string comparison. - if ((currentDomain != null) && (resourceDomain != null)) { - thirdPartyRequest = !resourceDomain.equals(currentDomain); + // Assert that currentDomain != null only if this is a third party request. Apparently, lint can't tell that this isn't redundant. + //noinspection RedundantIfStatement + if (isThirdPartyRequest) { + assert currentDomain != null; } // Process the white lists. // Main white list. - for (String[] whiteListEntry : blockList.get(1)) { + for (String[] whiteListEntry : blockList.get(Integer.valueOf(MAIN_WHITELIST))) { switch (whiteListEntry.length) { - case 1: // There is one entry. + case 2: // There is one entry. if (resourceUrl.contains(whiteListEntry[0])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " main white list: " + whiteListEntry[0] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_WHITELIST, whiteListEntry[0], whiteListEntry[1]}; } break; - case 2: + case 3: // There are two entries. if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " main white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } break; - case 3: + case 4: // There are three entries. if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " main white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " , " + whiteListEntry[2] + " - " + - resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]}; } break; } } // Final white list. - for (String[] whiteListEntry : blockList.get(2)) { - if (whiteListEntry.length == 1) { // There is one entry. + for (String[] whiteListEntry : blockList.get(Integer.valueOf(FINAL_WHITELIST))) { + if (whiteListEntry.length == 2) { // There is one entry. if (resourceUrl.contains(whiteListEntry[0])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " final white list: " + whiteListEntry[0] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_WHITELIST, whiteListEntry[0], whiteListEntry[1]}; } } else { // There are two entries. if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " final white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } } } @@ -1647,103 +1677,85 @@ public class BlockListHelper { // Only check the domain lists if the current domain is not null (like `about:blank`). if (currentDomain != null) { // Domain white list. - for (String[] whiteListEntry : blockList.get(3)) { + for (String[] whiteListEntry : blockList.get(Integer.valueOf(DOMAIN_WHITELIST))) { switch (whiteListEntry.length) { - case 2: // There is one entry. + case 3: // There is one entry. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " domain white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " --" + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } break; - case 3: // There are two entries. + case 4: // There are two entries. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " domain white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " , " + whiteListEntry[2] + - " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], + whiteListEntry[3]}; } break; - case 4: // There are three entries. + case 5: // There are three entries. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " domain white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " , " + whiteListEntry[2] + - " , " + whiteListEntry[3] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + + whiteListEntry[3], whiteListEntry[4]}; } break; - case 5: // There are four entries. + case 6: // There are four entries. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3]) && resourceUrl.contains(whiteListEntry[4])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " domain white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " , " + whiteListEntry[2] + - " , " + whiteListEntry[3] + " , " + whiteListEntry[4] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + + whiteListEntry[3] + "\n" + whiteListEntry[4], whiteListEntry[5]}; } break; } } // Domain initial white list. - for (String[] whiteListEntry : blockList.get(4)) { + for (String[] whiteListEntry : blockList.get(Integer.valueOf(DOMAIN_INITIAL_WHITELIST))) { switch (whiteListEntry.length) { - case 2: // There is one entry. + case 3: // There is one entry. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " domain initial white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_INITIAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } break; - case 3: // There are two entries. + case 4: // There are two entries. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " domain initial white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " , " + - whiteListEntry[2] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_INITIAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], + whiteListEntry[3]}; } break; - case 4: // There are three entries. + case 5: // There are three entries. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.startsWith(whiteListEntry[3])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " domain initial white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " , " + - whiteListEntry[2] + " , " + whiteListEntry[3] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_INITIAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + + whiteListEntry[3], whiteListEntry[4]}; } break; } } // Domain final white list. - for (String[] whiteListEntry : blockList.get(5)) { + for (String[] whiteListEntry : blockList.get(Integer.valueOf(DOMAIN_FINAL_WHITELIST))) { switch (whiteListEntry.length) { - case 2: // There is one entry; + case 3: // There is one entry; if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.endsWith(whiteListEntry[1])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " domain final white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_FINAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } break; - case 3: // There are two entries; + case 4: // There are two entries; if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.endsWith(whiteListEntry[2])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " domain final white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " , " + - whiteListEntry[2] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_FINAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], + whiteListEntry[3]}; } break; } @@ -1751,98 +1763,79 @@ public class BlockListHelper { } // Only check the third-party white lists if this is a third-party request. - if (thirdPartyRequest) { + if (isThirdPartyRequest) { // Third-party white list. - for (String[] whiteListEntry : blockList.get(6)) { + for (String[] whiteListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_WHITELIST))) { switch (whiteListEntry.length) { - case 1: // There is one entry + case 2: // There is one entry if (resourceUrl.contains(whiteListEntry[0])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " third-party white list: " + whiteListEntry[0] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0], whiteListEntry[1]}; } break; - case 2: // There are two entries. + case 3: // There are two entries. if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " third-party white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } break; - case 3: // There are three entries. + case 4: // There are three entries. if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " third-party white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " , " + whiteListEntry[2] + - " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], + whiteListEntry[3]}; } break; - case 4: // There are four entries. + case 5: // There are four entries. if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " third-party white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " , " + whiteListEntry[2] + - " , " + whiteListEntry[3] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + + whiteListEntry[3], whiteListEntry[4]}; } break; - case 5: // There are five entries. + case 6: // There are five entries. if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3]) && resourceUrl.contains(whiteListEntry[4])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " third-party white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " , " + whiteListEntry[2] + - " , " + whiteListEntry[3] + " , " + whiteListEntry[4] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + + whiteListEntry[3] + "\n" + whiteListEntry[4], whiteListEntry[5]}; } break; } } // Third-party domain white list. - for (String[] whiteListEntry : blockList.get(7)) { - if (whiteListEntry.length == 2) { // There is one entry. + for (String[] whiteListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_WHITELIST))) { + if (whiteListEntry.length == 3) { // There is one entry. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " third-party domain white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } } else { // There are two entries. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " third-party domain white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " , " + - whiteListEntry[2] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], + whiteListEntry[3]}; } } } // Third-party domain initial white list. - for (String[] whiteListEntry : blockList.get(8)) { - if (whiteListEntry.length == 2) { // There is one entry. + for (String[] whiteListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_INITIAL_WHITELIST))) { + if (whiteListEntry.length == 3) { // There is one entry. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " third-party domain initial white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " - " + - resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_INITIAL_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]}; } } else { // There are two entries. if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) { - Log.i("BlockLists", "Request allowed by " + blockListTitle + " third-party domain initial white list: " + whiteListEntry[0] + " , " + whiteListEntry[1] + " , " + - whiteListEntry[2] + " - " + resourceUrl); - - // Not blocked. - return false; + // Return a whitelist match request allowed. + return new String[] {REQUEST_ALLOWED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_WHITELIST, whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], + whiteListEntry[3]}; } } } @@ -1850,106 +1843,84 @@ public class BlockListHelper { // Process the black lists. // Main black list. - for (String[] blackListEntry : blockList.get(9)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(MAIN_BLACKLIST))) { switch (blackListEntry.length) { - case 1: // There is one entry. + case 2: // There is one entry. if (resourceUrl.contains(blackListEntry[0])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " main black list: " + blackListEntry[0] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0], blackListEntry[1]}; } break; - case 2: // There are two entries. + case 3: // There are two entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " main black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } break; - case 3: // There are three entries. + case 4: // There are three entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " main black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " , " + blackListEntry[2] + " - " + - resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]}; } break; - case 4: // There are four entries. + case 5: // There are four entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " main black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " , " + blackListEntry[2] + " , " + - blackListEntry[3] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + + blackListEntry[3], blackListEntry[4]}; } break; - case 5: // There are five entries. + case 6: // There are five entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3]) && resourceUrl.contains(blackListEntry[4])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " main black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " , " + blackListEntry[2] + " , " + - blackListEntry[3] + ", " + blackListEntry[4] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, MAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + + blackListEntry[3] + "\n" + blackListEntry[4], blackListEntry[5]}; } break; } } // Initial black list. - for (String[] blackListEntry : blockList.get(10)) { - if (blackListEntry.length == 1) { // There is one entry. + for (String[] blackListEntry : blockList.get(Integer.valueOf(INITIAL_BLACKLIST))) { + if (blackListEntry.length == 2) { // There is one entry. if (resourceUrl.startsWith(blackListEntry[0])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " initial black list: " + blackListEntry[0] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, INITIAL_BLACKLIST, blackListEntry[0], blackListEntry[1]}; } } else { // There are two entries if (resourceUrl.startsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " initial black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } } } // Final black list. - for (String[] blackListEntry : blockList.get(11)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(FINAL_BLACKLIST))) { switch (blackListEntry.length) { - case 1: // There is one entry. + case 2: // There is one entry. if (resourceUrl.endsWith(blackListEntry[0])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " final black list: " + blackListEntry[0] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_BLACKLIST, blackListEntry[0], blackListEntry[1]}; } break; - case 2: // There are two entries. + case 3: // There are two entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.endsWith(blackListEntry[1])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " final black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } break; - case 3: // There are three entries. + case 4: // There are three entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.endsWith(blackListEntry[2])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " final black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " , " + blackListEntry[2] + " - " + - resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, FINAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]}; } break; } @@ -1958,236 +1929,193 @@ public class BlockListHelper { // Only check the domain lists if the current domain is not null (like `about:blank`). if (currentDomain != null) { // Domain black list. - for (String[] blackListEntry : blockList.get(12)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(DOMAIN_BLACKLIST))) { switch (blackListEntry.length) { - case 2: // There is one entry. + case 3: // There is one entry. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " domain black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } break; - case 3: // There are two entries. + case 4: // There are two entries. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " domain black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " , " + blackListEntry[2] + - " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], + blackListEntry[3]}; } break; - case 4: // There are three entries. + case 5: // There are three entries. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " domain black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " , " + blackListEntry[2] + - " , " + blackListEntry[3] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + + blackListEntry[3], blackListEntry[4]}; } break; } } // Domain initial black list. - for (String[] blackListEntry : blockList.get(13)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(DOMAIN_INITIAL_BLACKLIST))) { + // Store the entry in the resource request log. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " domain initial black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } } // Domain final black list. - for (String[] blackListEntry : blockList.get(14)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(DOMAIN_FINAL_BLACKLIST))) { switch (blackListEntry.length) { - case 2: // There is one entry. + case 3: // There is one entry. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.endsWith(blackListEntry[1])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " domain final black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_FINAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } break; - case 3: // There are two entries. + case 4: // There are two entries. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.endsWith(blackListEntry[2])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " domain final black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " , " + blackListEntry[2] + - " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_FINAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], + blackListEntry[3]}; } break; } } // Domain regular expression black list. - for (String[] blackListEntry : blockList.get(15)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(DOMAIN_REGULAR_EXPRESSION_BLACKLIST))) { if (currentDomain.endsWith(blackListEntry[0]) && Pattern.matches(blackListEntry[1], resourceUrl)) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " domain regular expression black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, DOMAIN_REGULAR_EXPRESSION_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } } } // Only check the third-party black lists if this is a third-party request. - if (thirdPartyRequest) { + if (isThirdPartyRequest) { // Third-party black list. - for (String[] blackListEntry : blockList.get(16)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_BLACKLIST))) { switch (blackListEntry.length) { - case 1: // There is one entry. + case 2: // There is one entry. if (resourceUrl.contains(blackListEntry[0])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " third-party black list: " + blackListEntry[0] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_BLACKLIST, blackListEntry[0], blackListEntry[1]}; } break; - case 2: // There are two entries. + case 3: // There are two entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " third-party black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } break; - case 3: // There are three entries. + case 4: // There are three entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " third-party black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " , " + blackListEntry[2] + - " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], + blackListEntry[3]}; } break; - case 4: // There are four entries. + case 5: // There are four entries. if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " third-party black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " , " + blackListEntry[2] + - " , " + blackListEntry[3] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + + blackListEntry[3], blackListEntry[4]}; } break; } } // Third-party initial black list. - for (String[] blackListEntry : blockList.get(17)) { - if (blackListEntry.length == 1) { // There is one entry. + for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_INITIAL_BLACKLIST))) { + if (blackListEntry.length == 2) { // There is one entry. if (resourceUrl.startsWith(blackListEntry[0])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " third-party initial black list: " + blackListEntry[0] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_INITIAL_BLACKLIST, blackListEntry[0], blackListEntry[1]}; } } else { // There are two entries. if (resourceUrl.startsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " third-party initial black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } } } // Third-party domain black list. - for (String[] blackListEntry : blockList.get(18)) { - if (blackListEntry.length == 2) { // There is one entry. + for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_BLACKLIST))) { + if (blackListEntry.length == 3) { // There is one entry. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " third-party domain black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } } else { // There are two entries. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " third-party domain black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " , " + - blackListEntry[2] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], + blackListEntry[3]}; } } } // Third-party domain initial black list. - for (String[] blackListEntry : blockList.get(19)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST))) { switch (blackListEntry.length) { - case 2: // There is one entry. + case 3: // There is one entry. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " third-party domain initial black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " - " + - resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } break; - case 3: // There are two entries. + case 4: // There are two entries. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " third-party domain initial black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " , " + - blackListEntry[2] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + + blackListEntry[2], blackListEntry[3]}; } break; - case 4: // There are three entries. + case 5: // There are three entries. if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " third-party domain initial black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " , " + - blackListEntry[2] + blackListEntry[3] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + + blackListEntry[2] + "\n" + blackListEntry[3], blackListEntry[4]}; } break; } } // Third-party regular expression black list. - for (String[] blackListEntry : blockList.get(20)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST))) { if (Pattern.matches(blackListEntry[0], resourceUrl)) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " third-party regular expression black list: " + blackListEntry[0] + " - " + resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST, blackListEntry[0], blackListEntry[1]}; } } // Third-party domain regular expression black list. - for (String[] blackListEntry : blockList.get(21)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST))) { if (currentDomain.endsWith(blackListEntry[0]) && Pattern.matches(blackListEntry[1], resourceUrl)) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " third-party domain regular expression black list: " + blackListEntry[0] + " , " + blackListEntry[1] + " - " + - resourceUrl); - - // Blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST, blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]}; } } } // Regular expression black list. - for (String[] blackListEntry : blockList.get(22)) { + for (String[] blackListEntry : blockList.get(Integer.valueOf(REGULAR_EXPRESSION_BLACKLIST))) { if (Pattern.matches(blackListEntry[0], resourceUrl)) { - Log.i("BlockLists", "Request blocked by " + blockListTitle + " regular expression black list: " + blackListEntry[0] + " - " + resourceUrl); - - // blocked. - return true; + // Return a blacklist match request blocked. + return new String[] {REQUEST_BLOCKED, resourceUrl, BLOCK_LIST_NAME_STRING, REGULAR_EXPRESSION_BLACKLIST, blackListEntry[0], blackListEntry[1]}; } } - // Not blocked. - return false; + // Return a no match request default. + return new String[] {REQUEST_DEFAULT}; } } \ No newline at end of file