protected async override void OnAppearing() { base.OnAppearing(); _broadcasterService.Subscribe(nameof(TwoFactorPage), async(message) => { if (message.Command == "gotYubiKeyOTP") { if (_vm.YubikeyMethod) { _vm.Token = (string)message.Data; await _vm.SubmitAsync(); } } else if (message.Command == "resumeYubiKey") { if (_vm.YubikeyMethod) { _messagingService.Send("listenYubiKeyOTP", true); } } }); await LoadOnAppearedAsync(_scrollView, true, () => { _vm.Init(); if (_vm.TotpMethod) { RequestFocus(_totpEntry); } return(Task.FromResult(0)); }); }
public void Init(Func <AppOptions> getOptionsFunc, IAccountsManagerHost accountsManagerHost) { _getOptionsFunc = getOptionsFunc; _accountsManagerHost = accountsManagerHost; _broadcasterService.Subscribe(nameof(AccountsManager), OnMessage); }
protected override async void OnAppearing() { base.OnAppearing(); _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 Navigation.PopModalAsync(); return; } if (!_vm.EditMode && string.IsNullOrWhiteSpace(_vm.Send?.Name)) { RequestFocus(_nameEntry); } }); }
public void Init() { _broadcasterService.Subscribe(nameof(MobilePlatformUtilsService), (message) => { if (message.Command == "showDialogResolve") { var details = message.Data as Tuple <int, bool>; var dialogId = details.Item1; var confirmed = details.Item2; if (_showDialogResolves.ContainsKey(dialogId)) { var resolveObj = _showDialogResolves[dialogId].Item1; resolveObj.TrySetResult(confirmed); } // Clean up old tasks var deleteIds = new HashSet <int>(); foreach (var item in _showDialogResolves) { var age = DateTime.UtcNow - item.Value.Item2; if (age.TotalMilliseconds > DialogPromiseExpiration) { deleteIds.Add(item.Key); } } foreach (var id in deleteIds) { _showDialogResolves.Remove(id); } } }); }
protected override async void OnAppearing() { base.OnAppearing(); if (_syncService.SyncInProgress) { IsBusy = true; } _broadcasterService.Subscribe(nameof(ViewPage), 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 (message.Data is Dictionary <string, object> data && data.ContainsKey("successfully")) { var success = data["successfully"] as bool?; if (success.GetValueOrDefault()) { var task = _vm.LoadAsync(() => AdjustToolbar()); } } }); } else if (message.Command == "selectSaveFileResult") { Device.BeginInvokeOnMainThread(() => { var data = message.Data as Tuple <string, string>; if (data == null) { return; } _vm.SaveFileSelected(data.Item1, data.Item2); }); } } catch (Exception ex) { LoggerHelper.LogEvenIfCantBeResolved(ex); } }); await LoadOnAppearedAsync(_scrollView, true, async() => { var success = await _vm.LoadAsync(() => AdjustToolbar()); if (!success) { await Navigation.PopModalAsync(); } }, _mainContent); }
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); }
protected override async void OnAppearing() { base.OnAppearing(); await _vm.InitAsync(); if (_syncService.SyncInProgress) { IsBusy = true; } _broadcasterService.Subscribe(_pageName, async(message) => { if (message.Command == "syncStarted") { Device.BeginInvokeOnMainThread(() => IsBusy = true); } else if (message.Command == "syncCompleted" || message.Command == "sendUpdated") { await Task.Delay(500); Device.BeginInvokeOnMainThread(() => { IsBusy = false; if (_vm.LoadedOnce) { var task = _vm.LoadAsync(); } }); } }); await LoadOnAppearedAsync(_mainLayout, false, async() => { if (!_syncService.SyncInProgress || (await _sendService.GetAllAsync()).Any()) { try { await _vm.LoadAsync(); } catch (Exception e) when(e.Message.Contains("No key.")) { await Task.Delay(1000); await _vm.LoadAsync(); } } else { await Task.Delay(5000); if (!_vm.Loaded) { await _vm.LoadAsync(); } } await ShowPreviousPageAsync(); AdjustToolbar(); }, _mainContent); }
protected async override void OnAppearing() { base.OnAppearing(); _broadcasterService.Subscribe(_pageName, async(message) => { if (message.Command == "syncCompleted") { await Task.Delay(500); Device.BeginInvokeOnMainThread(() => { var task = _vm.LoadAsync(); }); } }); await LoadOnAppearedAsync(_mainLayout, false, async() => { if (!_syncService.SyncInProgress) { await _vm.LoadAsync(); } else { await Task.Delay(5000); if (!_vm.Loaded) { await _vm.LoadAsync(); } } }, _mainContent); // Push registration var lastPushRegistration = await _storageService.GetAsync <DateTime?>(Constants.PushLastRegistrationDateKey); lastPushRegistration = lastPushRegistration.GetValueOrDefault(DateTime.MinValue); if (Device.RuntimePlatform == Device.iOS) { var pushPromptShow = await _storageService.GetAsync <bool?>(Constants.PushInitialPromptShownKey); if (!pushPromptShow.GetValueOrDefault(false)) { await _storageService.SaveAsync(Constants.PushInitialPromptShownKey, true); await DisplayAlert(AppResources.EnableAutomaticSyncing, AppResources.PushNotificationAlert, AppResources.OkGotIt); } if (!pushPromptShow.GetValueOrDefault(false) || DateTime.UtcNow - lastPushRegistration > TimeSpan.FromDays(1)) { await _pushNotificationService.RegisterAsync(); } } else if (Device.RuntimePlatform == Device.Android && DateTime.UtcNow - lastPushRegistration > TimeSpan.FromDays(1)) { await _pushNotificationService.RegisterAsync(); } }
protected override async void OnAppearing() { base.OnAppearing(); _broadcasterService.Subscribe(nameof(ViewPage), (message) => { if (message.Command == "syncCompleted") { Device.BeginInvokeOnMainThread(() => { var data = message.Data as Dictionary <string, object>; if (data.ContainsKey("successfully")) { var success = data["successfully"] as bool?; if (success.HasValue && success.Value) { var task = _vm.LoadAsync(); } } }); } }); await LoadOnAppearedAsync(_scrollView, true, async() => { var success = await _vm.LoadAsync(); if (!success) { await Navigation.PopModalAsync(); } }, _mainContent); if (Device.RuntimePlatform == Device.Android) { if (_vm.Cipher.OrganizationId == null) { if (ToolbarItems.Contains(_collectionsItem)) { ToolbarItems.Remove(_collectionsItem); } if (!ToolbarItems.Contains(_shareItem)) { ToolbarItems.Insert(1, _shareItem); } } else { if (ToolbarItems.Contains(_shareItem)) { ToolbarItems.Remove(_shareItem); } if (!ToolbarItems.Contains(_collectionsItem)) { ToolbarItems.Insert(1, _collectionsItem); } } } }
protected async override void OnAppearing() { base.OnAppearing(); _broadcasterService.Subscribe(nameof(TwoFactorPage), (message) => { if (message.Command == "gotYubiKeyOTP") { var token = (string)message.Data; if (_vm.YubikeyMethod && !string.IsNullOrWhiteSpace(token) && token.Length == 44 && !token.Contains(" ")) { Device.BeginInvokeOnMainThread(async() => { _vm.Token = token; await _vm.SubmitAsync(); }); } } else if (message.Command == "resumeYubiKey") { if (_vm.YubikeyMethod) { _messagingService.Send("listenYubiKeyOTP", true); } } else if (message.Command == "gotFido2Token") // Receive the token to send in response t the server about two-factor { // Check if valid var token = (string)message.Data; if (!string.IsNullOrWhiteSpace(token)) { // send to the api service Device.BeginInvokeOnMainThread(async() => { _vm.Token = token; await _vm.SubmitAsync(); }); } } }); await LoadOnAppearedAsync(_scrollView, true, () => { if (!_inited) { _inited = true; _vm.Init(); } if (_vm.TotpMethod) { RequestFocus(_totpEntry); } return(Task.FromResult(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(); } }
public override bool FinishedLaunching(UIApplication app, NSDictionary options) { Forms.Init(); InitApp(); Bootstrap(); _deviceActionService = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService"); _messagingService = ServiceContainer.Resolve <IMessagingService>("messagingService"); _broadcasterService = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService"); _storageService = ServiceContainer.Resolve <IStorageService>("storageService"); LoadApplication(new App.App(null)); AppearanceAdjustments(); ZXing.Net.Mobile.Forms.iOS.Platform.Init(); _broadcasterService.Subscribe(nameof(AppDelegate), (message) => { if (message.Command == "scheduleLockTimer") { var lockOptionMinutes = (int)message.Data; } else if (message.Command == "cancelLockTimer") { } else if (message.Command == "updatedTheme") { // ThemeManager.SetThemeStyle(message.Data as string); } else if (message.Command == "copiedToClipboard") { } else if (message.Command == "listenYubiKeyOTP") { ListenYubiKey((bool)message.Data); } else if (message.Command == "showAppExtension") { } 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()) { } } }
protected override void OnAppearing() { base.OnAppearing(); _messagingService.Send("showStatusBar", false); CheckOnboarded(); _broadcasterService.Subscribe(nameof(HomePage), (message) => { if (message.Command == "onboarded") { CheckOnboarded(); } }); }
protected override async void OnAppearing() { base.OnAppearing(); _broadcasterService.Subscribe(nameof(AttachmentsPage), (message) => { if (message.Command == "selectFileResult") { var data = message.Data as Tuple <byte[], string>; _vm.FileData = data.Item1; _vm.FileName = data.Item2; } }); await LoadOnAppearedAsync(_scrollView, true, () => _vm.InitAsync()); }
protected override void OnAppearing() { base.OnAppearing(); _messagingService.Send("showStatusBar", false); _broadcasterService.Subscribe(nameof(HomePage), async(message) => { if (message.Command == "updatedTheme") { Device.BeginInvokeOnMainThread(() => { UpdateLogo(); }); } }); }
public CustomTabbedRenderer() { _broadcasterService = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService"); _broadcasterService.Subscribe(nameof(CustomTabbedRenderer), async(message) => { if (message.Command == "updatedTheme") { Device.BeginInvokeOnMainThread(() => { iOSCoreHelpers.AppearanceAdjustments(); UpdateTabBarAppearance(); }); } }); }
public override void OnCreate() { base.OnCreate(); LoadServices(); var settingsTask = LoadSettingsAsync(); _broadcasterService.Subscribe(nameof(AccessibilityService), (message) => { if (message.Command == "OnAutofillTileClick") { var runnable = new Java.Lang.Runnable(OnAutofillTileClick); _handler.PostDelayed(runnable, 250); } }); AccessibilityHelpers.IsAccessibilityBroadcastReady = true; }
public DeviceActionService( IStorageService storageService, IMessagingService messagingService, IBroadcasterService broadcasterService) { _storageService = storageService; _messagingService = messagingService; _broadcasterService = broadcasterService; _broadcasterService.Subscribe(nameof(DeviceActionService), (message) => { if (message.Command == "selectFileCameraPermissionDenied") { _cameraPermissionsDenied = true; } }); }
protected override async void OnAppearing() { base.OnAppearing(); _broadcasterService.Subscribe(nameof(TabsPage), async(message) => { if (message.Command == "syncCompleted") { Device.BeginInvokeOnMainThread(async() => await UpdateVaultButtonTitleAsync()); } }); await UpdateVaultButtonTitleAsync(); if (await _keyConnectorService.UserNeedsMigration()) { _messagingService.Send("convertAccountToKeyConnector"); } }
protected async override void OnAppearing() { base.OnAppearing(); if (!_fromTabPage) { await InitAsync(); } _broadcasterService.Subscribe(nameof(GeneratorPage), async(message) => { if (message.Command == "updatedTheme") { Device.BeginInvokeOnMainThread(() => { _vm.RedrawPassword(); }); } }); }
protected override void OnCreate(Bundle savedInstanceState) { var alarmIntent = new Intent(this, typeof(LockAlarmReceiver)); _lockAlarmPendingIntent = PendingIntent.GetBroadcast(this, 0, alarmIntent, PendingIntentFlags.UpdateCurrent); _deviceActionService = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService"); _messagingService = ServiceContainer.Resolve <IMessagingService>("messagingService"); _broadcasterService = ServiceContainer.Resolve <IBroadcasterService>("broadcasterService"); TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); Xamarin.Forms.Forms.Init(this, savedInstanceState); _appOptions = GetOptions(); LoadApplication(new App.App(_appOptions)); _broadcasterService.Subscribe(nameof(MainActivity), (message) => { if (message.Command == "scheduleLockTimer") { var lockOptionMs = (int)message.Data * 1000; var triggerMs = Java.Lang.JavaSystem.CurrentTimeMillis() + lockOptionMs + 10; var alarmManager = GetSystemService(AlarmService) as AlarmManager; alarmManager.Set(AlarmType.RtcWakeup, triggerMs, _lockAlarmPendingIntent); } else if (message.Command == "cancelLockTimer") { var alarmManager = GetSystemService(AlarmService) as AlarmManager; alarmManager.Cancel(_lockAlarmPendingIntent); } else if (message.Command == "finishMainActivity") { Finish(); } else if (message.Command == "listenYubiKeyOTP") { ListenYubiKey((bool)message.Data); } }); }
public DeviceActionService( IClipboardService clipboardService, IStateService stateService, IMessagingService messagingService, IBroadcasterService broadcasterService, Func <IEventService> eventServiceFunc) { _clipboardService = clipboardService; _stateService = stateService; _messagingService = messagingService; _broadcasterService = broadcasterService; _eventServiceFunc = eventServiceFunc; _broadcasterService.Subscribe(nameof(DeviceActionService), (message) => { if (message.Command == "selectFileCameraPermissionDenied") { _cameraPermissionsDenied = true; } }); }
protected override async void OnAppearing() { base.OnAppearing(); _mainContent.Content = _mainLayout; _accountAvatar?.OnAppearing(); if (!_appOptions?.HideAccountSwitcher ?? false) { _vm.AvatarImageSource = await GetAvatarImageSourceAsync(); } _broadcasterService.Subscribe(nameof(HomePage), (message) => { if (message.Command == "updatedTheme") { Device.BeginInvokeOnMainThread(() => { UpdateLogo(); }); } }); }
protected override async void OnAppearing() { base.OnAppearing(); if (_syncService.SyncInProgress) { IsBusy = true; } _broadcasterService.Subscribe(nameof(ViewPage), async(message) => { if (message.Command == "syncStarted") { Device.BeginInvokeOnMainThread(() => IsBusy = true); } else if (message.Command == "syncCompleted") { await Task.Delay(500); Device.BeginInvokeOnMainThread(() => { IsBusy = false; if (message.Data is Dictionary <string, object> data && data.ContainsKey("successfully")) { var success = data["successfully"] as bool?; if (success.GetValueOrDefault()) { var task = _vm.LoadAsync(() => AdjustToolbar()); } } }); } }); await LoadOnAppearedAsync(_scrollView, true, async() => { var success = await _vm.LoadAsync(() => AdjustToolbar()); if (!success) { await Navigation.PopModalAsync(); } }, _mainContent); }
protected async override void OnAppearing() { base.OnAppearing(); await _vm.InitAsync(); _broadcasterService.Subscribe(nameof(ExportVaultPage), (message) => { if (message.Command == "selectSaveFileResult") { Device.BeginInvokeOnMainThread(() => { var data = message.Data as Tuple <string, string>; if (data == null) { return; } _vm.SaveFileSelected(data.Item1, data.Item2); }); } }); RequestFocus(_masterPassword); }
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"); _stateService = ServiceContainer.Resolve <IStateService>("stateService"); _eventService = ServiceContainer.Resolve <IEventService>("eventService"); LoadApplication(new App.App(null)); iOSCoreHelpers.AppearanceAdjustments(); ZXing.Net.Mobile.Forms.iOS.Platform.Init(); _broadcasterService.Subscribe(nameof(AppDelegate), async(message) => { try { if (message.Command == "startEventTimer") { StartEventTimer(); } else if (message.Command == "stopEventTimer") { var task = StopEventTimerAsync(); } else if (message.Command == "updatedTheme") { Device.BeginInvokeOnMainThread(() => { iOSCoreHelpers.AppearanceAdjustments(); }); } 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 == "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 == "logout") { 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 _stateService.GetVaultTimeoutActionAsync(); if (timeoutAction == VaultTimeoutAction.Logout) { await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync(); } else { await ASHelpers.ReplaceAllIdentities(); } } } catch (Exception ex) { LoggerHelper.LogEvenIfCantBeResolved(ex); } }); return(base.FinishedLaunching(app, options)); }
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)); _lockAlarmPendingIntent = 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 hockeyAppListener = new HockeyAppCrashManagerListener(_appIdService, _userService); var hockeyAppTask = hockeyAppListener.InitAsync(this); #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 == "scheduleLockTimer") { var alarmManager = GetSystemService(AlarmService) as AlarmManager; var lockOptionMinutes = (int)message.Data; var lockOptionMs = lockOptionMinutes * 60000; var triggerMs = Java.Lang.JavaSystem.CurrentTimeMillis() + lockOptionMs + 10; alarmManager.Set(AlarmType.RtcWakeup, triggerMs, _lockAlarmPendingIntent); } else if (message.Command == "cancelLockTimer") { var alarmManager = GetSystemService(AlarmService) as AlarmManager; alarmManager.Cancel(_lockAlarmPendingIntent); } 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>); } }); }
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 LockedAsync(!(message.Data as bool?).GetValueOrDefault()); } 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 == "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") { 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(); } } }); } }); }
protected async override void OnAppearing() { base.OnAppearing(); if (_syncService.SyncInProgress) { IsBusy = true; } _broadcasterService.Subscribe(_pageName, async(message) => { 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(); } }); } }); var migratedFromV1 = await _storageService.GetAsync <bool?>(Constants.MigratedFromV1); await LoadOnAppearedAsync(_mainLayout, false, async() => { if (!_syncService.SyncInProgress) { try { await _vm.LoadAsync(); } catch (Exception e) when(e.Message.Contains("No key.")) { await Task.Delay(5000); await _vm.LoadAsync(); } } else { await Task.Delay(5000); if (!_vm.Loaded) { await _vm.LoadAsync(); } } // Forced sync if for some reason we have no data after a v1 migration if (_vm.MainPage && !_syncService.SyncInProgress && migratedFromV1.GetValueOrDefault() && !_vm.HasCiphers && Xamarin.Essentials.Connectivity.NetworkAccess != Xamarin.Essentials.NetworkAccess.None) { var triedV1ReSync = await _storageService.GetAsync <bool?>(Constants.TriedV1Resync); if (!triedV1ReSync.GetValueOrDefault()) { await _storageService.SaveAsync(Constants.TriedV1Resync, true); await _syncService.FullSyncAsync(true); } } }, _mainContent); if (!_vm.MainPage) { return; } // Push registration var lastPushRegistration = await _storageService.GetAsync <DateTime?>(Constants.PushLastRegistrationDateKey); lastPushRegistration = lastPushRegistration.GetValueOrDefault(DateTime.MinValue); if (Device.RuntimePlatform == Device.iOS) { var pushPromptShow = await _storageService.GetAsync <bool?>(Constants.PushInitialPromptShownKey); if (!pushPromptShow.GetValueOrDefault(false)) { await _storageService.SaveAsync(Constants.PushInitialPromptShownKey, true); await DisplayAlert(AppResources.EnableAutomaticSyncing, AppResources.PushNotificationAlert, AppResources.OkGotIt); } if (!pushPromptShow.GetValueOrDefault(false) || DateTime.UtcNow - lastPushRegistration > TimeSpan.FromDays(1)) { await _pushNotificationService.RegisterAsync(); } } else if (Device.RuntimePlatform == Device.Android) { if (DateTime.UtcNow - lastPushRegistration > TimeSpan.FromDays(1)) { await _pushNotificationService.RegisterAsync(); } if (!_deviceActionService.AutofillAccessibilityServiceRunning() && !_deviceActionService.AutofillServiceEnabled()) { if (migratedFromV1.GetValueOrDefault()) { var migratedFromV1AutofillPromptShown = await _storageService.GetAsync <bool?>( Constants.MigratedFromV1AutofillPromptShown); if (!migratedFromV1AutofillPromptShown.GetValueOrDefault()) { await DisplayAlert(AppResources.Autofill, AppResources.AutofillServiceNotEnabled, AppResources.Ok); } } } await _storageService.SaveAsync(Constants.MigratedFromV1AutofillPromptShown, true); } }
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"); _lockService = ServiceContainer.Resolve <ILockService>("lockService"); _eventService = ServiceContainer.Resolve <IEventService>("eventService"); _platformUtilsService = ServiceContainer.Resolve <IPlatformUtilsService>("platformUtilsService"); _cozyClientService = ServiceContainer.Resolve <ICozyClientService>("cozyClientService"); LoadApplication(new App.App(null)); iOSCoreHelpers.AppearanceAdjustments(_deviceActionService); ZXing.Net.Mobile.Forms.iOS.Platform.Init(); _broadcasterService.Subscribe(nameof(AppDelegate), async(message) => { if (message.Command == "scheduleLockTimer") { LockTimer((int)message.Data); } else if (message.Command == "cancelLockTimer") { CancelLockTimer(); } else 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") { ListenYubiKey((bool)message.Data); } 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") { 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") { 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(); } } }); return(base.FinishedLaunching(app, options)); }