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

Commit 73715ca6 authored by Jackal Guo's avatar Jackal Guo Committed by Android (Google) Code Review
Browse files

Merge "Add new APIs to support RegionInScreen in A11yWindowInfo"

parents 2675faee f382371d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -52435,6 +52435,7 @@ package android.view.accessibility {
    method public int getId();
    method public int getLayer();
    method public android.view.accessibility.AccessibilityWindowInfo getParent();
    method public void getRegionInScreen(@NonNull android.graphics.Region);
    method public android.view.accessibility.AccessibilityNodeInfo getRoot();
    method @Nullable public CharSequence getTitle();
    method public int getType();
+8 −7
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package android.view;

import android.graphics.Rect;
import android.graphics.Region;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
@@ -44,7 +44,7 @@ public class WindowInfo implements Parcelable {
    public IBinder parentToken;
    public IBinder activityToken;
    public boolean focused;
    public final Rect boundsInScreen = new Rect();
    public Region regionInScreen = new Region();
    public List<IBinder> childTokens;
    public CharSequence title;
    public long accessibilityIdOfAnchor = AccessibilityNodeInfo.UNDEFINED_NODE_ID;
@@ -73,7 +73,7 @@ public class WindowInfo implements Parcelable {
        window.parentToken = other.parentToken;
        window.activityToken = other.activityToken;
        window.focused = other.focused;
        window.boundsInScreen.set(other.boundsInScreen);
        window.regionInScreen.set(other.regionInScreen);
        window.title = other.title;
        window.accessibilityIdOfAnchor = other.accessibilityIdOfAnchor;
        window.inPictureInPicture = other.inPictureInPicture;
@@ -109,7 +109,7 @@ public class WindowInfo implements Parcelable {
        parcel.writeStrongBinder(parentToken);
        parcel.writeStrongBinder(activityToken);
        parcel.writeInt(focused ? 1 : 0);
        boundsInScreen.writeToParcel(parcel, flags);
        regionInScreen.writeToParcel(parcel, flags);
        parcel.writeCharSequence(title);
        parcel.writeLong(accessibilityIdOfAnchor);
        parcel.writeInt(inPictureInPicture ? 1 : 0);
@@ -132,7 +132,8 @@ public class WindowInfo implements Parcelable {
        builder.append(", type=").append(type);
        builder.append(", layer=").append(layer);
        builder.append(", token=").append(token);
        builder.append(", bounds=").append(boundsInScreen);
        builder.append(", region=").append(regionInScreen);
        builder.append(", bounds=").append(regionInScreen.getBounds());
        builder.append(", parent=").append(parentToken);
        builder.append(", focused=").append(focused);
        builder.append(", children=").append(childTokens);
@@ -151,7 +152,7 @@ public class WindowInfo implements Parcelable {
        parentToken = parcel.readStrongBinder();
        activityToken = parcel.readStrongBinder();
        focused = (parcel.readInt() == 1);
        boundsInScreen.readFromParcel(parcel);
        regionInScreen = Region.CREATOR.createFromParcel(parcel);
        title = parcel.readCharSequence();
        accessibilityIdOfAnchor = parcel.readLong();
        inPictureInPicture = (parcel.readInt() == 1);
@@ -174,7 +175,7 @@ public class WindowInfo implements Parcelable {
        parentToken = null;
        activityToken = null;
        focused = false;
        boundsInScreen.setEmpty();
        regionInScreen.setEmpty();
        if (childTokens != null) {
            childTokens.clear();
        }
+4 −0
Original line number Diff line number Diff line
@@ -622,6 +622,10 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par
    /**
     * Change type for {@link #TYPE_WINDOWS_CHANGED} event:
     * The window's bounds changed.
     * <p>
     * Starting in {@link android.os.Build.VERSION_CODES#R R}, this event implies the window's
     * region changed. It's also possible that region changed but bounds doesn't.
     * </p>
     */
    public static final int WINDOWS_CHANGE_BOUNDS = 0x00000008;

+28 −17
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@

package android.view.accessibility;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
@@ -107,7 +109,7 @@ public final class AccessibilityWindowInfo implements Parcelable {
    private int mBooleanProperties;
    private int mId = UNDEFINED_WINDOW_ID;
    private int mParentId = UNDEFINED_WINDOW_ID;
    private final Rect mBoundsInScreen = new Rect();
    private Region mRegionInScreen = new Region();
    private LongArray mChildIds;
    private CharSequence mTitle;
    private long mAnchorId = AccessibilityNodeInfo.UNDEFINED_NODE_ID;
@@ -305,23 +307,33 @@ public final class AccessibilityWindowInfo implements Parcelable {
    }

    /**
     * Gets the bounds of this window in the screen.
     * Gets the touchable region of this window in the screen.
     *
     * @param outBounds The out window bounds.
     * @param outRegion The out window region.
     */
    public void getBoundsInScreen(Rect outBounds) {
        outBounds.set(mBoundsInScreen);
    public void getRegionInScreen(@NonNull Region outRegion) {
        outRegion.set(mRegionInScreen);
    }

    /**
     * Sets the bounds of this window in the screen.
     * Sets the touchable region of this window in the screen.
     *
     * @param bounds The out window bounds.
     * @param region The window region.
     *
     * @hide
     */
    public void setBoundsInScreen(Rect bounds) {
        mBoundsInScreen.set(bounds);
    public void setRegionInScreen(Region region) {
        mRegionInScreen.set(region);
    }

    /**
     * Gets the bounds of this window in the screen. This is equivalent to get the bounds of the
     * Region from {@link #getRegionInScreen(Region)}.
     *
     * @param outBounds The out window bounds.
     */
    public void getBoundsInScreen(Rect outBounds) {
        outBounds.set(mRegionInScreen.getBounds());
    }

    /**
@@ -522,7 +534,7 @@ public final class AccessibilityWindowInfo implements Parcelable {
        parcel.writeInt(mBooleanProperties);
        parcel.writeInt(mId);
        parcel.writeInt(mParentId);
        mBoundsInScreen.writeToParcel(parcel, flags);
        mRegionInScreen.writeToParcel(parcel, flags);
        parcel.writeCharSequence(mTitle);
        parcel.writeLong(mAnchorId);

@@ -552,7 +564,7 @@ public final class AccessibilityWindowInfo implements Parcelable {
        mBooleanProperties = other.mBooleanProperties;
        mId = other.mId;
        mParentId = other.mParentId;
        mBoundsInScreen.set(other.mBoundsInScreen);
        mRegionInScreen.set(other.mRegionInScreen);
        mTitle = other.mTitle;
        mAnchorId = other.mAnchorId;

@@ -574,7 +586,7 @@ public final class AccessibilityWindowInfo implements Parcelable {
        mBooleanProperties = parcel.readInt();
        mId = parcel.readInt();
        mParentId = parcel.readInt();
        mBoundsInScreen.readFromParcel(parcel);
        mRegionInScreen = Region.CREATOR.createFromParcel(parcel);
        mTitle = parcel.readCharSequence();
        mAnchorId = parcel.readLong();

@@ -621,7 +633,8 @@ public final class AccessibilityWindowInfo implements Parcelable {
        builder.append(", id=").append(mId);
        builder.append(", type=").append(typeToString(mType));
        builder.append(", layer=").append(mLayer);
        builder.append(", bounds=").append(mBoundsInScreen);
        builder.append(", region=").append(mRegionInScreen);
        builder.append(", bounds=").append(mRegionInScreen.getBounds());
        builder.append(", focused=").append(isFocused());
        builder.append(", active=").append(isActive());
        builder.append(", pictureInPicture=").append(isInPictureInPictureMode());
@@ -661,7 +674,7 @@ public final class AccessibilityWindowInfo implements Parcelable {
        mBooleanProperties = 0;
        mId = UNDEFINED_WINDOW_ID;
        mParentId = UNDEFINED_WINDOW_ID;
        mBoundsInScreen.setEmpty();
        mRegionInScreen.setEmpty();
        mChildIds = null;
        mConnectionId = UNDEFINED_WINDOW_ID;
        mAnchorId = AccessibilityNodeInfo.UNDEFINED_NODE_ID;
@@ -716,7 +729,6 @@ public final class AccessibilityWindowInfo implements Parcelable {
        }
    }


    /**
     * Reports how this window differs from a possibly different state of the same window. The
     * argument must have the same id and type as neither of those properties may change.
@@ -739,8 +751,7 @@ public final class AccessibilityWindowInfo implements Parcelable {
        if (!TextUtils.equals(mTitle, other.mTitle)) {
            changes |= AccessibilityEvent.WINDOWS_CHANGE_TITLE;
        }

        if (!mBoundsInScreen.equals(other.mBoundsInScreen)) {
        if (!mRegionInScreen.equals(other.mRegionInScreen)) {
            changes |= AccessibilityEvent.WINDOWS_CHANGE_BOUNDS;
        }
        if (mLayer != other.mLayer) {
+3 −3
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ public class WindowInfoTest {
        assertFalse(w.focused);
        assertFalse(w.inPictureInPicture);
        assertFalse(w.hasFlagWatchOutsideTouch);
        assertTrue(w.boundsInScreen.isEmpty());
        assertTrue(w.regionInScreen.isEmpty());
    }

    @SmallTest
@@ -114,7 +114,7 @@ public class WindowInfoTest {
        equality &= w1.childTokens.equals(w2.childTokens);
        equality &= w1.parentToken == w2.parentToken;
        equality &= w1.activityToken == w2.activityToken;
        equality &= w1.boundsInScreen.equals(w2.boundsInScreen);
        equality &= w1.regionInScreen.equals(w2.regionInScreen);
        return equality;
    }

@@ -132,6 +132,6 @@ public class WindowInfoTest {
        windowInfo.focused = true;
        windowInfo.inPictureInPicture = true;
        windowInfo.hasFlagWatchOutsideTouch = true;
        windowInfo.boundsInScreen.set(0, 0, 1080, 1080);
        windowInfo.regionInScreen.set(0, 0, 1080, 1080);
    }
}
Loading