+ public Cursor getCursorForDomainName(String domainName) {
+ // Get a readable database handle.
+ SQLiteDatabase domainsDatabase = this.getReadableDatabase();
+
+ // Prepare the SQL statement to get the `Cursor` for `domainName`.
+ final String GET_CURSOR_FOR_DOMAIN_NAME = "SELECT * FROM " + DOMAINS_TABLE +
+ " WHERE " + DOMAIN_NAME + " = " + "\"" + domainName + "\"";
+
+ // Return the results as a `Cursor`. The second argument is `null` because there are no `selectionArgs`. We can't close the `Cursor` because we need to us it in the calling activity.
+ return domainsDatabase.rawQuery(GET_CURSOR_FOR_DOMAIN_NAME, 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_enabled", false);
+ boolean firstPartyCookiesEnabled = sharedPreferences.getBoolean("first_party_cookies_enabled", false);
+ boolean thirdPartyCookiesEnabled = sharedPreferences.getBoolean("third_party_cookies_enabled", false);
+ boolean domStorageEnabled = sharedPreferences.getBoolean("dom_storage_enabled", false);
+ boolean saveFormDataEnabled = sharedPreferences.getBoolean("save_form_data_enabled", false);
+ boolean easyListEnabled = sharedPreferences.getBoolean("easylist", true);
+ boolean easyPrivacyEnabled = sharedPreferences.getBoolean("easyprivacy", true);
+ boolean fanboyAnnoyanceListEnabled = sharedPreferences.getBoolean("fanboy_annoyance_list", true);
+ boolean fanboySocialBlockingListEnabled = sharedPreferences.getBoolean("fanboy_social_blocking_list", true);
+
+ // 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);
+ 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(USER_AGENT, "System default user agent");
+ domainContentValues.put(FONT_SIZE, 0);
+ domainContentValues.put(DISPLAY_IMAGES, 0);
+ domainContentValues.put(NIGHT_MODE, 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;
+ }
+
+ public void updateDomainExceptCertificate(int databaseId, String domainName, boolean javaScriptEnabled, boolean firstPartyCookiesEnabled, boolean thirdPartyCookiesEnabled, boolean domStorageEnabled,
+ boolean formDataEnabled, boolean easyListEnabled, boolean easyPrivacyEnabled, boolean fanboysAnnoyanceEnabled, boolean fanboysSocialBlockingEnabled,
+ String userAgent, int fontSize, int displayImages, int nightMode, boolean pinnedSslCertificate) {
+