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

Commit a9d72c8a authored by Garfield Tan's avatar Garfield Tan
Browse files

Add argument checks in setScale and setCrop

They are now public API, so they should perform the same checks as in
respective calls with ASurfaceTransaction.

Bug: 210837722
Test: atest SurfaceControlTest
Change-Id: I1f17f8402dc116a419189f31faf351ffa967ecda
parent f594db70
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import android.util.proto.ProtoOutputStream;
import android.view.Surface.OutOfResourcesException;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
import com.android.internal.util.VirtualRefBasePtr;

import dalvik.system.CloseGuard;
@@ -2961,6 +2962,8 @@ public final class SurfaceControl implements Parcelable {
        @NonNull
        public Transaction setScale(@NonNull SurfaceControl sc, float scaleX, float scaleY) {
            checkPreconditions(sc);
            Preconditions.checkArgument(scaleX >= 0, "Negative value passed in for scaleX");
            Preconditions.checkArgument(scaleY >= 0, "Negative value passed in for scaleY");
            nativeSetScale(mNativeObject, sc.mNativeObject, scaleX, scaleY);
            return this;
        }
@@ -3205,6 +3208,7 @@ public final class SurfaceControl implements Parcelable {
        public @NonNull Transaction setCrop(@NonNull SurfaceControl sc, @Nullable Rect crop) {
            checkPreconditions(sc);
            if (crop != null) {
                Preconditions.checkArgument(crop.isValid(), "Crop isn't valid.");
                nativeSetWindowCrop(mNativeObject, sc.mNativeObject,
                        crop.left, crop.top, crop.right, crop.bottom);
            } else {
+8 −0
Original line number Diff line number Diff line
@@ -290,6 +290,14 @@ public final class Rect implements Parcelable {
        return left >= right || top >= bottom;
    }

    /**
     * @return {@code true} if the rectangle is valid (left <= right and top <= bottom).
     * @hide
     */
    public boolean isValid() {
        return left <= right && top <= bottom;
    }

    /**
     * @return the rectangle's width. This does not check for a valid rectangle
     * (i.e. left <= right) so the result may be negative.