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

Commit 97bd7a52 authored by Roshan Pius's avatar Roshan Pius Committed by Android (Google) Code Review
Browse files

Merge "Revert "Use new create/removeInputChannel().""

parents eab871a7 e61a71b9
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ public final class InputChannel implements Parcelable {
     *
     *  @hide
     */
    private void setNativeInputChannel(long nativeChannel) {
    public void setNativeInputChannel(long nativeChannel) {
        if (nativeChannel == 0) {
            throw new IllegalArgumentException("Attempting to set native input channel to null.");
        }
@@ -148,11 +148,12 @@ public final class InputChannel implements Parcelable {
    }

    /**
     * Creates a copy of this instance to the outParameter. This is used to pass an input channel
     * Transfers ownership of the internal state of the input channel to another
     * instance and invalidates this instance.  This is used to pass an input channel
     * as an out parameter in a binder call.
     * @param other The other input channel instance.
     */
    public void copyTo(InputChannel outParameter) {
    public void transferTo(InputChannel outParameter) {
        if (outParameter == null) {
            throw new IllegalArgumentException("outParameter must not be null");
        }
+9 −38
Original line number Diff line number Diff line
@@ -36,9 +36,6 @@ namespace android {
static struct {
    jclass clazz;

    jmethodID mCtor;
    jmethodID mSetNativeInputChannel;

    jfieldID mPtr;   // native object attached to the DVM InputChannel
} gInputChannelClassInfo;

@@ -46,7 +43,7 @@ static struct {

class NativeInputChannel {
public:
    explicit NativeInputChannel(std::unique_ptr<InputChannel> inputChannel);
    explicit NativeInputChannel(const std::shared_ptr<InputChannel>& inputChannel);
    ~NativeInputChannel();

    inline std::shared_ptr<InputChannel> getInputChannel() { return mInputChannel; }
@@ -62,8 +59,8 @@ private:

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

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

NativeInputChannel::~NativeInputChannel() {
}
@@ -113,33 +110,13 @@ void android_view_InputChannel_setDisposeCallback(JNIEnv* env, jobject inputChan
}

static jlong android_view_InputChannel_createInputChannel(
        JNIEnv* env, std::unique_ptr<InputChannel> inputChannel) {
        JNIEnv* env, std::shared_ptr<InputChannel> inputChannel) {
    std::unique_ptr<NativeInputChannel> nativeInputChannel =
            std::make_unique<NativeInputChannel>(std::move(inputChannel));
            std::make_unique<NativeInputChannel>(inputChannel);

    return reinterpret_cast<jlong>(nativeInputChannel.release());
}

jobject android_view_InputChannel_createJavaObject(JNIEnv* env,
                                                   std::unique_ptr<InputChannel> inputChannel) {
    std::string name = inputChannel->getName();
    jlong ptr = android_view_InputChannel_createInputChannel(env, std::move(inputChannel));
    jobject javaInputChannel =
            env->NewObject(gInputChannelClassInfo.clazz, gInputChannelClassInfo.mCtor);
    if (!javaInputChannel) {
        ALOGE("Failed to create a Java InputChannel for channel %s.", name.c_str());
        return nullptr;
    }

    env->CallVoidMethod(javaInputChannel, gInputChannelClassInfo.mSetNativeInputChannel, ptr);
    if (env->ExceptionOccurred()) {
        ALOGE("Failed to set native ptr to the Java InputChannel for channel %s.",
              inputChannel->getName().c_str());
        return nullptr;
    }
    return javaInputChannel;
}

static jlongArray android_view_InputChannel_nativeOpenInputChannelPair(JNIEnv* env,
        jclass clazz, jstring nameObj) {
    ScopedUtfChars nameChars(env, nameObj);
@@ -203,10 +180,9 @@ static jlong android_view_InputChannel_nativeReadFromParcel(JNIEnv* env, jobject
    if (parcel) {
        bool isInitialized = parcel->readInt32();
        if (isInitialized) {
            std::unique_ptr<InputChannel> inputChannel = std::make_unique<InputChannel>();
            std::shared_ptr<InputChannel> inputChannel = std::make_shared<InputChannel>();
            inputChannel->readFromParcel(parcel);
            NativeInputChannel* nativeInputChannel =
                    new NativeInputChannel(std::move(inputChannel));
            NativeInputChannel* nativeInputChannel = new NativeInputChannel(inputChannel);
            return reinterpret_cast<jlong>(nativeInputChannel);
        }
    }
@@ -257,13 +233,13 @@ static jlong android_view_InputChannel_nativeDup(JNIEnv* env, jobject obj, jlong
        return 0;
    }

    std::unique_ptr<InputChannel> dupInputChannel = inputChannel->dup();
    std::shared_ptr<InputChannel> dupInputChannel = inputChannel->dup();
    if (dupInputChannel == nullptr) {
        std::string message = android::base::StringPrintf(
                "Could not duplicate input channel %s", inputChannel->getName().c_str());
        jniThrowRuntimeException(env, message.c_str());
    }
    return reinterpret_cast<jlong>(new NativeInputChannel(std::move(dupInputChannel)));
    return reinterpret_cast<jlong>(new NativeInputChannel(dupInputChannel));
}

static jobject android_view_InputChannel_nativeGetToken(JNIEnv* env, jobject obj, jlong channel) {
@@ -305,11 +281,6 @@ int register_android_view_InputChannel(JNIEnv* env) {
    jclass clazz = FindClassOrDie(env, "android/view/InputChannel");
    gInputChannelClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);

    gInputChannelClassInfo.mCtor =
            GetMethodIDOrDie(env, gInputChannelClassInfo.clazz, "<init>", "()V");
    gInputChannelClassInfo.mSetNativeInputChannel =
            GetMethodIDOrDie(env, gInputChannelClassInfo.clazz, "setNativeInputChannel", "(J)V");

    gInputChannelClassInfo.mPtr = GetFieldIDOrDie(env, gInputChannelClassInfo.clazz, "mPtr", "J");

    return res;
+0 −2
Original line number Diff line number Diff line
@@ -36,8 +36,6 @@ extern std::shared_ptr<InputChannel> android_view_InputChannel_getInputChannel(
extern void android_view_InputChannel_setDisposeCallback(JNIEnv* env, jobject inputChannelObj,
        InputChannelObjDisposeCallback callback, void* data = NULL);

extern jobject android_view_InputChannel_createJavaObject(
        JNIEnv* env, std::unique_ptr<InputChannel> inputChannel);
} // namespace android

#endif // _ANDROID_OS_INPUTCHANNEL_H
+27 −19
Original line number Diff line number Diff line
@@ -219,10 +219,10 @@ public class InputManagerService extends IInputManager.Stub
            int deviceId, int sourceMask, int sw);
    private static native boolean nativeHasKeys(long ptr,
            int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists);
    private static native InputChannel nativeCreateInputChannel(long ptr, String name);
    private static native InputChannel nativeCreateInputMonitor(long ptr, int displayId,
            boolean isGestureMonitor, String name);
    private static native void nativeRemoveInputChannel(long ptr, IBinder connectionToken);
    private static native void nativeRegisterInputChannel(long ptr, InputChannel inputChannel);
    private static native void nativeRegisterInputMonitor(long ptr, InputChannel inputChannel,
            int displayId, boolean isGestureMonitor);
    private static native void nativeUnregisterInputChannel(long ptr, IBinder connectionToken);
    private static native void nativePilferPointers(long ptr, IBinder token);
    private static native void nativeSetInputFilterEnabled(long ptr, boolean enable);
    private static native void nativeSetInTouchMode(long ptr, boolean inTouchMode);
@@ -522,8 +522,10 @@ public class InputManagerService extends IInputManager.Stub
            throw new IllegalArgumentException("displayId must >= 0.");
        }

        return nativeCreateInputMonitor(mPtr, displayId, false /* isGestureMonitor */,
                inputChannelName);
        InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
        nativeRegisterInputMonitor(mPtr, inputChannels[0], displayId, false /*isGestureMonitor*/);
        inputChannels[0].dispose(); // don't need to retain the Java object reference
        return inputChannels[1];
    }

    /**
@@ -550,32 +552,38 @@ public class InputManagerService extends IInputManager.Stub

        final long ident = Binder.clearCallingIdentity();
        try {
            InputChannel inputChannel = nativeCreateInputMonitor(
                    mPtr, displayId, true /*isGestureMonitor*/, inputChannelName);
            InputMonitorHost host = new InputMonitorHost(inputChannel);
            InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
            InputMonitorHost host = new InputMonitorHost(inputChannels[0]);
            nativeRegisterInputMonitor(
                    mPtr, inputChannels[0], displayId, true /*isGestureMonitor*/);
            synchronized (mGestureMonitorPidsLock) {
                mGestureMonitorPidsByToken.put(inputChannel.getToken(), pid);
                mGestureMonitorPidsByToken.put(inputChannels[1].getToken(), pid);
            }
            return new InputMonitor(inputChannel, host);
            return new InputMonitor(inputChannels[1], host);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    /**
     * Creates an input channel to be used as an input event target.
     * Registers an input channel so that it can be used as an input event target. The channel is
     * registered with a generated token.
     *
     * @param name The name of this input channel
     * @param inputChannel The input channel to register.
     */
    public InputChannel createInputChannel(String name) {
        return nativeCreateInputChannel(mPtr, name);
    public void registerInputChannel(InputChannel inputChannel) {
        if (inputChannel == null) {
            throw new IllegalArgumentException("inputChannel must not be null.");
        }

        nativeRegisterInputChannel(mPtr, inputChannel);
    }

    /**
     * Removes an input channel.
     * Unregisters an input channel.
     * @param connectionToken The input channel to unregister.
     */
    public void removeInputChannel(IBinder connectionToken) {
    public void unregisterInputChannel(IBinder connectionToken) {
        if (connectionToken == null) {
            throw new IllegalArgumentException("connectionToken must not be null.");
        }
@@ -583,7 +591,7 @@ public class InputManagerService extends IInputManager.Stub
            mGestureMonitorPidsByToken.remove(connectionToken);
        }

        nativeRemoveInputChannel(mPtr, connectionToken);
        nativeUnregisterInputChannel(mPtr, connectionToken);
    }

    /**
@@ -2447,7 +2455,7 @@ public class InputManagerService extends IInputManager.Stub

        @Override
        public void dispose() {
            nativeRemoveInputChannel(mPtr, mInputChannel.getToken());
            nativeUnregisterInputChannel(mPtr, mInputChannel.getToken());
            mInputChannel.dispose();
        }
    }
+10 −5
Original line number Diff line number Diff line
@@ -258,13 +258,16 @@ class DragState {
    }

    class InputInterceptor {
        InputChannel mClientChannel;
        InputChannel mServerChannel, mClientChannel;
        DragInputEventReceiver mInputEventReceiver;
        InputApplicationHandle mDragApplicationHandle;
        InputWindowHandle mDragWindowHandle;

        InputInterceptor(Display display) {
            mClientChannel = mService.mInputManager.createInputChannel("drag");
            InputChannel[] channels = InputChannel.openInputChannelPair("drag");
            mServerChannel = channels[0];
            mClientChannel = channels[1];
            mService.mInputManager.registerInputChannel(mServerChannel);
            mInputEventReceiver = new DragInputEventReceiver(mClientChannel,
                    mService.mH.getLooper(), mDragDropController);

@@ -275,7 +278,7 @@ class DragState {
            mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle,
                    display.getDisplayId());
            mDragWindowHandle.name = "drag";
            mDragWindowHandle.token = mClientChannel.getToken();
            mDragWindowHandle.token = mServerChannel.getToken();
            mDragWindowHandle.layoutParamsFlags = 0;
            mDragWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
            mDragWindowHandle.dispatchingTimeoutMillis = DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
@@ -305,11 +308,13 @@ class DragState {
        }

        void tearDown() {
            mService.mInputManager.removeInputChannel(mClientChannel.getToken());
            mService.mInputManager.unregisterInputChannel(mServerChannel.getToken());
            mInputEventReceiver.dispose();
            mInputEventReceiver = null;
            mClientChannel.dispose();
            mServerChannel.dispose();
            mClientChannel = null;
            mServerChannel = null;

            mDragWindowHandle = null;
            mDragApplicationHandle = null;
@@ -321,7 +326,7 @@ class DragState {
    }

    InputChannel getInputChannel() {
        return mInputInterceptor == null ? null : mInputInterceptor.mClientChannel;
        return mInputInterceptor == null ? null : mInputInterceptor.mServerChannel;
    }

    InputWindowHandle getInputWindowHandle() {
Loading