OSDN Git Service

DO NOT MERGE Disable smart sharing for password fields.
authorAbodunrinwa Toki <toki@google.com>
Sun, 22 Oct 2017 20:55:07 +0000 (21:55 +0100)
committerAbodunrinwa Toki <toki@google.com>
Wed, 25 Oct 2017 16:29:09 +0000 (17:29 +0100)
Test: bit FrameworksCoreTests:android.widget.TextViewActivityTest
bit CtsWidgetTestCases:android.widget.cts.TextViewTest
Bug: 66244132

Merged-In: Ifbf2c39d9f304251adc8c4acdf1b4fd6914011d8
Change-Id: If7d6f0240db22720fb8316cdac85eceee8003b35

core/java/android/widget/SelectionActionModeHelper.java
core/java/android/widget/TextView.java

index 142412a..227ef4c 100644 (file)
@@ -68,7 +68,7 @@ final class SelectionActionModeHelper {
 
     public void startActionModeAsync(boolean adjustSelection) {
         cancelAsyncTask();
-        if (isNoOpTextClassifier() || !hasSelection()) {
+        if (skipTextClassification()) {
             // No need to make an async call for a no-op TextClassifier.
             // Do not call the TextClassifier if there is no selection.
             startActionMode(null);
@@ -88,7 +88,7 @@ final class SelectionActionModeHelper {
 
     public void invalidateActionModeAsync() {
         cancelAsyncTask();
-        if (isNoOpTextClassifier() || !hasSelection()) {
+        if (skipTextClassification()) {
             // No need to make an async call for a no-op TextClassifier.
             // Do not call the TextClassifier if there is no selection.
             invalidateActionMode(null);
@@ -132,8 +132,16 @@ final class SelectionActionModeHelper {
         mTextClassification = null;
     }
 
-    private boolean isNoOpTextClassifier() {
-        return mEditor.getTextView().getTextClassifier() == TextClassifier.NO_OP;
+    private boolean skipTextClassification() {
+        final TextView textView = mEditor.getTextView();
+        // No need to make an async call for a no-op TextClassifier.
+        final boolean noOpTextClassifier = textView.getTextClassifier() == TextClassifier.NO_OP;
+        // Do not call the TextClassifier if there is no selection.
+        final boolean noSelection = textView.getSelectionEnd() == textView.getSelectionStart();
+        // Do not call the TextClassifier if this is a password field.
+        final boolean password = textView.hasPasswordTransformationMethod()
+                || TextView.isPasswordInputType(textView.getInputType());
+        return noOpTextClassifier || noSelection || password;
     }
 
     private boolean hasSelection() {
index 9a92489..52fc6d9 100644 (file)
@@ -5674,7 +5674,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
         return mTransformation instanceof PasswordTransformationMethod;
     }
 
-    private static boolean isPasswordInputType(int inputType) {
+    static boolean isPasswordInputType(int inputType) {
         final int variation =
                 inputType & (EditorInfo.TYPE_MASK_CLASS | EditorInfo.TYPE_MASK_VARIATION);
         return variation