Skip to content

Commit 4cd4982

Browse files
tumuyanBambooin
authored andcommitted
feat: privacy protection for draft
1 parent 3526ae3 commit 4cd4982

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

app/src/main/java/com/osfans/trime/ime/core/Trime.java

+46-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import android.os.Handler;
3636
import android.os.Looper;
3737
import android.os.Message;
38+
import android.text.InputType;
3839
import android.text.TextUtils;
3940
import android.view.Gravity;
4041
import android.view.KeyEvent;
@@ -96,6 +97,7 @@
9697
public class Trime extends LifecycleInputMethodService {
9798
private static Trime self = null;
9899
private LiquidKeyboard liquidKeyboard;
100+
private boolean normalTextEditor;
99101

100102
@NonNull
101103
private Preferences getPrefs() {
@@ -697,13 +699,54 @@ public void onStartInputView(EditorInfo attribute, boolean restarting) {
697699
bindKeyboardToInputView();
698700
if (!restarting) setNavBarColor();
699701
setCandidatesViewShown(!Rime.isEmpty()); // 軟鍵盤出現時顯示候選欄
700-
activeEditorInstance.cacheDraft();
701-
addDraft();
702+
703+
switch (attribute.inputType & InputType.TYPE_MASK_VARIATION) {
704+
case InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS:
705+
case InputType.TYPE_TEXT_VARIATION_PASSWORD:
706+
case InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD:
707+
case InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS:
708+
case InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD:
709+
Timber.i(
710+
"EditorInfo: private;"
711+
+ " packageName"
712+
+ attribute.packageName
713+
+ "; fieldName"
714+
+ attribute.fieldName
715+
+ "; actionLabel"
716+
+ attribute.actionLabel
717+
+ "; inputType"
718+
+ attribute.inputType
719+
+ "; &v "
720+
+ (attribute.inputType & InputType.TYPE_MASK_VARIATION)
721+
+ "; &c "
722+
+ (attribute.inputType & InputType.TYPE_MASK_CLASS));
723+
normalTextEditor = false;
724+
break;
725+
726+
default:
727+
Timber.i(
728+
"EditorInfo: normal;"
729+
+ " packageName"
730+
+ attribute.packageName
731+
+ "; fieldName"
732+
+ attribute.fieldName
733+
+ "; actionLabel"
734+
+ attribute.actionLabel
735+
+ "; inputType"
736+
+ attribute.inputType
737+
+ "; &v "
738+
+ (attribute.inputType & InputType.TYPE_MASK_VARIATION)
739+
+ "; &c "
740+
+ (attribute.inputType & InputType.TYPE_MASK_CLASS));
741+
normalTextEditor = true;
742+
activeEditorInstance.cacheDraft();
743+
addDraft();
744+
}
702745
}
703746

704747
@Override
705748
public void onFinishInputView(boolean finishingInput) {
706-
addDraft();
749+
if (normalTextEditor) addDraft();
707750
super.onFinishInputView(finishingInput);
708751
// Dismiss any pop-ups when the input-view is being finished and hidden.
709752
mainKeyboardView.closing();

app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import kotlinx.coroutines.CoroutineScope
2222
import kotlinx.coroutines.MainScope
2323
import kotlinx.coroutines.Runnable
2424
import kotlinx.coroutines.cancel
25+
import timber.log.Timber
2526
import java.util.Locale
2627

2728
/**
@@ -196,6 +197,12 @@ class TextInputManager private constructor() :
196197
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD,
197198
InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS,
198199
InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD -> {
200+
Timber.i(
201+
"EditorInfo: " +
202+
" inputAttrsRaw" + inputAttrsRaw +
203+
"; InputType" + (inputAttrsRaw and InputType.TYPE_MASK_VARIATION)
204+
)
205+
199206
tempAsciiMode = true
200207
".ascii"
201208
}

0 commit comments

Comments
 (0)