-
Notifications
You must be signed in to change notification settings - Fork 616
Fix Android connectivity issues #937
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 all commits
11ca8a5
448311d
403f91f
00568be
c865827
d714378
55e8f46
d202893
411ed9d
1519a40
5bce0a0
ba515b7
110fdc3
c9cafd5
b77e02e
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
|
||
package com.google.firebase.firestore.remote; | ||
|
||
import static com.google.firebase.firestore.remote.OnlineStateTracker.CONNECTIVITY_ATTEMPT_TIMEOUT_MS; | ||
import static com.google.firebase.firestore.util.Assert.hardAssert; | ||
|
||
import androidx.annotation.Nullable; | ||
|
@@ -35,6 +36,8 @@ | |
import com.google.firebase.firestore.remote.WatchChange.WatchTargetChange; | ||
import com.google.firebase.firestore.remote.WatchChange.WatchTargetChangeType; | ||
import com.google.firebase.firestore.util.AsyncQueue; | ||
import com.google.firebase.firestore.util.AsyncQueue.DelayedTask; | ||
import com.google.firebase.firestore.util.AsyncQueue.TimerId; | ||
import com.google.firebase.firestore.util.Logger; | ||
import com.google.firebase.firestore.util.Util; | ||
import com.google.protobuf.ByteString; | ||
|
@@ -129,6 +132,8 @@ public interface RemoteStoreCallback { | |
private final WriteStream writeStream; | ||
@Nullable private WatchChangeAggregator watchChangeAggregator; | ||
|
||
private final AsyncQueue workerQueue; | ||
|
||
/** | ||
* A list of up to MAX_PENDING_WRITES writes that we have fetched from the LocalStore via | ||
* fillWritePipeline() and have or will send to the write stream. | ||
|
@@ -155,12 +160,12 @@ public RemoteStore( | |
this.localStore = localStore; | ||
this.datastore = datastore; | ||
this.connectivityMonitor = connectivityMonitor; | ||
this.workerQueue = workerQueue; | ||
|
||
listenTargets = new HashMap<>(); | ||
writePipeline = new ArrayDeque<>(); | ||
|
||
onlineStateTracker = | ||
new OnlineStateTracker(workerQueue, remoteStoreCallback::handleOnlineStateChange); | ||
new OnlineStateTracker(this.workerQueue, remoteStoreCallback::handleOnlineStateChange); | ||
|
||
// Create new streams (but note they're not started yet). | ||
watchStream = | ||
|
@@ -223,6 +228,11 @@ public void onClose(Status status) { | |
}); | ||
} | ||
|
||
/** Marks that we should start checking for online state. */ | ||
public void attemptReconnect() { | ||
watchStream.handleConnectionAttemptTimeout(); | ||
} | ||
|
||
/** Re-enables the network. Only to be called as the counterpart to disableNetwork(). */ | ||
public void enableNetwork() { | ||
networkEnabled = true; | ||
|
@@ -412,8 +422,20 @@ private void startWatchStream() { | |
"startWatchStream() called when shouldStartWatchStream() is false."); | ||
watchChangeAggregator = new WatchChangeAggregator(this); | ||
watchStream.start(); | ||
|
||
onlineStateTracker.handleWatchStreamStart(); | ||
|
||
DelayedTask connectivityAttemptTimer = | ||
workerQueue.enqueueAfterDelay( | ||
TimerId.CONNECTIVITY_ATTEMPT_TIMER, | ||
CONNECTIVITY_ATTEMPT_TIMEOUT_MS, | ||
() -> { | ||
// If the network has been explicitly disabled, make sure we don't accidentally | ||
// re-enable it. | ||
if (canUseNetwork()) { | ||
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. Previously, in the case of an online state timeout we performed the following things: logClientOfflineWarningIfNecessary(
String.format(
Locale.ENGLISH,
"Backend didn't respond within %d seconds\n",
ONLINE_STATE_TIMEOUT_MS / 1000));
setAndBroadcastState(OnlineState.OFFLINE); This isn't calling 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.
The problem I was running into by leaving a |
||
attemptReconnect(); | ||
} | ||
}); | ||
onlineStateTracker.setConnectivityAttemptTimer(connectivityAttemptTimer); | ||
} | ||
|
||
private void handleWatchStreamOpen() { | ||
|
Uh oh!
There was an error while loading. Please reload this page.