2019-03-28 03:12:44 +03:00
|
|
|
|
using System;
|
2019-04-11 21:14:34 +03:00
|
|
|
|
using System.IO;
|
2019-04-18 19:31:35 +03:00
|
|
|
|
using System.Threading.Tasks;
|
2019-03-28 03:12:44 +03:00
|
|
|
|
using Android.App;
|
2019-06-13 17:06:08 +03:00
|
|
|
|
using Android.Content;
|
|
|
|
|
using Android.OS;
|
2019-03-28 03:12:44 +03:00
|
|
|
|
using Android.Runtime;
|
2019-04-11 21:14:34 +03:00
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Services;
|
2019-05-29 16:55:48 +03:00
|
|
|
|
using Bit.Core;
|
2019-04-11 21:14:34 +03:00
|
|
|
|
using Bit.Core.Abstractions;
|
|
|
|
|
using Bit.Core.Services;
|
|
|
|
|
using Bit.Core.Utilities;
|
|
|
|
|
using Bit.Droid.Services;
|
2019-05-16 23:31:58 +03:00
|
|
|
|
using Plugin.CurrentActivity;
|
|
|
|
|
using Plugin.Fingerprint;
|
2019-06-16 01:44:08 +03:00
|
|
|
|
using Xamarin.Android.Net;
|
2021-11-18 23:38:23 +03:00
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Net;
|
2022-01-24 19:25:46 +03:00
|
|
|
|
using Bit.App.Utilities;
|
|
|
|
|
using Bit.App.Pages;
|
2022-06-08 20:24:01 +03:00
|
|
|
|
using Bit.App.Utilities.AccountManagement;
|
2022-07-12 20:12:23 +03:00
|
|
|
|
using Bit.App.Controls;
|
2019-06-13 17:06:08 +03:00
|
|
|
|
#if !FDROID
|
|
|
|
|
using Android.Gms.Security;
|
|
|
|
|
#endif
|
2019-03-28 03:12:44 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.Droid
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
|
|
|
|
[Application(Debuggable = true)]
|
|
|
|
|
#else
|
|
|
|
|
[Application(Debuggable = false)]
|
|
|
|
|
#endif
|
|
|
|
|
[Register("com.x8bit.bitwarden.MainApplication")]
|
2019-06-13 17:06:08 +03:00
|
|
|
|
#if FDROID
|
2019-03-28 03:12:44 +03:00
|
|
|
|
public class MainApplication : Application
|
2019-06-13 17:06:08 +03:00
|
|
|
|
#else
|
|
|
|
|
public class MainApplication : Application, ProviderInstaller.IProviderInstallListener
|
|
|
|
|
#endif
|
2019-03-28 03:12:44 +03:00
|
|
|
|
{
|
|
|
|
|
public MainApplication(IntPtr handle, JniHandleOwnership transer)
|
|
|
|
|
: base(handle, transer)
|
2019-04-11 21:14:34 +03:00
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (ServiceContainer.RegisteredServices.Count == 0)
|
2019-04-11 21:14:34 +03:00
|
|
|
|
{
|
|
|
|
|
RegisterLocalServices();
|
2022-12-07 19:39:20 +03:00
|
|
|
|
|
2019-09-04 18:52:32 +03:00
|
|
|
|
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
2022-10-11 23:47:52 +03:00
|
|
|
|
ServiceContainer.Init(deviceActionService.DeviceUserAgent, Core.Constants.ClearCiphersCacheKey,
|
|
|
|
|
Core.Constants.AndroidAllClearCipherCacheKeys);
|
2022-12-07 19:39:20 +03:00
|
|
|
|
|
|
|
|
|
ServiceContainer.Register<IWatchDeviceService>(new WatchDeviceService(ServiceContainer.Resolve<ICipherService>(),
|
|
|
|
|
ServiceContainer.Resolve<IEnvironmentService>(),
|
|
|
|
|
ServiceContainer.Resolve<IStateService>(),
|
|
|
|
|
ServiceContainer.Resolve<IVaultTimeoutService>()));
|
|
|
|
|
|
2022-09-09 21:58:11 +03:00
|
|
|
|
InitializeAppSetup();
|
2022-01-24 19:25:46 +03:00
|
|
|
|
|
|
|
|
|
// TODO: Update when https://github.com/bitwarden/mobile/pull/1662 gets merged
|
|
|
|
|
var deleteAccountActionFlowExecutioner = new DeleteAccountActionFlowExecutioner(
|
|
|
|
|
ServiceContainer.Resolve<IApiService>("apiService"),
|
|
|
|
|
ServiceContainer.Resolve<IMessagingService>("messagingService"),
|
|
|
|
|
ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService"),
|
2022-03-02 20:15:16 +03:00
|
|
|
|
ServiceContainer.Resolve<IDeviceActionService>("deviceActionService"),
|
|
|
|
|
ServiceContainer.Resolve<ILogger>("logger"));
|
2022-01-24 19:25:46 +03:00
|
|
|
|
ServiceContainer.Register<IDeleteAccountActionFlowExecutioner>("deleteAccountActionFlowExecutioner", deleteAccountActionFlowExecutioner);
|
|
|
|
|
|
|
|
|
|
var verificationActionsFlowHelper = new VerificationActionsFlowHelper(
|
|
|
|
|
ServiceContainer.Resolve<IKeyConnectorService>("keyConnectorService"),
|
2022-02-03 23:46:45 +03:00
|
|
|
|
ServiceContainer.Resolve<IPasswordRepromptService>("passwordRepromptService"),
|
|
|
|
|
ServiceContainer.Resolve<ICryptoService>("cryptoService"));
|
2022-01-24 19:25:46 +03:00
|
|
|
|
ServiceContainer.Register<IVerificationActionsFlowHelper>("verificationActionsFlowHelper", verificationActionsFlowHelper);
|
2022-06-08 20:24:01 +03:00
|
|
|
|
|
|
|
|
|
var accountsManager = new AccountsManager(
|
|
|
|
|
ServiceContainer.Resolve<IBroadcasterService>("broadcasterService"),
|
|
|
|
|
ServiceContainer.Resolve<IVaultTimeoutService>("vaultTimeoutService"),
|
|
|
|
|
ServiceContainer.Resolve<IStorageService>("secureStorageService"),
|
|
|
|
|
ServiceContainer.Resolve<IStateService>("stateService"),
|
|
|
|
|
ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService"),
|
2022-07-12 20:12:23 +03:00
|
|
|
|
ServiceContainer.Resolve<IAuthService>("authService"),
|
2022-10-03 19:11:38 +03:00
|
|
|
|
ServiceContainer.Resolve<ILogger>("logger"),
|
2022-12-07 19:39:20 +03:00
|
|
|
|
ServiceContainer.Resolve<IMessagingService>("messagingService"),
|
|
|
|
|
ServiceContainer.Resolve<IWatchDeviceService>());
|
|
|
|
|
ServiceContainer.Register<IAccountsManager>("accountsManager", accountsManager);
|
2019-04-11 21:14:34 +03:00
|
|
|
|
}
|
2019-06-13 17:06:08 +03:00
|
|
|
|
#if !FDROID
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (Build.VERSION.SdkInt <= BuildVersionCodes.Kitkat)
|
2019-06-13 17:06:08 +03:00
|
|
|
|
{
|
|
|
|
|
ProviderInstaller.InstallIfNeededAsync(ApplicationContext, this);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2019-04-11 21:14:34 +03:00
|
|
|
|
}
|
2019-04-10 06:24:03 +03:00
|
|
|
|
|
|
|
|
|
public override void OnCreate()
|
|
|
|
|
{
|
|
|
|
|
base.OnCreate();
|
2019-04-18 19:31:35 +03:00
|
|
|
|
Bootstrap();
|
2019-05-16 23:31:58 +03:00
|
|
|
|
CrossCurrentActivity.Current.Init(this);
|
2019-04-10 06:24:03 +03:00
|
|
|
|
}
|
2019-04-11 21:14:34 +03:00
|
|
|
|
|
2019-06-13 17:06:08 +03:00
|
|
|
|
public void OnProviderInstallFailed(int errorCode, Intent recoveryIntent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnProviderInstalled()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-18 19:31:35 +03:00
|
|
|
|
private void RegisterLocalServices()
|
2019-04-11 21:14:34 +03:00
|
|
|
|
{
|
2022-03-02 20:15:16 +03:00
|
|
|
|
ServiceContainer.Register<INativeLogService>("nativeLogService", new AndroidLogService());
|
|
|
|
|
#if FDROID
|
2022-07-06 00:14:10 +03:00
|
|
|
|
var logger = new StubLogger();
|
2022-03-02 20:15:16 +03:00
|
|
|
|
#elif DEBUG
|
2022-07-06 00:14:10 +03:00
|
|
|
|
var logger = DebugLogger.Instance;
|
2022-03-02 20:15:16 +03:00
|
|
|
|
#else
|
2022-07-06 00:14:10 +03:00
|
|
|
|
var logger = Logger.Instance;
|
2022-03-02 20:15:16 +03:00
|
|
|
|
#endif
|
2022-07-06 00:14:10 +03:00
|
|
|
|
ServiceContainer.Register("logger", logger);
|
2019-05-30 22:11:22 +03:00
|
|
|
|
|
2019-04-26 17:58:41 +03:00
|
|
|
|
// Note: This might cause a race condition. Investigate more.
|
2019-05-23 03:28:31 +03:00
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
FFImageLoading.Forms.Platform.CachedImageRenderer.Init(true);
|
2019-06-07 03:38:53 +03:00
|
|
|
|
FFImageLoading.ImageService.Instance.Initialize(new FFImageLoading.Config.Configuration
|
|
|
|
|
{
|
|
|
|
|
FadeAnimationEnabled = false,
|
2021-11-18 23:38:23 +03:00
|
|
|
|
FadeAnimationForCachedImages = false,
|
|
|
|
|
HttpClient = new HttpClient(new AndroidClientHandler() { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate })
|
2019-06-07 03:38:53 +03:00
|
|
|
|
});
|
2019-05-23 03:28:31 +03:00
|
|
|
|
ZXing.Net.Mobile.Forms.Android.Platform.Init();
|
|
|
|
|
});
|
2019-05-16 23:31:58 +03:00
|
|
|
|
CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity);
|
2019-04-23 00:08:37 +03:00
|
|
|
|
|
2019-04-11 21:14:34 +03:00
|
|
|
|
var preferencesStorage = new PreferencesStorageService(null);
|
2019-06-13 17:06:08 +03:00
|
|
|
|
var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
|
2019-04-11 21:14:34 +03:00
|
|
|
|
var liteDbStorage = new LiteDbStorageService(Path.Combine(documentsPath, "bitwarden.db"));
|
2019-04-11 22:33:10 +03:00
|
|
|
|
var localizeService = new LocalizeService();
|
2022-07-06 00:14:10 +03:00
|
|
|
|
var broadcasterService = new BroadcasterService(logger);
|
2019-04-19 19:29:37 +03:00
|
|
|
|
var messagingService = new MobileBroadcasterMessagingService(broadcasterService);
|
2019-04-18 17:40:57 +03:00
|
|
|
|
var i18nService = new MobileI18nService(localizeService.GetCurrentCultureInfo());
|
|
|
|
|
var secureStorageService = new SecureStorageService();
|
|
|
|
|
var cryptoPrimitiveService = new CryptoPrimitiveService();
|
|
|
|
|
var mobileStorageService = new MobileStorageService(preferencesStorage, liteDbStorage);
|
2022-06-15 19:44:25 +03:00
|
|
|
|
var stateService = new StateService(mobileStorageService, secureStorageService, messagingService);
|
2022-02-23 20:40:17 +03:00
|
|
|
|
var stateMigrationService =
|
|
|
|
|
new StateMigrationService(liteDbStorage, preferencesStorage, secureStorageService);
|
2022-06-10 19:02:17 +03:00
|
|
|
|
var clipboardService = new ClipboardService(stateService);
|
2022-10-12 00:19:32 +03:00
|
|
|
|
var deviceActionService = new DeviceActionService(stateService, messagingService);
|
|
|
|
|
var fileService = new FileService(stateService, broadcasterService);
|
2022-06-10 19:02:17 +03:00
|
|
|
|
var platformUtilsService = new MobilePlatformUtilsService(deviceActionService, clipboardService,
|
|
|
|
|
messagingService, broadcasterService);
|
2022-12-19 20:03:22 +03:00
|
|
|
|
var autofillHandler = new AutofillHandler(stateService, messagingService, clipboardService,
|
|
|
|
|
platformUtilsService, new LazyResolve<IEventService>());
|
2020-08-09 04:33:49 +03:00
|
|
|
|
var biometricService = new BiometricService();
|
2021-05-21 16:13:54 +03:00
|
|
|
|
var cryptoFunctionService = new PclCryptoFunctionService(cryptoPrimitiveService);
|
2022-02-23 20:40:17 +03:00
|
|
|
|
var cryptoService = new CryptoService(stateService, cryptoFunctionService);
|
2021-05-21 16:13:54 +03:00
|
|
|
|
var passwordRepromptService = new MobilePasswordRepromptService(platformUtilsService, cryptoService);
|
2019-04-11 21:14:34 +03:00
|
|
|
|
|
2019-04-18 20:15:46 +03:00
|
|
|
|
ServiceContainer.Register<IBroadcasterService>("broadcasterService", broadcasterService);
|
2019-04-18 17:40:57 +03:00
|
|
|
|
ServiceContainer.Register<IMessagingService>("messagingService", messagingService);
|
2019-04-11 22:33:10 +03:00
|
|
|
|
ServiceContainer.Register<ILocalizeService>("localizeService", localizeService);
|
2019-04-18 17:40:57 +03:00
|
|
|
|
ServiceContainer.Register<II18nService>("i18nService", i18nService);
|
|
|
|
|
ServiceContainer.Register<ICryptoPrimitiveService>("cryptoPrimitiveService", cryptoPrimitiveService);
|
|
|
|
|
ServiceContainer.Register<IStorageService>("storageService", mobileStorageService);
|
|
|
|
|
ServiceContainer.Register<IStorageService>("secureStorageService", secureStorageService);
|
2022-02-23 20:40:17 +03:00
|
|
|
|
ServiceContainer.Register<IStateService>("stateService", stateService);
|
|
|
|
|
ServiceContainer.Register<IStateMigrationService>("stateMigrationService", stateMigrationService);
|
2022-06-10 19:02:17 +03:00
|
|
|
|
ServiceContainer.Register<IClipboardService>("clipboardService", clipboardService);
|
2019-04-11 21:14:34 +03:00
|
|
|
|
ServiceContainer.Register<IDeviceActionService>("deviceActionService", deviceActionService);
|
2022-10-12 00:19:32 +03:00
|
|
|
|
ServiceContainer.Register<IFileService>(fileService);
|
|
|
|
|
ServiceContainer.Register<IAutofillHandler>(autofillHandler);
|
2019-04-18 17:40:57 +03:00
|
|
|
|
ServiceContainer.Register<IPlatformUtilsService>("platformUtilsService", platformUtilsService);
|
2020-08-09 04:33:49 +03:00
|
|
|
|
ServiceContainer.Register<IBiometricService>("biometricService", biometricService);
|
2021-05-21 16:13:54 +03:00
|
|
|
|
ServiceContainer.Register<ICryptoFunctionService>("cryptoFunctionService", cryptoFunctionService);
|
|
|
|
|
ServiceContainer.Register<ICryptoService>("cryptoService", cryptoService);
|
|
|
|
|
ServiceContainer.Register<IPasswordRepromptService>("passwordRepromptService", passwordRepromptService);
|
2022-07-12 20:12:23 +03:00
|
|
|
|
ServiceContainer.Register<IAvatarImageSourcePool>("avatarImageSourcePool", new AvatarImageSourcePool());
|
2019-05-28 19:01:55 +03:00
|
|
|
|
|
|
|
|
|
// Push
|
|
|
|
|
#if FDROID
|
2019-05-28 20:50:01 +03:00
|
|
|
|
ServiceContainer.Register<IPushNotificationListenerService>(
|
|
|
|
|
"pushNotificationListenerService", new NoopPushNotificationListenerService());
|
|
|
|
|
ServiceContainer.Register<IPushNotificationService>(
|
|
|
|
|
"pushNotificationService", new NoopPushNotificationService());
|
2019-05-28 19:01:55 +03:00
|
|
|
|
#else
|
|
|
|
|
var notificationListenerService = new PushNotificationListenerService();
|
|
|
|
|
ServiceContainer.Register<IPushNotificationListenerService>(
|
|
|
|
|
"pushNotificationListenerService", notificationListenerService);
|
|
|
|
|
var androidPushNotificationService = new AndroidPushNotificationService(
|
2022-02-23 20:40:17 +03:00
|
|
|
|
stateService, notificationListenerService);
|
2019-05-28 19:01:55 +03:00
|
|
|
|
ServiceContainer.Register<IPushNotificationService>(
|
|
|
|
|
"pushNotificationService", androidPushNotificationService);
|
|
|
|
|
#endif
|
2019-04-11 21:14:34 +03:00
|
|
|
|
}
|
2019-04-18 19:31:35 +03:00
|
|
|
|
|
|
|
|
|
private void Bootstrap()
|
|
|
|
|
{
|
|
|
|
|
(ServiceContainer.Resolve<II18nService>("i18nService") as MobileI18nService).Init();
|
|
|
|
|
ServiceContainer.Resolve<IAuthService>("authService").Init();
|
|
|
|
|
// Note: This is not awaited
|
|
|
|
|
var bootstrapTask = BootstrapAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task BootstrapAsync()
|
|
|
|
|
{
|
|
|
|
|
await ServiceContainer.Resolve<IEnvironmentService>("environmentService").SetUrlsFromStorageAsync();
|
|
|
|
|
}
|
2022-09-09 21:58:11 +03:00
|
|
|
|
|
|
|
|
|
private void InitializeAppSetup()
|
|
|
|
|
{
|
|
|
|
|
var appSetup = new AppSetup();
|
|
|
|
|
appSetup.InitializeServicesLastChance();
|
|
|
|
|
ServiceContainer.Register<IAppSetup>("appSetup", appSetup);
|
|
|
|
|
}
|
2019-03-28 03:12:44 +03:00
|
|
|
|
}
|
2019-09-04 18:52:32 +03:00
|
|
|
|
}
|