-
Notifications
You must be signed in to change notification settings - Fork 29
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
Mob 4998 connectivity manager offline mode improvements #476
base: master
Are you sure you want to change the base?
Mob 4998 connectivity manager offline mode improvements #476
Conversation
Some improvements in ConnectivityManager. 1. By default, isConnected is set to true. to avoid situations of db bloat up and no listener registered. This will also make sure that an app restart will eventually reset the flag, in case where internet was available but callbacks were not registered. 2. ConnectivityManager also listens to onCapabilitiesChanged, which can indicate more granular detail of if internet is available or not. isConnected is set to true as soon as internet is available. Currently, opposite case is not true as during testing, it has been seen as when one network out of the two gets disconnected, sometimes, false callbacks are made and another callback with internet available is not called. Added a TODO statement which captures even larger context to make ConnectivityManager even better. Might have to store multiple network that device is connected to and as long as one exists isConnected switch can remain ON.
Device can be connected to multiple network at once. Mostly Wifi and cellular. Previous implementation would switch back to offline if either of the one got disconnected, thereby falsely picturing device being offline. This implementation takes multiple network into consideration and saves them in a Set. Only if all the network are disconnected, only then `isConnected` is flipped to false. onCapabilitiesChanged is another callback that can give even granular controls over if internet is actually present or not, but to keep it simple, this is a good improvement to existing functionality of offline mode.
396512b
to
357973f
Compare
iterableapi/src/main/java/com/iterable/iterableapi/IterableTaskRunner.java
Outdated
Show resolved
Hide resolved
iterableapi/src/main/java/com/iterable/iterableapi/IterableNetworkConnectivityManager.java
Outdated
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #476 +/- ##
==========================================
- Coverage 61.51% 61.38% -0.14%
==========================================
Files 75 75
Lines 4695 4710 +15
Branches 533 535 +2
==========================================
+ Hits 2888 2891 +3
- Misses 1507 1515 +8
- Partials 300 304 +4 ☔ View full report in Codecov by Sentry. |
iterableapi/src/main/java/com/iterable/iterableapi/IterableNetworkConnectivityManager.java
Outdated
Show resolved
Hide resolved
iterableapi/src/main/java/com/iterable/iterableapi/IterableNetworkConnectivityManager.java
Outdated
Show resolved
Hide resolved
iterableapi/src/main/java/com/iterable/iterableapi/IterableNetworkConnectivityManager.java
Show resolved
Hide resolved
1. Using `connectivityManager.getNetworkCapabilities` instead of `networkRequest.hasCapability` which was giving incorrect values before. 2. ConnectivityManager is now global private variable. 3. Logic of checking initial state of connectivity is modularized and moved to constructor.
e2fe72c
to
1fc4fc4
Compare
private void checkInternetAvailabilityOnActiveNetwork() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
Network activeNetwork = connectivityManager.getActiveNetwork(); | ||
isConnected = activeNetwork == null ? false : connectivityManager.getNetworkCapabilities(activeNetwork).hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also wrap all of this stuff in a try...catch
. It should be safe enough, but this is Android, who knows if it's going to blow up on some obscure Android device. 😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea 👍. Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This can be merged once its verified working on older version of Android SDK |
🔹 Jira Ticket(s) if any
✏️ Description
Default value to isConnected is set to true.
Extra conditions for when to set isConnected false.
Device can be connected to multiple network at once. Usually Wifi and cellular. Previous implementation would switch SDK mode to offline if either of the one got disconnected, thereby falsely picturing device being offline.
This implementation takes multiple network into consideration and saves them in a Set. Only if all the network are disconnected, only then
isConnected
is flipped to false.onCapabilitiesChanged is another callback that can give even granular controls over if internet is actually present or not, but to keep it simple, this is a good improvement to existing functionality of offline mode.