2016-06-18 09:45:46 +03:00
|
|
|
using System;
|
|
|
|
using Android.App;
|
|
|
|
using Android.Content;
|
|
|
|
using Android.OS;
|
|
|
|
using Android.Runtime;
|
|
|
|
using Bit.Android.Services;
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
using Bit.App.Repositories;
|
|
|
|
using Bit.App.Services;
|
|
|
|
using Plugin.Connectivity;
|
|
|
|
using Plugin.CurrentActivity;
|
|
|
|
using Plugin.Fingerprint;
|
|
|
|
using Plugin.Settings;
|
|
|
|
using XLabs.Ioc;
|
2016-08-27 21:36:32 +03:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Plugin.Settings.Abstractions;
|
2017-02-16 05:56:02 +03:00
|
|
|
using FFImageLoading.Forms.Droid;
|
2017-06-01 21:49:48 +03:00
|
|
|
using XLabs.Ioc.SimpleInjectorContainer;
|
|
|
|
using SimpleInjector;
|
2016-06-18 09:45:46 +03:00
|
|
|
|
|
|
|
namespace Bit.Android
|
|
|
|
{
|
2016-08-27 06:07:35 +03:00
|
|
|
#if DEBUG
|
2017-06-27 22:00:21 +03:00
|
|
|
[Application(Debuggable = true)]
|
2016-08-27 06:07:35 +03:00
|
|
|
#else
|
2017-06-27 22:00:21 +03:00
|
|
|
[Application(Debuggable = false)]
|
2016-08-27 06:07:35 +03:00
|
|
|
#endif
|
2016-06-18 09:45:46 +03:00
|
|
|
public class MainApplication : Application, Application.IActivityLifecycleCallbacks
|
|
|
|
{
|
2016-08-27 21:36:32 +03:00
|
|
|
private const string FirstLaunchKey = "firstLaunch";
|
|
|
|
private const string LastVersionCodeKey = "lastVersionCode";
|
|
|
|
|
2016-06-18 09:45:46 +03:00
|
|
|
public static Context AppContext;
|
|
|
|
|
|
|
|
public MainApplication(IntPtr handle, JniHandleOwnership transer)
|
|
|
|
: base(handle, transer)
|
|
|
|
{
|
2017-06-23 04:53:32 +03:00
|
|
|
//AndroidEnvironment.UnhandledExceptionRaiser += AndroidEnvironment_UnhandledExceptionRaiser;
|
2017-06-08 19:44:16 +03:00
|
|
|
|
2016-06-18 09:45:46 +03:00
|
|
|
if(!Resolver.IsSet)
|
|
|
|
{
|
2017-01-28 07:13:28 +03:00
|
|
|
SetIoc(this);
|
2016-06-18 09:45:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 19:44:16 +03:00
|
|
|
private void AndroidEnvironment_UnhandledExceptionRaiser(object sender, RaiseThrowableEventArgs e)
|
|
|
|
{
|
2017-06-24 06:21:39 +03:00
|
|
|
var message = Utilities.AppendExceptionToMessage("", e.Exception);
|
2017-06-23 04:54:57 +03:00
|
|
|
//Utilities.SaveCrashFile(message, true);
|
|
|
|
Utilities.SendCrashEmail(message, false);
|
2017-06-08 19:44:16 +03:00
|
|
|
}
|
|
|
|
|
2016-08-27 22:00:12 +03:00
|
|
|
public override void OnCreate()
|
2016-06-18 09:45:46 +03:00
|
|
|
{
|
|
|
|
base.OnCreate();
|
2016-08-27 21:36:32 +03:00
|
|
|
|
|
|
|
// workaround for app compat bug
|
|
|
|
// ref https://forums.xamarin.com/discussion/62414/app-resuming-results-in-crash-with-formsappcompatactivity
|
2016-08-27 22:00:12 +03:00
|
|
|
Task.Delay(10).Wait();
|
2016-08-27 21:36:32 +03:00
|
|
|
|
2016-06-18 09:45:46 +03:00
|
|
|
RegisterActivityLifecycleCallbacks(this);
|
|
|
|
AppContext = ApplicationContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnTerminate()
|
|
|
|
{
|
|
|
|
base.OnTerminate();
|
|
|
|
UnregisterActivityLifecycleCallbacks(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnActivityCreated(Activity activity, Bundle savedInstanceState)
|
|
|
|
{
|
|
|
|
CrossCurrentActivity.Current.Activity = activity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnActivityDestroyed(Activity activity)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnActivityPaused(Activity activity)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnActivityResumed(Activity activity)
|
|
|
|
{
|
|
|
|
CrossCurrentActivity.Current.Activity = activity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnActivitySaveInstanceState(Activity activity, Bundle outState)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnActivityStarted(Activity activity)
|
|
|
|
{
|
|
|
|
CrossCurrentActivity.Current.Activity = activity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnActivityStopped(Activity activity)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-28 07:13:28 +03:00
|
|
|
public static void SetIoc(Application application)
|
2016-06-18 09:45:46 +03:00
|
|
|
{
|
2017-02-16 05:56:02 +03:00
|
|
|
CachedImageRenderer.Init();
|
2017-07-14 00:23:18 +03:00
|
|
|
ZXing.Net.Mobile.Forms.Android.Platform.Init();
|
2016-06-18 09:45:46 +03:00
|
|
|
CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity);
|
2017-06-01 21:49:48 +03:00
|
|
|
|
|
|
|
//var container = new UnityContainer();
|
|
|
|
var container = new Container();
|
|
|
|
|
|
|
|
// Android Stuff
|
|
|
|
container.RegisterSingleton(application.ApplicationContext);
|
|
|
|
container.RegisterSingleton<Application>(application);
|
|
|
|
|
|
|
|
// Services
|
|
|
|
container.RegisterSingleton<IDatabaseService, DatabaseService>();
|
|
|
|
container.RegisterSingleton<ISqlService, SqlService>();
|
2017-06-27 22:00:21 +03:00
|
|
|
container.RegisterSingleton<ISecureStorageService, AndroidKeyStoreStorageService>();
|
2017-06-01 21:49:48 +03:00
|
|
|
container.RegisterSingleton<ICryptoService, CryptoService>();
|
|
|
|
container.RegisterSingleton<IKeyDerivationService, BouncyCastleKeyDerivationService>();
|
|
|
|
container.RegisterSingleton<IAuthService, AuthService>();
|
|
|
|
container.RegisterSingleton<IFolderService, FolderService>();
|
2017-11-25 07:15:25 +03:00
|
|
|
container.RegisterSingleton<ICollectionService, CollectionService>();
|
2017-10-19 03:55:33 +03:00
|
|
|
container.RegisterSingleton<ICipherService, CipherService>();
|
2017-06-01 21:49:48 +03:00
|
|
|
container.RegisterSingleton<ISyncService, SyncService>();
|
2017-07-13 06:09:44 +03:00
|
|
|
container.RegisterSingleton<IDeviceActionService, DeviceActionService>();
|
2017-06-01 21:49:48 +03:00
|
|
|
container.RegisterSingleton<IAppIdService, AppIdService>();
|
|
|
|
container.RegisterSingleton<IPasswordGenerationService, PasswordGenerationService>();
|
|
|
|
container.RegisterSingleton<IReflectionService, ReflectionService>();
|
|
|
|
container.RegisterSingleton<ILockService, LockService>();
|
|
|
|
container.RegisterSingleton<IAppInfoService, AppInfoService>();
|
|
|
|
container.RegisterSingleton<IGoogleAnalyticsService, GoogleAnalyticsService>();
|
|
|
|
container.RegisterSingleton<IDeviceInfoService, DeviceInfoService>();
|
|
|
|
container.RegisterSingleton<ILocalizeService, LocalizeService>();
|
|
|
|
container.RegisterSingleton<ILogService, LogService>();
|
|
|
|
container.RegisterSingleton<IHttpService, HttpService>();
|
|
|
|
container.RegisterSingleton<ITokenService, TokenService>();
|
|
|
|
container.RegisterSingleton<ISettingsService, SettingsService>();
|
|
|
|
container.RegisterSingleton<IMemoryService, MemoryService>();
|
|
|
|
container.RegisterSingleton<IAppSettingsService, AppSettingsService>();
|
|
|
|
|
|
|
|
// Repositories
|
|
|
|
container.RegisterSingleton<IFolderRepository, FolderRepository>();
|
|
|
|
container.RegisterSingleton<IFolderApiRepository, FolderApiRepository>();
|
2017-10-19 03:55:33 +03:00
|
|
|
container.RegisterSingleton<ICipherRepository, CipherRepository>();
|
2017-07-12 23:23:24 +03:00
|
|
|
container.RegisterSingleton<IAttachmentRepository, AttachmentRepository>();
|
2017-06-01 21:49:48 +03:00
|
|
|
container.RegisterSingleton<IConnectApiRepository, ConnectApiRepository>();
|
|
|
|
container.RegisterSingleton<IDeviceApiRepository, DeviceApiRepository>();
|
|
|
|
container.RegisterSingleton<IAccountsApiRepository, AccountsApiRepository>();
|
|
|
|
container.RegisterSingleton<ICipherApiRepository, CipherApiRepository>();
|
|
|
|
container.RegisterSingleton<ISettingsRepository, SettingsRepository>();
|
|
|
|
container.RegisterSingleton<ISettingsApiRepository, SettingsApiRepository>();
|
2017-06-29 18:22:06 +03:00
|
|
|
container.RegisterSingleton<ITwoFactorApiRepository, TwoFactorApiRepository>();
|
2017-09-20 20:17:05 +03:00
|
|
|
container.RegisterSingleton<ISyncApiRepository, SyncApiRepository>();
|
2017-11-25 00:11:40 +03:00
|
|
|
container.RegisterSingleton<ICollectionRepository, CollectionRepository>();
|
|
|
|
container.RegisterSingleton<ICipherCollectionRepository, CipherCollectionRepository>();
|
2017-06-01 21:49:48 +03:00
|
|
|
|
|
|
|
// Other
|
|
|
|
container.RegisterSingleton(CrossSettings.Current);
|
|
|
|
container.RegisterSingleton(CrossConnectivity.Current);
|
|
|
|
container.RegisterSingleton(CrossFingerprint.Current);
|
|
|
|
|
|
|
|
// Push
|
2017-12-22 06:14:56 +03:00
|
|
|
container.RegisterSingleton<IPushNotificationListener, PushNotificationListener>();
|
|
|
|
container.RegisterSingleton<IPushNotificationService, AndroidPushNotificationService>();
|
2017-06-01 21:49:48 +03:00
|
|
|
|
|
|
|
container.Verify();
|
|
|
|
Resolver.SetResolver(new SimpleInjectorResolver(container));
|
2016-06-18 09:45:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|