[DO NOT MERGE] Fix race in AbstractSinglePendingRequestRemoteService
Fixes: 135355306 Test: presubmit Change-Id: I78d9840a9d7e04cd373c967b259a614990153841
This commit is contained in:
@@ -60,10 +60,16 @@ public abstract class AbstractSinglePendingRequestRemoteService<S
|
|||||||
|
|
||||||
@Override // from AbstractRemoteService
|
@Override // from AbstractRemoteService
|
||||||
protected void handleOnDestroy() {
|
protected void handleOnDestroy() {
|
||||||
if (mPendingRequest != null) {
|
handleCancelPendingRequest();
|
||||||
mPendingRequest.cancel();
|
}
|
||||||
|
|
||||||
|
protected BasePendingRequest<S, I> handleCancelPendingRequest() {
|
||||||
|
BasePendingRequest<S, I> pendingRequest = mPendingRequest;
|
||||||
|
if (pendingRequest != null) {
|
||||||
|
pendingRequest.cancel();
|
||||||
mPendingRequest = null;
|
mPendingRequest = null;
|
||||||
}
|
}
|
||||||
|
return pendingRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from AbstractRemoteService
|
@Override // from AbstractRemoteService
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ import android.util.Slog;
|
|||||||
|
|
||||||
import com.android.internal.infra.AbstractSinglePendingRequestRemoteService;
|
import com.android.internal.infra.AbstractSinglePendingRequestRemoteService;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
final class RemoteFillService
|
final class RemoteFillService
|
||||||
extends AbstractSinglePendingRequestRemoteService<RemoteFillService, IAutoFillService> {
|
extends AbstractSinglePendingRequestRemoteService<RemoteFillService, IAutoFillService> {
|
||||||
|
|
||||||
@@ -103,26 +105,21 @@ final class RemoteFillService
|
|||||||
* <p>This can be used when the request is unnecessary or will be superceeded by a request that
|
* <p>This can be used when the request is unnecessary or will be superceeded by a request that
|
||||||
* will soon be queued.
|
* will soon be queued.
|
||||||
*
|
*
|
||||||
* @return the id of the canceled request, or {@link FillRequest#INVALID_REQUEST_ID} if no
|
* @return the future id of the canceled request, or {@link FillRequest#INVALID_REQUEST_ID} if
|
||||||
* {@link PendingFillRequest} was canceled.
|
* no {@link PendingFillRequest} was canceled.
|
||||||
*/
|
*/
|
||||||
// TODO(b/117779333): move this logic to super class (and make mPendingRequest private)
|
public CompletableFuture<Integer> cancelCurrentRequest() {
|
||||||
public int cancelCurrentRequest() {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
if (isDestroyed()) {
|
if (isDestroyed()) {
|
||||||
return INVALID_REQUEST_ID;
|
return INVALID_REQUEST_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
int requestId = INVALID_REQUEST_ID;
|
BasePendingRequest<RemoteFillService, IAutoFillService> canceledRequest =
|
||||||
if (mPendingRequest != null) {
|
handleCancelPendingRequest();
|
||||||
if (mPendingRequest instanceof PendingFillRequest) {
|
return canceledRequest instanceof PendingFillRequest
|
||||||
requestId = ((PendingFillRequest) mPendingRequest).mRequest.getId();
|
? ((PendingFillRequest) canceledRequest).mRequest.getId()
|
||||||
}
|
: INVALID_REQUEST_ID;
|
||||||
|
}, mHandler::post);
|
||||||
mPendingRequest.cancel();
|
|
||||||
mPendingRequest = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return requestId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onFillRequest(@NonNull FillRequest request) {
|
public void onFillRequest(@NonNull FillRequest request) {
|
||||||
|
|||||||
@@ -546,7 +546,11 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
+ "mForAugmentedAutofillOnly: %s", mForAugmentedAutofillOnly);
|
+ "mForAugmentedAutofillOnly: %s", mForAugmentedAutofillOnly);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int canceledRequest = mRemoteFillService.cancelCurrentRequest();
|
mRemoteFillService.cancelCurrentRequest().whenComplete((canceledRequest, err) -> {
|
||||||
|
if (err != null) {
|
||||||
|
Slog.e(TAG, "cancelCurrentRequest(): unexpected exception", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove the FillContext as there will never be a response for the service
|
// Remove the FillContext as there will never be a response for the service
|
||||||
if (canceledRequest != INVALID_REQUEST_ID && mContexts != null) {
|
if (canceledRequest != INVALID_REQUEST_ID && mContexts != null) {
|
||||||
@@ -561,6 +565,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2090,8 +2095,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
updateValuesForSaveLocked();
|
updateValuesForSaveLocked();
|
||||||
|
|
||||||
// Remove pending fill requests as the session is finished.
|
// Remove pending fill requests as the session is finished.
|
||||||
cancelCurrentRequestLocked();
|
|
||||||
|
|
||||||
|
cancelCurrentRequestLocked();
|
||||||
final ArrayList<FillContext> contexts = mergePreviousSessionLocked( /* forSave= */ true);
|
final ArrayList<FillContext> contexts = mergePreviousSessionLocked( /* forSave= */ true);
|
||||||
|
|
||||||
final SaveRequest saveRequest =
|
final SaveRequest saveRequest =
|
||||||
|
|||||||
Reference in New Issue
Block a user