+ // Upgrade from schema version 17, first used in Privacy Browser 3.15, to schema version 18, first used in Privacy Browser 3.17.
+ if (importDatabaseVersion < 18) {
+ // Create the new columns.
+ importDatabase.execSQL("ALTER TABLE $PREFERENCES_TABLE ADD COLUMN $DISPLAY_UNDER_CUTOUTS BOOLEAN")
+ importDatabase.execSQL("ALTER TABLE $PREFERENCES_TABLE ADD COLUMN $DOWNLOAD_PROVIDER TEXT")
+
+ // Get the current display under cutout value.
+ val displayUnderCutouts = sharedPreferences.getBoolean(DISPLAY_UNDER_CUTOUTS, false)
+
+ // Populate the preferences table with the current display under cutouts value.
+ // This can switch to using the variables directly once the minimum API >= 30. <https://www.sqlite.org/datatype3.html#boolean_datatype>
+ // <https://developer.android.com/reference/android/database/sqlite/package-summary>
+ if (displayUnderCutouts)
+ importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $DISPLAY_UNDER_CUTOUTS = 1")
+ else
+ importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $DISPLAY_UNDER_CUTOUTS = 0")
+
+ // Get the download with external app cursor.
+ val downloadWithExternalAppCursor = importDatabase.rawQuery("SELECT download_with_external_app FROM $PREFERENCES_TABLE", null)
+
+ // Move to the first entry.
+ downloadWithExternalAppCursor.moveToFirst()
+
+ // Get the old download with external app setting.
+ val downloadWithExternalApp = (downloadWithExternalAppCursor.getInt(downloadWithExternalAppCursor.getColumnIndexOrThrow("download_with_external_app")) == 1)
+
+ // Close the cursor.
+ downloadWithExternalAppCursor.close()
+
+ // Get the download provider entry values string array.
+ val downloadProviderEntryValuesStringArray = context.resources.getStringArray(R.array.download_provider_entry_values)
+
+ // Populate the new download provider preference.
+ if (downloadWithExternalApp) // Download with external app.
+ importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $DOWNLOAD_PROVIDER = '${downloadProviderEntryValuesStringArray[2]}'")
+ else // Download with Privacy Browser.
+ importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $DOWNLOAD_PROVIDER = '${downloadProviderEntryValuesStringArray[0]}'")
+ }
+
+ // Upgrade from schema version 18, first used in Privacy Browser 3.17, to schema version 19, first used in Privacy Browser 3.18.
+ // This upgrade removed `enableformdata` from the Domains table and `save_form_data` and `clear_form_data` from the Preferences table.
+ // There is no need to delete the columns as they will simply be ignored by the import.
+
+
+ /* End of database upgrade logic. */
+
+
+ // Get a cursor for the bookmarks table.
+ val importBookmarksCursor = importDatabase.rawQuery("SELECT * FROM $BOOKMARKS_TABLE", null)
+
+ // Delete the current bookmarks database.
+ context.deleteDatabase(BOOKMARKS_DATABASE)
+
+ // Create a new bookmarks database.
+ val bookmarksDatabaseHelper = BookmarksDatabaseHelper(context)
+
+ // Move to the first record.
+ importBookmarksCursor.moveToFirst()
+
+ // Get the bookmarks colum indexes.
+ val bookmarkNameColumnIndex = importBookmarksCursor.getColumnIndexOrThrow(BOOKMARK_NAME)
+ val bookmarkUrlColumnIndex = importBookmarksCursor.getColumnIndexOrThrow(BOOKMARK_URL)
+ val bookmarkParentFolderIdColumnIndex = importBookmarksCursor.getColumnIndexOrThrow(PARENT_FOLDER_ID)
+ val bookmarkDisplayOrderColumnIndex = importBookmarksCursor.getColumnIndexOrThrow(DISPLAY_ORDER)
+ val bookmarkIsFolderColumnIndex = importBookmarksCursor.getColumnIndexOrThrow(IS_FOLDER)
+ val bookmarkFolderIdColumnIndex = importBookmarksCursor.getColumnIndexOrThrow(FOLDER_ID)
+ val bookmarkFavoriteIconColumnIndex = importBookmarksCursor.getColumnIndexOrThrow(FAVORITE_ICON)
+
+ // Copy the data from the import bookmarks cursor into the bookmarks database.
+ for (i in 0 until importBookmarksCursor.count) {
+ // Create a bookmark content values.
+ val bookmarkContentValues = ContentValues()
+
+ // Add the information for this bookmark to the content values.
+ bookmarkContentValues.put(BOOKMARK_NAME, importBookmarksCursor.getString(bookmarkNameColumnIndex))
+ bookmarkContentValues.put(BOOKMARK_URL, importBookmarksCursor.getString(bookmarkUrlColumnIndex))
+ bookmarkContentValues.put(PARENT_FOLDER_ID, importBookmarksCursor.getLong(bookmarkParentFolderIdColumnIndex))
+ bookmarkContentValues.put(DISPLAY_ORDER, importBookmarksCursor.getInt(bookmarkDisplayOrderColumnIndex))
+ bookmarkContentValues.put(IS_FOLDER, importBookmarksCursor.getInt(bookmarkIsFolderColumnIndex))
+ bookmarkContentValues.put(FOLDER_ID, importBookmarksCursor.getLong(bookmarkFolderIdColumnIndex))
+ bookmarkContentValues.put(FAVORITE_ICON, importBookmarksCursor.getBlob(bookmarkFavoriteIconColumnIndex))
+
+ // Insert the content values into the bookmarks database.
+ bookmarksDatabaseHelper.createBookmark(bookmarkContentValues)
+
+ // Advance to the next record.
+ importBookmarksCursor.moveToNext()
+ }
+