summaryrefslogtreecommitdiff
path: root/services/autofill
diff options
context:
space:
mode:
authorFeng Cao <fengcao@google.com>2020-06-23 08:17:15 -0700
committerFeng Cao <fengcao@google.com>2020-06-23 19:17:42 -0700
commit17ca1ee84e6740e003dbfbd0ebb21cc2d2579a7d (patch)
tree6150fed067f6a6ee5fa93ee9c0f706736f41b6e6 /services/autofill
parent908126d4a7878a9c17f4e06afda57f7a995aadfc (diff)
Release remove inline suggestion views when session destroyed
* Attach to each inline suggestion remote view the user id and session id, which together identify a session. Then when the session is destroyed, we release all the remote views associated with the it. * Worst scenario is that the IME is still showing the UI when the remote view is released due to session destroy, in which case the suggestion will disappear from the IME window. But we also make sure we send an empty response to IME before releasing the views, so it should be bad. Plus when a session is destroyed, interacting with the suggestion UI doesn't do anything, so it's not very helpful to show them. * Also add a dump method to the InlineSuggestionRenderService to help with debugging Test: atest android.autofillservice.cts.inline Bug: 154683107 Change-Id: I488fd9d9af08d0df3ffd3c851f96c567d07eed5a
Diffstat (limited to 'services/autofill')
-rw-r--r--services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java9
-rw-r--r--services/autofill/java/com/android/server/autofill/RemoteInlineSuggestionRenderService.java11
-rw-r--r--services/autofill/java/com/android/server/autofill/Session.java14
-rw-r--r--services/autofill/java/com/android/server/autofill/ui/InlineFillUi.java12
-rw-r--r--services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java38
-rw-r--r--services/autofill/java/com/android/server/autofill/ui/RemoteInlineSuggestionViewConnector.java7
6 files changed, 63 insertions, 28 deletions
diff --git a/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java b/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java
index 11f901538868..533bbe68e274 100644
--- a/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java
+++ b/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java
@@ -149,7 +149,7 @@ final class RemoteAugmentedAutofillService
@Nullable InlineSuggestionsRequest inlineSuggestionsRequest,
@Nullable Function<InlineFillUi, Boolean> inlineSuggestionsCallback,
@NonNull Runnable onErrorCallback,
- @Nullable RemoteInlineSuggestionRenderService remoteRenderService) {
+ @Nullable RemoteInlineSuggestionRenderService remoteRenderService, int userId) {
long requestTime = SystemClock.elapsedRealtime();
AtomicReference<ICancellationSignal> cancellationRef = new AtomicReference<>();
@@ -173,7 +173,7 @@ final class RemoteAugmentedAutofillService
inlineSuggestionsRequest, inlineSuggestionsData,
clientState, focusedId, focusedValue,
inlineSuggestionsCallback,
- client, onErrorCallback, remoteRenderService);
+ client, onErrorCallback, remoteRenderService, userId);
if (!showingFillWindow) {
requestAutofill.complete(null);
}
@@ -243,7 +243,8 @@ final class RemoteAugmentedAutofillService
@NonNull AutofillId focusedId, @Nullable AutofillValue focusedValue,
@Nullable Function<InlineFillUi, Boolean> inlineSuggestionsCallback,
@NonNull IAutoFillManagerClient client, @NonNull Runnable onErrorCallback,
- @Nullable RemoteInlineSuggestionRenderService remoteRenderService) {
+ @Nullable RemoteInlineSuggestionRenderService remoteRenderService,
+ int userId) {
if (inlineSuggestionsData == null || inlineSuggestionsData.isEmpty()
|| inlineSuggestionsCallback == null || request == null
|| remoteRenderService == null) {
@@ -312,7 +313,7 @@ final class RemoteAugmentedAutofillService
Slog.w(TAG, "RemoteException starting intent sender");
}
}
- }, onErrorCallback, remoteRenderService);
+ }, onErrorCallback, remoteRenderService, userId, sessionId);
if (inlineSuggestionsCallback.apply(inlineFillUi)) {
mCallbacks.logAugmentedAutofillShown(sessionId, clientState);
diff --git a/services/autofill/java/com/android/server/autofill/RemoteInlineSuggestionRenderService.java b/services/autofill/java/com/android/server/autofill/RemoteInlineSuggestionRenderService.java
index 617c111c6c38..80b8583759e7 100644
--- a/services/autofill/java/com/android/server/autofill/RemoteInlineSuggestionRenderService.java
+++ b/services/autofill/java/com/android/server/autofill/RemoteInlineSuggestionRenderService.java
@@ -88,9 +88,9 @@ public final class RemoteInlineSuggestionRenderService extends
*/
public void renderSuggestion(@NonNull IInlineSuggestionUiCallback callback,
@NonNull InlinePresentation presentation, int width, int height,
- @Nullable IBinder hostInputToken, int displayId) {
+ @Nullable IBinder hostInputToken, int displayId, int userId, int sessionId) {
scheduleAsyncRequest((s) -> s.renderSuggestion(callback, presentation, width, height,
- hostInputToken, displayId));
+ hostInputToken, displayId, userId, sessionId));
}
/**
@@ -100,6 +100,13 @@ public final class RemoteInlineSuggestionRenderService extends
scheduleAsyncRequest((s) -> s.getInlineSuggestionsRendererInfo(callback));
}
+ /**
+ * Destroys the remote inline suggestion views associated with the given user id and session id.
+ */
+ public void destroySuggestionViews(int userId, int sessionId) {
+ scheduleAsyncRequest((s) -> s.destroySuggestionViews(userId, sessionId));
+ }
+
@Nullable
private static ServiceInfo getServiceInfo(Context context, int userId) {
final String packageName =
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index 3114a6a02e31..60b65fb812c2 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -155,6 +155,9 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
*/
public final int id;
+ /** userId the session belongs to */
+ public final int userId;
+
/** uid the session is for */
public final int uid;
@@ -823,6 +826,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
}
id = sessionId;
mFlags = flags;
+ this.userId = userId;
this.taskId = taskId;
this.uid = uid;
mStartTime = SystemClock.elapsedRealtime();
@@ -2982,7 +2986,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
mInlineSessionController.hideInlineSuggestionsUiLocked(
focusedId);
}
- }, remoteRenderService);
+ }, remoteRenderService, userId, id);
return mInlineSessionController.setInlineFillUiLocked(inlineFillUi);
}
@@ -3285,7 +3289,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
synchronized (mLock) {
cancelAugmentedAutofillLocked();
}
- }, mService.getRemoteInlineSuggestionRenderServiceLocked());
+ }, mService.getRemoteInlineSuggestionRenderServiceLocked(), userId);
}
};
@@ -3785,6 +3789,12 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
if (mCurrentViewId != null) {
mInlineSessionController.destroyLocked(mCurrentViewId);
}
+ final RemoteInlineSuggestionRenderService remoteRenderService =
+ mService.getRemoteInlineSuggestionRenderServiceLocked();
+ if (remoteRenderService != null) {
+ remoteRenderService.destroySuggestionViews(userId, id);
+ }
+
mDestroyed = true;
// Log metrics
diff --git a/services/autofill/java/com/android/server/autofill/ui/InlineFillUi.java b/services/autofill/java/com/android/server/autofill/ui/InlineFillUi.java
index 627c0733b078..25e9d5c90764 100644
--- a/services/autofill/java/com/android/server/autofill/ui/InlineFillUi.java
+++ b/services/autofill/java/com/android/server/autofill/ui/InlineFillUi.java
@@ -105,19 +105,20 @@ public final class InlineFillUi {
@NonNull AutofillId focusedViewId, @Nullable String filterText,
@NonNull AutoFillUI.AutoFillUiCallback uiCallback,
@NonNull Runnable onErrorCallback,
- @Nullable RemoteInlineSuggestionRenderService remoteRenderService) {
+ @Nullable RemoteInlineSuggestionRenderService remoteRenderService,
+ int userId, int sessionId) {
if (InlineSuggestionFactory.responseNeedAuthentication(response)) {
InlineSuggestion inlineAuthentication =
InlineSuggestionFactory.createInlineAuthentication(request, response,
- focusedViewId, uiCallback, onErrorCallback, remoteRenderService);
+ uiCallback, onErrorCallback, remoteRenderService, userId, sessionId);
return new InlineFillUi(focusedViewId, inlineAuthentication, filterText);
} else if (response.getDatasets() != null) {
SparseArray<Pair<Dataset, InlineSuggestion>> inlineSuggestions =
InlineSuggestionFactory.createAutofillInlineSuggestions(request,
response.getRequestId(),
response.getDatasets(), focusedViewId, uiCallback, onErrorCallback,
- remoteRenderService);
+ remoteRenderService, userId, sessionId);
return new InlineFillUi(focusedViewId, inlineSuggestions, filterText);
}
return new InlineFillUi(focusedViewId, new SparseArray<>(), filterText);
@@ -132,11 +133,12 @@ public final class InlineFillUi {
@NonNull AutofillId focusedViewId, @Nullable String filterText,
@NonNull InlineSuggestionUiCallback uiCallback,
@NonNull Runnable onErrorCallback,
- @Nullable RemoteInlineSuggestionRenderService remoteRenderService) {
+ @Nullable RemoteInlineSuggestionRenderService remoteRenderService,
+ int userId, int sessionId) {
SparseArray<Pair<Dataset, InlineSuggestion>> inlineSuggestions =
InlineSuggestionFactory.createAugmentedAutofillInlineSuggestions(request, datasets,
focusedViewId,
- uiCallback, onErrorCallback, remoteRenderService);
+ uiCallback, onErrorCallback, remoteRenderService, userId, sessionId);
return new InlineFillUi(focusedViewId, inlineSuggestions, filterText);
}
diff --git a/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java b/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java
index 462ffd668e2e..8fcb8aa9393c 100644
--- a/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java
+++ b/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java
@@ -53,9 +53,9 @@ final class InlineSuggestionFactory {
public static InlineSuggestion createInlineAuthentication(
@NonNull InlineSuggestionsRequest request, @NonNull FillResponse response,
- @NonNull AutofillId autofillId,
@NonNull AutoFillUI.AutoFillUiCallback client, @NonNull Runnable onErrorCallback,
- @Nullable RemoteInlineSuggestionRenderService remoteRenderService) {
+ @Nullable RemoteInlineSuggestionRenderService remoteRenderService, int userId,
+ int sessionId) {
final BiConsumer<Dataset, Integer> onClickFactory = (dataset, datasetIndex) -> {
client.authenticate(response.getRequestId(),
datasetIndex, response.getAuthentication(), response.getClientState(),
@@ -66,7 +66,8 @@ final class InlineSuggestionFactory {
InlinePresentation inlineAuthentication = response.getInlinePresentation();
return createInlineAuthSuggestion(
mergedInlinePresentation(request, 0, inlineAuthentication),
- remoteRenderService, onClickFactory, onErrorCallback, intentSenderConsumer,
+ remoteRenderService, userId, sessionId,
+ onClickFactory, onErrorCallback, intentSenderConsumer,
request.getHostInputToken(), request.getHostDisplayId());
}
@@ -80,7 +81,8 @@ final class InlineSuggestionFactory {
@NonNull List<Dataset> datasets,
@NonNull AutofillId autofillId,
@NonNull AutoFillUI.AutoFillUiCallback client, @NonNull Runnable onErrorCallback,
- @Nullable RemoteInlineSuggestionRenderService remoteRenderService) {
+ @Nullable RemoteInlineSuggestionRenderService remoteRenderService,
+ int userId, int sessionId) {
if (sDebug) Slog.d(TAG, "createInlineSuggestionsResponse called");
final Consumer<IntentSender> intentSenderConsumer = (intentSender) ->
client.startIntentSender(intentSender, new Intent());
@@ -90,7 +92,8 @@ final class InlineSuggestionFactory {
return createInlineSuggestionsInternal(/* isAugmented= */ false, request,
datasets, autofillId,
- onErrorCallback, onClickFactory, intentSenderConsumer, remoteRenderService);
+ onErrorCallback, onClickFactory, intentSenderConsumer, remoteRenderService, userId,
+ sessionId);
}
/**
@@ -104,7 +107,8 @@ final class InlineSuggestionFactory {
@NonNull AutofillId autofillId,
@NonNull InlineFillUi.InlineSuggestionUiCallback inlineSuggestionUiCallback,
@NonNull Runnable onErrorCallback,
- @Nullable RemoteInlineSuggestionRenderService remoteRenderService) {
+ @Nullable RemoteInlineSuggestionRenderService remoteRenderService,
+ int userId, int sessionId) {
if (sDebug) Slog.d(TAG, "createAugmentedInlineSuggestionsResponse called");
return createInlineSuggestionsInternal(/* isAugmented= */ true, request,
datasets, autofillId, onErrorCallback,
@@ -112,7 +116,7 @@ final class InlineSuggestionFactory {
inlineSuggestionUiCallback.autofill(dataset, datasetIndex),
(intentSender) ->
inlineSuggestionUiCallback.startIntentSender(intentSender, new Intent()),
- remoteRenderService);
+ remoteRenderService, userId, sessionId);
}
@Nullable
@@ -121,7 +125,8 @@ final class InlineSuggestionFactory {
@NonNull List<Dataset> datasets, @NonNull AutofillId autofillId,
@NonNull Runnable onErrorCallback, @NonNull BiConsumer<Dataset, Integer> onClickFactory,
@NonNull Consumer<IntentSender> intentSenderConsumer,
- @Nullable RemoteInlineSuggestionRenderService remoteRenderService) {
+ @Nullable RemoteInlineSuggestionRenderService remoteRenderService,
+ int userId, int sessionId) {
SparseArray<Pair<Dataset, InlineSuggestion>> response = new SparseArray<>(datasets.size());
for (int datasetIndex = 0; datasetIndex < datasets.size(); datasetIndex++) {
final Dataset dataset = datasets.get(datasetIndex);
@@ -139,7 +144,8 @@ final class InlineSuggestionFactory {
InlineSuggestion inlineSuggestion = createInlineSuggestion(isAugmented, dataset,
datasetIndex,
mergedInlinePresentation(request, datasetIndex, inlinePresentation),
- onClickFactory, remoteRenderService, onErrorCallback, intentSenderConsumer,
+ onClickFactory, remoteRenderService, userId, sessionId,
+ onErrorCallback, intentSenderConsumer,
request.getHostInputToken(), request.getHostDisplayId());
response.append(datasetIndex, Pair.create(dataset, inlineSuggestion));
}
@@ -151,6 +157,7 @@ final class InlineSuggestionFactory {
@NonNull InlinePresentation inlinePresentation,
@NonNull BiConsumer<Dataset, Integer> onClickFactory,
@NonNull RemoteInlineSuggestionRenderService remoteRenderService,
+ int userId, int sessionId,
@NonNull Runnable onErrorCallback, @NonNull Consumer<IntentSender> intentSenderConsumer,
@Nullable IBinder hostInputToken,
int displayId) {
@@ -167,7 +174,8 @@ final class InlineSuggestionFactory {
final InlineSuggestion inlineSuggestion = new InlineSuggestion(inlineSuggestionInfo,
createInlineContentProvider(inlinePresentation,
() -> onClickFactory.accept(dataset, datasetIndex), onErrorCallback,
- intentSenderConsumer, remoteRenderService, hostInputToken, displayId));
+ intentSenderConsumer, remoteRenderService, userId, sessionId,
+ hostInputToken, displayId));
return inlineSuggestion;
}
@@ -175,6 +183,7 @@ final class InlineSuggestionFactory {
private static InlineSuggestion createInlineAuthSuggestion(
@NonNull InlinePresentation inlinePresentation,
@NonNull RemoteInlineSuggestionRenderService remoteRenderService,
+ int userId, int sessionId,
@NonNull BiConsumer<Dataset, Integer> onClickFactory, @NonNull Runnable onErrorCallback,
@NonNull Consumer<IntentSender> intentSenderConsumer,
@Nullable IBinder hostInputToken, int displayId) {
@@ -187,8 +196,8 @@ final class InlineSuggestionFactory {
createInlineContentProvider(inlinePresentation,
() -> onClickFactory.accept(null,
AutofillManager.AUTHENTICATION_ID_DATASET_ID_UNDEFINED),
- onErrorCallback, intentSenderConsumer, remoteRenderService, hostInputToken,
- displayId));
+ onErrorCallback, intentSenderConsumer, remoteRenderService, userId,
+ sessionId, hostInputToken, displayId));
}
/**
@@ -216,12 +225,13 @@ final class InlineSuggestionFactory {
@NonNull Runnable onErrorCallback,
@NonNull Consumer<IntentSender> intentSenderConsumer,
@Nullable RemoteInlineSuggestionRenderService remoteRenderService,
+ int userId, int sessionId,
@Nullable IBinder hostInputToken,
int displayId) {
RemoteInlineSuggestionViewConnector
remoteInlineSuggestionViewConnector = new RemoteInlineSuggestionViewConnector(
- remoteRenderService, inlinePresentation, hostInputToken, displayId, onClickAction,
- onErrorCallback, intentSenderConsumer);
+ remoteRenderService, userId, sessionId, inlinePresentation, hostInputToken,
+ displayId, onClickAction, onErrorCallback, intentSenderConsumer);
InlineContentProviderImpl inlineContentProvider = new InlineContentProviderImpl(
remoteInlineSuggestionViewConnector, null);
return inlineContentProvider;
diff --git a/services/autofill/java/com/android/server/autofill/ui/RemoteInlineSuggestionViewConnector.java b/services/autofill/java/com/android/server/autofill/ui/RemoteInlineSuggestionViewConnector.java
index 9d23c171800d..7257255d1ee4 100644
--- a/services/autofill/java/com/android/server/autofill/ui/RemoteInlineSuggestionViewConnector.java
+++ b/services/autofill/java/com/android/server/autofill/ui/RemoteInlineSuggestionViewConnector.java
@@ -46,6 +46,8 @@ final class RemoteInlineSuggestionViewConnector {
@Nullable
private final IBinder mHostInputToken;
private final int mDisplayId;
+ private final int mUserId;
+ private final int mSessionId;
@NonNull
private final Runnable mOnAutofillCallback;
@@ -56,6 +58,7 @@ final class RemoteInlineSuggestionViewConnector {
RemoteInlineSuggestionViewConnector(
@Nullable RemoteInlineSuggestionRenderService remoteRenderService,
+ int userId, int sessionId,
@NonNull InlinePresentation inlinePresentation,
@Nullable IBinder hostInputToken,
int displayId,
@@ -66,6 +69,8 @@ final class RemoteInlineSuggestionViewConnector {
mInlinePresentation = inlinePresentation;
mHostInputToken = hostInputToken;
mDisplayId = displayId;
+ mUserId = userId;
+ mSessionId = sessionId;
mOnAutofillCallback = onAutofillCallback;
mOnErrorCallback = onErrorCallback;
@@ -82,7 +87,7 @@ final class RemoteInlineSuggestionViewConnector {
if (mRemoteRenderService != null) {
if (sDebug) Slog.d(TAG, "Request to recreate the UI");
mRemoteRenderService.renderSuggestion(callback, mInlinePresentation, width, height,
- mHostInputToken, mDisplayId);
+ mHostInputToken, mDisplayId, mUserId, mSessionId);
return true;
}
return false;