Changelog: setCancellable(false)

AppTask: bugfix for read-only dbs
CopyToClipboardService: Can handle time-out for additional strings copied to clipboard; can update the Keyboard data
added comments
minor changes
This commit is contained in:
Philipp Crocoll 2014-05-09 13:06:47 +02:00
parent dd557cb455
commit 2849620f55
17 changed files with 106 additions and 118 deletions

View File

@ -20,7 +20,7 @@
<DebugType>full</DebugType>
<Optimize>False</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;EXCLUDE_TWOFISH;INCLUDE_KEYBOARD;INCLUDE_FILECHOOSER;INCLUDE_JAVAFILESTORAGE;INCLUDE_KEYTRANSFORM</DefineConstants>
<DefineConstants>DEBUG;EXCLUDE_TWOFISH;EXCLUDE_KEYBOARD;EXCLUDE_FILECHOOSER;EXCLUDE_JAVAFILESTORAGE;EXCLUDE_KEYTRANSFORM</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause>

View File

@ -2,7 +2,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:4.0.30319.34011
// Laufzeitversion:4.0.30319.34014
//
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// der Code erneut generiert wird.

View File

@ -20,7 +20,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;EXCLUDE_TWOFISH;INCLUDE_KEYBOARD;INCLUDE_FILECHOOSER;INCLUDE_JAVAFILESTORAGE;INCLUDE_KEYTRANSFORM</DefineConstants>
<DefineConstants>TRACE;DEBUG;EXCLUDE_TWOFISH;EXCLUDE_KEYBOARD;EXCLUDE_FILECHOOSER;EXCLUDE_JAVAFILESTORAGE;EXCLUDE_KEYTRANSFORM</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

View File

@ -2,7 +2,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:4.0.30319.34011
// Laufzeitversion:4.0.30319.34014
//
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// der Code erneut generiert wird.

View File

@ -1,63 +1,9 @@
using System;
using KeePassLib;
using KeePassLib.Collections;
using KeePassLib.Keys;
using KeePassLib.Security;
using KeePassLib.Serialization;
namespace keepass2android
{
/// <summary>
/// Represents the strings which are output from a PwEntry.
/// </summary>
/// In contrast to the original PwEntry, this means that placeholders are replaced. Also, plugins may modify
/// or add fields.
public class PwEntryOutput
{
private readonly PwEntry _entry;
private readonly PwDatabase _db;
private readonly ProtectedStringDictionary _outputStrings = new ProtectedStringDictionary();
/// <summary>
/// Constructs the PwEntryOutput by replacing the placeholders
/// </summary>
public PwEntryOutput(PwEntry entry, PwDatabase db)
{
_entry = entry;
_db = db;
foreach (var pair in entry.Strings)
{
_outputStrings.Set(pair.Key, new ProtectedString(entry.Strings.Get(pair.Key).IsProtected, GetStringAndReplacePlaceholders(pair.Key)));
}
}
string GetStringAndReplacePlaceholders(string key)
{
String value = Entry.Strings.ReadSafe(key);
value = SprEngine.Compile(value, new SprContext(Entry, _db, SprCompileFlags.All));
return value;
}
/// <summary>
/// Returns the ID of the entry
/// </summary>
public PwUuid Uuid
{
get { return Entry.Uuid; }
}
/// <summary>
/// The output strings for the represented entry
/// </summary>
public ProtectedStringDictionary OutputStrings { get { return _outputStrings; } }
public PwEntry Entry
{
get { return _entry; }
}
}
public class App
{

View File

@ -87,17 +87,8 @@ namespace keepass2android
public void StorePlugin(string pluginPackage, string accessToken, IList<string> requestedScopes)
{
ISharedPreferences hostPrefs = GetHostPrefs();
ISharedPreferences pluginPrefs = GetPreferencesForPlugin(pluginPackage);
var stringSet = hostPrefs.GetStringSet(_pluginlist, new Collection<string>());
if (!stringSet.Contains(pluginPackage))
{
stringSet.Add(pluginPackage);
hostPrefs.Edit()
.PutStringSet(_pluginlist, stringSet)
.Commit();
}
pluginPrefs.Edit()
.PutString(_scopes, AccessManager.StringArrayToString(requestedScopes))
.PutString(_accessToken, accessToken)

View File

@ -21,6 +21,9 @@ using keepass2android.views;
namespace PluginHostTest
{
[Activity(Label = "TODO Details")]
[IntentFilter(new[] { Strings.ActionEditPluginSettings},
Label = AppNames.AppName,
Categories = new[] { Intent.CategoryDefault })]
public class PluginDetailsActivity : Activity
{
protected override void OnCreate(Bundle bundle)

View File

@ -1,28 +1,19 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using KeePassLib;
using KeePassLib.Collections;
using KeePassLib.Serialization;
using KeePassLib.Utility;
using Keepass2android;
using Keepass2android.Pluginsdk;
using Org.Json;
using PluginHostTest;
namespace keepass2android
{
/// <summary>
/// Class which manages plugins inside the app
/// </summary>
[BroadcastReceiver()]
[IntentFilter(new[] { Strings.ActionRequestAccess})]
public class PluginHost: BroadcastReceiver
@ -33,6 +24,9 @@ namespace keepass2android
private static readonly string[] _validScopes = { Strings.ScopeDatabaseActions, Strings.ScopeCurrentEntry };
/// <summary>
/// Sends a broadcast to all potential plugins prompting them to request access to our app.
/// </summary>
public static void TriggerRequests(Context ctx)
{
Intent accessIntent = new Intent(Strings.ActionTriggerRequestAccess);
@ -65,9 +59,6 @@ namespace keepass2android
}
public override void OnReceive(Context context, Intent intent)
{
PluginDatabase pluginDb = new PluginDatabase(context);
@ -143,6 +134,9 @@ namespace keepass2android
return true;
}
/// <summary>
/// adds the entry output data to the intent to be sent to a plugin
/// </summary>
public static void AddEntryToIntent(Intent intent, PwEntryOutput entry)
{
/*//add the entry XML

View File

@ -57,6 +57,7 @@
<ItemGroup>
<Compile Include="Activity1.cs" />
<Compile Include="App.cs" />
<Compile Include="AppNames.cs" />
<Compile Include="ClickView.cs" />
<Compile Include="CopyToClipboardService.cs" />
<Compile Include="EntryActivity.cs" />
@ -78,6 +79,7 @@
<Compile Include="PluginHost.cs" />
<Compile Include="EntryActivityClasses\PluginMenuOption.cs" />
<Compile Include="EntryActivityClasses\PluginPopupMenuItem.cs" />
<Compile Include="PwEntryOutput.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SprCompileFlags.cs" />

View File

@ -39,6 +39,7 @@ namespace keepass2android
};
builder.SetPositiveButton(Android.Resource.String.Ok, (dlgSender, dlgEvt) => { });
builder.SetCancelable(false);
builder.SetMessage("temp");
Dialog dialog = builder.Create();

View File

@ -2,7 +2,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:4.0.30319.34011
// Laufzeitversion:4.0.30319.34014
//
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// der Code erneut generiert wird.

View File

@ -79,7 +79,7 @@
<string name="error_invalid_db">Invalid database.</string>
<string name="error_invalid_path">Invalid path.</string>
<string name="error_no_name">A name is required.</string>
<string name="error_nopass">A password or a keyfile is required.</string>
<string name="error_nopass">A password or a key file is required.</string>
<string name="error_pass_gen_type">At least one password generation type must be selected</string>
<string name="error_pass_match">Passwords do not match.</string>
<string name="error_rounds_not_number">Rounds must be a number.</string>
@ -150,8 +150,8 @@
<string name="progress_create">Creating new database…</string>
<string name="create_database">Create database</string>
<string name="progress_title">Working…</string>
<string name="remember_keyfile_summary">Remembers the location of keyfiles</string>
<string name="remember_keyfile_title">Save keyfile</string>
<string name="remember_keyfile_summary">Remembers the location of key files</string>
<string name="remember_keyfile_title">Save key file</string>
<string name="remove_from_filelist">Remove</string>
<string name="rijndael">Rijndael (AES)</string>
<string name="root">Root</string>
@ -383,7 +383,7 @@
<string name="hint_key_file">Choose if you want to use a key file in addition to your master password:</string>
<string name="use_key_file">Use key file</string>
<string name="error_adding_keyfile">Error while adding the keyfile!</string>
<string name="error_adding_keyfile">Error while adding the key file!</string>
<string name="init_otp">Load OTP auxiliary file…</string>
<string name="otp_explanation">Enter the next One-time-passwords (OTPs). Swipe your Yubikey NEO at the back of your device to enter via NFC.</string>

View File

@ -180,7 +180,8 @@ namespace keepass2android
{
Finish();
return true;
} else
}
else
{
return false;
}

View File

@ -343,7 +343,10 @@ namespace keepass2android
{
//if the database is readonly, don't offer to modify the URL
if (App.Kp2a.GetDb().CanWrite == false)
{
base.OnCompleteCreateEntryActivity(entryActivity);
return;
}
entryActivity.AskAddUrlThenCompleteCreate(UrlToSearchFor);
}

View File

@ -25,6 +25,7 @@ namespace keepass2android
public class Intents
{
/// <summary>Broadcast this intent to lock the database (with quick unlock if enabled)</summary>
public const String LockDatabase = "keepass2android.lock_database";
/// <summary>Broadcast this intent to close the database (no quick unlock, full close)</summary>
@ -50,6 +51,8 @@ namespace keepass2android
public const int RequestCodeFileBrowseForKeyfile = 987324;
public const String ShowNotification = "keepass2android.show_notification";
public const String UpdateKeyboard = "keepass2android.update_keyboard";
public const String CopyStringToClipboard = "keepass2android.copy_string_to_clipboard";
}
}

View File

@ -30,7 +30,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;EXCLUDE_TWOFISH;INCLUDE_KEYBOARD;INCLUDE_FILECHOOSER;INCLUDE_JAVAFILESTORAGE;INCLUDE_KEYTRANSFORM</DefineConstants>
<DefineConstants>DEBUG;EXCLUDE_TWOFISH;EXCLUDE_KEYBOARD;EXCLUDE_FILECHOOSER;EXCLUDE_JAVAFILESTORAGE;EXCLUDE_KEYTRANSFORM</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause>
@ -110,6 +110,12 @@
<Compile Include="icons\DrawableFactory.cs" />
<Compile Include="icons\Icons.cs" />
<Compile Include="NfcOtpActivity.cs" />
<Compile Include="pluginhost\PluginArrayAdapter.cs" />
<Compile Include="pluginhost\PluginDatabase.cs" />
<Compile Include="pluginhost\PluginDetailsActivity.cs" />
<Compile Include="pluginhost\PluginHost.cs" />
<Compile Include="pluginhost\PluginListActivity.cs" />
<Compile Include="PwEntryOutput.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="KeePass.cs" />
@ -607,11 +613,11 @@
<AndroidResource Include="Resources\drawable\navigation_cancel.png" />
<AndroidResource Include="Resources\values-v14\styles.xml" />
<AndroidResource Include="Resources\values-v14\colors.xml" />
<AndroidResource Include="Resources\layout-v14\entry_view_contents.xml" />
<AndroidAsset Include="Resources\layout-v14\entry_view_contents.xml" />
<AndroidResource Include="Resources\layout-v14\group_add_entry.xml">
<SubType>Designer</SubType>
</AndroidResource>
<AndroidResource Include="Resources\layout-v14\entry_view.xml" />
<AndroidAsset Include="Resources\layout-v14\entry_view.xml" />
<AndroidResource Include="Resources\layout-v14\entry_edit.xml" />
<AndroidResource Include="Resources\layout-v14\SaveButton.xml" />
<AndroidResource Include="Resources\layout-v14\generate_password.xml" />
@ -689,6 +695,10 @@
<Project>{a8779d4d-7c49-4c2f-82bd-2cdc448391da}</Project>
<Name>Kp2aKeyboardBinding</Name>
</ProjectReference>
<ProjectReference Include="..\PluginSdkBinding\PluginSdkBinding.csproj">
<Project>{3da3911e-36de-465e-8f15-f1991b6437e5}</Project>
<Name>PluginSdkBinding</Name>
</ProjectReference>
<ProjectReference Include="..\TwofishCipher\TwofishCipher.csproj">
<Project>{5cf675a5-9bee-4720-bed9-d5bf14a2ebf9}</Project>
<Name>TwofishCipher</Name>
@ -957,4 +967,15 @@
<ItemGroup>
<AndroidResource Include="Resources\drawable\collections_new_label_holodark.png" />
</ItemGroup>
<ItemGroup>
<AndroidAsset Include="Resources\layout-v14\plugin_details.xml" />
</ItemGroup>
<ItemGroup>
<AndroidAsset Include="Resources\layout-v14\plugin_list.xml">
<SubType>AndroidResource</SubType>
</AndroidAsset>
</ItemGroup>
<ItemGroup>
<AndroidAsset Include="Resources\layout-v14\ListViewPluginRow.xml" />
</ItemGroup>
</Project>

View File

@ -49,6 +49,13 @@ namespace keepass2android
public const int NotifyKeyboard = 3;
public const int ClearClipboard = 4;
public void CopyValueToClipboardWithTimeout(Context ctx, string text)
{
Intent i = new Intent(ctx, typeof(CopyToClipboardService));
i.SetAction(Intents.CopyStringToClipboard);
i.PutExtra(_stringtocopy, text);
ctx.StartService(i);
}
public CopyToClipboardService (IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
@ -79,27 +86,46 @@ namespace keepass2android
filter.AddAction(Intents.DatabaseLocked);
RegisterReceiver(_stopOnLockBroadcastReceiver, filter);
String uuidBytes = intent.GetStringExtra(EntryActivity.KeyEntry);
bool closeAfterCreate = intent.GetBooleanExtra(EntryActivity.KeyCloseAfterCreate, false);
PwUuid entryId = PwUuid.Zero;
if (uuidBytes != null)
entryId = new PwUuid(MemUtil.HexStringToByteArray(uuidBytes));
PwEntry entry;
try
if ((intent.Action == Intents.ShowNotification) || (intent.Action == Intents.UpdateKeyboard))
{
entry = App.Kp2a.GetDb().Entries[entryId];
}
catch(Exception)
{
//seems like restarting the service happened after closing the DB
StopSelf();
return StartCommandResult.NotSticky;
}
DisplayAccessNotifications(entry, closeAfterCreate);
String uuidBytes = intent.GetStringExtra(EntryActivity.KeyEntry);
PwUuid entryId = PwUuid.Zero;
if (uuidBytes != null)
entryId = new PwUuid(MemUtil.HexStringToByteArray(uuidBytes));
PwEntry entry;
try
{
entry = App.Kp2a.GetDb().Entries[entryId];
}
catch (Exception)
{
//seems like restarting the service happened after closing the DB
StopSelf();
return StartCommandResult.NotSticky;
}
if (intent.Action == Intents.ShowNotification)
{
//first time opening the entry -> bring up the notifications
bool closeAfterCreate = intent.GetBooleanExtra(EntryActivity.KeyCloseAfterCreate, false);
DisplayAccessNotifications(entry, closeAfterCreate);
}
else
{
//this action is received when the data in the entry has changed (e.g. by plugins)
//update the keyboard data.
//Check if keyboard is (still) available
if (Keepass2android.Kbbridge.KeyboardData.EntryId == entry.Uuid.ToHexString())
MakeAccessibleForKeyboard(entry);
}
}
if (intent.Action == Intents.CopyStringToClipboard)
{
TimeoutCopyToClipboard(intent.GetStringExtra(_stringtocopy));
}
return StartCommandResult.RedeliverIntent;
}
@ -308,13 +334,7 @@ namespace keepass2android
#endif
}
static string GetStringAndReplacePlaceholders(PwEntry entry, string key)
{
String value = entry.Strings.ReadSafe(key);
value = SprEngine.Compile(value, new SprContext(entry, App.Kp2a.GetDb().KpDatabase, SprCompileFlags.All));
return value;
}
public void OnWaitElementDeleted(int itemId)
{
_numElementsToWaitFor--;
@ -392,6 +412,9 @@ namespace keepass2android
// Setup to allow the toast to happen in the foreground
readonly Handler _uiThreadCallback = new Handler();
private ClearClipboardTask _clearClipboardTask;
private const string _stringtocopy = "StringToCopy";
private Notification GetNotification(String intentText, int descResId, int drawableResId, String entryName) {
String desc = GetString(descResId);