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

Commit 433e9d9f authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Automerger Merge Worker
Browse files

Merge changes from topic "windowInfo_transferFocus" into udc-dev am: 7a6c7ba6

parents 644cf09f 7a6c7ba6
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -158,6 +158,14 @@ public final class InputWindowHandle {
     */
    public Matrix transform;

    /**
     * The input token for the window to which focus should be transferred when this input window
     * can be successfully focused. If null, this input window will not transfer its focus to
     * any other window.
     */
    @Nullable
    public IBinder focusTransferTarget;

    private native void nativeDispose();

    public InputWindowHandle(InputApplicationHandle inputApplicationHandle, int displayId) {
@@ -195,6 +203,7 @@ public final class InputWindowHandle {
            transform = new Matrix();
            transform.set(other.transform);
        }
        focusTransferTarget = other.focusTransferTarget;
    }

    @Override
+2 −23
Original line number Diff line number Diff line
@@ -265,7 +265,7 @@ public final class SurfaceControl implements Parcelable {
            int transformHint);
    private static native void nativeRemoveCurrentInputFocus(long nativeObject, int displayId);
    private static native void nativeSetFocusedWindow(long transactionObj, IBinder toToken,
            String windowName, IBinder focusedToken, String focusedWindowName, int displayId);
            String windowName, int displayId);
    private static native void nativeSetFrameTimelineVsync(long transactionObj,
            long frameTimelineVsyncId);
    private static native void nativeAddJankDataListener(long nativeListener,
@@ -3604,28 +3604,7 @@ public final class SurfaceControl implements Parcelable {
         */
        public Transaction setFocusedWindow(@NonNull IBinder token, String windowName,
                int displayId) {
            nativeSetFocusedWindow(mNativeObject, token,  windowName,
                    null /* focusedToken */, null /* focusedWindowName */, displayId);
            return this;
        }

        /**
         * Set focus on the window identified by the input {@code token} if the window identified by
         * the input {@code focusedToken} is currently focused. If the {@code focusedToken} does not
         * have focus, the request is dropped.
         *
         * This is used by forward focus transfer requests from clients that host embedded windows,
         * and want to transfer focus to/from them.
         *
         * @hide
         */
        public Transaction requestFocusTransfer(@NonNull IBinder token,
                                                String windowName,
                                                @NonNull IBinder focusedToken,
                                                String focusedWindowName,
                                                int displayId) {
            nativeSetFocusedWindow(mNativeObject, token, windowName, focusedToken,
                    focusedWindowName, displayId);
            nativeSetFocusedWindow(mNativeObject, token, windowName, displayId);
            return this;
        }

+34 −28
Original line number Diff line number Diff line
@@ -57,18 +57,16 @@ public class WindowlessWindowManager implements IWindowSession {
        SurfaceControl mLeash;
        Rect mFrame;
        Rect mAttachedFrame;
        IBinder mFocusGrantToken;

        State(SurfaceControl sc, WindowManager.LayoutParams p,
                int displayId, IBinder inputChannelToken, IWindow client, SurfaceControl leash,
                Rect frame, Rect attachedFrame) {
        State(SurfaceControl sc, WindowManager.LayoutParams p, int displayId, IWindow client,
                SurfaceControl leash, Rect frame) {
            mSurfaceControl = sc;
            mParams.copyFrom(p);
            mDisplayId = displayId;
            mInputChannelToken = inputChannelToken;
            mClient = client;
            mLeash = leash;
            mFrame = frame;
            mAttachedFrame = attachedFrame;
        }
    };

@@ -182,45 +180,53 @@ public class WindowlessWindowManager implements IWindowSession {
                .setParent(leash)
                .build();

        final State state = new State(sc, attrs, displayId, window, leash, /* frame= */ new Rect());
        synchronized (this) {
            State parentState = mStateForWindow.get(attrs.token);
            if (parentState != null) {
                state.mAttachedFrame = parentState.mFrame;
            }

            // Give the first window the mFocusGrantToken since that's the token the host can use
            // to give focus to the embedded.
            if (mStateForWindow.isEmpty()) {
                state.mFocusGrantToken = mFocusGrantToken;
            } else {
                state.mFocusGrantToken = new Binder();
            }

            mStateForWindow.put(window.asBinder(), state);
        }

        if (state.mAttachedFrame == null) {
            outAttachedFrame.set(0, 0, -1, -1);
        } else {
            outAttachedFrame.set(state.mAttachedFrame);
        }
        outSizeCompatScale[0] = 1f;

        if (((attrs.inputFeatures &
                WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0)) {
            try {
                if (mRealWm instanceof IWindowSession.Stub) {
                    mRealWm.grantInputChannel(displayId,
                            new SurfaceControl(sc, "WindowlessWindowManager.addToDisplay"),
                            window, mHostInputToken,
                            attrs.flags, attrs.privateFlags, attrs.inputFeatures, attrs.type,
                            attrs.token, mFocusGrantToken, attrs.getTitle().toString(),
                            window, mHostInputToken, attrs.flags, attrs.privateFlags,
                            attrs.inputFeatures, attrs.type,
                            attrs.token, state.mFocusGrantToken, attrs.getTitle().toString(),
                            outInputChannel);
                } else {
                    mRealWm.grantInputChannel(displayId, sc, window, mHostInputToken, attrs.flags,
                            attrs.privateFlags, attrs.inputFeatures, attrs.type, attrs.token,
                            mFocusGrantToken, attrs.getTitle().toString(), outInputChannel);
                            state.mFocusGrantToken, attrs.getTitle().toString(), outInputChannel);
                }
                state.mInputChannelToken =
                        outInputChannel != null ? outInputChannel.getToken() : null;
            } catch (RemoteException e) {
                Log.e(TAG, "Failed to grant input to surface: ", e);
            }
        }

        final State state = new State(sc, attrs, displayId,
                outInputChannel != null ? outInputChannel.getToken() : null, window,
                leash, /* frame= */ new Rect(), /* attachedFrame= */ null);
        Rect parentFrame = null;
        synchronized (this) {
            State parentState = mStateForWindow.get(attrs.token);
            if (parentState != null) {
                parentFrame = parentState.mFrame;
            }
            mStateForWindow.put(window.asBinder(), state);
        }
        state.mAttachedFrame = parentFrame;
        if (parentFrame == null) {
            outAttachedFrame.set(0, 0, -1, -1);
        } else {
            outAttachedFrame.set(parentFrame);
        }
        outSizeCompatScale[0] = 1f;

        final int res = WindowManagerGlobal.ADD_OKAY | WindowManagerGlobal.ADD_FLAG_APP_VISIBLE |
                        WindowManagerGlobal.ADD_FLAG_USE_BLAST;

+15 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ static struct {
    WeakRefHandleField touchableRegionSurfaceControl;
    jfieldID transform;
    jfieldID windowToken;
    jfieldID focusTransferTarget;
} gInputWindowHandleClassInfo;

static struct {
@@ -216,6 +217,17 @@ bool NativeInputWindowHandle::updateInfo() {
        mInfo.windowToken.clear();
    }

    ScopedLocalRef<jobject>
            focusTransferTargetObj(env,
                                   env->GetObjectField(obj,
                                                       gInputWindowHandleClassInfo
                                                               .focusTransferTarget));
    if (focusTransferTargetObj.get()) {
        mInfo.focusTransferTarget = ibinderForJavaObject(env, focusTransferTargetObj.get());
    } else {
        mInfo.focusTransferTarget.clear();
    }

    env->DeleteLocalRef(obj);
    return true;
}
@@ -433,6 +445,9 @@ int register_android_view_InputWindowHandle(JNIEnv* env) {
    GET_FIELD_ID(gInputWindowHandleClassInfo.windowToken, clazz, "windowToken",
                 "Landroid/os/IBinder;");

    GET_FIELD_ID(gInputWindowHandleClassInfo.focusTransferTarget, clazz, "focusTransferTarget",
                 "Landroid/os/IBinder;");

    jclass weakRefClazz;
    FIND_CLASS(weakRefClazz, "java/lang/ref/Reference");

+2 −13
Original line number Diff line number Diff line
@@ -1820,17 +1820,11 @@ static void nativeRemoveCurrentInputFocus(JNIEnv* env, jclass clazz, jlong trans
}

static void nativeSetFocusedWindow(JNIEnv* env, jclass clazz, jlong transactionObj,
                                   jobject toTokenObj, jstring windowNameJstr,
                                   jobject focusedTokenObj, jstring focusedWindowNameJstr,
                                   jint displayId) {
                                   jobject toTokenObj, jstring windowNameJstr, jint displayId) {
    auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
    if (toTokenObj == NULL) return;

    sp<IBinder> toToken(ibinderForJavaObject(env, toTokenObj));
    sp<IBinder> focusedToken;
    if (focusedTokenObj != NULL) {
        focusedToken = ibinderForJavaObject(env, focusedTokenObj);
    }

    FocusRequest request;
    request.token = toToken;
@@ -1839,11 +1833,6 @@ static void nativeSetFocusedWindow(JNIEnv* env, jclass clazz, jlong transactionO
        request.windowName = windowName.c_str();
    }

    request.focusedToken = focusedToken;
    if (focusedWindowNameJstr != NULL) {
        ScopedUtfChars focusedWindowName(env, focusedWindowNameJstr);
        request.focusedWindowName = focusedWindowName.c_str();
    }
    request.timestamp = systemTime(SYSTEM_TIME_MONOTONIC);
    request.displayId = displayId;
    transaction->setFocusedWindow(request);
@@ -2236,7 +2225,7 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeGetHandle },
    {"nativeSetFixedTransformHint", "(JJI)V",
            (void*)nativeSetFixedTransformHint},
    {"nativeSetFocusedWindow", "(JLandroid/os/IBinder;Ljava/lang/String;Landroid/os/IBinder;Ljava/lang/String;I)V",
    {"nativeSetFocusedWindow", "(JLandroid/os/IBinder;Ljava/lang/String;I)V",
            (void*)nativeSetFocusedWindow},
    {"nativeRemoveCurrentInputFocus", "(JI)V",
            (void*)nativeRemoveCurrentInputFocus},
Loading