Remove debugging delay, ensure prompt GC of memory used when loading DB

This commit is contained in:
AlexVallat 2013-08-04 09:38:15 +01:00
parent f0dfdefd67
commit 518479904a

View File

@ -270,8 +270,7 @@ namespace keepass2android
Window.SetSoftInputMode(SoftInput.StateVisible); Window.SetSoftInputMode(SoftInput.StateVisible);
Button confirmButton = (Button)FindViewById(Resource.Id.pass_ok); Button confirmButton = (Button)FindViewById(Resource.Id.pass_ok);
confirmButton.Click += (sender, e) => confirmButton.Click += (sender, e) => {
{
String pass = GetEditText(Resource.Id.password); String pass = GetEditText(Resource.Id.password);
String key = GetEditText(Resource.Id.pass_keyfile); String key = GetEditText(Resource.Id.pass_keyfile);
if (pass.Length == 0 && key.Length == 0) if (pass.Length == 0 && key.Length == 0)
@ -287,8 +286,7 @@ namespace keepass2android
LoadDb task = new LoadDb(App.Kp2a, _ioConnection, _loadDbTask, pass, key, new AfterLoad(handler, this)); LoadDb task = new LoadDb(App.Kp2a, _ioConnection, _loadDbTask, pass, key, new AfterLoad(handler, this));
_loadDbTask = null; // prevent accidental re-use _loadDbTask = null; // prevent accidental re-use
ProgressTask pt = new ProgressTask(App.Kp2a, this, task); new ProgressTask(App.Kp2a, this, task).Run();
pt.Run();
}; };
/*CheckBox checkBox = (CheckBox) FindViewById(Resource.Id.show_password); /*CheckBox checkBox = (CheckBox) FindViewById(Resource.Id.show_password);
@ -396,13 +394,11 @@ namespace keepass2android
capacity = (int)stream.Length; capacity = (int)stream.Length;
} }
memoryStream = new MemoryStream(capacity); memoryStream = new MemoryStream(capacity);
MemUtil.CopyStream(stream, memoryStream); stream.CopyTo(memoryStream);
stream.Close(); stream.Close();
memoryStream.Seek(0, System.IO.SeekOrigin.Begin); memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
} }
System.Threading.Thread.Sleep(3000);
Kp2aLog.Log("Pre-loading database file completed"); Kp2aLog.Log("Pre-loading database file completed");
return memoryStream; return memoryStream;
@ -514,17 +510,24 @@ namespace keepass2android
private class AfterLoad : OnFinish { private class AfterLoad : OnFinish {
readonly PasswordActivity _act; readonly PasswordActivity _act;
public AfterLoad(Handler handler, PasswordActivity act):base(handler) {
public AfterLoad(Handler handler, PasswordActivity act):base(handler)
{
_act = act; _act = act;
} }
public override void Run() { public override void Run() {
if ( Success ) { if ( Success )
{
_act.SetEditText(Resource.Id.password, ""); _act.SetEditText(Resource.Id.password, "");
_act.LaunchNextActivity(); _act.LaunchNextActivity();
} else {
GC.Collect(); // Ensure temporary memory used while loading is collected - it will contain sensitive data such as username and password, and also the large data of the encrypted database file
}
else
{
DisplayMessage(_act); DisplayMessage(_act);
} }
} }