diff --git a/src/Android/Autofill/AutofillHelpers.cs b/src/Android/Autofill/AutofillHelpers.cs index 73be52413..9f3b3df5e 100644 --- a/src/Android/Autofill/AutofillHelpers.cs +++ b/src/Android/Autofill/AutofillHelpers.cs @@ -9,11 +9,14 @@ using Bit.App.Abstractions; using System.Threading.Tasks; using Bit.App.Resources; using Bit.App.Enums; +using Android.Views.Autofill; namespace Bit.Android.Autofill { public static class AutofillHelpers { + private static int _pendingIntentId = 0; + public static async Task> GetFillItemsAsync(Parser parser, ICipherService service) { var items = new List(); @@ -43,7 +46,7 @@ namespace Bit.Android.Autofill return items; } - public static FillResponse BuildFillResponse(Context context, Parser parser, List items) + public static FillResponse BuildFillResponse(Context context, Parser parser, List items, bool locked) { var responseBuilder = new FillResponse.Builder(); if(items != null && items.Count > 0) @@ -58,6 +61,7 @@ namespace Bit.Android.Autofill } } + responseBuilder.AddDataset(BuildVaultDataset(context, parser.FieldCollection, parser.Uri, locked)); AddSaveInfo(responseBuilder, parser.FieldCollection); responseBuilder.SetIgnoredIds(parser.FieldCollection.IgnoreAutofillIds.ToArray()); return responseBuilder.Build(); @@ -74,11 +78,8 @@ namespace Bit.Android.Autofill return null; } - public static FillResponse BuildAuthResponse(Context context, FieldCollection fields, string uri) + public static Dataset BuildVaultDataset(Context context, FieldCollection fields, string uri, bool locked) { - var responseBuilder = new FillResponse.Builder(); - var view = BuildListView(context.PackageName, AppResources.AutofillWithBitwarden, - AppResources.VaultIsLocked, Resource.Drawable.icon); var intent = new Intent(context, typeof(MainActivity)); intent.PutExtra("autofillFramework", true); if(fields.FillableForLogin) @@ -98,11 +99,22 @@ namespace Bit.Android.Autofill return null; } intent.PutExtra("autofillFrameworkUri", uri); - var pendingIntent = PendingIntent.GetActivity(context, 0, intent, PendingIntentFlags.CancelCurrent); - responseBuilder.SetAuthentication(fields.AutofillIds.ToArray(), pendingIntent.IntentSender, view); - AddSaveInfo(responseBuilder, fields); - responseBuilder.SetIgnoredIds(fields.IgnoreAutofillIds.ToArray()); - return responseBuilder.Build(); + var pendingIntent = PendingIntent.GetActivity(context, ++_pendingIntentId, intent, + PendingIntentFlags.CancelCurrent); + + var view = BuildListView(context.PackageName, AppResources.AutofillWithBitwarden, + locked ? AppResources.VaultIsLocked : AppResources.GoToMyVault, Resource.Drawable.icon); + + var datasetBuilder = new Dataset.Builder(view); + datasetBuilder.SetAuthentication(pendingIntent.IntentSender); + + // Dataset must have a value set. We will reset this in the main activity when the real item is chosen. + foreach(var autofillId in fields.AutofillIds) + { + datasetBuilder.SetValue(autofillId, AutofillValue.ForText("PLACEHOLDER")); + } + + return datasetBuilder.Build(); } public static RemoteViews BuildListView(string packageName, string text, string subtext, int iconId) diff --git a/src/Android/Autofill/AutofillService.cs b/src/Android/Autofill/AutofillService.cs index 9e7bfc651..d348c310c 100644 --- a/src/Android/Autofill/AutofillService.cs +++ b/src/Android/Autofill/AutofillService.cs @@ -8,6 +8,7 @@ using Android.Widget; using Bit.App; using Bit.App.Abstractions; using Bit.App.Enums; +using System.Collections.Generic; using System.Linq; using XLabs.Ioc; @@ -44,22 +45,20 @@ namespace Bit.Android.Autofill _lockService = Resolver.Resolve(); } - var isLocked = (await _lockService.GetLockTypeAsync(false)) != LockType.None; - if(isLocked) + List items = null; + var locked = (await _lockService.GetLockTypeAsync(false)) != LockType.None; + if(!locked) { - var authResponse = AutofillHelpers.BuildAuthResponse(this, parser.FieldCollection, parser.Uri); - callback.OnSuccess(authResponse); - return; - } + if(_cipherService == null) + { + _cipherService = Resolver.Resolve(); + } - if(_cipherService == null) - { - _cipherService = Resolver.Resolve(); + items = await AutofillHelpers.GetFillItemsAsync(parser, _cipherService); } // build response - var items = await AutofillHelpers.GetFillItemsAsync(parser, _cipherService); - var response = AutofillHelpers.BuildFillResponse(this, parser, items); + var response = AutofillHelpers.BuildFillResponse(this, parser, items, locked); callback.OnSuccess(response); } diff --git a/src/Android/MainActivity.cs b/src/Android/MainActivity.cs index 0c376c105..fb438fa18 100644 --- a/src/Android/MainActivity.cs +++ b/src/Android/MainActivity.cs @@ -169,10 +169,9 @@ namespace Bit.Android return; } - var items = new List { new FilledItem(cipher.CipherModel) }; - var response = AutofillHelpers.BuildFillResponse(this, parser, items); + var dataset = AutofillHelpers.BuildDataset(this, parser.FieldCollection, new FilledItem(cipher.CipherModel)); var replyIntent = new Intent(); - replyIntent.PutExtra(AutofillManager.ExtraAuthenticationResult, response); + replyIntent.PutExtra(AutofillManager.ExtraAuthenticationResult, dataset); SetResult(Result.Ok, replyIntent); Finish(); } diff --git a/src/Android/Resources/layout/autofill_listitem.axml b/src/Android/Resources/layout/autofill_listitem.axml index 077f3489d..8afcb63cc 100644 --- a/src/Android/Resources/layout/autofill_listitem.axml +++ b/src/Android/Resources/layout/autofill_listitem.axml @@ -14,8 +14,8 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginEnd="10dp" - android:maxWidth="25dp" - android:maxHeight="25dp" + android:maxWidth="20dp" + android:maxHeight="20dp" android:adjustViewBounds="true" android:src="@drawable/login" /> + /// Looks up a localized string similar to Go to my vault. + /// + public static string GoToMyVault { + get { + return ResourceManager.GetString("GoToMyVault", resourceCulture); + } + } + /// /// Looks up a localized string similar to Go To Website. /// diff --git a/src/App/Resources/AppResources.resx b/src/App/Resources/AppResources.resx index 919fbfef6..2cd9e8e10 100644 --- a/src/App/Resources/AppResources.resx +++ b/src/App/Resources/AppResources.resx @@ -1191,4 +1191,7 @@ Vault is locked + + Go to my vault + \ No newline at end of file