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

Commit bce590e3 authored by Garfield Tan's avatar Garfield Tan Committed by Android (Google) Code Review
Browse files

Merge "Add argument checks in setScale and setCrop" into tm-dev

parents 15de8ff0 a9d72c8a
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.