From: Soren Stoutner Date: Mon, 14 Sep 2020 22:44:55 +0000 (-0700) Subject: Clear the logcat on exit. https://redmine.stoutner.com/issues/382 X-Git-Tag: v3.6~22 X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff_plain;h=5917df154b320eadd4c2d935baf30f98fd6055c4 Clear the logcat on exit. https://redmine.stoutner.com/issues/382 --- 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 f9f1780f..1635e5df 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -363,7 +363,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Get the screenshot preference. String appTheme = sharedPreferences.getString("app_theme", getString(R.string.app_theme_default_value)); - boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false); + boolean allowScreenshots = sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false); // Get the theme entry values string array. String[] appThemeEntryValuesStringArray = getResources().getStringArray(R.array.app_theme_entry_values); @@ -4963,6 +4963,19 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } } + // Clear the logcat. + if (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) { + try { + // Clear the logcat. `-c` clears the logcat. `-b all` clears all the buffers (instead of just crash, main, and system). + Process process = Runtime.getRuntime().exec("logcat -b all -c"); + + // Wait for the process to finish. + process.waitFor(); + } catch (IOException|InterruptedException exception) { + // Do nothing. + } + } + // Clear the cache. if (clearEverything || sharedPreferences.getBoolean("clear_cache", true)) { // Clear the cache from each WebView. 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 eb70ef25..b7a829da 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java @@ -81,7 +81,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { Preference customUserAgentPreference = findPreference("custom_user_agent"); Preference incognitoModePreference = findPreference("incognito_mode"); Preference doNotTrackPreference = findPreference("do_not_track"); - Preference allowScreenshotsPreference = findPreference("allow_screenshots"); + Preference allowScreenshotsPreference = findPreference(getString(R.string.allow_screenshots_key)); Preference easyListPreference = findPreference("easylist"); Preference easyPrivacyPreference = findPreference("easyprivacy"); Preference fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list"); @@ -102,6 +102,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { Preference clearCookiesPreference = findPreference("clear_cookies"); Preference clearDomStoragePreference = findPreference("clear_dom_storage"); Preference clearFormDataPreference = findPreference("clear_form_data"); // The clear form data preference can be removed once the minimum API >= 26. + Preference clearLogcatPreference = findPreference(getString(R.string.clear_logcat_key)); Preference clearCachePreference = findPreference("clear_cache"); Preference homepagePreference = findPreference("homepage"); Preference downloadLocationPreference = findPreference("download_location"); @@ -147,6 +148,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { assert clearCookiesPreference != null; assert clearDomStoragePreference != null; assert clearFormDataPreference != null; + assert clearLogcatPreference != null; assert clearCachePreference != null; assert homepagePreference != null; assert downloadLocationPreference != null; @@ -293,10 +295,11 @@ public class SettingsFragment extends PreferenceFragmentCompat { proxyCustomUrlPreference.setEnabled(proxyString.equals("Custom")); - // Set the status of the Clear and Exit preferences. + // Set the status of the clear and exit preferences. clearCookiesPreference.setEnabled(!clearEverything); clearDomStoragePreference.setEnabled(!clearEverything); clearFormDataPreference.setEnabled(!clearEverything); // The form data line can be removed once the minimum API is >= 26. + clearLogcatPreference.setEnabled(!clearEverything); clearCachePreference.setEnabled(!clearEverything); @@ -510,17 +513,17 @@ public class SettingsFragment extends PreferenceFragmentCompat { } // Set the allow screenshots icon. - if (savedPreferences.getBoolean("allow_screenshots", false)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night); - } else { + if (savedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day); + } else { + allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night); } } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day); + } else { + allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night); } } @@ -819,6 +822,17 @@ public class SettingsFragment extends PreferenceFragmentCompat { } } + // Set the clear logcat preference icon. + if (clearEverything || savedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + clearLogcatPreference.setIcon(R.drawable.bug_cleared_day); + } else { + clearLogcatPreference.setIcon(R.drawable.bug_cleared_night); + } + } else { + clearLogcatPreference.setIcon(R.drawable.bug_warning); + } + // Set the clear cache preference icon. if (clearEverything || savedPreferences.getBoolean("clear_cache", true)) { if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { @@ -1187,17 +1201,17 @@ public class SettingsFragment extends PreferenceFragmentCompat { case "allow_screenshots": // Update the icon. - if (sharedPreferences.getBoolean("allow_screenshots", false)) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night); - } else { + if (sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day); + } else { + allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night); } } else { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { - allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night); - } else { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day); + } else { + allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night); } } @@ -1597,16 +1611,17 @@ public class SettingsFragment extends PreferenceFragmentCompat { break; case "clear_everything": - // Store the new `clear_everything` status + // Store the new clear everything status boolean newClearEverythingBoolean = sharedPreferences.getBoolean("clear_everything", true); - // Update the status of the `Clear and Exit` preferences. + // Update the status of the clear and exit preferences. clearCookiesPreference.setEnabled(!newClearEverythingBoolean); clearDomStoragePreference.setEnabled(!newClearEverythingBoolean); clearFormDataPreference.setEnabled(!newClearEverythingBoolean); // This line can be removed once the minimum API >= 26. + clearLogcatPreference.setEnabled(!newClearEverythingBoolean); clearCachePreference.setEnabled(!newClearEverythingBoolean); - // Update the `clearEverythingPreference` icon. + // Update the clear everything preference icon. if (newClearEverythingBoolean) { if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night); @@ -1617,7 +1632,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled); } - // Update the `clearCookiesPreference` icon. + // Update the clear cookies preference icon. if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cookies", true)) { if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night); @@ -1628,7 +1643,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { clearCookiesPreference.setIcon(R.drawable.cookies_warning); } - // Update the `clearDomStoragePreference` icon. + // Update the clear dom storage preference icon. if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_dom_storage", true)) { if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night); @@ -1652,7 +1667,18 @@ public class SettingsFragment extends PreferenceFragmentCompat { } } - // Update the `clearCachePreference` icon. + // Update the clear logcat preference icon. + if (newClearEverythingBoolean || sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + clearLogcatPreference.setIcon(R.drawable.bug_cleared_day); + } else { + clearLogcatPreference.setIcon(R.drawable.bug_cleared_night); + } + } else { + clearLogcatPreference.setIcon(R.drawable.cache_warning); + } + + // Update the clear cache preference icon. if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cache", true)) { if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { clearCachePreference.setIcon(R.drawable.cache_cleared_night); @@ -1704,6 +1730,19 @@ public class SettingsFragment extends PreferenceFragmentCompat { } break; + case "clear_logcat": + // Update the icon. + if (sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { + clearLogcatPreference.setIcon(R.drawable.bug_cleared_day); + } else { + clearLogcatPreference.setIcon(R.drawable.bug_cleared_night); + } + } else { + clearLogcatPreference.setIcon(R.drawable.bug_warning); + } + break; + case "clear_cache": // Update the icon. if (sharedPreferences.getBoolean("clear_cache", true)) { diff --git a/app/src/main/res/drawable/bug_cleared_day.xml b/app/src/main/res/drawable/bug_cleared_day.xml new file mode 100644 index 00000000..02a0c8df --- /dev/null +++ b/app/src/main/res/drawable/bug_cleared_day.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bug_cleared_night.xml b/app/src/main/res/drawable/bug_cleared_night.xml new file mode 100644 index 00000000..e5959931 --- /dev/null +++ b/app/src/main/res/drawable/bug_cleared_night.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bug_warning.xml b/app/src/main/res/drawable/bug_warning.xml new file mode 100644 index 00000000..6c6560ab --- /dev/null +++ b/app/src/main/res/drawable/bug_warning.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c6612310..36d418b8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -607,13 +607,15 @@ Hide the app bar that contains the URL. Clear everything - Clears cookies, DOM storage, form data, and WebView’s cache. Then manually deletes the entire “app_webview” and “cache” directories. + Clears cookies, DOM storage, form data, the logcat, 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 logcat + Clears the logcat. Clear cache Clears WebView’s cache. General @@ -670,6 +672,7 @@ allow_screenshots + clear_logcat Privacy Browser diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 0b0142bd..afb3bde9 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -241,6 +241,12 @@ android:summary="@string/clear_form_data_summary" android:defaultValue="true" /> + +