bitwarden-android/src/iOS.Autofill/CredentialProviderViewController.cs

122 lines
5.6 KiB
C#
Raw Normal View History

2018-09-20 06:08:39 +03:00
using AuthenticationServices;
2018-09-20 20:18:30 +03:00
using Bit.App.Abstractions;
using Bit.App.Repositories;
using Bit.App.Resources;
using Bit.App.Services;
using Bit.iOS.Autofill.Models;
using Bit.iOS.Core.Services;
2018-09-20 06:08:39 +03:00
using Foundation;
2018-09-20 20:18:30 +03:00
using Plugin.Connectivity;
using Plugin.Fingerprint;
using Plugin.Settings.Abstractions;
using SimpleInjector;
2018-09-20 06:08:39 +03:00
using System;
using UIKit;
2018-09-20 20:18:30 +03:00
using XLabs.Ioc;
using XLabs.Ioc.SimpleInjectorContainer;
2018-09-20 06:08:39 +03:00
namespace Bit.iOS.Autofill
{
public partial class CredentialProviderViewController : ASCredentialProviderViewController
{
2018-09-20 20:18:30 +03:00
private Context _context = new Context();
2018-09-20 06:08:39 +03:00
public CredentialProviderViewController (IntPtr handle) : base (handle)
{
}
public override void ViewDidLoad()
2018-09-20 20:18:30 +03:00
{
SetIoc();
SetCulture();
2018-09-20 06:08:39 +03:00
base.ViewDidLoad();
2018-09-20 20:18:30 +03:00
_context.ExtContext = ExtensionContext;
// TODO: HockeyApp
2018-09-20 06:08:39 +03:00
}
public override void PrepareCredentialList(ASCredentialServiceIdentifier[] serviceIdentifiers)
{
2018-09-20 16:29:48 +03:00
System.Diagnostics.Debug.WriteLine("AUTOFILL Got identifiers " + serviceIdentifiers.Length);
2018-09-20 06:08:39 +03:00
base.PrepareCredentialList(serviceIdentifiers);
}
public override void ProvideCredentialWithoutUserInteraction(ASPasswordCredentialIdentity credentialIdentity)
{
base.ProvideCredentialWithoutUserInteraction(credentialIdentity);
}
public override void PrepareInterfaceToProvideCredential(ASPasswordCredentialIdentity credentialIdentity)
{
base.PrepareInterfaceToProvideCredential(credentialIdentity);
}
public override void PrepareInterfaceForExtensionConfiguration()
{
base.PrepareInterfaceForExtensionConfiguration();
2018-09-20 20:18:30 +03:00
}
private void SetIoc()
{
var container = new Container();
// Services
container.RegisterSingleton<IDatabaseService, DatabaseService>();
container.RegisterSingleton<ISqlService, SqlService>();
container.RegisterSingleton<ISecureStorageService, KeyChainStorageService>();
container.RegisterSingleton<ICryptoService, CryptoService>();
container.RegisterSingleton<IKeyDerivationService, CommonCryptoKeyDerivationService>();
container.RegisterSingleton<IAuthService, AuthService>();
container.RegisterSingleton<IFolderService, FolderService>();
container.RegisterSingleton<ICollectionService, CollectionService>();
container.RegisterSingleton<ICipherService, CipherService>();
container.RegisterSingleton<ISyncService, SyncService>();
container.RegisterSingleton<IDeviceActionService, NoopDeviceActionService>();
container.RegisterSingleton<IAppIdService, AppIdService>();
container.RegisterSingleton<IPasswordGenerationService, PasswordGenerationService>();
container.RegisterSingleton<ILockService, LockService>();
container.RegisterSingleton<IAppInfoService, AppInfoService>();
container.RegisterSingleton<IGoogleAnalyticsService, GoogleAnalyticsService>();
container.RegisterSingleton<IDeviceInfoService, DeviceInfoService>();
container.RegisterSingleton<ILocalizeService, LocalizeService>();
container.RegisterSingleton<ILogService, LogService>();
container.RegisterSingleton<IHttpService, HttpService>();
container.RegisterSingleton<ITokenService, TokenService>();
container.RegisterSingleton<ISettingsService, SettingsService>();
container.RegisterSingleton<IAppSettingsService, AppSettingsService>();
// Repositories
container.RegisterSingleton<IFolderRepository, FolderRepository>();
container.RegisterSingleton<IFolderApiRepository, FolderApiRepository>();
container.RegisterSingleton<ICipherRepository, CipherRepository>();
container.RegisterSingleton<IAttachmentRepository, AttachmentRepository>();
container.RegisterSingleton<IConnectApiRepository, ConnectApiRepository>();
container.RegisterSingleton<IDeviceApiRepository, DeviceApiRepository>();
container.RegisterSingleton<IAccountsApiRepository, AccountsApiRepository>();
container.RegisterSingleton<ICipherApiRepository, CipherApiRepository>();
container.RegisterSingleton<ISettingsRepository, SettingsRepository>();
container.RegisterSingleton<ISettingsApiRepository, SettingsApiRepository>();
container.RegisterSingleton<ITwoFactorApiRepository, TwoFactorApiRepository>();
container.RegisterSingleton<ISyncApiRepository, SyncApiRepository>();
container.RegisterSingleton<ICollectionRepository, CollectionRepository>();
container.RegisterSingleton<ICipherCollectionRepository, CipherCollectionRepository>();
// Other
container.RegisterSingleton(CrossConnectivity.Current);
container.RegisterSingleton(CrossFingerprint.Current);
var settings = new Settings("group.com.8bit.bitwarden");
container.RegisterSingleton<ISettings>(settings);
Resolver.ResetResolver(new SimpleInjectorResolver(container));
}
private void SetCulture()
{
var localizeService = Resolver.Resolve<ILocalizeService>();
var ci = localizeService.GetCurrentCultureInfo();
AppResources.Culture = ci;
localizeService.SetLocale(ci);
2018-09-20 06:08:39 +03:00
}
}
}