logging controllable through preferences, option to send logged data
This commit is contained in:
@@ -18,6 +18,9 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll.
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Android;
|
||||||
|
using Android.App;
|
||||||
|
using Android.Content;
|
||||||
using Android.Preferences;
|
using Android.Preferences;
|
||||||
using KeePassLib.Serialization;
|
using KeePassLib.Serialization;
|
||||||
|
|
||||||
@@ -57,7 +60,7 @@ namespace keepass2android
|
|||||||
|
|
||||||
private static string LogFilename
|
private static string LogFilename
|
||||||
{
|
{
|
||||||
get { return "/mnt/sdcard/keepass2android.log"; }
|
get { return Application.Context.FilesDir.CanonicalPath +"/keepass2android.log"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool LogToFile
|
private static bool LogToFile
|
||||||
@@ -77,5 +80,43 @@ namespace keepass2android
|
|||||||
if (OnUnexpectedError != null)
|
if (OnUnexpectedError != null)
|
||||||
OnUnexpectedError(null, exception);
|
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..."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,9 @@
|
|||||||
<string name="TrayTotp_SettingsField_key">TrayTotp_SettingsField_key</string>
|
<string name="TrayTotp_SettingsField_key">TrayTotp_SettingsField_key</string>
|
||||||
<string name="TrayTotp_SeedField_key">TrayTotp_SeedField_key</string>
|
<string name="TrayTotp_SeedField_key">TrayTotp_SeedField_key</string>
|
||||||
<string name="TrayTotp_prefs_key">TrayTotp_prefs_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="password_access_prefs_key">password_access_prefs_key</string>
|
||||||
<string name="security_prefs_key">security_prefs_key</string>
|
<string name="security_prefs_key">security_prefs_key</string>
|
||||||
|
|||||||
@@ -552,6 +552,14 @@
|
|||||||
<string name="TrayTotp_SettingsField_summary">Enter the field name of the settings field for TrayTotp here.</string>
|
<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="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>
|
||||||
|
|
||||||
|
|||||||
@@ -511,8 +511,25 @@
|
|||||||
android:key="@string/TrayTotp_SettingsField_key" />
|
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>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<PreferenceScreen android:key="plugin_key" android:title="@string/plugins">
|
<PreferenceScreen android:key="plugin_key" android:title="@string/plugins">
|
||||||
<intent android:action="kp2a.action.PluginListActivity"/>
|
<intent android:action="kp2a.action.PluginListActivity"/>
|
||||||
|
|||||||
@@ -356,6 +356,9 @@ namespace keepass2android
|
|||||||
// Re-use the change handlers for the application settings
|
// Re-use the change handlers for the application settings
|
||||||
FindPreference(GetString(Resource.String.keyfile_key)).PreferenceChange += OnRememberKeyFileHistoryChanged;
|
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.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)));
|
PrepareNoDonatePreference(Activity, FindPreference(GetString(Resource.String.NoDonateOption_key)));
|
||||||
PrepareNoDonationReminderPreference(Activity, ((PreferenceScreen)FindPreference(GetString(Resource.String.display_prefs_key))), FindPreference(GetString(Resource.String.NoDonationReminder_key)));
|
PrepareNoDonationReminderPreference(Activity, ((PreferenceScreen)FindPreference(GetString(Resource.String.display_prefs_key))), FindPreference(GetString(Resource.String.NoDonationReminder_key)));
|
||||||
|
|
||||||
@@ -445,6 +448,24 @@ namespace keepass2android
|
|||||||
cachingPreference.PreferenceChange += OnUseOfflineCacheChanged;
|
cachingPreference.PreferenceChange += OnUseOfflineCacheChanged;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
private void AlgorithmPrefChange(object sender, Preference.PreferenceChangeEventArgs preferenceChangeEventArgs)
|
||||||
|
|||||||
Reference in New Issue
Block a user