Loading services/autofill/java/com/android/server/autofill/InlineSuggestionRendorInfoCallbackOnResultListener.java 0 → 100644 +65 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.autofill; import android.annotation.Nullable; import android.os.Bundle; import android.os.RemoteCallback; import android.util.Slog; import android.view.autofill.AutofillId; import android.view.inputmethod.InlineSuggestionsRequest; import java.lang.ref.WeakReference; import java.util.function.Consumer; final class InlineSuggestionRendorInfoCallbackOnResultListener implements RemoteCallback.OnResultListener{ private static final String TAG = "InlineSuggestionRendorInfoCallbackOnResultListener"; private final int mRequestIdCopy; private final AutofillId mFocusedId; private final WeakReference<Session> mSessionWeakReference; private final Consumer<InlineSuggestionsRequest> mInlineSuggestionsRequestConsumer; InlineSuggestionRendorInfoCallbackOnResultListener(WeakReference<Session> sessionWeakReference, int requestIdCopy, Consumer<InlineSuggestionsRequest> inlineSuggestionsRequestConsumer, AutofillId focusedId) { this.mRequestIdCopy = requestIdCopy; this.mInlineSuggestionsRequestConsumer = inlineSuggestionsRequestConsumer; this.mSessionWeakReference = sessionWeakReference; this.mFocusedId = focusedId; } public void onResult(@Nullable Bundle result) { Session session = this.mSessionWeakReference.get(); if (session == null) { Slog.wtf(TAG, "Session is null before trying to call onResult"); return; } synchronized (session.mLock) { if (session.mDestroyed) { Slog.wtf(TAG, "Session is destroyed before trying to call onResult"); return; } session.mInlineSessionController.onCreateInlineSuggestionsRequestLocked( this.mFocusedId, session.inlineSuggestionsRequestCacheDecorator( this.mInlineSuggestionsRequestConsumer, this.mRequestIdCopy), result); } } } services/autofill/java/com/android/server/autofill/Session.java +23 −16 Original line number Diff line number Diff line Loading @@ -184,6 +184,7 @@ import com.android.server.wm.ActivityTaskManagerInternal; import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; Loading Loading @@ -321,7 +322,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState * Id of the View currently being displayed. */ @GuardedBy("mLock") @Nullable private AutofillId mCurrentViewId; @Nullable AutofillId mCurrentViewId; @GuardedBy("mLock") private IAutoFillManagerClient mClient; Loading Loading @@ -369,7 +370,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState private Bundle mClientState; @GuardedBy("mLock") private boolean mDestroyed; boolean mDestroyed; /** * Helper used to handle state of Save UI when it must be hiding to show a custom description Loading Loading @@ -448,7 +449,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState private ArrayList<AutofillId> mAugmentedAutofillableIds; @NonNull private final AutofillInlineSessionController mInlineSessionController; final AutofillInlineSessionController mInlineSessionController; /** * Receiver of assist data from the app's {@link Activity}. Loading Loading @@ -1226,22 +1227,28 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState if (mSessionFlags.mInlineSupportedByService && remoteRenderService != null && (isViewFocusedLocked(flags) || isRequestSupportFillDialog(flags))) { Consumer<InlineSuggestionsRequest> inlineSuggestionsRequestConsumer = mAssistReceiver.newAutofillRequestLocked(viewState, /* isInlineRequest= */ true); if (inlineSuggestionsRequestConsumer != null) { final AutofillId focusedId = mCurrentViewId; final int requestIdCopy = requestId; final AutofillId focusedId = mCurrentViewId; WeakReference sessionWeakReference = new WeakReference<Session>(this); InlineSuggestionRendorInfoCallbackOnResultListener inlineSuggestionRendorInfoCallbackOnResultListener = new InlineSuggestionRendorInfoCallbackOnResultListener( sessionWeakReference, requestIdCopy, inlineSuggestionsRequestConsumer, focusedId); RemoteCallback inlineSuggestionRendorInfoCallback = new RemoteCallback( inlineSuggestionRendorInfoCallbackOnResultListener, mHandler); remoteRenderService.getInlineSuggestionsRendererInfo( new RemoteCallback((extras) -> { synchronized (mLock) { mInlineSessionController.onCreateInlineSuggestionsRequestLocked( focusedId, inlineSuggestionsRequestCacheDecorator( inlineSuggestionsRequestConsumer, requestIdCopy), extras); } }, mHandler) ); inlineSuggestionRendorInfoCallback); viewState.setState(ViewState.STATE_PENDING_CREATE_INLINE_REQUEST); } } else { Loading Loading @@ -5151,7 +5158,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } @NonNull private Consumer<InlineSuggestionsRequest> inlineSuggestionsRequestCacheDecorator( Consumer<InlineSuggestionsRequest> inlineSuggestionsRequestCacheDecorator( @NonNull Consumer<InlineSuggestionsRequest> consumer, int requestId) { return inlineSuggestionsRequest -> { consumer.accept(inlineSuggestionsRequest); Loading Loading
services/autofill/java/com/android/server/autofill/InlineSuggestionRendorInfoCallbackOnResultListener.java 0 → 100644 +65 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.autofill; import android.annotation.Nullable; import android.os.Bundle; import android.os.RemoteCallback; import android.util.Slog; import android.view.autofill.AutofillId; import android.view.inputmethod.InlineSuggestionsRequest; import java.lang.ref.WeakReference; import java.util.function.Consumer; final class InlineSuggestionRendorInfoCallbackOnResultListener implements RemoteCallback.OnResultListener{ private static final String TAG = "InlineSuggestionRendorInfoCallbackOnResultListener"; private final int mRequestIdCopy; private final AutofillId mFocusedId; private final WeakReference<Session> mSessionWeakReference; private final Consumer<InlineSuggestionsRequest> mInlineSuggestionsRequestConsumer; InlineSuggestionRendorInfoCallbackOnResultListener(WeakReference<Session> sessionWeakReference, int requestIdCopy, Consumer<InlineSuggestionsRequest> inlineSuggestionsRequestConsumer, AutofillId focusedId) { this.mRequestIdCopy = requestIdCopy; this.mInlineSuggestionsRequestConsumer = inlineSuggestionsRequestConsumer; this.mSessionWeakReference = sessionWeakReference; this.mFocusedId = focusedId; } public void onResult(@Nullable Bundle result) { Session session = this.mSessionWeakReference.get(); if (session == null) { Slog.wtf(TAG, "Session is null before trying to call onResult"); return; } synchronized (session.mLock) { if (session.mDestroyed) { Slog.wtf(TAG, "Session is destroyed before trying to call onResult"); return; } session.mInlineSessionController.onCreateInlineSuggestionsRequestLocked( this.mFocusedId, session.inlineSuggestionsRequestCacheDecorator( this.mInlineSuggestionsRequestConsumer, this.mRequestIdCopy), result); } } }
services/autofill/java/com/android/server/autofill/Session.java +23 −16 Original line number Diff line number Diff line Loading @@ -184,6 +184,7 @@ import com.android.server.wm.ActivityTaskManagerInternal; import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; Loading Loading @@ -321,7 +322,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState * Id of the View currently being displayed. */ @GuardedBy("mLock") @Nullable private AutofillId mCurrentViewId; @Nullable AutofillId mCurrentViewId; @GuardedBy("mLock") private IAutoFillManagerClient mClient; Loading Loading @@ -369,7 +370,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState private Bundle mClientState; @GuardedBy("mLock") private boolean mDestroyed; boolean mDestroyed; /** * Helper used to handle state of Save UI when it must be hiding to show a custom description Loading Loading @@ -448,7 +449,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState private ArrayList<AutofillId> mAugmentedAutofillableIds; @NonNull private final AutofillInlineSessionController mInlineSessionController; final AutofillInlineSessionController mInlineSessionController; /** * Receiver of assist data from the app's {@link Activity}. Loading Loading @@ -1226,22 +1227,28 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState if (mSessionFlags.mInlineSupportedByService && remoteRenderService != null && (isViewFocusedLocked(flags) || isRequestSupportFillDialog(flags))) { Consumer<InlineSuggestionsRequest> inlineSuggestionsRequestConsumer = mAssistReceiver.newAutofillRequestLocked(viewState, /* isInlineRequest= */ true); if (inlineSuggestionsRequestConsumer != null) { final AutofillId focusedId = mCurrentViewId; final int requestIdCopy = requestId; final AutofillId focusedId = mCurrentViewId; WeakReference sessionWeakReference = new WeakReference<Session>(this); InlineSuggestionRendorInfoCallbackOnResultListener inlineSuggestionRendorInfoCallbackOnResultListener = new InlineSuggestionRendorInfoCallbackOnResultListener( sessionWeakReference, requestIdCopy, inlineSuggestionsRequestConsumer, focusedId); RemoteCallback inlineSuggestionRendorInfoCallback = new RemoteCallback( inlineSuggestionRendorInfoCallbackOnResultListener, mHandler); remoteRenderService.getInlineSuggestionsRendererInfo( new RemoteCallback((extras) -> { synchronized (mLock) { mInlineSessionController.onCreateInlineSuggestionsRequestLocked( focusedId, inlineSuggestionsRequestCacheDecorator( inlineSuggestionsRequestConsumer, requestIdCopy), extras); } }, mHandler) ); inlineSuggestionRendorInfoCallback); viewState.setState(ViewState.STATE_PENDING_CREATE_INLINE_REQUEST); } } else { Loading Loading @@ -5151,7 +5158,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } @NonNull private Consumer<InlineSuggestionsRequest> inlineSuggestionsRequestCacheDecorator( Consumer<InlineSuggestionsRequest> inlineSuggestionsRequestCacheDecorator( @NonNull Consumer<InlineSuggestionsRequest> consumer, int requestId) { return inlineSuggestionsRequest -> { consumer.accept(inlineSuggestionsRequest); Loading