2017-06-08 18:52:29 +03:00
|
|
|
|
using System;
|
|
|
|
|
using Android.App;
|
|
|
|
|
using Android.Content;
|
|
|
|
|
using Java.Security;
|
2017-06-22 22:33:37 +03:00
|
|
|
|
using System.IO;
|
2017-06-08 18:52:29 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.Android
|
|
|
|
|
{
|
|
|
|
|
public static class Utilities
|
|
|
|
|
{
|
|
|
|
|
public static void SendCrashEmail(Exception e, bool includeSecurityProviders = true)
|
|
|
|
|
{
|
|
|
|
|
SendCrashEmail(e.Message + "\n\n" + e.StackTrace, includeSecurityProviders);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-22 22:33:37 +03:00
|
|
|
|
public static void SaveCrashFile(Exception e, bool includeSecurityProviders = true)
|
|
|
|
|
{
|
|
|
|
|
SaveCrashFile(e.Message + "\n\n" + e.StackTrace, includeSecurityProviders);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-08 18:52:29 +03:00
|
|
|
|
public static void SendCrashEmail(string text, bool includeSecurityProviders = true)
|
2017-06-22 22:33:37 +03:00
|
|
|
|
{
|
|
|
|
|
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, FormatText(text, includeSecurityProviders));
|
|
|
|
|
|
|
|
|
|
Application.Context.StartActivity(Intent.CreateChooser(emailIntent, "Send mail..."));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SaveCrashFile(string text, bool includeSecurityProviders = true)
|
|
|
|
|
{
|
|
|
|
|
var path = global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
|
|
|
|
|
var dir = Path.Combine(path, "bitwarden");
|
|
|
|
|
if(!Directory.Exists(dir))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(dir);
|
|
|
|
|
}
|
|
|
|
|
var filename = Path.Combine(dir, $"crash-{Java.Lang.JavaSystem.CurrentTimeMillis()}.txt");
|
|
|
|
|
using(var streamWriter = new StreamWriter(filename, true))
|
|
|
|
|
{
|
|
|
|
|
streamWriter.WriteLine(FormatText(text, includeSecurityProviders));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string FormatText(string text, bool includeSecurityProviders = true)
|
2017-06-08 18:52:29 +03:00
|
|
|
|
{
|
|
|
|
|
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;
|
2017-06-22 22:33:37 +03:00
|
|
|
|
return text;
|
2017-06-08 18:52:29 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|