diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/AutofillLauncherActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/AutofillLauncherActivity.kt index 0820e50c4..227f14bd8 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/AutofillLauncherActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/AutofillLauncherActivity.kt @@ -100,11 +100,12 @@ class AutofillLauncherActivity : AppCompatActivity() { PreferencesUtil.applicationIdBlocklist(this)) || !KeeAutofillService.autofillAllowedFor(searchInfo.webDomain, PreferencesUtil.webDomainBlocklist(this))) { - // If item not allowed, show a toast - Toast.makeText(this.applicationContext, R.string.autofill_block_restart, Toast.LENGTH_LONG).show() + showBlockRestartMessage() setResult(Activity.RESULT_CANCELED) finish() } else { + val database = Database.getInstance() + val readOnly = database.isReadOnly // If database is open SearchHelper.checkAutoSearchInfo(this, Database.getInstance(), @@ -117,9 +118,10 @@ class AutofillLauncherActivity : AppCompatActivity() { { // Show the database UI to select the entry GroupActivity.launchForAutofillResult(this, + readOnly, assistStructure, - false, - searchInfo) + searchInfo, + false) }, { // If database not open @@ -136,22 +138,31 @@ class AutofillLauncherActivity : AppCompatActivity() { PreferencesUtil.applicationIdBlocklist(this)) || !KeeAutofillService.autofillAllowedFor(searchInfo.webDomain, PreferencesUtil.webDomainBlocklist(this))) { - // If item not allowed, show a toast - Toast.makeText(this.applicationContext, R.string.autofill_block_restart, Toast.LENGTH_LONG).show() + showBlockRestartMessage() setResult(Activity.RESULT_CANCELED) } else { + val database = Database.getInstance() + val readOnly = database.isReadOnly SearchHelper.checkAutoSearchInfo(this, - Database.getInstance(), + database, searchInfo, { _ -> - // Show the database UI to select the entry - GroupActivity.launchForRegistration(this, - registerInfo) + if (!readOnly) { + // Show the database UI to select the entry + GroupActivity.launchForRegistration(this, + registerInfo) + } else { + showReadOnlySaveMessage() + } }, { - // Show the database UI to select the entry - GroupActivity.launchForRegistration(this, - registerInfo) + if (!readOnly) { + // Show the database UI to select the entry + GroupActivity.launchForRegistration(this, + registerInfo) + } else { + showReadOnlySaveMessage() + } }, { // If database not open @@ -163,6 +174,15 @@ class AutofillLauncherActivity : AppCompatActivity() { finish() } + private fun showBlockRestartMessage() { + // If item not allowed, show a toast + Toast.makeText(this.applicationContext, R.string.autofill_block_restart, Toast.LENGTH_LONG).show() + } + + private fun showReadOnlySaveMessage() { + Toast.makeText(this.applicationContext, R.string.autofill_read_only_save, Toast.LENGTH_LONG).show() + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data) diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/EntrySelectionLauncherActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/EntrySelectionLauncherActivity.kt index 510486aa2..dbc545802 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntrySelectionLauncherActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntrySelectionLauncherActivity.kt @@ -76,8 +76,10 @@ class EntrySelectionLauncherActivity : AppCompatActivity() { val searchShareForMagikeyboard = PreferencesUtil.isKeyboardSearchShareEnable(this) // If database is open + val database = Database.getInstance() + val readOnly = database.isReadOnly SearchHelper.checkAutoSearchInfo(this, - Database.getInstance(), + database, searchInfo, { items -> // Items found @@ -91,25 +93,28 @@ class EntrySelectionLauncherActivity : AppCompatActivity() { } else { // Select the one we want GroupActivity.launchForKeyboardSelectionResult(this, - true, - searchInfo) + readOnly, + searchInfo, + true) } } else { GroupActivity.launchForSearchResult(this, - true, - searchInfo) + readOnly, + searchInfo, + true) } }, { // Show the database UI to select the entry - if (searchShareForMagikeyboard) { + if (readOnly || searchShareForMagikeyboard) { GroupActivity.launchForKeyboardSelectionResult(this, - false, - searchInfo) + readOnly, + searchInfo, + false) } else { GroupActivity.launchForSaveResult(this, - false, - searchInfo) + searchInfo, + false) } }, { diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/FileDatabaseSelectActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/FileDatabaseSelectActivity.kt index 332cb683c..6fb1dac8f 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/FileDatabaseSelectActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/FileDatabaseSelectActivity.kt @@ -171,7 +171,8 @@ class FileDatabaseSelectActivity : SpecialModeActivity(), databaseFiles.databaseFileToActivate?.let { databaseFileToAdd -> mAdapterDatabaseHistory?.addDatabaseFileHistory(databaseFileToAdd) } - GroupActivity.launch(this@FileDatabaseSelectActivity) + GroupActivity.launch(this@FileDatabaseSelectActivity, + PreferencesUtil.enableReadOnlyDatabase(this@FileDatabaseSelectActivity)) } DatabaseFilesViewModel.DatabaseFileAction.UPDATE -> { databaseFiles.databaseFileToActivate?.let { databaseFileToUpdate -> diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt index 7d168c357..b93cce8c1 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt @@ -36,6 +36,7 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView +import android.widget.Toast import androidx.annotation.RequiresApi import androidx.appcompat.view.ActionMode import androidx.appcompat.widget.SearchView @@ -1211,8 +1212,8 @@ class GroupActivity : LockingActivity(), * ------------------------- */ fun launch(context: Context, - autoSearch: Boolean = false, - readOnly: Boolean = PreferencesUtil.enableReadOnlyDatabase(context)) { + readOnly: Boolean, + autoSearch: Boolean = false) { checkTimeAndBuildIntent(context, null, readOnly) { intent -> intent.putExtra(AUTO_SEARCH_KEY, autoSearch) context.startActivity(intent) @@ -1225,9 +1226,9 @@ class GroupActivity : LockingActivity(), * ------------------------- */ fun launchForSearchResult(context: Context, - autoSearch: Boolean = false, + readOnly: Boolean, searchInfo: SearchInfo, - readOnly: Boolean = PreferencesUtil.enableReadOnlyDatabase(context)) { + autoSearch: Boolean = false) { checkTimeAndBuildIntent(context, null, readOnly) { intent -> intent.putExtra(AUTO_SEARCH_KEY, autoSearch) EntrySelectionHelper.addSearchInfoInIntent( @@ -1243,8 +1244,8 @@ class GroupActivity : LockingActivity(), * ------------------------- */ fun launchForSaveResult(context: Context, - autoSearch: Boolean = false, - searchInfo: SearchInfo) { + searchInfo: SearchInfo, + autoSearch: Boolean = false) { checkTimeAndBuildIntent(context, null, false) { intent -> intent.putExtra(AUTO_SEARCH_KEY, autoSearch) EntrySelectionHelper.startActivityForSaveModeResult(context, @@ -1259,9 +1260,9 @@ class GroupActivity : LockingActivity(), * ------------------------- */ fun launchForKeyboardSelectionResult(context: Context, - autoSearch: Boolean = false, + readOnly: Boolean, searchInfo: SearchInfo? = null, - readOnly: Boolean = PreferencesUtil.enableReadOnlyDatabase(context)) { + autoSearch: Boolean = false) { checkTimeAndBuildIntent(context, null, readOnly) { intent -> intent.putExtra(AUTO_SEARCH_KEY, autoSearch) EntrySelectionHelper.startActivityForKeyboardSelectionModeResult(context, @@ -1277,10 +1278,10 @@ class GroupActivity : LockingActivity(), */ @RequiresApi(api = Build.VERSION_CODES.O) fun launchForAutofillResult(activity: Activity, + readOnly: Boolean, assistStructure: AssistStructure, - autoSearch: Boolean = false, searchInfo: SearchInfo? = null, - readOnly: Boolean = PreferencesUtil.enableReadOnlyDatabase(activity)) { + autoSearch: Boolean = false) { checkTimeAndBuildIntent(activity, null, readOnly) { intent -> intent.putExtra(AUTO_SEARCH_KEY, autoSearch) AutofillHelper.startActivityForAutofillResult(activity, @@ -1318,8 +1319,8 @@ class GroupActivity : LockingActivity(), EntrySelectionHelper.doSpecialAction(activity.intent, { GroupActivity.launch(activity, - true, - readOnly) + readOnly, + true) }, { searchInfo -> SearchHelper.checkAutoSearchInfo(activity, @@ -1328,21 +1329,22 @@ class GroupActivity : LockingActivity(), { _ -> // Response is build GroupActivity.launchForSearchResult(activity, - true, - searchInfo) + readOnly, + searchInfo, + true) onLaunchActivitySpecialMode() }, { // Here no search info found if (readOnly) { GroupActivity.launchForSearchResult(activity, - false, + readOnly, searchInfo, - readOnly) + false) } else { GroupActivity.launchForSaveResult(activity, - false, - searchInfo) + searchInfo, + false) } onLaunchActivitySpecialMode() }, @@ -1369,17 +1371,18 @@ class GroupActivity : LockingActivity(), } else { // Select the one we want GroupActivity.launchForKeyboardSelectionResult(activity, - true, - searchInfo) + readOnly, + searchInfo, + true) onLaunchActivitySpecialMode() } }, { // Here no search info found, disable auto search GroupActivity.launchForKeyboardSelectionResult(activity, - false, + readOnly, searchInfo, - readOnly) + false) onLaunchActivitySpecialMode() }, { @@ -1401,10 +1404,10 @@ class GroupActivity : LockingActivity(), { // Here no search info found, disable auto search GroupActivity.launchForAutofillResult(activity, + readOnly, assistStructure, - false, searchInfo, - readOnly) + false) onLaunchActivitySpecialMode() }, { @@ -1417,26 +1420,34 @@ class GroupActivity : LockingActivity(), } }, { registerInfo -> - SearchHelper.checkAutoSearchInfo(activity, - Database.getInstance(), - registerInfo?.searchInfo, - { _ -> - // No auto search, it's a registration - GroupActivity.launchForRegistration(activity, - registerInfo) - onLaunchActivitySpecialMode() - }, - { - // Here no search info found, disable auto search - GroupActivity.launchForRegistration(activity, - registerInfo) - onLaunchActivitySpecialMode() - }, - { - // Simply close if database not opened, normally not happened - onCancelSpecialMode() - } - ) + if (!readOnly) { + SearchHelper.checkAutoSearchInfo(activity, + Database.getInstance(), + registerInfo?.searchInfo, + { _ -> + // No auto search, it's a registration + GroupActivity.launchForRegistration(activity, + registerInfo) + onLaunchActivitySpecialMode() + }, + { + // Here no search info found, disable auto search + GroupActivity.launchForRegistration(activity, + registerInfo) + onLaunchActivitySpecialMode() + }, + { + // Simply close if database not opened, normally not happened + onCancelSpecialMode() + } + ) + } else { + Toast.makeText(activity.applicationContext, + R.string.autofill_read_only_save, + Toast.LENGTH_LONG) + .show() + onCancelSpecialMode() + } }) } } diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/MagikeyboardLauncherActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/MagikeyboardLauncherActivity.kt index c7120919a..4583265d0 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/MagikeyboardLauncherActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/MagikeyboardLauncherActivity.kt @@ -30,12 +30,18 @@ import com.kunzisoft.keepass.database.search.SearchHelper class MagikeyboardLauncherActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { + val database = Database.getInstance() + val readOnly = database.isReadOnly SearchHelper.checkAutoSearchInfo(this, - Database.getInstance(), + database, null, - {}, { - GroupActivity.launchForKeyboardSelectionResult(this) + // Not called + // if items found directly returns before calling this activity + }, + { + // Select if not found + GroupActivity.launchForKeyboardSelectionResult(this, readOnly) }, { // Pass extra to get entry diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e25874213..28f1eedf2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -422,6 +422,7 @@ Blocklist that prevents auto filling of web domains Block autofill Restart the app containing the form to activate the blocking. + Data save is not allowed for a database opened as read-only. Allow no master key Allows tapping the \"Open\" button if no credentials are selected Delete password