Close volume onPause & FileViewer fullscreen fixes

This commit is contained in:
Hardcore Sushi 2020-08-08 14:09:34 +02:00
parent 62e04027d2
commit 35a2e35bdc
12 changed files with 110 additions and 40 deletions

View File

@ -552,6 +552,12 @@ func gcf_close(sessionID int){
delete(sessions, sessionID) delete(sessions, sessionID)
} }
//export gcf_is_closed
func gcf_is_closed(sessionID int) bool {
_, ok := sessions[sessionID]
return !ok
}
//export gcf_create_volume //export gcf_create_volume
func gcf_create_volume(root_cipher_dir string, password []byte, logN int, creator string) bool { 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) err := configfile.Create(filepath.Join(root_cipher_dir, configfile.ConfDefaultName), password, false, logN, creator, false, false)

View File

@ -54,6 +54,7 @@ open class BaseExplorerActivity : BaseActivity() {
protected lateinit var explorerElements: MutableList<ExplorerElement> protected lateinit var explorerElements: MutableList<ExplorerElement>
protected lateinit var explorerAdapter: ExplorerElementAdapter protected lateinit var explorerAdapter: ExplorerElementAdapter
private var isCreating = true private var isCreating = true
protected var isStartingActivity = false
private var usf_open = false private var usf_open = false
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -97,6 +98,7 @@ open class BaseExplorerActivity : BaseActivity() {
if (sortOrder.isNotEmpty()){ if (sortOrder.isNotEmpty()){
intent.putExtra("sortOrder", sortOrder) intent.putExtra("sortOrder", sortOrder)
} }
isStartingActivity = true
startActivity(intent) startActivity(intent)
} }
@ -196,15 +198,6 @@ open class BaseExplorerActivity : BaseActivity() {
.show() .show()
} }
protected open fun closeVolumeOnUserExit() {
finish()
}
protected open fun closeVolumeOnDestroy() {
gocryptfsVolume.close()
RestrictedFileProvider.wipeAll(this) //additional security
}
override fun onBackPressed() { override fun onBackPressed() {
if (explorerAdapter.selectedItems.isEmpty()) { if (explorerAdapter.selectedItems.isEmpty()) {
val parentPath = PathUtils.getParentPath(currentDirectoryPath) val parentPath = PathUtils.getParentPath(currentDirectoryPath)
@ -387,6 +380,7 @@ open class BaseExplorerActivity : BaseActivity() {
} }
R.id.external_open -> { R.id.external_open -> {
if (usf_open){ if (usf_open){
isStartingActivity = true
ExternalProvider.open(this, gocryptfsVolume, PathUtils.path_join(currentDirectoryPath, explorerElements[explorerAdapter.selectedItems[0]].name)) ExternalProvider.open(this, gocryptfsVolume, PathUtils.path_join(currentDirectoryPath, explorerElements[explorerAdapter.selectedItems[0]].name))
unselectAll() 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() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
if (!isChangingConfigurations) { //activity won't be recreated 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() { override fun onResume() {
super.onResume() super.onResume()
if (isCreating){ if (isCreating){
isCreating = false isCreating = false
} else { } else {
ExternalProvider.removeFiles(this) if (gocryptfsVolume.isClosed()){
finish()
} else {
isStartingActivity = false
ExternalProvider.removeFiles(this)
}
} }
} }
} }

View File

@ -79,6 +79,7 @@ class ExplorerActivity : BaseExplorerActivity() {
"importFromOtherVolumes" -> { "importFromOtherVolumes" -> {
val intent = Intent(this, OpenActivity::class.java) val intent = Intent(this, OpenActivity::class.java)
intent.action = "pick" intent.action = "pick"
isStartingActivity = true
startActivityForResult(intent, PICK_OTHER_VOLUME_ITEMS_REQUEST_CODE) startActivityForResult(intent, PICK_OTHER_VOLUME_ITEMS_REQUEST_CODE)
} }
"importFiles" -> { "importFiles" -> {
@ -86,6 +87,7 @@ class ExplorerActivity : BaseExplorerActivity() {
intent.type = "*/*" intent.type = "*/*"
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true) intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
intent.addCategory(Intent.CATEGORY_OPENABLE) intent.addCategory(Intent.CATEGORY_OPENABLE)
isStartingActivity = true
startActivityForResult(intent, PICK_FILES_REQUEST_CODE) startActivityForResult(intent, PICK_FILES_REQUEST_CODE)
} }
"createFile" -> { "createFile" -> {
@ -116,6 +118,7 @@ class ExplorerActivity : BaseExplorerActivity() {
val intent = Intent(this, CameraActivity::class.java) val intent = Intent(this, CameraActivity::class.java)
intent.putExtra("path", currentDirectoryPath) intent.putExtra("path", currentDirectoryPath)
intent.putExtra("sessionID", gocryptfsVolume.sessionID) intent.putExtra("sessionID", gocryptfsVolume.sessionID)
isStartingActivity = true
startActivity(intent) startActivity(intent)
} }
} }
@ -425,12 +428,14 @@ class ExplorerActivity : BaseExplorerActivity() {
for (i in explorerAdapter.selectedItems) { for (i in explorerAdapter.selectedItems) {
paths.add(explorerElements[i].fullPath) paths.add(explorerElements[i].fullPath)
} }
isStartingActivity = true
ExternalProvider.share(this, gocryptfsVolume, paths) ExternalProvider.share(this, gocryptfsVolume, paths)
unselectAll() unselectAll()
true true
} }
R.id.decrypt -> { R.id.decrypt -> {
val i = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) val i = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
isStartingActivity = true
startActivityForResult(i, PICK_DIRECTORY_REQUEST_CODE) startActivityForResult(i, PICK_DIRECTORY_REQUEST_CODE)
true true
} }

View File

@ -10,10 +10,10 @@ import sushi.hardcore.droidfs.util.PathUtils
import java.util.* import java.util.*
class ExplorerActivityPick : BaseExplorerActivity() { class ExplorerActivityPick : BaseExplorerActivity() {
private var result_intent = Intent() private var resultIntent = Intent()
override fun init() { override fun init() {
super.init() super.init()
result_intent.putExtra("sessionID", gocryptfsVolume.sessionID) resultIntent.putExtra("sessionID", gocryptfsVolume.sessionID)
} }
override fun onExplorerItemClick(position: Int) { override fun onExplorerItemClick(position: Int) {
@ -30,7 +30,7 @@ class ExplorerActivityPick : BaseExplorerActivity() {
setCurrentPath(PathUtils.getParentPath(currentDirectoryPath)) setCurrentPath(PathUtils.getParentPath(currentDirectoryPath))
} }
else -> { else -> {
result_intent.putExtra("path", full_path) resultIntent.putExtra("path", full_path)
returnActivityResult() returnActivityResult()
} }
} }
@ -42,9 +42,9 @@ class ExplorerActivityPick : BaseExplorerActivity() {
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.explorer_pick, menu) menuInflater.inflate(R.menu.explorer_pick, menu)
handleMenuItems(menu) handleMenuItems(menu)
val any_item_selected = explorerAdapter.selectedItems.isNotEmpty() val anyItemSelected = explorerAdapter.selectedItems.isNotEmpty()
menu.findItem(R.id.select_all).isVisible = any_item_selected menu.findItem(R.id.select_all).isVisible = anyItemSelected
menu.findItem(R.id.validate).isVisible = any_item_selected menu.findItem(R.id.validate).isVisible = anyItemSelected
return true return true
} }
@ -63,8 +63,8 @@ class ExplorerActivityPick : BaseExplorerActivity() {
paths.add(PathUtils.path_join(currentDirectoryPath, e.name)) paths.add(PathUtils.path_join(currentDirectoryPath, e.name))
types.add(e.elementType.toInt()) types.add(e.elementType.toInt())
} }
result_intent.putStringArrayListExtra("paths", paths) resultIntent.putStringArrayListExtra("paths", paths)
result_intent.putIntegerArrayListExtra("types", types) resultIntent.putIntegerArrayListExtra("types", types)
returnActivityResult() returnActivityResult()
true true
} }
@ -73,7 +73,7 @@ class ExplorerActivityPick : BaseExplorerActivity() {
} }
private fun returnActivityResult() { private fun returnActivityResult() {
setResult(Activity.RESULT_OK, result_intent) setResult(Activity.RESULT_OK, resultIntent)
finish() finish()
} }

View File

@ -7,8 +7,8 @@ import java.io.File
class AudioPlayer: MediaPlayer(){ class AudioPlayer: MediaPlayer(){
override fun viewFile() { override fun viewFile() {
super.viewFile()
setContentView(R.layout.activity_audio_player) setContentView(R.layout.activity_audio_player)
super.viewFile()
val filename = File(filePath).name val filename = File(filePath).name
val pos = filename.lastIndexOf('.') val pos = filename.lastIndexOf('.')
music_title.text = if (pos != -1){ music_title.text = if (pos != -1){

View File

@ -4,12 +4,14 @@ import android.os.Bundle
import android.view.View import android.view.View
import sushi.hardcore.droidfs.BaseActivity import sushi.hardcore.droidfs.BaseActivity
import sushi.hardcore.droidfs.R import sushi.hardcore.droidfs.R
import sushi.hardcore.droidfs.provider.RestrictedFileProvider
import sushi.hardcore.droidfs.util.GocryptfsVolume import sushi.hardcore.droidfs.util.GocryptfsVolume
import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder
abstract class FileViewerActivity: BaseActivity() { abstract class FileViewerActivity: BaseActivity() {
lateinit var gocryptfsVolume: GocryptfsVolume lateinit var gocryptfsVolume: GocryptfsVolume
lateinit var filePath: String lateinit var filePath: String
private var isGoingBackToExplorer = false
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
filePath = intent.getStringExtra("path")!! filePath = intent.getStringExtra("path")!!
@ -28,6 +30,12 @@ abstract class FileViewerActivity: BaseActivity() {
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION*/ View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION*/
} }
abstract fun viewFile() 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? { fun loadWholeFile(path: String): ByteArray? {
val fileSize = gocryptfsVolume.getSize(path) val fileSize = gocryptfsVolume.getSize(path)
if (fileSize >= 0){ if (fileSize >= 0){
@ -53,7 +61,7 @@ abstract class FileViewerActivity: BaseActivity() {
.setTitle(R.string.error) .setTitle(R.string.error)
.setMessage(R.string.read_file_failed) .setMessage(R.string.read_file_failed)
.setCancelable(false) .setCancelable(false)
.setPositiveButton(R.string.ok) { _, _ -> finish() } .setPositiveButton(R.string.ok) { _, _ -> goBackToExplorer() }
.show() .show()
} }
} catch (e: OutOfMemoryError){ } catch (e: OutOfMemoryError){
@ -61,7 +69,7 @@ abstract class FileViewerActivity: BaseActivity() {
.setTitle(R.string.error) .setTitle(R.string.error)
.setMessage(R.string.outofmemoryerror_msg) .setMessage(R.string.outofmemoryerror_msg)
.setCancelable(false) .setCancelable(false)
.setPositiveButton(getString(R.string.ok)) { _, _ -> finish() } .setPositiveButton(getString(R.string.ok)) { _, _ -> goBackToExplorer() }
.show() .show()
} }
@ -70,9 +78,32 @@ abstract class FileViewerActivity: BaseActivity() {
.setTitle(R.string.error) .setTitle(R.string.error)
.setMessage(R.string.get_size_failed) .setMessage(R.string.get_size_failed)
.setCancelable(false) .setCancelable(false)
.setPositiveButton(R.string.ok) { _, _ -> finish() } .setPositiveButton(R.string.ok) { _, _ -> goBackToExplorer() }
.show() .show()
} }
return null 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
}
} }

View File

@ -113,10 +113,14 @@ class ImageViewer: FileViewerActivity() {
override fun onUserInteraction() { override fun onUserInteraction() {
super.onUserInteraction() super.onUserInteraction()
if (action_buttons.visibility == View.GONE){ action_buttons?.let {
action_buttons.visibility = View.VISIBLE
handler.removeCallbacks(hideActionButtons) 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
}
} }
} }
} }

View File

@ -29,8 +29,10 @@ abstract class MediaPlayer: FileViewerActivity() {
.setTitle(R.string.error) .setTitle(R.string.error)
.setMessage(R.string.playing_failed) .setMessage(R.string.playing_failed)
.setCancelable(false) .setCancelable(false)
.setPositiveButton(R.string.ok) { _, _ -> finish() } .setPositiveButton(R.string.ok) { _, _ -> goBackToExplorer()}
.create() .create()
hideSystemUi()
initializePlayer()
} }
abstract fun bindPlayer(player: SimpleExoPlayer) abstract fun bindPlayer(player: SimpleExoPlayer)
@ -77,14 +79,8 @@ abstract class MediaPlayer: FileViewerActivity() {
} }
} }
override fun onResume() { override fun onDestroy() {
super.onResume() super.onDestroy()
hideSystemUi()
initializePlayer()
}
override fun onPause() {
super.onPause()
releasePlayer() releasePlayer()
} }
} }

View File

@ -34,7 +34,7 @@ class TextEditor: FileViewerActivity() {
.setTitle(R.string.error) .setTitle(R.string.error)
.setMessage(R.string.outofmemoryerror_msg) .setMessage(R.string.outofmemoryerror_msg)
.setCancelable(false) .setCancelable(false)
.setPositiveButton(getString(R.string.ok)) { _, _ -> finish() } .setPositiveButton(getString(R.string.ok)) { _, _ -> goBackToExplorer()}
.show() .show()
} }
} }
@ -103,13 +103,13 @@ class TextEditor: FileViewerActivity() {
.setMessage(R.string.ask_save) .setMessage(R.string.ask_save)
.setPositiveButton(getString(R.string.save)) { _, _ -> .setPositiveButton(getString(R.string.save)) { _, _ ->
if (save()){ if (save()){
finish() goBackToExplorer()
} }
} }
.setNegativeButton(getString(R.string.discard)){ _, _ -> finish() } .setNegativeButton(getString(R.string.discard)){ _, _ -> goBackToExplorer()}
.show() .show()
} else { } else {
finish() goBackToExplorer()
} }
} }

View File

@ -6,8 +6,8 @@ import sushi.hardcore.droidfs.R
class VideoPlayer: MediaPlayer() { class VideoPlayer: MediaPlayer() {
override fun viewFile() { override fun viewFile() {
super.viewFile()
setContentView(R.layout.activity_video_player) setContentView(R.layout.activity_video_player)
super.viewFile()
} }
override fun bindPlayer(player: SimpleExoPlayer) { override fun bindPlayer(player: SimpleExoPlayer) {

View File

@ -7,6 +7,7 @@ import java.io.*
class GocryptfsVolume(var sessionID: Int) { class GocryptfsVolume(var sessionID: Int) {
private external fun native_close(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<ExplorerElement> private external fun native_list_dir(sessionID: Int, dir_path: String): MutableList<ExplorerElement>
private external fun native_open_read_mode(sessionID: Int, file_path: String): Int 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 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) native_close(sessionID)
} }
fun isClosed(): Boolean {
return native_is_closed(sessionID)
}
fun listDir(dir_path: String): MutableList<ExplorerElement> { fun listDir(dir_path: String): MutableList<ExplorerElement> {
return native_list_dir(sessionID, dir_path) return native_list_dir(sessionID, dir_path)
} }

View File

@ -126,6 +126,12 @@ Java_sushi_hardcore_droidfs_util_GocryptfsVolume_00024Companion_init(JNIEnv *env
return sessionID; 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 JNIEXPORT jboolean JNICALL
Java_sushi_hardcore_droidfs_util_GocryptfsVolume_00024Companion_changePassword(JNIEnv *env, jclass clazz, Java_sushi_hardcore_droidfs_util_GocryptfsVolume_00024Companion_changePassword(JNIEnv *env, jclass clazz,
jstring jroot_cipher_dir, jstring jroot_cipher_dir,