Create @RestrictedFor annotation am: 9a200dde1f
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/modules-utils/+/2966604
Change-Id: I4d5ac562d4a98b0e22e5d7bce7ef7e8931d8f58e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/java/com/android/internal/util/Preconditions.java b/java/com/android/internal/util/Preconditions.java
index d2d8220..bee0808 100644
--- a/java/com/android/internal/util/Preconditions.java
+++ b/java/com/android/internal/util/Preconditions.java
@@ -18,6 +18,7 @@
import android.annotation.IntRange;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build;
import android.text.TextUtils;
@@ -768,4 +769,17 @@
return value;
}
+
+ /**
+ * Throws an exception that guides developers to configure a {@code RavenwoodRule} when the
+ * given argument is {@code null}.
+ */
+ public static <T> @NonNull T requireNonNullViaRavenwoodRule(@Nullable T t) {
+ if (t == null) {
+ throw new IllegalStateException("This operation requires that a RavenwoodRule be "
+ + "configured to accurately define the expected test environment");
+ } else {
+ return t;
+ }
+ }
}
diff --git a/java/com/android/modules/utils/FastDataInput.java b/java/com/android/modules/utils/FastDataInput.java
index 1437f80..318382b 100644
--- a/java/com/android/modules/utils/FastDataInput.java
+++ b/java/com/android/modules/utils/FastDataInput.java
@@ -18,8 +18,6 @@
import android.annotation.NonNull;
-import dalvik.system.VMRuntime;
-
import java.io.BufferedInputStream;
import java.io.Closeable;
import java.io.DataInput;
@@ -42,8 +40,6 @@
protected static final int DEFAULT_BUFFER_SIZE = 32_768;
- protected final VMRuntime mRuntime;
-
protected final byte[] mBuffer;
protected final int mBufferCap;
@@ -58,13 +54,12 @@
private String[] mStringRefs = new String[32];
public FastDataInput(@NonNull InputStream in, int bufferSize) {
- mRuntime = VMRuntime.getRuntime();
mIn = Objects.requireNonNull(in);
if (bufferSize < 8) {
throw new IllegalArgumentException();
}
- mBuffer = (byte[]) mRuntime.newNonMovableArray(byte.class, bufferSize);
+ mBuffer = newByteArray(bufferSize);
mBufferCap = mBuffer.length;
}
@@ -92,6 +87,10 @@
mStringRefCount = 0;
}
+ public byte[] newByteArray(int bufferSize) {
+ return new byte[bufferSize];
+ }
+
/**
* Re-initializes the object for the new input.
*/
@@ -173,7 +172,7 @@
mBufferPos += len;
return res;
} else {
- final byte[] tmp = (byte[]) mRuntime.newNonMovableArray(byte.class, len + 1);
+ final byte[] tmp = newByteArray(len + 1);
readFully(tmp, 0, len);
return ModifiedUtf8.decode(tmp, new char[len], 0, len);
}
diff --git a/java/com/android/modules/utils/FastDataOutput.java b/java/com/android/modules/utils/FastDataOutput.java
index 2098c2d..ae19573 100644
--- a/java/com/android/modules/utils/FastDataOutput.java
+++ b/java/com/android/modules/utils/FastDataOutput.java
@@ -18,8 +18,6 @@
import android.annotation.NonNull;
-import dalvik.system.VMRuntime;
-
import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.DataOutput;
@@ -42,8 +40,6 @@
protected static final int DEFAULT_BUFFER_SIZE = 32_768;
- protected final VMRuntime mRuntime;
-
protected final byte[] mBuffer;
protected final int mBufferCap;
@@ -56,12 +52,11 @@
private final HashMap<String, Integer> mStringRefs = new HashMap<>();
public FastDataOutput(@NonNull OutputStream out, int bufferSize) {
- mRuntime = VMRuntime.getRuntime();
if (bufferSize < 8) {
throw new IllegalArgumentException();
}
- mBuffer = (byte[]) mRuntime.newNonMovableArray(byte.class, bufferSize);
+ mBuffer = newByteArray(bufferSize);
mBufferCap = mBuffer.length;
setOutput(out);
@@ -94,6 +89,10 @@
mStringRefs.clear();
}
+ public byte[] newByteArray(int bufferSize) {
+ return new byte[bufferSize];
+ }
+
/**
* Re-initializes the object for the new output.
*/
@@ -163,7 +162,7 @@
ModifiedUtf8.encode(mBuffer, mBufferPos, s);
mBufferPos += len;
} else {
- final byte[] tmp = (byte[]) mRuntime.newNonMovableArray(byte.class, len + 1);
+ final byte[] tmp = newByteArray(len + 1);
ModifiedUtf8.encode(tmp, 0, s);
writeShort(len);
write(tmp, 0, len);