mirror of
https://github.com/moparisthebest/keepass2android
synced 2025-03-03 10:21:44 -05:00
Add strings for db actions
Broadcast database actions
This commit is contained in:
parent
87fe6abd38
commit
85fb4ba9f8
Binary file not shown.
@ -20,12 +20,13 @@ public abstract class PluginActionBroadcastReceiver extends BroadcastReceiver {
|
||||
protected Context _context;
|
||||
protected Intent _intent;
|
||||
|
||||
public PluginActionBase(Context context, Intent intent)
|
||||
|
||||
public PluginActionBase(Context context, Intent intent)
|
||||
{
|
||||
_context = context;
|
||||
_intent = intent;
|
||||
}
|
||||
|
||||
|
||||
public String getHostPackage() {
|
||||
return _intent.getStringExtra(Strings.EXTRA_SENDER);
|
||||
}
|
||||
@ -35,6 +36,16 @@ public abstract class PluginActionBroadcastReceiver extends BroadcastReceiver {
|
||||
return _context;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected abstract class PluginEntryActionBase extends PluginActionBase
|
||||
{
|
||||
|
||||
public PluginEntryActionBase(Context context, Intent intent)
|
||||
{
|
||||
super(context, intent);
|
||||
}
|
||||
|
||||
protected HashMap<String, String> getEntryFieldsFromIntent()
|
||||
{
|
||||
HashMap<String, String> res = new HashMap<String, String>();
|
||||
@ -60,7 +71,7 @@ public abstract class PluginActionBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
}
|
||||
|
||||
protected class ActionSelected extends PluginActionBase
|
||||
protected class ActionSelected extends PluginEntryActionBase
|
||||
{
|
||||
public ActionSelected(Context ctx, Intent intent) {
|
||||
super(ctx, intent);
|
||||
@ -114,7 +125,7 @@ public abstract class PluginActionBroadcastReceiver extends BroadcastReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
protected class CloseEntryView extends PluginActionBase
|
||||
protected class CloseEntryView extends PluginEntryActionBase
|
||||
{
|
||||
public CloseEntryView(Context context, Intent intent) {
|
||||
super(context, intent);
|
||||
@ -126,7 +137,7 @@ public abstract class PluginActionBroadcastReceiver extends BroadcastReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
protected class OpenEntry extends PluginActionBase
|
||||
protected class OpenEntry extends PluginEntryActionBase
|
||||
{
|
||||
|
||||
public OpenEntry(Context context, Intent intent)
|
||||
@ -195,6 +206,29 @@ public abstract class PluginActionBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
}
|
||||
|
||||
protected class DatabaseAction extends PluginActionBase
|
||||
{
|
||||
|
||||
public DatabaseAction(Context context, Intent intent) {
|
||||
super(context, intent);
|
||||
}
|
||||
|
||||
public String getFileDisplayName()
|
||||
{
|
||||
return _intent.getStringExtra(Strings.EXTRA_DATABASE_FILE_DISPLAYNAME);
|
||||
}
|
||||
|
||||
public String getFilePath()
|
||||
{
|
||||
return _intent.getStringExtra(Strings.EXTRA_DATABASE_FILEPATH);
|
||||
}
|
||||
|
||||
public String getAction()
|
||||
{
|
||||
return _intent.getAction();
|
||||
}
|
||||
|
||||
}
|
||||
//EntryOutputModified is very similar to OpenEntry because it receives the same
|
||||
//data (+ the field id which was modified)
|
||||
protected class EntryOutputModified extends OpenEntry
|
||||
@ -233,6 +267,13 @@ public abstract class PluginActionBroadcastReceiver extends BroadcastReceiver {
|
||||
{
|
||||
entryOutputModified(new EntryOutputModified(ctx, intent));
|
||||
}
|
||||
else if (action.equals(Strings.ACTION_LOCK_DATABASE)
|
||||
|| action.equals(Strings.ACTION_UNLOCK_DATABASE)
|
||||
|| action.equals(Strings.ACTION_OPEN_DATABASE)
|
||||
|| action.equals(Strings.ACTION_CLOSE_DATABASE))
|
||||
{
|
||||
databaseAction(new DatabaseAction(ctx, intent));
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO handle unexpected action
|
||||
@ -248,5 +289,7 @@ public abstract class PluginActionBroadcastReceiver extends BroadcastReceiver {
|
||||
protected void openEntry(OpenEntry oe) {}
|
||||
|
||||
protected void entryOutputModified(EntryOutputModified eom) {}
|
||||
|
||||
protected void databaseAction(DatabaseAction db) {}
|
||||
|
||||
}
|
||||
|
@ -164,6 +164,21 @@ public class Strings {
|
||||
*/
|
||||
public static final String ACTION_SET_ENTRY_FIELD = "keepass2android.ACTION_SET_ENTRY_FIELD";
|
||||
|
||||
/** Actions for an intent from KP2A to the plugin to inform that a database was opened, closed, quicklocked or quickunlocked.*/
|
||||
public static final String ACTION_OPEN_DATABASE = "keepass2android.ACTION_OPEN_DATABASE";
|
||||
public static final String ACTION_CLOSE_DATABASE = "keepass2android.ACTION_CLOSE_DATABASE";
|
||||
public static final String ACTION_LOCK_DATABASE = "keepass2android.ACTION_LOCK_DATABASE";
|
||||
public static final String ACTION_UNLOCK_DATABASE = "keepass2android.ACTION_UNLOCK_DATABASE";
|
||||
|
||||
/** Extra for ACTION_OPEN_DATABASE and ACTION_CLOSE_DATABASE containing a filepath which is used
|
||||
* by KP2A internally to identify the file. Use only where necessary, might contain credentials
|
||||
* for accessing the file (on remote storage).*/
|
||||
public static final String EXTRA_DATABASE_FILEPATH = "keepass2android.EXTRA_DATABASE_FILEPATH";
|
||||
/** Extra for ACTION_OPEN_DATABASE and ACTION_CLOSE_DATABASE containing a filepath which can be
|
||||
* displayed to the user.*/
|
||||
public static final String EXTRA_DATABASE_FILE_DISPLAYNAME = "keepass2android.EXTRA_DATABASE_FILE_DISPLAYNAME";
|
||||
|
||||
|
||||
public static final String EXTRA_FIELD_VALUE = "keepass2android.EXTRA_FIELD_VALUE";
|
||||
public static final String EXTRA_FIELD_PROTECTED = "keepass2android.EXTRA_FIELD_PROTECTED";
|
||||
|
||||
|
@ -35,6 +35,7 @@ using Android.Content.PM;
|
||||
using KeePassLib.Keys;
|
||||
using KeePassLib.Serialization;
|
||||
using KeePassLib.Utility;
|
||||
using Keepass2android.Pluginsdk;
|
||||
using OtpKeyProv;
|
||||
using keepass2android.Io;
|
||||
using keepass2android.Utils;
|
||||
@ -1293,6 +1294,8 @@ namespace keepass2android
|
||||
|
||||
_act.LaunchNextActivity();
|
||||
|
||||
_act.BroadcastOpenDatabase();
|
||||
|
||||
|
||||
GC.Collect(); // Ensure temporary memory used while loading is collected
|
||||
}
|
||||
@ -1303,6 +1306,11 @@ namespace keepass2android
|
||||
}
|
||||
}
|
||||
|
||||
private void BroadcastOpenDatabase()
|
||||
{
|
||||
App.Kp2a.BroadcastDatabaseAction(this, Strings.ActionOpenDatabase);
|
||||
}
|
||||
|
||||
private void ClearEnteredPassword()
|
||||
{
|
||||
SetEditText(Resource.Id.password, "");
|
||||
|
@ -44,7 +44,7 @@ namespace keepass2android
|
||||
}
|
||||
|
||||
public static void GotoUrl(Context context, String url) {
|
||||
if ( url != null && url.Length > 0 ) {
|
||||
if ( !string.IsNullOrEmpty(url) ) {
|
||||
|
||||
if (url.StartsWith("androidapp://"))
|
||||
{
|
||||
|
@ -34,6 +34,7 @@ using Android.Preferences;
|
||||
#if !EXCLUDE_TWOFISH
|
||||
using TwofishCipher;
|
||||
#endif
|
||||
using Keepass2android.Pluginsdk;
|
||||
using keepass2android.Io;
|
||||
using keepass2android.addons.OtpKeyProv;
|
||||
|
||||
@ -96,6 +97,7 @@ namespace keepass2android
|
||||
if (!QuickLocked)
|
||||
{
|
||||
Kp2aLog.Log("QuickLocking database");
|
||||
BroadcastDatabaseAction(Application.Context, Strings.ActionLockDatabase);
|
||||
|
||||
QuickLocked = true;
|
||||
}
|
||||
@ -108,6 +110,8 @@ namespace keepass2android
|
||||
{
|
||||
Kp2aLog.Log("Locking database");
|
||||
|
||||
BroadcastDatabaseAction(Application.Context, Strings.ActionCloseDatabase);
|
||||
|
||||
// Couldn't quick-lock, so unload database instead
|
||||
_db.Clear();
|
||||
QuickLocked = false;
|
||||
@ -122,6 +126,21 @@ namespace keepass2android
|
||||
Application.Context.SendBroadcast(new Intent(Intents.DatabaseLocked));
|
||||
}
|
||||
|
||||
|
||||
public void BroadcastDatabaseAction(Context ctx, string action)
|
||||
{
|
||||
Intent i = new Intent(action);
|
||||
i.PutExtra(Strings.ExtraDatabaseFileDisplayname, App.Kp2a.GetFileStorage(App.Kp2a.GetDb().Ioc).GetDisplayName(App.Kp2a.GetDb().Ioc));
|
||||
i.PutExtra(Strings.ExtraDatabaseFilepath, App.Kp2a.GetDb().Ioc.Path);
|
||||
foreach (var plugin in new PluginDatabase(ctx).GetPluginsWithAcceptedScope(Strings.ScopeDatabaseActions))
|
||||
{
|
||||
i.SetPackage(plugin);
|
||||
ctx.SendBroadcast(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void LoadDatabase(IOConnectionInfo ioConnectionInfo, MemoryStream memoryStream, CompositeKey compositeKey, ProgressDialogStatusLogger statusLogger, IDatabaseLoader databaseLoader)
|
||||
{
|
||||
_db.LoadData(this, ioConnectionInfo, memoryStream, compositeKey, statusLogger, databaseLoader);
|
||||
@ -134,6 +153,8 @@ namespace keepass2android
|
||||
QuickLocked = false;
|
||||
|
||||
UpdateOngoingNotification();
|
||||
|
||||
BroadcastDatabaseAction(Application.Context, Strings.ActionUnlockDatabase);
|
||||
}
|
||||
|
||||
public void UpdateOngoingNotification()
|
||||
|
Loading…
x
Reference in New Issue
Block a user