Loading services/autofill/java/com/android/server/autofill/Session.java +84 −100 Original line number Diff line number Diff line Loading @@ -422,15 +422,12 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState @GuardedBy("mLock") private FillRequest mPendingFillRequest; void newAutofillRequestLocked(boolean isInlineRequest) { @Nullable Consumer<InlineSuggestionsRequest> newAutofillRequestLocked(ViewState viewState, boolean isInlineRequest) { mPendingFillRequest = null; mWaitForInlineRequest = isInlineRequest; mPendingInlineSuggestionsRequest = null; } @NonNull Consumer<InlineSuggestionsRequest> newInlineRequestConsumerLocked( ViewState viewState) { return (inlineSuggestionsRequest) -> { return isInlineRequest ? (inlineSuggestionsRequest) -> { synchronized (mLock) { if (!mWaitForInlineRequest || mPendingInlineSuggestionsRequest != null) { return; Loading @@ -439,7 +436,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState maybeRequestFillLocked(); viewState.resetState(ViewState.STATE_PENDING_CREATE_INLINE_REQUEST); } }; } : null; } void maybeRequestFillLocked() { Loading Loading @@ -811,12 +808,32 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState // structure is taken. This causes only one fill request per burst of focus changes. cancelCurrentRequestLocked(); final Consumer<InlineSuggestionsRequest> inlineSuggestionsRequestConsumer = mAssistReceiver.newInlineRequestConsumerLocked(viewState); final boolean isInlineRequest = maybeRequestCreateInlineSuggestionsRequestLocked( /* isAugmented= */ false, inlineSuggestionsRequestConsumer, viewState, mCurrentViewId, flags); mAssistReceiver.newAutofillRequestLocked(isInlineRequest); // Only ask IME to create inline suggestions request if Autofill provider supports it and // the render service is available except the autofill is triggered manually and the view // is also not focused. final RemoteInlineSuggestionRenderService remoteRenderService = mService.getRemoteInlineSuggestionRenderServiceLocked(); if (mSessionFlags.mInlineSupportedByService && remoteRenderService != null && isViewFocusedLocked(flags)) { Consumer<InlineSuggestionsRequest> inlineSuggestionsRequestConsumer = mAssistReceiver.newAutofillRequestLocked(viewState, /* isInlineRequest= */ true); if (inlineSuggestionsRequestConsumer != null) { final AutofillId focusedId = mCurrentViewId; remoteRenderService.getInlineSuggestionsRendererInfo( new RemoteCallback((extras) -> { synchronized (mLock) { mInlineSessionController.onCreateInlineSuggestionsRequestLocked( focusedId, inlineSuggestionsRequestConsumer, extras); } }, mHandler) ); viewState.setState(ViewState.STATE_PENDING_CREATE_INLINE_REQUEST); } } else { mAssistReceiver.newAutofillRequestLocked(viewState, /* isInlineRequest= */ false); } // Now request the assist structure data. try { Loading @@ -836,60 +853,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } @GuardedBy("mLock") private boolean maybeRequestCreateInlineSuggestionsRequestLocked(boolean isAugmented, @NonNull Consumer<InlineSuggestionsRequest> requestConsumer, @NonNull ViewState viewState, @NonNull AutofillId focusedId, int flags) { final RemoteInlineSuggestionRenderService remoteRenderService = mService.getRemoteInlineSuggestionRenderServiceLocked(); if (remoteRenderService == null || !isViewFocusedLocked(flags)) { return false; } // Standard: // Only ask IME to create inline suggestions request if Autofill provider supports it // and the render service is available except the autofill is triggered manually and the // view is also not focused. // // Augmented: // When the inline suggestion render service is available and the view is focused, there // are 3 cases when augmented autofill should ask IME for inline suggestion request, // because standard autofill flow didn't: // 1. the field is augmented autofill only (when standard autofill provider is None or // when it returns null response) // 2. standard autofill provider doesn't support inline suggestion // 3. we re-entered the autofill session and standard autofill was not re-triggered, // this is recognized by seeing mExpiredResponse == true if ((!isAugmented && mSessionFlags.mInlineSupportedByService) || (isAugmented && (mSessionFlags.mAugmentedAutofillOnly || !mSessionFlags.mInlineSupportedByService || mSessionFlags.mExpiredResponse))) { if (sDebug) { Slog.d(TAG, "Create inline request for " + (isAugmented ? "augmented" : "standard") + " autofill"); } requestCreateInlineSuggestionsRequestLocked(remoteRenderService, focusedId, requestConsumer); viewState.setState(ViewState.STATE_PENDING_CREATE_INLINE_REQUEST); return true; } return false; } private void requestCreateInlineSuggestionsRequestLocked( @NonNull RemoteInlineSuggestionRenderService remoteRenderService, @NonNull AutofillId focusedId, @NonNull Consumer<InlineSuggestionsRequest> requestConsumer) { remoteRenderService.getInlineSuggestionsRendererInfo( new RemoteCallback((extras) -> { synchronized (mLock) { mInlineSessionController.onCreateInlineSuggestionsRequestLocked( focusedId, requestConsumer, extras); } }, mHandler)); } Session(@NonNull AutofillManagerServiceImpl service, @NonNull AutoFillUI ui, @NonNull Context context, @NonNull Handler handler, int userId, @NonNull Object lock, int sessionId, int taskId, int uid, @NonNull IBinder activityToken, Loading Loading @@ -2607,27 +2570,23 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } /** * Invokes either regular or augmented autofill process upon entering a view. * Starts (if necessary) a new fill request upon entering a view. * * <p> A new standard autofill request will be started in 2 scenarios: * <p>A new request will be started in 2 scenarios: * <ol> * <li>If the user manually requested autofill. * <li>If the view is part of a new partition. * </ol> * </p> * * <p> A new augmented autofill request will be started if the autofill id was marked as * uninterested/unfillable by the standard service. * * @param id The id of the view that is entered. * @param viewState The view that is entered. * @param flags The flag that was passed by the AutofillManager. * * @return {@code true} if either regular or augmented autofill is invoked. * @return {@code true} if a new fill response is requested. */ @GuardedBy("mLock") private boolean maybeRequestFillOnViewEnteredLocked(@NonNull AutofillId id, @NonNull ViewState viewState, boolean isSameViewEntered, int flags) { private boolean requestNewFillResponseOnViewEnteredIfNecessaryLocked(@NonNull AutofillId id, @NonNull ViewState viewState, int flags) { if ((flags & FLAG_MANUAL_REQUEST) != 0) { mSessionFlags.mAugmentedAutofillOnly = false; if (sDebug) Slog.d(TAG, "Re-starting session on view " + id + " and flags " + flags); Loading @@ -2635,24 +2594,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return true; } if (mAugmentedAutofillableIds != null && mAugmentedAutofillableIds.contains(id)) { // Regular autofill handled the view and returned null response, but it can trigger // augmented autofill. if (!isSameViewEntered) { if (sDebug) Slog.d(TAG, "trigger augmented autofill."); triggerAugmentedAutofillLocked(flags); } else { if (sDebug) Slog.d(TAG, "skip augmented autofill for same view."); } return true; } else if (mSessionFlags.mAugmentedAutofillOnly && isSameViewEntered) { // Regular autofill is disabled. if (sDebug) Slog.d(TAG, "skip augmented autofill for same view."); return true; } // If it's not for augmented, then check if it should start a partition for // regular autofill. // If it's not, then check if it it should start a partition. if (shouldStartNewPartitionLocked(id)) { if (sDebug) { Slog.d(TAG, "Starting partition or augmented request for view id " + id + ": " Loading Loading @@ -2847,7 +2789,27 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return; } if (maybeRequestFillOnViewEnteredLocked(id, viewState, isSameViewEntered, flags)) { if ((flags & FLAG_MANUAL_REQUEST) == 0) { // Not a manual request if (mAugmentedAutofillableIds != null && mAugmentedAutofillableIds.contains( id)) { // Regular autofill handled the view and returned null response, but it // triggered augmented autofill if (!isSameViewEntered) { if (sDebug) Slog.d(TAG, "trigger augmented autofill."); triggerAugmentedAutofillLocked(flags); } else { if (sDebug) Slog.d(TAG, "skip augmented autofill for same view."); } return; } else if (mSessionFlags.mAugmentedAutofillOnly && isSameViewEntered) { // Regular autofill is disabled. if (sDebug) Slog.d(TAG, "skip augmented autofill for same view."); return; } } if (requestNewFillResponseOnViewEnteredIfNecessaryLocked(id, viewState, flags)) { return; } Loading Loading @@ -3445,12 +3407,34 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } }; if (!maybeRequestCreateInlineSuggestionsRequestLocked(/* isAugmented= */ true, requestAugmentedAutofill, viewState, focusedId, flags)) { // When the inline suggestion render service is available and the view is focused, there // are 3 cases when augmented autofill should ask IME for inline suggestion request, // because standard autofill flow didn't: // 1. the field is augmented autofill only (when standard autofill provider is None or // when it returns null response) // 2. standard autofill provider doesn't support inline suggestion // 3. we re-entered the autofill session and standard autofill was not re-triggered, this is // recognized by seeing mExpiredResponse == true final RemoteInlineSuggestionRenderService remoteRenderService = mService.getRemoteInlineSuggestionRenderServiceLocked(); if (remoteRenderService != null && (mSessionFlags.mAugmentedAutofillOnly || !mSessionFlags.mInlineSupportedByService || mSessionFlags.mExpiredResponse) && isViewFocusedLocked(flags)) { if (sDebug) Slog.d(TAG, "Create inline request for augmented autofill"); remoteRenderService.getInlineSuggestionsRendererInfo(new RemoteCallback( (extras) -> { synchronized (mLock) { mInlineSessionController.onCreateInlineSuggestionsRequestLocked( focusedId, /*requestConsumer=*/ requestAugmentedAutofill, extras); } }, mHandler)); } else { requestAugmentedAutofill.accept( mInlineSessionController.getInlineSuggestionsRequestLocked().orElse(null)); } if (mAugmentedAutofillDestroyer == null) { mAugmentedAutofillDestroyer = remoteService::onDestroyAutofillWindowsRequest; } Loading Loading
services/autofill/java/com/android/server/autofill/Session.java +84 −100 Original line number Diff line number Diff line Loading @@ -422,15 +422,12 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState @GuardedBy("mLock") private FillRequest mPendingFillRequest; void newAutofillRequestLocked(boolean isInlineRequest) { @Nullable Consumer<InlineSuggestionsRequest> newAutofillRequestLocked(ViewState viewState, boolean isInlineRequest) { mPendingFillRequest = null; mWaitForInlineRequest = isInlineRequest; mPendingInlineSuggestionsRequest = null; } @NonNull Consumer<InlineSuggestionsRequest> newInlineRequestConsumerLocked( ViewState viewState) { return (inlineSuggestionsRequest) -> { return isInlineRequest ? (inlineSuggestionsRequest) -> { synchronized (mLock) { if (!mWaitForInlineRequest || mPendingInlineSuggestionsRequest != null) { return; Loading @@ -439,7 +436,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState maybeRequestFillLocked(); viewState.resetState(ViewState.STATE_PENDING_CREATE_INLINE_REQUEST); } }; } : null; } void maybeRequestFillLocked() { Loading Loading @@ -811,12 +808,32 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState // structure is taken. This causes only one fill request per burst of focus changes. cancelCurrentRequestLocked(); final Consumer<InlineSuggestionsRequest> inlineSuggestionsRequestConsumer = mAssistReceiver.newInlineRequestConsumerLocked(viewState); final boolean isInlineRequest = maybeRequestCreateInlineSuggestionsRequestLocked( /* isAugmented= */ false, inlineSuggestionsRequestConsumer, viewState, mCurrentViewId, flags); mAssistReceiver.newAutofillRequestLocked(isInlineRequest); // Only ask IME to create inline suggestions request if Autofill provider supports it and // the render service is available except the autofill is triggered manually and the view // is also not focused. final RemoteInlineSuggestionRenderService remoteRenderService = mService.getRemoteInlineSuggestionRenderServiceLocked(); if (mSessionFlags.mInlineSupportedByService && remoteRenderService != null && isViewFocusedLocked(flags)) { Consumer<InlineSuggestionsRequest> inlineSuggestionsRequestConsumer = mAssistReceiver.newAutofillRequestLocked(viewState, /* isInlineRequest= */ true); if (inlineSuggestionsRequestConsumer != null) { final AutofillId focusedId = mCurrentViewId; remoteRenderService.getInlineSuggestionsRendererInfo( new RemoteCallback((extras) -> { synchronized (mLock) { mInlineSessionController.onCreateInlineSuggestionsRequestLocked( focusedId, inlineSuggestionsRequestConsumer, extras); } }, mHandler) ); viewState.setState(ViewState.STATE_PENDING_CREATE_INLINE_REQUEST); } } else { mAssistReceiver.newAutofillRequestLocked(viewState, /* isInlineRequest= */ false); } // Now request the assist structure data. try { Loading @@ -836,60 +853,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } @GuardedBy("mLock") private boolean maybeRequestCreateInlineSuggestionsRequestLocked(boolean isAugmented, @NonNull Consumer<InlineSuggestionsRequest> requestConsumer, @NonNull ViewState viewState, @NonNull AutofillId focusedId, int flags) { final RemoteInlineSuggestionRenderService remoteRenderService = mService.getRemoteInlineSuggestionRenderServiceLocked(); if (remoteRenderService == null || !isViewFocusedLocked(flags)) { return false; } // Standard: // Only ask IME to create inline suggestions request if Autofill provider supports it // and the render service is available except the autofill is triggered manually and the // view is also not focused. // // Augmented: // When the inline suggestion render service is available and the view is focused, there // are 3 cases when augmented autofill should ask IME for inline suggestion request, // because standard autofill flow didn't: // 1. the field is augmented autofill only (when standard autofill provider is None or // when it returns null response) // 2. standard autofill provider doesn't support inline suggestion // 3. we re-entered the autofill session and standard autofill was not re-triggered, // this is recognized by seeing mExpiredResponse == true if ((!isAugmented && mSessionFlags.mInlineSupportedByService) || (isAugmented && (mSessionFlags.mAugmentedAutofillOnly || !mSessionFlags.mInlineSupportedByService || mSessionFlags.mExpiredResponse))) { if (sDebug) { Slog.d(TAG, "Create inline request for " + (isAugmented ? "augmented" : "standard") + " autofill"); } requestCreateInlineSuggestionsRequestLocked(remoteRenderService, focusedId, requestConsumer); viewState.setState(ViewState.STATE_PENDING_CREATE_INLINE_REQUEST); return true; } return false; } private void requestCreateInlineSuggestionsRequestLocked( @NonNull RemoteInlineSuggestionRenderService remoteRenderService, @NonNull AutofillId focusedId, @NonNull Consumer<InlineSuggestionsRequest> requestConsumer) { remoteRenderService.getInlineSuggestionsRendererInfo( new RemoteCallback((extras) -> { synchronized (mLock) { mInlineSessionController.onCreateInlineSuggestionsRequestLocked( focusedId, requestConsumer, extras); } }, mHandler)); } Session(@NonNull AutofillManagerServiceImpl service, @NonNull AutoFillUI ui, @NonNull Context context, @NonNull Handler handler, int userId, @NonNull Object lock, int sessionId, int taskId, int uid, @NonNull IBinder activityToken, Loading Loading @@ -2607,27 +2570,23 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } /** * Invokes either regular or augmented autofill process upon entering a view. * Starts (if necessary) a new fill request upon entering a view. * * <p> A new standard autofill request will be started in 2 scenarios: * <p>A new request will be started in 2 scenarios: * <ol> * <li>If the user manually requested autofill. * <li>If the view is part of a new partition. * </ol> * </p> * * <p> A new augmented autofill request will be started if the autofill id was marked as * uninterested/unfillable by the standard service. * * @param id The id of the view that is entered. * @param viewState The view that is entered. * @param flags The flag that was passed by the AutofillManager. * * @return {@code true} if either regular or augmented autofill is invoked. * @return {@code true} if a new fill response is requested. */ @GuardedBy("mLock") private boolean maybeRequestFillOnViewEnteredLocked(@NonNull AutofillId id, @NonNull ViewState viewState, boolean isSameViewEntered, int flags) { private boolean requestNewFillResponseOnViewEnteredIfNecessaryLocked(@NonNull AutofillId id, @NonNull ViewState viewState, int flags) { if ((flags & FLAG_MANUAL_REQUEST) != 0) { mSessionFlags.mAugmentedAutofillOnly = false; if (sDebug) Slog.d(TAG, "Re-starting session on view " + id + " and flags " + flags); Loading @@ -2635,24 +2594,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return true; } if (mAugmentedAutofillableIds != null && mAugmentedAutofillableIds.contains(id)) { // Regular autofill handled the view and returned null response, but it can trigger // augmented autofill. if (!isSameViewEntered) { if (sDebug) Slog.d(TAG, "trigger augmented autofill."); triggerAugmentedAutofillLocked(flags); } else { if (sDebug) Slog.d(TAG, "skip augmented autofill for same view."); } return true; } else if (mSessionFlags.mAugmentedAutofillOnly && isSameViewEntered) { // Regular autofill is disabled. if (sDebug) Slog.d(TAG, "skip augmented autofill for same view."); return true; } // If it's not for augmented, then check if it should start a partition for // regular autofill. // If it's not, then check if it it should start a partition. if (shouldStartNewPartitionLocked(id)) { if (sDebug) { Slog.d(TAG, "Starting partition or augmented request for view id " + id + ": " Loading Loading @@ -2847,7 +2789,27 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return; } if (maybeRequestFillOnViewEnteredLocked(id, viewState, isSameViewEntered, flags)) { if ((flags & FLAG_MANUAL_REQUEST) == 0) { // Not a manual request if (mAugmentedAutofillableIds != null && mAugmentedAutofillableIds.contains( id)) { // Regular autofill handled the view and returned null response, but it // triggered augmented autofill if (!isSameViewEntered) { if (sDebug) Slog.d(TAG, "trigger augmented autofill."); triggerAugmentedAutofillLocked(flags); } else { if (sDebug) Slog.d(TAG, "skip augmented autofill for same view."); } return; } else if (mSessionFlags.mAugmentedAutofillOnly && isSameViewEntered) { // Regular autofill is disabled. if (sDebug) Slog.d(TAG, "skip augmented autofill for same view."); return; } } if (requestNewFillResponseOnViewEnteredIfNecessaryLocked(id, viewState, flags)) { return; } Loading Loading @@ -3445,12 +3407,34 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } }; if (!maybeRequestCreateInlineSuggestionsRequestLocked(/* isAugmented= */ true, requestAugmentedAutofill, viewState, focusedId, flags)) { // When the inline suggestion render service is available and the view is focused, there // are 3 cases when augmented autofill should ask IME for inline suggestion request, // because standard autofill flow didn't: // 1. the field is augmented autofill only (when standard autofill provider is None or // when it returns null response) // 2. standard autofill provider doesn't support inline suggestion // 3. we re-entered the autofill session and standard autofill was not re-triggered, this is // recognized by seeing mExpiredResponse == true final RemoteInlineSuggestionRenderService remoteRenderService = mService.getRemoteInlineSuggestionRenderServiceLocked(); if (remoteRenderService != null && (mSessionFlags.mAugmentedAutofillOnly || !mSessionFlags.mInlineSupportedByService || mSessionFlags.mExpiredResponse) && isViewFocusedLocked(flags)) { if (sDebug) Slog.d(TAG, "Create inline request for augmented autofill"); remoteRenderService.getInlineSuggestionsRendererInfo(new RemoteCallback( (extras) -> { synchronized (mLock) { mInlineSessionController.onCreateInlineSuggestionsRequestLocked( focusedId, /*requestConsumer=*/ requestAugmentedAutofill, extras); } }, mHandler)); } else { requestAugmentedAutofill.accept( mInlineSessionController.getInlineSuggestionsRequestLocked().orElse(null)); } if (mAugmentedAutofillDestroyer == null) { mAugmentedAutofillDestroyer = remoteService::onDestroyAutofillWindowsRequest; } Loading