]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Clear the logcat on exit. https://redmine.stoutner.com/issues/382
authorSoren Stoutner <soren@stoutner.com>
Mon, 14 Sep 2020 22:44:55 +0000 (15:44 -0700)
committerSoren Stoutner <soren@stoutner.com>
Mon, 14 Sep 2020 22:44:55 +0000 (15:44 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java
app/src/main/res/drawable/bug_cleared_day.xml [new file with mode: 0644]
app/src/main/res/drawable/bug_cleared_night.xml [new file with mode: 0644]
app/src/main/res/drawable/bug_warning.xml [new file with mode: 0644]
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences.xml

index f9f1780f61c8575eec3a8671a2ac88d5be000073..1635e5df8bcd5e772862d7733f8c4b65a572c2ab 100644 (file)
@@ -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.
index eb70ef25fdf17ce6651778bb34de7d50cb76b253..b7a829da4b1bf1642316bd002ae3259309c68ed7 100644 (file)
@@ -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 (file)
index 0000000..02a0c8d
--- /dev/null
@@ -0,0 +1,13 @@
+<!-- This file comes from the Android Material icon set, where it is called `bug_report`.  It is released under the Apache License 2.0. -->
+<vector
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportHeight="24.0"
+    android:viewportWidth="24.0" >
+
+    <!-- A hard coded color must be used until API >= 21.  Then `@color` or `?attr/colorControlNormal` may be used instead. -->
+    <path
+        android:fillColor="#FF1565C0"
+        android:pathData="M20,8h-2.81c-0.45,-0.78 -1.07,-1.45 -1.82,-1.96L17,4.41 15.59,3l-2.17,2.17C12.96,5.06 12.49,5 12,5c-0.49,0 -0.96,0.06 -1.41,0.17L8.41,3 7,4.41l1.62,1.63C7.88,6.55 7.26,7.22 6.81,8L4,8v2h2.09c-0.05,0.33 -0.09,0.66 -0.09,1v1L4,12v2h2v1c0,0.34 0.04,0.67 0.09,1L4,16v2h2.81c1.04,1.79 2.97,3 5.19,3s4.15,-1.21 5.19,-3L20,18v-2h-2.09c0.05,-0.33 0.09,-0.66 0.09,-1v-1h2v-2h-2v-1c0,-0.34 -0.04,-0.67 -0.09,-1L20,10L20,8zM14,16h-4v-2h4v2zM14,12h-4v-2h4v2z"/>
+</vector>
\ 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 (file)
index 0000000..e595993
--- /dev/null
@@ -0,0 +1,13 @@
+<!-- This file comes from the Android Material icon set, where it is called `bug_report`.  It is released under the Apache License 2.0. -->
+<vector
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportHeight="24.0"
+    android:viewportWidth="24.0" >
+
+    <!-- A hard coded color must be used until API >= 21.  Then `@color` or `?attr/colorControlNormal` may be used instead. -->
+    <path
+        android:fillColor="#FF8AB4F8"
+        android:pathData="M20,8h-2.81c-0.45,-0.78 -1.07,-1.45 -1.82,-1.96L17,4.41 15.59,3l-2.17,2.17C12.96,5.06 12.49,5 12,5c-0.49,0 -0.96,0.06 -1.41,0.17L8.41,3 7,4.41l1.62,1.63C7.88,6.55 7.26,7.22 6.81,8L4,8v2h2.09c-0.05,0.33 -0.09,0.66 -0.09,1v1L4,12v2h2v1c0,0.34 0.04,0.67 0.09,1L4,16v2h2.81c1.04,1.79 2.97,3 5.19,3s4.15,-1.21 5.19,-3L20,18v-2h-2.09c0.05,-0.33 0.09,-0.66 0.09,-1v-1h2v-2h-2v-1c0,-0.34 -0.04,-0.67 -0.09,-1L20,10L20,8zM14,16h-4v-2h4v2zM14,12h-4v-2h4v2z"/>
+</vector>
\ 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 (file)
index 0000000..6c6560a
--- /dev/null
@@ -0,0 +1,13 @@
+<!-- This file comes from the Android Material icon set, where it is called `bug_report`.  It is released under the Apache License 2.0. -->
+<vector
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportHeight="24.0"
+    android:viewportWidth="24.0" >
+
+    <!-- A hard coded color must be used until API >= 21.  Then `@color` or `?attr/colorControlNormal` may be used instead. -->
+    <path
+        android:fillColor="#FFB71C1C"
+        android:pathData="M20,8h-2.81c-0.45,-0.78 -1.07,-1.45 -1.82,-1.96L17,4.41 15.59,3l-2.17,2.17C12.96,5.06 12.49,5 12,5c-0.49,0 -0.96,0.06 -1.41,0.17L8.41,3 7,4.41l1.62,1.63C7.88,6.55 7.26,7.22 6.81,8L4,8v2h2.09c-0.05,0.33 -0.09,0.66 -0.09,1v1L4,12v2h2v1c0,0.34 0.04,0.67 0.09,1L4,16v2h2.81c1.04,1.79 2.97,3 5.19,3s4.15,-1.21 5.19,-3L20,18v-2h-2.09c0.05,-0.33 0.09,-0.66 0.09,-1v-1h2v-2h-2v-1c0,-0.34 -0.04,-0.67 -0.09,-1L20,10L20,8zM14,16h-4v-2h4v2zM14,12h-4v-2h4v2z"/>
+</vector>
\ No newline at end of file
index c66123107f484502b0a51a2d447ac5fe2d2ab83c..36d418b80522a45ba50b682ee2bf1f72800cad0a 100644 (file)
         <string name="hide_app_bar_summary">Hide the app bar that contains the URL.</string>
     <string name="clear_everything">Clear everything</string>
         <!-- The form data part of this string can be removed once the minimum API >= 26. -->
-        <string name="clear_everything_summary">Clears cookies, DOM storage, form data, and WebView’s cache.  Then manually deletes the entire “app_webview” and “cache” directories.</string>
+        <string name="clear_everything_summary">Clears cookies, DOM storage, form data, the logcat, and WebView’s cache.  Then manually deletes the entire “app_webview” and “cache” directories.</string>
         <string name="clear_cookies_preference">Clear cookies</string>
         <string name="clear_cookies_summary">Clears first and third-party cookies.</string>
         <string name="clear_dom_storage_preference">Clear DOM storage</string>
         <string name="clear_dom_storage_summary">Clears DOM storage.</string>
         <string name="clear_form_data_preference">Clear form data</string>  <!-- The form data strings can be removed once the minimum API >= 26. -->
         <string name="clear_form_data_summary">Clears form data.</string>  <!-- The form data strings can be removed once the minimum API >= 26. -->
+        <string name="clear_logcat_preference">Clear logcat</string>
+        <string name="clear_logcat_summary">Clears the logcat.</string>
         <string name="clear_cache">Clear cache</string>
         <string name="clear_cache_summary">Clears WebView’s cache.</string>
     <string name="general">General</string>
 
     <!-- Non-translatable preference keys. -->
     <string name="allow_screenshots_key" translatable="false">allow_screenshots</string>
+    <string name="clear_logcat_key" translatable="false">clear_logcat</string>
 
     <!-- Non-translatable preference default values. -->
     <string name="user_agent_default_value" translatable="false">Privacy Browser</string>
index 0b0142bde3eca71a9f2b29cd165fa64b17d0230f..afb3bde93097b02229eb245a3c69ac8c2dda5e74 100644 (file)
             android:summary="@string/clear_form_data_summary"
             android:defaultValue="true" />
 
+        <SwitchPreference
+            android:key="clear_logcat"
+            android:title="@string/clear_logcat_preference"
+            android:summary="@string/clear_logcat_summary"
+            android:defaultValue="true" />
+
         <SwitchPreference
             android:key="clear_cache"
             android:title="@string/clear_cache"