diff options
| author | 2024-11-11 22:34:47 +0000 | |
|---|---|---|
| committer | 2024-11-11 22:34:47 +0000 | |
| commit | 8ed8a9f45ea2c4870c8a401d34ae733381e928a9 (patch) | |
| tree | b99fb4f7653e2b72211c9f43545ceb3a0c74c0bd | |
| parent | adb79c981344aa1afcde0002df100839ddce3544 (diff) | |
Public Autofill Id field in EditorInfo
CtsInputMethodTestCases test suit pass on ABTD, run link: https://android-build.corp.google.com/builds/abtd/run/L50900030007633534
Bug:b/342672560
Change-Id: I227e273c7b9b0200be8b147762928f9453583281
Flag: android.view.inputmethod.public_autofill_id_in_editorinfo
Test: atest CtsInputMethodTestCases
6 files changed, 44 insertions, 12 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index ed67cc2fe04b..c677cd366428 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -56885,6 +56885,7 @@ package android.view.inputmethod { ctor public EditorInfo(); method public int describeContents(); method public void dump(android.util.Printer, String); + method @FlaggedApi("android.view.inputmethod.public_autofill_id_in_editorinfo") @Nullable public android.view.autofill.AutofillId getAutofillId(); method @Nullable public CharSequence getInitialSelectedText(int); method @Nullable public android.view.inputmethod.SurroundingText getInitialSurroundingText(@IntRange(from=0) int, @IntRange(from=0) int, int); method @Nullable public CharSequence getInitialTextAfterCursor(@IntRange(from=0) int, int); @@ -56894,6 +56895,7 @@ package android.view.inputmethod { method @NonNull public java.util.List<java.lang.Class<? extends android.view.inputmethod.HandwritingGesture>> getSupportedHandwritingGestures(); method @FlaggedApi("android.view.inputmethod.editorinfo_handwriting_enabled") public boolean isStylusHandwritingEnabled(); method public final void makeCompatible(int); + method @FlaggedApi("android.view.inputmethod.public_autofill_id_in_editorinfo") public void setAutofillId(@Nullable android.view.autofill.AutofillId); method public void setInitialSurroundingSubText(@NonNull CharSequence, int); method public void setInitialSurroundingText(@NonNull CharSequence); method public void setInitialToolType(int); diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index ae8366817f2b..dadb5c386b76 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -3437,7 +3437,7 @@ public class InputMethodService extends AbstractInputMethodService { initialize(); mInlineSuggestionSessionController.notifyOnStartInput( editorInfo == null ? null : editorInfo.packageName, - editorInfo == null ? null : editorInfo.autofillId); + editorInfo == null ? null : editorInfo.getAutofillId()); if (DEBUG) Log.v(TAG, "CALL: onStartInput"); onStartInput(editorInfo, restarting); if (mDecorViewVisible) { diff --git a/core/java/android/view/inputmethod/EditorInfo.java b/core/java/android/view/inputmethod/EditorInfo.java index fb3e0831fdc9..a5603399142b 100644 --- a/core/java/android/view/inputmethod/EditorInfo.java +++ b/core/java/android/view/inputmethod/EditorInfo.java @@ -24,6 +24,7 @@ import static android.view.inputmethod.EditorInfoProto.PACKAGE_NAME; import static android.view.inputmethod.EditorInfoProto.PRIVATE_IME_OPTIONS; import static android.view.inputmethod.EditorInfoProto.TARGET_INPUT_METHOD_USER_ID; import static android.view.inputmethod.Flags.FLAG_EDITORINFO_HANDWRITING_ENABLED; +import static android.view.inputmethod.Flags.FLAG_PUBLIC_AUTOFILL_ID_IN_EDITORINFO; import android.annotation.FlaggedApi; import android.annotation.IntDef; @@ -470,12 +471,10 @@ public class EditorInfo implements InputType, Parcelable { public String packageName; /** - * Autofill Id for the field that's currently on focus. - * - * <p> Marked as hide since it's only used by framework.</p> - * @hide + * Autofill Id for the field that's currently on focus. See link {@link AutofillId} for more + * details. It is set by {@link View#getAutofillId()} */ - public AutofillId autofillId; + private AutofillId autofillId; /** * Identifier for the editor's field. This is optional, and may be @@ -1200,6 +1199,28 @@ public class EditorInfo implements InputType, Parcelable { } /** + * Returns the {@link AutofillId} of the view that this {@link EditorInfo} is associated with. + * The value is filled in with the result of {@link android.view.View#getAutofillId() + * View.getAutofillId()} on the view that is being edited. + * + * Note: For virtual view(e.g. Compose or Webview), default behavior is the autofillId is the id + * of the container view, unless the virtual view provider sets the virtual id when the + * InputMethodManager calls {@link android.view.View#onCreateInputConnection()} on the container + * view. + */ + @FlaggedApi(FLAG_PUBLIC_AUTOFILL_ID_IN_EDITORINFO) + @Nullable + public AutofillId getAutofillId() { + return autofillId; + } + + /** Sets the {@link AutofillId} of the view that this {@link EditorInfo} is associated with. */ + @FlaggedApi(FLAG_PUBLIC_AUTOFILL_ID_IN_EDITORINFO) + public void setAutofillId(@Nullable AutofillId autofillId) { + this.autofillId = autofillId; + } + + /** * Export the state of {@link EditorInfo} into a protocol buffer output stream. * * @param proto Stream to write the state to diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 73f9d9fc23dc..26a7a1f756b2 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -5174,7 +5174,7 @@ public final class InputMethodManager { // system can verify the consistency between the uid of this process and package name passed // from here. See comment of Context#getOpPackageName() for details. editorInfo.packageName = servedView.getContext().getOpPackageName(); - editorInfo.autofillId = servedView.getAutofillId(); + editorInfo.setAutofillId(servedView.getAutofillId()); editorInfo.fieldId = servedView.getId(); final InputConnection ic = servedView.onCreateInputConnection(editorInfo); if (DEBUG) Log.v(TAG, "Starting input: editorInfo=" + editorInfo + " ic=" + ic); @@ -5183,7 +5183,7 @@ public final class InputMethodManager { // This ensures that even disconnected EditorInfos have well-defined attributes, // making them consistently and straightforwardly comparable. if (ic == null) { - editorInfo.autofillId = AutofillId.NO_AUTOFILL_ID; + editorInfo.setAutofillId(AutofillId.NO_AUTOFILL_ID); editorInfo.fieldId = 0; } return new Pair<>(ic, editorInfo); diff --git a/core/java/android/view/inputmethod/flags.aconfig b/core/java/android/view/inputmethod/flags.aconfig index edd9d6cff799..e619ab064005 100644 --- a/core/java/android/view/inputmethod/flags.aconfig +++ b/core/java/android/view/inputmethod/flags.aconfig @@ -165,4 +165,13 @@ flag { description: "Writing tools API" bug: "373788889" is_fixed_read_only: true -}
\ No newline at end of file +} + +flag { + name: "public_autofill_id_in_editorinfo" + is_exported: true + namespace: "input_method" + description: "Guarding public API autofillId in editor info" + bug: "342672560" + is_fixed_read_only: true +} diff --git a/core/tests/InputMethodCoreTests/src/android/view/inputmethod/EditorInfoTest.java b/core/tests/InputMethodCoreTests/src/android/view/inputmethod/EditorInfoTest.java index 1721e1e2e935..9dd196daf412 100644 --- a/core/tests/InputMethodCoreTests/src/android/view/inputmethod/EditorInfoTest.java +++ b/core/tests/InputMethodCoreTests/src/android/view/inputmethod/EditorInfoTest.java @@ -79,7 +79,7 @@ public class EditorInfoTest { TEST_EDITOR_INFO.label = "testLabel"; TEST_EDITOR_INFO.packageName = "android.view.inputmethod"; TEST_EDITOR_INFO.fieldId = 0; - TEST_EDITOR_INFO.autofillId = AutofillId.NO_AUTOFILL_ID; + TEST_EDITOR_INFO.setAutofillId(AutofillId.NO_AUTOFILL_ID); TEST_EDITOR_INFO.fieldName = "testField"; TEST_EDITOR_INFO.extras = new Bundle(); TEST_EDITOR_INFO.extras.putString("testKey", "testValue"); @@ -531,7 +531,7 @@ public class EditorInfoTest { info.setStylusHandwritingEnabled(true); } info.packageName = "android.view.inputmethod"; - info.autofillId = new AutofillId(123); + info.setAutofillId(new AutofillId(123)); info.fieldId = 456; info.fieldName = "testField"; info.extras = new Bundle(); @@ -597,7 +597,7 @@ public class EditorInfoTest { @Test public void testKindofEqualsComparesAutofillId() { final EditorInfo infoCopy = TEST_EDITOR_INFO.createCopyInternal(); - infoCopy.autofillId = new AutofillId(42); + infoCopy.setAutofillId(new AutofillId(42)); assertFalse(TEST_EDITOR_INFO.kindofEquals(infoCopy)); } |