Merge "Add argument checks in setScale and setCrop" into tm-dev am: bce590e356
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17127507 Change-Id: I3eaec32a0f5b7569636ec09308284adee89daa91
This commit is contained in:
@@ -64,6 +64,7 @@ import android.util.proto.ProtoOutputStream;
|
|||||||
import android.view.Surface.OutOfResourcesException;
|
import android.view.Surface.OutOfResourcesException;
|
||||||
|
|
||||||
import com.android.internal.annotations.GuardedBy;
|
import com.android.internal.annotations.GuardedBy;
|
||||||
|
import com.android.internal.util.Preconditions;
|
||||||
import com.android.internal.util.VirtualRefBasePtr;
|
import com.android.internal.util.VirtualRefBasePtr;
|
||||||
|
|
||||||
import dalvik.system.CloseGuard;
|
import dalvik.system.CloseGuard;
|
||||||
@@ -2961,6 +2962,8 @@ public final class SurfaceControl implements Parcelable {
|
|||||||
@NonNull
|
@NonNull
|
||||||
public Transaction setScale(@NonNull SurfaceControl sc, float scaleX, float scaleY) {
|
public Transaction setScale(@NonNull SurfaceControl sc, float scaleX, float scaleY) {
|
||||||
checkPreconditions(sc);
|
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);
|
nativeSetScale(mNativeObject, sc.mNativeObject, scaleX, scaleY);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -3205,6 +3208,7 @@ public final class SurfaceControl implements Parcelable {
|
|||||||
public @NonNull Transaction setCrop(@NonNull SurfaceControl sc, @Nullable Rect crop) {
|
public @NonNull Transaction setCrop(@NonNull SurfaceControl sc, @Nullable Rect crop) {
|
||||||
checkPreconditions(sc);
|
checkPreconditions(sc);
|
||||||
if (crop != null) {
|
if (crop != null) {
|
||||||
|
Preconditions.checkArgument(crop.isValid(), "Crop isn't valid.");
|
||||||
nativeSetWindowCrop(mNativeObject, sc.mNativeObject,
|
nativeSetWindowCrop(mNativeObject, sc.mNativeObject,
|
||||||
crop.left, crop.top, crop.right, crop.bottom);
|
crop.left, crop.top, crop.right, crop.bottom);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -290,6 +290,14 @@ public final class Rect implements Parcelable {
|
|||||||
return left >= right || top >= bottom;
|
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
|
* @return the rectangle's width. This does not check for a valid rectangle
|
||||||
* (i.e. left <= right) so the result may be negative.
|
* (i.e. left <= right) so the result may be negative.
|
||||||
|
|||||||
Reference in New Issue
Block a user