summaryrefslogtreecommitdiff
path: root/core/java
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 /core/java
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 'core/java')
-rw-r--r--core/java/android/service/autofill/IInlineSuggestionRenderService.aidl8
-rw-r--r--core/java/android/service/autofill/InlineSuggestionRenderService.java49
2 files changed, 50 insertions, 7 deletions
diff --git a/core/java/android/service/autofill/IInlineSuggestionRenderService.aidl b/core/java/android/service/autofill/IInlineSuggestionRenderService.aidl
index bf0bb9e2a41f..7cd372fe97d8 100644
--- a/core/java/android/service/autofill/IInlineSuggestionRenderService.aidl
+++ b/core/java/android/service/autofill/IInlineSuggestionRenderService.aidl
@@ -29,6 +29,12 @@ import android.service.autofill.InlinePresentation;
oneway interface IInlineSuggestionRenderService {
void renderSuggestion(in IInlineSuggestionUiCallback callback,
in InlinePresentation presentation, int width, int height,
- in IBinder hostInputToken, int displayId);
+ in IBinder hostInputToken, int displayId, int userId, int sessionId);
void getInlineSuggestionsRendererInfo(in RemoteCallback callback);
+
+ /**
+ * Releases the inline suggestion SurfaceControlViewHosts hosted in the service, for the
+ * provided userId and sessionId.
+ */
+ void destroySuggestionViews(int userId, int sessionId);
}
diff --git a/core/java/android/service/autofill/InlineSuggestionRenderService.java b/core/java/android/service/autofill/InlineSuggestionRenderService.java
index 8790fb2299f5..839caff5c3d4 100644
--- a/core/java/android/service/autofill/InlineSuggestionRenderService.java
+++ b/core/java/android/service/autofill/InlineSuggestionRenderService.java
@@ -41,6 +41,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
import java.lang.ref.WeakReference;
/**
@@ -82,7 +84,7 @@ public abstract class InlineSuggestionRenderService extends Service {
Boolean newValue) {
if (evicted) {
Log.w(TAG,
- "Hit max=100 entries in the cache. Releasing oldest one to make "
+ "Hit max=30 entries in the cache. Releasing oldest one to make "
+ "space.");
key.releaseSurfaceControlViewHost();
}
@@ -130,7 +132,7 @@ public abstract class InlineSuggestionRenderService extends Service {
private void handleRenderSuggestion(IInlineSuggestionUiCallback callback,
InlinePresentation presentation, int width, int height, IBinder hostInputToken,
- int displayId) {
+ int displayId, int userId, int sessionId) {
if (hostInputToken == null) {
try {
callback.onError();
@@ -192,7 +194,8 @@ public abstract class InlineSuggestionRenderService extends Service {
}
return true;
});
- final InlineSuggestionUiImpl uiImpl = new InlineSuggestionUiImpl(host, mMainHandler);
+ final InlineSuggestionUiImpl uiImpl = new InlineSuggestionUiImpl(host, mMainHandler,
+ userId, sessionId);
mActiveInlineSuggestions.put(uiImpl, true);
// We post the callback invocation to the end of the main thread handler queue, to make
@@ -218,6 +221,18 @@ public abstract class InlineSuggestionRenderService extends Service {
callback.sendResult(rendererInfo);
}
+ private void handleDestroySuggestionViews(int userId, int sessionId) {
+ Log.v(TAG, "handleDestroySuggestionViews called for " + userId + ":" + sessionId);
+ for (final InlineSuggestionUiImpl inlineSuggestionUi :
+ mActiveInlineSuggestions.snapshot().keySet()) {
+ if (inlineSuggestionUi.mUserId == userId
+ && inlineSuggestionUi.mSessionId == sessionId) {
+ Log.v(TAG, "Destroy " + inlineSuggestionUi);
+ inlineSuggestionUi.releaseSurfaceControlViewHost();
+ }
+ }
+ }
+
/**
* A wrapper class around the {@link InlineSuggestionUiImpl} to ensure it's not strongly
* reference by the remote system server process.
@@ -260,10 +275,15 @@ public abstract class InlineSuggestionRenderService extends Service {
private SurfaceControlViewHost mViewHost;
@NonNull
private final Handler mHandler;
+ private final int mUserId;
+ private final int mSessionId;
- InlineSuggestionUiImpl(SurfaceControlViewHost viewHost, Handler handler) {
+ InlineSuggestionUiImpl(SurfaceControlViewHost viewHost, Handler handler, int userId,
+ int sessionId) {
this.mViewHost = viewHost;
this.mHandler = handler;
+ this.mUserId = userId;
+ this.mSessionId = sessionId;
}
/**
@@ -302,6 +322,16 @@ public abstract class InlineSuggestionRenderService extends Service {
}
}
+ /** @hide */
+ @Override
+ protected final void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw,
+ @NonNull String[] args) {
+ pw.println("mActiveInlineSuggestions: " + mActiveInlineSuggestions.size());
+ for (InlineSuggestionUiImpl impl : mActiveInlineSuggestions.snapshot().keySet()) {
+ pw.printf("ui: [%s] - [%d] [%d]\n", impl, impl.mUserId, impl.mSessionId);
+ }
+ }
+
@Override
@Nullable
public final IBinder onBind(@NonNull Intent intent) {
@@ -311,11 +341,12 @@ public abstract class InlineSuggestionRenderService extends Service {
@Override
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) {
mMainHandler.sendMessage(
obtainMessage(InlineSuggestionRenderService::handleRenderSuggestion,
InlineSuggestionRenderService.this, callback, presentation,
- width, height, hostInputToken, displayId));
+ width, height, hostInputToken, displayId, userId, sessionId));
}
@Override
@@ -324,6 +355,12 @@ public abstract class InlineSuggestionRenderService extends Service {
InlineSuggestionRenderService::handleGetInlineSuggestionsRendererInfo,
InlineSuggestionRenderService.this, callback));
}
+ @Override
+ public void destroySuggestionViews(int userId, int sessionId) {
+ mMainHandler.sendMessage(obtainMessage(
+ InlineSuggestionRenderService::handleDestroySuggestionViews,
+ InlineSuggestionRenderService.this, userId, sessionId));
+ }
}.asBinder();
}