diff options
author | Xin Li <delphij@google.com> | 2024-01-17 22:14:11 -0800 |
---|---|---|
committer | Xin Li <delphij@google.com> | 2024-01-17 22:14:11 -0800 |
commit | f5b15f0ab8bd178ac90409bc0ae1031c229e47dc (patch) | |
tree | 7103dc999393edad9ceeb61810de9f22cf5df85f | |
parent | 7e7aa1ac5dfe109339ada0af1cfa3eb54e47bb33 (diff) | |
parent | 992755010ad9999a0f8250f5a6dc14818e5ac804 (diff) | |
download | modules-utils-f5b15f0ab8bd178ac90409bc0ae1031c229e47dc.tar.gz |
Merge Android 24Q1 Release (ab/11220357)
Bug: 319669529
Merged-In: I4126d111f0003cec94d1c232e276cbc1cab8755d
Change-Id: I73fcc1c43f9f26c48e7676869997e99d89cc7e20
-rw-r--r-- | java/com/android/internal/util/Preconditions.java | 14 | ||||
-rw-r--r-- | java/com/android/modules/utils/FastDataInput.java | 13 | ||||
-rw-r--r-- | java/com/android/modules/utils/FastDataOutput.java | 13 |
3 files changed, 26 insertions, 14 deletions
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 @@ package com.android.internal.util; 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 @@ public class Preconditions { 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 @@ package com.android.modules.utils; import android.annotation.NonNull; -import dalvik.system.VMRuntime; - import java.io.BufferedInputStream; import java.io.Closeable; import java.io.DataInput; @@ -42,8 +40,6 @@ public class FastDataInput implements DataInput, Closeable { 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 @@ public class FastDataInput implements DataInput, Closeable { 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 @@ public class FastDataInput implements DataInput, Closeable { mStringRefCount = 0; } + public byte[] newByteArray(int bufferSize) { + return new byte[bufferSize]; + } + /** * Re-initializes the object for the new input. */ @@ -173,7 +172,7 @@ public class FastDataInput implements DataInput, Closeable { 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 @@ package com.android.modules.utils; import android.annotation.NonNull; -import dalvik.system.VMRuntime; - import java.io.BufferedOutputStream; import java.io.Closeable; import java.io.DataOutput; @@ -42,8 +40,6 @@ public class FastDataOutput implements DataOutput, Flushable, Closeable { 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 @@ public class FastDataOutput implements DataOutput, Flushable, Closeable { 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 @@ public class FastDataOutput implements DataOutput, Flushable, Closeable { mStringRefs.clear(); } + public byte[] newByteArray(int bufferSize) { + return new byte[bufferSize]; + } + /** * Re-initializes the object for the new output. */ @@ -163,7 +162,7 @@ public class FastDataOutput implements DataOutput, Flushable, Closeable { 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); |