Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 677db186 authored by Adam He's avatar Adam He Committed by Android (Google) Code Review
Browse files

Merge "Move rendering logic for inline suggestions to ExtServices."

parents 0a9d74fc 40116256
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -14064,6 +14064,14 @@ package android.view.contentcapture {
}
package android.view.inline {
  public final class InlinePresentationSpec implements android.os.Parcelable {
    method @Nullable public String getStyle();
  }
}
package android.webkit {
  public abstract class CookieManager {
+13 −0
Original line number Diff line number Diff line
@@ -789,6 +789,7 @@ public class InputMethodService extends AbstractInputMethodService {
                Log.w(TAG, "onCreateInlineSuggestionsRequest() returned null request");
                requestCallback.onInlineSuggestionsUnsupported();
            } else {
                request.setHostInputToken(getHostInputToken());
                final IInlineSuggestionsResponseCallback inlineSuggestionsResponseCallback =
                        new InlineSuggestionsResponseCallbackImpl(this,
                                mInlineSuggestionsRequestInfo.mComponentName,
@@ -833,6 +834,18 @@ public class InputMethodService extends AbstractInputMethodService {
        onInlineSuggestionsResponse(response);
    }

    /**
     * Returns the {@link IBinder} input token from the host view root.
     */
    @Nullable
    private IBinder getHostInputToken() {
        ViewRootImpl viewRoot = null;
        if (mRootView != null) {
            viewRoot = mRootView.getViewRootImpl();
        }
        return viewRoot == null ? null : viewRoot.getInputToken();
    }

    private void notifyImeHidden() {
        setImeWindowStatus(IME_ACTIVE | IME_INVISIBLE, mBackDisposition);
        onPreRenderedWindowVisibilityChanged(false /* setVisible */);
+4 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.service.autofill;

import android.os.IBinder;
import android.service.autofill.IInlineSuggestionUiCallback;
import android.service.autofill.InlinePresentation;

@@ -25,6 +26,7 @@ import android.service.autofill.InlinePresentation;
 * @hide
 */
oneway interface IInlineSuggestionRenderService {
    void renderSuggestion(in IInlineSuggestionUiCallback callback, in InlinePresentation presentation,
                     int width, int height);
    void renderSuggestion(in IInlineSuggestionUiCallback callback,
                          in InlinePresentation presentation, int width, int height,
                          in IBinder hostInputToken);
}
+4 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.service.autofill;

import android.os.IBinder;
import android.view.SurfaceControl;

/**
@@ -24,6 +25,8 @@ import android.view.SurfaceControl;
 * @hide
 */
oneway interface IInlineSuggestionUiCallback {
    void autofill();
    void onAutofill();
    void onContent(in SurfaceControl surface);
    void onError();
    void onTransferTouchFocusToImeWindow(in IBinder sourceInputToken, int displayId);
}
+42 −4
Original line number Diff line number Diff line
@@ -24,11 +24,16 @@ import android.annotation.TestApi;
import android.app.Service;
import android.app.slice.Slice;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.util.Log;
import android.view.SurfaceControl;
import android.view.SurfaceControlViewHost;
import android.view.View;
import android.view.WindowManager;

/**
 * A service that renders an inline presentation given the {@link InlinePresentation} containing
@@ -55,8 +60,40 @@ public abstract class InlineSuggestionRenderService extends Service {
    private final Handler mHandler = new Handler(Looper.getMainLooper(), null, true);

    private void handleRenderSuggestion(IInlineSuggestionUiCallback callback,
            InlinePresentation presentation, int width, int height) {
        //TODO(b/146453086): implementation in ExtService
            InlinePresentation presentation, int width, int height, IBinder hostInputToken) {
        if (hostInputToken == null) {
            try {
                callback.onError();
            } catch (RemoteException e) {
                Log.w(TAG, "RemoteException calling onError()");
            }
            return;
        }
        final SurfaceControlViewHost host = new SurfaceControlViewHost(this, this.getDisplay(),
                hostInputToken);
        final SurfaceControl surface = host.getSurfacePackage().getSurfaceControl();

        final View suggestionView = onRenderSuggestion(presentation, width, height);

        final InlineSuggestionRoot suggestionRoot = new InlineSuggestionRoot(this, callback);
        suggestionRoot.addView(suggestionView);
        suggestionRoot.setOnClickListener((v) -> {
            try {
                callback.onAutofill();
            } catch (RemoteException e) {
                Log.w(TAG, "RemoteException calling onAutofill()");
            }
        });

        WindowManager.LayoutParams lp =
                new WindowManager.LayoutParams(width, height,
                        WindowManager.LayoutParams.TYPE_APPLICATION, 0, PixelFormat.TRANSPARENT);
        host.addView(suggestionRoot, lp);
        try {
            callback.onContent(surface);
        } catch (RemoteException e) {
            Log.w(TAG, "RemoteException calling onContent(" + surface + ")");
        }
    }

    @Override
@@ -66,11 +103,12 @@ public abstract class InlineSuggestionRenderService extends Service {
            return new IInlineSuggestionRenderService.Stub() {
                @Override
                public void renderSuggestion(@NonNull IInlineSuggestionUiCallback callback,
                        @NonNull InlinePresentation presentation, int width, int height) {
                        @NonNull InlinePresentation presentation, int width, int height,
                        @Nullable IBinder hostInputToken) {
                    mHandler.sendMessage(obtainMessage(
                            InlineSuggestionRenderService::handleRenderSuggestion,
                            InlineSuggestionRenderService.this, callback, presentation,
                            width, height));
                            width, height, hostInputToken));
                }
            }.asBinder();
        }
Loading