diff --git a/src/Android/Android.csproj b/src/Android/Android.csproj index af2c93557..7327dc961 100644 --- a/src/Android/Android.csproj +++ b/src/Android/Android.csproj @@ -331,6 +331,7 @@ + diff --git a/src/Android/Services/KeyStoreBackedStorageService.cs b/src/Android/Services/KeyStoreBackedStorageService.cs index 0ffed7ecb..fbff9f6aa 100644 --- a/src/Android/Services/KeyStoreBackedStorageService.cs +++ b/src/Android/Services/KeyStoreBackedStorageService.cs @@ -12,7 +12,6 @@ using Android.App; using Plugin.Settings.Abstractions; using Java.Util; using Javax.Crypto.Spec; -using Android.Content; namespace Bit.Android.Services { @@ -47,45 +46,11 @@ namespace Bit.Android.Services } catch(Exception e) { - SendEmail(e.Message + "\n\n" + e.StackTrace); + Utilities.SendCrashEmail(e); throw; } } - private void SendEmail(string text, bool includeSecurityProviders = true) - { - var crashMessage = "bitwarden has crashed. Please send this email to our support team so that we can help " + - "resolve the problem for you. Thank you."; - - text = crashMessage + "\n\n =============================================== \n\n" + text; - - if(includeSecurityProviders) - { - text += "\n\n"; - var providers = Security.GetProviders(); - foreach(var provider in providers) - { - text += ("provider: " + provider.Name + "\n"); - var services = provider.Services; - foreach(var service in provider.Services) - { - text += ("- alg: " + service.Algorithm + "\n"); - } - } - } - - text += "\n\n ==================================================== \n\n" + crashMessage; - - var emailIntent = new Intent(Intent.ActionSend); - - emailIntent.SetType("plain/text"); - emailIntent.PutExtra(Intent.ExtraEmail, new String[] { "hello@bitwarden.com" }); - emailIntent.PutExtra(Intent.ExtraSubject, "bitwarden Crash Report"); - emailIntent.PutExtra(Intent.ExtraText, text); - - Application.Context.StartActivity(Intent.CreateChooser(emailIntent, "Send mail...")); - } - public bool Contains(string key) { return _settings.Contains(string.Format(SettingsFormat, key)) || _oldKeyStorageService.Contains(key); @@ -125,7 +90,7 @@ namespace Bit.Android.Services { Console.WriteLine("Failed to decrypt from secure storage."); _settings.Remove(formattedKey); - SendEmail(e.Message + "\n\n" + e.StackTrace); + Utilities.SendCrashEmail(e); return null; } } @@ -154,7 +119,7 @@ namespace Bit.Android.Services catch (Exception e) { Console.WriteLine("Failed to encrypt to secure storage."); - SendEmail(e.Message + "\n\n" + e.StackTrace); + Utilities.SendCrashEmail(e); } } @@ -233,7 +198,7 @@ namespace Bit.Android.Services Console.WriteLine("Cannot get AesKey."); _keyStore.DeleteEntry(KeyAlias); _settings.Remove(AesKey); - SendEmail(e.Message + "\n\n" + e.StackTrace); + Utilities.SendCrashEmail(e); return null; } } diff --git a/src/Android/Utilities.cs b/src/Android/Utilities.cs new file mode 100644 index 000000000..8f1af7a47 --- /dev/null +++ b/src/Android/Utilities.cs @@ -0,0 +1,50 @@ +using System; + +using Android.App; +using Android.Content; +using Java.Security; + +namespace Bit.Android +{ + public static class Utilities + { + public static void SendCrashEmail(Exception e, bool includeSecurityProviders = true) + { + SendCrashEmail(e.Message + "\n\n" + e.StackTrace, includeSecurityProviders); + } + + public static void SendCrashEmail(string text, bool includeSecurityProviders = true) + { + var crashMessage = "bitwarden has crashed. Please send this email to our support team so that we can help " + + "resolve the problem for you. Thank you."; + + text = crashMessage + "\n\n =============================================== \n\n" + text; + + if(includeSecurityProviders) + { + text += "\n\n"; + var providers = Security.GetProviders(); + foreach(var provider in providers) + { + text += ("provider: " + provider.Name + "\n"); + var services = provider.Services; + foreach(var service in provider.Services) + { + text += ("- alg: " + service.Algorithm + "\n"); + } + } + } + + text += "\n\n ==================================================== \n\n" + crashMessage; + + var emailIntent = new Intent(Intent.ActionSend); + + emailIntent.SetType("plain/text"); + emailIntent.PutExtra(Intent.ExtraEmail, new String[] { "hello@bitwarden.com" }); + emailIntent.PutExtra(Intent.ExtraSubject, "bitwarden Crash Report"); + emailIntent.PutExtra(Intent.ExtraText, text); + + Application.Context.StartActivity(Intent.CreateChooser(emailIntent, "Send mail...")); + } + } +} \ No newline at end of file