Skip to content

Add proper nullability annotations to firebase-common. #599

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 1 commit into from
Jul 11, 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
1 change: 0 additions & 1 deletion firebase-common/firebase-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ plugins {
firebaseLibrary {
testLab.enabled = true
publishSources = true
staticAnalysis.disableKotlinInteropLint()
}

android {
Expand Down
18 changes: 3 additions & 15 deletions firebase-common/src/main/java/com/google/firebase/FirebaseApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import com.google.android.gms.common.internal.Preconditions;
import com.google.android.gms.common.util.PlatformVersion;
import com.google.android.gms.common.util.ProcessUtils;
import com.google.firebase.annotations.PublicApi;
import com.google.firebase.components.Component;
import com.google.firebase.components.ComponentDiscovery;
import com.google.firebase.components.ComponentRegistrar;
Expand Down Expand Up @@ -85,12 +84,11 @@
* Use of Firebase in processes other than the main process is not supported and will likely cause
* problems related to resource contention.
*/
@PublicApi
public class FirebaseApp {

private static final String LOG_TAG = "FirebaseApp";

public static final String DEFAULT_APP_NAME = "[DEFAULT]";
public static final @NonNull String DEFAULT_APP_NAME = "[DEFAULT]";

private static final Object LOCK = new Object();

Expand Down Expand Up @@ -121,23 +119,20 @@ public class FirebaseApp {

/** Returns the application {@link Context}. */
@NonNull
@PublicApi
public Context getApplicationContext() {
checkNotDeleted();
return applicationContext;
}

/** Returns the unique name of this app. */
@NonNull
@PublicApi
public String getName() {
checkNotDeleted();
return name;
}

/** Returns the specified {@link FirebaseOptions}. */
@NonNull
@PublicApi
public FirebaseOptions getOptions() {
checkNotDeleted();
return options;
Expand All @@ -162,8 +157,8 @@ public String toString() {
}

/** Returns a mutable list of all FirebaseApps. */
@PublicApi
public static List<FirebaseApp> getApps(Context context) {
@NonNull
public static List<FirebaseApp> getApps(@NonNull Context context) {
synchronized (LOCK) {
return new ArrayList<>(INSTANCES.values());
}
Expand All @@ -175,7 +170,6 @@ public static List<FirebaseApp> getApps(Context context) {
* @throws IllegalStateException if the default app was not initialized.
*/
@NonNull
@PublicApi
public static FirebaseApp getInstance() {
synchronized (LOCK) {
FirebaseApp defaultApp = INSTANCES.get(DEFAULT_APP_NAME);
Expand All @@ -199,7 +193,6 @@ public static FirebaseApp getInstance() {
* #initializeApp(Context, FirebaseOptions, String)}.
*/
@NonNull
@PublicApi
public static FirebaseApp getInstance(@NonNull String name) {
synchronized (LOCK) {
FirebaseApp firebaseApp = INSTANCES.get(normalize(name));
Expand Down Expand Up @@ -239,7 +232,6 @@ public static FirebaseApp getInstance(@NonNull String name) {
* keys are present in string resources. Returns null otherwise.
*/
@Nullable
@PublicApi
public static FirebaseApp initializeApp(@NonNull Context context) {
synchronized (LOCK) {
if (INSTANCES.containsKey(DEFAULT_APP_NAME)) {
Expand Down Expand Up @@ -267,7 +259,6 @@ public static FirebaseApp initializeApp(@NonNull Context context) {
* initialization that way is the expected situation.
*/
@NonNull
@PublicApi
public static FirebaseApp initializeApp(
@NonNull Context context, @NonNull FirebaseOptions options) {
return initializeApp(context, options, DEFAULT_APP_NAME);
Expand All @@ -284,7 +275,6 @@ public static FirebaseApp initializeApp(
* @return an instance of {@link FirebaseApp}
*/
@NonNull
@PublicApi
public static FirebaseApp initializeApp(
@NonNull Context context, @NonNull FirebaseOptions options, @NonNull String name) {
GlobalBackgroundStateListener.ensureBackgroundStateListenerRegistered(context);
Expand Down Expand Up @@ -319,7 +309,6 @@ public static FirebaseApp initializeApp(
*
* @hide
*/
@PublicApi
public void delete() {
boolean valueChanged = deleted.compareAndSet(false /* expected */, true);
if (!valueChanged) {
Expand Down Expand Up @@ -348,7 +337,6 @@ public <T> T get(Class<T> anInterface) {
* If set to true it indicates that Firebase should close database connections automatically when
* the app is in the background. Disabled by default.
*/
@PublicApi
public void setAutomaticResourceManagementEnabled(boolean enabled) {
checkNotDeleted();
boolean updated =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
package com.google.firebase;

import androidx.annotation.NonNull;
import com.google.firebase.annotations.PublicApi;

/**
* Exception thrown when a request to a Firebase service has failed due to a network error. Inspect
* the device's network connectivity state or retry later to resolve.
*/
@PublicApi
public class FirebaseNetworkException extends FirebaseException {

@PublicApi
public FirebaseNetworkException(@NonNull String detailMessage) {
super(detailMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
import com.google.android.gms.common.internal.Objects;
import com.google.android.gms.common.internal.Preconditions;
import com.google.android.gms.common.internal.StringResourceValueReader;
import com.google.firebase.annotations.PublicApi;

/** Configurable Firebase options. */
@PublicApi
public final class FirebaseOptions {

// TODO: deprecate and remove it once we can fetch these from Remote Config.
Expand All @@ -50,7 +48,6 @@ public final class FirebaseOptions {
private final String projectId;

/** Builder for constructing FirebaseOptions. */
@PublicApi
public static final class Builder {
private String apiKey;
private String applicationId;
Expand All @@ -61,7 +58,6 @@ public static final class Builder {
private String projectId;

/** Constructs an empty builder. */
@PublicApi
public Builder() {}

/**
Expand All @@ -70,8 +66,7 @@ public Builder() {}
* <p>The new builder is not backed by this objects values, that is changes made to the new
* builder don't change the values of the origin object.
*/
@PublicApi
public Builder(FirebaseOptions options) {
public Builder(@NonNull FirebaseOptions options) {
applicationId = options.applicationId;
apiKey = options.apiKey;
databaseUrl = options.databaseUrl;
Expand All @@ -81,51 +76,52 @@ public Builder(FirebaseOptions options) {
projectId = options.projectId;
}

@PublicApi
@NonNull
public Builder setApiKey(@NonNull String apiKey) {
this.apiKey = checkNotEmpty(apiKey, "ApiKey must be set.");
return this;
}

@PublicApi
@NonNull
public Builder setApplicationId(@NonNull String applicationId) {
this.applicationId = checkNotEmpty(applicationId, "ApplicationId must be set.");
return this;
}

@PublicApi
@NonNull
public Builder setDatabaseUrl(@Nullable String databaseUrl) {
this.databaseUrl = databaseUrl;
return this;
}

/** @hide */
// TODO: unhide once an API (AppInvite) starts reading it.
@NonNull
@KeepForSdk
public Builder setGaTrackingId(@Nullable String gaTrackingId) {
this.gaTrackingId = gaTrackingId;
return this;
}

@PublicApi
@NonNull
public Builder setGcmSenderId(@Nullable String gcmSenderId) {
this.gcmSenderId = gcmSenderId;
return this;
}

@PublicApi
@NonNull
public Builder setStorageBucket(@Nullable String storageBucket) {
this.storageBucket = storageBucket;
return this;
}

@PublicApi
@NonNull
public Builder setProjectId(@Nullable String projectId) {
this.projectId = projectId;
return this;
}

@PublicApi
@NonNull
public FirebaseOptions build() {
return new FirebaseOptions(
applicationId, apiKey, databaseUrl, gaTrackingId, gcmSenderId, storageBucket, projectId);
Expand Down Expand Up @@ -155,8 +151,8 @@ private FirebaseOptions(
*
* @return The populated options or null if applicationId is missing from resources.
*/
@PublicApi
public static FirebaseOptions fromResource(Context context) {
@Nullable
public static FirebaseOptions fromResource(@NonNull Context context) {
StringResourceValueReader reader = new StringResourceValueReader(context);
String applicationId = reader.getString(APP_ID_RESOURCE_NAME);
if (TextUtils.isEmpty(applicationId)) {
Expand All @@ -176,19 +172,19 @@ public static FirebaseOptions fromResource(Context context) {
* API key used for authenticating requests from your app, e.g.
* AIzaSyDdVgKwhZl0sTTTLZ7iTmt1r3N2cJLnaDk, used to identify your app to Google servers.
*/
@PublicApi
@NonNull
public String getApiKey() {
return apiKey;
}

/** The Google App ID that is used to uniquely identify an instance of an app. */
@PublicApi
@NonNull
public String getApplicationId() {
return applicationId;
}

/** The database root URL, e.g. http://abc-xyz-123.firebaseio.com. */
@PublicApi
@Nullable
public String getDatabaseUrl() {
return databaseUrl;
}
Expand All @@ -199,6 +195,7 @@ public String getDatabaseUrl() {
* @hide
*/
// TODO: unhide once an API (AppInvite) starts reading it.
@Nullable
@KeepForSdk
public String getGaTrackingId() {
return gaTrackingId;
Expand All @@ -208,19 +205,19 @@ public String getGaTrackingId() {
* The Project Number from the Google Developer's console, for example 012345678901, used to
* configure Google Cloud Messaging.
*/
@PublicApi
@Nullable
public String getGcmSenderId() {
return gcmSenderId;
}

/** The Google Cloud Storage bucket name, e.g. abc-xyz-123.storage.firebase.com. */
@PublicApi
@Nullable
public String getStorageBucket() {
return storageBucket;
}

/** The Google Cloud project ID, e.g. my-project-1234 */
@PublicApi
@Nullable
public String getProjectId() {
return projectId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@

package com.google.firebase;

import com.google.firebase.annotations.PublicApi;
import androidx.annotation.NonNull;

/**
* Exception thrown when a request to a Firebase service has been blocked due to having received too
* many consecutive requests from the same device. Retry the request later to resolve.
*/
@PublicApi
public class FirebaseTooManyRequestsException extends FirebaseException {

@PublicApi
public FirebaseTooManyRequestsException(String message) {
public FirebaseTooManyRequestsException(@NonNull String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
// limitations under the License.

/** @hide */
package com.google.firebase.annotations;
package com.google.firebase.annotations;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/** @hide */
package com.google.firebase.internal;
Loading