make crash email util

This commit is contained in:
Kyle Spearrin 2017-06-08 11:52:29 -04:00
parent b139eadf0b
commit 7e23a8169f
3 changed files with 55 additions and 39 deletions

View file

@ -331,6 +331,7 @@
<Compile Include="Services\ReflectionService.cs" /> <Compile Include="Services\ReflectionService.cs" />
<Compile Include="Services\SqlService.cs" /> <Compile Include="Services\SqlService.cs" />
<Compile Include="SplashActivity.cs" /> <Compile Include="SplashActivity.cs" />
<Compile Include="Utilities.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="8bit.keystore.enc" /> <None Include="8bit.keystore.enc" />

View file

@ -12,7 +12,6 @@ using Android.App;
using Plugin.Settings.Abstractions; using Plugin.Settings.Abstractions;
using Java.Util; using Java.Util;
using Javax.Crypto.Spec; using Javax.Crypto.Spec;
using Android.Content;
namespace Bit.Android.Services namespace Bit.Android.Services
{ {
@ -47,45 +46,11 @@ namespace Bit.Android.Services
} }
catch(Exception e) catch(Exception e)
{ {
SendEmail(e.Message + "\n\n" + e.StackTrace); Utilities.SendCrashEmail(e);
throw; 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) public bool Contains(string key)
{ {
return _settings.Contains(string.Format(SettingsFormat, key)) || _oldKeyStorageService.Contains(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."); Console.WriteLine("Failed to decrypt from secure storage.");
_settings.Remove(formattedKey); _settings.Remove(formattedKey);
SendEmail(e.Message + "\n\n" + e.StackTrace); Utilities.SendCrashEmail(e);
return null; return null;
} }
} }
@ -154,7 +119,7 @@ namespace Bit.Android.Services
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine("Failed to encrypt to secure storage."); 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."); Console.WriteLine("Cannot get AesKey.");
_keyStore.DeleteEntry(KeyAlias); _keyStore.DeleteEntry(KeyAlias);
_settings.Remove(AesKey); _settings.Remove(AesKey);
SendEmail(e.Message + "\n\n" + e.StackTrace); Utilities.SendCrashEmail(e);
return null; return null;
} }
} }

50
src/Android/Utilities.cs Normal file
View file

@ -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..."));
}
}
}