2 * Copyright © 2018-2019 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.preference.PreferenceManager;
29 import com.stoutner.privacybrowser.R;
32 import java.io.FileInputStream;
33 import java.io.FileOutputStream;
34 import java.io.InputStream;
35 import java.io.OutputStream;
37 public class ImportExportDatabaseHelper {
38 public static final String EXPORT_SUCCESSFUL = "Export Successful";
39 public static final String IMPORT_SUCCESSFUL = "Import Successful";
41 private static final int SCHEMA_VERSION = 6;
42 private static final String PREFERENCES_TABLE = "preferences";
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_APP_BAR = "hide_app_bar";
70 private static final String CLEAR_EVERYTHING = "clear_everything";
71 private static final String CLEAR_COOKIES = "clear_cookies";
72 private static final String CLEAR_DOM_STORAGE = "clear_dom_storage";
73 private static final String CLEAR_FORM_DATA = "clear_form_data";
74 private static final String CLEAR_CACHE = "clear_cache";
75 private static final String HOMEPAGE = "homepage";
76 private static final String FONT_SIZE = "font_size";
77 private static final String OPEN_INTENTS_IN_NEW_TAB = "open_intents_in_new_tab";
78 private static final String SWIPE_TO_REFRESH = "swipe_to_refresh";
79 private static final String SCROLL_APP_BAR = "scroll_app_bar";
80 private static final String DISPLAY_ADDITIONAL_APP_BAR_ICONS = "display_additional_app_bar_icons";
81 private static final String DOWNLOAD_WITH_EXTERNAL_APP = "download_with_external_app";
82 private static final String DARK_THEME = "dark_theme";
83 private static final String NIGHT_MODE = "night_mode";
84 private static final String DISPLAY_WEBPAGE_IMAGES = "display_webpage_images";
86 public String exportUnencrypted(File exportFile, Context context) {
88 // Delete the current file if it exists.
89 if (exportFile.exists()) {
90 //noinspection ResultOfMethodCallIgnored
94 // Create the export database.
95 SQLiteDatabase exportDatabase = SQLiteDatabase.openOrCreateDatabase(exportFile, null);
97 // Set the export database version number.
98 exportDatabase.setVersion(SCHEMA_VERSION);
100 // Create the export database domains table.
101 exportDatabase.execSQL(DomainsDatabaseHelper.CREATE_DOMAINS_TABLE);
103 // Open the domains database. The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`.
104 DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(context, null, null, 0);
106 // Get a full domains database cursor.
107 Cursor domainsCursor = domainsDatabaseHelper.getCompleteCursorOrderedByDomain();
109 // Move to the first domain.
110 domainsCursor.moveToFirst();
112 // Copy the data from the domains cursor into the export database.
113 for (int i = 0; i < domainsCursor.getCount(); i++) {
114 // Extract the record from the cursor and store the data in a ContentValues.
115 ContentValues domainsContentValues = new ContentValues();
116 domainsContentValues.put(DomainsDatabaseHelper.DOMAIN_NAME, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME)));
117 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_JAVASCRIPT, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_JAVASCRIPT)));
118 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES)));
119 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES)));
120 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_DOM_STORAGE, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)));
121 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FORM_DATA, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA)));
122 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_EASYLIST, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYLIST)));
123 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_EASYPRIVACY, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYPRIVACY)));
124 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST)));
125 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST)));
126 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY)));
127 domainsContentValues.put(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS)));
128 domainsContentValues.put(DomainsDatabaseHelper.USER_AGENT, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.USER_AGENT)));
129 domainsContentValues.put(DomainsDatabaseHelper.FONT_SIZE, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.FONT_SIZE)));
130 domainsContentValues.put(DomainsDatabaseHelper.SWIPE_TO_REFRESH, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SWIPE_TO_REFRESH)));
131 domainsContentValues.put(DomainsDatabaseHelper.NIGHT_MODE, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.NIGHT_MODE)));
132 domainsContentValues.put(DomainsDatabaseHelper.DISPLAY_IMAGES, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.DISPLAY_IMAGES)));
133 domainsContentValues.put(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE)));
134 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME)));
135 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION)));
136 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATIONAL_UNIT, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATIONAL_UNIT)));
137 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_COMMON_NAME, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_COMMON_NAME)));
138 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATION, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATION)));
139 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATIONAL_UNIT, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATIONAL_UNIT)));
140 domainsContentValues.put(DomainsDatabaseHelper.SSL_START_DATE, domainsCursor.getLong(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_START_DATE)));
141 domainsContentValues.put(DomainsDatabaseHelper.SSL_END_DATE, domainsCursor.getLong(domainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_END_DATE)));
142 domainsContentValues.put(DomainsDatabaseHelper.PINNED_IP_ADDRESSES, domainsCursor.getInt(domainsCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_IP_ADDRESSES)));
143 domainsContentValues.put(DomainsDatabaseHelper.IP_ADDRESSES, domainsCursor.getString(domainsCursor.getColumnIndex(DomainsDatabaseHelper.IP_ADDRESSES)));
145 // Insert the record into the export database.
146 exportDatabase.insert(DomainsDatabaseHelper.DOMAINS_TABLE, null, domainsContentValues);
148 // Advance to the next record.
149 domainsCursor.moveToNext();
152 // Close the domains database.
153 domainsCursor.close();
154 domainsDatabaseHelper.close();
157 // Create the export database bookmarks table.
158 exportDatabase.execSQL(BookmarksDatabaseHelper.CREATE_BOOKMARKS_TABLE);
160 // Open the bookmarks database. The `0` specifies the database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`.
161 BookmarksDatabaseHelper bookmarksDatabaseHelper = new BookmarksDatabaseHelper(context, null, null, 0);
163 // Get a full bookmarks cursor.
164 Cursor bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarks();
166 // Move to the first bookmark.
167 bookmarksCursor.moveToFirst();
169 // Copy the data from the bookmarks cursor into the export database.
170 for (int i = 0; i < bookmarksCursor.getCount(); i++) {
171 // Extract the record from the cursor and store the data in a ContentValues.
172 ContentValues bookmarksContentValues = new ContentValues();
173 bookmarksContentValues.put(BookmarksDatabaseHelper.BOOKMARK_NAME, bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)));
174 bookmarksContentValues.put(BookmarksDatabaseHelper.BOOKMARK_URL, bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL)));
175 bookmarksContentValues.put(BookmarksDatabaseHelper.PARENT_FOLDER, bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.PARENT_FOLDER)));
176 bookmarksContentValues.put(BookmarksDatabaseHelper.DISPLAY_ORDER, bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)));
177 bookmarksContentValues.put(BookmarksDatabaseHelper.IS_FOLDER, bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)));
178 bookmarksContentValues.put(BookmarksDatabaseHelper.FAVORITE_ICON, bookmarksCursor.getBlob(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)));
180 // Insert the record into the export database.
181 exportDatabase.insert(BookmarksDatabaseHelper.BOOKMARKS_TABLE, null, bookmarksContentValues);
183 // Advance to the next record.
184 bookmarksCursor.moveToNext();
187 // Close the bookmarks database.
188 bookmarksCursor.close();
189 bookmarksDatabaseHelper.close();
192 // Prepare the preferences table SQL creation string.
193 String CREATE_PREFERENCES_TABLE = "CREATE TABLE " + PREFERENCES_TABLE + " (" +
194 _ID + " INTEGER PRIMARY KEY, " +
195 JAVASCRIPT + " BOOLEAN, " +
196 FIRST_PARTY_COOKIES + " BOOLEAN, " +
197 THIRD_PARTY_COOKIES + " BOOLEAN, " +
198 DOM_STORAGE + " BOOLEAN, " +
199 SAVE_FORM_DATA + " BOOLEAN, " +
200 USER_AGENT + " TEXT, " +
201 CUSTOM_USER_AGENT + " TEXT, " +
202 INCOGNITO_MODE + " BOOLEAN, " +
203 DO_NOT_TRACK + " BOOLEAN, " +
204 ALLOW_SCREENSHOTS + " BOOLEAN, " +
205 EASYLIST + " BOOLEAN, " +
206 EASYPRIVACY + " BOOLEAN, " +
207 FANBOYS_ANNOYANCE_LIST + " BOOLEAN, " +
208 FANBOYS_SOCIAL_BLOCKING_LIST + " BOOLEAN, " +
209 ULTRAPRIVACY + " BOOLEAN, " +
210 BLOCK_ALL_THIRD_PARTY_REQUESTS + " BOOLEAN, " +
211 PROXY_THROUGH_ORBOT + " BOOLEAN, " +
212 TOR_HOMEPAGE + " TEXT, " +
213 TOR_SEARCH + " TEXT, " +
214 TOR_SEARCH_CUSTOM_URL + " TEXT, " +
216 SEARCH_CUSTOM_URL + " TEXT, " +
217 FULL_SCREEN_BROWSING_MODE + " BOOLEAN, " +
218 HIDE_APP_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 OPEN_INTENTS_IN_NEW_TAB + " BOOLEAN, " +
227 SWIPE_TO_REFRESH + " BOOLEAN, " +
228 SCROLL_APP_BAR + " BOOLEAN, " +
229 DISPLAY_ADDITIONAL_APP_BAR_ICONS + " BOOLEAN, " +
230 DOWNLOAD_WITH_EXTERNAL_APP + " BOOLEAN, " +
231 DARK_THEME + " BOOLEAN, " +
232 NIGHT_MODE + " BOOLEAN, " +
233 DISPLAY_WEBPAGE_IMAGES + " BOOLEAN)";
235 // Create the export database preferences table.
236 exportDatabase.execSQL(CREATE_PREFERENCES_TABLE);
238 // Get a handle for the shared preference.
239 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
241 // Create a ContentValues with the preferences information.
242 ContentValues preferencesContentValues = new ContentValues();
243 preferencesContentValues.put(JAVASCRIPT, sharedPreferences.getBoolean(JAVASCRIPT, false));
244 preferencesContentValues.put(FIRST_PARTY_COOKIES, sharedPreferences.getBoolean(FIRST_PARTY_COOKIES, false));
245 preferencesContentValues.put(THIRD_PARTY_COOKIES, sharedPreferences.getBoolean(THIRD_PARTY_COOKIES, false));
246 preferencesContentValues.put(DOM_STORAGE, sharedPreferences.getBoolean(DOM_STORAGE, false));
247 preferencesContentValues.put(SAVE_FORM_DATA, sharedPreferences.getBoolean(SAVE_FORM_DATA, false)); // Save form data can be removed once the minimum API >= 26.
248 preferencesContentValues.put(USER_AGENT, sharedPreferences.getString(USER_AGENT, context.getString(R.string.user_agent_default_value)));
249 preferencesContentValues.put(CUSTOM_USER_AGENT, sharedPreferences.getString(CUSTOM_USER_AGENT, context.getString(R.string.custom_user_agent_default_value)));
250 preferencesContentValues.put(INCOGNITO_MODE, sharedPreferences.getBoolean(INCOGNITO_MODE, false));
251 preferencesContentValues.put(DO_NOT_TRACK, sharedPreferences.getBoolean(DO_NOT_TRACK, false));
252 preferencesContentValues.put(ALLOW_SCREENSHOTS, sharedPreferences.getBoolean(ALLOW_SCREENSHOTS, false));
253 preferencesContentValues.put(EASYLIST, sharedPreferences.getBoolean(EASYLIST, true));
254 preferencesContentValues.put(EASYPRIVACY, sharedPreferences.getBoolean(EASYPRIVACY, true));
255 preferencesContentValues.put(FANBOYS_ANNOYANCE_LIST, sharedPreferences.getBoolean(FANBOYS_ANNOYANCE_LIST, true));
256 preferencesContentValues.put(FANBOYS_SOCIAL_BLOCKING_LIST, sharedPreferences.getBoolean(FANBOYS_SOCIAL_BLOCKING_LIST, true));
257 preferencesContentValues.put(ULTRAPRIVACY, sharedPreferences.getBoolean(ULTRAPRIVACY, true));
258 preferencesContentValues.put(BLOCK_ALL_THIRD_PARTY_REQUESTS, sharedPreferences.getBoolean(BLOCK_ALL_THIRD_PARTY_REQUESTS, false));
259 preferencesContentValues.put(PROXY_THROUGH_ORBOT, sharedPreferences.getBoolean(PROXY_THROUGH_ORBOT, false));
260 preferencesContentValues.put(TOR_HOMEPAGE, sharedPreferences.getString(TOR_HOMEPAGE, context.getString(R.string.tor_homepage_default_value)));
261 preferencesContentValues.put(TOR_SEARCH, sharedPreferences.getString(TOR_SEARCH, context.getString(R.string.tor_search_default_value)));
262 preferencesContentValues.put(TOR_SEARCH_CUSTOM_URL, sharedPreferences.getString(TOR_SEARCH_CUSTOM_URL, context.getString(R.string.tor_search_custom_url_default_value)));
263 preferencesContentValues.put(SEARCH, sharedPreferences.getString(SEARCH, context.getString(R.string.search_default_value)));
264 preferencesContentValues.put(SEARCH_CUSTOM_URL, sharedPreferences.getString(SEARCH_CUSTOM_URL, context.getString(R.string.search_custom_url_default_value)));
265 preferencesContentValues.put(FULL_SCREEN_BROWSING_MODE, sharedPreferences.getBoolean(FULL_SCREEN_BROWSING_MODE, false));
266 preferencesContentValues.put(HIDE_APP_BAR, sharedPreferences.getBoolean(HIDE_APP_BAR, true));
267 preferencesContentValues.put(CLEAR_EVERYTHING, sharedPreferences.getBoolean(CLEAR_EVERYTHING, true));
268 preferencesContentValues.put(CLEAR_COOKIES, sharedPreferences.getBoolean(CLEAR_COOKIES, true));
269 preferencesContentValues.put(CLEAR_DOM_STORAGE, sharedPreferences.getBoolean(CLEAR_DOM_STORAGE, true));
270 preferencesContentValues.put(CLEAR_FORM_DATA, sharedPreferences.getBoolean(CLEAR_FORM_DATA, true)); // Clear form data can be removed once the minimum API >= 26.
271 preferencesContentValues.put(CLEAR_CACHE, sharedPreferences.getBoolean(CLEAR_CACHE, true));
272 preferencesContentValues.put(HOMEPAGE, sharedPreferences.getString(HOMEPAGE, context.getString(R.string.homepage_default_value)));
273 preferencesContentValues.put(FONT_SIZE, sharedPreferences.getString(FONT_SIZE, context.getString(R.string.font_size_default_value)));
274 preferencesContentValues.put(OPEN_INTENTS_IN_NEW_TAB, sharedPreferences.getBoolean(OPEN_INTENTS_IN_NEW_TAB, true));
275 preferencesContentValues.put(SWIPE_TO_REFRESH, sharedPreferences.getBoolean(SWIPE_TO_REFRESH, true));
276 preferencesContentValues.put(SCROLL_APP_BAR, sharedPreferences.getBoolean(SCROLL_APP_BAR, true));
277 preferencesContentValues.put(DISPLAY_ADDITIONAL_APP_BAR_ICONS, sharedPreferences.getBoolean(DISPLAY_ADDITIONAL_APP_BAR_ICONS, false));
278 preferencesContentValues.put(DOWNLOAD_WITH_EXTERNAL_APP, sharedPreferences.getBoolean(DOWNLOAD_WITH_EXTERNAL_APP, false));
279 preferencesContentValues.put(DARK_THEME, sharedPreferences.getBoolean(DARK_THEME, false));
280 preferencesContentValues.put(NIGHT_MODE, sharedPreferences.getBoolean(NIGHT_MODE, false));
281 preferencesContentValues.put(DISPLAY_WEBPAGE_IMAGES, sharedPreferences.getBoolean(DISPLAY_WEBPAGE_IMAGES, true));
283 // Insert the preferences into the export database.
284 exportDatabase.insert(PREFERENCES_TABLE, null, preferencesContentValues);
286 // Close the export database.
287 exportDatabase.close();
289 // Convert the database file to a string.
290 String exportFileString = exportFile.toString();
292 // Create strings for the temporary database files.
293 String journalFileString = exportFileString + "-journal";
295 // Get `Files` for the temporary database files.
296 File journalFile = new File(journalFileString);
298 // Delete the Journal file if it exists.
299 if (journalFile.exists()) {
300 //noinspection ResultOfMethodCallIgnored
301 journalFile.delete();
304 // Export successful.
305 return EXPORT_SUCCESSFUL;
306 } catch (Exception exception) {
307 // Return the export error.
308 return exception.toString();
312 public String importUnencrypted(File importFile, Context context){
314 // Create a temporary import file string.
315 String temporaryImportFileString = context.getCacheDir() + "/" + "temporary_import_file";
317 // Get a handle for a temporary import file.
318 File temporaryImportFile = new File(temporaryImportFileString);
320 // Delete the temporary import file if it already exists.
321 if (temporaryImportFile.exists()) {
322 //noinspection ResultOfMethodCallIgnored
323 temporaryImportFile.delete();
326 // Create input and output streams.
327 InputStream importFileInputStream = new FileInputStream(importFile);
328 OutputStream temporaryImportFileOutputStream = new FileOutputStream(temporaryImportFile);
330 // Create a byte array.
331 byte[] transferByteArray = new byte[1024];
333 // Create an integer to track the number of bytes read.
336 // Copy the import file to the temporary import file. Once the minimum API >= 26 `Files.copy` can be used instead.
337 while ((bytesRead = importFileInputStream.read(transferByteArray)) > 0) {
338 temporaryImportFileOutputStream.write(transferByteArray, 0, bytesRead);
341 // Close the file streams.
342 importFileInputStream.close();
343 temporaryImportFileOutputStream.close();
346 // Get a handle for the shared preference.
347 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
349 // Open the import database. Once the minimum API >= 27 the file can be opened directly without using the string.
350 SQLiteDatabase importDatabase = SQLiteDatabase.openDatabase(temporaryImportFileString, null, SQLiteDatabase.OPEN_READWRITE);
352 // Get the database version.
353 int importDatabaseVersion = importDatabase.getVersion();
355 // Upgrade the database if needed.
356 if (importDatabaseVersion < SCHEMA_VERSION) {
357 switch (importDatabaseVersion){
358 // Upgrade from schema version 1.
360 // Add the download with external app preference.
361 importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + DOWNLOAD_WITH_EXTERNAL_APP + " BOOLEAN");
363 // Get the current setting for downloading with an external app.
364 boolean downloadWithExternalApp = sharedPreferences.getBoolean(DOWNLOAD_WITH_EXTERNAL_APP, false);
366 // Set the download with external app preference to the current value.
367 if (downloadWithExternalApp) {
368 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + DOWNLOAD_WITH_EXTERNAL_APP + " = " + 1);
370 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + DOWNLOAD_WITH_EXTERNAL_APP + " = " + 0);
373 // Upgrade from schema version 2.
375 // 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
376 // https://developer.android.com/reference/android/database/sqlite/package-summary
377 // 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.
379 // Get a cursor with the current `default_font_size` value.
380 Cursor importDatabasePreferenceCursor = importDatabase.rawQuery("SELECT default_font_size FROM " + PREFERENCES_TABLE, null);
382 // Move to the beginning fo the cursor.
383 importDatabasePreferenceCursor.moveToFirst();
385 // Get the current value in `default_font_size`.
386 String fontSize = importDatabasePreferenceCursor.getString(importDatabasePreferenceCursor.getColumnIndex("default_font_size"));
389 importDatabasePreferenceCursor.close();
391 // Create a new column named `font_size`.
392 importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + FONT_SIZE + " TEXT");
394 // Place the font size string in the new column.
395 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + FONT_SIZE + " = " + fontSize);
397 // Upgrade from schema version 3.
399 // Add the Pinned IP Addresses columns to the domains table.
400 importDatabase.execSQL("ALTER TABLE " + DomainsDatabaseHelper.DOMAINS_TABLE + " ADD COLUMN " + DomainsDatabaseHelper.PINNED_IP_ADDRESSES + " BOOLEAN");
401 importDatabase.execSQL("ALTER TABLE " + DomainsDatabaseHelper.DOMAINS_TABLE + " ADD COLUMN " + DomainsDatabaseHelper.IP_ADDRESSES + " TEXT");
403 // Upgrade from schema version 4.
405 // Add the hide and scroll app bar preferences.
406 importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + HIDE_APP_BAR + " BOOLEAN");
407 importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + SCROLL_APP_BAR + " BOOLEAN");
409 // Get the current hide and scroll app bar settings.
410 boolean hideAppBar = sharedPreferences.getBoolean(HIDE_APP_BAR, true);
411 boolean scrollAppBar = sharedPreferences.getBoolean(SCROLL_APP_BAR, true);
413 // Populate the database with the current values.
415 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + HIDE_APP_BAR + " = " + 1);
417 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + HIDE_APP_BAR + " = " + 0);
421 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + SCROLL_APP_BAR + " = " + 1);
423 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + SCROLL_APP_BAR + " = " + 0);
426 // Upgrade from schema version 5.
428 // Add the open intents in new tab preference.
429 importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + OPEN_INTENTS_IN_NEW_TAB + " BOOLEAN");
431 // Get the current open intents in new tab setting.
432 boolean openIntentsInNewTab = sharedPreferences.getBoolean(OPEN_INTENTS_IN_NEW_TAB, true);
434 // Populate the database with the current value.
435 if (openIntentsInNewTab) {
436 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + OPEN_INTENTS_IN_NEW_TAB + " = " + 1);
438 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + OPEN_INTENTS_IN_NEW_TAB + " = " + 0);
443 // Get a cursor for the domains table.
444 Cursor importDomainsCursor = importDatabase.rawQuery("SELECT * FROM " + DomainsDatabaseHelper.DOMAINS_TABLE + " ORDER BY " + DomainsDatabaseHelper.DOMAIN_NAME + " ASC", null);
446 // Delete the current domains database.
447 context.deleteDatabase(DomainsDatabaseHelper.DOMAINS_DATABASE);
449 // Create a new domains database. The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`.
450 DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(context, null, null, 0);
452 // Move to the first domain.
453 importDomainsCursor.moveToFirst();
455 // Copy the data from the import domains cursor into the domains database.
456 for (int i = 0; i < importDomainsCursor.getCount(); i++) {
457 // Extract the record from the cursor and store the data in a ContentValues.
458 ContentValues domainsContentValues = new ContentValues();
459 domainsContentValues.put(DomainsDatabaseHelper.DOMAIN_NAME, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME)));
460 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_JAVASCRIPT, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_JAVASCRIPT)));
461 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES)));
462 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES)));
463 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_DOM_STORAGE, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)));
464 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FORM_DATA, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA)));
465 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_EASYLIST, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYLIST)));
466 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_EASYPRIVACY, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYPRIVACY)));
467 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST,
468 importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST)));
469 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST,
470 importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST)));
471 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY)));
472 domainsContentValues.put(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS,
473 importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS)));
474 domainsContentValues.put(DomainsDatabaseHelper.USER_AGENT, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.USER_AGENT)));
475 domainsContentValues.put(DomainsDatabaseHelper.FONT_SIZE, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.FONT_SIZE)));
476 domainsContentValues.put(DomainsDatabaseHelper.SWIPE_TO_REFRESH, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SWIPE_TO_REFRESH)));
477 domainsContentValues.put(DomainsDatabaseHelper.NIGHT_MODE, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.NIGHT_MODE)));
478 domainsContentValues.put(DomainsDatabaseHelper.DISPLAY_IMAGES, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.DISPLAY_IMAGES)));
479 domainsContentValues.put(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE)));
480 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME)));
481 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION)));
482 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATIONAL_UNIT,
483 importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATIONAL_UNIT)));
484 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_COMMON_NAME, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_COMMON_NAME)));
485 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATION, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATION)));
486 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATIONAL_UNIT,
487 importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATIONAL_UNIT)));
488 domainsContentValues.put(DomainsDatabaseHelper.SSL_START_DATE, importDomainsCursor.getLong(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_START_DATE)));
489 domainsContentValues.put(DomainsDatabaseHelper.SSL_END_DATE, importDomainsCursor.getLong(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_END_DATE)));
490 domainsContentValues.put(DomainsDatabaseHelper.PINNED_IP_ADDRESSES, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_IP_ADDRESSES)));
491 domainsContentValues.put(DomainsDatabaseHelper.IP_ADDRESSES, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.IP_ADDRESSES)));
493 // Insert the record into the export database.
494 domainsDatabaseHelper.addDomain(domainsContentValues);
496 // Advance to the next record.
497 importDomainsCursor.moveToNext();
500 // Close the domains cursor.
501 importDomainsCursor.close();
503 // Close the domains database.
504 domainsDatabaseHelper.close();
507 // Get a cursor for the bookmarks table.
508 Cursor importBookmarksCursor = importDatabase.rawQuery("SELECT * FROM " + BookmarksDatabaseHelper.BOOKMARKS_TABLE, null);
510 // Delete the current bookmarks database.
511 context.deleteDatabase(BookmarksDatabaseHelper.BOOKMARKS_DATABASE);
513 // Create a new bookmarks database. The `0` specifies the database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`.
514 BookmarksDatabaseHelper bookmarksDatabaseHelper = new BookmarksDatabaseHelper(context, null, null, 0);
516 // Move to the first bookmark.
517 importBookmarksCursor.moveToFirst();
519 // Copy the data from the import bookmarks cursor into the bookmarks database.
520 for (int i = 0; i < importBookmarksCursor.getCount(); i++) {
521 // Extract the record from the cursor and store the data in a ContentValues.
522 ContentValues bookmarksContentValues = new ContentValues();
523 bookmarksContentValues.put(BookmarksDatabaseHelper.BOOKMARK_NAME, importBookmarksCursor.getString(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)));
524 bookmarksContentValues.put(BookmarksDatabaseHelper.BOOKMARK_URL, importBookmarksCursor.getString(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL)));
525 bookmarksContentValues.put(BookmarksDatabaseHelper.PARENT_FOLDER, importBookmarksCursor.getString(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.PARENT_FOLDER)));
526 bookmarksContentValues.put(BookmarksDatabaseHelper.DISPLAY_ORDER, importBookmarksCursor.getInt(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)));
527 bookmarksContentValues.put(BookmarksDatabaseHelper.IS_FOLDER, importBookmarksCursor.getInt(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)));
528 bookmarksContentValues.put(BookmarksDatabaseHelper.FAVORITE_ICON, importBookmarksCursor.getBlob(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)));
530 // Insert the record into the export database.
531 bookmarksDatabaseHelper.createBookmark(bookmarksContentValues);
533 // Advance to the next record.
534 importBookmarksCursor.moveToNext();
537 // Close the bookmarks cursor.
538 importBookmarksCursor.close();
540 // Close the bookmarks database.
541 bookmarksDatabaseHelper.close();
544 // Get a cursor for the bookmarks table.
545 Cursor importPreferencesCursor = importDatabase.rawQuery("SELECT * FROM " + PREFERENCES_TABLE, null);
547 // Move to the first preference.
548 importPreferencesCursor.moveToFirst();
550 // Import the preference data.
551 sharedPreferences.edit()
552 .putBoolean(JAVASCRIPT, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(JAVASCRIPT)) == 1)
553 .putBoolean(FIRST_PARTY_COOKIES, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(FIRST_PARTY_COOKIES)) == 1)
554 .putBoolean(THIRD_PARTY_COOKIES, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(THIRD_PARTY_COOKIES)) == 1)
555 .putBoolean(DOM_STORAGE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DOM_STORAGE)) == 1)
556 // Save form data can be removed once the minimum API >= 26.
557 .putBoolean(SAVE_FORM_DATA, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(SAVE_FORM_DATA)) == 1)
558 .putString(USER_AGENT, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(USER_AGENT)))
559 .putString(CUSTOM_USER_AGENT, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(CUSTOM_USER_AGENT)))
560 .putBoolean(INCOGNITO_MODE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(INCOGNITO_MODE)) == 1)
561 .putBoolean(DO_NOT_TRACK, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DO_NOT_TRACK)) == 1)
562 .putBoolean(ALLOW_SCREENSHOTS, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(ALLOW_SCREENSHOTS)) == 1)
563 .putBoolean(EASYLIST, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(EASYLIST)) == 1)
564 .putBoolean(EASYPRIVACY, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(EASYPRIVACY)) == 1)
565 .putBoolean(FANBOYS_ANNOYANCE_LIST, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(FANBOYS_ANNOYANCE_LIST)) == 1)
566 .putBoolean(FANBOYS_SOCIAL_BLOCKING_LIST, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(FANBOYS_SOCIAL_BLOCKING_LIST)) == 1)
567 .putBoolean(ULTRAPRIVACY, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(ULTRAPRIVACY)) == 1)
568 .putBoolean(BLOCK_ALL_THIRD_PARTY_REQUESTS, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(BLOCK_ALL_THIRD_PARTY_REQUESTS)) == 1)
569 .putBoolean(PROXY_THROUGH_ORBOT, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(PROXY_THROUGH_ORBOT)) == 1)
570 .putString(TOR_HOMEPAGE, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(TOR_HOMEPAGE)))
571 .putString(TOR_SEARCH, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(TOR_SEARCH)))
572 .putString(TOR_SEARCH_CUSTOM_URL, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(TOR_SEARCH_CUSTOM_URL)))
573 .putString(SEARCH, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(SEARCH)))
574 .putString(SEARCH_CUSTOM_URL, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(SEARCH_CUSTOM_URL)))
575 .putBoolean(FULL_SCREEN_BROWSING_MODE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(FULL_SCREEN_BROWSING_MODE)) == 1)
576 .putBoolean(HIDE_APP_BAR, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(HIDE_APP_BAR)) == 1)
577 .putBoolean(CLEAR_EVERYTHING, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_EVERYTHING)) == 1)
578 .putBoolean(CLEAR_COOKIES, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_COOKIES)) == 1)
579 .putBoolean(CLEAR_DOM_STORAGE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_DOM_STORAGE)) == 1)
580 // Clear form data can be removed once the minimum API >= 26.
581 .putBoolean(CLEAR_FORM_DATA, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_FORM_DATA)) == 1)
582 .putBoolean(CLEAR_CACHE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_CACHE)) == 1)
583 .putString(HOMEPAGE, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(HOMEPAGE)))
584 .putString(FONT_SIZE, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(FONT_SIZE)))
585 .putBoolean(OPEN_INTENTS_IN_NEW_TAB, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(OPEN_INTENTS_IN_NEW_TAB)) == 1)
586 .putBoolean(SWIPE_TO_REFRESH, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(SWIPE_TO_REFRESH)) == 1)
587 .putBoolean(SCROLL_APP_BAR, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(SCROLL_APP_BAR)) == 1)
588 .putBoolean(DISPLAY_ADDITIONAL_APP_BAR_ICONS, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DISPLAY_ADDITIONAL_APP_BAR_ICONS)) == 1)
589 .putBoolean(DOWNLOAD_WITH_EXTERNAL_APP, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DOWNLOAD_WITH_EXTERNAL_APP)) == 1)
590 .putBoolean(DARK_THEME, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DARK_THEME)) == 1)
591 .putBoolean(NIGHT_MODE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(NIGHT_MODE)) == 1)
592 .putBoolean(DISPLAY_WEBPAGE_IMAGES, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DISPLAY_WEBPAGE_IMAGES)) == 1)
595 // Close the preferences cursor.
596 importPreferencesCursor.close();
599 // Close the import database.
600 importDatabase.close();
602 // Create strings for the temporary database files.
603 String shmFileString = temporaryImportFileString + "-shm";
604 String walFileString = temporaryImportFileString + "-wal";
605 String journalFileString = temporaryImportFileString + "-journal";
607 // Get `Files` for the temporary database files.
608 File shmFile = new File(shmFileString);
609 File walFile = new File(walFileString);
610 File journalFile = new File(journalFileString);
612 // Delete the Shared Memory file if it exists.
613 if (shmFile.exists()) {
614 //noinspection ResultOfMethodCallIgnored
618 // Delete the Write Ahead Log file if it exists.
619 if (walFile.exists()) {
620 //noinspection ResultOfMethodCallIgnored
624 // Delete the Journal file if it exists.
625 if (journalFile.exists()) {
626 //noinspection ResultOfMethodCallIgnored
627 journalFile.delete();
630 // Delete the temporary import file.
631 //noinspection ResultOfMethodCallIgnored
632 temporaryImportFile.delete();
634 // Import successful.
635 return IMPORT_SUCCESSFUL;
636 } catch (Exception exception) {
637 // Return the import error.
638 return exception.toString();