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

Commit 5ccc6641 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Set ActivityView's rect as tap exclude region"

parents fd8d8944 4b6599e4
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;

import dalvik.system.CloseGuard;

@@ -58,6 +59,8 @@ public class ActivityView extends ViewGroup {
    private StateCallback mActivityViewCallback;

    private IInputForwarder mInputForwarder;
    // Temp container to store view coordinates on screen.
    private final int[] mLocationOnScreen = new int[2];

    private final CloseGuard mGuard = CloseGuard.get();
    private boolean mOpened; // Protected by mGuard.
@@ -198,11 +201,30 @@ public class ActivityView extends ViewGroup {
        performRelease();
    }

    /**
     * Triggers an update of {@link ActivityView}'s location on screen to properly set touch exclude
     * regions and avoid focus switches by touches on this view.
     */
    public void onLocationChanged() {
        updateLocation();
    }

    @Override
    public void onLayout(boolean changed, int l, int t, int r, int b) {
        mSurfaceView.layout(0 /* left */, 0 /* top */, r - l /* right */, b - t /* bottom */);
    }

    /** Send current location and size to the WM to set tap exclude region for this view. */
    private void updateLocation() {
        try {
            getLocationOnScreen(mLocationOnScreen);
            WindowManagerGlobal.getWindowSession().updateTapExcludeRegion(getWindow(), hashCode(),
                    mLocationOnScreen[0], mLocationOnScreen[1], getWidth(), getHeight());
        } catch (RemoteException e) {
            e.rethrowAsRuntimeException();
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return injectInputEvent(event) || super.onTouchEvent(event);
@@ -241,6 +263,7 @@ public class ActivityView extends ViewGroup {
            } else {
                mVirtualDisplay.setSurface(surfaceHolder.getSurface());
            }
            updateLocation();
        }

        @Override
@@ -248,6 +271,7 @@ public class ActivityView extends ViewGroup {
            if (mVirtualDisplay != null) {
                mVirtualDisplay.resize(width, height, getBaseDisplayDensity());
            }
            updateLocation();
        }

        @Override
@@ -257,6 +281,7 @@ public class ActivityView extends ViewGroup {
            if (mVirtualDisplay != null) {
                mVirtualDisplay.setSurface(null);
            }
            cleanTapExcludeRegion();
        }
    }

@@ -290,6 +315,7 @@ public class ActivityView extends ViewGroup {
        if (mInputForwarder != null) {
            mInputForwarder = null;
        }
        cleanTapExcludeRegion();

        final boolean displayReleased;
        if (mVirtualDisplay != null) {
@@ -313,6 +339,17 @@ public class ActivityView extends ViewGroup {
        mOpened = false;
    }

    /** Report to server that tap exclude region on hosting display should be cleared. */
    private void cleanTapExcludeRegion() {
        // Update tap exclude region with an empty rect to clean the state on server.
        try {
            WindowManagerGlobal.getWindowSession().updateTapExcludeRegion(getWindow(), hashCode(),
                    0 /* left */, 0 /* top */, 0 /* width */, 0 /* height */);
        } catch (RemoteException e) {
            e.rethrowAsRuntimeException();
        }
    }

    /** Get density of the hosting display. */
    private int getBaseDisplayDensity() {
        final WindowManager wm = mContext.getSystemService(WindowManager.class);
+8 −0
Original line number Diff line number Diff line
@@ -236,4 +236,12 @@ interface IWindowSession {
    boolean startMovingTask(IWindow window, float startX, float startY);

    void updatePointerIcon(IWindow window);

    /**
     * Update a tap exclude region with a rectangular area identified by provided id in the window.
     * Touches on this region will not switch focus to this window. Passing an empty rect will
     * remove the area from the exclude region of this window.
     */
    void updateTapExcludeRegion(IWindow window, int regionId, int left, int top, int width,
            int height);
}
+9 −0
Original line number Diff line number Diff line
@@ -17885,6 +17885,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        return mAttachInfo != null ? mAttachInfo.mSession : null;
    }
    /**
     * Return the window this view is currently attached to. Used in
     * {@link android.app.ActivityView} to communicate with WM.
     * @hide
     */
    protected IWindow getWindow() {
        return mAttachInfo != null ? mAttachInfo.mWindow : null;
    }
    /**
     * Return the visibility value of the least visible component passed.
     */
+8 −1
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ import android.os.IBinder;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.Trace;
import android.util.ArraySet;
import android.util.DisplayMetrics;
import android.util.MutableBoolean;
import android.util.Slog;
@@ -330,6 +331,8 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
    final PinnedStackController mPinnedStackControllerLocked;

    final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
    /** A collection of windows that provide tap exclude regions inside of them. */
    final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();

    private boolean mHaveBootMsg = false;
    private boolean mHaveApp = false;
@@ -1866,10 +1869,14 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
            }
        }
        for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
            WindowState win = mTapExcludedWindows.get(i);
            final WindowState win = mTapExcludedWindows.get(i);
            win.getTouchableRegion(mTmpRegion);
            mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
        }
        for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
            final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
            win.amendTapExcludeRegion(mTouchExcludeRegion);
        }
        // TODO(multi-display): Support docked stacks on secondary displays.
        if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
            mDividerControllerLocked.getTouchRegion(mTmpRect);
+11 −0
Original line number Diff line number Diff line
@@ -467,6 +467,17 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
        }
    }

    @Override
    public void updateTapExcludeRegion(IWindow window, int regionId, int left, int top, int width,
            int height) {
        final long identity = Binder.clearCallingIdentity();
        try {
            mService.updateTapExcludeRegion(window, regionId, left, top, width, height);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
    }

    void windowAddedLocked(String packageName) {
        mPackageName = packageName;
        mRelayoutTag = "relayoutWindow: " + mPackageName;
Loading