Skip to content

Commit ca4a1d8

Browse files
authored
android: fix for app coming to foreground
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)
1 parent 7308d92 commit ca4a1d8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

android/src/main/java/io/grpc/android/AndroidChannelBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ private class DefaultNetworkCallback extends ConnectivityManager.NetworkCallback
297297
public void onAvailable(Network network) {
298298
delegate.enterIdle();
299299
}
300+
@Override
301+
public void onBlockedStatusChanged (Network network, boolean blocked) {
302+
if (!blocked)
303+
delegate.enterIdle();
304+
}
300305
}
301306

302307
/** Respond to network changes. Only used on API levels < 24. */

0 commit comments

Comments
 (0)