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

Commit 214fe981 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use display context all the way" into rvc-dev

parents 2f6d5754 17a647ee
Loading
Loading
Loading
Loading
+33 −30
Original line number Diff line number Diff line
@@ -23,16 +23,13 @@ import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.app.Service;
import android.app.slice.Slice;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.hardware.display.DisplayManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.SurfaceControl;
@@ -76,22 +73,29 @@ public abstract class InlineSuggestionRenderService extends Service {
            return;
        }

        final DisplayManager displayManager = getSystemService(DisplayManager.class);
        final Display targetDisplay = displayManager.getDisplay(displayId);
        if (targetDisplay == null) {
            sendResult(callback, /*surface*/ null);
        // When we create the UI it should be for the IME display
        updateDisplay(displayId);
        try {
            final View suggestionView = onRenderSuggestion(presentation, width, height);
            if (suggestionView == null) {
                try {
                    callback.onError();
                } catch (RemoteException e) {
                    Log.w(TAG, "Null suggestion view returned by renderer");
                }
                return;
            }
        final Context displayContext = createDisplayContext(targetDisplay);

        final SurfaceControlViewHost host = new SurfaceControlViewHost(displayContext,
                displayContext.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);
            WindowManager.LayoutParams lp =
                    new WindowManager.LayoutParams(width, height,
                            WindowManager.LayoutParams.TYPE_APPLICATION, 0,
                            PixelFormat.TRANSPARENT);

            final SurfaceControlViewHost host = new SurfaceControlViewHost(this, getDisplay(),
                    hostInputToken);
            host.addView(suggestionRoot, lp);
            suggestionRoot.setOnClickListener((v) -> {
                try {
                    callback.onAutofill();
@@ -100,11 +104,10 @@ public abstract class InlineSuggestionRenderService extends Service {
                }
            });

        WindowManager.LayoutParams lp =
                new WindowManager.LayoutParams(width, height,
                        WindowManager.LayoutParams.TYPE_APPLICATION, 0, PixelFormat.TRANSPARENT);
        host.addView(suggestionRoot, lp);
        sendResult(callback, surface);
            sendResult(callback, host.getSurfacePackage().getSurfaceControl());
        } finally {
            updateDisplay(Display.DEFAULT_DISPLAY);
        }
    }

    private void sendResult(@NonNull IInlineSuggestionUiCallback callback,