[DO NOT MERGE] Fix Memory Leak: Part II of rewrite render info callback am: e22573d1d8
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23416834 Change-Id: Ief6e710c46e8baf5bf19d5a98128ddb9e42161d0 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -323,7 +323,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;
|
||||||
@@ -614,7 +614,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")
|
||||||
@@ -629,17 +629,28 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
mPendingFillRequest = null;
|
mPendingFillRequest = null;
|
||||||
mWaitForInlineRequest = isInlineRequest;
|
mWaitForInlineRequest = isInlineRequest;
|
||||||
mPendingInlineSuggestionsRequest = null;
|
mPendingInlineSuggestionsRequest = null;
|
||||||
return isInlineRequest ? (inlineSuggestionsRequest) -> {
|
if (isInlineRequest) {
|
||||||
synchronized (mLock) {
|
WeakReference<AssistDataReceiverImpl> assistDataReceiverWeakReference =
|
||||||
if (!mWaitForInlineRequest || mPendingInlineSuggestionsRequest != null) {
|
new WeakReference<AssistDataReceiverImpl>(this);
|
||||||
return;
|
WeakReference<ViewState> viewStateWeakReference =
|
||||||
}
|
new WeakReference<ViewState>(viewState);
|
||||||
mWaitForInlineRequest = inlineSuggestionsRequest != null;
|
return new InlineSuggestionRequestConsumer(assistDataReceiverWeakReference,
|
||||||
mPendingInlineSuggestionsRequest = inlineSuggestionsRequest;
|
viewStateWeakReference);
|
||||||
maybeRequestFillLocked();
|
}
|
||||||
viewState.resetState(ViewState.STATE_PENDING_CREATE_INLINE_REQUEST);
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleInlineSuggestionRequest(InlineSuggestionsRequest inlineSuggestionsRequest,
|
||||||
|
ViewState viewState) {
|
||||||
|
synchronized (mLock) {
|
||||||
|
if (!mWaitForInlineRequest || mPendingInlineSuggestionsRequest != null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} : null;
|
mWaitForInlineRequest = inlineSuggestionsRequest != null;
|
||||||
|
mPendingInlineSuggestionsRequest = inlineSuggestionsRequest;
|
||||||
|
maybeRequestFillLocked();
|
||||||
|
viewState.resetState(ViewState.STATE_PENDING_CREATE_INLINE_REQUEST);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
|
|||||||
Reference in New Issue
Block a user