Ejemplo n.º 1
0
        protected async override void OnStart()
        {
            System.Diagnostics.Debug.WriteLine("XF App: OnStart");
            await ClearCacheIfNeededAsync();

            Prime();
            if (string.IsNullOrWhiteSpace(Options.Uri))
            {
                var updated = await AppHelpers.PerformUpdateTasksAsync(_syncService, _deviceActionService,
                                                                       _stateService);

                if (!updated)
                {
                    SyncIfNeeded();
                }
            }
            if (Device.RuntimePlatform == Device.Android)
            {
                await _vaultTimeoutService.CheckVaultTimeoutAsync();

                // Reset delay on every start
                _vaultTimeoutService.DelayLockAndLogoutMs = null;
            }
            _messagingService.Send("startEventTimer");
        }
Ejemplo n.º 2
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            if (!await AppHelpers.IsVaultTimeoutImmediateAsync())
            {
                await _vaultTimeoutService.CheckVaultTimeoutAsync();
            }
            if (await _vaultTimeoutService.IsLockedAsync())
            {
                return;
            }
            await LoadOnAppearedAsync(_scrollView, true, async() =>
            {
                var success = await _vm.LoadAsync(_appOptions);
                if (!success)
                {
                    await Navigation.PopModalAsync();
                    return;
                }
                AdjustToolbar();
                await ShowAlertsAsync();
                if (!_vm.EditMode && string.IsNullOrWhiteSpace(_vm.Cipher?.Name))
                {
                    RequestFocus(_nameEntry);
                }
                _scrollView.Scrolled += (sender, args) => _vm.HandleScroll();
            });

            // Hide password reprompt option if using key connector
            _passwordPrompt.IsVisible = !await _keyConnectorService.GetUsesKeyConnector();
        }
Ejemplo n.º 3
0
        protected async override void OnAppearing()
        {
            base.OnAppearing();
            if (_syncService.SyncInProgress)
            {
                IsBusy = true;
            }
            if (!await AppHelpers.IsVaultTimeoutImmediateAsync())
            {
                await _vaultTimeoutService.CheckVaultTimeoutAsync();
            }
            if (await _vaultTimeoutService.IsLockedAsync())
            {
                return;
            }

            _accountAvatar?.OnAppearing();
            _vm.AvatarImageSource = await GetAvatarImageSourceAsync();

            _broadcasterService.Subscribe(nameof(AutofillCiphersPage), async(message) =>
            {
                try
                {
                    if (message.Command == "syncStarted")
                    {
                        Device.BeginInvokeOnMainThread(() => IsBusy = true);
                    }
                    else if (message.Command == "syncCompleted")
                    {
                        await Task.Delay(500);
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            IsBusy = false;
                            if (_vm.LoadedOnce)
                            {
                                var task = _vm.LoadAsync();
                            }
                        });
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.LogEvenIfCantBeResolved(ex);
                }
            });

            await LoadOnAppearedAsync(_mainLayout, false, async() =>
            {
                try
                {
                    await _vm.LoadAsync();
                }
                catch (Exception e) when(e.Message.Contains("No key."))
                {
                    await Task.Delay(1000);
                    await _vm.LoadAsync();
                }
            }, _mainContent);
        }
Ejemplo n.º 4
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            try
            {
                if (!await AppHelpers.IsVaultTimeoutImmediateAsync())
                {
                    await _vaultTimeoutService.CheckVaultTimeoutAsync();
                }
                if (await _vaultTimeoutService.IsLockedAsync())
                {
                    return;
                }
                await _vm.InitAsync();

                _broadcasterService.Subscribe(nameof(SendAddEditPage), message =>
                {
                    if (message.Command == "selectFileResult")
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            var data     = message.Data as Tuple <byte[], string>;
                            _vm.FileData = data.Item1;
                            _vm.FileName = data.Item2;
                        });
                    }
                });

                await LoadOnAppearedAsync(_scrollView, true, async() =>
                {
                    var success = await _vm.LoadAsync();
                    if (!success)
                    {
                        await CloseAsync();
                        return;
                    }
                    await HandleCreateRequest();
                    if (!_vm.EditMode && string.IsNullOrWhiteSpace(_vm.Send?.Name))
                    {
                        RequestFocus(_nameEntry);
                    }
                    AdjustToolbar();
                });
            }
            catch (Exception ex)
            {
#if !FDROID
                Crashes.TrackError(ex);
#endif
                await CloseAsync();
            }
        }
Ejemplo n.º 5
0
        public async override void OnFillRequest(FillRequest request, CancellationSignal cancellationSignal,
                                                 FillCallback callback)
        {
            var structure = request.FillContexts?.LastOrDefault()?.Structure;

            if (structure == null)
            {
                return;
            }

            var parser = new Parser(structure, ApplicationContext);

            parser.Parse();

            if (_storageService == null)
            {
                _storageService = ServiceContainer.Resolve <IStorageService>("storageService");
            }

            var shouldAutofill = await parser.ShouldAutofillAsync(_storageService);

            if (!shouldAutofill)
            {
                return;
            }

            var inlineAutofillEnabled = await _storageService.GetAsync <bool?>(Constants.InlineAutofillEnabledKey) ?? true;

            if (_vaultTimeoutService == null)
            {
                _vaultTimeoutService = ServiceContainer.Resolve <IVaultTimeoutService>("vaultTimeoutService");
            }

            List <FilledItem> items = null;
            await _vaultTimeoutService.CheckVaultTimeoutAsync();

            var locked = await _vaultTimeoutService.IsLockedAsync();

            if (!locked)
            {
                if (_cipherService == null)
                {
                    _cipherService = ServiceContainer.Resolve <ICipherService>("cipherService");
                }
                items = await AutofillHelpers.GetFillItemsAsync(parser, _cipherService);
            }

            // build response
            var response = AutofillHelpers.BuildFillResponse(parser, items, locked, inlineAutofillEnabled, request);

            callback.OnSuccess(response);
        }
Ejemplo n.º 6
0
        private async void ResumedAsync()
        {
            await _vaultTimeoutService.CheckVaultTimeoutAsync();

            _messagingService.Send("startEventTimer");
            await ClearCacheIfNeededAsync();

            Prime();
            SyncIfNeeded();
            if (Current.MainPage is NavigationPage navPage && navPage.CurrentPage is LockPage lockPage)
            {
                await lockPage.PromptBiometricAfterResumeAsync();
            }
        }
Ejemplo n.º 7
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            try
            {
                if (!await AppHelpers.IsVaultTimeoutImmediateAsync())
                {
                    await _vaultTimeoutService.CheckVaultTimeoutAsync();
                }
                if (await _vaultTimeoutService.IsLockedAsync())
                {
                    return;
                }
                await _vm.InitAsync();

                if (!await _vm.LoadAsync())
                {
                    await CloseAsync();

                    return;
                }

                _accountAvatar?.OnAppearing();
                await Device.InvokeOnMainThreadAsync(async() => _vm.AvatarImageSource = await GetAvatarImageSourceAsync());

                await HandleCreateRequest();

                if (string.IsNullOrWhiteSpace(_vm.Send?.Name))
                {
                    RequestFocus(_nameEntry);
                }
                AdjustToolbar();
            }
            catch (Exception ex)
            {
                _logger.Value.Exception(ex);
                await CloseAsync();
            }
        }
Ejemplo n.º 8
0
        private void VaultTimeoutTimer(int vaultTimeoutMinutes)
        {
            if (_lockBackgroundTaskId > 0)
            {
                UIApplication.SharedApplication.EndBackgroundTask(_lockBackgroundTaskId);
                _lockBackgroundTaskId = 0;
            }
            _lockBackgroundTaskId = UIApplication.SharedApplication.BeginBackgroundTask(() =>
            {
                UIApplication.SharedApplication.EndBackgroundTask(_lockBackgroundTaskId);
                _lockBackgroundTaskId = 0;
            });
            var vaultTimeoutMs = vaultTimeoutMinutes * 60000;

            _vaultTimeoutTimer?.Invalidate();
            _vaultTimeoutTimer?.Dispose();
            _vaultTimeoutTimer = null;
            var vaultTimeoutMsSpan = TimeSpan.FromMilliseconds(vaultTimeoutMs + 10);

            Device.BeginInvokeOnMainThread(() =>
            {
                _vaultTimeoutTimer = NSTimer.CreateScheduledTimer(vaultTimeoutMsSpan, timer =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        _vaultTimeoutService.CheckVaultTimeoutAsync();
                        _vaultTimeoutTimer?.Invalidate();
                        _vaultTimeoutTimer?.Dispose();
                        _vaultTimeoutTimer = null;
                        if (_lockBackgroundTaskId > 0)
                        {
                            UIApplication.SharedApplication.EndBackgroundTask(_lockBackgroundTaskId);
                            _lockBackgroundTaskId = 0;
                        }
                    });
                });
            });
        }
Ejemplo n.º 9
0
 protected async override void OnAppearing()
 {
     base.OnAppearing();
     if (!await AppHelpers.IsVaultTimeoutImmediateAsync())
     {
         await _vaultTimeoutService.CheckVaultTimeoutAsync();
     }
     if (await _vaultTimeoutService.IsLockedAsync())
     {
         return;
     }
     await LoadOnAppearedAsync(_mainLayout, false, async() =>
     {
         try
         {
             await _vm.LoadAsync();
         }
         catch (Exception e) when(e.Message.Contains("No key."))
         {
             await Task.Delay(1000);
             await _vm.LoadAsync();
         }
     }, _mainContent);
 }
Ejemplo n.º 10
0
        public async override void OnFillRequest(FillRequest request, CancellationSignal cancellationSignal,
                                                 FillCallback callback)
        {
            try
            {
                var structure = request.FillContexts?.LastOrDefault()?.Structure;
                if (structure == null)
                {
                    return;
                }

                var parser = new Parser(structure, ApplicationContext);
                parser.Parse();

                if (_storageService == null)
                {
                    _storageService = ServiceContainer.Resolve <IStorageService>("storageService");
                }

                var shouldAutofill = await parser.ShouldAutofillAsync(_storageService);

                if (!shouldAutofill)
                {
                    return;
                }

                var inlineAutofillEnabled = await _storageService.GetAsync <bool?>(Constants.InlineAutofillEnabledKey) ?? true;

                if (_vaultTimeoutService == null)
                {
                    _vaultTimeoutService = ServiceContainer.Resolve <IVaultTimeoutService>("vaultTimeoutService");
                }

                List <FilledItem> items = null;
                await _vaultTimeoutService.CheckVaultTimeoutAsync();

                var locked = await _vaultTimeoutService.IsLockedAsync();

                if (!locked)
                {
                    if (_cipherService == null)
                    {
                        _cipherService = ServiceContainer.Resolve <ICipherService>("cipherService");
                    }
                    items = await AutofillHelpers.GetFillItemsAsync(parser, _cipherService);
                }

                // build response
                var response          = AutofillHelpers.CreateFillResponse(parser, items, locked, inlineAutofillEnabled, request);
                var disableSavePrompt = await _storageService.GetAsync <bool?>(Constants.AutofillDisableSavePromptKey);

                if (!disableSavePrompt.GetValueOrDefault())
                {
                    AutofillHelpers.AddSaveInfo(parser, request, response, parser.FieldCollection);
                }
                callback.OnSuccess(response.Build());
            }
            catch (Exception e)
            {
#if !FDROID
                Crashes.TrackError(e);
#endif
            }
        }