code cleanup
This commit is contained in:
@@ -21,100 +21,6 @@ using File = System.IO.File;
|
|||||||
|
|
||||||
namespace keepass2android
|
namespace keepass2android
|
||||||
{
|
{
|
||||||
|
|
||||||
public static class Kp2aLog
|
|
||||||
{
|
|
||||||
private static bool? _logToFile;
|
|
||||||
|
|
||||||
private static object _fileLocker = new object();
|
|
||||||
|
|
||||||
public static void Log(string message)
|
|
||||||
{
|
|
||||||
if (message != null)
|
|
||||||
Android.Util.Log.Debug("KP2A", message);
|
|
||||||
if (LogToFile)
|
|
||||||
{
|
|
||||||
lock (_fileLocker)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var streamWriter = System.IO.File.AppendText(LogFilename))
|
|
||||||
{
|
|
||||||
string stringToLog = DateTime.Now + ":" + DateTime.Now.Millisecond + " -- " + message;
|
|
||||||
streamWriter.WriteLine(stringToLog);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Android.Util.Log.Debug("KP2A", "Couldn't write to log file. " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string LogFilename
|
|
||||||
{
|
|
||||||
get { return Application.Context.FilesDir.CanonicalPath + "/keepass2android.log"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool LogToFile
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_logToFile == null)
|
|
||||||
_logToFile = System.IO.File.Exists(LogFilename);
|
|
||||||
return (bool)_logToFile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static event EventHandler<Exception> OnUnexpectedError;
|
|
||||||
|
|
||||||
public static void LogUnexpectedError(Exception exception)
|
|
||||||
{
|
|
||||||
Log(exception.ToString());
|
|
||||||
if (OnUnexpectedError != null)
|
|
||||||
OnUnexpectedError(null, exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void CreateLogFile()
|
|
||||||
{
|
|
||||||
if (!System.IO.File.Exists(LogFilename))
|
|
||||||
{
|
|
||||||
System.IO.File.Create(LogFilename).Dispose();
|
|
||||||
_logToFile = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void FinishLogFile()
|
|
||||||
{
|
|
||||||
if (System.IO.File.Exists(LogFilename))
|
|
||||||
{
|
|
||||||
_logToFile = false;
|
|
||||||
int count = 0;
|
|
||||||
while (System.IO.File.Exists(LogFilename + "." + count))
|
|
||||||
count++;
|
|
||||||
System.IO.File.Move(LogFilename, LogFilename + "." + count);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SendLog(Context ctx)
|
|
||||||
{
|
|
||||||
if (!System.IO.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..."));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public interface IBiometricAuthCallback
|
public interface IBiometricAuthCallback
|
||||||
{
|
{
|
||||||
void OnBiometricAuthSucceeded();
|
void OnBiometricAuthSucceeded();
|
||||||
@@ -215,6 +121,7 @@ namespace keepass2android
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
var result = BiometricManager.From(Activity).CanAuthenticate();
|
var result = BiometricManager.From(Activity).CanAuthenticate();
|
||||||
|
Kp2aLog.Log("BiometricHardware available = " + result);
|
||||||
return result == BiometricManager.BiometricSuccess
|
return result == BiometricManager.BiometricSuccess
|
||||||
|| result == BiometricManager.BiometricErrorNoneEnrolled;
|
|| result == BiometricManager.BiometricErrorNoneEnrolled;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -463,7 +463,7 @@ namespace keepass2android
|
|||||||
new AlertDialog.Builder(this)
|
new AlertDialog.Builder(this)
|
||||||
.SetTitle(Resource.String.autofill_enable)
|
.SetTitle(Resource.String.autofill_enable)
|
||||||
.SetMessage(Resource.String.autofill_enable_failed)
|
.SetMessage(Resource.String.autofill_enable_failed)
|
||||||
.SetPositiveButton(Resource.String.ok, (o, eventArgs) => { })
|
.SetPositiveButton(Resource.String.Ok, (o, eventArgs) => { })
|
||||||
.Show();
|
.Show();
|
||||||
const string autofillservicewasenabled = "AutofillServiceWasEnabled";
|
const string autofillservicewasenabled = "AutofillServiceWasEnabled";
|
||||||
_prefs.Edit().PutBoolean(autofillservicewasenabled, true).Commit();
|
_prefs.Edit().PutBoolean(autofillservicewasenabled, true).Commit();
|
||||||
|
|||||||
Reference in New Issue
Block a user