|
|
|
@@ -21,7 +21,6 @@ package com.kunzisoft.keepass.activities
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.Activity
|
|
|
|
import android.app.Activity
|
|
|
|
import android.content.Intent
|
|
|
|
import android.content.Intent
|
|
|
|
import android.content.pm.PackageManager
|
|
|
|
|
|
|
|
import android.net.Uri
|
|
|
|
import android.net.Uri
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.os.Bundle
|
|
|
|
@@ -41,7 +40,6 @@ import androidx.annotation.RequiresApi
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import androidx.appcompat.widget.Toolbar
|
|
|
|
import androidx.appcompat.widget.Toolbar
|
|
|
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
|
|
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
|
|
|
import androidx.core.app.ActivityCompat
|
|
|
|
|
|
|
|
import androidx.fragment.app.commit
|
|
|
|
import androidx.fragment.app.commit
|
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
|
import com.kunzisoft.keepass.R
|
|
|
|
import com.kunzisoft.keepass.R
|
|
|
|
@@ -101,7 +99,6 @@ class PasswordActivity : DatabaseModeActivity(), AdvancedUnlockFragment.BuilderL
|
|
|
|
private var mRememberKeyFile: Boolean = false
|
|
|
|
private var mRememberKeyFile: Boolean = false
|
|
|
|
private var mExternalFileHelper: ExternalFileHelper? = null
|
|
|
|
private var mExternalFileHelper: ExternalFileHelper? = null
|
|
|
|
|
|
|
|
|
|
|
|
private var mPermissionAsked = false
|
|
|
|
|
|
|
|
private var mReadOnly: Boolean = false
|
|
|
|
private var mReadOnly: Boolean = false
|
|
|
|
private var mForceReadOnly: Boolean = false
|
|
|
|
private var mForceReadOnly: Boolean = false
|
|
|
|
set(value) {
|
|
|
|
set(value) {
|
|
|
|
@@ -139,7 +136,6 @@ class PasswordActivity : DatabaseModeActivity(), AdvancedUnlockFragment.BuilderL
|
|
|
|
infoContainerView = findViewById(R.id.activity_password_info_container)
|
|
|
|
infoContainerView = findViewById(R.id.activity_password_info_container)
|
|
|
|
coordinatorLayout = findViewById(R.id.activity_password_coordinator_layout)
|
|
|
|
coordinatorLayout = findViewById(R.id.activity_password_coordinator_layout)
|
|
|
|
|
|
|
|
|
|
|
|
mPermissionAsked = savedInstanceState?.getBoolean(KEY_PERMISSION_ASKED) ?: mPermissionAsked
|
|
|
|
|
|
|
|
mReadOnly = if (savedInstanceState != null && savedInstanceState.containsKey(KEY_READ_ONLY)) {
|
|
|
|
mReadOnly = if (savedInstanceState != null && savedInstanceState.containsKey(KEY_READ_ONLY)) {
|
|
|
|
savedInstanceState.getBoolean(KEY_READ_ONLY)
|
|
|
|
savedInstanceState.getBoolean(KEY_READ_ONLY)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
@@ -249,8 +245,6 @@ class PasswordActivity : DatabaseModeActivity(), AdvancedUnlockFragment.BuilderL
|
|
|
|
mDatabaseFileViewModel.loadDatabaseFile(databaseFileUri)
|
|
|
|
mDatabaseFileViewModel.loadDatabaseFile(databaseFileUri)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
checkPermission()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mDatabase?.let { database ->
|
|
|
|
mDatabase?.let { database ->
|
|
|
|
launchGroupActivityIfLoaded(database)
|
|
|
|
launchGroupActivityIfLoaded(database)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -510,7 +504,6 @@ class PasswordActivity : DatabaseModeActivity(), AdvancedUnlockFragment.BuilderL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onSaveInstanceState(outState: Bundle) {
|
|
|
|
override fun onSaveInstanceState(outState: Bundle) {
|
|
|
|
outState.putBoolean(KEY_PERMISSION_ASKED, mPermissionAsked)
|
|
|
|
|
|
|
|
mDatabaseKeyFileUri?.let {
|
|
|
|
mDatabaseKeyFileUri?.let {
|
|
|
|
outState.putString(KEY_KEYFILE, it.toString())
|
|
|
|
outState.putString(KEY_KEYFILE, it.toString())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -613,35 +606,6 @@ class PasswordActivity : DatabaseModeActivity(), AdvancedUnlockFragment.BuilderL
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check permission
|
|
|
|
|
|
|
|
private fun checkPermission() {
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT in 23..28
|
|
|
|
|
|
|
|
&& !mReadOnly
|
|
|
|
|
|
|
|
&& !mPermissionAsked) {
|
|
|
|
|
|
|
|
mPermissionAsked = true
|
|
|
|
|
|
|
|
// Check self permission to show or not the dialog
|
|
|
|
|
|
|
|
val writePermission = android.Manifest.permission.WRITE_EXTERNAL_STORAGE
|
|
|
|
|
|
|
|
val permissions = arrayOf(writePermission)
|
|
|
|
|
|
|
|
if (toolbar != null
|
|
|
|
|
|
|
|
&& ActivityCompat.checkSelfPermission(this, writePermission) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
|
|
|
ActivityCompat.requestPermissions(this, permissions, WRITE_EXTERNAL_STORAGE_REQUEST)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
|
|
|
|
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when (requestCode) {
|
|
|
|
|
|
|
|
WRITE_EXTERNAL_STORAGE_REQUEST -> {
|
|
|
|
|
|
|
|
if (grantResults.isEmpty() || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
|
|
|
if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE))
|
|
|
|
|
|
|
|
Toast.makeText(this, R.string.read_only_warning, Toast.LENGTH_LONG).show()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// To fix multiple view education
|
|
|
|
// To fix multiple view education
|
|
|
|
private var performedEductionInProgress = false
|
|
|
|
private var performedEductionInProgress = false
|
|
|
|
private fun launchEducation(menu: Menu) {
|
|
|
|
private fun launchEducation(menu: Menu) {
|
|
|
|
@@ -729,8 +693,6 @@ class PasswordActivity : DatabaseModeActivity(), AdvancedUnlockFragment.BuilderL
|
|
|
|
private const val KEY_READ_ONLY = "KEY_READ_ONLY"
|
|
|
|
private const val KEY_READ_ONLY = "KEY_READ_ONLY"
|
|
|
|
private const val KEY_PASSWORD = "password"
|
|
|
|
private const val KEY_PASSWORD = "password"
|
|
|
|
private const val KEY_LAUNCH_IMMEDIATELY = "launchImmediately"
|
|
|
|
private const val KEY_LAUNCH_IMMEDIATELY = "launchImmediately"
|
|
|
|
private const val KEY_PERMISSION_ASKED = "KEY_PERMISSION_ASKED"
|
|
|
|
|
|
|
|
private const val WRITE_EXTERNAL_STORAGE_REQUEST = 647
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun buildAndLaunchIntent(activity: Activity, databaseFile: Uri, keyFile: Uri?,
|
|
|
|
private fun buildAndLaunchIntent(activity: Activity, databaseFile: Uri, keyFile: Uri?,
|
|
|
|
intentBuildLauncher: (Intent) -> Unit) {
|
|
|
|
intentBuildLauncher: (Intent) -> Unit) {
|
|
|
|
|