+ public Cursor getCursorForDomainName(String domainName) {
+ // Get a readable database handle.
+ SQLiteDatabase domainsDatabase = this.getReadableDatabase();
+
+ // Return a cursor for the requested domain name.
+ return domainsDatabase.query(DOMAINS_TABLE, null, DOMAIN_NAME + " = " + "\"" + domainName + "\"", null, null, null, null);
+
+ }
+
+ public int addDomain(String domainName) {
+ // Store the domain data in a `ContentValues`.
+ ContentValues domainContentValues = new ContentValues();
+
+ // Get a handle for the shared preference.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext);
+
+ // Get the default settings.
+ boolean javaScriptEnabled = sharedPreferences.getBoolean("javascript", false);
+ boolean firstPartyCookiesEnabled = sharedPreferences.getBoolean("first_party_cookies", false);
+ boolean thirdPartyCookiesEnabled = sharedPreferences.getBoolean("third_party_cookies", false);
+ boolean domStorageEnabled = sharedPreferences.getBoolean("dom_storage", false);
+ boolean saveFormDataEnabled = sharedPreferences.getBoolean("save_form_data", false); // Form data can be removed once the minimum API >= 26.
+ boolean easyListEnabled = sharedPreferences.getBoolean("easylist", true);
+ boolean easyPrivacyEnabled = sharedPreferences.getBoolean("easyprivacy", true);
+ boolean fanboyAnnoyanceListEnabled = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
+ boolean fanboySocialBlockingListEnabled = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
+ boolean ultraPrivacyEnabled = sharedPreferences.getBoolean("ultraprivacy", true);
+ boolean blockAllThirdPartyRequests = sharedPreferences.getBoolean("block_all_third_party_requests", false);
+
+ // Create entries for the database fields. The ID is created automatically. The pinned SSL certificate information is not created unless added by the user.
+ domainContentValues.put(DOMAIN_NAME, domainName);
+ domainContentValues.put(ENABLE_JAVASCRIPT, javaScriptEnabled);
+ domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, firstPartyCookiesEnabled);
+ domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, thirdPartyCookiesEnabled);
+ domainContentValues.put(ENABLE_DOM_STORAGE, domStorageEnabled);
+ domainContentValues.put(ENABLE_FORM_DATA, saveFormDataEnabled); // Form data can be removed once the minimum API >= 26.
+ domainContentValues.put(ENABLE_EASYLIST, easyListEnabled);
+ domainContentValues.put(ENABLE_EASYPRIVACY, easyPrivacyEnabled);
+ domainContentValues.put(ENABLE_FANBOYS_ANNOYANCE_LIST, fanboyAnnoyanceListEnabled);
+ domainContentValues.put(ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST, fanboySocialBlockingListEnabled);
+ domainContentValues.put(ENABLE_ULTRAPRIVACY, ultraPrivacyEnabled);
+ domainContentValues.put(BLOCK_ALL_THIRD_PARTY_REQUESTS, blockAllThirdPartyRequests);
+ domainContentValues.put(USER_AGENT, "System default user agent");
+ domainContentValues.put(FONT_SIZE, 0);
+ domainContentValues.put(SWIPE_TO_REFRESH, 0);
+ domainContentValues.put(NIGHT_MODE, 0);
+ domainContentValues.put(WIDE_VIEWPORT, 0);
+ domainContentValues.put(DISPLAY_IMAGES, 0);
+
+ // Get a writable database handle.
+ SQLiteDatabase domainsDatabase = this.getWritableDatabase();
+
+ // Insert a new row and store the resulting database ID. The second argument is `null`, which makes it so that a completely null row cannot be created.
+ int newDomainDatabaseId = (int) domainsDatabase.insert(DOMAINS_TABLE, null, domainContentValues);
+
+ // Close the database handle.
+ domainsDatabase.close();
+
+ // Return the new domain database ID.
+ return newDomainDatabaseId;
+ }
+
+ void addDomain(ContentValues contentValues) {
+ // Get a writable database handle.
+ SQLiteDatabase domainsDatabase = this.getWritableDatabase();
+
+ // Add the new domain.
+ domainsDatabase.insert(DOMAINS_TABLE, null, contentValues);
+
+ // Close the database handle.
+ domainsDatabase.close();
+ }
+
+ public void updateDomain(int databaseId, String domainName, boolean javaScriptEnabled, boolean firstPartyCookiesEnabled, boolean thirdPartyCookiesEnabled, boolean domStorageEnabled, boolean formDataEnabled,
+ boolean easyListEnabled, boolean easyPrivacyEnabled, boolean fanboysAnnoyanceEnabled, boolean fanboysSocialBlockingEnabled, boolean ultraPrivacyEnabled,
+ boolean blockAllThirdPartyRequests, String userAgent, int fontSize, int swipeToRefresh, int nightMode, int wideViewport, int displayImages, boolean pinnedSslCertificate,
+ boolean pinnedIpAddresses) {
+
+ // Store the domain data in a `ContentValues`.