Skip to content

Add nullability annotations, remove @PublicApi annotations for Storage. #602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions firebase-storage/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- [changed] Added validation to `StorageReference.getDownloadUrl()` and
`StorageReference.getMetadata()` to return an error if the reference is the
root of the bucket.
- [changed] Added missing nullability annotations for better Kotlin interop.
- [internal] Removed ``@PublicApi` annotations as they are no longer enforced
and have no semantic meaning.

# 17.0.0
- [internal] Updated the SDK initialization process and removed usages of
Expand Down
1 change: 0 additions & 1 deletion firebase-storage/firebase-storage.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ firebaseLibrary {
testLab.enabled = true
publishJavadoc = true
publishSources = true
staticAnalysis.disableKotlinInteropLint()
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@

package com.google.firebase.storage;

import com.google.firebase.annotations.PublicApi;
import java.io.IOException;

/** Represents an internal exception that is thrown to cancel a currently running task. */
@PublicApi
class CancelException extends IOException {
@PublicApi

CancelException() {
super("The operation was canceled.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import androidx.annotation.NonNull;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.annotations.PublicApi;
import java.util.concurrent.Executor;

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

/** @return true if the task has been canceled. */
@PublicApi
@Override
public abstract boolean isCanceled();

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

/**
* Adds a listener that is called periodically while the ControllableTask executes.
*
* @return this Task
*/
@PublicApi
@NonNull
public abstract CancellableTask<StateT> addOnProgressListener(
@NonNull OnProgressListener<? super StateT> listener);

Expand All @@ -64,7 +59,7 @@ public abstract CancellableTask<StateT> addOnProgressListener(
* @param executor the executor to use to call the listener
* @return this Task
*/
@PublicApi
@NonNull
public abstract CancellableTask<StateT> addOnProgressListener(
@NonNull Executor executor, @NonNull OnProgressListener<? super StateT> listener);

Expand All @@ -75,7 +70,7 @@ public abstract CancellableTask<StateT> addOnProgressListener(
* removed.
* @return this Task
*/
@PublicApi
@NonNull
public abstract CancellableTask<StateT> addOnProgressListener(
@NonNull Activity activity, @NonNull OnProgressListener<? super StateT> listener);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import android.app.Activity;
import androidx.annotation.NonNull;
import com.google.firebase.annotations.PublicApi;
import java.util.concurrent.Executor;

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

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

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

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

/**
* Adds a listener that is called when the Task becomes paused.
*
* @return this Task
*/
@PublicApi
@NonNull
public abstract ControllableTask<StateT> addOnPausedListener(
@NonNull OnPausedListener<? super StateT> listener);

Expand All @@ -66,7 +61,7 @@ public abstract ControllableTask<StateT> addOnPausedListener(
* @param executor the executor to use to call the listener
* @return this Task
*/
@PublicApi
@NonNull
public abstract ControllableTask<StateT> addOnPausedListener(
@NonNull Executor executor, @NonNull OnPausedListener<? super StateT> listener);

Expand All @@ -77,7 +72,7 @@ public abstract ControllableTask<StateT> addOnPausedListener(
* removed.
* @return this Task
*/
@PublicApi
@NonNull
public abstract ControllableTask<StateT> addOnPausedListener(
@NonNull Activity activity, @NonNull OnPausedListener<? super StateT> listener);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.util.Log;
import androidx.annotation.NonNull;
import com.google.android.gms.common.api.Status;
import com.google.firebase.annotations.PublicApi;
import com.google.firebase.storage.internal.ExponentialBackoffSender;
import com.google.firebase.storage.network.GetNetworkRequest;
import com.google.firebase.storage.network.NetworkRequest;
Expand All @@ -31,7 +30,6 @@

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

@Override
@PublicApi
protected void onCanceled() {
mSender.cancel();
mException = StorageException.fromErrorStatus(Status.RESULT_CANCELED);
Expand All @@ -274,7 +271,6 @@ private boolean isValidHttpResponseCode(int code) {

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

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

/** @return the total bytes downloaded so far. */
@PublicApi
public long getBytesTransferred() {
return mBytesDownloaded;
}

/** @return the total bytes to upload.. */
@PublicApi
public long getTotalByteCount() {
return FileDownloadTask.this.getTotalBytes();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.android.gms.common.internal.Preconditions;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.annotations.PublicApi;
import com.google.firebase.auth.internal.InternalAuthProvider;
import com.google.firebase.inject.Provider;
import com.google.firebase.storage.internal.Util;
Expand All @@ -40,7 +39,6 @@
* {@link FirebaseApp#getInstance()}. The storage location in this case will come the JSON
* configuration file downloaded from the web.
*/
@PublicApi
public class FirebaseStorage {
private static final String TAG = "FirebaseStorage";
private static final String STORAGE_URI_PARSE_EXCEPTION = "The storage Uri could not be parsed.";
Expand Down Expand Up @@ -81,7 +79,6 @@ private static FirebaseStorage getInstanceImpl(@NonNull FirebaseApp app, @Nullab
* @return a {@link FirebaseStorage} instance.
*/
@NonNull
@PublicApi
public static FirebaseStorage getInstance() {
FirebaseApp app = FirebaseApp.getInstance();
Preconditions.checkArgument(app != null, "You must call FirebaseApp.initialize() first.");
Expand All @@ -97,7 +94,6 @@ public static FirebaseStorage getInstance() {
* @return a {@link FirebaseStorage} instance.
*/
@NonNull
@PublicApi
public static FirebaseStorage getInstance(@NonNull String url) {
FirebaseApp app = FirebaseApp.getInstance();
Preconditions.checkArgument(app != null, "You must call FirebaseApp.initialize() first.");
Expand All @@ -112,7 +108,6 @@ public static FirebaseStorage getInstance(@NonNull String url) {
* @return a {@link FirebaseStorage} instance.
*/
@NonNull
@PublicApi
public static FirebaseStorage getInstance(@NonNull FirebaseApp app) {
// noinspection ConstantConditions
Preconditions.checkArgument(app != null, "Null is not a valid value for the FirebaseApp.");
Expand Down Expand Up @@ -140,7 +135,6 @@ public static FirebaseStorage getInstance(@NonNull FirebaseApp app) {
* @return a {@link FirebaseStorage} instance.
*/
@NonNull
@PublicApi
public static FirebaseStorage getInstance(@NonNull FirebaseApp app, @NonNull String url) {
// noinspection ConstantConditions
Preconditions.checkArgument(app != null, "Null is not a valid value for the FirebaseApp.");
Expand All @@ -165,7 +159,6 @@ public static FirebaseStorage getInstance(@NonNull FirebaseApp app, @NonNull Str
*
* @return maximum time in milliseconds. Defaults to 10 minutes (600,000 milliseconds).
*/
@PublicApi
public long getMaxDownloadRetryTimeMillis() {
return sMaxDownloadRetry;
}
Expand All @@ -176,7 +169,6 @@ public long getMaxDownloadRetryTimeMillis() {
* @param maxTransferRetryMillis the maximum time in milliseconds. Defaults to 10 minutes (600,000
* milliseconds).
*/
@PublicApi
public void setMaxDownloadRetryTimeMillis(long maxTransferRetryMillis) {
sMaxDownloadRetry = maxTransferRetryMillis;
}
Expand All @@ -186,7 +178,6 @@ public void setMaxDownloadRetryTimeMillis(long maxTransferRetryMillis) {
*
* @return the maximum time in milliseconds. Defaults to 10 minutes (600,000 milliseconds).
*/
@PublicApi
public long getMaxUploadRetryTimeMillis() {
return sMaxUploadRetry;
}
Expand All @@ -197,7 +188,6 @@ public long getMaxUploadRetryTimeMillis() {
* @param maxTransferRetryMillis the maximum time in milliseconds. Defaults to 10 minutes (600,000
* milliseconds).
*/
@PublicApi
public void setMaxUploadRetryTimeMillis(long maxTransferRetryMillis) {
sMaxUploadRetry = maxTransferRetryMillis;
}
Expand All @@ -208,7 +198,6 @@ public void setMaxUploadRetryTimeMillis(long maxTransferRetryMillis) {
*
* @return the maximum time in milliseconds. Defaults to 2 minutes (120,000 milliseconds).
*/
@PublicApi
public long getMaxOperationRetryTimeMillis() {
return sMaxQueryRetry;
}
Expand All @@ -220,7 +209,6 @@ public long getMaxOperationRetryTimeMillis() {
* milliseconds).
*/
@SuppressWarnings("unused")
@PublicApi
public void setMaxOperationRetryTimeMillis(long maxTransferRetryMillis) {
sMaxQueryRetry = maxTransferRetryMillis;
}
Expand All @@ -235,7 +223,6 @@ private String getBucketName() {
*
* @return An instance of {@link StorageReference}.
*/
@PublicApi
@NonNull
public StorageReference getReference() {
String bucketName = getBucketName();
Expand All @@ -257,7 +244,6 @@ public StorageReference getReference() {
* associated with the {@link FirebaseApp} used to initialize this {@link FirebaseStorage}.
*/
@NonNull
@PublicApi
public StorageReference getReferenceFromUrl(@NonNull String fullUrl) {
Preconditions.checkArgument(!TextUtils.isEmpty(fullUrl), "location must not be null or empty");
String lowerCaseLocation = fullUrl.toLowerCase();
Expand Down Expand Up @@ -288,7 +274,6 @@ public StorageReference getReferenceFromUrl(@NonNull String fullUrl) {
* @return An instance of {@link StorageReference} at the given child path.
*/
@NonNull
@PublicApi
public StorageReference getReference(@NonNull String location) {
Preconditions.checkArgument(!TextUtils.isEmpty(location), "location must not be null or empty");
String lowerCaseLocation = location.toLowerCase();
Expand All @@ -314,7 +299,6 @@ private StorageReference getReference(@NonNull Uri uri) {

/** The {@link FirebaseApp} associated with this {@link FirebaseStorage} instance. */
@NonNull
@PublicApi
public FirebaseApp getApp() {
return mApp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import androidx.annotation.Nullable;
import com.google.android.gms.common.internal.Preconditions;
import com.google.android.gms.tasks.TaskCompletionSource;
import com.google.firebase.annotations.PublicApi;
import com.google.firebase.storage.internal.ExponentialBackoffSender;
import com.google.firebase.storage.network.GetMetadataNetworkRequest;
import com.google.firebase.storage.network.NetworkRequest;
Expand Down Expand Up @@ -68,7 +67,6 @@ private Uri extractDownloadUrl(JSONObject response) {
}

@Override
@PublicApi
public void run() {
final NetworkRequest request =
new GetMetadataNetworkRequest(storageRef.getStorageUri(), storageRef.getApp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import androidx.annotation.NonNull;
import com.google.android.gms.common.internal.Preconditions;
import com.google.android.gms.tasks.TaskCompletionSource;
import com.google.firebase.annotations.PublicApi;
import com.google.firebase.storage.internal.ExponentialBackoffSender;
import com.google.firebase.storage.network.GetMetadataNetworkRequest;
import com.google.firebase.storage.network.NetworkRequest;
Expand Down Expand Up @@ -55,7 +54,6 @@ class GetMetadataTask implements Runnable {
}

@Override
@PublicApi
public void run() {
final NetworkRequest request =
new GetMetadataNetworkRequest(mStorageRef.getStorageUri(), mStorageRef.getApp());
Expand Down
Loading