From 4c1c4ee37ed5b51beed13fcd933065145d17b48d Mon Sep 17 00:00:00 2001 From: Etienne Ruffieux Date: Fri, 28 Jan 2022 17:59:42 +0000 Subject: Making CursorWindowAllocationException public Exposing CursorWindowAllocationException to access it from Bluetooth PBAP. Tag: #feature Bug: 211851706 Test: manual Change-Id: I9a2c4217e5556f7b8ab10c3884a0d3e9b6a4fe36 --- core/api/current.txt | 4 ++++ core/java/android/database/CursorWindow.java | 5 +++++ core/java/android/database/CursorWindowAllocationException.java | 6 +++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index 922ad16c2a6e..56cf7b1fbf25 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -12953,6 +12953,10 @@ package android.database { field @NonNull public static final android.os.Parcelable.Creator CREATOR; } + public class CursorWindowAllocationException extends java.lang.RuntimeException { + ctor public CursorWindowAllocationException(@NonNull String); + } + public class CursorWrapper implements android.database.Cursor { ctor public CursorWrapper(android.database.Cursor); method public void close(); diff --git a/core/java/android/database/CursorWindow.java b/core/java/android/database/CursorWindow.java index f13c79587a28..52bba1484f1a 100644 --- a/core/java/android/database/CursorWindow.java +++ b/core/java/android/database/CursorWindow.java @@ -131,11 +131,16 @@ public class CursorWindow extends SQLiteClosable implements Parcelable { * * @param name The name of the cursor window, or null if none. * @param windowSizeBytes Size of cursor window in bytes. + * @throws IllegalArgumentException if {@code windowSizeBytes} is less than 0 + * @throws AssertionError if created window pointer is 0 *

Note: Memory is dynamically allocated as data rows are added to the * window. Depending on the amount of data stored, the actual amount of memory allocated can be * lower than specified size, but cannot exceed it. */ public CursorWindow(String name, @BytesLong long windowSizeBytes) { + if (windowSizeBytes < 0) { + throw new IllegalArgumentException("Window size cannot be less than 0"); + } mStartPos = 0; mName = name != null && name.length() != 0 ? name : ""; mWindowPtr = nativeCreate(mName, (int) windowSizeBytes); diff --git a/core/java/android/database/CursorWindowAllocationException.java b/core/java/android/database/CursorWindowAllocationException.java index 2e3227dc6788..5315c8b591ab 100644 --- a/core/java/android/database/CursorWindowAllocationException.java +++ b/core/java/android/database/CursorWindowAllocationException.java @@ -16,14 +16,14 @@ package android.database; +import android.annotation.NonNull; + /** * This exception is thrown when a CursorWindow couldn't be allocated, * most probably due to memory not being available. - * - * @hide */ public class CursorWindowAllocationException extends RuntimeException { - public CursorWindowAllocationException(String description) { + public CursorWindowAllocationException(@NonNull String description) { super(description); } } -- cgit v1.2.3-59-g8ed1b