Check for disable save prompt option before sending fill request in Android Autofill (#1722)

* Check for disable save prompt option before sending fill request
- ignore save request payload if true

* Add exception handling to Autofill Service

* move System reference outside of FDROID
This commit is contained in:
Jake Fink 2022-01-20 09:51:42 -05:00 committed by GitHub
parent 6f3999016f
commit 52024109f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 127 additions and 101 deletions

View file

@ -160,7 +160,7 @@ namespace Bit.Droid.Autofill
return new List<FilledItem>(); return new List<FilledItem>();
} }
public static FillResponse BuildFillResponse(Parser parser, List<FilledItem> items, bool locked, public static FillResponse.Builder CreateFillResponse(Parser parser, List<FilledItem> items, bool locked,
bool inlineAutofillEnabled, FillRequest fillRequest = null) bool inlineAutofillEnabled, FillRequest fillRequest = null)
{ {
// Acquire inline presentation specs on Android 11+ // Acquire inline presentation specs on Android 11+
@ -211,9 +211,8 @@ namespace Bit.Droid.Autofill
} }
responseBuilder.AddDataset(BuildVaultDataset(parser.ApplicationContext, parser.FieldCollection, responseBuilder.AddDataset(BuildVaultDataset(parser.ApplicationContext, parser.FieldCollection,
parser.Uri, locked, inlinePresentationSpecs)); parser.Uri, locked, inlinePresentationSpecs));
AddSaveInfo(parser, fillRequest, responseBuilder, parser.FieldCollection);
responseBuilder.SetIgnoredIds(parser.FieldCollection.IgnoreAutofillIds.ToArray()); responseBuilder.SetIgnoredIds(parser.FieldCollection.IgnoreAutofillIds.ToArray());
return responseBuilder.Build(); return responseBuilder;
} }
public static Dataset BuildDataset(Context context, FieldCollection fields, FilledItem filledItem, public static Dataset BuildDataset(Context context, FieldCollection fields, FilledItem filledItem,

View file

@ -9,6 +9,10 @@ using Bit.Core;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Utilities; using Bit.Core.Utilities;
#if !FDROID
using Microsoft.AppCenter.Crashes;
#endif
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -28,6 +32,8 @@ namespace Bit.Droid.Autofill
public async override void OnFillRequest(FillRequest request, CancellationSignal cancellationSignal, public async override void OnFillRequest(FillRequest request, CancellationSignal cancellationSignal,
FillCallback callback) FillCallback callback)
{
try
{ {
var structure = request.FillContexts?.LastOrDefault()?.Structure; var structure = request.FillContexts?.LastOrDefault()?.Structure;
if (structure == null) if (structure == null)
@ -69,11 +75,25 @@ namespace Bit.Droid.Autofill
} }
// build response // build response
var response = AutofillHelpers.BuildFillResponse(parser, items, locked, inlineAutofillEnabled, request); var response = AutofillHelpers.CreateFillResponse(parser, items, locked, inlineAutofillEnabled, request);
callback.OnSuccess(response); var disableSavePrompt = await _storageService.GetAsync<bool?>(Constants.AutofillDisableSavePromptKey);
if (!disableSavePrompt.GetValueOrDefault())
{
AutofillHelpers.AddSaveInfo(parser, request, response, parser.FieldCollection);
}
callback.OnSuccess(response.Build());
}
catch (Exception e)
{
#if !FDROID
Crashes.TrackError(e);
#endif
}
} }
public async override void OnSaveRequest(SaveRequest request, SaveCallback callback) public async override void OnSaveRequest(SaveRequest request, SaveCallback callback)
{
try
{ {
var structure = request.FillContexts?.LastOrDefault()?.Structure; var structure = request.FillContexts?.LastOrDefault()?.Structure;
if (structure == null) if (structure == null)
@ -139,5 +159,12 @@ namespace Bit.Droid.Autofill
} }
StartActivity(intent); StartActivity(intent);
} }
catch (Exception e)
{
#if !FDROID
Crashes.TrackError(e);
#endif
}
}
} }
} }