Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit a321bb6

Browse files
Show new FillResponse right after publisher reset (#1138)
If Autofill shows a warning about an app whose publisher changed and the user decides to trust the app and clear previous matches, they should immediately be given the option to select a new match. Previously, as AutofillPublisherChangedActivity did not return a result, the old FillResponse with just a warning would be reused. We now pass a useful response with no matches on to the activity, which returns it after the user has chosen to reset the publisher info.
1 parent 1504268 commit a321bb6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillResponseBuilder.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import android.service.autofill.SaveInfo
1515
import android.widget.RemoteViews
1616
import androidx.annotation.RequiresApi
1717
import com.github.ajalt.timberkt.e
18-
import com.github.michaelbull.result.fold
1918
import com.github.androidpasswordstore.autofillparser.AutofillAction
2019
import com.github.androidpasswordstore.autofillparser.AutofillScenario
2120
import com.github.androidpasswordstore.autofillparser.Credentials
2221
import com.github.androidpasswordstore.autofillparser.FillableForm
2322
import com.github.androidpasswordstore.autofillparser.fillWith
23+
import com.github.michaelbull.result.fold
2424
import com.zeapo.pwdstore.autofill.oreo.ui.AutofillDecryptActivity
2525
import com.zeapo.pwdstore.autofill.oreo.ui.AutofillFilterView
2626
import com.zeapo.pwdstore.autofill.oreo.ui.AutofillPublisherChangedActivity
@@ -88,8 +88,13 @@ class AutofillResponseBuilder(form: FillableForm) {
8888
publisherChangedException: AutofillPublisherChangedException
8989
): Dataset {
9090
val remoteView = makeWarningRemoteView(context)
91+
// If the user decides to trust the new publisher, they can choose reset the list of
92+
// matches. In this case we need to immediately show a new `FillResponse` as if the app were
93+
// autofilled for the first time. This `FillResponse` needs to be returned as a result from
94+
// `AutofillPublisherChangedActivity`, which is why we create and pass it on here.
95+
val fillResponseAfterReset = makeFillResponse(context, emptyList())
9196
val intentSender = AutofillPublisherChangedActivity.makePublisherChangedIntentSender(
92-
context, publisherChangedException
97+
context, publisherChangedException, fillResponseAfterReset
9398
)
9499
return makePlaceholderDataset(remoteView, intentSender, AutofillAction.Match)
95100
}

app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillPublisherChangedActivity.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import android.content.IntentSender
1212
import android.content.pm.PackageManager
1313
import android.os.Build
1414
import android.os.Bundle
15+
import android.service.autofill.FillResponse
1516
import android.text.format.DateUtils
1617
import android.view.View
18+
import android.view.autofill.AutofillManager
1719
import androidx.appcompat.app.AppCompatActivity
1820
import com.github.ajalt.timberkt.e
1921
import com.github.androidpasswordstore.autofillparser.FormOrigin
@@ -33,14 +35,18 @@ class AutofillPublisherChangedActivity : AppCompatActivity() {
3335

3436
private const val EXTRA_APP_PACKAGE =
3537
"com.zeapo.pwdstore.autofill.oreo.ui.EXTRA_APP_PACKAGE"
38+
private const val EXTRA_FILL_RESPONSE_AFTER_RESET =
39+
"com.zeapo.pwdstore.autofill.oreo.ui.EXTRA_FILL_RESPONSE_AFTER_RESET"
3640
private var publisherChangedRequestCode = 1
3741

3842
fun makePublisherChangedIntentSender(
3943
context: Context,
40-
publisherChangedException: AutofillPublisherChangedException
44+
publisherChangedException: AutofillPublisherChangedException,
45+
fillResponseAfterReset: FillResponse?,
4146
): IntentSender {
4247
val intent = Intent(context, AutofillPublisherChangedActivity::class.java).apply {
4348
putExtra(EXTRA_APP_PACKAGE, publisherChangedException.formOrigin.identifier)
49+
putExtra(EXTRA_FILL_RESPONSE_AFTER_RESET, fillResponseAfterReset)
4450
}
4551
return PendingIntent.getActivity(
4652
context, publisherChangedRequestCode++, intent, PendingIntent.FLAG_CANCEL_CURRENT
@@ -72,6 +78,10 @@ class AutofillPublisherChangedActivity : AppCompatActivity() {
7278
}
7379
resetButton.setOnClickListener {
7480
AutofillMatcher.clearMatchesFor(this@AutofillPublisherChangedActivity, FormOrigin.App(appPackage))
81+
val fillResponse = intent.getParcelableExtra<FillResponse>(EXTRA_FILL_RESPONSE_AFTER_RESET)
82+
setResult(RESULT_OK, Intent().apply {
83+
putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, fillResponse)
84+
})
7585
finish()
7686
}
7787
}

0 commit comments

Comments
 (0)