summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/autofill/java/com/android/server/autofill/InlineSuggestionRendorInfoCallbackOnResultListener.java65
-rw-r--r--services/autofill/java/com/android/server/autofill/Session.java32
2 files changed, 83 insertions, 14 deletions
diff --git a/services/autofill/java/com/android/server/autofill/InlineSuggestionRendorInfoCallbackOnResultListener.java b/services/autofill/java/com/android/server/autofill/InlineSuggestionRendorInfoCallbackOnResultListener.java
new file mode 100644
index 000000000000..7351ef59feca
--- /dev/null
+++ b/services/autofill/java/com/android/server/autofill/InlineSuggestionRendorInfoCallbackOnResultListener.java
@@ -0,0 +1,65 @@
+/*
+ * 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);
+ }
+ }
+}
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index 7b459aa4a0ad..119867d50573 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -324,7 +324,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;
@@ -372,7 +372,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
@@ -451,7 +451,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}.
@@ -1274,18 +1274,22 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
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 if (mSessionFlags.mClientSuggestionsEnabled) {
@@ -5426,7 +5430,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);