コード例 #1
0
ファイル: AppDelegate.cs プロジェクト: tangyiyong/mobile
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Forms.Init();
            InitApp();

            _deviceActionService = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");
            _messagingService    = ServiceContainer.Resolve <IMessagingService>("messagingService");
            _broadcasterService  = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService");
            _storageService      = ServiceContainer.Resolve <IStorageService>("storageService");
            _vaultTimeoutService = ServiceContainer.Resolve <IVaultTimeoutService>("vaultTimeoutService");
            _eventService        = ServiceContainer.Resolve <IEventService>("eventService");

            LoadApplication(new App.App(null));
            iOSCoreHelpers.AppearanceAdjustments(_deviceActionService);
            ZXing.Net.Mobile.Forms.iOS.Platform.Init();

            _broadcasterService.Subscribe(nameof(AppDelegate), async(message) =>
            {
                if (message.Command == "startEventTimer")
                {
                    StartEventTimer();
                }
                else if (message.Command == "stopEventTimer")
                {
                    var task = StopEventTimerAsync();
                }
                else if (message.Command == "updatedTheme")
                {
                    // ThemeManager.SetThemeStyle(message.Data as string);
                }
                else if (message.Command == "copiedToClipboard")
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        var task = ClearClipboardTimerAsync(message.Data as Tuple <string, int?, bool>);
                    });
                }
                else if (message.Command == "listenYubiKeyOTP")
                {
                    iOSCoreHelpers.ListenYubiKey((bool)message.Data, _deviceActionService, _nfcSession, _nfcDelegate);
                }
                else if (message.Command == "unlocked")
                {
                    var needsAutofillReplacement = await _storageService.GetAsync <bool?>(
                        Core.Constants.AutofillNeedsIdentityReplacementKey);
                    if (needsAutofillReplacement.GetValueOrDefault())
                    {
                        await ASHelpers.ReplaceAllIdentities();
                    }
                }
                else if (message.Command == "showAppExtension")
                {
                    Device.BeginInvokeOnMainThread(() => ShowAppExtension((ExtensionPageViewModel)message.Data));
                }
                else if (message.Command == "showStatusBar")
                {
                    Device.BeginInvokeOnMainThread(() =>
                                                   UIApplication.SharedApplication.SetStatusBarHidden(!(bool)message.Data, false));
                }
                else if (message.Command == "syncCompleted")
                {
                    if (message.Data is Dictionary <string, object> data && data.ContainsKey("successfully"))
                    {
                        var success = data["successfully"] as bool?;
                        if (success.GetValueOrDefault() && _deviceActionService.SystemMajorVersion() >= 12)
                        {
                            await ASHelpers.ReplaceAllIdentities();
                        }
                    }
                }
                else if (message.Command == "addedCipher" || message.Command == "editedCipher" ||
                         message.Command == "restoredCipher")
                {
                    if (_deviceActionService.SystemMajorVersion() >= 12)
                    {
                        if (await ASHelpers.IdentitiesCanIncremental())
                        {
                            var cipherId = message.Data as string;
                            if (message.Command == "addedCipher" && !string.IsNullOrWhiteSpace(cipherId))
                            {
                                var identity = await ASHelpers.GetCipherIdentityAsync(cipherId);
                                if (identity == null)
                                {
                                    return;
                                }
                                await ASCredentialIdentityStore.SharedStore?.SaveCredentialIdentitiesAsync(
                                    new ASPasswordCredentialIdentity[] { identity });
                                return;
                            }
                        }
                        await ASHelpers.ReplaceAllIdentities();
                    }
                }
                else if (message.Command == "deletedCipher" || message.Command == "softDeletedCipher")
                {
                    if (_deviceActionService.SystemMajorVersion() >= 12)
                    {
                        if (await ASHelpers.IdentitiesCanIncremental())
                        {
                            var identity = ASHelpers.ToCredentialIdentity(
                                message.Data as Bit.Core.Models.View.CipherView);
                            if (identity == null)
                            {
                                return;
                            }
                            await ASCredentialIdentityStore.SharedStore?.RemoveCredentialIdentitiesAsync(
                                new ASPasswordCredentialIdentity[] { identity });
                            return;
                        }
                        await ASHelpers.ReplaceAllIdentities();
                    }
                }
                else if (message.Command == "loggedOut")
                {
                    if (_deviceActionService.SystemMajorVersion() >= 12)
                    {
                        await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync();
                    }
                }
                else if ((message.Command == "softDeletedCipher" || message.Command == "restoredCipher") &&
                         _deviceActionService.SystemMajorVersion() >= 12)
                {
                    await ASHelpers.ReplaceAllIdentities();
                }
                else if (message.Command == "vaultTimeoutActionChanged")
                {
                    var timeoutAction = await _storageService.GetAsync <string>(Constants.VaultTimeoutActionKey);
                    if (timeoutAction == "logOut")
                    {
                        await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync();
                    }
                    else
                    {
                        await ASHelpers.ReplaceAllIdentities();
                    }
                }
            });

            return(base.FinishedLaunching(app, options));
        }
コード例 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            var eventUploadIntent = new Intent(this, typeof(EventUploadReceiver));

            _eventUploadPendingIntent = PendingIntent.GetBroadcast(this, 0, eventUploadIntent,
                                                                   PendingIntentFlags.UpdateCurrent);
            var alarmIntent = new Intent(this, typeof(LockAlarmReceiver));

            _vaultTimeoutAlarmPendingIntent = PendingIntent.GetBroadcast(this, 0, alarmIntent,
                                                                         PendingIntentFlags.UpdateCurrent);
            var clearClipboardIntent = new Intent(this, typeof(ClearClipboardAlarmReceiver));

            _clearClipboardPendingIntent = PendingIntent.GetBroadcast(this, 0, clearClipboardIntent,
                                                                      PendingIntentFlags.UpdateCurrent);

            var policy = new StrictMode.ThreadPolicy.Builder().PermitAll().Build();

            StrictMode.SetThreadPolicy(policy);

            _deviceActionService = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");
            _messagingService    = ServiceContainer.Resolve <IMessagingService>("messagingService");
            _broadcasterService  = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService");
            _userService         = ServiceContainer.Resolve <IUserService>("userService");
            _appIdService        = ServiceContainer.Resolve <IAppIdService>("appIdService");
            _storageService      = ServiceContainer.Resolve <IStorageService>("storageService");
            _eventService        = ServiceContainer.Resolve <IEventService>("eventService");

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            UpdateTheme(ThemeManager.GetTheme(true));
            base.OnCreate(savedInstanceState);
            if (!CoreHelpers.InDebugMode())
            {
                Window.AddFlags(Android.Views.WindowManagerFlags.Secure);
            }

#if !FDROID
            var appCenterHelper = new AppCenterHelper(_appIdService, _userService);
            var appCenterTask   = appCenterHelper.InitAsync();
#endif

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            Xamarin.Forms.Forms.Init(this, savedInstanceState);
            _appOptions = GetOptions();
            LoadApplication(new App.App(_appOptions));

            _broadcasterService.Subscribe(_activityKey, (message) =>
            {
                if (message.Command == "scheduleVaultTimeoutTimer")
                {
                    var alarmManager        = GetSystemService(AlarmService) as AlarmManager;
                    var vaultTimeoutMinutes = (int)message.Data;
                    var vaultTimeoutMs      = vaultTimeoutMinutes * 60000;
                    var triggerMs           = Java.Lang.JavaSystem.CurrentTimeMillis() + vaultTimeoutMs + 10;
                    alarmManager.Set(AlarmType.RtcWakeup, triggerMs, _vaultTimeoutAlarmPendingIntent);
                }
                else if (message.Command == "cancelVaultTimeoutTimer")
                {
                    var alarmManager = GetSystemService(AlarmService) as AlarmManager;
                    alarmManager.Cancel(_vaultTimeoutAlarmPendingIntent);
                }
                else if (message.Command == "startEventTimer")
                {
                    StartEventAlarm();
                }
                else if (message.Command == "stopEventTimer")
                {
                    var task = StopEventAlarmAsync();
                }
                else if (message.Command == "finishMainActivity")
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(() => Finish());
                }
                else if (message.Command == "listenYubiKeyOTP")
                {
                    ListenYubiKey((bool)message.Data);
                }
                else if (message.Command == "updatedTheme")
                {
                    RestartApp();
                }
                else if (message.Command == "exit")
                {
                    ExitApp();
                }
                else if (message.Command == "copiedToClipboard")
                {
                    var task = ClearClipboardAlarmAsync(message.Data as Tuple <string, int?, bool>);
                }
            });
        }
コード例 #3
0
ファイル: App.xaml.cs プロジェクト: xamarinhub/mobile
        public App(AppOptions appOptions)
        {
            _appOptions                = appOptions ?? new AppOptions();
            _userService               = ServiceContainer.Resolve <IUserService>("userService");
            _broadcasterService        = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService");
            _messagingService          = ServiceContainer.Resolve <IMessagingService>("messagingService");
            _stateService              = ServiceContainer.Resolve <IStateService>("stateService");
            _lockService               = ServiceContainer.Resolve <ILockService>("lockService");
            _syncService               = ServiceContainer.Resolve <ISyncService>("syncService");
            _tokenService              = ServiceContainer.Resolve <ITokenService>("tokenService");
            _cryptoService             = ServiceContainer.Resolve <ICryptoService>("cryptoService");
            _cipherService             = ServiceContainer.Resolve <ICipherService>("cipherService");
            _folderService             = ServiceContainer.Resolve <IFolderService>("folderService");
            _settingsService           = ServiceContainer.Resolve <ISettingsService>("settingsService");
            _collectionService         = ServiceContainer.Resolve <ICollectionService>("collectionService");
            _searchService             = ServiceContainer.Resolve <ISearchService>("searchService");
            _authService               = ServiceContainer.Resolve <IAuthService>("authService");
            _platformUtilsService      = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService");
            _storageService            = ServiceContainer.Resolve <IStorageService>("storageService");
            _secureStorageService      = ServiceContainer.Resolve <IStorageService>("secureStorageService");
            _passwordGenerationService = ServiceContainer.Resolve <IPasswordGenerationService>(
                "passwordGenerationService");
            _i18nService         = ServiceContainer.Resolve <II18nService>("i18nService") as MobileI18nService;
            _deviceActionService = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");

            Bootstrap();
            _broadcasterService.Subscribe(nameof(App), async(message) =>
            {
                if (message.Command == "showDialog")
                {
                    var details     = message.Data as DialogDetails;
                    var confirmed   = true;
                    var confirmText = string.IsNullOrWhiteSpace(details.ConfirmText) ?
                                      AppResources.Ok : details.ConfirmText;
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        if (!string.IsNullOrWhiteSpace(details.CancelText))
                        {
                            confirmed = await Current.MainPage.DisplayAlert(details.Title, details.Text, confirmText,
                                                                            details.CancelText);
                        }
                        else
                        {
                            await Current.MainPage.DisplayAlert(details.Title, details.Text, confirmText);
                        }
                        _messagingService.Send("showDialogResolve", new Tuple <int, bool>(details.DialogId, confirmed));
                    });
                }
                else if (message.Command == "locked")
                {
                    await _stateService.PurgeAsync();
                    var lockPage = new LockPage(_appOptions, !(message.Data as bool?).GetValueOrDefault());
                    Device.BeginInvokeOnMainThread(() => Current.MainPage = new NavigationPage(lockPage));
                }
                else if (message.Command == "lockVault")
                {
                    await _lockService.LockAsync(true);
                }
                else if (message.Command == "logout")
                {
                    if (Migration.MigrationHelpers.Migrating)
                    {
                        return;
                    }
                    Device.BeginInvokeOnMainThread(async() => await LogOutAsync(false));
                }
                else if (message.Command == "loggedOut")
                {
                    // Clean up old migrated key if they ever log out.
                    await _secureStorageService.RemoveAsync("oldKey");
                }
                else if (message.Command == "resumed")
                {
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        ResumedAsync();
                    }
                }
                else if (message.Command == "migrated")
                {
                    await Task.Delay(1000);
                    await SetMainPageAsync();
                }
                else if (message.Command == "popAllAndGoToTabGenerator" ||
                         message.Command == "popAllAndGoToTabMyVault")
                {
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        if (Current.MainPage is TabsPage tabsPage)
                        {
                            while (tabsPage.Navigation.ModalStack.Count > 0)
                            {
                                await tabsPage.Navigation.PopModalAsync(false);
                            }
                            if (message.Command == "popAllAndGoToTabMyVault")
                            {
                                _appOptions.MyVaultTile = false;
                                tabsPage.ResetToVaultPage();
                            }
                            else
                            {
                                _appOptions.GeneratorTile = false;
                                tabsPage.ResetToGeneratorPage();
                            }
                        }
                    });
                }
            });
        }
コード例 #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            var eventUploadIntent = new Intent(this, typeof(EventUploadReceiver));

            _eventUploadPendingIntent = PendingIntent.GetBroadcast(this, 0, eventUploadIntent,
                                                                   PendingIntentFlags.UpdateCurrent);
            var alarmIntent = new Intent(this, typeof(LockAlarmReceiver));

            _vaultTimeoutAlarmPendingIntent = PendingIntent.GetBroadcast(this, 0, alarmIntent,
                                                                         PendingIntentFlags.UpdateCurrent);
            var clearClipboardIntent = new Intent(this, typeof(ClearClipboardAlarmReceiver));

            _clearClipboardPendingIntent = PendingIntent.GetBroadcast(this, 0, clearClipboardIntent,
                                                                      PendingIntentFlags.UpdateCurrent);

            var policy = new StrictMode.ThreadPolicy.Builder().PermitAll().Build();

            StrictMode.SetThreadPolicy(policy);

            _deviceActionService = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");
            _messagingService    = ServiceContainer.Resolve <IMessagingService>("messagingService");
            _broadcasterService  = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService");
            _userService         = ServiceContainer.Resolve <IUserService>("userService");
            _appIdService        = ServiceContainer.Resolve <IAppIdService>("appIdService");
            _storageService      = ServiceContainer.Resolve <IStorageService>("storageService");
            _eventService        = ServiceContainer.Resolve <IEventService>("eventService");

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            UpdateTheme(ThemeManager.GetTheme(true));
            base.OnCreate(savedInstanceState);
            if (!CoreHelpers.InDebugMode())
            {
                Window.AddFlags(Android.Views.WindowManagerFlags.Secure);
            }

#if !FDROID
            var appCenterHelper = new AppCenterHelper(_appIdService, _userService);
            var appCenterTask   = appCenterHelper.InitAsync();
#endif

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            Xamarin.Forms.Forms.Init(this, savedInstanceState);
            _appOptions = GetOptions();
            LoadApplication(new App.App(_appOptions));

            _broadcasterService.Subscribe(_activityKey, (message) =>
            {
                if (message.Command == "scheduleVaultTimeoutTimer")
                {
                    var alarmManager        = GetSystemService(AlarmService) as AlarmManager;
                    var vaultTimeoutMinutes = (int)message.Data;
                    var vaultTimeoutMs      = vaultTimeoutMinutes * 60000;
                    var triggerMs           = Java.Lang.JavaSystem.CurrentTimeMillis() + vaultTimeoutMs + 10;
                    alarmManager.Set(AlarmType.RtcWakeup, triggerMs, _vaultTimeoutAlarmPendingIntent);
                }
                else if (message.Command == "cancelVaultTimeoutTimer")
                {
                    var alarmManager = GetSystemService(AlarmService) as AlarmManager;
                    alarmManager.Cancel(_vaultTimeoutAlarmPendingIntent);
                }
                else if (message.Command == "startEventTimer")
                {
                    StartEventAlarm();
                }
                else if (message.Command == "stopEventTimer")
                {
                    var task = StopEventAlarmAsync();
                }
                else if (message.Command == "finishMainActivity")
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(() => Finish());
                }
                else if (message.Command == "listenFido2")                  // First time when FIDO2 two-factor is enable
                {
                    ListenFido2((Dictionary <string, object>)message.Data); // When is the first time token (JSON Data in string) received on two-factor is still valid for short time
                }
                else if (message.Command == "listenFido2TryAgain")          // When FIDO2 fails and the user want to try again
                {
                    ListenFido2();                                          // Old token is only valid once, so we don't send again the token because a new one needs to be requested
                }
                else if (message.Command == "listenYubiKeyOTP")
                {
                    ListenYubiKey((bool)message.Data);
                }
                else if (message.Command == "updatedTheme")
                {
                    RestartApp();
                }
                else if (message.Command == "exit")
                {
                    ExitApp();
                }
                else if (message.Command == "copiedToClipboard")
                {
                    var task = ClearClipboardAlarmAsync(message.Data as Tuple <string, int?, bool>);
                }
            });

            Fido2Service.INSTANCE.start(this); // Start FIDO2 Service with this Activity, for the FIDO2 to send events (Sucess, Failure, Complete) for this activity
        }
コード例 #5
0
ファイル: App.xaml.cs プロジェクト: ebell451/mobile
        public App(AppOptions appOptions)
        {
            Options = appOptions ?? new AppOptions();
            if (Options.IosExtension)
            {
                Current = this;
                return;
            }
            _userService          = ServiceContainer.Resolve <IUserService>("userService");
            _broadcasterService   = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService");
            _messagingService     = ServiceContainer.Resolve <IMessagingService>("messagingService");
            _stateService         = ServiceContainer.Resolve <IStateService>("stateService");
            _vaultTimeoutService  = ServiceContainer.Resolve <IVaultTimeoutService>("vaultTimeoutService");
            _syncService          = ServiceContainer.Resolve <ISyncService>("syncService");
            _authService          = ServiceContainer.Resolve <IAuthService>("authService");
            _platformUtilsService = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService");
            _storageService       = ServiceContainer.Resolve <IStorageService>("storageService");
            _secureStorageService = ServiceContainer.Resolve <IStorageService>("secureStorageService");
            _deviceActionService  = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");

            Bootstrap();
            _broadcasterService.Subscribe(nameof(App), async(message) =>
            {
                if (message.Command == "showDialog")
                {
                    var details     = message.Data as DialogDetails;
                    var confirmed   = true;
                    var confirmText = string.IsNullOrWhiteSpace(details.ConfirmText) ?
                                      AppResources.Ok : details.ConfirmText;
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        if (!string.IsNullOrWhiteSpace(details.CancelText))
                        {
                            confirmed = await Current.MainPage.DisplayAlert(details.Title, details.Text, confirmText,
                                                                            details.CancelText);
                        }
                        else
                        {
                            await Current.MainPage.DisplayAlert(details.Title, details.Text, confirmText);
                        }
                        _messagingService.Send("showDialogResolve", new Tuple <int, bool>(details.DialogId, confirmed));
                    });
                }
                else if (message.Command == "locked")
                {
                    await LockedAsync(!(message.Data as bool?).GetValueOrDefault());
                }
                else if (message.Command == "lockVault")
                {
                    await _vaultTimeoutService.LockAsync(true);
                }
                else if (message.Command == "logout")
                {
                    Device.BeginInvokeOnMainThread(async() =>
                                                   await LogOutAsync((message.Data as bool?).GetValueOrDefault()));
                }
                else if (message.Command == "loggedOut")
                {
                    // Clean up old migrated key if they ever log out.
                    await _secureStorageService.RemoveAsync("oldKey");
                }
                else if (message.Command == "resumed")
                {
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        ResumedAsync();
                    }
                }
                else if (message.Command == "slept")
                {
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        await SleptAsync();
                    }
                }
                else if (message.Command == "migrated")
                {
                    await Task.Delay(1000);
                    await SetMainPageAsync();
                }
                else if (message.Command == "popAllAndGoToTabGenerator" ||
                         message.Command == "popAllAndGoToTabMyVault" ||
                         message.Command == "popAllAndGoToTabSend")
                {
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        if (Current.MainPage is TabsPage tabsPage)
                        {
                            while (tabsPage.Navigation.ModalStack.Count > 0)
                            {
                                await tabsPage.Navigation.PopModalAsync(false);
                            }
                            if (message.Command == "popAllAndGoToTabMyVault")
                            {
                                Options.MyVaultTile = false;
                                tabsPage.ResetToVaultPage();
                            }
                            else if (message.Command == "popAllAndGoToTabGenerator")
                            {
                                Options.GeneratorTile = false;
                                tabsPage.ResetToGeneratorPage();
                            }
                            else if (message.Command == "popAllAndGoToTabSend")
                            {
                                tabsPage.ResetToSendPage();
                            }
                        }
                    });
                }
            });
        }
コード例 #6
0
ファイル: MainActivity.cs プロジェクト: turlodales/mobile
        protected override void OnCreate(Bundle savedInstanceState)
        {
            var eventUploadIntent = new Intent(this, typeof(EventUploadReceiver));
            _eventUploadPendingIntent = PendingIntent.GetBroadcast(this, 0, eventUploadIntent,
                PendingIntentFlags.UpdateCurrent);

            var policy = new StrictMode.ThreadPolicy.Builder().PermitAll().Build();
            StrictMode.SetThreadPolicy(policy);

            _deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
            _messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
            _broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
            _stateService = ServiceContainer.Resolve<IStateService>("stateService");
            _appIdService = ServiceContainer.Resolve<IAppIdService>("appIdService");
            _eventService = ServiceContainer.Resolve<IEventService>("eventService");

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            // this needs to be called here before base.OnCreate(...)
            Intent?.Validate();

            base.OnCreate(savedInstanceState);

            _deviceActionService.SetScreenCaptureAllowedAsync().FireAndForget(_ =>
            {
                Window.AddFlags(Android.Views.WindowManagerFlags.Secure);
            });

            ServiceContainer.Resolve<ILogger>("logger").InitAsync();

            var toplayout = Window?.DecorView?.RootView;
            if (toplayout != null)
            {
                toplayout.FilterTouchesWhenObscured = true;
            }

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            Xamarin.Forms.Forms.Init(this, savedInstanceState);
            _appOptions = GetOptions();
            LoadApplication(new App.App(_appOptions));


            _broadcasterService.Subscribe(_activityKey, (message) =>
            {
                if (message.Command == "startEventTimer")
                {
                    StartEventAlarm();
                }
                else if (message.Command == "stopEventTimer")
                {
                    var task = StopEventAlarmAsync();
                }
                else if (message.Command == "finishMainActivity")
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(() => Finish());
                }
                else if (message.Command == "listenYubiKeyOTP")
                {
                    ListenYubiKey((bool)message.Data);
                }
                else if (message.Command == "updatedTheme")
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(() => AppearanceAdjustments());
                }
                else if (message.Command == "exit")
                {
                    ExitApp();
                }
            });
        }
コード例 #7
0
        public App(AppOptions appOptions)
        {
            _appOptions                = appOptions ?? new AppOptions();
            _userService               = ServiceContainer.Resolve <IUserService>("userService");
            _broadcasterService        = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService");
            _messagingService          = ServiceContainer.Resolve <IMessagingService>("messagingService");
            _stateService              = ServiceContainer.Resolve <IStateService>("stateService");
            _lockService               = ServiceContainer.Resolve <ILockService>("lockService");
            _syncService               = ServiceContainer.Resolve <ISyncService>("syncService");
            _tokenService              = ServiceContainer.Resolve <ITokenService>("tokenService");
            _cryptoService             = ServiceContainer.Resolve <ICryptoService>("cryptoService");
            _cipherService             = ServiceContainer.Resolve <ICipherService>("cipherService");
            _folderService             = ServiceContainer.Resolve <IFolderService>("folderService");
            _settingsService           = ServiceContainer.Resolve <ISettingsService>("settingsService");
            _collectionService         = ServiceContainer.Resolve <ICollectionService>("collectionService");
            _searchService             = ServiceContainer.Resolve <ISearchService>("searchService");
            _authService               = ServiceContainer.Resolve <IAuthService>("authService");
            _platformUtilsService      = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService");
            _storageService            = ServiceContainer.Resolve <IStorageService>("storageService");
            _passwordGenerationService = ServiceContainer.Resolve <IPasswordGenerationService>(
                "passwordGenerationService");
            _i18nService         = ServiceContainer.Resolve <II18nService>("i18nService") as MobileI18nService;
            _deviceActionService = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");

            InitializeComponent();
            SetCulture();
            ThemeManager.SetThemeStyle("light");
            MainPage = new HomePage();
            var mainPageTask = SetMainPageAsync();

            ServiceContainer.Resolve <MobilePlatformUtilsService>("platformUtilsService").Init();
            _broadcasterService.Subscribe(nameof(App), async(message) =>
            {
                if (message.Command == "showDialog")
                {
                    var details     = message.Data as DialogDetails;
                    var confirmed   = true;
                    var confirmText = string.IsNullOrWhiteSpace(details.ConfirmText) ?
                                      AppResources.Ok : details.ConfirmText;
                    if (!string.IsNullOrWhiteSpace(details.CancelText))
                    {
                        confirmed = await MainPage.DisplayAlert(details.Title, details.Text, confirmText,
                                                                details.CancelText);
                    }
                    else
                    {
                        await MainPage.DisplayAlert(details.Title, details.Text, confirmText);
                    }
                    _messagingService.Send("showDialogResolve", new Tuple <int, bool>(details.DialogId, confirmed));
                }
                else if (message.Command == "locked")
                {
                    await _stateService.PurgeAsync();
                    MainPage = new NavigationPage(new LockPage());
                }
                else if (message.Command == "lockVault")
                {
                    await _lockService.LockAsync(true);
                }
                else if (message.Command == "logout")
                {
                    await LogOutAsync(false);
                }
                else if (message.Command == "loggedOut")
                {
                    // TODO
                }
                else if (message.Command == "unlocked" || message.Command == "loggedIn")
                {
                    // TODO
                }
            });
        }
コード例 #8
0
ファイル: App.xaml.cs プロジェクト: RussellWaite/mobile
        public App(AppOptions appOptions)
        {
            Options = appOptions ?? new AppOptions();
            if (Options.IosExtension)
            {
                Current = this;
                return;
            }
            _broadcasterService   = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService");
            _messagingService     = ServiceContainer.Resolve <IMessagingService>("messagingService");
            _stateService         = ServiceContainer.Resolve <IStateService>("stateService");
            _vaultTimeoutService  = ServiceContainer.Resolve <IVaultTimeoutService>("vaultTimeoutService");
            _syncService          = ServiceContainer.Resolve <ISyncService>("syncService");
            _authService          = ServiceContainer.Resolve <IAuthService>("authService");
            _platformUtilsService = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService");
            _secureStorageService = ServiceContainer.Resolve <IStorageService>("secureStorageService");
            _deviceActionService  = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");

            Bootstrap();
            _broadcasterService.Subscribe(nameof(App), async(message) =>
            {
                if (message.Command == "showDialog")
                {
                    var details     = message.Data as DialogDetails;
                    var confirmed   = true;
                    var confirmText = string.IsNullOrWhiteSpace(details.ConfirmText) ?
                                      AppResources.Ok : details.ConfirmText;
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        if (!string.IsNullOrWhiteSpace(details.CancelText))
                        {
                            confirmed = await Current.MainPage.DisplayAlert(details.Title, details.Text, confirmText,
                                                                            details.CancelText);
                        }
                        else
                        {
                            await Current.MainPage.DisplayAlert(details.Title, details.Text, confirmText);
                        }
                        _messagingService.Send("showDialogResolve", new Tuple <int, bool>(details.DialogId, confirmed));
                    });
                }
                else if (message.Command == "locked")
                {
                    var extras        = message.Data as Tuple <string, bool>;
                    var userId        = extras?.Item1;
                    var userInitiated = extras?.Item2 ?? false;
                    Device.BeginInvokeOnMainThread(async() => await LockedAsync(userId, userInitiated));
                }
                else if (message.Command == "lockVault")
                {
                    await _vaultTimeoutService.LockAsync(true);
                }
                else if (message.Command == "logout")
                {
                    var extras        = message.Data as Tuple <string, bool, bool>;
                    var userId        = extras?.Item1;
                    var userInitiated = extras?.Item2 ?? true;
                    var expired       = extras?.Item3 ?? false;
                    Device.BeginInvokeOnMainThread(async() => await LogOutAsync(userId, userInitiated, expired));
                }
                else if (message.Command == "loggedOut")
                {
                    // Clean up old migrated key if they ever log out.
                    await _secureStorageService.RemoveAsync("oldKey");
                }
                else if (message.Command == "resumed")
                {
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        ResumedAsync().FireAndForget();
                    }
                }
                else if (message.Command == "slept")
                {
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        await SleptAsync();
                    }
                }
                else if (message.Command == "addAccount")
                {
                    await AddAccount();
                }
                else if (message.Command == "accountAdded")
                {
                    await UpdateThemeAsync();
                }
                else if (message.Command == "switchedAccount")
                {
                    await SwitchedAccountAsync();
                }
                else if (message.Command == "migrated")
                {
                    await Task.Delay(1000);
                    await SetMainPageAsync();
                }
                else if (message.Command == "popAllAndGoToTabGenerator" ||
                         message.Command == "popAllAndGoToTabMyVault" ||
                         message.Command == "popAllAndGoToTabSend" ||
                         message.Command == "popAllAndGoToAutofillCiphers")
                {
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        if (Current.MainPage is TabsPage tabsPage)
                        {
                            while (tabsPage.Navigation.ModalStack.Count > 0)
                            {
                                await tabsPage.Navigation.PopModalAsync(false);
                            }
                            if (message.Command == "popAllAndGoToAutofillCiphers")
                            {
                                Current.MainPage = new NavigationPage(new AutofillCiphersPage(Options));
                            }
                            else if (message.Command == "popAllAndGoToTabMyVault")
                            {
                                Options.MyVaultTile = false;
                                tabsPage.ResetToVaultPage();
                            }
                            else if (message.Command == "popAllAndGoToTabGenerator")
                            {
                                Options.GeneratorTile = false;
                                tabsPage.ResetToGeneratorPage();
                            }
                            else if (message.Command == "popAllAndGoToTabSend")
                            {
                                tabsPage.ResetToSendPage();
                            }
                        }
                    });
                }
                else if (message.Command == "convertAccountToKeyConnector")
                {
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        await Application.Current.MainPage.Navigation.PushModalAsync(
                            new NavigationPage(new RemoveMasterPasswordPage()));
                    });
                }
            });
        }
コード例 #9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            var eventUploadIntent = new Intent(this, typeof(EventUploadReceiver));

            _eventUploadPendingIntent = PendingIntent.GetBroadcast(this, 0, eventUploadIntent,
                                                                   PendingIntentFlags.UpdateCurrent);

            var policy = new StrictMode.ThreadPolicy.Builder().PermitAll().Build();

            StrictMode.SetThreadPolicy(policy);

            _deviceActionService = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");
            _messagingService    = ServiceContainer.Resolve <IMessagingService>("messagingService");
            _broadcasterService  = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService");
            _userService         = ServiceContainer.Resolve <IUserService>("userService");
            _appIdService        = ServiceContainer.Resolve <IAppIdService>("appIdService");
            _eventService        = ServiceContainer.Resolve <IEventService>("eventService");

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            // this needs to be called here before base.OnCreate(...)
            Intent?.Validate();

            base.OnCreate(savedInstanceState);
            if (!CoreHelpers.InDebugMode())
            {
                Window.AddFlags(Android.Views.WindowManagerFlags.Secure);
            }

#if !FDROID
            var appCenterHelper = new AppCenterHelper(_appIdService, _userService);
            var appCenterTask   = appCenterHelper.InitAsync();
#endif

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            Xamarin.Forms.Forms.Init(this, savedInstanceState);
            _appOptions = GetOptions();
            LoadApplication(new App.App(_appOptions));

            _broadcasterService.Subscribe(_activityKey, (message) =>
            {
                if (message.Command == "startEventTimer")
                {
                    StartEventAlarm();
                }
                else if (message.Command == "stopEventTimer")
                {
                    var task = StopEventAlarmAsync();
                }
                else if (message.Command == "finishMainActivity")
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(() => Finish());
                }
                else if (message.Command == "listenYubiKeyOTP")
                {
                    ListenYubiKey((bool)message.Data);
                }
                else if (message.Command == "updatedTheme")
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(() => AppearanceAdjustments());
                }
                else if (message.Command == "exit")
                {
                    ExitApp();
                }
            });
        }
コード例 #10
0
        public App(AppOptions appOptions)
        {
            Options = appOptions ?? new AppOptions();
            if (Options.IosExtension)
            {
                Current = this;
                return;
            }
            _broadcasterService   = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService");
            _messagingService     = ServiceContainer.Resolve <IMessagingService>("messagingService");
            _stateService         = ServiceContainer.Resolve <IStateService>("stateService");
            _vaultTimeoutService  = ServiceContainer.Resolve <IVaultTimeoutService>("vaultTimeoutService");
            _syncService          = ServiceContainer.Resolve <ISyncService>("syncService");
            _authService          = ServiceContainer.Resolve <IAuthService>("authService");
            _platformUtilsService = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService");
            _secureStorageService = ServiceContainer.Resolve <IStorageService>("secureStorageService");
            _deviceActionService  = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService");
            _accountsManager      = ServiceContainer.Resolve <IAccountsManager>("accountsManager");

            _accountsManager.Init(() => Options, this);

            Bootstrap();
            _broadcasterService.Subscribe(nameof(App), async(message) =>
            {
                try
                {
                    if (message.Command == "showDialog")
                    {
                        var details     = message.Data as DialogDetails;
                        var confirmed   = true;
                        var confirmText = string.IsNullOrWhiteSpace(details.ConfirmText) ?
                                          AppResources.Ok : details.ConfirmText;
                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            if (!string.IsNullOrWhiteSpace(details.CancelText))
                            {
                                confirmed = await Current.MainPage.DisplayAlert(details.Title, details.Text, confirmText,
                                                                                details.CancelText);
                            }
                            else
                            {
                                await Current.MainPage.DisplayAlert(details.Title, details.Text, confirmText);
                            }
                            _messagingService.Send("showDialogResolve", new Tuple <int, bool>(details.DialogId, confirmed));
                        });
                    }
                    else if (message.Command == "resumed")
                    {
                        if (Device.RuntimePlatform == Device.iOS)
                        {
                            ResumedAsync().FireAndForget();
                        }
                    }
                    else if (message.Command == "slept")
                    {
                        if (Device.RuntimePlatform == Device.iOS)
                        {
                            await SleptAsync();
                        }
                    }
                    else if (message.Command == "migrated")
                    {
                        await Task.Delay(1000);
                        await _accountsManager.NavigateOnAccountChangeAsync();
                    }
                    else if (message.Command == "popAllAndGoToTabGenerator" ||
                             message.Command == "popAllAndGoToTabMyVault" ||
                             message.Command == "popAllAndGoToTabSend" ||
                             message.Command == "popAllAndGoToAutofillCiphers")
                    {
                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            if (Current.MainPage is TabsPage tabsPage)
                            {
                                while (tabsPage.Navigation.ModalStack.Count > 0)
                                {
                                    await tabsPage.Navigation.PopModalAsync(false);
                                }
                                if (message.Command == "popAllAndGoToAutofillCiphers")
                                {
                                    Current.MainPage = new NavigationPage(new AutofillCiphersPage(Options));
                                }
                                else if (message.Command == "popAllAndGoToTabMyVault")
                                {
                                    Options.MyVaultTile = false;
                                    tabsPage.ResetToVaultPage();
                                }
                                else if (message.Command == "popAllAndGoToTabGenerator")
                                {
                                    Options.GeneratorTile = false;
                                    tabsPage.ResetToGeneratorPage();
                                }
                                else if (message.Command == "popAllAndGoToTabSend")
                                {
                                    tabsPage.ResetToSendPage();
                                }
                            }
                        });
                    }
                    else if (message.Command == "convertAccountToKeyConnector")
                    {
                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            await Application.Current.MainPage.Navigation.PushModalAsync(
                                new NavigationPage(new RemoveMasterPasswordPage()));
                        });
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.LogEvenIfCantBeResolved(ex);
                }
            });
        }