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

Commit 6a47d98d authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove InputChannel from WindowState" into main

parents d373be66 26786f69
Loading
Loading
Loading
Loading
+1 −28
Original line number Diff line number Diff line
@@ -55,41 +55,25 @@ public:

    inline std::shared_ptr<InputChannel> getInputChannel() { return mInputChannel; }

    void setDisposeCallback(InputChannelObjDisposeCallback callback, void* data);
    void dispose(JNIEnv* env, jobject obj);

private:
    std::shared_ptr<InputChannel> mInputChannel;
    InputChannelObjDisposeCallback mDisposeCallback;
    void* mDisposeData;
};

// ----------------------------------------------------------------------------

NativeInputChannel::NativeInputChannel(std::unique_ptr<InputChannel> inputChannel)
      : mInputChannel(std::move(inputChannel)), mDisposeCallback(nullptr) {}
      : mInputChannel(std::move(inputChannel)) {}

NativeInputChannel::~NativeInputChannel() {
}

void NativeInputChannel::setDisposeCallback(InputChannelObjDisposeCallback callback, void* data) {
    if (input_flags::remove_input_channel_from_windowstate()) {
        return;
    }
    mDisposeCallback = callback;
    mDisposeData = data;
}

void NativeInputChannel::dispose(JNIEnv* env, jobject obj) {
    if (!mInputChannel) {
        return;
    }

    if (mDisposeCallback) {
        mDisposeCallback(env, obj, mInputChannel, mDisposeData);
        mDisposeCallback = nullptr;
        mDisposeData = nullptr;
    }
    mInputChannel.reset();
}

@@ -108,17 +92,6 @@ std::shared_ptr<InputChannel> android_view_InputChannel_getInputChannel(JNIEnv*
    return nativeInputChannel != nullptr ? nativeInputChannel->getInputChannel() : nullptr;
}

void android_view_InputChannel_setDisposeCallback(JNIEnv* env, jobject inputChannelObj,
        InputChannelObjDisposeCallback callback, void* data) {
    NativeInputChannel* nativeInputChannel =
            android_view_InputChannel_getNativeInputChannel(env, inputChannelObj);
    if (!nativeInputChannel || !nativeInputChannel->getInputChannel()) {
        ALOGW("Cannot set dispose callback because input channel object has not been initialized.");
    } else {
        nativeInputChannel->setDisposeCallback(callback, data);
    }
}

static jlong android_view_InputChannel_createInputChannel(
        JNIEnv* env, std::unique_ptr<InputChannel> inputChannel) {
    std::unique_ptr<NativeInputChannel> nativeInputChannel =
+5 −32
Original line number Diff line number Diff line
@@ -100,7 +100,6 @@ import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
import static android.view.WindowManagerPolicyConstants.TYPE_LAYER_MULTIPLIER;
import static android.view.WindowManagerPolicyConstants.TYPE_LAYER_OFFSET;

import static com.android.input.flags.Flags.removeInputChannelFromWindowstate;
import static com.android.internal.protolog.WmProtoLogGroups.WM_DEBUG_ADD_REMOVE;
import static com.android.internal.protolog.WmProtoLogGroups.WM_DEBUG_ANIM;
import static com.android.internal.protolog.WmProtoLogGroups.WM_DEBUG_APP_TRANSITIONS;
@@ -613,10 +612,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP

    // Input channel and input window handle used by the input dispatcher.
    final InputWindowHandleWrapper mInputWindowHandle;
    /**
     * Only populated if flag REMOVE_INPUT_CHANNEL_FROM_WINDOWSTATE is disabled.
     */
    private InputChannel mInputChannel;

    /**
     * The token will be assigned to {@link InputWindowHandle#token} if this window can receive
@@ -1830,13 +1825,9 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
     * Input Manager uses when discarding windows from input consideration.
     */
    boolean isPotentialDragTarget(boolean targetInterceptsGlobalDrag) {
        if (removeInputChannelFromWindowstate()) {
        return (targetInterceptsGlobalDrag || isVisibleNow()) && !mRemoved
                && mInputChannelToken != null && mInputWindowHandle != null;
    }
        return (targetInterceptsGlobalDrag || isVisibleNow()) && !mRemoved
                && mInputChannel != null && mInputWindowHandle != null;
    }

    /**
     * Is this window capable of being visible (policy and content), in a visible part of the
@@ -2583,7 +2574,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        if (mInputChannelToken != null) {
            throw new IllegalStateException("Window already has an input channel token.");
        }
        if (removeInputChannelFromWindowstate()) {
        String name = getName();
        InputChannel channel = mWmService.mInputManager.createInputChannel(name);
        mInputChannelToken = channel.getToken();
@@ -2591,17 +2581,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        mWmService.mInputToWindowMap.put(mInputChannelToken, this);
        channel.copyTo(outInputChannel);
        channel.dispose();
            return;
        }
        if (mInputChannel != null) {
            throw new IllegalStateException("Window already has an input channel.");
        }
        String name = getName();
        mInputChannel = mWmService.mInputManager.createInputChannel(name);
        mInputChannelToken = mInputChannel.getToken();
        mInputWindowHandle.setToken(mInputChannelToken);
        mWmService.mInputToWindowMap.put(mInputChannelToken, this);
        mInputChannel.copyTo(outInputChannel);
    }

    /**
@@ -2624,12 +2603,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            mInputChannelToken = null;
        }

        if (!removeInputChannelFromWindowstate()) {
            if (mInputChannel != null) {
                mInputChannel.dispose();
                mInputChannel = null;
            }
        }
        mInputWindowHandle.setToken(null);
    }

+0 −9
Original line number Diff line number Diff line
@@ -2309,13 +2309,6 @@ static jint nativeGetKeyCodeForKeyLocation(JNIEnv* env, jobject nativeImplObj, j
                                                                             locationKeyCode);
}

static void handleInputChannelDisposed(JNIEnv* env, jobject /* inputChannelObj */,
                                       const std::shared_ptr<InputChannel>& inputChannel,
                                       void* data) {
    NativeInputManager* im = static_cast<NativeInputManager*>(data);
    im->removeInputChannel(inputChannel->getConnectionToken());
}

static jobject nativeCreateInputChannel(JNIEnv* env, jobject nativeImplObj, jstring nameObj) {
    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);

@@ -2337,8 +2330,6 @@ static jobject nativeCreateInputChannel(JNIEnv* env, jobject nativeImplObj, jstr
        return nullptr;
    }

    android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
            handleInputChannelDisposed, im);
    return inputChannelObj;
}