|
|
|
@@ -29,10 +29,12 @@ using KeePassLib.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace keepass2android
|
|
|
|
|
{
|
|
|
|
|
[Activity (Label = "@string/app_name", ConfigurationChanges=ConfigChanges.Orientation|ConfigChanges.KeyboardHidden, Theme="@style/Base")]
|
|
|
|
|
[Activity(Label = "@string/app_name", ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
|
|
|
|
|
Theme = "@style/Base")]
|
|
|
|
|
public class QuickUnlock : LifecycleDebugActivity
|
|
|
|
|
{
|
|
|
|
|
IOConnectionInfo _ioc;
|
|
|
|
|
private IOConnectionInfo _ioc;
|
|
|
|
|
private QuickUnlockBroadcastReceiver _intentReceiver;
|
|
|
|
|
|
|
|
|
|
protected override void OnCreate(Bundle bundle)
|
|
|
|
|
{
|
|
|
|
@@ -52,70 +54,98 @@ namespace keepass2android
|
|
|
|
|
if (App.Kp2a.GetDb().KpDatabase.Name != "")
|
|
|
|
|
{
|
|
|
|
|
FindViewById(Resource.Id.filename_label).Visibility = ViewStates.Invisible;
|
|
|
|
|
((TextView)FindViewById(Resource.Id.qu_filename)).Text = App.Kp2a.GetDb().KpDatabase.Name;
|
|
|
|
|
} else
|
|
|
|
|
((TextView) FindViewById(Resource.Id.qu_filename)).Text = App.Kp2a.GetDb().KpDatabase.Name;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (
|
|
|
|
|
PreferenceManager.GetDefaultSharedPreferences(this)
|
|
|
|
|
.GetBoolean(GetString(Resource.String.RememberRecentFiles_key),
|
|
|
|
|
Resources.GetBoolean(Resource.Boolean.RememberRecentFiles_default)))
|
|
|
|
|
.GetBoolean(GetString(Resource.String.RememberRecentFiles_key),
|
|
|
|
|
Resources.GetBoolean(Resource.Boolean.RememberRecentFiles_default)))
|
|
|
|
|
{
|
|
|
|
|
((TextView)FindViewById(Resource.Id.qu_filename)).Text = App.Kp2a.GetFileStorage(_ioc).GetDisplayName(_ioc);
|
|
|
|
|
((TextView) FindViewById(Resource.Id.qu_filename)).Text = App.Kp2a.GetFileStorage(_ioc).GetDisplayName(_ioc);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
((TextView)FindViewById(Resource.Id.qu_filename)).Text = "*****";
|
|
|
|
|
((TextView) FindViewById(Resource.Id.qu_filename)).Text = "*****";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TextView txtLabel = (TextView)FindViewById(Resource.Id.QuickUnlock_label);
|
|
|
|
|
TextView txtLabel = (TextView) FindViewById(Resource.Id.QuickUnlock_label);
|
|
|
|
|
|
|
|
|
|
int quickUnlockLength = App.Kp2a.QuickUnlockKeyLength;
|
|
|
|
|
|
|
|
|
|
txtLabel.Text = GetString(Resource.String.QuickUnlock_label, new Java.Lang.Object[]{quickUnlockLength});
|
|
|
|
|
txtLabel.Text = GetString(Resource.String.QuickUnlock_label, new Java.Lang.Object[] {quickUnlockLength});
|
|
|
|
|
|
|
|
|
|
EditText pwd= (EditText)FindViewById(Resource.Id.QuickUnlock_password);
|
|
|
|
|
EditText pwd = (EditText) FindViewById(Resource.Id.QuickUnlock_password);
|
|
|
|
|
pwd.SetEms(quickUnlockLength);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Button btnUnlock = (Button)FindViewById(Resource.Id.QuickUnlock_button);
|
|
|
|
|
btnUnlock.Click += (object sender, EventArgs e) =>
|
|
|
|
|
{
|
|
|
|
|
KcpPassword kcpPassword = (KcpPassword)App.Kp2a.GetDb().KpDatabase.MasterKey.GetUserKey(typeof(KcpPassword));
|
|
|
|
|
String password = kcpPassword.Password.ReadString();
|
|
|
|
|
String expectedPasswordPart = password.Substring(Math.Max(0,password.Length-quickUnlockLength),Math.Min(password.Length, quickUnlockLength));
|
|
|
|
|
if (pwd.Text == expectedPasswordPart)
|
|
|
|
|
Button btnUnlock = (Button) FindViewById(Resource.Id.QuickUnlock_button);
|
|
|
|
|
btnUnlock.Click += (object sender, EventArgs e) =>
|
|
|
|
|
{
|
|
|
|
|
App.Kp2a.UnlockDatabase();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
KcpPassword kcpPassword = (KcpPassword) App.Kp2a.GetDb().KpDatabase.MasterKey.GetUserKey(typeof (KcpPassword));
|
|
|
|
|
String password = kcpPassword.Password.ReadString();
|
|
|
|
|
String expectedPasswordPart = password.Substring(Math.Max(0, password.Length - quickUnlockLength),
|
|
|
|
|
Math.Min(password.Length, quickUnlockLength));
|
|
|
|
|
if (pwd.Text == expectedPasswordPart)
|
|
|
|
|
{
|
|
|
|
|
App.Kp2a.UnlockDatabase();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
App.Kp2a.LockDatabase(false);
|
|
|
|
|
Toast.MakeText(this, GetString(Resource.String.QuickUnlock_fail), ToastLength.Long).Show();
|
|
|
|
|
}
|
|
|
|
|
Finish();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Button btnLock = (Button) FindViewById(Resource.Id.QuickUnlock_buttonLock);
|
|
|
|
|
btnLock.Click += (object sender, EventArgs e) =>
|
|
|
|
|
{
|
|
|
|
|
App.Kp2a.LockDatabase(false);
|
|
|
|
|
Toast.MakeText(this, GetString(Resource.String.QuickUnlock_fail), ToastLength.Long).Show();
|
|
|
|
|
}
|
|
|
|
|
Finish();
|
|
|
|
|
};
|
|
|
|
|
Finish();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Button btnLock = (Button)FindViewById(Resource.Id.QuickUnlock_buttonLock);
|
|
|
|
|
btnLock.Click += (object sender, EventArgs e) =>
|
|
|
|
|
{
|
|
|
|
|
App.Kp2a.LockDatabase(false);
|
|
|
|
|
Finish();
|
|
|
|
|
};
|
|
|
|
|
_intentReceiver = new QuickUnlockBroadcastReceiver(this);
|
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
|
filter.AddAction(Intents.DatabaseLocked);
|
|
|
|
|
RegisterReceiver(_intentReceiver, filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnLockDatabase()
|
|
|
|
|
{
|
|
|
|
|
CheckIfUnloaded();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnResume()
|
|
|
|
|
{
|
|
|
|
|
base.OnResume();
|
|
|
|
|
|
|
|
|
|
EditText pwd = (EditText)FindViewById(Resource.Id.QuickUnlock_password);
|
|
|
|
|
CheckIfUnloaded();
|
|
|
|
|
|
|
|
|
|
EditText pwd = (EditText) FindViewById(Resource.Id.QuickUnlock_password);
|
|
|
|
|
pwd.PostDelayed(() =>
|
|
|
|
|
{
|
|
|
|
|
InputMethodManager keyboard = (InputMethodManager) GetSystemService(Context.InputMethodService);
|
|
|
|
|
keyboard.ShowSoftInput(pwd, 0);
|
|
|
|
|
}, 50);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
base.OnDestroy();
|
|
|
|
|
UnregisterReceiver(_intentReceiver);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckIfUnloaded()
|
|
|
|
|
{
|
|
|
|
|
if ((App.Kp2a.GetDb() == null) || (App.Kp2a.GetDb().Loaded == false))
|
|
|
|
|
{
|
|
|
|
|
InputMethodManager keyboard = (InputMethodManager)GetSystemService(Context.InputMethodService);
|
|
|
|
|
keyboard.ShowSoftInput(pwd, 0);
|
|
|
|
|
}, 50);
|
|
|
|
|
Finish();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnBackPressed()
|
|
|
|
@@ -123,6 +153,27 @@ namespace keepass2android
|
|
|
|
|
SetResult(KeePass.ExitClose);
|
|
|
|
|
base.OnBackPressed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class QuickUnlockBroadcastReceiver : BroadcastReceiver
|
|
|
|
|
{
|
|
|
|
|
readonly QuickUnlock _activity;
|
|
|
|
|
public QuickUnlockBroadcastReceiver(QuickUnlock activity)
|
|
|
|
|
{
|
|
|
|
|
_activity = activity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnReceive(Context context, Intent intent)
|
|
|
|
|
{
|
|
|
|
|
switch (intent.Action)
|
|
|
|
|
{
|
|
|
|
|
case Intents.DatabaseLocked:
|
|
|
|
|
_activity.OnLockDatabase();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|