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

Commit 96c65d7c authored by Galia Peycheva's avatar Galia Peycheva Committed by Android (Google) Code Review
Browse files

Merge "Add SystemApi to set unrestricted keep-clear rects" into tm-dev

parents d985a179 acaf3857
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -15701,6 +15701,11 @@ package android.util {
package android.view {
  @UiThread public class View implements android.view.accessibility.AccessibilityEventSource android.graphics.drawable.Drawable.Callback android.view.KeyEvent.Callback {
    method @NonNull public final java.util.List<android.graphics.Rect> getUnrestrictedPreferKeepClearRects();
    method @RequiresPermission(android.Manifest.permission.SET_UNRESTRICTED_KEEP_CLEAR_AREAS) public final void setUnrestrictedPreferKeepClearRects(@NonNull java.util.List<android.graphics.Rect>);
  }
  public abstract class Window {
    method public void addSystemFlags(@android.view.WindowManager.LayoutParams.SystemFlags int);
  }
+2 −1
Original line number Diff line number Diff line
@@ -290,7 +290,8 @@ interface IWindowSession {
    /**
     * Called when the keep-clear areas for this window have changed.
     */
    oneway void reportKeepClearAreasChanged(IWindow window, in List<Rect> keepClearRects);
    oneway void reportKeepClearAreasChanged(IWindow window, in List<Rect> restricted,
           in List<Rect> unrestricted);

    /**
    * Request the server to call setInputWindowInfo on a given Surface, and return
+64 −0
Original line number Diff line number Diff line
@@ -46,9 +46,11 @@ import android.annotation.IntRange;
import android.annotation.LayoutRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.Size;
import android.annotation.StyleRes;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.UiContext;
import android.annotation.UiThread;
@@ -4744,6 +4746,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
         */
        private List<Rect> mSystemGestureExclusionRects = null;
        private List<Rect> mKeepClearRects = null;
        private List<Rect> mUnrestrictedKeepClearRects = null;
        private boolean mPreferKeepClear = false;
        private Rect mHandwritingArea = null;
@@ -11729,6 +11732,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        final ListenerInfo info = getListenerInfo();
        if (getSystemGestureExclusionRects().isEmpty()
                && collectPreferKeepClearRects().isEmpty()
                && collectUnrestrictedPreferKeepClearRects().isEmpty()
                && (info.mHandwritingArea == null || !isAutoHandwritingEnabled())) {
            if (info.mPositionUpdateListener != null) {
                mRenderNode.removePositionUpdateListener(info.mPositionUpdateListener);
@@ -11871,6 +11875,52 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        return Collections.emptyList();
    }
    /**
     * Set a preference to keep the provided rects clear from floating windows above this
     * view's window. This informs the system that these rects are considered vital areas for the
     * user and that ideally they should not be covered. Setting this is only appropriate for UI
     * where the user would likely take action to uncover it.
     * <p>
     * Note: The difference with {@link #setPreferKeepClearRects} is that the system won't apply
     * restrictions to the rects set here.
     * <p>
     * @see #setPreferKeepClear
     * @see #getPreferKeepClearRects
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.SET_UNRESTRICTED_KEEP_CLEAR_AREAS)
    public final void setUnrestrictedPreferKeepClearRects(@NonNull List<Rect> rects) {
        final ListenerInfo info = getListenerInfo();
        if (info.mUnrestrictedKeepClearRects != null) {
            info.mUnrestrictedKeepClearRects.clear();
            info.mUnrestrictedKeepClearRects.addAll(rects);
        } else {
            info.mUnrestrictedKeepClearRects = new ArrayList<>(rects);
        }
        updatePositionUpdateListener();
        postUpdate(this::updateKeepClearRects);
    }
    /**
     * @return the list of rects, set by {@link #setPreferKeepClearRects}.
     *
     * @see #setPreferKeepClearRects
     *
     * @hide
     */
    @SystemApi
    @NonNull
    public final List<Rect> getUnrestrictedPreferKeepClearRects() {
        final ListenerInfo info = mListenerInfo;
        if (info != null && info.mKeepClearRects != null) {
            return new ArrayList(info.mUnrestrictedKeepClearRects);
        }
        return Collections.emptyList();
    }
    void updateKeepClearRects() {
        final AttachInfo ai = mAttachInfo;
        if (ai != null) {
@@ -11898,6 +11948,20 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        return Collections.emptyList();
    }
    /**
     * Retrieve the list of unrestricted areas within this view's post-layout coordinate space
     * which the system will try to not cover with other floating elements, like the pip window.
     */
    @NonNull
    List<Rect> collectUnrestrictedPreferKeepClearRects() {
        final ListenerInfo info = mListenerInfo;
        if (info != null && info.mUnrestrictedKeepClearRects != null) {
            return info.mUnrestrictedKeepClearRects;
        }
        return Collections.emptyList();
    }
    /**
     * Set a list of handwriting areas in this view. If there is any stylus {@link MotionEvent}
     * occurs within those areas, it will trigger stylus handwriting mode. This can be disabled by
+18 −3
Original line number Diff line number Diff line
@@ -221,6 +221,7 @@ import java.io.StringWriter;
import java.lang.ref.WeakReference;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
@@ -778,6 +779,8 @@ public final class ViewRootImpl implements ViewParent,
            new ViewRootRectTracker(v -> v.getSystemGestureExclusionRects());
    private final ViewRootRectTracker mKeepClearRectsTracker =
            new ViewRootRectTracker(v -> v.collectPreferKeepClearRects());
    private final ViewRootRectTracker mUnrestrictedKeepClearRectsTracker =
            new ViewRootRectTracker(v -> v.collectUnrestrictedPreferKeepClearRects());

    private IAccessibilityEmbeddedConnection mAccessibilityEmbeddedConnection;

@@ -4879,14 +4882,26 @@ public final class ViewRootImpl implements ViewParent,
     */
    void updateKeepClearRectsForView(View view) {
        mKeepClearRectsTracker.updateRectsForView(view);
        mUnrestrictedKeepClearRectsTracker.updateRectsForView(view);
        mHandler.sendEmptyMessage(MSG_KEEP_CLEAR_RECTS_CHANGED);
    }

    void keepClearRectsChanged() {
        final List<Rect> rectsForWindowManager = mKeepClearRectsTracker.computeChangedRects();
        if (rectsForWindowManager != null && mView != null) {
        List<Rect> restrictedKeepClearRects = mKeepClearRectsTracker.computeChangedRects();
        List<Rect> unrestrictedKeepClearRects =
                mUnrestrictedKeepClearRectsTracker.computeChangedRects();
        if ((restrictedKeepClearRects != null || unrestrictedKeepClearRects != null)
                && mView != null) {
            if (restrictedKeepClearRects == null) {
                restrictedKeepClearRects = Collections.emptyList();
            }
            if (unrestrictedKeepClearRects == null) {
                unrestrictedKeepClearRects = Collections.emptyList();
            }

            try {
                mWindowSession.reportKeepClearAreasChanged(mWindow, rectsForWindowManager);
                mWindowSession.reportKeepClearAreasChanged(mWindow, restrictedKeepClearRects,
                        unrestrictedKeepClearRects);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
+4 −3
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.window.ClientWindowFrames;
import android.window.IOnBackInvokedCallback;

import java.util.HashMap;
import java.util.List;
import java.util.Objects;

/**
@@ -473,12 +474,12 @@ public class WindowlessWindowManager implements IWindowSession {

    @Override
    public void reportSystemGestureExclusionChanged(android.view.IWindow window,
            java.util.List<android.graphics.Rect> exclusionRects) {
            List<Rect> exclusionRects) {
    }

    @Override
    public void reportKeepClearAreasChanged(android.view.IWindow window,
            java.util.List<android.graphics.Rect> exclusionRects) {
    public void reportKeepClearAreasChanged(android.view.IWindow window, List<Rect> restrictedRects,
            List<Rect> unrestrictedRects) {
    }

    @Override
Loading