Skip to content
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

AndroidChannel fails to reconnect after block #8850

Closed
litclimbing opened this issue Jan 19, 2022 · 2 comments · Fixed by #8855
Closed

AndroidChannel fails to reconnect after block #8850

litclimbing opened this issue Jan 19, 2022 · 2 comments · Fixed by #8855
Assignees
Milestone

Comments

@litclimbing
Copy link
Contributor

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.

public void onAvailable(Network network) {

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.

@litclimbing
Copy link
Contributor Author

litclimbing commented Jan 19, 2022

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();
      }
    }

@dapengzhang0
Copy link
Member

@litclimbing Can you send out a PR for the fix?

@dapengzhang0 dapengzhang0 added this to the Next milestone Jan 25, 2022
@dapengzhang0 dapengzhang0 modified the milestones: Next, v1.45 Feb 1, 2022
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)
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)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants