From 337aebc73ea8d43fd912198e1eff9fe9f8f8f536 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Fri, 1 Jun 2018 15:39:47 -0700 Subject: [PATCH] Remove form data options from API >= 26. https://redmine.stoutner.com/issues/185 --- .../activities/DomainsActivity.java | 4 +- .../activities/MainWebViewActivity.java | 55 ++++++++----- .../fragments/DomainSettingsFragment.java | 61 ++++++++------- .../fragments/SettingsFragment.java | 78 ++++++++++++------- .../helpers/DomainsDatabaseHelper.java | 10 +-- app/src/main/res/values-de/strings.xml | 1 - app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values-ru/strings.xml | 2 +- app/src/main/res/values/strings.xml | 17 ++-- app/src/main/res/xml/preferences.xml | 3 +- 10 files changed, 140 insertions(+), 93 deletions(-) diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java index 77cde1fa..f0a3a0a1 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/DomainsActivity.java @@ -639,7 +639,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo Switch firstPartyCookiesSwitch = view.findViewById(R.id.domain_settings_first_party_cookies_switch); Switch thirdPartyCookiesSwitch = view.findViewById(R.id.domain_settings_third_party_cookies_switch); Switch domStorageSwitch = view.findViewById(R.id.domain_settings_dom_storage_switch); - Switch formDataSwitch = view.findViewById(R.id.domain_settings_form_data_switch); + Switch formDataSwitch = view.findViewById(R.id.domain_settings_form_data_switch); // Form data can be removed once the minimum API >= 26. Switch easyListSwitch = view.findViewById(R.id.domain_settings_easylist_switch); Switch easyPrivacySwitch = view.findViewById(R.id.domain_settings_easyprivacy_switch); Switch fanboysAnnoyanceSwitch = view.findViewById(R.id.domain_settings_fanboys_annoyance_list_switch); @@ -660,7 +660,7 @@ public class DomainsActivity extends AppCompatActivity implements AddDomainDialo boolean firstPartyCookiesEnabled = firstPartyCookiesSwitch.isChecked(); boolean thirdPartyCookiesEnabled = thirdPartyCookiesSwitch.isChecked(); boolean domStorageEnabled = domStorageSwitch.isChecked(); - boolean formDataEnabled = formDataSwitch.isChecked(); + boolean formDataEnabled = formDataSwitch.isChecked(); // Form data can be removed once the minimum API >= 26. boolean easyListEnabled = easyListSwitch.isChecked(); boolean easyPrivacyEnabled = easyPrivacySwitch.isChecked(); boolean fanboysAnnoyanceEnabled = fanboysAnnoyanceSwitch.isChecked(); diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index 3f96b721..933de06a 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -275,7 +275,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // `domStorageEnabled` is used in `onCreate()`, `onPrepareOptionsMenu()`, `onOptionsItemSelected()`, and `applyDomainSettings()`. private boolean domStorageEnabled; - // `saveFormDataEnabled` is used in `onCreate()`, `onPrepareOptionsMenu()`, `onOptionsItemSelected()`, and `applyDomainSettings()`. + // `saveFormDataEnabled` is used in `onCreate()`, `onPrepareOptionsMenu()`, `onOptionsItemSelected()`, and `applyDomainSettings()`. It can be removed once the minimum API >= 26. private boolean saveFormDataEnabled; // `nightMode` is used in `onCreate()` and `applyDomainSettings()`. @@ -1076,7 +1076,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook firstPartyCookiesEnabled = false; thirdPartyCookiesEnabled = false; domStorageEnabled = false; - saveFormDataEnabled = false; + saveFormDataEnabled = false; // Form data can be removed once the minimum API >= 26. nightMode = false; // Initialize the WebView title. @@ -1583,11 +1583,21 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook MenuItem toggleFirstPartyCookiesMenuItem = menu.findItem(R.id.toggle_first_party_cookies); MenuItem toggleThirdPartyCookiesMenuItem = menu.findItem(R.id.toggle_third_party_cookies); MenuItem toggleDomStorageMenuItem = menu.findItem(R.id.toggle_dom_storage); + MenuItem toggleSaveFormDataMenuItem = menu.findItem(R.id.toggle_save_form_data); // Form data can be removed once the minimum API >= 26. + MenuItem clearFormDataMenuItem = menu.findItem(R.id.clear_form_data); // Form data can be removed once the minimum API >= 26. MenuItem refreshMenuItem = menu.findItem(R.id.refresh); + MenuItem adConsentMenuItem = menu.findItem(R.id.ad_consent); - // Only display third-party cookies if SDK >= 21 + // Only display third-party cookies if API >= 21 toggleThirdPartyCookiesMenuItem.setVisible(Build.VERSION.SDK_INT >= 21); + // Only display the form data menu items if the API < 26. + toggleSaveFormDataMenuItem.setVisible(Build.VERSION.SDK_INT < 26); + clearFormDataMenuItem.setVisible(Build.VERSION.SDK_INT < 26); + + // Only show Ad Consent if this is the free flavor. + adConsentMenuItem.setVisible(BuildConfig.FLAVOR.contentEquals("free")); + // Get the shared preference values. `this` references the current context. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); @@ -1612,15 +1622,14 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook MenuItem toggleFirstPartyCookiesMenuItem = menu.findItem(R.id.toggle_first_party_cookies); MenuItem toggleThirdPartyCookiesMenuItem = menu.findItem(R.id.toggle_third_party_cookies); MenuItem toggleDomStorageMenuItem = menu.findItem(R.id.toggle_dom_storage); - MenuItem toggleSaveFormDataMenuItem = menu.findItem(R.id.toggle_save_form_data); + MenuItem toggleSaveFormDataMenuItem = menu.findItem(R.id.toggle_save_form_data); // Form data can be removed once the minimum API >= 26. MenuItem clearDataMenuItem = menu.findItem(R.id.clear_data); MenuItem clearCookiesMenuItem = menu.findItem(R.id.clear_cookies); MenuItem clearDOMStorageMenuItem = menu.findItem(R.id.clear_dom_storage); - MenuItem clearFormDataMenuItem = menu.findItem(R.id.clear_form_data); + MenuItem clearFormDataMenuItem = menu.findItem(R.id.clear_form_data); // Form data can be removed once the minimum API >= 26. MenuItem fontSizeMenuItem = menu.findItem(R.id.font_size); MenuItem swipeToRefreshMenuItem = menu.findItem(R.id.swipe_to_refresh); MenuItem displayImagesMenuItem = menu.findItem(R.id.display_images); - MenuItem adConsentMenuItem = menu.findItem(R.id.ad_consent); // Set the text for the domain menu item. if (domainSettingsApplied) { @@ -1633,7 +1642,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook toggleFirstPartyCookiesMenuItem.setChecked(firstPartyCookiesEnabled); toggleThirdPartyCookiesMenuItem.setChecked(thirdPartyCookiesEnabled); toggleDomStorageMenuItem.setChecked(domStorageEnabled); - toggleSaveFormDataMenuItem.setChecked(saveFormDataEnabled); + toggleSaveFormDataMenuItem.setChecked(saveFormDataEnabled); // Form data can be removed once the minimum API >= 26. swipeToRefreshMenuItem.setChecked(swipeRefreshLayout.isEnabled()); displayImagesMenuItem.setChecked(mainWebView.getSettings().getLoadsImagesAutomatically()); @@ -1663,9 +1672,11 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Enable `Clear DOM Storage` if there is any. clearDOMStorageMenuItem.setEnabled(localStorageDirectoryNumberOfFiles > 0 || indexedDBDirectoryNumberOfFiles > 0); - // Enable `Clear Form Data` is there is any. - WebViewDatabase mainWebViewDatabase = WebViewDatabase.getInstance(this); - clearFormDataMenuItem.setEnabled(mainWebViewDatabase.hasFormData()); + // Enable `Clear Form Data` is there is any. This can be removed once the minimum API >= 26. + if (Build.VERSION.SDK_INT < 26) { + WebViewDatabase mainWebViewDatabase = WebViewDatabase.getInstance(this); + clearFormDataMenuItem.setEnabled(mainWebViewDatabase.hasFormData()); + } // Enable `Clear Data` if any of the submenu items are enabled. clearDataMenuItem.setEnabled(clearCookiesMenuItem.isEnabled() || clearDOMStorageMenuItem.isEnabled() || clearFormDataMenuItem.isEnabled()); @@ -1727,9 +1738,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook fontSizeMenuItem.setTitle(fontSizeTitle); selectedFontSizeMenuItem.setChecked(true); - // Only show Ad Consent if this is the free flavor. - adConsentMenuItem.setVisible(BuildConfig.FLAVOR.contentEquals("free")); - // Run all the other default commands. super.onPrepareOptionsMenu(menu); @@ -1886,6 +1894,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook mainWebView.reload(); return true; + // Form data can be removed once the minimum API >= 26. case R.id.toggle_save_form_data: // Switch the status of saveFormDataEnabled. saveFormDataEnabled = !saveFormDataEnabled; @@ -1978,6 +1987,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook .show(); return true; + // Form data can be remove once the minimum API >= 26. case R.id.clear_form_data: Snackbar.make(findViewById(R.id.main_webview), R.string.form_data_deleted, Snackbar.LENGTH_LONG) .setAction(R.string.undo, v -> { @@ -2259,8 +2269,8 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } } - // Clear form data. - if (clearEverything || sharedPreferences.getBoolean("clear_form_data", true)) { + // Clear form data if the API < 26. + if ((Build.VERSION.SDK_INT < 26) && (clearEverything || sharedPreferences.getBoolean("clear_form_data", true))) { WebViewDatabase webViewDatabase = WebViewDatabase.getInstance(this); webViewDatabase.clearFormData(); @@ -3394,6 +3404,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook firstPartyCookiesEnabled = (currentHostDomainSettingsCursor.getInt(currentHostDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES)) == 1); thirdPartyCookiesEnabled = (currentHostDomainSettingsCursor.getInt(currentHostDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES)) == 1); domStorageEnabled = (currentHostDomainSettingsCursor.getInt(currentHostDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)) == 1); + // Form data can be removed once the minimum API >= 26. saveFormDataEnabled = (currentHostDomainSettingsCursor.getInt(currentHostDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA)) == 1); easyListEnabled = (currentHostDomainSettingsCursor.getInt(currentHostDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYLIST)) == 1); easyPrivacyEnabled = (currentHostDomainSettingsCursor.getInt(currentHostDomainSettingsCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYPRIVACY)) == 1); @@ -3449,7 +3460,11 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook mainWebView.getSettings().setJavaScriptEnabled(javaScriptEnabled); cookieManager.setAcceptCookie(firstPartyCookiesEnabled); mainWebView.getSettings().setDomStorageEnabled(domStorageEnabled); - mainWebView.getSettings().setSaveFormData(saveFormDataEnabled); + + // Apply the form data setting if the API < 26. + if (Build.VERSION.SDK_INT < 26) { + mainWebView.getSettings().setSaveFormData(saveFormDataEnabled); + } // Apply the font size. if (fontSize == 0) { // Apply the default font size. @@ -3545,7 +3560,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook firstPartyCookiesEnabled = sharedPreferences.getBoolean("first_party_cookies_enabled", false); thirdPartyCookiesEnabled = sharedPreferences.getBoolean("third_party_cookies_enabled", false); domStorageEnabled = sharedPreferences.getBoolean("dom_storage_enabled", false); - saveFormDataEnabled = sharedPreferences.getBoolean("save_form_data_enabled", false); + saveFormDataEnabled = sharedPreferences.getBoolean("save_form_data_enabled", false); // Form data can be removed once the minimum API >= 26. easyListEnabled = sharedPreferences.getBoolean("easylist", true); easyPrivacyEnabled = sharedPreferences.getBoolean("easyprivacy", true); fanboysAnnoyanceListEnabled = sharedPreferences.getBoolean("fanboy_annoyance_list", true); @@ -3560,10 +3575,14 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook mainWebView.getSettings().setJavaScriptEnabled(javaScriptEnabled); cookieManager.setAcceptCookie(firstPartyCookiesEnabled); mainWebView.getSettings().setDomStorageEnabled(domStorageEnabled); - mainWebView.getSettings().setSaveFormData(saveFormDataEnabled); mainWebView.getSettings().setTextZoom(Integer.valueOf(defaultFontSizeString)); swipeRefreshLayout.setEnabled(defaultSwipeToRefresh); + // Apply the form data setting if the API < 26. + if (Build.VERSION.SDK_INT < 26) { + mainWebView.getSettings().setSaveFormData(saveFormDataEnabled); + } + // Reset the pinned SSL certificate information. domainSettingsDatabaseId = -1; pinnedDomainSslCertificate = false; diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java index ea57bc35..477ab9e3 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainSettingsFragment.java @@ -110,8 +110,8 @@ public class DomainSettingsFragment extends Fragment { final ImageView thirdPartyCookiesImageView = domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_imageview); final Switch domStorageEnabledSwitch = domainSettingsView.findViewById(R.id.domain_settings_dom_storage_switch); final ImageView domStorageImageView = domainSettingsView.findViewById(R.id.domain_settings_dom_storage_imageview); - Switch formDataEnabledSwitch = domainSettingsView.findViewById(R.id.domain_settings_form_data_switch); - final ImageView formDataImageView = domainSettingsView.findViewById(R.id.domain_settings_form_data_imageview); + Switch formDataEnabledSwitch = domainSettingsView.findViewById(R.id.domain_settings_form_data_switch); // The form data views can be remove once the minimum API >= 26. + final ImageView formDataImageView = domainSettingsView.findViewById(R.id.domain_settings_form_data_imageview); // The form data views can be remove once the minimum API >= 26. Switch easyListSwitch = domainSettingsView.findViewById(R.id.domain_settings_easylist_switch); ImageView easyListImageView = domainSettingsView.findViewById(R.id.domain_settings_easylist_imageview); Switch easyPrivacySwitch = domainSettingsView.findViewById(R.id.domain_settings_easyprivacy_switch); @@ -181,7 +181,7 @@ public class DomainSettingsFragment extends Fragment { int firstPartyCookiesEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES)); int thirdPartyCookiesEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES)); final int domStorageEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE)); - int formDataEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA)); + int formDataEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA)); // Form data can be remove once the minimum API >= 26. int easyListEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYLIST)); int easyPrivacyEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_EASYPRIVACY)); int fanboysAnnoyanceListInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FANBOYS_ANNOYANCE_LIST)); @@ -453,19 +453,24 @@ public class DomainSettingsFragment extends Fragment { } } - // Set the form data status. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. - if (formDataEnabledInt == 1) { // Form data is on. - formDataEnabledSwitch.setChecked(true); - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_enabled)); - } else { // Form data is off. - // Turn the form data switch to off. - formDataEnabledSwitch.setChecked(false); + // Set the form data status. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons. Form data can be removed once the minimum API >= 26. + if (Build.VERSION.SDK_INT >= 26) { // Form data no longer applies to newer versions of Android. + // Hide the form data switch. + formDataEnabledSwitch.setVisibility(View.GONE); + } else { // Form data should be displayed because this is an older version of Android. + if (formDataEnabledInt == 1) { // Form data is on. + formDataEnabledSwitch.setChecked(true); + formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_enabled)); + } else { // Form data is off. + // Turn the form data switch to off. + formDataEnabledSwitch.setChecked(false); - // Set the icon according to the theme. - if (MainWebViewActivity.darkTheme) { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_dark)); - } else { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_light)); + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_dark)); + } else { + formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_light)); + } } } @@ -1160,20 +1165,22 @@ public class DomainSettingsFragment extends Fragment { } }); - // Set the form data switch listener. - formDataEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { - // Update the icon. - if (isChecked) { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_enabled)); - } else { - // Set the icon according to the theme. - if (MainWebViewActivity.darkTheme) { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_dark)); + // Set the form data switch listener. It can be removed once the minimum API >= 26. + if (Build.VERSION.SDK_INT < 26) { + formDataEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { + // Update the icon. + if (isChecked) { + formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_enabled)); } else { - formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_light)); + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_dark)); + } else { + formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_light)); + } } - } - }); + }); + } // Set the EasyList switch listener. easyListSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> { diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java index cb0ca13e..8e7a7112 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java @@ -26,6 +26,7 @@ import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; import android.preference.Preference; +import android.preference.PreferenceCategory; import android.preference.PreferenceFragment; import android.view.LayoutInflater; import android.view.View; @@ -55,7 +56,7 @@ public class SettingsFragment extends PreferenceFragment { final Preference firstPartyCookiesPreference = findPreference("first_party_cookies_enabled"); final Preference thirdPartyCookiesPreference = findPreference("third_party_cookies_enabled"); final Preference domStoragePreference = findPreference("dom_storage_enabled"); - final Preference saveFormDataPreference = findPreference("save_form_data_enabled"); + final Preference saveFormDataPreference = findPreference("save_form_data_enabled"); // The form data preference can be removed once the minimum API >= 26. final Preference userAgentPreference = findPreference("user_agent"); final Preference customUserAgentPreference = findPreference("custom_user_agent"); final Preference incognitoModePreference = findPreference("incognito_mode"); @@ -77,7 +78,7 @@ public class SettingsFragment extends PreferenceFragment { final Preference clearEverythingPreference = findPreference("clear_everything"); final Preference clearCookiesPreference = findPreference("clear_cookies"); final Preference clearDomStoragePreference = findPreference("clear_dom_storage"); - final Preference clearFormDataPreference = findPreference("clear_form_data"); + final Preference clearFormDataPreference = findPreference("clear_form_data"); // The clear form data preference can be removed once the minimum API >= 26. final Preference clearCachePreference = findPreference("clear_cache"); final Preference homepagePreference = findPreference("homepage"); final Preference defaultFontSizePreference = findPreference("default_font_size"); @@ -96,7 +97,7 @@ public class SettingsFragment extends PreferenceFragment { String torSearchString = savedPreferences.getString("tor_search", "https://3g2upl4pq6kufc4m.onion/html/?q="); String searchString = savedPreferences.getString("search", "https://duckduckgo.com/html/?q="); - // Get booleans from the preferences. + // Get booleans that are used in multiple places from the preferences. final boolean javaScriptEnabled = savedPreferences.getBoolean("javascript_enabled", false); boolean firstPartyCookiesEnabled = savedPreferences.getBoolean("first_party_cookies_enabled", false); boolean thirdPartyCookiesEnabled = savedPreferences.getBoolean("third_party_cookies_enabled", false); @@ -108,18 +109,29 @@ public class SettingsFragment extends PreferenceFragment { boolean clearEverything = savedPreferences.getBoolean("clear_everything", true); final boolean nightMode = savedPreferences.getBoolean("night_mode", false); - // Only enable the third-party preference if first-party cookies are enabled and API >= 21. + // Only enable the third-party cookies preference if first-party cookies are enabled and API >= 21. thirdPartyCookiesPreference.setEnabled(firstPartyCookiesEnabled && (Build.VERSION.SDK_INT >= 21)); // Only enable the DOM storage preference if either JavaScript or Night Mode is enabled. domStoragePreference.setEnabled(javaScriptEnabled || nightMode); + // Remove the form data preferences if the API is >= 26 as they no longer do anything. + if (Build.VERSION.SDK_INT >= 26) { + // Get the categories. + PreferenceCategory privacyCategory = (PreferenceCategory) findPreference("privacy"); + PreferenceCategory clearAndExitCategory = (PreferenceCategory) findPreference("clear_and_exit"); + + // Remove the form data preferences. + privacyCategory.removePreference(saveFormDataPreference); + clearAndExitCategory.removePreference(clearFormDataPreference); + } + // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list is disabled. fanboySocialBlockingListPreference.setEnabled(!fanboyAnnoyanceListEnabled); - // We need to inflated a `WebView` to get the default user agent. + // Inflate a WebView to get the default user agent. LayoutInflater inflater = getActivity().getLayoutInflater(); - // `@SuppressLint("InflateParams")` removes the warning about using `null` as the `ViewGroup`, which in this case makes sense because we don't want to display `bare_webview` on the screen. + // `@SuppressLint("InflateParams")` removes the warning about using `null` as the `ViewGroup`, which in this case makes sense because the `bare_webview` will not be displayed. @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false); final WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview); @@ -201,7 +213,7 @@ public class SettingsFragment extends PreferenceFragment { // Set the status of the `Clear and Exit` preferences. clearCookiesPreference.setEnabled(!clearEverything); clearDomStoragePreference.setEnabled(!clearEverything); - clearFormDataPreference.setEnabled(!clearEverything); + clearFormDataPreference.setEnabled(!clearEverything); // The form data line can be removed once the minimum API is >= 26. clearCachePreference.setEnabled(!clearEverything); // Set the homepage URL as the summary text for the homepage preference. @@ -269,14 +281,16 @@ public class SettingsFragment extends PreferenceFragment { } } - // Set the save form data icon. - if (savedPreferences.getBoolean("save_form_data_enabled", false)) { - saveFormDataPreference.setIcon(R.drawable.form_data_enabled); - } else { - if (MainWebViewActivity.darkTheme) { - saveFormDataPreference.setIcon(R.drawable.form_data_disabled_dark); + // Set the save form data icon if API < 26. Save form data has no effect on API >= 26. + if (Build.VERSION.SDK_INT < 26) { + if (savedPreferences.getBoolean("save_form_data_enabled", false)) { + saveFormDataPreference.setIcon(R.drawable.form_data_enabled); } else { - saveFormDataPreference.setIcon(R.drawable.form_data_disabled_light); + if (MainWebViewActivity.darkTheme) { + saveFormDataPreference.setIcon(R.drawable.form_data_disabled_dark); + } else { + saveFormDataPreference.setIcon(R.drawable.form_data_disabled_light); + } } } @@ -551,15 +565,17 @@ public class SettingsFragment extends PreferenceFragment { clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning); } - // Set the clear form data preference icon. - if (clearEverything || savedPreferences.getBoolean("clear_form_data", true)) { - if (MainWebViewActivity.darkTheme) { - clearFormDataPreference.setIcon(R.drawable.form_data_cleared_dark); + // Set the clear form data preference icon if the API < 26. It has no effect on newer versions of Android. + if (Build.VERSION.SDK_INT < 26) { + if (clearEverything || savedPreferences.getBoolean("clear_form_data", true)) { + if (MainWebViewActivity.darkTheme) { + clearFormDataPreference.setIcon(R.drawable.form_data_cleared_dark); + } else { + clearFormDataPreference.setIcon(R.drawable.form_data_cleared_light); + } } else { - clearFormDataPreference.setIcon(R.drawable.form_data_cleared_light); + clearFormDataPreference.setIcon(R.drawable.form_data_warning); } - } else { - clearFormDataPreference.setIcon(R.drawable.form_data_warning); } // Set the clear cache preference icon. @@ -749,6 +765,7 @@ public class SettingsFragment extends PreferenceFragment { } break; + // Save form data can be removed once the minimum API >= 26. case "save_form_data_enabled": // Update the icon. if (sharedPreferences.getBoolean("save_form_data_enabled", false)) { @@ -1249,7 +1266,7 @@ public class SettingsFragment extends PreferenceFragment { // Update the status of the `Clear and Exit` preferences. clearCookiesPreference.setEnabled(!newClearEverythingBoolean); clearDomStoragePreference.setEnabled(!newClearEverythingBoolean); - clearFormDataPreference.setEnabled(!newClearEverythingBoolean); + clearFormDataPreference.setEnabled(!newClearEverythingBoolean); // This line can be removed once the minimum API >= 26. clearCachePreference.setEnabled(!newClearEverythingBoolean); // Update the `clearEverythingPreference` icon. @@ -1285,15 +1302,17 @@ public class SettingsFragment extends PreferenceFragment { clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning); } - // Update the `clearFormDataPreference` icon. - if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_form_data", true)) { - if (MainWebViewActivity.darkTheme) { - clearFormDataPreference.setIcon(R.drawable.form_data_cleared_dark); + // Update the clear form data preference icon if the API < 26. + if (Build.VERSION.SDK_INT < 26) { + if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_form_data", true)) { + if (MainWebViewActivity.darkTheme) { + clearFormDataPreference.setIcon(R.drawable.form_data_cleared_dark); + } else { + clearFormDataPreference.setIcon(R.drawable.form_data_cleared_light); + } } else { - clearFormDataPreference.setIcon(R.drawable.form_data_cleared_light); + clearFormDataPreference.setIcon(R.drawable.form_data_warning); } - } else { - clearFormDataPreference.setIcon(R.drawable.form_data_warning); } // Update the `clearCachePreference` icon. @@ -1334,6 +1353,7 @@ public class SettingsFragment extends PreferenceFragment { } break; + // This section can be removed once the minimum API >= 26. case "clear_form_data": // Update the icon. if (sharedPreferences.getBoolean("clear_form_data", true)) { diff --git a/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java b/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java index 563040a3..9c94dfd2 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java +++ b/app/src/main/java/com/stoutner/privacybrowser/helpers/DomainsDatabaseHelper.java @@ -38,7 +38,7 @@ public class DomainsDatabaseHelper extends SQLiteOpenHelper { public static final String ENABLE_FIRST_PARTY_COOKIES = "enablefirstpartycookies"; public static final String ENABLE_THIRD_PARTY_COOKIES = "enablethirdpartycookies"; public static final String ENABLE_DOM_STORAGE = "enabledomstorage"; - public static final String ENABLE_FORM_DATA = "enableformdata"; + public static final String ENABLE_FORM_DATA = "enableformdata"; // Form data can be removed once the minimum API >= 26. public static final String ENABLE_EASYLIST = "enableeasylist"; public static final String ENABLE_EASYPRIVACY = "enableeasyprivacy"; public static final String ENABLE_FANBOYS_ANNOYANCE_LIST = "enablefanboysannoyancelist"; @@ -259,7 +259,7 @@ public class DomainsDatabaseHelper extends SQLiteOpenHelper { boolean firstPartyCookiesEnabled = sharedPreferences.getBoolean("first_party_cookies_enabled", false); boolean thirdPartyCookiesEnabled = sharedPreferences.getBoolean("third_party_cookies_enabled", false); boolean domStorageEnabled = sharedPreferences.getBoolean("dom_storage_enabled", false); - boolean saveFormDataEnabled = sharedPreferences.getBoolean("save_form_data_enabled", false); + boolean saveFormDataEnabled = sharedPreferences.getBoolean("save_form_data_enabled", false); // Form data can be removed once the minimum API >= 26. boolean easyListEnabled = sharedPreferences.getBoolean("easylist", true); boolean easyPrivacyEnabled = sharedPreferences.getBoolean("easyprivacy", true); boolean fanboyAnnoyanceListEnabled = sharedPreferences.getBoolean("fanboy_annoyance_list", true); @@ -271,7 +271,7 @@ public class DomainsDatabaseHelper extends SQLiteOpenHelper { domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, firstPartyCookiesEnabled); domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, thirdPartyCookiesEnabled); domainContentValues.put(ENABLE_DOM_STORAGE, domStorageEnabled); - domainContentValues.put(ENABLE_FORM_DATA, saveFormDataEnabled); + domainContentValues.put(ENABLE_FORM_DATA, saveFormDataEnabled); // Form data can be removed once the minimum API >= 26. domainContentValues.put(ENABLE_EASYLIST, easyListEnabled); domainContentValues.put(ENABLE_EASYPRIVACY, easyPrivacyEnabled); domainContentValues.put(ENABLE_FANBOYS_ANNOYANCE_LIST, fanboyAnnoyanceListEnabled); @@ -308,7 +308,7 @@ public class DomainsDatabaseHelper extends SQLiteOpenHelper { domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, firstPartyCookiesEnabled); domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, thirdPartyCookiesEnabled); domainContentValues.put(ENABLE_DOM_STORAGE, domStorageEnabled); - domainContentValues.put(ENABLE_FORM_DATA, formDataEnabled); + domainContentValues.put(ENABLE_FORM_DATA, formDataEnabled); // Form data can be removed once the minimum API >= 26. domainContentValues.put(ENABLE_EASYLIST, easyListEnabled); domainContentValues.put(ENABLE_EASYPRIVACY, easyPrivacyEnabled); domainContentValues.put(ENABLE_FANBOYS_ANNOYANCE_LIST, fanboysAnnoyanceEnabled); @@ -345,7 +345,7 @@ public class DomainsDatabaseHelper extends SQLiteOpenHelper { domainContentValues.put(ENABLE_FIRST_PARTY_COOKIES, firstPartyCookiesEnabled); domainContentValues.put(ENABLE_THIRD_PARTY_COOKIES, thirdPartyCookiesEnabled); domainContentValues.put(ENABLE_DOM_STORAGE, domStorageEnabled); - domainContentValues.put(ENABLE_FORM_DATA, formDataEnabled); + domainContentValues.put(ENABLE_FORM_DATA, formDataEnabled); // Form data can be removed once the minimum API >= 26. domainContentValues.put(ENABLE_EASYLIST, easyListEnabled); domainContentValues.put(ENABLE_EASYPRIVACY, easyPrivacyEnabled); domainContentValues.put(ENABLE_FANBOYS_ANNOYANCE_LIST, fanboysAnnoyanceEnabled); diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 292c2dca..655387a4 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -341,7 +341,6 @@ Herunterziehen zum Aktualisieren Einige Websites funktionieren nicht, wenn "Herunterziehen zum Aktualisieren" eingeschaltet ist. Weitere Icons in der Titelleiste - Icons zum Umschalten von Cookies, DOM-Speicher und Formulardaten neben der Adresszeile anzeigen, wenn noch Platz dafür da ist. Download-Zielordner diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 5cf7989f..93c0fc0b 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -391,7 +391,7 @@ Deslizar para actualizar Algunas webs no funcionan bien si la opción deslizar para actualizar está habilitada. Mostrar iconos adicionales en la barra de aplicación - Mostrar iconos para alternar entre cookies, almacenamiento DOM, y datos de formulario en la barra de aplicación, si hay espacio. + Mostrar iconos en la barra de aplicaciones para refrescar el WebView y, si hay espacio, para alternar entre cookies y almacenamiento DOM. Tema oscuro Cambiar el tema reiniciará Navegador Privado. Modo noche diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 892b82f4..d38edd62 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -388,7 +388,7 @@ Потянуть для обновления Некоторые веб-сайты могут работать некорректно при включении данной опции. Отображать дополнительные значки на панели приложения - Отображение значков для переключения файлов cookie, хранилища DOM и данных формы на панели приложения при наличии места. + Отображать значки на панели приложения для обновления WebView и, при наличии места, для переключения файлов cookie и хранилища DOM Темная тема Изменение темы перезапускает Privacy Browser. Ночной режим diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3a2a9063..84a28419 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -39,8 +39,8 @@ Third-Party Cookies disabled DOM Storage enabled DOM Storage disabled - Form Data enabled - Form Data disabled + Form Data enabled + Form Data disabled Cookies deleted DOM Storage deleted Form Data deleted @@ -126,8 +126,8 @@ First-Party Cookies Third-Party Cookies DOM Storage - Form Data - Clear Data + Form Data + Clear Data Clear Cookies Clear DOM Storage Clear Form Data @@ -268,8 +268,8 @@ This setting requires Android Lollipop (version 5.0) or higher. It has no effect if first-party cookies are disabled. Enable DOM storage by default JavaScript must be enabled for DOM storage to function. - Enable saving of form data by default - Saved form data can auto-populate fields on websites. + Enable saving of form data by default + Saved form data can auto-populate fields on websites. User agent Privacy Browser @@ -403,13 +403,14 @@ Translucent navigation bar Make the navigation bar translucent in full screen browsing mode. Clear everything + Clears cookies, DOM storage, form data, and WebView’s cache. Then manually deletes the entire “app_webview” and “cache” directories. Clear cookies Clears first and third-party cookies. Clear DOM storage Clears DOM storage. - Clear form data - Clears form data. + Clear form data + Clears form data. Clear cache Clears WebView’s cache. General diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index ace949a9..e38eed88 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -47,6 +47,7 @@ android:summary="@string/dom_storage_preference_summary" android:defaultValue="false" /> +