From a32f2ff7752cca28e5c9208eb3f7415262f21d18 Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Sat, 6 Jul 2024 22:03:07 +0300 Subject: [PATCH] Respect flag for no personalized learning --- java/src/org/futo/inputmethod/latin/InputAttributes.java | 9 +++++++++ .../futo/inputmethod/latin/inputlogic/InputLogic.java | 2 ++ .../inputmethod/latin/xlm/LanguageModelFacilitator.kt | 1 + 3 files changed, 12 insertions(+) diff --git a/java/src/org/futo/inputmethod/latin/InputAttributes.java b/java/src/org/futo/inputmethod/latin/InputAttributes.java index 20f34133c..7f455bd7a 100644 --- a/java/src/org/futo/inputmethod/latin/InputAttributes.java +++ b/java/src/org/futo/inputmethod/latin/InputAttributes.java @@ -50,6 +50,7 @@ public final class InputAttributes { */ final public boolean mDisableGestureFloatingPreviewText; final public boolean mIsGeneralTextInput; + final public boolean mNoLearning; final private int mInputType; final private EditorInfo mEditorInfo; final private String mPackageNameForPrivateImeOptions; @@ -86,6 +87,7 @@ public final class InputAttributes { mShouldShowVoiceInputKey = false; mDisableGestureFloatingPreviewText = false; mIsGeneralTextInput = false; + mNoLearning = false; return; } // inputClass == InputType.TYPE_CLASS_TEXT @@ -147,6 +149,13 @@ public final class InputAttributes { && InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD != variation && InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS != variation && InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD != variation; + + boolean noLearning = false; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + noLearning = (mEditorInfo.imeOptions & EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING) != 0; + } + + mNoLearning = noLearning; } public boolean isTypeNull() { diff --git a/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java b/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java index 3d7470986..98bbd2e5d 100644 --- a/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java @@ -1499,6 +1499,8 @@ public final class InputLogic { // That's to avoid unintended additions in some sensitive fields, or fields that // expect to receive non-words. if (!settingsValues.mAutoCorrectionEnabledPerUserSettings) return; + if (settingsValues.mInputAttributes.mNoLearning) return; + if (mConnection.hasSlowInputConnection()) { // Since we don't unlearn when the user backspaces on a slow InputConnection, // turn off learning to guard against adding typos that the user later deletes. diff --git a/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt b/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt index 0d8010775..d8abd73a6 100644 --- a/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt +++ b/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt @@ -550,6 +550,7 @@ public class LanguageModelFacilitator( ) { if(shouldPassThroughToLegacy()) return if(!trainingEnabled) return + if(settings.current?.mInputAttributes?.mNoLearning != false) return val wordCtx = ngramContext.fullContext.trim().lines().last() var committedNgramCtx = ngramContext.extractPrevWordsContext().replace(NgramContext.BEGINNING_OF_SENTENCE_TAG, " ").trim();