From 0518a2a0301f591cfb4332d27ef00a218767b945 Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Sun, 9 Aug 2020 17:01:47 +0200 Subject: [PATCH] Close volume onPause from camera and cross-imports --- app/build.gradle | 2 +- .../sushi/hardcore/droidfs/CameraActivity.kt | 26 ++++++++++--- .../sushi/hardcore/droidfs/OpenActivity.kt | 39 +++++++++++++++---- .../droidfs/explorers/ExplorerActivity.kt | 1 + .../droidfs/explorers/ExplorerActivityPick.kt | 21 +++++++--- .../file_viewers/FileViewerActivity.kt | 8 ++-- 6 files changed, 74 insertions(+), 23 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a6ea886..fad5dd9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,7 +15,7 @@ android { minSdkVersion 21 targetSdkVersion 29 versionCode 1 - versionName "1.1.3" + versionName "1.1.4" ndk { abiFilters 'x86_64', 'armeabi-v7a', 'arm64-v8a' diff --git a/app/src/main/java/sushi/hardcore/droidfs/CameraActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/CameraActivity.kt index db98701..87b2fa0 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/CameraActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/CameraActivity.kt @@ -1,7 +1,6 @@ package sushi.hardcore.droidfs import android.graphics.Color -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.text.InputType import android.view.View @@ -13,18 +12,16 @@ import com.otaliastudios.cameraview.PictureResult import com.otaliastudios.cameraview.controls.Facing import com.otaliastudios.cameraview.controls.Flash import kotlinx.android.synthetic.main.activity_camera.* +import sushi.hardcore.droidfs.provider.RestrictedFileProvider import sushi.hardcore.droidfs.util.GocryptfsVolume import sushi.hardcore.droidfs.util.MiscUtils import sushi.hardcore.droidfs.util.PathUtils import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder -import sushi.hardcore.droidfs.widgets.ThemeColor import java.io.ByteArrayInputStream -import java.io.FileOutputStream -import java.io.InputStream import java.text.SimpleDateFormat import java.util.* -class CameraActivity : AppCompatActivity() { +class CameraActivity : BaseActivity() { companion object { private val flashModes = listOf(Flash.AUTO, Flash.ON, Flash.OFF) private const val fileNameRandomMin = 100000 @@ -45,6 +42,7 @@ class CameraActivity : AppCompatActivity() { private lateinit var gocryptfsVolume: GocryptfsVolume private lateinit var outputDirectory: String private lateinit var fileName: String + private var isFinishingIntentionally = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_camera) @@ -135,4 +133,22 @@ class CameraActivity : AppCompatActivity() { dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) dialog.show() } + + override fun onDestroy() { + super.onDestroy() + if (!isFinishingIntentionally) { + gocryptfsVolume.close() + RestrictedFileProvider.wipeAll(this) + } + } + + override fun onPause() { + super.onPause() + finish() + } + + override fun onBackPressed() { + super.onBackPressed() + isFinishingIntentionally = true + } } \ No newline at end of file diff --git a/app/src/main/java/sushi/hardcore/droidfs/OpenActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/OpenActivity.kt index a58745d..c1908a1 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/OpenActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/OpenActivity.kt @@ -4,22 +4,18 @@ import android.app.Activity import android.content.Intent import android.os.Build import android.os.Bundle +import android.view.MenuItem import android.view.View import android.widget.AdapterView.OnItemClickListener -import android.widget.TextView -import android.widget.Toast import androidx.appcompat.app.AppCompatActivity -import kotlinx.android.synthetic.main.activity_open.checkbox_remember_path -import kotlinx.android.synthetic.main.activity_open.checkbox_save_password -import kotlinx.android.synthetic.main.activity_open.edit_password -import kotlinx.android.synthetic.main.activity_open.edit_volume_path -import kotlinx.android.synthetic.main.activity_open.saved_path_listview +import kotlinx.android.synthetic.main.activity_open.* import kotlinx.android.synthetic.main.toolbar.* import sushi.hardcore.droidfs.adapters.SavedVolumesAdapter import sushi.hardcore.droidfs.explorers.ExplorerActivity import sushi.hardcore.droidfs.explorers.ExplorerActivityDrop import sushi.hardcore.droidfs.explorers.ExplorerActivityPick import sushi.hardcore.droidfs.fingerprint_stuff.FingerprintPasswordHashSaver +import sushi.hardcore.droidfs.provider.RestrictedFileProvider import sushi.hardcore.droidfs.util.* import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder import java.io.File @@ -33,6 +29,7 @@ class OpenActivity : BaseActivity() { private lateinit var fingerprintPasswordHashSaver: FingerprintPasswordHashSaver private lateinit var rootCipherDir: String private var sessionID = -1 + private var isFinishingIntentionally = false private var usf_fingerprint = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -65,6 +62,17 @@ class OpenActivity : BaseActivity() { } } + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return when(item.itemId){ + android.R.id.home -> { + isFinishingIntentionally = true + finish() + true + } + else -> super.onOptionsItemSelected(item) + } + } + fun pickDirectory(view: View?) { val i = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) startActivityForResult(i, PICK_DIRECTORY_REQUEST_CODE) @@ -154,6 +162,7 @@ class OpenActivity : BaseActivity() { explorerIntent.putExtras(intent.extras!!) //forward extras } else if (currentIntentAction == "pick") { //pick items to import explorerIntent = Intent(this, ExplorerActivityPick::class.java) + explorerIntent.putExtra("originalSessionID", intent.getIntExtra("sessionID", -1)) explorerIntent.flags = Intent.FLAG_ACTIVITY_FORWARD_RESULT } } @@ -163,6 +172,7 @@ class OpenActivity : BaseActivity() { explorerIntent.putExtra("sessionID", sessionID) explorerIntent.putExtra("volume_name", File(rootCipherDir).name) startActivity(explorerIntent) + isFinishingIntentionally = true finish() } @@ -182,8 +192,16 @@ class OpenActivity : BaseActivity() { } } + override fun onBackPressed() { + super.onBackPressed() + isFinishingIntentionally = true + } + override fun onPause() { super.onPause() + if (intent.action == "pick"){ + finish() + } if (::fingerprintPasswordHashSaver.isInitialized && fingerprintPasswordHashSaver.isListening){ fingerprintPasswordHashSaver.stopListening() if (fingerprintPasswordHashSaver.fingerprintFragment.isAdded){ @@ -195,5 +213,12 @@ class OpenActivity : BaseActivity() { override fun onDestroy() { super.onDestroy() Wiper.wipeEditText(edit_password) + if (intent.action == "pick" && !isFinishingIntentionally){ + val sessionID = intent.getIntExtra("sessionID", -1) + if (sessionID != -1){ + GocryptfsVolume(sessionID).close() + RestrictedFileProvider.wipeAll(this) + } + } } } \ No newline at end of file diff --git a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt index efd5d28..64b36a5 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt @@ -81,6 +81,7 @@ class ExplorerActivity : BaseExplorerActivity() { "importFromOtherVolumes" -> { val intent = Intent(this, OpenActivity::class.java) intent.action = "pick" + intent.putExtra("sessionID", gocryptfsVolume.sessionID) isStartingActivity = true startActivityForResult(intent, PICK_OTHER_VOLUME_ITEMS_REQUEST_CODE) } diff --git a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityPick.kt b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityPick.kt index fefd82a..7a0e3cd 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityPick.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityPick.kt @@ -5,12 +5,13 @@ import android.content.Intent import android.view.Menu import android.view.MenuItem import sushi.hardcore.droidfs.R -import sushi.hardcore.droidfs.provider.RestrictedFileProvider +import sushi.hardcore.droidfs.util.GocryptfsVolume import sushi.hardcore.droidfs.util.PathUtils import java.util.* class ExplorerActivityPick : BaseExplorerActivity() { private var resultIntent = Intent() + private var isFinishingIntentionally = false override fun init() { super.init() resultIntent.putExtra("sessionID", gocryptfsVolume.sessionID) @@ -21,16 +22,16 @@ class ExplorerActivityPick : BaseExplorerActivity() { explorerAdapter.onItemClick(position) if (explorerAdapter.selectedItems.isEmpty()) { if (!wasSelecting) { - val full_path = PathUtils.path_join(currentDirectoryPath, explorerElements[position].name) + val fullPath = PathUtils.path_join(currentDirectoryPath, explorerElements[position].name) when { explorerElements[position].isDirectory -> { - setCurrentPath(full_path) + setCurrentPath(fullPath) } explorerElements[position].isParentFolder -> { setCurrentPath(PathUtils.getParentPath(currentDirectoryPath)) } else -> { - resultIntent.putExtra("path", full_path) + resultIntent.putExtra("path", fullPath) returnActivityResult() } } @@ -74,15 +75,23 @@ class ExplorerActivityPick : BaseExplorerActivity() { private fun returnActivityResult() { setResult(Activity.RESULT_OK, resultIntent) + isFinishingIntentionally = true finish() } override fun closeVolumeOnDestroy() { - //don't close volume - RestrictedFileProvider.wipeAll(this) + if (!isFinishingIntentionally){ + val sessionID = intent.getIntExtra("originalSessionID", -1) + if (sessionID != -1){ + val v = GocryptfsVolume(sessionID) + v.close() + } + super.closeVolumeOnDestroy() + } } override fun closeVolumeOnUserExit() { + isFinishingIntentionally = true super.closeVolumeOnUserExit() super.closeVolumeOnDestroy() } diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/FileViewerActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/FileViewerActivity.kt index f479e7d..ee86816 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/FileViewerActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/FileViewerActivity.kt @@ -11,7 +11,7 @@ import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder abstract class FileViewerActivity: BaseActivity() { lateinit var gocryptfsVolume: GocryptfsVolume lateinit var filePath: String - private var isGoingBackToExplorer = false + private var isFinishingIntentionally = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) filePath = intent.getStringExtra("path")!! @@ -85,13 +85,13 @@ abstract class FileViewerActivity: BaseActivity() { } protected fun goBackToExplorer(){ - isGoingBackToExplorer = true + isFinishingIntentionally = true finish() } override fun onDestroy() { super.onDestroy() - if (!isGoingBackToExplorer) { + if (!isFinishingIntentionally) { gocryptfsVolume.close() RestrictedFileProvider.wipeAll(this) } @@ -104,6 +104,6 @@ abstract class FileViewerActivity: BaseActivity() { override fun onBackPressed() { super.onBackPressed() - isGoingBackToExplorer = true + isFinishingIntentionally = true } } \ No newline at end of file