Skip to content

Conversation

@vbuberen
Copy link
Collaborator

@vbuberen vbuberen commented Mar 11, 2024

Description

Looks like we had an issue with catching connectivity state change on Android device when some network type gets disconnected (by either turning it off or losing signal) for quite some time. I believe that the issue happened due to a race condition after getting onLost() called.
In fact, the note about possible race condition is mentioned in the documentation in a few places:

This PR contains a fix, which is not really nice, but does its job. The fix itself is adding a 100ms delay to runnable sendEvent in broadcase receiver file.

For the usage of Android connectivity APIs in the plugin we don't have much options to create a NetworkRequest object, like it is suggested in https://developer.android.com/training/monitoring-device-state/connectivity-status-type

Thus, I think we can live with this delay for now. But feel free to correct me if I missed some better option.

Additionally fixed #2671 and removed the method which sends just String as a result, so also reverted my yesterday change from #2668

Here is a video on how the example app works now with same test as in #2672 where mobile network switches on and off on the same device with Android 14:

connectivity_fix.mp4

Also tested this fix with other connection types and worked good.

Related Issues

Closes #2672
Closes #2671

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to do it because of using 8.3.0 Gradle plugin, which didn't allow me to open just Android part of the plugin with 7.6.1 version of Gradle wrapper.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will open another PR where I will address such changes.

private final Handler mainHandler = new Handler(Looper.getMainLooper());
private ConnectivityManager.NetworkCallback networkCallback;
public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
implements EventChannel.StreamHandler {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting changed as in the editorconfig file we have no styles for Java. But, I beleive, it is not really an issue at the moment, especially as at some point this will be replaced with Kotlin code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see that out Java code style check failed. Will revert formatting changes then.

Copy link
Collaborator Author

@vbuberen vbuberen Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the formatting and added Java rules to avoid such issues

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, editorconfig had to be more complex, so I removed it and formatted with a help of the plugin that we use for formatting

@vbuberen vbuberen added the connectivity_plus Connectivity Plus label Mar 11, 2024
@vbuberen vbuberen requested a review from miquelbeltran March 11, 2024 11:23
@vbuberen vbuberen merged commit 2119168 into main Mar 11, 2024
@vbuberen vbuberen deleted the fix/connectivity_plus_disconnection branch March 11, 2024 15:24
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

connectivity_plus Connectivity Plus

3 participants