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;
|
|
|
|
|
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-06-04 05:19:51 +03:00
|
|
|
|
using Bit.Droid.Utilities;
|
2019-05-16 23:31:58 +03:00
|
|
|
|
using Plugin.CurrentActivity;
|
|
|
|
|
using Plugin.Fingerprint;
|
|
|
|
|
using Plugin.Fingerprint.Abstractions;
|
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")]
|
|
|
|
|
public class MainApplication : Application
|
|
|
|
|
{
|
|
|
|
|
public MainApplication(IntPtr handle, JniHandleOwnership transer)
|
|
|
|
|
: base(handle, transer)
|
2019-04-11 21:14:34 +03:00
|
|
|
|
{
|
|
|
|
|
if(ServiceContainer.RegisteredServices.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
RegisterLocalServices();
|
|
|
|
|
ServiceContainer.Init();
|
2019-06-02 06:33:36 +03:00
|
|
|
|
if(App.Migration.MigrationHelpers.NeedsMigration())
|
|
|
|
|
{
|
|
|
|
|
var task = App.Migration.MigrationHelpers.PerformMigrationAsync();
|
|
|
|
|
Task.Delay(2000).Wait();
|
|
|
|
|
}
|
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-04-18 19:31:35 +03:00
|
|
|
|
private void RegisterLocalServices()
|
2019-04-11 21:14:34 +03:00
|
|
|
|
{
|
2019-06-03 19:52:46 +03:00
|
|
|
|
ServiceContainer.Register<ILogService>("logService", new AndroidLogService());
|
2019-06-01 00:49:51 +03:00
|
|
|
|
ServiceContainer.Register("settingsShim", new App.Migration.SettingsShim());
|
|
|
|
|
if(App.Migration.MigrationHelpers.NeedsMigration())
|
|
|
|
|
{
|
|
|
|
|
ServiceContainer.Register<App.Migration.Abstractions.IOldSecureStorageService>(
|
|
|
|
|
"oldSecureStorageService", new Migration.AndroidKeyStoreStorageService());
|
|
|
|
|
}
|
2019-05-30 22:11:22 +03:00
|
|
|
|
|
2019-05-08 15:33:17 +03:00
|
|
|
|
Refractored.FabControl.Droid.FloatingActionButtonViewRenderer.Init();
|
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,
|
|
|
|
|
FadeAnimationForCachedImages = false
|
|
|
|
|
});
|
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-06-04 05:19:51 +03:00
|
|
|
|
CrossFingerprint.SetDialogFragmentType<CustomFingerprintDialogFragment>();
|
2019-04-23 00:08:37 +03:00
|
|
|
|
|
2019-04-11 21:14:34 +03:00
|
|
|
|
var preferencesStorage = new PreferencesStorageService(null);
|
|
|
|
|
var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
|
|
|
|
|
var liteDbStorage = new LiteDbStorageService(Path.Combine(documentsPath, "bitwarden.db"));
|
2019-04-26 17:55:29 +03:00
|
|
|
|
liteDbStorage.InitAsync();
|
2019-04-11 22:33:10 +03:00
|
|
|
|
var localizeService = new LocalizeService();
|
2019-04-19 19:29:37 +03:00
|
|
|
|
var broadcasterService = new BroadcasterService();
|
|
|
|
|
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);
|
2019-05-11 06:43:35 +03:00
|
|
|
|
var deviceActionService = new DeviceActionService(mobileStorageService, messagingService,
|
|
|
|
|
broadcasterService);
|
2019-04-18 20:15:46 +03:00
|
|
|
|
var platformUtilsService = new MobilePlatformUtilsService(deviceActionService, messagingService,
|
|
|
|
|
broadcasterService);
|
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);
|
2019-04-11 21:14:34 +03:00
|
|
|
|
ServiceContainer.Register<IDeviceActionService>("deviceActionService", deviceActionService);
|
2019-04-18 17:40:57 +03:00
|
|
|
|
ServiceContainer.Register<IPlatformUtilsService>("platformUtilsService", platformUtilsService);
|
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(
|
|
|
|
|
mobileStorageService, notificationListenerService);
|
|
|
|
|
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()
|
|
|
|
|
{
|
2019-05-29 16:55:48 +03:00
|
|
|
|
var disableFavicon = await ServiceContainer.Resolve<IStorageService>("storageService").GetAsync<bool?>(
|
|
|
|
|
Constants.DisableFaviconKey);
|
|
|
|
|
await ServiceContainer.Resolve<IStateService>("stateService").SaveAsync(Constants.DisableFaviconKey,
|
|
|
|
|
disableFavicon);
|
2019-04-18 19:31:35 +03:00
|
|
|
|
await ServiceContainer.Resolve<IEnvironmentService>("environmentService").SetUrlsFromStorageAsync();
|
|
|
|
|
}
|
2019-03-28 03:12:44 +03:00
|
|
|
|
}
|
|
|
|
|
}
|