private static native boolean nativeHasKeys(long ptr,
int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists);
private static native void nativeRegisterInputChannel(long ptr, InputChannel inputChannel,
- InputWindowHandle inputWindowHandle, boolean monitor);
+ InputWindowHandle inputWindowHandle, int displayId);
private static native void nativeUnregisterInputChannel(long ptr, InputChannel inputChannel);
private static native void nativeSetInputFilterEnabled(long ptr, boolean enable);
private static native int nativeInjectInputEvent(long ptr, InputEvent event,
/**
* Creates an input channel that will receive all input from the input dispatcher.
* @param inputChannelName The input channel name.
+ * @param displayId Target display id.
* @return The input channel.
*/
- public InputChannel monitorInput(String inputChannelName) {
+ public InputChannel monitorInput(String inputChannelName, int displayId) {
if (inputChannelName == null) {
throw new IllegalArgumentException("inputChannelName must not be null.");
}
+ if (displayId < Display.DEFAULT_DISPLAY) {
+ throw new IllegalArgumentException("displayId must >= 0.");
+ }
+
InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
- nativeRegisterInputChannel(mPtr, inputChannels[0], null, true);
+ // Register channel for monitor.
+ nativeRegisterInputChannel(mPtr, inputChannels[0], null, displayId);
inputChannels[0].dispose(); // don't need to retain the Java object reference
return inputChannels[1];
}
throw new IllegalArgumentException("inputChannel must not be null.");
}
- nativeRegisterInputChannel(mPtr, inputChannel, inputWindowHandle, false);
+ // Register channel for normal.
+ nativeRegisterInputChannel(mPtr, inputChannel, inputWindowHandle, Display.INVALID_DISPLAY);
}
/**
}
});
mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
- mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
+ //TODO (b/111365687) : make system context per display.
+ mWindowManagerFuncs.registerPointerEventListener(mSystemGestures, DEFAULT_DISPLAY);
mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
mLongPressVibePattern = getLongIntArray(mContext.getResources(),
WindowManager wm = (WindowManager) mContext.getSystemService(WINDOW_SERVICE);
lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
wm.addView(mPointerLocationView, lp);
- mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
+ //TODO (b/111365687) : make system context per display.
+ mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView, DEFAULT_DISPLAY);
}
}
private void disablePointerLocation() {
if (mPointerLocationView != null) {
- mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
+ //TODO (b/111365687) : make system context per display.
+ mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView,
+ DEFAULT_DISPLAY);
WindowManager wm = (WindowManager) mContext.getSystemService(WINDOW_SERVICE);
wm.removeView(mPointerLocationView);
mPointerLocationView = null;
public Object getWindowManagerLock();
/** Register a system listener for touch events */
- void registerPointerEventListener(PointerEventListener listener);
+ void registerPointerEventListener(PointerEventListener listener, int displayId);
/** Unregister a system listener for touch events */
- void unregisterPointerEventListener(PointerEventListener listener);
+ void unregisterPointerEventListener(PointerEventListener listener, int displayId);
/**
* @return The content insets of the docked divider window.
import android.view.DisplayCutout;
import android.view.DisplayInfo;
import android.view.Gravity;
+import android.view.InputChannel;
import android.view.InputDevice;
import android.view.MagnificationSpec;
import android.view.Surface;
import android.view.SurfaceControl;
import android.view.SurfaceControl.Transaction;
import android.view.SurfaceSession;
+import android.view.WindowManagerPolicyConstants.PointerEventListener;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ToBooleanFunction;
*/
WindowState mInputMethodWindow;
+ private final PointerEventDispatcher mPointerEventDispatcher;
+
private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
WindowStateAnimator winAnimator = w.mWinAnimator;
final AppWindowToken atoken = w.mAppToken;
mDisplayReady = true;
mInputMonitor = new InputMonitor(service, mDisplayId);
+
+ if (mService.mInputManager != null) {
+ final InputChannel inputChannel = mService.mInputManager.monitorInput("Display "
+ + mDisplayId, mDisplayId);
+ mPointerEventDispatcher = inputChannel != null
+ ? new PointerEventDispatcher(inputChannel) : null;
+ } else {
+ mPointerEventDispatcher = null;
+ }
}
boolean isReady() {
mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
+
+ // Tap Listeners are supported for:
+ // 1. All physical displays (multi-display).
+ // 2. VirtualDisplays on VR, AA (and everything else).
+ if (mPointerEventDispatcher != null && mTapDetector == null) {
+ if (DEBUG_DISPLAY) {
+ Slog.d(TAG,
+ "Registering PointerEventListener for DisplayId: " + mDisplayId);
+ }
+ mTapDetector = new TaskTapPointerEventListener(mService, this);
+ registerPointerEventListener(mTapDetector);
+ registerPointerEventListener(mService.mMousePositionTracker);
+ }
}
/**
try {
super.removeImmediately();
if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
- if (mService.canDispatchPointerEvents()) {
- if (mTapDetector != null) {
- mService.unregisterPointerEventListener(mTapDetector);
- }
- if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
- mService.unregisterPointerEventListener(mService.mMousePositionTracker);
- }
+ if (mPointerEventDispatcher != null && mTapDetector != null) {
+ unregisterPointerEventListener(mTapDetector);
+ unregisterPointerEventListener(mService.mMousePositionTracker);
+ mTapDetector = null;
}
mService.mAnimator.removeDisplayLocked(mDisplayId);
mWindowingLayer.release();
boolean getLastHasContent() {
return mLastHasContent;
}
+
+ void registerPointerEventListener(@NonNull PointerEventListener listener) {
+ if (mPointerEventDispatcher != null) {
+ mPointerEventDispatcher.registerInputEventListener(listener);
+ }
+ }
+
+ void unregisterPointerEventListener(@NonNull PointerEventListener listener) {
+ if (mPointerEventDispatcher != null) {
+ mPointerEventDispatcher.unregisterInputEventListener(listener);
+ }
+ }
}
mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(
displayId, dc.getDisplayInfo());
dc.configureDisplayPolicy();
-
- // Tap Listeners are supported for:
- // 1. All physical displays (multi-display).
- // 2. VirtualDisplays on VR, AA (and everything else).
- if (mService.canDispatchPointerEvents()) {
- if (DEBUG_DISPLAY) {
- Slog.d(TAG,
- "Registering PointerEventListener for DisplayId: " + displayId);
- }
- dc.mTapDetector = new TaskTapPointerEventListener(mService, dc);
- mService.registerPointerEventListener(dc.mTapDetector);
- if (displayId == DEFAULT_DISPLAY) {
- mService.registerPointerEventListener(mService.mMousePositionTracker);
- }
- }
}
return dc;
final ArrayMap<AnimationAdapter, SurfaceAnimator> mAnimationTransferMap = new ArrayMap<>();
final BoundsAnimationController mBoundsAnimationController;
- private final PointerEventDispatcher mPointerEventDispatcher;
-
private WindowContentFrameStats mTempWindowRenderStats;
private final LatencyTracker mLatencyTracker;
LocalServices.addService(WindowManagerPolicy.class, mPolicy);
- if(mInputManager != null) {
- final InputChannel inputChannel = mInputManager.monitorInput(TAG_WM);
- mPointerEventDispatcher = inputChannel != null
- ? new PointerEventDispatcher(inputChannel) : null;
- } else {
- mPointerEventDispatcher = null;
- }
-
mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE);
mKeyguardDisableHandler = new KeyguardDisableHandler(mContext, mPolicy);
}
@Override
- public void registerPointerEventListener(PointerEventListener listener) {
- mPointerEventDispatcher.registerInputEventListener(listener);
+ public void registerPointerEventListener(PointerEventListener listener, int displayId) {
+ synchronized (mWindowMap) {
+ final DisplayContent displayContent = mRoot.getDisplayContent(displayId);
+ if (displayContent != null) {
+ displayContent.registerPointerEventListener(listener);
+ }
+ }
}
@Override
- public void unregisterPointerEventListener(PointerEventListener listener) {
- mPointerEventDispatcher.unregisterInputEventListener(listener);
- }
-
- /** Check if the service is set to dispatch pointer events. */
- boolean canDispatchPointerEvents() {
- return mPointerEventDispatcher != null;
+ public void unregisterPointerEventListener(PointerEventListener listener, int displayId) {
+ synchronized (mWindowMap) {
+ final DisplayContent displayContent = mRoot.getDisplayContent(displayId);
+ if (displayContent != null) {
+ displayContent.unregisterPointerEventListener(listener);
+ }
+ }
}
// Called by window manager policy. Not exposed externally.
void setDisplayViewports(JNIEnv* env, jobjectArray viewportObjArray);
status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
- const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
+ const sp<InputWindowHandle>& inputWindowHandle, int32_t displayId);
status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray, int32_t displayId);
}
status_t NativeInputManager::registerInputChannel(JNIEnv* /* env */,
- const sp<InputChannel>& inputChannel,
- const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
+ const sp<InputChannel>& inputChannel, const sp<InputWindowHandle>& inputWindowHandle,
+ int32_t displayId) {
ATRACE_CALL();
- return mInputManager->getDispatcher()->registerInputChannel(
- inputChannel, inputWindowHandle, monitor);
+ return mInputManager->getDispatcher()->registerInputChannel(inputChannel, inputWindowHandle,
+ displayId);
}
status_t NativeInputManager::unregisterInputChannel(JNIEnv* /* env */,
}
static void nativeRegisterInputChannel(JNIEnv* env, jclass /* clazz */,
- jlong ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
+ jlong ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jint displayId) {
NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
status_t status = im->registerInputChannel(
- env, inputChannel, inputWindowHandle, monitor);
+ env, inputChannel, inputWindowHandle, displayId);
if (status) {
std::string message;
message += StringPrintf("Failed to register input channel. status=%d", status);
return;
}
- if (! monitor) {
+ // If inputWindowHandle is null and displayId >= 0, treat inputChannel as monitor.
+ if (inputWindowHandle != nullptr || displayId == ADISPLAY_ID_NONE) {
android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
handleInputChannelDisposed, im);
}
{ "nativeHasKeys", "(JII[I[Z)Z",
(void*) nativeHasKeys },
{ "nativeRegisterInputChannel",
- "(JLandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
+ "(JLandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;I)V",
(void*) nativeRegisterInputChannel },
{ "nativeUnregisterInputChannel", "(JLandroid/view/InputChannel;)V",
(void*) nativeUnregisterInputChannel },
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doNothing;
final WindowTestUtils.TestAppWindowToken token =
WindowTestUtils.createTestAppWindowToken(dc0);
task0.addChild(token, 0);
- dc0.mTapDetector = new TaskTapPointerEventListener(sWm, dc0);
- sWm.registerPointerEventListener(dc0.mTapDetector);
+ dc0.configureDisplayPolicy();
+ assertNotNull(dc0.mTapDetector);
+
final TaskStack stack1 = createTaskStackOnDisplay(dc1);
final Task task1 = createTaskInStack(stack1, 0 /* userId */);
final WindowTestUtils.TestAppWindowToken token1 =
WindowTestUtils.createTestAppWindowToken(dc0);
task1.addChild(token1, 0);
- dc1.mTapDetector = new TaskTapPointerEventListener(sWm, dc0);
- sWm.registerPointerEventListener(dc1.mTapDetector);
-
- // tap on primary display (by sending ACTION_DOWN followed by ACTION_UP)
- DisplayMetrics dm0 = dc0.getDisplayMetrics();
- dc0.mTapDetector.onPointerEvent(
- createTapEvent(dm0.widthPixels / 2, dm0.heightPixels / 2, true));
- dc0.mTapDetector.onPointerEvent(
- createTapEvent(dm0.widthPixels / 2, dm0.heightPixels / 2, false));
+ dc1.configureDisplayPolicy();
+ assertNotNull(dc1.mTapDetector);
+ // tap on primary display.
+ tapOnDisplay(dc0);
// Check focus is on primary display.
assertEquals(sWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus,
dc0.findFocusedWindow());
- // Tap on secondary display
- DisplayMetrics dm1 = dc1.getDisplayMetrics();
- dc1.mTapDetector.onPointerEvent(
- createTapEvent(dm1.widthPixels / 2, dm1.heightPixels / 2, true));
- dc1.mTapDetector.onPointerEvent(
- createTapEvent(dm1.widthPixels / 2, dm1.heightPixels / 2, false));
-
+ // Tap on secondary display.
+ tapOnDisplay(dc1);
// Check focus is on secondary.
assertEquals(sWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus,
dc1.findFocusedWindow());
return result;
}
- private MotionEvent createTapEvent(float x, float y, boolean isDownEvent) {
+ private void tapOnDisplay(final DisplayContent dc) {
+ final DisplayMetrics dm = dc.getDisplayMetrics();
+ final float x = dm.widthPixels / 2;
+ final float y = dm.heightPixels / 2;
final long downTime = SystemClock.uptimeMillis();
final long eventTime = SystemClock.uptimeMillis() + 100;
- final int metaState = 0;
+ // sending ACTION_DOWN
+ final MotionEvent downEvent = MotionEvent.obtain(
+ downTime,
+ downTime,
+ MotionEvent.ACTION_DOWN,
+ x,
+ y,
+ 0 /*metaState*/);
+ downEvent.setDisplayId(dc.getDisplayId());
+ dc.mTapDetector.onPointerEvent(downEvent);
- return MotionEvent.obtain(
+ // sending ACTION_UP
+ final MotionEvent upEvent = MotionEvent.obtain(
downTime,
eventTime,
- isDownEvent ? MotionEvent.ACTION_DOWN : MotionEvent.ACTION_UP,
+ MotionEvent.ACTION_UP,
x,
y,
- metaState);
+ 0 /*metaState*/);
+ upEvent.setDisplayId(dc.getDisplayId());
+ dc.mTapDetector.onPointerEvent(upEvent);
}
}
// InputChannel is final and can't be mocked.
InputChannel[] input = InputChannel.openInputChannelPair(TAG_WM);
if (input != null && input.length > 1) {
- doReturn(input[1]).when(ims).monitorInput(anyString());
+ doReturn(input[1]).when(ims).monitorInput(anyString(), anyInt());
}
mService = WindowManagerService.main(context, ims, false,