summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorTiger Huang <tigerhuang@google.com>2019-01-17 18:41:41 +0800
committerTiger Huang <tigerhuang@google.com>2019-01-30 00:52:51 +0800
commit04dc4cc64bbc9902643780901d22ccf025efb4b7 (patch)
tree089cd814bdeb7a3c6615c168bd8a5ccbe46a6b4d /core/java/android
parent844ff30bfb11cb60950feccfc80237c162b94a95 (diff)
Let the activity embedded in ActivityView can be directly touched
The goal is to eliminate the latency caused by forwarding the event. In this CL, we put an input portal window behind an ActivityView, and subtract the touchable region of the the ActivityView, so that the user can touch through the portal window, and let the touch arrive on the embedded activity. Bug: 120675821 Test: Manual test with ActivityViewTest Test: atest CtsActivityManagerDeviceTestCases:ActivityViewTest Change-Id: I6776387b65cf6a7d2ea60cb00ffdd38be22081ac
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/ActivityView.java53
-rw-r--r--core/java/android/view/InputWindowHandle.java8
2 files changed, 12 insertions, 49 deletions
diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java
index 4d3711ae7ff5..a122fcef42d8 100644
--- a/core/java/android/app/ActivityView.java
+++ b/core/java/android/app/ActivityView.java
@@ -27,15 +27,12 @@ import android.content.Context;
import android.content.Intent;
import android.hardware.display.DisplayManager;
import android.hardware.display.VirtualDisplay;
-import android.hardware.input.InputManager;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.IWindowManager;
-import android.view.InputDevice;
-import android.view.MotionEvent;
import android.view.SurfaceControl;
import android.view.SurfaceHolder;
import android.view.SurfaceSession;
@@ -50,9 +47,7 @@ import dalvik.system.CloseGuard;
import java.util.List;
/**
- * Activity container that allows launching activities into itself and does input forwarding.
- * <p>Creation of this view is only allowed to callers who have
- * {@link android.Manifest.permission#INJECT_EVENTS} permission.
+ * Activity container that allows launching activities into itself.
* <p>Activity launching into this container is restricted by the same rules that apply to launching
* on VirtualDisplays.
* @hide
@@ -75,9 +70,8 @@ public class ActivityView extends ViewGroup {
private StateCallback mActivityViewCallback;
private IActivityTaskManager mActivityTaskManager;
- private IInputForwarder mInputForwarder;
- // Temp container to store view coordinates on screen.
- private final int[] mLocationOnScreen = new int[2];
+ // Temp container to store view coordinates in window.
+ private final int[] mLocationInWindow = new int[2];
private TaskStackListener mTaskStackListener;
@@ -264,7 +258,7 @@ public class ActivityView extends ViewGroup {
}
/**
- * Triggers an update of {@link ActivityView}'s location on screen to properly set touch exclude
+ * Triggers an update of {@link ActivityView}'s location in window to properly set touch exclude
* regions and avoid focus switches by touches on this view.
*/
public void onLocationChanged() {
@@ -279,45 +273,14 @@ public class ActivityView extends ViewGroup {
/** Send current location and size to the WM to set tap exclude region for this view. */
private void updateLocation() {
try {
- getLocationOnScreen(mLocationOnScreen);
+ getLocationInWindow(mLocationInWindow);
WindowManagerGlobal.getWindowSession().updateTapExcludeRegion(getWindow(), hashCode(),
- mLocationOnScreen[0], mLocationOnScreen[1], getWidth(), getHeight());
+ mLocationInWindow[0], mLocationInWindow[1], getWidth(), getHeight());
} catch (RemoteException e) {
e.rethrowAsRuntimeException();
}
}
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- return injectInputEvent(event) || super.onTouchEvent(event);
- }
-
- @Override
- public boolean onGenericMotionEvent(MotionEvent event) {
- if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) {
- if (injectInputEvent(event)) {
- return true;
- }
- }
- return super.onGenericMotionEvent(event);
- }
-
- private boolean injectInputEvent(MotionEvent event) {
- if (mInputForwarder != null) {
- try {
- // The touch event that the ActivityView gets is in View space, but the event needs
- // to get forwarded in screen space. This offsets the touch event by the location
- // the ActivityView is on screen and sends it to the input forwarder.
- getLocationOnScreen(mLocationOnScreen);
- event.offsetLocation(mLocationOnScreen[0], mLocationOnScreen[1]);
- return mInputForwarder.forwardEvent(event);
- } catch (RemoteException e) {
- e.rethrowAsRuntimeException();
- }
- }
- return false;
- }
-
private class SurfaceCallback implements SurfaceHolder.Callback {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
@@ -400,7 +363,6 @@ public class ActivityView extends ViewGroup {
}
mTmpTransaction.show(mRootSurfaceControl).apply();
- mInputForwarder = InputManager.getInstance().createInputForwarder(displayId);
mTaskStackListener = new TaskStackListenerImpl();
try {
mActivityTaskManager.registerTaskStackListener(mTaskStackListener);
@@ -416,9 +378,6 @@ public class ActivityView extends ViewGroup {
mSurfaceView.getHolder().removeCallback(mSurfaceCallback);
- if (mInputForwarder != null) {
- mInputForwarder = null;
- }
cleanTapExcludeRegion();
if (mTaskStackListener != null) {
diff --git a/core/java/android/view/InputWindowHandle.java b/core/java/android/view/InputWindowHandle.java
index 92e0009bc21a..ec79eea45ee6 100644
--- a/core/java/android/view/InputWindowHandle.java
+++ b/core/java/android/view/InputWindowHandle.java
@@ -16,10 +16,10 @@
package android.view;
+import static android.view.Display.INVALID_DISPLAY;
+
import android.graphics.Region;
import android.os.IBinder;
-import android.view.IWindow;
-import android.view.InputChannel;
/**
* Functions as a handle for a window that can receive input.
@@ -94,6 +94,10 @@ public final class InputWindowHandle {
// Display this input is on.
public int displayId;
+ // If this value is set to a valid display ID, it indicates this window is a portal which
+ // transports the touch of this window to the display indicated by portalToDisplayId.
+ public int portalToDisplayId = INVALID_DISPLAY;
+
private native void nativeDispose();
public InputWindowHandle(InputApplicationHandle inputApplicationHandle,