Respect flag for no personalized learning

This commit is contained in:
Aleksandras Kostarevas 2024-07-06 22:03:07 +03:00
parent 3d6963bbda
commit a32f2ff775
3 changed files with 12 additions and 0 deletions

View File

@ -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() {

View File

@ -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.

View File

@ -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();