logging controllable through preferences, option to send logged data

This commit is contained in:
Philipp Crocoll
2017-10-16 12:57:30 +02:00
parent c7bad6f9a0
commit 82fa7eaf9f
5 changed files with 95 additions and 6 deletions

View File

@@ -18,6 +18,9 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll.
using System;
using System.Collections.Generic;
using System.IO;
using Android;
using Android.App;
using Android.Content;
using Android.Preferences;
using KeePassLib.Serialization;
@@ -57,7 +60,7 @@ namespace keepass2android
private static string LogFilename
{
get { return "/mnt/sdcard/keepass2android.log"; }
get { return Application.Context.FilesDir.CanonicalPath +"/keepass2android.log"; }
}
private static bool LogToFile
@@ -77,5 +80,43 @@ namespace keepass2android
if (OnUnexpectedError != null)
OnUnexpectedError(null, exception);
}
public static void CreateLogFile()
{
if (!File.Exists(LogFilename))
{
File.Create(LogFilename);
_logToFile = true;
}
}
public static void FinishLogFile()
{
if (File.Exists(LogFilename))
{
_logToFile = false;
int count = 0;
while (File.Exists(LogFilename + "." + count))
count++;
File.Move(LogFilename, LogFilename + "." + count);
}
}
public static void SendLog(Context ctx)
{
if (!File.Exists(LogFilename))
return;
Intent sendIntent = new Intent();
sendIntent.SetAction(Intent.ActionSend);
sendIntent.PutExtra(Intent.ExtraText, File.ReadAllText(LogFilename));
sendIntent.PutExtra(Intent.ExtraEmail, "crocoapps@gmail.com");
sendIntent.PutExtra(Intent.ExtraSubject, "Keepass2Android log");
sendIntent.SetType("text/plain");
ctx.StartActivity(Intent.CreateChooser(sendIntent, "Send log to..."));
}
}
}

View File

@@ -86,7 +86,9 @@
<string name="TrayTotp_SettingsField_key">TrayTotp_SettingsField_key</string>
<string name="TrayTotp_SeedField_key">TrayTotp_SeedField_key</string>
<string name="TrayTotp_prefs_key">TrayTotp_prefs_key</string>
<string name="DebugLog_key">DebugLog_key</string>
<string name="DebugLog_prefs_key">DebugLog_prefs_key</string>
<string name="DebugLog_send_key">DebugLog_send</string>
<string name="password_access_prefs_key">password_access_prefs_key</string>
<string name="security_prefs_key">security_prefs_key</string>

View File

@@ -552,8 +552,16 @@
<string name="TrayTotp_SettingsField_summary">Enter the field name of the settings field for TrayTotp here.</string>
<string name="TrayTotp_prefs">TrayTotp</string>
<string name="DebugLog_prefs_prefs">Log-File for Debugging</string>
<string name="DebugLog_title">Use log file</string>
<string name="DebugLog_summary">Write app output to a local log file</string>
<string name="DebugLog_send">Send debug log...</string>
<string name="loading">Loading…</string>
<string name="loading">Loading…</string>
<string name="plugins">Plug-ins</string>
<string name="plugin_packagename">Package name:</string>

View File

@@ -510,10 +510,27 @@
android:title="@string/TrayTotp_SettingsField_title"
android:key="@string/TrayTotp_SettingsField_key" />
</PreferenceScreen>
</PreferenceScreen>
<PreferenceScreen
android:key="@string/DebugLog_prefs_key"
android:title="@string/DebugLog_prefs_prefs"
>
<CheckBoxPreference
android:enabled="true"
android:persistent="true"
android:summary="@string/DebugLog_summary"
android:defaultValue="false"
android:title="@string/DebugLog_title"
android:key="@string/DebugLog_key" />
<Preference
android:enabled="true"
android:title="@string/DebugLog_send"
android:key="@string/DebugLog_send_key" />
</PreferenceScreen>
</PreferenceScreen>
<PreferenceScreen android:key="plugin_key" android:title="@string/plugins">
<intent android:action="kp2a.action.PluginListActivity"/>
</PreferenceScreen>

View File

@@ -356,6 +356,9 @@ namespace keepass2android
// Re-use the change handlers for the application settings
FindPreference(GetString(Resource.String.keyfile_key)).PreferenceChange += OnRememberKeyFileHistoryChanged;
FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)).PreferenceChange += OnShowUnlockedNotificationChanged;
FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)).PreferenceChange += OnShowUnlockedNotificationChanged;
FindPreference(GetString(Resource.String.DebugLog_key)).PreferenceChange += OnDebugLogChanged;
FindPreference(GetString(Resource.String.DebugLog_send_key)).PreferenceClick += OnSendDebug;
PrepareNoDonatePreference(Activity, FindPreference(GetString(Resource.String.NoDonateOption_key)));
PrepareNoDonationReminderPreference(Activity, ((PreferenceScreen)FindPreference(GetString(Resource.String.display_prefs_key))), FindPreference(GetString(Resource.String.NoDonationReminder_key)));
@@ -447,6 +450,24 @@ namespace keepass2android
}
private void OnSendDebug(object sender, Preference.PreferenceClickEventArgs e)
{
Kp2aLog.SendLog(this.Activity);
}
private void OnDebugLogChanged(object sender, Preference.PreferenceChangeEventArgs e)
{
if ((bool)e.NewValue)
{
Kp2aLog.CreateLogFile();
}
else
{
Kp2aLog.FinishLogFile();
}
}
private void AlgorithmPrefChange(object sender, Preference.PreferenceChangeEventArgs preferenceChangeEventArgs)
{
var db = App.Kp2a.GetDb();