diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 813def409c280..6c14b2cbed099 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -222,7 +222,7 @@ public class InputManagerService extends IInputManager.Stub 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, InputChannel inputChannel); + 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); @@ -581,17 +581,17 @@ public class InputManagerService extends IInputManager.Stub /** * Unregisters an input channel. - * @param inputChannel The input channel to unregister. + * @param connectionToken The input channel to unregister. */ - public void unregisterInputChannel(InputChannel inputChannel) { - if (inputChannel == null) { - throw new IllegalArgumentException("inputChannel must not be null."); + public void unregisterInputChannel(IBinder connectionToken) { + if (connectionToken == null) { + throw new IllegalArgumentException("connectionToken must not be null."); } synchronized (mGestureMonitorPidsLock) { - mGestureMonitorPidsByToken.remove(inputChannel.getToken()); + mGestureMonitorPidsByToken.remove(connectionToken); } - nativeUnregisterInputChannel(mPtr, inputChannel); + nativeUnregisterInputChannel(mPtr, connectionToken); } /** @@ -2455,7 +2455,7 @@ public class InputManagerService extends IInputManager.Stub @Override public void dispose() { - nativeUnregisterInputChannel(mPtr, mInputChannel); + nativeUnregisterInputChannel(mPtr, mInputChannel.getToken()); mInputChannel.dispose(); } } diff --git a/services/core/java/com/android/server/wm/DragState.java b/services/core/java/com/android/server/wm/DragState.java index c9f463b8fbeb2..6e32d0eddaafc 100644 --- a/services/core/java/com/android/server/wm/DragState.java +++ b/services/core/java/com/android/server/wm/DragState.java @@ -308,7 +308,7 @@ class DragState { } void tearDown() { - mService.mInputManager.unregisterInputChannel(mServerChannel); + mService.mInputManager.unregisterInputChannel(mServerChannel.getToken()); mInputEventReceiver.dispose(); mInputEventReceiver = null; mClientChannel.dispose(); diff --git a/services/core/java/com/android/server/wm/EmbeddedWindowController.java b/services/core/java/com/android/server/wm/EmbeddedWindowController.java index 5a2484735fb9c..8d20bb80bfd6e 100644 --- a/services/core/java/com/android/server/wm/EmbeddedWindowController.java +++ b/services/core/java/com/android/server/wm/EmbeddedWindowController.java @@ -192,7 +192,7 @@ class EmbeddedWindowController { void onRemoved() { if (mInputChannel != null) { - mWmService.mInputManager.unregisterInputChannel(mInputChannel); + mWmService.mInputManager.unregisterInputChannel(mInputChannel.getToken()); mInputChannel.dispose(); mInputChannel = null; } diff --git a/services/core/java/com/android/server/wm/InputConsumerImpl.java b/services/core/java/com/android/server/wm/InputConsumerImpl.java index a79d3bb009071..1d1a2663823ca 100644 --- a/services/core/java/com/android/server/wm/InputConsumerImpl.java +++ b/services/core/java/com/android/server/wm/InputConsumerImpl.java @@ -156,7 +156,7 @@ class InputConsumerImpl implements IBinder.DeathRecipient { } void disposeChannelsLw(SurfaceControl.Transaction t) { - mService.mInputManager.unregisterInputChannel(mServerChannel); + mService.mInputManager.unregisterInputChannel(mServerChannel.getToken()); mClientChannel.dispose(); mServerChannel.dispose(); t.remove(mInputSurface); diff --git a/services/core/java/com/android/server/wm/Letterbox.java b/services/core/java/com/android/server/wm/Letterbox.java index dccd3a6698272..4fe678dc19741 100644 --- a/services/core/java/com/android/server/wm/Letterbox.java +++ b/services/core/java/com/android/server/wm/Letterbox.java @@ -239,7 +239,7 @@ public class Letterbox { } void dispose() { - mWmService.mInputManager.unregisterInputChannel(mServerChannel); + mWmService.mInputManager.unregisterInputChannel(mServerChannel.getToken()); mInputEventReceiver.dispose(); mServerChannel.dispose(); mClientChannel.dispose(); diff --git a/services/core/java/com/android/server/wm/TaskPositioner.java b/services/core/java/com/android/server/wm/TaskPositioner.java index f32781a8fcb85..abe632941b97b 100644 --- a/services/core/java/com/android/server/wm/TaskPositioner.java +++ b/services/core/java/com/android/server/wm/TaskPositioner.java @@ -299,7 +299,7 @@ class TaskPositioner implements IBinder.DeathRecipient { } mService.mTaskPositioningController.hideInputSurface(mDisplayContent.getDisplayId()); - mService.mInputManager.unregisterInputChannel(mServerChannel); + mService.mInputManager.unregisterInputChannel(mServerChannel.getToken()); mInputEventReceiver.dispose(); mInputEventReceiver = null; diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 84a9c750d2d36..a5e50f0aa5ba8 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -2504,7 +2504,7 @@ class WindowState extends WindowContainer implements WindowManagerP // unregister server channel first otherwise it complains about broken channel if (mInputChannel != null) { - mWmService.mInputManager.unregisterInputChannel(mInputChannel); + mWmService.mInputManager.unregisterInputChannel(mInputChannel.getToken()); mInputChannel.dispose(); mInputChannel = null; diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index 5dd6cd7b42e95..46136ca0647d1 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -209,7 +209,7 @@ public: status_t registerInputChannel(JNIEnv* env, const std::shared_ptr& inputChannel); status_t registerInputMonitor(JNIEnv* env, const std::shared_ptr& inputChannel, int32_t displayId, bool isGestureMonitor); - status_t unregisterInputChannel(JNIEnv* env, const InputChannel& inputChannel); + status_t unregisterInputChannel(JNIEnv* env, const sp& connectionToken); status_t pilferPointers(const sp& token); void displayRemoved(JNIEnv* env, int32_t displayId); @@ -447,9 +447,9 @@ status_t NativeInputManager::registerInputMonitor(JNIEnv* /* env */, } status_t NativeInputManager::unregisterInputChannel(JNIEnv* /* env */, - const InputChannel& inputChannel) { + const sp& connectionToken) { ATRACE_CALL(); - return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel); + return mInputManager->getDispatcher()->unregisterInputChannel(connectionToken); } status_t NativeInputManager::pilferPointers(const sp& token) { @@ -1364,7 +1364,7 @@ static void handleInputChannelDisposed(JNIEnv* env, jobject /* inputChannelObj * ALOGW("Input channel object '%s' was disposed without first being unregistered with " "the input manager!", inputChannel->getName().c_str()); - im->unregisterInputChannel(env, *inputChannel); + im->unregisterInputChannel(env, inputChannel->getConnectionToken()); } static void nativeRegisterInputChannel(JNIEnv* env, jclass /* clazz */, @@ -1417,20 +1417,12 @@ static void nativeRegisterInputMonitor(JNIEnv* env, jclass /* clazz */, } } -static void nativeUnregisterInputChannel(JNIEnv* env, jclass /* clazz */, - jlong ptr, jobject inputChannelObj) { +static void nativeUnregisterInputChannel(JNIEnv* env, jclass /* clazz */, jlong ptr, + jobject tokenObj) { NativeInputManager* im = reinterpret_cast(ptr); + sp token = ibinderForJavaObject(env, tokenObj); - std::shared_ptr inputChannel = - android_view_InputChannel_getInputChannel(env, inputChannelObj); - if (inputChannel == nullptr) { - throwInputChannelNotInitialized(env); - return; - } - - android_view_InputChannel_setDisposeCallback(env, inputChannelObj, nullptr, nullptr); - - status_t status = im->unregisterInputChannel(env, *inputChannel); + status_t status = im->unregisterInputChannel(env, token); if (status && status != BAD_VALUE) { // ignore already unregistered channel std::string message; message += StringPrintf("Failed to unregister input channel. status=%d", status); @@ -1792,7 +1784,7 @@ static const JNINativeMethod gInputManagerMethods[] = { (void*)nativeRegisterInputChannel}, {"nativeRegisterInputMonitor", "(JLandroid/view/InputChannel;IZ)V", (void*)nativeRegisterInputMonitor}, - {"nativeUnregisterInputChannel", "(JLandroid/view/InputChannel;)V", + {"nativeUnregisterInputChannel", "(JLandroid/os/IBinder;)V", (void*)nativeUnregisterInputChannel}, {"nativePilferPointers", "(JLandroid/os/IBinder;)V", (void*)nativePilferPointers}, {"nativeSetInputFilterEnabled", "(JZ)V", (void*)nativeSetInputFilterEnabled},