From 4cd4982078af4dff3aef8879a2e6a4dc87a2da52 Mon Sep 17 00:00:00 2001 From: tumuyan Date: Mon, 10 Jan 2022 23:11:23 +0800 Subject: [PATCH] feat: privacy protection for draft --- .../java/com/osfans/trime/ime/core/Trime.java | 49 +++++++++++++++++-- .../osfans/trime/ime/text/TextInputManager.kt | 7 +++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/osfans/trime/ime/core/Trime.java b/app/src/main/java/com/osfans/trime/ime/core/Trime.java index e94b04553f..2ba38b7a16 100644 --- a/app/src/main/java/com/osfans/trime/ime/core/Trime.java +++ b/app/src/main/java/com/osfans/trime/ime/core/Trime.java @@ -35,6 +35,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; +import android.text.InputType; import android.text.TextUtils; import android.view.Gravity; import android.view.KeyEvent; @@ -96,6 +97,7 @@ public class Trime extends LifecycleInputMethodService { private static Trime self = null; private LiquidKeyboard liquidKeyboard; + private boolean normalTextEditor; @NonNull private Preferences getPrefs() { @@ -697,13 +699,54 @@ public void onStartInputView(EditorInfo attribute, boolean restarting) { bindKeyboardToInputView(); if (!restarting) setNavBarColor(); setCandidatesViewShown(!Rime.isEmpty()); // 軟鍵盤出現時顯示候選欄 - activeEditorInstance.cacheDraft(); - addDraft(); + + switch (attribute.inputType & InputType.TYPE_MASK_VARIATION) { + case InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS: + case InputType.TYPE_TEXT_VARIATION_PASSWORD: + case InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD: + case InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS: + case InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD: + Timber.i( + "EditorInfo: private;" + + " packageName" + + attribute.packageName + + "; fieldName" + + attribute.fieldName + + "; actionLabel" + + attribute.actionLabel + + "; inputType" + + attribute.inputType + + "; &v " + + (attribute.inputType & InputType.TYPE_MASK_VARIATION) + + "; &c " + + (attribute.inputType & InputType.TYPE_MASK_CLASS)); + normalTextEditor = false; + break; + + default: + Timber.i( + "EditorInfo: normal;" + + " packageName" + + attribute.packageName + + "; fieldName" + + attribute.fieldName + + "; actionLabel" + + attribute.actionLabel + + "; inputType" + + attribute.inputType + + "; &v " + + (attribute.inputType & InputType.TYPE_MASK_VARIATION) + + "; &c " + + (attribute.inputType & InputType.TYPE_MASK_CLASS)); + normalTextEditor = true; + activeEditorInstance.cacheDraft(); + addDraft(); + } } @Override public void onFinishInputView(boolean finishingInput) { - addDraft(); + if (normalTextEditor) addDraft(); super.onFinishInputView(finishingInput); // Dismiss any pop-ups when the input-view is being finished and hidden. mainKeyboardView.closing(); diff --git a/app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt b/app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt index 17289cd013..511f531a9c 100644 --- a/app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt +++ b/app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt @@ -22,6 +22,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.MainScope import kotlinx.coroutines.Runnable import kotlinx.coroutines.cancel +import timber.log.Timber import java.util.Locale /** @@ -196,6 +197,12 @@ class TextInputManager private constructor() : InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD, InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS, InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD -> { + Timber.i( + "EditorInfo: " + + " inputAttrsRaw" + inputAttrsRaw + + "; InputType" + (inputAttrsRaw and InputType.TYPE_MASK_VARIATION) + ) + tempAsciiMode = true ".ascii" }