Add @IntRange to Room's setAutoCloseTimeout()
Room's auto close timeout value must be zero or greater, by annotation the parameter with @IntRange we allow Lint to verify the value passed conforms to the requirement.
Bug: 177294504
Test: n/a
Relnote: Add @IntRange to setAutoCloseTimeout timeout parameter to statically check that is must greater than or equal to zero.
Change-Id: I33d5ecb4aa500c96cb846cafaffe1484bce0146d
diff --git a/room/runtime/api/current.txt b/room/runtime/api/current.txt
index 460a85c..d9b5519 100644
--- a/room/runtime/api/current.txt
+++ b/room/runtime/api/current.txt
@@ -86,7 +86,7 @@
method public androidx.room.RoomDatabase.Builder<T!> fallbackToDestructiveMigrationFrom(int...);
method public androidx.room.RoomDatabase.Builder<T!> fallbackToDestructiveMigrationOnDowngrade();
method public androidx.room.RoomDatabase.Builder<T!> openHelperFactory(androidx.sqlite.db.SupportSQLiteOpenHelper.Factory?);
- method public androidx.room.RoomDatabase.Builder<T!> setAutoCloseTimeout(long, java.util.concurrent.TimeUnit);
+ method public androidx.room.RoomDatabase.Builder<T!> setAutoCloseTimeout(@IntRange(from=0) long, java.util.concurrent.TimeUnit);
method public androidx.room.RoomDatabase.Builder<T!> setJournalMode(androidx.room.RoomDatabase.JournalMode);
method public androidx.room.RoomDatabase.Builder<T!> setQueryCallback(androidx.room.RoomDatabase.QueryCallback, java.util.concurrent.Executor);
method public androidx.room.RoomDatabase.Builder<T!> setQueryExecutor(java.util.concurrent.Executor);
diff --git a/room/runtime/api/public_plus_experimental_current.txt b/room/runtime/api/public_plus_experimental_current.txt
index 5813624..d0cfe70 100644
--- a/room/runtime/api/public_plus_experimental_current.txt
+++ b/room/runtime/api/public_plus_experimental_current.txt
@@ -87,7 +87,7 @@
method public androidx.room.RoomDatabase.Builder<T!> fallbackToDestructiveMigrationFrom(int...);
method public androidx.room.RoomDatabase.Builder<T!> fallbackToDestructiveMigrationOnDowngrade();
method public androidx.room.RoomDatabase.Builder<T!> openHelperFactory(androidx.sqlite.db.SupportSQLiteOpenHelper.Factory?);
- method public androidx.room.RoomDatabase.Builder<T!> setAutoCloseTimeout(long, java.util.concurrent.TimeUnit);
+ method public androidx.room.RoomDatabase.Builder<T!> setAutoCloseTimeout(@IntRange(from=0) long, java.util.concurrent.TimeUnit);
method public androidx.room.RoomDatabase.Builder<T!> setJournalMode(androidx.room.RoomDatabase.JournalMode);
method public androidx.room.RoomDatabase.Builder<T!> setQueryCallback(androidx.room.RoomDatabase.QueryCallback, java.util.concurrent.Executor);
method public androidx.room.RoomDatabase.Builder<T!> setQueryExecutor(java.util.concurrent.Executor);
diff --git a/room/runtime/api/restricted_current.txt b/room/runtime/api/restricted_current.txt
index 31ff929..0db4e83 100644
--- a/room/runtime/api/restricted_current.txt
+++ b/room/runtime/api/restricted_current.txt
@@ -129,7 +129,7 @@
method public androidx.room.RoomDatabase.Builder<T!> fallbackToDestructiveMigrationFrom(int...);
method public androidx.room.RoomDatabase.Builder<T!> fallbackToDestructiveMigrationOnDowngrade();
method public androidx.room.RoomDatabase.Builder<T!> openHelperFactory(androidx.sqlite.db.SupportSQLiteOpenHelper.Factory?);
- method public androidx.room.RoomDatabase.Builder<T!> setAutoCloseTimeout(long, java.util.concurrent.TimeUnit);
+ method public androidx.room.RoomDatabase.Builder<T!> setAutoCloseTimeout(@IntRange(from=0) long, java.util.concurrent.TimeUnit);
method public androidx.room.RoomDatabase.Builder<T!> setJournalMode(androidx.room.RoomDatabase.JournalMode);
method public androidx.room.RoomDatabase.Builder<T!> setQueryCallback(androidx.room.RoomDatabase.QueryCallback, java.util.concurrent.Executor);
method public androidx.room.RoomDatabase.Builder<T!> setQueryExecutor(java.util.concurrent.Executor);
diff --git a/room/runtime/src/main/java/androidx/room/RoomDatabase.java b/room/runtime/src/main/java/androidx/room/RoomDatabase.java
index d76e1c1..9b652bf 100644
--- a/room/runtime/src/main/java/androidx/room/RoomDatabase.java
+++ b/room/runtime/src/main/java/androidx/room/RoomDatabase.java
@@ -26,6 +26,7 @@
import android.util.Log;
import androidx.annotation.CallSuper;
+import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
@@ -1226,7 +1227,7 @@
* {@link RoomDatabase.Builder#build()}.
*
* @param autoCloseTimeout the amount of time after the last usage before closing the
- * database
+ * database. Must greater or equal to zero.
* @param autoCloseTimeUnit the timeunit for autoCloseTimeout.
* @return This {@link Builder} instance
*/
@@ -1234,8 +1235,8 @@
@SuppressWarnings("MissingGetterMatchingBuilder")
@ExperimentalRoomApi // When experimental is removed, add these parameters to
// DatabaseConfiguration
- public Builder<T> setAutoCloseTimeout(long autoCloseTimeout,
- @NonNull TimeUnit autoCloseTimeUnit) {
+ public Builder<T> setAutoCloseTimeout(
+ @IntRange(from = 0) long autoCloseTimeout, @NonNull TimeUnit autoCloseTimeUnit) {
if (autoCloseTimeout < 0) {
throw new IllegalArgumentException("autoCloseTimeout must be >= 0");
}