From: Soren Stoutner Date: Wed, 8 May 2019 22:04:01 +0000 (-0700) Subject: Add option to remove Google Analytics from URLs. https://redmine.stoutner.com/issues/414 X-Git-Tag: v3.1~13 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=0d5f4763ba83016e32a91379ceb66baac63cc0c9;p=PrivacyBrowserAndroid.git Add option to remove Google Analytics from URLs. https://redmine.stoutner.com/issues/414 --- diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml index e1c83ef8..1db0caef 100644 --- a/.idea/assetWizardSettings.xml +++ b/.idea/assetWizardSettings.xml @@ -78,9 +78,10 @@ diff --git a/app/src/main/assets/de/about_licenses_dark.html b/app/src/main/assets/de/about_licenses_dark.html index aaaac72f..86b8293a 100644 --- a/app/src/main/assets/de/about_licenses_dark.html +++ b/app/src/main/assets/de/about_licenses_dark.html @@ -124,6 +124,7 @@

important_devices.

info_outline.

language.

+

link_off.

list.

local_activity.

location_off.

diff --git a/app/src/main/assets/de/about_licenses_light.html b/app/src/main/assets/de/about_licenses_light.html index 69b7a2da..e156dcbc 100644 --- a/app/src/main/assets/de/about_licenses_light.html +++ b/app/src/main/assets/de/about_licenses_light.html @@ -124,6 +124,7 @@

important_devices.

info_outline.

language.

+

link_off.

list.

local_activity.

location_off.

diff --git a/app/src/main/assets/en/about_licenses_dark.html b/app/src/main/assets/en/about_licenses_dark.html index 0283e5b5..2efa366b 100644 --- a/app/src/main/assets/en/about_licenses_dark.html +++ b/app/src/main/assets/en/about_licenses_dark.html @@ -122,6 +122,7 @@

important_devices.

info_outline.

language.

+

link_off.

list.

local_activity.

location_off.

diff --git a/app/src/main/assets/en/about_licenses_light.html b/app/src/main/assets/en/about_licenses_light.html index 2a0b87a1..8da7e035 100644 --- a/app/src/main/assets/en/about_licenses_light.html +++ b/app/src/main/assets/en/about_licenses_light.html @@ -123,6 +123,7 @@

important_devices.

info_outline.

language.

+

link_off.

list.

local_activity.

location_off.

diff --git a/app/src/main/assets/es/about_licenses_dark.html b/app/src/main/assets/es/about_licenses_dark.html index 27318b7e..117dd369 100644 --- a/app/src/main/assets/es/about_licenses_dark.html +++ b/app/src/main/assets/es/about_licenses_dark.html @@ -127,6 +127,7 @@

important_devices.

info_outline.

language.

+

link_off.

list.

local_activity.

location_off.

diff --git a/app/src/main/assets/es/about_licenses_light.html b/app/src/main/assets/es/about_licenses_light.html index 97b70bf8..b2e078ab 100644 --- a/app/src/main/assets/es/about_licenses_light.html +++ b/app/src/main/assets/es/about_licenses_light.html @@ -128,6 +128,7 @@

important_devices.

info_outline.

language.

+

link_off.

list.

local_activity.

location_off.

diff --git a/app/src/main/assets/it/about_licenses_dark.html b/app/src/main/assets/it/about_licenses_dark.html index 4e01d4fa..231f25aa 100644 --- a/app/src/main/assets/it/about_licenses_dark.html +++ b/app/src/main/assets/it/about_licenses_dark.html @@ -131,6 +131,7 @@

important_devices.

info_outline.

language.

+

link_off.

list.

local_activity.

location_off.

diff --git a/app/src/main/assets/it/about_licenses_light.html b/app/src/main/assets/it/about_licenses_light.html index 320d8668..f31976f7 100644 --- a/app/src/main/assets/it/about_licenses_light.html +++ b/app/src/main/assets/it/about_licenses_light.html @@ -132,6 +132,7 @@

important_devices.

info_outline.

language.

+

link_off.

list.

local_activity.

location_off.

diff --git a/app/src/main/assets/ru/about_licenses_dark.html b/app/src/main/assets/ru/about_licenses_dark.html index 1ca17ea5..a7c1bbe0 100644 --- a/app/src/main/assets/ru/about_licenses_dark.html +++ b/app/src/main/assets/ru/about_licenses_dark.html @@ -125,6 +125,7 @@

important_devices.

info_outline.

language.

+

link_off.

list.

local_activity.

location_off.

diff --git a/app/src/main/assets/ru/about_licenses_light.html b/app/src/main/assets/ru/about_licenses_light.html index 7f90a11b..9304d2b8 100644 --- a/app/src/main/assets/ru/about_licenses_light.html +++ b/app/src/main/assets/ru/about_licenses_light.html @@ -125,6 +125,7 @@

important_devices.

info_outline.

language.

+

link_off.

list.

local_activity.

location_off.

diff --git a/app/src/main/assets/shared_images/link_off_dark.png b/app/src/main/assets/shared_images/link_off_dark.png new file mode 100644 index 00000000..2d80b53e Binary files /dev/null and b/app/src/main/assets/shared_images/link_off_dark.png differ diff --git a/app/src/main/assets/shared_images/link_off_light.png b/app/src/main/assets/shared_images/link_off_light.png new file mode 100644 index 00000000..d85bfc6b Binary files /dev/null and b/app/src/main/assets/shared_images/link_off_light.png differ diff --git a/app/src/main/assets/tr/about_licenses_dark.html b/app/src/main/assets/tr/about_licenses_dark.html index 627b822b..aa4fc54d 100644 --- a/app/src/main/assets/tr/about_licenses_dark.html +++ b/app/src/main/assets/tr/about_licenses_dark.html @@ -122,6 +122,7 @@

important_devices.

info_outline.

language.

+

link_off.

list.

local_activity.

location_off.

diff --git a/app/src/main/assets/tr/about_licenses_light.html b/app/src/main/assets/tr/about_licenses_light.html index 8876b9dc..fbe184be 100644 --- a/app/src/main/assets/tr/about_licenses_light.html +++ b/app/src/main/assets/tr/about_licenses_light.html @@ -123,6 +123,7 @@

important_devices.

info_outline.

language.

+

link_off.

list.

local_activity.

location_off.

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 df7cef48..7900b066 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -279,6 +279,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // The swipe refresh layout top padding is used when exiting full screen browsing mode. It is used in an inner class in `initializeWebView()`. private int swipeRefreshLayoutPaddingTop; + // The URL sanitizers are set in `applyAppSettings()` and used in `sanitizeUrl()`. + private boolean sanitizeGoogleAnalytics; + // The download strings are used in `onCreate()`, `onRequestPermissionResult()` and `initializeWebView()`. private String downloadUrl; private String downloadContentDisposition; @@ -2999,6 +3002,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } private void loadUrl(String url) { + // Sanitize the URL. + url = sanitizeUrl(url); + // Apply the domain settings. applyDomainSettings(currentWebView, url, true, false); @@ -3053,6 +3059,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Store the values from the shared preferences in variables. incognitoModeEnabled = sharedPreferences.getBoolean("incognito_mode", false); boolean doNotTrackEnabled = sharedPreferences.getBoolean("do_not_track", false); + sanitizeGoogleAnalytics = sharedPreferences.getBoolean("google_analytics", true); proxyThroughOrbot = sharedPreferences.getBoolean("proxy_through_orbot", false); fullScreenBrowsingModeEnabled = sharedPreferences.getBoolean("full_screen_browsing_mode", false); hideAppBar = sharedPreferences.getBoolean("hide_app_bar", true); @@ -3959,12 +3966,33 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook startActivity(openWithBrowserIntent); } + private String sanitizeUrl(String url) { + // Sanitize Google Analytics. + if (sanitizeGoogleAnalytics) { + // Remove `?utm_`. + if (url.contains("?utm_")) { + url = url.substring(0, url.indexOf("?utm_")); + } + + // Remove `&utm_`. + if (url.contains("&utm_")) { + url = url.substring(0, url.indexOf("&utm_")); + } + } + + // Return the sanitized URL. + return url; + } + public void addTab(View view) { // Add a new tab with a blank URL. addNewTab(""); } private void addNewTab(String url) { + // Sanitize the URL. + url = sanitizeUrl(url); + // Get a handle for the tab layout and the view pager. TabLayout tabLayout = findViewById(R.id.tablayout); ViewPager webViewPager = findViewById(R.id.webviewpager); @@ -4770,6 +4798,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // The deprecated `shouldOverrideUrlLoading` must be used until API >= 24. @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { + // Sanitize the url. + url = sanitizeUrl(url); + if (url.startsWith("http")) { // Load the URL in Privacy Browser. // Apply the domain settings for the new URL. This doesn't do anything if the domain has not changed. boolean userAgentChanged = applyDomainSettings(nestedScrollWebView, url, true, false); 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 35956e94..37225fb6 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java @@ -60,7 +60,7 @@ public class SettingsFragment extends PreferenceFragment { Preference firstPartyCookiesPreference = findPreference("first_party_cookies"); Preference thirdPartyCookiesPreference = findPreference("third_party_cookies"); Preference domStoragePreference = findPreference("dom_storage"); - Preference saveFormDataPreference = findPreference("save_form_data"); // The form data preference can be removed once the minimum API >= 26. + Preference formDataPreference = findPreference("save_form_data"); // The form data preference can be removed once the minimum API >= 26. Preference userAgentPreference = findPreference("user_agent"); Preference customUserAgentPreference = findPreference("custom_user_agent"); Preference incognitoModePreference = findPreference("incognito_mode"); @@ -72,6 +72,7 @@ public class SettingsFragment extends PreferenceFragment { Preference fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list"); Preference ultraPrivacyPreference = findPreference("ultraprivacy"); Preference blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests"); + Preference googleAnalyticsPreference = findPreference("google_analytics"); Preference proxyThroughOrbotPreference = findPreference("proxy_through_orbot"); Preference torHomepagePreference = findPreference("tor_homepage"); Preference torSearchPreference = findPreference("tor_search"); @@ -130,7 +131,7 @@ public class SettingsFragment extends PreferenceFragment { PreferenceCategory clearAndExitCategory = (PreferenceCategory) findPreference("clear_and_exit"); // Remove the form data preferences. - privacyCategory.removePreference(saveFormDataPreference); + privacyCategory.removePreference(formDataPreference); clearAndExitCategory.removePreference(clearFormDataPreference); } @@ -288,12 +289,12 @@ public class SettingsFragment extends PreferenceFragment { // 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", false)) { - saveFormDataPreference.setIcon(R.drawable.form_data_enabled); + formDataPreference.setIcon(R.drawable.form_data_enabled); } else { if (darkTheme) { - saveFormDataPreference.setIcon(R.drawable.form_data_disabled_dark); + formDataPreference.setIcon(R.drawable.form_data_disabled_dark); } else { - saveFormDataPreference.setIcon(R.drawable.form_data_disabled_light); + formDataPreference.setIcon(R.drawable.form_data_disabled_light); } } } @@ -457,6 +458,21 @@ public class SettingsFragment extends PreferenceFragment { } } + // Set the Google Analytics icons according to the theme. + if (savedPreferences.getBoolean("google_analytics", true)) { + if (darkTheme) { + googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_dark); + } else { + googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_light); + } + } else { + if (darkTheme) { + googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_dark); + } else { + googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_light); + } + } + // Set the Tor icons according to the theme. if (proxyThroughOrbot) { // Proxying is enabled. if (darkTheme) { @@ -829,12 +845,12 @@ public class SettingsFragment extends PreferenceFragment { case "save_form_data": // Update the icon. if (sharedPreferences.getBoolean("save_form_data", false)) { - saveFormDataPreference.setIcon(R.drawable.form_data_enabled); + formDataPreference.setIcon(R.drawable.form_data_enabled); } else { if (darkTheme) { - saveFormDataPreference.setIcon(R.drawable.form_data_disabled_dark); + formDataPreference.setIcon(R.drawable.form_data_disabled_dark); } else { - saveFormDataPreference.setIcon(R.drawable.form_data_disabled_light); + formDataPreference.setIcon(R.drawable.form_data_disabled_light); } } break; @@ -1110,6 +1126,23 @@ public class SettingsFragment extends PreferenceFragment { } break; + case "google_analytics": + // Update the icon. + if (sharedPreferences.getBoolean("google_analytics", true)) { + if (darkTheme) { + googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_dark); + } else { + googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_light); + } + } else { + if (darkTheme) { + googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_dark); + } else { + googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_light); + } + } + break; + case "proxy_through_orbot": // Get current settings. boolean currentProxyThroughOrbot = sharedPreferences.getBoolean("proxy_through_orbot", false); diff --git a/app/src/main/res/drawable/modify_url_disabled_dark.xml b/app/src/main/res/drawable/modify_url_disabled_dark.xml new file mode 100644 index 00000000..907eeecc --- /dev/null +++ b/app/src/main/res/drawable/modify_url_disabled_dark.xml @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/modify_url_disabled_light.xml b/app/src/main/res/drawable/modify_url_disabled_light.xml new file mode 100644 index 00000000..a8f2b293 --- /dev/null +++ b/app/src/main/res/drawable/modify_url_disabled_light.xml @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/modify_url_enabled_dark.xml b/app/src/main/res/drawable/modify_url_enabled_dark.xml new file mode 100644 index 00000000..7bcd082d --- /dev/null +++ b/app/src/main/res/drawable/modify_url_enabled_dark.xml @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/modify_url_enabled_light.xml b/app/src/main/res/drawable/modify_url_enabled_light.xml new file mode 100644 index 00000000..8f5c094d --- /dev/null +++ b/app/src/main/res/drawable/modify_url_enabled_light.xml @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/more_disabled_dark.xml b/app/src/main/res/drawable/more_disabled_dark.xml index c877d9be..ca98677d 100644 --- a/app/src/main/res/drawable/more_disabled_dark.xml +++ b/app/src/main/res/drawable/more_disabled_dark.xml @@ -11,7 +11,7 @@ android:viewportWidth="24.0" tools:ignore="VectorRaster"> - + diff --git a/app/src/main/res/drawable/more_disabled_light.xml b/app/src/main/res/drawable/more_disabled_light.xml index 7b6c9b55..1ea8021b 100644 --- a/app/src/main/res/drawable/more_disabled_light.xml +++ b/app/src/main/res/drawable/more_disabled_light.xml @@ -11,7 +11,7 @@ android:viewportWidth="24.0" tools:ignore="VectorRaster"> - + diff --git a/app/src/main/res/drawable/more_enabled_dark.xml b/app/src/main/res/drawable/more_enabled_dark.xml index 4ac57172..d7fcaa5f 100644 --- a/app/src/main/res/drawable/more_enabled_dark.xml +++ b/app/src/main/res/drawable/more_enabled_dark.xml @@ -11,7 +11,7 @@ android:width="24dp" tools:ignore="VectorRaster"> - + diff --git a/app/src/main/res/drawable/more_enabled_light.xml b/app/src/main/res/drawable/more_enabled_light.xml index b61bf654..0f494c9e 100644 --- a/app/src/main/res/drawable/more_enabled_light.xml +++ b/app/src/main/res/drawable/more_enabled_light.xml @@ -11,7 +11,7 @@ android:width="24dp" tools:ignore="VectorRaster"> - + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c48c937e..099857f3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -514,6 +514,9 @@ UltraPrivacy blocks trackers that EasyPrivacy doesn’t because doing so can break websites. Block all third-party requests Blocking all third-party requests increases privacy, but it breaks many websites. + URL Modification + Google Analytics + Remove “?utm_” or “&utm_” and anything after it from URLs. Tor Proxy through Orbot Proxy all web traffic through Orbot on localhost:8118. diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index af3e7a50..dc8ffcba 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -129,6 +129,17 @@ android:defaultValue="false" /> + + + + +