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="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
</ItemGroup>

View File

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

View File

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

View File

@ -2,6 +2,7 @@
using Bit.Core.Services;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
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 bool Inited { get; set; }
public static void Init()
public static void Init(HttpClientHandler httpClientHandler = null)
{
if(Inited)
{
@ -31,7 +32,8 @@ namespace Bit.Core.Utilities
var cryptoFunctionService = new PclCryptoFunctionService(cryptoPrimitiveService);
var cryptoService = new CryptoService(storageService, secureStorageService, cryptoFunctionService);
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 userService = new UserService(storageService, tokenService);
var settingsService = new SettingsService(userService, storageService);

View File

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