android http client handler

This commit is contained in:
Kyle Spearrin 2019-06-15 18:44:08 -04:00
parent 58ef292fa7
commit c50dee479a
5 changed files with 19 additions and 5 deletions

View file

@ -71,6 +71,7 @@
<Reference Include="Mono.Android.Export" /> <Reference Include="Mono.Android.Export" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>

View file

@ -15,6 +15,7 @@ using Bit.Droid.Services;
using Bit.Droid.Utilities; using Bit.Droid.Utilities;
using Plugin.CurrentActivity; using Plugin.CurrentActivity;
using Plugin.Fingerprint; using Plugin.Fingerprint;
using Xamarin.Android.Net;
#if !FDROID #if !FDROID
using Android.Gms.Security; using Android.Gms.Security;
#endif #endif
@ -39,7 +40,7 @@ namespace Bit.Droid
if(ServiceContainer.RegisteredServices.Count == 0) if(ServiceContainer.RegisteredServices.Count == 0)
{ {
RegisterLocalServices(); RegisterLocalServices();
ServiceContainer.Init(); ServiceContainer.Init(new AndroidClientHandler());
if(App.Migration.MigrationHelpers.NeedsMigration()) if(App.Migration.MigrationHelpers.NeedsMigration())
{ {
var task = App.Migration.MigrationHelpers.PerformMigrationAsync(); var task = App.Migration.MigrationHelpers.PerformMigrationAsync();

View file

@ -22,7 +22,7 @@ namespace Bit.Core.Services
{ {
ContractResolver = new CamelCasePropertyNamesContractResolver() ContractResolver = new CamelCasePropertyNamesContractResolver()
}; };
private readonly HttpClient _httpClient = new HttpClient(); private readonly HttpClient _httpClient;
private readonly ITokenService _tokenService; private readonly ITokenService _tokenService;
private readonly IPlatformUtilsService _platformUtilsService; private readonly IPlatformUtilsService _platformUtilsService;
private readonly Func<bool, Task> _logoutCallbackAsync; private readonly Func<bool, Task> _logoutCallbackAsync;
@ -31,13 +31,22 @@ namespace Bit.Core.Services
public ApiService( public ApiService(
ITokenService tokenService, ITokenService tokenService,
IPlatformUtilsService platformUtilsService, IPlatformUtilsService platformUtilsService,
Func<bool, Task> logoutCallbackAsync) Func<bool, Task> logoutCallbackAsync,
HttpMessageHandler httpMessageHandler = null)
{ {
_tokenService = tokenService; _tokenService = tokenService;
_platformUtilsService = platformUtilsService; _platformUtilsService = platformUtilsService;
_logoutCallbackAsync = logoutCallbackAsync; _logoutCallbackAsync = logoutCallbackAsync;
var device = _platformUtilsService.GetDevice(); var device = _platformUtilsService.GetDevice();
_deviceType = device.ToString(); _deviceType = device.ToString();
if(httpMessageHandler != null)
{
_httpClient = new HttpClient(httpMessageHandler);
}
else
{
_httpClient = new HttpClient();
}
} }
public bool UrlsSet { get; private set; } public bool UrlsSet { get; private set; }

View file

@ -2,6 +2,7 @@
using Bit.Core.Services; using Bit.Core.Services;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Bit.Core.Utilities namespace Bit.Core.Utilities
@ -11,7 +12,7 @@ namespace Bit.Core.Utilities
public static Dictionary<string, object> RegisteredServices { get; set; } = new Dictionary<string, object>(); public static Dictionary<string, object> RegisteredServices { get; set; } = new Dictionary<string, object>();
public static bool Inited { get; set; } public static bool Inited { get; set; }
public static void Init() public static void Init(HttpClientHandler httpClientHandler = null)
{ {
if(Inited) if(Inited)
{ {
@ -31,7 +32,8 @@ namespace Bit.Core.Utilities
var cryptoFunctionService = new PclCryptoFunctionService(cryptoPrimitiveService); var cryptoFunctionService = new PclCryptoFunctionService(cryptoPrimitiveService);
var cryptoService = new CryptoService(storageService, secureStorageService, cryptoFunctionService); var cryptoService = new CryptoService(storageService, secureStorageService, cryptoFunctionService);
var tokenService = new TokenService(storageService); var tokenService = new TokenService(storageService);
var apiService = new ApiService(tokenService, platformUtilsService, (bool expired) => Task.FromResult(0)); var apiService = new ApiService(tokenService, platformUtilsService, (bool expired) => Task.FromResult(0),
httpClientHandler);
var appIdService = new AppIdService(storageService); var appIdService = new AppIdService(storageService);
var userService = new UserService(storageService, tokenService); var userService = new UserService(storageService, tokenService);
var settingsService = new SettingsService(userService, storageService); var settingsService = new SettingsService(userService, storageService);

View file

@ -132,6 +132,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="Xamarin.iOS" /> <Reference Include="Xamarin.iOS" />