From 82fa7eaf9f7a31dabb6f77a75170546041a14bdf Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Mon, 16 Oct 2017 12:57:30 +0200 Subject: [PATCH] logging controllable through preferences, option to send logged data --- src/KeePassLib2Android/Kp2aLog.cs | 43 ++++++++++++++++++- .../Resources/values/config.xml | 4 +- .../Resources/values/strings.xml | 10 ++++- .../Resources/xml/preferences.xml | 23 ++++++++-- .../settings/DatabaseSettingsActivity.cs | 21 +++++++++ 5 files changed, 95 insertions(+), 6 deletions(-) diff --git a/src/KeePassLib2Android/Kp2aLog.cs b/src/KeePassLib2Android/Kp2aLog.cs index 84728988..b2a5a195 100644 --- a/src/KeePassLib2Android/Kp2aLog.cs +++ b/src/KeePassLib2Android/Kp2aLog.cs @@ -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...")); + } } } \ No newline at end of file diff --git a/src/keepass2android/Resources/values/config.xml b/src/keepass2android/Resources/values/config.xml index 1eef5c9f..acb53d91 100644 --- a/src/keepass2android/Resources/values/config.xml +++ b/src/keepass2android/Resources/values/config.xml @@ -86,7 +86,9 @@ TrayTotp_SettingsField_key TrayTotp_SeedField_key TrayTotp_prefs_key - + DebugLog_key + DebugLog_prefs_key + DebugLog_send password_access_prefs_key security_prefs_key diff --git a/src/keepass2android/Resources/values/strings.xml b/src/keepass2android/Resources/values/strings.xml index 426d0e13..c2a6cbca 100644 --- a/src/keepass2android/Resources/values/strings.xml +++ b/src/keepass2android/Resources/values/strings.xml @@ -552,8 +552,16 @@ Enter the field name of the settings field for TrayTotp here. TrayTotp + Log-File for Debugging + Use log file + Write app output to a local log file + Send debug log... + + - Loading… + + + Loading… Plug-ins Package name: diff --git a/src/keepass2android/Resources/xml/preferences.xml b/src/keepass2android/Resources/xml/preferences.xml index 9786aeab..aaf82f28 100644 --- a/src/keepass2android/Resources/xml/preferences.xml +++ b/src/keepass2android/Resources/xml/preferences.xml @@ -510,10 +510,27 @@ android:title="@string/TrayTotp_SettingsField_title" android:key="@string/TrayTotp_SettingsField_key" /> - - - + + + + + + + + diff --git a/src/keepass2android/settings/DatabaseSettingsActivity.cs b/src/keepass2android/settings/DatabaseSettingsActivity.cs index e4de490a..2fb17251 100644 --- a/src/keepass2android/settings/DatabaseSettingsActivity.cs +++ b/src/keepass2android/settings/DatabaseSettingsActivity.cs @@ -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();