+ // Get a handle for the shared preference.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext);
+
+ // Get the default settings.
+ boolean javaScript = sharedPreferences.getBoolean("javascript", false);
+ boolean firstPartyCookies = sharedPreferences.getBoolean("first_party_cookies", false);
+ boolean thirdPartyCookies = sharedPreferences.getBoolean("third_party_cookies", false);
+ boolean domStorage = sharedPreferences.getBoolean("dom_storage", false);
+ boolean saveFormData = sharedPreferences.getBoolean("save_form_data", false); // Form data can be removed once the minimum API >= 26.
+ boolean easyList = sharedPreferences.getBoolean("easylist", true);
+ boolean easyPrivacy = sharedPreferences.getBoolean("easyprivacy", true);
+ boolean fanboyAnnoyanceList = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
+ boolean fanboySocialBlockingList = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
+ boolean ultraList = sharedPreferences.getBoolean("ultralist", true);
+ boolean ultraPrivacy = 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, javaScript);
+ domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, firstPartyCookies);
+ domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, thirdPartyCookies);
+ domainContentValues.put(ENABLE_DOM_STORAGE, domStorage);
+ domainContentValues.put(ENABLE_FORM_DATA, saveFormData); // Form data can be removed once the minimum API >= 26.
+ domainContentValues.put(ENABLE_EASYLIST, easyList);
+ domainContentValues.put(ENABLE_EASYPRIVACY, easyPrivacy);
+ domainContentValues.put(ENABLE_FANBOYS_ANNOYANCE_LIST, fanboyAnnoyanceList);
+ domainContentValues.put(ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST, fanboySocialBlockingList);
+ domainContentValues.put(ULTRALIST, ultraList);
+ domainContentValues.put(ENABLE_ULTRAPRIVACY, ultraPrivacy);
+ 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(WEBVIEW_THEME, 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 javaScript, boolean firstPartyCookies, boolean thirdPartyCookies, boolean domStorage, boolean formData, boolean easyList,
+ boolean easyPrivacy, boolean fanboysAnnoyance, boolean fanboysSocialBlocking, boolean ultraList, boolean ultraPrivacy, boolean blockAllThirdPartyRequests, String userAgent,
+ int fontSize, int swipeToRefresh, int webViewTheme, int wideViewport, int displayImages, boolean pinnedSslCertificate, boolean pinnedIpAddresses) {
+
+ // Store the domain data in a `ContentValues`.
+ ContentValues domainContentValues = new ContentValues();
+
+ // Add entries for each field in the database.
+ domainContentValues.put(DOMAIN_NAME, domainName);
+ domainContentValues.put(ENABLE_JAVASCRIPT, javaScript);
+ domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, firstPartyCookies);
+ domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, thirdPartyCookies);
+ domainContentValues.put(ENABLE_DOM_STORAGE, domStorage);
+ domainContentValues.put(ENABLE_FORM_DATA, formData); // Form data can be removed once the minimum API >= 26.
+ domainContentValues.put(ENABLE_EASYLIST, easyList);
+ domainContentValues.put(ENABLE_EASYPRIVACY, easyPrivacy);
+ domainContentValues.put(ENABLE_FANBOYS_ANNOYANCE_LIST, fanboysAnnoyance);
+ domainContentValues.put(ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST, fanboysSocialBlocking);
+ domainContentValues.put(ULTRALIST, ultraList);
+ domainContentValues.put(ENABLE_ULTRAPRIVACY, ultraPrivacy);
+ domainContentValues.put(BLOCK_ALL_THIRD_PARTY_REQUESTS, blockAllThirdPartyRequests);
+ domainContentValues.put(USER_AGENT, userAgent);
+ domainContentValues.put(FONT_SIZE, fontSize);
+ domainContentValues.put(SWIPE_TO_REFRESH, swipeToRefresh);
+ domainContentValues.put(WEBVIEW_THEME, webViewTheme);
+ domainContentValues.put(WIDE_VIEWPORT, wideViewport);
+ domainContentValues.put(DISPLAY_IMAGES, displayImages);
+ domainContentValues.put(PINNED_SSL_CERTIFICATE, pinnedSslCertificate);
+ domainContentValues.put(PINNED_IP_ADDRESSES, pinnedIpAddresses);
+
+ // Get a writable database handle.
+ SQLiteDatabase domainsDatabase = this.getWritableDatabase();
+
+ // Update the row for `databaseId`. The last argument is `null` because there are no `whereArgs`.
+ domainsDatabase.update(DOMAINS_TABLE, domainContentValues, _ID + " = " + databaseId, null);
+
+ // Close the database handle.
+ domainsDatabase.close();
+ }
+
+ public void updatePinnedSslCertificate(int databaseId, String sslIssuedToCommonName, String sslIssuedToOrganization, String sslIssuedToOrganizationalUnit, String sslIssuedByCommonName,
+ String sslIssuedByOrganization, String sslIssuedByOrganizationalUnit, long sslStartDate, long sslEndDate) {
+
+ // Store the pinned SSL certificate in a content values.
+ ContentValues pinnedSslCertificateContentValues = new ContentValues();
+
+ // Add entries for each field in the certificate.
+ pinnedSslCertificateContentValues.put(SSL_ISSUED_TO_COMMON_NAME, sslIssuedToCommonName);
+ pinnedSslCertificateContentValues.put(SSL_ISSUED_TO_ORGANIZATION, sslIssuedToOrganization);
+ pinnedSslCertificateContentValues.put(SSL_ISSUED_TO_ORGANIZATIONAL_UNIT, sslIssuedToOrganizationalUnit);
+ pinnedSslCertificateContentValues.put(SSL_ISSUED_BY_COMMON_NAME, sslIssuedByCommonName);
+ pinnedSslCertificateContentValues.put(SSL_ISSUED_BY_ORGANIZATION, sslIssuedByOrganization);
+ pinnedSslCertificateContentValues.put(SSL_ISSUED_BY_ORGANIZATIONAL_UNIT, sslIssuedByOrganizationalUnit);
+ pinnedSslCertificateContentValues.put(SSL_START_DATE, sslStartDate);
+ pinnedSslCertificateContentValues.put(SSL_END_DATE, sslEndDate);
+
+ // Get a writable database handle.
+ SQLiteDatabase domainsDatabase = this.getWritableDatabase();
+
+ // Update the row for database ID.
+ domainsDatabase.update(DOMAINS_TABLE, pinnedSslCertificateContentValues, _ID + " = " + databaseId, null);
+
+ // Close the database handle.
+ domainsDatabase.close();
+ }
+
+ public void updatePinnedIpAddresses(int databaseId, String ipAddresses) {
+ // Store the pinned IP addresses in a content values.
+ ContentValues pinnedIpAddressesContentValues = new ContentValues();
+
+ // Add the IP addresses to the content values.
+ pinnedIpAddressesContentValues.put(IP_ADDRESSES, ipAddresses);
+
+ // Get a writable database handle.
+ SQLiteDatabase domainsDatabase = this.getWritableDatabase();
+
+ // Update the row for the database ID.
+ domainsDatabase.update(DOMAINS_TABLE, pinnedIpAddressesContentValues, _ID + " = " + databaseId, null);
+
+ // Close the database handle.
+ domainsDatabase.close();
+ }