[DO NOT MERGE] Fix Memory Leak: Part II of rewrite render info callback
Bug:270049350 Test: atest CtsAutoFillServiceTestCases Change-Id: I72d6e59e68e1c5e2f4cc733a34e78e7ff3f1daf0
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* 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.util.Slog;
|
||||||
|
import android.view.inputmethod.InlineSuggestionsRequest;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
class InlineSuggestionRequestConsumer implements Consumer<InlineSuggestionsRequest> {
|
||||||
|
|
||||||
|
static final String TAG = "InlineSuggestionRequestConsumer";
|
||||||
|
|
||||||
|
private final WeakReference<Session.AssistDataReceiverImpl> mAssistDataReceiverWeakReference;
|
||||||
|
private final WeakReference<ViewState> mViewStateWeakReference;
|
||||||
|
|
||||||
|
InlineSuggestionRequestConsumer(WeakReference<Session.AssistDataReceiverImpl>
|
||||||
|
assistDataReceiverWeakReference,
|
||||||
|
WeakReference<ViewState> viewStateWeakReference) {
|
||||||
|
mAssistDataReceiverWeakReference = assistDataReceiverWeakReference;
|
||||||
|
mViewStateWeakReference = viewStateWeakReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(InlineSuggestionsRequest inlineSuggestionsRequest) {
|
||||||
|
Session.AssistDataReceiverImpl assistDataReceiver = mAssistDataReceiverWeakReference.get();
|
||||||
|
ViewState viewState = mViewStateWeakReference.get();
|
||||||
|
if (assistDataReceiver == null) {
|
||||||
|
Slog.wtf(TAG, "assistDataReceiver is null when accepting new inline suggestion"
|
||||||
|
+ "requests");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (viewState == null) {
|
||||||
|
Slog.wtf(TAG, "view state is null when accepting new inline suggestion requests");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assistDataReceiver.handleInlineSuggestionRequest(inlineSuggestionsRequest, viewState);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -307,7 +307,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
* Id of the View currently being displayed.
|
* Id of the View currently being displayed.
|
||||||
*/
|
*/
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
@Nullable AutofillId mCurrentViewId;
|
private @Nullable AutofillId mCurrentViewId;
|
||||||
|
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private IAutoFillManagerClient mClient;
|
private IAutoFillManagerClient mClient;
|
||||||
@@ -595,7 +595,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
* TODO(b/151867668): improve how asynchronous data dependencies are handled, without using
|
* TODO(b/151867668): improve how asynchronous data dependencies are handled, without using
|
||||||
* CountDownLatch.
|
* CountDownLatch.
|
||||||
*/
|
*/
|
||||||
private final class AssistDataReceiverImpl extends IAssistDataReceiver.Stub {
|
final class AssistDataReceiverImpl extends IAssistDataReceiver.Stub {
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private boolean mWaitForInlineRequest;
|
private boolean mWaitForInlineRequest;
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
@@ -610,7 +610,19 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
mPendingFillRequest = null;
|
mPendingFillRequest = null;
|
||||||
mWaitForInlineRequest = isInlineRequest;
|
mWaitForInlineRequest = isInlineRequest;
|
||||||
mPendingInlineSuggestionsRequest = null;
|
mPendingInlineSuggestionsRequest = null;
|
||||||
return isInlineRequest ? (inlineSuggestionsRequest) -> {
|
if (isInlineRequest) {
|
||||||
|
WeakReference<AssistDataReceiverImpl> assistDataReceiverWeakReference =
|
||||||
|
new WeakReference<AssistDataReceiverImpl>(this);
|
||||||
|
WeakReference<ViewState> viewStateWeakReference =
|
||||||
|
new WeakReference<ViewState>(viewState);
|
||||||
|
return new InlineSuggestionRequestConsumer(assistDataReceiverWeakReference,
|
||||||
|
viewStateWeakReference);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleInlineSuggestionRequest(InlineSuggestionsRequest inlineSuggestionsRequest,
|
||||||
|
ViewState viewState) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (!mWaitForInlineRequest || mPendingInlineSuggestionsRequest != null) {
|
if (!mWaitForInlineRequest || mPendingInlineSuggestionsRequest != null) {
|
||||||
return;
|
return;
|
||||||
@@ -620,7 +632,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
maybeRequestFillLocked();
|
maybeRequestFillLocked();
|
||||||
viewState.resetState(ViewState.STATE_PENDING_CREATE_INLINE_REQUEST);
|
viewState.resetState(ViewState.STATE_PENDING_CREATE_INLINE_REQUEST);
|
||||||
}
|
}
|
||||||
} : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
|
|||||||
Reference in New Issue
Block a user