mirror of
https://github.com/bitwarden/mobile
synced 2025-12-05 23:53:33 +00:00
* Initial commit of LockService name refactor (#831) * [Auto-Logout] Update Service layer logic (#835) * Initial commit of service logic update * Added default value for action * Updated ToggleTokensAsync conditional * Removed unused variables, updated action conditional * Initial commit: lockOption/lock refactor app layer (#840) * [Auto-Logout] Settings Refactor - Application Layer Part 2 (#844) * Initial commit of app layer part 2 * Updated biometrics position * Reverted resource name refactor * LockOptions refactor revert * Updated method casing :: Removed VaultTimeout prefix for timeouts * Fixed dupe string resource (#854) * Updated dependency to use VaultTimeoutService (#896) * [Auto Logout] Xamarin Forms in AutoFill flow (iOS) (#902) * fix typo in PINRequireMasterPasswordRestart (#900) * initial commit for xf usage in autofill * Fixed databinding for hint button * Updated Two Factor page launch - removed unused imports * First pass at broadcast/messenger implentation for autofill * setting theme in extension using theme manager * extension app resources * App resources from main app * fix ref to twoFactorPage * apply resources to page * load empty app for sytling in extension * move ios renderers to ios core * static ref to resources and GetResourceColor helper * fix method ref * move application.current.resources refs to helper * switch login page alerts to device action dialogs * run on main thread * showDialog with device action service * abstract action sheet to device action service * add support for yubikey * add yubikey iimages to extension * support close button action * add support to action extension * remove empty lines Co-authored-by: Jonas Kittner <54631600+theendlessriver13@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> * [Auto Logout] Update lock option to be default value (#929) * Initial commit - make lock action default * Removed extra whitespace Co-authored-by: Jonas Kittner <54631600+theendlessriver13@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
131 lines
5.0 KiB
C#
131 lines
5.0 KiB
C#
using Android;
|
|
using Android.App;
|
|
using Android.Content;
|
|
using Android.OS;
|
|
using Android.Runtime;
|
|
using Android.Service.Autofill;
|
|
using Android.Widget;
|
|
using Bit.Core;
|
|
using Bit.Core.Abstractions;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.Utilities;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Bit.Droid.Autofill
|
|
{
|
|
[Service(Permission = Manifest.Permission.BindAutofillService, Label = "Bitwarden")]
|
|
[IntentFilter(new string[] { "android.service.autofill.AutofillService" })]
|
|
[MetaData("android.autofill", Resource = "@xml/autofillservice")]
|
|
[Register("com.x8bit.bitwarden.Autofill.AutofillService")]
|
|
public class AutofillService : Android.Service.Autofill.AutofillService
|
|
{
|
|
private ICipherService _cipherService;
|
|
private IVaultTimeoutService _vaultTimeoutService;
|
|
private IStorageService _storageService;
|
|
|
|
public async override void OnFillRequest(FillRequest request, CancellationSignal cancellationSignal,
|
|
FillCallback callback)
|
|
{
|
|
var structure = request.FillContexts?.LastOrDefault()?.Structure;
|
|
if (structure == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var parser = new Parser(structure, ApplicationContext);
|
|
parser.Parse();
|
|
|
|
if (_storageService == null)
|
|
{
|
|
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
|
|
}
|
|
|
|
var shouldAutofill = await parser.ShouldAutofillAsync(_storageService);
|
|
if (!shouldAutofill)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (_vaultTimeoutService == null)
|
|
{
|
|
_vaultTimeoutService = ServiceContainer.Resolve<IVaultTimeoutService>("vaultTimeoutService");
|
|
}
|
|
|
|
List<FilledItem> items = null;
|
|
var locked = await _vaultTimeoutService.IsLockedAsync();
|
|
if (!locked)
|
|
{
|
|
if (_cipherService == null)
|
|
{
|
|
_cipherService = ServiceContainer.Resolve<ICipherService>("cipherService");
|
|
}
|
|
items = await AutofillHelpers.GetFillItemsAsync(parser, _cipherService);
|
|
}
|
|
|
|
// build response
|
|
var response = AutofillHelpers.BuildFillResponse(parser, items, locked);
|
|
callback.OnSuccess(response);
|
|
}
|
|
|
|
public async override void OnSaveRequest(SaveRequest request, SaveCallback callback)
|
|
{
|
|
var structure = request.FillContexts?.LastOrDefault()?.Structure;
|
|
if (structure == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (_storageService == null)
|
|
{
|
|
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
|
|
}
|
|
|
|
var disableSavePrompt = await _storageService.GetAsync<bool?>(Constants.AutofillDisableSavePromptKey);
|
|
if (disableSavePrompt.GetValueOrDefault())
|
|
{
|
|
return;
|
|
}
|
|
|
|
var parser = new Parser(structure, ApplicationContext);
|
|
parser.Parse();
|
|
|
|
var savedItem = parser.FieldCollection.GetSavedItem();
|
|
if (savedItem == null)
|
|
{
|
|
Toast.MakeText(this, "Unable to save this form.", ToastLength.Short).Show();
|
|
return;
|
|
}
|
|
|
|
var intent = new Intent(this, typeof(MainActivity));
|
|
intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
|
|
intent.PutExtra("autofillFramework", true);
|
|
intent.PutExtra("autofillFrameworkSave", true);
|
|
intent.PutExtra("autofillFrameworkType", (int)savedItem.Type);
|
|
switch (savedItem.Type)
|
|
{
|
|
case CipherType.Login:
|
|
intent.PutExtra("autofillFrameworkName", parser.Uri
|
|
.Replace(Constants.AndroidAppProtocol, string.Empty)
|
|
.Replace("https://", string.Empty)
|
|
.Replace("http://", string.Empty));
|
|
intent.PutExtra("autofillFrameworkUri", parser.Uri);
|
|
intent.PutExtra("autofillFrameworkUsername", savedItem.Login.Username);
|
|
intent.PutExtra("autofillFrameworkPassword", savedItem.Login.Password);
|
|
break;
|
|
case CipherType.Card:
|
|
intent.PutExtra("autofillFrameworkCardName", savedItem.Card.Name);
|
|
intent.PutExtra("autofillFrameworkCardNumber", savedItem.Card.Number);
|
|
intent.PutExtra("autofillFrameworkCardExpMonth", savedItem.Card.ExpMonth);
|
|
intent.PutExtra("autofillFrameworkCardExpYear", savedItem.Card.ExpYear);
|
|
intent.PutExtra("autofillFrameworkCardCode", savedItem.Card.Code);
|
|
break;
|
|
default:
|
|
Toast.MakeText(this, "Unable to save this type of form.", ToastLength.Short).Show();
|
|
return;
|
|
}
|
|
StartActivity(intent);
|
|
}
|
|
}
|
|
}
|