]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Fix Clear DOM Storage detection. https://redmine.stoutner.com/issues/1242
authorSoren Stoutner <soren@stoutner.com>
Fri, 6 Dec 2024 21:54:43 +0000 (14:54 -0700)
committerSoren Stoutner <soren@stoutner.com>
Fri, 6 Dec 2024 21:54:43 +0000 (14:54 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt
app/src/main/res/xml/network_security_config.xml
build.gradle

index 418fb47e82df9872e6ae0cc3e44bb5a97a03d0cd..bf2c30a21b03ff2ee88b12b27c69c6061b6a3673 100644 (file)
@@ -1186,23 +1186,29 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook
         val privateDataDirectoryString = applicationInfo.dataDir
 
         // Get the storage directories.
-        val localStorageDirectory = File("$privateDataDirectoryString/app_webview/Local Storage/")
-        val indexedDBDirectory = File("$privateDataDirectoryString/app_webview/IndexedDB")
+        val localStorageDirectory = File("$privateDataDirectoryString/app_webview/Default/Local Storage/")
+        val sessionStorageDirectory = File("$privateDataDirectoryString/app_webview/Default/Session Storage/")
+        val indexedDBDirectory = File("$privateDataDirectoryString/app_webview/Default/IndexedDB")
 
         // Initialize the number of files counters.
         var localStorageDirectoryNumberOfFiles = 0
+        var sessionStorageDirectoryNumberOfFiles = 0
         var indexedDBDirectoryNumberOfFiles = 0
 
         // Get a count of the number of files in the Local Storage directory.  The list can be null, in which case a `0` is returned.
         if (localStorageDirectory.exists())
             localStorageDirectoryNumberOfFiles = (localStorageDirectory.list())?.size ?: 0
 
+        // Get a count of the number of files in the Local Storage directory.  The list can be null, in which case a `0` is returned.
+        if (sessionStorageDirectory.exists())
+            sessionStorageDirectoryNumberOfFiles = (sessionStorageDirectory.list())?.size ?: 0
+
         // Get a count of the number of files in the IndexedDB directory.  The list can be null, in which case a `0` is returned.
         if (indexedDBDirectory.exists())
             indexedDBDirectoryNumberOfFiles = (indexedDBDirectory.list())?.size ?: 0
 
         // Enable Clear DOM Storage if there is any.
-        optionsClearDomStorageMenuItem.isEnabled = localStorageDirectoryNumberOfFiles > 0 || indexedDBDirectoryNumberOfFiles > 0
+        optionsClearDomStorageMenuItem.isEnabled = localStorageDirectoryNumberOfFiles > 0 || sessionStorageDirectoryNumberOfFiles > 0 || indexedDBDirectoryNumberOfFiles > 0
 
         // Enable Clear Data if any of the submenu items are enabled.
         optionsClearDataMenuItem.isEnabled = (optionsClearCookiesMenuItem.isEnabled || optionsClearDomStorageMenuItem.isEnabled)
@@ -1474,11 +1480,8 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook
                     .addCallback(object : Snackbar.Callback() {
                         override fun onDismissed(snackbar: Snackbar, event: Int) {
                             if (event != DISMISS_EVENT_ACTION) {  // The snackbar was dismissed without the undo button being pushed.
-                                // Get a handle for the web storage.
-                                val webStorage = WebStorage.getInstance()
-
-                                // Delete the DOM Storage.
-                                webStorage.deleteAllData()
+                                // Ask web storage to clear the DOM storage.
+                                WebStorage.getInstance().deleteAllData()
 
                                 // Initialize a handler to manually delete the DOM storage files and directories.
                                 val deleteDomStorageHandler = Handler(Looper.getMainLooper())
@@ -1494,20 +1497,26 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook
                                         val privateDataDirectoryString = applicationInfo.dataDir
 
                                         // A string array must be used because the directory contains a space and `Runtime.exec` will otherwise not escape the string correctly.
-                                        val deleteLocalStorageProcess = runtime.exec(arrayOf("rm", "-rf", "$privateDataDirectoryString/app_webview/Local Storage/"))
+                                        val deleteLocalStorageProcess = runtime.exec(arrayOf("rm", "-rf", "$privateDataDirectoryString/app_webview/Default/Local Storage/"))
+                                        val deleteSessionStorageProcess = runtime.exec(arrayOf("rm", "-rf", "$privateDataDirectoryString/app_webview/Default/Session Storage/"))
+                                        val deleteWebDataProcess = runtime.exec(arrayOf("rm", "-rf", "$privateDataDirectoryString/app_webview/Default/Web Data"))
+                                        val deleteWebDataJournalProcess = runtime.exec(arrayOf("rm", "-rf", "$privateDataDirectoryString/app_webview/Default/Web Data-journal"))
 
                                         // Multiple commands must be used because `Runtime.exec()` does not like `*`.
-                                        val deleteIndexProcess = runtime.exec("rm -rf $privateDataDirectoryString/app_webview/IndexedDB")
-                                        val deleteQuotaManagerProcess = runtime.exec("rm -f $privateDataDirectoryString/app_webview/QuotaManager")
-                                        val deleteQuotaManagerJournalProcess = runtime.exec("rm -f $privateDataDirectoryString/app_webview/QuotaManager-journal")
-                                        val deleteDatabasesProcess = runtime.exec("rm -rf $privateDataDirectoryString/app_webview/databases")
+                                        val deleteIndexProcess = runtime.exec("rm -rf $privateDataDirectoryString/app_webview/Default/IndexedDB")
+                                        val deleteWebStorageProcess = runtime.exec("rm -rf $privateDataDirectoryString/app_webview/Default/WebStorage")
+                                        val deleteDatabasesProcess = runtime.exec("rm -rf $privateDataDirectoryString/app_webview/Default/databases")
+                                        val deleteBlobStorageProcess = runtime.exec("rm -rf $privateDataDirectoryString/app_webview/Default/blob_storage")
 
                                         // Wait for the processes to finish.
                                         deleteLocalStorageProcess.waitFor()
+                                        deleteSessionStorageProcess.waitFor()
+                                        deleteWebDataProcess.waitFor()
+                                        deleteWebDataJournalProcess.waitFor()
                                         deleteIndexProcess.waitFor()
-                                        deleteQuotaManagerProcess.waitFor()
-                                        deleteQuotaManagerJournalProcess.waitFor()
+                                        deleteWebStorageProcess.waitFor()
                                         deleteDatabasesProcess.waitFor()
+                                        deleteBlobStorageProcess.waitFor()
                                     } catch (exception: Exception) {
                                         // Do nothing if an error is thrown.
                                     }
@@ -3818,20 +3827,26 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook
             // Manually delete the DOM storage files and directories, as web storage sometimes will not flush its changes to disk before system exit is run.
             try {
                 // A string array must be used because the directory contains a space and `Runtime.exec` will otherwise not escape the string correctly.
-                val deleteLocalStorageProcess = runtime.exec(arrayOf("rm", "-rf", "$privateDataDirectoryString/app_webview/Local Storage/"))
+                val deleteLocalStorageProcess = runtime.exec(arrayOf("rm", "-rf", "$privateDataDirectoryString/app_webview/Default/Local Storage/"))
+                val deleteSessionStorageProcess = runtime.exec(arrayOf("rm", "-rf", "$privateDataDirectoryString/app_webview/Default/Session Storage/"))
+                val deleteWebDataProcess = runtime.exec(arrayOf("rm", "-rf", "$privateDataDirectoryString/app_webview/Default/Web Data"))
+                val deleteWebDataJournalProcess = runtime.exec(arrayOf("rm", "-rf", "$privateDataDirectoryString/app_webview/Default/Web Data-journal"))
 
                 // Multiple commands must be used because `Runtime.exec()` does not like `*`.
-                val deleteIndexProcess = runtime.exec("rm -rf $privateDataDirectoryString/app_webview/IndexedDB")
-                val deleteQuotaManagerProcess = runtime.exec("rm -f $privateDataDirectoryString/app_webview/QuotaManager")
-                val deleteQuotaManagerJournalProcess = runtime.exec("rm -f $privateDataDirectoryString/app_webview/QuotaManager-journal")
-                val deleteDatabaseProcess = runtime.exec("rm -rf $privateDataDirectoryString/app_webview/databases")
+                val deleteIndexProcess = runtime.exec("rm -rf $privateDataDirectoryString/app_webview/Default/IndexedDB")
+                val deleteWebStorageProcess = runtime.exec("rm -rf $privateDataDirectoryString/app_webview/Default/WebStorage")
+                val deleteDatabasesProcess = runtime.exec("rm -rf $privateDataDirectoryString/app_webview/Default/databases")
+                val deleteBlobStorageProcess = runtime.exec("rm -rf $privateDataDirectoryString/app_webview/Default/blob_storage")
 
                 // Wait until the processes have finished.
                 deleteLocalStorageProcess.waitFor()
+                deleteSessionStorageProcess.waitFor()
+                deleteWebDataProcess.waitFor()
+                deleteWebDataJournalProcess.waitFor()
                 deleteIndexProcess.waitFor()
-                deleteQuotaManagerProcess.waitFor()
-                deleteQuotaManagerJournalProcess.waitFor()
-                deleteDatabaseProcess.waitFor()
+                deleteWebStorageProcess.waitFor()
+                deleteDatabasesProcess.waitFor()
+                deleteBlobStorageProcess.waitFor()
             } catch (exception: Exception) {
                 // Do nothing if an error is thrown.
             }
index ab43d0d2de254dbb95553c0a7c2c622e2ec82edc..5c140da6c295182863a18388fd7cff42c15ebb61 100644 (file)
@@ -1,22 +1,23 @@
 <?xml version="1.0" encoding="utf-8"?>
 
 <!--
-  Copyright © 2018,2020,2022 Soren Stoutner <soren@stoutner.com>.
+  SPDX-License-Identifier: GPL-3.0-or-later
+  SPDX-FileCopyrightText: 2018, 2020, 2022 Soren Stoutner <soren@stoutner.com>
 
-  This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
+  This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android/>.
 
-  Privacy Browser Android is free software: you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation, either version 3 of the License, or
-  (at your option) any later version.
+  This program is free software: you can redistribute it and/or modify it under
+  the terms of the GNU General Public License as published by the Free Software
+  Foundation, either version 3 of the License, or (at your option) any later
+  version.
 
-  Privacy Browser Android is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
+  This program is distributed in the hope that it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+  details.
 
-  You should have received a copy of the GNU General Public License
-  along with Privacy Browser Android.  If not, see <http://www.gnu.org/licenses/>. -->
+  You should have received a copy of the GNU General Public License along with
+  this program.  If not, see <https://www.gnu.org/licenses/>. -->
 
 <network-security-config xmlns:tools="http://schemas.android.com/tools">
     <!-- Allow HTTP traffic and disable HSTS, which has no benefit for Privacy Browser (because unspecified links default to HTTPS) but has negative fingerprinting implications. -->
index f227d64322a1cc1ffa8e5e9b990dd560f587e2ff..ebbfec32b58ce18ee9530abf221492986e36f457 100644 (file)
@@ -26,7 +26,7 @@ buildscript {
     }
 
     dependencies {
-        classpath 'com.android.tools.build:gradle:8.7.2'
+        classpath 'com.android.tools.build:gradle:8.7.3'
         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20"
 
         // NOTE: Do not place your application dependencies here; they belong