1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-23 11:45:38 +01:00

launch for main activity and catch exceptions

This commit is contained in:
Kyle Spearrin 2017-06-23 23:21:39 -04:00
parent 573ff15925
commit 12da6fbd18
3 changed files with 42 additions and 21 deletions

View File

@ -15,6 +15,7 @@ using Xamarin.Forms;
using System.Threading.Tasks;
using Bit.App.Models.Page;
using Bit.App;
using Android.Runtime;
namespace Bit.Android
{
@ -29,6 +30,8 @@ namespace Bit.Android
protected override void OnCreate(Bundle bundle)
{
AndroidEnvironment.UnhandledExceptionRaiser += AndroidEnvironment_UnhandledExceptionRaiser;
var uri = Intent.GetStringExtra("uri");
if(!Resolver.IsSet)
{
@ -104,6 +107,12 @@ namespace Bit.Android
});
}
private void AndroidEnvironment_UnhandledExceptionRaiser(object sender, RaiseThrowableEventArgs e)
{
var message = Utilities.AppendExceptionToMessage("", e.Exception);
Utilities.SendCrashEmail(this, e.Exception, true);
}
private void ReturnCredentials(VaultListPageModel.Login login)
{
Intent data = new Intent();

View File

@ -24,9 +24,9 @@ using SimpleInjector;
namespace Bit.Android
{
#if DEBUG
[Application(Debuggable = true)]
//[Application(Debuggable = true)]
#else
[Application(Debuggable = false)]
//[Application(Debuggable = false)]
#endif
public class MainApplication : Application, Application.IActivityLifecycleCallbacks
{
@ -48,22 +48,11 @@ namespace Bit.Android
private void AndroidEnvironment_UnhandledExceptionRaiser(object sender, RaiseThrowableEventArgs e)
{
var message = AppendExceptionToMessage("", e.Exception);
var message = Utilities.AppendExceptionToMessage("", e.Exception);
//Utilities.SaveCrashFile(message, true);
Utilities.SendCrashEmail(message, false);
}
private string AppendExceptionToMessage(string message, Exception ex)
{
message += ("\n\n" + ex.Message + "\n\n" + ex.StackTrace);
if(ex.InnerException != null)
{
return AppendExceptionToMessage(message, ex.InnerException);
}
return message;
}
public override void OnCreate()
{
base.OnCreate();

View File

@ -13,6 +13,11 @@ namespace Bit.Android
SendCrashEmail(e.Message + "\n\n" + e.StackTrace, includeSecurityProviders);
}
public static void SendCrashEmail(Activity act, Exception e, bool includeSecurityProviders = true)
{
SendCrashEmail(act, e.Message + "\n\n" + e.StackTrace, includeSecurityProviders);
}
public static void SaveCrashFile(Exception e, bool includeSecurityProviders = true)
{
SaveCrashFile(e.Message + "\n\n" + e.StackTrace, includeSecurityProviders);
@ -30,15 +35,22 @@ namespace Bit.Android
Application.Context.StartActivity(Intent.CreateChooser(emailIntent, "Send mail..."));
}
public static void SendCrashEmail(Activity act, string text, bool includeSecurityProviders = true)
{
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));
act.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");
var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var filename = Path.Combine(path, $"crash-{Java.Lang.JavaSystem.CurrentTimeMillis()}.txt");
using(var streamWriter = new StreamWriter(filename, true))
{
streamWriter.WriteLine(FormatText(text, includeSecurityProviders));
@ -70,5 +82,16 @@ namespace Bit.Android
text += "\n\n ==================================================== \n\n" + crashMessage;
return text;
}
public static string AppendExceptionToMessage(string message, Exception ex)
{
message += ("\n\n" + ex.Message + "\n\n" + ex.StackTrace);
if(ex.InnerException != null)
{
return AppendExceptionToMessage(message, ex.InnerException);
}
return message;
}
}
}