2 * Copyright © 2017-2018 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 = 6;
32 private static final String DOMAINS_DATABASE = "domains.db";
33 private 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 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";
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;
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;
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;
76 private Context appContext;
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);
82 // Store a handle for the context.
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);";
117 domainsDatabase.execSQL(CREATE_DOMAINS_TABLE);
121 public void onUpgrade(SQLiteDatabase domainsDatabase, int oldVersion, int newVersion) {
122 // Upgrade the database table.
123 switch (oldVersion) {
124 // Upgrade from schema version 1.
126 // Add the display images column.
127 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + DISPLAY_IMAGES + " INTEGER");
129 // Upgrade from schema version 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");
142 // Upgrade from schema version 3.
144 // Add the Night Mode column.
145 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + NIGHT_MODE + " INTEGER");
147 // Upgrade from schema version 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");
155 // Get a handle for the shared preference.
156 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext);
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);
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);
168 domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_EASYLIST + " = " + 0);
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);
175 domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_EASYPRIVACY + " = " + 0);
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);
182 domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_FANBOYS_ANNOYANCE_LIST + " = " + 0);
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);
189 domainsDatabase.execSQL("UPDATE " + DOMAINS_TABLE + " SET " + ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST + " = " + 0);
192 // Upgrade from schema version 5.
194 // Add the swipe to refresh column.
195 domainsDatabase.execSQL("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + SWIPE_TO_REFRESH + " INTEGER");
199 public Cursor getDomainNameCursorOrderedByDomain() {
200 // Get a readable database handle.
201 SQLiteDatabase domainsDatabase = this.getReadableDatabase();
203 // Get everything in `DOMAINS_TABLE` ordered by `DOMAIN_NAME`.
204 String GET_CURSOR_ORDERED_BY_DOMAIN = "SELECT " + _ID + ", " + DOMAIN_NAME +
205 " FROM " + DOMAINS_TABLE +
206 " ORDER BY " + DOMAIN_NAME + " ASC";
208 // 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.
209 return domainsDatabase.rawQuery(GET_CURSOR_ORDERED_BY_DOMAIN, null);
212 public Cursor getDomainNameCursorOrderedByDomainExcept(int databaseId) {
213 // Get a readable database handle.
214 SQLiteDatabase domainsDatabase = this.getReadableDatabase();
216 // Prepare the SQL statement to select all rows except that with `databaseId`.
217 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";
222 // 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.
223 return domainsDatabase.rawQuery(GET_CURSOR_ORDERED_BY_DOMAIN_EXCEPT, null);
226 public Cursor getCursorForId(int databaseId) {
227 // Get a readable database handle.
228 SQLiteDatabase domainsDatabase = this.getReadableDatabase();
230 // Prepare the SQL statement to get the `Cursor` for `databaseId`.
231 String GET_CURSOR_FOR_ID = "SELECT * FROM " + DOMAINS_TABLE +
232 " WHERE " + _ID + " = " + databaseId;
234 // 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.
235 return domainsDatabase.rawQuery(GET_CURSOR_FOR_ID, null);
238 public Cursor getCursorForDomainName(String domainName) {
239 // Get a readable database handle.
240 SQLiteDatabase domainsDatabase = this.getReadableDatabase();
242 // Return a cursor for the requested domain name.
243 return domainsDatabase.query(DOMAINS_TABLE, null, DOMAIN_NAME + " = " + "\"" + domainName + "\"", null, null, null, null);
247 public int addDomain(String domainName) {
248 // Store the domain data in a `ContentValues`.
249 ContentValues domainContentValues = new ContentValues();
251 // Get a handle for the shared preference.
252 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext);
254 // Get the default settings.
255 boolean javaScriptEnabled = sharedPreferences.getBoolean("javascript_enabled", false);
256 boolean firstPartyCookiesEnabled = sharedPreferences.getBoolean("first_party_cookies_enabled", false);
257 boolean thirdPartyCookiesEnabled = sharedPreferences.getBoolean("third_party_cookies_enabled", false);
258 boolean domStorageEnabled = sharedPreferences.getBoolean("dom_storage_enabled", false);
259 boolean saveFormDataEnabled = sharedPreferences.getBoolean("save_form_data_enabled", false); // Form data can be removed once the minimum API >= 26.
260 boolean easyListEnabled = sharedPreferences.getBoolean("easylist", true);
261 boolean easyPrivacyEnabled = sharedPreferences.getBoolean("easyprivacy", true);
262 boolean fanboyAnnoyanceListEnabled = sharedPreferences.getBoolean("fanboy_annoyance_list", true);
263 boolean fanboySocialBlockingListEnabled = sharedPreferences.getBoolean("fanboy_social_blocking_list", true);
265 // Create entries for the database fields. The ID is created automatically. The pinned SSL certificate information is not created unless added by the user.
266 domainContentValues.put(DOMAIN_NAME, domainName);
267 domainContentValues.put(ENABLE_JAVASCRIPT, javaScriptEnabled);
268 domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, firstPartyCookiesEnabled);
269 domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, thirdPartyCookiesEnabled);
270 domainContentValues.put(ENABLE_DOM_STORAGE, domStorageEnabled);
271 domainContentValues.put(ENABLE_FORM_DATA, saveFormDataEnabled); // Form data can be removed once the minimum API >= 26.
272 domainContentValues.put(ENABLE_EASYLIST, easyListEnabled);
273 domainContentValues.put(ENABLE_EASYPRIVACY, easyPrivacyEnabled);
274 domainContentValues.put(ENABLE_FANBOYS_ANNOYANCE_LIST, fanboyAnnoyanceListEnabled);
275 domainContentValues.put(ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST, fanboySocialBlockingListEnabled);
276 domainContentValues.put(USER_AGENT, "System default user agent");
277 domainContentValues.put(FONT_SIZE, 0);
278 domainContentValues.put(SWIPE_TO_REFRESH, 0);
279 domainContentValues.put(NIGHT_MODE, 0);
280 domainContentValues.put(DISPLAY_IMAGES, 0);
282 // Get a writable database handle.
283 SQLiteDatabase domainsDatabase = this.getWritableDatabase();
285 // 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.
286 int newDomainDatabaseId = (int) domainsDatabase.insert(DOMAINS_TABLE, null, domainContentValues);
288 // Close the database handle.
289 domainsDatabase.close();
291 // Return the new domain database ID.
292 return newDomainDatabaseId;
295 public void updateDomainExceptCertificate(int databaseId, String domainName, boolean javaScriptEnabled, boolean firstPartyCookiesEnabled, boolean thirdPartyCookiesEnabled, boolean domStorageEnabled,
296 boolean formDataEnabled, boolean easyListEnabled, boolean easyPrivacyEnabled, boolean fanboysAnnoyanceEnabled, boolean fanboysSocialBlockingEnabled,
297 String userAgent, int fontSize, int swipeToRefresh, int nightMode, int displayImages, boolean pinnedSslCertificate) {
299 // Store the domain data in a `ContentValues`.
300 ContentValues domainContentValues = new ContentValues();
302 // Add entries for each field in the database.
303 domainContentValues.put(DOMAIN_NAME, domainName);
304 domainContentValues.put(ENABLE_JAVASCRIPT, javaScriptEnabled);
305 domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, firstPartyCookiesEnabled);
306 domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, thirdPartyCookiesEnabled);
307 domainContentValues.put(ENABLE_DOM_STORAGE, domStorageEnabled);
308 domainContentValues.put(ENABLE_FORM_DATA, formDataEnabled); // Form data can be removed once the minimum API >= 26.
309 domainContentValues.put(ENABLE_EASYLIST, easyListEnabled);
310 domainContentValues.put(ENABLE_EASYPRIVACY, easyPrivacyEnabled);
311 domainContentValues.put(ENABLE_FANBOYS_ANNOYANCE_LIST, fanboysAnnoyanceEnabled);
312 domainContentValues.put(ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST, fanboysSocialBlockingEnabled);
313 domainContentValues.put(USER_AGENT, userAgent);
314 domainContentValues.put(FONT_SIZE, fontSize);
315 domainContentValues.put(SWIPE_TO_REFRESH, swipeToRefresh);
316 domainContentValues.put(NIGHT_MODE, nightMode);
317 domainContentValues.put(DISPLAY_IMAGES, displayImages);
318 domainContentValues.put(PINNED_SSL_CERTIFICATE, pinnedSslCertificate);
320 // Get a writable database handle.
321 SQLiteDatabase domainsDatabase = this.getWritableDatabase();
323 // Update the row for `databaseId`. The last argument is `null` because there are no `whereArgs`.
324 domainsDatabase.update(DOMAINS_TABLE, domainContentValues, _ID + " = " + databaseId, null);
326 // Close the database handle.
327 domainsDatabase.close();
330 public void updateDomainWithCertificate(int databaseId, String domainName, boolean javaScriptEnabled, boolean firstPartyCookiesEnabled, boolean thirdPartyCookiesEnabled, boolean domStorageEnabled,
331 boolean formDataEnabled, boolean easyListEnabled, boolean easyPrivacyEnabled, boolean fanboysAnnoyanceEnabled, boolean fanboysSocialBlockingEnabled, String userAgent,
332 int fontSize, int swipeToRefresh, int nightMode, int displayImages, boolean pinnedSslCertificate, String sslIssuedToCommonName, String sslIssuedToOrganization,
333 String sslIssuedToOrganizationalUnit, String sslIssuedByCommonName, String sslIssuedByOrganization, String sslIssuedByOrganizationalUnit, long sslStartDate,
336 // Store the domain data in a `ContentValues`.
337 ContentValues domainContentValues = new ContentValues();
339 // Add entries for each field in the database.
340 domainContentValues.put(DOMAIN_NAME, domainName);
341 domainContentValues.put(ENABLE_JAVASCRIPT, javaScriptEnabled);
342 domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, firstPartyCookiesEnabled);
343 domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, thirdPartyCookiesEnabled);
344 domainContentValues.put(ENABLE_DOM_STORAGE, domStorageEnabled);
345 domainContentValues.put(ENABLE_FORM_DATA, formDataEnabled); // Form data can be removed once the minimum API >= 26.
346 domainContentValues.put(ENABLE_EASYLIST, easyListEnabled);
347 domainContentValues.put(ENABLE_EASYPRIVACY, easyPrivacyEnabled);
348 domainContentValues.put(ENABLE_FANBOYS_ANNOYANCE_LIST, fanboysAnnoyanceEnabled);
349 domainContentValues.put(ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST, fanboysSocialBlockingEnabled);
350 domainContentValues.put(USER_AGENT, userAgent);
351 domainContentValues.put(FONT_SIZE, fontSize);
352 domainContentValues.put(SWIPE_TO_REFRESH, swipeToRefresh);
353 domainContentValues.put(NIGHT_MODE, nightMode);
354 domainContentValues.put(DISPLAY_IMAGES, displayImages);
355 domainContentValues.put(PINNED_SSL_CERTIFICATE, pinnedSslCertificate);
356 domainContentValues.put(SSL_ISSUED_TO_COMMON_NAME, sslIssuedToCommonName);
357 domainContentValues.put(SSL_ISSUED_TO_ORGANIZATION, sslIssuedToOrganization);
358 domainContentValues.put(SSL_ISSUED_TO_ORGANIZATIONAL_UNIT, sslIssuedToOrganizationalUnit);
359 domainContentValues.put(SSL_ISSUED_BY_COMMON_NAME, sslIssuedByCommonName);
360 domainContentValues.put(SSL_ISSUED_BY_ORGANIZATION, sslIssuedByOrganization);
361 domainContentValues.put(SSL_ISSUED_BY_ORGANIZATIONAL_UNIT, sslIssuedByOrganizationalUnit);
362 domainContentValues.put(SSL_START_DATE, sslStartDate);
363 domainContentValues.put(SSL_END_DATE, sslEndDate);
365 // Get a writable database handle.
366 SQLiteDatabase domainsDatabase = this.getWritableDatabase();
368 // Update the row for `databaseId`. The last argument is `null` because there are no `whereArgs`.
369 domainsDatabase.update(DOMAINS_TABLE, domainContentValues, _ID + " = " + databaseId, null);
371 // Close the database handle.
372 domainsDatabase.close();
375 public void updateCertificate(int databaseId, String sslIssuedToCommonName, String sslIssuedToOrganization, String sslIssuedToOrganizationalUnit, String sslIssuedByCommonName,
376 String sslIssuedByOrganization, String sslIssuedByOrganizationalUnit, long sslStartDate, long sslEndDate) {
377 // Store the domain data in a `ContentValues`.
378 ContentValues domainContentValues = new ContentValues();
380 // Add entries for each field in the certificate.
381 domainContentValues.put(SSL_ISSUED_TO_COMMON_NAME, sslIssuedToCommonName);
382 domainContentValues.put(SSL_ISSUED_TO_ORGANIZATION, sslIssuedToOrganization);
383 domainContentValues.put(SSL_ISSUED_TO_ORGANIZATIONAL_UNIT, sslIssuedToOrganizationalUnit);
384 domainContentValues.put(SSL_ISSUED_BY_COMMON_NAME, sslIssuedByCommonName);
385 domainContentValues.put(SSL_ISSUED_BY_ORGANIZATION, sslIssuedByOrganization);
386 domainContentValues.put(SSL_ISSUED_BY_ORGANIZATIONAL_UNIT, sslIssuedByOrganizationalUnit);
387 domainContentValues.put(SSL_START_DATE, sslStartDate);
388 domainContentValues.put(SSL_END_DATE, sslEndDate);
390 // Get a writable database handle.
391 SQLiteDatabase domainsDatabase = this.getWritableDatabase();
393 // Update the row for `databaseId`. The last argument is `null` because there are no `whereArgs`.
394 domainsDatabase.update(DOMAINS_TABLE, domainContentValues, _ID + " = " + databaseId, null);
396 // Close the database handle.
397 domainsDatabase.close();
400 public void deleteDomain(int databaseId) {
401 // Get a writable database handle.
402 SQLiteDatabase domainsDatabase = this.getWritableDatabase();
404 // Delete the row for `databaseId`. The last argument is `null` because we don't need additional parameters.
405 domainsDatabase.delete(DOMAINS_TABLE, _ID + " = " + databaseId, null);
407 // Close the database handle.
408 domainsDatabase.close();