summaryrefslogtreecommitdiff
path: root/core/java/android/window/TaskEmbedder.java
diff options
context:
space:
mode:
authorYuncheol Heo <ycheo@google.com>2020-05-01 11:50:52 -0700
committerYuncheol Heo <ycheo@google.com>2020-05-05 14:41:43 -0700
commit8f5f53ca0fed52106ebddc84dd5e738e6facd566 (patch)
tree38c9af1fb38062158782698e2ba29952320cbe61 /core/java/android/window/TaskEmbedder.java
parent9d3317b8da7690c75ed799ab91df1e6b73b88aaa (diff)
Migrate Tap exclusion logic to TaskEmbedder.
We want to pass the touches on ActivityView to the Activity inside ActivityView, not to be consumed by Activity hosting ActivityView. To do that, we need to set a tap exclude region, so touches can go through. Bug: 155424730 Test: Make sure the Activity inside ActivityView gets touch. Change-Id: Ia9b2c7eba0c48512a633c798b1012e5fbec8422f
Diffstat (limited to 'core/java/android/window/TaskEmbedder.java')
-rw-r--r--core/java/android/window/TaskEmbedder.java69
1 files changed, 64 insertions, 5 deletions
diff --git a/core/java/android/window/TaskEmbedder.java b/core/java/android/window/TaskEmbedder.java
index 4257ce084829..ca6c568c2668 100644
--- a/core/java/android/window/TaskEmbedder.java
+++ b/core/java/android/window/TaskEmbedder.java
@@ -36,11 +36,14 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Region;
import android.hardware.display.VirtualDisplay;
+import android.os.RemoteException;
import android.os.UserHandle;
import android.view.IWindow;
import android.view.IWindowManager;
+import android.view.IWindowSession;
import android.view.KeyEvent;
import android.view.SurfaceControl;
+import android.view.WindowManagerGlobal;
import dalvik.system.CloseGuard;
@@ -184,31 +187,45 @@ public abstract class TaskEmbedder {
/**
* Called when the task embedder should be initialized.
+ * NOTE: all overriding methods should call this one after they finish their initialization.
* @return whether to report whether the embedder was initialized.
*/
- public abstract boolean onInitialize();
+ public boolean onInitialize() {
+ updateLocationAndTapExcludeRegion();
+ return true;
+ }
/**
* Called when the task embedder should be released.
* @return whether to report whether the embedder was released.
*/
- protected abstract boolean onRelease();
+ protected boolean onRelease() {
+ // Clear tap-exclude region (if any) for this window.
+ clearTapExcludeRegion();
+ return true;
+ }
/**
* Starts presentation of tasks in this container.
*/
- public abstract void start();
+ public void start() {
+ updateLocationAndTapExcludeRegion();
+ }
/**
* Stops presentation of tasks in this container.
*/
- public abstract void stop();
+ public void stop() {
+ clearTapExcludeRegion();
+ }
/**
* This should be called whenever the position or size of the surface changes
* or if touchable areas above the surface are added or removed.
*/
- public abstract void notifyBoundsChanged();
+ public void notifyBoundsChanged() {
+ updateLocationAndTapExcludeRegion();
+ }
/**
* Called to update the dimensions whenever the host size changes.
@@ -268,6 +285,48 @@ public abstract class TaskEmbedder {
}
/**
+ * Updates position and bounds information needed by WM and IME to manage window
+ * focus and touch events properly.
+ * <p>
+ * This should be called whenever the position or size of the surface changes
+ * or if touchable areas above the surface are added or removed.
+ */
+ protected void updateLocationAndTapExcludeRegion() {
+ if (!isInitialized() || mHost.getWindow() == null) {
+ return;
+ }
+ applyTapExcludeRegion(mHost.getWindow(), mHost.getTapExcludeRegion());
+ }
+
+ /**
+ * Call to update the tap exclude region for the window.
+ * <p>
+ * This should not normally be called directly, but through
+ * {@link #updateLocationAndTapExcludeRegion()}. This method
+ * is provided as an optimization when managing multiple TaskSurfaces within a view.
+ *
+ * @see IWindowSession#updateTapExcludeRegion(IWindow, Region)
+ */
+ private void applyTapExcludeRegion(IWindow window, @Nullable Region tapExcludeRegion) {
+ try {
+ IWindowSession session = WindowManagerGlobal.getWindowSession();
+ session.updateTapExcludeRegion(window, tapExcludeRegion);
+ } catch (RemoteException e) {
+ e.rethrowAsRuntimeException();
+ }
+ }
+
+ /**
+ * Removes the tap exclude region set by {@link #updateLocationAndTapExcludeRegion()}.
+ */
+ private void clearTapExcludeRegion() {
+ if (!isInitialized() || mHost.getWindow() == null) {
+ return;
+ }
+ applyTapExcludeRegion(mHost.getWindow(), null);
+ }
+
+ /**
* Set the callback to be notified about state changes.
* <p>This class must finish initializing before {@link #startActivity(Intent)} can be called.
* <p>Note: If the instance was ready prior to this call being made, then