Skip to content

Commit d90430e

Browse files
authored
Merge d455a90 into 68fb692
2 parents 68fb692 + d455a90 commit d90430e

File tree

10 files changed

+38
-10
lines changed

10 files changed

+38
-10
lines changed

firebase-database/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
# limitations under the License.
1414

1515
version=21.0.0
16-
latestReleasedVersion=20.3.1
16+
latestReleasedVersion=20.3.2
1717
android.enableUnitTestBinaryResources=true

firebase-database/src/androidTest/java/com/google/firebase/database/connection/ConnectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void onCacheHost(String s) {}
6666
IntegrationTestValues.getNamespace(),
6767
/*secure=*/ true);
6868
DatabaseConfig config = IntegrationTestHelpers.newFrozenTestConfig();
69-
Connection conn = new Connection(config.getConnectionContext(), info, null, del, null, "");
69+
Connection conn = new Connection(config.getConnectionContext(), info, null, del, null, "", false);
7070
conn.open();
7171
IntegrationTestHelpers.waitFor(valSemaphore);
7272
}

firebase-database/src/androidTest/java/com/google/firebase/database/core/SynchronousConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public SynchronousConnection(String host) {
5555
RepoInfo repoInfo = parsed.repoInfo;
5656
HostInfo hostInfo = new HostInfo(repoInfo.host, repoInfo.namespace, repoInfo.secure);
5757

58-
connection = new PersistentConnectionImpl(context.getConnectionContext(), hostInfo, this);
58+
connection = new PersistentConnectionImpl(context.getConnectionContext(), hostInfo, this, false);
5959
this.connectSemaphore = new Semaphore(0);
6060
}
6161

firebase-database/src/main/java/com/google/firebase/database/FirebaseDatabase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,13 @@ public synchronized void setPersistenceCacheSizeBytes(long cacheSizeInBytes) {
313313
* @param port the emulator port (for example, 9000)
314314
*/
315315
public void useEmulator(@NonNull String host, int port) {
316+
System.out.println("Using Emulator");
316317
if (this.repo != null) {
317318
throw new IllegalStateException(
318319
"Cannot call useEmulator() after instance has already been initialized.");
319320
}
320-
321321
this.emulatorSettings = new EmulatedServiceSettings(host, port);
322+
this.config.setUsingEmulator(true);
322323
}
323324

324325
/** @return The semver version for this build of the Firebase Database client */

firebase-database/src/main/java/com/google/firebase/database/android/AndroidPlatform.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ public PersistentConnection newPersistentConnection(
114114
ConnectionContext connectionContext,
115115
HostInfo info,
116116
PersistentConnection.Delegate delegate) {
117+
117118
final PersistentConnection connection =
118-
new PersistentConnectionImpl(connectionContext, info, delegate);
119+
new PersistentConnectionImpl(connectionContext, info, delegate, context.isUsingEmulator());
119120

120121
// TODO: Ideally we would remove this listener at some point, but right now
121122
// there's no cleanup path for PersistentConnection (or Repo, etc.). They live forever.

firebase-database/src/main/java/com/google/firebase/database/connection/Connection.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,22 @@ private enum State {
7070
private State state;
7171
private final LogWrapper logger;
7272

73+
private boolean isUsingEmulator;
74+
7375
public Connection(
7476
ConnectionContext context,
7577
HostInfo hostInfo,
7678
String cachedHost,
7779
Delegate delegate,
7880
String optLastSessionId,
79-
String appCheckToken) {
81+
String appCheckToken,
82+
boolean isUsingEmulator) {
8083
long connId = connectionIds++;
8184
this.hostInfo = hostInfo;
8285
this.delegate = delegate;
8386
this.logger = new LogWrapper(context.getLogger(), "Connection", "conn_" + connId);
8487
this.state = State.REALTIME_CONNECTING;
88+
this.isUsingEmulator = isUsingEmulator;
8589
this.conn =
8690
new WebsocketConnection(
8791
context, hostInfo, cachedHost, appCheckToken, this, optLastSessionId);
@@ -205,7 +209,9 @@ private void onConnectionShutdown(String reason) {
205209
private void onHandshake(Map<String, Object> handshake) {
206210
long timestamp = (Long) handshake.get(SERVER_HELLO_TIMESTAMP);
207211
String host = (String) handshake.get(SERVER_HELLO_HOST);
208-
delegate.onCacheHost(host);
212+
if(!this.isUsingEmulator) {
213+
delegate.onCacheHost(host);
214+
}
209215
String sessionId = (String) handshake.get(SERVER_HELLO_SESSION_ID);
210216

211217
if (state == State.REALTIME_CONNECTING) {

firebase-database/src/main/java/com/google/firebase/database/connection/PersistentConnectionImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,13 @@ private enum ConnectionState {
327327
private long lastWriteTimestamp;
328328
private boolean hasOnDisconnects;
329329

330+
private boolean isUsingEmulator;
331+
330332
public PersistentConnectionImpl(
331-
ConnectionContext context, HostInfo info, final Delegate delegate) {
333+
ConnectionContext context, HostInfo info, final Delegate delegate, boolean isUsingEmulator) {
332334
this.delegate = delegate;
333335
this.context = context;
336+
this.isUsingEmulator = isUsingEmulator;
334337
this.executorService = context.getExecutorService();
335338
this.authTokenProvider = context.getAuthTokenProvider();
336339
this.appCheckTokenProvider = context.getAppCheckTokenProvider();
@@ -829,7 +832,7 @@ public void openNetworkConnection(String authToken, String appCheckToken) {
829832
this.connectionState = ConnectionState.Connecting;
830833
realtime =
831834
new Connection(
832-
this.context, this.hostInfo, this.cachedHost, this, this.lastSessionId, appCheckToken);
835+
this.context, this.hostInfo, this.cachedHost, this, this.lastSessionId, appCheckToken, this.isUsingEmulator);
833836
realtime.open();
834837
}
835838

firebase-database/src/main/java/com/google/firebase/database/core/Context.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public class Context {
5454

5555
private Platform platform;
5656

57+
protected boolean isUsingEmulator = false;
58+
5759
private Platform getPlatform() {
5860
if (platform == null) {
5961
initializeAndroidPlatform();
@@ -65,6 +67,10 @@ private synchronized void initializeAndroidPlatform() {
6567
platform = new AndroidPlatform(this.firebaseApp);
6668
}
6769

70+
public boolean isUsingEmulator() {
71+
return this.isUsingEmulator;
72+
}
73+
6874
public boolean isFrozen() {
6975
return frozen;
7076
}
@@ -139,6 +145,7 @@ public LogWrapper getLogger(String component, String prefix) {
139145
return new LogWrapper(logger, component, prefix);
140146
}
141147

148+
// TODO(mtewani): fill this in instead of repoinfo
142149
public ConnectionContext getConnectionContext() {
143150
return new ConnectionContext(
144151
this.getLogger(),
@@ -211,8 +218,9 @@ public TokenProvider getAppCheckTokenProvider() {
211218
return this.appCheckTokenProvider;
212219
}
213220

221+
214222
public PersistentConnection newPersistentConnection(
215-
HostInfo info, PersistentConnection.Delegate delegate) {
223+
HostInfo info, PersistentConnection.Delegate delegate) {
216224
return getPlatform().newPersistentConnection(this, this.getConnectionContext(), info, delegate);
217225
}
218226

firebase-database/src/main/java/com/google/firebase/database/core/DatabaseConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ public synchronized void setPersistenceCacheSizeBytes(long cacheSizeInBytes) {
173173
this.cacheSize = cacheSizeInBytes;
174174
}
175175

176+
/**
177+
* @hide
178+
* @param isUsingEmulator
179+
*/
180+
public synchronized void setUsingEmulator(boolean isUsingEmulator) {
181+
this.isUsingEmulator = isUsingEmulator;
182+
}
183+
176184
public synchronized void setFirebaseApp(FirebaseApp app) {
177185
this.firebaseApp = app;
178186
}

firebase-database/src/main/java/com/google/firebase/database/core/RepoInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public final class RepoInfo {
2828
public String namespace;
2929
public String internalHost;
3030

31+
3132
@Override
3233
public String toString() {
3334
return "http" + (secure ? "s" : "") + "://" + host;

0 commit comments

Comments
 (0)