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 26a38935d..82d3fcba5 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/AutofillLauncherActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/AutofillLauncherActivity.kt @@ -151,8 +151,8 @@ class AutofillLauncherActivity : AppCompatActivity() { private const val KEY_REGISTER_INFO = "KEY_REGISTER_INFO" - fun getAuthIntentSenderForResponse(context: Context, - searchInfo: SearchInfo? = null): IntentSender { + fun getAuthIntentSenderForSelection(context: Context, + searchInfo: SearchInfo? = null): IntentSender { return PendingIntent.getActivity(context, 0, // Doesn't work with Parcelable (don't know why?) Intent(context, AutofillLauncherActivity::class.java).apply { @@ -164,6 +164,16 @@ class AutofillLauncherActivity : AppCompatActivity() { PendingIntent.FLAG_CANCEL_CURRENT).intentSender } + fun getAuthIntentSenderForRegistration(context: Context, + registerInfo: RegisterInfo): IntentSender { + return PendingIntent.getActivity(context, 0, + Intent(context, AutofillLauncherActivity::class.java).apply { + EntrySelectionHelper.addSpecialModeInIntent(this, SpecialMode.REGISTRATION) + putExtra(KEY_REGISTER_INFO, registerInfo) + }, + PendingIntent.FLAG_CANCEL_CURRENT).intentSender + } + fun launchForRegistration(context: Context, registerInfo: RegisterInfo) { val intent = Intent(context, AutofillLauncherActivity::class.java) diff --git a/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt b/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt index 2ac6f307c..fc403a1f6 100644 --- a/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt @@ -105,7 +105,7 @@ class KeeAutofillService : AutofillService() { if (autofillIds.isNotEmpty()) { // If the entire Autofill Response is authenticated, AuthActivity is used // to generate Response. - val sender = AutofillLauncherActivity.getAuthIntentSenderForResponse(this, + val intentSender = AutofillLauncherActivity.getAuthIntentSenderForSelection(this, searchInfo) val responseBuilder = FillResponse.Builder() val remoteViewsUnlock: RemoteViews = if (!parseResult.webDomain.isNullOrEmpty()) { @@ -140,7 +140,7 @@ class KeeAutofillService : AutofillService() { } } // Build response - responseBuilder.setAuthentication(autofillIds, sender, remoteViewsUnlock) + responseBuilder.setAuthentication(autofillIds, intentSender, remoteViewsUnlock) callback.onSuccess(responseBuilder.build()) } } @@ -161,11 +161,13 @@ class KeeAutofillService : AutofillService() { }, parseResult.usernameValue?.textValue?.toString(), parseResult.passwordValue?.textValue?.toString()) - AutofillLauncherActivity.launchForRegistration(this, registerInfo) - - // TODO Treat sender value to call - // callback.onSuccess() or - // callback.onFailure("Saving form canceled") + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + callback.onSuccess(AutofillLauncherActivity.getAuthIntentSenderForRegistration(this, + registerInfo)) + } else { + AutofillLauncherActivity.launchForRegistration(this, registerInfo) + callback.onSuccess() + } return } }