Merge "Minor Content Capture-related changes."
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index ec16828..c7f25d7 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -3406,18 +3406,33 @@
private static final int PFLAG4_NOTIFIED_CONTENT_CAPTURE_ADDED = 0x20;
private static final int PFLAG4_LAST_CONTENT_CAPTURE_NOTIFICATION_TYPE = 0x40;
+ /* End of masks for mPrivateFlags4 */
+
private static final int CONTENT_CAPTURE_NOTIFICATION_TYPE_APPEARED = 1;
private static final int CONTENT_CAPTURE_NOTIFICATION_TYPE_DISAPPEARED = 0;
- /** @hide */
@IntDef(flag = true, prefix = { "CONTENT_CAPTURE_NOTIFICATION_TYPE_" }, value = {
CONTENT_CAPTURE_NOTIFICATION_TYPE_APPEARED,
CONTENT_CAPTURE_NOTIFICATION_TYPE_DISAPPEARED
})
@Retention(RetentionPolicy.SOURCE)
- public @interface ContentCaptureNotificationType {}
+ private @interface ContentCaptureNotificationType {}
- /* End of masks for mPrivateFlags4 */
+ /** @hide */
+ protected static final int VIEW_STRUCTURE_FOR_ASSIST = 0;
+ /** @hide */
+ protected static final int VIEW_STRUCTURE_FOR_AUTOFILL = 1;
+ /** @hide */
+ protected static final int VIEW_STRUCTURE_FOR_CONTENT_CAPTURE = 2;
+
+ /** @hide */
+ @IntDef(flag = true, prefix = { "VIEW_STRUCTURE_FOR" }, value = {
+ VIEW_STRUCTURE_FOR_ASSIST,
+ VIEW_STRUCTURE_FOR_AUTOFILL,
+ VIEW_STRUCTURE_FOR_CONTENT_CAPTURE
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface ViewStructureType {}
/**
* Always allow a user to over-scroll this view, provided it is a
@@ -8043,8 +8058,7 @@
* fills in all data that can be inferred from the view itself.
*/
public void onProvideStructure(ViewStructure structure) {
- onProvideStructureForAssistOrAutofillOrViewCapture(structure, /* forAutofill = */ false,
- /* forViewCapture= */ false, /* flags= */ 0);
+ onProvideStructure(structure, VIEW_STRUCTURE_FOR_ASSIST, /* flags= */ 0);
}
/**
@@ -8117,8 +8131,7 @@
* @see #AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
*/
public void onProvideAutofillStructure(ViewStructure structure, @AutofillFlags int flags) {
- onProvideStructureForAssistOrAutofillOrViewCapture(structure, /* forAutofill = */ true,
- /* forViewCapture= */ false, flags);
+ onProvideStructure(structure, VIEW_STRUCTURE_FOR_AUTOFILL, flags);
}
/**
@@ -8150,13 +8163,13 @@
* virtual views are rendered.
*/
public boolean onProvideContentCaptureStructure(@NonNull ViewStructure structure, int flags) {
- onProvideStructureForAssistOrAutofillOrViewCapture(structure, /* forAutofill = */ false,
- /* forViewCapture= */ true, flags);
+ onProvideStructure(structure, VIEW_STRUCTURE_FOR_CONTENT_CAPTURE, flags);
return true;
}
- private void onProvideStructureForAssistOrAutofillOrViewCapture(ViewStructure structure,
- boolean forAutofill, boolean forViewCapture, @AutofillFlags int flags) {
+ /** @hide */
+ protected void onProvideStructure(@NonNull ViewStructure structure,
+ @ViewStructureType int viewFor, int flags) {
final int id = mID;
if (id != NO_ID && !isViewIdGenerated(id)) {
String pkg, type, entry;
@@ -8172,11 +8185,13 @@
} else {
structure.setId(id, null, null, null);
}
- if (forViewCapture) {
+ if (viewFor == VIEW_STRUCTURE_FOR_CONTENT_CAPTURE) {
+ //TODO(b/111276913): STOPSHIP - don't set it if not needed
structure.setDataIsSensitive(false);
}
- if (forAutofill || forViewCapture) {
+ if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL
+ || viewFor == VIEW_STRUCTURE_FOR_CONTENT_CAPTURE) {
final @AutofillType int autofillType = getAutofillType();
// Don't need to fill autofill info if view does not support it.
// For example, only TextViews that are editable support autofill
@@ -8190,7 +8205,8 @@
int ignoredParentLeft = 0;
int ignoredParentTop = 0;
- if (forAutofill && (flags & AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS) == 0) {
+ if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL
+ && (flags & AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS) == 0) {
View parentGroup = null;
ViewParent viewParent = getParent();
@@ -8213,7 +8229,8 @@
structure.setDimens(ignoredParentLeft + mLeft, ignoredParentTop + mTop, mScrollX, mScrollY,
mRight - mLeft, mBottom - mTop);
- if (!forAutofill) {
+ if (viewFor == VIEW_STRUCTURE_FOR_ASSIST
+ || viewFor == VIEW_STRUCTURE_FOR_CONTENT_CAPTURE) {
if (!hasIdentityMatrix()) {
structure.setTransformation(getMatrix());
}
@@ -8907,10 +8924,9 @@
}
/**
- * Helper used to notify the {@link IntelligenceManager}anager when the view is removed or
+ * Helper used to notify the {@link IntelligenceManager} when the view is removed or
* added, based on whether it's laid out and visible, and without knowing if the parent removed
- * it from the view
- * hierarchy.
+ * it from the view hierarchy.
*/
// TODO(b/111276913): make sure the current algorithm covers all cases. For example, it should
// probably be called every time notifyEnterOrExitForAutoFillIfNeeded() is called as well.
@@ -9084,7 +9100,7 @@
* {@link #onProvideVirtualStructure}.
*/
public void dispatchProvideStructure(ViewStructure structure) {
- dispatchProvideStructureForAssistOrAutofill(structure, false, 0);
+ dispatchProvideStructure(structure, VIEW_STRUCTURE_FOR_ASSIST, /* flags= */ 0);
}
/**
@@ -9126,12 +9142,12 @@
*/
public void dispatchProvideAutofillStructure(@NonNull ViewStructure structure,
@AutofillFlags int flags) {
- dispatchProvideStructureForAssistOrAutofill(structure, true, flags);
+ dispatchProvideStructure(structure, VIEW_STRUCTURE_FOR_AUTOFILL, flags);
}
- private void dispatchProvideStructureForAssistOrAutofill(ViewStructure structure,
- boolean forAutofill, @AutofillFlags int flags) {
- if (forAutofill) {
+ private void dispatchProvideStructure(@NonNull ViewStructure structure,
+ @ViewStructureType int viewFor, @AutofillFlags int flags) {
+ if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL) {
structure.setAutofillId(getAutofillId());
onProvideAutofillStructure(structure, flags);
onProvideAutofillVirtualStructure(structure, flags);
diff --git a/core/java/android/widget/AdapterView.java b/core/java/android/widget/AdapterView.java
index f3fe16e..ddff858 100644
--- a/core/java/android/widget/AdapterView.java
+++ b/core/java/android/widget/AdapterView.java
@@ -1309,13 +1309,23 @@
@Override
public void onProvideAutofillStructure(ViewStructure structure, int flags) {
super.onProvideAutofillStructure(structure, flags);
+ }
- final Adapter adapter = getAdapter();
- if (adapter == null) return;
+ /** @hide */
+ @Override
+ protected void onProvideStructure(@NonNull ViewStructure structure,
+ @ViewStructureType int viewFor, int flags) {
+ super.onProvideStructure(structure, viewFor, flags);
- final CharSequence[] options = adapter.getAutofillOptions();
- if (options != null) {
- structure.setAutofillOptions(options);
+ if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL
+ || viewFor == VIEW_STRUCTURE_FOR_CONTENT_CAPTURE) {
+ final Adapter adapter = getAdapter();
+ if (adapter == null) return;
+
+ final CharSequence[] options = adapter.getAutofillOptions();
+ if (options != null) {
+ structure.setAutofillOptions(options);
+ }
}
}
}
diff --git a/core/java/android/widget/CompoundButton.java b/core/java/android/widget/CompoundButton.java
index 8d09489..d35bec8 100644
--- a/core/java/android/widget/CompoundButton.java
+++ b/core/java/android/widget/CompoundButton.java
@@ -578,11 +578,16 @@
stream.addProperty("checked", isChecked());
}
- @Override
- public void onProvideAutofillStructure(ViewStructure structure, int flags) {
- super.onProvideAutofillStructure(structure, flags);
- structure.setDataIsSensitive(!mCheckedFromResource);
+ /** @hide */
+ @Override
+ protected void onProvideStructure(@NonNull ViewStructure structure,
+ @ViewStructureType int viewFor, int flags) {
+ super.onProvideStructure(structure, viewFor, flags);
+
+ if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL) {
+ structure.setDataIsSensitive(!mCheckedFromResource);
+ }
}
@Override
diff --git a/core/java/android/widget/RadioGroup.java b/core/java/android/widget/RadioGroup.java
index 327a5c1..ab12eac 100644
--- a/core/java/android/widget/RadioGroup.java
+++ b/core/java/android/widget/RadioGroup.java
@@ -17,6 +17,7 @@
package android.widget;
import android.annotation.IdRes;
+import android.annotation.NonNull;
import android.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.TypedArray;
@@ -424,10 +425,15 @@
}
}
+ /** @hide */
@Override
- public void onProvideAutofillStructure(ViewStructure structure, int flags) {
- super.onProvideAutofillStructure(structure, flags);
- structure.setDataIsSensitive(mCheckedId != mInitialCheckedId);
+ protected void onProvideStructure(@NonNull ViewStructure structure,
+ @ViewStructureType int viewFor, int flags) {
+ super.onProvideStructure(structure, viewFor, flags);
+
+ if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL) {
+ structure.setDataIsSensitive(mCheckedId != mInitialCheckedId);
+ }
}
@Override
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 3bdd7b8..35be766 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -6076,7 +6076,7 @@
if (needEditableForNotification) {
sendAfterTextChanged((Editable) text);
} else {
- notifyManagersAfterTextChanged();
+ notifyListeningManagersAfterTextChanged();
}
// SelectionModifierCursorController depends on textCanBeSelected, which depends on text
@@ -10124,13 +10124,16 @@
}
}
- // Always notify AutoFillManager - it will return right away if autofill is disabled.
- notifyManagersAfterTextChanged();
+ notifyListeningManagersAfterTextChanged();
hideErrorIfUnchanged();
}
- private void notifyManagersAfterTextChanged() {
+ /**
+ * Notify managers (such as {@link AutofillManager} and {@link IntelligenceManager}) that are
+ * interested on text changes.
+ */
+ private void notifyListeningManagersAfterTextChanged() {
// Autofill
if (isAutofillable()) {
@@ -10911,34 +10914,17 @@
return TextView.class.getName();
}
+ /** @hide */
@Override
- public void onProvideStructure(ViewStructure structure) {
- super.onProvideStructure(structure);
- onProvideStructureForAssistOrAutofillOrViewCapture(structure, /* forAutofill = */ false,
- /* forViewCapture= */ false);
- }
+ protected void onProvideStructure(@NonNull ViewStructure structure,
+ @ViewStructureType int viewFor, int flags) {
+ super.onProvideStructure(structure, viewFor, flags);
- @Override
- public void onProvideAutofillStructure(ViewStructure structure, int flags) {
- super.onProvideAutofillStructure(structure, flags);
- onProvideStructureForAssistOrAutofillOrViewCapture(structure, /* forAutofill = */ true,
- /* forViewCapture= */ false);
- }
-
- @Override
- public boolean onProvideContentCaptureStructure(ViewStructure structure, int flags) {
- final boolean notifyManager = super.onProvideContentCaptureStructure(structure, flags);
- onProvideStructureForAssistOrAutofillOrViewCapture(structure, /* forAutofill = */ false,
- /* forViewCapture= */ true);
- return notifyManager;
- }
-
- private void onProvideStructureForAssistOrAutofillOrViewCapture(ViewStructure structure,
- boolean forAutofill, boolean forViewCapture) {
final boolean isPassword = hasPasswordTransformationMethod()
|| isPasswordInputType(getInputType());
- if (forAutofill || forViewCapture) {
- if (forAutofill) {
+ if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL
+ || viewFor == VIEW_STRUCTURE_FOR_CONTENT_CAPTURE) {
+ if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL) {
structure.setDataIsSensitive(!mTextSetFromXmlOrResourceId);
}
if (mTextId != ResourceId.ID_NULL) {
@@ -10953,7 +10939,8 @@
}
}
- if (!isPassword || forAutofill || forViewCapture) {
+ if (!isPassword || viewFor == VIEW_STRUCTURE_FOR_AUTOFILL
+ || viewFor == VIEW_STRUCTURE_FOR_CONTENT_CAPTURE) {
if (mLayout == null) {
assumeLayout();
}
@@ -10962,7 +10949,7 @@
if (lineCount <= 1) {
// Simple case: this is a single line.
final CharSequence text = getText();
- if (forAutofill) {
+ if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL) {
structure.setText(text);
} else {
structure.setText(text, getSelectionStart(), getSelectionEnd());
@@ -11026,7 +11013,7 @@
text = text.subSequence(expandedTopChar, expandedBottomChar);
}
- if (forAutofill) {
+ if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL) {
structure.setText(text);
} else {
structure.setText(text, selStart - expandedTopChar, selEnd - expandedTopChar);
@@ -11042,7 +11029,8 @@
}
}
- if (!forAutofill) {
+ if (viewFor == VIEW_STRUCTURE_FOR_ASSIST
+ || viewFor == VIEW_STRUCTURE_FOR_CONTENT_CAPTURE) {
// Extract style information that applies to the TextView as a whole.
int style = 0;
int typefaceStyle = getTypefaceStyle();
@@ -11070,7 +11058,8 @@
structure.setTextStyle(getTextSize(), getCurrentTextColor(),
AssistStructure.ViewNode.TEXT_COLOR_UNDEFINED /* bgColor */, style);
}
- if (forAutofill || forViewCapture) {
+ if (viewFor == VIEW_STRUCTURE_FOR_AUTOFILL
+ || viewFor == VIEW_STRUCTURE_FOR_CONTENT_CAPTURE) {
structure.setMinTextEms(getMinEms());
structure.setMaxTextEms(getMaxEms());
int maxLength = -1;