From 79e0ba05ec5d029e7842ab8290a28e97ef9a031e Mon Sep 17 00:00:00 2001 From: Adam He Date: Mon, 13 May 2019 16:43:39 -0700 Subject: [PATCH] Fixed Cancellation for PendingAutofillRequest. 1. mCallback.cancel() now correctly cancels the pending request. 2. AutofillProxy.update() now updates the CancellationSignal. Fixes: 132459064 Test: atest android.autofillservice.cts.augmented Change-Id: If8b2ab5c0fd8db4cfad440bf47031f6d85c28ae5 Merged-In: If8b2ab5c0fd8db4cfad440bf47031f6d85c28ae5 --- .../augmented/AugmentedAutofillService.java | 14 ++++++++++++-- .../autofill/RemoteAugmentedAutofillService.java | 14 ++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/core/java/android/service/autofill/augmented/AugmentedAutofillService.java b/core/java/android/service/autofill/augmented/AugmentedAutofillService.java index 87e369f20d58c..66c3e19661340 100644 --- a/core/java/android/service/autofill/augmented/AugmentedAutofillService.java +++ b/core/java/android/service/autofill/augmented/AugmentedAutofillService.java @@ -228,7 +228,7 @@ public abstract class AugmentedAutofillService extends Service { } else { // TODO(b/123099468): figure out if it's ok to reuse the proxy; add logging if (sDebug) Log.d(TAG, "Reusing proxy for session " + sessionId); - proxy.update(focusedId, focusedValue, callback); + proxy.update(focusedId, focusedValue, callback, cancellationSignal); } try { @@ -252,6 +252,15 @@ public abstract class AugmentedAutofillService extends Service { Log.w(TAG, "No proxy for session " + sessionId); return; } + if (proxy.mCallback != null) { + try { + if (!proxy.mCallback.isCompleted()) { + proxy.mCallback.cancel(); + } + } catch (Exception e) { + Log.e(TAG, "failed to check current pending request status", e); + } + } proxy.destroy(); } mAutofillProxies.clear(); @@ -442,7 +451,7 @@ public abstract class AugmentedAutofillService extends Service { } private void update(@NonNull AutofillId focusedId, @NonNull AutofillValue focusedValue, - @NonNull IFillCallback callback) { + @NonNull IFillCallback callback, @NonNull CancellationSignal cancellationSignal) { synchronized (mLock) { mFocusedId = focusedId; mFocusedValue = focusedValue; @@ -457,6 +466,7 @@ public abstract class AugmentedAutofillService extends Service { Log.d(TAG, "mCallback is updated."); } mCallback = callback; + mCancellationSignal = cancellationSignal; } } diff --git a/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java b/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java index d2b71e591b228..d42943ce76fec 100644 --- a/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java +++ b/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java @@ -225,17 +225,7 @@ final class RemoteAugmentedAutofillService @Override public void cancel() { - synchronized (mLock) { - final boolean cancelled = isCancelledLocked(); - final ICancellationSignal cancellation = mCancellation; - if (!cancelled) { - try { - cancellation.cancel(); - } catch (RemoteException e) { - Slog.e(mTag, "Error requesting a cancellation", e); - } - } - } + PendingAutofillRequest.this.cancel(); } }; } @@ -304,7 +294,7 @@ final class RemoteAugmentedAutofillService try { cancellation.cancel(); } catch (RemoteException e) { - Slog.e(mTag, "Error cancelling a fill request", e); + Slog.e(mTag, "Error cancelling an augmented fill request", e); } } return true;