Trigger autofill service when a text field's text is set by the application.
Some apps have an payment screen with a scan card button. When a text field's text is set in this scenario, the autofill service is never triggered because no field gets focused. Currently this new behavior is implemented for normal view. Add the check logic in these two functions of AutofillManager (notifyValueChanged/notifyViewVisibilityChanged) to check if it should trigger autofill automatically. Bug: 142821537 Test: atest CtsAutoFillServiceTestCases Change-Id: Ibde94791f49772dc19cb8566a9c3a48dfbf16a58
This commit is contained in:
@@ -47,6 +47,7 @@ import android.os.SystemClock;
|
||||
import android.service.autofill.AutofillService;
|
||||
import android.service.autofill.FillEventHistory;
|
||||
import android.service.autofill.UserData;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.DebugUtils;
|
||||
@@ -61,6 +62,7 @@ import android.view.accessibility.AccessibilityManager;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import android.view.accessibility.AccessibilityNodeProvider;
|
||||
import android.view.accessibility.AccessibilityWindowInfo;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
@@ -1073,6 +1075,8 @@ public final class AutofillManager {
|
||||
} else if (sVerbose) {
|
||||
Log.v(TAG, "Ignoring visibility change on " + id + ": no tracked views");
|
||||
}
|
||||
} else if (!virtual && isVisible) {
|
||||
startAutofillIfNeededLocked(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1238,9 +1242,11 @@ public final class AutofillManager {
|
||||
return;
|
||||
}
|
||||
if (!mEnabled || !isActiveLocked()) {
|
||||
if (sVerbose) {
|
||||
Log.v(TAG, "notifyValueChanged(" + view.getAutofillId()
|
||||
+ "): ignoring on state " + getStateAsStringLocked());
|
||||
if (!startAutofillIfNeededLocked(view)) {
|
||||
if (sVerbose) {
|
||||
Log.v(TAG, "notifyValueChanged(" + view.getAutofillId()
|
||||
+ "): ignoring on state " + getStateAsStringLocked());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1879,6 +1885,37 @@ public final class AutofillManager {
|
||||
}
|
||||
}
|
||||
|
||||
@GuardedBy("mLock")
|
||||
private boolean startAutofillIfNeededLocked(View view) {
|
||||
if (mState == STATE_UNKNOWN
|
||||
&& mSessionId == NO_SESSION
|
||||
&& view instanceof EditText
|
||||
&& !TextUtils.isEmpty(((EditText) view).getText())
|
||||
&& !view.isFocused()
|
||||
&& view.isImportantForAutofill()
|
||||
&& view.isLaidOut()
|
||||
&& view.isVisibleToUser()) {
|
||||
|
||||
ensureServiceClientAddedIfNeededLocked();
|
||||
|
||||
if (sVerbose) {
|
||||
Log.v(TAG, "startAutofillIfNeededLocked(): enabled=" + mEnabled);
|
||||
}
|
||||
if (mEnabled && !isClientDisablingEnterExitEvent()) {
|
||||
final AutofillId id = view.getAutofillId();
|
||||
final AutofillValue value = view.getAutofillValue();
|
||||
// Starts new session.
|
||||
startSessionLocked(id, /* bounds= */ null, /* value= */ null, /* flags= */ 0);
|
||||
// Updates value.
|
||||
updateSessionLocked(id, /* bounds= */ null, value, ACTION_VALUE_CHANGED,
|
||||
/* flags= */ 0);
|
||||
addEnteredIdLocked(id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a {@link AutofillCallback} to receive autofill events.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user