Fix callback result

This commit is contained in:
J-Jamet committed 2020-10-12 15:40:40 +02:00
1 parent 7825071f61
commit 8a1a27f5a1
2 files changed
+21 -9

No files matched your search

@@ -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)
@@ -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
}
}