From b561db3a67e4252fa10ccbd5ea14e319baca6225 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sat, 26 Feb 2022 15:19:06 +0100 Subject: [PATCH] Workaround to fill OTP token in multiple fields with Magikeyboard (long press) #1158 --- CHANGELOG | 1 + .../keepass/magikeyboard/KeyboardView.java | 5 +++ .../magikeyboard/MagikeyboardService.kt | 40 ++++++++++++++----- .../metadata/android/en-US/changelogs/103.txt | 3 +- .../metadata/android/fr-FR/changelogs/103.txt | 3 +- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 56efc01f4..cb3a2f9c2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ KeePassDX(3.3.1) * Fix filters #1249 * Fix temp advanced unlocking #1245 * Best autofill recognition #1250 + * Workaround to fill OTP token in multiple fields with Magikeyboard (long press) #1158 KeePassDX(3.3.0) * Quick search and dynamic filters #163 #462 #521 diff --git a/app/src/main/java/com/kunzisoft/keepass/magikeyboard/KeyboardView.java b/app/src/main/java/com/kunzisoft/keepass/magikeyboard/KeyboardView.java index 79c35f8e3..0dcb22d6e 100644 --- a/app/src/main/java/com/kunzisoft/keepass/magikeyboard/KeyboardView.java +++ b/app/src/main/java/com/kunzisoft/keepass/magikeyboard/KeyboardView.java @@ -18,6 +18,8 @@ package com.kunzisoft.keepass.magikeyboard; import static com.kunzisoft.keepass.magikeyboard.MagikeyboardService.KEY_BACK_KEYBOARD; import static com.kunzisoft.keepass.magikeyboard.MagikeyboardService.KEY_CHANGE_KEYBOARD; +import static com.kunzisoft.keepass.magikeyboard.MagikeyboardService.KEY_OTP; +import static com.kunzisoft.keepass.magikeyboard.MagikeyboardService.KEY_OTP_ALT; import android.content.Context; import android.content.res.TypedArray; @@ -1047,6 +1049,9 @@ public class KeyboardView extends View implements View.OnClickListener { if (popupKey.codes[0] == KEY_BACK_KEYBOARD) { mKeyboardActionListener.onKey(KEY_CHANGE_KEYBOARD, popupKey.codes); return true; + } else if (popupKey.codes[0] == KEY_OTP) { + mKeyboardActionListener.onKey(KEY_OTP_ALT, popupKey.codes); + return true; } else { int popupKeyboardId = popupKey.popupResId; if (popupKeyboardId != 0) { diff --git a/app/src/main/java/com/kunzisoft/keepass/magikeyboard/MagikeyboardService.kt b/app/src/main/java/com/kunzisoft/keepass/magikeyboard/MagikeyboardService.kt index 2472ab69f..e64f26ec4 100644 --- a/app/src/main/java/com/kunzisoft/keepass/magikeyboard/MagikeyboardService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/magikeyboard/MagikeyboardService.kt @@ -245,35 +245,52 @@ class MagikeyboardService : InputMethodService(), KeyboardView.OnKeyboardActionL dismissCustomKeys() } KEY_USERNAME -> { - if (entryInfoKey != null) { - currentInputConnection.commitText(entryInfoKey!!.username, 1) + entryInfoKey?.username?.let { username -> + currentInputConnection.commitText(username, 1) } actionTabAutomatically() } KEY_PASSWORD -> { - if (entryInfoKey != null) { - currentInputConnection.commitText(entryInfoKey!!.password, 1) + entryInfoKey?.password?.let { password -> + currentInputConnection.commitText(password, 1) } val otpFieldExists = entryInfoKey?.containsCustomField(OTP_TOKEN_FIELD) ?: false actionGoAutomatically(!otpFieldExists) } KEY_OTP -> { - if (entryInfoKey != null) { + entryInfoKey?.let { entryInfo -> currentInputConnection.commitText( - entryInfoKey!!.getGeneratedFieldValue(OTP_TOKEN_FIELD), 1) + entryInfo.getGeneratedFieldValue(OTP_TOKEN_FIELD), 1) + } + actionGoAutomatically() + } + KEY_OTP_ALT -> { + entryInfoKey?.let { entryInfo -> + val otpToken = entryInfo.getGeneratedFieldValue(OTP_TOKEN_FIELD) + if (otpToken.isNotEmpty()) { + // Cut to fill each digit separatelyKeyEvent.KEYCODE_TAB + val otpTokenChars = otpToken.chunked(1) + otpTokenChars.forEachIndexed { index, char -> + currentInputConnection.commitText(char, 1) + if (index < (otpTokenChars.size-1)) + currentInputConnection.sendKeyEvent( + KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TAB) + ) + } + } } actionGoAutomatically() } KEY_URL -> { - if (entryInfoKey != null) { - currentInputConnection.commitText(entryInfoKey!!.url, 1) + entryInfoKey?.url?.let { url -> + currentInputConnection.commitText(url, 1) } actionGoAutomatically() } KEY_FIELDS -> { - if (entryInfoKey != null) { + entryInfoKey?.customFields?.let { customFields -> fieldsAdapter?.apply { - setFields(entryInfoKey!!.customFields.filter { it.name != OTP_TOKEN_FIELD}) + setFields(customFields.filter { it.name != OTP_TOKEN_FIELD}) notifyDataSetChanged() } } @@ -347,7 +364,8 @@ class MagikeyboardService : InputMethodService(), KeyboardView.OnKeyboardActionL private const val KEY_ENTRY = 620 private const val KEY_USERNAME = 500 private const val KEY_PASSWORD = 510 - private const val KEY_OTP = 515 + const val KEY_OTP = 515 + const val KEY_OTP_ALT = 516 private const val KEY_URL = 520 private const val KEY_FIELDS = 530 diff --git a/fastlane/metadata/android/en-US/changelogs/103.txt b/fastlane/metadata/android/en-US/changelogs/103.txt index f1d5a8db5..34ed26414 100644 --- a/fastlane/metadata/android/en-US/changelogs/103.txt +++ b/fastlane/metadata/android/en-US/changelogs/103.txt @@ -2,4 +2,5 @@ * Better OOM management #256 * Fix filters #1249 * Fix temp advanced unlocking #1245 - * Best autofill recognition #1250 \ No newline at end of file + * Best autofill recognition #1250 + * Workaround to fill OTP token in multiple fields with Magikeyboard (long press) #1158 \ No newline at end of file diff --git a/fastlane/metadata/android/fr-FR/changelogs/103.txt b/fastlane/metadata/android/fr-FR/changelogs/103.txt index ba8745a62..745626428 100644 --- a/fastlane/metadata/android/fr-FR/changelogs/103.txt +++ b/fastlane/metadata/android/fr-FR/changelogs/103.txt @@ -2,4 +2,5 @@ * Meilleur gestion d'OOM #256 * Correction des filtres #1249 * Correction du déverouillage avancé temporaire #1245 - * Meilleure reconnaissance du remplissage automatique #1250 \ No newline at end of file + * Meilleure reconnaissance du remplissage automatique #1250 + * Solution pour remplir le token OTP dans des champs multiple avec le Magiclavier (appui long) #1158 \ No newline at end of file