mirror of
https://github.com/bitwarden/mobile
synced 2026-01-05 18:13:36 +00:00
save info from service to add cipher page
This commit is contained in:
@@ -33,7 +33,7 @@ namespace Bit.Android.Autofill
|
||||
public static FillResponse BuildFillResponse(Context context, FieldCollection fields, List<IFilledItem> items)
|
||||
{
|
||||
var responseBuilder = new FillResponse.Builder();
|
||||
if(items != null)
|
||||
if(items != null && items.Count > 0)
|
||||
{
|
||||
foreach(var item in items)
|
||||
{
|
||||
@@ -44,6 +44,8 @@ namespace Bit.Android.Autofill
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AddSaveInfo(responseBuilder, fields);
|
||||
return responseBuilder.Build();
|
||||
}
|
||||
|
||||
@@ -64,11 +66,11 @@ namespace Bit.Android.Autofill
|
||||
var view = BuildListView(context.PackageName, "Autofill with bitwarden",
|
||||
"Vault locked", Resource.Drawable.icon);
|
||||
var intent = new Intent(context, typeof(MainActivity));
|
||||
intent.PutExtra("uri", uri);
|
||||
intent.PutExtra("autofillFramework", true);
|
||||
//intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
|
||||
intent.PutExtra("autofillFrameworkUri", uri);
|
||||
var pendingIntent = PendingIntent.GetActivity(context, 0, intent, PendingIntentFlags.CancelCurrent);
|
||||
responseBuilder.SetAuthentication(fields.AutofillIds.ToArray(), pendingIntent.IntentSender, view);
|
||||
AddSaveInfo(responseBuilder, fields);
|
||||
return responseBuilder.Build();
|
||||
}
|
||||
|
||||
@@ -81,6 +83,12 @@ namespace Bit.Android.Autofill
|
||||
return view;
|
||||
}
|
||||
|
||||
public static void AddSaveInfo(FillResponse.Builder responseBuilder, FieldCollection fields)
|
||||
{
|
||||
var saveInfo = new SaveInfo.Builder(SaveDataType.Password, fields.AutofillIds.ToArray()).Build();
|
||||
responseBuilder.SetSaveInfo(saveInfo);
|
||||
}
|
||||
|
||||
public static List<string> FilterForSupportedHints(string[] hints)
|
||||
{
|
||||
return hints?.Where(h => IsValidHint(h)).ToList() ?? new List<string>();
|
||||
|
||||
@@ -5,6 +5,7 @@ using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Service.Autofill;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Enums;
|
||||
using System.Linq;
|
||||
using XLabs.Ioc;
|
||||
|
||||
@@ -41,7 +42,7 @@ namespace Bit.Android.Autofill
|
||||
_lockService = Resolver.Resolve<ILockService>();
|
||||
}
|
||||
|
||||
var isLocked = (await _lockService.GetLockTypeAsync(false)) != App.Enums.LockType.None;
|
||||
var isLocked = (await _lockService.GetLockTypeAsync(false)) != LockType.None;
|
||||
if(isLocked)
|
||||
{
|
||||
var authResponse = AutofillHelpers.BuildAuthResponse(this, parser.FieldCollection, parser.Uri);
|
||||
@@ -56,11 +57,6 @@ namespace Bit.Android.Autofill
|
||||
|
||||
// build response
|
||||
var items = await AutofillHelpers.GetFillItemsAsync(_cipherService, parser.Uri);
|
||||
if(!items.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var response = AutofillHelpers.BuildFillResponse(this, parser.FieldCollection, items);
|
||||
callback.OnSuccess(response);
|
||||
}
|
||||
@@ -73,12 +69,18 @@ namespace Bit.Android.Autofill
|
||||
return;
|
||||
}
|
||||
|
||||
var clientState = request.ClientState;
|
||||
|
||||
var parser = new Parser(structure);
|
||||
parser.ParseForSave();
|
||||
var filledAutofillFieldCollection = parser.FilledFieldCollection;
|
||||
//SaveFilledAutofillFieldCollection(filledAutofillFieldCollection);
|
||||
|
||||
var intent = new Intent(this, typeof(MainActivity));
|
||||
intent.PutExtra("autofillFramework", true);
|
||||
intent.PutExtra("autofillFrameworkSave", true);
|
||||
intent.PutExtra("autofillFrameworkType", (int)CipherType.Login);
|
||||
intent.PutExtra("autofillFrameworkUri", parser.Uri);
|
||||
intent.PutExtra("autofillFrameworkUsername", "username");
|
||||
intent.PutExtra("autofillFrameworkPassword", "pass123");
|
||||
intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
|
||||
StartActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,13 +55,14 @@ namespace Bit.Android.Autofill
|
||||
var isEditText = node.ClassName == "android.widget.EditText";
|
||||
if(isEditText || (hints?.Length ?? 0) > 0)
|
||||
{
|
||||
if(Uri == null)
|
||||
{
|
||||
Uri = node.IdPackage;
|
||||
}
|
||||
|
||||
if(forFill)
|
||||
{
|
||||
FieldCollection.Add(new Field(node));
|
||||
if(Uri == null)
|
||||
{
|
||||
Uri = node.IdPackage;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -23,6 +23,8 @@ using Android.Views.Autofill;
|
||||
using Android.App.Assist;
|
||||
using Bit.Android.Autofill;
|
||||
using System.Collections.Generic;
|
||||
using Bit.App.Models;
|
||||
using Bit.App.Enums;
|
||||
|
||||
namespace Bit.Android
|
||||
{
|
||||
@@ -40,7 +42,6 @@ namespace Bit.Android
|
||||
|
||||
protected override void OnCreate(Bundle bundle)
|
||||
{
|
||||
var uri = Intent.GetStringExtra("uri");
|
||||
if(!Resolver.IsSet)
|
||||
{
|
||||
MainApplication.SetIoc(Application);
|
||||
@@ -78,8 +79,7 @@ namespace Bit.Android
|
||||
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
|
||||
_settings = Resolver.Resolve<ISettings>();
|
||||
LoadApplication(new App.App(
|
||||
uri,
|
||||
Intent.GetBooleanExtra("myVaultTile", false),
|
||||
GetOptions(),
|
||||
Resolver.Resolve<IAuthService>(),
|
||||
Resolver.Resolve<IConnectivity>(),
|
||||
Resolver.Resolve<IUserDialogs>(),
|
||||
@@ -425,5 +425,24 @@ namespace Bit.Android
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private AppOptions GetOptions()
|
||||
{
|
||||
var options = new AppOptions
|
||||
{
|
||||
Uri = Intent.GetStringExtra("uri") ?? Intent.GetStringExtra("autofillFrameworkUri"),
|
||||
MyVault = Intent.GetBooleanExtra("myVaultTile", false),
|
||||
FromAutofillFramework = Intent.GetBooleanExtra("autofillFramework", false)
|
||||
};
|
||||
|
||||
if(Intent.GetBooleanExtra("autofillFrameworkSave", false))
|
||||
{
|
||||
options.SaveType = (CipherType)Intent.GetIntExtra("autofillFrameworkType", 0);
|
||||
options.SaveUsername = Intent.GetStringExtra("autofillFrameworkUsername");
|
||||
options.SavePassword = Intent.GetStringExtra("autofillFrameworkPassword");
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user