mirror of
https://github.com/bitwarden/mobile
synced 2025-02-08 07:58:54 +01:00
device user agent
This commit is contained in:
parent
bdad5e4f0a
commit
2507f3301b
@ -40,7 +40,8 @@ namespace Bit.Droid
|
|||||||
if(ServiceContainer.RegisteredServices.Count == 0)
|
if(ServiceContainer.RegisteredServices.Count == 0)
|
||||||
{
|
{
|
||||||
RegisterLocalServices();
|
RegisterLocalServices();
|
||||||
ServiceContainer.Init();
|
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
||||||
|
ServiceContainer.Init(deviceActionService.DeviceUserAgent);
|
||||||
if(App.Migration.MigrationHelpers.NeedsMigration())
|
if(App.Migration.MigrationHelpers.NeedsMigration())
|
||||||
{
|
{
|
||||||
var task = App.Migration.MigrationHelpers.PerformMigrationAsync();
|
var task = App.Migration.MigrationHelpers.PerformMigrationAsync();
|
||||||
|
@ -40,6 +40,7 @@ namespace Bit.Droid.Services
|
|||||||
private ProgressDialog _progressDialog;
|
private ProgressDialog _progressDialog;
|
||||||
private bool _cameraPermissionsDenied;
|
private bool _cameraPermissionsDenied;
|
||||||
private Toast _toast;
|
private Toast _toast;
|
||||||
|
private string _userAgent;
|
||||||
|
|
||||||
public DeviceActionService(
|
public DeviceActionService(
|
||||||
IStorageService storageService,
|
IStorageService storageService,
|
||||||
@ -61,6 +62,19 @@ namespace Bit.Droid.Services
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string DeviceUserAgent
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if(string.IsNullOrWhiteSpace(_userAgent))
|
||||||
|
{
|
||||||
|
_userAgent = $"Bitwarden_Mobile/{Xamarin.Essentials.AppInfo.VersionString} " +
|
||||||
|
$"(Android {Build.VERSION.Release}; SDK {Build.VERSION.Sdk}; Model {Build.Model})";
|
||||||
|
}
|
||||||
|
return _userAgent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public DeviceType DeviceType => DeviceType.Android;
|
public DeviceType DeviceType => DeviceType.Android;
|
||||||
|
|
||||||
public void Toast(string text, bool longDuration = false)
|
public void Toast(string text, bool longDuration = false)
|
||||||
|
@ -6,6 +6,7 @@ namespace Bit.App.Abstractions
|
|||||||
{
|
{
|
||||||
public interface IDeviceActionService
|
public interface IDeviceActionService
|
||||||
{
|
{
|
||||||
|
string DeviceUserAgent { get; }
|
||||||
DeviceType DeviceType { get; }
|
DeviceType DeviceType { get; }
|
||||||
void Toast(string text, bool longDuration = false);
|
void Toast(string text, bool longDuration = false);
|
||||||
bool LaunchApp(string appName);
|
bool LaunchApp(string appName);
|
||||||
|
@ -25,18 +25,22 @@ namespace Bit.Core.Services
|
|||||||
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;
|
||||||
private string _deviceType;
|
|
||||||
|
|
||||||
public ApiService(
|
public ApiService(
|
||||||
ITokenService tokenService,
|
ITokenService tokenService,
|
||||||
IPlatformUtilsService platformUtilsService,
|
IPlatformUtilsService platformUtilsService,
|
||||||
Func<bool, Task> logoutCallbackAsync)
|
Func<bool, Task> logoutCallbackAsync,
|
||||||
|
string customUserAgent = null)
|
||||||
{
|
{
|
||||||
_tokenService = tokenService;
|
_tokenService = tokenService;
|
||||||
_platformUtilsService = platformUtilsService;
|
_platformUtilsService = platformUtilsService;
|
||||||
_logoutCallbackAsync = logoutCallbackAsync;
|
_logoutCallbackAsync = logoutCallbackAsync;
|
||||||
var device = _platformUtilsService.GetDevice();
|
var device = _platformUtilsService.GetDevice();
|
||||||
_deviceType = device.ToString();
|
_httpClient.DefaultRequestHeaders.Add("Device-Type", device.ToString());
|
||||||
|
if(!string.IsNullOrWhiteSpace(customUserAgent))
|
||||||
|
{
|
||||||
|
_httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(customUserAgent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool UrlsSet { get; private set; }
|
public bool UrlsSet { get; private set; }
|
||||||
@ -86,7 +90,6 @@ namespace Bit.Core.Services
|
|||||||
Content = new FormUrlEncodedContent(request.ToIdentityToken(_platformUtilsService.IdentityClientId))
|
Content = new FormUrlEncodedContent(request.ToIdentityToken(_platformUtilsService.IdentityClientId))
|
||||||
};
|
};
|
||||||
requestMessage.Headers.Add("Accept", "application/json");
|
requestMessage.Headers.Add("Accept", "application/json");
|
||||||
requestMessage.Headers.Add("Device-Type", _deviceType);
|
|
||||||
|
|
||||||
HttpResponseMessage response;
|
HttpResponseMessage response;
|
||||||
try
|
try
|
||||||
@ -304,7 +307,6 @@ namespace Bit.Core.Services
|
|||||||
{
|
{
|
||||||
requestMessage.Method = HttpMethod.Post;
|
requestMessage.Method = HttpMethod.Post;
|
||||||
requestMessage.RequestUri = new Uri(string.Concat(EventsBaseUrl, "/collect"));
|
requestMessage.RequestUri = new Uri(string.Concat(EventsBaseUrl, "/collect"));
|
||||||
requestMessage.Headers.Add("Device-Type", _deviceType);
|
|
||||||
var authHeader = await GetActiveBearerTokenAsync();
|
var authHeader = await GetActiveBearerTokenAsync();
|
||||||
requestMessage.Headers.Add("Authorization", string.Concat("Bearer ", authHeader));
|
requestMessage.Headers.Add("Authorization", string.Concat("Bearer ", authHeader));
|
||||||
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(request, _jsonSettings),
|
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(request, _jsonSettings),
|
||||||
@ -377,7 +379,6 @@ namespace Bit.Core.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
requestMessage.Headers.Add("Device-Type", _deviceType);
|
|
||||||
if(authed)
|
if(authed)
|
||||||
{
|
{
|
||||||
var authHeader = await GetActiveBearerTokenAsync();
|
var authHeader = await GetActiveBearerTokenAsync();
|
||||||
@ -432,7 +433,6 @@ namespace Bit.Core.Services
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
requestMessage.Headers.Add("Accept", "application/json");
|
requestMessage.Headers.Add("Accept", "application/json");
|
||||||
requestMessage.Headers.Add("Device-Type", _deviceType);
|
|
||||||
|
|
||||||
HttpResponseMessage response;
|
HttpResponseMessage response;
|
||||||
try
|
try
|
||||||
|
@ -11,7 +11,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(string customUserAgent = null)
|
||||||
{
|
{
|
||||||
if(Inited)
|
if(Inited)
|
||||||
{
|
{
|
||||||
@ -31,7 +31,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),
|
||||||
|
customUserAgent);
|
||||||
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);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using AuthenticationServices;
|
using AuthenticationServices;
|
||||||
|
using Bit.App.Abstractions;
|
||||||
using Bit.App.Resources;
|
using Bit.App.Resources;
|
||||||
using Bit.Core.Abstractions;
|
using Bit.Core.Abstractions;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
@ -265,7 +266,8 @@ namespace Bit.iOS.Autofill
|
|||||||
ServiceContainer.Reset();
|
ServiceContainer.Reset();
|
||||||
}
|
}
|
||||||
iOSCoreHelpers.RegisterLocalServices();
|
iOSCoreHelpers.RegisterLocalServices();
|
||||||
ServiceContainer.Init();
|
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
||||||
|
ServiceContainer.Init(deviceActionService.DeviceUserAgent);
|
||||||
if(!_initedHockeyApp)
|
if(!_initedHockeyApp)
|
||||||
{
|
{
|
||||||
iOSCoreHelpers.RegisterHockeyApp();
|
iOSCoreHelpers.RegisterHockeyApp();
|
||||||
|
@ -26,6 +26,7 @@ namespace Bit.iOS.Core.Services
|
|||||||
private readonly IMessagingService _messagingService;
|
private readonly IMessagingService _messagingService;
|
||||||
private Toast _toast;
|
private Toast _toast;
|
||||||
private UIAlertController _progressAlert;
|
private UIAlertController _progressAlert;
|
||||||
|
private string _userAgent;
|
||||||
|
|
||||||
public DeviceActionService(
|
public DeviceActionService(
|
||||||
IStorageService storageService,
|
IStorageService storageService,
|
||||||
@ -35,6 +36,19 @@ namespace Bit.iOS.Core.Services
|
|||||||
_messagingService = messagingService;
|
_messagingService = messagingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string DeviceUserAgent
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if(string.IsNullOrWhiteSpace(_userAgent))
|
||||||
|
{
|
||||||
|
_userAgent = $"Bitwarden_Mobile/{Xamarin.Essentials.AppInfo.VersionString} " +
|
||||||
|
$"(iOS {UIDevice.CurrentDevice.SystemVersion}; Model {UIDevice.CurrentDevice.Model})";
|
||||||
|
}
|
||||||
|
return _userAgent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public DeviceType DeviceType => DeviceType.iOS;
|
public DeviceType DeviceType => DeviceType.iOS;
|
||||||
|
|
||||||
public bool LaunchApp(string appName)
|
public bool LaunchApp(string appName)
|
||||||
@ -261,7 +275,7 @@ namespace Bit.iOS.Core.Services
|
|||||||
public int SystemMajorVersion()
|
public int SystemMajorVersion()
|
||||||
{
|
{
|
||||||
var versionParts = UIDevice.CurrentDevice.SystemVersion.Split('.');
|
var versionParts = UIDevice.CurrentDevice.SystemVersion.Split('.');
|
||||||
if(versionParts.Length > 0 && int.TryParse(versionParts[0], out int version))
|
if(versionParts.Length > 0 && int.TryParse(versionParts[0], out var version))
|
||||||
{
|
{
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Foundation;
|
using Foundation;
|
||||||
using UIKit;
|
using UIKit;
|
||||||
@ -12,6 +12,7 @@ using System.Collections.Generic;
|
|||||||
using Bit.iOS.Core.Models;
|
using Bit.iOS.Core.Models;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
using Bit.Core.Abstractions;
|
using Bit.Core.Abstractions;
|
||||||
|
using Bit.App.Abstractions;
|
||||||
|
|
||||||
namespace Bit.iOS.Extension
|
namespace Bit.iOS.Extension
|
||||||
{
|
{
|
||||||
@ -386,7 +387,8 @@ namespace Bit.iOS.Extension
|
|||||||
ServiceContainer.Reset();
|
ServiceContainer.Reset();
|
||||||
}
|
}
|
||||||
iOSCoreHelpers.RegisterLocalServices();
|
iOSCoreHelpers.RegisterLocalServices();
|
||||||
ServiceContainer.Init();
|
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
||||||
|
ServiceContainer.Init(deviceActionService.DeviceUserAgent);
|
||||||
if(!_initedHockeyApp)
|
if(!_initedHockeyApp)
|
||||||
{
|
{
|
||||||
iOSCoreHelpers.RegisterHockeyApp();
|
iOSCoreHelpers.RegisterHockeyApp();
|
||||||
|
@ -287,7 +287,8 @@ namespace Bit.iOS
|
|||||||
|
|
||||||
iOSCoreHelpers.RegisterLocalServices();
|
iOSCoreHelpers.RegisterLocalServices();
|
||||||
RegisterPush();
|
RegisterPush();
|
||||||
ServiceContainer.Init();
|
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
||||||
|
ServiceContainer.Init(deviceActionService.DeviceUserAgent);
|
||||||
iOSCoreHelpers.RegisterHockeyApp();
|
iOSCoreHelpers.RegisterHockeyApp();
|
||||||
_pushHandler = new iOSPushNotificationHandler(
|
_pushHandler = new iOSPushNotificationHandler(
|
||||||
ServiceContainer.Resolve<IPushNotificationListenerService>("pushNotificationListenerService"));
|
ServiceContainer.Resolve<IPushNotificationListenerService>("pushNotificationListenerService"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user