X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FImportExportActivity.java;h=5ff99d6f709f459e5663361e391361fbdf90e9dc;hp=548316dddba222bb8184f982902a2088ee3e7145;hb=6f8247bfc1b2c231e99302568a7b962b24174580;hpb=9338dfa2f8a295736d35e4f468f0c0ba573a1b58 diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/ImportExportActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/ImportExportActivity.java index 548316dd..5ff99d6f 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/ImportExportActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/ImportExportActivity.java @@ -1,5 +1,5 @@ /* - * Copyright © 2018-2022 Soren Stoutner . + * Copyright 2018-2022 Soren Stoutner . * * This file is part of Privacy Browser Android . * @@ -26,7 +26,6 @@ import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; import android.os.Handler; -import android.preference.PreferenceManager; import android.text.Editable; import android.text.TextWatcher; import android.view.View; @@ -46,6 +45,7 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.cardview.widget.CardView; import androidx.core.content.FileProvider; +import androidx.preference.PreferenceManager; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.textfield.TextInputLayout; @@ -105,6 +105,7 @@ public class ImportExportActivity extends AppCompatActivity { Button importExportButton; // Define the class variables. + private File fileProviderDirectory; private boolean openKeychainInstalled; private File temporaryPgpEncryptedImportFile; private File temporaryPreEncryptedExportFile; @@ -123,9 +124,6 @@ public class ImportExportActivity extends AppCompatActivity { getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); } - // Set the theme. - setTheme(R.style.PrivacyBrowser); - // Run the default commands. super.onCreate(savedInstanceState); @@ -502,6 +500,13 @@ public class ImportExportActivity extends AppCompatActivity { //noinspection ResultOfMethodCallIgnored temporaryPgpEncryptedImportFile.delete(); } + + // Delete the file provider directory if it exists. + if (fileProviderDirectory.exists()) { + //noinspection ResultOfMethodCallIgnored + fileProviderDirectory.delete(); + } + break; case OPENPGP_EXPORT_RESULT_CODE: @@ -510,6 +515,13 @@ public class ImportExportActivity extends AppCompatActivity { //noinspection ResultOfMethodCallIgnored temporaryPreEncryptedExportFile.delete(); } + + // Delete the file provider directory if it exists. + if (fileProviderDirectory.exists()) { + //noinspection ResultOfMethodCallIgnored + fileProviderDirectory.delete(); + } + break; } } @@ -660,8 +672,15 @@ public class ImportExportActivity extends AppCompatActivity { case OPENPGP_ENCRYPTION: try { + // Get a handle for the file provider directory. + fileProviderDirectory = new File(getApplicationContext().getCacheDir() + "/" + getString(R.string.file_provider_directory)); + + // Create the file provider directory. Any errors will be handled by the catch statement below. + //noinspection ResultOfMethodCallIgnored + fileProviderDirectory.mkdir(); + // Set the temporary PGP encrypted import file. - temporaryPgpEncryptedImportFile = File.createTempFile("temporary_pgp_encrypted_import_file", null, getApplicationContext().getCacheDir()); + temporaryPgpEncryptedImportFile = File.createTempFile("temporary_pgp_encrypted_import_file", null, fileProviderDirectory); // Create a temporary PGP encrypted import file output stream. FileOutputStream temporaryPgpEncryptedImportFileOutputStream = new FileOutputStream(temporaryPgpEncryptedImportFile); @@ -861,8 +880,15 @@ public class ImportExportActivity extends AppCompatActivity { case OPENPGP_ENCRYPTION: try { + // Get a handle for the file provider directory. + fileProviderDirectory = new File(getApplicationContext().getCacheDir() + "/" + getString(R.string.file_provider_directory)); + + // Create the file provider directory. Any errors will be handled by the catch statement below. + //noinspection ResultOfMethodCallIgnored + fileProviderDirectory.mkdir(); + // Set the temporary pre-encrypted export file. - temporaryPreEncryptedExportFile = new File(getApplicationContext().getCacheDir() + "/" + getString(R.string.settings) + " " + BuildConfig.VERSION_NAME + ".pbs"); + temporaryPreEncryptedExportFile = new File(fileProviderDirectory + "/" + getString(R.string.settings) + " " + BuildConfig.VERSION_NAME + ".pbs"); // Delete the temporary pre-encrypted export file if it already exists. if (temporaryPreEncryptedExportFile.exists()) { @@ -935,4 +961,4 @@ public class ImportExportActivity extends AppCompatActivity { // Restart Privacy Browser after 150 milliseconds to allow enough time for the preferences to be saved. restartHandler.postDelayed(restartRunnable, 150); } -} \ No newline at end of file +}