* improvements to Plugin handling and AccessibilityService based AutoFill:

* don't forget plugin scopes (fixes #136), improves workflow to setup AutoFill plugin
 * fix display issues with scopes
 * make sure credentials are not filled several times but always show notification

* removed unnecessary permission
This commit is contained in:
Philipp Crocoll
2017-11-27 11:32:14 +01:00
parent 5f855209c9
commit 135f2617f6
11 changed files with 39 additions and 23 deletions

View File

@@ -8,7 +8,7 @@ Allows to switch input method automatically on non-rooted devices.
# AutoFill Plug-in
Uses Android Accessibility Service to provide an option to AutoFill forms (e.g. on Chrome) or any Android app.
[https://philippc.github.io/keepass2android/AccServiceAutoFill.md]
[https://philippc.github.io/keepass2android/AccServiceAutoFill.html]
# InputStick Plug-in
Allows to send text from KP2A via InputStick to your PC.

View File

@@ -11,6 +11,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
@@ -29,7 +30,7 @@ import keepass2android.kbbridge.KeyboardData;
public class AutoFillService extends AccessibilityService {
private static boolean _hasUsedData = false;
private static boolean _hasUsedData = true;
private static String _lastSearchUrl;
private static final String _logTag = "KP2AAF";
private static boolean _isRunning;
@@ -193,6 +194,7 @@ public class AutoFillService extends AccessibilityService {
if (ExistsNodeOrChildren(root, new PasswordFieldCondition()))
{
if ((getLastReceivedCredentialsUser() != null) &&
(!_hasUsedData) &&
(Objects.equals(url, _lastSearchUrl)
|| isSame(getCredentialsField("URL"), url)))
{
@@ -313,6 +315,7 @@ public class AutoFillService extends AccessibilityService {
@TargetApi(21)
private void FillPassword(String url, AccessibilityNodeInfo usernameEdit, List<AccessibilityNodeInfo> passwordFields)
{
Log.d(_logTag, "_hasUsedData = " + _hasUsedData);
if ((keepass2android.kbbridge.KeyboardData.hasData()) && (_hasUsedData == false))
{
fillDataInTextField(usernameEdit, getLastReceivedCredentialsUser());

View File

@@ -55,18 +55,6 @@
</intent-filter>
</activity>
<service android:name="keepass2android.autofill.AutoFillService"
android:enabled="true"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accserviceconfig" />
</service>
<activity android:configChanges="orientation" android:label="@string/app_name" android:theme="@style/MyTheme_Blue" android:name="keepass2android.PasswordActivity" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/app_name">
<action android:name="android.intent.action.VIEW" />
@@ -129,6 +117,5 @@
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<!-- Samsung Pass permission -->
<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
</manifest>

View File

@@ -140,7 +140,6 @@
<uses-permission android:name="keepass2android.keepass2android.permission.KP2aInternalFileBrowsing" />
<uses-permission android:name="keepass2android.keepass2android_debug.permission.KP2aInternalSearch" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
<!-- Samsung Pass permission -->
<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />

View File

@@ -116,7 +116,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
<uses-permission android:name="keepass2android.keepass2android.permission.KP2aInternalFileBrowsing" />
<uses-permission android:name="keepass2android.keepass2android_debug.permission.KP2aInternalSearch" />
<!-- Samsung Pass permission -->

View File

@@ -102,6 +102,18 @@ namespace keepass2android
}
}
protected override void OnStart()
{
base.OnStart();
Kp2aLog.Log("Starting QueryCredentialsActivity");
}
protected override void OnResume()
{
base.OnResume();
Kp2aLog.Log("Resuming QueryCredentialsActivity");
}
private void ShowToast()
{
string pluginDisplayName = _pluginPackage;

View File

@@ -1,3 +1,4 @@
using System;
using Android.Content.PM;
using Android.Content.Res;
using Android.Graphics.Drawables;
@@ -6,6 +7,7 @@ using Android.Content;
using Android.Views;
using System.Collections.Generic;
using Android.App;
using Android.Runtime;
namespace keepass2android
{
@@ -80,6 +82,11 @@ namespace keepass2android
int layoutResourceId;
IList<PluginItem> data = null;
public PluginArrayAdapter(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}
public PluginArrayAdapter(Context context, int layoutResourceId, IList<PluginItem> data) :
base(context, layoutResourceId, data)
{

View File

@@ -132,7 +132,7 @@ namespace keepass2android
i.PutExtra(Strings.ExtraSender, _ctx.PackageName);
i.PutExtra(Strings.ExtraRequestToken, GetPreferencesForPlugin(pluginPackage).GetString(_requesttoken, null));
_ctx.SendBroadcast(i);
StorePlugin(pluginPackage, null, new List<string>());
StorePlugin(pluginPackage, null, GetPluginScopes(pluginPackage));
}
}

View File

@@ -117,7 +117,7 @@ namespace keepass2android
private void UpdateView()
{
var scopesContainer = FindViewById<LinearLayout>(Resource.Id.scopes_list);
//scopesContainer.RemoveAllViews();
scopesContainer.RemoveAllViews();
var pluginDb = new PluginDatabase(this);
_checkbox.Checked = pluginDb.IsEnabled(_pluginPackageName);

View File

@@ -72,13 +72,14 @@ namespace keepass2android
PluginDatabase pluginDb = new PluginDatabase(context);
if (intent.Action == Strings.ActionRequestAccess)
{
var senderPackage = intent.GetStringExtra(Strings.ExtraSender);
var requestToken = intent.GetStringExtra(Strings.ExtraRequestToken);
string senderPackage = intent.GetStringExtra(Strings.ExtraSender);
string requestToken = intent.GetStringExtra(Strings.ExtraRequestToken);
var requestedScopes = intent.GetStringArrayListExtra(Strings.ExtraScopes);
IList<string> requestedScopes = intent.GetStringArrayListExtra(Strings.ExtraScopes);
if (!AreScopesValid(requestedScopes))
{
Log.Debug(_tag, "requested scopes not valid");
return;
}

View File

@@ -44,7 +44,7 @@ namespace keepass2android
}
protected override void OnResume()
{
base.OnResume();
PluginDatabase pluginDb = new PluginDatabase(this);
_items = (from pluginPackage in pluginDb.GetAllPluginPackages()
@@ -59,6 +59,13 @@ namespace keepass2android
* */
_pluginArrayAdapter = new PluginArrayAdapter(this, Resource.Layout.ListViewPluginRow, _items);
ListAdapter = _pluginArrayAdapter;
base.OnResume();
}
protected override void OnPause()
{
base.OnPause();
ListAdapter = _pluginArrayAdapter = null;
}
}
}