-
Notifications
You must be signed in to change notification settings - Fork 3.9k
AndroidChannel fails to reconnect after block #8850
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
Milestone
Comments
For what it's worth, I made a local fork and added the hook. I then forced Firebase to use the updated version and it fixed my issue. /** Respond to changes in the default network. Only used on API levels 24+. */
@TargetApi(Build.VERSION_CODES.N)
private class DefaultNetworkCallback extends ConnectivityManager.NetworkCallback {
@Override
public void onAvailable(Network network) {
delegate.enterIdle();
}
@Override
public void onBlockedStatusChanged (Network network, boolean blocked) {
if (!blocked)
delegate.enterIdle();
}
} |
@litclimbing Can you send out a PR for the fix? |
ejona86
pushed a commit
that referenced
this issue
Feb 3, 2022
When an app goes to the background, onBlockedStatusChanged is called with true and then called with false when it comes back to the foreground. The function onAvailable isn't called in this case and the connection wasn't being reset. Closes #8850 I noticed the comment that this is used for API versions 24+ but onBlockedStatusChanged was added in 29. I'm not sure if some kind of guard needs to be added or not. https://developer.android.com/reference/android/net/ConnectivityManager.NetworkCallback#onBlockedStatusChanged(android.net.Network,%20boolean)
ejona86
pushed a commit
to ejona86/grpc-java
that referenced
this issue
Feb 9, 2022
When an app goes to the background, onBlockedStatusChanged is called with true and then called with false when it comes back to the foreground. The function onAvailable isn't called in this case and the connection wasn't being reset. Closes grpc#8850 I noticed the comment that this is used for API versions 24+ but onBlockedStatusChanged was added in 29. I'm not sure if some kind of guard needs to be added or not. https://developer.android.com/reference/android/net/ConnectivityManager.NetworkCallback#onBlockedStatusChanged(android.net.Network,%20boolean)
ejona86
pushed a commit
to ejona86/grpc-java
that referenced
this issue
Feb 9, 2022
When an app goes to the background, onBlockedStatusChanged is called with true and then called with false when it comes back to the foreground. The function onAvailable isn't called in this case and the connection wasn't being reset. Closes grpc#8850 I noticed the comment that this is used for API versions 24+ but onBlockedStatusChanged was added in 29. I'm not sure if some kind of guard needs to be added or not. https://developer.android.com/reference/android/net/ConnectivityManager.NetworkCallback#onBlockedStatusChanged(android.net.Network,%20boolean)
This was referenced Feb 9, 2022
ejona86
pushed a commit
that referenced
this issue
Feb 9, 2022
When an app goes to the background, onBlockedStatusChanged is called with true and then called with false when it comes back to the foreground. The function onAvailable isn't called in this case and the connection wasn't being reset. Closes #8850 I noticed the comment that this is used for API versions 24+ but onBlockedStatusChanged was added in 29. I'm not sure if some kind of guard needs to be added or not. https://developer.android.com/reference/android/net/ConnectivityManager.NetworkCallback#onBlockedStatusChanged(android.net.Network,%20boolean)
ejona86
pushed a commit
that referenced
this issue
Feb 9, 2022
When an app goes to the background, onBlockedStatusChanged is called with true and then called with false when it comes back to the foreground. The function onAvailable isn't called in this case and the connection wasn't being reset. Closes #8850 I noticed the comment that this is used for API versions 24+ but onBlockedStatusChanged was added in 29. I'm not sure if some kind of guard needs to be added or not. https://developer.android.com/reference/android/net/ConnectivityManager.NetworkCallback#onBlockedStatusChanged(android.net.Network,%20boolean)
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I'm having issues with Firestore (which uses gRPC) not connecting after a device is locked and was able to track it down to here.
grpc-java/android/src/main/java/io/grpc/android/AndroidChannelBuilder.java
Line 297 in a35336c
It seems that the network callback needs to override the onBlockedStatusChanged() function and reconnect when the blocked parameter is false.
I'm seeing onAvailable() only called when my app initially starts but onBlockedStatusChanged() is called with true when it has been idle for a while and false when it comes back up. This was tested on Android 12.
The text was updated successfully, but these errors were encountered: