Skip to content

Commit 23a0fed

Browse files
authored
Add nullability annotations, remove @PublicApi annotations for Storage. (#602)
* Add missing nullability annotations to Storage. * Remove redundant `@PublicApi` annotation. * Address review comments.
1 parent e7ffa75 commit 23a0fed

22 files changed

+64
-233
lines changed

firebase-storage/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
- [changed] Added validation to `StorageReference.getDownloadUrl()` and
66
`StorageReference.getMetadata()` to return an error if the reference is the
77
root of the bucket.
8+
- [changed] Added missing nullability annotations for better Kotlin interop.
9+
- [internal] Removed ``@PublicApi` annotations as they are no longer enforced
10+
and have no semantic meaning.
811

912
# 17.0.0
1013
- [internal] Updated the SDK initialization process and removed usages of

firebase-storage/firebase-storage.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ firebaseLibrary {
2121
testLab.enabled = true
2222
publishJavadoc = true
2323
publishSources = true
24-
staticAnalysis.disableKotlinInteropLint()
2524
}
2625

2726
android {

firebase-storage/src/main/java/com/google/firebase/storage/CancelException.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414

1515
package com.google.firebase.storage;
1616

17-
import com.google.firebase.annotations.PublicApi;
1817
import java.io.IOException;
1918

2019
/** Represents an internal exception that is thrown to cancel a currently running task. */
21-
@PublicApi
2220
class CancelException extends IOException {
23-
@PublicApi
21+
2422
CancelException() {
2523
super("The operation was canceled.");
2624
}

firebase-storage/src/main/java/com/google/firebase/storage/CancellableTask.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import androidx.annotation.NonNull;
1919
import com.google.android.gms.tasks.OnFailureListener;
2020
import com.google.android.gms.tasks.Task;
21-
import com.google.firebase.annotations.PublicApi;
2221
import java.util.concurrent.Executor;
2322

2423
/**
@@ -27,7 +26,6 @@
2726
* @param <StateT> the type of state this operation returns in events.
2827
*/
2928
@SuppressWarnings("unused")
30-
@PublicApi
3129
public abstract class CancellableTask<StateT> extends Task<StateT> {
3230
/**
3331
* Attempts to cancel the task. A canceled task cannot be resumed later. A canceled task calls
@@ -37,24 +35,21 @@ public abstract class CancellableTask<StateT> extends Task<StateT> {
3735
* @return true if this task was successfully canceled or is in the process of being canceled.
3836
* Returns false if the task is already completed or in a state that cannot be canceled.
3937
*/
40-
@PublicApi
4138
public abstract boolean cancel();
4239

4340
/** @return true if the task has been canceled. */
44-
@PublicApi
4541
@Override
4642
public abstract boolean isCanceled();
4743

4844
/** @return true if the task is currently running. */
49-
@PublicApi
5045
public abstract boolean isInProgress();
5146

5247
/**
5348
* Adds a listener that is called periodically while the ControllableTask executes.
5449
*
5550
* @return this Task
5651
*/
57-
@PublicApi
52+
@NonNull
5853
public abstract CancellableTask<StateT> addOnProgressListener(
5954
@NonNull OnProgressListener<? super StateT> listener);
6055

@@ -64,7 +59,7 @@ public abstract CancellableTask<StateT> addOnProgressListener(
6459
* @param executor the executor to use to call the listener
6560
* @return this Task
6661
*/
67-
@PublicApi
62+
@NonNull
6863
public abstract CancellableTask<StateT> addOnProgressListener(
6964
@NonNull Executor executor, @NonNull OnProgressListener<? super StateT> listener);
7065

@@ -75,7 +70,7 @@ public abstract CancellableTask<StateT> addOnProgressListener(
7570
* removed.
7671
* @return this Task
7772
*/
78-
@PublicApi
73+
@NonNull
7974
public abstract CancellableTask<StateT> addOnProgressListener(
8075
@NonNull Activity activity, @NonNull OnProgressListener<? super StateT> listener);
8176
}

firebase-storage/src/main/java/com/google/firebase/storage/ControllableTask.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import android.app.Activity;
1818
import androidx.annotation.NonNull;
19-
import com.google.firebase.annotations.PublicApi;
2019
import java.util.concurrent.Executor;
2120

2221
/**
@@ -26,7 +25,6 @@
2625
* @param <StateT> the type of state this operation returns in events.
2726
*/
2827
@SuppressWarnings("unused")
29-
@PublicApi
3028
public abstract class ControllableTask<StateT> extends CancellableTask<StateT> {
3129

3230
/**
@@ -35,7 +33,6 @@ public abstract class ControllableTask<StateT> extends CancellableTask<StateT> {
3533
* @return true if this task was successfully paused or is in the process of being paused. Returns
3634
* false if the task is already completed or in a state that cannot be paused.
3735
*/
38-
@PublicApi
3936
public abstract boolean pause();
4037

4138
/**
@@ -44,19 +41,17 @@ public abstract class ControllableTask<StateT> extends CancellableTask<StateT> {
4441
* @return true if the task is successfully resumed or is in the process of being resumed. Returns
4542
* false if the task is already completed or in a state that cannot be resumed.
4643
*/
47-
@PublicApi
4844
public abstract boolean resume();
4945

5046
/** @return true if the task has been paused. */
51-
@PublicApi
5247
public abstract boolean isPaused();
5348

5449
/**
5550
* Adds a listener that is called when the Task becomes paused.
5651
*
5752
* @return this Task
5853
*/
59-
@PublicApi
54+
@NonNull
6055
public abstract ControllableTask<StateT> addOnPausedListener(
6156
@NonNull OnPausedListener<? super StateT> listener);
6257

@@ -66,7 +61,7 @@ public abstract ControllableTask<StateT> addOnPausedListener(
6661
* @param executor the executor to use to call the listener
6762
* @return this Task
6863
*/
69-
@PublicApi
64+
@NonNull
7065
public abstract ControllableTask<StateT> addOnPausedListener(
7166
@NonNull Executor executor, @NonNull OnPausedListener<? super StateT> listener);
7267

@@ -77,7 +72,7 @@ public abstract ControllableTask<StateT> addOnPausedListener(
7772
* removed.
7873
* @return this Task
7974
*/
80-
@PublicApi
75+
@NonNull
8176
public abstract ControllableTask<StateT> addOnPausedListener(
8277
@NonNull Activity activity, @NonNull OnPausedListener<? super StateT> listener);
8378
}

firebase-storage/src/main/java/com/google/firebase/storage/FileDownloadTask.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import android.util.Log;
2020
import androidx.annotation.NonNull;
2121
import com.google.android.gms.common.api.Status;
22-
import com.google.firebase.annotations.PublicApi;
2322
import com.google.firebase.storage.internal.ExponentialBackoffSender;
2423
import com.google.firebase.storage.network.GetNetworkRequest;
2524
import com.google.firebase.storage.network.NetworkRequest;
@@ -31,7 +30,6 @@
3130

3231
/** A task that downloads bytes of a GCS blob to a specified File. */
3332
@SuppressWarnings("unused")
34-
@PublicApi
3533
public class FileDownloadTask extends StorageTask<FileDownloadTask.TaskSnapshot> {
3634
static final int PREFERRED_CHUNK_SIZE = 256 * 1024; // 256KB
3735
private static final String TAG = "FileDownloadTask";
@@ -262,7 +260,6 @@ private boolean processResponse(final NetworkRequest request) throws IOException
262260
}
263261

264262
@Override
265-
@PublicApi
266263
protected void onCanceled() {
267264
mSender.cancel();
268265
mException = StorageException.fromErrorStatus(Status.RESULT_CANCELED);
@@ -274,7 +271,6 @@ private boolean isValidHttpResponseCode(int code) {
274271

275272
/** Encapsulates state about the running {@link FileDownloadTask} */
276273
@SuppressWarnings("unused")
277-
@PublicApi
278274
public class TaskSnapshot extends StorageTask<FileDownloadTask.TaskSnapshot>.SnapshotBase {
279275
private final long mBytesDownloaded;
280276

@@ -284,13 +280,11 @@ public class TaskSnapshot extends StorageTask<FileDownloadTask.TaskSnapshot>.Sna
284280
}
285281

286282
/** @return the total bytes downloaded so far. */
287-
@PublicApi
288283
public long getBytesTransferred() {
289284
return mBytesDownloaded;
290285
}
291286

292287
/** @return the total bytes to upload.. */
293-
@PublicApi
294288
public long getTotalByteCount() {
295289
return FileDownloadTask.this.getTotalBytes();
296290
}

firebase-storage/src/main/java/com/google/firebase/storage/FirebaseStorage.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.google.android.gms.common.internal.Preconditions;
2424
import com.google.firebase.FirebaseApp;
2525
import com.google.firebase.FirebaseOptions;
26-
import com.google.firebase.annotations.PublicApi;
2726
import com.google.firebase.auth.internal.InternalAuthProvider;
2827
import com.google.firebase.inject.Provider;
2928
import com.google.firebase.storage.internal.Util;
@@ -40,7 +39,6 @@
4039
* {@link FirebaseApp#getInstance()}. The storage location in this case will come the JSON
4140
* configuration file downloaded from the web.
4241
*/
43-
@PublicApi
4442
public class FirebaseStorage {
4543
private static final String TAG = "FirebaseStorage";
4644
private static final String STORAGE_URI_PARSE_EXCEPTION = "The storage Uri could not be parsed.";
@@ -81,7 +79,6 @@ private static FirebaseStorage getInstanceImpl(@NonNull FirebaseApp app, @Nullab
8179
* @return a {@link FirebaseStorage} instance.
8280
*/
8381
@NonNull
84-
@PublicApi
8582
public static FirebaseStorage getInstance() {
8683
FirebaseApp app = FirebaseApp.getInstance();
8784
Preconditions.checkArgument(app != null, "You must call FirebaseApp.initialize() first.");
@@ -97,7 +94,6 @@ public static FirebaseStorage getInstance() {
9794
* @return a {@link FirebaseStorage} instance.
9895
*/
9996
@NonNull
100-
@PublicApi
10197
public static FirebaseStorage getInstance(@NonNull String url) {
10298
FirebaseApp app = FirebaseApp.getInstance();
10399
Preconditions.checkArgument(app != null, "You must call FirebaseApp.initialize() first.");
@@ -112,7 +108,6 @@ public static FirebaseStorage getInstance(@NonNull String url) {
112108
* @return a {@link FirebaseStorage} instance.
113109
*/
114110
@NonNull
115-
@PublicApi
116111
public static FirebaseStorage getInstance(@NonNull FirebaseApp app) {
117112
// noinspection ConstantConditions
118113
Preconditions.checkArgument(app != null, "Null is not a valid value for the FirebaseApp.");
@@ -140,7 +135,6 @@ public static FirebaseStorage getInstance(@NonNull FirebaseApp app) {
140135
* @return a {@link FirebaseStorage} instance.
141136
*/
142137
@NonNull
143-
@PublicApi
144138
public static FirebaseStorage getInstance(@NonNull FirebaseApp app, @NonNull String url) {
145139
// noinspection ConstantConditions
146140
Preconditions.checkArgument(app != null, "Null is not a valid value for the FirebaseApp.");
@@ -165,7 +159,6 @@ public static FirebaseStorage getInstance(@NonNull FirebaseApp app, @NonNull Str
165159
*
166160
* @return maximum time in milliseconds. Defaults to 10 minutes (600,000 milliseconds).
167161
*/
168-
@PublicApi
169162
public long getMaxDownloadRetryTimeMillis() {
170163
return sMaxDownloadRetry;
171164
}
@@ -176,7 +169,6 @@ public long getMaxDownloadRetryTimeMillis() {
176169
* @param maxTransferRetryMillis the maximum time in milliseconds. Defaults to 10 minutes (600,000
177170
* milliseconds).
178171
*/
179-
@PublicApi
180172
public void setMaxDownloadRetryTimeMillis(long maxTransferRetryMillis) {
181173
sMaxDownloadRetry = maxTransferRetryMillis;
182174
}
@@ -186,7 +178,6 @@ public void setMaxDownloadRetryTimeMillis(long maxTransferRetryMillis) {
186178
*
187179
* @return the maximum time in milliseconds. Defaults to 10 minutes (600,000 milliseconds).
188180
*/
189-
@PublicApi
190181
public long getMaxUploadRetryTimeMillis() {
191182
return sMaxUploadRetry;
192183
}
@@ -197,7 +188,6 @@ public long getMaxUploadRetryTimeMillis() {
197188
* @param maxTransferRetryMillis the maximum time in milliseconds. Defaults to 10 minutes (600,000
198189
* milliseconds).
199190
*/
200-
@PublicApi
201191
public void setMaxUploadRetryTimeMillis(long maxTransferRetryMillis) {
202192
sMaxUploadRetry = maxTransferRetryMillis;
203193
}
@@ -208,7 +198,6 @@ public void setMaxUploadRetryTimeMillis(long maxTransferRetryMillis) {
208198
*
209199
* @return the maximum time in milliseconds. Defaults to 2 minutes (120,000 milliseconds).
210200
*/
211-
@PublicApi
212201
public long getMaxOperationRetryTimeMillis() {
213202
return sMaxQueryRetry;
214203
}
@@ -220,7 +209,6 @@ public long getMaxOperationRetryTimeMillis() {
220209
* milliseconds).
221210
*/
222211
@SuppressWarnings("unused")
223-
@PublicApi
224212
public void setMaxOperationRetryTimeMillis(long maxTransferRetryMillis) {
225213
sMaxQueryRetry = maxTransferRetryMillis;
226214
}
@@ -235,7 +223,6 @@ private String getBucketName() {
235223
*
236224
* @return An instance of {@link StorageReference}.
237225
*/
238-
@PublicApi
239226
@NonNull
240227
public StorageReference getReference() {
241228
String bucketName = getBucketName();
@@ -257,7 +244,6 @@ public StorageReference getReference() {
257244
* associated with the {@link FirebaseApp} used to initialize this {@link FirebaseStorage}.
258245
*/
259246
@NonNull
260-
@PublicApi
261247
public StorageReference getReferenceFromUrl(@NonNull String fullUrl) {
262248
Preconditions.checkArgument(!TextUtils.isEmpty(fullUrl), "location must not be null or empty");
263249
String lowerCaseLocation = fullUrl.toLowerCase();
@@ -288,7 +274,6 @@ public StorageReference getReferenceFromUrl(@NonNull String fullUrl) {
288274
* @return An instance of {@link StorageReference} at the given child path.
289275
*/
290276
@NonNull
291-
@PublicApi
292277
public StorageReference getReference(@NonNull String location) {
293278
Preconditions.checkArgument(!TextUtils.isEmpty(location), "location must not be null or empty");
294279
String lowerCaseLocation = location.toLowerCase();
@@ -314,7 +299,6 @@ private StorageReference getReference(@NonNull Uri uri) {
314299

315300
/** The {@link FirebaseApp} associated with this {@link FirebaseStorage} instance. */
316301
@NonNull
317-
@PublicApi
318302
public FirebaseApp getApp() {
319303
return mApp;
320304
}

firebase-storage/src/main/java/com/google/firebase/storage/GetDownloadUrlTask.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import androidx.annotation.Nullable;
2121
import com.google.android.gms.common.internal.Preconditions;
2222
import com.google.android.gms.tasks.TaskCompletionSource;
23-
import com.google.firebase.annotations.PublicApi;
2423
import com.google.firebase.storage.internal.ExponentialBackoffSender;
2524
import com.google.firebase.storage.network.GetMetadataNetworkRequest;
2625
import com.google.firebase.storage.network.NetworkRequest;
@@ -68,7 +67,6 @@ private Uri extractDownloadUrl(JSONObject response) {
6867
}
6968

7069
@Override
71-
@PublicApi
7270
public void run() {
7371
final NetworkRequest request =
7472
new GetMetadataNetworkRequest(storageRef.getStorageUri(), storageRef.getApp());

firebase-storage/src/main/java/com/google/firebase/storage/GetMetadataTask.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import androidx.annotation.NonNull;
1919
import com.google.android.gms.common.internal.Preconditions;
2020
import com.google.android.gms.tasks.TaskCompletionSource;
21-
import com.google.firebase.annotations.PublicApi;
2221
import com.google.firebase.storage.internal.ExponentialBackoffSender;
2322
import com.google.firebase.storage.network.GetMetadataNetworkRequest;
2423
import com.google.firebase.storage.network.NetworkRequest;
@@ -55,7 +54,6 @@ class GetMetadataTask implements Runnable {
5554
}
5655

5756
@Override
58-
@PublicApi
5957
public void run() {
6058
final NetworkRequest request =
6159
new GetMetadataNetworkRequest(mStorageRef.getStorageUri(), mStorageRef.getApp());

0 commit comments

Comments
 (0)