+ // Populate the preferences table with the current font size value.
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + FONT_SIZE + " = '" + fontSize + "'");
+
+ // Upgrade from schema version 3, Privacy Browser 2.15.
+ case 3:
+ // Add the Pinned IP Addresses columns to the domains table.
+ importDatabase.execSQL("ALTER TABLE " + DomainsDatabaseHelper.DOMAINS_TABLE + " ADD COLUMN " + DomainsDatabaseHelper.PINNED_IP_ADDRESSES + " BOOLEAN");
+ importDatabase.execSQL("ALTER TABLE " + DomainsDatabaseHelper.DOMAINS_TABLE + " ADD COLUMN " + DomainsDatabaseHelper.IP_ADDRESSES + " TEXT");
+
+ // Upgrade from schema version 4, Privacy Browser 2.16.
+ case 4:
+ // Add the hide and scroll app bar columns to the preferences table.
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + HIDE_APP_BAR + " BOOLEAN");
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + SCROLL_APP_BAR + " BOOLEAN");
+
+ // Get the current hide and scroll app bar settings.
+ boolean hideAppBar = sharedPreferences.getBoolean(HIDE_APP_BAR, true);
+ boolean scrollAppBar = sharedPreferences.getBoolean(SCROLL_APP_BAR, true);
+
+ // Populate the preferences table with the current app bar values.
+ if (hideAppBar) {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + HIDE_APP_BAR + " = " + 1);
+ } else {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + HIDE_APP_BAR + " = " + 0);
+ }
+
+ if (scrollAppBar) {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + SCROLL_APP_BAR + " = " + 1);
+ } else {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + SCROLL_APP_BAR + " = " + 0);
+ }
+
+ // Upgrade from schema version 5, Privacy Browser 2.17.
+ case 5:
+ // Add the open intents in new tab column to the preferences table.
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + OPEN_INTENTS_IN_NEW_TAB + " BOOLEAN");
+
+ // Get the current open intents in new tab preference.
+ boolean openIntentsInNewTab = sharedPreferences.getBoolean(OPEN_INTENTS_IN_NEW_TAB, true);
+
+ // Populate the preferences table with the current open intents value.
+ if (openIntentsInNewTab) {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + OPEN_INTENTS_IN_NEW_TAB + " = " + 1);
+ } else {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + OPEN_INTENTS_IN_NEW_TAB + " = " + 0);
+ }
+
+ // Upgrade from schema version 6, Privacy Browser 3.0.
+ case 6:
+ // Add the wide viewport column to the domains table.
+ importDatabase.execSQL("ALTER TABLE " + DomainsDatabaseHelper.DOMAINS_TABLE + " ADD COLUMN " + DomainsDatabaseHelper.WIDE_VIEWPORT + " INTEGER");
+
+ // Add the Google Analytics, Facebook Click IDs, Twitter AMP redirects, and wide viewport columns to the preferences table.
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + GOOGLE_ANALYTICS + " BOOLEAN");
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + FACEBOOK_CLICK_IDS + " BOOLEAN");
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + TWITTER_AMP_REDIRECTS + " BOOLEAN");
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + WIDE_VIEWPORT + " BOOLEAN");
+
+ // Get the current preference values.
+ boolean googleAnalytics = sharedPreferences.getBoolean(GOOGLE_ANALYTICS, true);
+ boolean facebookClickIds = sharedPreferences.getBoolean(FACEBOOK_CLICK_IDS, true);
+ boolean twitterAmpRedirects = sharedPreferences.getBoolean(TWITTER_AMP_REDIRECTS, true);
+ boolean wideViewport = sharedPreferences.getBoolean(WIDE_VIEWPORT, true);
+
+ // Populate the preferences with the current Google Analytics value.
+ if (googleAnalytics) {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + GOOGLE_ANALYTICS + " = " + 1);
+ } else {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + GOOGLE_ANALYTICS + " = " + 0);
+ }
+
+ // Populate the preferences with the current Facebook Click IDs value.
+ if (facebookClickIds) {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + FACEBOOK_CLICK_IDS + " = " + 1);
+ } else {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + FACEBOOK_CLICK_IDS + " = " + 0);
+ }
+
+ // Populate the preferences table with the current Twitter AMP redirects value.
+ if (twitterAmpRedirects) {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + TWITTER_AMP_REDIRECTS + " = " + 1);
+ } else {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + TWITTER_AMP_REDIRECTS + " = " + 0);
+ }
+
+ // Populate the preferences table with the current wide viewport value.
+ if (wideViewport) {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + WIDE_VIEWPORT + " = " + 1);
+ } else {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + WIDE_VIEWPORT + " = " + 0);
+ }
+
+ // Upgrade from schema version 7, Privacy Browser 3.1.
+ case 7:
+ // Add the UltraList column to the domains table.
+ importDatabase.execSQL("ALTER TABLE " + DomainsDatabaseHelper.DOMAINS_TABLE + " ADD COLUMN " + DomainsDatabaseHelper.ULTRALIST + " BOOLEAN");
+
+ // Add the UltraList column to the preferences table.
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + ULTRALIST + " BOOLEAN");
+
+ // Get the current preference values.
+ boolean ultraList = sharedPreferences.getBoolean(ULTRALIST, true);
+
+ // Populate the preferences tables with the current UltraList value.
+ if (ultraList) {
+ importDatabase.execSQL("UPDATE " + DomainsDatabaseHelper.DOMAINS_TABLE + " SET " + DomainsDatabaseHelper.ULTRALIST + " = " + 1);
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + ULTRALIST + " = " + 1);
+ } else {
+ importDatabase.execSQL("UPDATE " + DomainsDatabaseHelper.DOMAINS_TABLE + " SET " + DomainsDatabaseHelper.ULTRALIST + " = " + 0);
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + ULTRALIST + " = " + 0);
+ }
+
+ // Upgrade from schema version 8, Privacy Browser 3.2.
+ case 8:
+ // Add the new proxy columns to the preferences table.
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + PROXY + " TEXT");
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + PROXY_CUSTOM_URL + " TEXT");
+
+ // Get the current proxy values.
+ String proxy = sharedPreferences.getString(PROXY, context.getString(R.string.proxy_default_value));
+ String proxyCustomUrl = sharedPreferences.getString(PROXY_CUSTOM_URL, context.getString(R.string.proxy_custom_url_default_value));
+
+ // SQL escape the proxy custom URL string.
+ proxyCustomUrl = DatabaseUtils.sqlEscapeString(proxyCustomUrl);
+
+ // Populate the preferences table with the current proxy values. The proxy custom URL does not need to be surrounded by `'` because it was SLQ escaped above.
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + PROXY + " = '" + proxy + "'");
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + PROXY_CUSTOM_URL + " = " + proxyCustomUrl);
+
+ // Upgrade from schema version 9, Privacy Browser 3.3.
+ case 9:
+ // Add the download location columns to the preferences table.
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + DOWNLOAD_LOCATION + " TEXT");
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + DOWNLOAD_CUSTOM_LOCATION + " TEXT");
+
+ // Get the current download location values.
+ String downloadLocation = sharedPreferences.getString(DOWNLOAD_LOCATION, context.getString(R.string.download_location_default_value));
+ String downloadCustomLocation = sharedPreferences.getString(DOWNLOAD_CUSTOM_LOCATION, context.getString(R.string.download_custom_location_default_value));
+
+ // Populate the preferences table with the current download location values.
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + DOWNLOAD_LOCATION + " = '" + downloadLocation + "'");
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + DOWNLOAD_CUSTOM_LOCATION + " = '" + downloadCustomLocation + "'");
+
+ // Upgrade from schema version 10, Privacy Browser 3.4.
+ case 10:
+ // Add the app theme column to the preferences table.
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + APP_THEME + " TEXT");
+
+ // Get a cursor for the dark theme preference.
+ Cursor darkThemePreferencesCursor = importDatabase.rawQuery("SELECT dark_theme FROM " + PREFERENCES_TABLE, null);
+
+ // Move to the first preference.
+ darkThemePreferencesCursor.moveToFirst();
+
+ // Get the old dark theme value, which is in column 0.
+ int darkTheme = darkThemePreferencesCursor.getInt(0);
+
+ // Close the dark theme preference cursor.
+ darkThemePreferencesCursor.close();
+
+ // Populate the app theme according to the old dark theme preference.
+ if (darkTheme == 0) { // A light theme was selected.
+ // Set the app theme to be the system default.
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + APP_THEME + " = 'System default'");
+ } else { // A dark theme was selected.
+ // Set the app theme to be dark.
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + APP_THEME + " = 'Dark'");
+ }
+
+ // Add the WebView theme to the domains table. This defaults to 0, which is `System default`, so a separate step isn't needed to populate the database.
+ importDatabase.execSQL("ALTER TABLE " + DomainsDatabaseHelper.DOMAINS_TABLE + " ADD COLUMN " + DomainsDatabaseHelper.WEBVIEW_THEME + " INTEGER");
+
+ // Add the WebView theme to the preferences table.
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + WEBVIEW_THEME + " TEXT");
+
+ // Get the WebView theme default value string.
+ String webViewThemeDefaultValue = context.getString(R.string.webview_theme_default_value);
+
+ // Set the WebView theme in the preferences table to be the default.
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + WEBVIEW_THEME + " = " + "'" + webViewThemeDefaultValue + "'");
+
+ // Upgrade from schema version 11, Privacy Browser 3.5.
+ case 11:
+ // Add the clear logcat column to the preferences table.
+ importDatabase.execSQL("ALTER TABLE " + PREFERENCES_TABLE + " ADD COLUMN " + CLEAR_LOGCAT + " BOOLEAN");
+
+ // Get the current clear logcat value.
+ boolean clearLogcat = sharedPreferences.getBoolean(CLEAR_LOGCAT, true);
+
+ // Populate the preference table with the current clear logcat value.
+ if (clearLogcat) {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + CLEAR_LOGCAT + " = " + 1);
+ } else {
+ importDatabase.execSQL("UPDATE " + PREFERENCES_TABLE + " SET " + CLEAR_LOGCAT + " = " + 0);
+ }