Implement IP Address Pinning. https://redmine.stoutner.com/issues/212
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / helpers / ImportExportDatabaseHelper.java
1 /*
2  * Copyright © 2018-2019 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.preference.PreferenceManager;
28
29 import com.stoutner.privacybrowser.R;
30
31 import java.io.File;
32 import java.io.FileInputStream;
33 import java.io.FileOutputStream;
34 import java.io.InputStream;
35 import java.io.OutputStream;
36
37 public class ImportExportDatabaseHelper {
38     public static final String EXPORT_SUCCESSFUL = "Export Successful";
39     public static final String IMPORT_SUCCESSFUL = "Import Successful";
40
41     private static final int SCHEMA_VERSION = 4;
42     private static final String PREFERENCES_TABLE = "preferences";
43
44     // The preferences constants.
45     private static final String _ID = "_id";
46     private static final String JAVASCRIPT = "javascript";
47     private static final String FIRST_PARTY_COOKIES = "first_party_cookies";
48     private static final String THIRD_PARTY_COOKIES = "third_party_cookies";
49     private static final String DOM_STORAGE = "dom_storage";
50     private static final String SAVE_FORM_DATA = "save_form_data";
51     private static final String USER_AGENT = "user_agent";
52     private static final String CUSTOM_USER_AGENT = "custom_user_agent";
53     private static final String INCOGNITO_MODE = "incognito_mode";
54     private static final String DO_NOT_TRACK = "do_not_track";
55     private static final String ALLOW_SCREENSHOTS = "allow_screenshots";
56     private static final String EASYLIST = "easylist";
57     private static final String EASYPRIVACY = "easyprivacy";
58     private static final String FANBOYS_ANNOYANCE_LIST = "fanboys_annoyance_list";
59     private static final String FANBOYS_SOCIAL_BLOCKING_LIST = "fanboys_social_blocking_list";
60     private static final String ULTRAPRIVACY = "ultraprivacy";
61     private static final String BLOCK_ALL_THIRD_PARTY_REQUESTS = "block_all_third_party_requests";
62     private static final String PROXY_THROUGH_ORBOT = "proxy_through_orbot";
63     private static final String TOR_HOMEPAGE = "tor_homepage";
64     private static final String TOR_SEARCH = "tor_search";
65     private static final String TOR_SEARCH_CUSTOM_URL = "tor_search_custom_url";
66     private static final String SEARCH = "search";
67     private static final String SEARCH_CUSTOM_URL = "search_custom_url";
68     private static final String FULL_SCREEN_BROWSING_MODE = "full_screen_browsing_mode";
69     private static final String HIDE_SYSTEM_BARS = "hide_system_bars";
70     private static final String TRANSLUCENT_NAVIGATION_BAR = "translucent_navigation_bar";
71     private static final String CLEAR_EVERYTHING = "clear_everything";
72     private static final String CLEAR_COOKIES = "clear_cookies";
73     private static final String CLEAR_DOM_STORAGE = "clear_dom_storage";
74     private static final String CLEAR_FORM_DATA = "clear_form_data";
75     private static final String CLEAR_CACHE = "clear_cache";
76     private static final String HOMEPAGE = "homepage";
77     private static final String FONT_SIZE = "font_size";
78     private static final String SWIPE_TO_REFRESH = "swipe_to_refresh";
79     private static final String DOWNLOAD_WITH_EXTERNAL_APP = "download_with_external_app";
80     private static final String DISPLAY_ADDITIONAL_APP_BAR_ICONS = "display_additional_app_bar_icons";
81     private static final String DARK_THEME = "dark_theme";
82     private static final String NIGHT_MODE = "night_mode";
83     private static final String DISPLAY_WEBPAGE_IMAGES = "display_webpage_images";
84
85     public String exportUnencrypted(File exportFile, Context context) {
86         try {
87             // Delete the current file if it exists.
88             if (exportFile.exists()) {
89                 //noinspection ResultOfMethodCallIgnored
90                 exportFile.delete();
91             }
92
93             // Create the export database.
94             SQLiteDatabase exportDatabase = SQLiteDatabase.openOrCreateDatabase(exportFile, null);
95
96             // Set the export database version number.
97             exportDatabase.setVersion(SCHEMA_VERSION);
98
99             // Create the export database domains table.
100             exportDatabase.execSQL(DomainsDatabaseHelper.CREATE_DOMAINS_TABLE);
101
102             // Open the domains database.  The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`.
103             DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(context, null, null, 0);
104
105             // Get a full domains database cursor.
106             Cursor domainsCursor = domainsDatabaseHelper.getCompleteCursorOrderedByDomain();
107
108             // Move to the first domain.
109             domainsCursor.moveToFirst();
110
111             // Copy the data from the domains cursor into the export database.
112             for (int i = 0; i < domainsCursor.getCount(); i++) {
113                 // Extract the record from the cursor and store the data in a ContentValues.
114                 ContentValues domainsContentValues = new ContentValues();
115                 domainsContentValues.put(DomainsDatabaseHelper.DOMAIN_NAME, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME)));
116                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_JAVASCRIPT, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_JAVASCRIPT)));
117                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES)));
118                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES)));
119                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_DOM_STORAGE, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)));
120                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FORM_DATA, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA)));
121                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_EASYLIST, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYLIST)));
122                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_EASYPRIVACY, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYPRIVACY)));
123                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST)));
124                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST)));
125                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY)));
126                 domainsContentValues.put(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS)));
127                 domainsContentValues.put(DomainsDatabaseHelper.USER_AGENT, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.USER_AGENT)));
128                 domainsContentValues.put(DomainsDatabaseHelper.FONT_SIZE, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.FONT_SIZE)));
129                 domainsContentValues.put(DomainsDatabaseHelper.SWIPE_TO_REFRESH, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SWIPE_TO_REFRESH)));
130                 domainsContentValues.put(DomainsDatabaseHelper.NIGHT_MODE, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.NIGHT_MODE)));
131                 domainsContentValues.put(DomainsDatabaseHelper.DISPLAY_IMAGES, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.DISPLAY_IMAGES)));
132                 domainsContentValues.put(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE)));
133                 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME)));
134                 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION)));
135                 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATIONAL_UNIT, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATIONAL_UNIT)));
136                 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_COMMON_NAME, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_COMMON_NAME)));
137                 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATION, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATION)));
138                 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATIONAL_UNIT, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATIONAL_UNIT)));
139                 domainsContentValues.put(DomainsDatabaseHelper.SSL_START_DATE, domainsCursor.getLong(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_START_DATE)));
140                 domainsContentValues.put(DomainsDatabaseHelper.SSL_END_DATE, domainsCursor.getLong(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_END_DATE)));
141                 domainsContentValues.put(DomainsDatabaseHelper.PINNED_IP_ADDRESSES, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_IP_ADDRESSES)));
142                 domainsContentValues.put(DomainsDatabaseHelper.IP_ADDRESSES, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.IP_ADDRESSES)));
143
144                 // Insert the record into the export database.
145                 exportDatabase.insert(DomainsDatabaseHelper.DOMAINS_TABLE, null, domainsContentValues);
146
147                 // Advance to the next record.
148                 domainsCursor.moveToNext();
149             }
150
151             // Close the domains database.
152             domainsCursor.close();
153             domainsDatabaseHelper.close();
154
155
156             // Create the export database bookmarks table.
157             exportDatabase.execSQL(BookmarksDatabaseHelper.CREATE_BOOKMARKS_TABLE);
158
159             // Open the bookmarks database.  The `0` specifies the database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`.
160             BookmarksDatabaseHelper bookmarksDatabaseHelper = new BookmarksDatabaseHelper(context, null, null, 0);
161
162             // Get a full bookmarks cursor.
163             Cursor bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarks();
164
165             // Move to the first bookmark.
166             bookmarksCursor.moveToFirst();
167
168             // Copy the data from the bookmarks cursor into the export database.
169             for (int i = 0; i < bookmarksCursor.getCount(); i++) {
170                 // Extract the record from the cursor and store the data in a ContentValues.
171                 ContentValues bookmarksContentValues = new ContentValues();
172                 bookmarksContentValues.put(BookmarksDatabaseHelper.BOOKMARK_NAME, bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)));
173                 bookmarksContentValues.put(BookmarksDatabaseHelper.BOOKMARK_URL, bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL)));
174                 bookmarksContentValues.put(BookmarksDatabaseHelper.PARENT_FOLDER, bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.PARENT_FOLDER)));
175                 bookmarksContentValues.put(BookmarksDatabaseHelper.DISPLAY_ORDER, bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)));
176                 bookmarksContentValues.put(BookmarksDatabaseHelper.IS_FOLDER, bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)));
177                 bookmarksContentValues.put(BookmarksDatabaseHelper.FAVORITE_ICON, bookmarksCursor.getBlob(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)));
178
179                 // Insert the record into the export database.
180                 exportDatabase.insert(BookmarksDatabaseHelper.BOOKMARKS_TABLE, null, bookmarksContentValues);
181
182                 // Advance to the next record.
183                 bookmarksCursor.moveToNext();
184             }
185
186             // Close the bookmarks database.
187             bookmarksCursor.close();
188             bookmarksDatabaseHelper.close();
189
190
191             // Prepare the preferences table SQL creation string.
192             String CREATE_PREFERENCES_TABLE = "CREATE TABLE " + PREFERENCES_TABLE + " (" +
193                     _ID + " INTEGER PRIMARY KEY, " +
194                     JAVASCRIPT + " BOOLEAN, " +
195                     FIRST_PARTY_COOKIES + " BOOLEAN, " +
196                     THIRD_PARTY_COOKIES + " BOOLEAN, " +
197                     DOM_STORAGE + " BOOLEAN, " +
198                     SAVE_FORM_DATA + " BOOLEAN, " +
199                     USER_AGENT + " TEXT, " +
200                     CUSTOM_USER_AGENT + " TEXT, " +
201                     INCOGNITO_MODE + " BOOLEAN, " +
202                     DO_NOT_TRACK + " BOOLEAN, " +
203                     ALLOW_SCREENSHOTS + " BOOLEAN, " +
204                     EASYLIST + " BOOLEAN, " +
205                     EASYPRIVACY + " BOOLEAN, " +
206                     FANBOYS_ANNOYANCE_LIST + " BOOLEAN, " +
207                     FANBOYS_SOCIAL_BLOCKING_LIST + " BOOLEAN, " +
208                     ULTRAPRIVACY + " BOOLEAN, " +
209                     BLOCK_ALL_THIRD_PARTY_REQUESTS + " BOOLEAN, " +
210                     PROXY_THROUGH_ORBOT + " BOOLEAN, " +
211                     TOR_HOMEPAGE + " TEXT, " +
212                     TOR_SEARCH + " TEXT, " +
213                     TOR_SEARCH_CUSTOM_URL + " TEXT, " +
214                     SEARCH + " TEXT, " +
215                     SEARCH_CUSTOM_URL + " TEXT, " +
216                     FULL_SCREEN_BROWSING_MODE + " BOOLEAN, " +
217                     HIDE_SYSTEM_BARS + " BOOLEAN, " +
218                     TRANSLUCENT_NAVIGATION_BAR + " BOOLEAN, " +
219                     CLEAR_EVERYTHING + " BOOLEAN, " +
220                     CLEAR_COOKIES + " BOOLEAN, " +
221                     CLEAR_DOM_STORAGE + " BOOLEAN, " +
222                     CLEAR_FORM_DATA + " BOOLEAN, " +
223                     CLEAR_CACHE + " BOOLEAN, " +
224                     HOMEPAGE + " TEXT, " +
225                     FONT_SIZE + " TEXT, " +
226                     SWIPE_TO_REFRESH + " BOOLEAN, " +
227                     DOWNLOAD_WITH_EXTERNAL_APP + " BOOLEAN, " +
228                     DISPLAY_ADDITIONAL_APP_BAR_ICONS + " BOOLEAN, " +
229                     DARK_THEME + " BOOLEAN, " +
230                     NIGHT_MODE + " BOOLEAN, " +
231                     DISPLAY_WEBPAGE_IMAGES + " BOOLEAN)";
232
233             // Create the export database preferences table.
234             exportDatabase.execSQL(CREATE_PREFERENCES_TABLE);
235
236             // Get a handle for the shared preference.
237             SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
238
239             // Create a ContentValues with the preferences information.
240             ContentValues preferencesContentValues = new ContentValues();
241             preferencesContentValues.put(JAVASCRIPT, sharedPreferences.getBoolean(JAVASCRIPT, false));
242             preferencesContentValues.put(FIRST_PARTY_COOKIES, sharedPreferences.getBoolean(FIRST_PARTY_COOKIES, false));
243             preferencesContentValues.put(THIRD_PARTY_COOKIES, sharedPreferences.getBoolean(THIRD_PARTY_COOKIES, false));
244             preferencesContentValues.put(DOM_STORAGE, sharedPreferences.getBoolean(DOM_STORAGE, false));
245             preferencesContentValues.put(SAVE_FORM_DATA, sharedPreferences.getBoolean(SAVE_FORM_DATA, false));  // Save form data can be removed once the minimum API >= 26.
246             preferencesContentValues.put(USER_AGENT, sharedPreferences.getString(USER_AGENT, context.getString(R.string.user_agent_default_value)));
247             preferencesContentValues.put(CUSTOM_USER_AGENT, sharedPreferences.getString(CUSTOM_USER_AGENT, context.getString(R.string.custom_user_agent_default_value)));
248             preferencesContentValues.put(INCOGNITO_MODE, sharedPreferences.getBoolean(INCOGNITO_MODE, false));
249             preferencesContentValues.put(DO_NOT_TRACK, sharedPreferences.getBoolean(DO_NOT_TRACK, false));
250             preferencesContentValues.put(ALLOW_SCREENSHOTS, sharedPreferences.getBoolean(ALLOW_SCREENSHOTS, false));
251             preferencesContentValues.put(EASYLIST, sharedPreferences.getBoolean(EASYLIST, true));
252             preferencesContentValues.put(EASYPRIVACY, sharedPreferences.getBoolean(EASYPRIVACY, true));
253             preferencesContentValues.put(FANBOYS_ANNOYANCE_LIST, sharedPreferences.getBoolean(FANBOYS_ANNOYANCE_LIST, true));
254             preferencesContentValues.put(FANBOYS_SOCIAL_BLOCKING_LIST, sharedPreferences.getBoolean(FANBOYS_SOCIAL_BLOCKING_LIST, true));
255             preferencesContentValues.put(ULTRAPRIVACY, sharedPreferences.getBoolean(ULTRAPRIVACY, true));
256             preferencesContentValues.put(BLOCK_ALL_THIRD_PARTY_REQUESTS, sharedPreferences.getBoolean(BLOCK_ALL_THIRD_PARTY_REQUESTS, false));
257             preferencesContentValues.put(PROXY_THROUGH_ORBOT, sharedPreferences.getBoolean(PROXY_THROUGH_ORBOT, false));
258             preferencesContentValues.put(TOR_HOMEPAGE, sharedPreferences.getString(TOR_HOMEPAGE, context.getString(R.string.tor_homepage_default_value)));
259             preferencesContentValues.put(TOR_SEARCH, sharedPreferences.getString(TOR_SEARCH, context.getString(R.string.tor_search_default_value)));
260             preferencesContentValues.put(TOR_SEARCH_CUSTOM_URL, sharedPreferences.getString(TOR_SEARCH_CUSTOM_URL, context.getString(R.string.tor_search_custom_url_default_value)));
261             preferencesContentValues.put(SEARCH, sharedPreferences.getString(SEARCH, context.getString(R.string.search_default_value)));
262             preferencesContentValues.put(SEARCH_CUSTOM_URL, sharedPreferences.getString(SEARCH_CUSTOM_URL, context.getString(R.string.search_custom_url_default_value)));
263             preferencesContentValues.put(FULL_SCREEN_BROWSING_MODE, sharedPreferences.getBoolean(FULL_SCREEN_BROWSING_MODE, false));
264             preferencesContentValues.put(HIDE_SYSTEM_BARS, sharedPreferences.getBoolean(HIDE_SYSTEM_BARS, false));
265             preferencesContentValues.put(TRANSLUCENT_NAVIGATION_BAR, sharedPreferences.getBoolean(TRANSLUCENT_NAVIGATION_BAR, true));
266             preferencesContentValues.put(CLEAR_EVERYTHING, sharedPreferences.getBoolean(CLEAR_EVERYTHING, true));
267             preferencesContentValues.put(CLEAR_COOKIES, sharedPreferences.getBoolean(CLEAR_COOKIES, true));
268             preferencesContentValues.put(CLEAR_DOM_STORAGE, sharedPreferences.getBoolean(CLEAR_DOM_STORAGE, true));
269             preferencesContentValues.put(CLEAR_FORM_DATA, sharedPreferences.getBoolean(CLEAR_FORM_DATA, true));  // Clear form data can be removed once the minimum API >= 26.
270             preferencesContentValues.put(CLEAR_CACHE, sharedPreferences.getBoolean(CLEAR_CACHE, true));
271             preferencesContentValues.put(HOMEPAGE, sharedPreferences.getString(HOMEPAGE, context.getString(R.string.homepage_default_value)));
272             preferencesContentValues.put(FONT_SIZE, sharedPreferences.getString(FONT_SIZE, context.getString(R.string.font_size_default_value)));
273             preferencesContentValues.put(SWIPE_TO_REFRESH, sharedPreferences.getBoolean(SWIPE_TO_REFRESH, true));
274             preferencesContentValues.put(DOWNLOAD_WITH_EXTERNAL_APP, sharedPreferences.getBoolean(DOWNLOAD_WITH_EXTERNAL_APP, false));
275             preferencesContentValues.put(DISPLAY_ADDITIONAL_APP_BAR_ICONS, sharedPreferences.getBoolean(DISPLAY_ADDITIONAL_APP_BAR_ICONS, false));
276             preferencesContentValues.put(DARK_THEME, sharedPreferences.getBoolean(DARK_THEME, false));
277             preferencesContentValues.put(NIGHT_MODE, sharedPreferences.getBoolean(NIGHT_MODE, false));
278             preferencesContentValues.put(DISPLAY_WEBPAGE_IMAGES, sharedPreferences.getBoolean(DISPLAY_WEBPAGE_IMAGES, true));
279
280             // Insert the preferences into the export database.
281             exportDatabase.insert(PREFERENCES_TABLE, null, preferencesContentValues);
282
283             // Close the export database.
284             exportDatabase.close();
285
286             // Convert the database file to a string.
287             String exportFileString = exportFile.toString();
288
289             // Create strings for the temporary database files.
290             String journalFileString = exportFileString + "-journal";
291
292             // Get `Files` for the temporary database files.
293             File journalFile = new File(journalFileString);
294
295             // Delete the Journal file if it exists.
296             if (journalFile.exists()) {
297                 //noinspection ResultOfMethodCallIgnored
298                 journalFile.delete();
299             }
300
301             // Export successful.
302             return EXPORT_SUCCESSFUL;
303         } catch (Exception exception) {
304             // Return the export error.
305             return exception.toString();
306         }
307     }
308
309     public String importUnencrypted(File importFile, Context context){
310         try {
311             // Create a temporary import file string.
312             String temporaryImportFileString = context.getCacheDir() + "/" + "temporary_import_file";
313
314             // Get a handle for a temporary import file.
315             File temporaryImportFile = new File(temporaryImportFileString);
316
317             // Delete the temporary import file if it already exists.
318             if (temporaryImportFile.exists()) {
319                 //noinspection ResultOfMethodCallIgnored
320                 temporaryImportFile.delete();
321             }
322
323             // Create input and output streams.
324             InputStream importFileInputStream = new FileInputStream(importFile);
325             OutputStream temporaryImportFileOutputStream = new FileOutputStream(temporaryImportFile);
326
327             // Create a byte array.
328             byte[] transferByteArray = new byte[1024];
329
330             // Create an integer to track the number of bytes read.
331             int bytesRead;
332
333             // Copy the import file to the temporary import file.  Once the minimum API >= 26 `Files.copy` can be used instead.
334             while ((bytesRead = importFileInputStream.read(transferByteArray)) > 0) {
335                 temporaryImportFileOutputStream.write(transferByteArray, 0, bytesRead);
336             }
337
338             // Close the file streams.
339             importFileInputStream.close();
340             temporaryImportFileOutputStream.close();
341
342
343             // Get a handle for the shared preference.
344             SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
345
346             // Open the import database.  Once the minimum API >= 27 the file can be opened directly without using the string.
347             SQLiteDatabase importDatabase = SQLiteDatabase.openDatabase(temporaryImportFileString, null, SQLiteDatabase.OPEN_READWRITE);
348
349             // Get the database version.
350             int importDatabaseVersion = importDatabase.getVersion();
351
352             // Upgrade the database if needed.
353             if (importDatabaseVersion < SCHEMA_VERSION) {
354                 switch (importDatabaseVersion){
355                     // Upgrade from schema version 1.
356                     case 1:
357                         // Add the download with external app preference.
358                         importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + DOWNLOAD_WITH_EXTERNAL_APP + " BOOLEAN");
359
360                         // Get the current setting for downloading with an external app.
361                         boolean downloadWithExternalApp = sharedPreferences.getBoolean("download_with_external_app", false);
362
363                         // Set the download with external app preference to the current default.
364                         if (downloadWithExternalApp) {
365                             importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + DOWNLOAD_WITH_EXTERNAL_APP + " = " + 1);
366                         } else {
367                             importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + DOWNLOAD_WITH_EXTERNAL_APP + " = " + 0);
368                         }
369
370                     // Upgrade from schema version 2.
371                     case 2:
372                         // Once the SQLite version is >= 3.25.0 `ALTER TABLE RENAME COLUMN` can be used.  https://www.sqlite.org/lang_altertable.html  https://www.sqlite.org/changes.html
373                         // https://developer.android.com/reference/android/database/sqlite/package-summary
374                         // In the meantime, a new column must be created with the new name.  There is no need to delete the old column on the temporary import database.
375
376                         // Get a cursor with the current `default_font_size` value.
377                         Cursor importDatabasePreferenceCursor = importDatabase.rawQuery("SELECT default_font_size FROM " + PREFERENCES_TABLE, null);
378
379                         // Move to the beginning fo the cursor.
380                         importDatabasePreferenceCursor.moveToFirst();
381
382                         // Get the current value in `default_font_size`.
383                         String fontSize = importDatabasePreferenceCursor.getString(importDatabasePreferenceCursor.getColumnIndex("default_font_size"));
384
385                         // Close the cursor.
386                         importDatabasePreferenceCursor.close();
387
388                         // Create a new column named `font_size`.
389                         importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + FONT_SIZE + " TEXT");
390
391                         // Place the font size string in the new column.
392                         importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + FONT_SIZE + " = " + fontSize);
393
394                     case 3:
395                         // Add the Pinned IP Addresses columns.
396                         importDatabase.execSQL("ALTER TABLE " + DomainsDatabaseHelper.DOMAINS_TABLE + " ADD COLUMN " + DomainsDatabaseHelper.PINNED_IP_ADDRESSES + " BOOLEAN");
397                         importDatabase.execSQL("ALTER TABLE " + DomainsDatabaseHelper.DOMAINS_TABLE + " ADD COLUMN " + DomainsDatabaseHelper.IP_ADDRESSES + " TEXT");
398                 }
399             }
400
401             // Get a cursor for the domains table.
402             Cursor importDomainsCursor = importDatabase.rawQuery("SELECT * FROM " + DomainsDatabaseHelper.DOMAINS_TABLE + " ORDER BY " + DomainsDatabaseHelper.DOMAIN_NAME + " ASC", null);
403
404             // Delete the current domains database.
405             context.deleteDatabase(DomainsDatabaseHelper.DOMAINS_DATABASE);
406
407             // Create a new domains database.  The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`.
408             DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(context, null, null, 0);
409
410             // Move to the first domain.
411             importDomainsCursor.moveToFirst();
412
413             // Copy the data from the import domains cursor into the domains database.
414             for (int i = 0; i < importDomainsCursor.getCount(); i++) {
415                 // Extract the record from the cursor and store the data in a ContentValues.
416                 ContentValues domainsContentValues = new ContentValues();
417                 domainsContentValues.put(DomainsDatabaseHelper.DOMAIN_NAME, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME)));
418                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_JAVASCRIPT, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_JAVASCRIPT)));
419                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES)));
420                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES)));
421                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_DOM_STORAGE, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)));
422                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FORM_DATA, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA)));
423                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_EASYLIST, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYLIST)));
424                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_EASYPRIVACY, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYPRIVACY)));
425                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST,
426                         importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST)));
427                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST,
428                         importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST)));
429                 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY)));
430                 domainsContentValues.put(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS,
431                         importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS)));
432                 domainsContentValues.put(DomainsDatabaseHelper.USER_AGENT, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.USER_AGENT)));
433                 domainsContentValues.put(DomainsDatabaseHelper.FONT_SIZE, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.FONT_SIZE)));
434                 domainsContentValues.put(DomainsDatabaseHelper.SWIPE_TO_REFRESH, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SWIPE_TO_REFRESH)));
435                 domainsContentValues.put(DomainsDatabaseHelper.NIGHT_MODE, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.NIGHT_MODE)));
436                 domainsContentValues.put(DomainsDatabaseHelper.DISPLAY_IMAGES, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.DISPLAY_IMAGES)));
437                 domainsContentValues.put(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE)));
438                 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME)));
439                 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION)));
440                 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATIONAL_UNIT,
441                         importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATIONAL_UNIT)));
442                 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_COMMON_NAME, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_COMMON_NAME)));
443                 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATION, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATION)));
444                 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATIONAL_UNIT,
445                         importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATIONAL_UNIT)));
446                 domainsContentValues.put(DomainsDatabaseHelper.SSL_START_DATE, importDomainsCursor.getLong(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_START_DATE)));
447                 domainsContentValues.put(DomainsDatabaseHelper.SSL_END_DATE, importDomainsCursor.getLong(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_END_DATE)));
448                 domainsContentValues.put(DomainsDatabaseHelper.PINNED_IP_ADDRESSES, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_IP_ADDRESSES)));
449                 domainsContentValues.put(DomainsDatabaseHelper.IP_ADDRESSES, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.IP_ADDRESSES)));
450
451                 // Insert the record into the export database.
452                 domainsDatabaseHelper.addDomain(domainsContentValues);
453
454                 // Advance to the next record.
455                 importDomainsCursor.moveToNext();
456             }
457
458             // Close the domains cursor.
459             importDomainsCursor.close();
460
461             // Close the domains database.
462             domainsDatabaseHelper.close();
463
464
465             // Get a cursor for the bookmarks table.
466             Cursor importBookmarksCursor = importDatabase.rawQuery("SELECT * FROM " + BookmarksDatabaseHelper.BOOKMARKS_TABLE, null);
467
468             // Delete the current bookmarks database.
469             context.deleteDatabase(BookmarksDatabaseHelper.BOOKMARKS_DATABASE);
470
471             // Create a new bookmarks database.  The `0` specifies the database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`.
472             BookmarksDatabaseHelper bookmarksDatabaseHelper = new BookmarksDatabaseHelper(context, null, null, 0);
473
474             // Move to the first bookmark.
475             importBookmarksCursor.moveToFirst();
476
477             // Copy the data from the import bookmarks cursor into the bookmarks database.
478             for (int i = 0; i < importBookmarksCursor.getCount(); i++) {
479                 // Extract the record from the cursor and store the data in a ContentValues.
480                 ContentValues bookmarksContentValues = new ContentValues();
481                 bookmarksContentValues.put(BookmarksDatabaseHelper.BOOKMARK_NAME, importBookmarksCursor.getString(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)));
482                 bookmarksContentValues.put(BookmarksDatabaseHelper.BOOKMARK_URL, importBookmarksCursor.getString(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL)));
483                 bookmarksContentValues.put(BookmarksDatabaseHelper.PARENT_FOLDER, importBookmarksCursor.getString(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.PARENT_FOLDER)));
484                 bookmarksContentValues.put(BookmarksDatabaseHelper.DISPLAY_ORDER, importBookmarksCursor.getInt(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)));
485                 bookmarksContentValues.put(BookmarksDatabaseHelper.IS_FOLDER, importBookmarksCursor.getInt(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)));
486                 bookmarksContentValues.put(BookmarksDatabaseHelper.FAVORITE_ICON, importBookmarksCursor.getBlob(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)));
487
488                 // Insert the record into the export database.
489                 bookmarksDatabaseHelper.createBookmark(bookmarksContentValues);
490
491                 // Advance to the next record.
492                 importBookmarksCursor.moveToNext();
493             }
494
495             // Close the bookmarks cursor.
496             importBookmarksCursor.close();
497
498             // Close the bookmarks database.
499             bookmarksDatabaseHelper.close();
500
501
502             // Get a cursor for the bookmarks table.
503             Cursor importPreferencesCursor = importDatabase.rawQuery("SELECT * FROM " + PREFERENCES_TABLE, null);
504
505             // Move to the first preference.
506             importPreferencesCursor.moveToFirst();
507
508             // Import the preference data.
509             sharedPreferences.edit()
510                     .putBoolean(JAVASCRIPT, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(JAVASCRIPT)) == 1)
511                     .putBoolean(FIRST_PARTY_COOKIES, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(FIRST_PARTY_COOKIES)) == 1)
512                     .putBoolean(THIRD_PARTY_COOKIES, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(THIRD_PARTY_COOKIES)) == 1)
513                     .putBoolean(DOM_STORAGE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DOM_STORAGE)) == 1)
514                     // Save form data can be removed once the minimum API >= 26.
515                     .putBoolean(SAVE_FORM_DATA, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(SAVE_FORM_DATA)) == 1)
516                     .putString(USER_AGENT, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(USER_AGENT)))
517                     .putString(CUSTOM_USER_AGENT, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(CUSTOM_USER_AGENT)))
518                     .putBoolean(INCOGNITO_MODE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(INCOGNITO_MODE)) == 1)
519                     .putBoolean(DO_NOT_TRACK, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DO_NOT_TRACK)) == 1)
520                     .putBoolean(ALLOW_SCREENSHOTS, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(ALLOW_SCREENSHOTS)) == 1)
521                     .putBoolean(EASYLIST, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(EASYLIST)) == 1)
522                     .putBoolean(EASYPRIVACY, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(EASYPRIVACY)) == 1)
523                     .putBoolean(FANBOYS_ANNOYANCE_LIST, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(FANBOYS_ANNOYANCE_LIST)) == 1)
524                     .putBoolean(FANBOYS_SOCIAL_BLOCKING_LIST, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(FANBOYS_SOCIAL_BLOCKING_LIST)) == 1)
525                     .putBoolean(ULTRAPRIVACY, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(ULTRAPRIVACY)) == 1)
526                     .putBoolean(BLOCK_ALL_THIRD_PARTY_REQUESTS, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(BLOCK_ALL_THIRD_PARTY_REQUESTS)) == 1)
527                     .putBoolean(PROXY_THROUGH_ORBOT, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(PROXY_THROUGH_ORBOT)) == 1)
528                     .putString(TOR_HOMEPAGE, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(TOR_HOMEPAGE)))
529                     .putString(TOR_SEARCH, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(TOR_SEARCH)))
530                     .putString(TOR_SEARCH_CUSTOM_URL, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(TOR_SEARCH_CUSTOM_URL)))
531                     .putString(SEARCH, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(SEARCH)))
532                     .putString(SEARCH_CUSTOM_URL, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(SEARCH_CUSTOM_URL)))
533                     .putBoolean(FULL_SCREEN_BROWSING_MODE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(FULL_SCREEN_BROWSING_MODE)) == 1)
534                     .putBoolean(HIDE_SYSTEM_BARS, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(HIDE_SYSTEM_BARS)) == 1)
535                     .putBoolean(TRANSLUCENT_NAVIGATION_BAR, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(TRANSLUCENT_NAVIGATION_BAR)) == 1)
536                     .putBoolean(CLEAR_EVERYTHING, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_EVERYTHING)) == 1)
537                     .putBoolean(CLEAR_COOKIES, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_COOKIES)) == 1)
538                     .putBoolean(CLEAR_DOM_STORAGE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_DOM_STORAGE)) == 1)
539                     // Clear form data can be removed once the minimum API >= 26.
540                     .putBoolean(CLEAR_FORM_DATA, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_FORM_DATA)) == 1)
541                     .putBoolean(CLEAR_CACHE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_CACHE)) == 1)
542                     .putString(HOMEPAGE, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(HOMEPAGE)))
543                     .putString(FONT_SIZE, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(FONT_SIZE)))
544                     .putBoolean(SWIPE_TO_REFRESH, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(SWIPE_TO_REFRESH)) == 1)
545                     .putBoolean(DOWNLOAD_WITH_EXTERNAL_APP, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DOWNLOAD_WITH_EXTERNAL_APP)) == 1)
546                     .putBoolean(DISPLAY_ADDITIONAL_APP_BAR_ICONS, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DISPLAY_ADDITIONAL_APP_BAR_ICONS)) == 1)
547                     .putBoolean(DARK_THEME, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DARK_THEME)) == 1)
548                     .putBoolean(NIGHT_MODE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(NIGHT_MODE)) == 1)
549                     .putBoolean(DISPLAY_WEBPAGE_IMAGES, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DISPLAY_WEBPAGE_IMAGES)) == 1)
550                     .apply();
551
552             // Close the preferences cursor.
553             importPreferencesCursor.close();
554
555
556             // Close the import database.
557             importDatabase.close();
558
559             // Create strings for the temporary database files.
560             String shmFileString = temporaryImportFileString + "-shm";
561             String walFileString = temporaryImportFileString + "-wal";
562             String journalFileString = temporaryImportFileString + "-journal";
563
564             // Get `Files` for the temporary database files.
565             File shmFile = new File(shmFileString);
566             File walFile = new File(walFileString);
567             File journalFile = new File(journalFileString);
568
569             // Delete the Shared Memory file if it exists.
570             if (shmFile.exists()) {
571                 //noinspection ResultOfMethodCallIgnored
572                 shmFile.delete();
573             }
574
575             // Delete the Write Ahead Log file if it exists.
576             if (walFile.exists()) {
577                 //noinspection ResultOfMethodCallIgnored
578                 walFile.delete();
579             }
580
581             // Delete the Journal file if it exists.
582             if (journalFile.exists()) {
583                 //noinspection ResultOfMethodCallIgnored
584                 journalFile.delete();
585             }
586
587             // Delete the temporary import file.
588             //noinspection ResultOfMethodCallIgnored
589             temporaryImportFile.delete();
590
591             // Import successful.
592             return IMPORT_SUCCESSFUL;
593         } catch (Exception exception) {
594             // Return the import error.
595             return exception.toString();
596         }
597     }
598 }