]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/helpers/BlockListHelper.java
Move Clear and Exit to the top of the navigation menu. https://redmine.stoutner...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / helpers / BlockListHelper.java
1 /*
2  * Copyright © 2018 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
5  *
6  * Privacy Browser is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Browser is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package com.stoutner.privacybrowser.helpers;
21
22 import android.content.res.AssetManager;
23
24 import com.stoutner.privacybrowser.activities.MainWebViewActivity;
25
26 import java.io.BufferedReader;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.regex.Pattern;
32
33 public class BlockListHelper {
34     public ArrayList<List<String[]>> parseBlockList(AssetManager assets, String blockListName) {
35         // Initialize the header list.
36         List<String[]> headers = new ArrayList<>();  // 0.
37
38         // Initialize the whitelists.
39         List<String[]> mainWhiteList = new ArrayList<>();  // 1.
40         List<String[]> finalWhiteList = new ArrayList<>();  // 2.
41         List<String[]> domainWhiteList = new ArrayList<>();  // 3.
42         List<String[]> domainInitialWhiteList = new ArrayList<>();  // 4.
43         List<String[]> domainFinalWhiteList = new ArrayList<>();  // 5.
44         List<String[]> thirdPartyWhiteList = new ArrayList<>();  // 6.
45         List<String[]> thirdPartyDomainWhiteList = new ArrayList<>();  // 7.
46         List<String[]> thirdPartyDomainInitialWhiteList = new ArrayList<>();  // 8.
47
48         // Initialize the blacklists
49         List<String[]> mainBlackList = new ArrayList<>();  // 9.
50         List<String[]> initialBlackList = new ArrayList<>();  // 10.
51         List<String[]> finalBlackList = new ArrayList<>();  // 11.
52         List<String[]> domainBlackList = new ArrayList<>();  // 12.
53         List<String[]> domainInitialBlackList = new ArrayList<>();  // 13.
54         List<String[]> domainFinalBlackList = new ArrayList<>();  // 14.
55         List<String[]> domainRegularExpressionBlackList = new ArrayList<>();  // 15.
56         List<String[]> thirdPartyBlackList = new ArrayList<>();  // 16.
57         List<String[]> thirdPartyInitialBlackList = new ArrayList<>();  // 17.
58         List<String[]> thirdPartyDomainBlackList = new ArrayList<>();  // 18.
59         List<String[]> thirdPartyDomainInitialBlackList = new ArrayList<>();  // 19.
60         List<String[]> regularExpressionBlackList = new ArrayList<>();  // 20.
61         List<String[]> thirdPartyRegularExpressionBlackList = new ArrayList<>();  // 21.
62         List<String[]> thirdPartyDomainRegularExpressionBlackList = new ArrayList<>();  // 22.
63
64
65         // Populate the block lists.  The `try` is required by `InputStreamReader`.
66         try {
67             // Load the block list into a `BufferedReader`.
68             BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(assets.open(blockListName)));
69
70             // Create a string for storing the block list entries.
71             String blockListEntry;
72
73             // Parse the block list.
74             while ((blockListEntry = bufferedReader.readLine()) != null) {
75                 // Store the original block list entry.
76                 String originalBlockListEntry = blockListEntry;
77
78                 // Remove any `^` from the block list entry.  Privacy Browser does not process them in the interest of efficiency.
79                 blockListEntry = blockListEntry.replace("^", "");
80
81                 //noinspection StatementWithEmptyBody
82                 if (blockListEntry.contains("##") || blockListEntry.contains("#?#") || blockListEntry.contains("#@#") || blockListEntry.startsWith("[")) {
83                     // Entries that contain `##`, `#?#`, and `#@#` are for hiding elements in the main page's HTML.  Entries that start with `[` describe the AdBlock compatibility level.
84                     // Do nothing.  Privacy Browser does not currently use these entries.
85
86                     //Log.i("BlockLists", "Not added: " + blockListEntry);
87                 } else //noinspection StatementWithEmptyBody
88                     if (blockListEntry.contains("$csp=script-src")) {  // Ignore entries that contain `$csp=script-src`.
89                         // 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.
90
91                         //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
92                 } else //noinspection StatementWithEmptyBody
93                     if (blockListEntry.contains("$websocket") || blockListEntry.contains("$third-party,websocket") || blockListEntry.contains("$script,websocket")) {  // Ignore entries with `websocket`.
94                         // Do nothing.  Privacy Browser does not differentiate between websocket requests and other requests and these entries cause a lot of false positivies.
95
96                         //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
97                 } else if (blockListEntry.startsWith("!")) {  //  Comment entries.
98                     if (blockListEntry.startsWith("! Version:")) {
99                         // Get the list version number.
100                         String[] listVersion = {blockListEntry.substring(11)};
101
102                         // Store the list version in the headers list.
103                         headers.add(listVersion);
104                     }
105
106                     if (blockListEntry.startsWith("! Title:")) {
107                         // Get the list title.
108                         String[] listTitle = {blockListEntry.substring(9)};
109
110                         // Store the list title in the headers list.
111                         headers.add(listTitle);
112                     }
113
114                     //Log.i("BlockLists", "Not added: " + blockListEntry);
115                 } else if (blockListEntry.startsWith("@@")) {  // Entries that begin with `@@` are whitelists.
116                     // Remove the `@@`
117                     blockListEntry = blockListEntry.substring(2);
118
119                     // Strip out any initial `||`.  Privacy Browser doesn't differentiate items that only match against the end of the domain name.
120                     if (blockListEntry.startsWith("||")) {
121                         blockListEntry = blockListEntry.substring(2);
122                     }
123
124                     if (blockListEntry.contains("$")) {  // Filter entries.
125                         //noinspection StatementWithEmptyBody
126                         if (blockListEntry.contains("~third-party")) {  // Ignore entries that contain `~third-party`.
127                             // Do nothing.
128
129                             //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
130                         } else if (blockListEntry.contains("third-party")) {  // Third-party white list entries.
131                             if (blockListEntry.contains("domain=")) {  // Third-party domain white list entries.
132                                 // Parse the entry.
133                                 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
134                                 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
135                                 String domains = filters.substring(filters.indexOf("domain=") + 7);
136
137                                 //noinspection StatementWithEmptyBody
138                                 if (domains.contains("~")) {  // It is uncertain what a `~` domain means inside an `@@` entry.
139                                     // Do Nothing
140
141                                     //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
142                                 } else if (blockListEntry.startsWith("|")) {  // Third-party domain initial white list entries.
143                                     // Strip out the initial `|`.
144                                     entry = entry.substring(1);
145
146                                     //noinspection StatementWithEmptyBody
147                                     if (entry.equals("http://") || entry.equals("https://")) {  // Ignore generic entries.
148                                         // Do nothing.  These entries are designed for filter options that Privacy Browser does not use.
149
150                                         //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
151                                     } else {  // Process third-party domain initial white list entries.
152                                         // Process each domain.
153                                         do {
154                                             // Create a string to keep track of the current domain.
155                                             String domain;
156
157                                             if (domains.contains("|")) {  // There is more than one domain in the list.
158                                                 // Get the first domain from the list.
159                                                 domain = domains.substring(0, domains.indexOf("|"));
160
161                                                 // Remove the first domain from the list.
162                                                 domains = domains.substring(domains.indexOf("|") + 1);
163                                             } else {  // There is only one domain in the list.
164                                                 domain = domains;
165                                             }
166
167                                             if (entry.contains("*")) {  // Process a third-party domain initial white list double entry.
168                                                 // Get the index of the wildcard.
169                                                 int wildcardIndex = entry.indexOf("*");
170
171                                                 // Split the entry into components.
172                                                 String firstEntry = entry.substring(0, wildcardIndex);
173                                                 String secondEntry = entry.substring(wildcardIndex + 1);
174
175                                                 // Create an entry string array.
176                                                 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
177
178                                                 // Add the entry to the white list.
179                                                 thirdPartyDomainInitialWhiteList.add(domainDoubleEntry);
180
181                                                 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial white list added: " + domain + " , " + firstEntry + " , " + secondEntry +
182                                                 //        "  -  " + originalBlockListEntry);
183                                             } else {  // Process a third-party domain initial white list single entry.
184                                                 // Create a domain entry string array.
185                                                 String[] domainEntry = {domain, entry, originalBlockListEntry};
186
187                                                 // Add the entry to the third party domain initial white list.
188                                                 thirdPartyDomainInitialWhiteList.add(domainEntry);
189
190                                                 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial white list added: " + domain + " , " + entry + "  -  " + originalBlockListEntry);
191                                             }
192                                         } while (domains.contains("|"));
193                                     }
194                                 } else {  // Third-party domain entries.
195                                     // Process each domain.
196                                     do {
197                                         // Create a string to keep track of the current domain.
198                                         String domain;
199
200                                         if (domains.contains("|")) {  // three is more than one domain in the list.
201                                             // Get the first domain from the list.
202                                             domain = domains.substring(0, domains.indexOf("|"));
203
204                                             // Remove the first domain from the list.
205                                             domains = domains.substring(domains.indexOf("|") + 1);
206                                         } else {  // There is only one domain in the list.
207                                             domain = domains;
208                                         }
209
210                                         // Remove any trailing `*` from the entry.
211                                         if (entry.endsWith("*")) {
212                                             entry = entry.substring(0, entry.length() - 1);
213                                         }
214
215                                         if (entry.contains("*")) {  // Process a third-party domain double entry.
216                                             // Get the index of the wildcard.
217                                             int wildcardIndex = entry.indexOf("*");
218
219                                             // Split the entry into components.
220                                             String firstEntry = entry.substring(0, wildcardIndex);
221                                             String secondEntry = entry.substring(wildcardIndex + 1);
222
223                                             // Create an entry string array.
224                                             String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
225
226                                             // Add the entry to the white list.
227                                             thirdPartyDomainWhiteList.add(domainDoubleEntry);
228
229                                             //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + firstEntry + " , " + secondEntry + "  -  " +
230                                             //        originalBlockListEntry);
231                                         } else {  // Process a third-party domain single entry.
232                                             // Create an entry string array.
233                                             String[] domainEntry = {domain, entry, originalBlockListEntry};
234
235                                             // Add the entry to the white list.
236                                             thirdPartyDomainWhiteList.add(domainEntry);
237
238                                             //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + entry + "  -  " + originalBlockListEntry);
239                                         }
240                                     } while (domains.contains("|"));
241                                 }
242                             } else {  // Process third-party white list entries.
243                                 // Parse the entry
244                                 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
245
246                                 if (entry.contains("*")) {  // There are two or more entries.
247                                     // Get the index of the wildcard.
248                                     int wildcardIndex = entry.indexOf("*");
249
250                                     // Split the entry into components.
251                                     String firstEntry = entry.substring(0, wildcardIndex);
252                                     String secondEntry = entry.substring(wildcardIndex + 1);
253
254                                     if (secondEntry.contains("*")) {  // There are three or more entries.
255                                         // Get the index of the wildcard.
256                                         int secondWildcardIndex = secondEntry.indexOf("*");
257
258                                         // Split the entry into components.
259                                         String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
260                                         String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
261
262                                         if (thirdEntry.contains("*")) {  // There are four or more entries.
263                                             // Get the index of the wildcard.
264                                             int thirdWildcardIndex = thirdEntry.indexOf("*");
265
266                                             // Split the entry into components.
267                                             String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
268                                             String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
269
270                                             if (fourthEntry.contains("*")) {  // Process a third-party white list quintuple entry.
271                                                 // Get the index of the wildcard.
272                                                 int fourthWildcardIndex = fourthEntry.indexOf("*");
273
274                                                 // Split the entry into components.
275                                                 String realFourthEntry = fourthEntry.substring(0, fourthWildcardIndex);
276                                                 String fifthEntry = fourthEntry.substring(fourthWildcardIndex + 1);
277
278                                                 // Create an entry string array.
279                                                 String[] quintupleEntry = {firstEntry, realSecondEntry, realThirdEntry, realFourthEntry, fifthEntry, originalBlockListEntry};
280
281                                                 // Add the entry to the white list.
282                                                 thirdPartyWhiteList.add(quintupleEntry);
283
284                                                 //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
285                                                 //        realFourthEntry + " , " + fifthEntry + "  -  " + originalBlockListEntry);
286                                             } else {  // Process a third-party white list quadruple entry.
287                                                 // Create an entry string array.
288                                                 String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
289
290                                                 // Add the entry to the white list.
291                                                 thirdPartyWhiteList.add(quadrupleEntry);
292
293                                                 //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
294                                                 //        fourthEntry + "  -  " + originalBlockListEntry);
295                                             }
296                                         } else {  // Process a third-party white list triple entry.
297                                             // Create an entry string array.
298                                             String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
299
300                                             // Add the entry to the white list.
301                                             thirdPartyWhiteList.add(tripleEntry);
302
303                                             //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + "  -  " +
304                                             //        originalBlockListEntry);
305                                         }
306                                     } else {  // Process a third-party white list double entry.
307                                         // Create an entry string array.
308                                         String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
309
310                                         // Add the entry to the white list.
311                                         thirdPartyWhiteList.add(doubleEntry);
312
313                                         //Log.i("BlockLists", headers.get(1)[0] + " third-party white list added: " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
314                                     }
315                                 } else {  // Process a third-party white list single entry.
316                                     // Create an entry string array.
317                                     String[] singleEntry = {entry, originalBlockListEntry};
318
319                                     // Add the entry to the white list.
320                                     thirdPartyWhiteList.add(singleEntry);
321
322                                     //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + entry + "  -  " + originalBlockListEntry);
323                                 }
324                             }
325                         } else if (blockListEntry.contains("domain=")) {  // Process domain white list entries.
326                             // Parse the entry
327                             String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
328                             String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
329                             String domains = filters.substring(filters.indexOf("domain=") + 7);
330
331                             if (entry.startsWith("|")) {  // Initial domain white list entries.
332                                 // Strip the initial `|`.
333                                 entry = entry.substring(1);
334
335                                 //noinspection StatementWithEmptyBody
336                                 if (entry.equals("http://") || entry.equals("https://")) {  // Ignore generic entries.
337                                     // Do nothing.  These entries are designed for filter options that Privacy Browser does not use.
338
339                                     //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
340                                 } else {  // Initial domain white list entry.
341                                     // Process each domain.
342                                     do {
343                                         // Create a string to keep track of the current domain.
344                                         String domain;
345
346                                         if (domains.contains("|")) {  // There is more than one domain in the list.
347                                             // Get the first domain from the list.
348                                             domain = domains.substring(0, domains.indexOf("|"));
349
350                                             // Remove the first domain from the list.
351                                             domains = domains.substring(domains.indexOf("|") + 1);
352                                         } else {  // There is only one domain in the list.
353                                             domain = domains;
354                                         }
355
356                                         if (entry.contains("*")) {  // There are two or more entries.
357                                             // Get the index of the wildcard.
358                                             int wildcardIndex = entry.indexOf("*");
359
360                                             // Split the entry into components.
361                                             String firstEntry = entry.substring(0, wildcardIndex);
362                                             String secondEntry = entry.substring(wildcardIndex + 1);
363
364                                             if (secondEntry.contains("*")) {  // Process a domain initial triple entry.
365                                                 // Get the index of the wildcard.
366                                                 int secondWildcardIndex = secondEntry.indexOf("*");
367
368                                                 // Split the entry into components.
369                                                 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
370                                                 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
371
372                                                 // Create an entry string array.
373                                                 String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
374
375                                                 // Add the entry to the white list.
376                                                 domainInitialWhiteList.add(domainTripleEntry);
377
378                                                 //Log.i("BlockLists", headers.get(1)[0] + " domain initial white list entry added: " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " +
379                                                 //        thirdEntry + "  -  " + originalBlockListEntry);
380                                             } else {  // Process a domain initial double entry.
381                                                 // Create an entry string array.
382                                                 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
383
384                                                 // Add the entry to the white list.
385                                                 domainInitialWhiteList.add(domainDoubleEntry);
386
387                                                 //Log.i("BlockLists", headers.get(1)[0] + " domain initial white list entry added: " + domain + " , " + firstEntry + " , " + secondEntry + "  -  " +
388                                                 //        originalBlockListEntry);
389                                             }
390                                         } else {  // Process a domain initial single entry.
391                                             // Create an entry string array.
392                                             String[] domainEntry = {domain, entry, originalBlockListEntry};
393
394                                             // Add the entry to the white list.
395                                             domainInitialWhiteList.add(domainEntry);
396
397                                             //Log.i("BlockLists", headers.get(1)[0] + " domain initial white list entry added: " + domain + " , " + entry + "  -  " + originalBlockListEntry);
398                                         }
399                                     } while (domains.contains("|"));
400                                 }
401                             } else if (entry.endsWith("|")) {  // Final domain white list entries.
402                                 // Strip the `|` from the end of the entry.
403                                 entry = entry.substring(0, entry.length() - 1);
404
405                                 // Process each domain.
406                                 do {
407                                     // Create a string to keep track of the current domain.
408                                     String domain;
409
410                                     if (domains.contains("|")) {  // There is more than one domain in the list.
411                                         // Get the first domain from the list.
412                                         domain = domains.substring(0, domains.indexOf("|"));
413
414                                         // Remove the first domain from the list.
415                                         domains = domains.substring(domains.indexOf("|") + 1);
416                                     } else {  // There is only one domain in the list.
417                                         domain = domains;
418                                     }
419
420                                     if (entry.contains("*")) {  // Process a domain final white list double entry.
421                                         // Get the index of the wildcard.
422                                         int wildcardIndex = entry.indexOf("*");
423
424                                         // Split the entry into components.
425                                         String firstEntry = entry.substring(0, wildcardIndex);
426                                         String secondEntry = entry.substring(wildcardIndex + 1);
427
428                                         // Create an entry string array.
429                                         String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
430
431                                         // Add the entry to the white list.
432                                         domainFinalWhiteList.add(domainDoubleEntry);
433
434                                         //Log.i("BlockLists", headers.get(1)[0] + " domain final white list added: " + domain + " , " + firstEntry + " , " + secondEntry + "  -  " +
435                                         //        originalBlockListEntry);
436                                     } else {  // Process a domain final white list single entry.
437                                         // create an entry string array.
438                                         String[] domainEntry = {domain, entry, originalBlockListEntry};
439
440                                         // Add the entry to the white list.
441                                         domainFinalWhiteList.add(domainEntry);
442
443                                         //Log.i("BlockLists", headers.get(1)[0] + " domain final white list added: " + domain + " , " + entry + "  -  " + originalBlockListEntry);
444                                     }
445                                 } while (domains.contains("|"));
446
447                             } else {  // Standard domain white list entries with filters.
448                                 //noinspection StatementWithEmptyBody
449                                 if (domains.contains("~")) {  // It is uncertain what a `~` domain means inside an `@@` entry.
450                                     // Do Nothing
451
452                                     //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
453                                 } else {
454                                     // Process each domain.
455                                     do {
456                                         // Create a string to keep track of the current domain.
457                                         String domain;
458
459                                         if (domains.contains("|")) {  // There is more than one domain in the list.
460                                             // Get the first domain from the list.
461                                             domain = domains.substring(0, domains.indexOf("|"));
462
463                                             // Remove the first domain from the list.
464                                             domains = domains.substring(domains.indexOf("|") + 1);
465                                         } else {  // There is only one domain in the list.
466                                             domain = domains;
467                                         }
468
469                                         if (entry.contains("*")) {  // There are two or more entries.
470                                             // Get the index of the wildcard.
471                                             int wildcardIndex = entry.indexOf("*");
472
473                                             // Split the entry into components.
474                                             String firstEntry = entry.substring(0, wildcardIndex);
475                                             String secondEntry = entry.substring(wildcardIndex + 1);
476
477                                             if (secondEntry.contains("*")) {  // There are three or more entries.
478                                                 // Get the index of the wildcard.
479                                                 int secondWildcardIndex = secondEntry.indexOf("*");
480
481                                                 // Split the entry into components.
482                                                 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
483                                                 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
484
485                                                 if (thirdEntry.contains("*")) {  // Process a domain white list quadruple entry.
486                                                     // Get the index of the wildcard.
487                                                     int thirdWildcardIndex = thirdEntry.indexOf("*");
488
489                                                     // Split the entry into components.
490                                                     String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
491                                                     String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
492
493                                                     // Create an entry string array.
494                                                     String[] domainQuadrupleEntry = {domain, firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
495
496                                                     // Add the entry to the white list.
497                                                     domainWhiteList.add(domainQuadrupleEntry);
498
499                                                     //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " +
500                                                     //        realThirdEntry + " , " + fourthEntry + "  -  " + originalBlockListEntry);
501                                                 } else {  // Process a domain white list triple entry.
502                                                     // Create an entry string array.
503                                                     String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
504
505                                                     // Add the entry to the white list.
506                                                     domainWhiteList.add(domainTripleEntry);
507
508                                                     //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " +
509                                                     //        thirdEntry + "  -  " + originalBlockListEntry);
510                                                 }
511                                             } else {  // Process a domain white list double entry.
512                                                 // Create an entry string array.
513                                                 String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
514
515                                                 // Add the entry to the white list.
516                                                 domainWhiteList.add(domainDoubleEntry);
517
518                                                 //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + firstEntry + " , " + secondEntry + "  -  " +
519                                                 //        originalBlockListEntry);
520                                             }
521                                         } else {  // Process a domain white list single entry.
522                                             // Create an entry string array.
523                                             String[] domainEntry = {domain, entry, originalBlockListEntry};
524
525                                             // Add the entry to the white list.
526                                             domainWhiteList.add(domainEntry);
527
528                                             //Log.i("BlockLists", headers.get(1)[0] + " domain white list added : " + domain + " , " + entry + "  -  " + originalBlockListEntry);
529                                         }
530                                     } while (domains.contains("|"));
531                                 }
532                             }
533                         }  // Ignore all other filter entries.
534                     } else if (blockListEntry.endsWith("|")) {  // Final white list entries.
535                         // Remove the final `|` from the entry.
536                         String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
537
538                         if (entry.contains("*")) {  // Process a final white list double entry
539                             // Get the index of the wildcard.
540                             int wildcardIndex = entry.indexOf("*");
541
542                             // split the entry into components.
543                             String firstEntry = entry.substring(0, wildcardIndex);
544                             String secondEntry = entry.substring(wildcardIndex + 1);
545
546                             // Create an entry string array.
547                             String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
548
549                             // Add the entry to the white list.
550                             finalWhiteList.add(doubleEntry);
551
552                             //Log.i("BlockLists", headers.get(1)[0] + " final white list added: " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
553                         } else {  // Process a final white list single entry.
554                             // Create an entry string array.
555                             String[] singleEntry = {entry, originalBlockListEntry};
556
557                             // Add the entry to the white list.
558                             finalWhiteList.add(singleEntry);
559
560                             //Log.i("BlockLists", headers.get(1)[0] + " final white list added: " + entry + "  -  " + originalBlockListEntry);
561                         }
562                     } else {  // Main white list entries.
563                         if (blockListEntry.contains("*")) {  // There are two or more entries.
564                             // Get the index of the wildcard.
565                             int wildcardIndex = blockListEntry.indexOf("*");
566
567                             // Split the entry into components.
568                             String firstEntry = blockListEntry.substring(0, wildcardIndex);
569                             String secondEntry = blockListEntry.substring(wildcardIndex + 1);
570
571                             if (secondEntry.contains("*")) {  // Process a main white list triple entry.
572                                 // Get the index of the wildcard.
573                                 int secondWildcardIndex = secondEntry.indexOf("*");
574
575                                 // Split the entry into components.
576                                 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
577                                 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
578
579                                 // Create an entry string array.
580                                 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
581
582                                 // Add the entry to the white list.
583                                 mainWhiteList.add(tripleEntry);
584
585                                 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + "  -  " + originalBlockListEntry);
586                             } else {  // Process a main white list double entry.
587                                 // Create an entry string array.
588                                 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
589
590                                 // Add the entry to the white list.
591                                 mainWhiteList.add(doubleEntry);
592
593                                 //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
594                             }
595                         } else {  // Process a main white list single entry.
596                             // Create an entry string array.
597                             String[] singleEntry = {blockListEntry, originalBlockListEntry};
598
599                             // Add the entry to the white list.
600                             mainWhiteList.add(singleEntry);
601
602                             //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + blockListEntry + "  -  " + originalBlockListEntry);
603                         }
604                     }
605                 } else if (blockListEntry.endsWith("|")) {  // Final black list entries.
606                     // Strip out the final "|"
607                     String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
608
609                     // Strip out any initial `||`.  They are redundant in this case because the block list entry is being matched against the end of the URL.
610                     if (entry.startsWith("||")) {
611                         entry = entry.substring(2);
612                     }
613
614                     if (entry.contains("*")) {  // Process a final black list double entry.
615                         // Get the index of the wildcard.
616                         int wildcardIndex = entry.indexOf("*");
617
618                         // Split the entry into components.
619                         String firstEntry = entry.substring(0, wildcardIndex);
620                         String secondEntry = entry.substring(wildcardIndex + 1);
621
622                         // Create an entry string array.
623                         String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
624
625                         // Add the entry to the black list.
626                         finalBlackList.add(doubleEntry);
627
628                         //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
629                     } else {  // Process a final black list single entry.
630                         // create an entry string array.
631                         String[] singleEntry = {entry, originalBlockListEntry};
632
633                         // Add the entry to the black list.
634                         finalBlackList.add(singleEntry);
635
636                         //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + entry + "  -  " + originalBlockListEntry);
637                     }
638                 } else if (blockListEntry.contains("$")) {  // Entries with filter options.
639                     // Strip out any initial `||`.  These will be treated like any other entry.
640                     if (blockListEntry.startsWith("||")) {
641                         blockListEntry = blockListEntry.substring(2);
642                     }
643
644                     if (blockListEntry.contains("third-party")) {  // Third-party entries.
645                         //noinspection StatementWithEmptyBody
646                         if (blockListEntry.contains("~third-party")) {  // Third-party filter white list entries.
647                             // Do not process these white list entries.  They are designed to combine with block filters that Privacy Browser doesn't use, like `subdocument` and `xmlhttprequest`.
648
649                             //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
650                         } else if (blockListEntry.contains("domain=")) {  // Third-party domain entries.
651                             if (blockListEntry.startsWith("|")) {  // Third-party domain initial entries.
652                                 // Strip the initial `|`.
653                                 blockListEntry = blockListEntry.substring(1);
654
655                                 // Parse the entry
656                                 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
657                                 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
658                                 String domains = filters.substring(filters.indexOf("domain=") + 7);
659
660                                 //noinspection StatementWithEmptyBody
661                                 if (entry.equals("http:") || entry.equals("https:") || entry.equals("http://") || entry.equals("https://")) {  // Ignore generic entries.
662                                     // Do nothing.  These entries will almost entirely disable the website.
663                                     // Often the original entry blocks filter options like `$script`, which Privacy Browser does not differentiate.
664
665                                     //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
666                                 } else {  // Third-party domain initial entries.
667                                     // Process each domain.
668                                     do {
669                                         // Create a string to keep track of the current domain.
670                                         String domain;
671
672                                         if (domains.contains("|")) {  // There is more than one domain in the list.
673                                             // Get the first domain from the list.
674                                             domain = domains.substring(0, domains.indexOf("|"));
675
676                                             // Remove the first domain from the list.
677                                             domains = domains.substring(domains.indexOf("|") + 1);
678                                         } else {  // There is only one domain in the list.
679                                             domain = domains;
680                                         }
681
682                                         if (entry.contains("*")) {  // Three are two or more entries.
683                                             // Get the index of the wildcard.
684                                             int wildcardIndex = entry.indexOf("*");
685
686                                             // Split the entry into components.
687                                             String firstEntry = entry.substring(0, wildcardIndex);
688                                             String secondEntry = entry.substring(wildcardIndex + 1);
689
690                                             if (secondEntry.contains("*")) {  // Process a third-party domain initial black list triple entry.
691                                                 // Get the index of the wildcard.
692                                                 int secondWildcardIndex = secondEntry.indexOf("*");
693
694                                                 // Split the entry into components.
695                                                 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
696                                                 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
697
698                                                 // Create an entry string array.
699                                                 String[] tripleDomainEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
700
701                                                 // Add the entry to the black list.
702                                                 thirdPartyDomainInitialBlackList.add(tripleDomainEntry);
703
704                                                 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial black list added: " + domain + " , " + firstEntry + " , " + realSecondEntry +
705                                                 //        " , " + thirdEntry + "  -  " + originalBlockListEntry);
706                                             } else {  // Process a third-party domain initial black list double entry.
707                                                 // Create an entry string array.
708                                                 String[] doubleDomainEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
709
710                                                 // Add the entry to the black list.
711                                                 thirdPartyDomainInitialBlackList.add(doubleDomainEntry);
712
713                                                 //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial black list added: " + domain + " , " + firstEntry + " , " + secondEntry +
714                                                 //        "  -  " + originalBlockListEntry);
715                                             }
716                                         } else {  // Process a third-party domain initial black list single entry.
717                                             // Create an entry string array.
718                                             String[] singleEntry = {domain, entry, originalBlockListEntry};
719
720                                             // Add the entry to the black list.
721                                             thirdPartyDomainInitialBlackList.add(singleEntry);
722
723                                             //Log.i("BlockLists", headers.get(1)[0] + " third-party domain initial black list added: " + domain + " , " + entry + "  -  " + originalBlockListEntry);
724                                         }
725                                     } while (domains.contains("|"));
726                                 }
727                             } else if (blockListEntry.contains("\\")) {  // Process a third-party domain black list regular expression.
728                                 // Parse the entry.  At least one regular expression in this entry contains `$`, so the parser uses `/$`.
729                                 String entry = blockListEntry.substring(0, blockListEntry.indexOf("/$") + 1);
730                                 String filters = blockListEntry.substring(blockListEntry.indexOf("/$") + 2);
731                                 String domains = filters.substring(filters.indexOf("domain=") + 7);
732
733                                 // Process each domain.
734                                 do {
735                                     // Create a string to keep track of the current domain.
736                                     String domain;
737
738                                     if (domains.contains("|")) {  // There is more than one domain in the list.
739                                         // Get the first domain from the list.
740                                         domain = domains.substring(0, domains.indexOf("|"));
741
742                                         // Remove the first domain from the list.
743                                         domains = domains.substring(domains.indexOf("|") + 1);
744                                     } else {  // There is only one domain in the list.
745                                         domain = domains;
746                                     }
747
748                                     // Create an entry string array.
749                                     String[] domainEntry = {domain, entry, originalBlockListEntry};
750
751                                     // Add the entry to the black list.
752                                     thirdPartyDomainRegularExpressionBlackList.add(domainEntry);
753
754                                     //Log.i("BlockLists", headers.get(1)[0] + " third-party domain regular expression black list added: " + domain + " , " + entry + "  -  " + originalBlockListEntry);
755                                 } while (domains.contains("|"));
756                             } else {  // Third-party domain entries.
757                                 // Parse the entry
758                                 String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
759                                 String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
760                                 String domains = filters.substring(filters.indexOf("domain=") + 7);
761
762                                 // Strip any trailing "*" from the entry.
763                                 if (entry.endsWith("*")) {
764                                     entry = entry.substring(0, entry.length() - 1);
765                                 }
766
767                                 // Track if any third-party white list filters are applied.
768                                 boolean whiteListDomain = false;
769
770                                 // Process each domain.
771                                 do {
772                                     // Create a string to keep track of the current domain.
773                                     String domain;
774
775                                     if (domains.contains("|")) {  // There is more than one domain in the list.
776                                         // Get the first domain from the list.
777                                         domain = domains.substring(0, domains.indexOf("|"));
778
779                                         // Remove the first domain from the list.
780                                         domains = domains.substring(domains.indexOf("|") + 1);
781                                     } else {  // The is only one domain in the list.
782                                         domain = domains;
783                                     }
784
785                                     // Differentiate between block list domains and white list domains.
786                                     if (domain.startsWith("~")) {  // White list third-party domain entry.
787                                         // Strip the initial `~`.
788                                         domain = domain.substring(1);
789
790                                         // Set the white list domain flag.
791                                         whiteListDomain = true;
792
793                                         if (entry.contains("*")) {  // Process a third-party domain white list double entry.
794                                             // Get the index of the wildcard.
795                                             int wildcardIndex = entry.indexOf("*");
796
797                                             // Split the entry into components.
798                                             String firstEntry = entry.substring(0, wildcardIndex);
799                                             String secondEntry = entry.substring(wildcardIndex + 1);
800
801                                             // Create an entry string array.
802                                             String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
803
804                                             // Add the entry to the white list.
805                                             thirdPartyDomainWhiteList.add(domainDoubleEntry);
806
807                                             //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + firstEntry + " , " + secondEntry + "  -  " +
808                                             //        originalBlockListEntry);
809                                         } else {  // Process a third-party domain white list single entry.
810                                             // Create an entry string array.
811                                             String[] domainEntry = {domain, entry, originalBlockListEntry};
812
813                                             // Add the entry to the white list.
814                                             thirdPartyDomainWhiteList.add(domainEntry);
815
816                                             //Log.i("BlockLists", headers.get(1)[0] + " third-party domain white list added: " + domain + " , " + entry + "  -  " + originalBlockListEntry);
817                                         }
818                                     } else {  // Third-party domain black list entries.
819                                         if (entry.contains("*")) {  // Process a third-party domain black list double entry.
820                                             // Get the index of the wildcard.
821                                             int wildcardIndex = entry.indexOf("*");
822
823                                             // Split the entry into components.
824                                             String firstEntry = entry.substring(0, wildcardIndex);
825                                             String secondEntry = entry.substring(wildcardIndex + 1);
826
827                                             // Create an entry string array.
828                                             String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
829
830                                             // Add the entry to the black list
831                                             thirdPartyDomainBlackList.add(domainDoubleEntry);
832
833                                             //Log.i("BlockLists", headers.get(1)[0] + " third-party domain black list added: " + domain + " , " + firstEntry + " , " + secondEntry + "  -  " +
834                                             //        originalBlockListEntry);
835                                         } else {  // Process a third-party domain black list single entry.
836                                             // Create an entry string array.
837                                             String[] domainEntry = {domain, entry, originalBlockListEntry};
838
839                                             // Add the entry to the black list.
840                                             thirdPartyDomainBlackList.add(domainEntry);
841
842                                             //Log.i("BlockLists", headers.get(1)[0] + " third-party domain block list added: " + domain + " , " + entry + "  -  " + originalBlockListEntry);
843                                         }
844                                     }
845                                 } while (domains.contains("|"));
846
847                                 // Add a third-party black list entry if a white list domain was processed.
848                                 if (whiteListDomain) {
849                                     if (entry.contains("*")) {  // Process a third-party black list double entry.
850                                         // Get the index of the wildcard.
851                                         int wildcardIndex = entry.indexOf("*");
852
853                                         // Split the entry into components.
854                                         String firstEntry = entry.substring(0, wildcardIndex);
855                                         String secondEntry = entry.substring(wildcardIndex + 1);
856
857                                         // Create an entry string array.
858                                         String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
859
860                                         // Add the entry to the black list.
861                                         thirdPartyBlackList.add(doubleEntry);
862
863                                         //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
864                                     } else {  // Process a third-party black list single entry.
865                                         // Create an entry string array.
866                                         String[] singleEntry = {entry, originalBlockListEntry};
867
868                                         // Add an entry to the black list.
869                                         thirdPartyBlackList.add(singleEntry);
870
871                                         //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + entry + "  -  " + originalBlockListEntry);
872                                     }
873                                 }
874                             }
875                         } else if (blockListEntry.startsWith("|")) {  // Third-party initial black list entries.
876                             // Strip the initial `|`.
877                             blockListEntry = blockListEntry.substring(1);
878
879                             // Get the entry.
880                             String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
881
882                             if (entry.contains("*")) {  // Process a third-party initial black list double entry.
883                                 // Get the index of the wildcard.
884                                 int wildcardIndex = entry.indexOf("*");
885
886                                 // Split the entry into components.
887                                 String firstEntry = entry.substring(0, wildcardIndex);
888                                 String secondEntry = entry.substring(wildcardIndex + 1);
889
890                                 // Create an entry string array.
891                                 String[] thirdPartyDoubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
892
893                                 // Add the entry to the black list.
894                                 thirdPartyInitialBlackList.add(thirdPartyDoubleEntry);
895
896                                 //Log.i("BlockLists", headers.get(1)[0] + " third-party initial black list added: " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
897                             } else {  // Process a third-party initial black list single entry.
898                                 // Create an entry string array.
899                                 String[] singleEntry = {entry, originalBlockListEntry};
900
901                                 // Add the entry to the black list.
902                                 thirdPartyInitialBlackList.add(singleEntry);
903
904                                 //Log.i("BlockLists", headers.get(1)[0] + " third-party initial black list added: " + entry + "  -  " + originalBlockListEntry);
905                             }
906                         } else if (blockListEntry.contains("\\")) {  // Process a regular expression black list entry.
907                             // Prepare a string to hold the entry.
908                             String entry;
909
910                             // Get the entry.
911                             if (blockListEntry.contains("$/$")) {  // The first `$` is part of the regular expression.
912                                 entry = blockListEntry.substring(0, blockListEntry.indexOf("$/$") + 2);
913                             } else {  // The only `$` indicates the filter options.
914                                 entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
915                             }
916
917                             // Create an entry string array.
918                             String[] singleEntry = {entry, originalBlockListEntry};
919
920                             // Add the entry to the black list.
921                             thirdPartyRegularExpressionBlackList.add(singleEntry);
922
923                             //Log.i("BlockLists", headers.get(1)[0] + " third-party regular expression black list added: " + entry + "  -  " + originalBlockListEntry);
924                         } else if (blockListEntry.contains("*")) {  // Third-party and regular expression black list entries.
925                             // Get the entry.
926                             String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
927
928                             if (entry.endsWith("*")) {  // Process a third-party black list single entry.
929                                 // Strip the final `*`.
930                                 entry = entry.substring(0, entry.length() - 1);
931
932                                 // Create an entry string array.
933                                 String[] singleEntry = {entry, originalBlockListEntry};
934
935                                 // Add the entry to the black list.
936                                 thirdPartyBlackList.add(singleEntry);
937
938                                 //Log.i("BlockLists", headers.get(1)[0] + " third party black list added: " + entry + "  -  " + originalBlockListEntry);
939                             } else {  // There are two or more entries.
940                                 // Get the index of the wildcard.
941                                 int wildcardIndex = entry.indexOf("*");
942
943                                 // Split the entry into components.
944                                 String firstEntry = entry.substring(0, wildcardIndex);
945                                 String secondEntry = entry.substring(wildcardIndex + 1);
946
947                                 if (secondEntry.contains("*")) {  // There are three or more entries.
948                                     // Get the index of the wildcard.
949                                     int secondWildcardIndex = secondEntry.indexOf("*");
950
951                                     // Split the entry into components.
952                                     String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
953                                     String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
954
955                                     if (thirdEntry.contains("*")) {  // Process a third-party black list quadruple entry.
956                                         // Get the index of the wildcard.
957                                         int thirdWildcardIndex = thirdEntry.indexOf("*");
958
959                                         // Split the entry into components.
960                                         String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
961                                         String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
962
963                                         // Create an entry string array.
964                                         String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
965
966                                         // Add the entry to the black list.
967                                         thirdPartyBlackList.add(quadrupleEntry);
968
969                                         //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
970                                         //        fourthEntry + "  -  " + originalBlockListEntry);
971                                     } else {  // Process a third-party black list triple entry.
972                                         // Create an entry string array.
973                                         String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
974
975                                         // Add the entry to the black list.
976                                         thirdPartyBlackList.add(tripleEntry);
977
978                                         //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + "  -  " +
979                                         //        originalBlockListEntry);
980                                     }
981                                 } else {  // Process a third-party black list double entry.
982                                     // Create an entry string array.
983                                     String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
984
985                                     // Add the entry to the black list.
986                                     thirdPartyBlackList.add(doubleEntry);
987
988                                     //Log.i("BlockLists", headers.get(1)[0] + " third-party black list added: " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
989                                 }
990                             }
991                         } else {  // Process a third party black list single entry.
992                             // Get the entry.
993                             String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
994
995                             // Create an entry string array.
996                             String[] singleEntry = {entry, originalBlockListEntry};
997
998                             // Add the entry to the black list.
999                             thirdPartyBlackList.add(singleEntry);
1000
1001                             //Log.i("BlockLists", headers.get(1)[0] + " third party black list added: " + entry + "  -  " + originalBlockListEntry);
1002                         }
1003                     } else if (blockListEntry.substring(blockListEntry.indexOf("$")).contains("domain=")) {  // Domain entries.
1004                         if (blockListEntry.contains("~")) {  // Domain white list entries.
1005                             // Separate the filters.
1006                             String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1007                             String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
1008                             String domains = filters.substring(filters.indexOf("domain=") + 7);
1009
1010                             // Strip any final `*` from the entry.  They are redundant.
1011                             if (entry.endsWith("*")) {
1012                                 entry = entry.substring(0, entry.length() - 1);
1013                             }
1014
1015                             // Process each domain.
1016                             do {
1017                                 // Create a string to keep track of the current domain.
1018                                 String domain;
1019
1020                                 if (domains.contains("|")) {  // There is more than one domain in the list.
1021                                     // Get the first domain from the list.
1022                                     domain = domains.substring(0, domains.indexOf("|"));
1023
1024                                     // Remove the first domain from the list.
1025                                     domains = domains.substring(domains.indexOf("|") + 1);
1026                                 } else {  // There is only one domain in the list.
1027                                     domain = domains;
1028                                 }
1029
1030                                 // Strip the initial `~`.
1031                                 domain = domain.substring(1);
1032
1033                                 if (entry.contains("*")) {  // There are two or more entries.
1034                                     // Get the index of the wildcard.
1035                                     int wildcardIndex = entry.indexOf("*");
1036
1037                                     // Split the entry into components.
1038                                     String firstEntry = entry.substring(0, wildcardIndex);
1039                                     String secondEntry = entry.substring(wildcardIndex + 1);
1040
1041                                     if (secondEntry.contains("*")) {  // Process a domain white list triple entry.
1042                                         // Get the index of the wildcard.
1043                                         int secondWildcardIndex = secondEntry.indexOf("*");
1044
1045                                         // Split the entry into components.
1046                                         String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1047                                         String thirdEntry = secondEntry.substring((secondWildcardIndex + 1));
1048
1049                                         // Create an entry string array.
1050                                         String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1051
1052                                         // Add the entry to the white list.
1053                                         domainWhiteList.add(domainTripleEntry);
1054
1055                                         //Log.i("BlockLists", headers.get(1)[0] + " domain white list added: " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry +
1056                                         //        "  -  " + originalBlockListEntry);
1057                                     } else {  // Process a domain white list double entry.
1058                                         // Create an entry string array.
1059                                         String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
1060
1061                                         // Add the entry to the white list.
1062                                         domainWhiteList.add(domainDoubleEntry);
1063
1064                                         //Log.i("BlockLists", headers.get(1)[0] + " domain white list added: " + domain + " , " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
1065                                     }
1066                                 } else {  // Process a domain white list single entry.
1067                                     // Create an entry string array.
1068                                     String[] domainEntry = {domain, entry, originalBlockListEntry};
1069
1070                                     // Add the entry to the white list.
1071                                     domainWhiteList.add(domainEntry);
1072
1073                                     //Log.i("BlockLists", headers.get(1)[0] + " domain white list added: " + domain + " , " + entry + "  -  " + originalBlockListEntry);
1074                                 }
1075                             } while (domains.contains("|"));
1076                         } else {  // Domain black list entries.
1077                             // Separate the filters.
1078                             String entry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1079                             String filters = blockListEntry.substring(blockListEntry.indexOf("$") + 1);
1080                             String domains = filters.substring(filters.indexOf("domain=") + 7);
1081
1082                             // Only process the item if the entry is not null.  For example, some lines begin with `$websocket`, which create a null entry.
1083                             if (!entry.equals("")) {
1084                                 // Process each domain.
1085                                 do {
1086                                     // Create a string to keep track of the current domain.
1087                                     String domain;
1088
1089                                     if (domains.contains("|")) {  // There is more than one domain in the list.
1090                                         // Get the first domain from the list.
1091                                         domain = domains.substring(0, domains.indexOf("|"));
1092
1093                                         // Remove the first domain from the list.
1094                                         domains = domains.substring(domains.indexOf("|") + 1);
1095                                     } else {  // There is only one domain in the list.
1096                                         domain = domains;
1097                                     }
1098
1099                                     if (entry.startsWith("|")) {  // Domain initial black list entries.
1100                                         // Remove the initial `|`;
1101                                         String entryBase = entry.substring(1);
1102
1103                                         //noinspection StatementWithEmptyBody
1104                                         if (entryBase.equals("http://") || entryBase.equals("https://")) {
1105                                             // Do nothing.  These entries will entirely block the website.
1106                                             // Often the original entry blocks `$script` but Privacy Browser does not currently differentiate between scripts and other entries.
1107
1108                                             //Log.i("BlockLists", headers.get(1)[0] + " not added: " + originalBlockListEntry);
1109                                         } else {  // Process a domain initial black list entry
1110                                             // Create an entry string array.
1111                                             String[] domainEntry = {domain, entryBase, originalBlockListEntry};
1112
1113                                             // Add the entry to the black list.
1114                                             domainInitialBlackList.add(domainEntry);
1115
1116                                             //Log.i("BlockLists", headers.get(1)[0] + " domain initial black list added: " + domain + " , " + entryBase + "  -  " + originalBlockListEntry);
1117                                         }
1118                                     } else if (entry.endsWith("|")) {  // Domain final black list entries.
1119                                         // Remove the final `|`.
1120                                         String entryBase = entry.substring(0, entry.length() - 1);
1121
1122                                         if (entryBase.contains("*")) {  // Process a domain final black list double entry.
1123                                             // Get the index of the wildcard.
1124                                             int wildcardIndex = entry.indexOf("*");
1125
1126                                             // Split the entry into components.
1127                                             String firstEntry = entryBase.substring(0, wildcardIndex);
1128                                             String secondEntry = entryBase.substring(wildcardIndex + 1);
1129
1130                                             // Create an entry string array.
1131                                             String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
1132
1133                                             // Add the entry to the black list.
1134                                             domainFinalBlackList.add(domainDoubleEntry);
1135
1136                                             //Log.i("BlockLists", headers.get(1)[0] + " domain final black list added: " + domain + " , " + firstEntry + " , " + secondEntry + "  -  " +
1137                                             //        originalBlockListEntry);
1138                                         } else {  // Process a domain final black list single entry.
1139                                             // Create an entry string array.
1140                                             String[] domainEntry = {domain, entryBase, originalBlockListEntry};
1141
1142                                             // Add the entry to the black list.
1143                                             domainFinalBlackList.add(domainEntry);
1144
1145                                             //Log.i("BlockLists", headers.get(1)[0] + " domain final black list added: " + domain + " , " + entryBase + "  -  " + originalBlockListEntry);
1146                                         }
1147                                     } else if (entry.contains("\\")) {  // Process a domain regular expression black list entry.
1148                                         // Create an entry string array.
1149                                         String[] domainEntry = {domain, entry, originalBlockListEntry};
1150
1151                                         // Add the entry to the black list.
1152                                         domainRegularExpressionBlackList.add(domainEntry);
1153
1154                                         //Log.i("BlockLists", headers.get(1)[0] + " domain regular expression black list added: " + domain + " , " + entry + "  -  " + originalBlockListEntry);
1155                                     } else if (entry.contains("*")) {  // There are two or more entries.
1156                                         // Get the index of the wildcard.
1157                                         int wildcardIndex = entry.indexOf("*");
1158
1159                                         // Split the entry into components.
1160                                         String firstEntry = entry.substring(0, wildcardIndex);
1161                                         String secondEntry = entry.substring(wildcardIndex + 1);
1162
1163                                         if (secondEntry.contains("*")) {  // Process a domain black list triple entry.
1164                                             // Get the index of the wildcard.
1165                                             int secondWildcardIndex = secondEntry.indexOf("*");
1166
1167                                             // Split the entry into components.
1168                                             String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1169                                             String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1170
1171                                             // Create an entry string array.
1172                                             String[] domainTripleEntry = {domain, firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1173
1174                                             // Add the entry to the black list.
1175                                             domainBlackList.add(domainTripleEntry);
1176
1177                                             //Log.i("BlockLists", headers.get(1)[0] + " domain black list added: " + domain + " , " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry +
1178                                             //        "  -  " + originalBlockListEntry);
1179                                         } else {  // Process a domain black list double entry.
1180                                             // Create an entry string array.
1181                                             String[] domainDoubleEntry = {domain, firstEntry, secondEntry, originalBlockListEntry};
1182
1183                                             // Add the entry to the black list.
1184                                             domainBlackList.add(domainDoubleEntry);
1185
1186                                             //Log.i("BlockLists", headers.get(1)[0] + " domain black list added: " + domain + " , " + firstEntry + " , " + secondEntry + "  -  " +
1187                                             //        originalBlockListEntry);
1188                                         }
1189                                     } else {  // Process a domain black list single entry.
1190                                         // Create an entry string array.
1191                                         String[] domainEntry = {domain, entry, originalBlockListEntry};
1192
1193                                         // Add the entry to the black list.
1194                                         domainBlackList.add(domainEntry);
1195
1196                                         //Log.i("BlockLists", headers.get(1)[0] + " domain black list added: " + domain + " , " + entry + "  -  " + originalBlockListEntry);
1197                                     }
1198                                 } while (domains.contains("|"));
1199                             }
1200                         }
1201                     } else if (blockListEntry.contains("~")) {  // White list entries.  Privacy Browser does not differentiate against these filter options, so they are just generally white listed.
1202                         // Remove the filter options.
1203                         blockListEntry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1204
1205                         // Strip any trailing `*`.
1206                         if (blockListEntry.endsWith("*")) {
1207                             blockListEntry = blockListEntry.substring(0, blockListEntry.length() - 1);
1208                         }
1209
1210                         if (blockListEntry.contains("*")) {  // Process a white list double entry.
1211                             // Get the index of the wildcard.
1212                             int wildcardIndex = blockListEntry.indexOf("*");
1213
1214                             // Split the entry into components.
1215                             String firstEntry = blockListEntry.substring(0, wildcardIndex);
1216                             String secondEntry = blockListEntry.substring(wildcardIndex + 1);
1217
1218                             // Create an entry string array.
1219                             String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1220
1221                             // Add the entry to the white list.
1222                             mainWhiteList.add(doubleEntry);
1223
1224                             //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
1225                         } else {  // Process a white list single entry.
1226                             // Create an entry string array.
1227                             String[] singleEntry = {blockListEntry, originalBlockListEntry};
1228
1229                             // Add the entry to the white list.
1230                             mainWhiteList.add(singleEntry);
1231
1232                             //Log.i("BlockLists", headers.get(1)[0] + " main white list added: " + blockListEntry + "  -  + " + originalBlockListEntry);
1233                         }
1234                     } else if (blockListEntry.contains("\\")) {  // Process a regular expression black list entry.
1235                         // Remove the filter options.
1236                         blockListEntry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1237
1238                         // Create an entry string array.
1239                         String[] singleEntry = {blockListEntry, originalBlockListEntry};
1240
1241                         // Add the entry to the black list.
1242                         regularExpressionBlackList.add(singleEntry);
1243
1244                         //Log.i("BlockLists", headers.get(1)[0] + " regular expression black list added: " + blockListEntry + "  -  " + originalBlockListEntry);
1245                     } else {  // Black list entries.
1246                         // Remove the filter options.
1247                         if (!blockListEntry.contains("$file")) {  // EasyPrivacy contains an entry with `$file` that does not have filter options.
1248                             blockListEntry = blockListEntry.substring(0, blockListEntry.indexOf("$"));
1249                         }
1250
1251                         // Strip any trailing `*`.  These are redundant.
1252                         if (blockListEntry.endsWith("*")) {
1253                             blockListEntry = blockListEntry.substring(0, blockListEntry.length() - 1);
1254                         }
1255
1256                         if (blockListEntry.startsWith("|")) {  // Initial black list entries.
1257                             // Strip the initial `|`.
1258                             String entry = blockListEntry.substring(1);
1259
1260                             if (entry.contains("*")) {  // Process an initial black list double entry.
1261                                 // Get the index of the wildcard.
1262                                 int wildcardIndex = entry.indexOf("*");
1263
1264                                 // Split the entry into components.
1265                                 String firstEntry = entry.substring(0, wildcardIndex);
1266                                 String secondEntry = entry.substring(wildcardIndex + 1);
1267
1268                                 // Create an entry string array.
1269                                 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1270
1271                                 // Add the entry to the black list.
1272                                 initialBlackList.add(doubleEntry);
1273
1274                                 //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
1275                             } else {  // Process an initial black list single entry.
1276                                 // Create an entry string array.
1277                                 String[] singleEntry = {entry, originalBlockListEntry};
1278
1279                                 // Add the entry to the black list.
1280                                 initialBlackList.add(singleEntry);
1281
1282                                 //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + entry + "  -  " + originalBlockListEntry);
1283                             }
1284                         } else if (blockListEntry.endsWith("|")) {  // Final black list entries.
1285                             // Ignore entries with `object` filters.  They can block entire websites and don't have any meaning in the context of Privacy Browser.
1286                             if (!originalBlockListEntry.contains("$object")) {
1287                                 // Strip the final `|`.
1288                                 String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
1289
1290                                 if (entry.contains("*")) {  // There are two or more entries.
1291                                     // Get the index of the wildcard.
1292                                     int wildcardIndex = entry.indexOf("*");
1293
1294                                     // Split the entry into components.
1295                                     String firstEntry = entry.substring(0, wildcardIndex);
1296                                     String secondEntry = entry.substring(wildcardIndex + 1);
1297
1298                                     if (secondEntry.contains("*")) {  // Process a final black list triple entry.
1299                                         // Get the index of the wildcard.
1300                                         int secondWildcardIndex = secondEntry.indexOf("*");
1301
1302                                         // Split the entry into components.
1303                                         String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1304                                         String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1305
1306                                         // Create an entry string array.
1307                                         String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1308
1309                                         // Add the entry to the black list.
1310                                         finalBlackList.add(tripleEntry);
1311
1312                                         //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + "  -  " +
1313                                         //        originalBlockListEntry);
1314                                     } else {  // Process a final black list double entry.
1315                                         // Create an entry string array.
1316                                         String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1317
1318                                         // Add the entry to the black list.
1319                                         finalBlackList.add(doubleEntry);
1320
1321                                         //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
1322                                     }
1323                                 } else {  // Process a final black list single entry.
1324                                     // Create an entry sting array.
1325                                     String[] singleEntry = {entry, originalBlockListEntry};
1326
1327                                     // Add the entry to the black list.
1328                                     finalBlackList.add(singleEntry);
1329
1330                                     //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + entry + "  -  " + originalBlockListEntry);
1331                                 }
1332                             }
1333                         } else if (blockListEntry.contains("*")) {  // There are two or more entries.
1334                             // Get the index of the wildcard.
1335                             int wildcardIndex = blockListEntry.indexOf("*");
1336
1337                             // Split the entry into components.
1338                             String firstEntry = blockListEntry.substring(0, wildcardIndex);
1339                             String secondEntry = blockListEntry.substring(wildcardIndex + 1);
1340
1341                             if (secondEntry.contains("*")) {  // Process a main black list triple entry.
1342                                 // Get the index of the wildcard.
1343                                 int secondWildcardIndex = secondEntry.indexOf("*");
1344
1345                                 // Split the entry into components.
1346                                 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1347                                 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1348
1349                                 // Create an entry string array.
1350                                 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1351
1352                                 // Add the entry to the black list.
1353                                 mainBlackList.add(tripleEntry);
1354
1355                                 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + "  -  " + originalBlockListEntry);
1356                             } else {  // Process a main black list double entry.
1357                                 // Create an entry string array.
1358                                 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1359
1360                                 // Add the entry to the black list.
1361                                 mainBlackList.add(doubleEntry);
1362
1363                                 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
1364                             }
1365                         } else {  // Process a main black list single entry.
1366                             // Create an entry string array.
1367                             String[] singleEntry = {blockListEntry, originalBlockListEntry};
1368
1369                             // Add the entry to the black list.
1370                             mainBlackList.add(singleEntry);
1371
1372                             //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + blockListEntry + "  -  " + originalBlockListEntry);
1373                         }
1374                     }
1375                 } else {  // Main black list entries
1376                     // Strip out any initial `||`.  These will be treated like any other entry.
1377                     if (blockListEntry.startsWith("||")) {
1378                         blockListEntry = blockListEntry.substring(2);
1379                     }
1380
1381                     // Strip out any initial `*`.
1382                     if (blockListEntry.startsWith("*")) {
1383                         blockListEntry = blockListEntry.substring(1);
1384                     }
1385
1386                     // Strip out any trailing `*`.
1387                     if (blockListEntry.endsWith("*")) {
1388                         blockListEntry = blockListEntry.substring(0, blockListEntry.length() - 1);
1389                     }
1390
1391                     if (blockListEntry.startsWith("|")) {  // Initial black list entries.
1392                         // Strip the initial `|`.
1393                         String entry = blockListEntry.substring(1);
1394
1395                         if (entry.contains("*")) {  // Process an initial black list double entry.
1396                             // Get the index of the wildcard.
1397                             int wildcardIndex = entry.indexOf("*");
1398
1399                             // Split the entry into components.
1400                             String firstEntry = entry.substring(0, wildcardIndex);
1401                             String secondEntry = entry.substring(wildcardIndex + 1);
1402
1403                             // Create an entry string array.
1404                             String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1405
1406                             // Add the entry to the black list.
1407                             initialBlackList.add(doubleEntry);
1408
1409                             //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
1410                         } else {  // Process an initial black list single entry.
1411                             // Create an entry string array.
1412                             String[] singleEntry = {entry, originalBlockListEntry};
1413
1414                             // Add the entry to the black list.
1415                             initialBlackList.add(singleEntry);
1416
1417                             //Log.i("BlockLists", headers.get(1)[0] + " initial black list added: " + entry + "  -  " + originalBlockListEntry);
1418                         }
1419                     } else if (blockListEntry.endsWith("|")) {  // Final black list entries.
1420                         // Strip the final `|`.
1421                         String entry = blockListEntry.substring(0, blockListEntry.length() - 1);
1422
1423                         if (entry.contains("*")) {  // There are two or more entries.
1424                             // Get the index of the wildcard.
1425                             int wildcardIndex = entry.indexOf("*");
1426
1427                             // Split the entry into components.
1428                             String firstEntry = entry.substring(0, wildcardIndex);
1429                             String secondEntry = entry.substring(wildcardIndex + 1);
1430
1431                             if (secondEntry.contains("*")) {  // Process a final black list triple entry.
1432                                 // Get the index of the wildcard.
1433                                 int secondWildcardIndex = secondEntry.indexOf("*");
1434
1435                                 // Split the entry into components.
1436                                 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1437                                 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1438
1439                                 // Create an entry string array.
1440                                 String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1441
1442                                 // Add the entry to the black list.
1443                                 finalBlackList.add(tripleEntry);
1444
1445                                 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + "  -  " +
1446                                 //        originalBlockListEntry);
1447                             } else {  // Process a final black list double entry.
1448                                 // Create an entry string array.
1449                                 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1450
1451                                 // Add the entry to the black list.
1452                                 finalBlackList.add(doubleEntry);
1453
1454                                 //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
1455                             }
1456                         } else {  // Process a final black list single entry.
1457                             // Create an entry string array.
1458                             String[] singleEntry = {entry, originalBlockListEntry};
1459
1460                             // Add the entry to the black list.
1461                             finalBlackList.add(singleEntry);
1462
1463                             //Log.i("BlockLists", headers.get(1)[0] + " final black list added: " + entry + "  -  " + originalBlockListEntry);
1464                         }
1465                     } else {  // Main black list entries.
1466                         if (blockListEntry.contains("*")) {  // There are two or more entries.
1467                             // Get the index of the wildcard.
1468                             int wildcardIndex = blockListEntry.indexOf("*");
1469
1470                             // Split the entry into components.
1471                             String firstEntry = blockListEntry.substring(0, wildcardIndex);
1472                             String secondEntry = blockListEntry.substring(wildcardIndex + 1);
1473
1474                             if (secondEntry.contains("*")) {  // There are three or more entries.
1475                                 // Get the index of the wildcard.
1476                                 int secondWildcardIndex = secondEntry.indexOf("*");
1477
1478                                 // Split the entry into components.
1479                                 String realSecondEntry = secondEntry.substring(0, secondWildcardIndex);
1480                                 String thirdEntry = secondEntry.substring(secondWildcardIndex + 1);
1481
1482                                 if (thirdEntry.contains("*")) {  // There are four or more entries.
1483                                     // Get the index of the wildcard.
1484                                     int thirdWildcardIndex = thirdEntry.indexOf("*");
1485
1486                                     // Split the entry into components.
1487                                     String realThirdEntry = thirdEntry.substring(0, thirdWildcardIndex);
1488                                     String fourthEntry = thirdEntry.substring(thirdWildcardIndex + 1);
1489
1490                                     if (fourthEntry.contains("*")) {  // Process a main black list quintuple entry.
1491                                         // Get the index of the wildcard.
1492                                         int fourthWildcardIndex = fourthEntry.indexOf("*");
1493
1494                                         // Split the entry into components.
1495                                         String realFourthEntry = fourthEntry.substring(0, fourthWildcardIndex);
1496                                         String fifthEntry = fourthEntry.substring(fourthWildcardIndex + 1);
1497
1498                                         // Create an entry string array.
1499                                         String[] quintupleEntry = {firstEntry, realSecondEntry, realThirdEntry, realFourthEntry, fifthEntry, originalBlockListEntry};
1500
1501                                         // Add the entry to the black list.
1502                                         mainBlackList.add(quintupleEntry);
1503
1504                                         //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
1505                                         //        realFourthEntry + " , " + fifthEntry + "  -  " + originalBlockListEntry);
1506                                     } else {  // Process a main black list quadruple entry.
1507                                         // Create an entry string array.
1508                                         String[] quadrupleEntry = {firstEntry, realSecondEntry, realThirdEntry, fourthEntry, originalBlockListEntry};
1509
1510                                         // Add the entry to the black list.
1511                                         mainBlackList.add(quadrupleEntry);
1512
1513                                         //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + realThirdEntry + " , " +
1514                                         //        fourthEntry + "  -  " + originalBlockListEntry);
1515                                     }
1516                                 } else {  // Process a main black list triple entry.
1517                                     // Create an entry string array.
1518                                     String[] tripleEntry = {firstEntry, realSecondEntry, thirdEntry, originalBlockListEntry};
1519
1520                                     // Add the entry to the black list.
1521                                     mainBlackList.add(tripleEntry);
1522
1523                                     //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + realSecondEntry + " , " + thirdEntry + "  -  " + originalBlockListEntry);
1524                                 }
1525                             } else {  // Process a main black list double entry.
1526                                 // Create an entry string array.
1527                                 String[] doubleEntry = {firstEntry, secondEntry, originalBlockListEntry};
1528
1529                                 // Add the entry to the black list.
1530                                 mainBlackList.add(doubleEntry);
1531
1532                                 //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + firstEntry + " , " + secondEntry + "  -  " + originalBlockListEntry);
1533                             }
1534                         } else {  // Process a main black list single entry.
1535                             // Create an entry string array.
1536                             String[] singleEntry = {blockListEntry, originalBlockListEntry};
1537
1538                             // Add the entry to the black list.
1539                             mainBlackList.add(singleEntry);
1540
1541                             //Log.i("BlockLists", headers.get(1)[0] + " main black list added: " + blockListEntry + "  -  " + originalBlockListEntry);
1542                         }
1543                     }
1544                 }
1545             }
1546             // Close `bufferedReader`.
1547             bufferedReader.close();
1548         } catch (IOException e) {
1549             // The asset exists, so the `IOException` will never be thrown.
1550         }
1551
1552         // Initialize the combined list.
1553         ArrayList<List<String[]>> combinedLists = new ArrayList<>();
1554
1555         // Add the headers (0).
1556         combinedLists.add(headers);  // 0.
1557
1558         // Add the white lists (1-8).
1559         combinedLists.add(mainWhiteList);  // 1.
1560         combinedLists.add(finalWhiteList);  // 2.
1561         combinedLists.add(domainWhiteList);  // 3.
1562         combinedLists.add(domainInitialWhiteList);  // 4.
1563         combinedLists.add(domainFinalWhiteList); // 5.
1564         combinedLists.add(thirdPartyWhiteList);  // 6.
1565         combinedLists.add(thirdPartyDomainWhiteList);  // 7.
1566         combinedLists.add(thirdPartyDomainInitialWhiteList);  // 8.
1567
1568         // Add the black lists (9-22).
1569         combinedLists.add(mainBlackList);  // 9.
1570         combinedLists.add(initialBlackList);  // 10.
1571         combinedLists.add(finalBlackList);  // 11.
1572         combinedLists.add(domainBlackList);  //  12.
1573         combinedLists.add(domainInitialBlackList);  // 13.
1574         combinedLists.add(domainFinalBlackList);  // 14.
1575         combinedLists.add(domainRegularExpressionBlackList);  // 15.
1576         combinedLists.add(thirdPartyBlackList);  // 16.
1577         combinedLists.add(thirdPartyInitialBlackList);  // 17.
1578         combinedLists.add(thirdPartyDomainBlackList);  // 18.
1579         combinedLists.add(thirdPartyDomainInitialBlackList);  // 19.
1580         combinedLists.add(thirdPartyRegularExpressionBlackList);  // 20.
1581         combinedLists.add(thirdPartyDomainRegularExpressionBlackList);  // 21.
1582         combinedLists.add(regularExpressionBlackList);  // 22.
1583
1584         return combinedLists;
1585     }
1586
1587     public boolean isBlocked(String currentDomain, String resourceUrl, boolean isThirdPartyRequest, ArrayList<List<String[]>> blockList) {
1588         // Get the blocklist name.
1589         String BLOCK_LIST_NAME_STRING = blockList.get(0).get(1)[0];
1590
1591         // Assert that currentDomain != null only if this is a third party request.  Apparently, lint can't tell that this isn't redundant.
1592         //noinspection RedundantIfStatement
1593         if (isThirdPartyRequest) {
1594             assert currentDomain != null;
1595         }
1596
1597         // Process the white lists.
1598         // Main white list.
1599         for (String[] whiteListEntry : blockList.get(MainWebViewActivity.MAIN_WHITELIST)) {
1600             switch (whiteListEntry.length) {
1601                 case 2:  // There is one entry.
1602                     if (resourceUrl.contains(whiteListEntry[0])) {
1603                         // Store the entry in the resource request log.
1604                         MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1605                                 String.valueOf(MainWebViewActivity.MAIN_WHITELIST), whiteListEntry[0], whiteListEntry[1]};
1606
1607                         // Not blocked.
1608                         return false;
1609                     }
1610                     break;
1611
1612                 case 3:  // There are two entries.
1613                     if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1614                         // Store the entry in the resource request log.
1615                         MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1616                                 String.valueOf(MainWebViewActivity.MAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1],
1617                                 whiteListEntry[2]};
1618
1619                         // Not blocked.
1620                         return false;
1621                     }
1622                     break;
1623
1624                 case 4:  // There are three entries.
1625                     if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1626                         // Store the entry in the resource request log.
1627                         MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1628                                 String.valueOf(MainWebViewActivity.MAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1629
1630                         // Not blocked.
1631                         return false;
1632                     }
1633                     break;
1634             }
1635         }
1636
1637         // Final white list.
1638         for (String[] whiteListEntry : blockList.get(MainWebViewActivity.FINAL_WHITELIST)) {
1639             if (whiteListEntry.length == 2) {  // There is one entry.
1640                 if (resourceUrl.contains(whiteListEntry[0])) {
1641                     // Store the entry in the resource request log.
1642                     MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1643                             String.valueOf(MainWebViewActivity.FINAL_WHITELIST), whiteListEntry[0], whiteListEntry[1]};
1644
1645                     // Not blocked.
1646                     return false;
1647                 }
1648             } else {  // There are two entries.
1649                 if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1650                     // Store the entry in the resource request log.
1651                     MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1652                             String.valueOf(MainWebViewActivity.FINAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1653
1654                     // Not blocked.
1655                     return false;
1656                 }
1657             }
1658         }
1659
1660         // Only check the domain lists if the current domain is not null (like `about:blank`).
1661         if (currentDomain != null) {
1662             // Domain white list.
1663             for (String[] whiteListEntry : blockList.get(MainWebViewActivity.DOMAIN_WHITELIST)) {
1664                 switch (whiteListEntry.length) {
1665                     case 3:  // There is one entry.
1666                         if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1667                             // Store the entry in the resource request log.
1668                             MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1669                                     String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1670
1671                             // Not blocked.
1672                             return false;
1673                         }
1674                         break;
1675
1676                     case 4:  // There are two entries.
1677                         if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1678                             // Store the entry in the resource request log.
1679                             MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1680                                     String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1681
1682                             // Not blocked.
1683                             return false;
1684                         }
1685                         break;
1686
1687                     case 5:  // There are three entries.
1688                         if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3])) {
1689                             // Store the entry in the resource request log.
1690                             MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1691                                     String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3],
1692                                     whiteListEntry[4]};
1693
1694                             // Not blocked.
1695                             return false;
1696                         }
1697                         break;
1698
1699                     case 6:  // There are four entries.
1700                         if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3]) &&
1701                                 resourceUrl.contains(whiteListEntry[4])) {
1702                             // Store the entry in the resource request log.
1703                             MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1704                                     String.valueOf(MainWebViewActivity.DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3] + "\n" +
1705                                     whiteListEntry[4], whiteListEntry[5]};
1706
1707                             // Not blocked.
1708                             return false;
1709                         }
1710                         break;
1711                 }
1712             }
1713
1714             // Domain initial white list.
1715             for (String[] whiteListEntry : blockList.get(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST)) {
1716                 switch (whiteListEntry.length) {
1717                     case 3:  // There is one entry.
1718                         if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1])) {
1719                             // Store the entry in the resource request log.
1720                             MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1721                                     String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1722
1723                             // Not blocked.
1724                             return false;
1725                         }
1726                         break;
1727
1728                     case 4:  // There are two entries.
1729                         if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1730                             // Store the entry in the resource request log.
1731                             MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1732                                     String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1733
1734                             // Not blocked.
1735                             return false;
1736                         }
1737                         break;
1738
1739                     case 5:  // There are three entries.
1740                         if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.startsWith(whiteListEntry[3])) {
1741                             // Store the entry in the resource request log.
1742                             MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1743                                     String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3],
1744                                     whiteListEntry[4]};
1745
1746                             // Not blocked.
1747                             return false;
1748                         }
1749                         break;
1750                 }
1751             }
1752
1753             // Domain final white list.
1754             for (String[] whiteListEntry : blockList.get(MainWebViewActivity.DOMAIN_FINAL_WHITELIST)) {
1755                 switch (whiteListEntry.length) {
1756                     case 3:  // There is one entry;
1757                         if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.endsWith(whiteListEntry[1])) {
1758                             // Store the entry in the resource request log.
1759                             MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1760                                     String.valueOf(MainWebViewActivity.DOMAIN_FINAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1761
1762                             // Not blocked.
1763                             return false;
1764                         }
1765                         break;
1766
1767                     case 4:  // There are two entries;
1768                         if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.endsWith(whiteListEntry[2])) {
1769                             // Store the entry in the resource request log.
1770                             MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1771                                     String.valueOf(MainWebViewActivity.DOMAIN_FINAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1772
1773
1774                             // Not blocked.
1775                             return false;
1776                         }
1777                         break;
1778                 }
1779             }
1780         }
1781
1782         // Only check the third-party white lists if this is a third-party request.
1783         if (isThirdPartyRequest) {
1784             // Third-party white list.
1785             for (String[] whiteListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_WHITELIST)) {
1786                 switch (whiteListEntry.length) {
1787                     case 2:  // There is one entry
1788                         if (resourceUrl.contains(whiteListEntry[0])) {
1789                             // Store the entry in the resource request log.
1790                             MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1791                                     String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0], whiteListEntry[1]};
1792
1793                             // Not blocked.
1794                             return false;
1795                         }
1796                         break;
1797
1798                     case 3:  // There are two entries.
1799                         if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1800                             // Store the entry in the resource request log.
1801                             MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1802                                     String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1803
1804                             // Not blocked.
1805                             return false;
1806                         }
1807                         break;
1808
1809                     case 4:  // There are three entries.
1810                         if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1811                             // Store the entry in the resource request log.
1812                             MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1813                                     String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1814
1815                             // Not blocked.
1816                             return false;
1817                         }
1818                         break;
1819
1820                     case 5:  // There are four entries.
1821                         if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3])) {
1822                             // Store the entry in the resource request log.
1823                             MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1824                                     String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3],
1825                                     whiteListEntry[4]};
1826                             // Not blocked.
1827                             return false;
1828                         }
1829                         break;
1830
1831                     case 6:  // There are five entries.
1832                         if (resourceUrl.contains(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2]) && resourceUrl.contains(whiteListEntry[3]) &&
1833                                 resourceUrl.contains(whiteListEntry[4])) {
1834                             // Store the entry in the resource request log.
1835                             MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1836                                     String.valueOf(MainWebViewActivity.THIRD_PARTY_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2] + "\n" + whiteListEntry[3] + "\n" +
1837                                     whiteListEntry[4], whiteListEntry[5]};
1838
1839                             // Not blocked.
1840                             return false;
1841                         }
1842                         break;
1843                 }
1844             }
1845
1846             // Third-party domain white list.
1847             for (String[] whiteListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST)) {
1848                 if (whiteListEntry.length == 3) {  // There is one entry.
1849                     if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1])) {
1850                         // Store the entry in the resource request log.
1851                         MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1852                                 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1853
1854                         // Not blocked.
1855                         return false;
1856                     }
1857                 } else {  // There are two entries.
1858                     if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.contains(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1859                         // Store the entry in the resource request log.
1860                         MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1861                                 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1862
1863                         // Not blocked.
1864                         return false;
1865                     }
1866                 }
1867             }
1868
1869             // Third-party domain initial white list.
1870             for (String[] whiteListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_WHITELIST)) {
1871                 if (whiteListEntry.length == 3) {  // There is one entry.
1872                     if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1])) {
1873                         // Store the entry in the resource request log.
1874                         MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1875                                 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1], whiteListEntry[2]};
1876
1877                         // Not blocked.
1878                         return false;
1879                     }
1880                 } else {  // There are two entries.
1881                     if (currentDomain.endsWith(whiteListEntry[0]) && resourceUrl.startsWith(whiteListEntry[1]) && resourceUrl.contains(whiteListEntry[2])) {
1882                         // Store the entry in the resource request log.
1883                         MainWebViewActivity.whiteListResultStringArray = new String[] {String.valueOf(MainWebViewActivity.REQUEST_ALLOWED), resourceUrl, BLOCK_LIST_NAME_STRING,
1884                                 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_WHITELIST), whiteListEntry[0] + "\n" + whiteListEntry[1] + "\n" + whiteListEntry[2], whiteListEntry[3]};
1885
1886                         // Not blocked.
1887                         return false;
1888                     }
1889                 }
1890             }
1891         }
1892
1893         // Process the black lists.
1894         // Main black list.
1895         for (String[] blackListEntry : blockList.get(MainWebViewActivity.MAIN_BLACKLIST)) {
1896             switch (blackListEntry.length) {
1897                 case 2:  // There is one entry.
1898                     if (resourceUrl.contains(blackListEntry[0])) {
1899                         // Store the entry in the resource request log.
1900                         MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1901                                 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0], blackListEntry[1]});
1902
1903                         // Blocked.
1904                         return true;
1905                     }
1906                     break;
1907
1908                 case 3:  // There are two entries.
1909                     if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
1910                         // Store the entry in the resource request log.
1911                         MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1912                                 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
1913
1914                         // Blocked.
1915                         return true;
1916                     }
1917                     break;
1918
1919                 case 4:  // There are three entries.
1920                     if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
1921                         // Store the entry in the resource request log.
1922                         MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1923                                 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
1924
1925                         // Blocked.
1926                         return true;
1927                     }
1928                     break;
1929
1930                 case 5:  // There are four entries.
1931                     if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
1932                         // Store the entry in the resource request log.
1933                         MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1934                                 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3], blackListEntry[4]});
1935
1936                         // Blocked.
1937                         return true;
1938                     }
1939                     break;
1940
1941                 case 6:  // There are five entries.
1942                     if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3]) &&
1943                             resourceUrl.contains(blackListEntry[4])) {
1944                         // Store the entry in the resource request log.
1945                         MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1946                                 String.valueOf(MainWebViewActivity.MAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3] + "\n" +
1947                                 blackListEntry[4], blackListEntry[5]});
1948
1949                         // Blocked.
1950                         return true;
1951                     }
1952                     break;
1953             }
1954         }
1955
1956         // Initial black list.
1957         for (String[] blackListEntry : blockList.get(MainWebViewActivity.INITIAL_BLACKLIST)) {
1958             if (blackListEntry.length == 2) {  // There is one entry.
1959                 if (resourceUrl.startsWith(blackListEntry[0])) {
1960                     // Store the entry in the resource request log.
1961                     MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1962                             String.valueOf(MainWebViewActivity.INITIAL_BLACKLIST), blackListEntry[0], blackListEntry[1]});
1963
1964                     // Blocked.
1965                     return true;
1966                 }
1967             } else {  // There are two entries
1968                 if (resourceUrl.startsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
1969                     // Store the entry in the resource request log.
1970                     MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1971                             String.valueOf(MainWebViewActivity.INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
1972
1973                     // Blocked.
1974                     return true;
1975                 }
1976             }
1977         }
1978
1979         // Final black list.
1980         for (String[] blackListEntry : blockList.get(MainWebViewActivity.FINAL_BLACKLIST)) {
1981             switch (blackListEntry.length) {
1982                 case 2:  // There is one entry.
1983                     if (resourceUrl.endsWith(blackListEntry[0])) {
1984                         // Store the entry in the resource request log.
1985                         MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1986                                 String.valueOf(MainWebViewActivity.FINAL_BLACKLIST), blackListEntry[0], blackListEntry[1]});
1987
1988                         // Blocked.
1989                         return true;
1990                     }
1991                     break;
1992
1993                 case 3:  // There are two entries.
1994                     if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.endsWith(blackListEntry[1])) {
1995                         // Store the entry in the resource request log.
1996                         MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
1997                                 String.valueOf(MainWebViewActivity.FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
1998
1999                         // Blocked.
2000                         return true;
2001                     }
2002                     break;
2003
2004                 case 4:  // There are three entries.
2005                     if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.endsWith(blackListEntry[2])) {
2006                         // Store the entry in the resource request log.
2007                         MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2008                                 String.valueOf(MainWebViewActivity.FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2009
2010                         // Blocked.
2011                         return true;
2012                     }
2013                     break;
2014             }
2015         }
2016
2017         // Only check the domain lists if the current domain is not null (like `about:blank`).
2018         if (currentDomain != null) {
2019             // Domain black list.
2020             for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_BLACKLIST)) {
2021                 switch (blackListEntry.length) {
2022                     case 3:  // There is one entry.
2023                         if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2024                             // Store the entry in the resource request log.
2025                             MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2026                                     String.valueOf(MainWebViewActivity.DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2027
2028                             // Blocked.
2029                             return true;
2030                         }
2031                         break;
2032
2033                     case 4:  // There are two entries.
2034                         if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2035                             // Store the entry in the resource request log.
2036                             MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2037                                     String.valueOf(MainWebViewActivity.DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2038
2039                             // Blocked.
2040                             return true;
2041                         }
2042                         break;
2043
2044                     case 5:  // There are three entries.
2045                         if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
2046                             // Store the entry in the resource request log.
2047                             MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2048                                     String.valueOf(MainWebViewActivity.DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3],
2049                                     blackListEntry[4]});
2050
2051                             // Blocked.
2052                             return true;
2053                         }
2054                         break;
2055                 }
2056             }
2057
2058             // Domain initial black list.
2059             for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_INITIAL_BLACKLIST)) {
2060                 // Store the entry in the resource request log.
2061                 if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1])) {
2062                     MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2063                             String.valueOf(MainWebViewActivity.DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1],
2064                             blackListEntry[2]});
2065
2066                     // Blocked.
2067                     return true;
2068                 }
2069             }
2070
2071             // Domain final black list.
2072             for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_FINAL_BLACKLIST)) {
2073                 switch (blackListEntry.length) {
2074                     case 3:  // There is one entry.
2075                         if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.endsWith(blackListEntry[1])) {
2076                             // Store the entry in the resource request log.
2077                             MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2078                                     String.valueOf(MainWebViewActivity.DOMAIN_FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2079
2080                             // Blocked.
2081                             return true;
2082                         }
2083                         break;
2084
2085                     case 4:  // There are two entries.
2086                         if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.endsWith(blackListEntry[2])) {
2087                             // Store the entry in the resource request log.
2088                             MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2089                                     String.valueOf(MainWebViewActivity.DOMAIN_FINAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2090
2091                             // Blocked.
2092                             return true;
2093                         }
2094                         break;
2095                 }
2096             }
2097
2098             // Domain regular expression black list.
2099             for (String[] blackListEntry : blockList.get(MainWebViewActivity.DOMAIN_REGULAR_EXPRESSION_BLACKLIST)) {
2100                 if (currentDomain.endsWith(blackListEntry[0]) && Pattern.matches(blackListEntry[1], resourceUrl)) {
2101                     // Store the entry in the resource request log.
2102                     MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2103                             String.valueOf(MainWebViewActivity.DOMAIN_REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2104
2105                     // Blocked.
2106                     return true;
2107                 }
2108             }
2109         }
2110
2111         // Only check the third-party black lists if this is a third-party request.
2112         if (isThirdPartyRequest) {
2113             // Third-party black list.
2114             for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_BLACKLIST)) {
2115                 switch (blackListEntry.length) {
2116                     case 2:  // There is one entry.
2117                         if (resourceUrl.contains(blackListEntry[0])) {
2118                             // Store the entry in the resource request log.
2119                             MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2120                                     String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0], blackListEntry[1]});
2121
2122                             // Blocked.
2123                             return true;
2124                         }
2125                         break;
2126
2127                     case 3:  // There are two entries.
2128                         if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2129                             // Store the entry in the resource request log.
2130                             MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2131                                     String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2132
2133                             // Blocked.
2134                             return true;
2135                         }
2136                         break;
2137
2138                     case 4:  // There are three entries.
2139                         if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2140                             // Store the entry in the resource request log.
2141                             MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2142                                     String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2143
2144                             // Blocked.
2145                             return true;
2146                         }
2147                         break;
2148
2149                     case 5:  // There are four entries.
2150                         if (resourceUrl.contains(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
2151                             // Store the entry in the resource request log.
2152                             MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2153                                     String.valueOf(MainWebViewActivity.THIRD_PARTY_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3],
2154                                     blackListEntry[4]});
2155
2156                             // Blocked.
2157                             return true;
2158                         }
2159                         break;
2160                 }
2161             }
2162
2163             // Third-party initial black list.
2164             for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_INITIAL_BLACKLIST)) {
2165                 if (blackListEntry.length == 2) {  // There is one entry.
2166                     if (resourceUrl.startsWith(blackListEntry[0])) {
2167                         // Store the entry in the resource request log.
2168                         MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2169                                 String.valueOf(MainWebViewActivity.THIRD_PARTY_INITIAL_BLACKLIST), blackListEntry[0], blackListEntry[1]});
2170
2171                         // Blocked.
2172                         return true;
2173                     }
2174                 } else {  // There are two entries.
2175                     if (resourceUrl.startsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2176                         // Store the entry in the resource request log.
2177                         MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2178                                 String.valueOf(MainWebViewActivity.THIRD_PARTY_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2179
2180                         // Blocked.
2181                         return true;
2182                     }
2183                 }
2184             }
2185
2186             // Third-party domain black list.
2187             for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_BLACKLIST)) {
2188                 if (blackListEntry.length == 3) {  // There is one entry.
2189                     if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1])) {
2190                         // Store the entry in the resource request log.
2191                         MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2192                                 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2193
2194                         // Blocked.
2195                         return true;
2196                     }
2197                 } else { // There are two entries.
2198                     if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.contains(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2199                         // Store the entry in the resource request log.
2200                         MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2201                                 String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2202
2203                         // Blocked.
2204                         return true;
2205                     }
2206                 }
2207             }
2208
2209             // Third-party domain initial black list.
2210             for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST)) {
2211                 switch (blackListEntry.length) {
2212                     case 3:  // There is one entry.
2213                         if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1])) {
2214                             // Store the entry in the resource request log.
2215                             MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2216                                     String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2217                             // Blocked.
2218                             return true;
2219                         }
2220                         break;
2221
2222                     case 4:  // There are two entries.
2223                         if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2])) {
2224                             // Store the entry in the resource request log.
2225                             MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2226                                     String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2], blackListEntry[3]});
2227
2228                             // Blocked.
2229                             return true;
2230                         }
2231                         break;
2232
2233                     case 5:  // There are three entries.
2234                         if (currentDomain.endsWith(blackListEntry[0]) && resourceUrl.startsWith(blackListEntry[1]) && resourceUrl.contains(blackListEntry[2]) && resourceUrl.contains(blackListEntry[3])) {
2235                             // Store the entry in the resource request log.
2236                             MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2237                                     String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_INITIAL_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1] + "\n" + blackListEntry[2] + "\n" + blackListEntry[3],
2238                                     blackListEntry[4]});
2239
2240                             // Blocked.
2241                             return true;
2242                         }
2243                         break;
2244                 }
2245             }
2246
2247             // Third-party regular expression black list.
2248             for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST)) {
2249                 if (Pattern.matches(blackListEntry[0], resourceUrl)) {
2250                     // Store the entry in the resource request log.
2251                     MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2252                             String.valueOf(MainWebViewActivity.THIRD_PARTY_REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0], blackListEntry[1]});
2253
2254                     // Blocked.
2255                     return true;
2256                 }
2257             }
2258
2259             // Third-party domain regular expression black list.
2260             for (String[] blackListEntry : blockList.get(MainWebViewActivity.THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST)) {
2261                 if (currentDomain.endsWith(blackListEntry[0]) && Pattern.matches(blackListEntry[1], resourceUrl)) {
2262                     // Store the entry in the resource request log.
2263                     MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2264                             String.valueOf(MainWebViewActivity.THIRD_PARTY_DOMAIN_REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0] + "\n" + blackListEntry[1], blackListEntry[2]});
2265
2266                     // Blocked.
2267                     return true;
2268                 }
2269             }
2270         }
2271
2272         // Regular expression black list.
2273         for (String[] blackListEntry : blockList.get(MainWebViewActivity.REGULAR_EXPRESSION_BLACKLIST)) {
2274             if (Pattern.matches(blackListEntry[0], resourceUrl)) {
2275                 // Store the entry in the resource request log.
2276                 MainWebViewActivity.resourceRequests.add(new String[] {String.valueOf(MainWebViewActivity.REQUEST_BLOCKED), resourceUrl, BLOCK_LIST_NAME_STRING,
2277                         String.valueOf(MainWebViewActivity.REGULAR_EXPRESSION_BLACKLIST), blackListEntry[0], blackListEntry[1]});
2278
2279                 // blocked.
2280                 return true;
2281             }
2282         }
2283
2284         // Not blocked.
2285         return false;
2286     }
2287 }