- // Clear form data if the API < 26.
- if (Build.VERSION.SDK_INT < 26 && (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_form_data_key), true))) {
- // Ask the WebView database to clear the form data.
- @Suppress("DEPRECATION")
- WebViewDatabase.getInstance(this).clearFormData()
-
- // Manually delete the form data database, as the WebView database sometimes will not flush its changes to disk before system exit is run.
- try {
- // A string array must be used because the database contains a space and `Runtime.exec` will not otherwise escape the string correctly.
- val deleteWebDataProcess = runtime.exec(arrayOf("rm", "-f", "$privateDataDirectoryString/app_webview/Web Data"))
- val deleteWebDataJournalProcess = runtime.exec(arrayOf("rm", "-f", "$privateDataDirectoryString/app_webview/Web Data-journal"))
-
- // Wait until the processes have finished.
- deleteWebDataProcess.waitFor()
- deleteWebDataJournalProcess.waitFor()
- } catch (exception: Exception) {
- // Do nothing if an error is thrown.
- }
- }
-