-
Notifications
You must be signed in to change notification settings - Fork 617
Unified emulator settings for Database #1672
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
Changes from 2 commits
9ef8a4b
9d4be7d
1ca25d4
f39c11f
0f931bb
fb262d3
2762764
24b8f3a
4dd3c23
f7e2832
4ef9919
a2a4cd6
4e1373f
7f173e0
6d1e179
2d67b78
8a51a73
b072f54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
version=19.3.1 | ||
version=19.4.0 | ||
latestReleasedVersion=19.3.0 | ||
android.enableUnitTestBinaryResources=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,6 @@ | |
|
||
package com.google.firebase; | ||
|
||
import static com.google.android.gms.common.util.Base64Utils.encodeUrlSafeNoPadding; | ||
|
||
import android.annotation.TargetApi; | ||
import android.app.Application; | ||
import android.content.BroadcastReceiver; | ||
|
@@ -27,11 +25,13 @@ | |
import android.os.Looper; | ||
import android.text.TextUtils; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.annotation.VisibleForTesting; | ||
import androidx.collection.ArrayMap; | ||
import androidx.core.os.UserManagerCompat; | ||
|
||
import com.google.android.gms.common.annotation.KeepForSdk; | ||
import com.google.android.gms.common.api.internal.BackgroundDetector; | ||
import com.google.android.gms.common.internal.Objects; | ||
|
@@ -44,12 +44,14 @@ | |
import com.google.firebase.components.ComponentRegistrar; | ||
import com.google.firebase.components.ComponentRuntime; | ||
import com.google.firebase.components.Lazy; | ||
import com.google.firebase.emulators.EmulatorSettings; | ||
import com.google.firebase.events.Publisher; | ||
import com.google.firebase.heartbeatinfo.DefaultHeartBeatInfo; | ||
import com.google.firebase.internal.DataCollectionConfigStorage; | ||
import com.google.firebase.platforminfo.DefaultUserAgentPublisher; | ||
import com.google.firebase.platforminfo.KotlinDetector; | ||
import com.google.firebase.platforminfo.LibraryVersionComponent; | ||
|
||
import java.nio.charset.Charset; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
@@ -59,8 +61,11 @@ | |
import java.util.concurrent.Executor; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import javax.annotation.concurrent.GuardedBy; | ||
|
||
import static com.google.android.gms.common.util.Base64Utils.encodeUrlSafeNoPadding; | ||
|
||
/** | ||
* The entry point of Firebase SDKs. It holds common configuration and state for Firebase APIs. Most | ||
* applications don't need to directly interact with FirebaseApp. | ||
|
@@ -109,6 +114,7 @@ public class FirebaseApp { | |
private final String name; | ||
private final FirebaseOptions options; | ||
private final ComponentRuntime componentRuntime; | ||
private EmulatorSettings emulatorSettings; | ||
|
||
// Default disabled. We released Firebase publicly without this feature, so making it default | ||
// enabled is a backwards incompatible change. | ||
|
@@ -142,6 +148,13 @@ public FirebaseOptions getOptions() { | |
return options; | ||
} | ||
|
||
/** Returns the specified {@link EmulatorSettings}. */ | ||
@Nullable | ||
samtstern marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public EmulatorSettings getEmulatorSettings() { | ||
checkNotDeleted(); | ||
return emulatorSettings; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (!(o instanceof FirebaseApp)) { | ||
|
@@ -305,6 +318,24 @@ public static FirebaseApp initializeApp( | |
return firebaseApp; | ||
} | ||
|
||
/** | ||
* Specify which services should access local emulators for this FirebaseApp instance. | ||
* | ||
* <p>For example, if the {@link EmulatorSettings} contain {@link | ||
* com.google.firebase.emulators.EmulatedServiceSettings} for {@link | ||
* com.google.firebase.emulators.FirebaseEmulators#FIRESTORE}, then calls to Cloud Firestore will | ||
* communicate with the emulator rather than production. | ||
* | ||
* @param emulatorSettings the emulator settings for all services. | ||
*/ | ||
public void enableEmulators(@NonNull EmulatorSettings emulatorSettings) { | ||
checkNotDeleted(); | ||
Preconditions.checkState( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How will this interact with firestore's firestore.terminate();
app.updateFirestoresEmulator();
Firebase.firestore.use(); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for calling this out, I resolved all the other comments since they were straightforward but I will have to look into this one more deeply. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok actually I do not want to allow that sequence of calls. One of the main reasons for this is to make sure that app developers can reason about their emulation settings at a single point before any Firebase service has done any communication. If you call WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point and sgtm. You may want to confirm this behavior with firestore folks though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do during the Firestore PR. |
||
!(this.emulatorSettings != null && this.emulatorSettings.isAccessed()), | ||
"Cannot enable emulators after Firebase SDKs have already been used."); | ||
this.emulatorSettings = emulatorSettings; | ||
} | ||
|
||
/** | ||
* Deletes the {@link FirebaseApp} and all its data. All calls to this {@link FirebaseApp} | ||
* instance will throw once it has been called. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2020 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. | ||
|
||
package com.google.firebase.emulators; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
/** | ||
* Settings to connect a single Firebase service to a local emulator. | ||
* | ||
* @see EmulatorSettings | ||
*/ | ||
public class EmulatedServiceSettings { | ||
samtstern marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public static final class Builder { | ||
|
||
private final String host; | ||
private final int port; | ||
|
||
/** | ||
* Create a new EmulatedServiceSettings builder. | ||
* | ||
* @param host the host where the local emulator is running. If you want to access 'localhost' | ||
* from an Android Emulator use '10.0.2.2' instead. | ||
* @param port the port where the local emulator is running. | ||
*/ | ||
public Builder(@NonNull String host, int port) { | ||
samtstern marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.host = host; | ||
this.port = port; | ||
} | ||
|
||
@NonNull | ||
public EmulatedServiceSettings build() { | ||
return new EmulatedServiceSettings(this.host, this.port); | ||
} | ||
} | ||
|
||
public final String host; | ||
public final int port; | ||
samtstern marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private EmulatedServiceSettings(@NonNull String host, int port) { | ||
this.host = host; | ||
this.port = port; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.