+ // **DEBUG** Log the beginning of the loading of the ad blocker.
+ Log.i("AdBlocker", "Begin loading ad blocker");
+
+ // Initialize `adServerSet`.
+ final Set<String> adServersSet = new HashSet<>();
+
+ // Load the list of ad servers into memory.
+ try {
+ // Load `easylist.txt` into a `BufferedReader`.
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(getAssets().open("easylist.txt")));
+
+ // Create a string for storing each ad server.
+ String adBlockerEntry;
+
+ // Populate `adServersSet`.
+ while ((adBlockerEntry = bufferedReader.readLine()) != null) {
+ //noinspection StatementWithEmptyBody
+ if (adBlockerEntry.contains("##") || adBlockerEntry.contains("#?#") || adBlockerEntry.contains("#@#") || adBlockerEntry.startsWith("[")) {
+ // Entries that contain `##`, `#?#`, and `#@#` are for hiding elements in the main page's HTML. Entries that start with `[` describe the AdBlock compatibility level.
+
+ // Do nothing. Privacy Browser does not currently use these entries.
+
+ // **DEBUG** Log the entries that are not added.
+ // Log.i("AdBlocker", "Not added: " + adBlockerEntry);
+ } else if (adBlockerEntry.startsWith("!")){ // Entries that begin with `!` are comments.
+ if (adBlockerEntry.startsWith("! Version:")) {
+ // Store the EasyList version number.
+ easyListVersion = adBlockerEntry.substring(11);
+ }
+
+ // **DEBUG** Log the entries that are not added.
+ // Log.i("AdBlocker", "Not added: " + adBlockerEntry);
+ } else {
+ adServersSet.add(adBlockerEntry);
+ }
+ }
+
+ // Close `bufferedReader`.
+ bufferedReader.close();
+ } catch (IOException e) {
+ // The asset exists, so the `IOException` will never be thrown.
+ }
+
+ // **DEBUG** Log the finishing of the loading of the ad blocker.
+ Log.i("AdBlocker", "Finish loading ad blocker");
+