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 86ba72d2f..7949e372d 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/FileDatabaseSelectActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/FileDatabaseSelectActivity.kt @@ -55,7 +55,6 @@ import com.kunzisoft.keepass.model.SearchInfo import com.kunzisoft.keepass.notifications.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_CREATE_TASK import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.utils.* -import com.kunzisoft.keepass.view.SpecialModeView import com.kunzisoft.keepass.view.asError import kotlinx.android.synthetic.main.activity_file_selection.* import java.io.FileNotFoundException @@ -69,7 +68,6 @@ class FileDatabaseSelectActivity : SpecialModeActivity(), private var databaseButtonsContainerView: View? = null private var createDatabaseButtonView: View? = null private var openDatabaseButtonView: View? = null - private var specialModeView: SpecialModeView? = null // Adapter to manage database history list private var mAdapterDatabaseHistory: FileDatabaseHistoryAdapter? = null @@ -115,9 +113,6 @@ class FileDatabaseSelectActivity : SpecialModeActivity(), } } - // Special mode view - specialModeView = findViewById(R.id.special_mode_view) - // History list val fileDatabaseHistoryRecyclerView = findViewById(R.id.file_list) fileDatabaseHistoryRecyclerView.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) @@ -274,15 +269,6 @@ class FileDatabaseSelectActivity : SpecialModeActivity(), override fun onResume() { super.onResume() - // To show the selection mode - specialModeView?.apply { - searchInfo = intent.getParcelableExtra(KEY_SEARCH_INFO) - visible = mSelectionMode - onCancelButtonClickListener = View.OnClickListener { - onBackPressed() - } - } - // Show open and create button or special mode if (mSelectionMode) { // Disable buttons if in selection mode or request for autofill 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 93c42d1ab..fe54e8e47 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt @@ -94,7 +94,6 @@ class GroupActivity : LockingActivity(), private var toolbarAction: ToolbarAction? = null private var iconView: ImageView? = null private var numberChildrenView: TextView? = null - private var specialModeView: SpecialModeView? = null private var addNodeButtonView: AddNodeButtonView? = null private var groupNameView: TextView? = null @@ -136,7 +135,6 @@ class GroupActivity : LockingActivity(), searchTitleView = findViewById(R.id.search_title) groupNameView = findViewById(R.id.group_name) toolbarAction = findViewById(R.id.toolbar_action) - specialModeView = findViewById(R.id.special_mode_view) lockView = findViewById(R.id.lock_button) lockView?.setOnClickListener { @@ -463,25 +461,6 @@ class GroupActivity : LockingActivity(), // Assign number of children refreshNumberOfChildren() - // Show selection mode message if needed - specialModeView?.apply { - searchInfo = intent.getParcelableExtra(KEY_SEARCH_INFO) - visible = mSelectionMode - onCancelButtonClickListener = View.OnClickListener { - // To remove the navigation history and - EntrySelectionHelper.removeEntrySelectionModeFromIntent(intent) - val fragmentManager = supportFragmentManager - if (mSelectionModeCountBackStack > 0) { - for (selectionMode in 0 .. mSelectionModeCountBackStack) { - fragmentManager.popBackStack() - } - } - // Reinit the counter for navigation history - mSelectionModeCountBackStack = 0 - backToTheAppCaller() - } - } - // Show button if allowed addNodeButtonView?.apply { @@ -499,6 +478,20 @@ class GroupActivity : LockingActivity(), } } + override fun onCancelSpecialMode() { + // To remove the navigation history and + EntrySelectionHelper.removeEntrySelectionModeFromIntent(intent) + val fragmentManager = supportFragmentManager + if (mSelectionModeCountBackStack > 0) { + for (selectionMode in 0 .. mSelectionModeCountBackStack) { + fragmentManager.popBackStack() + } + } + // Reinit the counter for navigation history + mSelectionModeCountBackStack = 0 + backToTheAppCaller() + } + private fun refreshNumberOfChildren() { numberChildrenView?.apply { if (PreferencesUtil.showNumberEntries(context)) { diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/PasswordActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/PasswordActivity.kt index a1cc4262e..a995994c1 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/PasswordActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/PasswordActivity.kt @@ -69,7 +69,6 @@ import com.kunzisoft.keepass.utils.MenuUtil import com.kunzisoft.keepass.utils.UriUtil import com.kunzisoft.keepass.view.AdvancedUnlockInfoView import com.kunzisoft.keepass.view.KeyFileSelectionView -import com.kunzisoft.keepass.view.SpecialModeView import com.kunzisoft.keepass.view.asError import kotlinx.android.synthetic.main.activity_password.* import java.io.FileNotFoundException @@ -78,7 +77,6 @@ open class PasswordActivity : SpecialModeActivity() { // Views private var toolbar: Toolbar? = null - private var specialModeView: SpecialModeView? = null private var filenameView: TextView? = null private var passwordView: EditText? = null private var keyFileSelectionView: KeyFileSelectionView? = null @@ -125,7 +123,6 @@ open class PasswordActivity : SpecialModeActivity() { supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) - specialModeView = findViewById(R.id.special_mode_view) confirmButtonView = findViewById(R.id.activity_password_open_button) filenameView = findViewById(R.id.filename) passwordView = findViewById(R.id.password) @@ -345,15 +342,6 @@ open class PasswordActivity : SpecialModeActivity() { override fun onResume() { super.onResume() - // To show the selection mode - specialModeView?.apply { - searchInfo = intent.getParcelableExtra(KEY_SEARCH_INFO) - visible = mSelectionMode - onCancelButtonClickListener = View.OnClickListener { - onBackPressed() - } - } - if (Database.getInstance().loaded) { launchGroupActivity() } else { diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/selection/SpecialModeActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/selection/SpecialModeActivity.kt index 1880c202e..36d722784 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/selection/SpecialModeActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/selection/SpecialModeActivity.kt @@ -1,9 +1,14 @@ package com.kunzisoft.keepass.activities.selection import android.os.Build +import android.view.View +import android.widget.Toast +import com.kunzisoft.keepass.R import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper import com.kunzisoft.keepass.activities.stylish.StylishActivity import com.kunzisoft.keepass.autofill.AutofillHelper +import com.kunzisoft.keepass.settings.PreferencesUtil +import com.kunzisoft.keepass.view.SpecialModeView /** * Activity to manage special mode (ie: selection mode) @@ -14,6 +19,12 @@ abstract class SpecialModeActivity : StylishActivity() { protected var mAutofillSelection: Boolean = false + private var specialModeView: SpecialModeView? = null + + open fun onCancelSpecialMode() { + onBackPressed() + } + override fun onResume() { super.onResume() @@ -21,5 +32,39 @@ abstract class SpecialModeActivity : StylishActivity() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { mAutofillSelection = AutofillHelper.retrieveAssistStructure(intent) != null } + + // To show the selection mode + specialModeView = findViewById(R.id.special_mode_view) + specialModeView?.apply { + searchInfo = intent.getParcelableExtra(EntrySelectionHelper.KEY_SEARCH_INFO) + visible = mSelectionMode + onCancelButtonClickListener = View.OnClickListener { + onCancelSpecialMode() + } + menu.clear() + if (mAutofillSelection) { + menuInflater.inflate(R.menu.autofill, menu) + setOnMenuItemClickListener { menuItem -> + when (menuItem.itemId) { + R.id.menu_autofill -> { + val webDomain = searchInfo?.webDomain + val applicationId = searchInfo?.applicationId + if (webDomain != null) { + PreferencesUtil.addWebDomainToBlocklist(this@SpecialModeActivity, + webDomain) + } else if (applicationId != null) { + PreferencesUtil.addApplicationIdToBlocklist(this@SpecialModeActivity, + applicationId) + } + onCancelSpecialMode() + Toast.makeText(this@SpecialModeActivity, + R.string.autofill_block_restart, + Toast.LENGTH_LONG).show() + } + } + true + } + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt b/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt index ec5a8f57c..579b1625c 100644 --- a/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt +++ b/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt @@ -119,29 +119,33 @@ object AutofillHelper { * Build the Autofill response for many entry */ fun buildResponse(activity: Activity, entriesInfo: List) { - var setResultOk = false - activity.intent?.extras?.let { extras -> - if (extras.containsKey(ASSIST_STRUCTURE)) { - activity.intent?.getParcelableExtra(ASSIST_STRUCTURE)?.let { structure -> - StructureParser(structure).parse()?.let { result -> - // New Response - val responseBuilder = FillResponse.Builder() - entriesInfo.forEach { - responseBuilder.addDataset(buildDataset(activity, it, result)) + if (entriesInfo.isEmpty()) { + activity.setResult(Activity.RESULT_CANCELED) + } else { + var setResultOk = false + activity.intent?.extras?.let { extras -> + if (extras.containsKey(ASSIST_STRUCTURE)) { + activity.intent?.getParcelableExtra(ASSIST_STRUCTURE)?.let { structure -> + StructureParser(structure).parse()?.let { result -> + // New Response + val responseBuilder = FillResponse.Builder() + entriesInfo.forEach { + responseBuilder.addDataset(buildDataset(activity, it, result)) + } + val mReplyIntent = Intent() + Log.d(activity.javaClass.name, "Successed Autofill auth.") + mReplyIntent.putExtra( + AutofillManager.EXTRA_AUTHENTICATION_RESULT, + responseBuilder.build()) + setResultOk = true + activity.setResult(Activity.RESULT_OK, mReplyIntent) } - val mReplyIntent = Intent() - Log.d(activity.javaClass.name, "Successed Autofill auth.") - mReplyIntent.putExtra( - AutofillManager.EXTRA_AUTHENTICATION_RESULT, - responseBuilder.build()) - setResultOk = true - activity.setResult(Activity.RESULT_OK, mReplyIntent) } } - } - if (!setResultOk) { - Log.w(activity.javaClass.name, "Failed Autofill auth.") - activity.setResult(Activity.RESULT_CANCELED) + if (!setResultOk) { + Log.w(activity.javaClass.name, "Failed Autofill auth.") + activity.setResult(Activity.RESULT_CANCELED) + } } } } diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt b/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt index 0968af9dc..a4a55f25a 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt +++ b/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt @@ -386,4 +386,22 @@ object PreferencesUtil { context.resources.getStringArray(R.array.autofill_web_domain_blocklist_default).toMutableSet()) ?: emptySet() } + + fun addApplicationIdToBlocklist(context: Context, applicationId: String) { + val prefs = PreferenceManager.getDefaultSharedPreferences(context) + val setItems: MutableSet = applicationIdBlocklist(context).toMutableSet() + setItems.add(applicationId) + prefs.edit() + .putStringSet(context.getString(R.string.autofill_application_id_blocklist_key), setItems) + .apply() + } + + fun addWebDomainToBlocklist(context: Context, webDomain: String) { + val prefs = PreferenceManager.getDefaultSharedPreferences(context) + val setItems: MutableSet = webDomainBlocklist(context).toMutableSet() + setItems.add(webDomain) + prefs.edit() + .putStringSet(context.getString(R.string.autofill_web_domain_blocklist_key), setItems) + .apply() + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fddb7c51d..fc067296e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -389,6 +389,7 @@ Web domain blocklist Blocklist that prevents auto filling of web domains Block autofill + Restart the app containing the form to activate the blocking. Allow no master key Enable the \"Open\" button if no credentials are selected Delete password