start implementing Xamarin.Insights based error reports

This commit is contained in:
Philipp Crocoll 2016-01-11 20:58:42 +01:00
parent 870e34d02e
commit 8fc98df53b
38 changed files with 228 additions and 53 deletions

View File

@ -14,6 +14,7 @@
<AssemblyName>KeePassLib2Android</AssemblyName> <AssemblyName>KeePassLib2Android</AssemblyName>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion> <TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk> <AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
<NuGetPackageImportStamp>8482b288</NuGetPackageImportStamp>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols> <DebugSymbols>True</DebugSymbols>
@ -54,6 +55,9 @@
<Reference Include="Mono.Android" /> <Reference Include="Mono.Android" />
<Reference Include="OpenTK-1.0" /> <Reference Include="OpenTK-1.0" />
<Reference Include="Mono.Security" /> <Reference Include="Mono.Security" />
<Reference Include="Xamarin.Insights">
<HintPath>..\packages\Xamarin.Insights.1.11.3\lib\MonoAndroid10\Xamarin.Insights.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="IDatabaseFormat.cs" /> <Compile Include="IDatabaseFormat.cs" />
@ -146,6 +150,7 @@
<Compile Include="Delegates\Handlers.cs" /> <Compile Include="Delegates\Handlers.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" />
<None Include="Resources\AboutResources.txt" /> <None Include="Resources\AboutResources.txt" />
<None Include="KeePassLib.pfx" /> <None Include="KeePassLib.pfx" />
</ItemGroup> </ItemGroup>
@ -163,4 +168,11 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<Import Project="..\packages\Xamarin.Insights.1.11.3\build\MonoAndroid10\Xamarin.Insights.targets" Condition="Exists('..\packages\Xamarin.Insights.1.11.3\build\MonoAndroid10\Xamarin.Insights.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Aktivieren Sie die Wiederherstellung von NuGet-Paketen, um die fehlende Datei herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Xamarin.Insights.1.11.3\build\MonoAndroid10\Xamarin.Insights.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Xamarin.Insights.1.11.3\build\MonoAndroid10\Xamarin.Insights.targets'))" />
</Target>
</Project> </Project>

View File

@ -16,6 +16,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll.
*/ */
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using Android.Preferences; using Android.Preferences;
using KeePassLib.Serialization; using KeePassLib.Serialization;
@ -68,5 +69,13 @@ namespace keepass2android
return (bool) _logToFile; return (bool) _logToFile;
} }
} }
public static event EventHandler<Exception> OnUnexpectedError;
public static void LogUnexpectedError(Exception exception)
{
Log(exception.ToString());
if (OnUnexpectedError != null)
OnUnexpectedError(null, exception);
}
} }
} }

View File

@ -251,7 +251,7 @@ namespace KeePassLib.Serialization
Kp2aLog.Log(e.ToString()); Kp2aLog.Log(e.ToString());
} catch (Exception e) } catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
Debug.Assert(false); Debug.Assert(false);
} }
} }

View File

@ -164,7 +164,7 @@ namespace keepass2android.Io
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
return false; return false;
} }

View File

@ -69,7 +69,7 @@ namespace keepass2android.Io
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
return false; return false;
} }

View File

@ -14,6 +14,7 @@
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies> <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion> <TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk> <AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<NuGetPackageImportStamp>06ffb71c</NuGetPackageImportStamp>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@ -53,6 +54,9 @@
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Xamarin.Insights">
<HintPath>..\packages\Xamarin.Insights.1.11.3\lib\MonoAndroid10\Xamarin.Insights.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="database\CheckDatabaseForChanges.cs" /> <Compile Include="database\CheckDatabaseForChanges.cs" />
@ -138,7 +142,17 @@
<Name>TwofishCipher</Name> <Name>TwofishCipher</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="..\packages\Xamarin.Insights.1.11.3\build\MonoAndroid10\Xamarin.Insights.targets" Condition="Exists('..\packages\Xamarin.Insights.1.11.3\build\MonoAndroid10\Xamarin.Insights.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Aktivieren Sie die Wiederherstellung von NuGet-Paketen, um die fehlende Datei herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Xamarin.Insights.1.11.3\build\MonoAndroid10\Xamarin.Insights.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Xamarin.Insights.1.11.3\build\MonoAndroid10\Xamarin.Insights.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">

View File

@ -135,7 +135,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
} }

View File

@ -94,20 +94,20 @@ namespace keepass2android
{ {
message = innerException.Message; message = innerException.Message;
// Override the message shown with the last (hopefully most recent) inner exception // Override the message shown with the last (hopefully most recent) inner exception
Kp2aLog.Log("Exception: " + innerException); Kp2aLog.LogUnexpectedError(innerException);
} }
Finish(false, _app.GetResourceString(UiStringKey.ErrorOcurred) + " " + message, Exception); Finish(false, _app.GetResourceString(UiStringKey.ErrorOcurred) + " " + message, Exception);
return; return;
} }
catch (DuplicateUuidsException e) catch (DuplicateUuidsException e)
{ {
Kp2aLog.Log("Exception: " + e); Kp2aLog.LogUnexpectedError(e);
Finish(false, _app.GetResourceString(UiStringKey.DuplicateUuidsError) + " " + e.Message + _app.GetResourceString(UiStringKey.DuplicateUuidsErrorAdditional), Exception); Finish(false, _app.GetResourceString(UiStringKey.DuplicateUuidsError) + " " + e.Message + _app.GetResourceString(UiStringKey.DuplicateUuidsErrorAdditional), Exception);
return; return;
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log("Exception: " + e); Kp2aLog.LogUnexpectedError(e);
Finish(false, _app.GetResourceString(UiStringKey.ErrorOcurred) + " " + e.Message, Exception); Finish(false, _app.GetResourceString(UiStringKey.ErrorOcurred) + " " + e.Message, Exception);
return; return;
} }

View File

@ -164,7 +164,7 @@ namespace keepass2android
bSuccess = false; bSuccess = false;
} }
*/ */
Kp2aLog.Log("Error while saving: " + e.ToString()); Kp2aLog.LogUnexpectedError(e);
Finish(false, e.Message); Finish(false, e.Message);
return; return;
} }
@ -188,6 +188,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.LogUnexpectedError(e);
Kp2aLog.Log("Error in worker thread of SaveDb: " + e); Kp2aLog.Log("Error in worker thread of SaveDb: " + e);
Finish(false, e.Message); Finish(false, e.Message);
} }
@ -197,6 +198,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.LogUnexpectedError(e);
Kp2aLog.Log("Error starting worker thread of SaveDb: "+e); Kp2aLog.Log("Error starting worker thread of SaveDb: "+e);
Finish(false, e.Message); Finish(false, e.Message);
} }

View File

@ -86,7 +86,7 @@ namespace KeeChallenge
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
finally finally
{ {

View File

@ -388,7 +388,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
} }

View File

@ -246,7 +246,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
} }

View File

@ -1128,7 +1128,8 @@ namespace keepass2android
TextView tv = (TextView) FindViewById(viewId); TextView tv = (TextView) FindViewById(viewId);
if (tv == null) if (tv == null)
{ {
Kp2aLog.Log("Invalid viewId " + viewId); var e = new Exception("Invalid viewId " + viewId);
Kp2aLog.LogUnexpectedError(e);
return; return;
} }
tv.Text = text; tv.Text = text;

View File

@ -97,7 +97,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
} }

View File

@ -134,7 +134,7 @@ namespace keepass2android
} }
catch (IllegalStateException ise) catch (IllegalStateException ise)
{ {
Kp2aLog.Log(ise.Message); Kp2aLog.LogUnexpectedError(ise);
} }
} }
} }

View File

@ -745,7 +745,7 @@ namespace keepass2android
catch (Exception e) catch (Exception e)
{ {
//don't crash if adding to dirty fails but log the exception: //don't crash if adding to dirty fails but log the exception:
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
AppTask = new NullTask(); AppTask = new NullTask();

View File

@ -85,7 +85,7 @@ namespace keepass2android
} }
catch (Exception ex) catch (Exception ex)
{ {
Kp2aLog.Log(ex.ToString()); Kp2aLog.LogUnexpectedError(ex);
} }
} }

View File

@ -88,7 +88,7 @@ namespace keepass2android
} }
catch (Exception ex) catch (Exception ex)
{ {
Kp2aLog.Log(ex.ToString()); Kp2aLog.LogUnexpectedError(ex);
} }
base.OnDestroy(); base.OnDestroy();

View File

@ -56,7 +56,7 @@ namespace keepass2android
} }
catch (Exception ex) catch (Exception ex)
{ {
Kp2aLog.Log(ex.ToString()); Kp2aLog.LogUnexpectedError(ex);
} }
base.OnDestroy(); base.OnDestroy();

View File

@ -87,7 +87,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
Toast.MakeText(this, "No Yubikey OTP found!", ToastLength.Long).Show(); Toast.MakeText(this, "No Yubikey OTP found!", ToastLength.Long).Show();
Finish(); Finish();
return; return;

View File

@ -396,7 +396,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
return null; return null;
} }
@ -482,7 +482,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
//retry with saved ioc //retry with saved ioc
try try
{ {
@ -494,7 +494,7 @@ namespace keepass2android
} }
catch (Exception e2) catch (Exception e2)
{ {
Kp2aLog.Log(e2.ToString()); Kp2aLog.LogUnexpectedError(e2);
} }
} }
@ -701,6 +701,7 @@ namespace keepass2android
private FingerprintDecryption _fingerprintDec; private FingerprintDecryption _fingerprintDec;
private bool _fingerprintPermissionGranted; private bool _fingerprintPermissionGranted;
private PasswordActivityBroadcastReceiver _intentReceiver; private PasswordActivityBroadcastReceiver _intentReceiver;
private int _appnameclickCount;
internal class MyActionBarDrawerToggle : ActionBarDrawerToggle internal class MyActionBarDrawerToggle : ActionBarDrawerToggle
@ -1003,6 +1004,20 @@ namespace keepass2android
AppSettingsActivity.Launch(this); AppSettingsActivity.Launch(this);
}; };
FindViewById(Resource.Id.nav_app_name).Click += (sender, args) =>
{
_appnameclickCount++;
if (_appnameclickCount == 6)
Toast.MakeText(this, "Once again and the app will crash.", ToastLength.Long).Show();
if (_appnameclickCount == 7)
{
Xamarin.Insights.Report(new Exception("blabla"), new Dictionary<string, string>() { { "key", "the value"}});
throw new Exception("This is an easter egg crash (for testing unhandled exceptions.)");
}
};
} }
private void InitializeToolbar() private void InitializeToolbar()
@ -1415,7 +1430,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
errorMessage = e.Message; errorMessage = e.Message;
return false; return false;
} }
@ -1430,7 +1445,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
errorMessage = GetString(Resource.String.OtpKeyError); errorMessage = GetString(Resource.String.OtpKeyError);
return false; return false;
@ -1941,6 +1956,7 @@ namespace keepass2android
_act.ClearEnteredPassword(); _act.ClearEnteredPassword();
_act.BroadcastOpenDatabase(); _act.BroadcastOpenDatabase();
_act.InvalidCompositeKeyCount = 0;
GC.Collect(); // Ensure temporary memory used while loading is collected GC.Collect(); // Ensure temporary memory used while loading is collected
@ -1949,6 +1965,7 @@ namespace keepass2android
if (Exception is InvalidCompositeKeyException) if (Exception is InvalidCompositeKeyException)
{ {
_act.InvalidCompositeKeyCount++;
if (_act.UsedFingerprintUnlock) if (_act.UsedFingerprintUnlock)
{ {
//disable fingerprint unlock if master password changed //disable fingerprint unlock if master password changed
@ -1957,9 +1974,24 @@ namespace keepass2android
Message = _act.GetString(Resource.String.fingerprint_disabled_wrong_masterkey); Message = _act.GetString(Resource.String.fingerprint_disabled_wrong_masterkey);
} }
else
{
if (_act.InvalidCompositeKeyCount > 1)
{
Message = _act.GetString(Resource.String.RepeatedInvalidCompositeKeyHelp);
}
else
{
Message = _act.GetString(Resource.String.FirstInvalidCompositeKeyError);
}
}
} }
if ((Exception != null) && (Exception.Message == KeePassLib.Resources.KLRes.FileCorrupted))
{
Message = _act.GetString(Resource.String.CorruptDatabaseHelp);
}
if ((Message != null) && (Message.Length > 150)) //show long messages as dialog if ((Message != null) && (Message.Length > 150)) //show long messages as dialog
@ -1992,6 +2024,11 @@ namespace keepass2android
} }
} }
public int InvalidCompositeKeyCount
{
get; set;
}
private void BroadcastOpenDatabase() private void BroadcastOpenDatabase()
{ {
App.Kp2a.BroadcastDatabaseAction(this, Strings.ActionOpenDatabase); App.Kp2a.BroadcastDatabaseAction(this, Strings.ActionOpenDatabase);
@ -2039,7 +2076,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.Message); Kp2aLog.LogUnexpectedError(e);
Toast.MakeText(_act, _act.GetString(Resource.String.ErrorUpdatingOtpAuxFile) + " " + e.Message, Toast.MakeText(_act, _act.GetString(Resource.String.ErrorUpdatingOtpAuxFile) + " " + e.Message,
ToastLength.Long).Show(); ToastLength.Long).Show();
@ -2063,7 +2100,6 @@ namespace keepass2android
switch (intent.Action) switch (intent.Action)
{ {
case Intent.ActionScreenOff: case Intent.ActionScreenOff:
Kp2aLog.Log("bla");
_activity.OnScreenLocked(); _activity.OnScreenLocked();
break; break;
} }

View File

@ -101,7 +101,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
if (String.IsNullOrEmpty(_requestedUrl)) if (String.IsNullOrEmpty(_requestedUrl))
Toast.MakeText(this, GetString(Resource.String.query_credentials, new Java.Lang.Object[] {pluginDisplayName}), ToastLength.Long).Show(); Toast.MakeText(this, GetString(Resource.String.query_credentials, new Java.Lang.Object[] {pluginDisplayName}), ToastLength.Long).Show();
@ -156,7 +156,7 @@ namespace keepass2android
//double check we really have the permission //double check we really have the permission
if (!new PluginDatabase(this).HasAcceptedScope(_pluginPackage, _requiredScope)) if (!new PluginDatabase(this).HasAcceptedScope(_pluginPackage, _requiredScope))
{ {
Kp2aLog.Log("Ohoh! Scope not available, shouldn't get here. Malicious app somewhere?"); Kp2aLog.LogUnexpectedError(new Exception("Ohoh! Scope not available, shouldn't get here. Malicious app somewhere?"));
SetResult(Result.Canceled); SetResult(Result.Canceled);
Finish(); Finish();
return; return;

View File

@ -340,7 +340,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
} }

View File

@ -399,6 +399,7 @@
android:scaleType="centerCrop" android:scaleType="centerCrop"
android:src="@drawable/navheader_bg" /> android:src="@drawable/navheader_bg" />
<TextView <TextView
android:id="@+id/nav_app_name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/app_name" android:text="@string/app_name"

View File

@ -613,6 +613,25 @@
<string name="Continue">Continue</string> <string name="Continue">Continue</string>
<string name="NoFilenameWarning">The URI you have entered does not look like a filename. Are you sure this is a valid file?</string> <string name="NoFilenameWarning">The URI you have entered does not look like a filename. Are you sure this is a valid file?</string>
<string name="FirstInvalidCompositeKeyError">Invalid composite key! Please try again.</string>
<string name="RepeatedInvalidCompositeKeyHelp">Invalid composite key! Please try the following steps to unlock your database:\n
* Make sure you have entered the correct password. Use the eye icon to reveal the entered password.\n
* Make sure you have selected the correct password type. Make sure this matches the type used when creating the database.\n
* Make sure you have selected the correct database file.</string>
<string name="CorruptDatabaseHelp">
File is corrupted. \n
Here are some hints which might help to diagnose the issue:\n
* If you copied the file over USB (MTP-Mode), please try again with tools like MyPhoneExplorer. MTP truncates files in certain cases.\n
* If you cannot open the file from the same location on your PC, it is very likely that the file is actually corrupted. Please use a database backup then. If you assume that Keepass2Android has corrupted the file, please contact support.\n
* If you can still open the file on your PC, please contact support. You might try to save it with different settings (e.g. unzipped) on the PC and retry to open in Keepass2Android.</string>
<string name="ErrorReportTitle">Keepass2Android: An error occurred.</string>
<string name="ErrorReportText">An unexpected error occurred. Please help us fix this by enabling error reports.</string>
<string name="ErrorReportPromise">Error reports will never contain any contents of your database or master password. You can disable them in the application settings.</string>
<string name="ErrorReportEnable">Enable</string>
<string name="ErrorReportDisable">Disable</string>
<string name="ChangeLog_0_9_8c"> <string name="ChangeLog_0_9_8c">
Version 0.9.8c\n Version 0.9.8c\n
* Fix for SSL vulnerability in Microsoft Live SDK (used when accessing files via OneDrive)\n * Fix for SSL vulnerability in Microsoft Live SDK (used when accessing files via OneDrive)\n

View File

@ -168,7 +168,7 @@ namespace PluginTOTP
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
//ignore, it's only a warning //ignore, it's only a warning
} }

View File

@ -30,7 +30,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
} }

View File

@ -86,7 +86,7 @@ namespace keepass2android.Utils
} }
catch (Exception t) catch (Exception t)
{ {
Kp2aLog.Log(t.ToString()); Kp2aLog.LogUnexpectedError(t);
} }
} }
@ -121,7 +121,7 @@ namespace keepass2android.Utils
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
} }

View File

@ -276,7 +276,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
String filename = data.Data.Path; String filename = data.Data.Path;

View File

@ -178,7 +178,7 @@ namespace OtpKeyProv
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
finally finally
{ {

View File

@ -31,6 +31,7 @@ using KeePassLib.Cryptography.Cipher;
using KeePassLib.Keys; using KeePassLib.Keys;
using KeePassLib.Serialization; using KeePassLib.Serialization;
using Android.Preferences; using Android.Preferences;
using Android.Support.V4.App;
#if !EXCLUDE_TWOFISH #if !EXCLUDE_TWOFISH
using TwofishCipher; using TwofishCipher;
#endif #endif
@ -365,7 +366,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
} }
@ -410,7 +411,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
} }
@ -566,7 +567,7 @@ namespace keepass2android
} }
enum ValidationMode public enum ValidationMode
{ {
Ignore, Warn, Error Ignore, Warn, Error
} }
@ -754,6 +755,9 @@ namespace keepass2android
#endif #endif
#endif #endif
public class App : Application { public class App : Application {
public const string Kp2AActionDisableerrorreport = "kp2a.action.DisableErrorReport";
public const string Kp2AActionEnableerrorreport = "kp2a.action.EnableErrorReport";
public const string PrefErrorreportmode = "pref_ErrorReportMode";
public App (IntPtr javaReference, JniHandleOwnership transfer) public App (IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer) : base(javaReference, transfer)
@ -762,6 +766,13 @@ namespace keepass2android
public static readonly Kp2aApp Kp2a = new Kp2aApp(); public static readonly Kp2aApp Kp2a = new Kp2aApp();
public enum ErrorReportMode
{
AskAgain=0,
Disabled=1,
Enabled=2
}
public override void OnCreate() { public override void OnCreate() {
base.OnCreate(); base.OnCreate();
@ -769,12 +780,50 @@ namespace keepass2android
Kp2a.OnCreate(this); Kp2a.OnCreate(this);
AndroidEnvironment.UnhandledExceptionRaiser += MyApp_UnhandledExceptionHandler; AndroidEnvironment.UnhandledExceptionRaiser += MyApp_UnhandledExceptionHandler;
Kp2aLog.OnUnexpectedError += (sender, exception) =>
{
var currentErrorReportMode = GetErrorReportMode();
if (currentErrorReportMode == ErrorReportMode.AskAgain)
{
NotificationCompat.Builder builder = new NotificationCompat.Builder(ApplicationContext);
var notification =
builder.SetContentTitle(Resources.GetString(Resource.String.ErrorReportTitle))
.SetContentText(Resources.GetString(Resource.String.ErrorReportText) + " " +
Resources.GetString(Resource.String.ErrorReportPromise))
.AddAction(Android.Resource.Drawable.IcMenuCloseClearCancel, Resource.String.ErrorReportDisable,
PendingIntent.GetBroadcast(ApplicationContext, 0, new Intent(Kp2AActionDisableerrorreport),
PendingIntentFlags.CancelCurrent))
.AddAction(Android.Resource.Drawable.IcMenuCloseClearCancel, Resource.String.ErrorReportEnable,
PendingIntent.GetBroadcast(ApplicationContext, 0, new Intent(Kp2AActionEnableerrorreport),
PendingIntentFlags.CancelCurrent))
.Build();
((NotificationManager) GetSystemService(NotificationService)).Notify(18919, notification);
var filter = new IntentFilter();
filter.AddAction(Kp2AActionDisableerrorreport);
filter.AddAction(Kp2AActionEnableerrorreport);
RegisterReceiver(new ErrorReportSettingsReceiver(), filter);
}
};
Xamarin.Insights.Initialize("fed2b273ed2a964d0ba6acc3743e68f7a04da957", ApplicationContext);
Xamarin.Insights.DisableExceptionCatching = true;
var errorReportMode = GetErrorReportMode();
Xamarin.Insights.DisableDataTransmission = errorReportMode != ErrorReportMode.Enabled;
}
private ErrorReportMode GetErrorReportMode()
{
ErrorReportMode errorReportMode;
Enum.TryParse(PreferenceManager.GetDefaultSharedPreferences(this.ApplicationContext)
.GetString(PrefErrorreportmode, ErrorReportMode.AskAgain.ToString()), out errorReportMode);
return errorReportMode;
} }
void MyApp_UnhandledExceptionHandler(object sender, RaiseThrowableEventArgs e) void MyApp_UnhandledExceptionHandler(object sender, RaiseThrowableEventArgs e)
{ {
Kp2aLog.Log(e.Exception.ToString()); Kp2aLog.LogUnexpectedError(e.Exception);
Xamarin.Insights.Save();
// Do your error handling here. // Do your error handling here.
throw e.Exception; throw e.Exception;
} }
@ -793,5 +842,24 @@ namespace keepass2android
} }
public class ErrorReportSettingsReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
if (intent.Action == App.Kp2AActionDisableerrorreport)
{
PreferenceManager.GetDefaultSharedPreferences(context)
.Edit()
.PutString(App.PrefErrorreportmode, App.ErrorReportMode.Disabled.ToString());
}
if (intent.Action == App.Kp2AActionEnableerrorreport)
{
PreferenceManager.GetDefaultSharedPreferences(context)
.Edit()
.PutString(App.PrefErrorreportmode, App.ErrorReportMode.Enabled.ToString());
}
}
}
} }

View File

@ -38,7 +38,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
return false; return false;
} }
} }
@ -57,7 +57,7 @@ namespace keepass2android
} }
catch(Exception e) catch(Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
return false; return false;
} }
} }
@ -71,7 +71,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
return null; return null;
} }
} }
@ -92,7 +92,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
} }
} }

View File

@ -15,6 +15,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>. along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
*/ */
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Android.App; using Android.App;
using Android.Content; using Android.Content;
@ -59,7 +60,7 @@ private static Drawable _blank;
} }
else else
Kp2aLog.Log("icon not found : " + icon); Kp2aLog.LogUnexpectedError(new Exception("icon not found : " + icon));
} }
public Drawable GetIconDrawable (Context context, PwDatabase db, PwIcon icon, PwUuid customIconId, bool forGroup) public Drawable GetIconDrawable (Context context, PwDatabase db, PwIcon icon, PwUuid customIconId, bool forGroup)
@ -113,7 +114,7 @@ private static Drawable _blank;
} }
catch (System.Exception e) catch (System.Exception e)
{ {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
draw = context.Resources.GetDrawable(Resource.Drawable.ic99_blank); draw = context.Resources.GetDrawable(Resource.Drawable.ic99_blank);
} }

View File

@ -19,6 +19,7 @@
<MandroidI18n /> <MandroidI18n />
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize> <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk> <AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<NuGetPackageImportStamp>9e78b013</NuGetPackageImportStamp>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols> <DebugSymbols>True</DebugSymbols>
@ -110,6 +111,9 @@
<HintPath>..\packages\Xamarin.GooglePlayServices.Drive.27.0.0.0\lib\MonoAndroid41\Xamarin.GooglePlayServices.Drive.dll</HintPath> <HintPath>..\packages\Xamarin.GooglePlayServices.Drive.27.0.0.0\lib\MonoAndroid41\Xamarin.GooglePlayServices.Drive.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Xamarin.Insights">
<HintPath>..\packages\Xamarin.Insights.1.11.3\lib\MonoAndroid10\Xamarin.Insights.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="addons\OtpKeyProv\EncodingUtil.cs" /> <Compile Include="addons\OtpKeyProv\EncodingUtil.cs" />
@ -1666,4 +1670,11 @@
<AndroidResource Include="Resources\drawable-mdpi\ic_fp_40px.png" /> <AndroidResource Include="Resources\drawable-mdpi\ic_fp_40px.png" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="..\packages\Xamarin.Insights.1.11.3\build\MonoAndroid10\Xamarin.Insights.targets" Condition="Exists('..\packages\Xamarin.Insights.1.11.3\build\MonoAndroid10\Xamarin.Insights.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Aktivieren Sie die Wiederherstellung von NuGet-Paketen, um die fehlende Datei herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Xamarin.Insights.1.11.3\build\MonoAndroid10\Xamarin.Insights.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Xamarin.Insights.1.11.3\build\MonoAndroid10\Xamarin.Insights.targets'))" />
</Target>
</Project> </Project>

View File

@ -7,4 +7,5 @@
<package id="Xamarin.GooglePlayServices.Base" version="27.0.0.0" targetFramework="MonoAndroid50" /> <package id="Xamarin.GooglePlayServices.Base" version="27.0.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.GooglePlayServices.Basement" version="27.0.0.0" targetFramework="MonoAndroid50" /> <package id="Xamarin.GooglePlayServices.Basement" version="27.0.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.GooglePlayServices.Drive" version="27.0.0.0" targetFramework="MonoAndroid50" /> <package id="Xamarin.GooglePlayServices.Drive" version="27.0.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.Insights" version="1.11.3" targetFramework="MonoAndroid60" />
</packages> </packages>

View File

@ -87,7 +87,7 @@ namespace keepass2android.search
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.Log("Failed to search for suggestions: " + e.Message); Kp2aLog.LogUnexpectedError(new Exception("Failed to search for suggestions", e));
} }
} }
break; break;

View File

@ -100,7 +100,7 @@ namespace keepass2android.search
try { try {
Group = App.Kp2a.GetDb().Search (searchParams, null); Group = App.Kp2a.GetDb().Search (searchParams, null);
} catch (Exception e) { } catch (Exception e) {
Kp2aLog.Log(e.ToString()); Kp2aLog.LogUnexpectedError(e);
Toast.MakeText(this,e.Message, ToastLength.Long).Show(); Toast.MakeText(this,e.Message, ToastLength.Long).Show();
Finish(); Finish();
return; return;

View File

@ -385,7 +385,7 @@ namespace keepass2android
} }
catch (Exception ex) catch (Exception ex)
{ {
Kp2aLog.Log(ex.ToString()); Kp2aLog.LogUnexpectedError(ex);
} }
@ -428,7 +428,7 @@ namespace keepass2android
} }
catch (Exception ex) catch (Exception ex)
{ {
Kp2aLog.Log(ex.ToString()); Kp2aLog.LogUnexpectedError(ex);
} }
@ -553,7 +553,7 @@ namespace keepass2android
} }
catch (Exception ex) catch (Exception ex)
{ {
Kp2aLog.Log(ex.ToString()); Kp2aLog.LogUnexpectedError(ex);
} }
} }
@ -585,7 +585,7 @@ namespace keepass2android
} }
catch (Exception ex) catch (Exception ex)
{ {
Kp2aLog.Log(ex.ToString()); Kp2aLog.LogUnexpectedError(ex);
Toast.MakeText(Application.Context, ex.Message, ToastLength.Long).Show(); Toast.MakeText(Application.Context, ex.Message, ToastLength.Long).Show();
} }
} }