我已经为我的密码管理器应用实现了Android 自动填充服务。用户报告了Paypal 应用程序的问题,该服务似乎无法正常工作。
我对此进行了调查,发现以下代码(Xamarin)onFillRequest
确实有效:(“有效”表示单击自动填充弹出窗口后填充字段)
var responseBuilder = new FillResponse.Builder();
var autofillIds = FindAutoFillIds(); //gets the autofill ids for each EditText
RemoteViews presentation = AutofillHelper.NewRemoteViews(PackageName, "fill data from onFillRequest", AppNames.LauncherIcon);
var datasetBuilder = new Dataset.Builder(presentation);
foreach (AutofillId autofillId in autofillIds)
{
datasetBuilder.SetValue(autofillId, AutofillValue.ForText("some data"));
}
responseBuilder.AddDataset(datasetBuilder.Build());
callback.OnSuccess(responseBuilder.Build());
它基本上使用单个数据集创建填充响应,该数据集为每个自动填充字段设置值。
现在我需要添加一个身份验证活动:
var responseBuilder = new FillResponse.Builder();
var autofillIds = FindAutoFillIds(); //gets the autofill ids for each EditText
Intent intent = new Intent(this, typeof(MyAuthActivity));
var sender = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.CancelCurrent).IntentSender;
RemoteViews presentation = AutofillHelper.NewRemoteViews(PackageName, "fill data after auth", AppNames.LauncherIcon);
var datasetBuilder = new Dataset.Builder(presentation);
//Main difference here:
datasetBuilder.SetAuthentication(sender);
foreach (AutofillId autofillId in autofillIds)
{
datasetBuilder.SetValue(autofillId, AutofillValue.ForText("some placeholder data"));
}
responseBuilder.AddDataset(datasetBuilder.Build());
callback.OnSuccess(responseBuilder.Build());
是MyAuthActivity.OnCreate
这样的:
RemoteViews presentation = AutofillHelper.NewRemoteViews(PackageName, "dataset from auth activity", AppNames.LauncherIcon);
var datasetBuilder = new Dataset.Builder(presentation);
var autofillIds = GetAutofillIds(...); //returns the same autofillIds as in the onFillRequest
foreach (AutofillId autofillId in autofillIds)
{
datasetBuilder.SetValue(autofillId, AutofillValue.ForText("some other data"));
}
var ReplyIntent = new Intent();
bool returnDataset = true; //tried both true and false, neither works
if (returnDataset)
{
ReplyIntent.PutExtra(AutofillManager.ExtraAuthenticationResult, datasetBuilder.Build());
}
else
{
var responseBuilder = new FillResponse.Builder();
responseBuilder.AddDataset(datasetBuilder.Build());
ReplyIntent.PutExtra(AutofillManager.ExtraAuthenticationResult, responseBuilder.Build());
}
SetResult(Result.Ok, ReplyIntent);
Finish();
它基本上使用相同的自动填充 ID 创建了另一个数据集,但是使用 FillResponse 和 Dataset 响应返回它们都不起作用:目标应用程序上的输入字段保持为空。
我注意到在Bitwarden的自动填充服务实现中出现了相同的行为。
我的问题是:身份验证活动的代码有什么问题吗?或者这是否表明 Paypal 的应用程序存在问题?我能做些什么来进一步调试吗?