diff --git a/app/libgocryptfs/main.go b/app/libgocryptfs/main.go index 0d392f7..78d387b 100644 --- a/app/libgocryptfs/main.go +++ b/app/libgocryptfs/main.go @@ -552,6 +552,12 @@ func gcf_close(sessionID int){ delete(sessions, sessionID) } +//export gcf_is_closed +func gcf_is_closed(sessionID int) bool { + _, ok := sessions[sessionID] + return !ok +} + //export gcf_create_volume func gcf_create_volume(root_cipher_dir string, password []byte, logN int, creator string) bool { err := configfile.Create(filepath.Join(root_cipher_dir, configfile.ConfDefaultName), password, false, logN, creator, false, false) diff --git a/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt index b6d46fc..f9b2f52 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt @@ -54,6 +54,7 @@ open class BaseExplorerActivity : BaseActivity() { protected lateinit var explorerElements: MutableList protected lateinit var explorerAdapter: ExplorerElementAdapter private var isCreating = true + protected var isStartingActivity = false private var usf_open = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -97,6 +98,7 @@ open class BaseExplorerActivity : BaseActivity() { if (sortOrder.isNotEmpty()){ intent.putExtra("sortOrder", sortOrder) } + isStartingActivity = true startActivity(intent) } @@ -196,15 +198,6 @@ open class BaseExplorerActivity : BaseActivity() { .show() } - protected open fun closeVolumeOnUserExit() { - finish() - } - - protected open fun closeVolumeOnDestroy() { - gocryptfsVolume.close() - RestrictedFileProvider.wipeAll(this) //additional security - } - override fun onBackPressed() { if (explorerAdapter.selectedItems.isEmpty()) { val parentPath = PathUtils.getParentPath(currentDirectoryPath) @@ -387,6 +380,7 @@ open class BaseExplorerActivity : BaseActivity() { } R.id.external_open -> { if (usf_open){ + isStartingActivity = true ExternalProvider.open(this, gocryptfsVolume, PathUtils.path_join(currentDirectoryPath, explorerElements[explorerAdapter.selectedItems[0]].name)) unselectAll() } @@ -400,6 +394,17 @@ open class BaseExplorerActivity : BaseActivity() { } } + protected open fun closeVolumeOnUserExit() { + finish() + } + + protected open fun closeVolumeOnDestroy() { + if (!gocryptfsVolume.isClosed()){ + gocryptfsVolume.close() + } + RestrictedFileProvider.wipeAll(this) //additional security + } + override fun onDestroy() { super.onDestroy() if (!isChangingConfigurations) { //activity won't be recreated @@ -407,12 +412,24 @@ open class BaseExplorerActivity : BaseActivity() { } } + override fun onPause() { + super.onPause() + if (!isChangingConfigurations && !isStartingActivity){ + finish() + } + } + override fun onResume() { super.onResume() if (isCreating){ isCreating = false } else { - ExternalProvider.removeFiles(this) + if (gocryptfsVolume.isClosed()){ + finish() + } else { + isStartingActivity = false + ExternalProvider.removeFiles(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 0374f5f..5c16d08 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt @@ -79,6 +79,7 @@ class ExplorerActivity : BaseExplorerActivity() { "importFromOtherVolumes" -> { val intent = Intent(this, OpenActivity::class.java) intent.action = "pick" + isStartingActivity = true startActivityForResult(intent, PICK_OTHER_VOLUME_ITEMS_REQUEST_CODE) } "importFiles" -> { @@ -86,6 +87,7 @@ class ExplorerActivity : BaseExplorerActivity() { intent.type = "*/*" intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true) intent.addCategory(Intent.CATEGORY_OPENABLE) + isStartingActivity = true startActivityForResult(intent, PICK_FILES_REQUEST_CODE) } "createFile" -> { @@ -116,6 +118,7 @@ class ExplorerActivity : BaseExplorerActivity() { val intent = Intent(this, CameraActivity::class.java) intent.putExtra("path", currentDirectoryPath) intent.putExtra("sessionID", gocryptfsVolume.sessionID) + isStartingActivity = true startActivity(intent) } } @@ -425,12 +428,14 @@ class ExplorerActivity : BaseExplorerActivity() { for (i in explorerAdapter.selectedItems) { paths.add(explorerElements[i].fullPath) } + isStartingActivity = true ExternalProvider.share(this, gocryptfsVolume, paths) unselectAll() true } R.id.decrypt -> { val i = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + isStartingActivity = true startActivityForResult(i, PICK_DIRECTORY_REQUEST_CODE) true } 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 2dadd9b..fefd82a 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityPick.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityPick.kt @@ -10,10 +10,10 @@ import sushi.hardcore.droidfs.util.PathUtils import java.util.* class ExplorerActivityPick : BaseExplorerActivity() { - private var result_intent = Intent() + private var resultIntent = Intent() override fun init() { super.init() - result_intent.putExtra("sessionID", gocryptfsVolume.sessionID) + resultIntent.putExtra("sessionID", gocryptfsVolume.sessionID) } override fun onExplorerItemClick(position: Int) { @@ -30,7 +30,7 @@ class ExplorerActivityPick : BaseExplorerActivity() { setCurrentPath(PathUtils.getParentPath(currentDirectoryPath)) } else -> { - result_intent.putExtra("path", full_path) + resultIntent.putExtra("path", full_path) returnActivityResult() } } @@ -42,9 +42,9 @@ class ExplorerActivityPick : BaseExplorerActivity() { override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.explorer_pick, menu) handleMenuItems(menu) - val any_item_selected = explorerAdapter.selectedItems.isNotEmpty() - menu.findItem(R.id.select_all).isVisible = any_item_selected - menu.findItem(R.id.validate).isVisible = any_item_selected + val anyItemSelected = explorerAdapter.selectedItems.isNotEmpty() + menu.findItem(R.id.select_all).isVisible = anyItemSelected + menu.findItem(R.id.validate).isVisible = anyItemSelected return true } @@ -63,8 +63,8 @@ class ExplorerActivityPick : BaseExplorerActivity() { paths.add(PathUtils.path_join(currentDirectoryPath, e.name)) types.add(e.elementType.toInt()) } - result_intent.putStringArrayListExtra("paths", paths) - result_intent.putIntegerArrayListExtra("types", types) + resultIntent.putStringArrayListExtra("paths", paths) + resultIntent.putIntegerArrayListExtra("types", types) returnActivityResult() true } @@ -73,7 +73,7 @@ class ExplorerActivityPick : BaseExplorerActivity() { } private fun returnActivityResult() { - setResult(Activity.RESULT_OK, result_intent) + setResult(Activity.RESULT_OK, resultIntent) finish() } diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/AudioPlayer.kt b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/AudioPlayer.kt index d96d535..f6e13b3 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/AudioPlayer.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/AudioPlayer.kt @@ -7,8 +7,8 @@ import java.io.File class AudioPlayer: MediaPlayer(){ override fun viewFile() { - super.viewFile() setContentView(R.layout.activity_audio_player) + super.viewFile() val filename = File(filePath).name val pos = filename.lastIndexOf('.') music_title.text = if (pos != -1){ 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 39bd7ec..f479e7d 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 @@ -4,12 +4,14 @@ import android.os.Bundle import android.view.View import sushi.hardcore.droidfs.BaseActivity import sushi.hardcore.droidfs.R +import sushi.hardcore.droidfs.provider.RestrictedFileProvider import sushi.hardcore.droidfs.util.GocryptfsVolume import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder abstract class FileViewerActivity: BaseActivity() { lateinit var gocryptfsVolume: GocryptfsVolume lateinit var filePath: String + private var isGoingBackToExplorer = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) filePath = intent.getStringExtra("path")!! @@ -28,6 +30,12 @@ abstract class FileViewerActivity: BaseActivity() { View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION*/ } abstract fun viewFile() + override fun onUserInteraction() { + super.onUserInteraction() + if (window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0){ + hideSystemUi() + } + } fun loadWholeFile(path: String): ByteArray? { val fileSize = gocryptfsVolume.getSize(path) if (fileSize >= 0){ @@ -53,7 +61,7 @@ abstract class FileViewerActivity: BaseActivity() { .setTitle(R.string.error) .setMessage(R.string.read_file_failed) .setCancelable(false) - .setPositiveButton(R.string.ok) { _, _ -> finish() } + .setPositiveButton(R.string.ok) { _, _ -> goBackToExplorer() } .show() } } catch (e: OutOfMemoryError){ @@ -61,7 +69,7 @@ abstract class FileViewerActivity: BaseActivity() { .setTitle(R.string.error) .setMessage(R.string.outofmemoryerror_msg) .setCancelable(false) - .setPositiveButton(getString(R.string.ok)) { _, _ -> finish() } + .setPositiveButton(getString(R.string.ok)) { _, _ -> goBackToExplorer() } .show() } @@ -70,9 +78,32 @@ abstract class FileViewerActivity: BaseActivity() { .setTitle(R.string.error) .setMessage(R.string.get_size_failed) .setCancelable(false) - .setPositiveButton(R.string.ok) { _, _ -> finish() } + .setPositiveButton(R.string.ok) { _, _ -> goBackToExplorer() } .show() } return null } + + protected fun goBackToExplorer(){ + isGoingBackToExplorer = true + finish() + } + + override fun onDestroy() { + super.onDestroy() + if (!isGoingBackToExplorer) { + gocryptfsVolume.close() + RestrictedFileProvider.wipeAll(this) + } + } + + override fun onPause() { + super.onPause() + finish() + } + + override fun onBackPressed() { + super.onBackPressed() + isGoingBackToExplorer = true + } } \ No newline at end of file diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/ImageViewer.kt b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/ImageViewer.kt index 27279f9..897992e 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/ImageViewer.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/ImageViewer.kt @@ -113,10 +113,14 @@ class ImageViewer: FileViewerActivity() { override fun onUserInteraction() { super.onUserInteraction() - if (action_buttons.visibility == View.GONE){ - action_buttons.visibility = View.VISIBLE + action_buttons?.let { handler.removeCallbacks(hideActionButtons) - handler.postDelayed(hideActionButtons, hideDelay) + if (it.visibility == View.GONE){ + it.visibility = View.VISIBLE + handler.postDelayed(hideActionButtons, hideDelay) + } else { + it.visibility = View.GONE + } } } } \ No newline at end of file diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/MediaPlayer.kt b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/MediaPlayer.kt index 63ae814..98e5357 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/MediaPlayer.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/MediaPlayer.kt @@ -29,8 +29,10 @@ abstract class MediaPlayer: FileViewerActivity() { .setTitle(R.string.error) .setMessage(R.string.playing_failed) .setCancelable(false) - .setPositiveButton(R.string.ok) { _, _ -> finish() } + .setPositiveButton(R.string.ok) { _, _ -> goBackToExplorer()} .create() + hideSystemUi() + initializePlayer() } abstract fun bindPlayer(player: SimpleExoPlayer) @@ -77,14 +79,8 @@ abstract class MediaPlayer: FileViewerActivity() { } } - override fun onResume() { - super.onResume() - hideSystemUi() - initializePlayer() - } - - override fun onPause() { - super.onPause() + override fun onDestroy() { + super.onDestroy() releasePlayer() } } \ No newline at end of file diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/TextEditor.kt b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/TextEditor.kt index 62ff071..afd49fd 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/TextEditor.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/TextEditor.kt @@ -34,7 +34,7 @@ class TextEditor: FileViewerActivity() { .setTitle(R.string.error) .setMessage(R.string.outofmemoryerror_msg) .setCancelable(false) - .setPositiveButton(getString(R.string.ok)) { _, _ -> finish() } + .setPositiveButton(getString(R.string.ok)) { _, _ -> goBackToExplorer()} .show() } } @@ -103,13 +103,13 @@ class TextEditor: FileViewerActivity() { .setMessage(R.string.ask_save) .setPositiveButton(getString(R.string.save)) { _, _ -> if (save()){ - finish() + goBackToExplorer() } } - .setNegativeButton(getString(R.string.discard)){ _, _ -> finish() } + .setNegativeButton(getString(R.string.discard)){ _, _ -> goBackToExplorer()} .show() } else { - finish() + goBackToExplorer() } } diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/VideoPlayer.kt b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/VideoPlayer.kt index 69f9240..71eac0e 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/VideoPlayer.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/VideoPlayer.kt @@ -6,8 +6,8 @@ import sushi.hardcore.droidfs.R class VideoPlayer: MediaPlayer() { override fun viewFile() { - super.viewFile() setContentView(R.layout.activity_video_player) + super.viewFile() } override fun bindPlayer(player: SimpleExoPlayer) { diff --git a/app/src/main/java/sushi/hardcore/droidfs/util/GocryptfsVolume.kt b/app/src/main/java/sushi/hardcore/droidfs/util/GocryptfsVolume.kt index d891848..bbbe792 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/util/GocryptfsVolume.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/util/GocryptfsVolume.kt @@ -7,6 +7,7 @@ import java.io.* class GocryptfsVolume(var sessionID: Int) { private external fun native_close(sessionID: Int) + private external fun native_is_closed(sessionID: Int): Boolean private external fun native_list_dir(sessionID: Int, dir_path: String): MutableList private external fun native_open_read_mode(sessionID: Int, file_path: String): Int private external fun native_open_write_mode(sessionID: Int, file_path: String): Int @@ -38,6 +39,10 @@ class GocryptfsVolume(var sessionID: Int) { native_close(sessionID) } + fun isClosed(): Boolean { + return native_is_closed(sessionID) + } + fun listDir(dir_path: String): MutableList { return native_list_dir(sessionID, dir_path) } diff --git a/app/src/main/native/gocryptfs_jni.c b/app/src/main/native/gocryptfs_jni.c index 6f794f8..e0eba96 100644 --- a/app/src/main/native/gocryptfs_jni.c +++ b/app/src/main/native/gocryptfs_jni.c @@ -126,6 +126,12 @@ Java_sushi_hardcore_droidfs_util_GocryptfsVolume_00024Companion_init(JNIEnv *env return sessionID; } +JNIEXPORT jboolean JNICALL +Java_sushi_hardcore_droidfs_util_GocryptfsVolume_native_1is_1closed(JNIEnv *env, jobject thiz, + jint sessionID) { + return gcf_is_closed(sessionID); +} + JNIEXPORT jboolean JNICALL Java_sushi_hardcore_droidfs_util_GocryptfsVolume_00024Companion_changePassword(JNIEnv *env, jclass clazz, jstring jroot_cipher_dir,