From f1854f2c04ec3eb3f10ed99fbb3beaff6031ef02 Mon Sep 17 00:00:00 2001 From: Dinis Vieira Date: Sat, 3 Feb 2024 15:59:22 +0000 Subject: [PATCH] PM-5903 Changed App.xaml.cs SetOption to only update the needed properties instead of replacing the existing Options object which would cause the AccountSwitcher button bug (#2973) --- src/App/Platforms/Android/MainActivity.cs | 3 ++- src/Core/App.xaml.cs | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/App/Platforms/Android/MainActivity.cs b/src/App/Platforms/Android/MainActivity.cs index 88fbceb8c..fe852fc7e 100644 --- a/src/App/Platforms/Android/MainActivity.cs +++ b/src/App/Platforms/Android/MainActivity.cs @@ -76,7 +76,8 @@ namespace Bit.Droid //We need to get and set the Options before calling OnCreate as that will "trigger" CreateWindow on App.xaml.cs _appOptions = GetOptions(); - ((Bit.App.App)Microsoft.Maui.Controls.Application.Current).SetOptions(_appOptions); + //This does not replace existing Options in App.xaml.cs if it exists already. It only updates properties in Options related with Autofill/CreateSend/etc.. + ((Bit.App.App)Microsoft.Maui.Controls.Application.Current).SetAndroidOptions(_appOptions); base.OnCreate(savedInstanceState); diff --git a/src/Core/App.xaml.cs b/src/Core/App.xaml.cs index 4f2fa1b3a..25b882d72 100644 --- a/src/Core/App.xaml.cs +++ b/src/Core/App.xaml.cs @@ -85,10 +85,27 @@ namespace Bit.App } } - //Allows setting Options from MainActivity before base.OnCreate - public void SetOptions(AppOptions appOptions) + /// + /// Allows setting Options from MainActivity before base.OnCreate + /// Note 1: This is only be used by Android due to way it's Lifecycle works + /// Note 2: This method does not replace existing Options in App.xaml.cs if it exists already. + /// It only updates properties in Options related with Autofill/CreateSend/etc.. + /// + /// Options created in Android MainActivity.cs + public void SetAndroidOptions(AppOptions appOptions) { - Options = appOptions ?? new AppOptions(); + if (Options == null) + { + Options = appOptions ?? new AppOptions(); + } + else if(appOptions != null) + { + Options.Uri = appOptions.Uri; + Options.MyVaultTile = appOptions.MyVaultTile; + Options.GeneratorTile = appOptions.GeneratorTile; + Options.FromAutofillFramework = appOptions.FromAutofillFramework; + Options.CreateSend = appOptions.CreateSend; + } } protected override Window CreateWindow(IActivationState activationState)