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 = 5;
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 SWIPE_TO_REFRESH = "swipe_to_refresh";
78 private static final String SCROLL_APP_BAR = "scroll_app_bar";
79 private static final String DISPLAY_ADDITIONAL_APP_BAR_ICONS = "display_additional_app_bar_icons";
80 private static final String DOWNLOAD_WITH_EXTERNAL_APP = "download_with_external_app";
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";
85 public String exportUnencrypted(File exportFile, Context context) {
87 // Delete the current file if it exists.
88 if (exportFile.exists()) {
89 //noinspection ResultOfMethodCallIgnored
93 // Create the export database.
94 SQLiteDatabase exportDatabase = SQLiteDatabase.openOrCreateDatabase(exportFile, null);
96 // Set the export database version number.
97 exportDatabase.setVersion(SCHEMA_VERSION);
99 // Create the export database domains table.
100 exportDatabase.execSQL(DomainsDatabaseHelper.CREATE_DOMAINS_TABLE);
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);
105 // Get a full domains database cursor.
106 Cursor domainsCursor = domainsDatabaseHelper.getCompleteCursorOrderedByDomain();
108 // Move to the first domain.
109 domainsCursor.moveToFirst();
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)));
144 // Insert the record into the export database.
145 exportDatabase.insert(DomainsDatabaseHelper.DOMAINS_TABLE, null, domainsContentValues);
147 // Advance to the next record.
148 domainsCursor.moveToNext();
151 // Close the domains database.
152 domainsCursor.close();
153 domainsDatabaseHelper.close();
156 // Create the export database bookmarks table.
157 exportDatabase.execSQL(BookmarksDatabaseHelper.CREATE_BOOKMARKS_TABLE);
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);
162 // Get a full bookmarks cursor.
163 Cursor bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarks();
165 // Move to the first bookmark.
166 bookmarksCursor.moveToFirst();
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)));
179 // Insert the record into the export database.
180 exportDatabase.insert(BookmarksDatabaseHelper.BOOKMARKS_TABLE, null, bookmarksContentValues);
182 // Advance to the next record.
183 bookmarksCursor.moveToNext();
186 // Close the bookmarks database.
187 bookmarksCursor.close();
188 bookmarksDatabaseHelper.close();
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, " +
215 SEARCH_CUSTOM_URL + " TEXT, " +
216 FULL_SCREEN_BROWSING_MODE + " BOOLEAN, " +
217 HIDE_APP_BAR + " BOOLEAN, " +
218 CLEAR_EVERYTHING + " BOOLEAN, " +
219 CLEAR_COOKIES + " BOOLEAN, " +
220 CLEAR_DOM_STORAGE + " BOOLEAN, " +
221 CLEAR_FORM_DATA + " BOOLEAN, " +
222 CLEAR_CACHE + " BOOLEAN, " +
223 HOMEPAGE + " TEXT, " +
224 FONT_SIZE + " TEXT, " +
225 SWIPE_TO_REFRESH + " BOOLEAN, " +
226 SCROLL_APP_BAR + " BOOLEAN, " +
227 DISPLAY_ADDITIONAL_APP_BAR_ICONS + " BOOLEAN, " +
228 DOWNLOAD_WITH_EXTERNAL_APP + " BOOLEAN, " +
229 DARK_THEME + " BOOLEAN, " +
230 NIGHT_MODE + " BOOLEAN, " +
231 DISPLAY_WEBPAGE_IMAGES + " BOOLEAN)";
233 // Create the export database preferences table.
234 exportDatabase.execSQL(CREATE_PREFERENCES_TABLE);
236 // Get a handle for the shared preference.
237 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
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_APP_BAR, sharedPreferences.getBoolean(HIDE_APP_BAR, true));
265 preferencesContentValues.put(CLEAR_EVERYTHING, sharedPreferences.getBoolean(CLEAR_EVERYTHING, true));
266 preferencesContentValues.put(CLEAR_COOKIES, sharedPreferences.getBoolean(CLEAR_COOKIES, true));
267 preferencesContentValues.put(CLEAR_DOM_STORAGE, sharedPreferences.getBoolean(CLEAR_DOM_STORAGE, true));
268 preferencesContentValues.put(CLEAR_FORM_DATA, sharedPreferences.getBoolean(CLEAR_FORM_DATA, true)); // Clear form data can be removed once the minimum API >= 26.
269 preferencesContentValues.put(CLEAR_CACHE, sharedPreferences.getBoolean(CLEAR_CACHE, true));
270 preferencesContentValues.put(HOMEPAGE, sharedPreferences.getString(HOMEPAGE, context.getString(R.string.homepage_default_value)));
271 preferencesContentValues.put(FONT_SIZE, sharedPreferences.getString(FONT_SIZE, context.getString(R.string.font_size_default_value)));
272 preferencesContentValues.put(SWIPE_TO_REFRESH, sharedPreferences.getBoolean(SWIPE_TO_REFRESH, true));
273 preferencesContentValues.put(SCROLL_APP_BAR, sharedPreferences.getBoolean(SCROLL_APP_BAR, true));
274 preferencesContentValues.put(DISPLAY_ADDITIONAL_APP_BAR_ICONS, sharedPreferences.getBoolean(DISPLAY_ADDITIONAL_APP_BAR_ICONS, false));
275 preferencesContentValues.put(DOWNLOAD_WITH_EXTERNAL_APP, sharedPreferences.getBoolean(DOWNLOAD_WITH_EXTERNAL_APP, 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));
280 // Insert the preferences into the export database.
281 exportDatabase.insert(PREFERENCES_TABLE, null, preferencesContentValues);
283 // Close the export database.
284 exportDatabase.close();
286 // Convert the database file to a string.
287 String exportFileString = exportFile.toString();
289 // Create strings for the temporary database files.
290 String journalFileString = exportFileString + "-journal";
292 // Get `Files` for the temporary database files.
293 File journalFile = new File(journalFileString);
295 // Delete the Journal file if it exists.
296 if (journalFile.exists()) {
297 //noinspection ResultOfMethodCallIgnored
298 journalFile.delete();
301 // Export successful.
302 return EXPORT_SUCCESSFUL;
303 } catch (Exception exception) {
304 // Return the export error.
305 return exception.toString();
309 public String importUnencrypted(File importFile, Context context){
311 // Create a temporary import file string.
312 String temporaryImportFileString = context.getCacheDir() + "/" + "temporary_import_file";
314 // Get a handle for a temporary import file.
315 File temporaryImportFile = new File(temporaryImportFileString);
317 // Delete the temporary import file if it already exists.
318 if (temporaryImportFile.exists()) {
319 //noinspection ResultOfMethodCallIgnored
320 temporaryImportFile.delete();
323 // Create input and output streams.
324 InputStream importFileInputStream = new FileInputStream(importFile);
325 OutputStream temporaryImportFileOutputStream = new FileOutputStream(temporaryImportFile);
327 // Create a byte array.
328 byte[] transferByteArray = new byte[1024];
330 // Create an integer to track the number of bytes read.
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);
338 // Close the file streams.
339 importFileInputStream.close();
340 temporaryImportFileOutputStream.close();
343 // Get a handle for the shared preference.
344 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
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);
349 // Get the database version.
350 int importDatabaseVersion = importDatabase.getVersion();
352 // Upgrade the database if needed.
353 if (importDatabaseVersion < SCHEMA_VERSION) {
354 switch (importDatabaseVersion){
355 // Upgrade from schema version 1.
357 // Add the download with external app preference.
358 importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + DOWNLOAD_WITH_EXTERNAL_APP + " BOOLEAN");
360 // Get the current setting for downloading with an external app.
361 boolean downloadWithExternalApp = sharedPreferences.getBoolean("download_with_external_app", false);
363 // Set the download with external app preference to the current value.
364 if (downloadWithExternalApp) {
365 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + DOWNLOAD_WITH_EXTERNAL_APP + " = " + 1);
367 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + DOWNLOAD_WITH_EXTERNAL_APP + " = " + 0);
370 // Upgrade from schema version 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.
376 // Get a cursor with the current `default_font_size` value.
377 Cursor importDatabasePreferenceCursor = importDatabase.rawQuery("SELECT default_font_size FROM " + PREFERENCES_TABLE, null);
379 // Move to the beginning fo the cursor.
380 importDatabasePreferenceCursor.moveToFirst();
382 // Get the current value in `default_font_size`.
383 String fontSize = importDatabasePreferenceCursor.getString(importDatabasePreferenceCursor.getColumnIndex("default_font_size"));
386 importDatabasePreferenceCursor.close();
388 // Create a new column named `font_size`.
389 importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + FONT_SIZE + " TEXT");
391 // Place the font size string in the new column.
392 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + FONT_SIZE + " = " + fontSize);
394 // Upgrade from schema version 3.
396 // Add the Pinned IP Addresses columns to the domains table.
397 importDatabase.execSQL("ALTER TABLE " + DomainsDatabaseHelper.DOMAINS_TABLE + " ADD COLUMN " + DomainsDatabaseHelper.PINNED_IP_ADDRESSES + " BOOLEAN");
398 importDatabase.execSQL("ALTER TABLE " + DomainsDatabaseHelper.DOMAINS_TABLE + " ADD COLUMN " + DomainsDatabaseHelper.IP_ADDRESSES + " TEXT");
400 // Upgrade from schema version 4.
402 // Add the hide and scroll app bar preferences.
403 importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + HIDE_APP_BAR + " BOOLEAN");
404 importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + SCROLL_APP_BAR + " BOOLEAN");
406 // Get the current hide and scroll app bar settings.
407 boolean hideAppBar = sharedPreferences.getBoolean("hide_app_bar", true);
408 boolean scrollAppBar = sharedPreferences.getBoolean("scroll_app_bar", true);
410 // Populate the database with the current values.
412 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + HIDE_APP_BAR + " = " + 1);
414 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + HIDE_APP_BAR + " = " + 0);
418 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + SCROLL_APP_BAR + " = " + 1);
420 importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + SCROLL_APP_BAR + " = " + 0);
425 // Get a cursor for the domains table.
426 Cursor importDomainsCursor = importDatabase.rawQuery("SELECT * FROM " + DomainsDatabaseHelper.DOMAINS_TABLE + " ORDER BY " + DomainsDatabaseHelper.DOMAIN_NAME + " ASC", null);
428 // Delete the current domains database.
429 context.deleteDatabase(DomainsDatabaseHelper.DOMAINS_DATABASE);
431 // Create a new domains database. The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`.
432 DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(context, null, null, 0);
434 // Move to the first domain.
435 importDomainsCursor.moveToFirst();
437 // Copy the data from the import domains cursor into the domains database.
438 for (int i = 0; i < importDomainsCursor.getCount(); i++) {
439 // Extract the record from the cursor and store the data in a ContentValues.
440 ContentValues domainsContentValues = new ContentValues();
441 domainsContentValues.put(DomainsDatabaseHelper.DOMAIN_NAME, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME)));
442 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_JAVASCRIPT, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_JAVASCRIPT)));
443 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES)));
444 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES)));
445 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_DOM_STORAGE, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)));
446 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FORM_DATA, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA)));
447 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_EASYLIST, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYLIST)));
448 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_EASYPRIVACY, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYPRIVACY)));
449 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST,
450 importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST)));
451 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST,
452 importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_SOCIAL_BLOCKING_LIST)));
453 domainsContentValues.put(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_ULTRAPRIVACY)));
454 domainsContentValues.put(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS,
455 importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.BLOCK_ALL_THIRD_PARTY_REQUESTS)));
456 domainsContentValues.put(DomainsDatabaseHelper.USER_AGENT, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.USER_AGENT)));
457 domainsContentValues.put(DomainsDatabaseHelper.FONT_SIZE, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.FONT_SIZE)));
458 domainsContentValues.put(DomainsDatabaseHelper.SWIPE_TO_REFRESH, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SWIPE_TO_REFRESH)));
459 domainsContentValues.put(DomainsDatabaseHelper.NIGHT_MODE, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.NIGHT_MODE)));
460 domainsContentValues.put(DomainsDatabaseHelper.DISPLAY_IMAGES, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.DISPLAY_IMAGES)));
461 domainsContentValues.put(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_SSL_CERTIFICATE)));
462 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_COMMON_NAME)));
463 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATION)));
464 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATIONAL_UNIT,
465 importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_TO_ORGANIZATIONAL_UNIT)));
466 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_COMMON_NAME, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_COMMON_NAME)));
467 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATION, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATION)));
468 domainsContentValues.put(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATIONAL_UNIT,
469 importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_ISSUED_BY_ORGANIZATIONAL_UNIT)));
470 domainsContentValues.put(DomainsDatabaseHelper.SSL_START_DATE, importDomainsCursor.getLong(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_START_DATE)));
471 domainsContentValues.put(DomainsDatabaseHelper.SSL_END_DATE, importDomainsCursor.getLong(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.SSL_END_DATE)));
472 domainsContentValues.put(DomainsDatabaseHelper.PINNED_IP_ADDRESSES, importDomainsCursor.getInt(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.PINNED_IP_ADDRESSES)));
473 domainsContentValues.put(DomainsDatabaseHelper.IP_ADDRESSES, importDomainsCursor.getString(importDomainsCursor.getColumnIndex(DomainsDatabaseHelper.IP_ADDRESSES)));
475 // Insert the record into the export database.
476 domainsDatabaseHelper.addDomain(domainsContentValues);
478 // Advance to the next record.
479 importDomainsCursor.moveToNext();
482 // Close the domains cursor.
483 importDomainsCursor.close();
485 // Close the domains database.
486 domainsDatabaseHelper.close();
489 // Get a cursor for the bookmarks table.
490 Cursor importBookmarksCursor = importDatabase.rawQuery("SELECT * FROM " + BookmarksDatabaseHelper.BOOKMARKS_TABLE, null);
492 // Delete the current bookmarks database.
493 context.deleteDatabase(BookmarksDatabaseHelper.BOOKMARKS_DATABASE);
495 // Create a new bookmarks database. The `0` specifies the database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`.
496 BookmarksDatabaseHelper bookmarksDatabaseHelper = new BookmarksDatabaseHelper(context, null, null, 0);
498 // Move to the first bookmark.
499 importBookmarksCursor.moveToFirst();
501 // Copy the data from the import bookmarks cursor into the bookmarks database.
502 for (int i = 0; i < importBookmarksCursor.getCount(); i++) {
503 // Extract the record from the cursor and store the data in a ContentValues.
504 ContentValues bookmarksContentValues = new ContentValues();
505 bookmarksContentValues.put(BookmarksDatabaseHelper.BOOKMARK_NAME, importBookmarksCursor.getString(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)));
506 bookmarksContentValues.put(BookmarksDatabaseHelper.BOOKMARK_URL, importBookmarksCursor.getString(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL)));
507 bookmarksContentValues.put(BookmarksDatabaseHelper.PARENT_FOLDER, importBookmarksCursor.getString(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.PARENT_FOLDER)));
508 bookmarksContentValues.put(BookmarksDatabaseHelper.DISPLAY_ORDER, importBookmarksCursor.getInt(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)));
509 bookmarksContentValues.put(BookmarksDatabaseHelper.IS_FOLDER, importBookmarksCursor.getInt(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)));
510 bookmarksContentValues.put(BookmarksDatabaseHelper.FAVORITE_ICON, importBookmarksCursor.getBlob(importBookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)));
512 // Insert the record into the export database.
513 bookmarksDatabaseHelper.createBookmark(bookmarksContentValues);
515 // Advance to the next record.
516 importBookmarksCursor.moveToNext();
519 // Close the bookmarks cursor.
520 importBookmarksCursor.close();
522 // Close the bookmarks database.
523 bookmarksDatabaseHelper.close();
526 // Get a cursor for the bookmarks table.
527 Cursor importPreferencesCursor = importDatabase.rawQuery("SELECT * FROM " + PREFERENCES_TABLE, null);
529 // Move to the first preference.
530 importPreferencesCursor.moveToFirst();
532 // Import the preference data.
533 sharedPreferences.edit()
534 .putBoolean(JAVASCRIPT, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(JAVASCRIPT)) == 1)
535 .putBoolean(FIRST_PARTY_COOKIES, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(FIRST_PARTY_COOKIES)) == 1)
536 .putBoolean(THIRD_PARTY_COOKIES, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(THIRD_PARTY_COOKIES)) == 1)
537 .putBoolean(DOM_STORAGE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DOM_STORAGE)) == 1)
538 // Save form data can be removed once the minimum API >= 26.
539 .putBoolean(SAVE_FORM_DATA, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(SAVE_FORM_DATA)) == 1)
540 .putString(USER_AGENT, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(USER_AGENT)))
541 .putString(CUSTOM_USER_AGENT, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(CUSTOM_USER_AGENT)))
542 .putBoolean(INCOGNITO_MODE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(INCOGNITO_MODE)) == 1)
543 .putBoolean(DO_NOT_TRACK, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DO_NOT_TRACK)) == 1)
544 .putBoolean(ALLOW_SCREENSHOTS, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(ALLOW_SCREENSHOTS)) == 1)
545 .putBoolean(EASYLIST, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(EASYLIST)) == 1)
546 .putBoolean(EASYPRIVACY, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(EASYPRIVACY)) == 1)
547 .putBoolean(FANBOYS_ANNOYANCE_LIST, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(FANBOYS_ANNOYANCE_LIST)) == 1)
548 .putBoolean(FANBOYS_SOCIAL_BLOCKING_LIST, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(FANBOYS_SOCIAL_BLOCKING_LIST)) == 1)
549 .putBoolean(ULTRAPRIVACY, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(ULTRAPRIVACY)) == 1)
550 .putBoolean(BLOCK_ALL_THIRD_PARTY_REQUESTS, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(BLOCK_ALL_THIRD_PARTY_REQUESTS)) == 1)
551 .putBoolean(PROXY_THROUGH_ORBOT, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(PROXY_THROUGH_ORBOT)) == 1)
552 .putString(TOR_HOMEPAGE, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(TOR_HOMEPAGE)))
553 .putString(TOR_SEARCH, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(TOR_SEARCH)))
554 .putString(TOR_SEARCH_CUSTOM_URL, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(TOR_SEARCH_CUSTOM_URL)))
555 .putString(SEARCH, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(SEARCH)))
556 .putString(SEARCH_CUSTOM_URL, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(SEARCH_CUSTOM_URL)))
557 .putBoolean(FULL_SCREEN_BROWSING_MODE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(FULL_SCREEN_BROWSING_MODE)) == 1)
558 .putBoolean(HIDE_APP_BAR, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(HIDE_APP_BAR)) == 1)
559 .putBoolean(CLEAR_EVERYTHING, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_EVERYTHING)) == 1)
560 .putBoolean(CLEAR_COOKIES, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_COOKIES)) == 1)
561 .putBoolean(CLEAR_DOM_STORAGE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_DOM_STORAGE)) == 1)
562 // Clear form data can be removed once the minimum API >= 26.
563 .putBoolean(CLEAR_FORM_DATA, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_FORM_DATA)) == 1)
564 .putBoolean(CLEAR_CACHE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(CLEAR_CACHE)) == 1)
565 .putString(HOMEPAGE, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(HOMEPAGE)))
566 .putString(FONT_SIZE, importPreferencesCursor.getString(importPreferencesCursor.getColumnIndex(FONT_SIZE)))
567 .putBoolean(SWIPE_TO_REFRESH, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(SWIPE_TO_REFRESH)) == 1)
568 .putBoolean(SCROLL_APP_BAR, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(SCROLL_APP_BAR)) == 1)
569 .putBoolean(DISPLAY_ADDITIONAL_APP_BAR_ICONS, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DISPLAY_ADDITIONAL_APP_BAR_ICONS)) == 1)
570 .putBoolean(DOWNLOAD_WITH_EXTERNAL_APP, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DOWNLOAD_WITH_EXTERNAL_APP)) == 1)
571 .putBoolean(DARK_THEME, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DARK_THEME)) == 1)
572 .putBoolean(NIGHT_MODE, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(NIGHT_MODE)) == 1)
573 .putBoolean(DISPLAY_WEBPAGE_IMAGES, importPreferencesCursor.getInt(importPreferencesCursor.getColumnIndex(DISPLAY_WEBPAGE_IMAGES)) == 1)
576 // Close the preferences cursor.
577 importPreferencesCursor.close();
580 // Close the import database.
581 importDatabase.close();
583 // Create strings for the temporary database files.
584 String shmFileString = temporaryImportFileString + "-shm";
585 String walFileString = temporaryImportFileString + "-wal";
586 String journalFileString = temporaryImportFileString + "-journal";
588 // Get `Files` for the temporary database files.
589 File shmFile = new File(shmFileString);
590 File walFile = new File(walFileString);
591 File journalFile = new File(journalFileString);
593 // Delete the Shared Memory file if it exists.
594 if (shmFile.exists()) {
595 //noinspection ResultOfMethodCallIgnored
599 // Delete the Write Ahead Log file if it exists.
600 if (walFile.exists()) {
601 //noinspection ResultOfMethodCallIgnored
605 // Delete the Journal file if it exists.
606 if (journalFile.exists()) {
607 //noinspection ResultOfMethodCallIgnored
608 journalFile.delete();
611 // Delete the temporary import file.
612 //noinspection ResultOfMethodCallIgnored
613 temporaryImportFile.delete();
615 // Import successful.
616 return IMPORT_SUCCESSFUL;
617 } catch (Exception exception) {
618 // Return the import error.
619 return exception.toString();