From 3161e902642f1a6fe0ec8aeef6a8c65a94f5e1cb Mon Sep 17 00:00:00 2001 From: Tim Yu Date: Wed, 18 Dec 2024 22:22:56 +0000 Subject: [Autofill] Add DeviceConfig flags for Flags.multipleFillHistory Adds DeviceConfig flag session_fill_event_history that will guard against Flags.multipleFillHistory. This will allow us to do A/B experiment of this feature in Android Beta. Flag: android.service.autofill.multiple_fill_history Bug: 384076035 Test: atest CtsAutoFillServiceTestCases Change-Id: I6d0d875f3d5b602a871fb16000e5df3b2c59a6c2 --- .../view/autofill/AutofillFeatureFlags.java | 32 ++++++++++++++++++++++ .../autofill/AutofillManagerServiceImpl.java | 12 ++++---- .../java/com/android/server/autofill/Session.java | 29 ++++++++++++++++++-- 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/core/java/android/view/autofill/AutofillFeatureFlags.java b/core/java/android/view/autofill/AutofillFeatureFlags.java index 206e47f13890..0814e23eea87 100644 --- a/core/java/android/view/autofill/AutofillFeatureFlags.java +++ b/core/java/android/view/autofill/AutofillFeatureFlags.java @@ -21,6 +21,7 @@ import static android.service.autofill.Flags.improveFillDialogAconfig; import android.annotation.SuppressLint; import android.annotation.TestApi; import android.provider.DeviceConfig; +import android.service.autofill.Flags; import android.text.TextUtils; import android.util.ArraySet; import android.view.View; @@ -347,6 +348,14 @@ public class AutofillFeatureFlags { // END AUTOFILL REMOVE PRE_TRIGGER FLAGS + /** + * Whether per Session FillEventHistory is enabled. + * + * @hide + */ + public static final String DEVICE_CONFIG_SESSION_FILL_EVENT_HISTORY = + "session_fill_event_history"; + /** * Define the max input length for autofill to show suggesiton UI * @@ -408,6 +417,13 @@ public class AutofillFeatureFlags { public static final long DEFAULT_FILL_DIALOG_MIN_WAIT_AFTER_IME_ANIMATION_END_MS = 0; // 0 ms // END AUTOFILL REMOVE PRE_TRIGGER FLAGS DEFAULTS + /** + * Default for whether per Session FillEventHistory is enabled + * + * @hide + */ + public static final boolean DEFAULT_SESSION_FILL_EVENT_HISTORY_ENABLED = false; + /** * @hide */ @@ -697,4 +713,20 @@ public class AutofillFeatureFlags { DEVICE_CONFIG_FILL_DIALOG_MIN_WAIT_AFTER_IME_ANIMATION_END_MS, DEFAULT_FILL_DIALOG_MIN_WAIT_AFTER_IME_ANIMATION_END_MS); } + + /** + * Whether tracking FillEventHistory per Session is enabled + * + * @hide + */ + public static boolean isMultipleFillEventHistoryEnabled() { + if (!Flags.multipleFillHistory()) { + return false; + } + + return DeviceConfig.getBoolean( + DeviceConfig.NAMESPACE_AUTOFILL, + DEVICE_CONFIG_SESSION_FILL_EVENT_HISTORY, + DEFAULT_SESSION_FILL_EVENT_HISTORY_ENABLED); + } } diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java index 11710c9d8a9b..b39b5b1a7660 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java @@ -73,6 +73,7 @@ import android.util.LocalLog; import android.util.Pair; import android.util.Slog; import android.util.SparseArray; +import android.view.autofill.AutofillFeatureFlags; import android.view.autofill.AutofillId; import android.view.autofill.AutofillManager; import android.view.autofill.AutofillManager.AutofillCommitReason; @@ -672,7 +673,7 @@ final class AutofillManagerServiceImpl flags, mInputMethodManagerInternal, isPrimaryCredential); mSessions.put(newSession.id, newSession); - if (Flags.multipleFillHistory() && !forAugmentedAutofillOnly) { + if (AutofillFeatureFlags.isMultipleFillEventHistoryEnabled() && !forAugmentedAutofillOnly) { mFillHistories.put(newSession.id, new FillEventHistory(sessionId, null)); } @@ -772,7 +773,8 @@ final class AutofillManagerServiceImpl FillEventHistory history = null; - if (Flags.multipleFillHistory() && mFillHistories != null) { + if (AutofillFeatureFlags.isMultipleFillEventHistoryEnabled() + && mFillHistories != null) { history = mFillHistories.get(sessionId); mFillHistories.delete(sessionId); } @@ -922,7 +924,7 @@ final class AutofillManagerServiceImpl } } mSessions.clear(); - if (Flags.multipleFillHistory()) { + if (AutofillFeatureFlags.isMultipleFillEventHistoryEnabled()) { mFillHistories.clear(); } @@ -991,7 +993,7 @@ final class AutofillManagerServiceImpl mEventHistory.addEvent(event); } - if (Flags.multipleFillHistory()) { + if (AutofillFeatureFlags.isMultipleFillEventHistoryEnabled()) { FillEventHistory history = mFillHistories.get(sessionId); if (history != null) { history.addEvent(event); @@ -1180,7 +1182,7 @@ final class AutofillManagerServiceImpl logViewEnteredForHistory(sessionId, clientState, mEventHistory, focusedId); } - if (Flags.multipleFillHistory()) { + if (AutofillFeatureFlags.isMultipleFillEventHistoryEnabled()) { FillEventHistory history = mFillHistories.get(sessionId); if (history != null) { logViewEnteredForHistory(sessionId, clientState, history, focusedId); diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java index 3ecff3b3ebae..6fdb2b6b83f7 100644 --- a/services/autofill/java/com/android/server/autofill/Session.java +++ b/services/autofill/java/com/android/server/autofill/Session.java @@ -441,6 +441,9 @@ final class Session @GuardedBy("mLock") private Bundle mClientState; + @GuardedBy("mLock") + private Bundle mClientStateForSecondary; + @GuardedBy("mLock") boolean mDestroyed; @@ -980,13 +983,19 @@ final class Session mergePreviousSessionLocked(/* forSave= */ false); final List hints = getTypeHintsForProvider(); + Bundle sendBackClientState = mClientState; + if (Flags.multipleFillHistory() + && mRequestId.isSecondaryProvider(requestId)) { + sendBackClientState = mClientStateForSecondary; + } + mDelayedFillPendingIntent = createPendingIntent(requestId); request = new FillRequest( requestId, contexts, hints, - mClientState, + sendBackClientState, flags, /* inlineSuggestionsRequest= */ null, /* delayedFillIntentSender= */ mDelayedFillPendingIntent == null @@ -3317,7 +3326,7 @@ final class Session AUTHENTICATION_RESULT_SUCCESS); if (newClientState != null) { if (sDebug) Slog.d(TAG, "Updating client state from auth dataset"); - mClientState = newClientState; + setClientState(newClientState, requestId); } Dataset datasetFromResult = getEffectiveDatasetForAuthentication((Dataset) result); final Dataset oldDataset = authenticatedResponse.getDatasets().get(datasetIdx); @@ -6699,6 +6708,18 @@ final class Session remoteService.onDestroyAutofillWindowsRequest(); } + @GuardedBy("mLock") + private void setClientState(@Nullable Bundle newClientState, int requestId) { + if (Flags.multipleFillHistory() + && mRequestId.isSecondaryProvider(requestId)) { + // Set the secondary clientstate + mClientStateForSecondary = newClientState; + } else { + // The old way - only set the primary provider clientstate + mClientState = newClientState; + } + } + @GuardedBy("mLock") private void processResponseLocked( @NonNull FillResponse newResponse, @Nullable Bundle newClientState, int flags) { @@ -6734,7 +6755,9 @@ final class Session mResponses = new SparseArray<>(2); } mResponses.put(requestId, newResponse); - mClientState = newClientState != null ? newClientState : newResponse.getClientState(); + + setClientState(newClientState != null ? newClientState : newResponse.getClientState(), + requestId); boolean webviewRequestedCredman = newClientState != null -- cgit v1.2.3-59-g8ed1b