2 * Copyright © 2017-2020 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
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.
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.
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/>.
20 package com.stoutner.privacybrowser.helpers;
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;
30 public class DomainsDatabaseHelper extends SQLiteOpenHelper {
31 private static final int SCHEMA_VERSION = 12;
32 static final String DOMAINS_DATABASE = "domains.db";
33 static final String DOMAINS_TABLE = "domains";
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"; // Form data can be removed once the minimum API >= 26.
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 ULTRALIST = "ultralist";
47 public static final String ENABLE_ULTRAPRIVACY = "enableultraprivacy";
48 public static final String BLOCK_ALL_THIRD_PARTY_REQUESTS = "blockallthirdpartyrequests";
49 public static final String USER_AGENT = "useragent";
50 public static final String FONT_SIZE = "fontsize";
51 public static final String SWIPE_TO_REFRESH = "swipetorefresh";
52 public static final String WEBVIEW_THEME = "webview_theme";
53 public static final String WIDE_VIEWPORT = "wide_viewport";
54 public static final String DISPLAY_IMAGES = "displayimages";
55 public static final String PINNED_SSL_CERTIFICATE = "pinnedsslcertificate";
56 public static final String SSL_ISSUED_TO_COMMON_NAME = "sslissuedtocommonname";
57 public static final String SSL_ISSUED_TO_ORGANIZATION = "sslissuedtoorganization";
58 public static final String SSL_ISSUED_TO_ORGANIZATIONAL_UNIT = "sslissuedtoorganizationalunit";
59 public static final String SSL_ISSUED_BY_COMMON_NAME = "sslissuedbycommonname";
60 public static final String SSL_ISSUED_BY_ORGANIZATION = "sslissuedbyorganization";
61 public static final String SSL_ISSUED_BY_ORGANIZATIONAL_UNIT = "sslissuedbyorganizationalunit";
62 public static final String SSL_START_DATE = "sslstartdate";
63 public static final String SSL_END_DATE = "sslenddate";
64 public static final String PINNED_IP_ADDRESSES = "pinned_ip_addresses";
65 public static final String IP_ADDRESSES = "ip_addresses";
68 public static final int SYSTEM_DEFAULT = 0;
69 public static final int ENABLED = 1;
70 public static final int DISABLED = 2;
71 public static final int LIGHT_THEME = 1;
72 public static final int DARK_THEME = 2;
74 static final String CREATE_DOMAINS_TABLE = "CREATE TABLE " + DOMAINS_TABLE + " (" +
75 _ID + " INTEGER PRIMARY KEY, " +
76 DOMAIN_NAME + " TEXT, " +
77 ENABLE_JAVASCRIPT + " BOOLEAN, " +
78 ENABLE_FIRST_PARTY_COOKIES + " BOOLEAN, " +
79 ENABLE_THIRD_PARTY_COOKIES + " BOOLEAN, " +
80 ENABLE_DOM_STORAGE + " BOOLEAN, " +
81 ENABLE_FORM_DATA + " BOOLEAN, " +
82 ENABLE_EASYLIST + " BOOLEAN, " +
83 ENABLE_EASYPRIVACY + " BOOLEAN, " +
84 ENABLE_FANBOYS_ANNOYANCE_LIST + " BOOLEAN, " +
85 ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST + " BOOLEAN, " +
86 ULTRALIST + " BOOLEAN, " +
87 ENABLE_ULTRAPRIVACY + " BOOLEAN, " +
88 BLOCK_ALL_THIRD_PARTY_REQUESTS + " BOOLEAN, " +
89 USER_AGENT + " TEXT, " +
90 FONT_SIZE + " INTEGER, " +
91 SWIPE_TO_REFRESH + " INTEGER, " +
92 WEBVIEW_THEME + " INTEGER, " +
93 WIDE_VIEWPORT + " INTEGER, " +
94 DISPLAY_IMAGES + " INTEGER, " +
95 PINNED_SSL_CERTIFICATE + " BOOLEAN, " +
96 SSL_ISSUED_TO_COMMON_NAME + " TEXT, " +
97 SSL_ISSUED_TO_ORGANIZATION + " TEXT, " +
98 SSL_ISSUED_TO_ORGANIZATIONAL_UNIT + " TEXT, " +
99 SSL_ISSUED_BY_COMMON_NAME + " TEXT, " +
100 SSL_ISSUED_BY_ORGANIZATION + " TEXT, " +
101 SSL_ISSUED_BY_ORGANIZATIONAL_UNIT + " TEXT, " +
102 SSL_START_DATE + " INTEGER, " +
103 SSL_END_DATE + " INTEGER, " +
104 PINNED_IP_ADDRESSES + " BOOLEAN, " +
105 IP_ADDRESSES + " TEXT)";
107 private final Context appContext;
109 // Initialize the database. The lint warnings for the unused parameters are suppressed.
110 public DomainsDatabaseHelper(Context context, @SuppressWarnings("UnusedParameters") String name, SQLiteDatabase.CursorFactory cursorFactory, @SuppressWarnings("UnusedParameters") int version) {
111 super(context, DOMAINS_DATABASE, cursorFactory, SCHEMA_VERSION);
113 // Store a handle for the context.
114 appContext = context;
118 public void onCreate(SQLiteDatabase domainsDatabase) {
119 // Create the domains table.
120 domainsDatabase.execSQL(CREATE_DOMAINS_TABLE);
124 public void onUpgrade(SQLiteDatabase domainsDatabase, int oldVersion, int newVersion) {
125 // Upgrade the database table.
126 switch (oldVersion) {
127 // Upgrade from schema version 1.
129 // Add the display images column.
130 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + DISPLAY_IMAGES + " INTEGER");
132 // Upgrade from schema version 2.
134 // Add the SSL certificate columns.
135 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + PINNED_SSL_CERTIFICATE + " BOOLEAN");
136 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_ISSUED_TO_COMMON_NAME + " TEXT");
137 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_ISSUED_TO_ORGANIZATION + " TEXT");
138 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_ISSUED_TO_ORGANIZATIONAL_UNIT + " TEXT");
139 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_ISSUED_BY_COMMON_NAME + " TEXT");
140 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_ISSUED_BY_ORGANIZATION + " TEXT");
141 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_ISSUED_BY_ORGANIZATIONAL_UNIT + " TEXT");
142 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_START_DATE + " INTEGER");
143 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SSL_END_DATE + " INTEGER");
145 // Upgrade from schema version 3.
147 // Add the night mode column.
148 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN nightmode INTEGER");
150 // Upgrade from schema version 4.
152 // Add the block lists columns.
153 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + ENABLE_EASYLIST + " BOOLEAN");
154 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + ENABLE_EASYPRIVACY + " BOOLEAN");
155 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + ENABLE_FANBOYS_ANNOYANCE_LIST + " BOOLEAN");
156 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST + " BOOLEAN");
158 // Get a handle for the shared preference.
159 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext);
161 // Get the default block list settings.
162 boolean easyListEnabled = sharedPreferences.getBoolean("easylist", true);
163 boolean easyPrivacyEnabled = sharedPreferences.getBoolean("easyprivacy", true);
164 boolean fanboyAnnoyanceListEnabled = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
165 boolean fanboySocialBlockingListEnabled = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
167 // Set EasyList for existing rows according to the current system-wide default.
168 if (easyListEnabled) {
169 domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_EASYLIST + " = " + 1);
171 domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_EASYLIST + " = " + 0);
174 // Set EasyPrivacy for existing rows according to the current system-wide default.
175 if (easyPrivacyEnabled) {
176 domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_EASYPRIVACY + " = " + 1);
178 domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_EASYPRIVACY + " = " + 0);
181 // Set Fanboy's Annoyance List for existing rows according to the current system-wide default.
182 if (fanboyAnnoyanceListEnabled) {
183 domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_FANBOYS_ANNOYANCE_LIST + " = " + 1);
185 domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_FANBOYS_ANNOYANCE_LIST + " = " + 0);
188 // Set Fanboy's Social Blocking List for existing rows according to the current system-wide default.
189 if (fanboySocialBlockingListEnabled) {
190 domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST + " = " + 1);
192 domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST + " = " + 0);
195 // Upgrade from schema version 5.
197 // Add the swipe to refresh column. This defaults to `0`, which is `System default`, so a separate step isn't needed to populate the column.
198 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SWIPE_TO_REFRESH + " INTEGER");
200 // Upgrade from schema version 6.
202 // Add the block all third-party requests column. This defaults to `0`, which is off, so a separate step isn't needed to populate the column.
203 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + BLOCK_ALL_THIRD_PARTY_REQUESTS + " BOOLEAN");
205 // Upgrade from schema version 7.
207 // Add the UltraPrivacy column.
208 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + ENABLE_ULTRAPRIVACY + " BOOLEAN");
210 // Enable it for all existing rows.
211 domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_ULTRAPRIVACY + " = " + 1);
213 // Upgrade from schema version 8.
215 // Add the pinned IP addresses columns. These default to `0` and `""`, so a separate step isn't needed to populate the columns.
216 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + PINNED_IP_ADDRESSES + " BOOLEAN");
217 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + IP_ADDRESSES + " TEXT");
219 // Upgrade from schema version 9.
221 // Add the wide viewport column. This defaults to `0`, which is `System default`, so a separate step isn't needed to populate the column.
222 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + WIDE_VIEWPORT + " INTEGER");
224 // Upgrade from schema version 10.
226 // Add the UltraList column.
227 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + ULTRALIST + " BOOLEAN");
229 // Enable it for all existing rows.
230 domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ULTRALIST + " = " + 1);
232 // Upgrade from schema version 11.
234 // Add the WebView theme column. This defaults to `0`, which is `System default`, so a separate step isn't needed to populate the column.
235 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + WEBVIEW_THEME + " INTEGER");
237 // SQLite amazingly doesn't include an easy command to delete a column. <https://www.sqlite.org/lang_altertable.html>
238 // Although a new table could be created and all the data copied to it, I think I will just leave the old night mode column. It will be wiped out the next time an import is run.
242 Cursor getCompleteCursorOrderedByDomain() {
243 // Get a readable database handle.
244 SQLiteDatabase domainsDatabase = this.getReadableDatabase();
246 // Return everything in the domains table ordered by the domain name. The second argument is `null` because there are no `selectionArgs`.
247 return domainsDatabase.rawQuery("SELECT * FROM " + DOMAINS_TABLE + " ORDER BY " + DOMAIN_NAME + " ASC", null);
250 public Cursor getDomainNameCursorOrderedByDomain() {
251 // Get a readable database handle.
252 SQLiteDatabase domainsDatabase = this.getReadableDatabase();
254 // Get everything in the domains table ordered by the domain name.
255 String GET_CURSOR_ORDERED_BY_DOMAIN = "SELECT " + _ID + ", " + DOMAIN_NAME +
256 " FROM " + DOMAINS_TABLE +
257 " ORDER BY " + DOMAIN_NAME + " ASC";
259 // Return the results as a `Cursor`. The second argument is `null` because there are no `selectionArgs`. The cursor can't be closed because it is needed in the calling activity.
260 return domainsDatabase.rawQuery(GET_CURSOR_ORDERED_BY_DOMAIN, null);
263 public Cursor getDomainNameCursorOrderedByDomainExcept(int databaseId) {
264 // Get a readable database handle.
265 SQLiteDatabase domainsDatabase = this.getReadableDatabase();
267 // Prepare the SQL statement to select all rows except that with `databaseId`.
268 String GET_CURSOR_ORDERED_BY_DOMAIN_EXCEPT = "SELECT " + _ID + ", " + DOMAIN_NAME +
269 " FROM " + DOMAINS_TABLE +
270 " WHERE " + _ID + " IS NOT " + databaseId +
271 " ORDER BY " + DOMAIN_NAME + " ASC";
273 // Return the results as a `Cursor`. The second argument is `null` because there are no `selectionArgs`. The cursor can't be closed because it is needed in the calling activity.
274 return domainsDatabase.rawQuery(GET_CURSOR_ORDERED_BY_DOMAIN_EXCEPT, null);
277 public Cursor getCursorForId(int databaseId) {
278 // Get a readable database handle.
279 SQLiteDatabase domainsDatabase = this.getReadableDatabase();
281 // Prepare the SQL statement to get the `Cursor` for `databaseId`.
282 String GET_CURSOR_FOR_ID = "SELECT * FROM " + DOMAINS_TABLE +
283 " WHERE " + _ID + " = " + databaseId;
285 // Return the results as a `Cursor`. The second argument is `null` because there are no `selectionArgs`. The cursor can't be closed because it is needed in the calling activity.
286 return domainsDatabase.rawQuery(GET_CURSOR_FOR_ID, null);
289 public Cursor getCursorForDomainName(String domainName) {
290 // Get a readable database handle.
291 SQLiteDatabase domainsDatabase = this.getReadableDatabase();
293 // Return a cursor for the requested domain name.
294 return domainsDatabase.query(DOMAINS_TABLE, null, DOMAIN_NAME + " = " + "\"" + domainName + "\"", null, null, null, null);
298 public int addDomain(String domainName) {
299 // Store the domain data in a `ContentValues`.
300 ContentValues domainContentValues = new ContentValues();
302 // Get a handle for the shared preference.
303 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext);
305 // Get the default settings.
306 boolean javaScript = sharedPreferences.getBoolean("javascript", false);
307 boolean firstPartyCookies = sharedPreferences.getBoolean("first_party_cookies", false);
308 boolean thirdPartyCookies = sharedPreferences.getBoolean("third_party_cookies", false);
309 boolean domStorage = sharedPreferences.getBoolean("dom_storage", false);
310 boolean saveFormData = sharedPreferences.getBoolean("save_form_data", false); // Form data can be removed once the minimum API >= 26.
311 boolean easyList = sharedPreferences.getBoolean("easylist", true);
312 boolean easyPrivacy = sharedPreferences.getBoolean("easyprivacy", true);
313 boolean fanboyAnnoyanceList = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
314 boolean fanboySocialBlockingList = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
315 boolean ultraList = sharedPreferences.getBoolean("ultralist", true);
316 boolean ultraPrivacy = sharedPreferences.getBoolean("ultraprivacy", true);
317 boolean blockAllThirdPartyRequests = sharedPreferences.getBoolean("block_all_third_party_requests", false);
319 // Create entries for the database fields. The ID is created automatically. The pinned SSL certificate information is not created unless added by the user.
320 domainContentValues.put(DOMAIN_NAME, domainName);
321 domainContentValues.put(ENABLE_JAVASCRIPT, javaScript);
322 domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, firstPartyCookies);
323 domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, thirdPartyCookies);
324 domainContentValues.put(ENABLE_DOM_STORAGE, domStorage);
325 domainContentValues.put(ENABLE_FORM_DATA, saveFormData); // Form data can be removed once the minimum API >= 26.
326 domainContentValues.put(ENABLE_EASYLIST, easyList);
327 domainContentValues.put(ENABLE_EASYPRIVACY, easyPrivacy);
328 domainContentValues.put(ENABLE_FANBOYS_ANNOYANCE_LIST, fanboyAnnoyanceList);
329 domainContentValues.put(ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST, fanboySocialBlockingList);
330 domainContentValues.put(ULTRALIST, ultraList);
331 domainContentValues.put(ENABLE_ULTRAPRIVACY, ultraPrivacy);
332 domainContentValues.put(BLOCK_ALL_THIRD_PARTY_REQUESTS, blockAllThirdPartyRequests);
333 domainContentValues.put(USER_AGENT, "System default user agent");
334 domainContentValues.put(FONT_SIZE, 0);
335 domainContentValues.put(SWIPE_TO_REFRESH, 0);
336 domainContentValues.put(WEBVIEW_THEME, 0);
337 domainContentValues.put(WIDE_VIEWPORT, 0);
338 domainContentValues.put(DISPLAY_IMAGES, 0);
340 // Get a writable database handle.
341 SQLiteDatabase domainsDatabase = this.getWritableDatabase();
343 // 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.
344 int newDomainDatabaseId = (int) domainsDatabase.insert(DOMAINS_TABLE, null, domainContentValues);
346 // Close the database handle.
347 domainsDatabase.close();
349 // Return the new domain database ID.
350 return newDomainDatabaseId;
353 void addDomain(ContentValues contentValues) {
354 // Get a writable database handle.
355 SQLiteDatabase domainsDatabase = this.getWritableDatabase();
357 // Add the new domain.
358 domainsDatabase.insert(DOMAINS_TABLE, null, contentValues);
360 // Close the database handle.
361 domainsDatabase.close();
364 public void updateDomain(int databaseId, String domainName, boolean javaScript, boolean firstPartyCookies, boolean thirdPartyCookies, boolean domStorage, boolean formData, boolean easyList,
365 boolean easyPrivacy, boolean fanboysAnnoyance, boolean fanboysSocialBlocking, boolean ultraList, boolean ultraPrivacy, boolean blockAllThirdPartyRequests, String userAgent,
366 int fontSize, int swipeToRefresh, int webViewTheme, int wideViewport, int displayImages, boolean pinnedSslCertificate, boolean pinnedIpAddresses) {
368 // Store the domain data in a `ContentValues`.
369 ContentValues domainContentValues = new ContentValues();
371 // Add entries for each field in the database.
372 domainContentValues.put(DOMAIN_NAME, domainName);
373 domainContentValues.put(ENABLE_JAVASCRIPT, javaScript);
374 domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, firstPartyCookies);
375 domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, thirdPartyCookies);
376 domainContentValues.put(ENABLE_DOM_STORAGE, domStorage);
377 domainContentValues.put(ENABLE_FORM_DATA, formData); // Form data can be removed once the minimum API >= 26.
378 domainContentValues.put(ENABLE_EASYLIST, easyList);
379 domainContentValues.put(ENABLE_EASYPRIVACY, easyPrivacy);
380 domainContentValues.put(ENABLE_FANBOYS_ANNOYANCE_LIST, fanboysAnnoyance);
381 domainContentValues.put(ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST, fanboysSocialBlocking);
382 domainContentValues.put(ULTRALIST, ultraList);
383 domainContentValues.put(ENABLE_ULTRAPRIVACY, ultraPrivacy);
384 domainContentValues.put(BLOCK_ALL_THIRD_PARTY_REQUESTS, blockAllThirdPartyRequests);
385 domainContentValues.put(USER_AGENT, userAgent);
386 domainContentValues.put(FONT_SIZE, fontSize);
387 domainContentValues.put(SWIPE_TO_REFRESH, swipeToRefresh);
388 domainContentValues.put(WEBVIEW_THEME, webViewTheme);
389 domainContentValues.put(WIDE_VIEWPORT, wideViewport);
390 domainContentValues.put(DISPLAY_IMAGES, displayImages);
391 domainContentValues.put(PINNED_SSL_CERTIFICATE, pinnedSslCertificate);
392 domainContentValues.put(PINNED_IP_ADDRESSES, pinnedIpAddresses);
394 // Get a writable database handle.
395 SQLiteDatabase domainsDatabase = this.getWritableDatabase();
397 // Update the row for `databaseId`. The last argument is `null` because there are no `whereArgs`.
398 domainsDatabase.update(DOMAINS_TABLE, domainContentValues, _ID + " = " + databaseId, null);
400 // Close the database handle.
401 domainsDatabase.close();
404 public void updatePinnedSslCertificate(int databaseId, String sslIssuedToCommonName, String sslIssuedToOrganization, String sslIssuedToOrganizationalUnit, String sslIssuedByCommonName,
405 String sslIssuedByOrganization, String sslIssuedByOrganizationalUnit, long sslStartDate, long sslEndDate) {
407 // Store the pinned SSL certificate in a content values.
408 ContentValues pinnedSslCertificateContentValues = new ContentValues();
410 // Add entries for each field in the certificate.
411 pinnedSslCertificateContentValues.put(SSL_ISSUED_TO_COMMON_NAME, sslIssuedToCommonName);
412 pinnedSslCertificateContentValues.put(SSL_ISSUED_TO_ORGANIZATION, sslIssuedToOrganization);
413 pinnedSslCertificateContentValues.put(SSL_ISSUED_TO_ORGANIZATIONAL_UNIT, sslIssuedToOrganizationalUnit);
414 pinnedSslCertificateContentValues.put(SSL_ISSUED_BY_COMMON_NAME, sslIssuedByCommonName);
415 pinnedSslCertificateContentValues.put(SSL_ISSUED_BY_ORGANIZATION, sslIssuedByOrganization);
416 pinnedSslCertificateContentValues.put(SSL_ISSUED_BY_ORGANIZATIONAL_UNIT, sslIssuedByOrganizationalUnit);
417 pinnedSslCertificateContentValues.put(SSL_START_DATE, sslStartDate);
418 pinnedSslCertificateContentValues.put(SSL_END_DATE, sslEndDate);
420 // Get a writable database handle.
421 SQLiteDatabase domainsDatabase = this.getWritableDatabase();
423 // Update the row for database ID.
424 domainsDatabase.update(DOMAINS_TABLE, pinnedSslCertificateContentValues, _ID + " = " + databaseId, null);
426 // Close the database handle.
427 domainsDatabase.close();
430 public void updatePinnedIpAddresses(int databaseId, String ipAddresses) {
431 // Store the pinned IP addresses in a content values.
432 ContentValues pinnedIpAddressesContentValues = new ContentValues();
434 // Add the IP addresses to the content values.
435 pinnedIpAddressesContentValues.put(IP_ADDRESSES, ipAddresses);
437 // Get a writable database handle.
438 SQLiteDatabase domainsDatabase = this.getWritableDatabase();
440 // Update the row for the database ID.
441 domainsDatabase.update(DOMAINS_TABLE, pinnedIpAddressesContentValues, _ID + " = " + databaseId, null);
443 // Close the database handle.
444 domainsDatabase.close();
447 public void deleteDomain(int databaseId) {
448 // Get a writable database handle.
449 SQLiteDatabase domainsDatabase = this.getWritableDatabase();
451 // Delete the row for `databaseId`. The last argument is `null` because we don't need additional parameters.
452 domainsDatabase.delete(DOMAINS_TABLE, _ID + " = " + databaseId, null);
454 // Close the database handle.
455 domainsDatabase.close();