From 6ece2aa6cb49a6261dfbdfedc1104e0e465b88ea Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Wed, 8 Apr 2020 20:50:28 +0200 Subject: [PATCH] Add autofill web domain and app id --- .../keepass/autofill/AutofillHelper.kt | 23 ++++++++-- .../keepass/autofill/KeeAutofillService.kt | 17 ++++++-- .../main/res/drawable/ic_apps_white_24dp.xml | 5 +++ .../main/res/drawable/ic_web_white_24dp.xml | 5 +++ .../main/res/layout/item_autofill_app_id.xml | 43 +++++++++++++++++++ ...ll_service.xml => item_autofill_entry.xml} | 4 +- ...ce_unlock.xml => item_autofill_unlock.xml} | 11 ++--- .../layout/item_autofill_unlock_app_id.xml | 25 +++++++++++ .../item_autofill_unlock_web_domain.xml | 25 +++++++++++ .../res/layout/item_autofill_web_domain.xml | 43 +++++++++++++++++++ 10 files changed, 185 insertions(+), 16 deletions(-) create mode 100644 app/src/main/res/drawable/ic_apps_white_24dp.xml create mode 100644 app/src/main/res/drawable/ic_web_white_24dp.xml create mode 100644 app/src/main/res/layout/item_autofill_app_id.xml rename app/src/main/res/layout/{item_autofill_service.xml => item_autofill_entry.xml} (95%) rename app/src/main/res/layout/{item_autofill_service_unlock.xml => item_autofill_unlock.xml} (88%) create mode 100644 app/src/main/res/layout/item_autofill_unlock_app_id.xml create mode 100644 app/src/main/res/layout/item_autofill_unlock_web_domain.xml create mode 100644 app/src/main/res/layout/item_autofill_web_domain.xml diff --git a/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt b/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt index c83af633c..0ae33b401 100644 --- a/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt +++ b/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt @@ -71,6 +71,23 @@ object AutofillHelper { return "" } + internal fun addHeader(responseBuilder: FillResponse.Builder, + packageName: String, + webDomain: String?, + applicationId: String?) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + if (webDomain != null) { + responseBuilder.setHeader(RemoteViews(packageName, R.layout.item_autofill_web_domain).apply { + setTextViewText(R.id.autofill_web_domain_text, webDomain) + }) + } else if (applicationId != null) { + responseBuilder.setHeader(RemoteViews(packageName, R.layout.item_autofill_app_id).apply { + setTextViewText(R.id.autofill_app_id_text, applicationId) + }) + } + } + } + internal fun buildDataset(context: Context, entryInfo: EntryInfo, struct: StructureParser.Result): Dataset? { @@ -195,11 +212,11 @@ object AutofillHelper { private fun newRemoteViews(context: Context, remoteViewsText: String, remoteViewsIcon: IconImage? = null): RemoteViews { - val presentation = RemoteViews(context.packageName, R.layout.item_autofill_service) - presentation.setTextViewText(R.id.text, remoteViewsText) + val presentation = RemoteViews(context.packageName, R.layout.item_autofill_entry) + presentation.setTextViewText(R.id.autofill_entry_text, remoteViewsText) if (remoteViewsIcon != null) { presentation.assignDatabaseIcon(context, - R.id.icon, + R.id.autofill_entry_icon, Database.getInstance().drawFactory, remoteViewsIcon, ContextCompat.getColor(context, R.color.green)) diff --git a/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt b/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt index 37b877384..04007d902 100644 --- a/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt @@ -53,6 +53,8 @@ class KeeAutofillService : AutofillService() { searchInfo, { items -> val responseBuilder = FillResponse.Builder() + AutofillHelper.addHeader(responseBuilder, packageName, + parseResult.domain, parseResult.applicationId) items.forEach { responseBuilder.addDataset(AutofillHelper.buildDataset(this, it, parseResult)) } @@ -79,10 +81,19 @@ class KeeAutofillService : AutofillService() { // to generate Response. val sender = AutofillLauncherActivity.getAuthIntentSenderForResponse(this, searchInfo) - val presentation = RemoteViews(packageName, R.layout.item_autofill_service_unlock) - val responseBuilder = FillResponse.Builder() - responseBuilder.setAuthentication(autofillIds, sender, presentation) + val remoteViewsUnlock: RemoteViews = if (!parseResult.domain.isNullOrEmpty()) { + RemoteViews(packageName, R.layout.item_autofill_unlock_web_domain).apply { + setTextViewText(R.id.autofill_web_domain_text, parseResult.domain) + } + } else if (!parseResult.applicationId.isNullOrEmpty()) { + RemoteViews(packageName, R.layout.item_autofill_unlock_app_id).apply { + setTextViewText(R.id.autofill_app_id_text, parseResult.applicationId) + } + } else { + RemoteViews(packageName, R.layout.item_autofill_unlock) + } + responseBuilder.setAuthentication(autofillIds, sender, remoteViewsUnlock) callback.onSuccess(responseBuilder.build()) } } diff --git a/app/src/main/res/drawable/ic_apps_white_24dp.xml b/app/src/main/res/drawable/ic_apps_white_24dp.xml new file mode 100644 index 000000000..373f7752b --- /dev/null +++ b/app/src/main/res/drawable/ic_apps_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_web_white_24dp.xml b/app/src/main/res/drawable/ic_web_white_24dp.xml new file mode 100644 index 000000000..880e42770 --- /dev/null +++ b/app/src/main/res/drawable/ic_web_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/item_autofill_app_id.xml b/app/src/main/res/layout/item_autofill_app_id.xml new file mode 100644 index 000000000..5358ef3dd --- /dev/null +++ b/app/src/main/res/layout/item_autofill_app_id.xml @@ -0,0 +1,43 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_autofill_service.xml b/app/src/main/res/layout/item_autofill_entry.xml similarity index 95% rename from app/src/main/res/layout/item_autofill_service.xml rename to app/src/main/res/layout/item_autofill_entry.xml index 14e5c95c0..a7202488b 100644 --- a/app/src/main/res/layout/item_autofill_service.xml +++ b/app/src/main/res/layout/item_autofill_entry.xml @@ -22,7 +22,7 @@ android:orientation="horizontal"> - - - \ No newline at end of file diff --git a/app/src/main/res/layout/item_autofill_unlock_app_id.xml b/app/src/main/res/layout/item_autofill_unlock_app_id.xml new file mode 100644 index 000000000..b9fbfad3b --- /dev/null +++ b/app/src/main/res/layout/item_autofill_unlock_app_id.xml @@ -0,0 +1,25 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_autofill_unlock_web_domain.xml b/app/src/main/res/layout/item_autofill_unlock_web_domain.xml new file mode 100644 index 000000000..973baa9bf --- /dev/null +++ b/app/src/main/res/layout/item_autofill_unlock_web_domain.xml @@ -0,0 +1,25 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_autofill_web_domain.xml b/app/src/main/res/layout/item_autofill_web_domain.xml new file mode 100644 index 000000000..4258b4607 --- /dev/null +++ b/app/src/main/res/layout/item_autofill_web_domain.xml @@ -0,0 +1,43 @@ + + + + + \ No newline at end of file