]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java
Add swipe to refresh to domain and on-the-fly settings. https://redmine.stoutner...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / helpers / DomainsDatabaseHelper.java
1 /*
2  * Copyright © 2017-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.ContentValues;
23 import android.content.Context;
24 import android.content.SharedPreferences;
25 import android.database.Cursor;
26 import android.database.sqlite.SQLiteDatabase;
27 import android.database.sqlite.SQLiteOpenHelper;
28 import android.preference.PreferenceManager;
29
30 public class DomainsDatabaseHelper extends SQLiteOpenHelper {
31     private static final int SCHEMA_VERSION = 6;
32     private static final String DOMAINS_DATABASE = "domains.db";
33     private static final String DOMAINS_TABLE = "domains";
34
35     public static final String _ID = "_id";
36     public static final String DOMAIN_NAME = "domainname";
37     public static final String ENABLE_JAVASCRIPT = "enablejavascript";
38     public static final String ENABLE_FIRST_PARTY_COOKIES = "enablefirstpartycookies";
39     public static final String ENABLE_THIRD_PARTY_COOKIES = "enablethirdpartycookies";
40     public static final String ENABLE_DOM_STORAGE = "enabledomstorage";
41     public static final String ENABLE_FORM_DATA = "enableformdata";
42     public static final String ENABLE_EASYLIST = "enableeasylist";
43     public static final String ENABLE_EASYPRIVACY = "enableeasyprivacy";
44     public static final String ENABLE_FANBOYS_ANNOYANCE_LIST = "enablefanboysannoyancelist";
45     public static final String ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST = "enablefanboyssocialblockinglist";
46     public static final String USER_AGENT = "useragent";
47     public static final String FONT_SIZE = "fontsize";
48     public static final String SWIPE_TO_REFRESH = "swipetorefresh";
49     public static final String NIGHT_MODE = "nightmode";
50     public static final String DISPLAY_IMAGES = "displayimages";
51     public static final String PINNED_SSL_CERTIFICATE = "pinnedsslcertificate";
52     public static final String SSL_ISSUED_TO_COMMON_NAME = "sslissuedtocommonname";
53     public static final String SSL_ISSUED_TO_ORGANIZATION = "sslissuedtoorganization";
54     public static final String SSL_ISSUED_TO_ORGANIZATIONAL_UNIT = "sslissuedtoorganizationalunit";
55     public static final String SSL_ISSUED_BY_COMMON_NAME = "sslissuedbycommonname";
56     public static final String SSL_ISSUED_BY_ORGANIZATION = "sslissuedbyorganization";
57     public static final String SSL_ISSUED_BY_ORGANIZATIONAL_UNIT = "sslissuedbyorganizationalunit";
58     public static final String SSL_START_DATE = "sslstartdate";
59     public static final String SSL_END_DATE = "sslenddate";
60
61     // Swipe to refresh constants.
62     public static final int SWIPE_TO_REFRESH_SYSTEM_DEFAULT = 0;
63     public static final int SWIPE_TO_REFRESH_ENABLED = 1;
64     public static final int SWIPE_TO_REFRESH_DISABLED = 2;
65
66     // Night mode constants.
67     public static final int NIGHT_MODE_SYSTEM_DEFAULT = 0;
68     public static final int NIGHT_MODE_ENABLED = 1;
69     public static final int NIGHT_MODE_DISABLED = 2;
70
71     // Display webpage images constants.
72     public static final int DISPLAY_WEBPAGE_IMAGES_SYSTEM_DEFAULT = 0;
73     public static final int DISPLAY_WEBPAGE_IMAGES_ENABLED = 1;
74     public static final int DISPLAY_WEBPAGE_IMAGES_DISABLED = 2;
75
76     private Context appContext;
77
78     // Initialize the database.  The lint warnings for the unused parameters are suppressed.
79     public DomainsDatabaseHelper(Context context, @SuppressWarnings("UnusedParameters") String name, SQLiteDatabase.CursorFactory cursorFactory, @SuppressWarnings("UnusedParameters") int version) {
80         super(context, DOMAINS_DATABASE, cursorFactory, SCHEMA_VERSION);
81
82         // Store a handle for the context.
83         appContext = context;
84     }
85
86     @Override
87     public void onCreate(SQLiteDatabase domainsDatabase) {
88         // Setup the SQL string to create the `domains` table.
89         String CREATE_DOMAINS_TABLE = "CREATE TABLE " + DOMAINS_TABLE + " (" +
90                 _ID + " INTEGER PRIMARY KEY, " +
91                 DOMAIN_NAME + " TEXT, " +
92                 ENABLE_JAVASCRIPT + " BOOLEAN, " +
93                 ENABLE_FIRST_PARTY_COOKIES + " BOOLEAN, " +
94                 ENABLE_THIRD_PARTY_COOKIES + " BOOLEAN, " +
95                 ENABLE_DOM_STORAGE + " BOOLEAN, " +
96                 ENABLE_FORM_DATA + " BOOLEAN, " +
97                 ENABLE_EASYLIST + " BOOLEAN, " +
98                 ENABLE_EASYPRIVACY + " BOOLEAN, " +
99                 ENABLE_FANBOYS_ANNOYANCE_LIST + " BOOLEAN, " +
100                 ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST + " BOOLEAN, " +
101                 USER_AGENT + " TEXT, " +
102                 FONT_SIZE + " INTEGER, " +
103                 SWIPE_TO_REFRESH + " INTEGER, " +
104                 NIGHT_MODE + " INTEGER, " +
105                 DISPLAY_IMAGES + " INTEGER, " +
106                 PINNED_SSL_CERTIFICATE + " BOOLEAN, " +
107                 SSL_ISSUED_TO_COMMON_NAME + " TEXT, " +
108                 SSL_ISSUED_TO_ORGANIZATION + " TEXT, " +
109                 SSL_ISSUED_TO_ORGANIZATIONAL_UNIT + " TEXT, " +
110                 SSL_ISSUED_BY_COMMON_NAME + " TEXT, " +
111                 SSL_ISSUED_BY_ORGANIZATION + " TEXT, " +
112                 SSL_ISSUED_BY_ORGANIZATIONAL_UNIT + " TEXT, " +
113                 SSL_START_DATE + " INTEGER, " +
114                 SSL_END_DATE + " INTEGER);";
115
116         // Make it so.
117         domainsDatabase.execSQL(CREATE_DOMAINS_TABLE);
118     }
119
120     @Override
121     public void onUpgrade(SQLiteDatabase domainsDatabase, int oldVersion, int newVersion) {
122         // Upgrade the database table.
123         switch (oldVersion) {
124             // Upgrade from schema version 1.
125             case 1:
126                 // Add the display images column.
127                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + DISPLAY_IMAGES + " INTEGER");
128
129             // Upgrade from schema version 2.
130             case 2:
131                 //  Add the SSL certificate columns.
132                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + PINNED_SSL_CERTIFICATE + " BOOLEAN");
133                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_ISSUED_TO_COMMON_NAME + " TEXT");
134                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_ISSUED_TO_ORGANIZATION + " TEXT");
135                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_ISSUED_TO_ORGANIZATIONAL_UNIT + " TEXT");
136                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_ISSUED_BY_COMMON_NAME + " TEXT");
137                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_ISSUED_BY_ORGANIZATION + " TEXT");
138                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_ISSUED_BY_ORGANIZATIONAL_UNIT + " TEXT");
139                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_START_DATE + " INTEGER");
140                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_END_DATE + " INTEGER");
141
142             // Upgrade from schema version 3.
143             case 3:
144                 // Add the Night Mode column.
145                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + NIGHT_MODE + " INTEGER");
146
147             // Upgrade from schema version 4.
148             case 4:
149                 // Add the block lists columns.
150                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + ENABLE_EASYLIST + " BOOLEAN");
151                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + ENABLE_EASYPRIVACY + " BOOLEAN");
152                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + ENABLE_FANBOYS_ANNOYANCE_LIST + " BOOLEAN");
153                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST + " BOOLEAN");
154
155                 // Get a handle for the shared preference.
156                 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext);
157
158                 // Get the default block list settings.
159                 boolean easyListEnabled = sharedPreferences.getBoolean("easylist", true);
160                 boolean easyPrivacyEnabled = sharedPreferences.getBoolean("easyprivacy", true);
161                 boolean fanboyAnnoyanceListEnabled = sharedPreferences.getBoolean("fanboy_annoyance_list", true);
162                 boolean fanboySocialBlockingListEnabled = sharedPreferences.getBoolean("fanboy_social_blocking_list", true);
163
164                 // Set EasyList for existing rows according to the current system-wide default.
165                 if (easyListEnabled) {
166                     domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_EASYLIST + " = " + 1);
167                 } else {
168                     domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_EASYLIST + " = " + 0);
169                 }
170
171                 // Set EasyPrivacy for existing rows according to the current system-wide default.
172                 if (easyPrivacyEnabled) {
173                     domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_EASYPRIVACY + " = " + 1);
174                 } else {
175                     domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_EASYPRIVACY + " = " + 0);
176                 }
177
178                 // Set Fanboy's Annoyance List for existing rows according to the current system-wide default.
179                 if (fanboyAnnoyanceListEnabled) {
180                     domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_FANBOYS_ANNOYANCE_LIST + " = " + 1);
181                 } else {
182                     domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_FANBOYS_ANNOYANCE_LIST + " = " + 0);
183                 }
184
185                 // Set Fanboy's Social Blocking List for existing rows according to the current system-wide default.
186                 if (fanboySocialBlockingListEnabled) {
187                     domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST + " = " + 1);
188                 } else {
189                     domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST + " = " + 0);
190                 }
191
192             // Upgrade from schema version 5.
193             case 5:
194                 // Add the swipe to refresh column.
195                 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SWIPE_TO_REFRESH + " INTEGER");
196         }
197     }
198
199     public Cursor getDomainNameCursorOrderedByDomain() {
200         // Get a readable database handle.
201         SQLiteDatabase domainsDatabase = this.getReadableDatabase();
202
203         // Get everything in `DOMAINS_TABLE` ordered by `DOMAIN_NAME`.
204         final String GET_CURSOR_ORDERED_BY_DOMAIN = "SELECT " + _ID + ", " + DOMAIN_NAME +
205                 " FROM " + DOMAINS_TABLE +
206                 " ORDER BY " + DOMAIN_NAME + " ASC";
207
208         // 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 use it in the parent activity.
209         return domainsDatabase.rawQuery(GET_CURSOR_ORDERED_BY_DOMAIN, null);
210     }
211
212     public Cursor getDomainNameCursorOrderedByDomainExcept(int databaseId) {
213         // Get a readable database handle.
214         SQLiteDatabase domainsDatabase = this.getReadableDatabase();
215
216         // Prepare the SQL statement to select all rows except that with `databaseId`.
217         final String GET_CURSOR_ORDERED_BY_DOMAIN_EXCEPT = "SELECT " + _ID + ", " + DOMAIN_NAME +
218                 " FROM " + DOMAINS_TABLE +
219                 " WHERE " + _ID + " IS NOT " + databaseId +
220                 " ORDER BY " + DOMAIN_NAME + " ASC";
221
222         // 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 use it in the calling activity.
223         return domainsDatabase.rawQuery(GET_CURSOR_ORDERED_BY_DOMAIN_EXCEPT, null);
224     }
225
226     public Cursor getCursorForId(int databaseId) {
227         // Get a readable database handle.
228         SQLiteDatabase domainsDatabase = this.getReadableDatabase();
229
230         // Prepare the SQL statement to get the `Cursor` for `databaseId`.
231         final String GET_CURSOR_FOR_ID = "SELECT * FROM " + DOMAINS_TABLE +
232                 " WHERE " + _ID + " = " + databaseId;
233
234         // 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 use it in the calling activity.
235         return domainsDatabase.rawQuery(GET_CURSOR_FOR_ID, null);
236     }
237
238     public Cursor getCursorForDomainName(String domainName) {
239         // Get a readable database handle.
240         SQLiteDatabase domainsDatabase = this.getReadableDatabase();
241
242         // Prepare the SQL statement to get the `Cursor` for `domainName`.
243         final String GET_CURSOR_FOR_DOMAIN_NAME = "SELECT * FROM " + DOMAINS_TABLE +
244                 " WHERE " + DOMAIN_NAME + " = " + "\"" + domainName + "\"";
245
246         // 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.
247         return domainsDatabase.rawQuery(GET_CURSOR_FOR_DOMAIN_NAME, null);
248     }
249
250     public int addDomain(String domainName) {
251         // Store the domain data in a `ContentValues`.
252         ContentValues domainContentValues = new ContentValues();
253
254         // Get a handle for the shared preference.
255         SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext);
256
257         // Get the default settings.
258         boolean javaScriptEnabled = sharedPreferences.getBoolean("javascript_enabled", false);
259         boolean firstPartyCookiesEnabled = sharedPreferences.getBoolean("first_party_cookies_enabled", false);
260         boolean thirdPartyCookiesEnabled = sharedPreferences.getBoolean("third_party_cookies_enabled", false);
261         boolean domStorageEnabled = sharedPreferences.getBoolean("dom_storage_enabled", false);
262         boolean saveFormDataEnabled = sharedPreferences.getBoolean("save_form_data_enabled", false);
263         boolean easyListEnabled = sharedPreferences.getBoolean("easylist", true);
264         boolean easyPrivacyEnabled = sharedPreferences.getBoolean("easyprivacy", true);
265         boolean fanboyAnnoyanceListEnabled = sharedPreferences.getBoolean("fanboy_annoyance_list", true);
266         boolean fanboySocialBlockingListEnabled = sharedPreferences.getBoolean("fanboy_social_blocking_list", true);
267
268         // Create entries for the database fields.  The ID is created automatically.  The pinned SSL certificate information is not created unless added by the user.
269         domainContentValues.put(DOMAIN_NAME, domainName);
270         domainContentValues.put(ENABLE_JAVASCRIPT, javaScriptEnabled);
271         domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, firstPartyCookiesEnabled);
272         domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, thirdPartyCookiesEnabled);
273         domainContentValues.put(ENABLE_DOM_STORAGE, domStorageEnabled);
274         domainContentValues.put(ENABLE_FORM_DATA, saveFormDataEnabled);
275         domainContentValues.put(ENABLE_EASYLIST, easyListEnabled);
276         domainContentValues.put(ENABLE_EASYPRIVACY, easyPrivacyEnabled);
277         domainContentValues.put(ENABLE_FANBOYS_ANNOYANCE_LIST, fanboyAnnoyanceListEnabled);
278         domainContentValues.put(ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST, fanboySocialBlockingListEnabled);
279         domainContentValues.put(USER_AGENT, "System default user agent");
280         domainContentValues.put(FONT_SIZE, 0);
281         domainContentValues.put(SWIPE_TO_REFRESH, 0);
282         domainContentValues.put(NIGHT_MODE, 0);
283         domainContentValues.put(DISPLAY_IMAGES, 0);
284
285         // Get a writable database handle.
286         SQLiteDatabase domainsDatabase = this.getWritableDatabase();
287
288         // 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.
289         int newDomainDatabaseId  = (int) domainsDatabase.insert(DOMAINS_TABLE, null, domainContentValues);
290
291         // Close the database handle.
292         domainsDatabase.close();
293
294         // Return the new domain database ID.
295         return newDomainDatabaseId;
296     }
297
298     public void updateDomainExceptCertificate(int databaseId, String domainName, boolean javaScriptEnabled, boolean firstPartyCookiesEnabled, boolean thirdPartyCookiesEnabled, boolean domStorageEnabled,
299                                               boolean formDataEnabled, boolean easyListEnabled, boolean easyPrivacyEnabled, boolean fanboysAnnoyanceEnabled, boolean fanboysSocialBlockingEnabled,
300                                               String userAgent, int fontSize, int swipeToRefresh, int nightMode, int displayImages, boolean pinnedSslCertificate) {
301
302         // Store the domain data in a `ContentValues`.
303         ContentValues domainContentValues = new ContentValues();
304
305         // Add entries for each field in the database.
306         domainContentValues.put(DOMAIN_NAME, domainName);
307         domainContentValues.put(ENABLE_JAVASCRIPT, javaScriptEnabled);
308         domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, firstPartyCookiesEnabled);
309         domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, thirdPartyCookiesEnabled);
310         domainContentValues.put(ENABLE_DOM_STORAGE, domStorageEnabled);
311         domainContentValues.put(ENABLE_FORM_DATA, formDataEnabled);
312         domainContentValues.put(ENABLE_EASYLIST, easyListEnabled);
313         domainContentValues.put(ENABLE_EASYPRIVACY, easyPrivacyEnabled);
314         domainContentValues.put(ENABLE_FANBOYS_ANNOYANCE_LIST, fanboysAnnoyanceEnabled);
315         domainContentValues.put(ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST, fanboysSocialBlockingEnabled);
316         domainContentValues.put(USER_AGENT, userAgent);
317         domainContentValues.put(FONT_SIZE, fontSize);
318         domainContentValues.put(SWIPE_TO_REFRESH, swipeToRefresh);
319         domainContentValues.put(NIGHT_MODE, nightMode);
320         domainContentValues.put(DISPLAY_IMAGES, displayImages);
321         domainContentValues.put(PINNED_SSL_CERTIFICATE, pinnedSslCertificate);
322
323         // Get a writable database handle.
324         SQLiteDatabase domainsDatabase = this.getWritableDatabase();
325
326         // Update the row for `databaseId`.  The last argument is `null` because there are no `whereArgs`.
327         domainsDatabase.update(DOMAINS_TABLE, domainContentValues, _ID + " = " + databaseId, null);
328
329         // Close the database handle.
330         domainsDatabase.close();
331     }
332
333     public void updateDomainWithCertificate(int databaseId, String domainName, boolean javaScriptEnabled, boolean firstPartyCookiesEnabled, boolean thirdPartyCookiesEnabled, boolean domStorageEnabled,
334                                             boolean formDataEnabled, boolean easyListEnabled, boolean easyPrivacyEnabled, boolean fanboysAnnoyanceEnabled, boolean fanboysSocialBlockingEnabled, String userAgent,
335                                             int fontSize, int swipeToRefresh, int nightMode, int displayImages, boolean pinnedSslCertificate, String sslIssuedToCommonName, String sslIssuedToOrganization,
336                                             String sslIssuedToOrganizationalUnit, String sslIssuedByCommonName, String sslIssuedByOrganization, String sslIssuedByOrganizationalUnit, long sslStartDate,
337                                             long sslEndDate) {
338
339         // Store the domain data in a `ContentValues`.
340         ContentValues domainContentValues = new ContentValues();
341
342         // Add entries for each field in the database.
343         domainContentValues.put(DOMAIN_NAME, domainName);
344         domainContentValues.put(ENABLE_JAVASCRIPT, javaScriptEnabled);
345         domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, firstPartyCookiesEnabled);
346         domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, thirdPartyCookiesEnabled);
347         domainContentValues.put(ENABLE_DOM_STORAGE, domStorageEnabled);
348         domainContentValues.put(ENABLE_FORM_DATA, formDataEnabled);
349         domainContentValues.put(ENABLE_EASYLIST, easyListEnabled);
350         domainContentValues.put(ENABLE_EASYPRIVACY, easyPrivacyEnabled);
351         domainContentValues.put(ENABLE_FANBOYS_ANNOYANCE_LIST, fanboysAnnoyanceEnabled);
352         domainContentValues.put(ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST, fanboysSocialBlockingEnabled);
353         domainContentValues.put(USER_AGENT, userAgent);
354         domainContentValues.put(FONT_SIZE, fontSize);
355         domainContentValues.put(SWIPE_TO_REFRESH, swipeToRefresh);
356         domainContentValues.put(NIGHT_MODE, nightMode);
357         domainContentValues.put(DISPLAY_IMAGES, displayImages);
358         domainContentValues.put(PINNED_SSL_CERTIFICATE, pinnedSslCertificate);
359         domainContentValues.put(SSL_ISSUED_TO_COMMON_NAME, sslIssuedToCommonName);
360         domainContentValues.put(SSL_ISSUED_TO_ORGANIZATION, sslIssuedToOrganization);
361         domainContentValues.put(SSL_ISSUED_TO_ORGANIZATIONAL_UNIT, sslIssuedToOrganizationalUnit);
362         domainContentValues.put(SSL_ISSUED_BY_COMMON_NAME, sslIssuedByCommonName);
363         domainContentValues.put(SSL_ISSUED_BY_ORGANIZATION, sslIssuedByOrganization);
364         domainContentValues.put(SSL_ISSUED_BY_ORGANIZATIONAL_UNIT, sslIssuedByOrganizationalUnit);
365         domainContentValues.put(SSL_START_DATE, sslStartDate);
366         domainContentValues.put(SSL_END_DATE, sslEndDate);
367
368         // Get a writable database handle.
369         SQLiteDatabase domainsDatabase = this.getWritableDatabase();
370
371         // Update the row for `databaseId`.  The last argument is `null` because there are no `whereArgs`.
372         domainsDatabase.update(DOMAINS_TABLE, domainContentValues, _ID + " = " + databaseId, null);
373
374         // Close the database handle.
375         domainsDatabase.close();
376     }
377
378     public void updateCertificate(int databaseId, String sslIssuedToCommonName, String sslIssuedToOrganization, String sslIssuedToOrganizationalUnit, String sslIssuedByCommonName,
379                                   String sslIssuedByOrganization, String sslIssuedByOrganizationalUnit, long sslStartDate, long sslEndDate) {
380         // Store the domain data in a `ContentValues`.
381         ContentValues domainContentValues = new ContentValues();
382
383         // Add entries for each field in the certificate.
384         domainContentValues.put(SSL_ISSUED_TO_COMMON_NAME, sslIssuedToCommonName);
385         domainContentValues.put(SSL_ISSUED_TO_ORGANIZATION, sslIssuedToOrganization);
386         domainContentValues.put(SSL_ISSUED_TO_ORGANIZATIONAL_UNIT, sslIssuedToOrganizationalUnit);
387         domainContentValues.put(SSL_ISSUED_BY_COMMON_NAME, sslIssuedByCommonName);
388         domainContentValues.put(SSL_ISSUED_BY_ORGANIZATION, sslIssuedByOrganization);
389         domainContentValues.put(SSL_ISSUED_BY_ORGANIZATIONAL_UNIT, sslIssuedByOrganizationalUnit);
390         domainContentValues.put(SSL_START_DATE, sslStartDate);
391         domainContentValues.put(SSL_END_DATE, sslEndDate);
392
393         // Get a writable database handle.
394         SQLiteDatabase domainsDatabase = this.getWritableDatabase();
395
396         // Update the row for `databaseId`.  The last argument is `null` because there are no `whereArgs`.
397         domainsDatabase.update(DOMAINS_TABLE, domainContentValues, _ID + " = " + databaseId, null);
398
399         // Close the database handle.
400         domainsDatabase.close();
401     }
402
403     public void deleteDomain(int databaseId) {
404         // Get a writable database handle.
405         SQLiteDatabase domainsDatabase = this.getWritableDatabase();
406
407         // Delete the row for `databaseId`.  The last argument is `null` because we don't need additional parameters.
408         domainsDatabase.delete(DOMAINS_TABLE, _ID + " = " + databaseId, null);
409
410         // Close the database handle.
411         domainsDatabase.close();
412     }
413 }