/*
- * Copyright © 2018-2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2018-2022 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
*
import java.io.OutputStream
// Define the private class constants.
-private const val SCHEMA_VERSION = 15
+private const val SCHEMA_VERSION = 16
private const val PREFERENCES_TABLE = "preferences"
// Define the private preferences constants.
// Upgrade from schema version 2, first used in Privacy Browser 2.14, to schema version 3, first used in Privacy Browser 2.15.
if (importDatabaseVersion < 3) {
+ // `default_font_size` was renamed `font_size`.
// Once the SQLite version is >= 3.25.0 (Android API >= 30) `ALTER TABLE RENAME COLUMN` can be used. <https://www.sqlite.org/lang_altertable.html> <https://www.sqlite.org/changes.html>
// <https://developer.android.com/reference/android/database/sqlite/package-summary>
// 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.
val scrollAppBar = sharedPreferences.getBoolean(SCROLL_APP_BAR, true)
// Populate the preferences table with the current app bar values.
- // This can switch to using the variables directly once the API >= 30. <https://www.sqlite.org/datatype3.html#boolean_datatype>
+ // 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 (hideAppBar) {
+ if (hideAppBar)
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $HIDE_APP_BAR = 1")
- } else {
+ else
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $HIDE_APP_BAR = 0")
- }
- if (scrollAppBar) {
+ if (scrollAppBar)
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $SCROLL_APP_BAR = 1")
- } else {
+ else
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $SCROLL_APP_BAR = 0")
- }
}
// Upgrade from schema version 5, first used in Privacy Browser 2.17, to schema version 6, first used in Privacy Browser 3.0.
// Populate the preferences table with the current open intents value.
// This can switch to using the variables directly once the API >= 30. <https://www.sqlite.org/datatype3.html#boolean_datatype>
// <https://developer.android.com/reference/android/database/sqlite/package-summary>
- if (openIntentsInNewTab) {
+ if (openIntentsInNewTab)
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $OPEN_INTENTS_IN_NEW_TAB = 1")
- } else {
+ else
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $OPEN_INTENTS_IN_NEW_TAB = 0")
- }
}
// Upgrade from schema version 6, first used in Privacy Browser 3.0, to schema version 7, first used in Privacy Browser 3.1.
// Populate the preferences with the current Tracking Queries value. Google Analytics was renamed Tracking Queries in schema version 15.
// This can switch to using the variables directly once the API >= 30. <https://www.sqlite.org/datatype3.html#boolean_datatype>
// <https://developer.android.com/reference/android/database/sqlite/package-summary>
- if (trackingQueries) {
+ if (trackingQueries)
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET google_analytics = 1")
- } else {
+ else
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET google_analytics = 0")
- }
// Populate the preferences table with the current AMP Redirects value. Twitter AMP Redirects was renamed AMP Redirects in schema version 15.
- if (ampRedirects) {
+ if (ampRedirects)
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET twitter_amp_redirects = 1")
- } else {
+ else
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET twitter_amp_redirects = 0")
- }
// Populate the preferences table with the current wide viewport value.
- if (wideViewport) {
+ if (wideViewport)
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $WIDE_VIEWPORT = 1")
- } else {
+ else
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $WIDE_VIEWPORT = 0")
- }
}
// Upgrade from schema version 7, first used in Privacy Browser 3.1, to schema version 8, first used in Privacy Browser 3.2.
// Populate the preferences table with the current clear logcat value.
// This can switch to using the variables directly once the API >= 30. <https://www.sqlite.org/datatype3.html#boolean_datatype>
// <https://developer.android.com/reference/android/database/sqlite/package-summary>
- if (clearLogcat) {
+ if (clearLogcat)
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $CLEAR_LOGCAT = 1")
- } else {
+ else
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $CLEAR_LOGCAT = 0")
- }
}
// Upgrade from schema version 12, first used in Privacy Browser 3.6, to schema version 13, first used in Privacy Browser 3.7.
// Upgrade from schema version 13, first used in Privacy Browser 3.7, to schema version 14, first used in Privacy Browser 3.8.
if (importDatabaseVersion < 14) {
// `enabledthirdpartycookies` was removed from the domains table. `do_not_track` and `third_party_cookies` were removed from the preferences table.
+ // There is no need to delete the columns as they will simply be ignored by the import.
+ // `enablefirstpartycookies` was renamed `cookies`.
// Once the SQLite version is >= 3.25.0 (Android API >= 30) `ALTER TABLE RENAME COLUMN` can be used. <https://www.sqlite.org/lang_altertable.html> <https://www.sqlite.org/changes.html>
// <https://developer.android.com/reference/android/database/sqlite/package-summary>
// 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.
// Populate the preferences table with the current download with external app value.
// This can switch to using the variables directly once the API >= 30. <https://www.sqlite.org/datatype3.html#boolean_datatype>
// <https://developer.android.com/reference/android/database/sqlite/package-summary>
- if (downloadWithExternalApp) {
+ if (downloadWithExternalApp)
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $DOWNLOAD_WITH_EXTERNAL_APP = 1")
- } else {
+ else
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $DOWNLOAD_WITH_EXTERNAL_APP = 0")
- }
// Populate the preferences table with the current bottom app bar value.
- if (bottomAppBar) {
+ if (bottomAppBar)
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $BOTTOM_APP_BAR = 1")
- } else {
+ else
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $BOTTOM_APP_BAR = 0")
- }
}
// Upgrade from schema version 14, first used in Privacy Browser 3.8, to schema version 15, first used in Privacy Browser 3.11.
if (importDatabaseVersion < 15) {
// `facebook_click_ids` was removed from the preferences table.
+ // There is no need to delete the columns as they will simply be ignored by the import.
- // Once the SQLite version is >= 3.25.0 (Android API >= 30) `ALTER TABLE RENAME COLUMN` can be used. <https://www.sqlite.org/lang_altertable.html> <https://www.sqlite.org/changes.html>
- // <https://developer.android.com/reference/android/database/sqlite/package-summary>
- // 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.
+ // `x_requested_with_header` was previously added to the preferences and domains tables in this version, but it was removed later in schema version 16.
// Create the new URL modification columns.
importDatabase.execSQL("ALTER TABLE $PREFERENCES_TABLE ADD COLUMN $TRACKING_QUERIES BOOLEAN")
importDatabase.execSQL("UPDATE $PREFERENCES_TABLE SET $AMP_REDIRECTS = twitter_amp_redirects")
}
+ // Upgrade from schema version 15, first used in Privacy Browser 3.11, to schema version 16, first used in Privacy Browser 3.12.
+ // This upgrade removed the `x_requested_with_header` from the domains and preferences tables.
+ // There is no need to delete the columns as they will simply be ignored by the import.
+
// Get a cursor for the bookmarks table.
val importBookmarksCursor = importDatabase.rawQuery("SELECT * FROM ${BookmarksDatabaseHelper.BOOKMARKS_TABLE}", null)
exception.toString()
}
}
-}
\ No newline at end of file
+}